summaryrefslogtreecommitdiff
path: root/ldso/ldso/ldso.c
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2012-01-02 02:43:37 -0500
committerMike Frysinger <vapier@gentoo.org>2012-01-02 03:02:53 -0500
commit97774e90d694f802ff0cfbf15687af77c6f7239e (patch)
tree2c464c571ddb07f3a01cbc295700430bb52248f8 /ldso/ldso/ldso.c
parentb3436addb5ccf14d7fffcf5503644e9a62aaec4e (diff)
ldso: setup search path even when there are no "/"
If people use an interp path such as "ld.so", then there is no "/" found, and we end up dereferencing a NULL pointer. Simplify the logic by having a relative interp path like that be the same as "" (which the code later on interprets as $PWD). While we're here, document some of the nuances of this code. Reported-by: Ignacy Gawędzki <uclibc@qult.net> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'ldso/ldso/ldso.c')
-rw-r--r--ldso/ldso/ldso.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/ldso/ldso/ldso.c b/ldso/ldso/ldso.c
index c5ec2fde1..a6e916ee9 100644
--- a/ldso/ldso/ldso.c
+++ b/ldso/ldso/ldso.c
@@ -138,11 +138,23 @@ static void _dl_ldsopath_init(struct elf_resolve *tpnt)
{
char *ldsopath, *ptmp;
- /* Store the path where the shared lib loader was found for later use */
+ /*
+ * Store the path where the shared lib loader was found for later use.
+ * Note that this logic isn't bullet proof when it comes to relative
+ * paths: if you use "./lib/ldso.so", and then the app does chdir()
+ * followed by dlopen(), the old ldso path won't get searched. But
+ * that is a fairly pathological use case, so if you don't like that,
+ * then set a full path to your interp and be done :P.
+ */
ldsopath = _dl_strdup(tpnt->libname);
ptmp = _dl_strrchr(ldsopath, '/');
- if (ptmp != ldsopath)
- *ptmp = '\0';
+ /*
+ * If there is no "/", then set the path to "", and the code
+ * later on will take this to implicitly mean "search $PWD".
+ */
+ if (!ptmp)
+ ptmp = ldsopath;
+ *ptmp = '\0';
_dl_ldsopath = ldsopath;
_dl_debug_early("Lib Loader: (%x) %s: using path: %s\n",