]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
SVCB: Fix the textwriter for escaped params
authorPieter Lexis <pieter.lexis@powerdns.com>
Mon, 29 Mar 2021 17:09:36 +0000 (19:09 +0200)
committerPieter Lexis <pieter.lexis@powerdns.com>
Mon, 29 Mar 2021 17:10:33 +0000 (19:10 +0200)
pdns/rcpgenerator.cc
pdns/test-dnsrecords_cc.cc

index 84a468f1237a67c6ed7d08785d1dfd9484b98b61..0acab9372c918c5bab6170cc139cf364ecfd6466 100644 (file)
@@ -760,8 +760,20 @@ void RecordTextWriter::xfrSVCBValueList(const vector<string> &val) {
       shouldQuote = true;
     }
     string tmp = txtEscape(v);
-    boost::replace_all(tmp, ",", "\\\\,");
-    escaped.push_back(tmp);
+    string unescaped;
+    unescaped.reserve(tmp.size() + 4);
+    for (auto const &ch : tmp) {
+      if (ch == '\\') {
+        unescaped += R"F(\\)F";
+        continue;
+      }
+      if (ch == ',') {
+        unescaped += R"F(\\,)F";
+        continue;
+      }
+      unescaped += ch;
+    }
+    escaped.push_back(unescaped);
   }
   if (shouldQuote) {
     d_string.append(1, '"');
index 9094d24ee8d7ce69c35e07cb503af54794abf27e..ca9522b81efaa2ce65ecb8af0fb0544695f7de0f 100644 (file)
@@ -233,6 +233,7 @@ BOOST_AUTO_TEST_CASE(test_record_types) {
      (CASE_L(QType::SVCB, "16 foo.powerdns.org. alpn=h2,h3 mandatory=alpn ipv4hint=\"192.0.2.1\"", "16 foo.powerdns.org. mandatory=alpn alpn=h2,h3 ipv4hint=192.0.2.1", "\0\x10\3foo\x08powerdns\x03org\x00\x00\x00\x00\x02\x00\x01\x00\x01\x00\x06\x02h2\x02h3\x00\x04\x00\x04\xc0\x00\x02\x01"))
      // Escaped ALPN value
      (CASE_S(QType::SVCB, R"FOO(1 foo.powerdns.org. alpn=h3\\,cool,h2)FOO", "\0\x01\3foo\x08powerdns\x03org\x00\x00\x01\x00\x0b\x07h3,cool\x02h2"))
+     (CASE_S(QType::SVCB, R"FOO(1 foo.powerdns.org. alpn=h\\\\3\\,cool,h2)FOO", "\0\x01\3foo\x08powerdns\x03org\x00\x00\x01\x00\x0c\x08h\\3,cool\x02h2"))
      // Escaped _and_ spaced ALPN value
      (CASE_S(QType::SVCB, R"FOO(1 foo.powerdns.org. alpn="h3\\,co ol,h2")FOO", "\0\x01\3foo\x08powerdns\x03org\x00\x00\x01\x00\x0c\x08h3,co ol\x02h2"))