Skip to contentSkip to conversation

fealnx: Write outside array bounds

PATCH Applied Roel Kluin 3 participants 4 messages Jul 24, 2009 – Jul 27, 2009

Subsystems (2)
lore
Share & tools
lore

Roel Kluin

author
#0 lore raw

PATCH 1/1 fealnx: Write outside array bounds

phy_idx is checked to be < 4, but np->phys[] is 2 elements long

---
Or should the number of elements be increased?

drivers/net/fealnx.c +1 -1
index 48385c4..100badd 100644
@@ -584,7 +584,7 @@ static int __devinit fealnx_init_one(struct pci_dev *pdev,
 	if (np->flags == HAS_MII_XCVR) {
 		int phy, phy_idx = 0;
 
-		for (phy = 1; phy < 32 && phy_idx < 4; phy++) {
+		for (phy = 1; phy < 32 && phy_idx < 2; phy++) {
 			int mii_status = mdio_read(dev, phy, 1);
 
 			if (mii_status != 0xffff && mii_status != 0x0000) {
#1 lore raw
Quoted 11 lines · Roel Kluin

phy_idx is checked to be < 4, but np->phys[] is 2 elements long

---
Or should the number of elements be increased?

drivers/net/fealnx.c +0 -0
index 48385c4..100badd 100644

drivers/net/fealnx.c static int __devinit fealnx_init_one(struct pci_dev *pdev, · line 590

Quoted 8 lines
drivers/net/fealnx.c +1 -1
@@ -584,7 +584,7 @@ static int __devinit fealnx_init_one(struct pci_dev *pdev,
 	if (np->flags == HAS_MII_XCVR) {
 		int phy, phy_idx = 0;
 
-		for (phy = 1; phy < 32 && phy_idx < 4; phy++) {
+		for (phy = 1; phy < 32 && phy_idx < 2; phy++) {
 			int mii_status = mdio_read(dev, phy, 1);
 
 			if (mii_status != 0xffff && mii_status != 0x0000) {

In either of the case, one should use ARRAY_SIZE(np->phys) instead of the number.

Signature · 1 line
 i.
author
#2 lore raw

phy_idx is checked to be < 4, but np->phys[] is 2 elements long

---

Quoted 7 lines

Review

Quoted 4 lines

Or should the number of elements be increased?

(quoted diff) +1 -1
-		for (phy = 1; phy < 32 && phy_idx < 4; phy++) {
+		for (phy = 1; phy < 32 && phy_idx < 2; phy++) {

In either of the case, one should use ARRAY_SIZE(np->phys) instead of the number.

Ah, yes.

drivers/net/fealnx.c +2 -1
index 48385c4..160655d 100644
@@ -584,7 +584,8 @@ static int __devinit fealnx_init_one(struct pci_dev *pdev,
 	if (np->flags == HAS_MII_XCVR) {
 		int phy, phy_idx = 0;
 
-		for (phy = 1; phy < 32 && phy_idx < 4; phy++) {
+		for (phy = 1; phy < 32 && phy_idx < ARRAY_SIZE(np->phys);
+			       phy++) {
 			int mii_status = mdio_read(dev, phy, 1);
 
 			if (mii_status != 0xffff && mii_status != 0x0000) {