]> granicus.if.org Git - procps-ng/commitdiff
pkill: reject -signal number with trailing garbage
authorFilipe Brandenburger <filbranden@google.com>
Fri, 5 Jun 2015 05:33:02 +0000 (22:33 -0700)
committerFilipe Brandenburger <filbranden@google.com>
Tue, 7 Jul 2015 17:39:49 +0000 (10:39 -0700)
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>
pgrep.c

diff --git a/pgrep.c b/pgrep.c
index 9a61e6d581a0e327878a943e6f1b0b30afddd263..539a2d841b8412045b74f9e3f385a1f33cb1bfbf 100644 (file)
--- a/pgrep.c
+++ b/pgrep.c
@@ -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));