From 362b83f44a4a6a731c64f8a6591ee717af2454a0 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Fri, 21 Oct 2016 15:48:34 -0700 Subject: [PATCH] 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 --- epan/dissectors/packet-cip.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/epan/dissectors/packet-cip.c b/epan/dissectors/packet-cip.c index 816b00e5de..bec93471f7 100644 --- a/epan/dissectors/packet-cip.c +++ b/epan/dissectors/packet-cip.c @@ -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;