[ros-diffs] [tfaber] 54298: [CRT] - Gracefully fail on NULL for gmtime functions. Fixes msvcrt:time crash

tfaber at svn.reactos.org tfaber at svn.reactos.org
Sat Nov 5 10:24:24 UTC 2011


Author: tfaber
Date: Sat Nov  5 10:24:24 2011
New Revision: 54298

URL: http://svn.reactos.org/svn/reactos?rev=54298&view=rev
Log:
[CRT]
- Gracefully fail on NULL for gmtime functions. Fixes msvcrt:time crash

Modified:
    trunk/reactos/lib/sdk/crt/time/gmtime.c

Modified: trunk/reactos/lib/sdk/crt/time/gmtime.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/time/gmtime.c?rev=54298&r1=54297&r2=54298&view=diff
==============================================================================
--- trunk/reactos/lib/sdk/crt/time/gmtime.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/time/gmtime.c [iso-8859-1] Sat Nov  5 10:24:24 2011
@@ -105,20 +105,19 @@
 {
     PTHREADDATA pThreadData;
     struct tm *ptm;
-    __time64_t time = *ptime;
 
     /* Validate parameters */
-    if (time < 0)
+    if (!ptime || *ptime < 0)
     {
-        return 0;
+        return NULL;
     }
 
     /* Get pointer to TLS tm buffer */
     pThreadData = GetThreadData();
     ptm = &pThreadData->tmbuf;
 
-    /* Use _gmtime_worker to do the ral work */
-    return _gmtime_worker(ptm, time, 0);
+    /* Use _gmtime_worker to do the real work */
+    return _gmtime_worker(ptm, *ptime, 0);
 }
 
 /******************************************************************************
@@ -129,7 +128,11 @@
 struct tm *
 _gmtime32(const __time32_t * ptime)
 {
-    __time64_t time64 = (__time64_t)*ptime;
+    __time64_t time64;
+
+    if (!ptime)
+        return NULL;
+    time64 = *ptime;
     return _gmtime64(&time64);
 }
 
@@ -141,6 +144,10 @@
 struct tm *
 gmtime(const time_t * ptime)
 {
-    __time64_t time64 = (__time64_t)*ptime;
+    __time64_t time64;
+
+    if (!ptime)
+        return NULL;
+    time64 = *ptime;
     return _gmtime64(&time64);
 }




More information about the Ros-diffs mailing list