commit c1ae852: [Minor] Do not try to modify constant memory

Vsevolod Stakhov vsevolod at highsecure.ru
Wed Jul 7 09:42:04 UTC 2021


Author: Vsevolod Stakhov
Date: 2021-07-07 10:37:32 +0100
URL: https://github.com/rspamd/rspamd/commit/c1ae8529075e7b9d6b22daca27b9017839fdd755 (HEAD -> master)

[Minor] Do not try to modify constant memory

---
 src/libmime/mime_headers.c     | 3 ++-
 test/rspamd_cxx_unit_utils.hxx | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/libmime/mime_headers.c b/src/libmime/mime_headers.c
index 71b4f2688..c1d5f397c 100644
--- a/src/libmime/mime_headers.c
+++ b/src/libmime/mime_headers.c
@@ -403,7 +403,8 @@ rspamd_mime_headers_process (struct rspamd_task *task,
 			}
 
 			if (nh->decoded == NULL) {
-				nh->decoded = "";
+				/* As we strip comments in place... */
+				nh->decoded = rspamd_mempool_strdup (task->task_pool, "");
 			}
 
 			/* We also validate utf8 and replace all non-valid utf8 chars */
diff --git a/test/rspamd_cxx_unit_utils.hxx b/test/rspamd_cxx_unit_utils.hxx
index 0cd229a4f..00b5e1b61 100644
--- a/test/rspamd_cxx_unit_utils.hxx
+++ b/test/rspamd_cxx_unit_utils.hxx
@@ -39,6 +39,7 @@ TEST_CASE("rspamd_strip_smtp_comments_inplace") {
 			{"ab(olo\\)lo)c(foo)", "abc"},
 			{"ab(trol\\\1lo)c(foo)", "abc"},
 			{"\\ab(trol\\\1lo)c(foo)", "abc"},
+			{"", ""},
 	};
 
 	for (const auto &c : cases) {


More information about the Commits mailing list