Skip to content

Commit 08182ac

Browse files
serrislewcmcfarlen
authored andcommitted
Check valid parent selection hash string (#12985)
* Check valid parent selection hash string * add regression test * off by one (cherry picked from commit 1252ea4)
1 parent a978a92 commit 08182ac

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

src/proxy/ParentSelection.cc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "tscore/Regression.h"
3333
#include "tscore/Tokenizer.h"
3434

35+
#include <string>
3536
#include <string_view>
3637

3738
using namespace std::literals;
@@ -556,6 +557,11 @@ ParentRecord::ProcessParents(char *val, bool isPrimary)
556557
errPtr = "Parent string is empty";
557558
goto MERROR;
558559
}
560+
if (tmp3 && strlen(tmp3 + 1) > MAXDNAME) {
561+
errPtr = "Parent hash string is too long";
562+
goto MERROR;
563+
}
564+
559565
// Update the pRecords
560566
if (isPrimary) {
561567
memcpy(this->parents[i].hostname, current, tmp - current);
@@ -1948,6 +1954,37 @@ EXCLUSIVE_REGRESSION_TEST(PARENTSELECTION)(RegressionTest * /* t ATS_UNUSED */,
19481954
FP;
19491955
RE(verify(result, ParentResultType::SPECIFIED, "minnie", 80), 213);
19501956

1957+
// Test 214
1958+
// Overlong hash_string (exceeding MAXDNAME chars) should be rejected by ProcessParents.
1959+
// The entry is discarded so findParent returns DIRECT.
1960+
{
1961+
tbl[0] = '\0';
1962+
ST(214);
1963+
std::string long_hash(MAXDNAME + 1, 'a');
1964+
std::string cfg = "dest_domain=. parent=host:80&" + long_hash + " round_robin=consistent_hash go_direct=true\n";
1965+
ink_strlcpy(tbl, cfg.c_str(), sizeof(tbl));
1966+
REBUILD;
1967+
REINIT;
1968+
br(request, "overlong.hash.net");
1969+
FP;
1970+
RE(verify(result, ParentResultType::DIRECT, nullptr, 0), 214);
1971+
}
1972+
1973+
// Test 215
1974+
// Max-length hash_string that fits (MAXDNAME chars) should be accepted.
1975+
{
1976+
tbl[0] = '\0';
1977+
ST(215);
1978+
std::string max_hash(MAXDNAME, 'b');
1979+
std::string cfg = "dest_domain=. parent=host:80&" + max_hash + " round_robin=consistent_hash go_direct=false\n";
1980+
ink_strlcpy(tbl, cfg.c_str(), sizeof(tbl));
1981+
REBUILD;
1982+
REINIT;
1983+
br(request, "maxlen.hash.net");
1984+
FP;
1985+
RE(verify(result, ParentResultType::SPECIFIED, "host", 80), 215);
1986+
}
1987+
19511988
delete request;
19521989
delete result;
19531990
delete params;

0 commit comments

Comments
 (0)