Skip to content

Crash if libproxy is unloaded and loaded again #285

@keltar

Description

@keltar

Here's a repro example:

#include <libproxy/proxy.h>
#include <dlfcn.h>
#include <stdio.h>

void *libproxy;
pxProxyFactory *(*factory_new)(void);
char **(*get_proxies)(pxProxyFactory *f, const char *url);

static void test_func(void) {
	pxProxyFactory *f = factory_new ();
	char **v = get_proxies (f, "https://www.amazon.com");
	printf("%p %p\n", f, v);
}

int main(int argc, char **argv) {
	libproxy = dlopen("libproxy.so", RTLD_NOW | RTLD_LOCAL);
	factory_new = dlsym(libproxy, "px_proxy_factory_new");
	get_proxies = dlsym(libproxy, "px_proxy_factory_get_proxies");
	test_func();
	dlclose(libproxy);

	libproxy = dlopen("libproxy.so", RTLD_NOW | RTLD_LOCAL);
	factory_new = dlsym(libproxy, "px_proxy_factory_new");
	get_proxies = dlsym(libproxy, "px_proxy_factory_get_proxies");
	test_func();

	return 0;
}

When builded somehow like this gcc -pipe -Wall test.c $(pkg-config glib-2.0 --cflags) -O0 -g3 -ld it crashes on second lookup. The problem seems to be it loses glib type information (saved as global variable?) and tries to register type again, which fails.

Yandex-disk linux client seems to be doing dlopen/dlclose things under the hood, rendering it unusable with libproxy-0.5+. With LD_PRELOAD it works fine.

Maybe there is a way to handle that on libproxy side?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions