From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Cc: "Stefan Fröberg" <stefan.froberg@petroprogram.com>
Subject: Re: BUG: $ORIGIN does not seem to work
Date: Wed, 7 Feb 2018 12:35:31 -0500 [thread overview]
Message-ID: <20180207173531.GF1627@brightrain.aerifal.cx> (raw)
In-Reply-To: <20180128005425.GK4418@port70.net>
[-- Attachment #1: Type: text/plain, Size: 903 bytes --]
On Sun, Jan 28, 2018 at 01:54:25AM +0100, Szabolcs Nagy wrote:
> * Stefan Fröberg <stefan.froberg@petroprogram.com> [2018-01-28 00:07:33 +0200]:
> > strace ./x
> ...
> > open("/root/batman/lib/libcrypto.so.1.1", O_RDONLY|O_CLOEXEC) = 3
> ...
> > ldd x
> > /lib/ld-musl-x86_64.so.1 (0x7f22efa03000)
> > libcrypto.so.1.1 => /usr/lib/libcrypto.so.1.1 (0x7f22ef352000)
> > libc.so => /lib/ld-musl-x86_64.so.1 (0x7f22efa03000)
>
> this is a bug in musl ldd: if the executable
> path has no / then it assumes origin is /, try
>
> ldd ./x
>
> then origin is ./ so it works as expected.
Does the attached patch look ok?
Alternatively we could fix the assumed invariant that p->name always
contains a slash by having the loader code in __dls3 allocate a copy
of argv[0] with "./" prepended, but that's a heavier cost at runtime
and doesn't seem to have any practical advantages.
Rich
[-- Attachment #2: ldd-curdir.diff --]
[-- Type: text/plain, Size: 435 bytes --]
diff --git a/ldso/dynlink.c b/ldso/dynlink.c
index 3380240..f507bc4 100644
--- a/ldso/dynlink.c
+++ b/ldso/dynlink.c
@@ -807,7 +807,12 @@ 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 {
+ origin = ".";
+ l = 1;
+ }
p->rpath = malloc(strlen(p->rpath_orig) + n*l + 1);
if (!p->rpath) return -1;
next prev parent reply other threads:[~2018-02-07 17:35 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-26 13:39 Stefan Fröberg
2018-01-26 14:21 ` Szabolcs Nagy
2018-01-26 23:50 ` Stefan Fröberg
2018-01-27 11:07 ` Szabolcs Nagy
2018-01-27 16:20 ` Stefan Fröberg
2018-01-27 16:42 ` Rich Felker
2018-01-27 17:14 ` Stefan Fröberg
2018-01-27 19:26 ` Szabolcs Nagy
2018-01-27 22:07 ` Stefan Fröberg
2018-01-28 0:54 ` Szabolcs Nagy
2018-02-07 17:35 ` Rich Felker [this message]
2018-02-07 20:28 ` Szabolcs Nagy
2018-01-26 16:34 ` Rich Felker
2018-01-26 21:28 ` Stefan Fröberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180207173531.GF1627@brightrain.aerifal.cx \
--to=dalias@libc.org \
--cc=musl@lists.openwall.com \
--cc=stefan.froberg@petroprogram.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).