Browse Source

plugins/samplesource/remotetcpinput: Fix message buffer overrun

Fix Coverity CID 652555 by allocating an extra byte and null-terminating the
message buffer. Guard text extraction when the delimiter is absent to avoid
reading beyond the buffer.

Signed-off-by: Robin Getz <rgetz503@gmail.com>
chirpmodem-v8.1.0
Robin Getz 4 weeks ago
parent
commit
c6f577af14
No known key found for this signature in database
GPG Key ID: 51C7231FFED0E060
  1. 7
      plugins/samplesource/remotetcpinput/remotetcpinputtcphandler.cpp

7
plugins/samplesource/remotetcpinput/remotetcpinputtcphandler.cpp

@ -1948,11 +1948,12 @@ void RemoteTCPInputTCPHandler::processCommands() @@ -1948,11 +1948,12 @@ void RemoteTCPInputTCPHandler::processCommands()
case RemoteTCPProtocol::sendMessage:
{
char *buf = new char[m_commandLength];
char *buf = new char[m_commandLength + 1];
qint64 bytesRead = m_dataSocket->read(buf, m_commandLength);
if (bytesRead == m_commandLength)
{
buf[m_commandLength] = '\0';
bool broadcast = (bool) buf[0];
int i;
for (i = 1; i < (int) m_commandLength; i++)
@ -1962,7 +1963,9 @@ void RemoteTCPInputTCPHandler::processCommands() @@ -1962,7 +1963,9 @@ void RemoteTCPInputTCPHandler::processCommands()
}
}
QString callsign = QString::fromUtf8(&buf[1]);
QString text = QString::fromUtf8(&buf[i+1]);
QString text = (i < (int) m_commandLength)
? QString::fromUtf8(&buf[i+1])
: QString();
qDebug() << "RemoteTCPInputTCPHandler::processCommands: Message " << m_dataSocket->peerAddress() << m_dataSocket->peerPort() << callsign << broadcast << text;
if (m_messageQueueToGUI) {

Loading…
Cancel
Save