about summary refs log tree commit diff
path: root/elf
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2017-12-14 15:18:38 +0100
committerFlorian Weimer <fweimer@redhat.com>2017-12-14 15:27:08 +0100
commit8a0b17e48b83e933960dfeb8fa08b259f03f310e (patch)
tree34c8b4ae867dd10a5f340dcad1109efbfcd12bce /elf
parentf58bd7f055988d367d8118ccbc4cb8c4dbfd9db2 (diff)
downloadglibc-8a0b17e48b83e933960dfeb8fa08b259f03f310e.tar.gz
glibc-8a0b17e48b83e933960dfeb8fa08b259f03f310e.tar.xz
glibc-8a0b17e48b83e933960dfeb8fa08b259f03f310e.zip
elf: Compute correct array size in _dl_init_paths [BZ #22606]
Diffstat (limited to 'elf')
-rw-r--r--elf/dl-load.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/elf/dl-load.c b/elf/dl-load.c
index 10d859bd35..5f1f908599 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -37,6 +37,7 @@
 #include <sysdep.h>
 #include <stap-probe.h>
 #include <libc-pointer-arith.h>
+#include <array_length.h>
 
 #include <dl-dst.h>
 #include <dl-load.h>
@@ -103,7 +104,9 @@ static size_t ncapstr attribute_relro;
 static size_t max_capstrlen attribute_relro;
 
 
-/* Get the generated information about the trusted directories.  */
+/* Get the generated information about the trusted directories.  Use
+   an array of concatenated strings to avoid relocations.  See
+   gen-trusted-dirs.awk.  */
 #include "trusted-dirs.h"
 
 static const char system_dirs[] = SYSTEM_DIRS;
@@ -111,9 +114,7 @@ static const size_t system_dirs_len[] =
 {
   SYSTEM_DIRS_LEN
 };
-#define nsystem_dirs_len \
-  (sizeof (system_dirs_len) / sizeof (system_dirs_len[0]))
-
+#define nsystem_dirs_len array_length (system_dirs_len)
 
 static bool
 is_trusted_path (const char *path, size_t len)
@@ -685,9 +686,8 @@ _dl_init_paths (const char *llp)
 		 + ncapstr * sizeof (enum r_dir_status))
 		/ sizeof (struct r_search_path_elem));
 
-  rtld_search_dirs.dirs[0] = (struct r_search_path_elem *)
-    malloc ((sizeof (system_dirs) / sizeof (system_dirs[0]))
-	    * round_size * sizeof (struct r_search_path_elem));
+  rtld_search_dirs.dirs[0] = malloc (nsystem_dirs_len * round_size
+				     * sizeof (*rtld_search_dirs.dirs[0]));
   if (rtld_search_dirs.dirs[0] == NULL)
     {
       errstring = N_("cannot create cache for search path");