2015-10-17 09:43:26

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 0/2] delete null dereference

These patches delete NULL dereferences, as detected by
scripts/coccinelle/null/deref_null.cocci.

---

drivers/media/pci/netup_unidvb/netup_unidvb_spi.c | 6 ++----
net/nfc/netlink.c | 6 ++----
2 files changed, 4 insertions(+), 8 deletions(-)


2015-10-19 12:58:32

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH 1/2] NFC: delete null dereference

The next goto after that is messed up as well:

1056 dev = nfc_get_device(idx);
1057 if (!dev)
1058 return -ENODEV;
1059
1060 device_lock(&dev->dev);
1061
1062 local = nfc_llcp_find_local(dev);
1063 if (!local) {
1064 nfc_put_device(dev);

It should not call nfc_put_device() because that happens after goto
exit.

1065 rc = -ENODEV;
1066 goto exit;
1067 }

regards,
dan carpenter

2015-10-17 09:43:28

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 1/2] NFC: delete null dereference

The exit label performs device_unlock(&dev->dev);, which will fail when dev
is NULL, and nfc_put_device(dev);, which is not useful when dev is NULL, so
just exit the function immediately.

Problem found using scripts/coccinelle/null/deref_null.cocci

Signed-off-by: Julia Lawall <[email protected]>

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

diff --git a/net/nfc/netlink.c b/net/nfc/netlink.c
index 853172c..f040532 100644
--- a/net/nfc/netlink.c
+++ b/net/nfc/netlink.c
@@ -1109,10 +1109,8 @@ static int nfc_genl_llc_sdreq(struct sk_buff *skb, struct genl_info *info)
idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);

dev = nfc_get_device(idx);
- if (!dev) {
- rc = -ENODEV;
- goto exit;
- }
+ if (!dev)
+ return -ENODEV;

device_lock(&dev->dev);



2015-10-20 04:51:04

by Samuel Ortiz

[permalink] [raw]
Subject: Re: [PATCH 1/2] NFC: delete null dereference

Hi Julia,

On Sat, Oct 17, 2015 at 11:32:19AM +0200, Julia Lawall wrote:
> The exit label performs device_unlock(&dev->dev);, which will fail when dev
> is NULL, and nfc_put_device(dev);, which is not useful when dev is NULL, so
> just exit the function immediately.
>
> Problem found using scripts/coccinelle/null/deref_null.cocci
>
> Signed-off-by: Julia Lawall <[email protected]>
>
> ---
> net/nfc/netlink.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
Applied to nfc-next, thanks.

Cheers,
Samuel.