Skip to content

Commit 42a303b

Browse files
committed
Fix length underflow in dummy_ticket_parse
Signed-off-by: Nim Dorji Subba <nimdorjisubba2003@gmail.com>
1 parent 9e9eb06 commit 42a303b

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

programs/ssl/ssl_server2.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,58 +1385,70 @@ static int dummy_ticket_parse(void *p_ticket, mbedtls_ssl_session *session,
13851385
int ret;
13861386
((void) p_ticket);
13871387

1388+
if (len < 4) {
1389+
return MBEDTLS_ERR_SSL_BAD_INPUT_DATA;
1390+
}
1391+
13881392
if ((ret = mbedtls_ssl_session_load(session, buf + 4, len - 4)) != 0) {
13891393
return ret;
13901394
}
13911395

13921396
switch (opt.dummy_ticket % 11) {
13931397
case 1:
13941398
return MBEDTLS_ERR_SSL_INVALID_MAC;
1399+
13951400
case 2:
13961401
return MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED;
1402+
13971403
case 3:
13981404
/* Creation time in the future. */
13991405
session->ticket_creation_time = mbedtls_ms_time() + 1000;
14001406
break;
1407+
14011408
case 4:
14021409
/* Ticket has reached the end of lifetime. */
14031410
session->ticket_creation_time = mbedtls_ms_time() -
14041411
(7 * 24 * 3600 * 1000 + 1000);
14051412
break;
1413+
14061414
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
14071415
case 5:
14081416
/* Ticket is valid, but client age is below the lower bound of the tolerance window. */
1409-
session->ticket_age_add += MBEDTLS_SSL_TLS1_3_TICKET_AGE_TOLERANCE + 4 * 1000;
1410-
/* Make sure the execution time does not affect the result */
1417+
session->ticket_age_add += MBEDTLS_SSL_TLS1_3_TICKET_AGE_TOLERANCE +
1418+
4 * 1000;
14111419
session->ticket_creation_time = mbedtls_ms_time();
14121420
break;
14131421

14141422
case 6:
14151423
/* Ticket is valid, but client age is beyond the upper bound of the tolerance window. */
1416-
session->ticket_age_add -= MBEDTLS_SSL_TLS1_3_TICKET_AGE_TOLERANCE + 4 * 1000;
1417-
/* Make sure the execution time does not affect the result */
1424+
session->ticket_age_add -= MBEDTLS_SSL_TLS1_3_TICKET_AGE_TOLERANCE +
1425+
4 * 1000;
14181426
session->ticket_creation_time = mbedtls_ms_time();
14191427
break;
1428+
14201429
case 7:
14211430
session->ticket_flags = MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_NONE;
14221431
break;
1432+
14231433
case 8:
14241434
session->ticket_flags = MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK;
14251435
break;
1436+
14261437
case 9:
14271438
session->ticket_flags = MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL;
14281439
break;
1440+
14291441
case 10:
14301442
session->ticket_flags = MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ALL;
14311443
break;
14321444
#endif
1445+
14331446
default:
14341447
break;
14351448
}
14361449

14371450
return ret;
14381451
}
1439-
#endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_TICKET_C && MBEDTLS_HAVE_TIME */
14401452

14411453
static int parse_cipher(char *buf)
14421454
{

0 commit comments

Comments
 (0)