[PATCH 1/2] cpu: microcode: ensure we don't overflow with strncpy
Colin King
colin.king at canonical.com
Tue Nov 6 16:19:29 UTC 2012
From: Colin Ian King <colin.king at canonical.com>
Signed-off-by: Colin Ian King <colin.king at canonical.com>
---
src/cpu/microcode/microcode.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/cpu/microcode/microcode.c b/src/cpu/microcode/microcode.c
index 50b19e1..7d9a607 100644
--- a/src/cpu/microcode/microcode.c
+++ b/src/cpu/microcode/microcode.c
@@ -75,7 +75,8 @@ static void gather_info(fwts_framework *fw, fwts_list *cpus)
fwts_log_error(fw, "Cannot allocate memory.");
break;
}
- strncpy(cpu->cpu, entry->d_name, 16);
+ strncpy(cpu->cpu, entry->d_name, sizeof(cpu->cpu) - 1);
+ cpu->cpu[sizeof(cpu->cpu) - 1] = '\0';
cpu->version = strtoul(data, NULL, 16);
free(data);
fwts_list_append(cpus, cpu);
--
1.7.10.4
More information about the fwts-devel
mailing list