From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Status: No, score=-4.1 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id DD0B21F8C6 for ; Mon, 9 Aug 2021 06:29:07 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2EAD13890416 for ; Mon, 9 Aug 2021 06:29:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2EAD13890416 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1628490546; bh=v5hZ7sUSUc9JYvN8G+DjMXP3ARvpdLDBrIeldZ30nzA=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=GVazdZRZ6VJmPgDDyU7pzLrEHISx4TaldM3D87eHETFxsy1c5kh26jYsl/8vU2YZ9 P9GUrTkXP2DeX5EZEEoJs1738zrOhzf88brSlNULyt7twnT73b87Q3P6BkqZba7C89 G8iIJgyVvhgNGXptmySUJc84BwYca95aA11u+gzs= Received: from dormouse.elm.relay.mailchannels.net (dormouse.elm.relay.mailchannels.net [23.83.212.50]) by sourceware.org (Postfix) with ESMTPS id 7AE7A3855019 for ; Mon, 9 Aug 2021 06:28:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7AE7A3855019 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 20199322320; Mon, 9 Aug 2021 06:28:37 +0000 (UTC) Received: from pdx1-sub0-mail-a30.g.dreamhost.com (100-96-16-104.trex-nlb.outbound.svc.cluster.local [100.96.16.104]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 7495032198B; Mon, 9 Aug 2021 06:28:35 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a30.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.96.16.104 (trex/6.3.3); Mon, 09 Aug 2021 06:28:36 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Obese-Spot: 42cd1080647d4fa1_1628490516435_3201858892 X-MC-Loop-Signature: 1628490516435:2259332128 X-MC-Ingress-Time: 1628490516435 Received: from pdx1-sub0-mail-a30.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a30.g.dreamhost.com (Postfix) with ESMTP id 2A38E7EEC0; Sun, 8 Aug 2021 23:28:35 -0700 (PDT) Received: from rhbox.redhat.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-a30.g.dreamhost.com (Postfix) with ESMTPSA id 7470F7E435; Sun, 8 Aug 2021 23:28:28 -0700 (PDT) X-DH-BACKEND: pdx1-sub0-mail-a30 To: libc-alpha@sourceware.org Subject: [PATCH] iconvconfig: Fix behaviour with --prefix [BZ #28199] Date: Mon, 9 Aug 2021 11:57:40 +0530 Message-Id: <20210809062740.322823-1-siddhesh@sourceware.org> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: , From: Siddhesh Poyarekar via Libc-alpha Reply-To: Siddhesh Poyarekar Cc: Patrick McCarty Errors-To: libc-alpha-bounces+e=80x24.org@sourceware.org Sender: "Libc-alpha" 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 Signed-off-by: Siddhesh Poyarekar --- iconv/gconv_conf.c | 2 +- iconv/gconv_parseconfdir.h | 21 +++++++++++++++------ iconv/iconvconfig.c | 16 ++++++++++++---- 3 files changed, 28 insertions(+), 11 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..38ffa9353a 100644 --- a/iconv/gconv_parseconfdir.h +++ b/iconv/gconv_parseconfdir.h @@ -38,8 +38,9 @@ =20 /* 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"; +#define GCONV_CONF_FILENAME "gconv-modules" +static const char gconv_conf_filename[] =3D GCONV_CONF_FILENAME; +static const char gconv_conf_dirname[] =3D GCONV_CONF_FILENAME ".d"; =20 static void add_alias (char *); static void add_module (char *, const char *, size_t, int); @@ -110,19 +111,27 @@ 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)); + size_t buflen =3D dir_len + sizeof (gconv_conf_dirname); + 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