public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] disk-io.c (open_ctree): Don't dereference NULL upon failed kzalloc
@ 2008-09-09 14:19 Jim Meyering
  0 siblings, 0 replies; only message in thread
From: Jim Meyering @ 2008-09-09 14:19 UTC (permalink / raw)
  To: linux-btrfs

I was looking at how *alloc-returned values are dereferenced,
and spotted two potential NULL dereferences (then stopped looking, for now):

changeset:   708:eecfd989f8c6
tag:         tip
user:        Jim Meyering <meyering@redhat.com>
date:        Tue Sep 09 16:02:31 2008 +0200
files:       disk-io.c
description:
disk-io.c (open_ctree): don't dereference NULL upon failed kzalloc


diff --git a/disk-io.c b/disk-io.c
--- a/disk-io.c
+++ b/disk-io.c
@@ -1321,35 +1321,36 @@ struct btrfs_root *open_ctree(struct sup
 	struct btrfs_root *extent_root = kzalloc(sizeof(struct btrfs_root),
 						 GFP_NOFS);
 	struct btrfs_root *tree_root = kzalloc(sizeof(struct btrfs_root),
 					       GFP_NOFS);
 	struct btrfs_fs_info *fs_info = kzalloc(sizeof(*fs_info),
 						GFP_NOFS);
 	struct btrfs_root *chunk_root = kzalloc(sizeof(struct btrfs_root),
 						GFP_NOFS);
 	struct btrfs_root *dev_root = kzalloc(sizeof(struct btrfs_root),
 					      GFP_NOFS);
 	struct btrfs_root *log_tree_root;
 
 	int ret;
 	int err = -EINVAL;
 
 	struct btrfs_super_block *disk_super;
 
-	if (!extent_root || !tree_root || !fs_info) {
+	if (!extent_root || !tree_root || !fs_info
+	    || !chunk_root || !dev_root) {
 		err = -ENOMEM;
 		goto fail;
 	}
 	INIT_RADIX_TREE(&fs_info->fs_roots_radix, GFP_NOFS);
 	INIT_LIST_HEAD(&fs_info->trans_list);
 	INIT_LIST_HEAD(&fs_info->dead_roots);
 	INIT_LIST_HEAD(&fs_info->hashers);
 	INIT_LIST_HEAD(&fs_info->delalloc_inodes);
 	spin_lock_init(&fs_info->hash_lock);
 	spin_lock_init(&fs_info->delalloc_lock);
 	spin_lock_init(&fs_info->new_trans_lock);
 	spin_lock_init(&fs_info->ref_cache_lock);
 
 	init_completion(&fs_info->kobj_unregister);
 	fs_info->tree_root = tree_root;
 	fs_info->extent_root = extent_root;
 	fs_info->chunk_root = chunk_root;


Here are some offending dereferences:

	chunk_root->node = read_tree_block(chunk_root,
...
	dev_root->track_dirty = 1;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-09-09 14:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-09 14:19 [PATCH] disk-io.c (open_ctree): Don't dereference NULL upon failed kzalloc Jim Meyering

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox