changeset 9622:429210228042

8035930: Check jdk/src/windows/native/java/io/io_util_md.c for JNI pending exceptions Summary: malloc null return checks and pending exception checks Reviewed-by: alanb
author msheppar
date Fri, 30 May 2014 13:28:19 +0100
parents dd77d81f2911
children 289d5c0e4bd7
files src/windows/native/java/io/io_util_md.c
diffstat 1 files changed, 20 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/windows/native/java/io/io_util_md.c	Fri May 30 14:46:36 2014 +0400
+++ b/src/windows/native/java/io/io_util_md.c	Fri May 30 13:28:19 2014 +0100
@@ -161,10 +161,17 @@
             {
                  if (pathlen > max_path - 1) {
                      pathbuf = prefixAbpath(ps, pathlen, pathlen);
+                     if (pathbuf == NULL) {
+                         JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
+                         return NULL;
+                     }
                  } else {
                      pathbuf = (WCHAR*)malloc((pathlen + 6) * sizeof(WCHAR));
                      if (pathbuf != 0) {
                          wcscpy(pathbuf, ps);
+                     } else {
+                         JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
+                         return NULL;
                      }
                  }
             } else {
@@ -184,10 +191,17 @@
                 int dirlen = currentDirLength(ps, pathlen);
                 if (dirlen + pathlen + 1 > max_path - 1) {
                     pathbuf = prefixAbpath(ps, pathlen, dirlen + pathlen);
+                    if( pathbuf == NULL) {
+                        JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
+                        return NULL;
+                    }
                 } else {
                     pathbuf = (WCHAR*)malloc((pathlen + 6) * sizeof(WCHAR));
                     if (pathbuf != 0) {
                         wcscpy(pathbuf, ps);
+                    } else {
+                        JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
+                        return NULL;
                     }
                 }
             }
@@ -196,7 +210,9 @@
 
     if (pathlen == 0) {
         if (throwFNFE == JNI_TRUE) {
-            throwFileNotFoundException(env, path);
+            if (!(*env)->ExceptionCheck(env)) {
+                throwFileNotFoundException(env, path);
+            }
             return NULL;
         } else {
             pathbuf = (WCHAR*)malloc(sizeof(WCHAR));
@@ -204,7 +220,9 @@
         }
     }
     if (pathbuf == 0) {
-        JNU_ThrowOutOfMemoryError(env, 0);
+        if (!(*env)->ExceptionCheck(env)) {
+            JNU_ThrowOutOfMemoryError(env,  "native memory allocation failed");
+        }
         return NULL;
     }
     return pathbuf;