zsh-workers
 help / color / mirror / code / Atom feed
From: Matthew Malcomson <hardenedapple@gmail.com>
To: zsh-workers@zsh.org
Subject: kill builtin argument parsing
Date: Sun, 5 Jun 2016 17:35:54 +0100	[thread overview]
Message-ID: <e065be41-429a-d39e-2db1-791e97f8f49a@gmail.com> (raw)

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


             reply	other threads:[~2016-06-05 16:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-05 16:35 Matthew Malcomson [this message]
2016-06-06  0:31 ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e065be41-429a-d39e-2db1-791e97f8f49a@gmail.com \
    --to=hardenedapple@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).