-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
temporary_cstring_as_ptr doesn't catch UAF when Result is assigned to a variable #4375
Comments
A possible fix would be to search for method chains of |
For what it's worth, this came from a real world example: mozilla/neqo#145 |
Fix `temporary_cstring_as_ptr` false negative Fixes #4375. Changes the check to test when `.unwrap().as_ptr()` is called on any `Result<CString, _>` as suggested by @flip1995 (#4375 (comment)). changelog: Fix `temporary_cstring_as_ptr` false negative
I believe the example in the issue report should store a pointer in another variable to trigger UAF, like the example in clippy lint page: let c_str = CString::new("foo").unwrap().as_ptr();
unsafe {
foo(c_str);
} The pointer is valid in function |
Source:
clippy doesn't complain about this, even though it's equally dangerous to
foo(CString::new(v).unwrap().as_ptr())
. It should complain about this formulation as well.Tested with clippy on play.rust-lang.org:
0.0.212 (2019-08-11 72da101)
The text was updated successfully, but these errors were encountered: