summaryrefslogtreecommitdiff
path: root/libjava/classpath/java/net/URLClassLoader.java
diff options
context:
space:
mode:
authormark <mark@138bc75d-0d04-0410-961f-82ee72b054a4>2006-05-18 17:29:21 +0000
committermark <mark@138bc75d-0d04-0410-961f-82ee72b054a4>2006-05-18 17:29:21 +0000
commit64089cc9f030d8ef7972adb5d117e0b23f47d62b (patch)
tree9f9c470de62ee62fba1331a396450d728d2b1fad /libjava/classpath/java/net/URLClassLoader.java
parent96034e28360d660d7a7708807fcbc4b519574d8e (diff)
downloadgcc-64089cc9f030d8ef7972adb5d117e0b23f47d62b.tar.gz
Imported GNU Classpath 0.90
* scripts/makemake.tcl: LocaleData.java moved to gnu/java/locale. * sources.am: Regenerated. * gcj/javaprims.h: Regenerated. * Makefile.in: Regenerated. * gcj/Makefile.in: Regenerated. * include/Makefile.in: Regenerated. * testsuite/Makefile.in: Regenerated. * gnu/java/lang/VMInstrumentationImpl.java: New override. * gnu/java/net/local/LocalSocketImpl.java: Likewise. * gnu/classpath/jdwp/VMMethod.java: Likewise. * gnu/classpath/jdwp/VMVirtualMachine.java: Update to latest interface. * java/lang/Thread.java: Add UncaughtExceptionHandler. * java/lang/reflect/Method.java: Implements GenericDeclaration and isSynthetic(), * java/lang/reflect/Field.java: Likewise. * java/lang/reflect/Constructor.java * java/lang/Class.java: Implements Type, GenericDeclaration, getSimpleName() and getEnclosing*() methods. * java/lang/Class.h: Add new public methods. * java/lang/Math.java: Add signum(), ulp() and log10(). * java/lang/natMath.cc (log10): New function. * java/security/VMSecureRandom.java: New override. * java/util/logging/Logger.java: Updated to latest classpath version. * java/util/logging/LogManager.java: New override. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@113887 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/classpath/java/net/URLClassLoader.java')
-rw-r--r--libjava/classpath/java/net/URLClassLoader.java110
1 files changed, 100 insertions, 10 deletions
diff --git a/libjava/classpath/java/net/URLClassLoader.java b/libjava/classpath/java/net/URLClassLoader.java
index 9e489db533f..183e645c85f 100644
--- a/libjava/classpath/java/net/URLClassLoader.java
+++ b/libjava/classpath/java/net/URLClassLoader.java
@@ -39,6 +39,7 @@ exception statement from your version. */
package java.net;
+import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.EOFException;
import java.io.File;
@@ -46,6 +47,7 @@ import java.io.FileInputStream;
import java.io.FilePermission;
import java.io.IOException;
import java.io.InputStream;
+import java.io.InputStreamReader;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.CodeSource;
@@ -315,27 +317,51 @@ public class URLClassLoader extends SecureClassLoader
jarfile =
((JarURLConnection) baseJarURL.openConnection()).getJarFile();
-
+
Manifest manifest;
Attributes attributes;
String classPathString;
- if ((manifest = jarfile.getManifest()) != null
+ this.classPath = new Vector();
+
+ // This goes through the cached jar files listed
+ // in the INDEX.LIST file. All the jars found are added
+ // to the classPath vector so they can be loaded.
+ String dir = "META-INF/INDEX.LIST";
+ if (jarfile.getEntry(dir) != null)
+ {
+ BufferedReader br = new BufferedReader(new InputStreamReader(new URL(baseJarURL,
+ dir).openStream()));
+ String line = br.readLine();
+ while (line != null)
+ {
+ if (line.endsWith(".jar"))
+ {
+ try
+ {
+ this.classPath.add(new URL(baseURL, line));
+ }
+ catch (java.net.MalformedURLException xx)
+ {
+ // Give up
+ }
+ }
+ line = br.readLine();
+ }
+ }
+ else if ((manifest = jarfile.getManifest()) != null
&& (attributes = manifest.getMainAttributes()) != null
&& ((classPathString
= attributes.getValue(Attributes.Name.CLASS_PATH))
!= null))
- {
- this.classPath = new Vector();
-
+ {
StringTokenizer st = new StringTokenizer(classPathString, " ");
while (st.hasMoreElements ())
{
String e = st.nextToken ();
try
{
- URL url = new URL(baseURL, e);
- this.classPath.add(url);
+ this.classPath.add(new URL(baseURL, e));
}
catch (java.net.MalformedURLException xx)
{
@@ -538,9 +564,14 @@ public class URLClassLoader extends SecureClassLoader
{
try
{
- File file = new File(dir, name).getCanonicalFile();
- if (file.exists() && !file.isDirectory())
- return new FileResource(this, file);
+ // Make sure that all components in name are valid by walking through
+ // them
+ File file = walkPathComponents(name);
+
+ if (file == null)
+ return null;
+
+ return new FileResource(this, file);
}
catch (IOException e)
{
@@ -548,6 +579,65 @@ public class URLClassLoader extends SecureClassLoader
}
return null;
}
+
+ /**
+ * Walk all path tokens and check them for validity. At no moment, we are
+ * allowed to reach a directory located "above" the root directory, stored
+ * in "dir" property. We are also not allowed to enter a non existing
+ * directory or a non directory component (plain file, symbolic link, ...).
+ * An empty or null path is valid. Pathnames components are separated by
+ * <code>File.separatorChar</code>
+ *
+ * @param resourceFileName the name to be checked for validity.
+ * @return the canonical file pointed by the resourceFileName or null if the
+ * walking failed
+ * @throws IOException in case of issue when creating the canonical
+ * resulting file
+ * @see File#separatorChar
+ */
+ private File walkPathComponents(String resourceFileName) throws IOException
+ {
+ StringTokenizer stringTokenizer = new StringTokenizer(resourceFileName, File.separator);
+ File currentFile = dir;
+ int tokenCount = stringTokenizer.countTokens();
+
+ for (int i = 0; i < tokenCount - 1; i++)
+ {
+ String currentToken = stringTokenizer.nextToken();
+
+ // If we are at the root directory and trying to go up, the walking is
+ // finished with an error
+ if ("..".equals(currentToken) && currentFile.equals(dir))
+ return null;
+
+ currentFile = new File(currentFile, currentToken);
+
+ // If the current file doesn't exist or is not a directory, the walking is
+ // finished with an error
+ if (! (currentFile.exists() && currentFile.isDirectory()))
+ return null;
+
+ }
+
+ // Treat the last token differently, if it exists, because it does not need
+ // to be a directory
+ if (tokenCount > 0)
+ {
+ String currentToken = stringTokenizer.nextToken();
+
+ if ("..".equals(currentToken) && currentFile.equals(dir))
+ return null;
+
+ currentFile = new File(currentFile, currentToken);
+
+ // If the current file doesn't exist, the walking is
+ // finished with an error
+ if (! currentFile.exists())
+ return null;
+ }
+
+ return currentFile.getCanonicalFile();
+ }
}
static final class FileResource extends Resource