zsh-workers
 help / color / mirror / code / Atom feed
* kill builtin argument parsing
@ 2016-06-05 16:35 Matthew Malcomson
  2016-06-06  0:31 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Matthew Malcomson @ 2016-06-05 16:35 UTC (permalink / raw)
  To: zsh-workers

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-06-06  0:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-05 16:35 kill builtin argument parsing Matthew Malcomson
2016-06-06  0:31 ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).