OpenJDK / amber / amber
changeset 55216:70c7c4db9c9a
8214854: JDWP: Unforseen output truncation in logging
Reviewed-by: cjplummer, dholmes
author | dchuyko |
---|---|
date | Sat, 02 Mar 2019 11:42:04 +0300 |
parents | 581c2f4f82d3 |
children | f3fd73c3a077 |
files | src/jdk.jdwp.agent/share/native/libjdwp/log_messages.c |
diffstat | 1 files changed, 17 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/jdk.jdwp.agent/share/native/libjdwp/log_messages.c Fri Mar 01 13:08:41 2019 -0800 +++ b/src/jdk.jdwp.agent/share/native/libjdwp/log_messages.c Sat Mar 02 11:42:04 2019 +0300 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -42,6 +42,12 @@ #define MAXLEN_MESSAGE 256 #define MAXLEN_EXEC (MAXLEN_FILENAME*2+MAXLEN_INTEGER+16) +#define TIMESTAMP_SIZE (MAXLEN_TIMESTAMP+1) +#define MAXLEN_DT 19 // "DD.MM.YYYY HH:MM:SS" +#define MAXLEN_MS 5 // ".mmm " +#define DT_SIZE (MAXLEN_DT+1) +#define TZ_SIZE (TIMESTAMP_SIZE-MAXLEN_DT-MAXLEN_MS) + static MUTEX_T my_mutex = MUTEX_INIT; /* Static variables (should be protected with mutex) */ @@ -52,12 +58,14 @@ static PID_T processPid; static int open_count; -/* Ascii id of current native thread. */ +/* + * "DD.MM.YYYY HH:MM:SS.mmm <TZ>" + */ static void get_time_stamp(char *tbuf, size_t ltbuf) { - char timestamp_prefix[MAXLEN_TIMESTAMP+1]; - char timestamp_postfix[MAXLEN_TIMESTAMP+1]; + char timestamp_date_time[DT_SIZE]; + char timestamp_timezone[TZ_SIZE]; unsigned millisecs = 0; time_t t = 0; @@ -65,15 +73,14 @@ if ( time(&t) == (time_t)(-1) ) { t = 0; } - /* Break this up so that the format strings are string literals - and we avoid a compiler warning. */ - (void)strftime(timestamp_prefix, sizeof(timestamp_prefix), + + (void)strftime(timestamp_date_time, DT_SIZE, "%d.%m.%Y %T", localtime(&t)); - (void)strftime(timestamp_postfix, sizeof(timestamp_postfix), + (void)strftime(timestamp_timezone, TZ_SIZE, "%Z", localtime(&t)); (void)snprintf(tbuf, ltbuf, - "%s.%.3d %s", timestamp_prefix, - (int)(millisecs), timestamp_postfix); + "%s.%.3d %s", timestamp_date_time, + (int)(millisecs), timestamp_timezone); } /* Get basename of filename */