if (date_pos > 0 && date_pos < len) {
rh->timestamp = rspamd_parse_smtp_date (data + date_pos,
- len - date_pos);
+ len - date_pos, NULL);
}
return 0;
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);
+guint64 rspamd_parse_smtp_date (const char *data, size_t len, GError **err);
#ifdef __cplusplus
}
if (h) {
time_t tt;
struct tm t;
+ GError *err = NULL;
- tt = rspamd_parse_smtp_date (h->decoded, strlen (h->decoded));
+ tt = rspamd_parse_smtp_date (h->decoded, strlen (h->decoded),
+ &err);
- if (!gmt) {
- rspamd_localtime (tt, &t);
+ if (err == NULL) {
+ if (!gmt) {
+ rspamd_localtime (tt, &t);
#if !defined(__sun)
- t.tm_gmtoff = 0;
+ t.tm_gmtoff = 0;
#endif
- t.tm_isdst = 0;
- tim = mktime (&t);
+ t.tm_isdst = 0;
+ tim = mktime (&t);
+ }
+ else {
+ tim = tt;
+ }
}
else {
- tim = tt;
+ g_error_free (err);
+ tim = 0.0;
}
}
else {
{
gsize slen;
const gchar *str = lua_tolstring (L, 1, &slen);
+ GError *err = NULL;
if (str == NULL) {
return luaL_argerror (L, 1, "invalid argument");
}
- time_t tt = rspamd_parse_smtp_date (str, slen);
+ time_t tt = rspamd_parse_smtp_date (str, slen, &err);
- if (lua_isboolean (L, 2) && !!lua_toboolean (L, 2)) {
- struct tm t;
+ if (err == NULL) {
+ if (lua_isboolean (L, 2) && !!lua_toboolean (L, 2)) {
+ struct tm t;
- rspamd_localtime (tt, &t);
+ rspamd_localtime (tt, &t);
#if !defined(__sun)
- t.tm_gmtoff = 0;
+ t.tm_gmtoff = 0;
#endif
- t.tm_isdst = 0;
- tt = mktime (&t);
+ t.tm_isdst = 0;
+ tt = mktime (&t);
+ }
+
+ lua_pushnumber (L, tt);
}
+ else {
+ lua_pushnil (L);
+ lua_pushstring (L, err->message);
+ g_error_free (err);
- lua_pushnumber (L, tt);
+ return 2;
+ }
return 1;
}
%% write data;
guint64
-rspamd_parse_smtp_date (const char *data, size_t len)
+rspamd_parse_smtp_date (const char *data, size_t len, GError **err)
{
const gchar *p = data, *pe = data + len, *eof = data + len, *tmp = data;
struct tm tm;
%% write init;
%% write exec;
+ 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);
+ return (guint64)(-1);
+ }
+
return rspamd_tm_to_time (&tm, tz);
}
\ No newline at end of file