Return-Path: Delivered-To: apmail-felix-dev-archive@www.apache.org Received: (qmail 26811 invoked from network); 17 Sep 2007 20:19:31 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 17 Sep 2007 20:19:31 -0000 Received: (qmail 82141 invoked by uid 500); 17 Sep 2007 20:19:23 -0000 Delivered-To: apmail-felix-dev-archive@felix.apache.org Received: (qmail 82040 invoked by uid 500); 17 Sep 2007 20:19:23 -0000 Mailing-List: contact dev-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@felix.apache.org Delivered-To: mailing list dev@felix.apache.org Received: (qmail 82031 invoked by uid 99); 17 Sep 2007 20:19:23 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Sep 2007 13:19:23 -0700 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [194.119.192.4] (HELO mx2.isti.cnr.it) (194.119.192.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Sep 2007 20:19:21 +0000 Received: from conversionlocal.isti.cnr.it by mx.isti.cnr.it (PMDF V6.3 #31251) id <01MLHC8Y3RIO9KNL0H@mx.isti.cnr.it> for dev@felix.apache.org; Mon, 17 Sep 2007 22:17:48 +0200 Received: from [192.168.1.100] ([151.23.182.167]) by mx.isti.cnr.it (PMDF V6.3 #31251) with ESMTPSA id <01MLHC8THCD69KNHUQ@mx.isti.cnr.it> for dev@felix.apache.org; Mon, 17 Sep 2007 22:17:29 +0200 Date: Mon, 17 Sep 2007 22:17:33 +0200 From: Stefano Lenzi Subject: A bug in Bundle.getResource(String)? To: dev@felix.apache.org Message-id: <46EEE0DD.5070903@interfree.it> MIME-version: 1.0 Content-type: multipart/mixed; boundary="Boundary_(ID_lPgrrbZTcv+ZlmeOx6ovTQ)" User-Agent: Thunderbird 1.5.0.13 (Windows/20070809) X-INSM-ip-source: 151.23.182.167 Auth Done X-Virus-Checked: Checked by ClamAV on apache.org --Boundary_(ID_lPgrrbZTcv+ZlmeOx6ovTQ) Content-type: text/plain; charset=ISO-8859-1; format=flowed Content-transfer-encoding: 7bit Hi All, I've found a odd behavior in the method Bundle.getResource(String), the method is not able to resolve the resource if the reource path contains: '.' or '..' directory. I have already patched the: org.apache.felix.framework.searchpolicy.ContentLoaderImpl.getResource(String) in order to accept the '..' and '.' path (see attchment). Can I commit the patch? Ciao, Stefano "Kismet" Lenzi P.S.: As you can see from my patch I do not consider the case when the URL is encoded. P.P.S.: Should I report a issue on JIRA? --Boundary_(ID_lPgrrbZTcv+ZlmeOx6ovTQ) Content-type: text/plain; name=resource.loading.patch Content-transfer-encoding: 7BIT Content-disposition: inline; filename=resource.loading.patch Index: src/main/java/org/apache/felix/framework/searchpolicy/ContentLoaderImpl.java =================================================================== --- src/main/java/org/apache/felix/framework/searchpolicy/ContentLoaderImpl.java (revision 576472) +++ src/main/java/org/apache/felix/framework/searchpolicy/ContentLoaderImpl.java (working copy) @@ -22,12 +22,18 @@ import java.io.InputStream; import java.net.URL; import java.security.ProtectionDomain; +import java.util.ArrayList; import java.util.Enumeration; +import java.util.Iterator; +import java.util.StringTokenizer; import java.util.Vector; import org.apache.felix.framework.Logger; import org.apache.felix.framework.util.SecureAction; -import org.apache.felix.moduleloader.*; +import org.apache.felix.moduleloader.IContent; +import org.apache.felix.moduleloader.IContentLoader; +import org.apache.felix.moduleloader.ISearchPolicy; +import org.apache.felix.moduleloader.IURLPolicy; public class ContentLoaderImpl implements IContentLoader { @@ -129,13 +135,49 @@ public URL getResource(String name) { URL url = null; - + + //TODO Handling encoded URL + // Remove leading slash, if present. if (name.startsWith("/")) { name = name.substring(1); - } - + } + + /* + * NORMALIZING PATH: + * 1 - Removing /./ path + * 2 - Resolving /../ path + */ + StringTokenizer tokenizer = new StringTokenizer(name,"/"); + ArrayList parts = new ArrayList(); + while(tokenizer.hasMoreTokens()) + { + String namePart = tokenizer.nextToken(); + if(namePart.equals(".")) + { + continue; + } + else if(namePart.equals("..") && parts.size()>=1) + { + //XXX Should we launch an exception if there are too many parent directory?!?!? + parts.remove(parts.size()-1); + } + else + { + parts.add(namePart); + } + } + + //Rebuilding the path from parts + name = ""; + for (Iterator i = parts.iterator(); i.hasNext();) + { + String p = (String) i.next(); + name += "/" + p; + } + name = name.substring(1); + // Check the module class path. for (int i = 0; (url == null) && --Boundary_(ID_lPgrrbZTcv+ZlmeOx6ovTQ)--