Commit 024ece50 authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

msvcrt: Fix parameter validation in _stat64 function.

parent 0988938d
......@@ -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;
......
......@@ -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";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment