]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
tools lib api: Fix missing null termination in filename__read_int/ull()
authorArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 8 Jun 2026 00:03:55 +0000 (21:03 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 10 Jun 2026 21:56:01 +0000 (18:56 -0300)
commit52b1f9678499b13b7aeb0186d9c6f486c043283f
tree1a15e434e86799deabb08ec36c8a3ee63fe571ac
parent33035f7dd4e49f3f117e70c5e36c8c1ae88d37f2
tools lib api: Fix missing null termination in filename__read_int/ull()

filename__read_int() passes a stack buffer to read() using the full
sizeof(line) and then hands it to atoi() without null-terminating.
If a sysfs file fills the 64-byte buffer exactly, atoi() reads past
the array into uninitialized stack memory.

filename__read_ull_base() has the same issue with strtoull().

Fix both by reading sizeof(line) - 1 bytes and explicitly
null-terminating after a successful read.

Fixes: 3a351127cbc682c3 ("tools lib fs: Adopt filename__read_int from tools/perf/")
Reported-by: sashiko-bot <sashiko-bot@kernel.org>
Assisted-by: Claude:claude-opus-4.6
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/lib/api/fs/fs.c