Bug 39013 - Incorrect use of docBase from XML Context file deployment
Summary: Incorrect use of docBase from XML Context file deployment
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 5
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 5.5.16
Hardware: PC Windows XP
: P2 minor (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-03-17 13:07 UTC by Nic Daniau
Modified: 2009-03-24 05:54 UTC (History)
1 user (show)



Attachments
Patch in ContextConfig.java (956 bytes, patch)
2008-12-09 16:30 UTC, Kirk True
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Nic Daniau 2006-03-17 13:07:53 UTC
I created a folder called "webapps-war" within the Tomcat installation directory
(CATALINA_HOME). The host's default appBase is "webapps" in this directory.

What I wanted to do is use the XML Context file deployment method, i.e. put my
xml file into conf/catalina/localhost (in my case) and specify the docBase to
look for the war in ${catalina.home}/webapps-war/myapp.

But just because the name starts with "webapps", it misinterprets the docBase
setting and I get in tomcat.log:
"A docBase C:\tomcat-5.5.16\webapps-war\myapp inside the host appBase has been
specified, and will be ignored"
and then my deployment fails.

On the other hand, if I name my folder "somethingelse" instead of "webapps-war",
it works like a charm.

So not a big problem (trivial workaround) but would be nicer if the rule was
perfectly implemented. And that would have saved me hours trying to figure out
what was wrong in my deployment!...

If my investigation is correct, the problem can be traced back to
org.apache.catalina.startup.HostConfig and below is my suggested change against
the download from SVN done today (17 March). I'm not an expert on the catalina
source, so it would need another pair of eyes and some testing before you can
say this is the resolution of this problem. The proposed solution is simply to
make sure the string comparaisons includes a trailing "/" after the default appBase.

Questions on the suggested resolution:
I'm not sure in particular if you can use "/" as the directory separator for all
platform of if you'd need to use something like
System.getProperty("file.separator")?
Would there be other places where this applies?
Is there a compelling reason why this can't be done like that?

DIFF FILE against $Revision: 386336 $ $Date: 2006-03-16 14:13:00 +0000 (Thu, 16
Mar 2006) $
Compare:
(<)D:\work-bak\tomcat\container\catalina\src\share\org\apache\catalina\startup\HostConfig.java
(45038 bytes)
   with:
(>)D:\work-bak\tomcat\container\catalina\src\share\org\apache\catalina\startup\HostConfig.java.changed
(44596 bytes)

592c592
<                 if
(!docBase.getCanonicalPath().startsWith(appBase().getAbsolutePath())) {
---
>                 if
(!docBase.getCanonicalPath().startsWith(appBase().getAbsolutePath() + "/")) {
995,996c995,996
<                             if
((current.getAbsolutePath().startsWith(appBase().getAbsolutePath()))
<                                     ||
(current.getAbsolutePath().startsWith(configBase().getAbsolutePath()))) {
---
>                             if
((current.getAbsolutePath().startsWith(appBase().getAbsolutePath() + "/"))
>                                     ||
(current.getAbsolutePath().startsWith(configBase().getAbsolutePath() + "/"))) {
1035,1036c1035,1036
<                         if
((current.getAbsolutePath().startsWith(appBase().getAbsolutePath()))
<                             ||
(current.getAbsolutePath().startsWith(configBase().getAbsolutePath()))) {
---
>                         if
((current.getAbsolutePath().startsWith(appBase().getAbsolutePath() + "/"))
>                             ||
(current.getAbsolutePath().startsWith(configBase().getAbsolutePath() + "/"))) {
1052,1053c1052,1053
<                         if
((current.getAbsolutePath().startsWith(appBase().getAbsolutePath()))
<                             ||
((current.getAbsolutePath().startsWith(configBase().getAbsolutePath())
---
>                         if
((current.getAbsolutePath().startsWith(appBase().getAbsolutePath() + "/"))
>                             ||
((current.getAbsolutePath().startsWith(configBase().getAbsolutePath() + "/")
Comment 1 Kirk True 2008-12-08 17:45:35 UTC
This still appears to exist in the trunk as of today's pull.

I've got a one-liner that appears to fix it that I'll post soon.
Comment 2 Kirk True 2008-12-09 16:30:17 UTC
Created attachment 23007 [details]
Patch in ContextConfig.java

Tacking on a '/' to the end of both path strings helps to ensure full path parentage when performing the substring match.
Comment 3 Kirk True 2008-12-09 16:33:18 UTC
I've attached a patch that fixes the immediate issue as per the bug report. However, there could easily be cases that this doesn't catch. Please review.

Thanks.
Comment 4 Mark Thomas 2009-02-09 11:42:16 UTC
I've gone through HostConfig and appended File.separator where required. It needs to be File.separator rather than '/'. I have applied the fix to trunk and have proposed it for 6.0.x and 5.5.x
Comment 5 Mark Thomas 2009-03-06 07:21:19 UTC
This has been fixed in 6.0.x and will be included in 6.0.19 onwards.
Comment 6 Mark Thomas 2009-03-24 05:54:41 UTC
This has been fixed in 5.5.x and will be included in 5.5.28 onwards.