From 1748adcc651ae0544e3ab0b22b965f0bacb7f3b0 Mon Sep 17 00:00:00 2001 From: "Gary V. Vaughan" Date: Wed, 1 Sep 2004 17:32:09 +0000 Subject: [PATCH] * libltdl/lt_dlloader.c (lt_dlloader_add): Handle malloc failure from slist_new. * libltdl/ltdl.c (loader_init): Trust lt_dlloader_add(), don't overwrite its error type, and simplify. Reported by Ralf Wildenhues --- ChangeLog | 8 ++++++++ libltdl/lt_dlloader.c | 34 +++++++++++++++++++++------------- libltdl/ltdl.c | 16 +++------------- 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index edf31703c..91e5b0d7b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2004-09-01 Gary V. Vaughan + + * libltdl/lt_dlloader.c (lt_dlloader_add): Handle malloc failure + from slist_new. + * libltdl/ltdl.c (loader_init): Trust lt_dlloader_add(), don't + overwrite its error type, and simplify. + Reported by Ralf Wildenhues + 2004-09-01 Ralf Wildenhues * libltdl/slist.c (slist_new): Handle malloc failure gracefully. diff --git a/libltdl/lt_dlloader.c b/libltdl/lt_dlloader.c index 8487747c1..1700cc019 100644 --- a/libltdl/lt_dlloader.c +++ b/libltdl/lt_dlloader.c @@ -59,29 +59,37 @@ loader_cmp (const SList *node, const void *userdata) int lt_dlloader_add (const lt_dlvtable *vtable) { - if ((vtable == 0) /* diagnose null parameters */ + SList *list; + + if ((vtable == 0) /* diagnose invalid vtable fields */ || (vtable->module_open == 0) || (vtable->module_close == 0) - || (vtable->find_sym == 0)) + || (vtable->find_sym == 0) + || ((vtable->priority != LT_DLLOADER_PREPEND) && + (vtable->priority != LT_DLLOADER_APPEND))) { LT__SETERROR (INVALID_LOADER); return RETURN_FAILURE; } - switch (vtable->priority) + list = slist_new (vtable); + if (!list) { - case LT_DLLOADER_PREPEND: - loaders = slist_cons (slist_new (vtable), loaders); - break; - - case LT_DLLOADER_APPEND: - loaders = slist_concat (loaders, slist_new (vtable)); - break; + (*lt__alloc_die) (); - default: - LT__SETERROR (INVALID_LOADER); + /* Let the caller know something went wrong if lt__alloc_die + doesn't abort. */ return RETURN_FAILURE; - /*NOTREACHED*/ + } + + if (vtable->priority == LT_DLLOADER_PREPEND) + { + loaders = slist_cons (list, loaders); + } + else + { + assert (vtable->priority == LT_DLLOADER_APPEND); + loaders = slist_concat (loaders, list); } return RETURN_SUCCESS; diff --git a/libltdl/ltdl.c b/libltdl/ltdl.c index 9c4215b10..27273595c 100644 --- a/libltdl/ltdl.c +++ b/libltdl/ltdl.c @@ -167,20 +167,10 @@ loader_init (lt_get_vtable *vtable_func, lt_user_data data) vtable = (*vtable_func) (data); } - if (!vtable) - { - LT__SETERROR (INVALID_LOADER); - ++errors; - } + /* lt_dlloader_add will LT__SETERROR if it fails. */ + errors += lt_dlloader_add (vtable); - if (!errors) - { - if (lt_dlloader_add (vtable)) - { - LT__SETERROR (DLOPEN_NOT_SUPPORTED); - ++errors; - } - } + assert (errors || vtable); if ((!errors) && vtable->dlloader_init) { -- 2.47.2