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

GetFinalPathNameByHandleW should be audited #12406

Closed
lilyball opened this issue Feb 19, 2014 · 2 comments
Closed

GetFinalPathNameByHandleW should be audited #12406

lilyball opened this issue Feb 19, 2014 · 2 comments
Labels
O-windows Operating system: Windows

Comments

@lilyball
Copy link
Contributor

The call to GetFinalPathNameByHandleW() in src/libnative/io/file.rs needs to be audited. I am not a Windows developer, but my interpretation of the documentation indicates that the buffer length provided to that function should be 1 less than the actual buffer size. The reasoning is that the documentation states:

cchFilePath [in]
The size of lpszFilePath, in TCHARs. This value does not include a NULL termination character.

yet the function itself will NULL-terminate the output it writes. To me this says that it will write one more TCHAR to the buffer than is indicated by cchFilePath.

This should be verified by someone who is actually familiar with Windows APIs.

@huonw
Copy link
Member

huonw commented Feb 19, 2014

It seems relatively likely that there would be other functions like this too.

@lilyball
Copy link
Contributor Author

Sure, I was looking at this in conjunction with fill_utf16_buf_and_decode(). There are only 3 Windows functions called with fill_utf16_buf_and_decode(), and the other two are documented as taking a size that includes the NULL. But it's entirely possible there are other Windows API functions used in other situations that have similar concerns.

bors added a commit to rust-lang-ci/rust that referenced this issue Jul 25, 2022
…-without-block, r=Veykril

fix: add an option to show inlay hint for return type of closures wit…

fix rust-lang#12321
flip1995 pushed a commit to flip1995/rust that referenced this issue Mar 7, 2024
…-of-core, r=Alexendoo

Dedup std_instead_of_core by using first segment span for uniqueness

Relates to rust-lang#12379.

Instead of checking that the paths have an identical span, it checks that the relevant `std` part of the path segment's span is identical. Added a multiline test, because my first implementation was worse and failed that, then I realized that you could grab the span off the first_segment `Ident`.

I did find another bug that isn't addressed by this, and that exists on master as well.

The path:
```Rust
use std::{io::Write, fmt::Display};
```

Will get fixed into:
```Rust
use core::{io::Write, fmt::Display};
```

Which doesn't compile since `io::Write` isn't in `core`, if any of those paths are present in `core` it'll do the replace and cause a miscompilation. Do you think I should file a separate bug for that? Since `rustfmt` default splits those up it isn't that big of a deal.

Rustfmt:
```Rust
// Pre
use std::{io::Write, fmt::Display};
// Post
use std::fmt::Display;
use std::io::Write;
```
---

changelog: [`std_instead_of_core`]: Fix duplicated output on multiple imports
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-windows Operating system: Windows
Projects
None yet
Development

No branches or pull requests

2 participants