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

Unsoundness in "string_from_c_char" #1592

Open
lwz23 opened this issue Nov 27, 2024 · 3 comments
Open

Unsoundness in "string_from_c_char" #1592

lwz23 opened this issue Nov 27, 2024 · 3 comments

Comments

@lwz23
Copy link

lwz23 commented Nov 27, 2024

Describe the bug
The string_from_c_char functions use CStr::from_ptr to convert a raw pointer (*const c_char) into a CStr. However, the functions do not validate that the pointer meets the necessary safety requirements. This may lead to Undefined Behavior (UB) if the pointer is invalid, null, or if the data it references is not null-terminated.

let c_str = unsafe { CStr::from_ptr(c_char) };

pub fn string_from_c_char(c_char: *const c_char) -> Result<String> {
    let c_str = unsafe { CStr::from_ptr(c_char) };
    Ok(c_str.to_str()?.to_owned())
}

Expected behavior
The functions should validate the input pointer to ensure that:
It is not null.
It points to valid memory.
It references a null-terminated C string.
The functions should gracefully handle invalid inputs by returning an appropriate error instead of invoking Undefined Behavior.
Additional context
Expected behavior includes:
Validating the raw pointer before dereferencing it.
Ensuring the memory it points to is a valid, null-terminated C string.

@lwz23
Copy link
Author

lwz23 commented Dec 1, 2024

ping?

@kvinwang
Copy link
Collaborator

kvinwang commented Dec 1, 2024

@lwz23 Thank you for the discovery. However, the prouter component has ceased development and has never been integrated in any product. We plan to remove it from this repository.

@lwz23
Copy link
Author

lwz23 commented Dec 1, 2024

Ok, thanks for your reply :)

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

2 participants