Subject: kill builtin argument parsing
From: Matthew Malcomson <[email-masked]>
To: [email-masked]
Date: Sun, 5 Jun 2016 17:35:54 +0100
List-Id: Zsh Workers List <zsh-workers.zsh.org>

Hello there,

I recently mistakenly used arguments for the /bin/kill binary with the 
zsh kill builtin and noticed something strange that I think should be 
improved.

The command line I used was:
kill -1 -- <any pid>
which ends up killing the current Zsh process.

This is because the pid valid argument check at Src/builtin.c:2572 uses 
isanum() that just asserts that all characters in the string are either 
'-' or a digit.
When the string "--" is parsed as a digit with atoi() in Src/jobs.c:2572 
it returns '0' which is passed to kill(2) syscall.

I'm not sure whether to suggest changing the isanum() function, or the 
check in bin_kill() that relies on it.
I would personally change the isanum() function, as a cursory reading of 
the two places it's used appear to not require this particular behaviour 
(the other place it's used in Src/jobs.c:2193 doesn't appear to have any 
negative consequences either way), but the comment above this isanum() 
function clearly shows it was a known behaviour, so there may be a 
reason I'm missing.

Either way I think the behaviour is surprising enough and possible 
enough to be worth changing.

Cheers

MM