From f63ad23ef9036a60e78e5efd45936aae1705d5ac Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Mon, 17 Apr 2017 00:48:20 -0700 Subject: [PATCH] Check for localtime() failing. It "shouldn't happen", but at least this squelches a Coverity complaint, CID 1398224. Change-Id: I9555f71a50574e9386a3c96d52143d838f7f121f Reviewed-on: https://code.wireshark.org/review/21160 Reviewed-by: Guy Harris --- ui/text_import.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ui/text_import.c b/ui/text_import.c index 0536028a5bf..812d34e64b0 100644 --- a/ui/text_import.c +++ b/ui/text_import.c @@ -921,6 +921,7 @@ text_import(text_import_info_t *info) { yyscan_t scanner; int ret; + struct tm *now_tm; packet_buf = (guint8 *)g_malloc(sizeof(HDR_ETHERNET) + sizeof(HDR_IP) + sizeof(HDR_SCTP) + sizeof(HDR_DATA_CHUNK) + @@ -938,8 +939,17 @@ text_import(text_import_info_t *info) packet_start = 0; packet_preamble_len = 0; ts_sec = time(0); /* initialize to current time */ - /* We trust the OS not to provide a time before the Epoch. */ - timecode_default = *localtime(&ts_sec); + now_tm = localtime(&ts_sec); + if (now_tm == NULL) { + /* + * This shouldn't happen - on UN*X, this should Just Work, and + * on Windows, it won't work if ts_sec is before the Epoch, + * but it's long after 1970, so.... + */ + fprintf(stderr, "localtime(right now) failed\n"); + exit(-1); + } + timecode_default = *now_tm; timecode_default.tm_isdst = -1; /* Unknown for now, depends on time given to the strptime() function */ ts_usec = 0;