Skip to contentSkip to conversation

btfs-progs: Add null pointer checks

PATCH New Harshavardhana 1 participant 1 message Apr 7, 2010 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btfs-progs: Add null pointer checks

root tree is NULL in case of non btrfs devices, resulting in segfault. This patch fixes such issue.

---
 btrfs-image.c |    5 +++++
 btrfstune.c   |    7 +++++++
 2 files changed, 12 insertions(+), 0 deletions(-)
btrfs-image.c +5 -0
index f2bbcc8..b3cafbb 100644
@@ -491,6 +491,11 @@ static int create_metadump(const char *input, FILE *out, int num_threads,
 	int ret;
 
 	root = open_ctree(input, 0, 0);
+        if (!root) {
+                fprintf (stderr, "unable to open ctree for %s\n", input);
+                return 1;
+        }
+
 	BUG_ON(root->nodesize != root->leafsize);
 
 	ret = metadump_init(&metadump, root, out, num_threads,
btrfstune.c +7 -0
index 47830c5..d2c3d51 100644
@@ -108,6 +108,13 @@ int main(int argc, char *argv[])
 
 	root = open_ctree(device, 0, 1);
 
+        /* root is NULL if btrfs not found */
+        if (!root) {
+                fprintf(stderr, "Unable to open ctree for device: %s\n",
+                        device);
+                return 1;
+        }
+
 	if (seeding_flag) {
 		ret = update_seeding_flag(root, seeding_value);
 		if (!ret)
Signature · 1 line
1.6.6.1