Skip to content

Commit

Permalink
Additional check to only do match when we find a binding.
Browse files Browse the repository at this point in the history
  • Loading branch information
hariharan-devarajan committed Jun 17, 2024
1 parent 7578aa4 commit dbd4428
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/gotcha_dl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit dbd4428

Please sign in to comment.