1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
From: László Várady <laszlo.varady@protonmail.com>
Date: Sat, 20 Aug 2022 14:30:22 +0200
Subject: timeutils: fix invalid calculation of ISO timestamp length
Signed-off-by: László Várady <laszlo.varady@protonmail.com>
Origin: https://github.com/syslog-ng/syslog-ng/commit/8c6e2c1c41b0fcc5fbd464c35f4dac7102235396
---
lib/timeutils/scan-timestamp.c | 8 ++++++--
lib/timeutils/tests/test_scan-timestamp.c | 7 +++++++
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/lib/timeutils/scan-timestamp.c b/lib/timeutils/scan-timestamp.c
index 197e3ad..4e618e4 100644
--- a/lib/timeutils/scan-timestamp.c
+++ b/lib/timeutils/scan-timestamp.c
@@ -346,19 +346,21 @@ __parse_usec(const guchar **data, gint *length)
static gboolean
__has_iso_timezone(const guchar *src, gint length)
{
- return (length >= 5) &&
+ return (length >= 6) &&
(*src == '+' || *src == '-') &&
isdigit(*(src+1)) &&
isdigit(*(src+2)) &&
*(src+3) == ':' &&
isdigit(*(src+4)) &&
isdigit(*(src+5)) &&
- !isdigit(*(src+6));
+ (length < 7 || !isdigit(*(src+6)));
}
static guint32
__parse_iso_timezone(const guchar **data, gint *length)
{
+ g_assert(*length >= 6);
+
gint hours, mins;
const guchar *src = *data;
guint32 tz = 0;
@@ -368,8 +370,10 @@ __parse_iso_timezone(const guchar **data, gint *length)
hours = (*(src + 1) - '0') * 10 + *(src + 2) - '0';
mins = (*(src + 4) - '0') * 10 + *(src + 5) - '0';
tz = sign * (hours * 3600 + mins * 60);
+
src += 6;
(*length) -= 6;
+
*data = src;
return tz;
}
diff --git a/lib/timeutils/tests/test_scan-timestamp.c b/lib/timeutils/tests/test_scan-timestamp.c
index da375c8..9b38738 100644
--- a/lib/timeutils/tests/test_scan-timestamp.c
+++ b/lib/timeutils/tests/test_scan-timestamp.c
@@ -248,6 +248,13 @@ Test(parse_timestamp, non_zero_terminated_rfc5424_input_is_handled_properly)
}
+Test(parse_timestamp, non_zero_terminated_rfc5424_timestamp_only)
+{
+ const gchar *ts = "2022-08-17T05:02:28.417+03:00";
+ gint ts_len = strlen(ts);
+ _expect_rfc5424_timestamp_len_eq(ts, ts_len, ts);
+}
+
Test(parse_timestamp, daylight_saving_behavior_at_spring_with_explicit_timezones)
{
|