This is an automated email from the ASF dual-hosted git repository.
cmcfarlen pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/10.1.x by this push:
new 2ba8c1c8f7 header_rewrite fix storage lifetime for LAST-CAPTURE
(#12809) (#12819)
2ba8c1c8f7 is described below
commit 2ba8c1c8f7f73ac23a2951e2dc238cb9d21d734b
Author: Chris McFarlen <[email protected]>
AuthorDate: Fri Jan 16 09:13:23 2026 -0600
header_rewrite fix storage lifetime for LAST-CAPTURE (#12809) (#12819)
* Use a class member variable to hold regex match
* Use regex subject storage in Resources
* rename extended struct
(cherry picked from commit 9efc018724def2c1a0e1fe5129bb04c79f53bcf0)
---
plugins/header_rewrite/conditions.cc | 4 ++--
plugins/header_rewrite/matcher.h | 2 +-
plugins/header_rewrite/resources.h | 26 ++++++++++++++++++++++++--
3 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/plugins/header_rewrite/conditions.cc
b/plugins/header_rewrite/conditions.cc
index 9442c0ab56..fb44abdba6 100644
--- a/plugins/header_rewrite/conditions.cc
+++ b/plugins/header_rewrite/conditions.cc
@@ -1718,8 +1718,8 @@ ConditionLastCapture::set_qualifier(const std::string &q)
void
ConditionLastCapture::append_value(std::string &s, const Resources &res)
{
- if (res.matches.size() > _ix) {
- s.append(res.matches[_ix]);
+ if (res.matches().size() > _ix) {
+ s.append(res.matches()[_ix]);
Dbg(pi_dbg_ctl, "Evaluating LAST-CAPTURE(%d)", _ix);
}
}
diff --git a/plugins/header_rewrite/matcher.h b/plugins/header_rewrite/matcher.h
index 891fb46a46..5c2682105c 100644
--- a/plugins/header_rewrite/matcher.h
+++ b/plugins/header_rewrite/matcher.h
@@ -193,7 +193,7 @@ private:
test_reg(const std::string &t, const Resources &res) const
{
Dbg(pi_dbg_ctl, "Test regular expression %s : %s (NOCASE = %d)",
_data.c_str(), t.c_str(), static_cast<int>(_nocase));
- int count = _reHelper.regexMatch(t, const_cast<Resources &>(res).matches);
+ int count = res.match(_reHelper, t);
if (count > 0) {
Dbg(pi_dbg_ctl, "Successfully found regular expression match");
diff --git a/plugins/header_rewrite/resources.h
b/plugins/header_rewrite/resources.h
index 3e2d729278..ab59540f97 100644
--- a/plugins/header_rewrite/resources.h
+++ b/plugins/header_rewrite/resources.h
@@ -23,6 +23,7 @@
#include <string>
+#include "regex_helper.h"
#include "ts/ts.h"
#include "ts/remap.h"
@@ -79,6 +80,22 @@ public:
return _ready;
}
+ int
+ match(const regexHelper &re, const std::string &s) const
+ {
+ // For last capture to work safely, this has to make a copy of the subject
string
+ // so the matches results will point into that and avoid any lifetime
issues with
+ // the passed in `s`
+ _extended_info.subject_storage = s;
+ return re.regexMatch(_extended_info.subject_storage,
_extended_info.matches);
+ }
+
+ const RegexMatches &
+ matches() const
+ {
+ return _extended_info.matches;
+ }
+
TSCont contp = nullptr;
TSRemapRequestInfo *_rri = nullptr;
TSMBuffer bufp = nullptr;
@@ -95,8 +112,13 @@ public:
TransactionState state; // Without cripts, txnp / ssnp goes here
#endif
TSHttpStatus resp_status = TS_HTTP_STATUS_NONE;
- RegexMatches matches;
- bool changed_url = false;
+
+ struct LifetimeExtension {
+ std::string subject_storage;
+ RegexMatches matches;
+ };
+ bool changed_url = false;
+ mutable LifetimeExtension _extended_info;
private:
void