From 489d586702839d3c5629823796226c8f1338a769 Mon Sep 17 00:00:00 2001 From: Przemyslaw Pawelczyk Date: Sun, 6 Sep 2015 18:26:26 +0200 Subject: Fix reading extended attributes values from metadata file. During implementation and tests of new dump action, I've noticed that while non-textual values in extended attributes were properly stored in .metadata file, retrieving them from it was simply broken, i.e. anything beyond first null byte was zeroed. Small quantum of solace is the fact that apparently metastore users rarely use extended attributes or at least rarely with non-textual values, because otherwise they would surely report such crucial bug. Let's perform simple test to show the problem: $ mkdir -p ~/testxattr/ && cd ~/testxattr/ && touch test $ setfattr -n user.txt -v "tekst" test $ setfattr -n user.bin -v 0x020100ff00 test $ getfattr -d -e hex test # file: test user.bin=0x020100ff00 user.txt=0x74656b7374 $ metastore -s test $ OFFSET=$(($(grep -abo user.bin .metadata | sed 's/:.*//')+8+1+4)) $ xxd -p -l5 -s $OFFSET .metadata 020100ff00 So far everything seems fine, i.e. user.bin xattr is properly stored. $ metastore -c test ./test: xattr Apparently on-disk test xattrs differ from those in metadata file, even though they should not! Let's apply those from metadata file and show how they look on-disk. $ metastore -a test ./test: changing metadata ./test: removing xattr user.bin ./test: adding xattr user.bin $ getfattr -d -e hex test # file: test user.bin=0x0201000000 user.txt=0x74656b7374 Oh no! Extended attribute with non-textual data has been corrupted now. But no more, because this commit fixes it! As long as you haven't stored corrupted xattrs in metadata file, you can still recover on-disk ones by applying them from metadata file using fixed version of metastore. --- utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'utils.c') diff --git a/utils.c b/utils.c index 9b96412..7c85b38 100644 --- a/utils.c +++ b/utils.c @@ -173,7 +173,7 @@ read_binary_string(char **from, size_t len, const char *max) } result = xmalloc(len); - strncpy(result, *from, len); + memcpy(result, *from, len); *from += len; return result; } -- cgit v1.2.1