0032-proc/sig.c: Fix the strtosig() function.

Do not memleak "copy" in case of an error.

Do not use "sizeof(converted)" in snprintf(), since "converted" is a
"char *" (luckily, 8 >= sizeof(char *)). Also, remove "sizeof(char)"
which is guaranteed to be 1 by the C standard, and replace 8 with 12,
which is enough to hold any stringified int and does not consume more
memory (in both cases, the glibc malloc()ates a minimum-sized chunk).

---------------------------- adapted for newlib branch
. no longer in library, logic  now found in lib/signals.c
. craig already addressed "copy" memleak in commit beloww

Reference(s):
commit d2df396ba9

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Qualys Security Advisory 1970-01-01 00:00:00 +00:00 committed by Craig Small
parent ef03c89447
commit 50b343e068

View File

@ -278,11 +278,9 @@ char *strtosig(const char *restrict s)
} else {
for (i = 0; i < number_of_signals; i++){
if (strcmp(p, get_sigtable_name(i)) == 0){
converted = malloc(sizeof(char) * 8);
converted = malloc(12);
if (converted)
snprintf(converted,
sizeof(converted) - 1,
"%d", get_sigtable_num(i));
snprintf(converted, 12, "%d", sigtable[i].num);
break;
}
}