Avoid dclose(RTLD_NEXT)
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Thu, 10 Nov 2022 18:38:17 +0000 (18:38 +0000)
committerAndreas Schneider <asn@samba.org>
Mon, 23 Jan 2023 12:09:52 +0000 (13:09 +0100)
In case the libc was not found and RTLD_NEXT is used instead, we should not
dlclose it, otherwise mayhem happens.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15228

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Pavel Filipenský <pfilipensky@samba.org>
src/nss_wrapper.c

index 07c975765e4bb2e07bfc4999d5b57a51466b6f07..0b2066cabe4a34a4d422ea6e629ca9ee4c8b041b 100644 (file)
@@ -6499,13 +6499,25 @@ void nwrap_destructor(void)
 
                /* libc */
                if (m->libc != NULL) {
-                       if (m->libc->handle != NULL) {
+                       if (m->libc->handle != NULL
+#ifdef RTLD_NEXT
+                           && m->libc->handle != RTLD_NEXT
+#endif
+                          ) {
                                dlclose(m->libc->handle);
                        }
-                       if (m->libc->nsl_handle != NULL) {
+                       if (m->libc->nsl_handle != NULL
+#ifdef RTLD_NEXT
+                           && m->libc->nsl_handle != RTLD_NEXT
+#endif
+                          ) {
                                dlclose(m->libc->nsl_handle);
                        }
-                       if (m->libc->sock_handle != NULL) {
+                       if (m->libc->sock_handle != NULL
+#ifdef RTLD_NEXT
+                           && m->libc->sock_handle != RTLD_NEXT
+#endif
+                          ) {
                                dlclose(m->libc->sock_handle);
                        }
                        SAFE_FREE(m->libc);