]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
FreeBSD syscall: clean up sigwait wrapper
authorPaul Floyd <pjfloyd@wanadoo.fr>
Mon, 2 Mar 2026 20:12:13 +0000 (21:12 +0100)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Mon, 2 Mar 2026 20:12:13 +0000 (21:12 +0100)
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.

coregrind/m_syswrap/syswrap-freebsd.c
memcheck/tests/freebsd/Makefile.am
memcheck/tests/freebsd/sigwait.c
memcheck/tests/freebsd/sigwait.stderr.exp
memcheck/tests/freebsd/sigwait.stderr.exp-x86

index 7dc778595d3e8f6ba4570153e7c71c72aff49774..04d829ca9709d7593fcc36a6aefbe3d9b063ce5a 100644 (file)
@@ -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
index ae0bd1e48bb547ddcbd1c52f0f8c2f9b4899d76e..9ea49533ffbf2bfad845436134c47a1d752efc2d 100644 (file)
@@ -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@
index 13dd2007e77bd21a5077482eb6d8cc00689848a8..eb078c4dfec75eda8cf6864482e22c3bfee1619d 100644 (file)
@@ -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;
 }
 
index 039c4329563897f4a126d665266c322cb41d0ef9..925859b950575de7d72d9338f7d16c712059d426 100644 (file)
@@ -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
 
index c03ad32206fcfbe51ac43f015e94d976f388b812..f5ed1970539e4f0d16ed8dbdcb30ee0e5e86a15f 100644 (file)
@@ -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