From e4ef64beea862790bf81f8554cc23aded72e758e Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Fri, 18 Mar 2016 10:55:38 +0100 Subject: [PATCH] dnsdist: Prevent EOF error for empty console response w/o sodium 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 | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/pdns/dnsdist-console.cc b/pdns/dnsdist-console.cc index 8e9dc5914..f9fafc60f 100644 --- a/pdns/dnsdist-console.cc +++ b/pdns/dnsdist-console.cc @@ -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 resp(new char[len]); - readn2(fd, resp.get(), len); - msg.assign(resp.get(), len); - msg=sodDecryptSym(msg, g_key, theirs); - cout< 0) { + boost::scoped_array resp(new char[len]); + readn2(fd, resp.get(), len); + msg.assign(resp.get(), len); + msg=sodDecryptSym(msg, g_key, theirs); + cout<