]> git.ipfire.org Git - thirdparty/libtool.git/commitdiff
* libltdl/lt__alloc.c (lt__memdup): Allocation can fail, so we
authorRalf Wildenhues <Ralf.Wildenhues@gmx.de>
Fri, 1 Oct 2004 10:24:18 +0000 (10:24 +0000)
committerGary V. Vaughan <gary@gnu.org>
Fri, 1 Oct 2004 10:24:18 +0000 (10:24 +0000)
need to guard against null pointer dereference here.
* libltdl/ltdl.c (lt_dlcaller_register): Ditto.

ChangeLog
libltdl/lt__alloc.c
libltdl/ltdl.c

index 0db962e5f390266a18f415a936c5bf5487db802f..f958c517632df86f7431b4de35d3af0757910754 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2004-10-01  Ralf Wildenhues  <Ralf.Wildenhues@gmx.de>
 
+       * libltdl/lt__alloc.c (lt__memdup): Allocation can fail, so we
+       need to guard against null pointer dereference here.
+       * libltdl/ltdl.c (lt_dlcaller_register): Ditto.
+
        * libltdl/slist.c (slist_foreach): result was declared as
        inner variable, shadowing the actually returned value.
 
index 0f769ea6374a096fd19c5903488f71de69588e44..147a873c90648e676f83c2feefb135bcf0e6a31e 100644 (file)
@@ -82,7 +82,12 @@ lt__realloc (void *mem, size_t n)
 void *
 lt__memdup (void const *mem, size_t n)
 {
-  return memcpy (lt__malloc (n), mem, n);
+  void *newmem;
+
+  if ((newmem = lt__malloc (n)))
+    return memcpy (newmem, mem, n);
+
+  return 0;
 }
 
 char *
index d0316928e528b4499f943c16a50bfc8bf25e2312..06ce70468c018c9014b0cd2c14cdabdc3247b98d 100644 (file)
@@ -1992,8 +1992,13 @@ lt_dlcaller_register (const char *id_string, lt_dlhandle_interface *iface)
 {
   lt__caller_id *caller_id = lt__malloc (sizeof *caller_id);
 
-  caller_id->id_string = lt__strdup (id_string);
-  caller_id->iface = iface;
+  /* If lt__malloc fails, it will LT__SETERROR (NO_MEMORY), which
+     can then be detected with lt_dlerror() if we return 0.  */
+  if (caller_id)
+    {
+      caller_id->id_string = lt__strdup (id_string);
+      caller_id->iface = iface;
+    }
 
   return (lt_dlcaller_id) caller_id;
 }