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)
6 import javax.naming.directory.ModificationItem;
7 import javax.naming.directory.SearchControls;
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;
15 protected String normalize(String path) {
17 - String normalized = path;
18 + return RequestUtil.normalize(path, File.separatorChar == '\\');
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;
26 - // Resolve occurrences of "//" in the normalized path
28 - int index = normalized.indexOf("//");
31 - normalized = normalized.substring(0, index) +
32 - normalized.substring(index + 1);
35 - // Resolve occurrences of "/./" in the normalized path
37 - int index = normalized.indexOf("/./");
40 - normalized = normalized.substring(0, index) +
41 - normalized.substring(index + 2);
44 - // Resolve occurrences of "/../" in the normalized path
46 - int index = normalized.indexOf("/../");
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);
56 - // Return the normalized path that we have completed
57 - return (normalized);
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)
70 int pos = requestPath.lastIndexOf('/');
71 String relative = null;
73 - relative = RequestUtil.normalize
74 - (requestPath.substring(0, pos + 1) + path);
75 + relative = requestPath.substring(0, pos + 1) + path;
77 - relative = RequestUtil.normalize(requestPath + path);
78 + relative = requestPath + path;
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)
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;
95 path = path.substring(0, pos);
98 - path = normalize(path);
99 + path = RequestUtil.normalize(path);
104 throw new MalformedURLException(sm.getString("applicationContext.requestDispatcher.iae", path));
107 - path = normalize(path);
108 + path = RequestUtil.normalize(path);
112 @@ -524,10 +525,13 @@
114 public InputStream getResourceAsStream(String path) {
116 - path = normalize(path);
117 if (path == null || !path.startsWith("/"))
120 + path = RequestUtil.normalize(path);
124 DirContext resources = context.getResources();
125 if (resources != null) {
128 (sm.getString("applicationContext.resourcePaths.iae", path));
131 - path = normalize(path);
132 + path = RequestUtil.normalize(path);
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.
146 - * @param path Path to be normalized
148 - private String normalize(String path) {
150 - if (path == null) {
154 - String normalized = path;
156 - // Normalize the slashes
157 - if (normalized.indexOf('\\') >= 0)
158 - normalized = normalized.replace('\\', '/');
160 - // Resolve occurrences of "/../" in the normalized path
162 - int index = normalized.indexOf("/../");
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);
172 - // Return the normalized path that we have completed
173 - return (normalized);
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);
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.
197 - * @param path Path to be normalized
199 - protected String normalize(String path) {
200 - if (path == null) {
204 - // Create a place for the normalized path
205 - String normalized = path;
207 - if (normalized.equals("/.")) {
211 - // Normalize the slashes and add leading slash if necessary
212 - if (normalized.indexOf('\\') >= 0) {
213 - normalized = normalized.replace('\\', '/');
216 - if (!normalized.startsWith("/")) {
217 - normalized = "/" + normalized;
220 - // Resolve occurrences of "//" in the normalized path
222 - int index = normalized.indexOf("//");
226 - normalized = normalized.substring(0, index) +
227 - normalized.substring(index + 1);
230 - // Resolve occurrences of "/./" in the normalized path
232 - int index = normalized.indexOf("/./");
236 - normalized = normalized.substring(0, index) +
237 - normalized.substring(index + 2);
240 - // Resolve occurrences of "/../" in the normalized path
242 - int index = normalized.indexOf("/../");
247 - return (null); // Trying to go outside our context
250 - int index2 = normalized.lastIndexOf('/', index - 1);
251 - normalized = normalized.substring(0, index2) +
252 - normalized.substring(index + 3);
255 - // Return the normalized path that we have completed
256 - return (normalized);
260 // -------------------------------------------------------- Private Methods
263 @@ -1589,7 +1519,7 @@
266 // Normalise destination path (remove '.' and '..')
267 - destinationPath = normalize(destinationPath);
268 + destinationPath = RequestUtil.normalize(destinationPath);
270 String contextPath = req.getContextPath();
271 if ((contextPath != null) &&
272 @@ -2347,7 +2277,8 @@
273 if (!toAppend.startsWith("/"))
274 toAppend = "/" + toAppend;
276 - generatedXML.writeText(rewriteUrl(normalize(absoluteUri + toAppend)));
277 + generatedXML.writeText(rewriteUrl(RequestUtil.normalize(
278 + absoluteUri + toAppend)));
280 generatedXML.writeElement(null, "href", XMLWriter.CLOSING);
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;
290 - relative = RequestUtil.normalize
291 - (requestPath.substring(0, pos + 1) + path);
292 + relative = requestPath.substring(0, pos + 1) + path;
294 - relative = RequestUtil.normalize(requestPath + path);
295 + relative = requestPath + path;
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)
304 if ((result == null) || (result.equals(""))) {
307 - return normalize(result);
308 + return RequestUtil.normalize(result);
315 * Path to be normalized
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);
327 + return RequestUtil.normalize(path);
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)
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;
344 + pathWithoutContext);
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: "
353 return new ServletContextAndPath(context,
354 getAbsolutePath(virtualPath));
356 - String normalized = SSIServletRequestUtil.normalize(virtualPath);
357 + String normalized = RequestUtil.normalize(virtualPath);
358 if (isVirtualWebappRelative) {
359 return new ServletContextAndPath(context, normalized);
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
368 public static String normalize(String path) {
369 + return normalize(path, true);
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.
378 + * @param path Relative path to be normalized
379 + * @param replaceBackSlash Should '\\' be replaced with '/'
381 + public static String normalize(String path, boolean replaceBackSlash) {
386 // Create a place for the normalized path
387 String normalized = path;
389 + if (replaceBackSlash && normalized.indexOf('\\') >= 0)
390 + normalized = normalized.replace('\\', '/');
392 if (normalized.equals("/."))