From cbe58b755e1946ed0fde248c65b7dbd8c203cc4a Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Wed, 23 Feb 2022 20:35:17 +0300 Subject: [PATCH] UI: ControlManager: Improve log about bad control requests --- src/ui/control/controlmanager.cpp | 2 -- src/ui/control/controlworker.cpp | 13 +++++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/ui/control/controlmanager.cpp b/src/ui/control/controlmanager.cpp index c6102e01..4e35de86 100644 --- a/src/ui/control/controlmanager.cpp +++ b/src/ui/control/controlmanager.cpp @@ -51,8 +51,6 @@ ControlWorker *ControlManager::newServiceClient(QObject *parent) const w->setupForAsync(); w->setIsServiceClient(true); - connect(w, &ControlWorker::disconnected, this, - [&] { logWarning() << "Server disconnected" << w->errorString(); }); connect(w, &ControlWorker::requestReady, this, &ControlManager::processRequest); if (!w->connectToServer(getServerName(true))) { diff --git a/src/ui/control/controlworker.cpp b/src/ui/control/controlworker.cpp index db19db53..0221cc8b 100644 --- a/src/ui/control/controlworker.cpp +++ b/src/ui/control/controlworker.cpp @@ -2,6 +2,7 @@ #include #include +#include namespace { @@ -223,12 +224,20 @@ bool ControlWorker::readRequest() bool ControlWorker::readRequestHeader() { - if (socket()->read((char *) &m_requestHeader, sizeof(RequestHeader)) != sizeof(RequestHeader)) + const int headerSize = socket()->read((char *) &m_requestHeader, sizeof(RequestHeader)); + if (headerSize != sizeof(RequestHeader)) { + qWarning() << "Bad request header:" + << "size=" << headerSize; return false; + } if (m_requestHeader.command() == Control::CommandNone - || m_requestHeader.dataSize() > dataMaxSize) + || m_requestHeader.dataSize() > dataMaxSize) { + qWarning() << "Bad request:" + << "command=" << m_requestHeader.command() + << "size=" << m_requestHeader.dataSize(); return false; + } return true; }