8067030: JDWP crash in transport_startTransport on OOM
authordsamersoff
Thu, 11 Dec 2014 06:49:12 -0800
changeset 27959 701e99e828ca
parent 27958 51c87937ff0c
child 27960 52310706ed47
8067030: JDWP crash in transport_startTransport on OOM Summary: Check for result of jvmtiAllocate Reviewed-by: jbachorik, sspitsyn
jdk/src/jdk.jdwp.agent/share/native/libjdwp/transport.c
--- a/jdk/src/jdk.jdwp.agent/share/native/libjdwp/transport.c	Thu Dec 11 15:10:35 2014 +0300
+++ b/jdk/src/jdk.jdwp.agent/share/native/libjdwp/transport.c	Thu Dec 11 06:49:12 2014 -0800
@@ -66,8 +66,10 @@
         len = (int)strlen(msg);
         maxlen = len+len/2+2; /* Should allow for plenty of room */
         utf8msg = (jbyte*)jvmtiAllocate(maxlen+1);
-        (void)utf8FromPlatform(msg, len, utf8msg, maxlen);
-        utf8msg[maxlen] = 0;
+        if (utf8msg != NULL) {
+           (void)utf8FromPlatform(msg, len, utf8msg, maxlen);
+           utf8msg[maxlen] = 0;
+        }
     }
     if (rv == JDWPTRANSPORT_ERROR_NONE) {
         ERROR_MESSAGE(("transport error %d: %s",err, utf8msg));
@@ -391,6 +393,10 @@
     /* Convert commandLine from UTF-8 to platform encoding */
     len = (int)strlen(commandLine);
     buf = jvmtiAllocate(len*3+3);
+    if (buf == NULL) {
+        jvmtiDeallocate(commandLine);
+        return JDWP_ERROR(OUT_OF_MEMORY);
+    }
     (void)utf8ToPlatform((jbyte*)commandLine, len, buf, len*3+3);
 
     /* Exec commandLine */
@@ -447,21 +453,23 @@
         if (info == NULL) {
             return JDWP_ERROR(OUT_OF_MEMORY);
         }
+        info->timeout = timeout;
+
         info->name = jvmtiAllocate((int)strlen(name)+1);
-        (void)strcpy(info->name, name);
-        info->address = NULL;
-        info->timeout = timeout;
         if (info->name == NULL) {
             serror = JDWP_ERROR(OUT_OF_MEMORY);
             goto handleError;
         }
+        (void)strcpy(info->name, name);
+
+        info->address = NULL;
         if (address != NULL) {
             info->address = jvmtiAllocate((int)strlen(address)+1);
-            (void)strcpy(info->address, address);
             if (info->address == NULL) {
                 serror = JDWP_ERROR(OUT_OF_MEMORY);
                 goto handleError;
             }
+            (void)strcpy(info->address, address);
         }
 
         info->transport = trans;
@@ -478,6 +486,10 @@
          */
         len = (int)strlen(name) + (int)strlen(retAddress) + 2; /* ':' and '\0' */
         prop_value = (char*)jvmtiAllocate(len);
+        if (prop_value == NULL) {
+            serror = JDWP_ERROR(OUT_OF_MEMORY);
+            goto handleError;
+        }
         strcpy(prop_value, name);
         strcat(prop_value, ":");
         strcat(prop_value, retAddress);