Skip to content

Commit

Permalink
fix error where memset was intended to be used instead of memcpy; do …
Browse files Browse the repository at this point in the history
…proper error detection around ZMQ recv/send;
  • Loading branch information
gatekeep committed Nov 2, 2022
1 parent dca0ee0 commit db019eb
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
5 changes: 4 additions & 1 deletion FirmwareMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ int checkArgs(int argc, char* argv[])
else if (IS("-t")) {
if ((argc - 1) <= 0)
usage("error: %s", "must specify the ZeroMQ Tx IPC Endpoint");
m_zmqRx = std::string(argv[++i]);
m_zmqTx = std::string(argv[++i]);

if (m_zmqTx == "")
usage("error: %s", "IPC endpoint cannot be blank!");
Expand Down Expand Up @@ -417,6 +417,9 @@ static void sigHandler(int signum)

int main(int argc, char** argv)
{
m_zmqRx = std::string("ipc:///tmp/dvm-rx.ipc");
m_zmqTx = std::string("ipc:///tmp/dvm-tx.ipc");

if (argv[0] != nullptr && *argv[0] != 0)
g_progExe = std::string(argv[0]);

Expand Down
2 changes: 1 addition & 1 deletion SerialPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ void SerialPort::getVersion()
reply[4U] = io.getCPU();

// Reserve 16 bytes for the UDID
::memcpy(reply + 5U, 0x00U, 16U);
::memset(reply + 5U, 0x00U, 16U);
io.getUDID(reply + 5U);

uint8_t count = 21U;
Expand Down
44 changes: 40 additions & 4 deletions sdr/IOSDR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ void IO::interrupt()
zmq::message_t reply = zmq::message_t(720 * sizeof(short));
::memcpy(reply.data(), (unsigned char*)m_audioBufTx.data(), 720 * sizeof(short));

m_zmqSocketTx.send(reply, zmq::send_flags::dontwait);
try
{
m_zmqSocketTx.send(reply, zmq::send_flags::dontwait);
}
catch(const zmq::error_t& zmqE) { /* stub */ }

usleep(9600 * 3);

Expand Down Expand Up @@ -149,8 +153,21 @@ void IO::initInt()
/// </summary>
void IO::startInt()
{
m_zmqSocketTx.bind(m_zmqTx);
m_zmqSocketRx.connect(m_zmqRx);
try
{
::LogMessage(LOG_DSP, "Binding Tx socket to %s", m_zmqTx.c_str());
m_zmqSocketTx.bind(m_zmqTx);
}
catch(const zmq::error_t& zmqE) { ::LogError(LOG_DSP, "IO::startInt(), Tx Socket: %s", zmqE.what()); }
catch(const std::exception& e) { ::LogError(LOG_DSP, "IO::startInt(), Tx Socket: %s", e.what()); }

try
{
::LogMessage(LOG_DSP, "Connecting Rx socket to %s", m_zmqRx.c_str());
m_zmqSocketRx.connect(m_zmqRx);
}
catch(const zmq::error_t& zmqE) { ::LogError(LOG_DSP, "IO::startInt(), Rx Socket: %s", zmqE.what()); }
catch(const std::exception& e) { ::LogError(LOG_DSP, "IO::startInt(), Rx Socket: %s", e.what()); }

if (::pthread_mutex_init(&m_txLock, NULL) != 0) {
::LogError(LOG_DSP, "Tx thread lock failed?");
Expand Down Expand Up @@ -248,7 +265,26 @@ void IO::interruptRx()
uint8_t control = MARK_NONE;

zmq::message_t msg;
zmq::recv_result_t recv = m_zmqSocketRx.recv(msg, zmq::recv_flags::none);
zmq::recv_result_t recv;
try
{
recv = m_zmqSocketRx.recv(msg, zmq::recv_flags::none);
}
catch(const zmq::error_t& zmqE)
{
if (zmqE.num() == ENOTSOCK || zmqE.num() == ENOTCONN ||
zmqE.num() == ECONNABORTED || zmqE.num() == ECONNRESET ||
zmqE.num() == ENETDOWN || zmqE.num() == ENETUNREACH || zmqE.num() == ENETRESET) {
try
{
m_zmqSocketRx.connect(m_zmqRx);
}
catch(const zmq::error_t& zmqE) { /* stub */}
return;
} else {
::LogError(LOG_DSP, "IO::interruptRx(): %s (%u)", zmqE.what(), zmqE.num());
}
}

int size = msg.size();
if (size < 1)
Expand Down

0 comments on commit db019eb

Please sign in to comment.