From nobody Thu Aug 11 16:43:47 2022 X-Original-To: dev-commits-src-main@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 4M3Xgl4FCTz4Ywx7; Thu, 11 Aug 2022 16:43:47 +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 4M3Xgl3RwRz3yCQ; Thu, 11 Aug 2022 16:43:47 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660236227; 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=IkSnh6AFEPry18hsJT6mhfyLeifgblvjJhiFolHu6xE=; b=DLsfIRLLc6Sd24dLLX0osQQFXMaMQn+VccF/SEsbBiXxM6D5CrzGBAXYybD+rJLGuRrWWu WcVveOlAN1JYRHafu7GrfqqOypZ9V7mYBQjGF691+DDfCyIKA+Qji753lcIEfu+jEsgYR+ WqlKRq+wSl6/jKukHWqTtwkbLTh0rrXO5/HqV3SGMEPeTvQJAAm40+R3WCXtQaU+0lYjt2 MIcfPc8xrm4rfDL96iGO5V64XomNNJnQYJLHnp/tnHTAfMxbGjdrOyjZvlGcBmOoEWxVt1 pjtUTZb905OCk0pbZf3bJwchISmmr06vc8wzxNY4l8n5j5cZjoj0U3Uo0BwLvw== 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 4M3Xgl2YrNzyn6; Thu, 11 Aug 2022 16:43:47 +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 27BGhlCa082660; Thu, 11 Aug 2022 16:43:47 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 27BGhltA082659; Thu, 11 Aug 2022 16:43:47 GMT (envelope-from git) Date: Thu, 11 Aug 2022 16:43:47 GMT Message-Id: <202208111643.27BGhltA082659@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: c1f46b8fcb97 - main - libc: iconv: push option ignore into citrus_iconv_open() List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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: c1f46b8fcb9758b52afce5971d12167628f62dfd Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660236227; 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=IkSnh6AFEPry18hsJT6mhfyLeifgblvjJhiFolHu6xE=; b=IrXdn3D+DmXoG0VOOgc6I9Y+PqLvDLN7+YIa1/DRg+MJUZwYhhnBmbdU9GMOdv0tgaZ1Ud hVsBOLqX710kj/yWA57LG5yke8f1PES7usYk6OB1277Bb1lxyGG8Md9UrnfsLjTipn5jZ8 HMKoudYBACau+UAIQR31vMBnvyUr0XY4gVwSi8z6bzGaNEJTQuUr6gyVwddauoW/OIwF1a ft3kQx2R7lmA/pBCn73Tcm4chgJjT1Z9zg71KXzmmpz+ITrkYvi0wUDDEa+PebI0wGVRBx qmdt/UuhpVP4ms046THeFqgAB9Sy7rfXli8OcQdOqR5sLgS3SqAap26JJ8MiZA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1660236227; a=rsa-sha256; cv=none; b=rwKzWJrSYV6w28YRnabwvP7J0kRmLcaWbJA79BuUzAEzr633FKriTWYyKw2MYZCELhSKgj gFnQ4zAcdyuDc9t1vr2r68EIHNX05UCuVbEIVlQyxQF1LMRDEYIuMsW1edrGxfirv7D9s+ Wg+c5wnu04KUvZaauw/qN4p79VqTPmGtOR0WYQz1HLZ8+6oHpYCPGFnW2Lbol6bEiJm2Fo yFdqf22hZ9blFfacWdJOw/w+9vsbz/r6PtLYW6+Z5z4R5XzzsV5dRp/W+Y4BLoSeDRpG+j A9vXn5LImrByc0QQMkfFeh438aIaxjHpEf6nfkhrQYCycAJLbhKv/7uoPrO+mQ== 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=c1f46b8fcb9758b52afce5971d12167628f62dfd commit c1f46b8fcb9758b52afce5971d12167628f62dfd Author: Kyle Evans AuthorDate: 2022-02-22 07:10:05 +0000 Commit: Kyle Evans CommitDate: 2022-08-11 16:33:28 +0000 libc: iconv: push option ignore into citrus_iconv_open() Make it vaguely aware of options in the sense that it now knows that it can zap any trailing //. It now copies the entire string in realsrc and realdst, then terminates them at the options. __bsd___iconv_open can now stop trying to allocate memory just for this purpose, and the new version is technically more correct. GNU libiconv will ignore options on the `in` codeset and still do the right thing. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D34343 --- lib/libc/iconv/bsd_iconv.c | 16 +--------------- lib/libc/iconv/citrus_iconv.c | 28 +++++++++++++++++++++------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/lib/libc/iconv/bsd_iconv.c b/lib/libc/iconv/bsd_iconv.c index 0fcff0e2d1b8..5a0f523b9d15 100644 --- a/lib/libc/iconv/bsd_iconv.c +++ b/lib/libc/iconv/bsd_iconv.c @@ -56,8 +56,6 @@ static iconv_t __bsd___iconv_open(const char *out, const char *in, struct _citrus_iconv *handle) { - const char *out_slashes; - char *out_noslashes; int ret; /* @@ -66,19 +64,7 @@ __bsd___iconv_open(const char *out, const char *in, struct _citrus_iconv *handle * This is for compatibility with software that uses these * blindly. */ - out_slashes = strstr(out, "//"); - if (out_slashes != NULL) { - out_noslashes = strndup(out, out_slashes - out); - if (out_noslashes == NULL) { - errno = ENOMEM; - return ((iconv_t)-1); - } - ret = _citrus_iconv_open(&handle, in, out_noslashes); - free(out_noslashes); - } else { - ret = _citrus_iconv_open(&handle, in, out); - } - + ret = _citrus_iconv_open(&handle, in, out); if (ret) { errno = ret == ENOENT ? EINVAL : ret; return ((iconv_t)-1); diff --git a/lib/libc/iconv/citrus_iconv.c b/lib/libc/iconv/citrus_iconv.c index fbabf6524399..88dfc2deca33 100644 --- a/lib/libc/iconv/citrus_iconv.c +++ b/lib/libc/iconv/citrus_iconv.c @@ -126,7 +126,12 @@ open_shared(struct _citrus_iconv_shared * __restrict * __restrict rci, * See gettext-0.18.3+ NEWS: * msgfmt now checks PO file headers more strictly with less * false-positives. - * NetBSD don't do this either. + * NetBSD, also, doesn't do the below pass-through. + * + * Also note that this currently falls short if dst options have been + * specified. It may be the case that we want to ignore EILSEQ, in which + * case we should also select iconv_std anyways. This trick, while + * clever, may not be worth it. */ module = (strcmp(src, dst) != 0) ? "iconv_std" : "iconv_none"; #else @@ -279,7 +284,7 @@ _citrus_iconv_open(struct _citrus_iconv * __restrict * __restrict rcv, { struct _citrus_iconv *cv = NULL; struct _citrus_iconv_shared *ci = NULL; - char realdst[PATH_MAX], realsrc[PATH_MAX]; + char realdst[PATH_MAX], realsrc[PATH_MAX], *slashes; #ifdef _PATH_ICONV char buf[PATH_MAX], path[PATH_MAX]; #endif @@ -293,16 +298,25 @@ _citrus_iconv_open(struct _citrus_iconv * __restrict * __restrict rcv, if ((strcmp(dst, "") == 0) || (strcmp(dst, "char") == 0)) dst = nl_langinfo(CODESET); + strlcpy(realsrc, src, (size_t)PATH_MAX); + if ((slashes = strstr(realsrc, "//")) != NULL) + *slashes = '\0'; + strlcpy(realdst, dst, (size_t)PATH_MAX); + if ((slashes = strstr(realdst, "//")) != NULL) + *slashes = '\0'; + /* resolve codeset name aliases */ #ifdef _PATH_ICONV + /* + * Note that the below reads from realsrc and realdst while it's + * repopulating (writing to) realsrc and realdst, but it's done so with + * a trip through `buf`. + */ snprintf(path, sizeof(path), "%s/%s", _PATH_ICONV, _CITRUS_ICONV_ALIAS); - strlcpy(realsrc, _lookup_alias(path, src, buf, (size_t)PATH_MAX, + strlcpy(realsrc, _lookup_alias(path, realsrc, buf, (size_t)PATH_MAX, _LOOKUP_CASE_IGNORE), (size_t)PATH_MAX); - strlcpy(realdst, _lookup_alias(path, dst, buf, (size_t)PATH_MAX, + strlcpy(realdst, _lookup_alias(path, realdst, buf, (size_t)PATH_MAX, _LOOKUP_CASE_IGNORE), (size_t)PATH_MAX); -#else - strlcpy(realsrc, src, (size_t)PATH_MAX); - strlcpy(realdst, dst, (size_t)PATH_MAX); #endif /* sanity check */