kernel32: Add some parameter checking to FileTimeToDosDateTime.

This commit is contained in:
Juan Lang 2011-03-07 15:55:35 -08:00 committed by Alexandre Julliard
parent c4d628cb02
commit 2ca58402e7
2 changed files with 48 additions and 1 deletions

View File

@ -600,6 +600,43 @@ static void test_TzSpecificLocalTimeToSystemTime(void)
} }
} }
static void test_FileTimeToDosDateTime(void)
{
FILETIME ft = { 0 };
WORD fatdate, fattime;
BOOL ret;
if (0)
{
/* Crashes */
FileTimeToDosDateTime(NULL, NULL, NULL);
}
/* Parameter checking */
SetLastError(0xdeadbeef);
ret = FileTimeToDosDateTime(&ft, NULL, NULL);
ok(!ret, "expected failure\n");
ok(GetLastError() == ERROR_INVALID_PARAMETER,
"expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
SetLastError(0xdeadbeef);
ret = FileTimeToDosDateTime(&ft, &fatdate, NULL);
ok(!ret, "expected failure\n");
ok(GetLastError() == ERROR_INVALID_PARAMETER,
"expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
SetLastError(0xdeadbeef);
ret = FileTimeToDosDateTime(&ft, NULL, &fattime);
ok(!ret, "expected failure\n");
ok(GetLastError() == ERROR_INVALID_PARAMETER,
"expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
SetLastError(0xdeadbeef);
ret = FileTimeToDosDateTime(&ft, &fatdate, &fattime);
ok(!ret, "expected failure\n");
ok(GetLastError() == ERROR_INVALID_PARAMETER,
"expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
}
START_TEST(time) START_TEST(time)
{ {
HMODULE hKernel = GetModuleHandle("kernel32"); HMODULE hKernel = GetModuleHandle("kernel32");
@ -612,4 +649,5 @@ START_TEST(time)
test_FileTimeToSystemTime(); test_FileTimeToSystemTime();
test_FileTimeToLocalFileTime(); test_FileTimeToLocalFileTime();
test_TzSpecificLocalTimeToSystemTime(); test_TzSpecificLocalTimeToSystemTime();
test_FileTimeToDosDateTime();
} }

View File

@ -1000,9 +1000,18 @@ BOOL WINAPI FileTimeToDosDateTime( const FILETIME *ft, LPWORD fatdate,
time_t unixtime; time_t unixtime;
struct tm* tm; struct tm* tm;
if (!fatdate || !fattime)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
li.u.LowPart = ft->dwLowDateTime; li.u.LowPart = ft->dwLowDateTime;
li.u.HighPart = ft->dwHighDateTime; li.u.HighPart = ft->dwHighDateTime;
RtlTimeToSecondsSince1970( &li, &t ); if (!RtlTimeToSecondsSince1970( &li, &t ))
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
unixtime = t; unixtime = t;
tm = gmtime( &unixtime ); tm = gmtime( &unixtime );
if (fattime) if (fattime)