This is an automated email from the ASF dual-hosted git repository. cmcfarlen pushed a commit to branch 10.0.x in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit 33da84bdf95a3ebbb7c525fa04eb7ec2ea093449 Author: Masaori Koshiba <[email protected]> AuthorDate: Wed Jan 29 08:04:19 2025 +0900 Fix crash by including remap files with named filters (#11997) * Fix crash by including remap files with named filters * Fix unit test (cherry picked from commit 4c9c7c63dcddc60c473509f66a262a09593f9b2e) --- include/proxy/http/remap/RemapConfig.h | 3 +++ src/proxy/http/remap/RemapConfig.cc | 22 ++++++++++++++-------- src/proxy/http/remap/unit-tests/test_RemapRules.cc | 3 +++ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/include/proxy/http/remap/RemapConfig.h b/include/proxy/http/remap/RemapConfig.h index 4ef2470bd1..8a58271a76 100644 --- a/include/proxy/http/remap/RemapConfig.h +++ b/include/proxy/http/remap/RemapConfig.h @@ -66,6 +66,9 @@ struct BUILD_TABLE_INFO { // Clear the argument vector. void reset(); + // Free acl_filter_rule in the list + void clear_acl_rules_list(); + // noncopyable BUILD_TABLE_INFO(const BUILD_TABLE_INFO &) = delete; // disabled BUILD_TABLE_INFO &operator=(const BUILD_TABLE_INFO &) = delete; // disabled diff --git a/src/proxy/http/remap/RemapConfig.cc b/src/proxy/http/remap/RemapConfig.cc index 8ff273c3f5..65775beff5 100644 --- a/src/proxy/http/remap/RemapConfig.cc +++ b/src/proxy/http/remap/RemapConfig.cc @@ -97,14 +97,6 @@ BUILD_TABLE_INFO::BUILD_TABLE_INFO() BUILD_TABLE_INFO::~BUILD_TABLE_INFO() { this->reset(); - - // clean up any leftover named filter rules - auto *rp = rules_list; - while (rp != nullptr) { - auto *tmp = rp->next; - delete rp; - rp = tmp; - } } void @@ -115,6 +107,18 @@ BUILD_TABLE_INFO::reset() clear_xstr_array(this->argv, sizeof(this->argv) / sizeof(char *)); } +void +BUILD_TABLE_INFO::clear_acl_rules_list() +{ + // clean up any leftover named filter rules + auto *rp = rules_list; + while (rp != nullptr) { + auto *tmp = rp->next; + delete rp; + rp = tmp; + } +} + static const char * process_filter_opt(url_mapping *mp, const BUILD_TABLE_INFO *bti, char *errStrBuf, int errStrBufSize) { @@ -1488,5 +1492,7 @@ remap_parse_config(const char *path, UrlRewrite *rewrite) * accordingly notify all plugins that we are done */ rewrite->pluginFactory.indicatePostReload(status); + bti.clear_acl_rules_list(); + return status; } diff --git a/src/proxy/http/remap/unit-tests/test_RemapRules.cc b/src/proxy/http/remap/unit-tests/test_RemapRules.cc index f226f4dc45..033f8c6e14 100644 --- a/src/proxy/http/remap/unit-tests/test_RemapRules.cc +++ b/src/proxy/http/remap/unit-tests/test_RemapRules.cc @@ -35,6 +35,8 @@ #include "swoc/swoc_file.h" #include "ts/apidefs.h" #include "tscore/BaseLogFile.h" +#include "tsutil/PostScript.h" + #include <memory> #define CATCH_CONFIG_MAIN /* include main function */ @@ -83,6 +85,7 @@ SCENARIO("Parsing ACL named filters", "[proxy][remap]") GIVEN("Named filter definitions with multiple actions") { BUILD_TABLE_INFO bti{}; + ts::PostScript acl_rules_defer([&]() -> void { bti.clear_acl_rules_list(); }); UrlRewrite rewrite{}; bti.rewrite = &rewrite;
