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

Keep message pointer valid by binding CString #2

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

Conversation

chlohal
Copy link

@chlohal chlohal commented Mar 14, 2023

From the docs of as_ptr():

It is your responsibility to make sure that the underlying memory is not freed too early. For example, the following code will cause undefined behavior when ptr is used inside the unsafe block:

use std::ffi::CString;

let ptr = CString::new("Hello").expect("CString::new failed").as_ptr();
unsafe {
    // `ptr` is dangling
    *ptr;
}

I noticed that this causes an issue in PamConv::send, and fixed it by binding the CString to a variable, keeping it valid through the use of the pointer.

Please let me know if there are any issues with my PR! Although it's short, I'm just learning Rust, so I would definitely appreciate correction on any pitfalls that I've fallen into :)

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.

1 participant