From d8dd6512cea25f9e62a0c0c290f5931343067f5f Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Fri, 19 Jun 2015 16:49:02 -0600 Subject: [PATCH] Better handling of setlocale() returning NULL. --- lib/util/sudo_conf.c | 7 +++++-- plugins/sudoers/locale.c | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/util/sudo_conf.c b/lib/util/sudo_conf.c index d02eb7be2..db20b1be2 100644 --- a/lib/util/sudo_conf.c +++ b/lib/util/sudo_conf.c @@ -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); } diff --git a/plugins/sudoers/locale.c b/plugins/sudoers/locale.c index c63a1d8aa..1259149cd 100644 --- a/plugins/sudoers/locale.c +++ b/plugins/sudoers/locale.c @@ -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; } -- 2.40.0