From d8e47a12ae221b2e79dbd786ccfa0402cff0c49b Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 9 Aug 2023 17:31:04 +0100 Subject: [PATCH] [Fix] Fix `url:set_redirected` method --- src/lua/lua_url.c | 16 +++++++++++----- src/plugins/lua/url_redirector.lua | 5 +++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/lua/lua_url.c b/src/lua/lua_url.c index 3f25b3128..913469f6d 100644 --- a/src/lua/lua_url.c +++ b/src/lua/lua_url.c @@ -1,11 +1,11 @@ -/*- - * Copyright 2016 Vsevolod Stakhov +/* + * Copyright 2023 Vsevolod Stakhov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -500,10 +500,10 @@ lua_url_get_phished(lua_State *L) } /*** - * @method url:set_redirected(url,[ pool]) + * @method url:set_redirected(url, pool) * Set url as redirected to another url * @param {string|url} url new url that is redirecting an old one - * @param {pool} pool if url is a string this is required for parsing + * @param {pool} pool memory pool to allocate memory if needed * @return {url} parsed redirected url (if needed) */ static gint @@ -557,6 +557,12 @@ lua_url_set_redirected(lua_State *L) return luaL_error(L, "url is required as the second argument"); } + pool = rspamd_lua_check_mempool(L, 3); + + if (pool == NULL) { + return luaL_error(L, "mempool is required as the third argument"); + } + url->url->flags |= RSPAMD_URL_FLAG_REDIRECTED; if (url->url->ext == NULL) { url->url->ext = rspamd_mempool_alloc0_type(pool, struct rspamd_url_ext); diff --git a/src/plugins/lua/url_redirector.lua b/src/plugins/lua/url_redirector.lua index 19189a5ee..092fb7def 100644 --- a/src/plugins/lua/url_redirector.lua +++ b/src/plugins/lua/url_redirector.lua @@ -59,12 +59,13 @@ local settings = { } local function adjust_url(task, orig_url, redir_url) + local mempool = task:get_mempool() if type(redir_url) == 'string' then - redir_url = rspamd_url.create(task:get_mempool(), redir_url, { 'redirect_target' }) + redir_url = rspamd_url.create(mempool, redir_url, { 'redirect_target' }) end if redir_url then - orig_url:set_redirected(redir_url) + orig_url:set_redirected(redir_url, mempool) task:inject_url(redir_url) if settings.redirector_symbol then task:insert_result(settings.redirector_symbol, 1.0, -- 2.39.5