From patchwork Mon Aug 9 06:27:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 1514925 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=FXUz7d0B; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4GjmPx55Ztz9sWS for ; Mon, 9 Aug 2021 16:29:08 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 352DC385742D for ; Mon, 9 Aug 2021 06:29:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 352DC385742D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1628490541; 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=FXUz7d0BfKKfuvwAkHRH/QqUKYXd3K57iVaBpqmyoW+TWXPsoFISNuNQJEUsE4fO0 P+nZ+AK0Drm8UTjbVIiBFPubfZB7R3AYe4zozweIpGKCCzZi8ZVuK8qun7r/x4ypUR ldpEbmGBWlpnUc8tsqXQoq6IkwWtYZ5BAhsOmV1E= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org 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 X-Spam-Status: No, score=-3494.0 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.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-Patchwork-Original-From: Siddhesh Poyarekar via Libc-alpha From: Siddhesh Poyarekar Reply-To: Siddhesh Poyarekar Cc: Patrick McCarty Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.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 (); 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; }