kernel32: Add some parameter checking to FileTimeToDosDateTime.
authorJuan Lang <juan.lang@gmail.com>
Mon, 7 Mar 2011 23:55:35 +0000 (15:55 -0800)
committerAlexandre Julliard <julliard@winehq.org>
Wed, 9 Mar 2011 11:28:41 +0000 (12:28 +0100)
dlls/kernel32/tests/time.c
dlls/kernel32/time.c

index 36dcbdfa5eabc5e2de8bbe6caaf8435c065a5bf2..b0d8a4632f7b2720b711d20f258d16dcb90b9bce 100644 (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)
 {
     HMODULE hKernel = GetModuleHandle("kernel32");
@@ -612,4 +649,5 @@ START_TEST(time)
     test_FileTimeToSystemTime();
     test_FileTimeToLocalFileTime();
     test_TzSpecificLocalTimeToSystemTime();
+    test_FileTimeToDosDateTime();
 }
index 2b7bd6cce7bfeff05faf0b676beab5db5e3f59ff..5dff796a1a6e00b78bc023b3771e047f7decb845 100644 (file)
@@ -1000,9 +1000,18 @@ BOOL WINAPI FileTimeToDosDateTime( const FILETIME *ft, LPWORD fatdate,
     time_t              unixtime;
     struct tm*          tm;
 
+    if (!fatdate || !fattime)
+    {
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return FALSE;
+    }
     li.u.LowPart = ft->dwLowDateTime;
     li.u.HighPart = ft->dwHighDateTime;
-    RtlTimeToSecondsSince1970( &li, &t );
+    if (!RtlTimeToSecondsSince1970( &li, &t ))
+    {
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return FALSE;
+    }
     unixtime = t;
     tm = gmtime( &unixtime );
     if (fattime)