From 943a69ef2d0a6a5b527fcc1245ad57e1b9b8d77b Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Thu, 2 Nov 2023 16:03:48 +1030 Subject: [PATCH] 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 Signed-off-by: David Sterba --- cmds/subvolume.c | 9 +++++++++ 1 file changed, 9 insertions(+) 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)) {