commit b48fa1b: [CritFix] Fix controller paths normalisation

Vsevolod Stakhov vsevolod at highsecure.ru
Tue Dec 22 17:28:05 UTC 2020


Author: Vsevolod Stakhov
Date: 2020-12-22 17:23:11 +0000
URL: https://github.com/rspamd/rspamd/commit/b48fa1b0535ece50118827de341c673d40186346

[CritFix] Fix controller paths normalisation
It fixes errors like 'rspamd_controller_handle_lua_plugin: plugin handler
/plugins/selectors/list_extractorstors has not been found'

---
 src/libserver/http/http_router.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/libserver/http/http_router.c b/src/libserver/http/http_router.c
index 01d47b612..9f36118b2 100644
--- a/src/libserver/http/http_router.c
+++ b/src/libserver/http/http_router.c
@@ -286,15 +286,20 @@ rspamd_http_router_finish_handler (struct rspamd_http_connection *conn,
 
 		/* Search for path */
 		if (msg->url != NULL && msg->url->len != 0) {
+			gchar *pathbuf = NULL;
 
 			http_parser_parse_url (msg->url->str, msg->url->len, TRUE, &u);
 
 			if (u.field_set & (1 << UF_PATH)) {
 				guint unnorm_len;
-				lookup.begin = msg->url->str + u.field_data[UF_PATH].off;
+
+				pathbuf = g_malloc (u.field_data[UF_PATH].len);
+				memcpy (pathbuf, msg->url->str + u.field_data[UF_PATH].off,
+						u.field_data[UF_PATH].len);
+				lookup.begin = pathbuf;
 				lookup.len = u.field_data[UF_PATH].len;
 
-				rspamd_http_normalize_path_inplace ((gchar *)lookup.begin,
+				rspamd_http_normalize_path_inplace (pathbuf,
 						lookup.len,
 						&unnorm_len);
 				lookup.len = unnorm_len;
@@ -307,6 +312,10 @@ rspamd_http_router_finish_handler (struct rspamd_http_connection *conn,
 			found = g_hash_table_lookup (entry->rt->paths, &lookup);
 			memcpy (&handler, &found, sizeof (found));
 			msg_debug ("requested known path: %T", &lookup);
+
+			if (pathbuf) {
+				g_free (pathbuf);
+			}
 		}
 		else {
 			err = g_error_new (HTTP_ERROR, 404,


More information about the Commits mailing list