diff mbox series

[v1,1/1] drivers: isdn: NULL pointer dereference [null-pointer-deref] (CWE 476) problem

Message ID 20180215202700.48177-2-joe.moriarty@oracle.com
State Rejected, archived
Delegated to: David Miller
Headers show
Series Parfait changes | expand

Commit Message

Joe Moriarty Feb. 15, 2018, 8:27 p.m. UTC
The Parfait (version 2.1.0) static code analysis tool found the
following NULL pointer dereference problem.

- drivers/isdn/mISDN/core.c
function channelmap_show() does not check the returned mdev
variable from dev_to_mISDN() for NULL.  Added the check for
NULL, which results in a value of 0 being returned.

Signed-off-by: Joe Moriarty <joe.moriarty@oracle.com>
Reviewed-by: Jonathan Helman <jonathan.helman@oracle.com>
---
 drivers/isdn/mISDN/core.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

David Miller Feb. 16, 2018, 9:11 p.m. UTC | #1
From: Joe Moriarty <joe.moriarty@oracle.com>
Date: Thu, 15 Feb 2018 15:27:00 -0500

> The Parfait (version 2.1.0) static code analysis tool found the
> following NULL pointer dereference problem.
> 
> - drivers/isdn/mISDN/core.c
> function channelmap_show() does not check the returned mdev
> variable from dev_to_mISDN() for NULL.  Added the check for
> NULL, which results in a value of 0 being returned.
> 
> Signed-off-by: Joe Moriarty <joe.moriarty@oracle.com>
> Reviewed-by: Jonathan Helman <jonathan.helman@oracle.com>

Since the lifetime for the sysfs files for these devices is strictly
smaller than the lifetime of the 'dev' object and it's driver data,
it is not possible for mdev to be NULL in this situation.

I understand what the static checker is trying to do, but within
context this lack of a NULL check is legitimate.

I'm not applying this, sorry.
Joe Moriarty Feb. 20, 2018, 1:47 p.m. UTC | #2
On 2/16/2018 4:11 PM, David Miller wrote:
> From: Joe Moriarty <joe.moriarty@oracle.com>
> Date: Thu, 15 Feb 2018 15:27:00 -0500
> 
>> The Parfait (version 2.1.0) static code analysis tool found the
>> following NULL pointer dereference problem.
>>
>> - drivers/isdn/mISDN/core.c
>> function channelmap_show() does not check the returned mdev
>> variable from dev_to_mISDN() for NULL.  Added the check for
>> NULL, which results in a value of 0 being returned.
>>
>> Signed-off-by: Joe Moriarty <joe.moriarty@oracle.com>
>> Reviewed-by: Jonathan Helman <jonathan.helman@oracle.com>
> 
> Since the lifetime for the sysfs files for these devices is strictly
> smaller than the lifetime of the 'dev' object and it's driver data,
> it is not possible for mdev to be NULL in this situation.
> 
> I understand what the static checker is trying to do, but within
> context this lack of a NULL check is legitimate.
> 
> I'm not applying this, sorry.
> 
Thanks for the review David and there is no reason to be sorry.  I'll 
will mark this as a false positive result from our static checker.
diff mbox series

Patch

diff --git a/drivers/isdn/mISDN/core.c b/drivers/isdn/mISDN/core.c
index faf505462a4f..aec7e2706109 100644
--- a/drivers/isdn/mISDN/core.c
+++ b/drivers/isdn/mISDN/core.c
@@ -129,8 +129,10 @@  static ssize_t channelmap_show(struct device *dev,
 	char *bp = buf;
 	int i;
 
-	for (i = 0; i <= mdev->nrbchan; i++)
-		*bp++ = test_channelmap(i, mdev->channelmap) ? '1' : '0';
+	if (mdev)
+		for (i = 0; i <= mdev->nrbchan; i++)
+			*bp++ = test_channelmap(i, mdev->channelmap) ?
+				'1' : '0';
 
 	return bp - buf;
 }