]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
findmnt: always zero-terminate SOURCES data
authorThomas Weißschuh <thomas@t-8ch.de>
Sun, 21 Apr 2024 18:00:31 +0000 (20:00 +0200)
committerThomas Weißschuh <thomas@t-8ch.de>
Sun, 21 Apr 2024 18:00:31 +0000 (20:00 +0200)
libsmartcols expects it's data fields to be zero terminated.
See the call to strlen() in scols_column_greatest_wrap().
ul_buffer however does not guarantee that termination,
ul_buffer_append_strings() discard the zero-termination.

Always zero-terminate in get_data_col_sources() and drop the now
unnecessary variable "i".

Closes: https://github.com/util-linux/util-linux/issues/2980
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
misc-utils/findmnt.c

index 2e4d59ecc0c78f87bb0e48d6fe10760613acd392..f40b13726a7178ed7435515d37413aba2b698ed5 100644 (file)
@@ -552,7 +552,6 @@ static char *get_vfs_attr(struct libmnt_fs *fs, int sizetype)
 static char *get_data_col_sources(struct libmnt_fs *fs, int evaluate, size_t *datasiz)
 {
        const char *tag = NULL, *p = NULL;
-       int i = 0;
        const char *device = NULL;
        char *val = NULL;
        blkid_dev_iterate iter;
@@ -602,10 +601,8 @@ static char *get_data_col_sources(struct libmnt_fs *fs, int evaluate, size_t *da
                dev = blkid_verify(blk_cache, dev);
                if (!dev)
                        continue;
-               if (i != 0)
-                       ul_buffer_append_data(&buf, "\0", 1);
                ul_buffer_append_string(&buf, blkid_dev_devname(dev));
-               i++;
+               ul_buffer_append_data(&buf, "\0", 1);
        }
        blkid_dev_iterate_end(iter);
        free(val);