]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lscpu: fix possible buffer overflow in cpuinfo parser
authorKarel Zak <kzak@redhat.com>
Tue, 20 May 2025 08:10:59 +0000 (10:10 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 20 May 2025 08:10:59 +0000 (10:10 +0200)
Addresses: https://github.com/util-linux/util-linux/pull/3577
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/lscpu-cputype.c

index bdb33ac783b961d578911932f40660d83f11e6f5..0626df6a0cdff9582a9fd4c631ce9f213e32e924 100644 (file)
@@ -288,7 +288,7 @@ static const struct cpuinfo_pattern cache_patterns[] =
        DEF_PAT_CACHE("cache",  PAT_CACHE),
 };
 
-#define CPUTYPE_PATTERN_BUFSZ  32
+#define CPUTYPE_PATTERN_BUFSZ  128
 
 static int cmp_pattern(const void *a0, const void *b0)
 {
@@ -462,8 +462,7 @@ static const struct cpuinfo_pattern *cpuinfo_parse_line(char *str, char **value,
                return NULL;
 
        /* prepare name of the field */
-       xstrncpy(buf, p, sizeof(buf));
-       buf[v - p] = '\0';
+       xstrncpy(buf, p, min((size_t)(v - p)+1, sizeof(buf)));
        v++;
 
        /* prepare value */