7158804: Improve config file parsing
authorkamg
Fri, 08 Jun 2012 12:49:12 -0400
changeset 14139 339b184759f9
parent 14138 d62d6721cf2a
child 14140 33893458b2e3
7158804: Improve config file parsing Summary: Check buffer length when reading Reviewed-by: dholmes, dcubed
hotspot/src/share/vm/compiler/compilerOracle.cpp
hotspot/src/share/vm/runtime/arguments.cpp
hotspot/test/runtime/7158804/Test7158804.sh
--- a/hotspot/src/share/vm/compiler/compilerOracle.cpp	Wed May 23 12:11:25 2012 -0700
+++ b/hotspot/src/share/vm/compiler/compilerOracle.cpp	Fri Jun 08 12:49:12 2012 -0400
@@ -572,7 +572,7 @@
   char token[1024];
   int  pos = 0;
   int  c = getc(stream);
-  while(c != EOF && pos < (sizeof(token)-1)) {
+  while(c != EOF && pos < (int)(sizeof(token)-1)) {
     if (c == '\n') {
       token[pos++] = '\0';
       parse_from_line(token);
@@ -593,7 +593,7 @@
   int  pos = 0;
   const char* sp = str;
   int  c = *sp++;
-  while (c != '\0' && pos < (sizeof(token)-1)) {
+  while (c != '\0' && pos < (int)(sizeof(token)-1)) {
     if (c == '\n') {
       token[pos++] = '\0';
       parse_line(token);
--- a/hotspot/src/share/vm/runtime/arguments.cpp	Wed May 23 12:11:25 2012 -0700
+++ b/hotspot/src/share/vm/runtime/arguments.cpp	Fri Jun 08 12:49:12 2012 -0400
@@ -860,7 +860,7 @@
   bool result         = true;
 
   int c = getc(stream);
-  while(c != EOF) {
+  while(c != EOF && pos < (int)(sizeof(token)-1)) {
     if (in_white_space) {
       if (in_comment) {
         if (c == '\n') in_comment = false;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/7158804/Test7158804.sh	Fri Jun 08 12:49:12 2012 -0400
@@ -0,0 +1,30 @@
+#!/bin/sh
+#
+# Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+
+##
+## @test Test7158804.sh
+## @bug 7158804
+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