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 1rnf4T-00EPC3-71 for pgsql-bugs@arkaria.postgresql.org; Fri, 22 Mar 2024 13:36:33 +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 1rnf4R-003dFG-PL for pgsql-bugs@arkaria.postgresql.org; Fri, 22 Mar 2024 13:36:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rnf4R-003dF7-G4 for pgsql-bugs@lists.postgresql.org; Fri, 22 Mar 2024 13:36:32 +0000 Received: from momjian.us ([72.94.173.45]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rnf4K-005uSq-V7 for pgsql-bugs@lists.postgresql.org; Fri, 22 Mar 2024 13:36:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=momjian.us; s=2024011501; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description; bh=/nPA0zBhKzV87dLp093oRrN7aEO7IfFUS1/2Jbvjw9Q=; b=hT3Zj rl9Upjn/Mof/2+pJRbIyUg/cLvA4anRDNDCG9GrsAXMEE5nDJFZaKPdH/uBFNlRJZAik9vjV1FsE0 JTrTwWF90CA/GU56T3rWSvde2YSVGwE6lVkhgHejcAMw8ereV2XsURQMESvgbbCuBT5/J61Mj4/5m gF0vETBayoI6sKbU0rMZ1uHQDSySkpqXB76te0mx/gxk4cPyzQe8XKc3KVzrfvUg6XTaTDqekANrV +OUDwVkdbm9n4ANexfeN2HRNQBh+2zBjIBbWuW73mX6gkIIMNUyu+qPKmce9kqjm4DcQ6NiTcWgaK G5mSb1uaGSCyVnhxBFrb0Hy319iOA==; Received: from bruce by momjian.us with local (Exim 4.96) (envelope-from ) id 1rnf4F-006GS5-0q; Fri, 22 Mar 2024 09:36:19 -0400 Date: Fri, 22 Mar 2024 09:36:19 -0400 From: Bruce Momjian To: walther@technowledgy.de Cc: Thomas Munro , Peter Eisentraut , Christophe Pettus , Andrew Dunstan , PostgreSQL Bugs , Tom Lane Subject: Re: Regression tests fail with musl libc because libpq.so can't be loaded Message-ID: References: <4095435.1710900216@sss.pgh.pa.us> <477fa513-6bf0-456d-8d24-1e22a19df671@technowledgy.de> <36690fcf-f0c8-4d60-af49-6a7efa0e2b14@technowledgy.de> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="1oNR6uTIepXZ2NsI" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --1oNR6uTIepXZ2NsI Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Mar 22, 2024 at 09:33:38AM +0100, walther@technowledgy.de wrote: > Bruce Momjian: > > I suggest we use the #ifdef test to continue our existing behavior for > > the libraries we know about, like glibc, and use the LD_* process title > > truncation hack for libc's we don't recognize. > > > > Attached is a prototype patch which implements this based on previous > > patches. > > The condition to check for linux/glibc in your patch is slightly off: > > #if ! defined(__linux__) || (! defined(__GLIBC__) && defined(__UCLIBC__ )) > > should be > > #if defined(__linux__) && ! (defined(__GLIBC__) || defined(__UCLIBC__ )) > > With the latter, it passes tests with musl. Yes, my logic was wrong. Not sure what I was thinking, frankly. I am not a big fan of negating a complex conditional, but would rather pass the negation into the conditional, new patch attached. -- Bruce Momjian https://momjian.us EDB https://enterprisedb.com Only you can decide what is important to you. --1oNR6uTIepXZ2NsI Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="proctitle.diff" diff --git a/src/backend/utils/misc/ps_status.c b/src/backend/utils/misc/ps_status.c index 5d829e6e483..c0786d30937 100644 --- a/src/backend/utils/misc/ps_status.c +++ b/src/backend/utils/misc/ps_status.c @@ -151,7 +151,32 @@ save_ps_display_args(int argc, char **argv) for (i = 0; environ[i] != NULL; i++) { if (end_of_area + 1 == environ[i]) - end_of_area = environ[i] + strlen(environ[i]); + { + + /* Do this for Linux libc libraries that might be unsafe. */ +#if defined(__linux__) && (! defined(__GLIBC__) && ! defined(__UCLIBC__ )) + /* + * If we see variables that the musl runtime linker is known + * to stash pointers to, give up so we don't break later calls + * to dlopen(). + */ + if (strstr(environ[i], "LD_LIBRARY_PATH=") == environ[i] || + strstr(environ[i], "LD_PRELOAD=") == environ[i]) + { + /* + * We can overwrite the name, but stop at the equals sign. + * Future loops will not find contiguous space, but we + * don't break early because we want to count the total + * number. + */ + end_of_area = strchr(environ[i], '='); + } + else +#endif + { + end_of_area = environ[i] + strlen(environ[i]); + } + } } ps_buffer = argv[0]; --1oNR6uTIepXZ2NsI--