diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-10-06 15:42:21 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-10-06 15:42:21 +0100 |
commit | fe908bdce8f1d331d5b1ff18c1c6766a59aebd6f (patch) | |
tree | cc3e3ff84f81a858550dfe9b28266d7ef9f33b09 | |
parent | b6085d45f1a31b4bf19abf91d5926e1ef87d39ca (diff) | |
download | rspamd-fe908bdce8f1d331d5b1ff18c1c6766a59aebd6f.tar.gz rspamd-fe908bdce8f1d331d5b1ff18c1c6766a59aebd6f.zip |
[Minor] Add some more error cases to the smtp date parsing
-rw-r--r-- | src/libmime/smtp_parsers.h | 2 | ||||
-rw-r--r-- | src/ragel/smtp_date.rl | 21 | ||||
-rw-r--r-- | src/ragel/smtp_date_parser.rl | 7 |
3 files changed, 26 insertions, 4 deletions
diff --git a/src/libmime/smtp_parsers.h b/src/libmime/smtp_parsers.h index 067d84424..7eff6bf71 100644 --- a/src/libmime/smtp_parsers.h +++ b/src/libmime/smtp_parsers.h @@ -46,7 +46,7 @@ rspamd_rfc2047_parser (const gchar *in, gsize len, gint *pencoding, rspamd_inet_addr_t *rspamd_parse_smtp_ip (const char *data, size_t len, rspamd_mempool_t *pool); -guint64 rspamd_parse_smtp_date (const char *data, size_t len, GError **err); +guint64 rspamd_parse_smtp_date (const unsigned char *data, size_t len, GError **err); #ifdef __cplusplus } diff --git a/src/ragel/smtp_date.rl b/src/ragel/smtp_date.rl index e873e44de..df21cb3f3 100644 --- a/src/ragel/smtp_date.rl +++ b/src/ragel/smtp_date.rl @@ -15,6 +15,9 @@ if (n > 0 && n <= 31) { tm.tm_mday = n; } + else { + fbreak; + } } } } @@ -52,8 +55,14 @@ if (n < 24) { tm.tm_hour = n; } + else { + fbreak; + } } } + else { + fbreak; + } } action Minute_Start { tmp = p; @@ -65,8 +74,14 @@ if (n < 60) { tm.tm_min = n; } + else { + fbreak; + } } } + else { + fbreak; + } } action Second_Start { tmp = p; @@ -78,8 +93,14 @@ if (n <= 60) { /* Leap second */ tm.tm_sec = n; } + else { + fbreak; + } } } + else { + fbreak; + } } action TZ_Sign { tmp = p; diff --git a/src/ragel/smtp_date_parser.rl b/src/ragel/smtp_date_parser.rl index 48a1cbcbf..d53e61148 100644 --- a/src/ragel/smtp_date_parser.rl +++ b/src/ragel/smtp_date_parser.rl @@ -1,6 +1,7 @@ %%{ machine smtp_date_parser; + alphtype unsigned char; include smtp_base "smtp_base.rl"; include smtp_date "smtp_date.rl"; @@ -13,9 +14,9 @@ %% write data; guint64 -rspamd_parse_smtp_date (const char *data, size_t len, GError **err) +rspamd_parse_smtp_date (const unsigned char *data, size_t len, GError **err) { - const gchar *p = data, *pe = data + len, *eof = data + len, *tmp = data; + const unsigned char *p = data, *pe = data + len, *eof = data + len, *tmp = data; struct tm tm; glong tz = 0; gint cs = 0; @@ -27,7 +28,7 @@ rspamd_parse_smtp_date (const char *data, size_t len, GError **err) if ( cs < %%{ write first_final; }%% ) { g_set_error (err, g_quark_from_static_string ("smtp_date"), cs, "invalid date at offset %d (%c), state %d", - p - data, *p, cs); + (int)(p - data), (*p > 0 && *p < 128) ? *p : '?', cs); return (guint64)(-1); } |