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 210223858002 for ; Mon, 13 Sep 2021 15:24:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 210223858002 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 47E4D78350C; Mon, 13 Sep 2021 15:24:10 +0000 (UTC) Received: from pdx1-sub0-mail-a67.g.dreamhost.com (100-96-133-188.trex.outbound.svc.cluster.local [100.96.133.188]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 6E31D783628; Mon, 13 Sep 2021 15:24:08 +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.96.133.188 (trex/6.4.3); Mon, 13 Sep 2021 15:24:09 +0000 X-MC-Relay: Junk X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Share-Army: 4e93923d4a5571e1_1631546649652_3217811497 X-MC-Loop-Signature: 1631546649652:4029966393 X-MC-Ingress-Time: 1631546649651 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 1A1CA7EF5A; Mon, 13 Sep 2021 08:24:08 -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 5071C7EF49; Mon, 13 Sep 2021 08:24:02 -0700 (PDT) X-DH-BACKEND: pdx1-sub0-mail-a67 From: Siddhesh Poyarekar To: libc-stable@sourceware.org Cc: Patrick McCarty , Michael Hudson-Doyle , Andreas Schwab Subject: [COMMITTED 2.34] iconvconfig: Fix behaviour with --prefix [BZ #28199] Date: Mon, 13 Sep 2021 20:53:54 +0530 Message-Id: <20210913152354.204572-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-stable@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-stable mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Sep 2021 15:24:17 -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 Reviewed-by: Andreas Schwab (cherry picked from commit 43cea6d5652b6b9e61ac6ecc69419c909b504f47) --- 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 62bee28769..cc391d8f93 100644 --- a/iconv/gconv_conf.c +++ b/iconv/gconv_conf.c @@ -478,7 +478,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 783b2bbdbb..273a71f673 100644 --- a/iconv/iconvconfig.c +++ b/iconv/iconvconfig.c @@ -653,13 +653,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) { @@ -671,7 +679,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