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 dynamic_set.rs and from_mutated_str #279

Open
Ralith opened this issue Jul 6, 2023 · 0 comments
Open

Unsoundness in dynamic_set.rs and from_mutated_str #279

Ralith opened this issue Jul 6, 2023 · 0 comments

Comments

@Ralith
Copy link

Ralith commented Jul 6, 2023

Reviewing this crate's use of unsafe identified a few issues:

return NonNull::from(&mut **entry);

let entry_ptr: *mut Entry = &mut **entry_ptr;

These construct a &mut Entry that may exist concurrently with the &Entry references unsafely constructed by many methods on Atom. These should use the new ptr::addr_of_mut helper which avoids the hazard.

current = unsafe { &mut (*entry_ptr).next_in_bucket };

This similarly constructs a unique reference to a field, which may actually get written while an aliasing &Entry is live elsewhere. This probably needs an UnsafeCell.

let buffer = unsafe { &mut *buffer.as_mut_ptr() };

This constructs a reference to uninitialized memory. Raw pointer writes should be used instead.

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