8192978: Missing checks and small fixes in jdwp library

Reviewed-by: cjplummer, sspitsyn
diff --git a/src/jdk.jdwp.agent/share/native/libjdwp/VirtualMachineImpl.c b/src/jdk.jdwp.agent/share/native/libjdwp/VirtualMachineImpl.c
index 8e1639c..767b1b3 100644
--- a/src/jdk.jdwp.agent/share/native/libjdwp/VirtualMachineImpl.c
+++ b/src/jdk.jdwp.agent/share/native/libjdwp/VirtualMachineImpl.c
@@ -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)
 {
diff --git a/src/jdk.jdwp.agent/share/native/libjdwp/error_messages.c b/src/jdk.jdwp.agent/share/native/libjdwp/error_messages.c
index d6a08c1..0cd00d6 100644
--- a/src/jdk.jdwp.agent/share/native/libjdwp/error_messages.c
+++ b/src/jdk.jdwp.agent/share/native/libjdwp/error_messages.c
@@ -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) */
diff --git a/src/jdk.jdwp.agent/share/native/libjdwp/error_messages.h b/src/jdk.jdwp.agent/share/native/libjdwp/error_messages.h
index bf37653..e25908c 100644
--- a/src/jdk.jdwp.agent/share/native/libjdwp/error_messages.h
+++ b/src/jdk.jdwp.agent/share/native/libjdwp/error_messages.h
@@ -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);
diff --git a/src/jdk.jdwp.agent/share/native/libjdwp/eventHandler.c b/src/jdk.jdwp.agent/share/native/libjdwp/eventHandler.c
index 2fc3d1b..ad4b773 100644
--- a/src/jdk.jdwp.agent/share/native/libjdwp/eventHandler.c
+++ b/src/jdk.jdwp.agent/share/native/libjdwp/eventHandler.c
@@ -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
diff --git a/src/jdk.jdwp.agent/share/native/libjdwp/invoker.c b/src/jdk.jdwp.agent/share/native/libjdwp/invoker.c
index d3d533b..8e2981d 100644
--- a/src/jdk.jdwp.agent/share/native/libjdwp/invoker.c
+++ b/src/jdk.jdwp.agent/share/native/libjdwp/invoker.c
@@ -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);
-
     }
 
     /*
diff --git a/src/jdk.jdwp.agent/share/native/libjdwp/log_messages.c b/src/jdk.jdwp.agent/share/native/libjdwp/log_messages.c
index a2607d1..287cebb 100644
--- a/src/jdk.jdwp.agent/share/native/libjdwp/log_messages.c
+++ b/src/jdk.jdwp.agent/share/native/libjdwp/log_messages.c
@@ -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));