8277029: JMM GetDiagnosticXXXInfo APIs should verify output array sizes

Reviewed-by: dholmes, sspitsyn
This commit is contained in:
Thomas Stuefe 2021-11-16 09:49:03 +00:00
parent 1d79cfd3a1
commit b8d33a2a4e
3 changed files with 9 additions and 6 deletions

View File

@ -333,7 +333,8 @@ typedef struct jmmInterface_1_ {
void (JNICALL *GetDiagnosticCommandArgumentsInfo)
(JNIEnv *env,
jstring commandName,
dcmdArgInfo *infoArray);
dcmdArgInfo *infoArray,
jint count);
jstring (JNICALL *ExecuteDiagnosticCommand)
(JNIEnv *env,
jstring command);

View File

@ -2015,7 +2015,7 @@ JVM_ENTRY(void, jmm_GetDiagnosticCommandInfo(JNIEnv *env, jobjectArray cmds,
JVM_END
JVM_ENTRY(void, jmm_GetDiagnosticCommandArgumentsInfo(JNIEnv *env,
jstring command, dcmdArgInfo* infoArray))
jstring command, dcmdArgInfo* infoArray, jint count))
ResourceMark rm(THREAD);
oop cmd = JNIHandles::resolve_external_guard(command);
if (cmd == NULL) {
@ -2039,10 +2039,12 @@ JVM_ENTRY(void, jmm_GetDiagnosticCommandArgumentsInfo(JNIEnv *env,
}
DCmdMark mark(dcmd);
GrowableArray<DCmdArgumentInfo*>* array = dcmd->argument_info_array();
if (array->length() == 0) {
return;
const int num_args = array->length();
if (num_args != count) {
assert(false, "jmm_GetDiagnosticCommandArgumentsInfo count mismatch (%d vs %d)", count, num_args);
THROW_MSG(vmSymbols::java_lang_InternalError(), "jmm_GetDiagnosticCommandArgumentsInfo count mismatch");
}
for (int i = 0; i < array->length(); i++) {
for (int i = 0; i < num_args; i++) {
infoArray[i].name = array->at(i)->name();
infoArray[i].description = array->at(i)->description();
infoArray[i].type = array->at(i)->type();

View File

@ -79,7 +79,7 @@ jobject getDiagnosticCommandArgumentInfoArray(JNIEnv *env, jstring command,
return NULL;
}
jmm_interface->GetDiagnosticCommandArgumentsInfo(env, command,
dcmd_arg_info_array);
dcmd_arg_info_array, num_arg);
dcmdArgInfoCls = (*env)->FindClass(env,
"com/sun/management/internal/DiagnosticCommandArgumentInfo");
POP_EXCEPTION_CHECK_AND_FREE(0, dcmd_arg_info_array);