https://sourceware.org/cgit/valgrind/commit/?id=46bc7241a79e68663b707b40b1866cc8303924c3
commit 46bc7241a79e68663b707b40b1866cc8303924c3
Author: Paul Floyd <pj...@wa...>
Date: Fri Dec 5 21:59:34 2025 +0100
Darwin: also clean up client stack creation
Make stringbase and strtab be based off clstack_end + 1
rather than clstack_end. clstack_end is the address of the
last byte of the stack, not one past the end of the stack.
That means that it is not word aligned. Adding 1 makes
the calculation word aligned.
Depending on the length of the string table with rounding
it could happen that the executable_path pointer would
overwrite the start of argv[0] in the string table.
I think that that there are supposed to be 0-16 bytes between
the end of the pointers and the string table (or is that
ELF?).
Diff:
---
coregrind/m_initimg/initimg-darwin.c | 14 +++-----------
1 file changed, 3 insertions(+), 11 deletions(-)
diff --git a/coregrind/m_initimg/initimg-darwin.c b/coregrind/m_initimg/initimg-darwin.c
index 3ddc9806c6..0befeaef39 100644
--- a/coregrind/m_initimg/initimg-darwin.c
+++ b/coregrind/m_initimg/initimg-darwin.c
@@ -360,16 +360,8 @@ Addr setup_client_stack( void* init_sp,
stringsize += VG_(strlen)(*cpp) + 1;
}
- // @todo PJF there is a bug in the size calculation or rounding
- // somewhere. This should be "+= 2" (one of the pointer to exec
- // path and one for the terminating NULL pointer). When I run
- // "./tests/vg_regtest none/tests" from a Korn shell script
- // then the allexec32/64 tests fail because they print out "argv[0]".
- // I think that what happens is that writing to "ptr" overwrites the
- // start of strtab resulting in the argv[0] the exe name being a
- // string starting with 8 \0s (not tested)
- /* Darwin executable_path + NULL */
- auxsize += 3 * sizeof(Word);
+ /* NULL separator and executable path */
+ auxsize += 2 * sizeof(HChar **);
if (info->executable_path) {
stringsize += 1 + VG_(strlen)(info->executable_path);
}
@@ -395,7 +387,7 @@ Addr setup_client_stack( void* init_sp,
client_SP = VG_ROUNDDN(client_SP, 32); /* make stack 32 byte aligned */
/* base of the string table (aligned) */
- stringbase = strtab = (HChar *)clstack_end
+ stringbase = strtab = (HChar *)clstack_end + 1
- VG_ROUNDUP(stringsize, sizeof(int));
/* The max stack size */
|