Check length before reading handshake header
diff --git a/include/polarssl/ssl.h b/include/polarssl/ssl.h
index 0b5f912..1cfb606 100644
--- a/include/polarssl/ssl.h
+++ b/include/polarssl/ssl.h
@@ -784,7 +784,8 @@
(equal to in_left if none) */
#endif
- size_t in_hslen; /*!< current handshake message length */
+ size_t in_hslen; /*!< current handshake message length,
+ including the handshake header */
int nb_zero; /*!< # of 0-length encrypted messages */
int record_read; /*!< record is already present */
@@ -1948,6 +1949,17 @@
return( 5 );
}
+static inline size_t ssl_hs_hdr_len( const ssl_context *ssl )
+{
+#if defined(POLARSSL_SSL_PROTO_DTLS)
+ if( ssl->transport == SSL_TRANSPORT_DATAGRAM )
+ return( 12 );
+#else
+ ((void) ssl);
+#endif
+ return( 4 );
+}
+
/* constant-time buffer comparison */
static inline int safer_memcmp( const void *a, const void *b, size_t n )
{