Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StabbyLibrary::get_stabbied causes segmentation fault if symbol is called init_module #65

Open
andreivasiliu opened this issue Apr 7, 2024 · 0 comments

Comments

@andreivasiliu
Copy link

If I try to use StabbyLibrary::get_stabbied on a function symbol named init_module, it returns something different compared to libloading and get_canaried.

To reproduce, rename the function called stable_fn to init_module in these two locations:

pub extern "C" fn stable_fn(v: u8) {

let stable_fn = lib.get_stabbied::<extern "C" fn(u8)>(b"stable_fn").unwrap();

Recompile, and notice how the println! from the library is no longer executed.

The returned function pointer executes something, but it is no longer the expected library function, and returns -1 instead. If -1 is not a valid value for the return type of the function, then this causes a segmentation fault when trying to use it.

This doesn't seem to happen when using the standard libloading without get_stabbied, nor when using get_canaried instead of get_stabbied.

Renaming it to anything else makes the issue go away.

My guess is it loads init_module from libc.so.6 instead for some reason? Do the libloading/RTLD flags or loading methods differ between get_stabbied and get_canaried?

I tried rustc 1.73 and 1.77.1, downloaded through rustup, on a NixOS 23.11 system, with libloading = "0.8.3" and stabby = { version = "4.0.4", features = ["libloading"] }.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant