changeset 13927:76696e5fbe49

8186098: sun/security/pkcs11/KeyStore/SecretKeysBasic.sh failed due to libnss3 version cannot be parsed Summary: Improves the approach on parsing lib version Reviewed-by: weijun, xuelei
author igerasim
date Tue, 23 Oct 2018 11:29:55 -0700
parents 93ed62498ddc
children fa2ff684ed23
files test/sun/security/pkcs11/PKCS11Test.java
diffstat 1 files changed, 15 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/test/sun/security/pkcs11/PKCS11Test.java	Tue Oct 23 11:29:39 2018 -0700
+++ b/test/sun/security/pkcs11/PKCS11Test.java	Tue Oct 23 11:29:55 2018 -0700
@@ -25,6 +25,7 @@
 // common infrastructure for SunPKCS11 tests
 
 import java.io.*;
+import java.nio.charset.StandardCharsets;
 import java.util.*;
 import java.lang.reflect.*;
 
@@ -269,6 +270,11 @@
         getNSSInfo(nss_library);
     }
 
+    // Try to parse the version for the specified library.
+    // Assuming the library contains either of the following patterns:
+    // $Header: NSS <version>
+    // Version: NSS <version>
+    // Here, <version> stands for NSS version.
     static double getNSSInfo(String library) {
         // look for two types of headers in NSS libraries
         String nssHeader1 = "$Header: NSS";
@@ -299,7 +305,7 @@
                     read = 100 + is.read(data, 100, 900);
                 }
 
-                s = new String(data, 0, read);
+                s = new String(data, 0, read, StandardCharsets.US_ASCII);
                 i = s.indexOf(nssHeader1);
                 if (i > 0 || (i = s.indexOf(nssHeader2)) > 0) {
                     found = true;
@@ -327,18 +333,13 @@
 
         // the index after whitespace after nssHeader
         int afterheader = s.indexOf("NSS", i) + 4;
-        int nextSpaceIndex = s.indexOf(' ', afterheader);
-
-        // If the next space is not found,
-        // it has to print the content for further investigation.
-        if (nextSpaceIndex == -1) {
-            System.out.println("===== Content start =====");
-            System.out.println(s);
-            System.out.println("===== Content end =====");
+        String version = String.valueOf(s.charAt(afterheader));
+        for (char c = s.charAt(++afterheader);
+                c == '.' || (c >= '0' && c <= '9');
+                c = s.charAt(++afterheader)) {
+            version += c;
         }
 
-        String version = s.substring(afterheader, nextSpaceIndex);
-
         // If a "dot dot" release, strip the extra dots for double parsing
         String[] dot = version.split("\\.");
         if (dot.length > 2) {
@@ -352,6 +353,9 @@
         try {
             nss_version = Double.parseDouble(version);
         } catch (NumberFormatException e) {
+            System.out.println("===== Content start =====");
+            System.out.println(s);
+            System.out.println("===== Content end =====");
             System.out.println("Failed to parse lib" + library +
                     " version. Set to 0.0");
             e.printStackTrace();