r9728 - helma-ng/trunk/src/org/helma/repository

[email protected] Tue, 12 May 2009 15:29:46 +0200 (CEST)
Newsgroups gmane.comp.java.helma.cvs
Message-ID <20090512132946.406003D0D6@mia>
Author: hannes
Date: 2009-05-12 15:29:46 +0200 (Tue, 12 May 2009)
New Revision: 9728

Modified:
   helma-ng/trunk/src/org/helma/repository/AbstractRepository.java
   helma-ng/trunk/src/org/helma/repository/FileRepository.java
   helma-ng/trunk/src/org/helma/repository/WebappRepository.java
   helma-ng/trunk/src/org/helma/repository/ZipRepository.java
Log:
Provide better error message when somebody tries to pass beneath the repository root.

Details at http://dev.helma.org/trac/helma/changeset/9728

Modified: helma-ng/trunk/src/org/helma/repository/AbstractRepository.java
===================================================================
--- helma-ng/trunk/src/org/helma/repository/AbstractRepository.java	2009-05-12 13:16:13 UTC (rev 9727)
+++ helma-ng/trunk/src/org/helma/repository/AbstractRepository.java	2009-05-12 13:29:46 UTC (rev 9728)
@@ -182,6 +182,9 @@
      * Get this repository's parent repository.
      */
     public Repository getParentRepository() {
+        if (parent == null) {
+            throw new RuntimeException("Tried to escape repository root");
+        }
         return parent;
     }
 

Modified: helma-ng/trunk/src/org/helma/repository/FileRepository.java
===================================================================
--- helma-ng/trunk/src/org/helma/repository/FileRepository.java	2009-05-12 13:16:13 UTC (rev 9727)
+++ helma-ng/trunk/src/org/helma/repository/FileRepository.java	2009-05-12 13:29:46 UTC (rev 9728)
@@ -99,7 +99,7 @@
         if (".".equals(name)) {
             return this;
         } else if ("..".equals(name)) {
-            return parent;
+            return getParentRepository();
         }
         return new FileRepository(new File(directory, name), this);
     }

Modified: helma-ng/trunk/src/org/helma/repository/WebappRepository.java
===================================================================
--- helma-ng/trunk/src/org/helma/repository/WebappRepository.java	2009-05-12 13:16:13 UTC (rev 9727)
+++ helma-ng/trunk/src/org/helma/repository/WebappRepository.java	2009-05-12 13:29:46 UTC (rev 9728)
@@ -59,7 +59,7 @@
         if (".".equals(name)) {
             return this;
         } else if ("..".equals(name)) {
-            return parent;
+            return getParentRepository();
         }        
         return new WebappRepository(context, this, name);
     }

Modified: helma-ng/trunk/src/org/helma/repository/ZipRepository.java
===================================================================
--- helma-ng/trunk/src/org/helma/repository/ZipRepository.java	2009-05-12 13:16:13 UTC (rev 9727)
+++ helma-ng/trunk/src/org/helma/repository/ZipRepository.java	2009-05-12 13:29:46 UTC (rev 9728)
@@ -225,7 +225,7 @@
         if (".".equals(name)) {
             return this;
         } else if ("..".equals(name)) {
-            return parent;
+            return getParentRepository();
         }
         return new ZipRepository(file, this, new ZipEntry(entryPath + "/" + name));
     }