From: Tobias Stoeckmann Date: Wed, 8 Apr 2026 19:39:32 +0000 (+0200) Subject: libblkid: Simplify blkid_probe_log_csum_mismatch X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=70f31d4e6fc6b93324a5efa7647fdf82cd2e64ab;p=thirdparty%2Futil-linux.git libblkid: Simplify blkid_probe_log_csum_mismatch The function blkid_probe_log_csum_mismatch is only used for debugging purposes. Simplify the code to avoid any form of modifier for %s. Right now, %*s is incorrect because it specifies the field width, not the precision. This could theoretically lead to issues, but since this function is always called with sizes of 8 or 32, it is safe. Just make sure that the strings are always NUL-terminated, even if size is 0 or larger than 256. Signed-off-by: Tobias Stoeckmann --- diff --git a/libblkid/src/probe.c b/libblkid/src/probe.c index fba7eb124..3c59c2c7e 100644 --- a/libblkid/src/probe.c +++ b/libblkid/src/probe.c @@ -2020,9 +2020,9 @@ int blkid_probe_set_magic(blkid_probe pr, uint64_t offset, static void blkid_probe_log_csum_mismatch(blkid_probe pr, size_t n, const void *csum, const void *expected) { - char csum_hex[256]; - char expected_hex[sizeof(csum_hex)]; - int hex_size = min(sizeof(csum_hex), n * 2); + char csum_hex[256 + 1] = ""; + char expected_hex[sizeof(csum_hex)] = ""; + int hex_size = min(sizeof(csum_hex) - 1, n * 2); for (int i = 0; i < hex_size; i+=2) { snprintf(&csum_hex[i], sizeof(csum_hex) - i, "%02X", ((const unsigned char *) csum)[i / 2]); @@ -2031,9 +2031,9 @@ static void blkid_probe_log_csum_mismatch(blkid_probe pr, size_t n, const void * DBG(LOWPROBE, ul_debug( "incorrect checksum for type %s," - " got %*s, expected %*s", + " got %s, expected %s", blkid_probe_get_probername(pr), - hex_size, csum_hex, hex_size, expected_hex)); + csum_hex, expected_hex)); }