From nobody Sun Sep 18 06:27:16 2022 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 4MVdBr6h2Vz4c33X; Sun, 18 Sep 2022 06:27:16 +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 4MVdBr5vxCz3Yy7; Sun, 18 Sep 2022 06:27:16 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1663482436; 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=+oXsFVUtyM34MUHbW9lDLG2TjBT+CeUHYxAtqC08J2w=; b=xbNUh6ObvfDX2nrrU6nAuuh9wMXnts7XHl6gmHs82JVDV81S7103fUs5/GjZiS/lNP24MT IC/DZd79weX0uI6J2tZIodcWt8+MHPEl6lcpeobisvvvvm8dch0NyluushsD9rXu4dh1om EzyypMGcXrreOj41xCweeh7HSwIPY5gEZGdkIbA7A0VebqqjD+UMBgj6ajarVpy2C5An6/ RmSlWaVdIgHtick8NmaILJuq8aTu8Gf5bulRFO4o9mCdsWoBUyTd9TqwL0iSZoCoDx0QeH uMVE0tYM8WcBy1Ye4pilYQ6reB85a79oLgBeN6t+nen4cklE5PHuaUGGTpeoyg== 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 4MVdBr4s6jzxH8; Sun, 18 Sep 2022 06:27:16 +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 28I6RGZ9068238; Sun, 18 Sep 2022 06:27:16 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 28I6RGLq068237; Sun, 18 Sep 2022 06:27:16 GMT (envelope-from git) Date: Sun, 18 Sep 2022 06:27:16 GMT Message-Id: <202209180627.28I6RGLq068237@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: 65b33f206d34 - stable/12 - tools: test: iconv: fix open_2 to not segfault 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: kevans X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 65b33f206d3465c10f374ded3895efb9872d6f63 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1663482436; 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=+oXsFVUtyM34MUHbW9lDLG2TjBT+CeUHYxAtqC08J2w=; b=ke7yVfrUSmowsHleEZ1G9qVVU/dGm8ASo07aoXfEpKC8aj64KQel7CaBpSrrTv4E5GW16D 9kc9iFPijr7gpzGcnX3gcCEufeLfy6xlMFFLiqfRM4yK18yCLUTo/jPx9L9zJIN2eP42IQ zWJe9RpiEJkWdZ84z0eJB930BncvGGeNC6ldzP5YPlUIJ5Qi5hHI/q072fbfyoRlXZJTSr dJX6S3zML28BgaJiur9VD7WVhIdjylZTZ+LqKrXYiK9Bw4VjOL81NJFse6iUd/fOjav4I/ 0JgvpOUSIlqxwz6z4h7QcKaRpUh2AJvD5mbhAWi0f7yfhKlxm2HsLx8VoQKeaA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1663482436; a=rsa-sha256; cv=none; b=Ehm8M65RqJb174x6j9tGjUqOkLm3jo8pQHQz5Ie9gTRXHgERVmKunLelmdRQb8FCwj6zIk 9uCVbj/BnDTKFwPQwvNV3V+WzxZRgs/YVcaIXasF3bmUG1VBItMfI1Q6cZExAEQsBvFJ9y S21slbBaXHV6cPXTPWbflR7js4qL+3Jn78Gf5tvErSd+sIBpZ8I1UAuXjzSeY1/aM+tgnl hSaJGnacKytZ+rxZiZ4yKmX1vBRWwXUY0RTjYkLaCAKSCIJAHOI71tIB7pC3T6TVo+Q/Cz iviHdP1dKEsW83tYDioKz27M2UkgGzvCRaP+tfajdwZokDNTxbBpSBYS+bc4vQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=65b33f206d3465c10f374ded3895efb9872d6f63 commit 65b33f206d3465c10f374ded3895efb9872d6f63 Author: Kyle Evans AuthorDate: 2022-01-11 23:41:10 +0000 Commit: Kyle Evans CommitDate: 2022-09-17 19:30:14 +0000 tools: test: iconv: fix open_2 to not segfault Record error condition when iconv_open() fails rather than leaving a bogus iconv_t that iconv_close() can later choke on; this is one failure mode. If we opened MAX_LIMIT files with success, we need to rewind one so that we don't iconv_close() one past the end of cd; this is the second failure mode. Sponsored by: Klara, Inc. (cherry picked from commit 814bd1ed438f7dfc5bedcb1f3e772a46fe7026bb) --- tools/test/iconv/posix/posix.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tools/test/iconv/posix/posix.c b/tools/test/iconv/posix/posix.c index 2502393b5509..a95e8863fa30 100644 --- a/tools/test/iconv/posix/posix.c +++ b/tools/test/iconv/posix/posix.c @@ -27,8 +27,8 @@ #include __FBSDID("$FreeBSD$"); +#include #include -#include #include #include @@ -66,18 +66,22 @@ static int open_2(void) { iconv_t cd[MAX_LIMIT]; - int i, ret; + size_t i; + int ret; errno = 0; + ret = 1; for (i = 0; i < MAX_LIMIT; i++) { cd[i] = iconv_open("ASCII", "UTF8"); - if (cd[i] == (iconv_t)-1) + if (cd[i] == (iconv_t)-1) { + if (errno == ENFILE || errno == EMFILE) + ret = 0; + cd[i] = NULL; break; + } } - ret = (cd[i] == (iconv_t)-1) && ((errno == ENFILE) || - (errno == EMFILE)) ? 0 : 1; - for (; i > 0; i--) + for (i = MIN(i, nitems(cd) - 1); i > 0; i--) iconv_close(cd[i]); return (ret); }