From b281ceee7b240242dcfea8e82428729303a37e62 Mon Sep 17 00:00:00 2001 From: Matthias Wirth Date: Mon, 8 Apr 2019 20:03:57 +0200 Subject: [PATCH 1/2] Increase maximum TSV packet size Due to commit 45886edc4014f6808ad5c44f198dceabbf240b5d faup1090: write _v on every line, bump TSV_VERSION and maybe other changes the TSV packets are bigger and some users have reported the following error: piaware[9040]: faup1090(27427): fatsv: output too large (max 600, overran by 20) Fix this error by increasing TSV_MAX_PACKET_SIZE to 800 --- net_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net_io.c b/net_io.c index 2d8c0b8..a24bfc1 100644 --- a/net_io.c +++ b/net_io.c @@ -1878,7 +1878,7 @@ __attribute__ ((format (printf,4,5))) static char *appendFATSV(char *p, char *en return p; } -#define TSV_MAX_PACKET_SIZE 600 +#define TSV_MAX_PACKET_SIZE 800 #define TSV_VERSION "4E" static void writeFATSVPositionUpdate(float lat, float lon, float alt) From 82c5ff67243cf32c9761c821afcc54c37987d0d0 Mon Sep 17 00:00:00 2001 From: Matthias Wirth Date: Mon, 8 Apr 2019 20:29:56 +0200 Subject: [PATCH 2/2] Fix possible missing \n termination of TSV messages If the \n termination of TSV messages is missing, faup1090 encounters the following error: Caught background error: list must have an even number of elements while executing "array set row [split $line "\t"]" (object "::faup1090" method "::FaupConnection::data_available" body line 28) This missing termination with \n can happen when p == end is true in the overrun check. vsnprintf will always terminate the string with \0, so if the vsnprintf is called to write the to the last position in the buffer (end-1), it will write \0 instead to terminate the string as not to overflow the buffer. To catch that possibility the overrun check is changed to p < end as then vsnprintf is assured to have had enough room to write the \0 termination to end-1. --- net_io.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/net_io.c b/net_io.c index a24bfc1..f98b7c4 100644 --- a/net_io.c +++ b/net_io.c @@ -1550,7 +1550,7 @@ char *generateStatsJson(const char *url_path, int *len) { p = appendStatsJson(p, end, &add, "total"); p = safe_snprintf(p, end, "\n}\n"); - assert(p <= end); + assert(p < end); *len = p-buf; return buf; @@ -1908,7 +1908,7 @@ static void writeFATSVPositionUpdate(float lat, float lon, float alt) --p; // remove last tab p = safe_snprintf(p, end, "\n"); - if (p <= end) + if (p < end) completeWrite(&Modes.fatsv_out, p); else fprintf(stderr, "fatsv: output too large (max %d, overran by %d)\n", TSV_MAX_PACKET_SIZE, (int) (p - end)); @@ -1935,7 +1935,7 @@ static void writeFATSVEventMessage(struct modesMessage *mm, const char *datafiel } p = safe_snprintf(p, end, "\n"); - if (p <= end) + if (p < end) completeWrite(&Modes.fatsv_out, p); else fprintf(stderr, "fatsv: output too large (max %d, overran by %d)\n", TSV_MAX_PACKET_SIZE, (int) (p - end)); @@ -2256,7 +2256,7 @@ static void writeFATSV() --p; // remove last tab p = safe_snprintf(p, end, "\n"); - if (p <= end) + if (p < end) completeWrite(&Modes.fatsv_out, p); else fprintf(stderr, "fatsv: output too large (max %d, overran by %d)\n", TSV_MAX_PACKET_SIZE, (int) (p - end));