Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 337715 - RCP application segfaults at startup when launched from bash with an empty PATH component
Summary: RCP application segfaults at startup when launched from bash with an empty PA...
Status: RESOLVED FIXED
Alias: None
Product: Equinox
Classification: Eclipse Project
Component: Launcher (show other bugs)
Version: 3.5   Edit
Hardware: PC Linux
: P3 minor (vote)
Target Milestone: 3.7 M7   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-21 07:45 EST by benedict CLA
Modified: 2011-03-21 16:06 EDT (History)
3 users (show)

See Also:


Attachments
Strace from a segfault'ing launch (464.89 KB, text/plain)
2011-02-21 07:47 EST, benedict CLA
no flags Details
patch (2.85 KB, patch)
2011-03-18 15:04 EDT, Andrew Niefer CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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