From patchwork Fri Jun 25 09:01:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 44019 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 995AF39C19D9 for ; Fri, 25 Jun 2021 09:02:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 995AF39C19D9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1624611735; bh=1znYM0/c3P2A13VZYVeeLM2oUBGUcnhwWUmVNNhUD9c=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=q5jgIC1JmINVALLmlUziPHWDToiquhF+QhUwL0jHFH6mLjsD+RVQQL7vmraMKfFgQ Wzecs6yqR03Qb+V/H/VAm6kCer4mScQuyaCefCD6aDUeWS5d5OFL7CkF4GCjvpyDvp Ev2HwCKP8Ntet8i/kc5hDUeemiEBAyNt7Y6hWqiw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from bird.elm.relay.mailchannels.net (bird.elm.relay.mailchannels.net [23.83.212.17]) by sourceware.org (Postfix) with ESMTPS id 9ADDD39C19CC for ; Fri, 25 Jun 2021 09:01:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9ADDD39C19CC 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 D40E6102A12; Fri, 25 Jun 2021 09:01:45 +0000 (UTC) Received: from pdx1-sub0-mail-a75.g.dreamhost.com (100-96-13-105.trex.outbound.svc.cluster.local [100.96.13.105]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id EA1C610251F; Fri, 25 Jun 2021 09:01:44 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a75.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.96.13.105 (trex/6.3.3); Fri, 25 Jun 2021 09:01:45 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Whispering-Well-Made: 12f687ce62977045_1624611705480_837427618 X-MC-Loop-Signature: 1624611705480:706426547 X-MC-Ingress-Time: 1624611705480 Received: from pdx1-sub0-mail-a75.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a75.g.dreamhost.com (Postfix) with ESMTP id 8881D8C382; Fri, 25 Jun 2021 02:01:44 -0700 (PDT) Received: from rhbox.intra.reserved-bit.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-a75.g.dreamhost.com (Postfix) with ESMTPSA id 3DEF28C37A; Fri, 25 Jun 2021 02:01:40 -0700 (PDT) X-DH-BACKEND: pdx1-sub0-mail-a75 To: libc-alpha@sourceware.org Subject: [PATCH v2] iconvconfig: Fix multiple issues Date: Fri, 25 Jun 2021 14:31:28 +0530 Message-Id: <20210625090128.316837-1-siddhesh@sourceware.org> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Spam-Status: No, score=-3494.6 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: fweimer@redhat.com, schwab@linux-m68k.org Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" It was noticed on big-endian systems that msgfmt would fail with the following error: msgfmt: gconv_builtin.c:70: __gconv_get_builtin_trans: Assertion `cnt < sizeof (map) / sizeof (map[0])' failed. Aborted (core dumped) This is only seen on installed systems because it was due to a corrupted gconv-modules.cache. iconvconfig had the following issues (it was specifically freeing fulldir that caused this issue, but other cleanups are also needed) that this patch fixes. - Add prefix only if dir starts with '/' - Use asprintf instead of mempcpy so that the directory string is NULL terminated - Make a copy of the directory reference in new_module so that fulldir can be freed within the same scope in handle_dir. --- iconv/Makefile | 2 +- iconv/iconvconfig.c | 24 +++++++++--------------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/iconv/Makefile b/iconv/Makefile index a9b267c851..07d77c9eca 100644 --- a/iconv/Makefile +++ b/iconv/Makefile @@ -33,7 +33,7 @@ vpath %.c ../locale/programs ../intl iconv_prog-modules = iconv_charmap charmap charmap-dir linereader \ dummy-repertoire simple-hash xstrdup xmalloc \ record-status -iconvconfig-modules = strtab xmalloc hash-string +iconvconfig-modules = strtab xmalloc xasprintf xstrdup hash-string extra-objs = $(iconv_prog-modules:=.o) $(iconvconfig-modules:=.o) CFLAGS-iconv_prog.c += -I../locale/programs CFLAGS-iconv_charmap.c += -I../locale/programs diff --git a/iconv/iconvconfig.c b/iconv/iconvconfig.c index e69334d71c..783b2bbdbb 100644 --- a/iconv/iconvconfig.c +++ b/iconv/iconvconfig.c @@ -250,6 +250,7 @@ static const char gconv_module_ext[] = MODULE_EXT; #include +#include /* C string table handling. */ @@ -519,11 +520,12 @@ module_compare (const void *p1, const void *p2) /* Create new module record. */ static void new_module (const char *fromname, size_t fromlen, const char *toname, - size_t tolen, const char *directory, + size_t tolen, const char *dir_in, const char *filename, size_t filelen, int cost, size_t need_ext) { struct module *new_module; - size_t dirlen = strlen (directory) + 1; + size_t dirlen = strlen (dir_in) + 1; + const char *directory = xstrdup (dir_in); char *tmp; void **inserted; @@ -654,20 +656,10 @@ handle_dir (const char *dir) size_t dirlen = strlen (dir); bool found = false; - /* Add the prefix before sending it off to the parser. */ - char *fulldir = xmalloc (prefix_len + dirlen + 2); - char *cp = mempcpy (mempcpy (fulldir, prefix, prefix_len), dir, dirlen); + char *fulldir = xasprintf ("%s%s%s", dir[0] == '/' ? prefix : "", + dir, dir[dirlen - 1] != '/' ? "/" : ""); - if (dir[dirlen - 1] != '/') - { - *cp++ = '/'; - *cp = '\0'; - dirlen++; - } - - found = gconv_parseconfdir (fulldir, dirlen + prefix_len); - - free (fulldir); + found = gconv_parseconfdir (fulldir, strlen (fulldir)); if (!found) { @@ -679,6 +671,8 @@ handle_dir (const char *dir) "configuration files with names ending in .conf."); } + free (fulldir); + return found ? 0 : 1; }