[libcompat] W32U_libc.c::W32U_stat64(): Work around an MSVCRT bug with regards to...
authorDavid Korth <gerbilsoft@gerbilsoft.com>
Sat, 5 Sep 2015 03:08:17 +0000 (23:08 -0400)
committerDavid Korth <gerbilsoft@gerbilsoft.com>
Sat, 5 Sep 2015 03:08:17 +0000 (23:08 -0400)
commit3f8c3204f809afd2a7919808d9366c9743d01de0
tree7f9e899936720ab1278eb825c7cbe67146030fdd
parentbdd897fef684bb49947013e8bd359631f88fd9ef
[libcompat] W32U_libc.c::W32U_stat64(): Work around an MSVCRT bug with regards to empty strings.

All versions of MSVCRT prior to MSVC 2015's UCRT have a bug where it will
blindly access pathname[1] without checking if pathname[0] is not NULL.
This can cause an out-of-bounds memory access if pathname[0] is the last
byte of a page, and the next page isn't allocated.

References:
- http://blogs.msdn.com/b/vcblog/archive/2014/06/18/crt-features-fixes-and-breaking-changes-in-visual-studio-14-ctp1.aspx
- http://connect.microsoft.com/VisualStudio/feedback/details/796796/msvcrt-stat-actually-stat64i32-blindly-refers-to-2nd-char-of-string-parameter
- https://github.com/dynamorio/drmemory/issues/1298#c1

In addition, W32U_stat64() will set errno = EFAULT if either pathname or
buf is NULL. MSVCRT would normally crash if that happened, while glibc
sets errno = EFAULT and returns -1.
src/libcompat/W32U/W32U_libc.c