From 44d3ee3e1f94acf71d52016f771988196955c259 Mon Sep 17 00:00:00 2001 From: Satoru Takeuchi Date: Thu, 18 Dec 2014 16:39:26 +0900 Subject: btrfs-progs fix wrong memory free on check_is_root When "/" is Btrfs, "btrfs property /" regards it as non-root by mistake. check_is_root() regards @object as a file system root if the following two conditions are satisfied. a) Both @object and its parent directory are Btrfs object (file system root, subvolume, inode, and device used for Btrfs). b) fsid of the above mentioned two objects are different. It doesn't work if @object is "/" because, in this case, fsid of "/" and its parent (it's also "/"), are the same. * Test environment Two Btrfs file system (not subvolume) "/" and "/home/sat/mnt". * How to reproduce Submit "btrfs prop get" against the above mentioned file systems. * Test Result ** Actual result (without my patch) ========================== ro=false label= # label is displayed because it's a file system root ro=false # label is not displayed even if it's a file system root ========================== ** Expected result (with my patch) ========================== ro=false label= ro=false label=foo # label is displayed =========================== Signed-off-by: Satoru Takeuchi Reported-by: Naohiro Aota Reviewed-by: Gui Hecheng Signed-off-by: David Sterba --- cmds-property.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'cmds-property.c') diff --git a/cmds-property.c b/cmds-property.c index a7642933..6501338e 100644 --- a/cmds-property.c +++ b/cmds-property.c @@ -124,7 +124,18 @@ static int check_is_root(const char *object) int ret; u8 fsid[BTRFS_FSID_SIZE]; u8 fsid2[BTRFS_FSID_SIZE]; - char *tmp; + char *tmp = NULL; + char *rp; + + rp = realpath(object, NULL); + if (!rp) { + ret = -errno; + goto out; + } + if (!strcmp(rp, "/")) { + ret = 0; + goto out; + } tmp = malloc(strlen(object) + 5); if (!tmp) { @@ -165,6 +176,7 @@ static int check_is_root(const char *object) out: free(tmp); + free(rp); return ret; } -- cgit v1.2.3