You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I found a memory-safety/soundness issue in this crate while scanning Rust code for potential vulnerabilities. This PR contains a fix for the issue.
// read ok. forget overlapped to let the completion routine handle memory
mem::forget(overlapped);
If a panic!() occurs between the Box::new() function and std::mem::forget, a double free vulnerability emerges.
Fix
In Rust, std::mem::forget does not actually free the memory, instead it simply allows the memory to leak. This can lead to double free when the data object goes out of scope and its destructor is called automatically. The modification here uses std::mem::ManuallyDrop to wrap data. This ensures that data will not be automatically dropped when it goes out of scope, thus avoiding a double free scenario. With ManuallyDrop, we explicitly state that the data variable should not be dropped, thus avoiding any potential double free issues.
The text was updated successfully, but these errors were encountered:
Hi, thanks for reporting.
Adding ManuallyDrop doesn't seem to be wrong. However I can't find any way this could panic - at least not in a way that it creates a problem. The only thing that could panic is ReadDirectoryChangesW itself, which would mean the C-API of windows is panicking, as it's a direct wrapper.
Thanks for your answer. For now, I guess there is no possible panic!() here, but it may be important to fix this error for the progress of the project.
I will create a PR. Please let me know if there is any mistake.
Hi,
I found a memory-safety/soundness issue in this crate while scanning Rust code for potential vulnerabilities. This PR contains a fix for the issue.
Issue Description
notify/notify/src/windows.rs
Lines 281 to 310 in 5f40b83
If a panic!() occurs between the
Box::new()
function andstd::mem::forget
, a double free vulnerability emerges.Fix
In Rust,
std::mem::forget
does not actually free the memory, instead it simply allows the memory to leak. This can lead to double free when the data object goes out of scope and its destructor is called automatically. The modification here usesstd::mem::ManuallyDrop
to wrap data. This ensures that data will not be automatically dropped when it goes out of scope, thus avoiding a double free scenario. WithManuallyDrop
, we explicitly state that the data variable should not be dropped, thus avoiding any potential double free issues.The text was updated successfully, but these errors were encountered: