From b36466f05a59c7b508ed5c1952079a3769d686b8 Mon Sep 17 00:00:00 2001 From: Martin Matuska Date: Sat, 26 Mar 2022 10:46:31 +0100 Subject: Update vendor/libarchive to libarchive/libarchive@cfaa28168 Bugfixes: IS #1672 and OSS-Fuzz #38766: (zip reader) fix possible out-of-bounds read in zipx_lzma_alone_init() PR #1676: (mtree reader) remove the unused variable "detected_bytes" PR #1674: (doc) fix use of At mdoc(7) macro in cpio.5 Obtained from: libarchive Libarchive commit: cfaa28168a07ea4a53276b63068f94fce37d6aff --- configure.ac | 4 ++-- libarchive/archive_read_disk_posix.c | 7 ++++++- libarchive/archive_read_support_format_mtree.c | 5 +---- libarchive/archive_read_support_format_zip.c | 2 +- libarchive/cpio.5 | 2 +- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/configure.ac b/configure.ac index 05aa0407b678..2c9e1f957e11 100644 --- a/configure.ac +++ b/configure.ac @@ -715,14 +715,14 @@ AC_CHECK_TYPES(struct statfs,,, # There are several variants of readdir_r around; we only # accept the POSIX-compliant version. -AC_COMPILE_IFELSE( +AC_LINK_IFELSE( [AC_LANG_PROGRAM([[#include ]], [[DIR *dir; struct dirent e, *r; return(readdir_r(dir, &e, &r));]])], [AC_DEFINE(HAVE_READDIR_R,1,[Define to 1 if you have a POSIX compatible readdir_r])] ) # dirfd can be either a function or a macro. -AC_COMPILE_IFELSE( +AC_LINK_IFELSE( [AC_LANG_PROGRAM([[#include DIR *dir;]], [[return(dirfd(dir));]])], diff --git a/libarchive/archive_read_disk_posix.c b/libarchive/archive_read_disk_posix.c index d0e1f35c8291..2b39e672b49c 100644 --- a/libarchive/archive_read_disk_posix.c +++ b/libarchive/archive_read_disk_posix.c @@ -109,6 +109,11 @@ __FBSDID("$FreeBSD$"); #define O_CLOEXEC 0 #endif +#if defined(__hpux) && !defined(HAVE_DIRFD) +#define dirfd(x) ((x)->__dd_fd) +#define HAVE_DIRFD +#endif + /*- * This is a new directory-walking system that addresses a number * of problems I've had with fts(3). In particular, it has no @@ -2428,7 +2433,7 @@ tree_dir_next_posix(struct tree *t) #else /* HAVE_FDOPENDIR */ if (tree_enter_working_dir(t) == 0) { t->d = opendir("."); -#if HAVE_DIRFD || defined(dirfd) +#ifdef HAVE_DIRFD __archive_ensure_cloexec_flag(dirfd(t->d)); #endif } diff --git a/libarchive/archive_read_support_format_mtree.c b/libarchive/archive_read_support_format_mtree.c index 88bca76fb915..4a2816325f22 100644 --- a/libarchive/archive_read_support_format_mtree.c +++ b/libarchive/archive_read_support_format_mtree.c @@ -692,7 +692,7 @@ detect_form(struct archive_read *a, int *is_form_d) { const char *p; ssize_t avail, ravail; - ssize_t detected_bytes = 0, len, nl; + ssize_t len, nl; int entry_cnt = 0, multiline = 0; int form_D = 0;/* The archive is generated by `NetBSD mtree -D' * (In this source we call it `form D') . */ @@ -728,8 +728,6 @@ detect_form(struct archive_read *a, int *is_form_d) * character of previous line was '\' character. */ if (bid_keyword_list(p, len, 0, 0) <= 0) break; - if (multiline == 1) - detected_bytes += len; if (p[len-nl-1] != '\\') { if (multiline == 1 && ++entry_cnt >= MAX_BID_ENTRY) @@ -745,7 +743,6 @@ detect_form(struct archive_read *a, int *is_form_d) keywords = bid_entry(p, len, nl, &last_is_path); if (keywords >= 0) { - detected_bytes += len; if (form_D == 0) { if (last_is_path) form_D = 1; diff --git a/libarchive/archive_read_support_format_zip.c b/libarchive/archive_read_support_format_zip.c index 38ada70b5577..9d6c900b2c6e 100644 --- a/libarchive/archive_read_support_format_zip.c +++ b/libarchive/archive_read_support_format_zip.c @@ -1667,7 +1667,7 @@ zipx_lzma_alone_init(struct archive_read *a, struct zip *zip) */ /* Read magic1,magic2,lzma_params from the ZIPX stream. */ - if((p = __archive_read_ahead(a, 9, NULL)) == NULL) { + if(zip->entry_bytes_remaining < 9 || (p = __archive_read_ahead(a, 9, NULL)) == NULL) { archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "Truncated lzma data"); return (ARCHIVE_FATAL); diff --git a/libarchive/cpio.5 b/libarchive/cpio.5 index 837a45692e3b..c71018b1996e 100644 --- a/libarchive/cpio.5 +++ b/libarchive/cpio.5 @@ -354,7 +354,7 @@ while working in AT&T's Unix Support Group. It appeared in 1977 as part of PWB/UNIX 1.0, the .Dq Programmer's Work Bench derived from -.At 6th Edition UNIX +.At v6 that was used internally at AT&T. Both the new binary and old character formats were in use by 1980, according to the System III source released -- cgit v1.2.3