]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: Simplify blkid_probe_log_csum_mismatch
authorTobias Stoeckmann <tobias@stoeckmann.org>
Wed, 8 Apr 2026 19:39:32 +0000 (21:39 +0200)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Wed, 8 Apr 2026 19:39:32 +0000 (21:39 +0200)
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 <tobias@stoeckmann.org>
libblkid/src/probe.c

index fba7eb1240afb68be5ac5b7808229d9fb6963681..3c59c2c7e8130bd21ebd63e5b5adac0b30978229 100644 (file)
@@ -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));
 }