Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/locale fix lib/42124: setlocale(3) never returns NU...



details:   https://anonhg.NetBSD.org/src/rev/ec2f76d321bd
branches:  trunk
changeset: 747886:ec2f76d321bd
user:      tnozaki <tnozaki%NetBSD.org@localhost>
date:      Sun Oct 04 21:05:18 2009 +0000

description:
fix lib/42124: setlocale(3) never returns NULL with none existing locale.
reported by kambe-san, thanks!

diffstat:

 lib/libc/locale/generic_lc_all.c |  20 +++++++++++++-------
 1 files changed, 13 insertions(+), 7 deletions(-)

diffs (67 lines):

diff -r fe6adad1b57b -r ec2f76d321bd lib/libc/locale/generic_lc_all.c
--- a/lib/libc/locale/generic_lc_all.c  Sun Oct 04 20:53:23 2009 +0000
+++ b/lib/libc/locale/generic_lc_all.c  Sun Oct 04 21:05:18 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: generic_lc_all.c,v 1.2 2009/01/11 02:46:28 christos Exp $ */
+/* $NetBSD: generic_lc_all.c,v 1.3 2009/10/04 21:05:18 tnozaki Exp $ */
 
 /*-
  * Copyright (c)2008 Citrus Project,
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: generic_lc_all.c,v 1.2 2009/01/11 02:46:28 christos Exp $");
+__RCSID("$NetBSD: generic_lc_all.c,v 1.3 2009/10/04 21:05:18 tnozaki Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include <sys/types.h>
@@ -56,10 +56,11 @@
        _locale_category_t *l;
        char head[_LOCALENAME_LEN_MAX * (_LC_LAST - 1)], *tail;
        const char *tokens[_LC_LAST], *s, *t;
-       int i, j;
+       int load_locale_success, i, j;
 
        l = _find_category(1);
        _DIAGASSERT(l != NULL);
+       load_locale_success = 0;
        if (name != NULL) {
                strlcpy(&head[0], name, sizeof(head));
                tokens[1] = &head[0];
@@ -78,10 +79,11 @@
                        }
                        tokens[_LC_LAST - 1] = (const char *)tail;
                        tail = strchr(tokens[i], '/');
-                       if (tail == NULL)
+                       if (tail != NULL)
                                return NULL;
                }
-               (*l->setlocale)(tokens[1], locale);
+               if ((*l->setlocale)(tokens[1], locale) != NULL)
+                       load_locale_success = 1;
        }
        s = (*l->setlocale)(NULL, locale);
        _DIAGASSERT(s != NULL);
@@ -89,8 +91,10 @@
        for (i = 2, j = 0; i < _LC_LAST; ++i) {
                l = _find_category(i);
                _DIAGASSERT(l != NULL);
-               if (name != NULL)
-                       (*l->setlocale)(tokens[1], locale);
+               if (name != NULL) {
+                       if ((*l->setlocale)(tokens[i], locale) != NULL)
+                               load_locale_success = 1;
+               }
                t = (*l->setlocale)(NULL, locale);
                _DIAGASSERT(t != NULL);
                if (j == 0) {
@@ -106,6 +110,8 @@
                strlcat(&locale->query[0], "/", sizeof(locale->query));
                strlcat(&locale->query[0], t, sizeof(locale->query));
        }
+       if (name != NULL && !load_locale_success)
+               return NULL;
        return (const char *)&locale->query[0];
 }
 



Home | Main Index | Thread Index | Old Index