From oleg@core.zp.ua  Sun Jul  7 01:26:03 2002
Return-Path: <oleg@core.zp.ua>
Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 1837F37B400
	for <FreeBSD-gnats-submit@freebsd.org>; Sun,  7 Jul 2002 01:26:03 -0700 (PDT)
Received: from core.zp.ua (core.zp.ua [193.108.112.7])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 9E6FB43E52
	for <FreeBSD-gnats-submit@freebsd.org>; Sun,  7 Jul 2002 01:26:00 -0700 (PDT)
	(envelope-from oleg@core.zp.ua)
Received: from core.zp.ua (oleg@localhost [127.0.0.1])
	by core.zp.ua with ESMTP id g678PuUY041339
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 7 Jul 2002 11:25:56 +0300 (EEST)
	(envelope-from oleg@core.zp.ua)
Received: (from oleg@localhost)
	by core.zp.ua  id g678PuYG041338;
	 Sun, 7 Jul 2002 11:25:56 +0300 (EEST)
Message-Id: <200207070825.g678PuYG041338@core.zp.ua>
Date: Sun, 7 Jul 2002 11:25:56 +0300 (EEST)
From: "Oleg V. Naumann" <oleg@reis.zp.ua>
Reply-To: "Oleg V. Naumann" <oleg@reis.zp.ua>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: /bin/kill has bad error checking for command line parameters
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         40282
>Category:       bin
>Synopsis:       [patch] kill(1) has bad error checking for command line parameters
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    jilles
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Jul 07 01:30:04 PDT 2002
>Closed-Date:    Thu Jul 29 21:07:31 UTC 2010
>Last-Modified:  Thu Jul 29 21:07:31 UTC 2010
>Originator:     Oleg V. Naumann
>Release:        FreeBSD 4.6-STABLE i386
>Organization:
ReIS Ltd.
>Environment:
System: FreeBSD core.zp.ua 4.6-STABLE FreeBSD 4.6-STABLE #1: Sat Jun 29 10:41:35 EEST 2002 root@core.zp.ua:/usr/obj/usr/src/sys/core i386

>Description:
	Some time ago I typed
	kill _HUP 1 
	under 'sh' shell after editing /etc/ttys
	Yes, this was a typo...
	Heh... oops... I'm in a single user mode without any warnings...
	This problem exist under sh/bash shells, because [t]csh has
	builtin 'kill' command, which seems doesn't have this problem:
	[root@core]~# set | grep shell
	shell   /bin/tcsh
	[root@core]~# kill _HUP 1
	kill: Arguments should be jobs or process id's.
	[root@core]~# which kill
	kill: shell built-in command.
	But sh/bash uses external /bin/kill:
	[root@core]~# sh
	# which kill
	/bin/kill
	# bash
	bash-2.05# which kill
	/bin/kill
	
>How-To-Repeat:
	kill _HUP 1 under 'sh' or 'bash' shells 
	(Please DO NOT on any production server!)
>Fix:
--- /usr/src/bin/kill/kill.c	Wed Sep 26 09:54:28 2001
+++ kill.c	Tue Jan 15 23:57:16 2002
@@ -125,7 +126,7 @@
 	if (argc == 0)
 		usage();
 
