From c1f9bfc86391e4be50a5fbd16a7b899288a3a84c Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 1 Oct 2019 15:03:10 +0100 Subject: [PATCH] [Fix] Fix parsing of the received headers with empty part --- src/libmime/mime_headers.c | 16 ++++++++++++---- test/lua/unit/received.lua | 9 ++++++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/libmime/mime_headers.c b/src/libmime/mime_headers.c index e83debc43..f7eb86f2e 100644 --- a/src/libmime/mime_headers.c +++ b/src/libmime/mime_headers.c @@ -1098,8 +1098,14 @@ rspamd_smtp_received_process_part (struct rspamd_task *task, p ++; break; case all_done: - *last = p - (const guchar *)data; - return npart; + if (p > (const guchar *)data) { + *last = p - (const guchar *) data; + return npart; + } + else { + /* Empty element */ + return NULL; + } break; } } @@ -1120,9 +1126,11 @@ rspamd_smtp_received_process_part (struct rspamd_task *task, } break; case skip_spaces: - *last = p - (const guchar *)data; + if (p > c) { + *last = p - (const guchar *) data; - return npart; + return npart; + } default: break; } diff --git a/test/lua/unit/received.lua b/test/lua/unit/received.lua index fc1f24de8..908c1904e 100644 --- a/test/lua/unit/received.lua +++ b/test/lua/unit/received.lua @@ -121,7 +121,14 @@ context("Received headers parser", function() { by_hostname = 'example.com', }, - } + }, + {[[from 171-29.br (1-1-1-1.z.com.br [1.1.1.1]) by x.com.br (Postfix) with;ESMTP id 44QShF6xj4z1X for ; Thu, 21 Mar 2019 23:45:46 -0300 : ]], + { + from_hostname = '171-29.br', + real_ip = '1.1.1.1', + by_hostname = 'x.com.br', + } + }, } local task = ffi.C.rspamd_task_new(nil, nil) -- 2.39.5