Skip to content

Update buffer size notes for (Sym)FindExecutableImage(Ex)(W) #2013

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

Open
wants to merge 12 commits into
base: docs
Choose a base branch
from

Conversation

adeyblue
Copy link
Contributor

@adeyblue adeyblue commented May 7, 2025

All these functions assume a valid output buffer size of 261 characters (MAX_PATH+1).
The DbgHelp.h header has this information as SAL annotations (or whatever they're called this week) but it seems this information hasn't been migrated to the docs.

adeyblue added 5 commits May 7, 2025 23:22
For some reason this function passes MAX_PATH + 1 as the size of ImageFilePath to GetFullPathName, which dutifully clears MAX_PATH + 1 characters and writes past the end of a MAX_PATH sized buffer
@adeyblue
Copy link
Contributor Author

adeyblue commented May 8, 2025

@microsoft-github-policy-service agree company="Magical Glamour Executables"

Though one wonders how anyone can agree to term number 2 'before making a submission' if they're not shown the license until after it's been made

Copy link

@adeyblue : Thanks for your contribution! The author(s) and reviewer(s) have been notified to review your proposed change.

@Karl-Bridge-Microsoft
Copy link
Contributor

I scanned the dbghelp.h file and did not find a SAL annotation as you specify. Please provide this info.

@adeyblue
Copy link
Contributor Author

Karl, mate, please take all your holiday this year, you're clearly overworked.
There are 12 of these with SAL annotatons, they're in both dbghelp,h and imagehlp.h, and they've been there for at least 20 years.

HANDLE
IMAGEAPI
SymFindDebugInfoFile(
    _In_ HANDLE hProcess,
    _In_ PCSTR FileName,
    _Out_writes_(MAX_PATH + 1) PSTR DebugFilePath, <<<<<LOOK, ITS HERE, 1
    _In_opt_ PFIND_DEBUG_FILE_CALLBACK Callback,
    _In_opt_ PVOID CallerData
    );

HANDLE
IMAGEAPI
SymFindDebugInfoFileW(
    _In_ HANDLE hProcess,
    _In_ PCWSTR FileName,
    _Out_writes_(MAX_PATH + 1) PWSTR DebugFilePath,  <<<<<LOOK, ITS HERE, 2
    _In_opt_ PFIND_DEBUG_FILE_CALLBACKW Callback,
    _In_opt_ PVOID CallerData
    );

HANDLE
IMAGEAPI
FindDebugInfoFile (
    _In_ PCSTR FileName,
    _In_ PCSTR SymbolPath,
    _Out_writes_(MAX_PATH + 1) PSTR DebugFilePath  <<<<<LOOK, ITS HERE, 3
    );

HANDLE
IMAGEAPI
FindDebugInfoFileEx (
    _In_ PCSTR FileName,
    _In_ PCSTR SymbolPath,
    _Out_writes_(MAX_PATH + 1) PSTR  DebugFilePath,  <<<<<LOOK, ITS HERE, 4
    _In_opt_ PFIND_DEBUG_FILE_CALLBACK Callback,
    _In_opt_ PVOID CallerData
    );

HANDLE
IMAGEAPI
FindDebugInfoFileExW (
    _In_ PCWSTR FileName,
    _In_ PCWSTR SymbolPath,
    _Out_writes_(MAX_PATH + 1) PWSTR DebugFilePath,  <<<<<LOOK, ITS HERE, 5
    _In_opt_ PFIND_DEBUG_FILE_CALLBACKW Callback,
    _In_opt_ PVOID CallerData
    );

BOOL
IMAGEAPI
SymFindFileInPath(
    _In_ HANDLE hprocess,
    _In_opt_ PCSTR SearchPath,
    _In_ PCSTR FileName,
    _In_opt_ PVOID id,
    _In_ DWORD two,
    _In_ DWORD three,
    _In_ DWORD flags,
    _Out_writes_(MAX_PATH + 1) PSTR FoundFile,  <<<<<LOOK, ITS HERE, 6
    _In_opt_ PFINDFILEINPATHCALLBACK callback,
    _In_opt_ PVOID context
    );

BOOL
IMAGEAPI
SymFindFileInPathW(
    _In_ HANDLE hprocess,
    _In_opt_ PCWSTR SearchPath,
    _In_ PCWSTR FileName,
    _In_opt_ PVOID id,
    _In_ DWORD two,
    _In_ DWORD three,
    _In_ DWORD flags,
    _Out_writes_(MAX_PATH + 1) PWSTR FoundFile,  <<<<<LOOK, ITS HERE, 7
    _In_opt_ PFINDFILEINPATHCALLBACKW callback,
    _In_opt_ PVOID context
    );

HANDLE
IMAGEAPI
SymFindExecutableImage(
    _In_ HANDLE hProcess,
    _In_ PCSTR FileName,
    _Out_writes_(MAX_PATH + 1) PSTR ImageFilePath,  <<<<<LOOK, ITS HERE, 8
    _In_ PFIND_EXE_FILE_CALLBACK Callback,
    _In_ PVOID CallerData
    );

HANDLE
IMAGEAPI
SymFindExecutableImageW(
    _In_ HANDLE hProcess,
    _In_ PCWSTR FileName,
    _Out_writes_(MAX_PATH + 1) PWSTR ImageFilePath,  <<<<<LOOK, ITS HERE, 9
    _In_ PFIND_EXE_FILE_CALLBACKW Callback,
    _In_ PVOID CallerData
    );

HANDLE
IMAGEAPI
FindExecutableImage(
    _In_ PCSTR FileName,
    _In_ PCSTR SymbolPath,
    _Out_writes_(MAX_PATH + 1) PSTR ImageFilePath  <<<<<LOOK, ITS HERE, 10
    );

HANDLE
IMAGEAPI
FindExecutableImageEx(
    _In_ PCSTR FileName,
    _In_ PCSTR SymbolPath,
    _Out_writes_(MAX_PATH + 1) PSTR ImageFilePath,  <<<<<LOOK, ITS HERE, 11
    _In_opt_ PFIND_EXE_FILE_CALLBACK Callback,
    _In_opt_ PVOID CallerData
    );

HANDLE
IMAGEAPI
FindExecutableImageExW(
    _In_ PCWSTR FileName,
    _In_ PCWSTR SymbolPath,
    _Out_writes_(MAX_PATH + 1) PWSTR ImageFilePath,  <<<<<LOOK, ITS HERE, 12
    _In_opt_ PFIND_EXE_FILE_CALLBACKW Callback,
    _In_ PVOID CallerData
    );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants