]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - elf/dl-deps.c
Prefer https to http for gnu.org and fsf.org URLs
[thirdparty/glibc.git] / elf / dl-deps.c
index 20b8e94f2e06774d9893203dfe70dd3f5244f5a6..c29b9888b0d71d5a50f76df3b22b0f8f2ef3f61f 100644 (file)
@@ -1,5 +1,5 @@
 /* Load the dependencies of a mapped object.
-   Copyright (C) 1996-2018 Free Software Foundation, Inc.
+   Copyright (C) 1996-2019 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -14,7 +14,7 @@
 
    You should have received a copy of the GNU Lesser General Public
    License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
+   <https://www.gnu.org/licenses/>.  */
 
 #include <atomic.h>
 #include <assert.h>
@@ -27,6 +27,7 @@
 #include <unistd.h>
 #include <sys/param.h>
 #include <ldsodefs.h>
+#include <scratch_buffer.h>
 
 #include <dl-dst.h>
 
@@ -181,9 +182,8 @@ _dl_map_object_deps (struct link_map *map,
   /* Pointer to last unique object.  */
   tail = &known[nlist - 1];
 
-  /* No alloca'd space yet.  */
-  struct link_map **needed_space = NULL;
-  size_t needed_space_bytes = 0;
+  struct scratch_buffer needed_space;
+  scratch_buffer_init (&needed_space);
 
   /* Process each element of the search list, loading each of its
      auxiliary objects and immediate dependencies.  Auxiliary objects
@@ -213,13 +213,12 @@ _dl_map_object_deps (struct link_map *map,
       if (l->l_searchlist.r_list == NULL && l->l_initfini == NULL
          && l != map && l->l_ldnum > 0)
        {
-         size_t new_size = l->l_ldnum * sizeof (struct link_map *);
-
-         if (new_size > needed_space_bytes)
-           needed_space
-             = extend_alloca (needed_space, needed_space_bytes, new_size);
-
-         needed = needed_space;
+         /* l->l_ldnum includes space for the terminating NULL.  */
+         if (!scratch_buffer_set_array_size
+             (&needed_space, l->l_ldnum, sizeof (struct link_map *)))
+           _dl_signal_error (ENOMEM, map->l_name, NULL,
+                             N_("cannot allocate dependency buffer"));
+         needed = needed_space.data;
        }
 
       if (l->l_info[DT_NEEDED] || l->l_info[AUXTAG] || l->l_info[FILTERTAG])
@@ -438,8 +437,11 @@ _dl_map_object_deps (struct link_map *map,
          struct link_map **l_initfini = (struct link_map **)
            malloc ((2 * nneeded + 1) * sizeof needed[0]);
          if (l_initfini == NULL)
-           _dl_signal_error (ENOMEM, map->l_name, NULL,
-                             N_("cannot allocate dependency list"));
+           {
+             scratch_buffer_free (&needed_space);
+             _dl_signal_error (ENOMEM, map->l_name, NULL,
+                               N_("cannot allocate dependency list"));
+           }
          l_initfini[0] = l;
          memcpy (&l_initfini[1], needed, nneeded * sizeof needed[0]);
          memcpy (&l_initfini[nneeded + 1], l_initfini,
@@ -457,6 +459,8 @@ _dl_map_object_deps (struct link_map *map,
     }
 
  out:
+  scratch_buffer_free (&needed_space);
+
   if (errno == 0 && errno_saved != 0)
     __set_errno (errno_saved);