Bug 137208 - osl_getModuleURLFromAddress returns false if getcwd returns an error
Summary: osl_getModuleURLFromAddress returns false if getcwd returns an error
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: sdk (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: All Linux (All)
: medium normal
Assignee: Stephan Bergmann
URL:
Whiteboard: target:7.2.0
Keywords:
Depends on:
Blocks:
 
Reported: 2020-10-02 14:30 UTC by Marc-Oliver Straub
Modified: 2021-02-17 13:57 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marc-Oliver Straub 2020-10-02 14:30:37 UTC
We had a crash when bootstrapping UNO because someone removed the current working directory.
Stacktrace:
SEGV
libuno_cppu.so.3(uno_getMapping+0x178)[0x7ffff43372c8]
libuno_cppuhelpergcc3.so.3(+0x64dea)[0x7ffff4bbadea]
libuno_cppuhelpergcc3.so.3(_ZN4cppu40defaultBootstrap_InitialComponentContextERKN3rtl8OUStringE+0x6f9)[0x7ffff4b993b9]

uno_getMapping crashed due to aFrom, aTo being nullptr, caused by osl_getModuleURLFromAddress always returning false - so no module could be loaded.

osl_getModuleURLFromAddress called osl_getProcessWorkingDir(workDir), which returned a nullptr as workDir because the current working dir had been deleted. This caused osl_getModureURLFromAddress to return false, even though the module path (as returned by getModulePathFromAddress) was an absolute path.

To improve robustness against such (accidental) work directory removals, I suggest osl_getModuleURLFromAddress to not check the current working directory at all, but to delegate checking of the working dir to osl_getAbsoluteFileURL(...), once the given path is detected to be a relative path.
Comment 1 Xisco Faulí 2021-02-15 18:09:55 UTC Comment hidden (obsolete)
Comment 2 Stephan Bergmann 2021-02-16 14:14:10 UTC
There is probably no good reason that osl_getModuleURLFromAddress calls osl_getAbsoluteFileURL(workDir,...) ever since <https://git.libreoffice.org/core/+/3dfb38a45d6495d357c3359b5b02cde871df6f67%5E!/> "added getUrlFromAddress (#88338#)", apparently under the assumption that the pathname obtained from dladdr might be relative to the process's CWD.  I'll see to rip that out.
Comment 3 Commit Notification 2021-02-16 21:16:44 UTC
Stephan Bergmann committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/c8976bdfdfa361fec9e1e5ff342094e409981fad

tdf#137208 Assume that dladdr provides an absolute pathname

It will be available in 7.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 4 Marc-Oliver Straub 2021-02-17 12:35:03 UTC
Thank you Stephan, your fix works well.