fsl/mc: Limit the ethernet name to ETH_NAME_LEN

The ethernet name should be within the ETH_NAME_LEN, as this
is the buffer space allocated to ethernet name.

Otherwise, this causes buffer overflow.

Reported-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>
This commit is contained in:
Pankaj Bansal 2018-08-02 16:31:28 +05:30 committed by York Sun
parent 6ce83fb3d6
commit c022ec039d
2 changed files with 5 additions and 5 deletions

View file

@ -322,7 +322,7 @@ static int mc_fixup_dpc_mac_addr(void *blob, int dpmac_id,
static int mc_fixup_mac_addrs(void *blob, enum mc_fixup_type type) static int mc_fixup_mac_addrs(void *blob, enum mc_fixup_type type)
{ {
int i, err = 0, ret = 0; int i, err = 0, ret = 0;
char ethname[10]; char ethname[ETH_NAME_LEN];
struct eth_device *eth_dev; struct eth_device *eth_dev;
for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) { for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
@ -331,7 +331,7 @@ static int mc_fixup_mac_addrs(void *blob, enum mc_fixup_type type)
(wriop_get_phy_address(i) == -1)) (wriop_get_phy_address(i) == -1))
continue; continue;
sprintf(ethname, "DPMAC%d@%s", i, snprintf(ethname, ETH_NAME_LEN, "DPMAC%d@%s", i,
phy_interface_strings[wriop_get_enet_if(i)]); phy_interface_strings[wriop_get_enet_if(i)]);
eth_dev = eth_get_dev_by_name(ethname); eth_dev = eth_get_dev_by_name(ethname);

View file

@ -993,7 +993,7 @@ static int ldpaa_eth_netdev_init(struct eth_device *net_dev,
int err; int err;
struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv; struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
sprintf(net_dev->name, "DPMAC%d@%s", priv->dpmac_id, snprintf(net_dev->name, ETH_NAME_LEN, "DPMAC%d@%s", priv->dpmac_id,
phy_interface_strings[enet_if]); phy_interface_strings[enet_if]);
net_dev->iobase = 0; net_dev->iobase = 0;