changeset 39466:838ae1e90961

8154820: JDWP: -agentlib:jdwp=help assertion error Reviewed-by: dholmes, sspitsyn, dsamersoff
author iklam
date Mon, 20 Jun 2016 08:49:40 -0700
parents aaf17117b16c
children 4fa628bbb108
files jdk/src/jdk.jdwp.agent/share/native/libjdwp/debugInit.c jdk/src/jdk.jdwp.agent/share/native/libjdwp/error_messages.c jdk/src/jdk.jdwp.agent/share/native/libjdwp/transport.c jdk/src/jdk.jdwp.agent/share/native/libjdwp/utf_util.c jdk/src/jdk.jdwp.agent/share/native/libjdwp/utf_util.h
diffstat 5 files changed, 47 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/jdk/src/jdk.jdwp.agent/share/native/libjdwp/debugInit.c	Wed Jun 15 20:43:53 2016 +0300
+++ b/jdk/src/jdk.jdwp.agent/share/native/libjdwp/debugInit.c	Mon Jun 20 08:49:40 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2016, 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
@@ -870,8 +870,9 @@
  "onuncaught=y|n                   debug on any uncaught?            n\n"
  "timeout=<timeout value>          for listen/attach in milliseconds n\n"
  "mutf8=y|n                        output modified utf-8             n\n"
