# UNDF: UNDF-2026-000001159 --- a/src/network_inspectors/appid/detector_plugins/http_url_patterns.h +++ b/src/network_inspectors/appid/detector_plugins/http_url_patterns.h @@ -217,9 +217,11 @@ struct CHPMatchCandidate typedef std::vector CHPMatchTally; +#include + class ChpMatchDescriptor { public: void sort_chp_matches() { for(unsigned i = 0; i < NUM_HTTP_FIELDS; i++) @@ -235,6 +237,7 @@ public: unsigned cur_ptype = 0; uint8_t* buffer[NUM_HTTP_FIELDS] = {}; unsigned length[NUM_HTTP_FIELDS] = {}; CHPMatchTally match_tally; + std::unordered_map match_tally_index; }; --- a/src/network_inspectors/appid/detector_plugins/http_url_patterns.cc +++ b/src/network_inspectors/appid/detector_plugins/http_url_patterns.cc @@ -589,14 +589,14 @@ static int chp_pattern_match(void* id, void*, int match_end_pos, void* data, vo static inline void chp_add_candidate_to_tally(CHPMatchTally& match_tally, CHPApp* chpapp) { - auto it = std::find_if(match_tally.begin(), match_tally.end(), - [&chpapp](const CHPMatchCandidate& item){ return chpapp == item.chpapp; }); - if (it != match_tally.end()) - { - (*it).key_pattern_countdown--; - return; - } - - match_tally.emplace_back( CHPMatchCandidate{ chpapp, chpapp->key_pattern_length_sum, - chpapp->key_pattern_count - 1 } ); } +static inline void chp_add_candidate_to_tally(CHPMatchTally& match_tally, + std::unordered_map& match_tally_index, CHPApp* chpapp) +{ + auto it = match_tally_index.find(chpapp); + if (it != match_tally_index.end()) + { + match_tally[it->second].key_pattern_countdown--; + return; + } + + std::size_t idx = match_tally.size(); + match_tally.emplace_back( CHPMatchCandidate{ chpapp, chpapp->key_pattern_length_sum, + chpapp->key_pattern_count - 1 } ); + match_tally_index[chpapp] = idx; +} + // In addition to creating the linked list of matching actions this function will // create the CHPMatchTally needed to find the longest matching pattern. static int chp_key_pattern_match(void* id, void*, int match_end_pos, void* data, void*) @@ -611,7 +613,7 @@ static int chp_key_pattern_match(void* id, void*, int match_end_pos, void* data if (target->key_pattern) { - chp_add_candidate_to_tally(cmd->match_tally, target->chpapp); + chp_add_candidate_to_tally(cmd->match_tally, cmd->match_tally_index, target->chpapp); } return chp_pattern_match(id, nullptr, match_end_pos, cmd, nullptr);