From f17f6f0f42ce99c130618fa02b4e3955a461b622 Mon Sep 17 00:00:00 2001 From: Mikael Nousiainen Date: Wed, 8 Mar 2023 23:35:08 +0200 Subject: [PATCH] Disable rig port flushing when async I/O is enabled. Improve validation of Icom frames. --- rigs/icom/frame.c | 6 ++++++ src/misc.c | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/rigs/icom/frame.c b/rigs/icom/frame.c index 081692705..9812b1e3a 100644 --- a/rigs/icom/frame.c +++ b/rigs/icom/frame.c @@ -530,6 +530,12 @@ static int read_icom_frame_generic(hamlib_port_t *p, while ((read < rxbuffer_len) && (rxbuffer[read - 1] != FI) && (rxbuffer[read - 1] != COL)); + // Check that we have a valid frame preamble (which might be just a single preable character) + if (rxbuffer[0] != PR) + { + return -RIG_EPROTO; + } + return (read); } diff --git a/src/misc.c b/src/misc.c index 6a7d34f34..41fe8d7eb 100644 --- a/src/misc.c +++ b/src/misc.c @@ -2147,6 +2147,12 @@ int HAMLIB_API parse_hoststr(char *hoststr, int hoststr_len, char host[256], //#define RIG_FLUSH_REMOVE int HAMLIB_API rig_flush(hamlib_port_t *port) { + // Data should never be flushed when using async I/O + if (port->asyncio) + { + return RIG_OK; + } + #ifndef RIG_FLUSH_REMOVE rig_debug(RIG_DEBUG_TRACE, "%s: called for %s device\n", __func__, port->type.rig == RIG_PORT_SERIAL ? "serial" : "network");