Skip to content

Commit 68a1cda

Browse files
committed
dtls.c: Fixed possible integer underflow in dtls_cookie_create()
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
1 parent 9b46175 commit 68a1cda

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

dtls.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ dtls_create_cookie(dtls_context_t *ctx,
343343
uint8 *msg, size_t msglen,
344344
uint8 *cookie, int *clen) {
345345
unsigned char buf[DTLS_HMAC_MAX];
346-
size_t e;
346+
size_t e, fragment_length;
347347
int len;
348348

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

386+
fragment_length = dtls_get_fragment_length(DTLS_HANDSHAKE_HEADER(msg));
387+
if ((fragment_length < e) || (e + DTLS_HS_LENGTH + fragment_length) > msglen)
388+
return dtls_alert_fatal_create(DTLS_ALERT_HANDSHAKE_FAILURE);
389+
386390
dtls_hmac_update(&hmac_context,
387391
msg + DTLS_HS_LENGTH + e,
388-
dtls_get_fragment_length(DTLS_HANDSHAKE_HEADER(msg)) - e);
392+
fragment_length - e);
389393

390394
len = dtls_hmac_finalize(&hmac_context, buf);
391395

0 commit comments

Comments
 (0)