From nobody Sun Sep 18 06:27:08 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 4MVdBh4jk3z4c3GR; Sun, 18 Sep 2022 06:27:08 +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 4MVdBh3XSbz3YSd; Sun, 18 Sep 2022 06:27:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1663482428; 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=RP0Uytu6Dw3RDeZoIFkkIEN4Qp8/xHp09XsDm7mpN4k=; b=jvmwd8lNPy2l1XWOVEZvC8NowzXNG6XiX9whglv4W9Ej2U9tiZXucHnLhc+HAklL4bHtWd Rq7aPIAETV0hXr2oEeCpjImI9nAKzW7vbPzahuNX9Uu3m/xBG6fp2ybWJcFrX4OY3vAR0K Ze59fGWyyZXvGyKIjdkazv0yUQ6dDShk0vgV2WaaOVxEhOH80WZPRNhF2EKoXSgFi0hERg V08NkeehOuT7ZVQWbUS5OmLwVaS0taMR8A2lNLSe7RasPlMIsyC/LBLjvCiT2aT+kpBUi4 VY6YjFKktgOdmXUx5A4aK9hfQ4EonrgdwEeWE1qDSWVQIRjCbpHj8q2OvMHopg== 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 4MVdBh2dDhzxdc; Sun, 18 Sep 2022 06:27:08 +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 28I6R8iO067872; Sun, 18 Sep 2022 06:27:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 28I6R85Z067871; Sun, 18 Sep 2022 06:27:08 GMT (envelope-from git) Date: Sun, 18 Sep 2022 06:27:08 GMT Message-Id: <202209180627.28I6R85Z067871@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: 540ecebdd01b - stable/13 - 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/stable/13 X-Git-Reftype: branch X-Git-Commit: 540ecebdd01b1a094cdcdef30e4b6cbd87aa3403 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1663482428; 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=RP0Uytu6Dw3RDeZoIFkkIEN4Qp8/xHp09XsDm7mpN4k=; b=I/JCqPUbajMz3uFlXNyGOkb3W8S7KM+V9Eetr7cwvXaferyQ0ikDJpdz82X1QbiVe1lZWP c+u+lhPiHf6v+ejv0elhagFjkimli+7A+lOIJLqYquWzeL7UbW5ivvLexuASsGAR7cKdnU KwdlzuxhSyZG2S3L1NkxdqSI7RUub5XhXWsomDi0GcATfD0MhNO73p5mE2uGMnrv5CCprM aM0jhVHplJM7R+ZANbQKiMNm3a67ZNctebxZ7/BVdun1oxXLY0zoZKGVi5O32K+z7SR+sB RfjWUx7sLpcZcRQLk79pNSwTM9s2Sg/qGsjZ1wA4kZw81EavzoEkyusqpTEMEQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1663482428; a=rsa-sha256; cv=none; b=j+UDlTEQSg8hYa2j19ifDKkP2FS2uOY1R4EG0oPADmkhGjWe0cxq0za3+2lBHmlupeTFFu MuMxebUYWmfzL+Ncz7sN791DP9ZUZV2Qv4wl5styMLPGj9R2Sk5udRXi97DRReVZvdIXSD 628YASkPjDOR9wfpqg0VUBUDXAm6QX5Uaf8n8bPWQQwJxZpjE7jAjo0aGPLFul3Ez90QvH MvNf9uVfxzflF2hsbIjER/TWu2fl8/Sd3A18d7BrygsesnTj2uXo9jKfafIQRTRatQxJB+ LgP7J5n0vK5za2m4EvaWxK7vZAC8+behLQLJbKdGxP1kJH1AOpI2M6iawi0mPw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=540ecebdd01b1a094cdcdef30e4b6cbd87aa3403 commit 540ecebdd01b1a094cdcdef30e4b6cbd87aa3403 Author: Kyle Evans AuthorDate: 2022-01-11 23:41:10 +0000 Commit: Kyle Evans CommitDate: 2022-09-18 06:26:39 +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); }