8003689: MemTracker::init_tracking_options() reads outside array if commandline argument is empty
authorzgu
Wed, 28 Nov 2012 09:19:38 -0500
changeset 14575 be194f2e2ba1
parent 14573 2dd27e5691f7
child 14576 f6e3d7795d57
8003689: MemTracker::init_tracking_options() reads outside array if commandline argument is empty Summary: Fixed potential buffer overrun when giving empty option to NativeMemoryTracking commandline option Reviewed-by: ctornqvi, hseigel, kvn
hotspot/src/share/vm/services/memTracker.cpp
--- a/hotspot/src/share/vm/services/memTracker.cpp	Wed Nov 21 21:26:12 2012 -0500
+++ b/hotspot/src/share/vm/services/memTracker.cpp	Wed Nov 28 09:19:38 2012 -0500
@@ -69,15 +69,12 @@
 
 void MemTracker::init_tracking_options(const char* option_line) {
   _tracking_level = NMT_off;
-  if (strncmp(option_line, "=summary", 8) == 0) {
+  if (strcmp(option_line, "=summary") == 0) {
     _tracking_level = NMT_summary;
-  } else if (strncmp(option_line, "=detail", 7) == 0) {
+  } else if (strcmp(option_line, "=detail") == 0) {
     _tracking_level = NMT_detail;
-  } else {
-    char msg[255];
-    //+1 to remove the '=' character
-    jio_snprintf(msg, 255, "Unknown option given to XX:NativeMemoryTracking: %s", option_line+1);
-    vm_exit_during_initialization(msg, NULL);
+  } else if (strcmp(option_line, "=off") != 0) {
+    vm_exit_during_initialization("Syntax error, expecting -XX:NativeMemoryTracking=[off|summary|detail]", NULL);
   }
 }