Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 337715

Summary: RCP application segfaults at startup when launched from bash with an empty PATH component
Product: [Eclipse Project] Equinox Reporter: benedict
Component: LauncherAssignee: Project Inbox <equinox.launcher-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: minor    
Priority: P3 CC: aniefer, remy.suen, tjwatson
Version: 3.5   
Target Milestone: 3.7 M7   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
Strace from a segfault'ing launch
none
patch none

Description benedict CLA 2011-02-21 07:45:53 EST
Build Identifier: 3.5.0.v20090525

Bash has 2 ways to include the current directory in your PATH: by including a . entry in PATH, or by including an 'empty' entry, via either a leading or trailing : in the PATH. We have an RCP application for Linux GTK x86; if you unzip it in /home/foo/app, and the RCP binary is named LaunchApp, then the following happens:

1 - CWD is /home/foo/app, ./LaunchApp works, no matter the PATH
2 - CWD is /home/foo/app, PATH includes . ; LaunchApp works
3 - CWD is /home/foo, PATH includes /home/foo/app ; LaunchApp works
4 - CWD is /home/foo/app, PATH has an empty entry ; ./LaunchApp works but LaunchApp segfaults

Not a huge issue, since as the above shows there are many workarounds, but still indicative of a bug in the code, and potentially annoying to someone who uses an empty entry instead of . to put the working directory in their PATH.

Attached is strace output from the segfault case; it appears that the launcher tries to find the last / char in some path, and then get the length of the string after that, but with no /, it gets NULL and then does a strlen(NULL) which segfaults.

Reproducible: Always

Steps to Reproduce:
1. Install an RCP application in a directory.
2. cd to that directory
3. Set your PATH to have an empty entry: export PATH=:$PATH
4. Launch the application without using ./
Comment 1 benedict CLA 2011-02-21 07:47:25 EST
Created attachment 189405 [details]
Strace from a segfault'ing launch

Shows the strlen(NULL) which causes the segfault, plus the strrchr('/') which fails to find a '/' character and returns NULL.
Comment 2 Andrew Niefer CLA 2011-02-22 11:32:01 EST
The launcher tries to find the absolute path to itself by scanning the PATH.  It does not know to treat an empty entry as the CWD.
This leaves us with a NULL programDir location.  

The segfault here is in eclipseMain/findLibrary() on the line
progLength = pathLength = _tcslen(programDir);

Similarly, I expect if the .ini file specifies a --launcher.library argument then there would be one in eclipseCommon/checkPath
Comment 3 Andrew Niefer CLA 2011-03-18 15:04:20 EDT
Created attachment 191541 [details]
patch
Comment 4 Andrew Niefer CLA 2011-03-21 16:06:59 EDT
Patch was released to HEAD