From 936e0a51fea31f9ba0484c29d1dcbe1e367ce9e2 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Wed, 7 Feb 2018 15:02:53 +0100 Subject: [PATCH] libnm-core: don't use RTLD_DEEPBIND when building with asan The address sanitizer is not compatible [1] with libraries dynamically opened using RTLD_DEEPBIND: disable the flag when building with asan. [1] https://github.com/google/sanitizers/issues/611 --- configure.ac | 1 + libnm-core/nm-json.c | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 62dae15eef..01984dec76 100644 --- a/configure.ac +++ b/configure.ac @@ -1148,6 +1148,7 @@ if test "$with_address_sanitizer" = yes -o "$with_address_sanitizer" = "exec"; t sanitizer_exec_cflags="$sanitizer_exec_cflags -fsanitize=address" sanitizer_exec_ldflags="$sanitizer_exec_ldflags -Wc,-fsanitize=address" + AC_DEFINE(ASAN_BUILD, 1, [Whether NM is built with address sanitizer]) if test "$with_address_sanitizer" = "yes"; then sanitizer_lib_cflags="$sanitizer_lib_cflags -fsanitize=address" diff --git a/libnm-core/nm-json.c b/libnm-core/nm-json.c index f359a76046..aa181a4aec 100644 --- a/libnm-core/nm-json.c +++ b/libnm-core/nm-json.c @@ -94,6 +94,7 @@ nm_jansson_load (void) MISSING, } state = UNKNOWN; void *handle; + int mode; if (G_LIKELY (state != UNKNOWN)) goto out; @@ -102,7 +103,13 @@ nm_jansson_load (void) if (!bind_symbols (RTLD_DEFAULT)) goto out; - handle = dlopen (JANSSON_SONAME, RTLD_LAZY | RTLD_LOCAL | RTLD_NODELETE | RTLD_DEEPBIND); + mode = RTLD_LAZY | RTLD_LOCAL | RTLD_NODELETE | RTLD_DEEPBIND; +#if defined (ASAN_BUILD) + /* Address sanitizer is incompatible with RTLD_DEEPBIND. */ + mode &= ~RTLD_DEEPBIND; +#endif + handle = dlopen (JANSSON_SONAME, mode); + if (!handle) goto out;