* [PATCH] Reject invalid category values for dcgettext
@ 2002-08-30 11:24 Jakub Jelinek
0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2002-08-30 11:24 UTC (permalink / raw)
To: Ulrich Drepper, Roland McGrath; +Cc: Glibc hackers
Hi!
E.g. dcgettext("foo", "bar", -32) would segfault...
2002-08-30 Jakub Jelinek <jakub@redhat.com>
* intl/dcigettext.c: Include localeinfo.h.
(dcigettext): Check for invalid category values.
(category_to_name): Use _nl_category_names.
--- libc/intl/dcigettext.c.jj 2002-08-05 08:44:15.000000000 +0200
+++ libc/intl/dcigettext.c 2002-08-30 19:57:24.000000000 +0200
@@ -69,6 +69,10 @@ extern int errno;
# include <sys/param.h>
#endif
+#ifdef _LIBC
+# include <locale/localeinfo.h>
+#endif
+
#include "gettextP.h"
#include "plural-exp.h"
#ifdef _LIBC
@@ -391,6 +395,16 @@ DCIGETTEXT (domainname, msgid1, msgid2,
if (msgid1 == NULL)
return NULL;
+ if (category == LC_ALL
+#ifdef _LIBC
+ || category >= (unsigned) __LC_LAST
+#endif
+ )
+ return (plural == 0
+ ? (char *) msgid1
+ /* Use the Germanic plural rule. */
+ : n == 1 ? (char *) msgid1 : (char *) msgid2);
+
__libc_rwlock_rdlock (_nl_state_lock);
/* If DOMAINNAME is NULL, we are interested in the default domain. If
@@ -992,6 +1006,9 @@ internal_function
category_to_name (category)
int category;
{
+#ifdef _LIBC
+ return _nl_category_names[category];
+#else
const char *retval;
switch (category)
@@ -1044,6 +1061,7 @@ category_to_name (category)
}
return retval;
+#endif
}
/* Guess value of current locale from value of the environment variables. */
Jakub
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2002-08-30 18:24 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-30 11:24 [PATCH] Reject invalid category values for dcgettext Jakub Jelinek
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).