diff --git a/src/proxy/ParentSelection.cc b/src/proxy/ParentSelection.cc index b282fba7b38..a1bc20452fb 100644 --- a/src/proxy/ParentSelection.cc +++ b/src/proxy/ParentSelection.cc @@ -32,6 +32,7 @@ #include "tscore/Regression.h" #include "tscore/Tokenizer.h" +#include #include using namespace std::literals; @@ -556,6 +557,11 @@ ParentRecord::ProcessParents(char *val, bool isPrimary) errPtr = "Parent string is empty"; goto MERROR; } + if (tmp3 && strlen(tmp3 + 1) > MAXDNAME) { + errPtr = "Parent hash string is too long"; + goto MERROR; + } + // Update the pRecords if (isPrimary) { memcpy(this->parents[i].hostname, current, tmp - current); @@ -1948,6 +1954,37 @@ EXCLUSIVE_REGRESSION_TEST(PARENTSELECTION)(RegressionTest * /* t ATS_UNUSED */, FP; RE(verify(result, ParentResultType::SPECIFIED, "minnie", 80), 213); + // Test 214 + // Overlong hash_string (exceeding MAXDNAME chars) should be rejected by ProcessParents. + // The entry is discarded so findParent returns DIRECT. + { + tbl[0] = '\0'; + ST(214); + std::string long_hash(MAXDNAME + 1, 'a'); + std::string cfg = "dest_domain=. parent=host:80&" + long_hash + " round_robin=consistent_hash go_direct=true\n"; + ink_strlcpy(tbl, cfg.c_str(), sizeof(tbl)); + REBUILD; + REINIT; + br(request, "overlong.hash.net"); + FP; + RE(verify(result, ParentResultType::DIRECT, nullptr, 0), 214); + } + + // Test 215 + // Max-length hash_string that fits (MAXDNAME chars) should be accepted. + { + tbl[0] = '\0'; + ST(215); + std::string max_hash(MAXDNAME, 'b'); + std::string cfg = "dest_domain=. parent=host:80&" + max_hash + " round_robin=consistent_hash go_direct=false\n"; + ink_strlcpy(tbl, cfg.c_str(), sizeof(tbl)); + REBUILD; + REINIT; + br(request, "maxlen.hash.net"); + FP; + RE(verify(result, ParentResultType::SPECIFIED, "host", 80), 215); + } + delete request; delete result; delete params;