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

ensure we're not dereferencing null pointers #5

Open
jimkring opened this issue Jun 27, 2023 · 0 comments
Open

ensure we're not dereferencing null pointers #5

jimkring opened this issue Jun 27, 2023 · 0 comments

Comments

@jimkring
Copy link
Contributor

In this commit we added some code to toml_edit_item_get_type that checks if the item reference passed in from LabVIEW is null. If it is null, we don't try to deference it and just return a "None" value. We should do similar checks in other functions when receiving object references from LabVIEW before we de-reference them. If we don't, then we'll end up getting Error 1097 and/or crashing LabVIEW.

    ...
    // check if item has a null value
    if item.is_null() {
        let raw_string = match CString::new("None").unwrap().into_raw() {
            ptr if ptr.is_null() => {
                println!("Unable to allocate memory for string");
                return CString::new("").unwrap().into_raw();
            }
            ptr => ptr,
        };

        return raw_string;
    }

    // de-reference the item
    let item = unsafe { &mut *(item as *mut Item) };
    ...
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