From 387a5b8281f7981b38fd3ff583cc5f80bee5d201 Mon Sep 17 00:00:00 2001 From: Achim Kraus Date: Tue, 24 Jan 2023 20:08:13 +0100 Subject: [PATCH] dtls.c: use GET_VAR_FIELD in dtls_get_cookie. Signed-off-by: Achim Kraus --- dtls.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/dtls.c b/dtls.c index 83b1e489..5f1f4325 100644 --- a/dtls.c +++ b/dtls.c @@ -431,6 +431,7 @@ dtls_write(struct dtls_context_t *ctx, session_t *session, static int dtls_get_cookie(uint8 *msg, size_t msglen, uint8 **cookie) { + size_t cookie_len; /* To access the cookie, we have to determine the session id's * length and skip the whole thing. */ if (msglen < DTLS_HS_LENGTH + DTLS_CH_LENGTH + sizeof(uint8)) @@ -446,11 +447,11 @@ dtls_get_cookie(uint8 *msg, size_t msglen, uint8 **cookie) { SKIP_VAR_FIELD(msg, msglen, uint8, DTLS_ALERT_HANDSHAKE_FAILURE, "get_cookie, session_id"); - if (msglen < (*msg & 0xff) + sizeof(uint8)) - return dtls_alert_fatal_create(DTLS_ALERT_HANDSHAKE_FAILURE); + GET_VAR_FIELD(cookie_len, msg, msglen, uint8, DTLS_ALERT_HANDSHAKE_FAILURE, + "get_cookie, cookie"); - *cookie = msg + sizeof(uint8); - return dtls_uint8_to_int(msg); + *cookie = msg; + return cookie_len; } static int