From d822f4aa3e8b220ce575dcc0832f91c44f6ab02e Mon Sep 17 00:00:00 2001 From: markt Date: Sat, 15 Aug 2009 12:07:42 +0000 Subject: [PATCH] Apply Konstantin's new patch for https://issues.apache.org/bugzilla/show_bug.cgi?id=45403 git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@804462 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/catalina/loader/LocalStrings.properties | 2 + java/org/apache/catalina/loader/WebappLoader.java | 103 ++++++++++++--------- 2 files changed, 60 insertions(+), 45 deletions(-) diff --git a/java/org/apache/catalina/loader/LocalStrings.properties b/java/org/apache/catalina/loader/LocalStrings.properties index 1bc1b1797..37ed5042c 100644 --- a/java/org/apache/catalina/loader/LocalStrings.properties +++ b/java/org/apache/catalina/loader/LocalStrings.properties @@ -49,3 +49,5 @@ webappLoader.removeRepository=Removing repository {0} webappLoader.starting=Starting this Loader webappLoader.stopping=Stopping this Loader webappLoader.failModifiedCheck=Error tracking modifications +webappLoader.copyFailure=Failed to copy resources +webappLoader.namingFailure=Failed to access resource {0} diff --git a/java/org/apache/catalina/loader/WebappLoader.java b/java/org/apache/catalina/loader/WebappLoader.java index 96fced9d7..4b3b17994 100644 --- a/java/org/apache/catalina/loader/WebappLoader.java +++ b/java/org/apache/catalina/loader/WebappLoader.java @@ -40,7 +40,6 @@ import java.util.jar.JarFile; import javax.management.MBeanRegistration; import javax.management.MBeanServer; import javax.management.ObjectName; -import javax.naming.Binding; import javax.naming.NameClassPair; import javax.naming.NamingEnumeration; import javax.naming.NamingException; @@ -870,8 +869,9 @@ public class WebappLoader /** * Configure the repositories for our class loader, based on the * associated Context. + * @throws IOException */ - private void setRepositories() { + private void setRepositories() throws IOException { if (!(container instanceof Context)) return; @@ -925,7 +925,10 @@ public class WebappLoader classRepository = new File(workDir, classesPath); classRepository.mkdirs(); - copyDir(classes, classRepository); + if (!copyDir(classes, classRepository)) { + throw new IOException( + sm.getString("webappLoader.copyFailure")); + } } @@ -973,59 +976,69 @@ public class WebappLoader } // Looking up directory /WEB-INF/lib in the context + NamingEnumeration enumeration = null; try { - NamingEnumeration enumeration = - resources.listBindings(libPath); - while (enumeration.hasMoreElements()) { - - Binding binding = enumeration.nextElement(); - String filename = libPath + "/" + binding.getName(); - if (!filename.endsWith(".jar")) - continue; + enumeration = libDir.list(""); + } catch (NamingException e) { + IOException ioe = new IOException(sm.getString( + "webappLoader.namingFailure", libPath)); + ioe.initCause(e); + throw ioe; + } + while (enumeration.hasMoreElements()) { + NameClassPair ncPair = enumeration.nextElement(); + String filename = libPath + "/" + ncPair.getName(); + if (!filename.endsWith(".jar")) + continue; - // Copy JAR in the work directory, always (the JAR file - // would get locked otherwise, which would make it - // impossible to update it or remove it at runtime) - File destFile = new File(destDir, binding.getName()); + // Copy JAR in the work directory, always (the JAR file + // would get locked otherwise, which would make it + // impossible to update it or remove it at runtime) + File destFile = new File(destDir, ncPair.getName()); - if( log.isDebugEnabled()) - log.debug(sm.getString("webappLoader.jarDeploy", filename, - destFile.getAbsolutePath())); + if( log.isDebugEnabled()) + log.debug(sm.getString("webappLoader.jarDeploy", filename, + destFile.getAbsolutePath())); - Object obj = binding.getObject(); - - if (!(obj instanceof Resource)) - continue; + // Bug 45403 - Explicitly call lookup() on the name to check + // that the resource is readable. We cannot use resources + // returned by listBindings(), because that lists all of them, + // but does not perform the necessary checks on each. + Object obj = null; + try { + obj = libDir.lookup(ncPair.getName()); + } catch (NamingException e) { + IOException ioe = new IOException(sm.getString( + "webappLoader.namingFailure", filename)); + ioe.initCause(e); + throw ioe; + } + + if (!(obj instanceof Resource)) + continue; - Resource jarResource = (Resource) obj; + Resource jarResource = (Resource) obj; - if (copyJars) { - if (!copy(jarResource.streamContent(), - new FileOutputStream(destFile))) - continue; + if (copyJars) { + if (!copy(jarResource.streamContent(), + new FileOutputStream(destFile))) { + throw new IOException( + sm.getString("webappLoader.copyFailure")); } + } - try { - JarFile jarFile = new JarFile(destFile); - classLoader.addJar(filename, jarFile, destFile); - } catch (Exception ex) { - // Catch the exception if there is an empty jar file - // Should ignore and continute loading other jar files - // in the dir - } - - loaderRepositories.add( filename ); - + try { + JarFile jarFile = new JarFile(destFile); + classLoader.addJar(filename, jarFile, destFile); + } catch (Exception ex) { + // Catch the exception if there is an empty jar file + // Should ignore and continue loading other jar files + // in the dir } - } catch (NamingException e) { - // Silent catch: it's valid that no /WEB-INF/lib directory - // exists - } catch (IOException e) { - e.printStackTrace(); + + loaderRepositories.add( filename ); } - } - } -- 2.11.0