|
From: Paul F. <pa...@so...> - 2026-03-02 20:16:23
|
https://sourceware.org/cgit/valgrind/commit/?id=5aea26aa5d6c7ed809d98231dd43ef3d7cf23ecf commit 5aea26aa5d6c7ed809d98231dd43ef3d7cf23ecf Author: Paul Floyd <pj...@wa...> Date: Mon Mar 2 21:12:13 2026 +0100 FreeBSD syscall: clean up sigwait wrapper This is another that returns 0 / errno code. The POST was already doing the right thing. Changed the PRE to always set SfMayBlock rather than only if ARG1 is safe to dereference. Updated testcase. Diff: --- coregrind/m_syswrap/syswrap-freebsd.c | 5 +--- memcheck/tests/freebsd/Makefile.am | 2 +- memcheck/tests/freebsd/sigwait.c | 9 +++++++ memcheck/tests/freebsd/sigwait.stderr.exp | 33 ++++++++++++++++++++---- memcheck/tests/freebsd/sigwait.stderr.exp-x86 | 36 +++++++++++++++++++++++---- 5 files changed, 70 insertions(+), 15 deletions(-) diff --git a/coregrind/m_syswrap/syswrap-freebsd.c b/coregrind/m_syswrap/syswrap-freebsd.c index 7dc778595d..04d829ca97 100644 --- a/coregrind/m_syswrap/syswrap-freebsd.c +++ b/coregrind/m_syswrap/syswrap-freebsd.c @@ -4211,11 +4211,8 @@ PRE(sys_sigwait) PRE_REG_READ2(int, "sigwait", const vki_sigset_t *, set, int *, sig); PRE_MEM_READ( "sigwait(set)", ARG1, sizeof(vki_sigset_t)); - vki_sigset_t* set = (vki_sigset_t*)ARG1; - if (ML_(safe_to_deref)(set, sizeof(vki_sigset_t))) { - *flags |= SfMayBlock; - } PRE_MEM_WRITE( "sigwait(sig)", ARG2, sizeof(int)); + *flags |= SfMayBlock; } // sigwait doesn't follow the norm of returning -1 on error diff --git a/memcheck/tests/freebsd/Makefile.am b/memcheck/tests/freebsd/Makefile.am index ae0bd1e48b..9ea49533ff 100644 --- a/memcheck/tests/freebsd/Makefile.am +++ b/memcheck/tests/freebsd/Makefile.am @@ -263,7 +263,7 @@ scalar_pdfork_CFLAGS = ${AM_CFLAGS} @FLAG_W_NO_UNINITIALIZED@ scalar_thr_exit_CFLAGS = ${AM_CFLAGS} @FLAG_W_NO_UNINITIALIZED@ scalar_vfork_CFLAGS = ${AM_CFLAGS} @FLAG_W_NO_UNUSED_VARIABLE@ sctp2_CFLAGS = ${AM_CFLAGS} @FLAG_W_NO_UNINITIALIZED@ -sigwait_CFLAGS = ${AM_CFLAGS} @FLAG_W_NO_USE_AFTER_FREE@ +sigwait_CFLAGS = ${AM_CFLAGS} @FLAG_W_NO_USE_AFTER_FREE@ @FLAG_W_NO_NONNULL@ stat_CFLAGS = ${AM_CFLAGS} @FLAG_W_NO_MAYBE_UNINITIALIZED@ @FLAG_W_NO_UNINITIALIZED@ @FLAG_W_NO_USE_AFTER_FREE@ statfs_CFLAGS = ${AM_CFLAGS} @FLAG_W_NO_UNINITIALIZED@ @FLAG_W_NO_USE_AFTER_FREE@ @FLAG_W_NO_ALLOC_SIZE@ timing_safe_CFLAGS = ${AM_CFLAGS} @FLAG_W_NO_USE_AFTER_FREE@ diff --git a/memcheck/tests/freebsd/sigwait.c b/memcheck/tests/freebsd/sigwait.c index 13dd2007e7..eb078c4dfe 100644 --- a/memcheck/tests/freebsd/sigwait.c +++ b/memcheck/tests/freebsd/sigwait.c @@ -2,6 +2,7 @@ #include <stdio.h> #include <stdlib.h> #include <assert.h> +#include <errno.h> // from stack overflow // https://stackoverflow.com/questions/6326290/about-the-ambiguous-description-of-sigwait @@ -63,6 +64,14 @@ int main(void) result = sigwait(psigset, &sig); + result = sigwait(NULL, &sig); + assert(result == EFAULT); + + raise(SIGUSR1); + + result = sigwait(psigset, NULL); + assert(result == EFAULT); + return 0; } diff --git a/memcheck/tests/freebsd/sigwait.stderr.exp b/memcheck/tests/freebsd/sigwait.stderr.exp index 039c432956..925859b950 100644 --- a/memcheck/tests/freebsd/sigwait.stderr.exp +++ b/memcheck/tests/freebsd/sigwait.stderr.exp @@ -1,22 +1,45 @@ Syscall param sigwait(sig) points to unaddressable byte(s) at 0x........: _sigwait (in /...libc...) by 0x........: __sigwait (in /...libc...) - by 0x........: main (sigwait.c:58) + by 0x........: main (sigwait.c:59) Address 0x........ is 0 bytes inside a block of size 4 free'd at 0x........: free (vg_replace_malloc.c:...) + by 0x........: main (sigwait.c:58) + Block was alloc'd at + at 0x........: malloc (vg_replace_malloc.c:...) by 0x........: main (sigwait.c:57) + +Syscall param sigwait(set) points to unaddressable byte(s) + at 0x........: _sigwait (in /...libc...) + by 0x........: __sigwait (in /...libc...) + by 0x........: main (sigwait.c:65) + Address 0x........ is 0 bytes inside a block of size 16 free'd + at 0x........: free (vg_replace_malloc.c:...) + by 0x........: main (sigwait.c:61) Block was alloc'd at at 0x........: malloc (vg_replace_malloc.c:...) - by 0x........: main (sigwait.c:56) + by 0x........: main (sigwait.c:28) + +Syscall param sigwait(set) points to unaddressable byte(s) + at 0x........: _sigwait (in /...libc...) + by 0x........: __sigwait (in /...libc...) + by 0x........: main (sigwait.c:67) + Address 0x........ is not stack'd, malloc'd or (recently) free'd Syscall param sigwait(set) points to unaddressable byte(s) at 0x........: _sigwait (in /...libc...) by 0x........: __sigwait (in /...libc...) - by 0x........: main (sigwait.c:64) + by 0x........: main (sigwait.c:72) Address 0x........ is 0 bytes inside a block of size 16 free'd at 0x........: free (vg_replace_malloc.c:...) - by 0x........: main (sigwait.c:60) + by 0x........: main (sigwait.c:61) Block was alloc'd at at 0x........: malloc (vg_replace_malloc.c:...) - by 0x........: main (sigwait.c:27) + by 0x........: main (sigwait.c:28) + +Syscall param sigwait(sig) points to unaddressable byte(s) + at 0x........: _sigwait (in /...libc...) + by 0x........: __sigwait (in /...libc...) + by 0x........: main (sigwait.c:72) + Address 0x........ is not stack'd, malloc'd or (recently) free'd diff --git a/memcheck/tests/freebsd/sigwait.stderr.exp-x86 b/memcheck/tests/freebsd/sigwait.stderr.exp-x86 index c03ad32206..f5ed197053 100644 --- a/memcheck/tests/freebsd/sigwait.stderr.exp-x86 +++ b/memcheck/tests/freebsd/sigwait.stderr.exp-x86 @@ -2,23 +2,49 @@ Syscall param sigwait(sig) points to unaddressable byte(s) at 0x........: _sigwait (in /...libc...) by 0x........: __sigwait (in /...libc...) by 0x........: __sigwait (in /...libc...) - by 0x........: main (sigwait.c:58) + by 0x........: main (sigwait.c:59) Address 0x........ is 0 bytes inside a block of size 4 free'd at 0x........: free (vg_replace_malloc.c:...) + by 0x........: main (sigwait.c:58) + Block was alloc'd at + at 0x........: malloc (vg_replace_malloc.c:...) by 0x........: main (sigwait.c:57) + +Syscall param sigwait(set) points to unaddressable byte(s) + at 0x........: _sigwait (in /...libc...) + by 0x........: __sigwait (in /...libc...) + by 0x........: __sigwait (in /...libc...) + by 0x........: main (sigwait.c:65) + Address 0x........ is 0 bytes inside a block of size 16 free'd + at 0x........: free (vg_replace_malloc.c:...) + by 0x........: main (sigwait.c:61) Block was alloc'd at at 0x........: malloc (vg_replace_malloc.c:...) - by 0x........: main (sigwait.c:56) + by 0x........: main (sigwait.c:28) Syscall param sigwait(set) points to unaddressable byte(s) at 0x........: _sigwait (in /...libc...) by 0x........: __sigwait (in /...libc...) by 0x........: __sigwait (in /...libc...) - by 0x........: main (sigwait.c:64) + by 0x........: main (sigwait.c:67) + Address 0x........ is not stack'd, malloc'd or (recently) free'd + +Syscall param sigwait(set) points to unaddressable byte(s) + at 0x........: _sigwait (in /...libc...) + by 0x........: __sigwait (in /...libc...) + by 0x........: __sigwait (in /...libc...) + by 0x........: main (sigwait.c:72) Address 0x........ is 0 bytes inside a block of size 16 free'd at 0x........: free (vg_replace_malloc.c:...) - by 0x........: main (sigwait.c:60) + by 0x........: main (sigwait.c:61) Block was alloc'd at at 0x........: malloc (vg_replace_malloc.c:...) - by 0x........: main (sigwait.c:27) + by 0x........: main (sigwait.c:28) + +Syscall param sigwait(sig) points to unaddressable byte(s) + at 0x........: _sigwait (in /...libc...) + by 0x........: __sigwait (in /...libc...) + by 0x........: __sigwait (in /...libc...) + by 0x........: main (sigwait.c:72) + Address 0x........ is not stack'd, malloc'd or (recently) free'd |