From nobody Mon Sep 11 07:04:02 2023 X-Original-To: dev-commits-src-branches@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 4Rkd42554jz4t9kR; Mon, 11 Sep 2023 07:04:02 +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 4Rkd423xXPz4WcX; Mon, 11 Sep 2023 07:04:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1694415842; 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=KVzUyLLwdfjnYe/BL3Df3U+eIZuD86O0SSVZEUyYndo=; b=BHrtXaeUI3syephMsnjWrG0Vk0ZpEpPD/vU3FD1l5XlIun1fvQsgEmUYGmJCcXQu7Nm4l5 AkShV2rMsaRUqBaWx9HeYCzWq03Q9DNw744ZW8Q51nvQRss5VhiDJrv439mf67ztz2gZjh cuSgWwaxaChHXZq/Eh3Kr8L+01NwMAvjsYVqZiq8iJcS9hNG/POGXwvuOAvQ+6l8FsgBAA GtevLMw5HhqK/6i/D3YSt0PQWooyXlQDsQKpZ4+34keTeNh+PfvrCcEyRA0D+qB0PB92gB Fegt04djd6AIFWZoypuv1H7IaN+wLHOJHDxzAKOe6OLnThygFCdFVD9WfSgT3Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1694415842; a=rsa-sha256; cv=none; b=r/dAX7hwkncGRhRx4ZNN9azHOaSftoS7ZgEPhOOi3TfO7+/mpCYBV2PYz/pMFh9wGYEgsB A1eT2Hv3AVIuQyQFJscVM5gD6ACa9Aafz6Dm8f7QWmK1tWeK8jwq0x1Pm1ZJtS4OxwNOk6 8wzc7PW9f+SRVMSrktflhaESTrdtp0pdSkPbu4OoTJbs6iwpuJNS1VzwTqzTkOnUOtFhmg w/EdSbUpnZyrMqCs8ugYMuXtJ4Qcri/eqI79fSHtbnM6WrGc6jCKDt8lboNpfAJTY6nBx/ NZEvzXp1U5mXDz7oV6uf8m2mcvKl0Khtn0JxEb448GHWbZCbWDpp0G06wGGFzA== 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=1694415842; 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=KVzUyLLwdfjnYe/BL3Df3U+eIZuD86O0SSVZEUyYndo=; b=F0yVVPe0GBwh4QHntc+ia2nuwlcW5ryJdbV3tlkCoNgCqL0PjC3s3ECTVgN+hdfwloLBdJ 27O4+nXWbMuypzfUzo07SDFX5Z51y27LrXE3Y6jYZEWUcOyEi5/z8q7QoFDQqSw3dr9v75 fbkfhmmmXnRnbLctzwkcsD0FZ4vcVEU4Tqaa/FL78TwTv2ThhYmFgm20jzr3H4xWmWqbbl 3jdnzogllDhzQcu2GPcs8yC7FmA/QgmKMTKJbyIWeDIAiqOx/ouP7wFF2G4oj3786K6yjv AhH/ChsAcVknhicj3yx1YeU+ZTXIDxpP7f+gSAQgnh9wHkSvsh0zNRvK7seHaA== 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 4Rkd4232VpzgN8; Mon, 11 Sep 2023 07:04:02 +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 38B742nE010164; Mon, 11 Sep 2023 07:04:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 38B742jB010161; Mon, 11 Sep 2023 07:04:02 GMT (envelope-from git) Date: Mon, 11 Sep 2023 07:04:02 GMT Message-Id: <202309110704.38B742jB010161@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: af386f70fa0c - stable/12 - libarchive: merge security fix from vendor branch List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/stable/12 X-Git-Reftype: branch X-Git-Commit: af386f70fa0c8d0a605c50710283f6f59525bd05 Auto-Submitted: auto-generated The branch stable/12 has been updated by mm: URL: https://cgit.FreeBSD.org/src/commit/?id=af386f70fa0c8d0a605c50710283f6f59525bd05 commit af386f70fa0c8d0a605c50710283f6f59525bd05 Author: Martin Matuska AuthorDate: 2023-09-07 15:18:12 +0000 Commit: Martin Matuska CommitDate: 2023-09-11 07:03:43 +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 MFC after: 3 days (cherry picked from commit f10f65999fe56e92f00b5bc5d27ac342cfea5364) --- .../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 a2e6d9ad1c53..2d3c7086e1f9 100644 --- a/contrib/libarchive/libarchive/archive_write_set_format_pax.c +++ b/contrib/libarchive/libarchive/archive_write_set_format_pax.c @@ -367,10 +367,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); @@ -403,17 +405,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); } } @@ -422,6 +429,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);