Skip to content

Commit 8457db5

Browse files
joerchankartben
authored andcommitted
net: tls_credentials: Do not free slot when cred buf is NULL
Do not free the slot when cred buf is NULL. If the TLS credential storage backend does not have a buffer pointer to the TLS credential, then the buffer pointer can be NULL. This may happen with an out-of-tree TLS credential storage backend. In this case where credential buffer is NULL find_ref_slot retrieves a new slot, and then tries to free it, causing a crash. Signed-off-by: Joakim Andersson <[email protected]>
1 parent 3cc9282 commit 8457db5

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

subsys/net/lib/tls_credentials/tls_credentials_shell.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ static int tls_cred_cmd_del(const struct shell *sh, size_t argc, char *argv[])
561561
goto cleanup;
562562
}
563563

564-
ref_slot = find_ref_slot(cred->buf);
564+
ref_slot = cred->buf != NULL ? find_ref_slot(cred->buf) : -1;
565565
if (ref_slot >= 0) {
566566
/* This was a credential we copied to heap. Clear and free it. */
567567
memset((void *)cred_buf, 0, cred->len);

0 commit comments

Comments
 (0)