]> git.ipfire.org Git - thirdparty/util-linux.git/commit
lib/mbsalign: use snprintf() instead of sprintf()
authorKarel Zak <kzak@redhat.com>
Tue, 7 Oct 2025 10:48:41 +0000 (12:48 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 7 Oct 2025 11:46:15 +0000 (13:46 +0200)
commit62f8363caa017741db8e5ced9c0f1e305f61c5ea
treed030061d6f57718b96d457ce4cbc37869a291caa
parentaf2f3f99b90ded1481c80912744cd0a0dfa58d6b
lib/mbsalign: use snprintf() instead of sprintf()

Add bufsiz parameter to mbs_safe_encode_to_buffer() and
mbs_invalid_encode_to_buffer() functions to enable safe buffer
operations. Track remaining buffer size internally using int
variable and convert all sprintf() calls to snprintf().

Add buffer overflow protection by checking snprintf() return
values and verifying sufficient space before memcpy() and
direct writes. Break encoding loop early if buffer space
is exhausted.

This change improves code safety by preventing potential buffer
overflows and makes buffer size limits explicit in the API.

Signed-off-by: Karel Zak <kzak@redhat.com>
include/mbsalign.h
lib/buffer.c
lib/mbsalign.c
libsmartcols/src/print.c