[Date Prev][Date Next] [Chronological] [Thread] [Top]

RE: FW: atexit-handler causes segfault when dlopen-ed libldap is unloaded prior to program termination (ITS#1577)



I've committed a preliminary fix for this problem. It works, but it requires
gcc;
I don't know a portable way to trigger these mechanisms on all the possible
platform combinations. If the compiler doesn't provide a mechanism, then you
have to resort to platform-specific link options instead. All in all, pretty
messy to put in a comprehensive fix.

> -----Original Message-----
> From: Kurt D. Zeilenga [mailto:Kurt@OpenLDAP.org]

> At 04:13 PM 2002-02-04, Howard Chu wrote:
> >Perhaps we should instead have a public ldap_pvt_destroy() function that
> >callers explicitly used to clean up the LDAP library?
>
> My thoughts are to have a init()/destroy() function pair.
> If the init() function is called as the first function,
> then the atexit() handler will be avoided and a destroy()
> call expected.
>
>         ldap_x_initialize();
>         ldap_x_destroy();
>
> I suspect that dlopen/dlclose() provides a means for library
> init/destroy routines to be called.  A little glue would
> be nice.
>
> Kurt
>
>
> >  -- Howard Chu
> >  Chief Architect, Symas Corp.       Director, Highland Sun
> >  http://www.symas.com               http://highlandsun.com/hyc
> >  Symas: Premier OpenSource Development and Support
> >
> >-----Original Message-----
> >From: owner-openldap-bugs@OpenLDAP.org
> >[mailto:owner-openldap-bugs@OpenLDAP.org] On Behalf Of argggh@linpro.no
> >Sent: Monday, February 04, 2002 1:24 AM
> >To: openldap-its@OpenLDAP.org
> >Subject: atexit-handler causes segfault when dlopen-ed libldap is
> >unloaded prior to program termination (ITS#1577)
> >
> >
> >Full_Name: Arne Georg Gleditsch
> >Version: 2.0.21
> >OS: GNU/Linux
> >URL:
> >Submission from: (NULL) (213.203.57.130)
> >
> >
> >openldap-2.0.21/libraries/libldap/init.c contains the statement
> >"atexit(ldap_int_destroy_global_options)".  This causes programs
> >that load and unload libldap using dlopen to segfault upon
> termination because
> >one of the exit handlers reside in now unmapped memory.  Trivial example
> >program:
> >
> >#include <stdio.h>
> >#include <dlfcn.h>
> >
> >int main() {
> >    void *(* ldap_init)(const char *, int);
> >    void *ldap = NULL;
> >    char *error;
> >
> >    void *handle = dlopen("libldap.so.2", RTLD_LAZY);
> >
> >    if (error = dlerror()) {
> >        printf("%s\n", error);
> >        exit();
> >    }
> >
> >    ldap_init = dlsym(handle, "ldap_init");
> >    if (error = dlerror()) {
> >        printf("%s\n", error);
> >        exit();
> >    }
> >
> >    printf("libldap loaded.\n");
> >
> >    ldap_init("localhost", 389);
> >
> >    dlclose(handle);
> >
> >    printf("libldap unloaded.\n");
> >}
> >
> >This is a real problem with pam-ldap, as su is now segfaulting
> at exit on my
> >systems. Other services are likely affected as well.
>

  -- Howard Chu
  Chief Architect, Symas Corp.       Director, Highland Sun
  http://www.symas.com               http://highlandsun.com/hyc
  Symas: Premier OpenSource Development and Support