|
32 | 32 | #include "tscore/Regression.h" |
33 | 33 | #include "tscore/Tokenizer.h" |
34 | 34 |
|
| 35 | +#include <string> |
35 | 36 | #include <string_view> |
36 | 37 |
|
37 | 38 | using namespace std::literals; |
@@ -556,6 +557,11 @@ ParentRecord::ProcessParents(char *val, bool isPrimary) |
556 | 557 | errPtr = "Parent string is empty"; |
557 | 558 | goto MERROR; |
558 | 559 | } |
| 560 | + if (tmp3 && strlen(tmp3 + 1) > MAXDNAME) { |
| 561 | + errPtr = "Parent hash string is too long"; |
| 562 | + goto MERROR; |
| 563 | + } |
| 564 | + |
559 | 565 | // Update the pRecords |
560 | 566 | if (isPrimary) { |
561 | 567 | memcpy(this->parents[i].hostname, current, tmp - current); |
@@ -1948,6 +1954,37 @@ EXCLUSIVE_REGRESSION_TEST(PARENTSELECTION)(RegressionTest * /* t ATS_UNUSED */, |
1948 | 1954 | FP; |
1949 | 1955 | RE(verify(result, ParentResultType::SPECIFIED, "minnie", 80), 213); |
1950 | 1956 |
|
| 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 | + |
1951 | 1988 | delete request; |
1952 | 1989 | delete result; |
1953 | 1990 | delete params; |
|
0 commit comments