diff --git a/include/zephyr/net/tls_credentials.h b/include/zephyr/net/tls_credentials.h index 6477543f4042012..2804df061018e1d 100644 --- a/include/zephyr/net/tls_credentials.h +++ b/include/zephyr/net/tls_credentials.h @@ -107,6 +107,7 @@ int tls_credential_add(sec_tag_t tag, enum tls_credential_type type, * @retval -EACCES Access to the TLS credential subsystem was denied. * @retval -ENOENT Requested TLS credential was not found. * @retval -EFBIG Requested TLS credential does not fit in the buffer provided. + * Check *credlen for size required. */ int tls_credential_get(sec_tag_t tag, enum tls_credential_type type, void *cred, size_t *credlen); diff --git a/subsys/net/lib/tls_credentials/tls_credentials.c b/subsys/net/lib/tls_credentials/tls_credentials.c index 94f4d9c5cd5a90a..2e8ee255109f831 100644 --- a/subsys/net/lib/tls_credentials/tls_credentials.c +++ b/subsys/net/lib/tls_credentials/tls_credentials.c @@ -158,11 +158,13 @@ int tls_credential_get(sec_tag_t tag, enum tls_credential_type type, credential = credential_get(tag, type); if (credential == NULL) { ret = -ENOENT; + *credlen = 0; goto exit; } if (credential->len > *credlen) { ret = -EFBIG; + *credlen = credential->len; goto exit; }