pkill: reject -signal number with trailing garbage

This commit prevents pkill from accepting something like `-1garbage` as
a SIGHUP. The previous code was using atoi() which does not check for
trailing garbage and would parse the above as 1.

Handling numeric signals in signal_option() is not really necessary,
since signal_name_to_number() will recognize numeric signals and parse
them properly using strtol() and checking for trailing garbage. It also
checks that the numeric signals are in the proper range. So all we need
to do is remove the buggy numeric signal handling here.

Tested with `pkill -1garbage sleep`, after this patch it will complain
that "1" is not a valid option, which is the expected.

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
This commit is contained in:
Filipe Brandenburger 2015-06-04 22:33:02 -07:00
parent 27b2937d2d
commit 9646f7cba4

View File

@ -661,8 +661,6 @@ static int signal_option(int *argc, char **argv)
for (i = 1; i < *argc; i++) {
if (argv[i][0] == '-') {
sig = signal_name_to_number(argv[i] + 1);
if (sig == -1 && isdigit(argv[i][1]))
sig = atoi(argv[i] + 1);
if (-1 < sig) {
memmove(argv + i, argv + i + 1,
sizeof(char *) * (*argc - i));