From 95ed10ff438ee1c850bbd235f1bd98e6113ccfe6 Mon Sep 17 00:00:00 2001 From: Olof Sivertsson Date: Thu, 8 Sep 2016 08:32:43 +0200 Subject: [PATCH] kill: Fix free() with bad pointer on SIG-prefixed signal-name kill -l SIGHUP (or any other signal-name prefixed with "SIG") would cause free() to be called with a bad pointer instead of a pointer to what was allocated. Fix this and add test-case. --- lib/signals.c | 2 +- testsuite/kill.test/kill.exp | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/signals.c b/lib/signals.c index f10ed1e5..a9d0ebb4 100644 --- a/lib/signals.c +++ b/lib/signals.c @@ -263,7 +263,7 @@ char *strtosig(const char *restrict s) } } } - free(p); + free(copy); return converted; } diff --git a/testsuite/kill.test/kill.exp b/testsuite/kill.test/kill.exp index 1668ac4f..211395c9 100644 --- a/testsuite/kill.test/kill.exp +++ b/testsuite/kill.test/kill.exp @@ -24,6 +24,10 @@ set test "kill convert signal name to number" spawn $kill -lHUP expect_pass "$test" "^1\\s*" +set test "kill convert SIG-prefixed signal name to number" +spawn $kill -lSIGHUP +expect_pass "$test" "^1\\s*$" + set test "kill convert signal number to name" spawn $kill -l 1 expect_pass "$test" "^HUP\\s*"