Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rou1G-003zz7-VA for pgsql-bugs@arkaria.postgresql.org; Mon, 25 Mar 2024 23:46:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rou1F-009Jzy-Li for pgsql-bugs@arkaria.postgresql.org; Mon, 25 Mar 2024 23:46:22 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rotyE-009H6H-Eb for pgsql-bugs@lists.postgresql.org; Mon, 25 Mar 2024 23:43:14 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rotyB-006QKi-57 for pgsql-bugs@lists.postgresql.org; Mon, 25 Mar 2024 23:43:13 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 42PNh8uO2715728; Mon, 25 Mar 2024 19:43:08 -0400 From: Tom Lane To: Thomas Munro cc: Peter Eisentraut , Bruce Momjian , walther@technowledgy.de, Christophe Pettus , Andrew Dunstan , PostgreSQL Bugs , Robert Haas Subject: Re: Regression tests fail with musl libc because libpq.so can't be loaded In-reply-to: <2712381.1711408552@sss.pgh.pa.us> References: <477fa513-6bf0-456d-8d24-1e22a19df671@technowledgy.de> <36690fcf-f0c8-4d60-af49-6a7efa0e2b14@technowledgy.de> <443430b4-0c10-49f3-8c8a-e5e76602f309@eisentraut.org> <2712381.1711408552@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Mon, 25 Mar 2024 19:15:52 -0400" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <2715709.1711410168.0@sss.pgh.pa.us> Date: Mon, 25 Mar 2024 19:43:08 -0400 Message-ID: <2715727.1711410188@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2715709.1711410168.1@sss.pgh.pa.us> I wrote: > Thomas Munro writes: >> I had originally proposed to avoid anything beginning "LD_" but Tom >> suggested being more specific. I doubt LD_PRELOAD can really hurt you >> though (the linker probably only needs the value at the start by >> definition, not at later dlopen() time (?)). > Oh, good point. So we could simplify the patch by only looking for > LD_LIBRARY_PATH. I looked at the musl source code you identified and confirmed that only the LD_LIBRARY_PATH string is remembered in a static variable; LD_PRELOAD is only accessed locally in that initialization function. So we only need to do the attached. (I failed to resist the temptation to rewrite the comments.) regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="v2-0001-Don-t-clobber-LD_-environment-variables.patch"; charset="us-ascii" Content-ID: <2715709.1711410168.2@sss.pgh.pa.us> Content-Description: v2-0001-Don-t-clobber-LD_-environment-variables.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/utils/misc/ps_status.c b/src/backend/utils/misc/p= s_status.c index 5d829e6e48..92cd2c7899 100644 --- a/src/backend/utils/misc/ps_status.c +++ b/src/backend/utils/misc/ps_status.c @@ -151,7 +151,33 @@ save_ps_display_args(int argc, char **argv) for (i =3D 0; environ[i] !=3D NULL; i++) { if (end_of_area + 1 =3D=3D environ[i]) - end_of_area =3D environ[i] + strlen(environ[i]); + { + /* + * The musl runtime linker keeps a static pointer to the + * initial value of LD_LIBRARY_PATH, if that is defined in the + * process's environment. Therefore, we must not overwrite the + * value of that setting and thus cannot advance end_of_area + * beyond it. Musl does not define any identifying compiler + * symbol, so we have to do this for any Linux libc we don't + * know is safe. + */ +#if defined(__linux__) && (!defined(__GLIBC__) && !defined(__UCLIBC__ )) + if (strncmp(environ[i], "LD_LIBRARY_PATH=3D", 16) =3D=3D 0) + { + /* + * We can overwrite the name, but stop at the equals sign. + * Future loop iterations will not find any more + * contiguous space, but we don't break early because we + * need to count the total number of environ[] entries. + */ + end_of_area =3D environ[i] + 15; + } + else +#endif + { + end_of_area =3D environ[i] + strlen(environ[i]); + } + } } = ps_buffer =3D argv[0]; ------- =_aaaaaaaaaa0--