8199924: Solaris: Correctly enqueue null arguments of attach operations
authorclanger
Fri, 23 Mar 2018 09:26:59 +0100
changeset 49288 6e2d71029781
parent 49287 c84772a698c8
child 49289 148e29df1644
8199924: Solaris: Correctly enqueue null arguments of attach operations Reviewed-by: dcubed, dholmes
src/jdk.attach/solaris/native/libattach/VirtualMachineImpl.c
--- a/src/jdk.attach/solaris/native/libattach/VirtualMachineImpl.c	Thu Mar 22 23:49:48 2018 +0000
+++ b/src/jdk.attach/solaris/native/libattach/VirtualMachineImpl.c	Fri Mar 23 09:26:59 2018 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2018, 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
@@ -231,7 +231,7 @@
     int table_size = sizeof(error_messages) / sizeof(error_messages[0]);
     int i;
 
-    for (i=0; i<table_size; i++) {
+    for (i = 0; i < table_size; i++) {
         if (err == error_messages[i].err) {
             return error_messages[i].msg;
         }
@@ -293,7 +293,7 @@
      */
     arg_count = (*env)->GetArrayLength(env, args);
 
-    for (i=0; i<arg_count; i++) {
+    for (i = 0; i < arg_count; i++) {
         jobject obj = (*env)->GetObjectArrayElement(env, args, i);
         if (obj != NULL) {
             cstr = JNU_GetStringPlatformChars(env, obj, &isCopy);
@@ -314,6 +314,15 @@
                     return -1;
                 }
             }
+        } else {
+            char* newbuf = (char*)realloc(buf, size + 1);
+            if (newbuf == NULL) {
+                free(buf);
+                JNU_ThrowOutOfMemoryError(env, "realloc failed");
+                return -1;
+            }
+            buf = newbuf;
+            buf[size++] = 0;
         }
         if ((*env)->ExceptionOccurred(env)) {
             free(buf);