Skip to contentSkip to conversation

ceph: don't null-terminate xattr values

PATCH In review Alex Elder 2 participants 2 messages Feb 29, 2012 – Mar 2, 2012 Ceph client

lore
Share & tools
lore

Alex Elder

author
#0 lore raw

PATCH 1/1 ceph: don't null-terminate xattr values

For some reason, ceph_setxattr() allocates an extra byte in which a '\0' is stored past the end of an extended attribute value. This is not needed, and is potentially misleading, so get rid of it.

---
 fs/ceph/xattr.c |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)
fs/ceph/xattr.c +1 -3
index 9e6734e..b98b91d 100644
@@ -730,11 +730,9 @@ int ceph_setxattr(struct dentry *dentry, const char *name,
 		goto out;
 
 	if (val_len) {
-		newval = kmalloc(val_len + 1, GFP_NOFS);
+		newval = kmemdup(value, val_len, GFP_NOFS);
 		if (!newval)
 			goto out;
-		memcpy(newval, value, val_len);
-		newval[val_len] = '\0';
 	}
 
 	xattr = kmalloc(sizeof(struct ceph_inode_xattr), GFP_NOFS);
Signature · 1 line
1.7.5.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 36 lines · Alex Elder

For some reason, ceph_setxattr() allocates an extra byte in which a '\0' is stored past the end of an extended attribute value. This is not needed, and is potentially misleading, so get rid of it.

---
 fs/ceph/xattr.c |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)
fs/ceph/xattr.c +1 -3
index 9e6734e..b98b91d 100644
@@ -730,11 +730,9 @@ int ceph_setxattr(struct dentry *dentry, const char
 *name,
 		goto out;
 
 	if (val_len) {
-		newval = kmalloc(val_len + 1, GFP_NOFS);
+		newval = kmemdup(value, val_len, GFP_NOFS);
 		if (!newval)
 			goto out;
-		memcpy(newval, value, val_len);
-		newval[val_len] = '\0';
 	}
 

xattr = kmalloc(sizeof(struct ceph_inode_xattr), GFP_NOFS);

Signature · 6 lines
1.7.5.4

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html