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

Maybe unsound in store #87

Open
lwz23 opened this issue Dec 9, 2024 · 2 comments
Open

Maybe unsound in store #87

lwz23 opened this issue Dec 9, 2024 · 2 comments

Comments

@lwz23
Copy link

lwz23 commented Dec 9, 2024

Hello, thank you for your contribution in this project. I am scanning the unsound problem in rust project and I notice the following code.

pub fn store(ts: *mut ffi::PyThreadState) -> PyThreadStateUnlimited {
    match VERSION.1 {
        6 => {
            let ts = ts as *mut PyThreadStateUnlimited3_6;
            unsafe {
                let unlimited = PyThreadStateUnlimited {
                    frame: (*ts).frame,
                    recursion_depth: (*ts).recursion_depth,
                    exc_type: (*ts).exc_type,
                    exc_value: (*ts).exc_value,
                    exc_traceback: (*ts).exc_traceback,
                    ..Default::default()
                };
                (*ts).frame = std::ptr::null_mut();
                (*ts).recursion_depth = 0;
                (*ts).exc_type = std::ptr::null_mut();
                (*ts).exc_value = std::ptr::null_mut();
                (*ts).exc_traceback = std::ptr::null_mut();
                unlimited
            }
        }
...................................

consider this is a pub fn and loader is a pub mod, I assume the user can direct call the store function. If the user pass a eg. null pointer to ts, it will lead to a UB in rust.

@lwz23
Copy link
Author

lwz23 commented Dec 9, 2024

if there is no external usage for store, maybe we should mark it as pub(crate) or mark it as unsafe?

@lwz23
Copy link
Author

lwz23 commented Dec 11, 2024

same for

pub fn restore(limited: *mut ffi::PyThreadState, unlimited: &PyThreadStateUnlimited) {

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