718148
commit 585367266923156ac6fb789939a923641ba5aaf4
718148
Author: Florian Weimer <fweimer@redhat.com>
718148
Date:   Wed May 28 14:05:03 2014 +0200
718148
718148
    manual: Update the locale documentation
718148
718148
commit 4e8f95a0df7c2300b830ec12c0ae1e161bc8a8a3
718148
Author: Florian Weimer <fweimer@redhat.com>
718148
Date:   Mon May 12 15:24:12 2014 +0200
718148
718148
    _nl_find_locale: Improve handling of crafted locale names [BZ #17137]
718148
    
718148
    Prevent directory traversal in locale-related environment variables
718148
    (CVE-2014-0475).
718148
718148
commit d183645616b0533b3acee28f1a95570bffbdf50f
718148
Author: Florian Weimer <fweimer@redhat.com>
718148
Date:   Wed May 28 14:41:52 2014 +0200
718148
718148
    setlocale: Use the heap for the copy of the locale argument
718148
    
718148
    This avoids alloca calls with potentially large arguments.
718148
12745e
diff -pruN glibc-2.17-c758a686/locale/findlocale.c glibc-2.17-c758a686/locale/findlocale.c
12745e
--- glibc-2.17-c758a686/locale/findlocale.c	2013-08-11 04:22:55.000000000 +0530
12745e
+++ glibc-2.17-c758a686/locale/findlocale.c	2014-08-26 16:14:50.403253778 +0530
718148
@@ -17,6 +17,7 @@
718148
    <http://www.gnu.org/licenses/>.  */
718148
 
718148
 #include <assert.h>
718148
+#include <errno.h>
718148
 #include <locale.h>
718148
 #include <stdlib.h>
718148
 #include <string.h>
718148
@@ -57,6 +58,45 @@ struct loaded_l10nfile *_nl_locale_file_
718148
 
718148
 const char _nl_default_locale_path[] attribute_hidden = LOCALEDIR;
718148
 
718148
+/* Checks if the name is actually present, that is, not NULL and not
718148
+   empty.  */
718148
+static inline int
718148
+name_present (const char *name)
718148
+{
718148
+  return name != NULL && name[0] != '\0';
718148
+}
718148
+
718148
+/* Checks that the locale name neither extremely long, nor contains a
718148
+   ".." path component (to prevent directory traversal).  */
718148
+static inline int
718148
+valid_locale_name (const char *name)
718148
+{
718148
+  /* Not set.  */
718148
+  size_t namelen = strlen (name);
718148
+  /* Name too long.  The limit is arbitrary and prevents stack overflow
718148
+     issues later.  */
718148
+  if (__glibc_unlikely (namelen > 255))
718148
+    return 0;
718148
+  /* Directory traversal attempt.  */
718148
+  static const char slashdot[4] = {'/', '.', '.', '/'};
718148
+  if (__glibc_unlikely (memmem (name, namelen,
718148
+				slashdot, sizeof (slashdot)) != NULL))
718148
+    return 0;
718148
+  if (namelen == 2 && __glibc_unlikely (name[0] == '.' && name [1] == '.'))
718148
+    return 0;
718148
+  if (namelen >= 3
718148
+      && __glibc_unlikely (((name[0] == '.'
718148
+			     && name[1] == '.'
718148
+			     && name[2] == '/')
718148
+			    || (name[namelen - 3] == '/'
718148
+				&& name[namelen - 2] == '.'
718148
+				&& name[namelen - 1] == '.'))))
718148
+    return 0;
718148
+  /* If there is a slash in the name, it must start with one.  */
718148
+  if (__glibc_unlikely (memchr (name, '/', namelen) != NULL) && name[0] != '/')
718148
+    return 0;
718148
+  return 1;
718148
+}
718148
 
718148
 struct __locale_data *
718148
 internal_function
718148
@@ -65,7 +105,7 @@ _nl_find_locale (const char *locale_path
718148
 {
718148
   int mask;
718148
   /* Name of the locale for this category.  */
718148
-  char *loc_name;
718148
+  char *loc_name = (char *) *name;
718148
   const char *language;
718148
   const char *modifier;
718148
   const char *territory;
718148
@@ -73,31 +113,39 @@ _nl_find_locale (const char *locale_path
718148
   const char *normalized_codeset;
718148
   struct loaded_l10nfile *locale_file;
718148
 
718148
-  if ((*name)[0] == '\0')
718148
+  if (loc_name[0] == '\0')
718148
     {
718148
       /* The user decides which locale to use by setting environment
718148
 	 variables.  */
718148
-      *name = getenv ("LC_ALL");
718148
-      if (*name == NULL || (*name)[0] == '\0')
718148
-	*name = getenv (_nl_category_names.str
718148
+      loc_name = getenv ("LC_ALL");
718148
+      if (!name_present (loc_name))
718148
+	loc_name = getenv (_nl_category_names.str
718148
 			+ _nl_category_name_idxs[category]);
718148
-      if (*name == NULL || (*name)[0] == '\0')
718148
-	*name = getenv ("LANG");
718148
+      if (!name_present (loc_name))
718148
+	loc_name = getenv ("LANG");
718148
+      if (!name_present (loc_name))
718148
+	loc_name = (char *) _nl_C_name;
718148
     }
718148
 
718148
-  if (*name == NULL || (*name)[0] == '\0'
718148
-      || (__builtin_expect (__libc_enable_secure, 0)
718148
-	  && strchr (*name, '/') != NULL))
718148
-    *name = (char *) _nl_C_name;
718148
+  /* We used to fall back to the C locale if the name contains a slash
718148
+     character '/', but we now check for directory traversal in
718148
+     valid_locale_name, so this is no longer necessary.  */
718148
 
718148
-  if (__builtin_expect (strcmp (*name, _nl_C_name), 1) == 0
718148
-      || __builtin_expect (strcmp (*name, _nl_POSIX_name), 1) == 0)
718148
+  if (__builtin_expect (strcmp (loc_name, _nl_C_name), 1) == 0
718148
+      || __builtin_expect (strcmp (loc_name, _nl_POSIX_name), 1) == 0)
718148
     {
718148
       /* We need not load anything.  The needed data is contained in
718148
 	 the library itself.  */
718148
       *name = (char *) _nl_C_name;
718148
       return _nl_C[category];
718148
     }
718148
+  else if (!valid_locale_name (loc_name))
718148
+    {
718148
+      __set_errno (EINVAL);
718148
+      return NULL;
718148
+    }
718148
+
718148
+  *name = loc_name;
718148
 
718148
   /* We really have to load some data.  First we try the archive,
718148
      but only if there was no LOCPATH environment variable specified.  */
12745e
diff -pruN glibc-2.17-c758a686/locale/setlocale.c glibc-2.17-c758a686/locale/setlocale.c
12745e
--- glibc-2.17-c758a686/locale/setlocale.c	2013-08-11 04:22:55.000000000 +0530
12745e
+++ glibc-2.17-c758a686/locale/setlocale.c	2014-08-26 16:14:50.401253764 +0530
718148
@@ -272,6 +272,8 @@ setlocale (int category, const char *loc
718148
 	 of entries of the form `CATEGORY=VALUE'.  */
718148
       const char *newnames[__LC_LAST];
718148
       struct __locale_data *newdata[__LC_LAST];
718148
+      /* Copy of the locale argument, for in-place splitting.  */
718148
+      char *locale_copy = NULL;
718148
 
718148
       /* Set all name pointers to the argument name.  */
718148
       for (category = 0; category < __LC_LAST; ++category)
718148
@@ -281,7 +283,13 @@ setlocale (int category, const char *loc
718148
       if (__builtin_expect (strchr (locale, ';') != NULL, 0))
718148
 	{
718148
 	  /* This is a composite name.  Make a copy and split it up.  */
718148
-	  char *np = strdupa (locale);
718148
+	  locale_copy = strdup (locale);
718148
+	  if (__glibc_unlikely (locale_copy == NULL))
718148
+	    {
718148
+	      __libc_rwlock_unlock (__libc_setlocale_lock);
718148
+	      return NULL;
718148
+	    }
718148
+	  char *np = locale_copy;
718148
 	  char *cp;
718148
 	  int cnt;
718148
 
718148
@@ -299,6 +307,7 @@ setlocale (int category, const char *loc
718148
 		{
718148
 		error_return:
718148
 		  __libc_rwlock_unlock (__libc_setlocale_lock);
718148
+		  free (locale_copy);
718148
 
718148
 		  /* Bogus category name.  */
718148
 		  ERROR_RETURN;
718148
@@ -391,8 +400,9 @@ setlocale (int category, const char *loc
718148
       /* Critical section left.  */
718148
       __libc_rwlock_unlock (__libc_setlocale_lock);
718148
 
718148
-      /* Free the resources (the locale path variable).  */
718148
+      /* Free the resources.  */
718148
       free (locale_path);
718148
+      free (locale_copy);
718148
 
718148
       return composite;
718148
     }
12745e
diff -pruN glibc-2.17-c758a686/localedata/Makefile glibc-2.17-c758a686/localedata/Makefile
12745e
--- glibc-2.17-c758a686/localedata/Makefile	2014-08-26 16:15:22.656474571 +0530
12745e
+++ glibc-2.17-c758a686/localedata/Makefile	2014-08-26 16:14:50.403253778 +0530
718148
@@ -77,7 +77,7 @@ locale_test_suite := tst_iswalnum tst_is
718148
 
718148
 tests = $(locale_test_suite) tst-digits tst-setlocale bug-iconv-trans \
718148
 	tst-leaks tst-mbswcs6 tst-xlocale1 tst-xlocale2 bug-usesetlocale \
718148
-	tst-strfmon1 tst-sscanf bug-setlocale1 tst-setlocale2
718148
+	tst-strfmon1 tst-sscanf bug-setlocale1 tst-setlocale2 tst-setlocale3
718148
 ifeq (yes,$(build-shared))
718148
 ifneq (no,$(PERL))
718148
 tests: $(objpfx)mtrace-tst-leaks
12745e
diff -pruN glibc-2.17-c758a686/localedata/tst-setlocale3.c glibc-2.17-c758a686/localedata/tst-setlocale3.c
12745e
--- glibc-2.17-c758a686/localedata/tst-setlocale3.c	1970-01-01 05:30:00.000000000 +0530
12745e
+++ glibc-2.17-c758a686/localedata/tst-setlocale3.c	2014-08-26 16:14:50.403253778 +0530
718148
@@ -0,0 +1,203 @@
718148
+/* Regression test for setlocale invalid environment variable handling.
718148
+   Copyright (C) 2014 Free Software Foundation, Inc.
718148
+   This file is part of the GNU C Library.
718148
+
718148
+   The GNU C Library is free software; you can redistribute it and/or
718148
+   modify it under the terms of the GNU Lesser General Public
718148
+   License as published by the Free Software Foundation; either
718148
+   version 2.1 of the License, or (at your option) any later version.
718148
+
718148
+   The GNU C Library is distributed in the hope that it will be useful,
718148
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
718148
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
718148
+   Lesser General Public License for more details.
718148
+
718148
+   You should have received a copy of the GNU Lesser General Public
718148
+   License along with the GNU C Library; if not, see
718148
+   <http://www.gnu.org/licenses/>.  */
718148
+
718148
+#include <locale.h>
718148
+#include <stdio.h>
718148
+#include <stdlib.h>
718148
+#include <string.h>
718148
+
718148
+/* The result of setlocale may be overwritten by subsequent calls, so
718148
+   this wrapper makes a copy.  */
718148
+static char *
718148
+setlocale_copy (int category, const char *locale)
718148
+{
718148
+  const char *result = setlocale (category, locale);
718148
+  if (result == NULL)
718148
+    return NULL;
718148
+  return strdup (result);
718148
+}
718148
+
718148
+static char *de_locale;
718148
+
718148
+static void
718148
+setlocale_fail (const char *envstring)
718148
+{
718148
+  setenv ("LC_CTYPE", envstring, 1);
718148
+  if (setlocale (LC_CTYPE, "") != NULL)
718148
+    {
718148
+      printf ("unexpected setlocale success for \"%s\" locale\n", envstring);
718148
+      exit (1);
718148
+    }
718148
+  const char *newloc = setlocale (LC_CTYPE, NULL);
718148
+  if (strcmp (newloc, de_locale) != 0)
718148
+    {
718148
+      printf ("failed setlocale call \"%s\" changed locale to \"%s\"\n",
718148
+	      envstring, newloc);
718148
+      exit (1);
718148
+    }
718148
+}
718148
+
718148
+static void
718148
+setlocale_success (const char *envstring)
718148
+{
718148
+  setenv ("LC_CTYPE", envstring, 1);
718148
+  char *newloc = setlocale_copy (LC_CTYPE, "");
718148
+  if (newloc == NULL)
718148
+    {
718148
+      printf ("setlocale for \"%s\": %m\n", envstring);
718148
+      exit (1);
718148
+    }
718148
+  if (strcmp (newloc, de_locale) == 0)
718148
+    {
718148
+      printf ("setlocale with LC_CTYPE=\"%s\" left locale at \"%s\"\n",
718148
+	      envstring, de_locale);
718148
+      exit (1);
718148
+    }
718148
+  if (setlocale (LC_CTYPE, de_locale) == NULL)
718148
+    {
718148
+      printf ("restoring locale \"%s\" with LC_CTYPE=\"%s\": %m\n",
718148
+	      de_locale, envstring);
718148
+      exit (1);
718148
+    }
718148
+  char *newloc2 = setlocale_copy (LC_CTYPE, newloc);
718148
+  if (newloc2 == NULL)
718148
+    {
718148
+      printf ("restoring locale \"%s\" following \"%s\": %m\n",
718148
+	      newloc, envstring);
718148
+      exit (1);
718148
+    }
718148
+  if (strcmp (newloc, newloc2) != 0)
718148
+    {
718148
+      printf ("representation of locale \"%s\" changed from \"%s\" to \"%s\"",
718148
+	      envstring, newloc, newloc2);
718148
+      exit (1);
718148
+    }
718148
+  free (newloc);
718148
+  free (newloc2);
718148
+
718148
+  if (setlocale (LC_CTYPE, de_locale) == NULL)
718148
+    {
718148
+      printf ("restoring locale \"%s\" with LC_CTYPE=\"%s\": %m\n",
718148
+	      de_locale, envstring);
718148
+      exit (1);
718148
+    }
718148
+}
718148
+
718148
+/* Checks that a known-good locale still works if LC_ALL contains a
718148
+   value which should be ignored.  */
718148
+static void
718148
+setlocale_ignore (const char *to_ignore)
718148
+{
718148
+  const char *fr_locale = "fr_FR.UTF-8";
718148
+  setenv ("LC_CTYPE", fr_locale, 1);
718148
+  char *expected_locale = setlocale_copy (LC_CTYPE, "");
718148
+  if (expected_locale == NULL)
718148
+    {
718148
+      printf ("setlocale with LC_CTYPE=\"%s\" failed: %m\n", fr_locale);
718148
+      exit (1);
718148
+    }
718148
+  if (setlocale (LC_CTYPE, de_locale) == NULL)
718148
+    {
718148
+      printf ("failed to restore locale: %m\n");
718148
+      exit (1);
718148
+    }
718148
+  unsetenv ("LC_CTYPE");
718148
+
718148
+  setenv ("LC_ALL", to_ignore, 1);
718148
+  setenv ("LC_CTYPE", fr_locale, 1);
718148
+  const char *actual_locale = setlocale (LC_CTYPE, "");
718148
+  if (actual_locale == NULL)
718148
+    {
718148
+      printf ("setlocale with LC_ALL, LC_CTYPE=\"%s\" failed: %m\n",
718148
+	      fr_locale);
718148
+      exit (1);
718148
+    }
718148
+  if (strcmp (actual_locale, expected_locale) != 0)
718148
+    {
718148
+      printf ("setlocale under LC_ALL failed: got \"%s\", expected \"%s\"\n",
718148
+	      actual_locale, expected_locale);
718148
+      exit (1);
718148
+    }
718148
+  unsetenv ("LC_CTYPE");
718148
+  setlocale_success (fr_locale);
718148
+  unsetenv ("LC_ALL");
718148
+  free (expected_locale);
718148
+}
718148
+
718148
+static int
718148
+do_test (void)
718148
+{
718148
+  /* The glibc test harness sets this environment variable
718148
+     uncondionally.  */
718148
+  unsetenv ("LC_ALL");
718148
+
718148
+  de_locale = setlocale_copy (LC_CTYPE, "de_DE.UTF-8");
718148
+  if (de_locale == NULL)
718148
+    {
718148
+      printf ("setlocale (LC_CTYPE, \"de_DE.UTF-8\"): %m\n");
718148
+      return 1;
718148
+    }
718148
+  setlocale_success ("C");
718148
+  setlocale_success ("en_US.UTF-8");
718148
+  setlocale_success ("/en_US.UTF-8");
718148
+  setlocale_success ("//en_US.UTF-8");
718148
+  setlocale_ignore ("");
718148
+
718148
+  setlocale_fail ("does-not-exist");
718148
+  setlocale_fail ("/");
718148
+  setlocale_fail ("/../localedata/en_US.UTF-8");
718148
+  setlocale_fail ("en_US.UTF-8/");
718148
+  setlocale_fail ("en_US.UTF-8/..");
718148
+  setlocale_fail ("en_US.UTF-8/../en_US.UTF-8");
718148
+  setlocale_fail ("../localedata/en_US.UTF-8");
718148
+  {
718148
+    size_t large_length = 1024;
718148
+    char *large_name = malloc (large_length + 1);
718148
+    if (large_name == NULL)
718148
+      {
718148
+	puts ("malloc failure");
718148
+	return 1;
718148
+      }
718148
+    memset (large_name, '/', large_length);
718148
+    const char *suffix = "en_US.UTF-8";
718148
+    strcpy (large_name + large_length - strlen (suffix), suffix);
718148
+    setlocale_fail (large_name);
718148
+    free (large_name);
718148
+  }
718148
+  {
718148
+    size_t huge_length = 64 * 1024 * 1024;
718148
+    char *huge_name = malloc (huge_length + 1);
718148
+    if (huge_name == NULL)
718148
+      {
718148
+	puts ("malloc failure");
718148
+	return 1;
718148
+      }
718148
+    memset (huge_name, 'X', huge_length);
718148
+    huge_name[huge_length] = '\0';
718148
+    /* Construct a composite locale specification. */
718148
+    const char *prefix = "LC_CTYPE=de_DE.UTF-8;LC_TIME=";
718148
+    memcpy (huge_name, prefix, strlen (prefix));
718148
+    setlocale_fail (huge_name);
718148
+    free (huge_name);
718148
+  }
718148
+
718148
+  return 0;
718148
+}
718148
+
718148
+#define TEST_FUNCTION do_test ()
718148
+#include "../test-skeleton.c"
12745e
diff -pruN glibc-2.17-c758a686/manual/locale.texi glibc-2.17-c758a686/manual/locale.texi
12745e
--- glibc-2.17-c758a686/manual/locale.texi	2013-08-11 04:22:55.000000000 +0530
12745e
+++ glibc-2.17-c758a686/manual/locale.texi	2014-08-26 16:14:50.404253785 +0530
718148
@@ -29,6 +29,7 @@ will follow the conventions preferred by
718148
 * Setting the Locale::          How a program specifies the locale
718148
                                  with library functions.
718148
 * Standard Locales::            Locale names available on all systems.
718148
+* Locale Names::                Format of system-specific locale names.
718148
 * Locale Information::          How to access the information for the locale.
718148
 * Formatting Numbers::          A dedicated function to format numbers.
718148
 * Yes-or-No Questions::         Check a Response against the locale.
718148
@@ -99,14 +100,16 @@ locale named @samp{espana-castellano} to
718148
 most of Spain.
718148
 
718148
 The set of locales supported depends on the operating system you are
718148
-using, and so do their names.  We can't make any promises about what
718148
-locales will exist, except for one standard locale called @samp{C} or
718148
-@samp{POSIX}.  Later we will describe how to construct locales.
718148
-@comment (@pxref{Building Locale Files}).
718148
+using, and so do their names, except that the standard locale called
718148
+@samp{C} or @samp{POSIX} always exist.  @xref{Locale Names}.
718148
+
718148
+In order to force the system to always use the default locale, the
718148
+user can set the @code{LC_ALL} environment variable to @samp{C}.
718148
 
718148
 @cindex combining locales
718148
-A user also has the option of specifying different locales for different
718148
-purposes---in effect, choosing a mixture of multiple locales.
718148
+A user also has the option of specifying different locales for
718148
+different purposes---in effect, choosing a mixture of multiple
718148
+locales.  @xref{Locale Categories}.
718148
 
718148
 For example, the user might specify the locale @samp{espana-castellano}
718148
 for most purposes, but specify the locale @samp{usa-english} for
718148
@@ -120,7 +123,7 @@ which locales apply.  However, the user
718148
 for a particular subset of those purposes.
718148
 
718148
 @node Locale Categories, Setting the Locale, Choosing Locale, Locales
718148
-@section Categories of Activities that Locales Affect
718148
+@section Locale Categories
718148
 @cindex categories for locales
718148
 @cindex locale categories
718148
 
718148
@@ -128,7 +131,11 @@ The purposes that locales serve are grou
718148
 that a user or a program can choose the locale for each category
718148
 independently.  Here is a table of categories; each name is both an
718148
 environment variable that a user can set, and a macro name that you can
718148
-use as an argument to @code{setlocale}.
718148
+use as the first argument to @code{setlocale}.
718148
+
718148
+The contents of the environment variable (or the string in the second
718148
+argument to @code{setlocale}) has to be a valid locale name.
718148
+@xref{Locale Names}.
718148
 
718148
 @vtable @code
718148
 @comment locale.h
718148
@@ -172,7 +179,7 @@ for affirmative and negative responses.
718148
 @comment locale.h
718148
 @comment ISO
718148
 @item LC_ALL
718148
-This is not an environment variable; it is only a macro that you can use
718148
+This is not a category; it is only a macro that you can use
718148
 with @code{setlocale} to set a single locale for all purposes.  Setting
718148
 this environment variable overwrites all selections by the other
718148
 @code{LC_*} variables or @code{LANG}.
718148
@@ -225,13 +232,7 @@ The symbols in this section are defined
718148
 @comment ISO
718148
 @deftypefun {char *} setlocale (int @var{category}, const char *@var{locale})
718148
 The function @code{setlocale} sets the current locale for category
718148
-@var{category} to @var{locale}.  A list of all the locales the system
718148
-provides can be created by running
718148
-
718148
-@pindex locale
718148
-@smallexample
718148
-  locale -a
718148
-@end smallexample
718148
+@var{category} to @var{locale}.
718148
 
718148
 If @var{category} is @code{LC_ALL}, this specifies the locale for all
718148
 purposes.  The other possible values of @var{category} specify an
718148
@@ -256,10 +257,9 @@ is passed in as @var{locale} parameter.
718148
 
718148
 When you read the current locale for category @code{LC_ALL}, the value
718148
 encodes the entire combination of selected locales for all categories.
718148
-In this case, the value is not just a single locale name.  In fact, we
718148
-don't make any promises about what it looks like.  But if you specify
718148
-the same ``locale name'' with @code{LC_ALL} in a subsequent call to
718148
-@code{setlocale}, it restores the same combination of locale selections.
718148
+If you specify the same ``locale name'' with @code{LC_ALL} in a
718148
+subsequent call to @code{setlocale}, it restores the same combination
718148
+of locale selections.
718148
 
718148
 To be sure you can use the returned string encoding the currently selected
718148
 locale at a later time, you must make a copy of the string.  It is not
718148
@@ -275,20 +275,15 @@ for @var{category}.
718148
 If a nonempty string is given for @var{locale}, then the locale of that
718148
 name is used if possible.
718148
 
718148
+The effective locale name (either the second argument to
718148
+@code{setlocale}, or if the argument is an empty string, the name
718148
+obtained from the process environment) must be valid locale name.
718148
+@xref{Locale Names}.
718148
+
718148
 If you specify an invalid locale name, @code{setlocale} returns a null
718148
 pointer and leaves the current locale unchanged.
718148
 @end deftypefun
718148
 
718148
-The path used for finding locale data can be set using the
718148
-@code{LOCPATH} environment variable. The default path for finding
718148
-locale data is system specific.  It is computed from the value given
718148
-as the prefix while configuring the C library.  This value normally is
718148
-@file{/usr} or @file{/}.  For the former the complete path is:
718148
-
718148
-@smallexample
718148
-/usr/lib/locale
718148
-@end smallexample
718148
-
718148
 Here is an example showing how you might use @code{setlocale} to
718148
 temporarily switch to a new locale.
718148
 
718148
@@ -328,7 +323,7 @@ locale categories, and future versions o
718148
 portability, assume that any symbol beginning with @samp{LC_} might be
718148
 defined in @file{locale.h}.
718148
 
718148
-@node Standard Locales, Locale Information, Setting the Locale, Locales
718148
+@node Standard Locales, Locale Names, Setting the Locale, Locales
718148
 @section Standard Locales
718148
 
718148
 The only locale names you can count on finding on all operating systems
718148
@@ -362,7 +357,94 @@ with the environment, rather than trying
718148
 locale explicitly by name.  Remember, different machines might have
718148
 different sets of locales installed.
718148
 
718148
-@node Locale Information, Formatting Numbers, Standard Locales, Locales
718148
+@node Locale Names, Locale Information, Standard Locales, Locales
718148
+@section Locale Names
718148
+
718148
+The following command prints a list of locales supported by the
718148
+system:
718148
+
718148
+@pindex locale
718148
+@smallexample
718148
+  locale -a
718148
+@end smallexample
718148
+
718148
+@strong{Portability Note:} With the notable exception of the standard
718148
+locale names @samp{C} and @samp{POSIX}, locale names are
718148
+system-specific.
718148
+
718148
+Most locale names follow XPG syntax and consist of up to four parts:
718148
+
718148
+@smallexample
718148
+@var{language}[_@var{territory}[.@var{codeset}]][@@@var{modifier}]
718148
+@end smallexample
718148
+
718148
+Beside the first part, all of them are allowed to be missing.  If the
718148
+full specified locale is not found, less specific ones are looked for.
718148
+The various parts will be stripped off, in the following order:
718148
+
718148
+@enumerate
718148
+@item
718148
+codeset
718148
+@item
718148
+normalized codeset
718148
+@item
718148
+territory
718148
+@item
718148
+modifier
718148
+@end enumerate
718148
+
718148
+For example, the locale name @samp{de_AT.iso885915@@euro} denotes a
718148
+German-language locale for use in Austria, using the ISO-8859-15
718148
+(Latin-9) character set, and with the Euro as the currency symbol.
718148
+
718148
+In addition to locale names which follow XPG syntax, systems may
718148
+provide aliases such as @samp{german}.  Both categories of names must
718148
+not contain the slash character @samp{/}.
718148
+
718148
+If the locale name starts with a slash @samp{/}, it is treated as a
718148
+path relative to the configured locale directories; see @code{LOCPATH}
718148
+below.  The specified path must not contain a component @samp{..}, or
718148
+the name is invalid, and @code{setlocale} will fail.
718148
+
718148
+@strong{Portability Note:} POSIX suggests that if a locale name starts
718148
+with a slash @samp{/}, it is resolved as an absolute path.  However,
718148
+@theglibc{} treats it as a relative path under the directories listed
718148
+in @code{LOCPATH} (or the default locale directory if @code{LOCPATH}
718148
+is unset).
718148
+
718148
+Locale names which are longer than an implementation-defined limit are
718148
+invalid and cause @code{setlocale} to fail.
718148
+
718148
+As a special case, locale names used with @code{LC_ALL} can combine
718148
+several locales, reflecting different locale settings for different
718148
+categories.  For example, you might want to use a U.S. locale with ISO
718148
+A4 paper format, so you set @code{LANG} to @samp{en_US.UTF-8}, and
718148
+@code{LC_PAPER} to @samp{de_DE.UTF-8}.  In this case, the
718148
+@code{LC_ALL}-style combined locale name is
718148
+
718148
+@smallexample
718148
+LC_CTYPE=en_US.UTF-8;LC_TIME=en_US.UTF-8;LC_PAPER=de_DE.UTF-8;@dots{}
718148
+@end smallexample
718148
+
718148
+followed by other category settings not shown here.
718148
+
718148
+@vindex LOCPATH
718148
+The path used for finding locale data can be set using the
718148
+@code{LOCPATH} environment variable.  This variable lists the
718148
+directories in which to search for locale definitions, separated by a
718148
+colon @samp{:}.
718148
+
718148
+The default path for finding locale data is system specific.  A typical
718148
+value for the @code{LOCPATH} default is:
718148
+
718148
+@smallexample
718148
+/usr/share/locale
718148
+@end smallexample
718148
+
718148
+The value of @code{LOCPATH} is ignored by privileged programs for
718148
+security reasons, and only the default directory is used.
718148
+
718148
+@node Locale Information, Formatting Numbers, Locale Names, Locales
718148
 @section Accessing Locale Information
718148
 
718148
 There are several ways to access locale information.  The simplest