Merge pull request #495 from mrdeep1/identity_len

DTLS: Fix identity length checking
This commit is contained in:
obgm authored and GitHub committed 2020-06-16 11:06:37 +02:00
commit 6e1927f04b
1 file changed
+5 -8
+5 -8
View File
@@ -229,9 +229,10 @@ get_psk_info(struct dtls_context_t *dtls_context,
}
identity_length = 0;
/* result_length is max size of the returned identity */
psk_len = coap_context->get_client_psk(coap_session, (const uint8_t*)id, id_len, (uint8_t*)result, &identity_length, result_length, psk, sizeof(psk));
if (!psk_len) {
coap_log(LOG_WARNING, "no PSK identity for given realm\n");
coap_log(LOG_WARNING, "no PSK identity for given realm or buffer too small\n");
fatal_error = DTLS_ALERT_CLOSE_NOTIFY;
goto error;
}
@@ -242,17 +243,13 @@ get_psk_info(struct dtls_context_t *dtls_context,
if (!coap_context || !coap_context->get_client_psk)
goto error;
identity_length = 0;
psk_len = coap_context->get_client_psk(coap_session, (const uint8_t*)id, id_len, (uint8_t*)result, &identity_length, result_length, psk, sizeof(psk));
/* Use psk[] as a scratch area for returning the unused identity */
psk_len = coap_context->get_client_psk(coap_session, (const uint8_t*)id, id_len, psk, &identity_length, sizeof(psk), result, result_length);
if (!psk_len) {
coap_log(LOG_WARNING, "no pre-shared key for given realm\n");
coap_log(LOG_WARNING, "no pre-shared key for given realm or buffer too small\n");
fatal_error = DTLS_ALERT_CLOSE_NOTIFY;
goto error;
}
if (psk_len > result_length) {
coap_log(LOG_WARNING, "cannot set psk -- buffer too small\n");
goto error;
}
memcpy(result, psk, psk_len);
return (int)psk_len;
}
if (coap_context->get_server_psk) {