Skip to content

Commit

Permalink
dtls.c: Fixed possible integer underflow in dtls_cookie_create()
Browse files Browse the repository at this point in the history
The sender-provided fragment_length must be sanity-checked before
using as length parameter for dtls_create_cookie().

Fixes https://bugs.eclipse.org/bugs/show_bug.cgi?id=534333

Change-Id: I7168f408b12739057331c2de7d1d661e829a3f39
  • Loading branch information
obgm committed May 16, 2019
1 parent 9b46175 commit 68a1cda
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions dtls.c
Expand Up @@ -343,7 +343,7 @@ dtls_create_cookie(dtls_context_t *ctx,
uint8 *msg, size_t msglen,
uint8 *cookie, int *clen) {
unsigned char buf[DTLS_HMAC_MAX];
size_t e;
size_t e, fragment_length;
int len;

/* create cookie with HMAC-SHA256 over:
Expand Down Expand Up @@ -383,9 +383,13 @@ dtls_create_cookie(dtls_context_t *ctx,
if (e + DTLS_HS_LENGTH > msglen)
return dtls_alert_fatal_create(DTLS_ALERT_HANDSHAKE_FAILURE);

fragment_length = dtls_get_fragment_length(DTLS_HANDSHAKE_HEADER(msg));
if ((fragment_length < e) || (e + DTLS_HS_LENGTH + fragment_length) > msglen)
return dtls_alert_fatal_create(DTLS_ALERT_HANDSHAKE_FAILURE);

dtls_hmac_update(&hmac_context,
msg + DTLS_HS_LENGTH + e,
dtls_get_fragment_length(DTLS_HANDSHAKE_HEADER(msg)) - e);
fragment_length - e);

len = dtls_hmac_finalize(&hmac_context, buf);

Expand Down

0 comments on commit 68a1cda

Please sign in to comment.