Skip to content

Commit

Permalink
8308748: JNU_GetStringPlatformChars may write to String's internal me…
Browse files Browse the repository at this point in the history
…mory array

Reviewed-by: dholmes, rriggs, alanb
  • Loading branch information
rudihorn authored and Alan Bateman committed Jun 6, 2023
1 parent 01455a0 commit 8f0839b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/java.base/share/native/libjava/jni_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ getStringUTF8(JNIEnv *env, jstring jstr, jboolean strict)
// we need two bytes for each latin-1 char above 127 (negative jbytes)
for (i = 0; i < len; i++) {
if (strict && str[i] == 0) {
(*env)->ReleasePrimitiveArrayCritical(env, value, str, 0);
(*env)->ReleasePrimitiveArrayCritical(env, value, str, JNI_ABORT);
JNU_ThrowIllegalArgumentException(env, "NUL character not allowed in platform string");
return NULL;
}
Expand All @@ -926,7 +926,7 @@ getStringUTF8(JNIEnv *env, jstring jstr, jboolean strict)

result = MALLOC_MIN4(rlen);
if (result == NULL) {
(*env)->ReleasePrimitiveArrayCritical(env, value, str, 0);
(*env)->ReleasePrimitiveArrayCritical(env, value, str, JNI_ABORT);
JNU_ThrowOutOfMemoryError(env, "requested array size exceeds VM limit");
return NULL;
}
Expand All @@ -940,7 +940,7 @@ getStringUTF8(JNIEnv *env, jstring jstr, jboolean strict)
result[ri++] = c;
}
}
(*env)->ReleasePrimitiveArrayCritical(env, value, str, 0);
(*env)->ReleasePrimitiveArrayCritical(env, value, str, JNI_ABORT);
result[rlen] = '\0';
return result;
}
Expand Down

1 comment on commit 8f0839b

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.