btrfs-progs: subvolume create: handle failure for strdup()

The function strdup() can return NULL if the system is out of memory,
thus we need to hanle the rare but possible -ENOMEM case.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Qu Wenruo 2023-11-02 16:03:48 +10:30 committed by David Sterba
parent 69a3871fdd
commit 943a69ef2d
1 changed files with 9 additions and 0 deletions

View File

@ -194,8 +194,17 @@ static int cmd_subvolume_create(const struct cmd_struct *cmd, int argc, char **a
}
dupname = strdup(dst);
if (!dupname) {
error_msg(ERROR_MSG_MEMORY, "duplicating %s", dst);
goto out;
}
newname = basename(dupname);
dupdir = strdup(dst);
if (!dupdir) {
error_msg(ERROR_MSG_MEMORY, "duplicating %s", dst);
goto out;
}
dstdir = dirname(dupdir);
if (!test_issubvolname(newname)) {