From: Junio C Hamano Date: Tue, 17 Jan 2017 23:19:03 +0000 (-0800) Subject: Merge branch 'mk/mingw-winansi-ttyname-termination-fix' into maint X-Git-Tag: v2.11.1~37 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/8554ee155d8e69703dfaa04d03cd45f2d82f1a0f Merge branch 'mk/mingw-winansi-ttyname-termination-fix' into maint A potential but unlikely buffer overflow in Windows port has been fixed. * mk/mingw-winansi-ttyname-termination-fix: mingw: consider that UNICODE_STRING::Length counts bytes --- 8554ee155d8e69703dfaa04d03cd45f2d82f1a0f diff --cc compat/winansi.c index 477209fce7,6b4f736fdc..3c9ed3cfe0 --- a/compat/winansi.c +++ b/compat/winansi.c @@@ -540,17 -553,19 +540,17 @@@ static void detect_msys_tty(int fd buffer, sizeof(buffer) - 2, &result))) return; name = nameinfo->Name.Buffer; - name[nameinfo->Name.Length] = 0; + name[nameinfo->Name.Length / sizeof(*name)] = 0; - /* check if this could be a MSYS2 pty pipe ('msys-XXXX-ptyN-XX') */ - if (!wcsstr(name, L"msys-") || !wcsstr(name, L"-pty")) + /* + * Check if this could be a MSYS2 pty pipe ('msys-XXXX-ptyN-XX') + * or a cygwin pty pipe ('cygwin-XXXX-ptyN-XX') + */ + if ((!wcsstr(name, L"msys-") && !wcsstr(name, L"cygwin-")) || + !wcsstr(name, L"-pty")) return; - /* init ioinfo size if we haven't done so */ - if (init_sizeof_ioinfo()) - return; - - /* set FDEV flag, reset FPIPE flag */ - _pioinfo(fd)->osflags &= ~FPIPE; - _pioinfo(fd)->osflags |= FDEV; + fd_is_interactive[fd] |= FD_MSYS; } #endif