aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQu Wenruo <wqu@suse.com>2023-11-02 16:03:48 +1030
committerDavid Sterba <dsterba@suse.com>2023-11-23 20:11:17 +0100
commit943a69ef2d0a6a5b527fcc1245ad57e1b9b8d77b (patch)
treef22bb9d4400bc7f223cacee020e8fe8b75b68d51
parent69a3871fdd223612f554b8d7eeebddae3fc67ace (diff)
downloadbtrfs-progs-943a69ef2d0a6a5b527fcc1245ad57e1b9b8d77b.tar.gz
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>
-rw-r--r--cmds/subvolume.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/cmds/subvolume.c b/cmds/subvolume.c
index 8504c380..7e45b48e 100644
--- a/cmds/subvolume.c
+++ b/cmds/subvolume.c
@@ -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)) {