From: Jakub Jelinek <jakub@redhat.com>
To: Roland McGrath <roland@redhat.com>, Ulrich Drepper <drepper@redhat.com>
Cc: Glibc hackers <libc-hacker@sources.redhat.com>
Subject: [PATCH] Fix localedef
Date: Tue, 22 Oct 2002 07:00:00 -0000 [thread overview]
Message-ID: <20021022153746.X3451@sunsite.ms.mff.cuni.cz> (raw)
Hi!
localedef can create bogus archive if enlarge_archive happens in add_alias
and not in add_locale. The problem is that add_locale_to_archive keeps the
old locrec_offset accross archive enlargement. Another problem is
that add_alias needs to be given exactly the same name as has been passed
to add_locale initially, while it passed name unconditionally in the first
case and already free'd memory in the second case.
2002-10-22 Jakub Jelinek <jakub@redhat.com>
* locale/programs/locarchive.c (add_alias): Change locrec_offset arg
into pointer to locrec_offset.
(add_locale_to_archive): Adjust callers. Free normalized_name right
before returning, not immediately after add_locale, pass it to
add_alias if not NULL instead of name. Rename second normalized_name
occurence to nnormalized_codeset_name.
--- libc/locale/programs/locarchive.c.jj 2002-10-22 15:34:50.000000000 +0200
+++ libc/locale/programs/locarchive.c 2002-10-22 15:34:37.000000000 +0200
@@ -583,8 +583,9 @@ insert_name (struct locarhandle *ah,
static void
add_alias (struct locarhandle *ah, const char *alias, bool replace,
- const char *oldname, uint32_t locrec_offset)
+ const char *oldname, uint32_t *locrec_offset_p)
{
+ uint32_t locrec_offset = *locrec_offset_p;
struct locarhead *head = ah->addr;
const size_t name_len = strlen (alias);
struct namehashent *namehashent = insert_name (ah, alias, strlen (alias),
@@ -607,10 +608,10 @@ add_alias (struct locarhandle *ah, const
namehashent = insert_name (ah, oldname, strlen (oldname), true);
assert (namehashent->name_offset != 0);
assert (namehashent->locrec_offset != 0);
- locrec_offset = namehashent->locrec_offset;
+ *locrec_offset_p = namehashent->locrec_offset;
/* Tail call to try the whole thing again. */
- add_alias (ah, alias, replace, oldname, locrec_offset);
+ add_alias (ah, alias, replace, oldname, locrec_offset_p);
return;
}
@@ -932,9 +933,9 @@ add_locale_to_archive (ah, name, data, r
/* This call does the main work. */
locrec_offset = add_locale (ah, normalized_name ?: name, data, replace);
- free (normalized_name);
if (locrec_offset == 0)
{
+ free (normalized_name);
if (mask & XPG_NORM_CODESET)
free ((char *) normalized_codeset);
return -1;
@@ -953,17 +954,19 @@ add_locale_to_archive (ah, name, data, r
} *filedata = data[LC_CTYPE].addr;
codeset = (char *) filedata
+ filedata->strindex[_NL_ITEM_INDEX (_NL_CTYPE_CODESET_NAME)];
+ char *normalized_codeset_name = NULL;
normalized_codeset = _nl_normalize_codeset (codeset, strlen (codeset));
mask |= XPG_NORM_CODESET;
- asprintf (&normalized_name, "%s%s%s.%s%s%s",
+ asprintf (&normalized_codeset_name, "%s%s%s.%s%s%s",
language, territory == NULL ? "" : "_", territory ?: "",
normalized_codeset,
modifier == NULL ? "" : "@", modifier ?: "");
- add_alias (ah, normalized_name, replace, name, locrec_offset);
- free (normalized_name);
+ add_alias (ah, normalized_codeset_name, replace,
+ normalized_name ?: name, &locrec_offset);
+ free (normalized_codeset_name);
}
/* Now read the locale.alias files looking for lines whose
@@ -1061,7 +1064,7 @@ add_locale_to_archive (ah, name, data, r
&& !strcmp (modifier ?: "", rhs_modifier ?: ""))
/* We have a winner. */
add_alias (ah, alias, replace,
- normalized_name ?: name, locrec_offset);
+ normalized_name ?: name, &locrec_offset);
if (rhs_mask & XPG_NORM_CODESET)
free ((char *) rhs_normalized_codeset);
}
@@ -1083,6 +1086,8 @@ add_locale_to_archive (ah, name, data, r
fclose (fp);
}
+ free (normalized_name);
+
if (mask & XPG_NORM_CODESET)
free ((char *) normalized_codeset);
Jakub
next reply other threads:[~2002-10-22 13:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-10-22 7:00 Jakub Jelinek [this message]
2009-04-27 9:12 Jakub Jelinek
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=20021022153746.X3451@sunsite.ms.mff.cuni.cz \
--to=jakub@redhat.com \
--cc=drepper@redhat.com \
--cc=libc-hacker@sources.redhat.com \
--cc=roland@redhat.com \
/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).