int ssl_check_serverhello_tlsext(SSL *s);
#endif
+#define CHECKLEN(curr, val, limit) \
+ (((curr) >= (limit)) || (size_t)((limit) - (curr)) < (size_t)(val))
+
SSL3_ENC_METHOD TLSv1_enc_data = {
tls1_enc,
tls1_mac,
* + hostname length
*/
size_str = strlen(s->tlsext_hostname);
- if (ret >= limit || (size_t)(limit - ret) < 9 + size_str)
+ if (CHECKLEN(ret, 9 + size_str, limit))
return NULL;
/* extension type and length */
* 1 for the srp user identity
* + srp user identity length
*/
- if (ret >= limit || (size_t)(limit - ret) < 5 + login_len)
+ if (CHECKLEN(ret, 5 + login_len, limit))
return NULL;
/* fill in the extension */
* 1 byte for the length of the formats
* + formats length
*/
- if (ret >= limit || (size_t)(limit - ret) < 5 + num_formats)
+ if (CHECKLEN(ret, 5 + num_formats, limit))
return NULL;
s2n(TLSEXT_TYPE_ec_point_formats, ret);
* 2 bytes for the curve list length
* + curve list length
*/
- if (ret >= limit || (size_t)(limit - ret) < 6 + curves_list_len)
+ if (CHECKLEN(ret, 6 + curves_list_len, limit))
return NULL;
s2n(TLSEXT_TYPE_elliptic_curves, ret);
* Check for enough room 2 for extension type, 2 for len rest for
* ticket
*/
- if (ret >= limit || (size_t)(limit - ret) < 4 + ticklen)
+ if (CHECKLEN(ret, 4 + ticklen, limit))
return NULL;
s2n(TLSEXT_TYPE_session_ticket, ret);
s2n(ticklen, ret);
* 2 bytes for the sigalg list length
* + sigalg list length
*/
- if (ret >= limit || (size_t)(limit - ret) < salglen + 6)
+ if (CHECKLEN(ret, salglen + 6, limit))
return NULL;
s2n(TLSEXT_TYPE_signature_algorithms, ret);
s2n(salglen + 2, ret);
* 1 byte for OCSP request type
* 2 bytes for length of ids
* 2 bytes for length of extensions
+ * + length of ids
+ * + length of extensions
*/
- if (ret >= limit || (size_t)(limit - ret) < 9 + idlen + extlen)
+ if (CHECKLEN(ret, 9 + idlen + extlen, limit))
return NULL;
s2n(TLSEXT_TYPE_status_request, ret);
* 4 bytes for the heartbeat ext type and extension length
* 1 byte for the mode
*/
- if (ret >= limit || limit - ret < 5)
+ if (CHECKLEN(ret, 5, limit))
return NULL;
s2n(TLSEXT_TYPE_heartbeat, ret);
* check for enough space.
* 4 bytes for the NPN ext type and extension length
*/
- if (ret >= limit || limit - ret < 4)
+ if (CHECKLEN(ret, 4, limit))
return NULL;
s2n(TLSEXT_TYPE_next_proto_neg, ret);
s2n(0, ret);
* 2 bytes for the ALPN protocol list length
* + ALPN protocol list length
*/
- if (ret >= limit || limit - ret < 6 + s->alpn_client_proto_list_len)
+ if (CHECKLEN(ret, 6 + s->alpn_client_proto_list_len, limit))
return NULL;
s2n(TLSEXT_TYPE_application_layer_protocol_negotiation, ret);
s2n(2 + s->alpn_client_proto_list_len, ret);
* 4 bytes for the SRTP type and extension length
* + SRTP profiles length
*/
- if (ret >= limit || limit - ret < 4 + el)
+ if (CHECKLEN(ret, 4 + el, limit))
return NULL;
s2n(TLSEXT_TYPE_use_srtp, ret);
* 4 bytes for the padding type and extension length
* + padding length
*/
- if (ret >= limit || limit - ret < 4 + hlen)
+ if (CHECKLEN(ret, 4 + hlen, limit))
return NULL;
s2n(TLSEXT_TYPE_padding, ret);
s2n(hlen, ret);
* 4 bytes for the reneg type and extension length
* + reneg data length
*/
- if (ret >= limit || limit - ret < 4 + el)
+ if (CHECKLEN(ret, 4 + el, limit))
return NULL;
s2n(TLSEXT_TYPE_renegotiate, ret);
* 1 byte for the points format list length
* + length of points format list
*/
- if (ret >= limit || (size_t)(limit - ret) < 5 + plistlen)
+ if (CHECKLEN(ret, 5 + plistlen, limit))
return NULL;
s2n(TLSEXT_TYPE_ec_point_formats, ret);
* check for enough space.
* 4 bytes for the Ticket type and extension length
*/
- if (ret >= limit || limit - ret < 4)
+ if (CHECKLEN(ret, 4, limit))
return NULL;
s2n(TLSEXT_TYPE_session_ticket, ret);
s2n(0, ret);
* check for enough space.
* 4 bytes for the Status request type and extension length
*/
- if (ret >= limit || limit - ret < 4)
+ if (CHECKLEN(ret, 4, limit))
return NULL;
s2n(TLSEXT_TYPE_status_request, ret);
s2n(0, ret);
* 4 bytes for the SRTP profiles type and extension length
* + length of the SRTP profiles list
*/
- if (ret >= limit || limit - ret < 4 + el)
+ if (CHECKLEN(ret, 4 + el, limit))
return NULL;
s2n(TLSEXT_TYPE_use_srtp, ret);
};
/* check for enough space. */
- if (ret >= limit || (size_t)(limit - ret) < sizeof(cryptopro_ext))
+ if (CHECKLEN(ret, sizeof(cryptopro_ext), limit))
return NULL;
memcpy(ret, cryptopro_ext, sizeof(cryptopro_ext));
ret += sizeof(cryptopro_ext);
* 4 bytes for the Heartbeat type and extension length
* 1 byte for the mode
*/
- if (ret >= limit || limit - ret < 5)
+ if (CHECKLEN(ret, 5, limit))
return NULL;
s2n(TLSEXT_TYPE_heartbeat, ret);
s2n(1, ret);
* 4 bytes for the NPN type and extension length
* + length of protocols list
*/
- if (ret >= limit || limit - ret < 4 + npalen)
+ if (CHECKLEN(ret, 4 + npalen, limit))
return NULL;
s2n(TLSEXT_TYPE_next_proto_neg, ret);
s2n(npalen, ret);
* 1 byte for selected protocol length
* + length of the selected protocol
*/
- if (ret >= limit || (size_t)(limit - ret) < 7 + len)
+ if (CHECKLEN(ret, 7 + len, limit))
return NULL;
s2n(TLSEXT_TYPE_application_layer_protocol_negotiation, ret);
s2n(3 + len, ret);