]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Also convert callers of readWithTimeout(), as suggested by @rgacogne 14396/head
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 2 Jul 2024 10:02:52 +0000 (12:02 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 2 Jul 2024 10:02:52 +0000 (12:02 +0200)
modules/remotebackend/httpconnector.cc
pdns/ixfrutils.cc
pdns/webserver.cc

index 38950b15dad791ae2f7a2bc93323808b92be7840..acff9dfb7c0dcb7b52dc9887c93cc4639eab7b9e 100644 (file)
@@ -431,23 +431,19 @@ int HTTPConnector::recv_message(Json& output)
   if (d_socket == nullptr) {
     return -1; // cannot receive :(
   }
-  char buffer[4096];
-  int rd = -1;
-  time_t t0 = 0;
+  std::array<char, 4096> buffer{};
+  time_t time0 = 0;
 
   arl.initialize(&resp);
 
   try {
-    t0 = time((time_t*)nullptr);
-    while (!arl.ready() && (labs(time((time_t*)nullptr) - t0) <= timeout)) {
-      rd = d_socket->readWithTimeout(buffer, sizeof(buffer), timeout);
-      if (rd == 0) {
+    time0 = time(nullptr);
+    while (!arl.ready() && (labs(time(nullptr) - time0) <= timeout)) {
+      auto readBytes = d_socket->readWithTimeout(buffer.data(), buffer.size(), timeout);
+      if (readBytes == 0) {
         throw NetworkError("EOF while reading");
       }
-      if (rd < 0) {
-        throw NetworkError(std::string(strerror(rd)));
-      }
-      arl.feed(std::string(buffer, rd));
+      arl.feed(std::string(buffer.data(), readBytes));
     }
     // timeout occurred.
     if (!arl.ready()) {
@@ -470,13 +466,12 @@ int HTTPConnector::recv_message(Json& output)
     throw PDNSException("Received unacceptable HTTP status code " + std::to_string(resp.status) + " from HTTP endpoint " + d_addr.toStringWithPort());
   }
 
-  int rv = -1;
   std::string err;
   output = Json::parse(resp.body, err);
   if (output != nullptr) {
-    return resp.body.size();
+    return static_cast<int>(resp.body.size());
   }
   g_log << Logger::Error << "Cannot parse JSON reply: " << err << endl;
 
-  return rv;
+  return -1;
 }
index 40b6b2495d7465caf4b4f863160a20b729d30d0e..385ac490b0a0a6e22387611969563f16cb6b5474 100644 (file)
@@ -53,8 +53,8 @@ uint32_t getSerialFromPrimary(const ComboAddress& primary, const DNSName& zone,
   string reply;
   reply.resize(4096);
   // will throw a NetworkError on timeout
-  ssize_t got = s.readWithTimeout(&reply[0], reply.size(), timeout);
-  if (got < 0 || static_cast<size_t>(got) < sizeof(dnsheader)) {
+  size_t got = s.readWithTimeout(reply.data(), reply.size(), timeout);
+  if (got < sizeof(dnsheader)) {
     throw std::runtime_error("Invalid response size " + std::to_string(got));
   }
 
index 754484558af6b0dbe42ccfca98405419834a8a02..8a257c66fe3384c771c2369c42f5783b96f5927b 100644 (file)
@@ -525,11 +525,10 @@ void WebServer::serveConnection(const std::shared_ptr<Socket>& client) const {
 
     try {
       while(!req.complete) {
-        int bytes;
-        char buf[16000];
-        bytes = client->readWithTimeout(buf, sizeof(buf), timeout);
+        std::array<char, 16000> buf{};
+        auto bytes = client->readWithTimeout(buf.data(), buf.size(), timeout);
         if (bytes > 0) {
-          string data = string(buf, bytes);
+          string data = string(buf.data(), bytes);
           req.complete = yarl.feed(data);
         } else {
           // read error OR EOF