public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Siddhesh Poyarekar <siddhesh@sourceware.org>
To: libc-alpha@sourceware.org
Cc: schwab@linux-m68k.org
Subject: [PATCH] iconvconfig: Fix multiple issues
Date: Fri, 25 Jun 2021 11:39:13 +0530	[thread overview]
Message-ID: <20210625060913.300418-1-siddhesh@sourceware.org> (raw)

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 stpcpy instead of mempcpy so that the directory string is NULL
  terminated

- Do not free fulldir because it is used later while writing out the
  gconv-modules.cache file.
---
 iconv/iconvconfig.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/iconv/iconvconfig.c b/iconv/iconvconfig.c
index e69334d71c..afc40d06cb 100644
--- a/iconv/iconvconfig.c
+++ b/iconv/iconvconfig.c
@@ -656,7 +656,10 @@ handle_dir (const char *dir)
 
   /* 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 *cp = fulldir;
+  if (dir[0] == '/')
+    cp = mempcpy (cp, prefix, prefix_len);
+  cp = stpcpy (cp, dir);
 
   if (dir[dirlen - 1] != '/')
     {
@@ -667,8 +670,6 @@ handle_dir (const char *dir)
 
   found = gconv_parseconfdir (fulldir, dirlen + prefix_len);
 
-  free (fulldir);
-
   if (!found)
     {
       error (0, errno, "failed to open gconv configuration files in `%s'",
-- 
2.31.1


             reply	other threads:[~2021-06-25  6:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-25  6:09 Siddhesh Poyarekar [this message]
2021-06-25  7:26 ` Florian Weimer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210625060913.300418-1-siddhesh@sourceware.org \
    --to=siddhesh@sourceware.org \
    --cc=libc-alpha@sourceware.org \
    --cc=schwab@linux-m68k.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).