Date: Sun, 18 Sep 2022 06:27:16 GMT From: Kyle Evans <kevans@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 65b33f206d34 - stable/12 - tools: test: iconv: fix open_2 to not segfault Message-ID: <202209180627.28I6RGLq068237@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/12 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=65b33f206d3465c10f374ded3895efb9872d6f63 commit 65b33f206d3465c10f374ded3895efb9872d6f63 Author: Kyle Evans <kevans@FreeBSD.org> AuthorDate: 2022-01-11 23:41:10 +0000 Commit: Kyle Evans <kevans@FreeBSD.org> 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 <sys/cdefs.h> __FBSDID("$FreeBSD$"); +#include <sys/param.h> #include <sys/endian.h> -#include <sys/types.h> #include <err.h> #include <errno.h> @@ -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); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202209180627.28I6RGLq068237>