Merge branch 'mk/mingw-winansi-ttyname-termination-fix' into maint
authorJunio C Hamano <gitster@pobox.com>
Tue, 17 Jan 2017 23:19:03 +0000 (15:19 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 17 Jan 2017 23:19:03 +0000 (15:19 -0800)
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

1  2 
compat/winansi.c
index 477209fce7beedca3159a8140d2ac9e3a69400f3,6b4f736fdcc16d979ad3e8047a34e98afc33ddda..3c9ed3cfe07c1f3b58f5400af861fb8ae44c3fdb
@@@ -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