Skip to content

Commit

Permalink
Add some packet sanity checks
Browse files Browse the repository at this point in the history
  • Loading branch information
fsphil committed Jul 4, 2018
1 parent 3310c6f commit 035f920
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions ssdv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,13 @@ char ssdv_dec_feed(ssdv_t *s, uint8_t *packet)
/* Is this not the packet we expected? */
if(packet_id != s->packet_id)
{
if(packet_id < s->packet_id)
{
/* The decoder can only accept packets in the correct order */
fprintf(stderr, "Packets are not in order. %i > %i\n", s->packet_id - 1, packet_id);
return(SSDV_FEED_ME);
}

/* One or more packets have been lost! */
fprintf(stderr, "Gap detected between packets %i and %i\n", s->packet_id - 1, packet_id);

Expand Down Expand Up @@ -1343,6 +1350,13 @@ char ssdv_dec_feed(ssdv_t *s, uint8_t *packet)
/* The first MCU in a packet is byte aligned,
* any old bits should be dropped. */
s->workbits = s->worklen = 0;

/* Abandon the packet if the MCU index is not what it should be. */
if(s->mcu_id != s->packet_mcu_id)
{
fprintf(stderr, "Unexpected MCU ID in packet %d.\n", packet_id);
return(SSDV_FEED_ME);
}
}

b = packet[SSDV_PKT_SIZE_HEADER + i];
Expand Down

0 comments on commit 035f920

Please sign in to comment.