summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSatoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>2014-12-18 16:39:26 +0900
committerDavid Sterba <dsterba@suse.cz>2014-12-22 18:34:23 +0100
commit44d3ee3e1f94acf71d52016f771988196955c259 (patch)
treec7a1ebee4660dc1c412b0d4b1524a377c7f91831
parentfb7ddc498f4ddb63836e5b0e419f33fe6ce1cae6 (diff)
btrfs-progs fix wrong memory free on check_is_root
When "/" is Btrfs, "btrfs property <subcommand> /" 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 <takeuchi_satoru@jp.fujitsu.com> Reported-by: Naohiro Aota <naota@elisp.net> Reviewed-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
-rw-r--r--cmds-property.c14
1 files changed, 13 insertions, 1 deletions
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;
}