pwrap: Add support for running with Sanitizers
authorAndreas Schneider <asn@samba.org>
Fri, 15 Nov 2019 08:34:03 +0000 (09:34 +0100)
committerAndreas Schneider <asn@samba.org>
Fri, 15 Nov 2019 08:34:03 +0000 (09:34 +0100)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
src/pam_wrapper.c

index 48d2c2ae566a6a20a74e2caec5ff448c706aa44b..7ae26d104965e62625e2557a1d9c9c2922889feb 100644 (file)
@@ -300,15 +300,25 @@ static void *pwrap_load_lib_handle(enum pwrap_lib lib)
        void *handle = NULL;
 
 #ifdef RTLD_DEEPBIND
-       const char *env = getenv("LD_PRELOAD");
+       const char *env_preload = getenv("LD_PRELOAD");
+       const char *env_deepbind = getenv("UID_WRAPPER_DISABLE_DEEPBIND");
+       bool enable_deepbind = true;
 
        /* Don't do a deepbind if we run with libasan */
-       if (env != NULL && strlen(env) < PATH_MAX) {
-               const char *p = strstr(env, "libasan.so");
-               if (p == NULL) {
-                       flags |= RTLD_DEEPBIND;
+       if (env_preload != NULL && strlen(env_preload) < 1024) {
+               const char *p = strstr(env_preload, "libasan.so");
+               if (p != NULL) {
+                       enable_deepbind = false;
                }
        }
+
+       if (env_deepbind != NULL && strlen(env_deepbind) >= 1) {
+               enable_deepbind = false;
+       }
+
+       if (enable_deepbind) {
+               flags |= RTLD_DEEPBIND;
+       }
 #endif
 
        switch (lib) {