Skip to content

Commit

Permalink
net: tls_credentials: Do not free slot when cred buf is NULL
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
joerchan authored and kartben committed Jan 28, 2025
1 parent 3cc9282 commit 8457db5
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion subsys/net/lib/tls_credentials/tls_credentials_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ static int tls_cred_cmd_del(const struct shell *sh, size_t argc, char *argv[])
goto cleanup;
}

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

0 comments on commit 8457db5

Please sign in to comment.