NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

standards/60997: sigqueue accepts zero and negative "pids", contrary to POSIX and manpage



>Number:         60997
>Category:       standards
>Synopsis:       sigqueue accepts zero and negative "pids", contrary to POSIX and manpage
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    standards-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Nov 13 06:30:01 +0000 2026
>Originator:     Bobby Bingham
>Release:        NetBSD-current 20261111155711
>Organization:
>Environment:
NetBSD netbsdvm.local 11.99.11 NetBSD 11.99.11 (GENERIC) #0: Wed Nov 11 15:57:11 UTC 2026  mkrepro%mkrepro.NetBSD.org@localhost:/usr/src/sys/arch/amd64/compile/GENERIC amd64
>Description:
sys_sigqueueinfo calls kill1, which is also used by sys_kill and handles the signal broadcasts specified for pid<=0 in that system call.

However, sigqueue is not specified to support broadcasts, and is required to fail for a pid that does not exist:

>From https://pubs.opengroup.org/onlinepubs/9799919799/functions/sigqueue.html

    The sigqueue() function shall fail if:
        ...
        [ESRCH]
        The process pid does not exist.

This also does not appear to be a documented extension.  It is not mentioned in the manpage, which in fact says:

    The sigqueue() system call queues a signal to a single process specified by the pid argument
>How-To-Repeat:
Apply this patch to the tests and run them.

diff --git a/tests/lib/libc/sys/t_sigqueue.c b/tests/lib/libc/sys/t_sigqueue.c
index 317ee591162a..9fefba0f7d1a 100644
--- a/tests/lib/libc/sys/t_sigqueue.c
+++ b/tests/lib/libc/sys/t_sigqueue.c
@@ -73,7 +73,7 @@ ATF_TC_BODY(sigqueue_basic, tc)
 
 	sv.sival_int = VALUE;
 
-	if (sigqueue(0, SIGUSR1, sv) != 0)
+	if (sigqueue(getpid(), SIGUSR1, sv) != 0)
 		atf_tc_fail("sigqueue failed");
 
 	sched_yield();
@@ -92,6 +92,8 @@ ATF_TC_BODY(sigqueue_err, tc)
 
 	errno = 0;
 	ATF_REQUIRE_ERRNO(EINVAL, sigqueue(getpid(), -1, sv) == -1);
+	errno = 0;
+	ATF_REQUIRE_ERRNO(ESRCH, sigqueue(0, SIGINFO, sv) == -1);
 }
 
 static int signals[] = {
>Fix:
diff --git a/sys/kern/sys_sig.c b/sys/kern/sys_sig.c
index 211ccc8587c7..dbed5c8191bf 100644
--- a/sys/kern/sys_sig.c
+++ b/sys/kern/sys_sig.c
@@ -285,9 +285,10 @@ sys_sigqueueinfo(struct lwp *l, const struct sys_sigqueueinfo_args *uap,
     register_t *retval)
 {
 	/* {
-		syscallarg(pid_t int)	pid;
+		syscallarg(pid_t)	pid;
 		syscallarg(const siginfo_t *)	info;
 	} */
+	pid_t pid;
 	ksiginfo_t	ksi;
 	int error;
 
@@ -297,7 +298,10 @@ sys_sigqueueinfo(struct lwp *l, const struct sys_sigqueueinfo_args *uap,
 	    sizeof(ksi.ksi_info))) != 0)
 		return error;
 
-	return kill1(l, SCARG(uap, pid), &ksi, retval);
+	if ((pid = SCARG(uap, pid)) <= 0)
+		return ESRCH;
+
+	return kill1(l, pid, &ksi, retval);
 }
 
 int




Home | Main Index | Thread Index | Old Index