summaryrefslogtreecommitdiff
path: root/src/ldso/dynlink.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2013-07-18 19:29:44 -0400
committerRich Felker <dalias@aerifal.cx>2013-07-18 19:29:44 -0400
commitf389c4984a0fee80c5322e4d1ec3aa207e9b5c01 (patch)
tree4d46e10d0503cb6c07caf1fa679eae4dc30a4ab5 /src/ldso/dynlink.c
parent23815f88df6c45247f3755dc7857f4013264c04f (diff)
downloadmusl-f389c4984a0fee80c5322e4d1ec3aa207e9b5c01.tar.gz
musl-f389c4984a0fee80c5322e4d1ec3aa207e9b5c01.tar.bz2
musl-f389c4984a0fee80c5322e4d1ec3aa207e9b5c01.tar.xz
musl-f389c4984a0fee80c5322e4d1ec3aa207e9b5c01.zip
make the dynamic linker find its path file relative to its own location
prior to this change, using a non-default syslibdir was impractical on systems where the ordinary library paths contain musl-incompatible library files. the file containing search paths was always taken from /etc, which would either correspond to a system-wide musl installation, or fail to exist at all, resulting in searching of the default library path. the new search strategy is safe even for suid programs because the pathname used comes from the PT_INTERP header of the program being run, rather than any external input. as part of this change, I have also begun differentiating the names of arch variants that differ by endianness or floating point calling convention. the corresponding changes in the build system and and gcc wrapper script (to use an alternate dynamic linker name) for these configurations have not yet been made.
Diffstat (limited to 'src/ldso/dynlink.c')
-rw-r--r--src/ldso/dynlink.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/ldso/dynlink.c b/src/ldso/dynlink.c
index ff5b738d..1d5e2977 100644
--- a/src/ldso/dynlink.c
+++ b/src/ldso/dynlink.c
@@ -483,7 +483,26 @@ static struct dso *load_library(const char *name)
if (fd < 0 && env_path) fd = path_open(name, env_path, buf, sizeof buf);
if (fd < 0) {
if (!sys_path) {
- FILE *f = fopen(ETC_LDSO_PATH, "rbe");
+ char *prefix = 0;
+ size_t prefix_len;
+ if (ldso->name[0]=='/') {
+ char *s, *t, *z;
+ for (s=t=z=ldso->name; *s; s++)
+ if (*s=='/') z=t, t=s;
+ prefix_len = z-ldso->name;
+ if (prefix_len < PATH_MAX)
+ prefix = ldso->name;
+ }
+ if (!prefix) {
+ prefix = "";
+ prefix_len = 0;
+ }
+ char etc_ldso_path[prefix_len + 1
+ + sizeof "/etc/ld-musl-" LDSO_ARCH ".path"];
+ snprintf(etc_ldso_path, sizeof etc_ldso_path,
+ "%.*s/etc/ld-musl-" LDSO_ARCH ".path",
+ (int)prefix_len, prefix);
+ FILE *f = fopen(etc_ldso_path, "rbe");
if (f) {
if (getdelim(&sys_path, (size_t[1]){0}, 0, f) <= 0) {
free(sys_path);