]> git.pld-linux.org Git - packages/tomcat.git/blob - tomcat-CVE-2008-5515.patch
- merged DEVEL
[packages/tomcat.git] / tomcat-CVE-2008-5515.patch
1 Index: container/catalina/src/share/org/apache/naming/resources/FileDirContext.java
2 ===================================================================
3 --- container/catalina/src/share/org/apache/naming/resources/FileDirContext.java        (wersja 782756)
4 +++ container/catalina/src/share/org/apache/naming/resources/FileDirContext.java        (wersja 782757)
5 @@ -37,6 +37,7 @@
6  import javax.naming.directory.ModificationItem;
7  import javax.naming.directory.SearchControls;
8  
9 +import org.apache.catalina.util.RequestUtil;
10  import org.apache.naming.NamingContextBindingsEnumeration;
11  import org.apache.naming.NamingContextEnumeration;
12  import org.apache.naming.NamingEntry;
13 @@ -773,50 +774,10 @@
14       */
15      protected String normalize(String path) {
16  
17 -    String normalized = path;
18 +        return RequestUtil.normalize(path, File.separatorChar == '\\');
19  
20 -    // Normalize the slashes and add leading slash if necessary
21 -    if (File.separatorChar == '\\' && normalized.indexOf('\\') >= 0)
22 -        normalized = normalized.replace('\\', '/');
23 -    if (!normalized.startsWith("/"))
24 -        normalized = "/" + normalized;
25 -
26 -    // Resolve occurrences of "//" in the normalized path
27 -    while (true) {
28 -        int index = normalized.indexOf("//");
29 -        if (index < 0)
30 -        break;
31 -        normalized = normalized.substring(0, index) +
32 -        normalized.substring(index + 1);
33      }
34  
35 -    // Resolve occurrences of "/./" in the normalized path
36 -    while (true) {
37 -        int index = normalized.indexOf("/./");
38 -        if (index < 0)
39 -        break;
40 -        normalized = normalized.substring(0, index) +
41 -        normalized.substring(index + 2);
42 -    }
43 -
44 -    // Resolve occurrences of "/../" in the normalized path
45 -    while (true) {
46 -        int index = normalized.indexOf("/../");
47 -        if (index < 0)
48 -        break;
49 -        if (index == 0)
50 -        return (null);  // Trying to go outside our context
51 -        int index2 = normalized.lastIndexOf('/', index - 1);
52 -        normalized = normalized.substring(0, index2) +
53 -        normalized.substring(index + 3);
54 -    }
55 -
56 -    // Return the normalized path that we have completed
57 -    return (normalized);
58 -
59 -    }
60 -
61 -
62      /**
63       * Return a File object representing the specified normalized
64       * context-relative path if it exists and is readable.  Otherwise,
65 Index: container/catalina/src/share/org/apache/catalina/core/ApplicationHttpRequest.java
66 ===================================================================
67 --- container/catalina/src/share/org/apache/catalina/core/ApplicationHttpRequest.java   (wersja 782756)
68 +++ container/catalina/src/share/org/apache/catalina/core/ApplicationHttpRequest.java   (wersja 782757)
69 @@ -318,10 +318,9 @@
70          int pos = requestPath.lastIndexOf('/');
71          String relative = null;
72          if (pos >= 0) {
73 -            relative = RequestUtil.normalize
74 -                (requestPath.substring(0, pos + 1) + path);
75 +            relative = requestPath.substring(0, pos + 1) + path;
76          } else {
77 -            relative = RequestUtil.normalize(requestPath + path);
78 +            relative = requestPath + path;
79          }
80  
81          return (context.getServletContext().getRequestDispatcher(relative));
82 Index: container/catalina/src/share/org/apache/catalina/core/ApplicationContext.java
83 ===================================================================
84 --- container/catalina/src/share/org/apache/catalina/core/ApplicationContext.java       (wersja 782756)
85 +++ container/catalina/src/share/org/apache/catalina/core/ApplicationContext.java       (wersja 782757)
86 @@ -43,6 +43,7 @@
87  import org.apache.catalina.Wrapper;
88  import org.apache.catalina.deploy.ApplicationParameter;
89  import org.apache.catalina.util.Enumerator;
90 +import org.apache.catalina.util.RequestUtil;
91  import org.apache.catalina.util.ResourceSet;
92  import org.apache.catalina.util.ServerInfo;
93  import org.apache.catalina.util.StringManager;
94 @@ -388,7 +389,7 @@
95              path = path.substring(0, pos); 
96          }
97   
98 -        path = normalize(path);
99 +        path = RequestUtil.normalize(path);
100          if (path == null)
101              return (null);
102  
103 @@ -475,7 +476,7 @@
104              throw new MalformedURLException(sm.getString("applicationContext.requestDispatcher.iae", path));
105          }
106          
107 -        path = normalize(path);
108 +        path = RequestUtil.normalize(path);
109          if (path == null)
110              return (null);
111  
112 @@ -524,10 +525,13 @@
113       */
114      public InputStream getResourceAsStream(String path) {
115  
116 -        path = normalize(path);
117          if (path == null || !path.startsWith("/"))
118              return (null);
119  
120 +        path = RequestUtil.normalize(path);
121 +        if (path == null)
122 +            return null;
123 +
124          DirContext resources = context.getResources();
125          if (resources != null) {
126              try {
127 @@ -560,7 +564,7 @@
128                  (sm.getString("applicationContext.resourcePaths.iae", path));
129          }
130  
131 -        path = normalize(path);
132 +        path = RequestUtil.normalize(path);
133          if (path == null)
134              return (null);
135  
136 @@ -870,45 +874,6 @@
137  
138  
139      /**
140 -     * Return a context-relative path, beginning with a "/", that represents
141 -     * the canonical version of the specified path after ".." and "." elements
142 -     * are resolved out.  If the specified path attempts to go outside the
143 -     * boundaries of the current context (i.e. too many ".." path elements
144 -     * are present), return <code>null</code> instead.
145 -     *
146 -     * @param path Path to be normalized
147 -     */
148 -    private String normalize(String path) {
149 -
150 -        if (path == null) {
151 -            return null;
152 -        }
153 -
154 -        String normalized = path;
155 -
156 -        // Normalize the slashes
157 -        if (normalized.indexOf('\\') >= 0)
158 -            normalized = normalized.replace('\\', '/');
159 -
160 -        // Resolve occurrences of "/../" in the normalized path
161 -        while (true) {
162 -            int index = normalized.indexOf("/../");
163 -            if (index < 0)
164 -                break;
165 -            if (index == 0)
166 -                return (null);  // Trying to go outside our context
167 -            int index2 = normalized.lastIndexOf('/', index - 1);
168 -            normalized = normalized.substring(0, index2) +
169 -                normalized.substring(index + 3);
170 -        }
171 -
172 -        // Return the normalized path that we have completed
173 -        return (normalized);
174 -
175 -    }
176 -
177 -
178 -    /**
179       * Merge the context initialization parameters specified in the application
180       * deployment descriptor with the application parameters described in the
181       * server configuration, respecting the <code>override</code> property of
182 Index: container/catalina/src/share/org/apache/catalina/servlets/WebdavServlet.java
183 ===================================================================
184 --- container/catalina/src/share/org/apache/catalina/servlets/WebdavServlet.java        (wersja 782756)
185 +++ container/catalina/src/share/org/apache/catalina/servlets/WebdavServlet.java        (wersja 782757)
186 @@ -1369,76 +1369,6 @@
187          resp.setStatus(WebdavStatus.SC_NO_CONTENT);
188      }
189  
190 -    /**
191 -     * Return a context-relative path, beginning with a "/", that represents
192 -     * the canonical version of the specified path after ".." and "." elements
193 -     * are resolved out.  If the specified path attempts to go outside the
194 -     * boundaries of the current context (i.e. too many ".." path elements
195 -     * are present), return <code>null</code> instead.
196 -     *
197 -     * @param path Path to be normalized
198 -     */
199 -    protected String normalize(String path) {
200 -        if (path == null) {
201 -            return null;
202 -        }
203 -
204 -        // Create a place for the normalized path
205 -        String normalized = path;
206 -
207 -        if (normalized.equals("/.")) {
208 -            return "/";
209 -        }
210 -
211 -        // Normalize the slashes and add leading slash if necessary
212 -        if (normalized.indexOf('\\') >= 0) {
213 -            normalized = normalized.replace('\\', '/');
214 -        }
215 -
216 -        if (!normalized.startsWith("/")) {
217 -            normalized = "/" + normalized;
218 -        }
219 -
220 -        // Resolve occurrences of "//" in the normalized path
221 -        while (true) {
222 -            int index = normalized.indexOf("//");
223 -            if (index < 0) {
224 -                break;
225 -            }
226 -            normalized = normalized.substring(0, index) +
227 -                normalized.substring(index + 1);
228 -        }
229 -
230 -        // Resolve occurrences of "/./" in the normalized path
231 -        while (true) {
232 -            int index = normalized.indexOf("/./");
233 -            if (index < 0) {
234 -                break;
235 -            }
236 -            normalized = normalized.substring(0, index) +
237 -                normalized.substring(index + 2);
238 -        }
239 -
240 -        // Resolve occurrences of "/../" in the normalized path
241 -        while (true) {
242 -            int index = normalized.indexOf("/../");
243 -            if (index < 0) {
244 -                break;
245 -            }
246 -            if (index == 0) {
247 -                return (null);  // Trying to go outside our context
248 -            }
249 -
250 -            int index2 = normalized.lastIndexOf('/', index - 1);
251 -            normalized = normalized.substring(0, index2) +
252 -                normalized.substring(index + 3);
253 -        }
254 -
255 -        // Return the normalized path that we have completed
256 -        return (normalized);
257 -    }
258 -
259 -
260      // -------------------------------------------------------- Private Methods
261  
262      /**
263 @@ -1589,7 +1519,7 @@
264          }
265  
266          // Normalise destination path (remove '.' and '..')
267 -        destinationPath = normalize(destinationPath);
268 +        destinationPath = RequestUtil.normalize(destinationPath);
269  
270          String contextPath = req.getContextPath();
271          if ((contextPath != null) &&
272 @@ -2347,7 +2277,8 @@
273          if (!toAppend.startsWith("/"))
274              toAppend = "/" + toAppend;
275  
276 -        generatedXML.writeText(rewriteUrl(normalize(absoluteUri + toAppend)));
277 +        generatedXML.writeText(rewriteUrl(RequestUtil.normalize(
278 +                absoluteUri + toAppend)));
279  
280          generatedXML.writeElement(null, "href", XMLWriter.CLOSING);
281  
282 Index: container/catalina/src/share/org/apache/catalina/connector/Request.java
283 ===================================================================
284 --- container/catalina/src/share/org/apache/catalina/connector/Request.java     (wersja 782756)
285 +++ container/catalina/src/share/org/apache/catalina/connector/Request.java     (wersja 782757)
286 @@ -1243,10 +1243,9 @@
287          int pos = requestPath.lastIndexOf('/');
288          String relative = null;
289          if (pos >= 0) {
290 -            relative = RequestUtil.normalize
291 -                (requestPath.substring(0, pos + 1) + path);
292 +            relative = requestPath.substring(0, pos + 1) + path;
293          } else {
294 -            relative = RequestUtil.normalize(requestPath + path);
295 +            relative = requestPath + path;
296          }
297  
298          return (context.getServletContext().getRequestDispatcher(relative));
299 Index: container/catalina/src/share/org/apache/catalina/ssi/SSIServletRequestUtil.java
300 ===================================================================
301 --- container/catalina/src/share/org/apache/catalina/ssi/SSIServletRequestUtil.java     (wersja 782756)
302 +++ container/catalina/src/share/org/apache/catalina/ssi/SSIServletRequestUtil.java     (wersja 782757)
303 @@ -48,7 +48,7 @@
304          if ((result == null) || (result.equals(""))) {
305              result = "/";
306          }
307 -        return normalize(result);
308 +        return RequestUtil.normalize(result);
309      }
310  
311  
312 @@ -64,15 +64,9 @@
313       * 
314       * @param path
315       *            Path to be normalized
316 +     * @deprecated
317       */
318      public static String normalize(String path) {
319 -        if (path == null) return null;
320 -        String normalized = path;
321 -        //Why doesn't RequestUtil do this??
322 -        // Normalize the slashes and add leading slash if necessary
323 -        if (normalized.indexOf('\\') >= 0)
324 -            normalized = normalized.replace('\\', '/');
325 -        normalized = RequestUtil.normalize(path);
326 -        return normalized;
327 +        return RequestUtil.normalize(path);
328      }
329  }
330 \ No newline at end of file
331 Index: container/catalina/src/share/org/apache/catalina/ssi/SSIServletExternalResolver.java
332 ===================================================================
333 --- container/catalina/src/share/org/apache/catalina/ssi/SSIServletExternalResolver.java        (wersja 782756)
334 +++ container/catalina/src/share/org/apache/catalina/ssi/SSIServletExternalResolver.java        (wersja 782757)
335 @@ -32,6 +32,7 @@
336  import javax.servlet.http.HttpServletRequest;
337  import javax.servlet.http.HttpServletResponse;
338  import org.apache.catalina.connector.Request;
339 +import org.apache.catalina.util.RequestUtil;
340  import org.apache.coyote.Constants;
341  
342  /**
343 @@ -373,7 +374,7 @@
344                      + pathWithoutContext);
345          }
346          String fullPath = prefix + path;
347 -        String retVal = SSIServletRequestUtil.normalize(fullPath);
348 +        String retVal = RequestUtil.normalize(fullPath);
349          if (retVal == null) {
350              throw new IOException("Normalization yielded null on path: "
351                      + fullPath);
352 @@ -406,7 +407,7 @@
353              return new ServletContextAndPath(context,
354                      getAbsolutePath(virtualPath));
355          } else {
356 -            String normalized = SSIServletRequestUtil.normalize(virtualPath);
357 +            String normalized = RequestUtil.normalize(virtualPath);
358              if (isVirtualWebappRelative) {
359                  return new ServletContextAndPath(context, normalized);
360              } else {
361 Index: container/catalina/src/share/org/apache/catalina/util/RequestUtil.java
362 ===================================================================
363 --- container/catalina/src/share/org/apache/catalina/util/RequestUtil.java      (wersja 782756)
364 +++ container/catalina/src/share/org/apache/catalina/util/RequestUtil.java      (wersja 782757)
365 @@ -147,13 +147,29 @@
366       * @param path Relative path to be normalized
367       */
368      public static String normalize(String path) {
369 +        return normalize(path, true);
370 +    }
371  
372 +    /**
373 +     * Normalize a relative URI path that may have relative values ("/./",
374 +     * "/../", and so on ) it it.  <strong>WARNING</strong> - This method is
375 +     * useful only for normalizing application-generated paths.  It does not
376 +     * try to perform security checks for malicious input.
377 +     *
378 +     * @param path Relative path to be normalized
379 +     * @param replaceBackSlash Should '\\' be replaced with '/'
380 +     */
381 +    public static String normalize(String path, boolean replaceBackSlash) {
382 +
383          if (path == null)
384              return null;
385  
386          // Create a place for the normalized path
387          String normalized = path;
388  
389 +        if (replaceBackSlash && normalized.indexOf('\\') >= 0)
390 +            normalized = normalized.replace('\\', '/');
391 +
392          if (normalized.equals("/."))
393              return "/";
394  
This page took 0.060546 seconds and 3 git commands to generate.