From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 4080 invoked from network); 3 Jan 2022 17:00:37 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 3 Jan 2022 17:00:37 -0000 Received: (qmail 20141 invoked by uid 550); 3 Jan 2022 17:00:34 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 20108 invoked from network); 3 Jan 2022 17:00:34 -0000 Date: Mon, 03 Jan 2022 17:00:19 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=harmenstoppels.nl; s=protonmail; t=1641229222; bh=pEEoabmM2SV9xVpI2SWBtv3YBZMLR7ZYc32TfvCtEWA=; h=Date:To:From:Reply-To:Subject:Message-ID:From:To:Cc; b=lF2JYgRupS6mw/O8uZNLQqFFCIheIR1uDAYCXJdY7pAVNvqqszCV9dnxw7ZIs7SbY SswuICNtZV7gHLCPe6pEpwtpl9JzX893YMG+nK+rh5qj69vhp0wPpeopQtQI3/nVK+ bWz8j61QJrC3d+YQVFrif3DE86BNnL+0hzL884Cs= To: "musl@lists.openwall.com" From: Harmen Stoppels Message-ID: MIME-Version: 1.0 Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg=pgp-sha256; boundary="------c33798292f423439d0a907b89c9c48fe294f012c334a3faa7acc674d26055e5f"; charset=utf-8 Subject: [musl] [PATCH] Improve locating ld-musl-[arch].path file This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --------c33798292f423439d0a907b89c9c48fe294f012c334a3faa7acc674d26055e5f Content-Type: multipart/mixed;boundary=---------------------9725824129eb9f4053c8c71ffac594fc -----------------------9725824129eb9f4053c8c71ffac594fc Content-Transfer-Encoding: quoted-printable Content-Type: text/plain;charset=utf-8 musl locates the config file with search paths relative to the interpreter/loader by taking the path up to the second to last /, that is, it tries to drop the filename and dir. This logic is flawed when the interpreter contains multiple /'s between dir and filename. This commit fixes that. Example: ``` $ ./configure "--prefix=3D$PWD/build" "--syslibdir=3D$PWD/build/loader/lib= " $ make install -j $ mkdir -p build/loader/etc example $ echo "$PWD/example" > "./build/loader/etc/ld-musl-$(arch).path" $ echo 'int f() {return 0;}' | ./build/bin/musl-gcc -shared -x c - -Wl,-so= name,libf.so -o example/libf.so $ echo 'int f(); int main(){return f();}' | ./build/bin/musl-gcc -x c - -L= example -lf -o example/a.out $ ./example/a.out && echo "works" works $ patchelf --set-interpreter "$PWD/build/loader/lib//ld-musl-$(arch).so.1"= example/a.out $ ./example/a.out || echo "does not work" Error loading shared library libf.so: No such file or directory (needed by= ./example/a.out) Error relocating ./example/a.out: f: symbol not found does not work ``` --- ldso/dynlink.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ldso/dynlink.c b/ldso/dynlink.c index 5b9c8be4..3e7766ac 100644 --- a/ldso/dynlink.c +++ b/ldso/dynlink.c @@ -1065,8 +1065,12 @@ static struct dso *load_library(const char *name, s= truct dso *needed_by) size_t prefix_len; if (ldso.name[0]=3D=3D'/') { char *s, *t, *z; - for (s=3Dt=3Dz=3Dldso.name; *s; s++) - if (*s=3D=3D'/') z=3Dt, t=3Ds; + s=3Dt=3Dz=3Dldso.name; + do { + if (*s++ !=3D '/') continue; + z=3Dt, t=3Ds-1; + while (*s =3D=3D '/') ++s; + } while (*s); prefix_len =3D z-ldso.name; if (prefix_len < PATH_MAX) prefix =3D ldso.name; -- = 2.25.1 -----------------------9725824129eb9f4053c8c71ffac594fc-- --------c33798292f423439d0a907b89c9c48fe294f012c334a3faa7acc674d26055e5f Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: ProtonMail wsBzBAEBCAAGBQJh0yuVACEJEI0c4W9l+YSCFiEE/VN8iJjfG7NRPUUojRzh b2X5hIJhhAf+K8oDxcXcV899lGnbLQ5f3Cy6XmwAFGIr+OXu+gFRWykyRz8q RNc0n1OPWX/JvAY+X/wwrP0YHe+OqyNEyqgsQsNyiPqpnWwATT6ByWrJ55lE s645IWqjCTQ4CRA8QPzOcaaTz97vfCHUa+Py/1tn+CXKXw+3vzv/0s28gR9o 3rGkKJM8fHkhVKwgS8YVPEiw48eeiCnThP13m+OQwHd/we91uhjOVMat6P5j v2B5diyqw8J7TG1LtF1vJU2Re6ZDPPjYZRbUs0dVFnpRnjfLJCY0PEPHxVUP /K/vjFakudtGJYIczZzDnfxU96+uhX4lGiSOquQJ7tlEwMwZUh/pKA== =S4lE -----END PGP SIGNATURE----- --------c33798292f423439d0a907b89c9c48fe294f012c334a3faa7acc674d26055e5f--