Skip to content

[WRAPPER] Fixed atfork handler#3460

Merged
ptitSeb merged 1 commit intoptitSeb:mainfrom
devarajabc:atfork
Feb 4, 2026
Merged

[WRAPPER] Fixed atfork handler#3460
ptitSeb merged 1 commit intoptitSeb:mainfrom
devarajabc:atfork

Conversation

@devarajabc
Copy link
Contributor

@devarajabc devarajabc commented Feb 4, 2026

Increment atfork_sz after registering an entry in my___register_atfork and my32___register_atfork, matching the working pattern in wrappedlibpthread.c. Without the increment, each registration overwrites slot 0 and all prior handlers are lost.

The two bugs mask each other. Since atfork_sz is never incremented by __register_atfork, it stays 0, so the broken loops are never reached with a nonzero count. Programs that register atfork handlers via pthread_atfork (which calls wrappedlibpthread.c and does increment correctly) would hit Bug 2 though — their parent/child handlers silently never run.

Fixes #3455

Increment atfork_sz after registering an entry in my___register_atfork
and my32___register_atfork, matching the working pattern in
wrappedlibpthread.c. Without the increment, each registration
overwrites slot 0 and all prior handlers are lost.

Fixed parent/child atfork loops from --i to ++i in x64emu_fork().
Starting at i=0 with --i causes an infinite loop with out-of-bounds
access when atfork_sz > 0. Changed to ++i to iterate forward, matching
the POSIX requirement that parent and child handlers execute in
registration order (FIFO), consistent with the existing prepare loop
which correctly iterates in reverse (LIFO).

Fixes ptitSeb#3455
@ptitSeb
Copy link
Owner

ptitSeb commented Feb 4, 2026

Thanks.

@ptitSeb ptitSeb merged commit 88272c2 into ptitSeb:main Feb 4, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Possible issues in atfork handler registration and execution in wrappedlibc.c

2 participants