8217216: Launcher does not defend itself against LD_LIBRARY_PATH_64 (Solaris)
authorhenryjen
Thu, 07 Mar 2019 10:18:23 -0800
changeset 54023 a764c49570c6
parent 54022 ff399127078a
child 54024 e445608fce9b
8217216: Launcher does not defend itself against LD_LIBRARY_PATH_64 (Solaris) Reviewed-by: rriggs
src/java.base/unix/native/libjli/java_md_solinux.c
test/jdk/tools/launcher/Test7029048.java
--- a/src/java.base/unix/native/libjli/java_md_solinux.c	Thu Mar 07 15:27:42 2019 +0100
+++ b/src/java.base/unix/native/libjli/java_md_solinux.c	Thu Mar 07 10:18:23 2019 -0800
@@ -303,6 +303,9 @@
 
 #ifdef SETENV_REQUIRED
     jboolean mustsetenv = JNI_FALSE;
+#ifdef __solaris__
+    char *llp64 = NULL; /* existing LD_LIBRARY_PATH_64 setting */
+#endif // __solaris__
     char *runpath = NULL; /* existing effective LD_LIBRARY_PATH setting */
     char* new_runpath = NULL; /* desired new LD_LIBRARY_PATH string */
     char* newpath = NULL; /* path on new LD_LIBRARY_PATH */
@@ -367,7 +370,12 @@
          * any.
          */
 
+#ifdef __solaris__
+        llp64 = getenv("LD_LIBRARY_PATH_64");
+        runpath = (llp64 == NULL) ? getenv(LD_LIBRARY_PATH) : llp64;
+#else
         runpath = getenv(LD_LIBRARY_PATH);
+#endif /* __solaris__ */
 
         /* runpath contains current effective LD_LIBRARY_PATH setting */
         { /* New scope to declare local variable */
@@ -440,6 +448,14 @@
          * once at startup, so we have to re-exec the current executable
          * to get the changed environment variable to have an effect.
          */
+#ifdef __solaris__
+        /*
+         * new LD_LIBRARY_PATH took over for LD_LIBRARY_PATH_64
+         */
+        if (llp64 != NULL) {
+            UnsetEnv("LD_LIBRARY_PATH_64");
+        }
+#endif // __solaris__
 
         newenvp = environ;
     }
--- a/test/jdk/tools/launcher/Test7029048.java	Thu Mar 07 15:27:42 2019 +0100
+++ b/test/jdk/tools/launcher/Test7029048.java	Thu Mar 07 10:18:23 2019 -0800
@@ -23,7 +23,7 @@
 
 /**
  * @test
- * @bug 7029048 8217340
+ * @bug 7029048 8217340 8217216
  * @summary Ensure that the launcher defends against user settings of the
  *          LD_LIBRARY_PATH environment variable on Unixes
  * @library /test/lib
@@ -89,6 +89,29 @@
     }
 
     static void analyze(TestResult tr, int nLLPComponents, String caseID) {
+        if (isSolaris) {
+            String envValue = getValue("LD_LIBRARY_PATH_64", tr.testOutput);
+           /*
+            * the envValue can never be null, since the test code should always
+            * print a "null" string.
+            */
+            if (envValue == null) {
+                throw new RuntimeException("NPE, likely a program crash ??");
+            }
+            boolean noLLP64 = envValue.equals("null");
+            if (nLLPComponents == 0 && noLLP64) {
+                System.out.println("FAIL: test7029048, " + caseID);
+                System.out.println(" Missing LD_LIBRARY_PATH_64");
+                errors++;
+                return;
+            } else if (nLLPComponents > 3 && !noLLP64) {
+                System.out.println("FAIL: test7029048, " + caseID);
+                System.out.println(" Unexpected LD_LIBRARY_PATH_64: " + envValue);
+                errors++;
+                return;
+            }
+        }
+
         String envValue = getValue(LD_LIBRARY_PATH, tr.testOutput);
        /*
         * the envValue can never be null, since the test code should always
@@ -202,8 +225,8 @@
                 env.clear();
                 env.put(LD_LIBRARY_PATH_64, dstServerDir.getAbsolutePath());
                 run(env,
-                    v.value,            // Do not add one, since we didn't set
-                                        // LD_LIBRARY_PATH here
+                    // LD_LIBRARY_PATH_64 is copied into LD_LIBRARY_PATH for LIBJVM case
+                    v.value == 0 ? 0 : v.value + 1,
                     "Case 3: " + desc);
             }
         }