gmtime() 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 1374110.

Change-Id: I78bf92cfbb94a86544442269cc3b53338eb19778
Reviewed-on: https://code.wireshark.org/review/18361
Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
Guy Harris 2016-10-21 15:48:34 -07:00
parent 1b9d46a950
commit 362b83f44a
1 changed files with 4 additions and 1 deletions

View File

@ -5073,7 +5073,10 @@ static int dissect_cip_attribute(packet_info *pinfo, proto_tree *tree, proto_ite
/* Convert to nstime epoch */
computed_time = CIP_TIMEBASE+(temp_data*60*60*24);
date = gmtime(&computed_time);
strftime(date_str, 20, "%b %d, %Y", date);
if (date != NULL)
strftime(date_str, 20, "%b %d, %Y", date);
else
g_strlcpy(date_str, "Not representable", sizeof date_str);
proto_tree_add_uint_format_value(tree, *(attr->phf), tvb, offset, 2, temp_data, "%s", date_str);
consumed = 2;
break;