Skip to contentSkip to conversation

cosa.c : Array index 'i' is used before limits check.

PATCH In review Ameen Ali 3 participants 4 messages Feb 24, 2015 – Mar 2, 2015

Subsystems (2)
lore
Share & tools
lore

Ameen Ali

author
#0 lore raw

PATCH 2/2 cosa.c : Array index 'i' is used before limits check.

avoid out-of-bounds-read by checking count before indexing.

---
 drivers/net/wan/cosa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wan/cosa.c +1 -1
index 83c39e2..5252e21 100644
@@ -376,7 +376,7 @@ static int __init cosa_init(void)
 	}
 	for (i=0; i<MAX_CARDS; i++)
 		cosa_cards[i].num = -1;
-	for (i=0; io[i] != 0 && i < MAX_CARDS; i++)
+	for (i=0; (i < MAX_CARDS) && (io[i] != 0) ; i++)
 		cosa_probe(io[i], irq[i], dma[i]);
 	if (!nr_cards) {
 		pr_warn("no devices found\n");
Signature · 1 line
2.1.0
#1 lore raw

Hello.

Quoted 12 lines · Ameen Ali

avoid out-of-bounds-read by checking count before indexing.

---
  drivers/net/wan/cosa.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wan/cosa.c +0 -0
index 83c39e2..5252e21 100644

drivers/net/wan/cosa.c static int __init cosa_init(void) · line 379

Quoted 5 lines
drivers/net/wan/cosa.c +1 -1
@@ -376,7 +376,7 @@ static int __init cosa_init(void)
  	}
  	for (i=0; i<MAX_CARDS; i++)
  		cosa_cards[i].num = -1;
-	for (i=0; io[i] != 0 && i < MAX_CARDS; i++)
+	for (i=0; (i < MAX_CARDS) && (io[i] != 0) ; i++)

Parens you've added aren't necessary.
I suggest to add spaces after and before = in the first expression.

[...]

WBR, Sergei

#2 lore raw

Sergei Shtylyov wrote:
: Hello.
:
: On 02/24/2015 10:52 PM, Ameen Ali wrote:
:
: >avoid out-of-bounds-read by checking count before indexing. :
: >Signed-off-by: Ameen Ali <[email protected]>
: >---
: > drivers/net/wan/cosa.c | 2 +-
: > 1 file changed, 1 insertion(+), 1 deletion(-)
:
: >diff --git a/drivers/net/wan/cosa.c b/drivers/net/wan/cosa.c : >index 83c39e2..5252e21 100644
: >--- a/drivers/net/wan/cosa.c
: >+++ b/drivers/net/wan/cosa.c
: >@@ -376,7 +376,7 @@ static int __init cosa_init(void)

: >  	}
: >  	for (i=0; i<MAX_CARDS; i++)
: >  		cosa_cards[i].num = -1;

: >- for (i=0; io[i] != 0 && i < MAX_CARDS; i++)
: >+ for (i=0; (i < MAX_CARDS) && (io[i] != 0) ; i++)
:
: Parens you've added aren't necessary.

Yes, but I am OK with both variants.

: I suggest to add spaces after and before = in the first expression.

In that case, also the upper for() cycle should be modified
to match this. I don't think this is necessary.

-Yenya

Signature · 6 lines
| Jan "Yenya" Kasprzak   <kas at {fi.muni.cz - work | yenya.net - private}> |
| New GPG 4096R/A45477D5 -- see http://www.fi.muni.cz/~kas/pgp-rollover.txt |
| http://www.fi.muni.cz/~kas/     Journal: http://www.fi.muni.cz/~kas/blog/ |
||| "New and improved" is only really improved if it also takes backwards |||
||| compatibility into account, rather than saying "now everybody must do |||
||| things the new and improved - and different - way"   --Linus Torvalds |||
#3 lore raw

Hello.

Quoted 15 lines · Jan Kasprzak

: >avoid out-of-bounds-read by checking count before indexing. :
: >Signed-off-by: Ameen Ali <[email protected]>
: >---
: > drivers/net/wan/cosa.c | 2 +-
: > 1 file changed, 1 insertion(+), 1 deletion(-)
:
: >diff --git a/drivers/net/wan/cosa.c b/drivers/net/wan/cosa.c : >index 83c39e2..5252e21 100644
: >--- a/drivers/net/wan/cosa.c
: >+++ b/drivers/net/wan/cosa.c
: >@@ -376,7 +376,7 @@ static int __init cosa_init(void)

: >  	}
: >  	for (i=0; i<MAX_CARDS; i++)
: >  		cosa_cards[i].num = -1;
Quoted 6 lines

: >- for (i=0; io[i] != 0 && i < MAX_CARDS; i++)
: >+ for (i=0; (i < MAX_CARDS) && (io[i] != 0) ; i++)

: Parens you've added aren't necessary.

Yes, but I am OK with both variants.

Anyway, space before ; should be removed (just noticed).

Quoted 4 lines

: I suggest to add spaces after and before = in the first expression.

In that case, also the upper for() cycle should be modified
to match this. I don't think this is necessary.

As long as it doesn't cause complaints from scripts/checkpatch.pl...

Quoted 1 line

-Yenya

WBR, Sergei