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.
This commit is contained in:
Olof Sivertsson 2016-09-08 08:32:43 +02:00 committed by Craig Small
parent e02d9f554d
commit 95ed10ff43
2 changed files with 5 additions and 1 deletions

View File

@ -263,7 +263,7 @@ char *strtosig(const char *restrict s)
}
}
}
free(p);
free(copy);
return converted;
}

View File

@ -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*"