aboutsummaryrefslogtreecommitdiffstats
path: root/src/libmime/mime_headers.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2021-09-22 13:01:40 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2021-09-22 13:01:40 +0100
commit8492c4a1d56199763cf87645e8d2261ede2596e1 (patch)
treea69fa57fb0d0821c97b96d57d7d0769350d60e8b /src/libmime/mime_headers.c
parentf879e676a216443d648edffc6d37322001a8994d (diff)
downloadrspamd-8492c4a1d56199763cf87645e8d2261ede2596e1.tar.gz
rspamd-8492c4a1d56199763cf87645e8d2261ede2596e1.zip
[Fix] Fix parsing of the from_hostname when it is an IP address
Diffstat (limited to 'src/libmime/mime_headers.c')
-rw-r--r--src/libmime/mime_headers.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/libmime/mime_headers.c b/src/libmime/mime_headers.c
index 8f229a9b3..7b5011be4 100644
--- a/src/libmime/mime_headers.c
+++ b/src/libmime/mime_headers.c
@@ -1309,6 +1309,34 @@ rspamd_smtp_received_process_rdns (struct rspamd_task *task,
p = begin;
end = begin + len;
+ if (len == 0) {
+ return FALSE;
+ }
+
+ if (*p == '[' && *(end - 1) == ']' && len > 2) {
+ /* We have enclosed ip address */
+ rspamd_inet_addr_t *addr = rspamd_parse_inet_address_pool (p + 1,
+ (end - p) - 2,
+ task->task_pool,
+ RSPAMD_INET_ADDRESS_PARSE_RECEIVED);
+
+ if (addr) {
+ const gchar *addr_str;
+ gchar *dest;
+
+ if (rspamd_inet_address_get_port (addr) != 0) {
+ addr_str = rspamd_inet_address_to_string_pretty (addr);
+ }
+ else {
+ addr_str = rspamd_inet_address_to_string (addr);
+ }
+ dest = rspamd_mempool_strdup (task->task_pool, addr_str);
+ *pdest = dest;
+
+ return TRUE;
+ }
+ }
+
while (p < end) {
if (!g_ascii_isspace (*p) && rspamd_url_is_domain (*p)) {
if (*p == '.') {
@@ -1481,7 +1509,8 @@ rspamd_smtp_received_process_from (struct rspamd_task *task,
rh->from_ip = rh->real_ip;
}
}
- } else if (g_ascii_isxdigit (rpart->data[0])) {
+ }
+ else if (g_ascii_isxdigit (rpart->data[0])) {
/* Try to parse IP address */
rspamd_inet_addr_t *addr;
addr = rspamd_parse_inet_address_pool (rpart->data,