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: AS17314 8.43.84.0/22 X-Spam-Status: No, score=-3.4 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,PDS_RDNS_DYNAMIC_FP,RCVD_IN_DNSWL_MED,RDNS_DYNAMIC, SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (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 C66EA1F8C6 for ; Tue, 17 Aug 2021 02:59:35 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 068B23969035 for ; Tue, 17 Aug 2021 02:59:35 +0000 (GMT) Received: from bumble.birch.relay.mailchannels.net (bumble.birch.relay.mailchannels.net [23.83.209.25]) by sourceware.org (Postfix) with ESMTPS id 96801396D804 for ; Tue, 17 Aug 2021 02:59:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 96801396D804 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gotplt.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gotplt.org 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 8C2EF342090 for ; Tue, 17 Aug 2021 02:59:04 +0000 (UTC) Received: from pdx1-sub0-mail-a84.g.dreamhost.com (100-96-133-152.trex.outbound.svc.cluster.local [100.96.133.152]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 9C8E5342190 for ; Tue, 17 Aug 2021 02:59:03 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a84.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.96.133.152 (trex/6.3.3); Tue, 17 Aug 2021 02:59:04 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Skirt-Duck: 562c63e57d5db125_1629169144381_1995697791 X-MC-Loop-Signature: 1629169144381:2741337136 X-MC-Ingress-Time: 1629169144381 Received: from pdx1-sub0-mail-a84.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a84.g.dreamhost.com (Postfix) with ESMTP id 488A288459 for ; Mon, 16 Aug 2021 19:59:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gotplt.org; h=subject:to :references:from:message-id:date:mime-version:in-reply-to :content-type:content-transfer-encoding; s=gotplt.org; bh=33jjH8 fJfNvQ4RR6NY7EGtYN5fY=; b=bYII6OAa1p73EhhjDbikLrSJlDHmqqyamAiMEH uTXIhSLJEBqSr4jHBPFf+7GICSCyVQi8T+9xUfn16jfSJ13lQXBP6O1PW54yLIja YWRMjNpGCyYqdnLcPB5qxQV4MUOEw2BYnNDlILEESs5b9jJ2jHsVr2nxfx05by0F RxZ6o= Received: from [192.168.1.165] (unknown [1.186.101.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a84.g.dreamhost.com (Postfix) with ESMTPSA id 7C28489A99 for ; Mon, 16 Aug 2021 19:59:01 -0700 (PDT) Subject: [PING][PATCH] iconvconfig: Fix behaviour with --prefix [BZ #28199] To: libc-alpha@sourceware.org References: <20210809062740.322823-1-siddhesh@sourceware.org> X-DH-BACKEND: pdx1-sub0-mail-a84 From: Siddhesh Poyarekar Message-ID: <7c7ccf14-978d-473a-78ca-9b2d7854c7e7@gotplt.org> Date: Tue, 17 Aug 2021 08:28:56 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210809062740.322823-1-siddhesh@sourceware.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit 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: , Errors-To: libc-alpha-bounces+e=80x24.org@sourceware.org Sender: "Libc-alpha" Ping! On 8/9/21 11:57 AM, Siddhesh Poyarekar via Libc-alpha wrote: > 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 (); > > for (cnt = 0; __gconv_path_elem[cnt].name != NULL; ++cnt) > - gconv_parseconfdir (__gconv_path_elem[cnt].name, > + gconv_parseconfdir (NULL, __gconv_path_elem[cnt].name, > __gconv_path_elem[cnt].len); > #endif > > 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 @@ > > /* 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"; > +#define GCONV_CONF_FILENAME "gconv-modules" > +static const char gconv_conf_filename[] = GCONV_CONF_FILENAME; > +static const char gconv_conf_dirname[] = GCONV_CONF_FILENAME ".d"; > > 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 *directory, size_t dir_len) > return true; > } > > +/* Prefix DIR (with length DIR_LEN) with PREFIX if the latter is non-NULL 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 = malloc (dir_len + sizeof (gconv_conf_dirname)); > + size_t buflen = dir_len + sizeof (gconv_conf_dirname); > + char *buf = malloc (buflen + (prefix != NULL ? strlen (prefix) : 0)); > + char *cp = buf; > bool found = false; > > if (buf == NULL) > return false; > > - char *cp = mempcpy (mempcpy (buf, dir, dir_len), gconv_conf_filename, > - sizeof (gconv_conf_filename)); > + if (prefix != NULL) > + cp = stpcpy (cp, prefix); > + > + cp = mempcpy (mempcpy (cp, 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); > 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 = NULL; > size_t dirlen = strlen (dir); > bool found = false; > > - char *fulldir = xasprintf ("%s%s%s", dir[0] == '/' ? prefix : "", > - dir, dir[dirlen - 1] != '/' ? "/" : ""); > + /* End directory path with a '/' if it doesn't already. */ > + if (dir[dirlen - 1] != '/') > + { > + newp = xmalloc (dirlen + 2); > + memcpy (newp, dir, dirlen); > + newp[dirlen++] = '/'; > + newp[dirlen] = '\0'; > + dir = newp; > + } > > - found = gconv_parseconfdir (fulldir, strlen (fulldir)); > + found = gconv_parseconfdir (dir[0] == '/' ? prefix : NULL, dir, dirlen); > > if (!found) > { > @@ -671,7 +679,7 @@ handle_dir (const char *dir) > "configuration files with names ending in .conf."); > } > > - free (fulldir); > + free (newp); > > return found ? 0 : 1; > } >