Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Su Yue <l@damenly.su>
To: linux-btrfs@vger.kernel.org
Cc: l@damenly.su
Subject: [PATCH] btrfs-progs: cmd-subvolume: set subvol_path to NULL after free
Date: Mon,  7 Dec 2020 17:07:55 +0800	[thread overview]
Message-ID: <20201207090755.16161-1-l@damenly.su> (raw)

User reported that `btrfs subvolume show -u -- /mnt` causes double free.


Pointer subovl_path was freed in iterations but still keeps old value.
In the last iteration, error BTRFS_UTIL_ERROR_STOP_ITERATION returned,
then the double free of subvol_path happens in the out goto label.

Set subvol_path to NULL after each free() in the loop to fix the issue.

Links: https://github.com/kdave/btrfs-progs/issues/317
Signed-off-by: Su Yue <l@damenly.su>
---
 cmds/subvolume.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/cmds/subvolume.c b/cmds/subvolume.c
index f153cfa9..a6771d10 100644
--- a/cmds/subvolume.c
+++ b/cmds/subvolume.c
@@ -1117,6 +1117,7 @@ static int cmd_subvol_show(const struct cmd_struct *cmd, int argc, char **argv)
 				break;
 
 			free(subvol_path);
+			subvol_path = NULL;
 		}
 		btrfs_util_destroy_subvolume_iterator(iter);
 	} else {
-- 
2.29.2


             reply	other threads:[~2020-12-07  9:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-07  9:07 Su Yue [this message]
2020-12-10 16:13 ` [PATCH] btrfs-progs: cmd-subvolume: set subvol_path to NULL after free David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201207090755.16161-1-l@damenly.su \
    --to=l@damenly.su \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox