8243936: NonWriteable system properties are actually writeable

Reviewed-by: iklam, dcubed
This commit is contained in:
David Holmes 2020-05-28 02:58:56 -04:00
parent 60ce159dad
commit 686ca5ae49
3 changed files with 77 additions and 20 deletions

View file

@ -2144,7 +2144,7 @@ bool Arguments::check_vm_args_consistency() {
if (status && EnableJVMCI) {
PropertyList_unique_add(&_system_properties, "jdk.internal.vm.ci.enabled", "true",
AddProperty, UnwriteableProperty, InternalProperty);
if (!create_numbered_property("jdk.module.addmods", "jdk.internal.vm.ci", addmods_count++)) {
if (!create_numbered_module_property("jdk.module.addmods", "jdk.internal.vm.ci", addmods_count++)) {
return false;
}
}
@ -2208,7 +2208,9 @@ bool Arguments::parse_uintx(const char* value,
return false;
}
bool Arguments::create_property(const char* prop_name, const char* prop_value, PropertyInternal internal) {
bool Arguments::create_module_property(const char* prop_name, const char* prop_value, PropertyInternal internal) {
assert(is_internal_module_property(prop_name) ||
strcmp(prop_name, "jdk.module.illegalAccess") == 0, "unknown module property: '%s'", prop_name);
size_t prop_len = strlen(prop_name) + strlen(prop_value) + 2;
char* property = AllocateHeap(prop_len, mtArguments);
int ret = jio_snprintf(property, prop_len, "%s=%s", prop_name, prop_value);
@ -2216,12 +2218,18 @@ bool Arguments::create_property(const char* prop_name, const char* prop_value, P
FreeHeap(property);
return false;
}
bool added = add_property(property, UnwriteableProperty, internal);
// These are not strictly writeable properties as they cannot be set via -Dprop=val. But that
// is enforced by checking is_internal_module_property(). We need the property to be writeable so
// that multiple occurrences of the associated flag just causes the existing property value to be
// replaced ("last option wins"). Otherwise we would need to keep track of the flags and only convert
// to a property after we have finished flag processing.
bool added = add_property(property, WriteableProperty, internal);
FreeHeap(property);
return added;
}
bool Arguments::create_numbered_property(const char* prop_base_name, const char* prop_value, unsigned int count) {
bool Arguments::create_numbered_module_property(const char* prop_base_name, const char* prop_value, unsigned int count) {
assert(is_internal_module_property(prop_base_name), "unknown module property: '%s'", prop_base_name);
const unsigned int props_count_limit = 1000;
const int max_digits = 3;
const int extra_symbols_count = 3; // includes '.', '=', '\0'
@ -2383,7 +2391,7 @@ int Arguments::process_patch_mod_option(const char* patch_mod_tail, bool* patch_
// The path piece begins one past the module_equal sign
add_patch_mod_prefix(module_name, module_equal + 1, patch_mod_javabase);
FREE_C_HEAP_ARRAY(char, module_name);
if (!create_numbered_property("jdk.module.patch", patch_mod_tail, patch_mod_count++)) {
if (!create_numbered_module_property("jdk.module.patch", patch_mod_tail, patch_mod_count++)) {
return JNI_ENOMEM;
}
} else {
@ -2528,31 +2536,31 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, bool* patch_m
add_init_library(name, options);
}
} else if (match_option(option, "--add-reads=", &tail)) {
if (!create_numbered_property("jdk.module.addreads", tail, addreads_count++)) {
if (!create_numbered_module_property("jdk.module.addreads", tail, addreads_count++)) {
return JNI_ENOMEM;
}
} else if (match_option(option, "--add-exports=", &tail)) {
if (!create_numbered_property("jdk.module.addexports", tail, addexports_count++)) {
if (!create_numbered_module_property("jdk.module.addexports", tail, addexports_count++)) {
return JNI_ENOMEM;
}
} else if (match_option(option, "--add-opens=", &tail)) {
if (!create_numbered_property("jdk.module.addopens", tail, addopens_count++)) {
if (!create_numbered_module_property("jdk.module.addopens", tail, addopens_count++)) {
return JNI_ENOMEM;
}
} else if (match_option(option, "--add-modules=", &tail)) {
if (!create_numbered_property("jdk.module.addmods", tail, addmods_count++)) {
if (!create_numbered_module_property("jdk.module.addmods", tail, addmods_count++)) {
return JNI_ENOMEM;
}
} else if (match_option(option, "--limit-modules=", &tail)) {
if (!create_property("jdk.module.limitmods", tail, InternalProperty)) {
if (!create_module_property("jdk.module.limitmods", tail, InternalProperty)) {
return JNI_ENOMEM;
}
} else if (match_option(option, "--module-path=", &tail)) {
if (!create_property("jdk.module.path", tail, ExternalProperty)) {
if (!create_module_property("jdk.module.path", tail, ExternalProperty)) {
return JNI_ENOMEM;
}
} else if (match_option(option, "--upgrade-module-path=", &tail)) {
if (!create_property("jdk.module.upgrade.path", tail, ExternalProperty)) {
if (!create_module_property("jdk.module.upgrade.path", tail, ExternalProperty)) {
return JNI_ENOMEM;
}
} else if (match_option(option, "--patch-module=", &tail)) {
@ -2562,7 +2570,7 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, bool* patch_m
return res;
}
} else if (match_option(option, "--illegal-access=", &tail)) {
if (!create_property("jdk.module.illegalAccess", tail, ExternalProperty)) {
if (!create_module_property("jdk.module.illegalAccess", tail, ExternalProperty)) {
return JNI_ENOMEM;
}
// -agentlib and -agentpath
@ -2606,7 +2614,7 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, bool* patch_m
jio_snprintf(options, length, "%s", tail);
add_instrument_agent("instrument", options, false);
// java agents need module java.instrument
if (!create_numbered_property("jdk.module.addmods", "java.instrument", addmods_count++)) {
if (!create_numbered_module_property("jdk.module.addmods", "java.instrument", addmods_count++)) {
return JNI_ENOMEM;
}
}
@ -2787,7 +2795,7 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, bool* patch_m
return JNI_EINVAL;
}
// management agent in module jdk.management.agent
if (!create_numbered_property("jdk.module.addmods", "jdk.management.agent", addmods_count++)) {
if (!create_numbered_module_property("jdk.module.addmods", "jdk.management.agent", addmods_count++)) {
return JNI_ENOMEM;
}
#else
@ -4314,14 +4322,15 @@ void Arguments::PropertyList_unique_add(SystemProperty** plist, const char* k, c
if (plist == NULL)
return;
// If property key exist then update with new value.
// If property key exists and is writeable, then update with new value.
// Trying to update a non-writeable property is silently ignored.
SystemProperty* prop;
for (prop = *plist; prop != NULL; prop = prop->next()) {
if (strcmp(k, prop->key()) == 0) {
if (append == AppendProperty) {
prop->append_value(v);
prop->append_writeable_value(v);
} else {
prop->set_value(v);
prop->set_writeable_value(v);
}
return;
}