diff options
author | Guy Harris <guy@alum.mit.edu> | 2015-11-26 00:02:12 -0800 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2015-11-26 08:02:45 +0000 |
commit | 30f46b61bb7cbfbd8fe2ea18bf3c2b026a37969e (patch) | |
tree | 052176599f44332eaee520bd12abd6527d31e620 /wiretap/nettrace_3gpp_32_423.c | |
parent | ce9d2ee428ce699e8b1c0c184a38cd75441e8d25 (diff) |
Add a check for the day of the month.
Also, fix the month check ("month" is in the range 1 through 12, not 0
through 11), and if neither sscanf() gets the right number of fields,
fail immediately.
Change-Id: I3f0da49e969c020c292facb843b9741116647302
Reviewed-on: https://code.wireshark.org/review/12170
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'wiretap/nettrace_3gpp_32_423.c')
-rw-r--r-- | wiretap/nettrace_3gpp_32_423.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/wiretap/nettrace_3gpp_32_423.c b/wiretap/nettrace_3gpp_32_423.c index 935736bc78..d8ce0a024e 100644 --- a/wiretap/nettrace_3gpp_32_423.c +++ b/wiretap/nettrace_3gpp_32_423.c @@ -204,6 +204,8 @@ nettrace_close(wtap *wth) * "2001-09-11T09:30:47-05:00". */ +#define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0)) + static guint8* nettrace_parse_begin_time(guint8 *curr_pos, struct wtap_pkthdr *phdr) { @@ -212,6 +214,9 @@ nettrace_parse_begin_time(guint8 *curr_pos, struct wtap_pkthdr *phdr) int UTCdiffh; guint UTCdiffm; int scan_found; + static const guint days_in_month[12] = { + 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 + }; struct tm tm; guint8 *prev_pos, *next_pos; int length; @@ -240,8 +245,11 @@ nettrace_parse_begin_time(guint8 *curr_pos, struct wtap_pkthdr *phdr) /* Use the code below to set the time stamp */ scan_found = 8; } else { + phdr->presence_flags = 0; /* yes, we have no bananas^Wtime stamp */ + phdr->ts.secs = 0; + phdr->ts.nsecs = 0; g_warning("Failed to parse second time format, scan_found %u", scan_found); - scan_found = 0; + return curr_pos; } } if (scan_found == 8) { @@ -249,7 +257,7 @@ nettrace_parse_begin_time(guint8 *curr_pos, struct wtap_pkthdr *phdr) /* Only set time if we managed to parse it*/ /* Fill in remaining fields and return it in a time_t */ tm.tm_year = year - 1900; - if (month < 1 || month > 11) { + if (month < 1 || month > 12) { phdr->presence_flags = 0; /* yes, we have no bananas^Wtime stamp */ phdr->ts.secs = 0; phdr->ts.nsecs = 0; @@ -257,6 +265,14 @@ nettrace_parse_begin_time(guint8 *curr_pos, struct wtap_pkthdr *phdr) return curr_pos; } tm.tm_mon = month - 1; /* Zero count*/ + if (day > ((month == 2 && isleap(year)) ? 29 : days_in_month[month - 1])) { + phdr->presence_flags = 0; /* yes, we have no bananas^Wtime stamp */ + phdr->ts.secs = 0; + phdr->ts.nsecs = 0; + g_warning("Failed to parse time, %u-%02u-%2u is not a valid day", + year, month, day); + return curr_pos; + } tm.tm_mday = day; if (hour > 23) { phdr->presence_flags = 0; /* yes, we have no bananas^Wtime stamp */ |