[PATCH] avoid NULL deference in ext2_xattr_get

From: shenghui
Date: Sat Jul 10 2010 - 04:07:38 EST


Hi,

I walked through ext2 code, and found one potential NULL deference
in ext2/xattr.c. The version is 2.6.35-rc4, while earlier versions have the
same problem.
If you configure EXT2_XATTR_DEBUG, you'll get:
# define ea_idebug(inode, f...) do { \
printk(KERN_DEBUG "inode %s:%ld: ", \
inode->i_sb->s_id, inode->i_ino); \
printk(f); \
printk("\n"); \
} while (0)

In ext2/xttr.c ext2_xattr_get, NULL pointer check is done after
ea_idebug call, so some may hit NULL deference here.
ext2_xattr_get(struct inode *inode, int name_index, const char *name,
void *buffer, size_t buffer_size)
{
struct buffer_head *bh = NULL;
struct ext2_xattr_entry *entry;
size_t name_len, size;
char *end;
int error;

ea_idebug(inode, "name=%d.%s, buffer=%p, buffer_size=%ld",
name_index, name, buffer, (long)buffer_size);

if (name == NULL)
return -EINVAL;


Following is my patch. Please check it.
The patch is against kernel 2.6.35-rc4.