changeset 46367:6e532778cb35

8178118: Arguments::create_numbered_property allocates wrong buffer in case count > 99 Reviewed-by: dholmes, dcubed, sspitsyn Contributed-by: ekaterina.pavlova@oracle.com
author iignatyev
date Thu, 06 Apr 2017 14:07:21 -0700
parents 4c676683bdb9
children da05330bbc7b
files hotspot/src/share/vm/runtime/arguments.cpp
diffstat 1 files changed, 10 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/hotspot/src/share/vm/runtime/arguments.cpp	Tue Mar 21 11:25:18 2017 -0400
+++ b/hotspot/src/share/vm/runtime/arguments.cpp	Thu Apr 06 14:07:21 2017 -0700
@@ -2587,19 +2587,26 @@
 }
 
 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.
-  if (count < 1000) {
-    size_t prop_len = strlen(prop_base_name) + strlen(prop_value) + 5;
+  const unsigned int props_count_limit = 1000;
+  const int max_digits = 3;
+  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);
     int ret = jio_snprintf(property, prop_len, "%s.%d=%s", prop_base_name, count, prop_value);
     if (ret < 0 || ret >= (int)prop_len) {
       FreeHeap(property);
+      jio_fprintf(defaultStream::error_stream(), "Failed to create property %s.%d=%s\n", prop_base_name, count, prop_value);
       return false;
     }
     bool added = add_property(property, UnwriteableProperty, InternalProperty);
     FreeHeap(property);
     return added;
   }
+
+  jio_fprintf(defaultStream::error_stream(), "Property count limit exceeded: %s, limit=%d\n", prop_base_name, props_count_limit);
   return false;
 }