From patchwork Thu Jun 10 11:18:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 43815 X-Patchwork-Delegate: dj@redhat.com Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5F0AD398E450 for ; Thu, 10 Jun 2021 11:20:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5F0AD398E450 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623324046; bh=IaGyDmwqAN4tZ3tJ4Z+2yV6AiV6GOfXqle2Yz2qdUIQ=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=jdEyIE0KbRlJCVLOWd8xN5Moas/Wg8dVl45shjhfd+qKg2eb7ifORnwWpmqCIj7h1 woSOntl6QgNYmoV+l2nP7Dcmhv3Qb69MxnjsMBjzCRofZu3tPRfmi6H/xDKJiFOJQT SgzM0vCnB6dtyOHr3VvQ2SEtBR/mMtrqYlvnkgjo= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from eastern.birch.relay.mailchannels.net (eastern.birch.relay.mailchannels.net [23.83.209.55]) by sourceware.org (Postfix) with ESMTPS id F1A50399E04E for ; Thu, 10 Jun 2021 11:19:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F1A50399E04E X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 84D0A341F9D; Thu, 10 Jun 2021 11:19:42 +0000 (UTC) Received: from pdx1-sub0-mail-a13.g.dreamhost.com (100-96-133-111.trex.outbound.svc.cluster.local [100.96.133.111]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id F0F99341FA1; Thu, 10 Jun 2021 11:19:41 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a13.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.96.133.111 (trex/6.3.1); Thu, 10 Jun 2021 11:19:42 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Left-Army: 16e54b286949f880_1623323982307_2367986257 X-MC-Loop-Signature: 1623323982307:97461113 X-MC-Ingress-Time: 1623323982307 Received: from pdx1-sub0-mail-a13.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a13.g.dreamhost.com (Postfix) with ESMTP id A7B4280468; Thu, 10 Jun 2021 11:19:41 +0000 (UTC) Received: from rhbox.intra.reserved-bit.com (unknown [1.186.101.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a13.g.dreamhost.com (Postfix) with ESMTPSA id DEE10800C5; Thu, 10 Jun 2021 11:19:37 +0000 (UTC) X-DH-BACKEND: pdx1-sub0-mail-a13 To: libc-alpha@sourceware.org Subject: [PATCH 1/6] iconv: Remove alloca use in gconv-modules configuration parsing Date: Thu, 10 Jun 2021 16:48:48 +0530 Message-Id: <20210610111853.2286873-2-siddhesh@sourceware.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210610111853.2286873-1-siddhesh@sourceware.org> References: <20210610111853.2286873-1-siddhesh@sourceware.org> MIME-Version: 1.0 X-Spam-Status: No, score=-3494.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Siddhesh Poyarekar via Libc-alpha From: Siddhesh Poyarekar Reply-To: Siddhesh Poyarekar Cc: schwab@linux-m68k.org Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" The alloca sizes ought to be constrained to PATH_MAX, but replace them with dynamic allocation to be safe. A static PATH_MAX array would have worked too but Hurd does not have PATH_MAX and the code path is not hot enough to micro-optimise this allocation. Revisit if any of those realities change. Reviewed-by: DJ Delorie --- iconv/gconv_conf.c | 17 +++++++++-------- iconv/iconvconfig.c | 17 +++++++++++------ 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/iconv/gconv_conf.c b/iconv/gconv_conf.c index c8ad8099a4..3f2cef255b 100644 --- a/iconv/gconv_conf.c +++ b/iconv/gconv_conf.c @@ -559,15 +559,15 @@ __gconv_read_conf (void) for (cnt = 0; __gconv_path_elem[cnt].name != NULL; ++cnt) { -#define BUF_LEN elem_len + sizeof (gconv_conf_dirname) - const char *elem = __gconv_path_elem[cnt].name; size_t elem_len = __gconv_path_elem[cnt].len; - char *buf; /* No slash needs to be inserted between elem and gconv_conf_filename; elem already ends in a slash. */ - buf = alloca (BUF_LEN); + char *buf = malloc (elem_len + sizeof (gconv_conf_dirname)); + if (buf == NULL) + continue; + char *cp = __mempcpy (__mempcpy (buf, elem, elem_len), gconv_conf_filename, sizeof (gconv_conf_filename)); @@ -596,15 +596,16 @@ __gconv_read_conf (void) if (len > strlen (suffix) && strcmp (ent->d_name + len - strlen (suffix), suffix) == 0) { - /* LEN <= PATH_MAX so this alloca is not unbounded. */ - char *conf = alloca (BUF_LEN + len + 1); - cp = stpcpy (conf, buf); - sprintf (cp, "/%s", ent->d_name); + char *conf; + if (__asprintf (&conf, "%s/%s", buf, ent->d_name) < 0) + continue; read_conf_file (conf, elem, elem_len, &modules, &nmodules); + free (conf); } } __closedir (confdir); } + free (buf); } #endif diff --git a/iconv/iconvconfig.c b/iconv/iconvconfig.c index b2a868919c..c9607fb645 100644 --- a/iconv/iconvconfig.c +++ b/iconv/iconvconfig.c @@ -712,7 +712,6 @@ handle_file (const char *dir, const char *infile) static int handle_dir (const char *dir) { -#define BUF_LEN prefix_len + dirlen + sizeof "gconv-modules.d" char *cp; size_t dirlen = strlen (dir); bool found = false; @@ -726,7 +725,10 @@ handle_dir (const char *dir) } /* First, look for a gconv-modules file. */ - char buf[BUF_LEN]; + char *buf = malloc (prefix_len + dirlen + sizeof "gconv-modules.d"); + if (buf == NULL) + goto out; + cp = buf; if (dir[0] == '/') cp = mempcpy (cp, prefix, prefix_len); @@ -756,16 +758,19 @@ handle_dir (const char *dir) if (len > strlen (suffix) && strcmp (ent->d_name + len - strlen (suffix), suffix) == 0) { - /* LEN <= PATH_MAX so this alloca is not unbounded. */ - char *conf = alloca (BUF_LEN + len + 1); - cp = stpcpy (conf, buf); - sprintf (cp, "/%s", ent->d_name); + char *conf; + if (asprintf (&conf, "%s/%s", buf, ent->d_name) < 0) + continue; found |= handle_file (dir, conf); + free (conf); } } closedir (confdir); } + free (buf); + +out: if (!found) { error (0, errno, "failed to open gconv configuration files in `%s'", From patchwork Thu Jun 10 11:18:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 43816 X-Patchwork-Delegate: dj@redhat.com Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C0AF239A0032 for ; Thu, 10 Jun 2021 11:21:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C0AF239A0032 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623324090; bh=S4pDNK4NlswQpQZplvg0mnstRqMmgV8eJ1oSZQ308nM=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=gAQB2y1XwJO/JBFDzaK8uGXnFKqGk+WMXVN451IrlYG1THmbtjeuU6ZPT+WW7Cy/4 yJv2q/NMkOZVJG917E1/Bc3C6oaZndQyCki3+Rit8ozuuJEti5cLzQNlrmN3lJTWno 5VZDMnqPhX/PDGFA+WY7xKEMUis+awDDDh9KBkcA= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from bumble.maple.relay.mailchannels.net (bumble.maple.relay.mailchannels.net [23.83.214.25]) by sourceware.org (Postfix) with ESMTPS id BEA7B39A505D for ; Thu, 10 Jun 2021 11:19:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BEA7B39A505D X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 3E3B63421BC; Thu, 10 Jun 2021 11:19:48 +0000 (UTC) Received: from pdx1-sub0-mail-a13.g.dreamhost.com (100-96-16-76.trex.outbound.svc.cluster.local [100.96.16.76]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 680023421FA; Thu, 10 Jun 2021 11:19:47 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a13.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.96.16.76 (trex/6.3.1); Thu, 10 Jun 2021 11:19:48 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Unite-Attack: 62a6d13427ca0465_1623323988060_2353029261 X-MC-Loop-Signature: 1623323988060:1197891452 X-MC-Ingress-Time: 1623323988060 Received: from pdx1-sub0-mail-a13.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a13.g.dreamhost.com (Postfix) with ESMTP id 18250800C5; Thu, 10 Jun 2021 11:19:47 +0000 (UTC) Received: from rhbox.intra.reserved-bit.com (unknown [1.186.101.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a13.g.dreamhost.com (Postfix) with ESMTPSA id 907757FF19; Thu, 10 Jun 2021 11:19:42 +0000 (UTC) X-DH-BACKEND: pdx1-sub0-mail-a13 To: libc-alpha@sourceware.org Subject: [PATCH 2/6] gconv_conf: Remove unused variables Date: Thu, 10 Jun 2021 16:48:49 +0530 Message-Id: <20210610111853.2286873-3-siddhesh@sourceware.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210610111853.2286873-1-siddhesh@sourceware.org> References: <20210610111853.2286873-1-siddhesh@sourceware.org> MIME-Version: 1.0 X-Spam-Status: No, score=-3494.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Siddhesh Poyarekar via Libc-alpha From: Siddhesh Poyarekar Reply-To: Siddhesh Poyarekar Cc: schwab@linux-m68k.org Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" The modules and nmodules parameters passed to add_modules, add_alias, etc. are not used and are hence unnecessary. Remove them so that their signatures match the functions in iconvconfig. Reviewed-by: DJ Delorie --- iconv/gconv_conf.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/iconv/gconv_conf.c b/iconv/gconv_conf.c index 3f2cef255b..6c6625c37a 100644 --- a/iconv/gconv_conf.c +++ b/iconv/gconv_conf.c @@ -132,7 +132,7 @@ detect_conflict (const char *alias) /* The actual code to add aliases. */ static void -add_alias2 (const char *from, const char *to, const char *wp, void *modules) +add_alias2 (const char *from, const char *to, const char *wp) { /* Test whether this alias conflicts with any available module. */ if (detect_conflict (from)) @@ -161,7 +161,7 @@ add_alias2 (const char *from, const char *to, const char *wp, void *modules) /* Add new alias. */ static void -add_alias (char *rp, void *modules) +add_alias (char *rp) { /* We now expect two more string. The strings are normalized (converted to UPPER case) and strored in the alias database. */ @@ -186,7 +186,7 @@ add_alias (char *rp, void *modules) return; *wp++ = '\0'; - add_alias2 (from, to, wp, modules); + add_alias2 (from, to, wp); } @@ -250,8 +250,7 @@ insert_module (struct gconv_module *newp, int tobefreed) /* Add new module. */ static void -add_module (char *rp, const char *directory, size_t dir_len, void **modules, - size_t *nmodules, int modcounter) +add_module (char *rp, const char *directory, size_t dir_len, int modcounter) { /* We expect now 1. `from' name @@ -364,8 +363,7 @@ add_module (char *rp, const char *directory, size_t dir_len, void **modules, /* Read the next configuration file. */ static void -read_conf_file (const char *filename, const char *directory, size_t dir_len, - void **modules, size_t *nmodules) +read_conf_file (const char *filename, const char *directory, size_t dir_len) { /* Note the file is opened with cancellation in the I/O functions disabled. */ @@ -415,10 +413,10 @@ read_conf_file (const char *filename, const char *directory, size_t dir_len, if (rp - word == sizeof ("alias") - 1 && memcmp (word, "alias", sizeof ("alias") - 1) == 0) - add_alias (rp, *modules); + add_alias (rp); else if (rp - word == sizeof ("module") - 1 && memcmp (word, "module", sizeof ("module") - 1) == 0) - add_module (rp, directory, dir_len, modules, nmodules, modcounter++); + add_module (rp, directory, dir_len, modcounter++); /* else */ /* Otherwise ignore the line. */ } @@ -540,8 +538,6 @@ __gconv_get_path (void) static void __gconv_read_conf (void) { - void *modules = NULL; - size_t nmodules = 0; int save_errno = errno; size_t cnt; @@ -572,7 +568,7 @@ __gconv_read_conf (void) gconv_conf_filename, sizeof (gconv_conf_filename)); /* Read the gconv-modules configuration file first. */ - read_conf_file (buf, elem, elem_len, &modules, &nmodules); + read_conf_file (buf, elem, elem_len); /* Next, see if there is a gconv-modules.d directory containing configuration files and if it is non-empty. */ @@ -599,7 +595,7 @@ __gconv_read_conf (void) char *conf; if (__asprintf (&conf, "%s/%s", buf, ent->d_name) < 0) continue; - read_conf_file (conf, elem, elem_len, &modules, &nmodules); + read_conf_file (conf, elem, elem_len); free (conf); } } @@ -633,7 +629,7 @@ __gconv_read_conf (void) const char *to = __rawmemchr (from, '\0') + 1; cp = __rawmemchr (to, '\0') + 1; - add_alias2 (from, to, cp, modules); + add_alias2 (from, to, cp); } while (*cp != '\0'); From patchwork Thu Jun 10 11:18:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 43817 X-Patchwork-Delegate: dj@redhat.com Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1D3823984C0C for ; Thu, 10 Jun 2021 11:22:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1D3823984C0C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623324136; bh=nmnuu1KJALKmJgBDYqBSvU4HxifsPYLVdTjuj3DCP+8=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=jKybdbbCcRFN02dK39LkNP8Sa8uA82pGPqRucnblA4kRH3hxVjbCiVEVqas4VJObW 9aBnJR4Qc/QtQOYeUG37ogTe60MOCDyY7O5a/+ZqlJFaTSfXpXlCMOlAci9DdoH6YH Y+rGHUn+esz/SouaYJ9Vog2IzemcNAunrBW5U0Dg= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from eastern.birch.relay.mailchannels.net (eastern.birch.relay.mailchannels.net [23.83.209.55]) by sourceware.org (Postfix) with ESMTPS id C75AF39BD42C for ; Thu, 10 Jun 2021 11:19:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C75AF39BD42C X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 6CE0322CF6; Thu, 10 Jun 2021 11:19:52 +0000 (UTC) Received: from pdx1-sub0-mail-a13.g.dreamhost.com (100-96-133-111.trex.outbound.svc.cluster.local [100.96.133.111]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id E24D022C98; Thu, 10 Jun 2021 11:19:51 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a13.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.96.133.111 (trex/6.3.1); Thu, 10 Jun 2021 11:19:52 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Abiding-Ruddy: 6ebbecbc258d11a3_1623323992258_86251955 X-MC-Loop-Signature: 1623323992258:4077380334 X-MC-Ingress-Time: 1623323992257 Received: from pdx1-sub0-mail-a13.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a13.g.dreamhost.com (Postfix) with ESMTP id 8B3CA800C5; Thu, 10 Jun 2021 11:19:51 +0000 (UTC) Received: from rhbox.intra.reserved-bit.com (unknown [1.186.101.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a13.g.dreamhost.com (Postfix) with ESMTPSA id 2387E7FF19; Thu, 10 Jun 2021 11:19:47 +0000 (UTC) X-DH-BACKEND: pdx1-sub0-mail-a13 To: libc-alpha@sourceware.org Subject: [PATCH 3/6] gconv_conf: Split out configuration file processing Date: Thu, 10 Jun 2021 16:48:50 +0530 Message-Id: <20210610111853.2286873-4-siddhesh@sourceware.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210610111853.2286873-1-siddhesh@sourceware.org> References: <20210610111853.2286873-1-siddhesh@sourceware.org> MIME-Version: 1.0 X-Spam-Status: No, score=-3494.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Siddhesh Poyarekar via Libc-alpha From: Siddhesh Poyarekar Reply-To: Siddhesh Poyarekar Cc: schwab@linux-m68k.org Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Split configuration file processing into a separate header file and include it. Macroize all calls that need to go through internal interfaces so that iconvconfig can also use them. Reviewed-by: DJ Delorie --- iconv/gconv_conf.c | 129 +---------------------------- iconv/gconv_parseconfdir.h | 161 +++++++++++++++++++++++++++++++++++++ 2 files changed, 164 insertions(+), 126 deletions(-) create mode 100644 iconv/gconv_parseconfdir.h diff --git a/iconv/gconv_conf.c b/iconv/gconv_conf.c index 6c6625c37a..62bee28769 100644 --- a/iconv/gconv_conf.c +++ b/iconv/gconv_conf.c @@ -19,7 +19,6 @@ #include #include -#include #include #include #include @@ -31,11 +30,10 @@ #include #include #include -#include #include #include - +#include /* This is the default path where we look for module lists. */ static const char default_gconv_path[] = GCONV_PATH; @@ -56,11 +54,6 @@ size_t __gconv_max_path_elem_len; /* We use the following struct if we couldn't allocate memory. */ static const struct path_elem empty_path_elem = { NULL, 0 }; -/* Name of the file containing the module information in the directories - along the path. */ -static const char gconv_conf_filename[] = "gconv-modules"; -static const char gconv_conf_dirname[] = "gconv-modules.d"; - /* Filename extension for the modules. */ #ifndef MODULE_EXT # define MODULE_EXT ".so" @@ -99,9 +92,6 @@ static const char builtin_aliases[] = #undef BUILTIN_ALIAS }; -#include -#define __getdelim(line, len, c, fp) _IO_getdelim (line, len, c, fp) - /* Value of the GCONV_PATH environment variable. */ const char *__gconv_path_envvar; @@ -361,72 +351,6 @@ add_module (char *rp, const char *directory, size_t dir_len, int modcounter) } -/* Read the next configuration file. */ -static void -read_conf_file (const char *filename, const char *directory, size_t dir_len) -{ - /* Note the file is opened with cancellation in the I/O functions - disabled. */ - FILE *fp = fopen (filename, "rce"); - char *line = NULL; - size_t line_len = 0; - static int modcounter; - - /* Don't complain if a file is not present or readable, simply silently - ignore it. */ - if (fp == NULL) - return; - - /* No threads reading from this stream. */ - __fsetlocking (fp, FSETLOCKING_BYCALLER); - - /* Process the known entries of the file. Comments start with `#' and - end with the end of the line. Empty lines are ignored. */ - while (!__feof_unlocked (fp)) - { - char *rp, *endp, *word; - ssize_t n = __getdelim (&line, &line_len, '\n', fp); - if (n < 0) - /* An error occurred. */ - break; - - rp = line; - /* Terminate the line (excluding comments or newline) by an NUL byte - to simplify the following code. */ - endp = strchr (rp, '#'); - if (endp != NULL) - *endp = '\0'; - else - if (rp[n - 1] == '\n') - rp[n - 1] = '\0'; - - while (__isspace_l (*rp, _nl_C_locobj_ptr)) - ++rp; - - /* If this is an empty line go on with the next one. */ - if (rp == endp) - continue; - - word = rp; - while (*rp != '\0' && !__isspace_l (*rp, _nl_C_locobj_ptr)) - ++rp; - - if (rp - word == sizeof ("alias") - 1 - && memcmp (word, "alias", sizeof ("alias") - 1) == 0) - add_alias (rp); - else if (rp - word == sizeof ("module") - 1 - && memcmp (word, "module", sizeof ("module") - 1) == 0) - add_module (rp, directory, dir_len, modcounter++); - /* else */ - /* Otherwise ignore the line. */ - } - - free (line); - - fclose (fp); -} - - /* Determine the directories we are looking for data in. This function should only be called from __gconv_read_conf. */ static void @@ -554,55 +478,8 @@ __gconv_read_conf (void) __gconv_get_path (); for (cnt = 0; __gconv_path_elem[cnt].name != NULL; ++cnt) - { - const char *elem = __gconv_path_elem[cnt].name; - size_t elem_len = __gconv_path_elem[cnt].len; - - /* No slash needs to be inserted between elem and gconv_conf_filename; - elem already ends in a slash. */ - char *buf = malloc (elem_len + sizeof (gconv_conf_dirname)); - if (buf == NULL) - continue; - - char *cp = __mempcpy (__mempcpy (buf, elem, elem_len), - gconv_conf_filename, sizeof (gconv_conf_filename)); - - /* Read the gconv-modules configuration file first. */ - read_conf_file (buf, elem, elem_len); - - /* Next, see if there is a gconv-modules.d directory containing - configuration files and if it is non-empty. */ - cp--; - cp[0] = '.'; - cp[1] = 'd'; - cp[2] = '\0'; - - DIR *confdir = __opendir (buf); - if (confdir != NULL) - { - struct dirent *ent; - while ((ent = __readdir (confdir)) != NULL) - { - if (ent->d_type != DT_REG) - continue; - - size_t len = strlen (ent->d_name); - const char *suffix = ".conf"; - - if (len > strlen (suffix) - && strcmp (ent->d_name + len - strlen (suffix), suffix) == 0) - { - char *conf; - if (__asprintf (&conf, "%s/%s", buf, ent->d_name) < 0) - continue; - read_conf_file (conf, elem, elem_len); - free (conf); - } - } - __closedir (confdir); - } - free (buf); - } + gconv_parseconfdir (__gconv_path_elem[cnt].name, + __gconv_path_elem[cnt].len); #endif /* Add the internal modules. */ diff --git a/iconv/gconv_parseconfdir.h b/iconv/gconv_parseconfdir.h new file mode 100644 index 0000000000..3d4d58d4be --- /dev/null +++ b/iconv/gconv_parseconfdir.h @@ -0,0 +1,161 @@ +/* Handle configuration data. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include + +#if IS_IN (libc) +# include +# define __getdelim(line, len, c, fp) _IO_getdelim (line, len, c, fp) + +# undef isspace +# define isspace(__c) __isspace_l ((__c), _nl_C_locobj_ptr) +# define asprintf __asprintf +# define opendir __opendir +# define readdir __readdir +# define closedir __closedir +# define mempcpy __mempcpy +#endif + +/* Name of the file containing the module information in the directories + along the path. */ +static const char gconv_conf_filename[] = "gconv-modules"; +static const char gconv_conf_dirname[] = "gconv-modules.d"; + +static void add_alias (char *); +static void add_module (char *, const char *, size_t, int); + +/* Read the next configuration file. */ +static bool +read_conf_file (const char *filename, const char *directory, size_t dir_len) +{ + /* Note the file is opened with cancellation in the I/O functions + disabled. */ + FILE *fp = fopen (filename, "rce"); + char *line = NULL; + size_t line_len = 0; + static int modcounter; + + /* Don't complain if a file is not present or readable, simply silently + ignore it. */ + if (fp == NULL) + return false; + + /* No threads reading from this stream. */ + __fsetlocking (fp, FSETLOCKING_BYCALLER); + + /* Process the known entries of the file. Comments start with `#' and + end with the end of the line. Empty lines are ignored. */ + while (!__feof_unlocked (fp)) + { + char *rp, *endp, *word; + ssize_t n = __getdelim (&line, &line_len, '\n', fp); + if (n < 0) + /* An error occurred. */ + break; + + rp = line; + /* Terminate the line (excluding comments or newline) by an NUL byte + to simplify the following code. */ + endp = strchr (rp, '#'); + if (endp != NULL) + *endp = '\0'; + else + if (rp[n - 1] == '\n') + rp[n - 1] = '\0'; + + while (isspace (*rp)) + ++rp; + + /* If this is an empty line go on with the next one. */ + if (rp == endp) + continue; + + word = rp; + while (*rp != '\0' && !isspace (*rp)) + ++rp; + + if (rp - word == sizeof ("alias") - 1 + && memcmp (word, "alias", sizeof ("alias") - 1) == 0) + add_alias (rp); + else if (rp - word == sizeof ("module") - 1 + && memcmp (word, "module", sizeof ("module") - 1) == 0) + add_module (rp, directory, dir_len, modcounter++); + /* else */ + /* Otherwise ignore the line. */ + } + + free (line); + + fclose (fp); + return true; +} + +static __always_inline bool +gconv_parseconfdir (const char *dir, size_t dir_len) +{ + /* No slash needs to be inserted between dir and gconv_conf_filename; + dir already ends in a slash. */ + char *buf = malloc (dir_len + sizeof (gconv_conf_dirname)); + bool found = false; + + if (buf == NULL) + return false; + + char *cp = mempcpy (mempcpy (buf, dir, dir_len), gconv_conf_filename, + sizeof (gconv_conf_filename)); + + /* Read the gconv-modules configuration file first. */ + found = read_conf_file (buf, dir, dir_len); + + /* Next, see if there is a gconv-modules.d directory containing + configuration files and if it is non-empty. */ + cp--; + cp[0] = '.'; + cp[1] = 'd'; + cp[2] = '\0'; + + DIR *confdir = opendir (buf); + if (confdir != NULL) + { + struct dirent *ent; + while ((ent = readdir (confdir)) != NULL) + { + if (ent->d_type != DT_REG) + continue; + + size_t len = strlen (ent->d_name); + const char *suffix = ".conf"; + + if (len > strlen (suffix) + && strcmp (ent->d_name + len - strlen (suffix), suffix) == 0) + { + char *conf; + if (asprintf (&conf, "%s/%s", buf, ent->d_name) < 0) + continue; + found |= read_conf_file (conf, dir, dir_len); + free (conf); + } + } + closedir (confdir); + } + free (buf); + return found; +} From patchwork Thu Jun 10 11:18:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 43818 X-Patchwork-Delegate: dj@redhat.com Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8345239A0016 for ; Thu, 10 Jun 2021 11:23:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8345239A0016 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623324187; bh=TtTf1D2q3gR/lY8p00tNQvLwYP01KxTGmtBA1onfjgE=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=MAEXS1xqnqEWCV41jOoylZ/xuCOZgLi+oW1pMxdahu3v5LyBrCoiwyqT06dymXDLz TEpJMkSzOG8oWeVJup1r9Gh1W7TY0hpgeREGeiC6SVko3qdtxRIfzJuG6c8xemUJ2M 7sKqa3mZgVtvrCvgHKMvTPmeo4TQESRgrlrLPUuw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from cross.elm.relay.mailchannels.net (cross.elm.relay.mailchannels.net [23.83.212.46]) by sourceware.org (Postfix) with ESMTPS id C55C639A0010 for ; Thu, 10 Jun 2021 11:19:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C55C639A0010 X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 012FC34206C; Thu, 10 Jun 2021 11:19:57 +0000 (UTC) Received: from pdx1-sub0-mail-a13.g.dreamhost.com (100-96-17-41.trex.outbound.svc.cluster.local [100.96.17.41]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 7FF11341EB1; Thu, 10 Jun 2021 11:19:56 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a13.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.96.17.41 (trex/6.3.1); Thu, 10 Jun 2021 11:19:56 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Plucky-Tangy: 0b05f25d666db7b9_1623323996800_137689112 X-MC-Loop-Signature: 1623323996800:1116579169 X-MC-Ingress-Time: 1623323996800 Received: from pdx1-sub0-mail-a13.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a13.g.dreamhost.com (Postfix) with ESMTP id 1692A800C5; Thu, 10 Jun 2021 11:19:56 +0000 (UTC) Received: from rhbox.intra.reserved-bit.com (unknown [1.186.101.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a13.g.dreamhost.com (Postfix) with ESMTPSA id 78BDD7FF19; Thu, 10 Jun 2021 11:19:51 +0000 (UTC) X-DH-BACKEND: pdx1-sub0-mail-a13 To: libc-alpha@sourceware.org Subject: [PATCH 4/6] iconvconfig: Use common gconv module parsing function Date: Thu, 10 Jun 2021 16:48:51 +0530 Message-Id: <20210610111853.2286873-5-siddhesh@sourceware.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210610111853.2286873-1-siddhesh@sourceware.org> References: <20210610111853.2286873-1-siddhesh@sourceware.org> MIME-Version: 1.0 X-Spam-Status: No, score=-3494.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Siddhesh Poyarekar via Libc-alpha From: Siddhesh Poyarekar Reply-To: Siddhesh Poyarekar Cc: schwab@linux-m68k.org Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Drop local copy of gconv file parsing and use the one in gconv_parseconfdir.h instead. Now there is a single implementation of configuration file parsing. --- iconv/iconvconfig.c | 126 ++++---------------------------------------- 1 file changed, 11 insertions(+), 115 deletions(-) diff --git a/iconv/iconvconfig.c b/iconv/iconvconfig.c index c9607fb645..53e5c5c6f4 100644 --- a/iconv/iconvconfig.c +++ b/iconv/iconvconfig.c @@ -18,7 +18,6 @@ #include #include -#include #include #include #include @@ -34,10 +33,10 @@ #include #include #include -#include #include #include "iconvconfig.h" +#include /* Get libc version number. */ #include "../version.h" @@ -568,7 +567,7 @@ new_module (const char *fromname, size_t fromlen, const char *toname, /* Add new module. */ static void -add_module (char *rp, const char *directory) +add_module (char *rp, const char *directory, size_t dirlen, int modcount) { /* We expect now 1. `from' name @@ -646,131 +645,28 @@ add_module (char *rp, const char *directory) cost, need_ext); } -/* Read a gconv-modules configuration file. */ -static bool -handle_file (const char *dir, const char *infile) -{ - FILE *fp; - char *line = NULL; - size_t linelen = 0; - - fp = fopen (infile, "r"); - if (fp == NULL) - return false; - - /* No threads present. */ - __fsetlocking (fp, FSETLOCKING_BYCALLER); - - while (!feof_unlocked (fp)) - { - char *rp, *endp, *word; - ssize_t n = __getdelim (&line, &linelen, '\n', fp); - - if (n < 0) - /* An error occurred. */ - break; - - rp = line; - /* Terminate the line (excluding comments or newline) with a NUL - byte to simplify the following code. */ - endp = strchr (rp, '#'); - if (endp != NULL) - *endp = '\0'; - else - if (rp[n - 1] == '\n') - rp[n - 1] = '\0'; - - while (isspace (*rp)) - ++rp; - - /* If this is an empty line go on with the next one. */ - if (rp == endp) - continue; - - word = rp; - while (*rp != '\0' && !isspace (*rp)) - ++rp; - - if (rp - word == sizeof ("alias") - 1 - && memcmp (word, "alias", sizeof ("alias") - 1) == 0) - add_alias (rp); - else if (rp - word == sizeof ("module") - 1 - && memcmp (word, "module", sizeof ("module") - 1) == 0) - add_module (rp, dir); - /* else */ - /* Otherwise ignore the line. */ - } - - free (line); - - fclose (fp); - - return true; -} - /* Read config files and add the data for this directory to cache. */ static int handle_dir (const char *dir) { - char *cp; size_t dirlen = strlen (dir); bool found = false; + /* Add the prefix before sending it off to the parser. */ + char *fulldir = xmalloc (prefix_len + dirlen + 2); + char *cp = mempcpy (mempcpy (fulldir, prefix, prefix_len), dir, dirlen); + if (dir[dirlen - 1] != '/') { - char *newp = (char *) xmalloc (dirlen + 2); - dir = memcpy (newp, dir, dirlen); - newp[dirlen++] = '/'; - newp[dirlen] = '\0'; + *cp++ = '/'; + *cp = '\0'; + dirlen += 2; } - /* First, look for a gconv-modules file. */ - char *buf = malloc (prefix_len + dirlen + sizeof "gconv-modules.d"); - if (buf == NULL) - goto out; - - cp = buf; - if (dir[0] == '/') - cp = mempcpy (cp, prefix, prefix_len); - cp = mempcpy (cp, dir, dirlen); - cp = stpcpy (cp, "gconv-modules"); - - found |= handle_file (dir, buf); - - /* Next, see if there is a gconv-modules.d directory containing configuration - files and if it is non-empty. */ - cp[0] = '.'; - cp[1] = 'd'; - cp[2] = '\0'; - - DIR *confdir = opendir (buf); - if (confdir != NULL) - { - struct dirent *ent; - while ((ent = readdir (confdir)) != NULL) - { - if (ent->d_type != DT_REG) - continue; - - size_t len = strlen (ent->d_name); - const char *suffix = ".conf"; - - if (len > strlen (suffix) - && strcmp (ent->d_name + len - strlen (suffix), suffix) == 0) - { - char *conf; - if (asprintf (&conf, "%s/%s", buf, ent->d_name) < 0) - continue; - found |= handle_file (dir, conf); - free (conf); - } - } - closedir (confdir); - } + found = gconv_parseconfdir (fulldir, dirlen + prefix_len); - free (buf); + free (fulldir); -out: if (!found) { error (0, errno, "failed to open gconv configuration files in `%s'", From patchwork Thu Jun 10 11:18:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 43819 X-Patchwork-Delegate: dj@redhat.com Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 14B6C398A41A for ; Thu, 10 Jun 2021 11:23:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 14B6C398A41A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623324233; bh=xN0JoeyrGOoZJ4k/lExlydKRFv7cpTdDQ8NlBI+oDmo=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=SskJcbQbO117gTy94ceb3V8Kz7NoBoLNnubrw2Rhq2hrEJ8puPD9QvE5aVXwmadxB bVDiANXNp7bqc6ZPyo5KaWgDOgMAKSTJ60Xe7vXKltKnQjL1k5wGnD730SQGxymdhS 4Y+brS3psSfzabEd+uYTHNCw9wLpfC/zQCShLxrQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from crocodile.elm.relay.mailchannels.net (crocodile.elm.relay.mailchannels.net [23.83.212.45]) by sourceware.org (Postfix) with ESMTPS id 56D20399E040 for ; Thu, 10 Jun 2021 11:20:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 56D20399E040 X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id CEA974026C5; Thu, 10 Jun 2021 11:20:00 +0000 (UTC) Received: from pdx1-sub0-mail-a13.g.dreamhost.com (100-98-55-29.trex.outbound.svc.cluster.local [100.98.55.29]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 40D4A402B99; Thu, 10 Jun 2021 11:20:00 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a13.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.98.55.29 (trex/6.3.1); Thu, 10 Jun 2021 11:20:00 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Lonely-Little: 6f16b5573a0d8f16_1623324000628_4019447868 X-MC-Loop-Signature: 1623324000628:3843803844 X-MC-Ingress-Time: 1623324000627 Received: from pdx1-sub0-mail-a13.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a13.g.dreamhost.com (Postfix) with ESMTP id EF62E800C5; Thu, 10 Jun 2021 11:19:59 +0000 (UTC) Received: from rhbox.intra.reserved-bit.com (unknown [1.186.101.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a13.g.dreamhost.com (Postfix) with ESMTPSA id 0C67E7FF19; Thu, 10 Jun 2021 11:19:56 +0000 (UTC) X-DH-BACKEND: pdx1-sub0-mail-a13 To: libc-alpha@sourceware.org Subject: [PATCH 5/6] Handle DT_UNKNOWN in gconv-modules.d Date: Thu, 10 Jun 2021 16:48:52 +0530 Message-Id: <20210610111853.2286873-6-siddhesh@sourceware.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210610111853.2286873-1-siddhesh@sourceware.org> References: <20210610111853.2286873-1-siddhesh@sourceware.org> MIME-Version: 1.0 X-Spam-Status: No, score=-3494.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Siddhesh Poyarekar via Libc-alpha From: Siddhesh Poyarekar Reply-To: Siddhesh Poyarekar Cc: schwab@linux-m68k.org Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" On filesystems that do not support dt_type, a regular file shows up as DT_UNKNOWN. Fall back to using lstat64 to read file properties in such cases. Reviewed-by: DJ Delorie --- iconv/gconv_parseconfdir.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/iconv/gconv_parseconfdir.h b/iconv/gconv_parseconfdir.h index 3d4d58d4be..e73ea0ff5c 100644 --- a/iconv/gconv_parseconfdir.h +++ b/iconv/gconv_parseconfdir.h @@ -32,6 +32,7 @@ # define readdir __readdir # define closedir __closedir # define mempcpy __mempcpy +# define lstat64 __lstat64 #endif /* Name of the file containing the module information in the directories @@ -138,7 +139,7 @@ gconv_parseconfdir (const char *dir, size_t dir_len) struct dirent *ent; while ((ent = readdir (confdir)) != NULL) { - if (ent->d_type != DT_REG) + if (ent->d_type != DT_REG && ent->d_type != DT_UNKNOWN) continue; size_t len = strlen (ent->d_name); @@ -148,8 +149,14 @@ gconv_parseconfdir (const char *dir, size_t dir_len) && strcmp (ent->d_name + len - strlen (suffix), suffix) == 0) { char *conf; + struct stat64 st; if (asprintf (&conf, "%s/%s", buf, ent->d_name) < 0) continue; + if (ent->d_type == DT_UNKNOWN + && (lstat64 (conf, &st) == -1 + || !S_ISREG (st.st_mode))) + continue; + found |= read_conf_file (conf, dir, dir_len); free (conf); } From patchwork Thu Jun 10 11:18:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 43820 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5D65339B5C2E for ; Thu, 10 Jun 2021 11:24:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5D65339B5C2E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623324277; bh=4ALyHcna7cXh8kjixSzO4Uh3m/c+dwdTDWSwNDX0FMM=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=wwonLeuYgmkNpNdIS1ptgo272Ha7Y5/cssaf7yApEY46NtFtnJz1GJXomXqlSqk6Q J+X/UyEg8IM/8dEwarue59To7Jy6gEe1Efg8iLRYD46lkVcKu0IYKM697UNxnG6Ve+ kZtA31L9pYSx5VoYbUpQqUJpnPiSpeoCqhELitPI= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from anteater.oak.relay.mailchannels.net (anteater.oak.relay.mailchannels.net [23.83.215.3]) by sourceware.org (Postfix) with ESMTPS id 8303A398E44A for ; Thu, 10 Jun 2021 11:20:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8303A398E44A Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id DA19A122C63; Thu, 10 Jun 2021 11:20:15 +0000 (UTC) Received: from pdx1-sub0-mail-a13.g.dreamhost.com (100-96-16-76.trex.outbound.svc.cluster.local [100.96.16.76]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 69A23122C56; Thu, 10 Jun 2021 11:20:05 +0000 (UTC) Received: from pdx1-sub0-mail-a13.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.96.16.76 (trex/6.3.1); Thu, 10 Jun 2021 11:20:15 +0000 Received: from pdx1-sub0-mail-a13.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a13.g.dreamhost.com (Postfix) with ESMTP id 24861800C5; Thu, 10 Jun 2021 11:20:05 +0000 (UTC) Received: from rhbox.intra.reserved-bit.com (unknown [1.186.101.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a13.g.dreamhost.com (Postfix) with ESMTPSA id E2F5B7FF19; Thu, 10 Jun 2021 11:20:00 +0000 (UTC) X-DH-BACKEND: pdx1-sub0-mail-a13 To: libc-alpha@sourceware.org Subject: [PATCH 6/6] Add NEWS item for gconv-modules.d change Date: Thu, 10 Jun 2021 16:48:53 +0530 Message-Id: <20210610111853.2286873-7-siddhesh@sourceware.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210610111853.2286873-1-siddhesh@sourceware.org> References: <20210610111853.2286873-1-siddhesh@sourceware.org> MIME-Version: 1.0 X-Spam-Status: No, score=-3494.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Siddhesh Poyarekar via Libc-alpha From: Siddhesh Poyarekar Reply-To: Siddhesh Poyarekar Cc: schwab@linux-m68k.org Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" --- NEWS | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/NEWS b/NEWS index 1bf3daa502..605d53b256 100644 --- a/NEWS +++ b/NEWS @@ -31,6 +31,12 @@ Major new features: __STDC_WANT_IEC_60559_BFP_EXT__, as specified in TS 18661-1, is defined, and when _GNU_SOURCE is defined. +* Configuration files for iconv converter modules have moved from the single + gconv-modules file to a directory gconv-modules.d containing multiple + configuration files with names ending with .conf. The configuration parser + continues to also support parsing the gconv-modules file in $GCONV_PATH for + backward compatibility. + Deprecated and removed features, and other changes affecting compatibility: * The function pthread_mutex_consistent_np has been deprecated; programs