From ec9a44b2a59a9061e1979be5268dd657cd5402fd Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Thu, 20 May 2021 15:28:59 +0200 Subject: [PATCH] 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 --- lib/std/crypto/tlcsprng.zig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/std/crypto/tlcsprng.zig b/lib/std/crypto/tlcsprng.zig index c23e99e2dd..c2cb119d4a 100644 --- a/lib/std/crypto/tlcsprng.zig +++ b/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); }