]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Fix zero-sized response in dnsdist client without libsodium
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 10 Dec 2015 15:17:54 +0000 (16:17 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 10 Dec 2015 15:17:54 +0000 (16:17 +0100)
Without libsodium support, we do actually get zero-sized response
(no padding).
Reported by @gryphius in issue #3015.

pdns/dnsdist-console.cc

index 31bf6f5dffa2e8a91434bf804a0189421e7ba644..41d17b24634b8473f9426b6fafe708b5ca2e9c1a 100644 (file)
@@ -65,16 +65,21 @@ void doClient(ComboAddress server, const std::string& command)
     putMsgLen32(fd, msg.length());
     writen2(fd, msg);
     uint32_t len;
-    if(!getMsgLen32(fd, &len) || len == 0) {
+    if(!getMsgLen32(fd, &len)) {
       cout << "Connection closed by the server." << endl;
       break;
     }
 
-    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 (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<<endl;
+    }
   }
 }