summaryrefslogtreecommitdiffstats
path: root/src/libserver/http
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2022-01-29 13:44:50 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2022-01-29 13:44:50 +0000
commit00927e0ef03a05916151c15c16f7e2697d655379 (patch)
tree490515576c29ce6ec623d7a96a866c4f28666a11 /src/libserver/http
parentcc7c9000e05e1810d408f4e9b40e2073e85cb0fb (diff)
downloadrspamd-00927e0ef03a05916151c15c16f7e2697d655379.tar.gz
rspamd-00927e0ef03a05916151c15c16f7e2697d655379.zip
[Fix] Fix host header usage in lua_http
The issue is that `rspamd_http_message_get_http_host` actually returns non zero-terminated string in the case where `Host` header is found in a message. Hence, we *cannot* treat it as a zero terminated string. The proper approach is to use `rspamd_ftok_t` everywhere for strings but the change will be too intrusive, since it also involves many libraries, e.g. `rdns` and others. The current approach is much simplier: just copy a string into a temporary buffer ensuring that it is zero terminated in all the cases. Issue: #4051
Diffstat (limited to 'src/libserver/http')
-rw-r--r--src/libserver/http/http_message.c6
-rw-r--r--src/libserver/http/http_message.h4
2 files changed, 8 insertions, 2 deletions
diff --git a/src/libserver/http/http_message.c b/src/libserver/http/http_message.c
index a313283f3..23ff85cd7 100644
--- a/src/libserver/http/http_message.c
+++ b/src/libserver/http/http_message.c
@@ -693,7 +693,8 @@ rspamd_http_message_remove_header (struct rspamd_http_message *msg,
}
const gchar*
-rspamd_http_message_get_http_host (struct rspamd_http_message *msg)
+rspamd_http_message_get_http_host (struct rspamd_http_message *msg,
+ gsize *hostlen)
{
if (msg->flags & RSPAMD_HTTP_FLAG_HAS_HOST_HEADER) {
rspamd_ftok_t srch;
@@ -703,14 +704,17 @@ rspamd_http_message_get_http_host (struct rspamd_http_message *msg)
khiter_t k = kh_get (rspamd_http_headers_hash, msg->headers, &srch);
if (k != kh_end (msg->headers)) {
+ *hostlen = (kh_value (msg->headers, k)->value).len;
return (kh_value (msg->headers, k)->value).begin;
}
else if (msg->host) {
+ *hostlen = msg->host->len;
return msg->host->str;
}
}
else {
if (msg->host) {
+ *hostlen = msg->host->len;
return msg->host->str;
}
}
diff --git a/src/libserver/http/http_message.h b/src/libserver/http/http_message.h
index 1750c1dd6..38f599048 100644
--- a/src/libserver/http/http_message.h
+++ b/src/libserver/http/http_message.h
@@ -233,9 +233,11 @@ guint rspamd_http_message_get_flags (struct rspamd_http_message *msg);
* Returns an HTTP hostname for a message, derived from a header if it has it
* or from a url if it doesn't
* @param msg
+ * @param hostlen output of the host length
* @return
*/
-const gchar* rspamd_http_message_get_http_host (struct rspamd_http_message *msg);
+const gchar* rspamd_http_message_get_http_host (struct rspamd_http_message *msg,
+ gsize *hostlen);
#ifdef __cplusplus
}