Skip to content

Commit

Permalink
Fix crash by including remap files with named filters (#11997)
Browse files Browse the repository at this point in the history
* Fix crash by including remap files with named filters

* Fix unit test

(cherry picked from commit 4c9c7c6)
  • Loading branch information
masaori335 authored and Chris McFarlen committed Jan 28, 2025
1 parent 8d070df commit 33da84b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
3 changes: 3 additions & 0 deletions include/proxy/http/remap/RemapConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 14 additions & 8 deletions src/proxy/http/remap/RemapConfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
{
Expand Down Expand Up @@ -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;
}
3 changes: 3 additions & 0 deletions src/proxy/http/remap/unit-tests/test_RemapRules.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 33da84b

Please sign in to comment.