From 82f77cc17a190dbc87415fc697e76261fcbd972f Mon Sep 17 00:00:00 2001 From: Jeff Zaroyko Date: Tue, 30 Sep 2008 15:34:51 +1000 Subject: [PATCH] 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 deletion(-) diff --git a/dlls/msvcrt/tests/time.c b/dlls/msvcrt/tests/time.c index 1fe6cbf3340..33b2e56eeb1 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 69762e07724..ba4e95c7e3d 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 ); } /********************************************************************* -- 2.11.4.GIT