From 74da0f24f0c99d2cb1646234e841bd42a7fb8c99 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Mon, 24 May 2021 08:21:59 -0600 Subject: [PATCH] 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. --- Userland/Libraries/LibC/stdlib.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibC/stdlib.cpp b/Userland/Libraries/LibC/stdlib.cpp index 0406462959..5449b9814d 100644 --- a/Userland/Libraries/LibC/stdlib.cpp +++ b/Userland/Libraries/LibC/stdlib.cpp @@ -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)