From 8c13702598714290ca65957e7c1460d246918f66 Mon Sep 17 00:00:00 2001 From: Mikael Nousiainen Date: Fri, 18 Feb 2022 10:38:43 +0200 Subject: [PATCH] Fix APRS call sign padding and reading past end of source buffer --- src/codecs/ax25/ax25.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/codecs/ax25/ax25.c b/src/codecs/ax25/ax25.c index 918db2f..d9ba168 100644 --- a/src/codecs/ax25/ax25.c +++ b/src/codecs/ax25/ax25.c @@ -81,12 +81,14 @@ uint16_t ax25_encode_packet_aprs(char *source, uint8_t source_ssid, char *destin header->flag = AX25_PACKET_FLAG; + size_t call_length = strlen(source); memset(header->source, ' ', sizeof(header->source)); - memcpy(header->source, source, 6); + memcpy(header->source, source, call_length < 6 ? call_length : 6); header->source_ssid = (uint8_t) (source_ssid >= 'A' ? source_ssid - 7 : source_ssid);; + call_length = strlen(destination); memset(header->destination, ' ', sizeof(header->destination)); - memcpy(header->destination, destination, 6); + memcpy(header->destination, destination, call_length < 6 ? call_length : 6); header->destination_ssid = destination_ssid; char *digipeater_addresses_start = ((char *) header) + 1 + 14;