]> 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>
Thu, 19 Jun 2025 08:23:06 +0000 (10:23 +0200)
Addresses: https://github.com/util-linux/util-linux/pull/3577
Signed-off-by: Karel Zak <kzak@redhat.com>
(cherry picked from commit ea04d719352add738251446315cebdada90171a9)

sys-utils/lscpu-cputype.c

index 33be3343172271b599f40dfc2926a488aec84444..9bb4ff79e53e6a398c10812efe076e4d9e337cc1 100644 (file)
@@ -287,7 +287,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)
 {
@@ -461,8 +461,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 */