msvcrt: Fix parameter validation in _stat64 function.

This commit is contained in:
Piotr Caban 2013-08-26 13:29:27 +02:00 committed by Alexandre Julliard
parent 0988938d0f
commit 024ece50e8
2 changed files with 14 additions and 2 deletions

View file

@ -2684,7 +2684,8 @@ int CDECL MSVCRT_stat64(const char* path, struct MSVCRT__stat64 * buf)
while (plen && path[plen-1]==' ')
plen--;
if (plen && (path[plen-1]=='\\' || path[plen-1]=='/'))
if (plen && (plen<2 || path[plen-2]!=':') &&
(path[plen-1]==':' || path[plen-1]=='\\' || path[plen-1]=='/'))
{
*MSVCRT__errno() = MSVCRT_ENOENT;
return -1;
@ -2784,7 +2785,8 @@ int CDECL MSVCRT__wstat64(const MSVCRT_wchar_t* path, struct MSVCRT__stat64 * bu
while (plen && path[plen-1]==' ')
plen--;
if(plen && (path[plen-1]=='\\' || path[plen-1]=='/'))
if(plen && (plen<2 || path[plen-2]!=':') &&
(path[plen-1]==':' || path[plen-1]=='\\' || path[plen-1]=='/'))
{
*MSVCRT__errno() = MSVCRT_ENOENT;
return -1;

View file

@ -1907,6 +1907,16 @@ static void test_stat(void)
}
else
skip("mkdir failed with errno %d\n", errno);
errno = 0xdeadbeef;
ret = stat("c:", &buf);
ok(ret == -1, "stat returned %d\n", ret);
ok(errno == ENOENT, "errno = %d\n", errno);
ret = stat("c:/", &buf);
ok(!ret, "stat returned %d\n", ret);
ok(buf.st_dev == 2, "st_dev = %d\n", buf.st_dev);
ok(buf.st_rdev == 2, "st_rdev = %d\n", buf.st_rdev);
}
static const char* pipe_string="Hello world";