]> granicus.if.org Git - pdns/commitdiff
dnsdist: Prevent EOF error for empty console response w/o sodium
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 18 Mar 2016 09:55:38 +0000 (10:55 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 18 Mar 2016 09:55:38 +0000 (10:55 +0100)
Prevent the "Fatal error: EOF while reading message" error when
the server send an empty response to a single console command.
It was caused by calling `readn2()` for a 0-sized read.
When libsodium support is enabled, padding prevents 0-sized
responses anyway.

pdns/dnsdist-console.cc

index 8e9dc591462d5e960c8cad355ffc380afaf685d9..f9fafc60faab98f1bd822c453a56b5c27f4317d3 100644 (file)
@@ -33,18 +33,23 @@ void doClient(ComboAddress server, const std::string& command)
   readn2(fd, (char*)theirs.value, sizeof(theirs.value));
 
   if(!command.empty()) {
-    string response;
     string msg=sodEncryptSym(command, g_key, ours);
     putMsgLen32(fd, msg.length());
     if(!msg.empty())
       writen2(fd, msg);
     uint32_t len;
-    getMsgLen32(fd, &len);
-    boost::scoped_array<char> resp(new char[len]);
-    readn2(fd, resp.get(), len);
-    msg.assign(resp.get(), len);
-    msg=sodDecryptSym(msg, g_key, theirs);
-    cout<<msg<<endl;
+    if(getMsgLen32(fd, &len)) {
+      if (len > 0) {
+        boost::scoped_array<char> resp(new char[len]);
+        readn2(fd, resp.get(), len);
+        msg.assign(resp.get(), len);
+        msg=sodDecryptSym(msg, g_key, theirs);
+        cout<<msg<<endl;
+      }
+    }
+    else {
+      cout << "Connection closed by the server." << endl;
+    }
     close(fd);
     return; 
   }
@@ -80,7 +85,6 @@ void doClient(ComboAddress server, const std::string& command)
     if(line.empty())
       continue;
 
-    string response;
     string msg=sodEncryptSym(line, g_key, ours);
     putMsgLen32(fd, msg.length());
     writen2(fd, msg);