mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-19 10:34:38 +02:00
8178118: Arguments::create_numbered_property allocates wrong buffer in case count > 99
Reviewed-by: dholmes, dcubed, sspitsyn
This commit is contained in:
parent
3af1da4533
commit
11a8c7a52f
1 changed files with 10 additions and 3 deletions
|
@ -2587,19 +2587,26 @@ bool Arguments::create_property(const char* prop_name, const char* prop_value, P
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Arguments::create_numbered_property(const char* prop_base_name, const char* prop_value, unsigned int count) {
|
bool Arguments::create_numbered_property(const char* prop_base_name, const char* prop_value, unsigned int count) {
|
||||||
// Make sure count is < 1,000. Otherwise, memory allocation will be too small.
|
const unsigned int props_count_limit = 1000;
|
||||||
if (count < 1000) {
|
const int max_digits = 3;
|
||||||
size_t prop_len = strlen(prop_base_name) + strlen(prop_value) + 5;
|
const int extra_symbols_count = 3; // includes '.', '=', '\0'
|
||||||
|
|
||||||
|
// Make sure count is < props_count_limit. Otherwise, memory allocation will be too small.
|
||||||
|
if (count < props_count_limit) {
|
||||||
|
size_t prop_len = strlen(prop_base_name) + strlen(prop_value) + max_digits + extra_symbols_count;
|
||||||
char* property = AllocateHeap(prop_len, mtArguments);
|
char* property = AllocateHeap(prop_len, mtArguments);
|
||||||
int ret = jio_snprintf(property, prop_len, "%s.%d=%s", prop_base_name, count, prop_value);
|
int ret = jio_snprintf(property, prop_len, "%s.%d=%s", prop_base_name, count, prop_value);
|
||||||
if (ret < 0 || ret >= (int)prop_len) {
|
if (ret < 0 || ret >= (int)prop_len) {
|
||||||
FreeHeap(property);
|
FreeHeap(property);
|
||||||
|
jio_fprintf(defaultStream::error_stream(), "Failed to create property %s.%d=%s\n", prop_base_name, count, prop_value);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool added = add_property(property, UnwriteableProperty, InternalProperty);
|
bool added = add_property(property, UnwriteableProperty, InternalProperty);
|
||||||
FreeHeap(property);
|
FreeHeap(property);
|
||||||
return added;
|
return added;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jio_fprintf(defaultStream::error_stream(), "Property count limit exceeded: %s, limit=%d\n", prop_base_name, props_count_limit);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue