Skip to content

Commit

Permalink
ZOOKEEPER-4809: Fix adaptor threads use-after-free when log level is …
Browse files Browse the repository at this point in the history
…debug

The log callback needs to be obtained from freed zhandle when the log level
is debug, resulting in used-after-free.
  • Loading branch information
fanyang89 committed Mar 15, 2024
1 parent 7074448 commit fb7486a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions zookeeper-client/zookeeper-client-c/src/mt_adaptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ unsigned __stdcall do_io( void * v)
void *do_io(void *v)
#endif
{
log_callback_fn log_fn;
zhandle_t *zh = (zhandle_t*)v;
#ifndef WIN32
struct pollfd fds[2];
Expand Down Expand Up @@ -456,8 +457,9 @@ void *do_io(void *v)
if(is_unrecoverable(zh))
break;
}
api_epilog(zh, 0);
LOG_DEBUG(LOGCALLBACK(zh), "IO thread terminated");
log_fn = LOGCALLBACK(zh);
api_epilog(zh, 0);
LOG_DEBUG(log_fn, "IO thread terminated");
return 0;
}

Expand All @@ -468,6 +470,7 @@ void *do_completion(void *v)
#endif
{
zhandle_t *zh = v;
log_callback_fn fn;
api_prolog(zh);
notify_thread_ready(zh);
LOG_DEBUG(LOGCALLBACK(zh), "started completion thread");
Expand All @@ -479,8 +482,9 @@ void *do_completion(void *v)
pthread_mutex_unlock(&zh->completions_to_process.lock);
process_completions(zh);
}
api_epilog(zh, 0);
LOG_DEBUG(LOGCALLBACK(zh), "completion thread terminated");
fn = LOGCALLBACK(zh);
api_epilog(zh, 0);
LOG_DEBUG(fn, "completion thread terminated");
return 0;
}

Expand Down

0 comments on commit fb7486a

Please sign in to comment.