aboutsummaryrefslogtreecommitdiffstats
path: root/editcap.c
diff options
context:
space:
mode:
authorGuy Harris <gharris@sonic.net>2020-08-06 02:10:04 -0700
committerGuy Harris <gharris@sonic.net>2020-08-06 09:26:09 +0000
commit613c1bd93147576df74a660e04449fd02a3e46de (patch)
treeddf94e2d412cbfc8302bf30daaf8c7ad930302a9 /editcap.c
parent75884bd0110558d4d08f802075b7086b371fd61f (diff)
editcap: clean up the parsing of fractional time in -A and -B.
Use ws_strtou32() so that we're guaranteed to produce a value that fits in a 32-bit integer (and don't get a narrowing warning on LP64 platforms for converting a long to an int), and then make sure it's less than one billion. Note, while we're at it, that you can, for example, specify a date of 2020-10-40 and it won't produce an error. Change-Id: I26c36d346cfa5c2bdc9ecdbdf821a9bc3529c940 Reviewed-on: https://code.wireshark.org/review/38065 Petri-Dish: Guy Harris <gharris@sonic.net> Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris <gharris@sonic.net>
Diffstat (limited to 'editcap.c')
-rw-r--r--editcap.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/editcap.c b/editcap.c
index a07f13fb5c..de0bd4e49b 100644
--- a/editcap.c
+++ b/editcap.c
@@ -1188,7 +1188,7 @@ main(int argc, char *argv[])
{
#define NSEC_MAXLEN 9
struct tm st_tm;
- int nsec = 0;
+ guint32 nsec = 0;
char *och;
memset(&st_tm,0,sizeof(struct tm));
@@ -1224,12 +1224,23 @@ main(int argc, char *argv[])
*c++ = '0';
}
*c = '\0';
- nsec = strtol(subsec, NULL, 10);
+ if (!ws_strtou32(subsec, NULL, &nsec) || nsec >= 1000000000) {
+ goto invalid_time;
+ }
}
check_startstop = TRUE;
st_tm.tm_isdst = -1;
+ /*
+ * XXX - this will normalize invalid dates rather than
+ * returning an error, so you could specify, for example,
+ * 2020-10-40 (to quote the macOS and probably *BSD manual
+ * page for ctime()/localtime()/mktime()/etc., "October 40
+ * is changed into November 9").
+ *
+ * Is that a bug or a feature?
+ */
if (opt == 'A') {
starttime.secs = mktime(&st_tm);
starttime.nsecs = nsec;