Mercurial > hg > truffle
diff src/share/vm/prims/jniCheck.cpp @ 12819:f9be370a7d54
8025922: JNI access to Strings need to check if the value field is non-null
Reviewed-by: dholmes, dcubed
author | sla |
---|---|
date | Sat, 05 Oct 2013 15:18:57 +0200 |
parents | c29568b733d2 |
children | de6a9e811145 |
line wrap: on
line diff
--- a/src/share/vm/prims/jniCheck.cpp Fri Oct 04 13:01:07 2013 +0200 +++ b/src/share/vm/prims/jniCheck.cpp Sat Oct 05 15:18:57 2013 +0200 @@ -1324,18 +1324,19 @@ IN_VM( checkString(thr, str); ) + jchar* newResult = NULL; const jchar *result = UNCHECKED()->GetStringChars(env,str,isCopy); assert (isCopy == NULL || *isCopy == JNI_TRUE, "GetStringChars didn't return a copy as expected"); - - size_t len = UNCHECKED()->GetStringLength(env,str) + 1; // + 1 for NULL termination - jint* tagLocation = (jint*) AllocateHeap(len * sizeof(jchar) + sizeof(jint), mtInternal); - *tagLocation = STRING_TAG; - jchar* newResult = (jchar*) (tagLocation + 1); - memcpy(newResult, result, len * sizeof(jchar)); - // Avoiding call to UNCHECKED()->ReleaseStringChars() since that will fire unexpected dtrace probes - // Note that the dtrace arguments for the allocated memory will not match up with this solution. - FreeHeap((char*)result); - + if (result != NULL) { + size_t len = UNCHECKED()->GetStringLength(env,str) + 1; // + 1 for NULL termination + jint* tagLocation = (jint*) AllocateHeap(len * sizeof(jchar) + sizeof(jint), mtInternal); + *tagLocation = STRING_TAG; + newResult = (jchar*) (tagLocation + 1); + memcpy(newResult, result, len * sizeof(jchar)); + // Avoiding call to UNCHECKED()->ReleaseStringChars() since that will fire unexpected dtrace probes + // Note that the dtrace arguments for the allocated memory will not match up with this solution. + FreeHeap((char*)result); + } functionExit(env); return newResult; JNI_END @@ -1394,18 +1395,19 @@ IN_VM( checkString(thr, str); ) + char* newResult = NULL; const char *result = UNCHECKED()->GetStringUTFChars(env,str,isCopy); assert (isCopy == NULL || *isCopy == JNI_TRUE, "GetStringUTFChars didn't return a copy as expected"); - - size_t len = strlen(result) + 1; // + 1 for NULL termination - jint* tagLocation = (jint*) AllocateHeap(len + sizeof(jint), mtInternal); - *tagLocation = STRING_UTF_TAG; - char* newResult = (char*) (tagLocation + 1); - strcpy(newResult, result); - // Avoiding call to UNCHECKED()->ReleaseStringUTFChars() since that will fire unexpected dtrace probes - // Note that the dtrace arguments for the allocated memory will not match up with this solution. - FreeHeap((char*)result, mtInternal); - + if (result != NULL) { + size_t len = strlen(result) + 1; // + 1 for NULL termination + jint* tagLocation = (jint*) AllocateHeap(len + sizeof(jint), mtInternal); + *tagLocation = STRING_UTF_TAG; + newResult = (char*) (tagLocation + 1); + strcpy(newResult, result); + // Avoiding call to UNCHECKED()->ReleaseStringUTFChars() since that will fire unexpected dtrace probes + // Note that the dtrace arguments for the allocated memory will not match up with this solution. + FreeHeap((char*)result, mtInternal); + } functionExit(env); return newResult; JNI_END