[PATCH] Avoid segvs in ld.so

Jakub Jelinek jakub@redhat.com
Thu Aug 17 04:18:00 GMT 2000


Hi!

/lib/ld-linux.so.2 ls
used to work (it just printed:
ls: error while loading shared libraries: ls: cannot open shared object file: No such file or directory
and exited) but is crashing now instead.
This patch tries to fix it:

In this case, both loader and _dl_loaded are NULL, but we'd dereference it
to query l_flags_1.

2000-08-17  Jakub Jelinek  <jakub@redhat.com>

	* elf/dl-load.c (_dl_map_object): Don't crash if both loader and
	_dl_loaded are NULL.

--- libc/elf/dl-load.c.jj	Wed Aug 16 10:25:23 2000
+++ libc/elf/dl-load.c	Thu Aug 17 13:10:18 2000
@@ -1466,16 +1466,18 @@ _dl_map_object (struct link_map *loader,
 	     for compatibility with Linux's ldconfig program.  */
 	  extern const char *_dl_load_cache_lookup (const char *name);
 	  const char *cached = _dl_load_cache_lookup (name);
+
+#ifdef SHARED
+	  l = loader ?: _dl_loaded;
+#else
+	  l = loader;
+#endif
+
 	  if (cached)
 	    {
 	      /* If the loader has the DF_1_NODEFLIB flag set we must not
 		 use a cache entry from any of these directories.  */
-	      if (
-#ifndef SHARED
-		  loader != NULL &&
-#endif
-		  __builtin_expect ((loader ?: _dl_loaded)->l_flags_1
-				    & DF_1_NODEFLIB, 0))
+	      if (l && __builtin_expect (l->l_flags_1 & DF_1_NODEFLIB, 0))
 		{
 		  const char *dirp = system_dirs;
 		  int cnt = 0;
@@ -1514,12 +1516,8 @@ _dl_map_object (struct link_map *loader,
 
       /* Finally, try the default path.  */
       if (fd == -1
-	  && (
-#ifndef SHARED
-	      loader == NULL ||
-#endif
-	      __builtin_expect (!((loader ?: _dl_loaded)->l_flags_1
-				  & DF_1_NODEFLIB), 1)))
+	  && (l == NULL ||
+	      __builtin_expect (!(l->l_flags_1 & DF_1_NODEFLIB), 1)))
 	fd = open_path (name, namelen, preloaded, &rtld_search_dirs,
 			&realname);
 


	Jakub


More information about the Libc-hacker mailing list