linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Anand jain <Anand.Jain@oracle.com>
To: linux-btrfs@vger.kernel.org
Cc: Anand Jain <anand.jain@oracle.com>
Subject: [PATCH] Btrfs-progs: seg fault in get_label_unmounted
Date: Wed, 15 Aug 2012 16:29:53 +0800	[thread overview]
Message-ID: <1345019393-6168-1-git-send-email-Anand.Jain@oracle.com> (raw)

From: Anand Jain <anand.jain@oracle.com>

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>
---
 btrfslabel.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/btrfslabel.c b/btrfslabel.c
index bf73802..cb142b0 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;
 }
 
 
-- 
1.7.1


             reply	other threads:[~2012-08-15  8:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-15  8:29 Anand jain [this message]
2012-08-22 13:47 ` [PATCH] Btrfs-progs: seg fault in get_label_unmounted 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=1345019393-6168-1-git-send-email-Anand.Jain@oracle.com \
    --to=anand.jain@oracle.com \
    --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;
as well as URLs for NNTP newsgroup(s).