-	for (errors = 0; argc; argc--, argv++) {
+	for (errors = 0; (argc && (errors == 0)); argc--, argv++) {
 		pid = strtol(*argv, &ep, 10);
 		if (!**argv || *ep) {
 			warnx("illegal process id: %s", *argv);


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->tjr 
Responsible-Changed-By: tjr 
Responsible-Changed-When: Sun Jul 7 05:07:27 PDT 2002 
Responsible-Changed-Why:  
I'll look into this one. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=40282 
Responsible-Changed-From-To: tjr->freebsd-bugs 
Responsible-Changed-By: tjr 
Responsible-Changed-When: Sat Jul 13 00:38:35 PDT 2002 
Responsible-Changed-Why:  
I would rather not change the historical behaviour, but perhaps somebody 
else will. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=40282 
State-Changed-From-To: open->analyzed 
State-Changed-By: rwatson 
State-Changed-When: Fri Jan 25 17:24:00 UTC 2008 
State-Changed-Why:  
If we want to make a change along these lines, we should change from 
warnx() to errx(EX_USAGE, ...) rather than changing the loop logic. 
Does the csh/tcsh kill validate all arguments before starting the 
killing (so to speak), or does it abort when it hits the first bad 
one (as this patch suggests)? 


http://www.freebsd.org/cgi/query-pr.cgi?pr=40282 

From: Jilles Tjoelker <jilles@stack.nl>
To: bug-followup@FreeBSD.org, oleg@reis.zp.ua
Cc:  
Subject: Re: bin/40282: [patch] kill(1) has bad error checking for command
	line parameters
Date: Sat, 7 Nov 2009 16:21:46 +0100

 I think the idea of aborting on syntax errors makes sense, but aborting
 on a kill(2) error seems to go too far. I have found various shells
 (tcsh, real ksh) that stop processing a kill builtin if they encounter
 an invalid pid (if there were any previous valid pids, signals will have
 been sent), but have not found any that stop processing if a kill(2)
 returns an error.
 
 By the way, do not imply anything about command behaviour from
 /usr/bin/which. sh(1) and bash(1) do not have a which(1) builtin, so
 /usr/bin/which will be used, which does not know about shell builtins.
 It just happens to be the case that sh(1) does not have a kill builtin
 (although that may change in the future) and bash's kill builtin handles
 errors the same way as our /bin/kill. You can use 'type' for accurate
 information in these shells.
 
 -- 
 Jilles Tjoelker

From: Jilles Tjoelker <jilles@stack.nl>
To: bug-followup@FreeBSD.org, oleg@reis.zp.ua
Cc:  
Subject: Re: bin/40282: [patch] kill(1) has bad error checking for command
	line parameters
Date: Sun, 8 Nov 2009 18:10:31 +0100

 --W/nzBZO5zC0uMSeA
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 So I suggest this patch (EX_USAGE vs 1 can be changed separately).
 
 -- 
 Jilles Tjoelker
 
 --W/nzBZO5zC0uMSeA
 Content-Type: text/x-diff; charset=us-ascii
 Content-Disposition: attachment; filename="kill-stop-on-synerror.patch"
 
 Index: bin/kill/kill.c
 ===================================================================
 --- bin/kill/kill.c	(revision 198703)
 +++ bin/kill/kill.c	(working copy)
 @@ -123,10 +123,9 @@
  
  	for (errors = 0; argc; argc--, argv++) {
  		pid = strtol(*argv, &ep, 10);
 -		if (!**argv || *ep) {
 -			warnx("illegal process id: %s", *argv);
 -			errors = 1;
 -		} else if (kill(pid, numsig) == -1) {
 +		if (!**argv || *ep)
 +			errx(1, "illegal process id: %s", *argv);
 +		else if (kill(pid, numsig) == -1) {
  			warn("%s", *argv);
  			errors = 1;
  		}
 
 --W/nzBZO5zC0uMSeA--

From: "Oleg V. Nauman" <oleg@reis.zp.ua>
To: Jilles Tjoelker <jilles@stack.nl>
Cc: bug-followup@freebsd.org, oleg@reis.zp.ua
Subject: Re: bin/40282: [patch] kill(1) has bad error checking for command line parameters
Date: Tue, 1 Dec 2009 18:14:29 +0200

  Hello Jilles,
 
 Thank you for looking into this.
 
 Your patch is fine, but it raises the next questions: do we really want to 
 keep historical kill(1) behavior regarding processing on the rest of list of 
 PIDs when an error occurs? Both of proposed patches ( mine and you ) just 
 break this historical behavior. Well I think that breaking the ( bad ) things 
 is the fine thing. Please commit your patch. 
 
  Thank you.
 
 On Sunday 08 November 2009 19:10:31 you wrote:
 > So I suggest this patch (EX_USAGE vs 1 can be changed separately).
 > 
 > -- 
 > Jilles Tjoelker
 > 
 > Index: bin/kill/kill.c
 > ===================================================================
 > --- bin/kill/kill.c     (revision 198703)
 > +++ bin/kill/kill.c     (working copy)
 > @@ -123,10 +123,9 @@
 > 
 >         for (errors = 0; argc; argc--, argv++) {
 >                 pid = strtol(*argv, &ep, 10);
 > -               if (!**argv || *ep) {
 > -                       warnx("illegal process id: %s", *argv);
 > -                       errors = 1;
 > -               } else if (kill(pid, numsig) == -1) {
 > +               if (!**argv || *ep)
 > +                       errx(1, "illegal process id: %s", *argv);
 > +               else if (kill(pid, numsig) == -1) {
 >                         warn("%s", *argv);
 >                         errors = 1;
 >                 }
 > 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/40282: commit references a PR
Date: Thu, 29 Jul 2010 16:40:55 +0000 (UTC)

 Author: jilles
 Date: Thu Jul 29 16:40:45 2010
 New Revision: 210613
 URL: http://svn.freebsd.org/changeset/base/210613
 
 Log:
   kill: Stop processing if a syntactically invalid pid is encountered.
   
   So a command like
     kill _HUP 1
   now fails without sending SIGTERM to init.
   
   The behaviour when kill(2) fails remains unchanged: processing continues.
   This matches other implementations and POSIX and is useful for killing
   multiple processes at once when some of them may already be gone.
   
   PR:		bin/40282
 
 Modified:
   head/bin/kill/kill.c
 
 Modified: head/bin/kill/kill.c
 ==============================================================================
 --- head/bin/kill/kill.c	Thu Jul 29 16:30:27 2010	(r210612)
 +++ head/bin/kill/kill.c	Thu Jul 29 16:40:45 2010	(r210613)
 @@ -123,10 +123,9 @@ main(int argc, char *argv[])
  
  	for (errors = 0; argc; argc--, argv++) {
  		pid = strtol(*argv, &ep, 10);
 -		if (!**argv || *ep) {
 -			warnx("illegal process id: %s", *argv);
 -			errors = 1;
 -		} else if (kill(pid, numsig) == -1) {
 +		if (!**argv || *ep)
 +			errx(1, "illegal process id: %s", *argv);
 +		else if (kill(pid, numsig) == -1) {
  			warn("%s", *argv);
  			errors = 1;
  		}
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: analyzed->closed 
State-Changed-By: jilles 
State-Changed-When: Thu Jul 29 21:06:59 UTC 2010 
State-Changed-Why:  
Fixed in 9-current, no MFC planned. 


Responsible-Changed-From-To: freebsd-bugs->jilles 
Responsible-Changed-By: jilles 
Responsible-Changed-When: Thu Jul 29 21:06:59 UTC 2010 
Responsible-Changed-Why:  
Take. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=40282 
>Unformatted:
