Copilot commented on code in PR #12593:
URL: https://github.com/apache/trafficserver/pull/12593#discussion_r4517614755
##########
include/proxy/http/remap/NextHopStrategyFactory.h:
##########
@@ -50,11 +51,16 @@ class NextHopStrategyFactory
// counted and attached to an HttpSM.
NextHopSelectionStrategy *strategyInstance(const char *name) const;
+ // Pointer comparison only; safe to call with a dangling pointer.
+ bool contains(NextHopSelectionStrategy const *strategy) const;
+
bool strategies_loaded;
private:
std::string fn;
void loadConfigFile(const std::string &file, std::stringstream &doc,
std::unordered_set<std::string> &include_once);
void createStrategy(const std::string &name, const NHPolicyType
policy_type, ts::Yaml::Map &node);
std::unordered_map<std::string, NextHopSelectionStrategy *> _strategies;
+ std::unordered_set<NextHopSelectionStrategy const *> _strategy_ptrs;
+ mutable std::atomic<bool>
_not_loaded_logged{false};
Review Comment:
`std::unordered_set` is used in this header but `<unordered_set>` is not
included, which can cause build failures depending on transitive includes. Add
the missing include explicitly. Also, the implementation uses
`unordered_set::contains(...)` (C++20); if the project/toolchain is still
C++17, replace `.contains` with `find(...) != end()` (or ensure the build is
configured for C++20 consistently).
##########
plugins/regex_remap/regex_remap.cc:
##########
@@ -919,6 +927,26 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, char
* /* errbuf ATS_UNUSE
ri->rule_hits.resize(ri->rule_set->rules().size());
}
+ auto const &rules = ri->rule_set->rules();
+
+ ri->strategy_actions.resize(rules.size());
+ for (size_t ix = 0; ix < rules.size(); ++ix) {
+ if (!rules[ix]->has_strategy_option()) {
+ continue;
+ }
Review Comment:
`ri->rule_set` is dereferenced unconditionally here, but earlier code paths
indicate it can be null (there was already a guard around `rule_hits.resize`).
If `ri->rule_set` can be null, this becomes a null-deref crash in
`TSRemapNewInstance`. Fix by guarding this entire strategy_actions
initialization behind `if (ri->rule_set != nullptr)` (or returning `TS_ERROR`
when rules are unavailable), and ensure `TSRemapDoRemap` can’t index
`strategy_actions` unless it was sized.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]