Commit ec9a44b2a5

LemonBoy <thatlemon@gmail.com>
2021-05-20 15:28:59
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
1 parent abfe7f9
Changed files (1)
lib
std
lib/std/crypto/tlcsprng.zig
@@ -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);
 }