From 3a7202306c6aca5be2dad604f62063d605fd0982 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Mon, 6 May 2019 17:55:36 +0200 Subject: EDI: Handle sequence counter check for incomplete AF packets --- lib/edi/ETIDecoder.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/edi/ETIDecoder.cpp b/lib/edi/ETIDecoder.cpp index ffc17a4..a5d817e 100644 --- a/lib/edi/ETIDecoder.cpp +++ b/lib/edi/ETIDecoder.cpp @@ -156,8 +156,14 @@ ETIDecoder::decode_state_t ETIDecoder::decode_afpacket( // read length from packet uint32_t taglength = read_32b(input_data.begin() + 2); uint16_t seq = read_16b(input_data.begin() + 6); + + const size_t crclength = 2; + if (input_data.size() < AFPACKET_HEADER_LEN + taglength + crclength) { + return {false, 0}; + } + if (m_last_seq + 1 != seq) { - etiLog.level(warn) << "EDI AF Packet sequence error"; + etiLog.level(warn) << "EDI AF Packet sequence error, " << seq; } m_last_seq = seq; @@ -174,10 +180,6 @@ ETIDecoder::decode_state_t ETIDecoder::decode_afpacket( return {false, 0}; } - const size_t crclength = 2; - if (input_data.size() < AFPACKET_HEADER_LEN + taglength + crclength) { - return {false, 0}; - } if (not has_crc) { throw invalid_argument("AF packet not supported, has no CRC"); -- cgit v1.2.3