From 14e0811e01ceba4ef5fa9162ab5baa73957fa1ee Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Thu, 15 Feb 2024 10:48:50 +0100 Subject: [PATCH] localename: Add parameter validation. * lib/localename.c (get_locale_t_name, gl_locale_name_thread_unsafe, gl_locale_name_thread, gl_locale_name_posix, gl_locale_name): Verify that the category argument is not LC_ALL. --- ChangeLog | 7 +++++++ lib/localename.c | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/ChangeLog b/ChangeLog index 023c1d4d50..531d5ffa57 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2024-02-15 Bruno Haible + + localename: Add parameter validation. + * lib/localename.c (get_locale_t_name, gl_locale_name_thread_unsafe, + gl_locale_name_thread, gl_locale_name_posix, gl_locale_name): Verify + that the category argument is not LC_ALL. + 2024-02-14 Bruno Haible localename: Notice setlocale() invocations on more platforms. diff --git a/lib/localename.c b/lib/localename.c index 3bfcdabf4f..72f773bbed 100644 --- a/lib/localename.c +++ b/lib/localename.c @@ -2730,6 +2730,9 @@ struniq (const char *string) static const char * get_locale_t_name (int category, locale_t locale) { + if (category == LC_ALL) + /* Invalid argument. */ + abort (); if (locale == LC_GLOBAL_LOCALE) { /* Query the global locale. */ @@ -3105,6 +3108,9 @@ static const char * gl_locale_name_thread_unsafe (int category, _GL_UNUSED const char *categoryname) { + if (category == LC_ALL) + /* Invalid argument. */ + abort (); # if HAVE_GOOD_USELOCALE { locale_t thread_locale = uselocale (NULL); @@ -3282,6 +3288,9 @@ gl_locale_name_thread_unsafe (int category, _GL_UNUSED const char *categoryname) const char * gl_locale_name_thread (int category, _GL_UNUSED const char *categoryname) { + if (category == LC_ALL) + /* Invalid argument. */ + abort (); #if HAVE_GOOD_USELOCALE const char *name = gl_locale_name_thread_unsafe (category, categoryname); if (name != NULL) @@ -3328,6 +3337,9 @@ gl_locale_name_thread (int category, _GL_UNUSED const char *categoryname) const char * gl_locale_name_posix (int category, _GL_UNUSED const char *categoryname) { + if (category == LC_ALL) + /* Invalid argument. */ + abort (); #if defined WINDOWS_NATIVE if (LC_MIN <= category && category <= LC_MAX) { @@ -3531,6 +3543,10 @@ gl_locale_name (int category, const char *categoryname) { const char *retval; + if (category == LC_ALL) + /* Invalid argument. */ + abort (); + retval = gl_locale_name_thread (category, categoryname); if (retval != NULL) return retval; -- 2.39.5