JDK-8214854 : JDWP: Unforseen output truncation in logging
  • Type: Bug
  • Component: core-svc
  • Sub-Component: debugger
  • Affected Version: 11,13
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2018-12-05
  • Updated: 2021-07-20
  • Resolved: 2019-03-02
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 13
11.0.12Fixed 13 b11Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
GCC 8 reports an error:

src/jdk.jdwp.agent/share/native/libjdwp/log_messages.c:75:24: error: '%.3d' directive output may be truncated writing between 3 and 11 bytes into a region of size between 0 and 80 [-Werror=format-truncation=] 
                    "%s.%.3d %s", timestamp_prefix, 
                        ^~~~ 
The call is:
    (void)snprintf(tbuf, ltbuf,
                   "%s.%.3d %s", timestamp_prefix,
                   (int)(millisecs), timestamp_postfix);

It can be fixed by making prefix and postfix reasonably short, like: 

char timestamp_prefix[MAXLEN_TIMESTAMP / 2 - 4]; 
char timestamp_postfix[MAXLEN_TIMESTAMP / 2]; 
Comments
JDK11 backport request I would like to have the patch in jdk11 as well, because the issue is present there too. The patch applies cleanly.
05-05-2021

Yes, I also see this failure.
11-06-2019

For some reason 32-bit builds still fail for me even after this patch: src/jdk.jdwp.agent/share/native/libjdwp/log_messages.c:81:11: note: 'snprintf' output between 6 and 86 bytes into a destination of size 81 (void)snprintf(tbuf, ltbuf, ^~~~~~~~~~~~~~~~~~~~~ "%s.%.3d %s", timestamp_date_time, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (int)(millisecs), timestamp_timezone); I've worked around this locally with this fix: diff -r d25b24c70126 src/jdk.jdwp.agent/share/native/libjdwp/log_messages.c --- a/src/jdk.jdwp.agent/share/native/libjdwp/log_messages.c Mon Mar 25 00:57:03 2019 -0400 +++ b/src/jdk.jdwp.agent/share/native/libjdwp/log_messages.c Mon Mar 25 11:46:55 2019 +0100 @@ -79,7 +79,7 @@ (void)strftime(timestamp_timezone, TZ_SIZE, "%Z", localtime(&t)); (void)snprintf(tbuf, ltbuf, - "%s.%.3d %s", timestamp_date_time, + "%.19s.%.3d %.50s", timestamp_date_time, (int)(millisecs), timestamp_timezone); }
25-03-2019

http://cr.openjdk.java.net/~dchuyko/8214854/webrev.00/
28-02-2019