]> granicus.if.org Git - sudo/commitdiff
Better handling of setlocale() returning NULL.
authorTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 19 Jun 2015 22:49:02 +0000 (16:49 -0600)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 19 Jun 2015 22:49:02 +0000 (16:49 -0600)
lib/util/sudo_conf.c
plugins/sudoers/locale.c

index d02eb7be23d1b4a94976989b1ba0739656d844dc..db20b1be2b7119a2dce5acb2c6743840dac08498 100644 (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);
     }
index c63a1d8aaccb119d0484a9e83c3d818613d7ec46..1259149cd6f7b1051b2249359828693fbb85c189 100644 (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;
                }