remm 00/11/17 16:16:57 Modified: catalina/src/share/org/apache/catalina/resources FileResources.java Log: - Should fix lots of potential problems. The base is removed before comparing. I checked with Tomcat 3.2, and the code is very similar. Also, the case checking is only necessary when running Windows. Revision Changes Path 1.6 +42 -25 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/resources/FileResources.java Index: FileResources.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/resources/FileResources.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- FileResources.java 2000/11/17 20:09:21 1.5 +++ FileResources.java 2000/11/18 00:16:57 1.6 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/resources/FileResources.java,v 1.5 2000/11/17 20:09:21 remm Exp $ - * $Revision: 1.5 $ - * $Date: 2000/11/17 20:09:21 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/resources/FileResources.java,v 1.6 2000/11/18 00:16:57 remm Exp $ + * $Revision: 1.6 $ + * $Date: 2000/11/18 00:16:57 $ * * ==================================================================== * @@ -95,7 +95,7 @@ * * @author Craig R. McClanahan * @author Remy Maucherat - * @version $Revision: 1.5 $ $Date: 2000/11/17 20:09:21 $ + * @version $Revision: 1.6 $ $Date: 2000/11/18 00:16:57 $ */ public final class FileResources extends ResourcesBase { @@ -123,6 +123,12 @@ protected static final int BUFFER_SIZE = 2048; + /** + * Absolute normalized filename of the base. + */ + protected String absoluteBase; + + // ------------------------------------------------------------- Properties @@ -153,7 +159,8 @@ throw new IllegalArgumentException (sm.getString("fileResources.base", docBase)); this.base = base; - + this.absoluteBase = normalize(base.getAbsolutePath()); + // Perform the standard superclass processing super.setDocBase(docBase); @@ -369,17 +376,22 @@ File file = new File(base, normalized.substring(1)); - String absPath = normalize(file.getAbsolutePath()); - String canPath = null; - try { - canPath = file.getCanonicalPath(); - if (canPath != null) - canPath = normalize(canPath); - } catch (IOException e) { + // Windows only check + if (File.separatorChar == '\\') { + String absPath = normalize(file.getAbsolutePath()); + String canPath = null; + try { + canPath = file.getCanonicalPath(); + if (canPath != null) + canPath = normalize(canPath); + } catch (IOException e) { + } + absPath = absPath.substring(absoluteBase.length()); + canPath = canPath.substring(absoluteBase.length()); + if ((canPath == null) || (absPath == null) + || (!canPath.equals(absPath))) + return (false); } - if ((canPath == null) || (absPath == null) - || (!canPath.equals(absPath))) - return (false); //File file = file(normalized.substring(1)); if (file != null) { @@ -709,17 +721,22 @@ return (null); File file = new File(base, name.substring(1)); if (file.exists() && file.canRead()) { - String absPath = normalize(file.getAbsolutePath()); - String canPath = null; - try { - canPath = file.getCanonicalPath(); - if (canPath != null) - canPath = normalize(canPath); - } catch (IOException e) { + // Windows only check + if (File.separatorChar == '\\') { + String absPath = normalize(file.getAbsolutePath()); + String canPath = null; + try { + canPath = file.getCanonicalPath(); + if (canPath != null) + canPath = normalize(canPath); + } catch (IOException e) { + } + absPath = absPath.substring(absoluteBase.length()); + canPath = canPath.substring(absoluteBase.length()); + if ((canPath == null) || (absPath == null) + || (!canPath.equals(absPath))) + return (null); } - if ((canPath == null) || (absPath == null) - || (!canPath.equals(absPath))) - return (null); return (file); } else { return (null);