Skip to content

Commit

Permalink
writer: Reject empty xattr names
Browse files Browse the repository at this point in the history
Came out of a related discussion in ostree
ostreedev/ostree#3346 (comment)

Today we faithfully write this, and `fsck.erofs` doesn't seem
to complain...but such a thing makes no sense so we shouldn't
support it.

Actually digging in more here...in practice the way xattrs
work in Linux at least is they're restricted to starting with
one of the standard prefixes like `security.` or `user.`; but
enforcing/validating that is a whole other thing. For now
let's just deny this edge case.

Signed-off-by: Colin Walters <walters@verbum.org>
  • Loading branch information
cgwalters committed Dec 2, 2024
1 parent d62aec4 commit 02077e8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion libcomposefs/lcfs-writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1691,7 +1691,7 @@ int lcfs_node_set_xattr_internal(struct lcfs_node_s *node, const char *name,
char *k, *v;

const size_t namelen = strlen(name);
if (namelen > XATTR_NAME_MAX) {
if (namelen == 0 || namelen > XATTR_NAME_MAX) {
errno = ERANGE;
return -1;
}
Expand Down
2 changes: 2 additions & 0 deletions tests/assets/should-fail-empty-xattr-key.dump
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/ 4096 40555 2 0 0 0 1633950376.0 - - -
/noxattr-key 0 100644 1 0 0 0 0.0 - - - =somevalue
1 change: 1 addition & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ test_assets_small_extra = [

test_assets_should_fail = [
'should-fail-long-link.dump',
'should-fail-empty-xattr-key.dump',
'should-fail-long-xattr-key.dump',
'should-fail-long-xattr-value.dump',
'should-fail-honggfuzz-long-xattr.dump',
Expand Down

0 comments on commit 02077e8

Please sign in to comment.