]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Make TimeUtil_GetTimeFormat avoid a null pointer dereference if ctime_r fails
authorOliver Kurth <okurth@vmware.com>
Fri, 15 Sep 2017 18:23:54 +0000 (11:23 -0700)
committerOliver Kurth <okurth@vmware.com>
Fri, 15 Sep 2017 18:23:54 +0000 (11:23 -0700)
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).

open-vm-tools/lib/misc/timeutil.c

index 50c68e67451e6cef5a980e090138dc173a71271f..c2210fe6879381a705c8a1f3134629e9b0c3e955 100644 (file)
@@ -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