aboutsummaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--doc/README.dissector2
-rw-r--r--epan/introspection-enums.c1
-rw-r--r--epan/proto.c106
-rw-r--r--epan/proto.h9
-rw-r--r--epan/tvbuff.c213
-rw-r--r--epan/tvbuff.h4
-rw-r--r--test/lua/tvb.lua51
7 files changed, 242 insertions, 144 deletions
diff --git a/doc/README.dissector b/doc/README.dissector
index 264e5c7d37..4252bda2aa 100644
--- a/doc/README.dissector
+++ b/doc/README.dissector
@@ -1727,7 +1727,7 @@ For string-decoding, the passed-in encoding argument needs to specify the
string encoding (e.g., ENC_ASCII, ENC_UTF_8) as well as the format. For
some XXX types, the format is constrained - for example for the encoding format
for proto_tree_add_time_item() can only be one of the ENC_ISO_8601_* ones
-or ENC_RFC_822 or ENC_RFC_1123. For proto_tree_add_bytes_item() it can only
+or ENC_IMF_DATE_TIME. For proto_tree_add_bytes_item() it can only
be ENC_STR_HEX bit-or'ed with one or more of the ENC_SEP_* separator types.
proto_tree_add_protocol_format()
diff --git a/epan/introspection-enums.c b/epan/introspection-enums.c
index fa0bcec9e3..28692911bf 100644
--- a/epan/introspection-enums.c
+++ b/epan/introspection-enums.c
@@ -97,6 +97,7 @@ static ws_enum_t all_enums[] = {
ENUM(ENC_EUC_KR),
ENUM(ENC_GB18030),
ENUM(ENC_HOST_ENDIAN),
+ ENUM(ENC_IMF_DATE_TIME),
ENUM(ENC_ISO_646_BASIC),
ENUM(ENC_ISO_646_IRV),
ENUM(ENC_ISO_8601_DATE),
diff --git a/epan/proto.c b/epan/proto.c
index b438d3fe3b..4753906a65 100644
--- a/epan/proto.c
+++ b/epan/proto.c
@@ -348,11 +348,15 @@ static expert_field ei_type_length_mismatch_error = EI_INIT;
static expert_field ei_type_length_mismatch_warn = EI_INIT;
static void register_type_length_mismatch(void);
-/* Handle number string decoding errors with expert info */
-static int proto_number_string_decoding_error = -1;
-static expert_field ei_number_string_decoding_failed_error = EI_INIT;
-static expert_field ei_number_string_decoding_erange_error = EI_INIT;
-static void register_number_string_decodinws_error(void);
+/* Handle byte array string decoding errors with expert info */
+static int proto_byte_array_string_decoding_error = -1;
+static expert_field ei_byte_array_string_decoding_failed_error = EI_INIT;
+static void register_byte_array_string_decodinws_error(void);
+
+/* Handle date and time string decoding errors with expert info */
+static int proto_date_time_string_decoding_error = -1;
+static expert_field ei_date_time_string_decoding_failed_error = EI_INIT;
+static void register_date_time_string_decodinws_error(void);
/* Handle string errors expert info */
static int proto_string_errors = -1;
@@ -586,7 +590,8 @@ proto_init(GSList *register_all_plugin_protocols_list,
/* Register the pseudo-protocols used for exceptions. */
register_show_exception();
register_type_length_mismatch();
- register_number_string_decodinws_error();
+ register_byte_array_string_decodinws_error();
+ register_date_time_string_decodinws_error();
register_string_errors();
ftypes_register_pseudofields();
col_register_protocol();
@@ -4292,7 +4297,7 @@ proto_tree_add_bytes_item(proto_tree *tree, int hfindex, tvbuff_t *tvb,
field_info *new_fi;
GByteArray *bytes = retval;
GByteArray *created_bytes = NULL;
- gint saved_err = 0;
+ gboolean failed = FALSE;
guint32 n = 0;
header_field_info *hfinfo;
gboolean generate = (bytes || tree) ? TRUE : FALSE;
@@ -4323,11 +4328,14 @@ proto_tree_add_bytes_item(proto_tree *tree, int hfindex, tvbuff_t *tvb,
bytes = created_bytes = g_byte_array_new();
}
- /* bytes might be NULL after this, but can't add expert error until later */
+ /*
+ * bytes might be NULL after this, but can't add expert
+ * error until later; if it's NULL, just note that
+ * it failed.
+ */
bytes = tvb_get_string_bytes(tvb, start, length, encoding, bytes, endoff);
-
- /* grab the errno now before it gets overwritten */
- saved_err = errno;
+ if (bytes == NULL)
+ failed = TRUE;
}
else if (generate) {
tvb_ensure_bytes_exist(tvb, start, length);
@@ -4353,7 +4361,8 @@ proto_tree_add_bytes_item(proto_tree *tree, int hfindex, tvbuff_t *tvb,
*endoff = start + n + length;
}
- if (err) *err = saved_err;
+ if (err)
+ *err = failed ? EINVAL : 0;
CHECK_FOR_NULL_TREE_AND_FREE(tree,
{
@@ -4375,10 +4384,8 @@ proto_tree_add_bytes_item(proto_tree *tree, int hfindex, tvbuff_t *tvb,
new_fi = new_field_info(tree, hfinfo, tvb, start, n + length);
if (encoding & ENC_STRING) {
- if (saved_err == ERANGE)
- expert_add_info(NULL, tree, &ei_number_string_decoding_erange_error);
- else if (!bytes || saved_err != 0)
- expert_add_info(NULL, tree, &ei_number_string_decoding_failed_error);
+ if (failed)
+ expert_add_info(NULL, tree, &ei_byte_array_string_decoding_failed_error);
if (bytes)
proto_tree_set_bytes_gbytearray(new_fi, bytes);
@@ -4430,9 +4437,8 @@ proto_tree_add_time_item(proto_tree *tree, int hfindex, tvbuff_t *tvb,
* 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;
+ if (!tvb_get_string_time(tvb, start, length, encoding, &time_stamp, endoff))
+ saved_err = EINVAL;
}
else {
DISSECTOR_ASSERT_FIELD_TYPE_IS_TIME(hfinfo);
@@ -4459,10 +4465,8 @@ proto_tree_add_time_item(proto_tree *tree, int hfindex, tvbuff_t *tvb,
proto_tree_set_time(new_fi, &time_stamp);
if (encoding & ENC_STRING) {
- if (saved_err == ERANGE)
- expert_add_info(NULL, tree, &ei_number_string_decoding_erange_error);
- else if (saved_err == EDOM)
- expert_add_info(NULL, tree, &ei_number_string_decoding_failed_error);
+ if (saved_err)
+ expert_add_info(NULL, tree, &ei_date_time_string_decoding_failed_error);
}
else {
FI_SET_FLAG(new_fi,
@@ -9111,35 +9115,57 @@ register_type_length_mismatch(void)
}
static void
-register_number_string_decodinws_error(void)
+register_byte_array_string_decodinws_error(void)
{
static ei_register_info ei[] = {
- { &ei_number_string_decoding_failed_error,
- { "_ws.number_string.decoding_error.failed", PI_MALFORMED, PI_ERROR,
- "Failed to decode number from string", EXPFILL
+ { &ei_byte_array_string_decoding_failed_error,
+ { "_ws.byte_array_string.decoding_error.failed", PI_MALFORMED, PI_ERROR,
+ "Failed to decode byte array from string", EXPFILL
}
},
- { &ei_number_string_decoding_erange_error,
- { "_ws.number_string.decoding_error.erange", PI_MALFORMED, PI_ERROR,
- "Decoded number from string is out of valid range", EXPFILL
+ };
+
+ expert_module_t* expert_byte_array_string_decoding_error;
+
+ proto_byte_array_string_decoding_error =
+ proto_register_protocol("Byte Array-String Decoding Error",
+ "Byte Array-string decoding error",
+ "_ws.byte_array_string.decoding_error");
+
+ expert_byte_array_string_decoding_error =
+ expert_register_protocol(proto_byte_array_string_decoding_error);
+ expert_register_field_array(expert_byte_array_string_decoding_error, ei, array_length(ei));
+
+ /* "Byte Array-String Decoding Error" isn't really a protocol, it's an error indication;
+ disabling them makes no sense. */
+ proto_set_cant_toggle(proto_byte_array_string_decoding_error);
+}
+
+static void
+register_date_time_string_decodinws_error(void)
+{
+ static ei_register_info ei[] = {
+ { &ei_date_time_string_decoding_failed_error,
+ { "_ws.date_time_string.decoding_error.failed", PI_MALFORMED, PI_ERROR,
+ "Failed to decode date and time from string", EXPFILL
}
},
};
- expert_module_t* expert_number_string_decoding_error;
+ expert_module_t* expert_date_time_string_decoding_error;
- proto_number_string_decoding_error =
- proto_register_protocol("Number-String Decoding Error",
- "Number-string decoding error",
- "_ws.number_string.decoding_error");
+ proto_date_time_string_decoding_error =
+ proto_register_protocol("Date and Time-String Decoding Error",
+ "Date and Time-string decoding error",
+ "_ws.date_time_string.decoding_error");
- expert_number_string_decoding_error =
- expert_register_protocol(proto_number_string_decoding_error);
- expert_register_field_array(expert_number_string_decoding_error, ei, array_length(ei));
+ expert_date_time_string_decoding_error =
+ expert_register_protocol(proto_date_time_string_decoding_error);
+ expert_register_field_array(expert_date_time_string_decoding_error, ei, array_length(ei));
- /* "Number-String Decoding Error" isn't really a protocol, it's an error indication;
+ /* "Date and Time-String Decoding Error" isn't really a protocol, it's an error indication;
disabling them makes no sense. */
- proto_set_cant_toggle(proto_number_string_decoding_error);
+ proto_set_cant_toggle(proto_date_time_string_decoding_error);
}
static void
diff --git a/epan/proto.h b/epan/proto.h
index f4346898e7..ec1712dc03 100644
--- a/epan/proto.h
+++ b/epan/proto.h
@@ -624,8 +624,9 @@ void proto_report_dissector_bug(const char *format, ...)
#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_IMF_DATE_TIME 0x00040000 /* Internet Message Format - RFCs 822, 1123, 2822, 5322 */
+#define ENC_RFC_822 0x00040000 /* backwards compatibility */
+#define ENC_RFC_1123 0x00080000 /* DEPRECATED - all of them support 2-digit dates, so don't use this */
#define ENC_ISO_8601_DATE_TIME_BASIC 0x00100000
/* a convenience macro for the above - for internal use only */
#define ENC_STR_TIME_MASK 0x001F0000
@@ -1679,7 +1680,7 @@ proto_tree_add_bytes_with_length(proto_tree *tree, int hfindex, tvbuff_t *tvb, g
@param encoding data encoding (e.g, ENC_LITTLE_ENDIAN, or ENC_UTF_8|ENC_STR_HEX)
@param[in,out] retval points to a GByteArray which will be set to the bytes from the Tvb.
@param[in,out] endoff if not NULL, gets set to the character after those consumed.
- @param[in,out] err if not NULL, gets set to 0 if no failure, else the errno code (e.g., EDOM, ERANGE).
+ @param[in,out] err if not NULL, gets set to 0 if no failure, else the errno code (e.g., EINVAL).
@return the newly created item, and retval is set to the decoded value
*/
WS_DLL_PUBLIC proto_item *
@@ -1758,7 +1759,7 @@ proto_tree_add_time(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
@param encoding data encoding (e.g, ENC_LITTLE_ENDIAN, ENC_UTF_8|ENC_ISO_8601_DATE_TIME, etc.)
@param[in,out] retval points to a nstime_t which will be set to the value
@param[in,out] endoff if not NULL, gets set to the character after those consumed.
- @param[in,out] err if not NULL, gets set to 0 if no failure, else the errno code (e.g., EDOM, ERANGE).
+ @param[in,out] err if not NULL, gets set to 0 if no failure, else EINVAL.
@return the newly created item, and retval is set to the decoded value
*/
WS_DLL_PUBLIC proto_item *
diff --git a/epan/tvbuff.c b/epan/tvbuff.c
index 74473d0d4e..acd8d6c7c6 100644
--- a/epan/tvbuff.c
+++ b/epan/tvbuff.c
@@ -29,6 +29,7 @@
#include "wsutil/pint.h"
#include "wsutil/sign_ext.h"
+#include "wsutil/strtoi.h"
#include "wsutil/unicode-utils.h"
#include "wsutil/nstime.h"
#include "wsutil/time_util.h"
@@ -1743,8 +1744,6 @@ tvb_get_string_bytes(tvbuff_t *tvb, const gint offset, const gint length,
const gchar *end = NULL;
GByteArray *retval = NULL;
- errno = EDOM;
-
validate_single_byte_ascii_encoding(encoding);
ptr = (gchar*) tvb_get_raw_string(NULL, tvb, offset, length);
@@ -1758,7 +1757,6 @@ tvb_get_string_bytes(tvbuff_t *tvb, const gint offset, const gint length,
if (hex_str_to_bytes_encoding(begin, bytes, &end, encoding, FALSE)) {
if (bytes->len > 0) {
if (endoff) *endoff = offset + (gint)(end - ptr);
- errno = 0;
retval = bytes;
}
}
@@ -1791,15 +1789,8 @@ tvb_get_string_time(tvbuff_t *tvb, const gint offset, const gint length,
gchar *begin;
const gchar *ptr;
const gchar *end = NULL;
- struct tm tm;
- nstime_t* retval = NULL;
- char sign = '+';
- int off_hr = 0;
- int off_min = 0;
int num_chars = 0;
- gboolean matched = FALSE;
-
- errno = EDOM;
+ int utc_offset = 0;
validate_single_byte_ascii_encoding(encoding);
@@ -1813,15 +1804,19 @@ tvb_get_string_time(tvbuff_t *tvb, const gint offset, const gint length,
if (*ptr) {
if ((encoding & ENC_ISO_8601_DATE_TIME) == ENC_ISO_8601_DATE_TIME) {
if ((num_chars = iso8601_to_nstime(ns, ptr, ISO8601_DATETIME))) {
- errno = 0;
end = ptr + num_chars;
+ } else {
+ goto fail;
}
} 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 {
+ goto fail;
}
} else {
+ struct tm tm;
+
memset(&tm, 0, sizeof(tm));
tm.tm_isdst = -1;
ns->secs = 0;
@@ -1838,10 +1833,11 @@ tvb_get_string_time(tvbuff_t *tvb, const gint offset, const gint length,
&tm.tm_mday,
&num_chars) >= 3)
{
- errno = 0;
end = ptr + num_chars;
tm.tm_mon--;
if (tm.tm_year > 1900) tm.tm_year -= 1900;
+ } else {
+ goto fail;
}
}
else if (encoding & ENC_ISO_8601_TIME) {
@@ -1867,89 +1863,172 @@ tvb_get_string_time(tvbuff_t *tvb, const gint offset, const gint length,
tm.tm_mday = 31;
}
end = ptr + num_chars;
- errno = 0;
-
+ } else {
+ goto fail;
}
}
- else if (encoding & ENC_RFC_822 || encoding & ENC_RFC_1123) {
+ else if (encoding & ENC_IMF_DATE_TIME || encoding & ENC_RFC_1123) {
/*
- * Match [dow,] day month year hh:mm[:ss] with two-digit
- * years (RFC 822) or four-digit years (RFC 1123). Skip
- * the day of week since it is locale dependent and does
- * not affect the resulting date anyway.
+ * Match [dow,] day month year hh:mm[:ss] with
+ * two-digit years (RFC 822) or four-digit
+ * years (RFCs 1123, 2822, 5822). Skip
+ * the day of week since it is locale
+ * dependent and does not affect the resulting
+ * date anyway.
*/
if (g_ascii_isalpha(ptr[0]) && g_ascii_isalpha(ptr[1]) && g_ascii_isalpha(ptr[2]) && ptr[3] == ',')
ptr += 4; /* Skip day of week. */
+
+ /*
+ * Parse the day-of-month and month
+ * name.
+ */
char month_name[4] = { 0 };
- if (sscanf(ptr, "%d %3s %d %d:%d%n:%d%n",
+
+ if (sscanf(ptr, "%d %3s%n",
&tm.tm_mday,
month_name,
- &tm.tm_year,
+ &num_chars) < 2) {
+ /* Not matched. */
+ goto fail;
+ }
+ if (!parse_month_name(month_name, &tm.tm_mon)) {
+ goto fail;
+ }
+ ptr += num_chars;
+ while (*ptr == ' ')
+ ptr++;
+
+ /*
+ * Scan the year. Treat 2-digit years
+ * differently from 4-digit years.
+ */
+ guint32 year;
+ const gchar *yearendp;
+
+ if (!ws_strtou32(ptr, &yearendp, &year)) {
+ goto fail;
+ }
+ if (*yearendp != ' ') {
+ /* Not followed by a space. */
+ goto fail;
+ }
+ if (yearendp - ptr < 2) {
+ /* 1-digit year. Error. */
+ goto fail;
+ }
+ if (yearendp - ptr == 2) {
+ /*
+ * 2-digit year.
+ *
+ * Match RFC 2822/RFC 5322 behavior;
+ * add 2000 to years from 0 to
+ * 49 and 1900 to uears from 50
+ * to 99.
+ */
+ if (year <= 49) {
+ year += 2000;
+ } else {
+ year += 1900;
+ }
+ } else if (yearendp - ptr == 3) {
+ /*
+ * 3-digit year.
+ *
+ * Match RFC 2822/RFC 5322 behavior;
+ * add 1900 to the year.
+ */
+ year += 1900;
+ }
+ tm.tm_year = year - 1900;
+ ptr = yearendp;
+ while (*ptr == ' ')
+ ptr++;
+
+ /* Parse the time. */
+ if (sscanf(ptr, "%d:%d%n:%d%n",
&tm.tm_hour,
&tm.tm_min,
&num_chars,
&tm.tm_sec,
- &num_chars) >= 5)
+ &num_chars) < 2)
{
- if (encoding & ENC_RFC_822) {
- /* Match strptime behavior: years 00-68
- * are in the 21th century. */
- if (tm.tm_year <= 68) {
- tm.tm_year += 100;
- matched = TRUE;
- } else if (tm.tm_year <= 99) {
- matched = TRUE;
- }
- } else if (encoding & ENC_RFC_1123) {
- tm.tm_year -= 1900;
- matched = TRUE;
- }
- if (!parse_month_name(month_name, &tm.tm_mon))
- matched = FALSE;
- if (matched)
- end = ptr + num_chars;
+ goto fail;
}
- if (end) {
- errno = 0;
- if (*end == ' ') end++;
- if (g_ascii_strncasecmp(end, "UT", 2) == 0)
- {
- end += 2;
- }
- else if (g_ascii_strncasecmp(end, "GMT", 3) == 0)
- {
- end += 3;
- }
- else if (sscanf(end, "%c%2d%2d%n",
+ ptr += num_chars;
+ while (*ptr == ' ')
+ ptr++;
+
+ /*
+ * Parse the time zone.
+ * Check for obs-zone values first.
+ */
+ if (g_ascii_strncasecmp(ptr, "UT", 2) == 0)
+ {
+ ptr += 2;
+ }
+ else if (g_ascii_strncasecmp(ptr, "GMT", 3) == 0)
+ {
+ ptr += 3;
+ }
+ else
+ {
+ char sign;
+ int off_hr;
+ int off_min;
+
+ if (sscanf(ptr, "%c%2d%2d%n",
&sign,
&off_hr,
&off_min,
&num_chars) < 3)
{
- errno = ERANGE;
+ goto fail;
+ }
+
+ /*
+ * If sign is '+', there's a positive
+ * UTC offset.
+ *
+ * If sign is '-', there's a negative
+ * UTC offset.
+ *
+ * Otherwise, that's an invalid UTC
+ * offset string.
+ */
+ if (sign == '+')
+ utc_offset += (off_hr * 3600) + (off_min * 60);
+ else if (sign == '-')
+ utc_offset -= (off_hr * 3600) + (off_min * 60);
+ else {
+ /* Sign must be + or - */
+ goto fail;
}
- if (sign == '-') off_hr = -off_hr;
+ ptr += num_chars;
}
+ end = ptr;
}
if (errno == 0) {
- ns->secs = mktime_utc (&tm);
- if (off_hr > 0)
- ns->secs += (off_hr * 3600) + (off_min * 60);
- else if (off_hr < 0)
- ns->secs -= ((-off_hr) * 3600) + (off_min * 60);
+ ns->secs = mktime_utc(&tm);
+ if (ns->secs == (time_t)-1 && errno != 0) {
+ goto fail;
+ }
+ ns->secs += utc_offset;
}
}
+ } else {
+ /* Empty string */
+ goto fail;
}
- if (errno == 0) {
- retval = ns;
- if (endoff)
- *endoff = (gint)(offset + (end - begin));
- }
-
+ if (endoff)
+ *endoff = (gint)(offset + (end - begin));
wmem_free(NULL, begin);
+ return ns;
- return retval;
+fail:
+ wmem_free(NULL, begin);
+ return NULL;
}
/* Fetch an IPv4 address, in network byte order.
diff --git a/epan/tvbuff.h b/epan/tvbuff.h
index 9e067a0a06..cfcd057ee6 100644
--- a/epan/tvbuff.h
+++ b/epan/tvbuff.h
@@ -397,8 +397,8 @@ WS_DLL_PUBLIC gdouble tvb_get_ieee_double(tvbuff_t *tvb, const gint offset, cons
* they may not consume the whole section.
*
* @return a pointer to the nstime_t passed-in, or NULL on failure; if no
- * valid conversion could be performed, *endoff is set to 0, and errno will be
- * EDOM or ERANGE, and the nstime_t* passed-in will be cleared.
+ * valid conversion could be performed, *endoff is set to 0, and the
+ * nstime_t* passed-in will be cleared.
*
* @note The conversion ignores leading spaces, and will succeed even if it does
* not consume the entire string. If you care about such things, always compare
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")