aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Thacker <johnthacker@gmail.com>2021-12-01 23:13:21 -0500
committerJohn Thacker <johnthacker@gmail.com>2021-12-02 14:19:49 +0000
commitaadf4efcbe06a96dba2e8eb8d600f3b9b73d9fa5 (patch)
treeac62ae13f6699984db3a5c5eae7a4eebe1c82be9
parent871895f95a3e9085424c91779b14a7ec589d55f4 (diff)
epan: Add ENC_ISO_8601_DATE_TIME_BASIC
Add the ISO 8601 Basic date time format as another string time option. This could be used for e.g. ASN.1 GeneralizedTime. Add tests for it.
-rw-r--r--epan/introspection-enums.c1
-rw-r--r--epan/proto.c11
-rw-r--r--epan/proto.h13
-rw-r--r--epan/tvbuff.c5
-rw-r--r--test/lua/globals_2.2.txt1
-rw-r--r--test/lua/tvb.lua43
-rw-r--r--wsutil/time_util.c3
7 files changed, 66 insertions, 11 deletions
diff --git a/epan/introspection-enums.c b/epan/introspection-enums.c
index 7a356da3e2..23fc859690 100644
--- a/epan/introspection-enums.c
+++ b/epan/introspection-enums.c
@@ -88,6 +88,7 @@ static ws_enum_t all_enums[] = {
ENUM(ENC_ISO_646_IRV),
ENUM(ENC_ISO_8601_DATE),
ENUM(ENC_ISO_8601_DATE_TIME),
+ ENUM(ENC_ISO_8601_DATE_TIME_BASIC),
ENUM(ENC_ISO_8601_TIME),
ENUM(ENC_ISO_8859_1),
ENUM(ENC_ISO_8859_10),
diff --git a/epan/proto.c b/epan/proto.c
index 1441b64de3..1099c51e94 100644
--- a/epan/proto.c
+++ b/epan/proto.c
@@ -4207,23 +4207,26 @@ proto_tree_add_time_item(proto_tree *tree, int hfindex, tvbuff_t *tvb,
DISSECTOR_ASSERT_HINT(hfinfo != NULL, "Not passed hfi!");
- DISSECTOR_ASSERT_FIELD_TYPE_IS_TIME(hfinfo);
-
/* length has to be -1 or > 0 regardless of encoding */
if (length < -1 || length == 0) {
REPORT_DISSECTOR_BUG("Invalid length %d passed to proto_tree_add_time_item",
length);
}
- time_stamp.secs = 0;
- time_stamp.nsecs = 0;
+ nstime_set_zero(&time_stamp);
if (encoding & ENC_STR_TIME_MASK) {
+ DISSECTOR_ASSERT_FIELD_TYPE(hfinfo, FT_ABSOLUTE_TIME);
+ /* The only string format that could be a relative time is
+ * ENC_ISO_8601_TIME, and that is treated as an absolute time
+ * relative to "now" currently.
+ */
tvb_get_string_time(tvb, start, length, encoding, &time_stamp, endoff);
/* grab the errno now before it gets overwritten */
saved_err = errno;
}
else {
+ DISSECTOR_ASSERT_FIELD_TYPE_IS_TIME(hfinfo);
const gboolean is_relative = (hfinfo->type == FT_RELATIVE_TIME) ? TRUE : FALSE;
tvb_ensure_bytes_exist(tvb, start, length);
diff --git a/epan/proto.h b/epan/proto.h
index 01b8e0cf05..b058edef81 100644
--- a/epan/proto.h
+++ b/epan/proto.h
@@ -613,13 +613,14 @@ void proto_report_dissector_bug(const char *format, ...)
* you can't do both at the same time. They must not, however,
* overlap with the character encoding values.
*/
-#define ENC_ISO_8601_DATE 0x00010000
-#define ENC_ISO_8601_TIME 0x00020000
-#define ENC_ISO_8601_DATE_TIME 0x00030000
-#define ENC_RFC_822 0x00040000
-#define ENC_RFC_1123 0x00080000
+#define ENC_ISO_8601_DATE 0x00010000
+#define ENC_ISO_8601_TIME 0x00020000
+#define ENC_ISO_8601_DATE_TIME 0x00030000
+#define ENC_RFC_822 0x00040000
+#define ENC_RFC_1123 0x00080000
+#define ENC_ISO_8601_DATE_TIME_BASIC 0x00100000
/* a convenience macro for the above - for internal use only */
-#define ENC_STR_TIME_MASK 0x000F0000
+#define ENC_STR_TIME_MASK 0x001F0000
/*
* Encodings for variable-length integral types.
diff --git a/epan/tvbuff.c b/epan/tvbuff.c
index e7ff264439..6c9f7dfe13 100644
--- a/epan/tvbuff.c
+++ b/epan/tvbuff.c
@@ -1796,6 +1796,11 @@ tvb_get_string_time(tvbuff_t *tvb, const gint offset, const gint length,
errno = 0;
end = ptr + num_chars;
}
+ } else if ((encoding & ENC_ISO_8601_DATE_TIME_BASIC) == ENC_ISO_8601_DATE_TIME_BASIC) {
+ if ((num_chars = iso8601_to_nstime(ns, ptr, ISO8601_DATETIME_BASIC))) {
+ errno = 0;
+ end = ptr + num_chars;
+ }
} else {
memset(&tm, 0, sizeof(tm));
tm.tm_isdst = -1;
diff --git a/test/lua/globals_2.2.txt b/test/lua/globals_2.2.txt
index 4d81a29360..e319bd21de 100644
--- a/test/lua/globals_2.2.txt
+++ b/test/lua/globals_2.2.txt
@@ -130,6 +130,7 @@
["ENC_EBCDIC"] = 46,
["ENC_ISO_8601_DATE"] = 65536,
["ENC_ISO_8601_DATE_TIME"] = 196608,
+ ["ENC_ISO_8601_DATE_TIME_BASIC"] = 1048576,
["ENC_ISO_8601_TIME"] = 131072,
["ENC_ISO_8859_1"] = 10,
["ENC_ISO_8859_10"] = 28,
diff --git a/test/lua/tvb.lua b/test/lua/tvb.lua
index 646e5a04cb..a8885fa7b9 100644
--- a/test/lua/tvb.lua
+++ b/test/lua/tvb.lua
@@ -54,7 +54,7 @@ end
-- number of verifyFields() * (1 + number of fields) +
-- number of verifyResults() * (1 + 2 * number of values)
--
-local taptests = { [FRAME]=4, [OTHER]=353 }
+local taptests = { [FRAME]=4, [OTHER]=413 }
local function getResults()
print("\n-----------------------------\n")
@@ -883,6 +883,47 @@ function test_proto.dissector(tvbuf,pktinfo,root)
verifyResults("add_pfield-rfc1123-local", autc_match_values)
----------------------------------------
+ testing(OTHER, "tree:add_packet_field Time string ENC_ISO_8601_DATE_TIME_BASIC")
+
+ resetResults()
+ autc_match_values = {}
+
+ local datetimestring1 = "20130301T221448+0000" -- this is 1362176088 seconds epoch time
+ local tvb1 = ByteArray.new(datetimestring1, true):tvb("Date_Time string 1")
+ local datetimestring2 = " 20130301171448+0500" -- this is 1362176088 seconds epoch time
+ local tvb2 = ByteArray.new(datetimestring2 .. " foobar", true):tvb("Date_Time string 2")
+ local datetimestring3 = " 20130301T1644+0530" -- this is 1362176040 seconds epoch time
+ local tvb3 = ByteArray.new(datetimestring3, true):tvb("Date_Time string 3")
+ local datetimestring4 = "20130302 014400-0330" -- this is 1362176040 seconds epoch time
+ local tvb4 = ByteArray.new(datetimestring4, true):tvb("Date_Time string 4")
+ local datetimestring5 = "20130301T221448Z" -- this is 1362176088 seconds epoch time
+ local tvb5 = ByteArray.new(datetimestring5, true):tvb("Date_Time string 5")
+ local datetimestring6 = "201303012214Z" -- this is 1362176040 seconds epoch time
+ local tvb6 = ByteArray.new(datetimestring6, true):tvb("Date_Time string 6")
+
+ execute ("add_pfield-datetime-local", treeAddPField ( tree, AUTC, tvb1:range(), ENC_ISO_8601_DATE_TIME_BASIC) )
+ addMatch( NSTime( 1362176088, 0), string.len(datetimestring1))
+
+ execute ("add_pfield-datetime-local", treeAddPField ( tree, AUTC, tvb2:range(), ENC_ISO_8601_DATE_TIME_BASIC) )
+ addMatch( NSTime( 1362176088, 0), string.len(datetimestring2))
+
+ execute ("add_pfield-datetime-local", treeAddPField ( tree, AUTC, tvb3:range(), ENC_ISO_8601_DATE_TIME_BASIC) )
+ addMatch( NSTime( 1362176040, 0), string.len(datetimestring3))
+
+ execute ("add_pfield-datetime-local", treeAddPField ( tree, AUTC, tvb4:range(), ENC_ISO_8601_DATE_TIME_BASIC) )
+ addMatch( NSTime( 1362176040, 0), string.len(datetimestring4))
+
+ execute ("add_pfield-datetime-local", treeAddPField ( tree, AUTC, tvb5:range(), ENC_ISO_8601_DATE_TIME_BASIC) )
+ addMatch( NSTime( 1362176088, 0), string.len(datetimestring5))
+
+ execute ("add_pfield-datetime-local", treeAddPField ( tree, AUTC, tvb6:range(), ENC_ISO_8601_DATE_TIME_BASIC) )
+ addMatch( NSTime( 1362176040, 0), string.len(datetimestring6))
+
+ verifyFields("time.ABSOLUTE_UTC", autc_match_fields)
+
+ verifyResults("add_pfield-datetime-local", autc_match_values)
+
+----------------------------------------
testing(OTHER, "TvbRange subsets")
resetResults()
diff --git a/wsutil/time_util.c b/wsutil/time_util.c
index 89aa883642..5ea9ddbd82 100644
--- a/wsutil/time_util.c
+++ b/wsutil/time_util.c
@@ -92,6 +92,9 @@ tm_is_valid(struct tm *tm)
if (tm->tm_hour < 0 || tm->tm_hour > 23) {
return FALSE;
}
+ /* XXX: ISO 8601 and others allow 24:00:00 for end of day, perhaps that
+ * one case should be allowed?
+ */
if (tm->tm_min < 0 || tm->tm_min > 59) {
return FALSE;
}