Message ID | 8c3df11d55b5add76a6abfd7896762697520a136.1698903010.git.wqu@suse.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | btrfs-progs: subvolume create: accept multiple arguments | expand |
On Thu, Nov 02, 2023 at 04:03:48PM +1030, Qu Wenruo wrote: > 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> > --- > cmds/subvolume.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/cmds/subvolume.c b/cmds/subvolume.c > index 8504c380c9ee..bccc4968dad3 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("out of memory when duplicating %s", dst); There are message templats for the most common errors, so this is now error_msg(ERROR_MSG_MEMORY, "duplicating %s", dst);
diff --git a/cmds/subvolume.c b/cmds/subvolume.c index 8504c380c9ee..bccc4968dad3 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("out of memory when duplicating %s", dst); + goto out; + } newname = basename(dupname); + dupdir = strdup(dst); + if (!dupdir) { + error("out of memory when duplicating %s", dst); + goto out; + } dstdir = dirname(dupdir); if (!test_issubvolname(newname)) {
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> --- cmds/subvolume.c | 9 +++++++++ 1 file changed, 9 insertions(+)