aboutsummaryrefslogtreecommitdiffstats
path: root/test/lua
diff options
context:
space:
mode:
authorGuy Harris <gharris@sonic.net>2023-09-07 18:59:31 -0700
committerGuy Harris <gharris@sonic.net>2023-09-07 19:03:02 -0700
commit5dbe4ee8a85f09e21cea99254e1931a86b3ce08e (patch)
treeea9979db4d9b462f0eb49af5db5de7171e7650d2 /test/lua
parent79ff5944394dd67d235f093aaee2c0cb5f4245fa (diff)
Clean up handling of string encodings for byte arrays and absolute times.
There is no reason to have separate "RFC 822" and "RFC 1123" parsing of Internet Message Format date/time values. RFC 1123 adds support for 4-digit years to RFC 822's 2-digit years; RFC 2822, which supplanted RFC 822, supports both, and RFC 5322, which supplanted RFC 2822, continues to do so. I know of no cases where *only* 2-digit years should be supported, especially given that it has beenover 23 years since January 1, 2000. Instead, have ENC_IMF_DATE_TIME for Internet Message Format date/time values; keep ENC_RFC_1123 for backwards compatibility, but treat it exactly the same as ENC_IMF_DATE_TIME. Keep ENC_RFC_822 around as an alias for ENC_IMF_DATE_TIME. Have separate expert infos for errors parsing string-encoded byte arrays and string-encoded dates and times, with the messages speaking of byte arrays and dates/times rather than "numbers". For now, have the only error being "couldn't convert"; we can add more for specific cases of what's wrong. In tvb_get_string_bytes() and tvb_get_string_time(), don't use errno as a way of indicating failure, use a return of NULL. Using errno 1) runs the risk of getting errno overwritten by intermediate calls and 2) would force assinging particular errno values, the set of which we don't control, to particular errors if we were to distinguish different errors in the future. In tvb_get_string_time(), for Internet Message Format date/time values, check for 2-digit and 3-digit years based on the length of the year field in the string. Handle them the way the RFCs say, not the way strptime() does (strptime(), which was originally written to allow programs to ask the user to specify a date and time and let them enter it in the locale's date and time format, and to use 2-digit years in case they were in the habit of doing so, which they might have been given that this was the mid 1980's; the choice of 1969 as the first "not 21st century" year was based on the fact that it was the earliest year for a date correspnding to a non-negative time_t value, which is UNIX-specific, unlike the Internet Message Format). Change tvb_get_string_time() to use guard clauses to handle errors; yes it involves gotos, but it's easier to read than nested ifs, for example. Update the Lua unit tests to reflect this.
Diffstat (limited to 'test/lua')
-rw-r--r--test/lua/tvb.lua51
1 files changed, 21 insertions, 30 deletions
diff --git a/test/lua/tvb.lua b/test/lua/tvb.lua
index 918123bab5..baf702cdd1 100644
--- a/test/lua/tvb.lua
+++ b/test/lua/tvb.lua
@@ -20,8 +20,10 @@ local OTHER = "other"
-- number of verifyFields() * (1 + number of fields) +
-- number of verifyResults() * (1 + 2 * number of values)
--
+-- if one happens to know the number of fields and the number of values.
+--
local n_frames = 1
-local taptests = { [FRAME]=n_frames, [OTHER]=413*n_frames }
+local taptests = { [FRAME]=n_frames, [OTHER]=391*n_frames }
testlib.init(taptests)
@@ -741,46 +743,35 @@ function test_proto.dissector(tvbuf,pktinfo,root)
verifyResults("add_pfield-time-local", autc_match_values)
----------------------------------------
- testlib.testing(OTHER, "tree:add_packet_field Time string ENC_RFC_822")
+ testlib.testing(OTHER, "tree:add_packet_field Time string ENC_IMF_DATE_TIME")
resetResults()
autc_match_values = {}
- local rfc822string1 = "Fri, 01 Mar 13 22:14:48 GMT" -- this is 1362176088 seconds epoch time
- local rfc822_tvb1 = ByteArray.new(rfc822string1, true):tvb("RFC 822 Time string 1")
- local rfc822string2 = " Fri, 01 Mar 13 22:14:48 GMT" -- this is 1362176088 seconds epoch time
- local rfc822_tvb2 = ByteArray.new(rfc822string2 .. " foobar", true):tvb("RFC 822 Time string 2")
-
- testlib.test(OTHER, "add_pfield-time-local", treeAddPField ( tree, AUTC, rfc822_tvb1:range(), ENC_RFC_822) )
- addMatch( NSTime( 1362176088, 0), string.len(rfc822string1))
-
- testlib.test(OTHER, "add_pfield-time-local", treeAddPField ( tree, AUTC, rfc822_tvb2:range(), ENC_RFC_822) )
- addMatch( NSTime( 1362176088, 0), string.len(rfc822string2))
-
- verifyFields("time.ABSOLUTE_UTC", autc_match_fields)
-
- verifyResults("add_pfield-rfc822-local", autc_match_values)
-
-----------------------------------------
- testlib.testing(OTHER, "tree:add_packet_field Time string ENC_RFC_1123")
+ local imfstring1 = "Fri, 01 Mar 13 22:14:48 GMT" -- this is 1362176088 seconds epoch time
+ local imf_tvb1 = ByteArray.new(imfstring1, true):tvb("Internet Message Format Time string 1")
+ local imfstring2 = " Fri, 01 Mar 13 22:14:48 GMT" -- this is 1362176088 seconds epoch time
+ local imf_tvb2 = ByteArray.new(imfstring2 .. " foobar", true):tvb("Internet Message Format Time string 2")
+ local imfstring3 = "Fri, 01 Mar 2013 22:14:48 GMT" -- this is 1362176088 seconds epoch time
+ local imf_tvb3 = ByteArray.new(imfstring3, true):tvb("Internet Message Format Time string 3")
+ local imfstring4 = " Fri, 01 Mar 2013 22:14:48 GMT" -- this is 1362176088 seconds epoch time
+ local imf_tvb4 = ByteArray.new(imfstring4 .. " foobar", true):tvb("Internet Message Format Time string 4")
- resetResults()
- autc_match_values = {}
+ testlib.test(OTHER, "add_pfield-time-local", treeAddPField ( tree, AUTC, imf_tvb1:range(), ENC_IMF_DATE_TIME) )
+ addMatch( NSTime( 1362176088, 0), string.len(imfstring1))
- local rfc1123string1 = "Fri, 01 Mar 2013 22:14:48 GMT" -- this is 1362176088 seconds epoch time
- local rfc1123_tvb1 = ByteArray.new(rfc1123string1, true):tvb("RFC 1123 Time string 1")
- local rfc1123string2 = " Fri, 01 Mar 2013 22:14:48 GMT" -- this is 1362176088 seconds epoch time
- local rfc1123_tvb2 = ByteArray.new(rfc1123string2 .. " foobar", true):tvb("RFC 1123 Time string 2")
+ testlib.test(OTHER, "add_pfield-time-local", treeAddPField ( tree, AUTC, imf_tvb2:range(), ENC_IMF_DATE_TIME) )
+ addMatch( NSTime( 1362176088, 0), string.len(imfstring2))
- testlib.test(OTHER, "add_pfield-time-local", treeAddPField ( tree, AUTC, rfc1123_tvb1:range(), ENC_RFC_1123) )
- addMatch( NSTime( 1362176088, 0), string.len(rfc1123string1))
+ testlib.test(OTHER, "add_pfield-time-local", treeAddPField ( tree, AUTC, imf_tvb3:range(), ENC_IMF_DATE_TIME) )
+ addMatch( NSTime( 1362176088, 0), string.len(imfstring3))
- testlib.test(OTHER, "add_pfield-time-local", treeAddPField ( tree, AUTC, rfc1123_tvb2:range(), ENC_RFC_1123) )
- addMatch( NSTime( 1362176088, 0), string.len(rfc1123string2))
+ testlib.test(OTHER, "add_pfield-time-local", treeAddPField ( tree, AUTC, imf_tvb4:range(), ENC_IMF_DATE_TIME) )
+ addMatch( NSTime( 1362176088, 0), string.len(imfstring4))
verifyFields("time.ABSOLUTE_UTC", autc_match_fields)
- verifyResults("add_pfield-rfc1123-local", autc_match_values)
+ verifyResults("add_pfield-imf-date-time-local", autc_match_values)
----------------------------------------
testlib.testing(OTHER, "tree:add_packet_field Time string ENC_ISO_8601_DATE_TIME_BASIC")