ce426f
commit e7f07af50b231d3ade6b4d338a65d6b571f96116
ce426f
Author: Alexandre Oliva <aoliva@redhat.com>
ce426f
Date:   Fri Feb 27 22:18:56 2015 -0300
ce426f
ce426f
    Avoid unsafe loc_name type casts with additional variable
ce426f
    
ce426f
    for  ChangeLog
ce426f
    
ce426f
    	[BZ #15969]
ce426f
    	* locale/findlocale.c (_nl_find_locale): Introduce const
ce426f
    	version of loc_name and drop unsafe type casts.
ce426f
ce426f
diff --git a/locale/findlocale.c b/locale/findlocale.c
ce426f
index 5e2639b..9e7df12 100644
ce426f
--- a/locale/findlocale.c
ce426f
+++ b/locale/findlocale.c
ce426f
@@ -105,7 +105,7 @@ _nl_find_locale (const char *locale_path, size_t locale_path_len,
ce426f
 {
ce426f
   int mask;
ce426f
   /* Name of the locale for this category.  */
ce426f
-  char *loc_name = (char *) *name;
ce426f
+  const char *cloc_name = *name;
ce426f
   const char *language;
ce426f
   const char *modifier;
ce426f
   const char *territory;
ce426f
@@ -113,39 +113,39 @@ _nl_find_locale (const char *locale_path, size_t locale_path_len,
ce426f
   const char *normalized_codeset;
ce426f
   struct loaded_l10nfile *locale_file;
ce426f
 
ce426f
-  if (loc_name[0] == '\0')
ce426f
+  if (cloc_name[0] == '\0')
ce426f
     {
ce426f
       /* The user decides which locale to use by setting environment
ce426f
 	 variables.  */
ce426f
-      loc_name = getenv ("LC_ALL");
ce426f
-      if (!name_present (loc_name))
ce426f
-	loc_name = getenv (_nl_category_names.str
ce426f
-			+ _nl_category_name_idxs[category]);
ce426f
-      if (!name_present (loc_name))
ce426f
-	loc_name = getenv ("LANG");
ce426f
-      if (!name_present (loc_name))
ce426f
-	loc_name = (char *) _nl_C_name;
ce426f
+      cloc_name = getenv ("LC_ALL");
ce426f
+      if (!name_present (cloc_name))
ce426f
+	cloc_name = getenv (_nl_category_names.str
ce426f
+			    + _nl_category_name_idxs[category]);
ce426f
+      if (!name_present (cloc_name))
ce426f
+	cloc_name = getenv ("LANG");
ce426f
+      if (!name_present (cloc_name))
ce426f
+	cloc_name = _nl_C_name;
ce426f
     }
ce426f
 
ce426f
   /* We used to fall back to the C locale if the name contains a slash
ce426f
      character '/', but we now check for directory traversal in
ce426f
      valid_locale_name, so this is no longer necessary.  */
ce426f
 
ce426f
-  if (__builtin_expect (strcmp (loc_name, _nl_C_name), 1) == 0
ce426f
-      || __builtin_expect (strcmp (loc_name, _nl_POSIX_name), 1) == 0)
ce426f
+  if (__builtin_expect (strcmp (cloc_name, _nl_C_name), 1) == 0
ce426f
+      || __builtin_expect (strcmp (cloc_name, _nl_POSIX_name), 1) == 0)
ce426f
     {
ce426f
       /* We need not load anything.  The needed data is contained in
ce426f
 	 the library itself.  */
ce426f
-      *name = (char *) _nl_C_name;
ce426f
+      *name = _nl_C_name;
ce426f
       return _nl_C[category];
ce426f
     }
ce426f
-  else if (!valid_locale_name (loc_name))
ce426f
+  else if (!valid_locale_name (cloc_name))
ce426f
     {
ce426f
       __set_errno (EINVAL);
ce426f
       return NULL;
ce426f
     }
ce426f
 
ce426f
-  *name = loc_name;
ce426f
+  *name = cloc_name;
ce426f
 
ce426f
   /* We really have to load some data.  First we try the archive,
ce426f
      but only if there was no LOCPATH environment variable specified.  */
ce426f
@@ -158,11 +158,10 @@ _nl_find_locale (const char *locale_path, size_t locale_path_len,
ce426f
 
ce426f
       /* Nothing in the archive with the given name.  Expanding it as
ce426f
 	 an alias and retry.  */
ce426f
-      loc_name = (char *) _nl_expand_alias (*name);
ce426f
-      if (loc_name != NULL)
ce426f
+      cloc_name = _nl_expand_alias (*name);
ce426f
+      if (cloc_name != NULL)
ce426f
 	{
ce426f
-	  data = _nl_load_locale_from_archive (category,
ce426f
-					       (const char **) &loc_name);
ce426f
+	  data = _nl_load_locale_from_archive (category, &cloc_name);
ce426f
 	  if (__builtin_expect (data != NULL, 1))
ce426f
 	    return data;
ce426f
 	}
ce426f
@@ -175,14 +174,14 @@ _nl_find_locale (const char *locale_path, size_t locale_path_len,
ce426f
     /* We really have to load some data.  First see whether the name is
ce426f
        an alias.  Please note that this makes it impossible to have "C"
ce426f
        or "POSIX" as aliases.  */
ce426f
-    loc_name = (char *) _nl_expand_alias (*name);
ce426f
+    cloc_name = _nl_expand_alias (*name);
ce426f
 
ce426f
-  if (loc_name == NULL)
ce426f
+  if (cloc_name == NULL)
ce426f
     /* It is no alias.  */
ce426f
-    loc_name = (char *) *name;
ce426f
+    cloc_name = *name;
ce426f
 
ce426f
   /* Make a writable copy of the locale name.  */
ce426f
-  loc_name = strdupa (loc_name);
ce426f
+  char *loc_name = strdupa (cloc_name);
ce426f
 
ce426f
   /* LOCALE can consist of up to four recognized parts for the XPG syntax:
ce426f