25845f
commit 97f13188c9fbafeaab89146996b3cce1f4952b5e
25845f
Author: Dmitry V. Levin <ldv@altlinux.org>
25845f
Date:   Tue Dec 19 21:06:23 2017 +0000
25845f
25845f
    elf: remove redundant code from _dl_dst_substitute
25845f
    
25845f
    There are just two users of _dl_dst_substitute: one is expand_dst that
25845f
    sets is_path argument to 0, another one is expand_dynamic_string_token.
25845f
    The latter function also has just two users: one is _dl_map_object that
25845f
    sets is_path argument to 0, another one is fillin_rpath that sets
25845f
    is_path argument to 1 and name argument contains no ':'.
25845f
    
25845f
    In any case (is_path && name[i] == ':') is always false and all code
25845f
    depending on it can be safely removed.
25845f
    
25845f
    * elf/dl-load.c (_dl_dst_substitute): Remove checks that is_path
25845f
    is set and name contains ':', and all code depending on these checks.
25845f
25845f
Index: glibc-2.17-c758a686/elf/dl-load.c
25845f
===================================================================
25845f
--- glibc-2.17-c758a686.orig/elf/dl-load.c
25845f
+++ glibc-2.17-c758a686/elf/dl-load.c
25845f
@@ -349,13 +349,7 @@ _dl_dst_substitute (struct link_map *l,
25845f
 	      /* We cannot use this path element, the value of the
25845f
 		 replacement is unknown.  */
25845f
 	      wp = last_elem;
25845f
-	      name += len;
25845f
-	      while (*name != '\0' && (!is_path || *name != ':'))
25845f
-		++name;
25845f
-	      /* Also skip following colon if this is the first rpath
25845f
-		 element, but keep an empty element at the end.  */
25845f
-	      if (wp == result && is_path && *name == ':' && name[1] != '\0')
25845f
-		++name;
25845f
+	      break;
25845f
 	    }
25845f
 	  else
25845f
 	    /* No DST we recognize.  */
25845f
@@ -364,19 +358,6 @@ _dl_dst_substitute (struct link_map *l,
25845f
       else
25845f
 	{
25845f
 	  *wp++ = *name++;
25845f
-	  if (is_path && *name == ':')
25845f
-	    {
25845f
-	      /* In SUID/SGID programs, after $ORIGIN expansion the
25845f
-		 normalized path must be rooted in one of the trusted
25845f
-		 directories.  */
25845f
-	      if (__builtin_expect (check_for_trusted, false)
25845f
-		  && !is_trusted_path_normalize (last_elem, wp - last_elem))
25845f
-		wp = last_elem;
25845f
-	      else
25845f
-		last_elem = wp;
25845f
-
25845f
-	      check_for_trusted = false;
25845f
-	    }
25845f
 	}
25845f
     }
25845f
   while (*name != '\0');