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

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.