Module: wine Branch: master Commit: 82f77cc17a190dbc87415fc697e76261fcbd972f URL: http://source.winehq.org/git/wine.git/?a=commit;h=82f77cc17a190dbc87415fc697...
Author: Jeff Zaroyko jeffz@jeffz.name Date: Tue Sep 30 15:34:51 2008 +1000
msvcrt: Avoid a NULL pointer deref in ctime.
---
dlls/msvcrt/tests/time.c | 8 ++++++++ dlls/msvcrt/time.c | 5 ++++- 2 files changed, 12 insertions(+), 1 deletions(-)
diff --git a/dlls/msvcrt/tests/time.c b/dlls/msvcrt/tests/time.c index 1fe6cbf..33b2e56 100644 --- a/dlls/msvcrt/tests/time.c +++ b/dlls/msvcrt/tests/time.c @@ -31,6 +31,13 @@ #define MINSPERHOUR 60 #define HOURSPERDAY 24
+static void test_ctime(void) +{ + time_t badtime = -1; + char* ret; + ret = ctime(&badtime); + ok(ret == NULL, "expected ctime to return NULL, got %s\n", ret); +} static void test_gmtime(void) { time_t gmt = (time_t)NULL; @@ -249,6 +256,7 @@ static void test_wstrtime(void)
START_TEST(time) { + test_ctime(); test_gmtime(); test_mktime(); test_localtime(); diff --git a/dlls/msvcrt/time.c b/dlls/msvcrt/time.c index 69762e0..ba4e95c 100644 --- a/dlls/msvcrt/time.c +++ b/dlls/msvcrt/time.c @@ -447,7 +447,10 @@ MSVCRT_wchar_t * CDECL MSVCRT__wasctime(const struct MSVCRT_tm *mstm) */ char * CDECL MSVCRT_ctime(const MSVCRT_time_t *time) { - return MSVCRT_asctime( MSVCRT_localtime(time) ); + struct MSVCRT_tm *t; + t = MSVCRT_localtime( time ); + if (!t) return NULL; + return MSVCRT_asctime( t ); }
/*********************************************************************