]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lscpu: make lookup_cache() more robust
authorKarel Zak <kzak@redhat.com>
Fri, 24 Jun 2016 09:07:00 +0000 (11:07 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 24 Jun 2016 09:07:00 +0000 (11:07 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/lscpu.c

index 4bd8e872dfc0492ec2d6ad7a9f3185a9f739ff9c..b30b003b16746301b76fa1f8f8b32552499287e8 100644 (file)
@@ -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));