about summary refs log tree commit diff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2001-07-20 17:51:33 +0000
committerUlrich Drepper <drepper@redhat.com>2001-07-20 17:51:33 +0000
commit95ce33a55a958b3863188d65c4efc257721a0791 (patch)
treecdd3efa7b0818a22ae0f434fd4cb005afd83b5a0
parentbab889aa27e734478bc06b00c4aa89116952418c (diff)
downloadglibc-95ce33a55a958b3863188d65c4efc257721a0791.tar.gz
glibc-95ce33a55a958b3863188d65c4efc257721a0791.tar.xz
glibc-95ce33a55a958b3863188d65c4efc257721a0791.zip
(search_dir): Avoid use of uninitialized memory. Add a few __builtin_expect to mark unlikely error cases.
-rw-r--r--elf/ldconfig.c28
1 files changed, 23 insertions, 5 deletions
diff --git a/elf/ldconfig.c b/elf/ldconfig.c
index e1c3f84054..a087da85e4 100644
--- a/elf/ldconfig.c
+++ b/elf/ldconfig.c
@@ -654,7 +654,11 @@ search_dir (const struct dir_entry *entry)
       if (((strncmp (direntry->d_name, "lib", 3) != 0
 	    && strncmp (direntry->d_name, "ld-", 3) != 0)
 	   || strstr (direntry->d_name, ".so") == NULL)
-	  && !is_hwcap_platform (direntry->d_name))
+	  && (
+#ifdef _DIRENT_HAVE_D_TYPE
+	      direntry->d_type == DT_REG ||
+#endif
+	      !is_hwcap_platform (direntry->d_name)))
 	continue;
       len = strlen (entry->path) + strlen (direntry->d_name);
       if (len > file_name_len)
@@ -680,9 +684,9 @@ search_dir (const struct dir_entry *entry)
 	lstat_buf.st_mode = DTTOIF (direntry->d_type);
       else
 #endif
-	if (lstat64 (real_file_name, &lstat_buf))
+	if (__builtin_expect (lstat64 (real_file_name, &lstat_buf), 0))
 	  {
-	    error (0, errno, _("Can't lstat %s"), file_name);
+	    error (0, errno, _("Cannot lstat %s"), file_name);
 	    continue;
 	  }
 
@@ -691,10 +695,10 @@ search_dir (const struct dir_entry *entry)
         {
 	  /* In case of symlink, we check if the symlink refers to
 	     a directory. */
-	  if (stat64 (real_file_name, &stat_buf))
+	  if (__builtin_expect (stat64 (real_file_name, &stat_buf), 0))
 	    {
 	      if (opt_verbose)
-		error (0, errno, _("Can't stat %s"), file_name);
+		error (0, errno, _("Cannot stat %s"), file_name);
 	      continue;
 	    }
 	  is_dir = S_ISDIR (stat_buf.st_mode);
@@ -718,6 +722,20 @@ search_dir (const struct dir_entry *entry)
 	    }
 	  else
 	    {
+#ifdef _DIRENT_HAVE_D_TYPE
+	      /* We have filled in lstat only #ifndef
+		 _DIRENT_HAVE_D_TYPE.  Fill it in if needed.  */
+	      if (direntry->d_type != DT_UNKNOWN
+		  && __builtin_expect (lstat64 (real_file_name, &lstat_buf),
+				       0))
+		{
+		  error (0, errno, _("Cannot lstat %s"), file_name);
+		  free (new_entry->path);
+		  free (new_entry);
+		  continue;
+		}
+#endif
+
 	      new_entry->ino = lstat_buf.st_ino;
 	      new_entry->dev = lstat_buf.st_dev;
 	    }