Skip to content

Commit

Permalink
xar: Fix another infinite loop and expat error handling (#2150)
Browse files Browse the repository at this point in the history
Fixes two issues:
- expat code keeps track of error conditions
- adding link=original multiple times is prohibited
  • Loading branch information
stoeckmann committed Apr 28, 2024
1 parent 9951b9c commit b910cb7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions libarchive/archive_read_support_format_xar.c
Original file line number Diff line number Diff line change
Expand Up @@ -2055,9 +2055,10 @@ xml_start(struct archive_read *a, const char *name, struct xmlattr_list *list)
attr = attr->next) {
if (strcmp(attr->name, "link") != 0)
continue;
if (xar->file->hdnext != NULL || xar->file->link != 0) {
if (xar->file->hdnext != NULL || xar->file->link != 0 ||
xar->file == xar->hdlink_orgs) {
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
"File with multiple link targets");
"File with multiple link attributes");
return (ARCHIVE_FATAL);
}
if (strcmp(attr->value, "original") == 0) {
Expand Down Expand Up @@ -3256,6 +3257,9 @@ expat_start_cb(void *userData, const XML_Char *name, const XML_Char **atts)
struct xmlattr_list list;
int r;

if (ud->state != ARCHIVE_OK)
return;

r = expat_xmlattr_setup(a, &list, atts);
if (r == ARCHIVE_OK)
r = xml_start(a, (const char *)name, &list);
Expand Down
2 changes: 1 addition & 1 deletion libarchive/test/test_read_format_xar_doublelink.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ DEFINE_TEST(test_read_format_xar_doublelink)

assertA(ARCHIVE_FATAL == archive_read_next_header(a, &ae));
assertEqualString(archive_error_string(a),
"File with multiple link targets");
"File with multiple link attributes");
assert(archive_errno(a) != 0);

assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
Expand Down

0 comments on commit b910cb7

Please sign in to comment.