8192978: Missing checks and small fixes in jdwp library
authorclanger
Mon, 11 Dec 2017 08:20:05 +0100
changeset 48235 8db54e2c453b
parent 48234 e7342e1becb4
child 48236 31febb3f66f7
8192978: Missing checks and small fixes in jdwp library Reviewed-by: cjplummer, sspitsyn
src/jdk.jdwp.agent/share/native/libjdwp/VirtualMachineImpl.c
src/jdk.jdwp.agent/share/native/libjdwp/error_messages.c
src/jdk.jdwp.agent/share/native/libjdwp/error_messages.h
src/jdk.jdwp.agent/share/native/libjdwp/eventHandler.c
src/jdk.jdwp.agent/share/native/libjdwp/invoker.c
src/jdk.jdwp.agent/share/native/libjdwp/log_messages.c
--- a/src/jdk.jdwp.agent/share/native/libjdwp/VirtualMachineImpl.c	Mon Dec 11 06:58:14 2017 +0530
+++ b/src/jdk.jdwp.agent/share/native/libjdwp/VirtualMachineImpl.c	Mon Dec 11 08:20:05 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2017, 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
@@ -839,7 +839,7 @@
     }
 
     pos = string;
-    for ( i = 0 ; i < npaths ; i++ ) {
+    for ( i = 0 ; i < npaths && pos != NULL; i++ ) {
         char *psPos;
         int   plen;
 
@@ -859,8 +859,6 @@
     jvmtiDeallocate(buf);
 }
 
-
-
 static jboolean
 classPaths(PacketInputStream *in, PacketOutputStream *out)
 {
--- a/src/jdk.jdwp.agent/share/native/libjdwp/error_messages.c	Mon Dec 11 06:58:14 2017 +0530
+++ b/src/jdk.jdwp.agent/share/native/libjdwp/error_messages.c	Mon Dec 11 08:20:05 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, 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
@@ -71,6 +71,7 @@
 
     /* Fill buffer with single UTF-8 string */
     (void)vsnprintf((char*)utf8buf, sizeof(utf8buf), format, ap);
+    utf8buf[sizeof(utf8buf) - 1] = 0;
     len = (int)strlen((char*)utf8buf);
 
     /* Convert to platform encoding (ignore errors, dangerous area) */
--- a/src/jdk.jdwp.agent/share/native/libjdwp/error_messages.h	Mon Dec 11 06:58:14 2017 +0530
+++ b/src/jdk.jdwp.agent/share/native/libjdwp/error_messages.h	Mon Dec 11 08:20:05 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, 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
@@ -47,7 +47,7 @@
     #define THIS_FILE __FILE__
 #endif
 
-#define EXIT_ERROR(error,msg) \
+#define EXIT_ERROR(error, msg) \
         { \
                 print_message(stderr, "JDWP exit error ", "\n", \
                         "%s(%d): %s [%s:%d]", \
@@ -56,21 +56,21 @@
                 debugInit_exit((jvmtiError)error, msg); \
         }
 
-#define JDI_ASSERT(expression)  \
-do {                            \
-    if (gdata && gdata->assertOn && !(expression)) {            \
+#define JDI_ASSERT(expression) \
+do { \
+    if (gdata && gdata->assertOn && !(expression)) { \
         jdiAssertionFailed(THIS_FILE, __LINE__, #expression); \
-    }                                           \
+    } \
 } while (0)
 
-#define JDI_ASSERT_MSG(expression, msg)  \
-do {                            \
-    if (gdata && gdata->assertOn && !(expression)) {            \
+#define JDI_ASSERT_MSG(expression, msg) \
+do { \
+    if (gdata && gdata->assertOn && !(expression)) { \
         jdiAssertionFailed(THIS_FILE, __LINE__, msg); \
-    }                                           \
+    } \
 } while (0)
 
-#define JDI_ASSERT_FAILED(msg)  \
+#define JDI_ASSERT_FAILED(msg) \
    jdiAssertionFailed(THIS_FILE, __LINE__, msg)
 
 void do_pause(void);
--- a/src/jdk.jdwp.agent/share/native/libjdwp/eventHandler.c	Mon Dec 11 06:58:14 2017 +0530
+++ b/src/jdk.jdwp.agent/share/native/libjdwp/eventHandler.c	Mon Dec 11 08:20:05 2017 +0100
@@ -471,11 +471,8 @@
     jbyte eventSessionID = currentSessionID;
     struct bag *eventBag = eventHelper_createEventBag();
 
-    if (eventBag == NULL) {
-        /* TO DO: Report, but don't die
-         */
-        JDI_ASSERT(eventBag != NULL);
-    }
+    /* TO DO: Report null error, but don't die */
+    JDI_ASSERT(eventBag != NULL);
 
     /* Signature needs to last, so convert extra copy to
      * classname
--- a/src/jdk.jdwp.agent/share/native/libjdwp/invoker.c	Mon Dec 11 06:58:14 2017 +0530
+++ b/src/jdk.jdwp.agent/share/native/libjdwp/invoker.c	Mon Dec 11 08:20:05 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2017, 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
@@ -808,7 +808,6 @@
         mustReleaseReturnValue = request->invokeType == INVOKE_CONSTRUCTOR ||
            returnTypeTag(request->methodSignature) == JDWP_TAG(OBJECT) ||
            returnTypeTag(request->methodSignature) == JDWP_TAG(ARRAY);
-
     }
 
     /*
--- a/src/jdk.jdwp.agent/share/native/libjdwp/log_messages.c	Mon Dec 11 06:58:14 2017 +0530
+++ b/src/jdk.jdwp.agent/share/native/libjdwp/log_messages.c	Mon Dec 11 08:20:05 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, 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
@@ -187,6 +187,7 @@
             /* Construct message string. */
             va_start(ap, format);
             (void)vsnprintf(message, sizeof(message), format, ap);
+            message[sizeof(message) - 1] = 0;
             va_end(ap);
 
             get_time_stamp(datetime, sizeof(datetime));