From 50b343e06867169c0b1548deb75fbd36003dcdaf Mon Sep 17 00:00:00 2001 From: Qualys Security Advisory Date: Thu, 1 Jan 1970 00:00:00 +0000 Subject: [PATCH] 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 d2df396ba9bff2180af1233f65ca68342c35fed0 Signed-off-by: Jim Warner --- lib/signals.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/signals.c b/lib/signals.c index 6d9cc559..6074d6a3 100644 --- a/lib/signals.c +++ b/lib/signals.c @@ -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; } }