Skip to content

Commit 293b8ae

Browse files
1480c1dscho
authored andcommitted
winansi: check result and Buffer before using Name
NtQueryObject under Wine can return a success but fill out no name. In those situations, Wine will set Buffer to NULL, and set result to the sizeof(OBJECT_NAME_INFORMATION). Running a command such as echo "$(git.exe --version 2>/dev/null)" will crash due to a NULL pointer dereference when the code attempts to null terminate the buffer, although, weirdly, removing the subshell or redirecting stdout to a file will not trigger the crash. Code has been added to also check Buffer and Length to ensure the check is as robust as possible due to the current behavior being fragile at best, and could potentially change in the future This code is based on the behavior of NtQueryObject under wine and reactos. Signed-off-by: Christopher Degawa <[email protected]>
1 parent 5501b4a commit 293b8ae

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

compat/winansi.c

+3
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,9 @@ static void detect_msys_tty(int fd)
573573
if (!NT_SUCCESS(NtQueryObject(h, ObjectNameInformation,
574574
buffer, sizeof(buffer) - 2, &result)))
575575
return;
576+
if (result < sizeof(*nameinfo) || !nameinfo->Name.Buffer ||
577+
!nameinfo->Name.Length)
578+
return;
576579
name = nameinfo->Name.Buffer;
577580
name[nameinfo->Name.Length / sizeof(*name)] = 0;
578581

0 commit comments

Comments
 (0)