about summary refs log tree commit diff
path: root/ldso
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2018-02-07 14:27:08 -0500
committerRich Felker <dalias@aerifal.cx>2018-02-07 14:27:08 -0500
commitf0b235c138d26caafeda44475818508f1911e78e (patch)
treed6236883a7123b94e1cc66fa1cca44f31d864acb /ldso
parentc7f0da4134d4e7f2efd295e7fb738c65c469fbd1 (diff)
downloadmusl-f0b235c138d26caafeda44475818508f1911e78e.tar.gz
musl-f0b235c138d26caafeda44475818508f1911e78e.tar.xz
musl-f0b235c138d26caafeda44475818508f1911e78e.zip
honor rpath $ORIGIN for ldd/ldso command with program in working dir
the rpath fixup code assumed any module's name field would contain at
least one slash, an invariant which is usually met but not in the case
of a main executable loaded from the current working directory by
running ldd or ldso as a command. it would be possible to make this
invariant always hold, but it has a higher runtime allocation cost and
does not seem useful elsewhere, so just patch things up in fixup_rpath
instead.
Diffstat (limited to 'ldso')
-rw-r--r--ldso/dynlink.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/ldso/dynlink.c b/ldso/dynlink.c
index 33802400..3741c30d 100644
--- a/ldso/dynlink.c
+++ b/ldso/dynlink.c
@@ -807,7 +807,16 @@ static int fixup_rpath(struct dso *p, char *buf, size_t buf_size)
 		origin = p->name;
 	}
 	t = strrchr(origin, '/');
-	l = t ? t-origin : 0;
+	if (t) {
+		l = t-origin;
+	} else {
+		/* Normally p->name will always be an absolute or relative
+		 * pathname containing at least one '/' character, but in the
+		 * case where ldso was invoked as a command to execute a
+		 * program in the working directory, app.name may not. Fix. */
+		origin = ".";
+		l = 1;
+	}
 	p->rpath = malloc(strlen(p->rpath_orig) + n*l + 1);
 	if (!p->rpath) return -1;