Skip to content

Commit

Permalink
stdlib: fix arc4random fallback to /dev/urandom (BZ 31612)
Browse files Browse the repository at this point in the history
The __getrandom_nocancel used by __arc4random_buf uses
INLINE_SYSCALL_CALL (which returns -1/errno) and the loop checks for
the return value instead of errno to fallback to /dev/urandom.

The malloc code now uses __getrandom_nocancel_nostatus, which uses
INTERNAL_SYSCALL_CALL, so there is no need to use the variant that does
not set errno (BZ#29624).

Checked on x86_64-linux-gnu.

Reviewed-by: Xi Ruoyao <xry111@xry111.site>
  • Loading branch information
zatrazz committed Jul 8, 2024
1 parent 9fc639f commit 184b9e5
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion stdlib/arc4random.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ __arc4random_buf (void *p, size_t n)
n -= l;
continue; /* Interrupted by a signal; keep going. */
}
else if (l == -ENOSYS)
else if (l < 0 && errno == ENOSYS)
break; /* No syscall, so fallback to /dev/urandom. */
arc4random_getrandom_failure ();
}
Expand Down

0 comments on commit 184b9e5

Please sign in to comment.