UI: ControlManager: Improve log about bad control requests

This commit is contained in:
Nodir Temirkhodjaev 2022-02-23 20:35:17 +03:00
parent baaa249796
commit cbe58b755e
2 changed files with 11 additions and 4 deletions

View File

@ -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))) {

View File

@ -2,6 +2,7 @@
#include <QDataStream>
#include <QLocalSocket>
#include <QLoggingCategory>
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;
}