1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 08:44:58 +00:00

LibC: Use u32 in arc4random instead of char[4]

There's no alignment requirements on a char[4] buffer, so this was
causing unaligned reads that were caught by UBSAN.
This commit is contained in:
Andrew Kaster 2021-05-24 08:21:59 -06:00 committed by Andreas Kling
parent 1a0eed705c
commit 74da0f24f0

View file

@ -1080,9 +1080,9 @@ unsigned long long strtoull(const char* str, char** endptr, int base)
// TODO: In the future, rand can be made deterministic and this not.
uint32_t arc4random(void)
{
char buf[4];
syscall(SC_getrandom, buf, 4, 0);
return *(uint32_t*)buf;
uint32_t buf;
syscall(SC_getrandom, &buf, sizeof(buf), 0);
return buf;
}
void arc4random_buf(void* buffer, size_t buffer_size)