From: Ralf Wildenhues Date: Fri, 1 Oct 2004 10:24:18 +0000 (+0000) Subject: * libltdl/lt__alloc.c (lt__memdup): Allocation can fail, so we X-Git-Tag: release-1-9d~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9bc5390549361e552c4e0cfcb1b7e547aa405739;p=thirdparty%2Flibtool.git * 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. --- diff --git a/ChangeLog b/ChangeLog index 0db962e5f..f958c5176 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2004-10-01 Ralf Wildenhues + * 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. diff --git a/libltdl/lt__alloc.c b/libltdl/lt__alloc.c index 0f769ea63..147a873c9 100644 --- a/libltdl/lt__alloc.c +++ b/libltdl/lt__alloc.c @@ -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 * diff --git a/libltdl/ltdl.c b/libltdl/ltdl.c index d0316928e..06ce70468 100644 --- a/libltdl/ltdl.c +++ b/libltdl/ltdl.c @@ -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; }