Author: markt
Date: Tue Dec 11 14:29:27 2018
New Revision: 1848687

URL: http://svn.apache.org/viewvc?rev=1848687&view=rev
Log:
Implement the requirements of section 8.2.2 2c of the Servlet specification and 
prevent a web application from deploying if it has fragments with duplicate 
names and is configured to use relative ordering of fragments.

Modified:
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/LocalStrings.properties
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/WebXml.java
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/ContextConfig.java
    tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml

Modified: 
tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/LocalStrings.properties
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/LocalStrings.properties?rev=1848687&r1=1848686&r2=1848687&view=diff
==============================================================================
--- 
tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/LocalStrings.properties 
(original)
+++ 
tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/LocalStrings.properties 
Tue Dec 11 14:29:27 2018
@@ -19,6 +19,7 @@ servletDef.invalidServletName=Invalid <s
 
 webXml.duplicateEnvEntry=Duplicate env-entry name [{0}]
 webXml.duplicateFilter=Duplicate filter name [{0}]
+webXml.duplicateFragment=More than one fragment with the name [{0}] was found. 
This is not legal with relative ordering. See section 8.2.2 2c of the Servlet 
specification for details. Consider using absolute ordering.
 webXml.duplicateMessageDestination=Duplicate message-destination name [{0}]
 webXml.duplicateMessageDestinationRef=Duplicate message-destination-ref name 
[{0}]
 webXml.duplicateResourceEnvRef=Duplicate resource-env-ref name [{0}]

Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/WebXml.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/WebXml.java?rev=1848687&r1=1848686&r2=1848687&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/WebXml.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/WebXml.java Tue Dec 11 
14:29:27 2018
@@ -76,6 +76,19 @@ public class WebXml {
         this.overridable = overridable;
     }
 
+    /*
+     * Ideally, fragment names will be unique. If they are not, Tomcat needs
+     * to know as the action that the specification requires (see 8.2.2 1.e and
+     * 2.c) varies depending on the ordering method used.
+     */
+    private boolean duplicated = false;
+    public boolean isDuplicated() {
+        return duplicated;
+    }
+    public void setDuplicated(boolean duplicated) {
+        this.duplicated = duplicated;
+    }
+
     // web.xml only elements
     // Absolute Ordering
     private Set<String> absoluteOrdering = null;
@@ -2319,6 +2332,13 @@ public class WebXml {
                 }
             }
         } else {
+            // Stage 0. Check there were no fragments with duplicate names
+            for (WebXml fragment : fragments.values()) {
+                if (fragment.isDuplicated()) {
+                    throw new IllegalArgumentException(
+                            sm.getString("webXml.duplicateFragment", 
fragment.getName()));
+                }
+            }
             // Stage 1. Make all dependencies bi-directional - this makes the
             //          next stage simpler.
             for (WebXml fragment : fragments.values()) {

Modified: 
tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/ContextConfig.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/ContextConfig.java?rev=1848687&r1=1848686&r2=1848687&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/ContextConfig.java 
(original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/ContextConfig.java 
Tue Dec 11 14:29:27 2018
@@ -2699,12 +2699,7 @@ public class ContextConfig implements Li
                 if (jar != null) {
                     jar.close();
                 }
-                fragment.setURL(url);
-                if (fragment.getName() == null) {
-                    fragment.setName(fragment.getURL().toString());
-                }
-                fragment.setJarName(extractJarFileName(url));
-                fragments.put(fragment.getName(), fragment);
+                addFragment(fragment, url);
             }
         }
 
@@ -2745,13 +2740,26 @@ public class ContextConfig implements Li
                     } catch (IOException e) {
                     }
                 }
-                fragment.setURL(file.toURI().toURL());
-                if (fragment.getName() == null) {
-                    fragment.setName(fragment.getURL().toString());
-                }
-                fragment.setJarName(file.getName());
-                fragments.put(fragment.getName(), fragment);
+                addFragment(fragment, file.toURI().toURL());
+            }
+        }
+
+        private void addFragment(WebXml fragment, URL url) {
+            fragment.setURL(url);
+            if (fragment.getName() == null) {
+                fragment.setName(url.toString());
             }
+            fragment.setJarName(extractJarFileName(url));
+            if (fragments.containsKey(fragment.getName())) {
+                // Duplicate. Mark the fragment that has already been found 
with
+                // this name as having a duplicate so Tomcat can handle it
+                // correctly when the fragments are being ordered.
+                String duplicateName = fragment.getName();
+                fragments.get(duplicateName).setDuplicated(true);
+                // Rename the current fragment so it doesn't clash
+                fragment.setName(url.toString());
+             }
+            fragments.put(fragment.getName(), fragment);
         }
 
         public Map<String,WebXml> getFragments() {

Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1848687&r1=1848686&r2=1848687&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Tue Dec 11 14:29:27 2018
@@ -83,6 +83,12 @@
         web application start to make integration simpler for downstream users.
         Based on a patch provided by rmannibucau. (markt)
       </scode>
+      <fix>
+        Implement the requirements of section 8.2.2 2c of the Servlet
+        specification and prevent a web application from deploying if it has
+        fragments with duplicate names and is configured to use relative
+        ordering of fragments. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Other">



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

Reply via email to