Skip to content

Commit

Permalink
libarchive: fail if name_max is 0
Browse files Browse the repository at this point in the history
Add error handling to the USE_READDIR_R code paths that set name_max
from struct statfs or statvfs; if the determined name_max == 0
then return an error.

Avoids a crash in tree_dir_next_posix() when the calculation of
dirent_size from name_max is too small for the memory allocated
for struct dirent.

Submitted to upstream in pull request
	libarchive/libarchive#1903

Should fix PR bin/56080
  • Loading branch information
lukem committed Jun 10, 2023
1 parent bd16a96 commit d699df5
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions external/bsd/libarchive/dist/libarchive/archive_read_disk_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -1653,6 +1653,11 @@ setup_current_filesystem(struct archive_read_disk *a)
else
t->current_filesystem->name_max = nm;
#endif
if (t->current_filesystem->name_max == 0) {
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
"Cannot determine name_max");
return (ARCHIVE_FAILED);
}
#endif /* USE_READDIR_R */
return (ARCHIVE_OK);
}
Expand Down Expand Up @@ -1726,6 +1731,11 @@ setup_current_filesystem(struct archive_read_disk *a)

/* Set maximum filename length. */
t->current_filesystem->name_max = sfs.f_namemax;
if (t->current_filesystem->name_max == 0) {
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
"Cannot determine name_max");
return (ARCHIVE_FAILED);
}
return (ARCHIVE_OK);
}

Expand Down Expand Up @@ -1858,6 +1868,11 @@ setup_current_filesystem(struct archive_read_disk *a)
#if defined(USE_READDIR_R)
/* Set maximum filename length. */
t->current_filesystem->name_max = sfs.f_namelen;
if (t->current_filesystem->name_max == 0) {
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
"Cannot determine name_max");
return (ARCHIVE_FAILED);
}
#endif
return (ARCHIVE_OK);
}
Expand Down Expand Up @@ -1939,6 +1954,11 @@ setup_current_filesystem(struct archive_read_disk *a)
#if defined(USE_READDIR_R)
/* Set maximum filename length. */
t->current_filesystem->name_max = sfs.f_namemax;
if (t->current_filesystem->name_max == 0) {
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
"Cannot determine name_max");
return (ARCHIVE_FAILED);
}
#endif
return (ARCHIVE_OK);
}
Expand Down Expand Up @@ -1993,6 +2013,11 @@ setup_current_filesystem(struct archive_read_disk *a)
else
t->current_filesystem->name_max = nm;
# endif /* _PC_NAME_MAX */
if (t->current_filesystem->name_max == 0) {
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
"Cannot determine name_max");
return (ARCHIVE_FAILED);
}
#endif /* USE_READDIR_R */
return (ARCHIVE_OK);
}
Expand Down

0 comments on commit d699df5

Please sign in to comment.