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

We are relying on undocumented behavior of GetUserProfileDirectoryW #124325

Open
RalfJung opened this issue Apr 24, 2024 · 1 comment
Open

We are relying on undocumented behavior of GetUserProfileDirectoryW #124325

RalfJung opened this issue Apr 24, 2024 · 1 comment
Labels
C-bug Category: This is a bug. O-windows Operating system: Windows T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@RalfJung
Copy link
Member

This is about this code:

super::fill_utf16_buf(
|buf, mut sz| {
match c::GetUserProfileDirectoryW(
ptr::without_provenance_mut(CURRENT_PROCESS_TOKEN),
buf,
&mut sz,
) {
0 if api::get_last_error().code != c::ERROR_INSUFFICIENT_BUFFER => 0,
0 => sz,
_ => sz - 1, // sz includes the null terminator
}
},
super::os2path,
)

According to the docs, the size pointer is updated as follows:

"If the buffer specified by lpProfileDir is not large enough or lpProfileDir is NULL, the function fails and this parameter receives the necessary buffer size, including the terminating null character."

The docs say nothing about what happens to the size pointer if the buffer is large enough (and not NULL). std however assumes that in that case, the size pointer is updated to the actual length of the data (including the null terminator). Reality seems to agree as otherwise we'd long have seen issues (and FWIW, wine agrees as well). Still, we're technically relying on undocumented behavior here.

Probably the best way forward is for the Windows docs to be updated.

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 24, 2024
@Nilstrieb
Copy link
Member

@ChrisDenton

@Nilstrieb Nilstrieb added O-windows Operating system: Windows C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. O-windows Operating system: Windows T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants