]> git.ipfire.org Git - thirdparty/linux.git/commit
tools lib api: Fix filename__write_int() writing uninitialized stack data
authorArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 8 Jun 2026 10:05:19 +0000 (07:05 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 10 Jun 2026 21:56:01 +0000 (18:56 -0300)
commit438ece06185696e14c63c6113d5e2d34ec0a9680
treee114353fc9b1ddd9780270fc68180063cbe0bbfb
parent2ea64782a428bed74f595961e651ceb8c4c5bf22
tools lib api: Fix filename__write_int() writing uninitialized stack data

filename__write_int() formats an integer into a 64-byte buffer with
sprintf() then passes sizeof(buf) (64) as the write length.  This
writes all 64 bytes including uninitialized stack data past the
formatted string.  Most sysfs files reject the oversized write,
making the function always return -1.

Fix by capturing the sprintf() return value and using it as the
write length.

Reported-by: sashiko-bot <sashiko-bot@kernel.org>
Fixes: 3b00ea938653d136 ("tools lib api fs: Add sysfs__write_int function")
Cc: Kan Liang <kan.liang@intel.com>
Assisted-by: Claude:claude-opus-4.6
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/lib/api/fs/fs.c