From 3939d9aeb5cf336e508e733f3e0facc7df7d19e9 Mon Sep 17 00:00:00 2001 From: Duncan Overbruck Date: Sun, 19 Dec 2021 15:45:07 +0100 Subject: [PATCH] lib/plist_fetch.c: don't abort on ARCHIVE_WARN in xbps_archive_fetch_file_into_fd Prior to this change, xbps-query --cat would abort if the entry file name would contain non ascii characters as it returns ARCHIVE_WARN when failing to use iconv to the users character encoding without having locales initialized. Other places in xbps already ignore ARCHIVE_WARN. --- lib/plist_fetch.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/plist_fetch.c b/lib/plist_fetch.c index 3c3c5e5f..ba0c67ae 100644 --- a/lib/plist_fetch.c +++ b/lib/plist_fetch.c @@ -238,18 +238,35 @@ xbps_archive_fetch_file_into_fd(const char *url, const char *fname, int fd) if ((a = open_archive(url)) == NULL) return EINVAL; - while ((archive_read_next_header(a, &entry)) == ARCHIVE_OK) { + for (;;) { const char *bfile; - + rv = archive_read_next_header(a, &entry); + if (rv == ARCHIVE_EOF) { + rv = 0; + break; + } + if (rv == ARCHIVE_FATAL) { + const char *error = archive_error_string(a); + if (error != NULL) { + xbps_error_printf( + "Reading archive entry from: %s: %s\n", + url, error); + } else { + xbps_error_printf( + "Reading archive entry from: %s: %s\n", + url, strerror(archive_errno(a))); + } + rv = archive_errno(a); + break; + } bfile = archive_entry_pathname(entry); if (bfile[0] == '.') bfile++; /* skip first dot */ if (strcmp(bfile, fname) == 0) { rv = archive_read_data_into_fd(a, fd); - if (rv != 0) + if (rv != ARCHIVE_OK) rv = archive_errno(a); - break; } archive_read_data_skip(a);