From a3975a9c6098218decf2d79b01c7a70512eded9e Mon Sep 17 00:00:00 2001 From: Filipe Brandenburger Date: Thu, 4 Jun 2015 22:33:02 -0700 Subject: [PATCH] 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 Ported-by: Jim Warner From original: commit 9646f7cba47e078855d1fc5e3be9fb05b1b89629 --- pgrep.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/pgrep.c b/pgrep.c index e1a7c831..ed2f02c0 100644 --- a/pgrep.c +++ b/pgrep.c @@ -609,8 +609,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));