Skip to content

Commit 6fb36c3

Browse files
committed
Fix NULL dereference in accept_callback when process terminates
If the owning process terminates between the accept() call and globalcontext_get_process_lock(), ctx will be NULL. The code immediately dereferences ctx->platform_data without checking, causing a segfault. Add a NULL check consistent with other callbacks (e.g. recv_callback), closing the accepted fd if needed and freeing the listener before returning. Signed-off-by: Peter M <petermm@gmail.com>
1 parent 8897a34 commit 6fb36c3

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

src/platforms/generic_unix/lib/socket_driver.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,13 @@ static EventListener *accept_callback(GlobalContext *glb, EventListener *base_li
10461046
socklen_t clientlen = sizeof(clientaddr);
10471047
int fd = accept(listener->base.fd, (struct sockaddr *) &clientaddr, &clientlen);
10481048
Context *ctx = globalcontext_get_process_lock(glb, listener->process_id);
1049+
if (UNLIKELY(ctx == NULL)) {
1050+
if (fd != -1) {
1051+
close(fd);
1052+
}
1053+
free(listener);
1054+
return NULL;
1055+
}
10491056
SocketDriverData *socket_data = (SocketDriverData *) ctx->platform_data;
10501057
EventListener *result = NULL;
10511058
if (fd == -1) {

0 commit comments

Comments
 (0)