Skip to content

Commit 6a35610

Browse files
authored
Merge pull request eclipse-openj9#5392 from sharon-wang/pr5353
(v0.14.0) Ignore empty and whitespace VM options
2 parents 600c106 + 1668953 commit 6a35610

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

runtime/vm/jvminit.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ UDATA runJVMOnLoad (J9JavaVM* vm, J9VMDllLoadInfo* loadInfo, char* options);
212212
static IDATA updateJavaAgentClasspath (J9JavaVM * vm);
213213
#endif /* J9VM_OPT_JVMTI */
214214
static void consumeVMArgs (J9JavaVM* vm, J9VMInitArgs* j9vm_args);
215+
static BOOLEAN isEmpty (const char * str);
215216

216217
#if (defined(J9VM_OPT_SIDECAR))
217218
static UDATA initializeJVMExtensionInterface (J9JavaVM* vm);
@@ -2392,9 +2393,10 @@ static UDATA checkArgsConsumed(J9PortLibrary* portLibrary, J9VMInitArgs* j9vm_ar
23922393
if (IS_CONSUMABLE( j9vm_args, i ) && !IS_CONSUMED( j9vm_args, i )) {
23932394
char* optString = j9vm_args->actualVMArgs->options[i].optionString;
23942395
char* envVar = j9vm_args->j9Options[i].fromEnvVar;
2395-
2396-
/* If ignoreUnrecognized is set to JNI_TRUE, we should not reject any unrecognized options beginning with -X or _ */
2397-
if (ignoreUnrecognized && optString && (!strncmp(optString, "-X", 2) || *optString=='_')) {
2396+
2397+
/* If ignoreUnrecognized is set to JNI_TRUE, we should not reject any options that are:
2398+
empty or contain only whitespace, or unrecognized options beginning with -X or _ */
2399+
if (ignoreUnrecognized && (NULL != optString) && (isEmpty(optString) || !strncmp(optString, "-X", 2) || *optString=='_')) {
23982400
continue;
23992401
}
24002402
if (REQUIRES_LIBRARY( j9vm_args, i )) {
@@ -2421,6 +2423,18 @@ static UDATA checkArgsConsumed(J9PortLibrary* portLibrary, J9VMInitArgs* j9vm_ar
24212423
return TRUE;
24222424
}
24232425

2426+
/* Returns TRUE if a string is empty or if it contains only whitespace characters. */
2427+
static BOOLEAN isEmpty(const char * str) {
2428+
BOOLEAN isEmpty = TRUE;
2429+
while('\0' != *str) {
2430+
if (0 == isspace((unsigned char) *str)) {
2431+
isEmpty = FALSE;
2432+
break;
2433+
}
2434+
str++;
2435+
}
2436+
return isEmpty;
2437+
}
24242438

24252439
/* Run using a pool_do after each initialization stage. If any errors were reported by libraries,
24262440
a flag is set to FALSE and the error is printed. See checkPostStage. */

0 commit comments

Comments
 (0)