test: dm_mdio: avoid out of bounds access
authorHeinrich Schuchardt <xypron.glpk@gmx.de>
Tue, 30 Jul 2019 21:49:00 +0000 (23:49 +0200)
committerJoe Hershberger <joe.hershberger@ni.com>
Wed, 4 Sep 2019 16:37:19 +0000 (11:37 -0500)
SANDBOX_PHY_REG_CNT is not an allowable index for the array
u16 reg[SANDBOX_PHY_REG_CNT].

Identified by cppcheck.

Fixes: b47edf8069cc ("test: dm_mdio: add a 2nd register to the emulated PHY")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
drivers/net/mdio_sandbox.c

index df053f5381422aeb692d5ef6c64590d345be365e..b731f60a98a132380d8d93d69ac8e27a897f0b03 100644 (file)
@@ -27,7 +27,7 @@ static int mdio_sandbox_read(struct udevice *dev, int addr, int devad, int reg)
                return -ENODEV;
        if (devad != MDIO_DEVAD_NONE)
                return -ENODEV;
                return -ENODEV;
        if (devad != MDIO_DEVAD_NONE)
                return -ENODEV;
-       if (reg < 0 || reg > SANDBOX_PHY_REG_CNT)
+       if (reg < 0 || reg >= SANDBOX_PHY_REG_CNT)
                return -ENODEV;
 
        return priv->reg[reg];
                return -ENODEV;
 
        return priv->reg[reg];
@@ -45,7 +45,7 @@ static int mdio_sandbox_write(struct udevice *dev, int addr, int devad, int reg,
                return -ENODEV;
        if (devad != MDIO_DEVAD_NONE)
                return -ENODEV;
                return -ENODEV;
        if (devad != MDIO_DEVAD_NONE)
                return -ENODEV;
-       if (reg < 0 || reg > SANDBOX_PHY_REG_CNT)
+       if (reg < 0 || reg >= SANDBOX_PHY_REG_CNT)
                return -ENODEV;
 
        priv->reg[reg] = val;
                return -ENODEV;
 
        priv->reg[reg] = val;