From 54d6324dea2e89ee00ef4f24ca11a1ce5c1cda99 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Wed, 23 Sep 2020 09:12:14 -0500 Subject: [PATCH] Fix invalid return in patty_ax25_aprs_is_send() Fix invalid return in patty_ax25_aprs_is_send() wherein the number of bytes written to APRS-IS was returned, rather than the number of AX.25 packet bytes; the number of bytes read is the more important value as it is used later for repeating the frame to promiscuous mode SOCK_RAW sockets --- src/aprs_is.c | 58 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/src/aprs_is.c b/src/aprs_is.c index fa4da9b..bf10265 100644 --- a/src/aprs_is.c +++ b/src/aprs_is.c @@ -320,24 +320,30 @@ ssize_t patty_ax25_aprs_is_send(patty_ax25_aprs_is *aprs, size_t len) { patty_ax25_frame frame; - size_t offset = 0; + size_t i = 0, + o = 0, + hop; + ssize_t decoded; - int formatted, - i; + int formatted; char call[PATTY_AX25_ADDRSTRLEN+1]; if ((decoded = patty_ax25_frame_decode_address(&frame, buf, len)) < 0) { goto error; + } else { + i += decoded; } - if (patty_ax25_frame_decode_control(&frame, - PATTY_AX25_FRAME_NORMAL, - buf, - decoded, - len) < 0) { + if ((decoded = patty_ax25_frame_decode_control(&frame, + PATTY_AX25_FRAME_NORMAL, + buf, + i, + len)) < 0) { goto error; + } else { + i += decoded; } if (!PATTY_AX25_FRAME_CONTROL_UI(frame.control)) { @@ -354,55 +360,59 @@ ssize_t patty_ax25_aprs_is_send(patty_ax25_aprs_is *aprs, call)) < 0) { goto error; } else { - offset += formatted; + o += formatted; } if (patty_ax25_ntop(&frame.dest, call, sizeof(call)) < 0) { goto error; } - if ((formatted = snprintf(aprs->tx_buf + offset, - aprs->tx_bufsz - offset, + if ((formatted = snprintf(aprs->tx_buf + o, + aprs->tx_bufsz - o, "%s", call)) < 0) { goto error; } else { - offset += formatted; + o += formatted; } - for (i=0; itx_buf + offset, - aprs->tx_bufsz - offset, + if ((formatted = snprintf(aprs->tx_buf + o, + aprs->tx_bufsz - o, ",%s", call)) < 0) { goto error; } else { - offset += formatted; + o += formatted; } } - if (aprs->tx_bufsz - offset < frame.infolen + 3) { + if (aprs->tx_bufsz < o + frame.infolen + 3) { errno = EOVERFLOW; goto error; } - aprs->tx_buf[offset++] = ':'; + aprs->tx_buf[o++] = ':'; - memcpy(aprs->tx_buf + offset, frame.info, frame.infolen); + memcpy(aprs->tx_buf + o, frame.info, frame.infolen); - offset += frame.infolen; + o += frame.infolen; - aprs->tx_buf[offset++] = '\r'; - aprs->tx_buf[offset++] = '\n'; + aprs->tx_buf[o++] = '\r'; + aprs->tx_buf[o++] = '\n'; - return write(aprs->fd, aprs->tx_buf, offset); + if (write(aprs->fd, aprs->tx_buf, o) < 0) { + goto error; + } + + return i; error: return -1;