std: Make atfork handler more robust

The atfork handler is executed even when fork()-ing threads that have
never initialized their local csprng. Handle this case gracefully
instead of raising a runtime error.

Fixes #8841
This commit is contained in:
LemonBoy 2021-05-20 15:28:59 +02:00
parent abfe7f96dd
commit ec9a44b2a5

View File

@ -150,6 +150,9 @@ fn setupPthreadAtforkAndFill(buffer: []u8) void {
}
fn childAtForkHandler() callconv(.C) void {
// The atfork handler is global, this function may be called after
// fork()-ing threads that never initialized the CSPRNG context.
if (wipe_mem.len == 0) return;
std.crypto.utils.secureZero(u8, wipe_mem);
}