From 586bfb765595d3076e0907f4561c832fdc798e21 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. --- proc/sig.c | 2 +- testsuite/kill.test/kill.exp | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/proc/sig.c b/proc/sig.c index 2191cda5..a93aabb9 100644 --- a/proc/sig.c +++ b/proc/sig.c @@ -261,7 +261,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*"