File tree Expand file tree Collapse file tree 1 file changed +8
-9
lines changed
src/java.base/share/native/libjava Expand file tree Collapse file tree 1 file changed +8
-9
lines changed Original file line number Diff line number Diff line change 2323 * questions.
2424 */
2525
26+ #include <limits.h>
2627#include <stdlib.h>
2728#include <string.h>
2829
3536 * such as "z:" need to be appended with a "." so we
3637 * must allocate at least 4 bytes to allow room for
3738 * this expansion. See 4235353 for details.
39+ * This macro returns NULL if the requested size is
40+ * negative, or the size is INT_MAX as the macro adds 1
41+ * that overflows into negative value.
3842 */
39- #define MALLOC_MIN4 (len ) ((char *)malloc((len) + 1 < 4 ? 4 : (len) + 1))
43+ #define MALLOC_MIN4 (len ) ((unsigned)(len) >= INT_MAX ? \
44+ NULL : \
45+ ((char *)malloc((len) + 1 < 4 ? 4 : (len) + 1)))
4046
4147/**
4248 * Throw a Java exception by name. Similar to SignalError.
@@ -885,17 +891,10 @@ getStringUTF8(JNIEnv *env, jstring jstr)
885891 }
886892 }
887893
888- // Check `jint` overflow
889- if (rlen < 0 ) {
890- (* env )-> ReleasePrimitiveArrayCritical (env , value , str , 0 );
891- JNU_ThrowOutOfMemoryError (env , "requested array size exceeds VM limit" );
892- return NULL ;
893- }
894-
895894 result = MALLOC_MIN4 (rlen );
896895 if (result == NULL ) {
897896 (* env )-> ReleasePrimitiveArrayCritical (env , value , str , 0 );
898- JNU_ThrowOutOfMemoryError (env , 0 );
897+ JNU_ThrowOutOfMemoryError (env , "requested array size exceeds VM limit" );
899898 return NULL ;
900899 }
901900
You can’t perform that action at this time.
0 commit comments