From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from bumble.elm.relay.mailchannels.net (bumble.elm.relay.mailchannels.net [23.83.212.25]) by sourceware.org (Postfix) with ESMTPS id 825D43857419 for ; Mon, 13 Sep 2021 14:38:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 825D43857419 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 BCBE8221C1; Mon, 13 Sep 2021 14:38:11 +0000 (UTC) Received: from pdx1-sub0-mail-a67.g.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id BA9572210A; Mon, 13 Sep 2021 14:38:10 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a67.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.99.42.164 (trex/6.4.3); Mon, 13 Sep 2021 14:38:11 +0000 X-MC-Relay: Junk X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Spill-Shoe: 4de8b2ec05391899_1631543891197_2280709452 X-MC-Loop-Signature: 1631543891197:3194522061 X-MC-Ingress-Time: 1631543891196 Received: from pdx1-sub0-mail-a67.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a67.g.dreamhost.com (Postfix) with ESMTP id 3F5777F5C7; Mon, 13 Sep 2021 07:38:10 -0700 (PDT) Received: from rhbox.intra.reserved-bit.com (unknown [1.186.224.18]) (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-a67.g.dreamhost.com (Postfix) with ESMTPSA id 14D727EF5A; Mon, 13 Sep 2021 07:38:02 -0700 (PDT) X-DH-BACKEND: pdx1-sub0-mail-a67 From: Siddhesh Poyarekar To: libc-alpha@sourceware.org Cc: schwab@linux-m68k.org, arjun@redhat.com, Patrick McCarty , Michael Hudson-Doyle Subject: [PATCH v3] iconvconfig: Fix behaviour with --prefix [BZ #28199] Date: Mon, 13 Sep 2021 20:07:51 +0530 Message-Id: <20210913143751.201035-1-siddhesh@sourceware.org> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3495.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Mon, 13 Sep 2021 14:38:18 -0000 The consolidation of configuration parsing broke behaviour with --prefix, where the prefix bled into the modules cache. Accept a prefix which, when non-NULL, is prepended to the path when looking for configuration files but only the original directory is added to the modules cache. This has no effect on the codegen of gconv_conf since it passes NULL. Reported-by: Patrick McCarty Reported-by: Michael Hudson-Doyle --- Changes from v2: - Drop gconv_conf_dirname. Changes from v1: - Dropped the Signed-off-by that I added accidentally. iconv/gconv_conf.c | 2 +- iconv/gconv_parseconfdir.h | 22 +++++++++++++++------- iconv/iconvconfig.c | 16 ++++++++++++---- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/iconv/gconv_conf.c b/iconv/gconv_conf.c index 09ffe023f9..077082af66 100644 --- a/iconv/gconv_conf.c +++ b/iconv/gconv_conf.c @@ -477,7 +477,7 @@ __gconv_read_conf (void) __gconv_get_path (); =20 for (cnt =3D 0; __gconv_path_elem[cnt].name !=3D NULL; ++cnt) - gconv_parseconfdir (__gconv_path_elem[cnt].name, + gconv_parseconfdir (NULL, __gconv_path_elem[cnt].name, __gconv_path_elem[cnt].len); #endif =20 diff --git a/iconv/gconv_parseconfdir.h b/iconv/gconv_parseconfdir.h index 2f062689ec..a586268abc 100644 --- a/iconv/gconv_parseconfdir.h +++ b/iconv/gconv_parseconfdir.h @@ -39,7 +39,6 @@ /* Name of the file containing the module information in the directories along the path. */ static const char gconv_conf_filename[] =3D "gconv-modules"; -static const char gconv_conf_dirname[] =3D "gconv-modules.d"; =20 static void add_alias (char *); static void add_module (char *, const char *, size_t, int); @@ -110,19 +109,28 @@ read_conf_file (const char *filename, const char *d= irectory, size_t dir_len) return true; } =20 +/* Prefix DIR (with length DIR_LEN) with PREFIX if the latter is non-NUL= L and + parse configuration in it. */ + static __always_inline bool -gconv_parseconfdir (const char *dir, size_t dir_len) +gconv_parseconfdir (const char *prefix, 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 =3D malloc (dir_len + sizeof (gconv_conf_dirname)); + /* No slash needs to be inserted between dir and gconv_conf_filename; = dir + already ends in a slash. The additional 2 is to accommodate the ".= d" + when looking for configuration files in gconv-modules.d. */ + size_t buflen =3D dir_len + sizeof (gconv_conf_filename) + 2; + char *buf =3D malloc (buflen + (prefix !=3D NULL ? strlen (prefix) : 0= )); + char *cp =3D buf; bool found =3D false; =20 if (buf =3D=3D NULL) return false; =20 - char *cp =3D mempcpy (mempcpy (buf, dir, dir_len), gconv_conf_filename= , - sizeof (gconv_conf_filename)); + if (prefix !=3D NULL) + cp =3D stpcpy (cp, prefix); + + cp =3D mempcpy (mempcpy (cp, dir, dir_len), gconv_conf_filename, + sizeof (gconv_conf_filename)); =20 /* Read the gconv-modules configuration file first. */ found =3D read_conf_file (buf, dir, dir_len); diff --git a/iconv/iconvconfig.c b/iconv/iconvconfig.c index fd61cf27fe..a89b62e784 100644 --- a/iconv/iconvconfig.c +++ b/iconv/iconvconfig.c @@ -652,13 +652,21 @@ add_module (char *rp, const char *directory, static int handle_dir (const char *dir) { + char *newp =3D NULL; size_t dirlen =3D strlen (dir); bool found =3D false; =20 - char *fulldir =3D xasprintf ("%s%s%s", dir[0] =3D=3D '/' ? prefix : ""= , - dir, dir[dirlen - 1] !=3D '/' ? "/" : ""); + /* End directory path with a '/' if it doesn't already. */ + if (dir[dirlen - 1] !=3D '/') + { + newp =3D xmalloc (dirlen + 2); + memcpy (newp, dir, dirlen); + newp[dirlen++] =3D '/'; + newp[dirlen] =3D '\0'; + dir =3D newp; + } =20 - found =3D gconv_parseconfdir (fulldir, strlen (fulldir)); + found =3D gconv_parseconfdir (dir[0] =3D=3D '/' ? prefix : NULL, dir, = dirlen); =20 if (!found) { @@ -670,7 +678,7 @@ handle_dir (const char *dir) "configuration files with names ending in .conf."); } =20 - free (fulldir); + free (newp); =20 return found ? 0 : 1; } --=20 2.31.1