Author: delphij
Date: Wed Jun 17 19:13:13 2015
New Revision: 284525
URL: https://svnweb.freebsd.org/changeset/base/284525

Log:
  MFC r264038 (theraven)
  
  Fix an issue where the locale and rune locale could become out of sync,
  causing mb* functions (and similar) to be called with the wrong data
  (possibly a null pointer, causing a crash).
  
  PR:           standards/188036

Modified:
  stable/9/lib/libc/locale/setrunelocale.c
  stable/9/lib/libc/locale/xlocale.c
Directory Properties:
  stable/9/lib/libc/   (props changed)

Modified: stable/9/lib/libc/locale/setrunelocale.c
==============================================================================
--- stable/9/lib/libc/locale/setrunelocale.c    Wed Jun 17 19:12:18 2015        
(r284524)
+++ stable/9/lib/libc/locale/setrunelocale.c    Wed Jun 17 19:13:13 2015        
(r284525)
@@ -202,6 +202,8 @@ __set_thread_rune_locale(locale_t loc)
 
        if (loc == NULL) {
                _ThreadRuneLocale = &_DefaultRuneLocale;
+       } else if (loc == LC_GLOBAL_LOCALE) {
+               _ThreadRuneLocale = 0;
        } else {
                _ThreadRuneLocale = XLOCALE_CTYPE(loc)->runes;
        }

Modified: stable/9/lib/libc/locale/xlocale.c
==============================================================================
--- stable/9/lib/libc/locale/xlocale.c  Wed Jun 17 19:12:18 2015        
(r284524)
+++ stable/9/lib/libc/locale/xlocale.c  Wed Jun 17 19:13:13 2015        
(r284525)
@@ -154,23 +154,24 @@ __get_locale(void)
 static void
 set_thread_locale(locale_t loc)
 {
+       locale_t l = (loc == LC_GLOBAL_LOCALE) ? 0 : loc;
 
        _once(&once_control, init_key);
        
-       if (NULL != loc) {
-               xlocale_retain((struct xlocale_refcounted*)loc);
+       if (NULL != l) {
+               xlocale_retain((struct xlocale_refcounted*)l);
        }
        locale_t old = pthread_getspecific(locale_info_key);
-       if ((NULL != old) && (loc != old)) {
+       if ((NULL != old) && (l != old)) {
                xlocale_release((struct xlocale_refcounted*)old);
        }
        if (fake_tls) {
-               thread_local_locale = loc;
+               thread_local_locale = l;
        } else {
-               pthread_setspecific(locale_info_key, loc);
+               pthread_setspecific(locale_info_key, l);
        }
 #ifndef __NO_TLS
-       __thread_locale = loc;
+       __thread_locale = l;
        __set_thread_rune_locale(loc);
 #endif
 }
@@ -361,9 +362,6 @@ locale_t uselocale(locale_t loc)
 {
        locale_t old = get_thread_locale();
        if (NULL != loc) {
-               if (LC_GLOBAL_LOCALE == loc) {
-                       loc = NULL;
-               }
                set_thread_locale(loc);
        }
        return (old ? old : LC_GLOBAL_LOCALE);
_______________________________________________
svn-src-stable-9@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-stable-9
To unsubscribe, send any mail to "svn-src-stable-9-unsubscr...@freebsd.org"

Reply via email to