Blame SOURCES/issue3.patch

6f88fb
commit b4232ae35d2b86592a945a56c948f107fe7efabe
6f88fb
Author: Jiri Vanek <jvanek@redhat.com>
6f88fb
Date:   Wed Jun 26 13:46:45 2019 +0200
6f88fb
6f88fb
    Nested jar, if by relative path point up, is stored as hashed
6f88fb
6f88fb
diff --git a/netx/net/sourceforge/jnlp/cache/CacheUtil.java b/netx/net/sourceforge/jnlp/cache/CacheUtil.java
6f88fb
index a972eb8e..5c8652b6 100644
6f88fb
--- a/netx/net/sourceforge/jnlp/cache/CacheUtil.java
6f88fb
+++ b/netx/net/sourceforge/jnlp/cache/CacheUtil.java
6f88fb
@@ -741,7 +741,7 @@
6f88fb
         }
6f88fb
     }
6f88fb
 
6f88fb
-    private static String hex(String origName, String candidate) throws NoSuchAlgorithmException {
6f88fb
+    public static String hex(String origName, String candidate) throws NoSuchAlgorithmException {
6f88fb
         MessageDigest md = MessageDigest.getInstance("SHA-256");
6f88fb
         byte[] sum = md.digest(candidate.getBytes(StandardCharsets.UTF_8));
6f88fb
         //convert the byte to hex format method 2
6f88fb
diff --git a/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java b/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java
6f88fb
index e015f348..117163f3 100644
6f88fb
--- a/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java
6f88fb
+++ b/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java
6f88fb
@@ -1340,7 +1340,11 @@
6f88fb
                                         // (inline loading with "jar:..!/..." path will not work
6f88fb
                                         // with standard classloader methods)
6f88fb
 
6f88fb
-                                        String extractedJarLocation = localFile + ".nested/" + je.getName();
6f88fb
+                                        String name = je.getName();
6f88fb
+                                        if (name.contains("..")){
6f88fb
+                                            name=CacheUtil.hex(name, name);
6f88fb
+                                        }
6f88fb
+                                        String extractedJarLocation = localFile + ".nested/" + name;
6f88fb
                                         File parentDir = new File(extractedJarLocation).getParentFile();
6f88fb
                                         if (!parentDir.isDirectory() && !parentDir.mkdirs()) {
6f88fb
                                             throw new RuntimeException(R("RNestedJarExtration"));
6f88fb
diff --git a/tests/netx/unit/net/sourceforge/jnlp/runtime/JNLPClassLoaderTest.java b/tests/netx/unit/net/sourceforge/jnlp/runtime/JNLPClassLoaderTest.java
6f88fb
index 7580d23b..a20a1d8f 100644
6f88fb
--- a/tests/netx/unit/net/sourceforge/jnlp/runtime/JNLPClassLoaderTest.java
6f88fb
+++ b/tests/netx/unit/net/sourceforge/jnlp/runtime/JNLPClassLoaderTest.java
6f88fb
@@ -43,6 +43,8 @@
6f88fb
 import java.io.File;
6f88fb
 import java.io.FileOutputStream;
6f88fb
 import java.io.InputStream;
6f88fb
+import java.io.OutputStream;
6f88fb
+import net.sourceforge.jnlp.ResourcesDesc;
6f88fb
 import java.net.URL;
6f88fb
 import java.nio.charset.Charset;
6f88fb
 import java.nio.file.Files;
6f88fb
@@ -407,13 +409,7 @@ public class JNLPClassLoaderTest extends NoStdOutErrTest {
6f88fb
         JNLPRuntime.setDebug(true);
6f88fb
         try {
6f88fb
             final JNLPFile jnlpFile1 = new JNLPFile(new URL("http://localhost:" + port + "/up.jnlp"));
6f88fb
-            final JNLPClassLoader classLoader1 = new JNLPClassLoader(jnlpFile1, UpdatePolicy.ALWAYS) {
6f88fb
-                @Override
6f88fb
-                protected void activateJars(List<JARDesc> jars) {
6f88fb
-                    super.activateJars(jars);
6f88fb
-                }
6f88fb
-
6f88fb
-            };
6f88fb
+            final JNLPClassLoader classLoader1 = JNLPClassLoader.getInstance(jnlpFile1, UpdatePolicy.ALWAYS, false);
6f88fb
             InputStream is1 = classLoader1.getResourceAsStream("Hello1.class");
6f88fb
             is1.close();
6f88fb
             is1 = classLoader1.getResourceAsStream("META-INF/MANIFEST.MF");
6f88fb
@@ -430,4 +426,74 @@ public class JNLPClassLoaderTest extends NoStdOutErrTest {
6f88fb
 
6f88fb
     }
6f88fb
 
6f88fb
+    @Test
6f88fb
+    public void testRelativePathInNestedJars() throws Exception {
6f88fb
+        CacheUtil.clearCache();
6f88fb
+        int port = ServerAccess.findFreePort();
6f88fb
+        File dir = FileTestUtils.createTempDirectory();
6f88fb
+        dir.deleteOnExit();
6f88fb
+        File jar = new File(dir,"jar03_dotdotN1.jar");
6f88fb
+        File jnlp = new File(dir,"jar_03_dotdot_jarN1.jnlp");
6f88fb
+        InputStream is1 = ClassLoader.getSystemClassLoader().getResourceAsStream("net/sourceforge/jnlp/runtime/jar_03_dotdot_jarN1.jnlp");
6f88fb
+        InputStream is2 = ClassLoader.getSystemClassLoader().getResourceAsStream("net/sourceforge/jnlp/runtime/jar03_dotdotN1.jar");
6f88fb
+        OutputStream fos1 = new FileOutputStream(jnlp);
6f88fb
+        OutputStream fos2 = new FileOutputStream(jar);
6f88fb
+        StreamUtils.copyStream(is1, fos1);
6f88fb
+        StreamUtils.copyStream(is2, fos2);
6f88fb
+        fos1.flush();;
6f88fb
+        fos2.flush();
6f88fb
+        fos1.close();
6f88fb
+        fos2.close();
6f88fb
+        ServerLauncher as = ServerAccess.getIndependentInstance(dir.getAbsolutePath(), port);
6f88fb
+        boolean verifyBackup = JNLPRuntime.isVerifying();
6f88fb
+        boolean trustBackup= JNLPRuntime.isTrustAll();
6f88fb
+        boolean securityBAckup= JNLPRuntime.isSecurityEnabled();
6f88fb
+        boolean verbose= JNLPRuntime.isDebug();
6f88fb
+        JNLPRuntime.setVerify(false);
6f88fb
+        JNLPRuntime.setTrustAll(true);
6f88fb
+        JNLPRuntime.setSecurityEnabled(false);
6f88fb
+        JNLPRuntime.setDebug(true);
6f88fb
+        try {
6f88fb
+            //it is invalid jar, so we have to disable checks first
6f88fb
+            final JNLPFile jnlpFile = new JNLPFile(new URL("http://localhost:" + port + "/jar_03_dotdot_jarN1.jnlp"));
6f88fb
+            final JNLPClassLoader classLoader = JNLPClassLoader.getInstance(jnlpFile, UpdatePolicy.ALWAYS, false);
6f88fb
+
6f88fb
+            //ThreadGroup group = Thread.currentThread().getThreadGroup();
6f88fb
+            //ApplicationInstance app = new ApplicationInstance(jnlpFile, group, classLoader);
6f88fb
+            //classLoader.setApplication(app);
6f88fb
+            //app.initialize();
6f88fb
+
6f88fb
+            //this test is actually not testing mutch. The app must be accessing the nested jar in plugin-like way
6f88fb
+            InputStream is = classLoader.getResourceAsStream("application/abev/nyomtatvanyinfo/1965.teminfo.enyk");
6f88fb
+            is.close();
6f88fb
+            is = classLoader.getResourceAsStream("META-INF/MANIFEST.MF");
6f88fb
+            is.close();
6f88fb
+            is = classLoader.getResourceAsStream("META-INF/j1.jar");
6f88fb
+            is.close();
6f88fb
+            is = classLoader.getResourceAsStream("META-INF/../../jar01_to_be_injected.jar");
6f88fb
+            //the .. is not recognized correctly
6f88fb
+            //is.close();
6f88fb
+            //Class c = classLoader.getClass().forName("Hello1");
6f88fb
+            // in j1.jar
6f88fb
+            is = classLoader.getResourceAsStream("Hello1.class");
6f88fb
+            //is.close(); nested jar is not on defualt CP
6f88fb
+            //in  jar01
6f88fb
+            //c = classLoader.getClass().forName("com.devdaily.FileUtilities");
6f88fb
+            is = classLoader.getResourceAsStream("com/devdaily/FileUtilities.class");
6f88fb
+            // is.close(); nested jar is not on defualt CP
6f88fb
+            Assert.assertTrue(new File(PathsAndFiles.CACHE_DIR.getFullPath()+"/0/http/localhost/"+port+"/jar_03_dotdot_jarN1.jnlp").exists());
6f88fb
+            Assert.assertTrue(new File(PathsAndFiles.CACHE_DIR.getFullPath()+"/1/http/localhost/"+port+"/jar03_dotdotN1.jar").exists());
6f88fb
+            Assert.assertTrue(new File(PathsAndFiles.CACHE_DIR.getFullPath()+"/1/http/localhost/"+port+"/jar03_dotdotN1.jar.nested/99a90686bfbe84e3f9dbeed8127bba85672ed73688d3c69191aa1ee70916a.jar").exists());
6f88fb
+            Assert.assertTrue(new File(PathsAndFiles.CACHE_DIR.getFullPath()+"/1/http/localhost/"+port+"/jar03_dotdotN1.jar.nested/META-INF/j1.jar").exists());
6f88fb
+        } finally {
6f88fb
+            JNLPRuntime.setVerify(verifyBackup);
6f88fb
+            JNLPRuntime.setTrustAll(trustBackup);
6f88fb
+            JNLPRuntime.setSecurityEnabled(securityBAckup);
6f88fb
+            JNLPRuntime.setDebug(verbose);
6f88fb
+            as.stop();
6f88fb
+        }
6f88fb
+
6f88fb
+    }
6f88fb
+
6f88fb
+
6f88fb
 }
6f88fb
diff --git a/tests/netx/unit/net/sourceforge/jnlp/runtime/jar_03_dotdot_jarN1.jnlp b/tests/netx/unit/net/sourceforge/jnlp/runtime/jar_03_dotdot_jarN1.jnlp
6f88fb
new file mode 100644
6f88fb
index 00000000..71bdea87
6f88fb
--- /dev/null
6f88fb
+++ b/tests/netx/unit/net/sourceforge/jnlp/runtime/jar_03_dotdot_jarN1.jnlp
6f88fb
@@ -0,0 +1,15 @@
6f88fb
+
6f88fb
+<jnlp spec="6.0+" >
6f88fb
+
6f88fb
+<information><title>1965</title><vendor>Nemzeti Ado- es Vamhivatal</vendor><offline-allowed/></information>
6f88fb
+
6f88fb
+<security><all-permissions/></security>
6f88fb
+
6f88fb
+<resources>
6f88fb
+  <j2se href="http://java.sun.com/products/autodl/j2se" version="1.8+" />
6f88fb
+  <jar href="jar03_dotdotN1.jar" version="2.0"/>
6f88fb
+</resources>
6f88fb
+
6f88fb
+<application-desc main-class="http://localhost/jar01.jar!META-INF/jar01_to_be_injected.jar!METAxINF.Test" />
6f88fb
+
6f88fb
+</jnlp>