changeset 54931:5f02b8c98b35

8218939: vm/mlvm/anonloader/stress/byteMutation crashed on windows Reviewed-by: kbarrett, coleenp, mikael, iignatyev
author dholmes
date Thu, 14 Feb 2019 22:57:37 -0500
parents f940579715a5
children 291944be3f92
files src/hotspot/share/classfile/classFileParser.cpp test/hotspot/jtreg/runtime/classFileParserBug/TestBadClassName.java
diffstat 2 files changed, 24 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/classfile/classFileParser.cpp	Thu Feb 14 15:27:46 2019 -0800
+++ b/src/hotspot/share/classfile/classFileParser.cpp	Thu Feb 14 22:57:37 2019 -0500
@@ -5020,7 +5020,8 @@
   return true;
 }
 
-// Take pointer to a string. Skip over the longest part of the string that could
+// Take pointer to a UTF8 byte string (not NUL-terminated).
+// Skip over the longest part of the string that could
 // be taken as a fieldname. Allow '/' if slash_ok is true.
 // Return a pointer to just past the fieldname.
 // Return NULL if no fieldname at all was found, or in the case of slash_ok
@@ -5098,7 +5099,8 @@
   return (not_first_ch) ? p : NULL;
 }
 
-// Take pointer to a string. Skip over the longest part of the string that could
+// Take pointer to a UTF8 byte string (not NUL-terminated).
+// Skip over the longest part of the string that could
 // be taken as a field signature. Allow "void" if void_ok.
 // Return a pointer to just past the signature.
 // Return NULL if no legal signature is found.
@@ -5132,7 +5134,7 @@
       else {
         // Skip leading 'L' and ignore first appearance of ';'
         signature++;
-        char* c = strchr((char*) signature, ';');
+        const char* c = (const char*) memchr(signature, ';', length - 1);
         // Format check signature
         if (c != NULL) {
           int newlen = c - (char*) signature;
@@ -5199,7 +5201,7 @@
     Exceptions::fthrow(
       THREAD_AND_LOCATION,
       vmSymbols::java_lang_ClassFormatError(),
-      "Illegal class name \"%s\" in class file %s", bytes,
+      "Illegal class name \"%.*s\" in class file %s", length, bytes,
       _class_name->as_C_string()
     );
     return;
@@ -5232,7 +5234,7 @@
     Exceptions::fthrow(
       THREAD_AND_LOCATION,
       vmSymbols::java_lang_ClassFormatError(),
-      "Illegal field name \"%s\" in class %s", bytes,
+      "Illegal field name \"%.*s\" in class %s", length, bytes,
       _class_name->as_C_string()
     );
     return;
@@ -5269,7 +5271,7 @@
     Exceptions::fthrow(
       THREAD_AND_LOCATION,
       vmSymbols::java_lang_ClassFormatError(),
-      "Illegal method name \"%s\" in class %s", bytes,
+      "Illegal method name \"%.*s\" in class %s", length, bytes,
       _class_name->as_C_string()
     );
     return;
--- a/test/hotspot/jtreg/runtime/classFileParserBug/TestBadClassName.java	Thu Feb 14 15:27:46 2019 -0800
+++ b/test/hotspot/jtreg/runtime/classFileParserBug/TestBadClassName.java	Thu Feb 14 22:57:37 2019 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8158297
+ * @bug 8158297 8218939
  * @summary Constant pool utf8 entry for class name cannot have empty qualified name '//'
  * @compile p1/BadInterface1.jcod
  * @compile p1/BadInterface2.jcod
@@ -37,20 +37,32 @@
 
         System.out.println("Regression test for bug 8042660");
 
-        // Test class name with p1//BadInterface2
+        // Test class name with p1//BadInterface1
+        String expected = "Illegal class name \"p1//BadInterface1\" in class file UseBadInterface1";
         try {
             Class newClass = Class.forName("UseBadInterface1");
             throw new RuntimeException("Expected ClassFormatError exception not thrown");
         } catch (java.lang.ClassFormatError e) {
+            check(e, expected);
             System.out.println("Test UseBadInterface1 passed test case with illegal class name");
         }
 
         // Test class name with p1/BadInterface2/
+        expected = "Illegal class name \"p1/BadInterface2/\" in class file UseBadInterface2";
         try {
             Class newClass = Class.forName("UseBadInterface2");
             throw new RuntimeException("Expected ClassFormatError exception not thrown");
         } catch (java.lang.ClassFormatError e) {
-            System.out.println("Test UseBadInterface1 passed test case with illegal class name");
+            check(e, expected);
+            System.out.println("Test UseBadInterface2 passed test case with illegal class name");
+        }
+    }
+
+    static void check(ClassFormatError c, String expected) {
+        if (!c.getMessage().equals(expected)) {
+            throw new RuntimeException("Wrong ClassFormatError - expected: \"" +
+                                       expected + "\", got \"" +
+                                       c.getMessage() + "\"");
         }
     }
 }