mirror of
https://github.com/ziglang/zig.git
synced 2026-01-20 22:35:24 +00:00
start code: overwrite AT_RANDOM after we use it
This commit is contained in:
parent
013efaf139
commit
4dcd1e6059
@ -226,11 +226,17 @@ fn posixCallMainAndExit() noreturn {
|
||||
// "The address of sixteen bytes containing a random value."
|
||||
const addr = auxv[i].a_un.a_val;
|
||||
if (addr == 0) break;
|
||||
const ptr = @intToPtr(*const [16]u8, addr);
|
||||
const ptr = @intToPtr(*[16]u8, addr);
|
||||
var seed: [32]u8 = undefined;
|
||||
seed[0..16].* = ptr.*;
|
||||
seed[16..].* = ptr.*;
|
||||
tlcsprng.init(seed);
|
||||
// Overwrite AT_RANDOM after we use it, otherwise our secure
|
||||
// seed is sitting in memory ready for some other code in the
|
||||
// program to reuse, and hence break our security.
|
||||
// We play nice by refreshing it with fresh random bytes
|
||||
// rather than clearing it.
|
||||
std.crypto.random.bytes(ptr);
|
||||
break;
|
||||
},
|
||||
else => continue,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user