Document that GetUserProfileDirectory sets the size of the path written on success#1810
Conversation
|
@ChrisDenton : Thanks for your contribution! The author(s) have been notified to review your proposed change. |
|
Hello, @jwmsft seems to not be responding and this has lain fallow for a year. Can we get a review from someone else? @drewbatgit or @stevewhims perhaps? |
|
Cc @cgettys-microsoft @sivadeilra -- this came up when discussing the semantics of a Miri shim.
FWIW this function has been un-deprecated in the mean time. |
|
FWIW - I believe that the SAL annotations actually do match the semantics that the proposed documentation update suggests (edit: corrected misreading of the annotations) (from a recent userenv.h on my local dev machine - e.g. "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um\UserEnv.h"). SAL reference: https://learn.microsoft.com/en-us/cpp/code-quality/annotating-function-parameters-and-return-values?view=msvc-170 //=============================================================================
//
// GetUserProfileDirectory
//
// Returns the path to the root of the requested user's profile
//
// hToken - User's token returned from LogonUser()
// lpProfileDir - Receives the path
// lpcchSize - Size of lpProfileDir
//
// Returns: TRUE if successful
// FALSE if not. Call GetLastError() for more details
//
// Note: If lpProfileDir is not large enough or NULL, the function will fail,
// and lpcchSize will contain the necessary buffer size.
//
// Example return value: C:\Users\Joe
//
//=============================================================================
USERENVAPI
BOOL
WINAPI
GetUserProfileDirectoryA(
_In_ HANDLE hToken,
_Out_writes_opt_(*lpcchSize) LPSTR lpProfileDir,
_Inout_ LPDWORD lpcchSize);
USERENVAPI
BOOL
WINAPI
GetUserProfileDirectoryW(
_In_ HANDLE hToken,
_Out_writes_opt_(*lpcchSize) LPWSTR lpProfileDir,
_Inout_ LPDWORD lpcchSize);
#ifdef UNICODE
#define GetUserProfileDirectory GetUserProfileDirectoryW
#else
#define GetUserProfileDirectory GetUserProfileDirectoryA
#endif // !UNICODE |
|
Actually, I might be slightly misreading this - it may be that technically the SAL annotations don't go quite far enough - but that may just be because the annotations are pretty verbose to be that precise with: |
|
The implementation meets the requirement that you want -- on successful return, This is strongly implied by the SAL annotations. I've checked the implementation and it guarantees this contract. |
… r=ChrisDenton GetUserProfileDirectoryW is now documented to always store the size Update to match MicrosoftDocs/sdk-api#1810 Also fix a bug in the Miri implementation while I am starting at that code... r? `@ChrisDenton` Fixes rust-lang#141254
… r=ChrisDenton GetUserProfileDirectoryW is now documented to always store the size Update to match MicrosoftDocs/sdk-api#1810 Also fix a bug in the Miri implementation while I am starting at that code... r? ``@ChrisDenton`` Fixes rust-lang#141254
… r=ChrisDenton GetUserProfileDirectoryW is now documented to always store the size Update to match MicrosoftDocs/sdk-api#1810 Also fix a bug in the Miri implementation while I am starting at that code... r? ```@ChrisDenton``` Fixes rust-lang#141254
Rollup merge of #141405 - RalfJung:GetUserProfileDirectoryW, r=ChrisDenton GetUserProfileDirectoryW is now documented to always store the size Update to match MicrosoftDocs/sdk-api#1810 Also fix a bug in the Miri implementation while I am starting at that code... r? ```@ChrisDenton``` Fixes #141254
…enton GetUserProfileDirectoryW is now documented to always store the size Update to match MicrosoftDocs/sdk-api#1810 Also fix a bug in the Miri implementation while I am starting at that code... r? ```@ChrisDenton``` Fixes #141254
… r=ChrisDenton GetUserProfileDirectoryW is now documented to always store the size Update to match MicrosoftDocs/sdk-api#1810 Also fix a bug in the Miri implementation while I am starting at that code... r? ```@ChrisDenton``` Fixes rust-lang#141254
It was discovered that this undocumented behaviour was being relied on by a long deprecated Rust stdlib function.
In confirming this behaviour applied to both
GetUserProfileDirectoryWandGetUserProfileDirectoryA, I found that theAfunction, unlike theWfunction, was not returningTRUEon success. Instead it also returns the size written to the buffer. I'm not sure if that part should be documented so I just changed the success case to nonzero and failure to zero.