From 02077e89b5b81c76e962a6643c7a7423b1f8336f Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Mon, 2 Dec 2024 11:15:17 -0500 Subject: [PATCH] writer: Reject empty xattr names Came out of a related discussion in ostree https://github.com/ostreedev/ostree/pull/3346#discussion_r1866007266 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 --- libcomposefs/lcfs-writer.c | 2 +- tests/assets/should-fail-empty-xattr-key.dump | 2 ++ tests/meson.build | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 tests/assets/should-fail-empty-xattr-key.dump diff --git a/libcomposefs/lcfs-writer.c b/libcomposefs/lcfs-writer.c index f6e202e6..6e675b0a 100644 --- a/libcomposefs/lcfs-writer.c +++ b/libcomposefs/lcfs-writer.c @@ -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; } diff --git a/tests/assets/should-fail-empty-xattr-key.dump b/tests/assets/should-fail-empty-xattr-key.dump new file mode 100644 index 00000000..52a9d7d7 --- /dev/null +++ b/tests/assets/should-fail-empty-xattr-key.dump @@ -0,0 +1,2 @@ +/ 4096 40555 2 0 0 0 1633950376.0 - - - +/noxattr-key 0 100644 1 0 0 0 0.0 - - - =somevalue diff --git a/tests/meson.build b/tests/meson.build index 58f98750..30277c4e 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -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',