mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH][isapnp] Fix a potential NULL pointer dereference in isapnp_read_tag()
@ 2007-06-30 23:38 Jesper Juhl
  2007-07-03 20:03 ` Andrew Morton
  0 siblings, 1 reply; 4+ messages in thread
From: Jesper Juhl @ 2007-06-30 23:38 UTC (permalink / raw)
  To: Linux Kernel Mailing List; +Cc: Jaroslav Kysela, Jesper Juhl

The Coverity checker spotted (as bug #809) that we dereference 'type' 
long before we actually test it against NULL in 
drivers/pnp/isapnp/core.c::isapnp_read_tag() - both branches of the 
'if (tag & 0x80)' dereference type, and since this 'if' is before the test 
against NULL and the return of -1, this will blow up is ever type is NULL.
This is easy to fix by simply moving the NULL test to the beginning of 
the function.


Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com>
---

 drivers/pnp/isapnp/core.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/Documentation/00-INDEX b/Documentation/00-INDEX
diff --git a/drivers/pnp/isapnp/core.c b/drivers/pnp/isapnp/core.c
index a0b1587..5696924 100644
--- a/drivers/pnp/isapnp/core.c
+++ b/drivers/pnp/isapnp/core.c
@@ -356,6 +356,8 @@ static int __init isapnp_read_tag(unsigned char *type, unsigned short *size)
 {
 	unsigned char tag, tmp[2];
 
+	if (!type)	/* wrong type */
+		return -1;
 	isapnp_peek(&tag, 1);
 	if (tag == 0)				/* invalid tag */
 		return -1;
@@ -370,8 +372,6 @@ static int __init isapnp_read_tag(unsigned char *type, unsigned short *size)
 #if 0
 	printk(KERN_DEBUG "tag = 0x%x, type = 0x%x, size = %i\n", tag, *type, *size);
 #endif
-	if (type == 0)				/* wrong type */
-		return -1;
 	if (*type == 0xff && *size == 0xffff)	/* probably invalid data */
 		return -1;
 	return 0;



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-07-04 22:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-30 23:38 [PATCH][isapnp] Fix a potential NULL pointer dereference in isapnp_read_tag() Jesper Juhl
2007-07-03 20:03 ` Andrew Morton
2007-07-04  1:04   ` Jesper Juhl
2007-07-04 22:59     ` [PATCH][isapnp] Remove pointless check of 'type' against 0 " Jesper Juhl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome