From 7bfc9c6fc7191c1ac21eb2c9c32b2a629499bd9e Mon Sep 17 00:00:00 2001 From: Trung Nguyen Date: Sun, 16 Apr 2023 18:38:26 +1000 Subject: [PATCH] libroot: Fix bad pointer access in __init_stack_protector MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The address of the variable should be taken instead of the variable itself being casted to `void*`. This fixes a rare segfault bug when any Haiku binary runs in a `chroot`ed environment without a `/dev` mount. Change-Id: I2fdacac62fadbcce8006bbf0a5350f6ec95133ae Reviewed-on: https://review.haiku-os.org/c/haiku/+/6377 Tested-by: Commit checker robot Reviewed-by: Jérôme Duval --- src/system/libroot/os/stack_protector.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/system/libroot/os/stack_protector.cpp b/src/system/libroot/os/stack_protector.cpp index 78dd546e89..21fdff5e9e 100644 --- a/src/system/libroot/os/stack_protector.cpp +++ b/src/system/libroot/os/stack_protector.cpp @@ -32,10 +32,11 @@ __init_stack_protector() } if (!done) { - ((unsigned char *)(void *)__stack_chk_guard)[0] = 0; - ((unsigned char *)(void *)__stack_chk_guard)[1] = 0; - ((unsigned char *)(void *)__stack_chk_guard)[2] = '\n'; - ((unsigned char *)(void *)__stack_chk_guard)[3] = 0xff; + unsigned char* p = (unsigned char *)&__stack_chk_guard; + p[0] = 0; + p[1] = 0; + p[2] = '\n'; + p[3] = 0xff; } }