Juan Lang : kernel32: Add some parameter checking to FileTimeToDosDateTime.

Alexandre Julliard julliard at winehq.org
Wed Mar 9 11:12:47 CST 2011


Module: wine
Branch: master
Commit: 2ca58402e71b29aa06b4ef94b70ade8124ddd883
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=2ca58402e71b29aa06b4ef94b70ade8124ddd883

Author: Juan Lang <juan.lang at gmail.com>
Date:   Mon Mar  7 15:55:35 2011 -0800

kernel32: Add some parameter checking to FileTimeToDosDateTime.

---

 dlls/kernel32/tests/time.c |   38 ++++++++++++++++++++++++++++++++++++++
 dlls/kernel32/time.c       |   11 ++++++++++-
 2 files changed, 48 insertions(+), 1 deletions(-)

diff --git a/dlls/kernel32/tests/time.c b/dlls/kernel32/tests/time.c
index 36dcbdf..b0d8a46 100644
--- a/dlls/kernel32/tests/time.c
+++ b/dlls/kernel32/tests/time.c
@@ -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();
 }
diff --git a/dlls/kernel32/time.c b/dlls/kernel32/time.c
index 2b7bd6c..5dff796 100644
--- a/dlls/kernel32/time.c
+++ b/dlls/kernel32/time.c
@@ -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)




More information about the wine-cvs mailing list