From patchwork Mon Sep 13 13:26:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 44947 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 32D0D3857C7A for ; Mon, 13 Sep 2021 13:27:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 32D0D3857C7A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1631539645; bh=W9xkvx6rUuUJk/c5szV2LYf4mU1VuCJ2T5gLOMpVciQ=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=QjPu+st2Rrsgc5iduoK6akSKkHDK/DmvZMxpXepDq+wuWxvAPOf6mGCc6SAPy79Zq aljxiPvxVmbB2KMe0ORjOrr9R02u8zZ4X4WY1kB6wRt2rnKp1K5aOMJvGPiHgzwFiv 2wDO6yxatdGt8dD29dTqMxXypwQtyV7ngczJgiAk= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from cadetblue.ash.relay.mailchannels.net (cadetblue.ash.relay.mailchannels.net [23.83.222.28]) by sourceware.org (Postfix) with ESMTPS id BDCF3385783E for ; Mon, 13 Sep 2021 13:26:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BDCF3385783E 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 4EB207625E3; Mon, 13 Sep 2021 13:26:55 +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 B8268762738; Mon, 13 Sep 2021 13:26:54 +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.114.12.118 (trex/6.4.3); Mon, 13 Sep 2021 13:26:55 +0000 X-MC-Relay: Junk X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Illustrious-Tangy: 2d6a2eb734f98d49_1631539615121_1778684523 X-MC-Loop-Signature: 1631539615120:2533417076 X-MC-Ingress-Time: 1631539615120 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 75A9C7ECE8; Mon, 13 Sep 2021 06:26:54 -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 BE3597EF5A; Mon, 13 Sep 2021 06:26:47 -0700 (PDT) X-DH-BACKEND: pdx1-sub0-mail-a67 To: libc-alpha@sourceware.org Subject: [PATCH v2] iconvconfig: Fix behaviour with --prefix [BZ #28199] Date: Mon, 13 Sep 2021 18:56:35 +0530 Message-Id: <20210913132635.67314-1-siddhesh@sourceware.org> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Spam-Status: No, score=-3495.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, 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+patchwork=sourceware.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 --- Changes from v1: - Dropped the Signed-off-by that I added accidentally. 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 09ffe023f9..077082af66 100644 --- a/iconv/gconv_conf.c +++ b/iconv/gconv_conf.c @@ -477,7 +477,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 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 = 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) { @@ -670,7 +678,7 @@ handle_dir (const char *dir) "configuration files with names ending in .conf."); } - free (fulldir); + free (newp); return found ? 0 : 1; }