From 9e179d46bf954c93ba0b23922d40457e57d01325 Mon Sep 17 00:00:00 2001 From: Oliver Jowett Date: Wed, 14 Sep 2016 16:11:31 +0100 Subject: [PATCH] Don't accept all-zeros messages (e.g. off the network - the demodulator doesn't accept them already) --- mode_s.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mode_s.c b/mode_s.c index 94ec7af..c28fce4 100644 --- a/mode_s.c +++ b/mode_s.c @@ -307,12 +307,12 @@ static inline __attribute__((always_inline)) unsigned getbits(unsigned char *da // -1: message might be valid, but we couldn't validate the CRC against a known ICAO // -2: bad message or unrepairable CRC error +static unsigned char all_zeros[14] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int scoreModesMessage(unsigned char *msg, int validbits) { int msgtype, msgbits, crc, iid; uint32_t addr; struct errorinfo *ei; - static unsigned char all_zeros[14] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; if (validbits < 56) return -2; @@ -434,6 +434,10 @@ int decodeModesMessage(struct modesMessage *mm, unsigned char *msg) } msg = mm->msg; + // don't accept all-zeros messages + if (!memcmp(all_zeros, msg, 7)) + return -2; + // Get the message type ASAP as other operations depend on this mm->msgtype = getbits(msg, 1, 5); // Downlink Format mm->msgbits = modesMessageLenByType(mm->msgtype);