From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 From: Siddhesh Poyarekar To: libc-alpha@sourceware.org Cc: schwab@linux-m68k.org, fweimer@redhat.com 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 Content-Transfer-Encoding: quoted-printable 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-List-Received-Date: Fri, 25 Jun 2021 09:01:51 -0000 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 < s= izeof (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 =3D iconv_charmap charmap charmap-dir linereader \ dummy-repertoire simple-hash xstrdup xmalloc \ record-status -iconvconfig-modules =3D strtab xmalloc hash-string +iconvconfig-modules =3D strtab xmalloc xasprintf xstrdup hash-string extra-objs =3D $(iconv_prog-modules:=3D.o) $(iconvconfig-modules:=3D.= o) CFLAGS-iconv_prog.c +=3D -I../locale/programs CFLAGS-iconv_charmap.c +=3D -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[] =3D MODULE_EXT; =20 =20 #include +#include =20 =20 /* 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 =3D strlen (directory) + 1; + size_t dirlen =3D strlen (dir_in) + 1; + const char *directory =3D xstrdup (dir_in); char *tmp; void **inserted; =20 @@ -654,20 +656,10 @@ handle_dir (const char *dir) size_t dirlen =3D strlen (dir); bool found =3D false; =20 - /* Add the prefix before sending it off to the parser. */ - char *fulldir =3D xmalloc (prefix_len + dirlen + 2); - char *cp =3D mempcpy (mempcpy (fulldir, prefix, prefix_len), dir, dirl= en); + char *fulldir =3D xasprintf ("%s%s%s", dir[0] =3D=3D '/' ? prefix : ""= , + dir, dir[dirlen - 1] !=3D '/' ? "/" : ""); =20 - if (dir[dirlen - 1] !=3D '/') - { - *cp++ =3D '/'; - *cp =3D '\0'; - dirlen++; - } - - found =3D gconv_parseconfdir (fulldir, dirlen + prefix_len); - - free (fulldir); + found =3D gconv_parseconfdir (fulldir, strlen (fulldir)); =20 if (!found) { @@ -679,6 +671,8 @@ handle_dir (const char *dir) "configuration files with names ending in .conf."); } =20 + free (fulldir); + return found ? 0 : 1; } =20 --=20 2.31.1