summaryrefslogtreecommitdiff
path: root/btrfslabel.c
diff options
context:
space:
mode:
authorAnand Jain <anand.jain@oracle.com>2012-08-15 16:29:53 +0800
committerroot <root@localhost.localdomain>2012-10-04 16:26:32 -0400
commitf4dfc8f6edb62c0a73b6334fc04ac399a289c449 (patch)
treeccb5d7a2fcb885d5b839fff5a0baeb88da306644 /btrfslabel.c
parent8a25bb834b218068dec79983fdfc76ef4f8e605f (diff)
Btrfs-progs: seg fault in get_label_unmounted
btrfs f l / No valid Btrfs found on / Segmentation fault (core dumped) open_ctree can return NULL, we need to check that. Signed-off-by: Anand Jain <anand.jain@oracle.com>
Diffstat (limited to 'btrfslabel.c')
-rw-r--r--btrfslabel.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/btrfslabel.c b/btrfslabel.c
index bf738024..cb142b0a 100644
--- a/btrfslabel.c
+++ b/btrfslabel.c
@@ -67,7 +67,7 @@ static void change_label_unmounted(char *dev, char *nLabel)
close_ctree(root);
}
-static void get_label_unmounted(char *dev)
+int get_label_unmounted(char *dev)
{
struct btrfs_root *root;
@@ -76,10 +76,14 @@ static void get_label_unmounted(char *dev)
*/
root = open_ctree(dev, 0, 0);
+ if(!root)
+ return -1;
+
fprintf(stdout, "%s\n", root->fs_info->super_copy.label);
/* Now we close it since we are done. */
close_ctree(root);
+ return 0;
}
int get_label(char *btrfs_dev)
@@ -98,8 +102,8 @@ int get_label(char *btrfs_dev)
fprintf(stderr, "FATAL: the filesystem has to be unmounted\n");
return -2;
}
- get_label_unmounted(btrfs_dev);
- return 0;
+ ret = get_label_unmounted(btrfs_dev);
+ return ret;
}