You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2014/03/02 22:28:26 UTC

svn commit: r1573370 - in /tomcat/trunk/java/org/apache/catalina/webresources: AbstractResourceSet.java Cache.java LocalStrings.properties StandardRoot.java

Author: markt
Date: Sun Mar  2 21:28:25 2014
New Revision: 1573370

URL: http://svn.apache.org/r1573370
Log:
Better way to avoid NPE in resource cache - don't let the request get that far when we know we are going to fail it anyway.

Modified:
    tomcat/trunk/java/org/apache/catalina/webresources/AbstractResourceSet.java
    tomcat/trunk/java/org/apache/catalina/webresources/Cache.java
    tomcat/trunk/java/org/apache/catalina/webresources/LocalStrings.properties
    tomcat/trunk/java/org/apache/catalina/webresources/StandardRoot.java

Modified: tomcat/trunk/java/org/apache/catalina/webresources/AbstractResourceSet.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/AbstractResourceSet.java?rev=1573370&r1=1573369&r2=1573370&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/AbstractResourceSet.java (original)
+++ tomcat/trunk/java/org/apache/catalina/webresources/AbstractResourceSet.java Sun Mar  2 21:28:25 2014
@@ -39,7 +39,8 @@ public abstract class AbstractResourceSe
 
     protected final void checkPath(String path) {
         if (path == null || path.length() == 0 || path.charAt(0) != '/') {
-            throw new IllegalArgumentException();
+            throw new IllegalArgumentException(
+                    sm.getString("abstractResourceSet.checkPath", path));
         }
     }
 

Modified: tomcat/trunk/java/org/apache/catalina/webresources/Cache.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/Cache.java?rev=1573370&r1=1573369&r2=1573370&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/Cache.java (original)
+++ tomcat/trunk/java/org/apache/catalina/webresources/Cache.java Sun Mar  2 21:28:25 2014
@@ -145,7 +145,7 @@ public class Cache {
 
     private boolean noCache(String path) {
         // Don't cache resources used by the class loader (it has its own cache)
-        if (path == null || path.startsWith("/WEB-INF/classes") ||
+        if (path.startsWith("/WEB-INF/classes") ||
                 path.startsWith("/WEB-INF/lib")) {
             return true;
         }

Modified: tomcat/trunk/java/org/apache/catalina/webresources/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/LocalStrings.properties?rev=1573370&r1=1573369&r2=1573370&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/LocalStrings.properties (original)
+++ tomcat/trunk/java/org/apache/catalina/webresources/LocalStrings.properties Sun Mar  2 21:28:25 2014
@@ -14,9 +14,12 @@
 # limitations under the License.
 
 abstractArchiveResourceSet.setReadOnlyFalse=Archive based WebResourceSets such as those based on JARs are hard-coded to be read-only and may not be configured to be read-write
+
 abstractResource.getContentFail=Unable to return [{0}] as a byte array
 abstractResource.getContentTooLarge=Unable to return [{0}] as a byte array since the resource is [{1}] bytes in size which is larger than the maximum size of a byte array
 
+abstractResourceSet.checkPath=The requested path [{0}] is not valid. It must begin with "/".
+
 cache.addFail=Unable to add the resource at [{0}] to the cache because there was insufficient free space available after evicting expired cache entries - consider increasing the maximum size of the cache
 cache.backgroundEvictFail=The background cache eviction process was unable to free [{0}] percent of the cache for Context [{1}] - consider increasing the maximum size of the cache. After eviction approximately [{2}] KB of data remained in the cache.
 cache.objectMaxSizeTooBig=The value of [{0}]kB for objectMaxSize is larger than the limit of maxSize/20 so has been reduced to [{1}]kB
@@ -37,6 +40,7 @@ standardRoot.createInvalidFile=Unable to
 standardRoot.createNoFileResourceSet=The FileResourceSet feature has not yet been implemented
 standardRoot.createUnknownType=Unable to create WebResourceSet of unknown type [{0}]
 standardRoot.invalidPath=The resource path [{0}] is not valid
+standardRoot.invalidPathNormal=The resource path [{0}] has been normalized to [{1}] which is not valid
 standardRoot.lockedFile=The web application [{0}] failed to close the file [{1}] opened via the following stack trace
 standardRoot.noContext=A Context has not been configured for this WebResourceRoot
 standardRoot.startInvalidMain=The main resource set specified [{0}] is not valid

Modified: tomcat/trunk/java/org/apache/catalina/webresources/StandardRoot.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/StandardRoot.java?rev=1573370&r1=1573369&r2=1573370&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/StandardRoot.java (original)
+++ tomcat/trunk/java/org/apache/catalina/webresources/StandardRoot.java Sun Mar  2 21:28:25 2014
@@ -237,7 +237,14 @@ public class StandardRoot extends Lifecy
             throw new IllegalArgumentException(
                     sm.getString("standardRoot.invalidPath", path));
         }
-        return RequestUtil.normalize(path);
+
+        String result = RequestUtil.normalize(path);
+        if (result == null || result.length() == 0 || !result.startsWith("/")) {
+            throw new IllegalArgumentException(
+                    sm.getString("standardRoot.invalidPathNormal", path, result));
+        }
+
+        return result;
     }
 
     protected final WebResource getResourceInternal(String path,



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org