]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Do not read further than the length we received, the string might 10930/head
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 1 Nov 2021 07:28:18 +0000 (08:28 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 1 Nov 2021 07:28:18 +0000 (08:28 +0100)
be followed by a passed fd.

Interesting to see that OpenBSD chops up recvs based on the sends,
while Linux is happy to read more than was passed to the corresponding
send call if another send was called after that.

pdns/rec_channel.cc

index 4f8742022c1e55bc8f283119b2d4416c5d05f85b..b288abe8325970e955ed241f073ff4fe0c667aaf 100644 (file)
@@ -171,7 +171,8 @@ RecursorControlChannel::Answer RecursorControlChannel::recv(int fd, unsigned int
   str.reserve(len);
   while (str.length() < len) {
     char buffer[1024];
-    ssize_t recvd = ::recv(fd, buffer, sizeof(buffer), 0);
+    size_t toRead = std::min(len - str.length(), sizeof(buffer));
+    ssize_t recvd = ::recv(fd, buffer, toRead, 0);
     if (recvd <= 0) {
       // EOF means we have a length error
       throw PDNSException("Unable to receive message over control channel: " + stringerror());