From f5f7053bcdb5b25b412a87f5853b4a6d94b8abe8 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Tue, 11 Jun 2013 15:38:56 +0200 Subject: [PATCH] leak-detective: Resolve hooked functions during initialization If uses of dlopen(), e.g. when loading plugins, produce errors an error string could get allocated dynamically. At this point realloc() might not yet be resolved and when dlsym() is later called by leak detective to do so the error string might get freed while leak detective is disabled and real_free() will be called with a pointer into one of leak detective's memory blocks instead of a pointer to the block itself, causing a SIGSEGV. --- src/libstrongswan/utils/leak_detective.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libstrongswan/utils/leak_detective.c b/src/libstrongswan/utils/leak_detective.c index 9d9062203..a24516352 100644 --- a/src/libstrongswan/utils/leak_detective.c +++ b/src/libstrongswan/utils/leak_detective.c @@ -404,10 +404,13 @@ static void* real_realloc(void *ptr, size_t size) #define HOOK(ret, name, ...) ret name(__VA_ARGS__) /** - * Hook initialization when not using hooks + * Hook initialization when not using hooks, resolve functions. */ static bool register_hooks() { + void *buf = real_malloc(8); + real_realloc(buf, 16); + real_free(buf); return TRUE; }