diff --git a/compat/winansi.c b/compat/winansi.c index ac2ffb78691a7d..d28137a20b0bcc 100644 --- a/compat/winansi.c +++ b/compat/winansi.c @@ -575,6 +575,9 @@ static void detect_msys_tty(int fd) if (!NT_SUCCESS(NtQueryObject(h, ObjectNameInformation, buffer, sizeof(buffer) - 2, &result))) return; + if (result < sizeof(*nameinfo) || !nameinfo->Name.Buffer || + !nameinfo->Name.Length) + return; name = nameinfo->Name.Buffer; name[nameinfo->Name.Length / sizeof(*name)] = 0;