- "quiet=y|n                        control over terminal messages    n\n"
- "\n"
+ "quiet=y|n                        control over terminal messages    n\n"));
+
+    TTY_MESSAGE((
  "Obsolete Options\n"
  "----------------\n"
  "strict=y|n\n"
@@ -914,7 +915,9 @@
  "                               locations     = 0x020\n"
  "                               callbacks     = 0x040\n"
  "                               errors        = 0x080\n"
- "                               everything    = 0xfff\n"
+ "                               everything    = 0xfff"));
+
+    TTY_MESSAGE((
  "debugflags=flags             debug flags (bitmask)           none\n"
  "                               USE_ITERATE_THROUGH_HEAP 0x01\n"
  "\n"
--- a/jdk/src/jdk.jdwp.agent/share/native/libjdwp/error_messages.c	Wed Jun 15 20:43:53 2016 +0300
+++ b/jdk/src/jdk.jdwp.agent/share/native/libjdwp/error_messages.c	Mon Jun 20 08:49:40 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2016, 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
@@ -50,8 +50,12 @@
 #include "utf_util.h"
 #include "proc_md.h"
 
-/* Maximim length of a message */
-#define MAX_MESSAGE_LEN MAXPATHLEN*2+512
+/* Maximum number of bytes in a message, including the trailing zero.
+ * Do not print very long messages as they could be truncated.
+ * Use at most one pathname per message. NOTE, we use MAXPATHLEN*2
+ * in case each character in the pathname takes 2 bytes.
+ */
+#define MAX_MESSAGE_BUF MAXPATHLEN*2+512
 
 /* Print message in platform encoding (assume all input is UTF-8 safe)
  *    NOTE: This function is at the lowest level of the call tree.
@@ -61,17 +65,16 @@
 vprint_message(FILE *fp, const char *prefix, const char *suffix,
                const char *format, va_list ap)
 {
-    jbyte  utf8buf[MAX_MESSAGE_LEN+1];
+    jbyte  utf8buf[MAX_MESSAGE_BUF];
     int    len;
-    char   pbuf[MAX_MESSAGE_LEN+1];
+    char   pbuf[MAX_MESSAGE_BUF];
 
     /* Fill buffer with single UTF-8 string */
-    (void)vsnprintf((char*)utf8buf, MAX_MESSAGE_LEN, format, ap);
-    utf8buf[MAX_MESSAGE_LEN] = 0;
+    (void)vsnprintf((char*)utf8buf, sizeof(utf8buf), format, ap);
     len = (int)strlen((char*)utf8buf);
 
     /* Convert to platform encoding (ignore errors, dangerous area) */
-    (void)utf8ToPlatform(utf8buf, len, pbuf, MAX_MESSAGE_LEN);
+    (void)utf8ToPlatform(utf8buf, len, pbuf, (int)sizeof(pbuf));
 
     (void)fprintf(fp, "%s%s%s", prefix, pbuf, suffix);
 }
--- a/jdk/src/jdk.jdwp.agent/share/native/libjdwp/transport.c	Wed Jun 15 20:43:53 2016 +0300
+++ b/jdk/src/jdk.jdwp.agent/share/native/libjdwp/transport.c	Mon Jun 20 08:49:40 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2016, 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
@@ -67,8 +67,7 @@
         maxlen = len+len/2+2; /* Should allow for plenty of room */
         utf8msg = (jbyte*)jvmtiAllocate(maxlen+1);
         if (utf8msg != NULL) {
-           (void)utf8FromPlatform(msg, len, utf8msg, maxlen);
-           utf8msg[maxlen] = 0;
+           (void)utf8FromPlatform(msg, len, utf8msg, maxlen+1);
         }
     }
     if (rv == JDWPTRANSPORT_ERROR_NONE) {
--- a/jdk/src/jdk.jdwp.agent/share/native/libjdwp/utf_util.c	Wed Jun 15 20:43:53 2016 +0300
+++ b/jdk/src/jdk.jdwp.agent/share/native/libjdwp/utf_util.c	Mon Jun 20 08:49:40 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2016, 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
@@ -350,16 +350,20 @@
 
 /*
  * Convert UTF-8 to a platform string
+ * NOTE: outputBufSize includes the space for the trailing 0.
  */
-int JNICALL utf8ToPlatform(jbyte *utf8, int len, char* output, int outputMaxLen) {
+int JNICALL utf8ToPlatform(jbyte *utf8, int len, char* output, int outputBufSize) {
     int wlen;
     int plen;
     WCHAR* wstr;
     UINT codepage;
+    int outputMaxLen;
 
     UTF_ASSERT(utf8);
     UTF_ASSERT(output);
-    UTF_ASSERT(outputMaxLen > len);
+    UTF_ASSERT(len >= 0);
+    UTF_ASSERT(outputBufSize > len);
+    outputMaxLen = outputBufSize - 1; // leave space for trailing 0
 
     /* Zero length is ok, but we don't need to do much */
     if ( len == 0 ) {
@@ -394,16 +398,20 @@
 
 /*
  * Convert Platform Encoding to UTF-8.
+ * NOTE: outputBufSize includes the space for the trailing 0.
  */
-int JNICALL utf8FromPlatform(char *str, int len, jbyte *output, int outputMaxLen) {
+int JNICALL utf8FromPlatform(char *str, int len, jbyte *output, int outputBufSize) {
     int wlen;
     int plen;
     WCHAR* wstr;
     UINT codepage;
+    int outputMaxLen;
 
     UTF_ASSERT(str);
     UTF_ASSERT(output);
-    UTF_ASSERT(outputMaxLen > len);
+    UTF_ASSERT(len >= 0);
+    UTF_ASSERT(outputBufSize > len);
+    outputMaxLen = outputBufSize - 1; // leave space for trailing 0
 
     /* Zero length is ok, but we don't need to do much */
     if ( len == 0 ) {
@@ -449,18 +457,21 @@
 /*
  * Do iconv() conversion.
  *    Returns length or -1 if output overflows.
+ * NOTE: outputBufSize includes the space for the trailing 0.
  */
-static int iconvConvert(conv_direction drn, char *bytes, size_t len, char *output, size_t outputMaxLen) {
+static int iconvConvert(conv_direction drn, char *bytes, size_t len, char *output, size_t outputBufSize) {
 
     static char *codeset = 0;
     iconv_t func;
     size_t bytes_converted;
     size_t inLeft, outLeft;
     char *inbuf, *outbuf;
+    int outputMaxLen;
 
     UTF_ASSERT(bytes);
     UTF_ASSERT(output);
-    UTF_ASSERT(outputMaxLen > len);
+    UTF_ASSERT(outputBufSize > len);
+    outputMaxLen = outputBufSize - 1; // leave space for trailing 0
 
     /* Zero length is ok, but we don't need to do much */
     if ( len == 0 ) {
@@ -524,17 +535,19 @@
 /*
  * Convert UTF-8 to Platform Encoding.
  *    Returns length or -1 if output overflows.
+ * NOTE: outputBufSize includes the space for the trailing 0.
  */
-int JNICALL utf8ToPlatform(jbyte *utf8, int len, char *output, int outputMaxLen) {
-    return iconvConvert(FROM_UTF8, (char*)utf8, len, output, outputMaxLen);
+int JNICALL utf8ToPlatform(jbyte *utf8, int len, char *output, int outputBufSize) {
+    return iconvConvert(FROM_UTF8, (char*)utf8, len, output, outputBufSize);
 }
 
 /*
  * Convert Platform Encoding to UTF-8.
  *    Returns length or -1 if output overflows.
+ * NOTE: outputBufSize includes the space for the trailing 0.
  */
-int JNICALL utf8FromPlatform(char *str, int len, jbyte *output, int outputMaxLen) {
-    return iconvConvert(TO_UTF8, str, len, (char*) output, outputMaxLen);
+int JNICALL utf8FromPlatform(char *str, int len, jbyte *output, int outputBufSize) {
+    return iconvConvert(TO_UTF8, str, len, (char*) output, outputBufSize);
 }
 
 #endif
--- a/jdk/src/jdk.jdwp.agent/share/native/libjdwp/utf_util.h	Wed Jun 15 20:43:53 2016 +0300
+++ b/jdk/src/jdk.jdwp.agent/share/native/libjdwp/utf_util.h	Mon Jun 20 08:49:40 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2016, 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
@@ -34,7 +34,7 @@
 int JNICALL utf8mToUtf8sLength(jbyte *string, int length);
 void JNICALL utf8mToUtf8s(jbyte *string, int length, jbyte *newString, int newLength);
 
-int JNICALL utf8ToPlatform(jbyte *utf8, int len, char* output, int outputMaxLen);
-int JNICALL utf8FromPlatform(char *str, int len, jbyte *output, int outputMaxLen);
+int JNICALL utf8ToPlatform(jbyte *utf8, int len, char* output, int outputBufSize);
+int JNICALL utf8FromPlatform(char *str, int len, jbyte *output, int outputBufSize);
 
 #endif