Skip to content

Commit

Permalink
kill: validate pid (#534)
Browse files Browse the repository at this point in the history
* Avoid passing non-numeric pids to kill()
* Printing "Can't kill a non-numeric process ID" is not helpful because kill can accept many pids and the error doesn't indicate which pid is bad
* This was found when testing against the bash-builtin kill
  • Loading branch information
mknos committed Apr 4, 2024
1 parent 09aef9d commit 964afac
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bin/kill
Expand Up @@ -53,6 +53,10 @@ die "$0: No PIDs specified.\n" unless ( @ARGV );

my($ret) = 0;
foreach ( @ARGV ) { # do the kills...
unless (m/\A\-?[0-9]+\Z/) {
warn "$0: failed to parse argument '$_'\n";
exit 1;
}
unless (kill $signal, $_) {
warn "$0: $_: $!\n";
$ret = 1;
Expand Down

0 comments on commit 964afac

Please sign in to comment.