8204055: SIGSEGV in java -XX:
authordholmes
Thu, 31 May 2018 18:47:21 -0400
changeset 50335 01e20d8850e3
parent 50334 928a93482dd7
child 50336 1b6ea6bcd21a
child 56647 0d1c342d7337
8204055: SIGSEGV in java -XX: Reviewed-by: iklam, stuefe, ccheung
src/hotspot/share/utilities/stringUtils.cpp
test/hotspot/gtest/logging/test_logConfiguration.cpp
test/hotspot/jtreg/runtime/CommandLine/UnrecognizedVMOption.java
--- a/src/hotspot/share/utilities/stringUtils.cpp	Thu May 31 14:56:51 2018 -0700
+++ b/src/hotspot/share/utilities/stringUtils.cpp	Thu May 31 18:47:21 2018 -0400
@@ -23,6 +23,7 @@
  */
 
 #include "precompiled.hpp"
+#include "utilities/debug.hpp"
 #include "utilities/stringUtils.hpp"
 
 int StringUtils::replace_no_expand(char* string, const char* from, const char* to) {
@@ -43,9 +44,16 @@
 }
 
 double StringUtils::similarity(const char* str1, size_t len1, const char* str2, size_t len2) {
-  size_t total = len1 + len2;
+  assert(str1 != NULL && str2 != NULL, "sanity");
 
+  // filter out zero-length strings else we will underflow on len-1 below
+  if (len1 == 0 || len2 == 0) {
+    return 0.0;
+  }
+
+  size_t total = len1 + len2;
   size_t hit = 0;
+
   for (size_t i = 0; i < len1 - 1; i++) {
     for (size_t j = 0; j < len2 - 1; j++) {
       if ((str1[i] == str2[j]) && (str1[i+1] == str2[j+1])) {
--- a/test/hotspot/gtest/logging/test_logConfiguration.cpp	Thu May 31 14:56:51 2018 -0700
+++ b/test/hotspot/gtest/logging/test_logConfiguration.cpp	Thu May 31 18:47:21 2018 -0400
@@ -239,6 +239,7 @@
   EXPECT_FALSE(LogConfiguration::parse_command_line_arguments("all=invalid_level"));
   EXPECT_FALSE(LogConfiguration::parse_command_line_arguments("what=invalid"));
   EXPECT_FALSE(LogConfiguration::parse_command_line_arguments("all::invalid_decorator"));
+  EXPECT_FALSE(LogConfiguration::parse_command_line_arguments("*"));
 }
 
 // Test empty configuration options
--- a/test/hotspot/jtreg/runtime/CommandLine/UnrecognizedVMOption.java	Thu May 31 14:56:51 2018 -0700
+++ b/test/hotspot/jtreg/runtime/CommandLine/UnrecognizedVMOption.java	Thu May 31 18:47:21 2018 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2018 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 8006298
+ * @bug 8006298 8204055
  * @summary Using an unrecognized VM option should print the name of the option
  * @library /test/lib
  * @modules java.base/jdk.internal.misc
@@ -35,11 +35,19 @@
 
 public class UnrecognizedVMOption {
   public static void main(String[] args) throws Exception {
-    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
-        "-XX:bogus_option", "-version");
+    // Note: -XX by itself is an unrecognized launcher option, the :
+    // must be present for it to be passed through as a VM option.
+    String[] badOptions = {
+      "",  // empty option
+      "bogus_option",
+    };
+    for (String option : badOptions) {
+      ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
+          "-XX:" + option, "-version");
 
-    OutputAnalyzer output = new OutputAnalyzer(pb.start());
-    output.shouldContain("Unrecognized VM option 'bogus_option'");
-    output.shouldHaveExitValue(1);
+      OutputAnalyzer output = new OutputAnalyzer(pb.start());
+      output.shouldContain("Unrecognized VM option '" + option + "'");
+      output.shouldHaveExitValue(1);
+    }
   }
 }