kernelbase: Check for invalid value in FileTimeToSystemTime.

Signed-off-by: Daniel Lehman <dlehman@esri.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Daniel Lehman 2022-03-15 10:15:13 -07:00 committed by Alexandre Julliard
parent a4a7ab8e3b
commit a5d14fa980
2 changed files with 7 additions and 3 deletions

View File

@ -400,11 +400,9 @@ static void test_FileTimeToSystemTime(void)
ft.dwLowDateTime = -1; ft.dwLowDateTime = -1;
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
ret = FileTimeToSystemTime(&ft, &st); ret = FileTimeToSystemTime(&ft, &st);
todo_wine {
ok(!ret, "expected failure\n"); ok(!ret, "expected failure\n");
ok(GetLastError() == ERROR_INVALID_PARAMETER, ok(GetLastError() == ERROR_INVALID_PARAMETER,
"expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError()); "expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
}
} }
static void test_FileTimeToLocalFileTime(void) static void test_FileTimeToLocalFileTime(void)

View File

@ -3874,8 +3874,14 @@ BOOL WINAPI DECLSPEC_HOTPATCH FileTimeToLocalFileTime( const FILETIME *utc, FILE
BOOL WINAPI DECLSPEC_HOTPATCH FileTimeToSystemTime( const FILETIME *ft, SYSTEMTIME *systime ) BOOL WINAPI DECLSPEC_HOTPATCH FileTimeToSystemTime( const FILETIME *ft, SYSTEMTIME *systime )
{ {
TIME_FIELDS tf; TIME_FIELDS tf;
const LARGE_INTEGER *li = (const LARGE_INTEGER *)ft;
RtlTimeToTimeFields( (const LARGE_INTEGER *)ft, &tf ); if (li->QuadPart < 0)
{
SetLastError( ERROR_INVALID_PARAMETER );
return FALSE;
}
RtlTimeToTimeFields( li, &tf );
systime->wYear = tf.Year; systime->wYear = tf.Year;
systime->wMonth = tf.Month; systime->wMonth = tf.Month;
systime->wDay = tf.Day; systime->wDay = tf.Day;