Skip to content

Commit 70a3d7d

Browse files
committed
btrfs-progs: handle allocation errors in cmd_subvolume_list()
Handle potential allocation errors of the filtering and sorting helper structures (they have to be initialized before the option parsing). Also drop conditional free() (reported by CodeQL scan). Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 8e3fc85 commit 70a3d7d

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

cmds/subvolume-list.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,8 +1579,8 @@ static struct btrfs_list_comparer_set *btrfs_list_alloc_comparer_set(void)
15791579

15801580
static int cmd_subvolume_list(const struct cmd_struct *cmd, int argc, char **argv)
15811581
{
1582-
struct btrfs_list_filter_set *filter_set;
1583-
struct btrfs_list_comparer_set *comparer_set;
1582+
struct btrfs_list_filter_set *filter_set = NULL;
1583+
struct btrfs_list_comparer_set *comparer_set = NULL;
15841584
u64 flags = 0;
15851585
int fd = -1;
15861586
u64 top_id;
@@ -1591,7 +1591,15 @@ static int cmd_subvolume_list(const struct cmd_struct *cmd, int argc, char **arg
15911591
enum btrfs_list_layout layout = BTRFS_LIST_LAYOUT_DEFAULT;
15921592

15931593
filter_set = btrfs_list_alloc_filter_set();
1594+
if (!filter_set) {
1595+
error_msg(ERROR_MSG_MEMORY, "allocating filter set");
1596+
return 1;
1597+
}
15941598
comparer_set = btrfs_list_alloc_comparer_set();
1599+
if (!comparer_set) {
1600+
error_msg(ERROR_MSG_MEMORY, "allocating comparator set");
1601+
return 1;
1602+
}
15951603

15961604
optind = 0;
15971605
while(1) {
@@ -1730,10 +1738,8 @@ static int cmd_subvolume_list(const struct cmd_struct *cmd, int argc, char **arg
17301738

17311739
out:
17321740
close(fd);
1733-
if (filter_set)
1734-
free(filter_set);
1735-
if (comparer_set)
1736-
free(comparer_set);
1741+
free(filter_set);
1742+
free(comparer_set);
17371743
if (uerr)
17381744
usage(cmd, 1);
17391745
return !!ret;

0 commit comments

Comments
 (0)