Skip to content

Add safer segfault implementation #6

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Creative0708
Copy link

The current segfault implementation uses unsafe code. Unsafe code is discouraged as it can be a source of bugs, such as possible memory safety issues.

This PR adds a segfault implementation, segfault_safe, which only uses safe Rust. Although this may not be as reliable as the unsafe implementation, the benefit of using no unsafe code is evident.

Also, README.md has been updated to include an example of this implementation

@largenumberhere
Copy link

This is cool but I'd say it's arguably less safe because it relies on undefined behaviour in the rust compiler.

This approach tries to use invalid memory and the effect of that is completely platform dependant. Raising a signal, is to my knowledge far less platform-dependant because it doesn't rely on the platform to handle an invalid pointer correctly. Instead, it just directly tells libc to call to call the OS to say something bad happened. I could be wrong on this, my understanding assumes the libc function is sound and implemented correctly on all major platforms, which may not be true. I wouldn't put it past the C standard library to have a sloppy approach, C is well-known for its rampant undefined behaviour.

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

Successfully merging this pull request may close these issues.

2 participants