]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Check sizes of generated protobuf messages
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 3 Aug 2022 09:33:02 +0000 (11:33 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 23 Aug 2022 07:15:21 +0000 (09:15 +0200)
pdns/pdns_recursor.cc
pdns/recursordist/rec-protozero.hh
pdns/remote_logger.cc

index 59583f42fb52cf2f44ae425f85a6e96770d04ce3..d1b7178a07a25899e7f1fcd1a2680127be617060 100644 (file)
@@ -1359,7 +1359,11 @@ void startDoResolve(void* p)
 #endif /* NOD ENABLED */
 
         if (t_protobufServers) {
-          pbMessage.addRR(*i, luaconfsLocal->protobufExportConfig.exportTypes, udr);
+          // Max size is 64k, but we're conservative here, as other fields are added after the answers have been added
+          // If a single answer causes a too big protobuf message, it wil be dropped by queueData()
+          if (pbMessage.size() < std::numeric_limits<uint16_t>::max() / 2) {
+            pbMessage.addRR(*i, luaconfsLocal->protobufExportConfig.exportTypes, udr);
+          }
         }
       }
       if (needCommit)
index 6502fd71a7ab1303242c3a61cf6474b967a590b0..926982a20c8e757f16f3233c982eaac614610901 100644 (file)
@@ -92,6 +92,11 @@ namespace ProtoZero
       return d_rspbuf;
     }
 
+    [[nodiscard]] size_t size() const
+    {
+      return d_msgbuf.size() + d_rspbuf.size();
+    }
+
     std::string&& finishAndMoveBuf()
     {
       if (!d_rspbuf.empty()) {
index 8eee2e7c1722921ba04d603ea71bc903cf952a1c..77eee2d446bd0d6286e9b020391fc1b5107e7c7e 100644 (file)
@@ -134,7 +134,14 @@ bool RemoteLogger::reconnect()
 void RemoteLogger::queueData(const std::string& data)
 {
   if (data.size() > std::numeric_limits<uint16_t>::max()) {
-    throw std::runtime_error("Got a request to write an object of size " + std::to_string(data.size()));
+    const auto msg = "Not sending too large protobuf message";
+#ifdef WE_ARE_RECURSOR
+    SLOG(g_log<<Logger::Info<<msg<<endl,
+         g_slog->withName("protobuf")->info(Logr::Info, msg));
+#else
+    warnlog(msg);
+#endif
+    return;
   }
 
   auto runtime = d_runtime.lock();