From: Guus Sliepen Date: Sat, 9 Aug 2014 09:56:59 +0000 (+0200) Subject: Fix packet length check in sptps_receive_data_datagram(). X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=4f58bbcc171f8566b190fce9b1817a0f62fb94d2;p=meshlink Fix packet length check in sptps_receive_data_datagram(). --- diff --git a/src/sptps.c b/src/sptps.c index 99a3cea9..49e0a336 100644 --- a/src/sptps.c +++ b/src/sptps.c @@ -371,12 +371,12 @@ static bool receive_handshake(sptps_t *s, const char *data, uint16_t len) { // Check datagram for valid HMAC bool sptps_verify_datagram(sptps_t *s, const void *data, size_t len) { - if(len < 21) - return error(s, EIO, "Received short packet in sptps_verify_datagram"); - if (!s->instate) return error(s, EIO, "SPTPS state not ready to verify this datagram"); + if(len < 21) + return error(s, EIO, "Received short packet in sptps_verify_datagram"); + uint32_t seqno; memcpy(&seqno, data, 4); seqno = ntohl(seqno); @@ -391,12 +391,9 @@ bool sptps_verify_datagram(sptps_t *s, const void *data, size_t len) { static bool sptps_receive_data_datagram(sptps_t *s, const void *vdata, size_t len) { const char *data = vdata; - if(len < 21) + if(len < (s->instate ? 21 : 5)) return error(s, EIO, "Received short packet in sptps_receive_data_datagram"); - if (!s->instate) - return error(s, EIO, "SPTPS state not ready to verify this datagram"); - uint32_t seqno; memcpy(&seqno, data, 4); seqno = ntohl(seqno);