This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH v2][BZ #10253] Fix breaking of RPATH when $ORIGIN contains colons.


On Sat, Oct 26, 2013 at 03:41:04PM +0200, Andreas Schwab wrote:
> OndÅej BÃlka <neleai@seznam.cz> writes:
> 
> > +	      int check_trusted, const char *what, const char *where,
> > +              struct link_map *l)
> 
> Whitespace.
> 
> >  {
> >    char *cp;
> >    size_t nelems = 0;
> >  
> > +  char *to_free;
> >    while ((cp = __strsep (&rpath, sep)) != NULL)
> 
> Whitespace.
> 
> > @@ -570,6 +577,7 @@ fillin_rpath (char *rpath, struct r_search_path_elem **result, const char *sep,
> >  	  /* Put it in the result array.  */
> >  	  result[nelems++] = dirp;
> >  	}
> > +      free (to_free);
> 
> Whitespace.
> 
> > @@ -627,7 +635,7 @@ decompose_rpath (struct r_search_path_struct *sps,
> >  
> >    /* Make a writable copy.  At the same time expand possible dynamic
> >       string tokens.  */
> > -  copy = expand_dynamic_string_token (l, rpath, 1);
> > +  copy = local_strdup(rpath);
> 
> Whitespace.
> 
> > @@ -865,7 +873,12 @@ _dl_init_paths (const char *llp)
> >  
> >        (void) fillin_rpath (llp_tmp, env_path_list.dirs, ":;",
> >  			   INTUSE(__libc_enable_secure), "LD_LIBRARY_PATH",
> > -			   NULL);
> > +			   NULL,
> > +#ifdef SHARED
> > +                           l);
> > +#else
> > +                           NULL);
> > +#endif
> 
> Whitespace.  Don't duplicate paren.
> 
> Andreas.
> 
> -- 
> Andreas Schwab, schwab@linux-m68k.org
> GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
> "And now for something completely different."

Here is v2

	[BZ #10253]
	* elf/dl-load.c (fillin_rpath): Add linkmap parameter and expand path.
	(decompose_rpath): Defer expansion to fillin_rpath.
	(_dl_init_paths): Pass linkmap to fillin_rpath.

diff --git a/elf/dl-load.c b/elf/dl-load.c
index 6a73f27..a289a7d 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -481,14 +481,19 @@ static size_t max_dirnamelen;
 
 static struct r_search_path_elem **
 fillin_rpath (char *rpath, struct r_search_path_elem **result, const char *sep,
-	      int check_trusted, const char *what, const char *where)
+	      int check_trusted, const char *what, const char *where,
+	      struct link_map *l)
 {
   char *cp;
   size_t nelems = 0;
+  char *to_free;
 
   while ((cp = __strsep (&rpath, sep)) != NULL)
     {
       struct r_search_path_elem *dirp;
+
+      to_free = cp = expand_dynamic_string_token (l, cp);
+
       size_t len = strlen (cp);
 
       /* `strsep' can pass an empty string.  This has to be
@@ -509,7 +514,10 @@ fillin_rpath (char *rpath, struct r_search_path_elem **result, const char *sep,
 
       /* Make sure we don't use untrusted directories if we run SUID.  */
       if (__builtin_expect (check_trusted, 0) && !is_trusted_path (cp, len))
-	continue;
+	{
+	  free (to_free);
+	  continue;
+	}
 
       /* See if this directory is already known.  */
       for (dirp = GL(dl_all_dirs); dirp != NULL; dirp = dirp->next)
@@ -570,6 +578,7 @@ fillin_rpath (char *rpath, struct r_search_path_elem **result, const char *sep,
 	  /* Put it in the result array.  */
 	  result[nelems++] = dirp;
 	}
+      free (to_free);
     }
 
   /* Terminate the array.  */
@@ -627,7 +636,7 @@ decompose_rpath (struct r_search_path_struct *sps,
 
   /* Make a writable copy.  At the same time expand possible dynamic
      string tokens.  */
-  copy = expand_dynamic_string_token (l, rpath, 1);
+  copy = local_strdup (rpath);
   if (copy == NULL)
     {
       errstring = N_("cannot create RUNPATH/RPATH copy");
@@ -660,7 +669,7 @@ decompose_rpath (struct r_search_path_struct *sps,
       _dl_signal_error (ENOMEM, NULL, NULL, errstring);
     }
 
-  fillin_rpath (copy, result, ":", 0, what, where);
+  fillin_rpath (copy, result, ":", 0, what, where, l);
 
   /* Free the copied RPATH string.  `fillin_rpath' make own copies if
      necessary.  */
@@ -708,9 +717,7 @@ _dl_init_paths (const char *llp)
   const char *strp;
   struct r_search_path_elem *pelem, **aelem;
   size_t round_size;
-#ifdef SHARED
-  struct link_map *l;
-#endif
+  struct link_map __attribute__ ((unused)) *l = NULL;
   /* Initialize to please the compiler.  */
   const char *errstring = NULL;
 
@@ -865,7 +872,7 @@ _dl_init_paths (const char *llp)
 
       (void) fillin_rpath (llp_tmp, env_path_list.dirs, ":;",
 			   INTUSE(__libc_enable_secure), "LD_LIBRARY_PATH",
-			   NULL);
+			   NULL, l);
 
       if (env_path_list.dirs[0] == NULL)
 	{


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]