From dbd4428af5b84e352f5d727069ceab103010465e Mon Sep 17 00:00:00 2001 From: hariharandev1 Date: Mon, 17 Jun 2024 16:45:17 -0700 Subject: [PATCH] Additional check to only do match when we find a binding. --- src/gotcha_dl.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/gotcha_dl.c b/src/gotcha_dl.c index 7ee28a8..fe9308d 100644 --- a/src/gotcha_dl.c +++ b/src/gotcha_dl.c @@ -159,14 +159,16 @@ static void *dlsym_wrapper(void *handle, const char *symbol_name) { int result = lookup_hashtable(&function_hash_table, (hash_key_t)symbol_name, (hash_data_t *)&binding); void *val = orig_dlsym(handle, symbol_name); - void **wrappee_ptr = getInternalBindingAddressPointer( - (struct internal_binding_t **)binding->user_binding->function_handle); - if (result != -1 && (val == NULL || *wrappee_ptr == val)) { - // if the wrapper is found and the wrappee is the function requested. - // This is needed in cases where we wrap a function F1 from library A and - // we dynamically load function F1 from library B. As name is same, we need - // to make sure the wrappee are the same as well - return binding->user_binding->wrapper_pointer; + if (result != -1) { + void **wrappee_ptr = getInternalBindingAddressPointer( + (struct internal_binding_t **)binding->user_binding->function_handle); + if (val == NULL || *wrappee_ptr == val) { + // if the wrapper is found and the wrappee is the function requested. + // This is needed in cases where we wrap a function F1 from library A and + // we dynamically load function F1 from library B. As name is same, we + // need to make sure the wrappee are the same as well + return binding->user_binding->wrapper_pointer; + } } if (handle == RTLD_NEXT) { struct link_map *lib = gotchas_dlsym_rtld_next_lookup(