localtime() can return NULL, even if it's unlikely.

ANSI C says it can return NULL - and, at least on Windows with the MSVC
library, it *will* return null for dates prior to the Epoch.  Check for
a null return and handle it.

Fixes CID 1374109.

Change-Id: Ib18566d1a75e4109adb21834b157e87532fcac10
Reviewed-on: https://code.wireshark.org/review/18365
Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
Guy Harris 2016-10-21 17:08:03 -07:00
parent b3363fbbde
commit 49cf42c571
1 changed files with 4 additions and 1 deletions

View File

@ -365,7 +365,10 @@ void ImportTextDialog::on_dateTimeLineEdit_textChanged(const QString &time_forma
time(&cur_time);
cur_tm = localtime(&cur_time);
strftime(time_str, 100, ti_ui_->dateTimeLineEdit->text().toUtf8().constData(), cur_tm);
if (cur_tm != NULL)
strftime(time_str, sizeof time_str, ti_ui_->dateTimeLineEdit->text().toUtf8().constData(), cur_tm);
else
g_strlcpy(time_str, "Not representable", sizeof time_str);
ti_ui_->timestampExampleLabel->setText(QString(tr("Example: %1")).arg(time_str));
time_format_ok_ = true;
}