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

fix missing null termination in exepath string #32

Merged
merged 1 commit into from
Jan 2, 2019
Merged

fix missing null termination in exepath string #32

merged 1 commit into from
Jan 2, 2019

Conversation

maxxd
Copy link

@maxxd maxxd commented Jan 2, 2019

In find_exe_realpath when realexe is copied to exepath, there is no null termination. The wcsncpy function will only result in a null terminated string if a null is copied from the source to the destination. If the characters copied do not include a terminating null, it must be appended manually. Because exepath is uninitialized, the string will only terminate if the memory happened to have nulls at the position where the path ends.

Because the wrapper typically has a short life-span, the memory may generally be clean, but hook DLLs can leave it dirty enough to trigger this defect. In the case of git-for-windows/git#1855 this resulted in a child process bomb due to the garbage data later being acted upon due to dirty released memory from an Nvidia driver process hook.

In `find_exe_realpath` when `realexe` is copied to `exepath`, there is no null termination. The `wcsncpy` function will only result in a null terminated string if a null is copied from the source to the destination. If the characters copied do not include a terminating null, it must be appended manually. Because exepath is uninitialized, the string will only terminate if the memory happened to have nulls at the position where the path ends.

Because the wrapper typically has a short life-span, the memory may generally be clean, but hook DLLs can leave it dirty enough to trigger this defect. In the case of git-for-windows/git#1855 this resulted in a child process bomb due to the garbage data later being acted upon due to dirty released memory from an Nvidia driver process hook.

Signed-off-by: Maxx Daymon <maxx@maxxdaymon.com>
@dscho
Copy link
Member

dscho commented Jan 2, 2019

Excellent, thank you!

@dscho dscho merged commit 9249811 into git-for-windows:master Jan 2, 2019
dscho added a commit to git-for-windows/build-extra that referenced this pull request Jan 2, 2019
Certain drivers/anti-malware caused `git.exe` to hang, which [has
been fixed](git-for-windows/MINGW-packages#32).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
@maxxd maxxd deleted the git-wrapper-missing-null-termination branch January 6, 2019 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants