X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fsptps.c;h=2e9ac6fe63331917c320805fdac592fea91753f7;hb=e4e5a81447142da0fb1291b2d2119ed6981b89e5;hp=99a3cea9fca47049bd070f6f3e0c0cc1f0452174;hpb=43ed5b9a5d739c50317d5d24898de07526a9297f;p=meshlink diff --git a/src/sptps.c b/src/sptps.c index 99a3cea9..2e9ac6fe 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); @@ -568,6 +565,9 @@ bool sptps_receive_data(sptps_t *s, const void *data, size_t len) { // Start a SPTPS session. bool sptps_start(sptps_t *s, void *handle, bool initiator, bool datagram, ecdsa_t *mykey, ecdsa_t *hiskey, const char *label, size_t labellen, send_data_t send_data, receive_record_t receive_record) { + if(!s || !mykey || !hiskey || !label || !labellen || !send_data || !receive_record) + return error(s, EINVAL, "Invalid argument to sptps_start()"); + // Initialise struct sptps memset(s, 0, sizeof *s);