summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibC
diff options
context:
space:
mode:
authorAndrew Kaster <andrewdkaster@gmail.com>2021-05-24 08:21:59 -0600
committerAndreas Kling <kling@serenityos.org>2021-05-27 15:18:03 +0200
commit74da0f24f0c99d2cb1646234e841bd42a7fb8c99 (patch)
tree3151cd69df717953c95dbb975825f7f527e15092 /Userland/Libraries/LibC
parent1a0eed705ce5348a9528bb1ecc184e921dcbac2b (diff)
downloadserenity-74da0f24f0c99d2cb1646234e841bd42a7fb8c99.zip
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.
Diffstat (limited to 'Userland/Libraries/LibC')
-rw-r--r--Userland/Libraries/LibC/stdlib.cpp6
1 files 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)