Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/proxy/ParentSelection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "tscore/Regression.h"
#include "tscore/Tokenizer.h"

#include <string>
#include <string_view>

using namespace std::literals;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down