test: dm_mdio: avoid out of bounds access

SANDBOX_PHY_REG_CNT is not an allowable index for the array
u16 reg[SANDBOX_PHY_REG_CNT].

Identified by cppcheck.

Fixes: b47edf8069 ("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>
This commit is contained in:
Heinrich Schuchardt 2019-07-30 23:49:00 +02:00 committed by Joe Hershberger
parent a37c082248
commit fd6d88f55b

View File

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