]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
FreeBSD syscall: improve sigwait and sigwaitinfo wrapper.
authorPaul Floyd <pjfloyd@wanadoo.fr>
Thu, 24 Jul 2025 20:45:01 +0000 (22:45 +0200)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Thu, 24 Jul 2025 20:45:01 +0000 (22:45 +0200)
Both take two pointers. We were allowing null pointers for all
of them. Only the 2nd argument of sigwaitinfo, info, is
allowed to be NULL. Update the scalar test with some NULL
arguments for these syscalls.

coregrind/m_syswrap/syswrap-freebsd.c
memcheck/tests/freebsd/scalar.c
memcheck/tests/freebsd/scalar.stderr.exp

index ac371e125ab130a01d72318e4378050cc67628d9..08c4ec3c3c4c2d61ff3b9eb9730245c93fd6f352 100644 (file)
@@ -3317,9 +3317,7 @@ PRE(sys_sigwaitinfo)
          ARG1,ARG2);
    PRE_REG_READ2(int, "sigwaitinfo",
                  const vki_sigset_t *, set, vki_siginfo_t *, info);
-   if (ARG1 != 0) {
-      PRE_MEM_READ(  "sigwaitinfo(set)",  ARG1, sizeof(vki_sigset_t));
-   }
+   PRE_MEM_READ(  "sigwaitinfo(set)",  ARG1, sizeof(vki_sigset_t));
    if (ARG2 != 0) {
       PRE_MEM_WRITE( "sigwaitinfo(info)", ARG2, sizeof(vki_siginfo_t) );
    }
@@ -4099,21 +4097,20 @@ PRE(sys_sigwait)
          ARG1,ARG2);
    PRE_REG_READ2(int, "sigwait",
                  const vki_sigset_t *, set, int *, sig);
-   if (ARG1 != 0) {
-      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;
-      }
-   }
-   if (ARG2 != 0) {
-      PRE_MEM_WRITE( "sigwait(sig)", ARG2, sizeof(int));
+   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));
 }
 
+// sigwait doesn't follow the norm of returning -1 on error
+// instead it returns errno if there is an error
 POST(sys_sigwait)
 {
-   if (RES == 0 && ARG2 != 0) {
+   if (RES == 0)
+   {
       POST_MEM_WRITE( ARG2, sizeof(int));
    }
 }
index 9c67888f984439152326cc9eff43a0f21651dfd5..234e649f78fdbabfa706a5930c481b8fbd1e1c18 100644 (file)
@@ -1271,7 +1271,11 @@ int main(void)
 
    /* SYS_sigwaitinfo             346 */
    GO(SYS_sigwaitinfo, "2s 2m");
-   SY(SYS_sigwaitinfo, x0+1, x0+2, x0+3); FAIL;
+   SY(SYS_sigwaitinfo, x0+1, x0+2); FAIL;
+
+   GO(SYS_sigwaitinfo, "(NULL info) 2s 1m");
+   SY(SYS_sigwaitinfo, x0, x0); FAIL;
+
 
    /* SYS___acl_get_file          347 */
    GO(SYS___acl_get_file, "3s 2m");
@@ -1549,6 +1553,10 @@ int main(void)
    SY(SYS_sigwait, x0+1, x0+2); SUCC;
    assert(res == EFAULT);
 
+   GO(SYS_sigwait, "(NULL ags) 2s 2m");
+   SY(SYS_sigwait, x0, x0); SUCC;
+   assert(res == EFAULT);
+
    // thr_create                  430
 
    /* SYS_thr_exit                431 */
index dbe79c6e84efccdcd4b9ce8ebaa9513b005328b4..ae9c15f6a840e0e23d54a7cb4955c565f5be5bbd 100644 (file)
@@ -2509,6 +2509,19 @@ Syscall param sigwaitinfo(info) points to unaddressable byte(s)
    ...
  Address 0x........ is not stack'd, malloc'd or (recently) free'd
 
+---------------------------------------------------------
+346:         SYS_sigwaitinfo (NULL info) 2s 1m
+---------------------------------------------------------
+Syscall param sigwaitinfo(set) contains uninitialised byte(s)
+   ...
+
+Syscall param sigwaitinfo(info) contains uninitialised byte(s)
+   ...
+
+Syscall param sigwaitinfo(set) points to unaddressable byte(s)
+   ...
+ Address 0x........ is not stack'd, malloc'd or (recently) free'd
+
 ---------------------------------------------------------
 347:      SYS___acl_get_file 3s 2m
 ---------------------------------------------------------
@@ -3360,6 +3373,23 @@ Syscall param sigwait(sig) points to unaddressable byte(s)
    ...
  Address 0x........ is not stack'd, malloc'd or (recently) free'd
 
+---------------------------------------------------------
+429:             SYS_sigwait (NULL ags) 2s 2m
+---------------------------------------------------------
+Syscall param sigwait(set) contains uninitialised byte(s)
+   ...
+
+Syscall param sigwait(sig) contains uninitialised byte(s)
+   ...
+
+Syscall param sigwait(set) points to unaddressable byte(s)
+   ...
+ Address 0x........ is not stack'd, malloc'd or (recently) free'd
+
+Syscall param sigwait(sig) points to unaddressable byte(s)
+   ...
+ Address 0x........ is not stack'd, malloc'd or (recently) free'd
+
 ---------------------------------------------------------
 431:            SYS_thr_exit other
 ---------------------------------------------------------