From: Remi Gacogne Date: Fri, 17 Feb 2023 13:30:50 +0000 (+0100) Subject: dnsdist: Ensure we have at least one protobuf MetaValue X-Git-Tag: dnsdist-1.8.0-rc1~2^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F12561%2Fhead;p=thirdparty%2Fpdns.git dnsdist: Ensure we have at least one protobuf MetaValue --- diff --git a/pdns/dnsdist-protobuf.cc b/pdns/dnsdist-protobuf.cc index c1250ba154..3eb5b82d92 100644 --- a/pdns/dnsdist-protobuf.cc +++ b/pdns/dnsdist-protobuf.cc @@ -197,7 +197,13 @@ void DNSDistProtoBufMessage::serialize(std::string& data) const m.commitResponse(); for (const auto& [key, values] : d_metaTags) { - m.setMeta(key, values, {}); + if (!values.empty()) { + m.setMeta(key, values, {}); + } + else { + /* the MetaValue field is _required_ to exist, even if we have no value */ + m.setMeta(key, {std::string()}, {}); + } } } diff --git a/regression-tests.dnsdist/test_Protobuf.py b/regression-tests.dnsdist/test_Protobuf.py index fead59012a..eee259b048 100644 --- a/regression-tests.dnsdist/test_Protobuf.py +++ b/regression-tests.dnsdist/test_Protobuf.py @@ -551,12 +551,8 @@ class TestProtobufMetaDOH(DNSDistProtobufTest): self.assertEqual(len(msg.meta), 5) tags = {} for entry in msg.meta: - if method == "sendDOHQueryWrapper": - self.assertEqual(len(entry.value.stringVal), 1) - tags[entry.key] = entry.value.stringVal[0] - else: - self.assertEqual(len(entry.value.stringVal), 0) - tags[entry.key] = None + self.assertEqual(len(entry.value.stringVal), 1) + tags[entry.key] = entry.value.stringVal[0] self.assertIn('agent', tags) if method == "sendDOHQueryWrapper": @@ -576,12 +572,8 @@ class TestProtobufMetaDOH(DNSDistProtobufTest): self.assertEqual(len(msg.meta), 5) tags = {} for entry in msg.meta: - if method == "sendDOHQueryWrapper": - self.assertEqual(len(entry.value.stringVal), 1) - tags[entry.key] = entry.value.stringVal[0] - else: - self.assertEqual(len(entry.value.stringVal), 0) - tags[entry.key] = None + self.assertEqual(len(entry.value.stringVal), 1) + tags[entry.key] = entry.value.stringVal[0] self.assertIn('agent', tags) if method == "sendDOHQueryWrapper":