diff options
author | Bill Meier <wmeier@newsguy.com> | 2015-01-18 18:41:37 -0500 |
---|---|---|
committer | Bill Meier <wmeier@newsguy.com> | 2015-01-19 00:07:31 +0000 |
commit | 5162b7f146093a35d8bfc0facf88fb55737f9395 (patch) | |
tree | 2c8cf686ca6753b0e2111e786a1840bc0125b9ff /epan/dissectors/packet-smpp.c | |
parent | b2b640f02b1886fce8d4d93cf978dd4b019795cf (diff) |
smpp: Prevent crash if invalid date/time field.
gmtime()/localtime() can return NULL;
Bug 10868
Change-Id: I496bab62555c7741b3d159726e74a3d14c4b51cb
Reviewed-on: https://code.wireshark.org/review/6644
Reviewed-by: Bill Meier <wmeier@newsguy.com>
Diffstat (limited to 'epan/dissectors/packet-smpp.c')
-rw-r--r-- | epan/dissectors/packet-smpp.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/epan/dissectors/packet-smpp.c b/epan/dissectors/packet-smpp.c index 5e43e5395a..d92d726d2e 100644 --- a/epan/dissectors/packet-smpp.c +++ b/epan/dissectors/packet-smpp.c @@ -1147,7 +1147,11 @@ smpp_stats_tree_per_packet(stats_tree *st, /* st as it was passed to us */ * \param nsecs Returns the additional nano-seconds * * \return Whether time is specified relative (TRUE) or absolute (FALSE) + * If invalid abs time: return *secs = (time_t)(-1) and *nsecs=0 */ + +/* XXX: This function needs better error checking and handling */ + static gboolean smpp_mktime(const char *datestr, time_t *secs, int *nsecs) { @@ -1174,6 +1178,10 @@ smpp_mktime(const char *datestr, time_t *secs, int *nsecs) int gm_hour, gm_min; *secs = mktime(&r_time); + *nsecs = 0; + if (*secs == (time_t)(-1)) { + return relative; + } *nsecs = (datestr[12] - '0') * 100000000; t_diff = (10 * (datestr[13] - '0') + (datestr[14] - '0')) * 900; @@ -1190,11 +1198,14 @@ smpp_mktime(const char *datestr, time_t *secs, int *nsecs) * To do that, first determine how the time is represented in the * local time zone and in UTC. */ - gm = gmtime(secs); - gm_hour = gm->tm_hour; - gm_min = gm->tm_min; - local_time = localtime(secs); + if (((gm = gmtime(secs)) == NULL) || ((local_time = localtime(secs)) == NULL)) { + *secs = (time_t)(-1); + *nsecs = 0; + return relative; + } + gm_hour = gm->tm_hour; + gm_min = gm->tm_min; /* Then subtract out the difference between those times (whether the * difference is measured in hours, minutes, or both). */ |