]> git.sesse.net Git - bcachefs-tools-debian/commitdiff
Fix bchu_fs_get_devices()
authorKent Overstreet <kent.overstreet@gmail.com>
Fri, 27 Dec 2019 19:04:16 +0000 (14:04 -0500)
committerKent Overstreet <kent.overstreet@gmail.com>
Fri, 27 Dec 2019 19:04:16 +0000 (14:04 -0500)
libbcachefs.c

index 89c203a15b677dfa2a22d793efcd290f942979cc..8f656a276c1dcf4d5551389ad5ea2e60f88d19da 100644 (file)
@@ -1114,7 +1114,7 @@ dev_names bchu_fs_get_devices(struct bchfs_handle fs)
        darray_init(devs);
 
        while ((errno = 0), (d = readdir(dir))) {
-               struct dev_name n;
+               struct dev_name n = { 0, NULL, NULL };
 
                if (sscanf(d->d_name, "dev-%u", &n.idx) != 1)
                        continue;
@@ -1122,9 +1122,12 @@ dev_names bchu_fs_get_devices(struct bchfs_handle fs)
                char *block_attr = mprintf("dev-%u/block", n.idx);
 
                char sysfs_block_buf[4096];
-               if (readlinkat(fs.sysfs_fd, block_attr,
-                              sysfs_block_buf, sizeof(sysfs_block_buf)) > 0)
+               ssize_t r = readlinkat(fs.sysfs_fd, block_attr,
+                                      sysfs_block_buf, sizeof(sysfs_block_buf));
+               if (r > 0) {
+                       sysfs_block_buf[r] = '\0';
                        n.dev = strdup(basename(sysfs_block_buf));
+               }
 
                free(block_attr);