2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-08-31 22:35:10 +00:00

Better handling of setlocale() returning NULL.

This commit is contained in:
Todd C. Miller
2015-06-19 16:49:02 -06:00
parent c36415417f
commit d8dd6512ce
2 changed files with 8 additions and 3 deletions

View File

@@ -539,8 +539,11 @@ sudo_conf_read_v1(const char *conf_file, int conf_types)
size_t linesize = 0;
debug_decl(sudo_conf_read, SUDO_DEBUG_UTIL)
prev_locale = strdup(setlocale(LC_ALL, NULL));
if (prev_locale == NULL) {
if ((prev_locale = setlocale(LC_ALL, NULL)) == NULL) {
sudo_warn("setlocale(LC_ALL, NULL)");
debug_return_int(-1);
}
if ((prev_locale = strdup(prev_locale)) == NULL) {
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
debug_return_int(-1);
}

View File

@@ -84,7 +84,9 @@ sudoers_setlocale(int newlocale, int *prevlocale)
current_locale = SUDOERS_LOCALE_USER;
res = setlocale(LC_ALL, user_locale ? user_locale : "");
if (res != NULL && user_locale == NULL) {
user_locale = strdup(setlocale(LC_ALL, NULL));
user_locale = setlocale(LC_ALL, NULL);
if (user_locale != NULL)
user_locale = strdup(user_locale);
if (user_locale == NULL)
res = NULL;
}