Skip to contentSkip to conversation

Fix possible pointer dereference

PATCH In review Diego Calleja 2 participants 2 messages Oct 6, 2009 – Oct 7, 2009 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix possible pointer dereference

We should always check btrfs_alloc_path(). Some places BUG(), others return -ENOMEM, btrfs_insert_dir_item() seems like it can return safely.

fs/btrfs/dir-item.c renamed from fs/btrfs/dir-item.c.BAK +3 -0
@@ -147,6 +147,9 @@ int btrfs_insert_dir_item(struct btrfs_t
 	key.offset = btrfs_name_hash(name, name_len);
 
 	path = btrfs_alloc_path();
+	if (!path)
+		return -ENOMEM;
+
 	path->leave_spinning = 1;
 
 	data_size = sizeof(*dir_item) + name_len;
#1 lore raw
Quoted 3 lines · Diego Calleja

We should always check btrfs_alloc_path(). Some places BUG(), others return -ENOMEM, btrfs_insert_dir_item() seems like it can return safely.

The problem is that all the callers don't handle errors.
It doesn't make sense to fix it low-level currently when it cannot be handled properly higher up anyways.

Proper out of memory handling needs much more work, one liners don't really help.

-Andi

Signature · 1 line
[email protected] -- Speaking for myself only.