Blame SOURCES/tomcat-7.0.76-CVE-2017-12617.patch

828cdb
--- java/org/apache/catalina/servlets/DefaultServlet.java.orig	2017-10-13 09:41:05.734302404 -0400
828cdb
+++ java/org/apache/catalina/servlets/DefaultServlet.java	2017-10-13 09:42:53.515701311 -0400
828cdb
@@ -855,23 +855,6 @@
828cdb
             return;
828cdb
         }
828cdb
 
828cdb
-        // If the resource is not a collection, and the resource path
828cdb
-        // ends with "/" or "\", return NOT FOUND
828cdb
-        if (cacheEntry.context == null) {
828cdb
-            if (path.endsWith("/") || (path.endsWith("\\"))) {
828cdb
-                // Check if we're included so we can return the appropriate
828cdb
-                // missing resource name in the error
828cdb
-                String requestUri = (String) request.getAttribute(
828cdb
-                        RequestDispatcher.INCLUDE_REQUEST_URI);
828cdb
-                if (requestUri == null) {
828cdb
-                    requestUri = request.getRequestURI();
828cdb
-                }
828cdb
-                response.sendError(HttpServletResponse.SC_NOT_FOUND,
828cdb
-                                   requestUri);
828cdb
-                return;
828cdb
-            }
828cdb
-        }
828cdb
-
828cdb
         boolean isError = DispatcherType.ERROR == request.getDispatcherType();
828cdb
 
828cdb
         // Check if the conditions specified in the optional If headers are
828cdb
--- java/org/apache/naming/resources/FileDirContext.java.orig	2017-10-13 09:41:05.737302387 -0400
828cdb
+++ java/org/apache/naming/resources/FileDirContext.java	2017-10-13 09:42:53.516701306 -0400
828cdb
@@ -14,8 +14,6 @@
828cdb
  * See the License for the specific language governing permissions and
828cdb
  * limitations under the License.
828cdb
  */
828cdb
-
828cdb
-
828cdb
 package org.apache.naming.resources;
828cdb
 
828cdb
 import java.io.File;
828cdb
@@ -75,6 +73,8 @@
828cdb
 
828cdb
     /**
828cdb
      * Builds a file directory context using the given environment.
828cdb
+     *
828cdb
+     * @param env The environment with which to build the context
828cdb
      */
