From: Oliver Kurth Date: Fri, 15 Sep 2017 18:23:54 +0000 (-0700) Subject: Make TimeUtil_GetTimeFormat avoid a null pointer dereference if ctime_r fails X-Git-Tag: stable-10.2.0~69 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=321eaaafc80bc4d7e7c07b779d8021ff7adb27fc;p=thirdparty%2Fopen-vm-tools.git Make TimeUtil_GetTimeFormat avoid a null pointer dereference if ctime_r fails ctime_r potentially could return NULL on failure. Instead of blindly dereferencing the result, TimeUtil_GetTimeFormat should check for that and also return NULL (which callers should already expect on failure). --- diff --git a/open-vm-tools/lib/misc/timeutil.c b/open-vm-tools/lib/misc/timeutil.c index 50c68e674..c2210fe68 100644 --- a/open-vm-tools/lib/misc/timeutil.c +++ b/open-vm-tools/lib/misc/timeutil.c @@ -861,7 +861,9 @@ TimeUtil_GetTimeFormat(int64 utcTime, // IN: #else str = Util_SafeStrdup(ctime_r(&t, buf)); #endif - str[strlen(str) - 1] = '\0'; // Remove the trailing '\n'. + if (str != NULL) { + str[strlen(str) - 1] = '\0'; // Remove the trailing '\n'. + } return str; #endif // _WIN32