]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/sysfs: zero-terminate result of sysfs_blkdev_get_devchain()
authorThomas Weißschuh <thomas@t-8ch.de>
Wed, 12 Jun 2024 21:32:15 +0000 (23:32 +0200)
committerThomas Weißschuh <thomas@t-8ch.de>
Thu, 13 Jun 2024 09:46:03 +0000 (11:46 +0200)
sysfs_blkdev_get_devchain() does not zero-terminate its result, but the
caller expects a C-string.
Use ul_buffer_get_string() which includes a trailing zero-byte.

Now it's also valid for sz and bufsz to be equal.

See #3088.
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
lib/sysfs.c

index e7294e6b1aa457552ba82bb84251ed38b93a3bb2..ac9c5c3bf324b5ec3e29ba8d07af96c400ec16b9 100644 (file)
@@ -404,8 +404,8 @@ char *sysfs_blkdev_get_devchain(struct path_cxt *pc, char *buf, size_t bufsz)
        ul_buffer_append_string(&tmp, _PATH_SYS_DEVBLOCK "/");
        ul_buffer_append_data(&tmp, buf, ssz);
 
-       p = ul_buffer_get_data(&tmp, &sz, NULL);
-       if (p && sz < bufsz) {
+       p = ul_buffer_get_string(&tmp, &sz, NULL);
+       if (p && sz <= bufsz) {
                memcpy(buf, p, sz);
                res = buf;
        }