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

shouldn't raw::Library::open be unsafe? #48

Open
domenpk opened this issue Aug 7, 2023 · 0 comments
Open

shouldn't raw::Library::open be unsafe? #48

domenpk opened this issue Aug 7, 2023 · 0 comments

Comments

@domenpk
Copy link

domenpk commented Aug 7, 2023

I think open should probably be marked unsafe, because it could call a unsafe function, although not directly.

For example, below code demonstrates a constructor function is called on library load (no unsafe code needed):

cargo new dlopen-test
cd dlopen-test/

cat > hello.c << EOF
#include <stdio.h>

void __attribute__ ((constructor)) hello(void)
{
        printf("hello from C\n");
}
EOF

gcc -Wall -shared -fPIC -o hello.so hello.c
cat > src/main.rs << EOF
extern crate dlopen;
use dlopen::raw::Library;

fn main() {
    let lib = Library::open("./hello.so").unwrap();
}
EOF

cargo add dlopen
cargo run

# some cargo outputs, ends with this print from C code
hello from C
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