File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed
libc/test/integration/src/stdlib/linux Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -20,13 +20,20 @@ void basic_test() {
20
20
// Try to get a guard
21
21
if (auto guard = local_state.get ()) {
22
22
// Fill a small buffer with random data
23
- long long buffer[32 ] = { 0 };
23
+ char buffer[256 ]{ };
24
24
guard->fill (buffer, sizeof (buffer));
25
25
26
- // Basic sanity check - buffer should not have zero
26
+ // Basic sanity check - count zero bytes.
27
+ // With 256 bytes, getting more than ~10 zero bytes would be suspicious
28
+ size_t zero_count = 0 ;
27
29
for (auto &i : buffer)
28
30
if (i == 0 )
29
- __builtin_trap ();
31
+ zero_count++;
32
+
33
+ // With uniform distribution, expect ~1 zero byte per 256 bytes
34
+ // Having more than 16 zero bytes in 256 bytes is very unlikely
35
+ if (zero_count > 16 )
36
+ __builtin_trap ();
30
37
}
31
38
// If we can't get a guard, that's okay - the vDSO might not be available
32
39
// or the system might not support getrandom
You can’t perform that action at this time.
0 commit comments