From: Karel Zak Date: Tue, 20 May 2025 08:10:59 +0000 (+0200) Subject: lscpu: fix possible buffer overflow in cpuinfo parser X-Git-Tag: v2.41.1~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=637501ad1b1b04012d4f8cd3c67426f9d0f84e72;p=thirdparty%2Futil-linux.git lscpu: fix possible buffer overflow in cpuinfo parser Addresses: https://github.com/util-linux/util-linux/pull/3577 Signed-off-by: Karel Zak (cherry picked from commit ea04d719352add738251446315cebdada90171a9) --- diff --git a/sys-utils/lscpu-cputype.c b/sys-utils/lscpu-cputype.c index 33be33431..9bb4ff79e 100644 --- a/sys-utils/lscpu-cputype.c +++ b/sys-utils/lscpu-cputype.c @@ -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 */