diff options
author | Colin Watson <cjwatson@debian.org> | 2022-01-02 00:23:31 +0000 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2022-01-02 00:23:31 +0000 |
commit | 2ce26131ac9cb7444367c809f674624320e8e8e2 (patch) | |
tree | cef71b40802559deadd250ee5340376bdec4d080 /lib | |
parent | f999640373ee13e94487b2322e804260d06c81b6 (diff) |
Fix NULL dereference in get_locale_charset callers
* lib/encodings.c (get_canonical_charset_name): Declare argument and
return value as non-NULL.
(get_locale_charset): Declare return value as non-NULL. Fall back to
"ANSI_X3.4-1968" if locale_charset returned NULL or the empty string.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/encodings.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/encodings.c b/lib/encodings.c index cb09f7b7..6fe9accd 100644 --- a/lib/encodings.c +++ b/lib/encodings.c @@ -523,7 +523,8 @@ const char *get_source_encoding (const char *lang) return fallback_source_encoding; } -const char *get_canonical_charset_name (const char *charset) +const char * ATTRIBUTE_NONNULL ((1)) ATTRIBUTE_RETURNS_NONNULL + get_canonical_charset_name (const char *charset) { const struct charset_alias_entry *entry; char *charset_upper = xstrdup (charset); @@ -543,7 +544,7 @@ const char *get_canonical_charset_name (const char *charset) } /* Return the current locale's character set. */ -const char *get_locale_charset (void) +const char * ATTRIBUTE_RETURNS_NONNULL get_locale_charset (void) { const char *charset; char *saved_locale; @@ -563,10 +564,9 @@ const char *get_locale_charset (void) setlocale (LC_CTYPE, saved_locale); free (saved_locale); - if (charset && *charset) - return get_canonical_charset_name (charset); - else - return NULL; + if (!charset || !*charset) + charset = "ANSI_X3.4-1968"; + return get_canonical_charset_name (charset); } /* Find a locale with this character set. This is a non-portable operation, |