NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lib/41760: dlclose and dlsym do not always prepare dlerror when they fail

>Number:         41760
>Category:       lib
>Synopsis:       dlclose and dlsym do not always prepare dlerror when they fail
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jul 21 19:00:00 +0000 2009
>Originator:     Taylor R Campbell <>
>Release:        NetBSD 5.0_STABLE
#0: Sun Jun 14 17:49:06 EDT 2009 
Architecture: i386
Machine: i386

        If dlclose or dlsym fail, they should prepare dlerror to yield
        appropriate error messages, but they do not always do so.


        Call dlclose or dlsym with a handle that is not known, such as
        NULL.  Observe that the call fails -- dlclose returns nonzero,
        or dlsym returns NULL.  Call dlerror to find the error string.
        Read a stale error string or NULL.

        Example:  The following program should exit with value 2 and
        print `dlclose: <message>', for some error message <message>.
        Instead, it prints two messages to standard error, of which
        one is from deep within ld.elf_so, and of which the other is
        `dlclose gave no error message'; then it exits with value 1.

#include <err.h>
#include <dlfcn.h>
#include <stdio.h>

main(int argc, char *argv[])
        if (dlclose(NULL) != 0)
                const char *error = dlerror();
                if (error == NULL)
                        errx(1, "dlclose gave no error message");
                        errx(2, "dlclose: %s", error);

        errx(3, "dlclose succeeded");


        Apply the following patch to src/libexec/ld.elf_so/rtld.c:

RCS file: /cvsroot/src/libexec/ld.elf_so/rtld.c,v
retrieving revision 1.124
diff -p -u -r1.124 rtld.c
--- rtld.c      19 May 2009 20:44:52 -0000      1.124
+++ rtld.c      21 Jul 2009 18:51:53 -0000
@@ -591,7 +591,7 @@ _rtld_dlcheck(void *handle)
        if (obj == NULL || obj->dl_refcount == 0) {
-               xwarnx("Invalid shared object handle %p", handle);
+               _rtld_error("Invalid shared object handle %p", handle);
                return NULL;
        return obj;

 Reply-To: riastradh
 X-send-pr-version: 3.95

Home | Main Index | Thread Index | Old Index