Btrfs-progs: set string end sing '\0' for property

Set string "xattr_name" 's end with '\0' so that it won't be
violated in memory.

With this fix, xfstest/btrfs/048 can pass on my box.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Reviewed-by: Filipe Manana <fdmanana@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
This commit is contained in:
Liu Bo 2014-04-25 18:44:03 +08:00 committed by David Sterba
parent 9317400a67
commit 21a1ff8887

View file

@ -129,13 +129,14 @@ static int prop_compression(enum prop_object_type type,
goto out;
}
xattr_name = malloc(XATTR_BTRFS_PREFIX_LEN + strlen(name));
xattr_name = malloc(XATTR_BTRFS_PREFIX_LEN + strlen(name) + 1);
if (!xattr_name) {
ret = -ENOMEM;
goto out;
}
memcpy(xattr_name, XATTR_BTRFS_PREFIX, XATTR_BTRFS_PREFIX_LEN);
memcpy(xattr_name + XATTR_BTRFS_PREFIX_LEN, name, strlen(name));
xattr_name[XATTR_BTRFS_PREFIX_LEN + strlen(name)] = '\0';
if (value)
sret = fsetxattr(fd, xattr_name, value, strlen(value), 0);