net.c: fix possible derefence after null errors

Fix possible null pointer dereference in coap_get_context_server_hint()
and coap_get_context_server_psk().

These issues have been detected by Coverity scan as CIDs 1495725 and
1495729.
This commit is contained in:
Olaf Bergmann committed 2020-06-19 15:09:35 +02:00
1 parent 04958a1069
commit e0cc7ebf32
1 file changed
+8 -2
+8 -2
View File
@@ -330,7 +330,10 @@ coap_get_context_server_psk(
(void)identity;
(void)identity_len;
if (session && session->psk_key &&
if (!session)
return 0;
if (session->psk_key &&
session->psk_key->length <= max_psk_len) {
memcpy(psk, session->psk_key->s, session->psk_key->length);
return session->psk_key->length;
@@ -352,7 +355,10 @@ coap_get_context_server_hint(
) {
const coap_dtls_spsk_info_t *psk_info;
if (session && session->psk_hint &&
if (!session)
return 0;
if (session->psk_hint &&
session->psk_hint->s && session->psk_hint->length > 0 &&
session->psk_hint->length <= max_hint_len) {
memcpy(hint, session->psk_hint->s, session->psk_hint->length);