Skip to content

Commit

Permalink
compat/winansi: check result before using Name field
Browse files Browse the repository at this point in the history
NtQueryObject can return a success but fill out no name.
In those situations, it will set the last argument to the size of the
passed in struct, that being 16, to indicate that the name field is NULL.

Without this change, using git compiled for Windows under wine in certain
circumstances can result in a crash due to a null pointer dereference.

Signed-off-by: Christopher Degawa <[email protected]>
  • Loading branch information
1480c1 committed May 28, 2022
1 parent 3260e2e commit 8a45589
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions compat/winansi.c
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,8 @@ static void detect_msys_tty(int fd)
if (!NT_SUCCESS(NtQueryObject(h, ObjectNameInformation,
buffer, sizeof(buffer) - 2, &result)))
return;
if (result <= sizeof(*nameinfo))
return;
name = nameinfo->Name.Buffer;
name[nameinfo->Name.Length / sizeof(*name)] = 0;

Expand Down

0 comments on commit 8a45589

Please sign in to comment.