aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-systemd-journal.c
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2020-07-13 12:20:58 -0700
committerAnders Broman <a.broman58@gmail.com>2020-07-14 04:02:35 +0000
commit4a4c8bdfeafba4833bdcb99fc1617e19fc65e950 (patch)
tree88df7c74d12165915982f536dad15dfdd437277b /epan/dissectors/packet-systemd-journal.c
parent73f24f5ad8dcd207c3ebcbd848ba2303d1a6f977 (diff)
Systemd journal: Fix timestamp conversions.
Use ws_strtou64 to convert __REALTIME_TIMESTAMP= and other timestamps, which should work across platforms. Bug: 16664 Change-Id: I371f2b60e1957e57dbbdbbc3ded5ad49e8eb79d1 Reviewed-on: https://code.wireshark.org/review/37849 Reviewed-by: Gerald Combs <gerald@wireshark.org> Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'epan/dissectors/packet-systemd-journal.c')
-rw-r--r--epan/dissectors/packet-systemd-journal.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/epan/dissectors/packet-systemd-journal.c b/epan/dissectors/packet-systemd-journal.c
index 2a06d58244..5171302fb9 100644
--- a/epan/dissectors/packet-systemd-journal.c
+++ b/epan/dissectors/packet-systemd-journal.c
@@ -30,6 +30,8 @@
#include <epan/packet.h>
#include <epan/expert.h>
+#include <wsutil/strtoi.h>
+
#include "packet-syslog.h"
#define PNAME "systemd Journal Entry"
@@ -157,6 +159,7 @@ static int hf_sj_unhandled_field_type = -1;
static expert_field ei_unhandled_field_type = EI_INIT;
static expert_field ei_nonbinary_field = EI_INIT;
+static expert_field ei_undecoded_field = EI_INIT;
#define MAX_DATA_SIZE 262144 // WTAP_MAX_PACKET_SIZE_STANDARD. Increase if needed.
@@ -287,12 +290,17 @@ static void init_jf_to_hf_map(void) {
static void
dissect_sjle_time_usecs(proto_tree *tree, int hf_idx, tvbuff_t *tvb, int offset, int len) {
- unsigned long rt_ts = strtoul(tvb_format_text(tvb, offset, len), NULL, 10);
- // XXX Check errno?
- nstime_t ts;
- ts.secs = (time_t) rt_ts / 1000000;
- ts.nsecs = (rt_ts % 1000000) * 1000;
- proto_tree_add_time(tree, hf_idx, tvb, offset, len, &ts);
+ guint64 rt_ts = 0;
+ char *time_str = tvb_format_text(tvb, offset, len);
+ gboolean ok = ws_strtou64(time_str, NULL, &rt_ts);
+ if (ok) {
+ nstime_t ts;
+ ts.secs = (time_t) (rt_ts / 1000000);
+ ts.nsecs = (rt_ts % 1000000) * 1000;
+ proto_tree_add_time(tree, hf_idx, tvb, offset, len, &ts);
+ } else {
+ proto_tree_add_expert_format(tree, NULL, &ei_undecoded_field, tvb, offset, len, "Invalid time value %s", time_str);
+ }
}
static void
@@ -851,6 +859,10 @@ proto_register_systemd_journal(void)
{ &ei_nonbinary_field,
{ "systemd_journal.nonbinary_field", PI_UNDECODED, PI_WARN,
"Field shouldn't be binary", EXPFILL }
+ },
+ { &ei_undecoded_field,
+ { "systemd_journal.undecoded_field", PI_UNDECODED, PI_WARN,
+ "Unable to decode field", EXPFILL }
}
};