Skip to content

Commit 482ee78

Browse files
committed
net: lib: tls_credentials: return size required
If either no buffer is provided or the size of it is too small, return the required length. Signed-off-by: Pete Skeggs <[email protected]>
1 parent ea7e265 commit 482ee78

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

include/zephyr/net/tls_credentials.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ int tls_credential_add(sec_tag_t tag, enum tls_credential_type type,
107107
* @retval -EACCES Access to the TLS credential subsystem was denied.
108108
* @retval -ENOENT Requested TLS credential was not found.
109109
* @retval -EFBIG Requested TLS credential does not fit in the buffer provided.
110+
* Check *credlen for size required.
110111
*/
111112
int tls_credential_get(sec_tag_t tag, enum tls_credential_type type,
112113
void *cred, size_t *credlen);

subsys/net/lib/tls_credentials/tls_credentials.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,13 @@ int tls_credential_get(sec_tag_t tag, enum tls_credential_type type,
158158
credential = credential_get(tag, type);
159159
if (credential == NULL) {
160160
ret = -ENOENT;
161+
*credlen = 0;
161162
goto exit;
162163
}
163164

164165
if (credential->len > *credlen) {
165166
ret = -EFBIG;
167+
*credlen = credential->len;
166168
goto exit;
167169
}
168170

0 commit comments

Comments
 (0)