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