828cdb
     public FileDirContext(Hashtable<String,Object> env) {
828cdb
         super(env);
828cdb
@@ -95,6 +95,8 @@
828cdb
      */
828cdb
     protected String absoluteBase = null;
828cdb
 
828cdb
+    private String canonicalBase = null;
828cdb
+
828cdb
 
828cdb
     /**
828cdb
      * Allow linking.
828cdb
@@ -104,7 +106,6 @@
828cdb
 
828cdb
     // ------------------------------------------------------------- Properties
828cdb
 
828cdb
-
828cdb
     /**
828cdb
      * Set the document root.
828cdb
      *
828cdb
@@ -117,32 +118,41 @@
828cdb
      */
828cdb
     @Override
828cdb
     public void setDocBase(String docBase) {
828cdb
+        // Validate the format of the proposed document root
828cdb
+        if (docBase == null) {
828cdb
+            throw new IllegalArgumentException(sm.getString("resources.null"));
828cdb
+        }
828cdb
 
828cdb
-    // Validate the format of the proposed document root
828cdb
-    if (docBase == null)
828cdb
-        throw new IllegalArgumentException
828cdb
-        (sm.getString("resources.null"));
828cdb
-
828cdb
-    // Calculate a File object referencing this document base directory
828cdb
-    base = new File(docBase);
828cdb
+        // Calculate a File object referencing this document base directory
828cdb
+        base = new File(docBase);
828cdb
         try {
828cdb
             base = base.getCanonicalFile();
828cdb
         } catch (IOException e) {
828cdb
             // Ignore
828cdb
         }
828cdb
 
828cdb
-    // Validate that the document base is an existing directory
828cdb
-    if (!base.exists() || !base.isDirectory() || !base.canRead())
828cdb
-        throw new IllegalArgumentException
828cdb
-        (sm.getString("fileResources.base", docBase));
828cdb
-        this.absoluteBase = base.getAbsolutePath();
828cdb
-        super.setDocBase(docBase);
828cdb
+        // Validate that the document base is an existing directory
828cdb
+        if (!base.exists() || !base.isDirectory() || !base.canRead()) {
828cdb
+            throw new IllegalArgumentException(sm.getString("fileResources.base", docBase));
828cdb
+        }
828cdb
 
828cdb
+        this.absoluteBase = normalize(base.getAbsolutePath());
828cdb
+
828cdb
+        // absoluteBase also needs to be normalized. Using the canonical path is
828cdb
+        // the simplest way of doing this.
828cdb
+        try {
828cdb
+            this.canonicalBase = base.getCanonicalPath();
828cdb
+        } catch (IOException e) {
828cdb
+            throw new IllegalArgumentException(e);
828cdb
+        }
828cdb
+        super.setDocBase(docBase);
828cdb
     }
828cdb
 
828cdb
 
828cdb
     /**
828cdb
      * Set allow linking.
828cdb
+     *
828cdb
+     * @param allowLinking The new value for the attribute
828cdb
      */
828cdb
     public void setAllowLinking(boolean allowLinking) {
828cdb
         this.allowLinking = allowLinking;
828cdb
@@ -151,6 +161,8 @@
828cdb
 
828cdb
     /**
828cdb
      * Is linking allowed.
828cdb
+     *
828cdb
+     * @return {@code true} is linking is allowed, otherwise {@false}
828cdb
      */
828cdb
     public boolean getAllowLinking() {
828cdb
         return allowLinking;
828cdb
@@ -193,7 +205,7 @@
828cdb
     @Override
828cdb
     protected Object doLookup(String name) {
828cdb
         Object result = null;
828cdb
-        File file = file(name);
828cdb
+        File file = file(name, true);
828cdb
 
828cdb
         if (file == null)
828cdb
             return null;
828cdb
@@ -230,7 +242,7 @@
828cdb
     public void unbind(String name)
828cdb
         throws NamingException {
828cdb
 
828cdb
-        File file = file(name);
828cdb
+        File file = file(name, true);
828cdb
 
828cdb
         if (file == null)
828cdb
             throw new NameNotFoundException(
828cdb
@@ -255,22 +267,22 @@
828cdb
      * @exception NamingException if a naming exception is encountered
828cdb
      */
828cdb
     @Override
828cdb
-    public void rename(String oldName, String newName)
828cdb
-        throws NamingException {
828cdb
+    public void rename(String oldName, String newName) throws NamingException {
828cdb
 
828cdb
-        File file = file(oldName);
828cdb
+        File file = file(oldName, true);
828cdb
 
828cdb
-        if (file == null)
828cdb
-            throw new NameNotFoundException
828cdb
-                (sm.getString("resources.notFound", oldName));
828cdb
+        if (file == null) {
828cdb
+            throw new NameNotFoundException(sm.getString("resources.notFound", oldName));
828cdb
+        }
828cdb
 
828cdb
-        File newFile = new File(base, newName);
828cdb
+        File newFile = file(newName, false);
828cdb
+        if (newFile == null) {
828cdb
+            throw new NamingException(sm.getString("resources.renameFail", oldName, newName));
828cdb
+        }
828cdb
 
828cdb
         if (!file.renameTo(newFile)) {
828cdb
-            throw new NamingException(sm.getString("resources.renameFail",
828cdb
-                    oldName, newName));
828cdb
+            throw new NamingException(sm.getString("resources.renameFail", oldName, newName));
828cdb
         }
828cdb
-
828cdb
     }
828cdb
 
828cdb
 
828cdb
@@ -291,11 +303,11 @@
828cdb
     protected List<NamingEntry> doListBindings(String name)
828cdb
         throws NamingException {
828cdb
 
828cdb
-        File file = file(name);
828cdb
+        File file = file(name, true);
828cdb
 
828cdb
         if (file == null)
828cdb
             return null;
828cdb
-        
828cdb
+
828cdb
         return list(file);
828cdb
 
828cdb
     }
828cdb
@@ -395,7 +407,7 @@
828cdb
         throws NamingException {
828cdb
 
828cdb
         // Building attribute list
828cdb
-        File file = file(name);
828cdb
+        File file = file(name, true);
828cdb
 
828cdb
         if (file == null)
828cdb
             return null;
828cdb
@@ -463,12 +475,20 @@
828cdb
      * @exception NamingException if a naming exception is encountered
828cdb
      */
828cdb
     @Override
828cdb
-    public void bind(String name, Object obj, Attributes attrs)
828cdb
-        throws NamingException {
828cdb
+    public void bind(String name, Object obj, Attributes attrs) throws NamingException {
828cdb
 
828cdb
         // Note: No custom attributes allowed
828cdb
 
828cdb
-        File file = new File(base, name);
828cdb
+        // bind() is meant to create a file so ensure that the path doesn't end
828cdb
+        // in '/'
828cdb
+        if (name.endsWith("/")) {
828cdb
+            throw new NamingException(sm.getString("resources.bindFailed", name));
828cdb
+        }
828cdb
+
828cdb
+        File file = file(name, false);
828cdb
+        if (file == null) {
828cdb
+            throw new NamingException(sm.getString("resources.bindFailed", name));
828cdb
+        }
828cdb
         if (file.exists())
828cdb
             throw new NameAlreadyBoundException
828cdb
                 (sm.getString("resources.alreadyBound", name));
828cdb
@@ -503,7 +523,10 @@
828cdb
         // Note: No custom attributes allowed
828cdb
         // Check obj type
828cdb
 
828cdb
-        File file = new File(base, name);
828cdb
+        File file = file(name, false);
828cdb
+        if (file == null) {
828cdb
+            throw new NamingException(sm.getString("resources.bindFailed", name));
828cdb
+        }
828cdb
 
828cdb
         InputStream is = null;
828cdb
         if (obj instanceof Resource) {
828cdb
@@ -583,13 +606,14 @@
828cdb
     public DirContext createSubcontext(String name, Attributes attrs)
828cdb
         throws NamingException {
828cdb
 
828cdb
-        File file = new File(base, name);
828cdb
+        File file = file(name, false);
828cdb
+        if (file == null) {
828cdb
+            throw new NamingException(sm.getString("resources.bindFailed", name));
828cdb
+        }
828cdb
         if (file.exists())
828cdb
-            throw new NameAlreadyBoundException
828cdb
-                (sm.getString("resources.alreadyBound", name));
828cdb
+            throw new NameAlreadyBoundException(sm.getString("resources.alreadyBound", name));
828cdb
         if (!file.mkdir())
828cdb
-            throw new NamingException
828cdb
-                (sm.getString("resources.bindFailed", name));
828cdb
+            throw new NamingException(sm.getString("resources.bindFailed", name));
828cdb
         return (DirContext) lookup(name);
828cdb
 
828cdb
     }
828cdb
@@ -758,6 +782,7 @@
828cdb
 
828cdb
     }
828cdb
 
828cdb
+
828cdb
     /**
828cdb
      * Return a File object representing the specified normalized
828cdb
      * context-relative path if it exists and is readable.  Otherwise,
828cdb
@@ -766,51 +791,133 @@
828cdb
      * @param name Normalized context-relative path (with leading '/')
828cdb
      */
828cdb
     protected File file(String name) {
828cdb
+        return file(name, true);
828cdb
+    }
828cdb
+
828cdb
+
828cdb
+    /**
828cdb
+     * Return a File object representing the specified normalized
828cdb
+     * context-relative path if it exists and is readable.  Otherwise,
828cdb
+     * return null.
828cdb
+     *
828cdb
+     * @param name      Normalized context-relative path (with leading '/')
828cdb
+     * @param mustExist Must the specified resource exist?
828cdb
+     */
828cdb
+    protected File file(String name, boolean mustExist) {
828cdb
+        if (name.equals("/")) {
828cdb
+            name = "";
828cdb
+        }
828cdb
 
828cdb
         File file = new File(base, name);
828cdb
-        if (file.exists() && file.canRead()) {
828cdb
+        return validate(file, name, mustExist, absoluteBase, canonicalBase);
828cdb
+    }
828cdb
 
828cdb
-            if (allowLinking)
828cdb
-                return file;
828cdb
-            
828cdb
-            // Check that this file belongs to our root path
828cdb
-            String canPath = null;
828cdb
-            try {
828cdb
-                canPath = file.getCanonicalPath();
828cdb
-            } catch (IOException e) {
828cdb
-                // Ignore
828cdb
-            }
828cdb
-            if (canPath == null)
828cdb
-                return null;
828cdb
 
828cdb
-            // Check to see if going outside of the web application root
828cdb
-            if (!canPath.startsWith(absoluteBase)) {
828cdb
-                return null;
828cdb
-            }
828cdb
+    protected File validate(File file, String name, boolean mustExist, String absoluteBase,
828cdb
+            String canonicalBase) {
828cdb
 
828cdb
-            // Case sensitivity check - this is now always done
828cdb
-            String fileAbsPath = file.getAbsolutePath();
828cdb
-            if (fileAbsPath.endsWith("."))
828cdb
-                fileAbsPath = fileAbsPath + "/";
828cdb
-            String absPath = normalize(fileAbsPath);
828cdb
-            canPath = normalize(canPath);
828cdb
-            if ((absoluteBase.length() < absPath.length())
828cdb
-                && (absoluteBase.length() < canPath.length())) {
828cdb
-                absPath = absPath.substring(absoluteBase.length() + 1);
828cdb
-                if (absPath.equals(""))
828cdb
-                    absPath = "/";
828cdb
-                canPath = canPath.substring(absoluteBase.length() + 1);
828cdb
-                if (canPath.equals(""))
828cdb
-                    canPath = "/";
828cdb
-                if (!canPath.equals(absPath))
828cdb
-                    return null;
828cdb
-            }
828cdb
+        // If the requested names ends in '/', the Java File API will return a
828cdb
+        // matching file if one exists. This isn't what we want as it is not
828cdb
+        // consistent with the Servlet spec rules for request mapping.
828cdb
+        if (name.endsWith("/") && file.isFile()) {
828cdb
+            return null;
828cdb
+        }
828cdb
 
828cdb
-        } else {
828cdb
+        // If the file/dir must exist but the identified file/dir can't be read
828cdb
+        // then signal that the resource was not found
828cdb
+        if (mustExist && !file.canRead()) {
828cdb
+            return null;
828cdb
+        }
828cdb
+
828cdb
+        // If allow linking is enabled, files are not limited to being located
828cdb
+        // under the fileBase so all further checks are disabled.
828cdb
+        if (allowLinking) {
828cdb
+            return file;
828cdb
+        }
828cdb
+
828cdb
+        // Additional Windows specific checks to handle known problems with
828cdb
+        // File.getCanonicalPath()
828cdb
+        if (JrePlatform.IS_WINDOWS && isInvalidWindowsFilename(name)) {
828cdb
+            return null;
828cdb
+        }
828cdb
+
828cdb
+        // Check that this file is located under the web application root
828cdb
+        String canPath = null;
828cdb
+        try {
828cdb
+            canPath = file.getCanonicalPath();
828cdb
+        } catch (IOException e) {
828cdb
+            // Ignore
828cdb
+        }
828cdb
+        if (canPath == null || !canPath.startsWith(canonicalBase)) {
828cdb
+            return null;
828cdb
+        }
828cdb
+
828cdb
+        // Ensure that the file is not outside the fileBase. This should not be
828cdb
+        // possible for standard requests (the request is normalized early in
828cdb
+        // the request processing) but might be possible for some access via the
828cdb
+        // Servlet API (RequestDispatcher etc.) therefore these checks are
828cdb
+        // retained as an additional safety measure. absoluteBase has been
828cdb
+        // normalized so absPath needs to be normalized as well.
828cdb
+        String absPath = normalize(file.getAbsolutePath());
828cdb
+        if ((absoluteBase.length() > absPath.length())) {
828cdb
             return null;
828cdb
         }
828cdb
+
828cdb
+        // Remove the fileBase location from the start of the paths since that
828cdb
+        // was not part of the requested path and the remaining check only
828cdb
+        // applies to the request path
828cdb
+        absPath = absPath.substring(absoluteBase.length());
828cdb
+        canPath = canPath.substring(canonicalBase.length());
828cdb
+
828cdb
+        // Case sensitivity check
828cdb
+        // The normalized requested path should be an exact match the equivalent
828cdb
+        // canonical path. If it is not, possible reasons include:
828cdb
+        // - case differences on case insensitive file systems
828cdb
+        // - Windows removing a trailing ' ' or '.' from the file name
828cdb
+        //
828cdb
+        // In all cases, a mis-match here results in the resource not being
828cdb
+        // found
828cdb
+        //
828cdb
+        // absPath is normalized so canPath needs to be normalized as well
828cdb
+        // Can't normalize canPath earlier as canonicalBase is not normalized
828cdb
+        if (canPath.length() > 0) {
828cdb
+            canPath = normalize(canPath);
828cdb
+        }
828cdb
+        if (!canPath.equals(absPath)) {
828cdb
+            return null;
828cdb
+        }
828cdb
+
828cdb
         return file;
828cdb
+    }
828cdb
+
828cdb
 
828cdb
+    private boolean isInvalidWindowsFilename(String name) {
828cdb
+        final int len = name.length();
828cdb
+        if (len == 0) {
828cdb
+            return false;
828cdb
+        }
828cdb
+        // This consistently ~10 times faster than the equivalent regular
828cdb
+        // expression irrespective of input length.
828cdb
+        for (int i = 0; i < len; i++) {
828cdb
+            char c = name.charAt(i);
828cdb
+            if (c == '\"' || c == '<' || c == '>') {
828cdb
+                // These characters are disallowed in Windows file names and
828cdb
+                // there are known problems for file names with these characters
828cdb
+                // when using File#getCanonicalPath().
828cdb
+                // Note: There are additional characters that are disallowed in
828cdb
+                //       Windows file names but these are not known to cause
828cdb
+                //       problems when using File#getCanonicalPath().
828cdb
+                return true;
828cdb
+            }
828cdb
+        }
828cdb
+        // Windows does not allow file names to end in ' ' unless specific low
828cdb
+        // level APIs are used to create the files that bypass various checks.
828cdb
+        // File names that end in ' ' are known to cause problems when using
828cdb
+        // File#getCanonicalPath().
828cdb
+        if (name.charAt(len -1) == ' ') {
828cdb
+            return true;
828cdb
+        }
828cdb
+        return false;
828cdb
     }
828cdb
 
828cdb
 
828cdb
@@ -1054,10 +1161,10 @@
828cdb
             return super.getResourceType();
828cdb
         }
828cdb
 
828cdb
-        
828cdb
+
828cdb
         /**
828cdb
          * Get canonical path.
828cdb
-         * 
828cdb
+         *
828cdb
          * @return String the file's canonical path
828cdb
          */
828cdb
         @Override
828cdb
@@ -1071,10 +1178,6 @@
828cdb
             }
828cdb
             return canonicalPath;
828cdb
         }
828cdb
-        
828cdb
-
828cdb
     }
828cdb
-
828cdb
-
828cdb
 }
828cdb
 
828cdb
--- java/org/apache/naming/resources/VirtualDirContext.java.orig	2017-10-13 09:41:05.740302370 -0400
828cdb
+++ java/org/apache/naming/resources/VirtualDirContext.java	2017-10-13 09:42:53.517701300 -0400
828cdb
@@ -76,7 +76,8 @@
828cdb
      * be listed twice.
828cdb
      * 

828cdb
      *
828cdb
-     * @param path
828cdb
+     * @param path The set of file system paths and virtual paths to map them to
828cdb
+     *             in the required format
828cdb
      */
828cdb
     public void setExtraResourcePaths(String path) {
828cdb
         extraResourcePaths = path;
828cdb
@@ -106,13 +107,13 @@
828cdb
                     }
828cdb
                     path = resSpec.substring(0, idx);
828cdb
                 }
828cdb
-                String dir = resSpec.substring(idx + 1);
828cdb
+                File dir = new File(resSpec.substring(idx + 1));
828cdb
                 List<String> resourcePaths = mappedResourcePaths.get(path);
828cdb
                 if (resourcePaths == null) {
828cdb
                     resourcePaths = new ArrayList<String>();
828cdb
                     mappedResourcePaths.put(path, resourcePaths);
828cdb
                 }
828cdb
-                resourcePaths.add(dir);
828cdb
+                resourcePaths.add(dir.getAbsolutePath());
828cdb
             }
828cdb
         }
828cdb
         if (mappedResourcePaths.isEmpty()) {
828cdb
@@ -151,15 +152,17 @@
828cdb
                 String resourcesDir = dirList.get(0);
828cdb
                 if (name.equals(path)) {
828cdb
                     File f = new File(resourcesDir);
828cdb
-                    if (f.exists() && f.canRead()) {
828cdb
+                    f = validate(f, name, true, resourcesDir);
828cdb
+                    if (f != null) {
828cdb
                         return new FileResourceAttributes(f);
828cdb
                     }
828cdb
                 }
828cdb
                 path += "/";
828cdb
                 if (name.startsWith(path)) {
828cdb
                     String res = name.substring(path.length());
828cdb
-                    File f = new File(resourcesDir + "/" + res);
828cdb
-                    if (f.exists() && f.canRead()) {
828cdb
+                    File f = new File(resourcesDir, res);
828cdb
+                    f = validate(f, res, true, resourcesDir);
828cdb
+                    if (f != null) {
828cdb
                         return new FileResourceAttributes(f);
828cdb
                     }
828cdb
                 }
828cdb
@@ -168,9 +171,16 @@
828cdb
         throw initialException;
828cdb
     }
828cdb
 
828cdb
+
828cdb
     @Override
828cdb
     protected File file(String name) {
828cdb
-        File file = super.file(name);
828cdb
+        return file(name, true);
828cdb
+    }
828cdb
+
828cdb
+
828cdb
+    @Override
828cdb
+    protected File file(String name, boolean mustExist) {
828cdb
+        File file = super.file(name, true);
828cdb
         if (file != null || mappedResourcePaths == null) {
828cdb
             return file;
828cdb
         }
828cdb
@@ -185,7 +195,8 @@
828cdb
             if (name.equals(path)) {
828cdb
                 for (String resourcesDir : dirList) {
828cdb
                     file = new File(resourcesDir);
828cdb
-                    if (file.exists() && file.canRead()) {
828cdb
+                    file = validate(file, name, true, resourcesDir);
828cdb
+                    if (file != null) {
828cdb
                         return file;
828cdb
                     }
828cdb
                 }
828cdb
@@ -194,7 +205,8 @@
828cdb
                 String res = name.substring(path.length());
828cdb
                 for (String resourcesDir : dirList) {
828cdb
                     file = new File(resourcesDir, res);
828cdb
-                    if (file.exists() && file.canRead()) {
828cdb
+                    file = validate(file, res, true, resourcesDir);
828cdb
+                    if (file != null) {
828cdb
                         return file;
828cdb
                     }
828cdb
                 }
828cdb
@@ -229,7 +241,8 @@
828cdb
                     if (res != null) {
828cdb
                         for (String resourcesDir : dirList) {
828cdb
                             File f = new File(resourcesDir, res);
828cdb
-                            if (f.exists() && f.canRead() && f.isDirectory()) {
828cdb
+                            f = validate(f, res, true, resourcesDir);
828cdb
+                            if (f != null && f.isDirectory()) {
828cdb
                                 List<NamingEntry> virtEntries = super.list(f);
828cdb
                                 for (NamingEntry entry : virtEntries) {
828cdb
                                     // filter duplicate
828cdb
@@ -264,7 +277,8 @@
828cdb
             if (name.equals(path)) {
828cdb
                 for (String resourcesDir : dirList) {
828cdb
                     File f = new File(resourcesDir);
828cdb
-                    if (f.exists() && f.canRead()) {
828cdb
+                    f = validate(f, name, true, resourcesDir);
828cdb
+                    if (f != null) {
828cdb
                         if (f.isFile()) {
828cdb
                             return new FileResource(f);
828cdb
                         }
828cdb
@@ -279,8 +293,9 @@
828cdb
             if (name.startsWith(path)) {
828cdb
                 String res = name.substring(path.length());
828cdb
                 for (String resourcesDir : dirList) {
828cdb
-                    File f = new File(resourcesDir + "/" + res);
828cdb
-                    if (f.exists() && f.canRead()) {
828cdb
+                    File f = new File(resourcesDir, res);
828cdb
+                    f = validate(f, res, true, resourcesDir);
828cdb
+                    if (f != null) {
828cdb
                         if (f.isFile()) {
828cdb
                             return new FileResource(f);
828cdb
                         }
828cdb
@@ -304,4 +319,9 @@
828cdb
             return null;
828cdb
         }
828cdb
     }
828cdb
+
828cdb
+
828cdb
+    protected File validate(File file, String name, boolean mustExist, String absoluteBase) {
828cdb
+        return validate(file, name, mustExist, normalize(absoluteBase), absoluteBase);
828cdb
+    }
828cdb
 }
828cdb
--- webapps/docs/changelog.xml.orig	2017-10-13 09:15:35.996884086 -0400
828cdb
+++ webapps/docs/changelog.xml	2017-10-13 09:44:50.895046977 -0400
828cdb
@@ -64,6 +64,14 @@
828cdb
         <bug>61101</bug>: CORS filter should set Vary header in response.
828cdb
         Submitted by Rick Riemer. (remm)
828cdb
       </fix>
828cdb
+      <fix>
828cdb
+        Correct regression in 7.0.80 that broke WebDAV. (markt)
828cdb
+      </fix>
828cdb
+      <fix>
828cdb
+        <bug>61542</bug>: Fix CVE-2017-12617 and prevent JSPs from being
828cdb
+        uploaded via a specially crafted request when HTTP PUT was enabled.
828cdb
+        (markt)
828cdb
+      </fix>
828cdb
     </changelog>
828cdb
   </subsection>
828cdb
 </section>
828cdb
--- java/org/apache/naming/resources/JrePlatform.java.orig	2017-10-13 09:41:05.745302342 -0400
828cdb
+++ java/org/apache/naming/resources/JrePlatform.java	2017-10-13 09:42:53.516701306 -0400
828cdb
@@ -0,0 +1,59 @@
828cdb
+/*
828cdb
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
828cdb
+ *  contributor license agreements.  See the NOTICE file distributed with
828cdb
+ *  this work for additional information regarding copyright ownership.
828cdb
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
828cdb
+ *  (the "License"); you may not use this file except in compliance with
828cdb
+ *  the License.  You may obtain a copy of the License at
828cdb
+ *
828cdb
+ *      http://www.apache.org/licenses/LICENSE-2.0
828cdb
+ *
828cdb
+ *  Unless required by applicable law or agreed to in writing, software
828cdb
+ *  distributed under the License is distributed on an "AS IS" BASIS,
828cdb
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
828cdb
+ *  See the License for the specific language governing permissions and
828cdb
+ *  limitations under the License.
828cdb
+ */
828cdb
+package org.apache.naming.resources;
828cdb
+
828cdb
+import java.security.AccessController;
828cdb
+import java.security.PrivilegedAction;
828cdb
+
828cdb
+public class JrePlatform {
828cdb
+
828cdb
+    private static final String OS_NAME_PROPERTY = "os.name";
828cdb
+    private static final String OS_NAME_WINDOWS_PREFIX = "Windows";
828cdb
+
828cdb
+    static {
828cdb
+        /*
828cdb
+         * There are a few places where a) the behaviour of the Java API depends
828cdb
+         * on the underlying platform and b) those behavioural differences have
828cdb
+         * an impact on Tomcat.
828cdb
+         *
828cdb
+         * Tomcat therefore needs to be able to determine the platform it is
828cdb
+         * running on to account for those differences.
828cdb
+         *
828cdb
+         * In an ideal world this code would not exist.
828cdb
+         */
828cdb
+
828cdb
+        // This check is derived from the check in Apache Commons Lang
828cdb
+        String osName;
828cdb
+        if (System.getSecurityManager() == null) {
828cdb
+            osName = System.getProperty(OS_NAME_PROPERTY);
828cdb
+        } else {
828cdb
+            osName = AccessController.doPrivileged(
828cdb
+                    new PrivilegedAction<String>() {
828cdb
+
828cdb
+                    @Override
828cdb
+                    public String run() {
828cdb
+                        return System.getProperty(OS_NAME_PROPERTY);
828cdb
+                    }
828cdb
+                });
828cdb
+        }
828cdb
+
828cdb
+        IS_WINDOWS = osName.startsWith(OS_NAME_WINDOWS_PREFIX);
828cdb
+    }
828cdb
+
828cdb
+
828cdb
+    public static final boolean IS_WINDOWS;
828cdb
+}
828cdb
--- test/org/apache/naming/resources/TestFileDirContext.java.orig	2017-10-13 09:45:35.991795584 -0400
828cdb
+++ test/org/apache/naming/resources/TestFileDirContext.java	2017-10-13 09:42:53.517701300 -0400
828cdb
@@ -0,0 +1,46 @@
828cdb
+/*
828cdb
+ * Licensed to the Apache Software Foundation (ASF) under one or more
828cdb
+ * contributor license agreements.  See the NOTICE file distributed with
828cdb
+ * this work for additional information regarding copyright ownership.
828cdb
+ * The ASF licenses this file to You under the Apache License, Version 2.0
828cdb
+ * (the "License"); you may not use this file except in compliance with
828cdb
+ * the License.  You may obtain a copy of the License at
828cdb
+ *
828cdb
+ *      http://www.apache.org/licenses/LICENSE-2.0
828cdb
+ *
828cdb
+ * Unless required by applicable law or agreed to in writing, software
828cdb
+ * distributed under the License is distributed on an "AS IS" BASIS,
828cdb
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
828cdb
+ * See the License for the specific language governing permissions and
828cdb
+ * limitations under the License.
828cdb
+ */
828cdb
+package org.apache.naming.resources;
828cdb
+
828cdb
+import java.io.File;
828cdb
+
828cdb
+import javax.servlet.http.HttpServletResponse;
828cdb
+
828cdb
+import org.junit.Assert;
828cdb
+import org.junit.Test;
828cdb
+
828cdb
+import org.apache.catalina.startup.Tomcat;
828cdb
+import org.apache.catalina.startup.TomcatBaseTest;
828cdb
+import org.apache.tomcat.util.buf.ByteChunk;
828cdb
+
828cdb
+public class TestFileDirContext extends TomcatBaseTest {
828cdb
+
828cdb
+    @Test
828cdb
+    public void testLookupResourceWithTrailingSlash() throws Exception {
828cdb
+        Tomcat tomcat = getTomcatInstance();
828cdb
+
828cdb
+        File appDir = new File("test/webapp-3.0");
828cdb
+        // app dir is relative to server home
828cdb
+        tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
828cdb
+
828cdb
+        tomcat.start();
828cdb
+
828cdb
+        int sc = getUrl("http://localhost:" + getPort() +
828cdb
+                "/test/index.html/", new ByteChunk(), null);
828cdb
+        Assert.assertEquals(HttpServletResponse.SC_NOT_FOUND, sc);
828cdb
+    }
828cdb
+}