From db97488e6fe044a81cd45d90b11f1262b296c50c Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Wed, 10 Mar 2021 20:45:40 +0000 Subject: [PATCH] Avoid a crash if constructors in other libraries are called before br_init. --- auto-buildrequires-preload.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/auto-buildrequires-preload.c b/auto-buildrequires-preload.c index b67e20a..c8622a1 100644 --- a/auto-buildrequires-preload.c +++ b/auto-buildrequires-preload.c @@ -95,6 +95,13 @@ abr_open (const char *pathname, int flags, mode_t mode) int fd; char *rp; + /* Constructors in other libraries can call this function before + * br_init has been called. Detect this and call br_init to avoid a + * crash. + */ + if (glibc_open == NULL) + br_init (); + rp = br_path (pathname); if (rp) br_log ("open %s\n", rp); @@ -114,6 +121,13 @@ abr_execve (const char *filename, char *const argv[], char *const envp[]) int r; char *rp; + /* Constructors in other libraries can call this function before + * br_init has been called. Detect this and call br_init to avoid a + * crash. + */ + if (glibc_open == NULL) + br_init (); + rp = br_path (filename); if (rp) br_log ("execve %s\n", rp); @@ -190,7 +204,9 @@ br_log (const char *fs, ...) static void br_init (void) { - void *dl; + _Atomic static void *dl; + + if (dl != NULL) return; dl = dlopen ("/lib64/" LIBC_SO, RTLD_LAZY|RTLD_LOCAL); if (dl == NULL) // Try '/lib/' also -- 1.8.3.1