Subject: port-pmax/11589: NetBSD pmax dlopen returns invalid handle
To: None <gnats-bugs@gnats.netbsd.org>
From: None <jsmolens+@andrew.cmu.edu>
List: netbsd-bugs
Date: 11/29/2000 12:57:11
>Number:         11589
>Category:       port-pmax
>Synopsis:       dlopen() returns non-zero handle when given 0 as library argument
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    port-pmax-maintainer
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Nov 29 12:57:00 PST 2000
>Closed-Date:
>Last-Modified:
>Originator:     Jared Smolens
>Release:        NetBSD 1.4.2 (GENERIC) pmax
>Organization:
Carnegie Mellon University
>Environment:
System: NetBSD mad-hatter 1.4.2 NetBSD 1.4.2 (GENERIC) #53: Wed Mar 15 10:14:32 EST 2000 root@vlad:/usr/src/sys/arch/pmax/compile/GENERIC pmax


>Description:

When given an argument of 0 for the path, dlopen() returns a bogus (non-zero) handle
to the shared library.  In testing, this handle was 536883200 (in decimal), although
this may be system-dependant.  When dlclose() is subsequently used to close the bogus
library handle, a segmentation fault occurs.

>How-To-Repeat:

This C code will cause a coredump at the dlclose() call.

--- Cut here ---

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

int
main ( int argc, char ** argv )
{
        void * handle = NULL;

        handle = dlopen ( 0, DL_LAZY );

        printf ( "handle: %d\n", handle );

        if ( !handle ) { 
                perror ( "Opening shared library" );
                printf ( "%s\n", dlerror() );
                return 1;
        }

        dlclose ( handle );

        return 0;

}

--- Uncut here ---

>Fix:

Verify that NULL input checking to dlopen() works and returns NULL if the path
argument is NULL.  
>Release-Note:
>Audit-Trail:
>Unformatted: