From: Saverio Proto Date: Fri, 8 Aug 2014 11:46:18 +0000 (+0000) Subject: sptps: split error conditions handling X-Git-Url: http://git.meshlink.io/?p=meshlink;a=commitdiff_plain;h=74e7603bcf698316d72e1bfab6ce80fdea8b2258 sptps: split error conditions handling --- diff --git a/src/sptps.c b/src/sptps.c index 917b1e20..99a3cea9 100644 --- a/src/sptps.c +++ b/src/sptps.c @@ -371,8 +371,11 @@ 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(!s->instate || len < 21) - return error(s, EIO, "Received short packet"); + 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"); uint32_t seqno; memcpy(&seqno, data, 4); @@ -388,8 +391,11 @@ 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 < (s->instate ? 21 : 5)) - return error(s, EIO, "Received short packet"); + if(len < 21) + 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);