Skip to contentSkip to conversation

btrfs-progs: cmd-subvolume: set subvol_path to NULL after free

PATCH In review Su Yue 2 participants 2 messages Dec 7, 2020 – Dec 10, 2020 Btrfs file system

lore
Share & tools
lore

Su Yue

author
#0 lore raw

PATCH 1/1 btrfs-progs: cmd-subvolume: set subvol_path to NULL after free

User reported that btrfs subvolume show -u -- /mnt causes double free.

Pointer subovl_path was freed in iterations but still keeps old value. In the last iteration, error BTRFS_UTIL_ERROR_STOP_ITERATION returned, then the double free of subvol_path happens in the out goto label.

Set subvol_path to NULL after each free() in the loop to fix the issue.

Links: https://github.com/kdave/btrfs-progs/issues/317

---
 cmds/subvolume.c | 1 +
 1 file changed, 1 insertion(+)
cmds/subvolume.c +1 -0
index f153cfa9..a6771d10 100644
@@ -1117,6 +1117,7 @@ static int cmd_subvol_show(const struct cmd_struct *cmd, int argc, char **argv)
 				break;
 
 			free(subvol_path);
+			subvol_path = NULL;
 		}
 		btrfs_util_destroy_subvolume_iterator(iter);
 	} else {
Signature · 1 line
2.29.2
#1 lore raw
Quoted 11 lines · Su Yue

User reported that btrfs subvolume show -u -- /mnt causes double free.

Pointer subovl_path was freed in iterations but still keeps old value. In the last iteration, error BTRFS_UTIL_ERROR_STOP_ITERATION returned, then the double free of subvol_path happens in the out goto label.

Set subvol_path to NULL after each free() in the loop to fix the issue.

Links: https://github.com/kdave/btrfs-progs/issues/317

Thanks, added to devel.