From nobody Mon Sep 11 19:45:01 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Rkxy56N2nz4sywP; Mon, 11 Sep 2023 19:45:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Rkxy54WjWz4GmS; Mon, 11 Sep 2023 19:45:01 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1694461501; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=PgUEbMkpaamzYyzkFvk1G0sUgEJguQq4cJBveZQRjwQ=; b=yJFVFMp5CxSiyZo2zdGdsxIENy0726rYca17yD6dfIL/LZ5gAvdsJqYdEnMCBuN4Z4nfhU 3qRpiGmKrHAIvlMO121QyAF6/l9P5JwUegEHynNCvqcyMRFgm7VFQtOscc2X73U7Sw+LuF uBjRg5PSmnr4729TX8TRqwm2ZTqkEUq8WfopOwnmukrVAEfq+vw/+tW4dluqMfNBe3HQbF e7Uh0r8UkGiZwGiH0Y/wSnAktZjDT5XR5+twAFMRbiQ52DgV/v17GPmDof4Wf2J2Y1QsdP lnRbGxXM0wfQA7gxkzBifrlnWSnA5yC4ux6tO+TdtuTdVnsPiiP4VmrgnC0r3w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1694461501; a=rsa-sha256; cv=none; b=S+iDLAt+wo926QYPE27X1z8DDjghv010RFV1nz6Qn/q30IfGtZ5lpLmUA6vtSwROxVaMMi 0RscMwmEW9qQRirucJ4jvXbw+kSQyjCQ2I6UDrS322kuE6OEe8FWbDQDIs8eJianh0mwsU Wep/RiwV1HeHhso8sS7OKFfgsT81p7FNaHm6eY5xhOgBEu8HJJcnW5UMkDpVF/STXFUnKx q0xV4wUgnCsDVaxHV28hQMD2pjt0ARAbBFPEOo0/O+iv+cza9ohf11miS2sq3Bhi5VPwu1 vkWNE1WPJs1xmoZme5mEsl9A9YU9YjrFllsFS6y4uIlt58G2dmwtQIBH2S2lZw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1694461501; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=PgUEbMkpaamzYyzkFvk1G0sUgEJguQq4cJBveZQRjwQ=; b=vNdt2j4cu8ICRQkSFbhLcrhaitwC85qr2Zkb/N2XPX7cuU49wf5c0+GICbSCk9Juy6ciTg HmfweQwRU2lm/tluOJpE5dbm8+J1ix84jbLLAKMZIOf5vR9hUT1Wh21+KLLhUx3k3mGXU6 F+Il1psxofDXP6zBF7d8XqRRb71lVP+xQC+rzHonDIZH3rigfVn+BW05sVSDodq+mlOEZq 1+025gKVrYJO3ee1ZNHCdqeGPLaIRf3J7W5saxWbc0oy64iqhm+e1b9gawIu1CnEJAFX6O KWwkTfkCH0RRvnCW1GT03RlVVoFq165Qlv3nGEB+7Ls0qEVz3Bl2+osokWumuQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Rkxy53Z80z12q1; Mon, 11 Sep 2023 19:45:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 38BJj1Hs073107; Mon, 11 Sep 2023 19:45:01 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 38BJj1i6073104; Mon, 11 Sep 2023 19:45:01 GMT (envelope-from git) Date: Mon, 11 Sep 2023 19:45:01 GMT Message-Id: <202309111945.38BJj1i6073104@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Martin Matuska Subject: git: f0ed478f0596 - releng/14.0 - libarchive: merge security fix from vendor branch List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mm X-Git-Repository: src X-Git-Refname: refs/heads/releng/14.0 X-Git-Reftype: branch X-Git-Commit: f0ed478f0596deb99db65738baa73d18ea4368ee Auto-Submitted: auto-generated The branch releng/14.0 has been updated by mm: URL: https://cgit.FreeBSD.org/src/commit/?id=f0ed478f0596deb99db65738baa73d18ea4368ee commit f0ed478f0596deb99db65738baa73d18ea4368ee Author: Martin Matuska AuthorDate: 2023-09-07 15:18:12 +0000 Commit: Martin Matuska CommitDate: 2023-09-11 19:44:49 +0000 libarchive: merge security fix from vendor branch This commit fixes a couple of security vulnerabilities in the PAX writer: 1. Heap overflow in url_encode() in archive_write_set_format_pax.c 2. NULL dereference in archive_write_pax_header_xattrs() 3. Another NULL dereference in archive_write_pax_header_xattrs() 4. NULL dereference in archive_write_pax_header_xattr() Security: No known reference yet Obtained from: https://github.com/libarchive/libarchive/commit/1b4e0d0f9 Approved by: re (gjb) (cherry picked from commit f10f65999fe56e92f00b5bc5d27ac342cfea5364) (cherry picked from commit 0c9b0086715b3b354d471de9dee2ea113aa94481) --- .../libarchive/archive_write_set_format_pax.c | 35 +++++++++++++++------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/contrib/libarchive/libarchive/archive_write_set_format_pax.c b/contrib/libarchive/libarchive/archive_write_set_format_pax.c index 661b7013e0d2..8ce1d18c61e5 100644 --- a/contrib/libarchive/libarchive/archive_write_set_format_pax.c +++ b/contrib/libarchive/libarchive/archive_write_set_format_pax.c @@ -368,10 +368,12 @@ archive_write_pax_header_xattr(struct pax *pax, const char *encoded_name, struct archive_string s; char *encoded_value; + if (encoded_name == NULL) + return; + if (pax->flags & WRITE_LIBARCHIVE_XATTR) { encoded_value = base64_encode((const char *)value, value_len); - - if (encoded_name != NULL && encoded_value != NULL) { + if (encoded_value != NULL) { archive_string_init(&s); archive_strcpy(&s, "LIBARCHIVE.xattr."); archive_strcat(&s, encoded_name); @@ -404,17 +406,22 @@ archive_write_pax_header_xattrs(struct archive_write *a, archive_entry_xattr_next(entry, &name, &value, &size); url_encoded_name = url_encode(name); - if (url_encoded_name != NULL) { + if (url_encoded_name == NULL) + goto malloc_error; + else { /* Convert narrow-character to UTF-8. */ r = archive_strcpy_l(&(pax->l_url_encoded_name), url_encoded_name, pax->sconv_utf8); free(url_encoded_name); /* Done with this. */ if (r == 0) encoded_name = pax->l_url_encoded_name.s; - else if (errno == ENOMEM) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate memory for Linkname"); - return (ARCHIVE_FATAL); + else if (r == -1) + goto malloc_error; + else { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Error encoding pax extended attribute"); + return (ARCHIVE_FAILED); } } @@ -423,6 +430,9 @@ archive_write_pax_header_xattrs(struct archive_write *a, } return (ARCHIVE_OK); +malloc_error: + archive_set_error(&a->archive, ENOMEM, "Can't allocate memory"); + return (ARCHIVE_FATAL); } static int @@ -1904,14 +1914,19 @@ url_encode(const char *in) { const char *s; char *d; - int out_len = 0; + size_t out_len = 0; char *out; for (s = in; *s != '\0'; s++) { - if (*s < 33 || *s > 126 || *s == '%' || *s == '=') + if (*s < 33 || *s > 126 || *s == '%' || *s == '=') { + if (SIZE_MAX - out_len < 4) + return (NULL); out_len += 3; - else + } else { + if (SIZE_MAX - out_len < 2) + return (NULL); out_len++; + } } out = (char *)malloc(out_len + 1);