From: Karel Zak Date: Fri, 24 Jun 2016 09:07:00 +0000 (+0200) Subject: lscpu: make lookup_cache() more robust X-Git-Tag: v2.29-rc1~173 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=81a307bd4d906815dad7b6b3c355f663907a68c4;p=thirdparty%2Futil-linux.git lscpu: make lookup_cache() more robust Signed-off-by: Karel Zak --- diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c index 4bd8e872df..b30b003b16 100644 --- a/sys-utils/lscpu.c +++ b/sys-utils/lscpu.c @@ -438,15 +438,20 @@ lookup_cache(char *line, struct lscpu_desc *desc) if (!p || strncmp(p, "Private", 7) == 0) return 0; p = strstr(line, "level="); - sscanf(p, "level=%d", &level); + if (!p || sscanf(p, "level=%d", &level) != 1) + return 0; p = strstr(line, "type=") + 5; + if (!p || !*p) + return 0; type = 0; if (strncmp(p, "Data", 4) == 0) type = 'd'; if (strncmp(p, "Instruction", 11) == 0) type = 'i'; p = strstr(line, "size="); - sscanf(p, "size=%lld", &size); + if (!p || sscanf(p, "size=%lld", &size) != 1) + return 0; + desc->necaches++; desc->ecaches = xrealloc(desc->ecaches, desc->necaches * sizeof(struct cpu_cache));