Agreed. I submitted one to dalnet-src@ but still hasn't made it to the list yet. We'll use yours since you took more precautions regarding dlsym()'s return than my code did.
Thanks!
On Thu, Dec 22, 2011 at 1:01 PM, Ned T. Crigler <RuneB@dal.net> wrote:
We were not clearing dlerror() before checking it, which caused us to
report the last error that occurred, even if it was not our fault.
Also check that dlsym never returns NULL. An error is better than a
crash in this case.
Original patch by Emilio Escobar, with some editing by me.
---
src/modules.c | 10 +++++++++-
1 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/src/modules.c b/src/modules.c
index 6e75ea4..26874b2 100644
--- a/src/modules.c
+++ b/src/modules.c
@@ -140,9 +140,17 @@ modsym_load(aClient *sptr, char *modname, char *symbol, void *modulehandle,
void *ret;
const char *error;
+ /* Clear dlerror() to make sure we're dealing with our own error. */
+ dlerror();
+
ret = dlsym(modulehandle, symbol);
+ error = dlerror();
+
+ /* Even if there was no error, ret must not be NULL or we will crash. */
+ if(error == NULL && ret == NULL)
+ error = "dlsym returned NULL";
- if((error = dlerror()) != NULL)
+ if(error != NULL)
{
if(sptr)
sendto_one(sptr, ":%s NOTICE %s :Module symbol error for %s/%s: %s",
--
1.7.7.3