Skip to contentSkip to conversation

NFC: add NULL checks to avoid potential NULL pointer dereference

PATCH Applied Gustavo A. R. Silva 2 participants 2 messages May 30, 2017 – Jun 22, 2017 NFC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 NFC: add NULL checks to avoid potential NULL pointer dereference

NULL checks at line 457: if (!link0 || !link1) {, implies that both pointers link0 and link1 might be NULL.
Function nfcsim_link_free() dereference pointers link0 and link1. Add NULL checks before calling nfcsim_link_free() to avoid a potential NULL pointer dereference.

Addresses-Coverity-ID: 1364857

---
 drivers/nfc/nfcsim.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/nfc/nfcsim.c +4 -2
index a466e79..6e90b54 100644
@@ -482,8 +482,10 @@ static int __init nfcsim_init(void)
 exit_err:
 	pr_err("Failed to initialize nfcsim driver (%d)\n", rc);
 
-	nfcsim_link_free(link0);
-	nfcsim_link_free(link1);
+	if (link0)
+		nfcsim_link_free(link0);
+	if (link1)
+		nfcsim_link_free(link1);
 
 	return rc;
 }
Signature · 1 line
2.5.0
Applied
#1 lore raw
Quoted 11 lines · Gustavo A. R. Silva

NULL checks at line 457: if (!link0 || !link1) {, implies that both pointers link0 and link1 might be NULL.
Function nfcsim_link_free() dereference pointers link0 and link1. Add NULL checks before calling nfcsim_link_free() to avoid a potential NULL pointer dereference.

Addresses-Coverity-ID: 1364857

---
 drivers/nfc/nfcsim.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Applied, thanks.

Cheers,
Samuel.