Permalink
Browse files

Adding pointer dereferencing after calling dlsym()

dlsym() resolves the location of the loaded symbol,
therefore dlsym() returns the type (fuse_module_factory_t *), not (fuse_module_factory_t).
Added pinter dereferencing to correctly refer the factory function.
  • Loading branch information...
mununum authored and Nikratio committed Sep 27, 2017
1 parent 77092d9 commit d92bf83c152ff88c2d92bd852752d4c326004400
Showing with 1 addition and 1 deletion.
  1. +1 −1 lib/fuse.c
View
@@ -263,7 +263,7 @@ static int fuse_load_so_module(const char *module)
}
sprintf(tmp, "fuse_module_%s_factory", module);
factory = dlsym(so->handle, tmp);
factory = *((fuse_module_factory_t *) dlsym(so->handle, tmp));
if (factory == NULL) {
fprintf(stderr, "fuse: symbol <%s> not found in module: %s\n",
tmp, dlerror());

2 comments on commit d92bf83

@mtheall

This comment has been minimized.

Show comment
Hide comment
@mtheall

mtheall Oct 31, 2017

This change is bogus. fuse_module_factory_t is already a pointer type. Additionally, if dlsym returns NULL, then you will be dereferencing it causing a segfault. In my testing, a segfault will happen even if dlsym returns successfully.

If any change is necessary to make this "correct", it'd look like this:

*(void**)(&factory) = dlsym(so->handle, tmp);

mtheall replied Oct 31, 2017

This change is bogus. fuse_module_factory_t is already a pointer type. Additionally, if dlsym returns NULL, then you will be dereferencing it causing a segfault. In my testing, a segfault will happen even if dlsym returns successfully.

If any change is necessary to make this "correct", it'd look like this:

*(void**)(&factory) = dlsym(so->handle, tmp);
@Nikratio

This comment has been minimized.

Show comment
Hide comment
@Nikratio

Nikratio Nov 3, 2017

Contributor

Applied, thanks!

Contributor

Nikratio replied Nov 3, 2017

Applied, thanks!

Please sign in to comment.