From nobody Thu Aug 11 16:43:45 2022 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 4M3Xgj2QDPz4Yx08; Thu, 11 Aug 2022 16:43:45 +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 4M3Xgj1m3wz3y8B; Thu, 11 Aug 2022 16:43:45 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660236225; 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=uZLLLqcplXRuY62mwyvt1i0MqWpfkbqEl/XysG2I1Mo=; b=U44rgknKB/qry/GFjLODZltxR7inBBim8f2wGsghyW9HV9dB2Byk43iP3xhk5VNOILEXAM J83A4BtvcVKFbMxXkSpHiBu6O04TltolQZjXAxBTROdXujhMCACjXP7Wp64+7YNsqXGQi1 Fzp1vOPnq07Uz6DfkFhJ/H1lVuMbG9qeIVPttMyI1dQPKY2v9wQ8pqKLRd8YTSUvsS7+Sb 1mgJOC6Eq3Vyp2Z0FuMB6yP3cgJdkMHhyqrbfxjSFgWoMiAS46csXIyNAt8PVY1R2Nfe98 237pjCWJXo498+JMtZ4Nmp/fZWzvxrxxWgxpRJlpFeAVpObF69PgHW8kZpPLBQ== 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 4M3Xgj0q7MzyQ9; Thu, 11 Aug 2022 16:43:45 +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 27BGhjGV082612; Thu, 11 Aug 2022 16:43:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 27BGhjC4082611; Thu, 11 Aug 2022 16:43:45 GMT (envelope-from git) Date: Thu, 11 Aug 2022 16:43:45 GMT Message-Id: <202208111643.27BGhjC4082611@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: 814bd1ed438f - main - tools: test: iconv: fix open_2 to not segfault 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: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 814bd1ed438f7dfc5bedcb1f3e772a46fe7026bb Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660236225; 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=uZLLLqcplXRuY62mwyvt1i0MqWpfkbqEl/XysG2I1Mo=; b=I3qBOfseiDYXNvpST3rvuPuF0LAeXp7WMf9jzrXYvN5zp/7F8a0UMlkeupojIfQ2SFNRPM 6Kcio+qDlmVjHDN9cVFTTTC90PSae3EldhdeOiLYZnMIFV3dm3BAEN9xDrHdvXNeWsLKYb i7a4TpiVNVtG0d858ct7OPRPnB9olNfWIE8MtYMZ0VpZWXZ4mowhPMAK9YXIYy/eG4G2xH FJXF+TFVSLUKtOuBS5QiOSR5YAJmVqa+wGChp9Iqk/aHcY4DBnhI0BwKasbyADYzxUygbC GBBGYl6icFOXyeh5D+XXuAKOiEkXdRwEhh86A9jBhTZboxckcl9SQ8WK+lnSaQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1660236225; a=rsa-sha256; cv=none; b=KCBETwCusEIZFi20KKjB4IB8TSCV6csJFTi4ml9/T8X8CBTy6MeqMbtQl9I+e7Hpc/fvxq 1li/uByrkH5c3WL2pSFLN1DMHdVVkhJl63yrR6q03O6NSqahEKgqfbaMcnQS2UXiIqUb1x mIJ93l2eBvXwFcY/o33NPopF4YO2c39hZ9AFfwlqMtl1kX3Mj8w06clXsE947HM1e55P0c 2QxrEqctb1SCtrrvi3qDakty6Rmsapc7pcpxSdg91GeoU9LU1qnS8eSjxW3CdnRlPvErCW jYPW11R7gBDL4xOLb3Bxmwd36sgY01MnoAmtz18h55d82yKs/KIhHNAL+L7DsQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=814bd1ed438f7dfc5bedcb1f3e772a46fe7026bb commit 814bd1ed438f7dfc5bedcb1f3e772a46fe7026bb Author: Kyle Evans AuthorDate: 2022-01-11 23:41:10 +0000 Commit: Kyle Evans CommitDate: 2022-08-11 16:33:28 +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. --- 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 7faed92416a3..3e813226fa5e 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); }