Skip to content

Commit

Permalink
Reject an empty name
Browse files Browse the repository at this point in the history
Yep, just me testing more boundary conditions; this is another
one that ends up with a corrupted erofs. Reject empty filenames
in both the shared library and the C parser.

Signed-off-by: Colin Walters <[email protected]>
  • Loading branch information
cgwalters committed Aug 19, 2024
1 parent 2a450b8 commit 500e7e3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion libcomposefs/lcfs-writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,12 @@ int lcfs_node_add_child(struct lcfs_node_s *parent, struct lcfs_node_s *child,
return -1;
}

if (strlen(name) > LCFS_MAX_NAME_LENGTH) {
const size_t namelen = strlen(name);
if (namelen == 0) {
errno = EINVAL;
return -1;
}
if (namelen > LCFS_MAX_NAME_LENGTH) {
errno = ENAMETOOLONG;
return -1;
}
Expand Down
2 changes: 2 additions & 0 deletions tests/assets/should-fail-empty-name.dump
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/ 4096 40555 2 0 0 0 1633950376.0 - - -
// 4096 40555 2 0 0 0 1633950376.0 - - -
1 change: 1 addition & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ test_assets_should_fail = [
'should-fail-long-xattr-key.dump',
'should-fail-long-xattr-value.dump',
'should-fail-no-ftype.dump',
'should-fail-empty-name.dump',
]

test_assets = test_assets_small + [
Expand Down
3 changes: 3 additions & 0 deletions tools/mkcomposefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,9 @@ static char *tree_from_dump_line(dump_info *info, const char *line, size_t line_
fields[FIELD_PATH].data, fields[FIELD_PATH].len, NULL, &err);
if (path == NULL && err)
return err;
if (!*path) {
return make_error("Invalid empty path");
}

bool is_hardlink = false;
/* First char in mode is @ if hardlink */
Expand Down

0 comments on commit 500e7e3

Please sign in to comment.