[PATCH] Cygwin: kill(1): fix parsing of negative pid

Christian Franke Christian.Franke@t-online.de
Sat Apr 12 14:03:53 GMT 2025


Found during testing of:
https://sourceware.org/pipermail/cygwin-patches/2025q2/013651.html

Examples using nonexistent PIDs:

$ /bin/kill -9 -8 # OK, same as /bin/kill -9 -- -8
kill: -8: No such process

$ /bin/kill -SIGKILL -11 # bogus message
kill: illegal pid: -SIGKILL
kill: -11: No such process

$ /bin/kill -9 -11 # BAD, same as /bin/kill -9 -- -9 -11
kill: -9: No such process
kill: -11: No such process

The above works as expected with the bash builtin and with /usr/bin/kill 
from Debian 12.

-- 
Regards,
Christian

-------------- next part --------------
From 0ce4615d80cd1a5f417511d7988c90cd7cc6ebc7 Mon Sep 17 00:00:00 2001
From: Christian Franke <christian.franke@t-online.de>
Date: Sat, 12 Apr 2025 15:51:53 +0200
Subject: [PATCH] Cygwin: kill(1): fix parsing of negative pid

Signed-off-by: Christian Franke <christian.franke@t-online.de>
---
 winsup/utils/kill.cc | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/winsup/utils/kill.cc b/winsup/utils/kill.cc
index bcabcd47c..1e6ab5c4b 100644
--- a/winsup/utils/kill.cc
+++ b/winsup/utils/kill.cc
@@ -372,7 +372,9 @@ main (int argc, char **argv)
 	case '?':
 	  if (gotasig) /* this is a negative pid, go ahead */
 	    {
-	      --optind;
+	      /* Reset optind because it points to the next argument if and
+		 only if the pid has one digit. */
+	      optind = av - argv;
 	      goto out;
 	    }
 	  optreset = 1;
-- 
2.45.1



More information about the Cygwin-patches mailing list