From nobody Mon Oct 18 11:16:52 2021
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 3EFFE180531B;
	Mon, 18 Oct 2021 11:16:53 +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 4HXvTd0tL6z3QTk;
	Mon, 18 Oct 2021 11:16:53 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
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 F1E431F0FD;
	Mon, 18 Oct 2021 11:16:52 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from gitrepo.freebsd.org ([127.0.1.44])
	by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 19IBGqwG039501;
	Mon, 18 Oct 2021 11:16:52 GMT
	(envelope-from git@gitrepo.freebsd.org)
Received: (from git@localhost)
	by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 19IBGqJj039500;
	Mon, 18 Oct 2021 11:16:52 GMT
	(envelope-from git)
Date: Mon, 18 Oct 2021 11:16:52 GMT
Message-Id: <202110181116.19IBGqJj039500@gitrepo.freebsd.org>
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org,
        dev-commits-src-branches@FreeBSD.org
From: Yoshihiro Takahashi <nyan@FreeBSD.org>
Subject: git: 3bfe213143c5 - stable/13 - unzip: Fix segmentation fault if a zip file contains buggy filename.
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
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: nyan
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/13
X-Git-Reftype: branch
X-Git-Commit: 3bfe213143c562154e04d840380651f182df04de
Auto-Submitted: auto-generated
X-ThisMailContainsUnwantedMimeParts: N

The branch stable/13 has been updated by nyan:

URL: https://cgit.FreeBSD.org/src/commit/?id=3bfe213143c562154e04d840380651f182df04de

commit 3bfe213143c562154e04d840380651f182df04de
Author:     Yoshihiro Takahashi <nyan@FreeBSD.org>
AuthorDate: 2021-10-10 11:49:19 +0000
Commit:     Yoshihiro Takahashi <nyan@FreeBSD.org>
CommitDate: 2021-10-18 11:16:02 +0000

    unzip: Fix segmentation fault if a zip file contains buggy filename.
    
    PR:             259011
    Reported by:    Robert Morris
    Submitted by:   ak
    
    (cherry picked from commit 2c614481fd5248c1685e713f67d40cf2d5fba494)
---
 usr.bin/unzip/unzip.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/usr.bin/unzip/unzip.c b/usr.bin/unzip/unzip.c
index e5ca1ff2c939..0b564b0f08ec 100644
--- a/usr.bin/unzip/unzip.c
+++ b/usr.bin/unzip/unzip.c
@@ -211,6 +211,9 @@ pathdup(const char *path)
 	char *str;
 	size_t i, len;
 
+	if (path == NULL || path[0] == '\0')
+		return (NULL);
+
 	len = strlen(path);
 	while (len && path[len - 1] == '/')
 		len--;
@@ -697,7 +700,11 @@ extract(struct archive *a, struct archive_entry *e)
 	mode_t filetype;
 	char *p, *q;
 
-	pathname = pathdup(archive_entry_pathname(e));
+	if ((pathname = pathdup(archive_entry_pathname(e))) == NULL) {
+		warningx("skipping empty or unreadable filename entry");
+		ac(archive_read_data_skip(a));
+		return;
+	}
 	filetype = archive_entry_filetype(e);
 
 	/* sanity checks */
@@ -760,7 +767,11 @@ extract_stdout(struct archive *a, struct archive_entry *e)
 	char *pathname;
 	mode_t filetype;
 
-	pathname = pathdup(archive_entry_pathname(e));
+	if ((pathname = pathdup(archive_entry_pathname(e))) == NULL) {
+		warningx("skipping empty or unreadable filename entry");
+		ac(archive_read_data_skip(a));
+		return;
+	}
 	filetype = archive_entry_filetype(e);
 
 	/* I don't think this can happen in a zipfile.. */