From: Pieter Lexis Date: Mon, 8 Feb 2021 19:21:43 +0000 (+0100) Subject: Use SVCB Valuelist parser when parsing record text X-Git-Tag: dnsdist-1.6.0-rc1~33^2~18 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d1082642c949f409771f98bd57ba4a1531b2f7fc;p=thirdparty%2Fpdns.git Use SVCB Valuelist parser when parsing record text --- diff --git a/pdns/rcpgenerator.cc b/pdns/rcpgenerator.cc index c9cd1afa3d..d249cabee7 100644 --- a/pdns/rcpgenerator.cc +++ b/pdns/rcpgenerator.cc @@ -303,6 +303,11 @@ void RecordTextReader::xfrRFC1035CharString(string &val) { d_pos += ctr; } +void RecordTextReader::xfrSVCBValueList(vector &val) { + auto ctr = parseSVCBValueList(d_string.substr(d_pos, d_end - d_pos), val); + d_pos += ctr; +} + void RecordTextReader::xfrSvcParamKeyVals(set& val) { while (d_pos != d_end) { @@ -347,16 +352,13 @@ void RecordTextReader::xfrSvcParamKeyVals(set& val) break; case SvcParam::ipv4hint: /* fall-through */ case SvcParam::ipv6hint: { + vector value; + xfrSVCBValueList(value); vector hints; - do { - ComboAddress address; - xfrCAWithoutPort(key, address); // The SVBC authors chose 4 and 6 to represent v4hint and v6hint :) - hints.push_back(address); - if (d_pos < d_end && d_string.at(d_pos) == ',') { - d_pos++; // Go to the next address - } - } while (d_pos != d_end && d_string.at(d_pos) != ' '); try { + for (auto const &v: value) { + hints.push_back(ComboAddress(v)); + } val.insert(SvcParam(key, std::move(hints))); } catch (const std::invalid_argument& e) { @@ -365,18 +367,14 @@ void RecordTextReader::xfrSvcParamKeyVals(set& val) break; } case SvcParam::alpn: { - string value; - xfrUnquotedText(value, false); - vector parts; - stringtok(parts, value, ","); - val.insert(SvcParam(key, std::move(parts))); + vector value; + xfrSVCBValueList(value); + val.insert(SvcParam(key, std::move(value))); break; } case SvcParam::mandatory: { - string value; - xfrUnquotedText(value, false); vector parts; - stringtok(parts, value, ","); + xfrSVCBValueList(parts); set values(parts.begin(), parts.end()); val.insert(SvcParam(key, std::move(values))); break; @@ -395,6 +393,9 @@ void RecordTextReader::xfrSvcParamKeyVals(set& val) string value; xfrBlobNoSpaces(value); if (haveQuote) { + if (d_string.at(d_pos) != '"') { + throw RecordTextException("echconfig value starts, but does not end with a '\"' symbol"); + } d_pos++; } val.insert(SvcParam(key, value)); diff --git a/pdns/rcpgenerator.hh b/pdns/rcpgenerator.hh index d824dac865..22b79ce87e 100644 --- a/pdns/rcpgenerator.hh +++ b/pdns/rcpgenerator.hh @@ -64,6 +64,7 @@ public: void xfrSvcParamKeyVals(set& val); void xfrRFC1035CharString(string &val); + void xfrSVCBValueList(vector &val); const string getRemaining() const { return d_string.substr(d_pos);