Fix some non-NULL terminated strings in the networking subsystem
Subsystems (6)
cover Fix some non-NULL terminated strings in the networking subsystem
This series is the result of a small patching spree, which started off by noticing some truncation that might take place when setting the MDIO bus name in one driver, and then looked at what other drivers do, and then.....
Vladimir Oltean (25):
arch: powerpc: mpc85xx: ensure mdiodev->name is NULL terminated after
MDIO_NAME_LEN truncation
board: gdsys: a38x: ensure mdiodev->name is NULL terminated after
MDIO_NAME_LEN truncation
net: armada100_fec: ensure mdiodev->name is NULL terminated after
MDIO_NAME_LEN truncation
net: at91_emac: ensure mdiodev->name is NULL terminated after
MDIO_NAME_LEN truncation
net: bcm-sf2: ensure mdiodev->name is NULL terminated after
MDIO_NAME_LEN truncation
net: eepro100: ensure mdiodev->name is NULL terminated after
MDIO_NAME_LEN truncation
net: ep93xx: ensure mdiodev->name is NULL terminated after
MDIO_NAME_LEN truncation
net: enetc: ensure imdio.name is NULL terminated after MDIO_NAME_LEN
truncation
net: mcdmafec: ensure bus->name is NULL terminated after MDIO_NAME_LEN
truncation
net: ftmac110: ensure mdiodev->name is NULL terminated after
MDIO_NAME_LEN truncation
net: lpc32xx: ensure mdiodev->name is NULL terminated after
MDIO_NAME_LEN truncation
net: macb: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN
truncation
net: mpc8xx_fec: ensure mdiodev->name is NULL terminated after
MDIO_NAME_LEN truncation
net: dsa: felix: ensure mii_bus->name is NULL terminated after
MDIO_NAME_LEN truncation
net: mvgbe: ensure mdiodev->name is NULL terminated after
MDIO_NAME_LEN truncation
net: sh_eth: ensure mdiodev->name is NULL terminated after
MDIO_NAME_LEN truncation
net: smc911x: ensure mdiodev->name is NULL terminated after
MDIO_NAME_LEN truncation
net: davinci_emac: ensure mdiodev->name is NULL terminated after
MDIO_NAME_LEN truncation
net: qe: uec: ensure mdiodev->name is NULL terminated after
MDIO_NAME_LEN truncation
net: mdio-uclass: rewrite dm_mdio_post_probe using strlcpy
scripts: ensure the cocci script for miiphy_register does not leave
NULL-unterminated strings
net: dsa: felix: check return code of mdio_alloc and mdio_register
net: dsa: ensure port names are NULL-terminated after
DSA_PORT_NAME_LENGTH truncation
arch: powerpc: mpc85xx: free MDIO bus if mdio_register fails
scripts: ensure the cocci script for miiphy_register does not leak the
MDIO bus
arch/powerpc/cpu/mpc85xx/ether_fcc.c | 6 ++++-- board/gdsys/a38x/ihs_phys.c | 4 +--- drivers/net/armada100_fec.c | 2 +- drivers/net/at91_emac.c | 2 +- drivers/net/bcm-sf2-eth.c | 2 +- drivers/net/eepro100.c | 2 +- drivers/net/ep93xx_eth.c | 2 +- drivers/net/fsl_enetc.c | 2 +- drivers/net/fsl_mcdmafec.c | 2 +- drivers/net/ftmac110.c | 2 +- drivers/net/lpc32xx_eth.c | 2 +- drivers/net/macb.c | 4 ++-- drivers/net/mpc8xx_fec.c | 2 +- drivers/net/mscc_eswitch/felix_switch.c | 14 +++++++++++--- drivers/net/mvgbe.c | 2 +- drivers/net/sh_eth.c | 2 +- drivers/net/smc911x.c | 2 +- drivers/net/ti/davinci_emac.c | 2 +- drivers/qe/uec.c | 2 +- net/dsa-uclass.c | 4 ++-- net/mdio-uclass.c | 2 +- scripts/coccinelle/net/mdio_register.cocci | 4 ++-- 22 files changed, 38 insertions(+), 30 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/25 arch: powerpc: mpc85xx: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation
strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.
One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.
The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.
--- arch/powerpc/cpu/mpc85xx/ether_fcc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/cpu/mpc85xx/ether_fcc.c +1 -1
@@ -444,7 +444,7 @@ int fec_initialize(struct bd_info *bis)struct mii_dev *mdiodev =mdio_alloc ();if (!mdiodev)return -ENOMEM ; -strncpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); +strlcpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); mdiodev->read = bb_miiphy_read; mdiodev->write = bb_miiphy_write;
Signature · 1 line
2.25.1
Re: [PATCH 01/25] arch: powerpc: mpc85xx: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation
Quoted 34 lines · Vladimir Oltean
strncpy()simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.One possible way to address is to pass
MDIO_NAME_LEN- 1 and a previously zero-initialized destination string, but this is more difficult to maintain.The chosen alternative is to use
strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than thestrncpy()byte-by-byte implementation by using memcpy. The destination string returned bystrlcpy()is always NULL terminated.Signed-off-by Vladimir Oltean <[email protected]>--- arch/powerpc/cpu/mpc85xx/ether_fcc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/powerpc/cpu/mpc85xx/ether_fcc.c +1
-2@@ -444,7 +444,7 @@ int fec_initialize(struct bd_info *bis)struct mii_dev *mdiodev =mdio_alloc ();if (!mdiodev)return -ENOMEM ; -strncpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); +strlcpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); mdiodev->read = bb_miiphy_read; mdiodev->write = bb_miiphy_write; --
Quoted 2 lines
2.25.1
PATCH 2/25 board: gdsys: a38x: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation
In reply to Vladimir Olteanstrncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.
One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.
The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.
--- board/gdsys/a38x/ihs_phys.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
board/gdsys/a38x/ihs_phys.c +1 -3
@@ -110,9 +110,7 @@ int register_miiphy_bus(uint k, struct mii_dev **bus)if (!mdiodev)return -ENOMEM ; -strncpy (mdiodev->name, - name, -MDIO_NAME_LEN ); +strlcpy (mdiodev->name, name,MDIO_NAME_LEN ); mdiodev->read = bb_miiphy_read; mdiodev->write = bb_miiphy_write;
Signature · 1 line
2.25.1
Re: [PATCH 02/25] board: gdsys: a38x: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation
Quoted 36 lines · Vladimir Oltean
strncpy()simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.One possible way to address is to pass
MDIO_NAME_LEN- 1 and a previously zero-initialized destination string, but this is more difficult to maintain.The chosen alternative is to use
strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than thestrncpy()byte-by-byte implementation by using memcpy. The destination string returned bystrlcpy()is always NULL terminated.Signed-off-by Vladimir Oltean <[email protected]>--- board/gdsys/a38x/ihs_phys.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)board/gdsys/a38x/ihs_phys.c +1
-4@@ -110,9 +110,7 @@ int register_miiphy_bus(uint k, struct mii_dev **bus)if (!mdiodev)return -ENOMEM ; -strncpy (mdiodev->name, - name, -MDIO_NAME_LEN ); +strlcpy (mdiodev->name, name,MDIO_NAME_LEN ); mdiodev->read = bb_miiphy_read; mdiodev->write = bb_miiphy_write; --
Quoted 2 lines
2.25.1
PATCH 3/25 net: armada100_fec: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation
In reply to Vladimir Olteanstrncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.
One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.
The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.
--- drivers/net/armada100_fec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/armada100_fec.c +1 -1
@@ -717,7 +717,7 @@ int armada100_fec_register(unsigned long base_addr)struct mii_dev *mdiodev =mdio_alloc ();if (!mdiodev)return -ENOMEM ; -strncpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); +strlcpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); mdiodev->read = smi_reg_read; mdiodev->write = smi_reg_write;
Signature · 1 line
2.25.1
Re: [PATCH 03/25] net: armada100_fec: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation
Quoted 34 lines · Vladimir Oltean
strncpy()simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.One possible way to address is to pass
MDIO_NAME_LEN- 1 and a previously zero-initialized destination string, but this is more difficult to maintain.The chosen alternative is to use
strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than thestrncpy()byte-by-byte implementation by using memcpy. The destination string returned bystrlcpy()is always NULL terminated.Signed-off-by Vladimir Oltean <[email protected]>--- drivers/net/armada100_fec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/armada100_fec.c +1
-2@@ -717,7 +717,7 @@ int armada100_fec_register(unsigned long base_addr)struct mii_dev *mdiodev =mdio_alloc ();if (!mdiodev)return -ENOMEM ; -strncpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); +strlcpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); mdiodev->read = smi_reg_read; mdiodev->write = smi_reg_write; --
Quoted 2 lines
2.25.1
PATCH 4/25 net: at91_emac: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation
In reply to Vladimir Olteanstrncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.
One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.
The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.
--- drivers/net/at91_emac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/at91_emac.c +1 -1
@@ -507,7 +507,7 @@ int at91emac_register(struct bd_info *bis, unsigned long iobase)struct mii_dev *mdiodev =mdio_alloc ();if (!mdiodev)return -ENOMEM ; -strncpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); +strlcpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); mdiodev->read = at91emac_mii_read; mdiodev->write = at91emac_mii_write;
Signature · 1 line
2.25.1
Re: [PATCH 04/25] net: at91_emac: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation
Quoted 34 lines · Vladimir Oltean
strncpy()simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.One possible way to address is to pass
MDIO_NAME_LEN- 1 and a previously zero-initialized destination string, but this is more difficult to maintain.The chosen alternative is to use
strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than thestrncpy()byte-by-byte implementation by using memcpy. The destination string returned bystrlcpy()is always NULL terminated.Signed-off-by Vladimir Oltean <[email protected]>--- drivers/net/at91_emac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/at91_emac.c +1
-2@@ -507,7 +507,7 @@ int at91emac_register(struct bd_info *bis, unsigned long iobase)struct mii_dev *mdiodev =mdio_alloc ();if (!mdiodev)return -ENOMEM ; -strncpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); +strlcpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); mdiodev->read = at91emac_mii_read; mdiodev->write = at91emac_mii_write; --
Quoted 2 lines
2.25.1
PATCH 5/25 net: bcm-sf2: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation
In reply to Vladimir Olteanstrncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.
One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.
The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.
--- drivers/net/bcm-sf2-eth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/bcm-sf2-eth.c +1 -1
@@ -250,7 +250,7 @@ int bcm_sf2_eth_register(struct bd_info *bis, u8 dev_num)if (!mdiodev)return -ENOMEM ; -strncpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); +strlcpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); mdiodev->read = eth->miiphy_read; mdiodev->write = eth->miiphy_write;
Signature · 1 line
2.25.1
Re: [PATCH 05/25] net: bcm-sf2: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation
Quoted 34 lines · Vladimir Oltean
strncpy()simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.One possible way to address is to pass
MDIO_NAME_LEN- 1 and a previously zero-initialized destination string, but this is more difficult to maintain.The chosen alternative is to use
strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than thestrncpy()byte-by-byte implementation by using memcpy. The destination string returned bystrlcpy()is always NULL terminated.Signed-off-by Vladimir Oltean <[email protected]>--- drivers/net/bcm-sf2-eth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/bcm-sf2-eth.c +1
-2@@ -250,7 +250,7 @@ int bcm_sf2_eth_register(struct bd_info *bis, u8 dev_num)if (!mdiodev)return -ENOMEM ; -strncpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); +strlcpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); mdiodev->read = eth->miiphy_read; mdiodev->write = eth->miiphy_write; --
Quoted 2 lines
2.25.1
PATCH 6/25 net: eepro100: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation
In reply to Vladimir Olteanstrncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.
One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.
The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.
--- drivers/net/eepro100.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/eepro100.c +1 -1
@@ -493,7 +493,7 @@ static int eepro100_initialize_mii(struct eepro100_priv *priv)if (!mdiodev)return -ENOMEM ; -strncpy (mdiodev->name, priv->name,MDIO_NAME_LEN ); +strlcpy (mdiodev->name, priv->name,MDIO_NAME_LEN ); mdiodev->read = eepro100_miiphy_read; mdiodev->write = eepro100_miiphy_write; mdiodev->priv = priv;
Signature · 1 line
2.25.1
Re: [PATCH 06/25] net: eepro100: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation
Quoted 34 lines · Vladimir Oltean
strncpy()simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.One possible way to address is to pass
MDIO_NAME_LEN- 1 and a previously zero-initialized destination string, but this is more difficult to maintain.The chosen alternative is to use
strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than thestrncpy()byte-by-byte implementation by using memcpy. The destination string returned bystrlcpy()is always NULL terminated.Signed-off-by Vladimir Oltean <[email protected]>--- drivers/net/eepro100.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/eepro100.c +1
-2@@ -493,7 +493,7 @@ static int eepro100_initialize_mii(struct eepro100_priv *priv)if (!mdiodev)return -ENOMEM ; -strncpy (mdiodev->name, priv->name,MDIO_NAME_LEN ); +strlcpy (mdiodev->name, priv->name,MDIO_NAME_LEN ); mdiodev->read = eepro100_miiphy_read; mdiodev->write = eepro100_miiphy_write; mdiodev->priv = priv; --
Quoted 2 lines
2.25.1
PATCH 7/25 net: ep93xx: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation
In reply to Vladimir Olteanstrncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.
One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.
The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.
--- drivers/net/ep93xx_eth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ep93xx_eth.c +1 -1
@@ -427,7 +427,7 @@ int ep93xx_miiphy_initialize(struct bd_info * const bd)struct mii_dev *mdiodev =mdio_alloc ();if (!mdiodev)return -ENOMEM ; -strncpy (mdiodev->name,"ep93xx_eth0" ,MDIO_NAME_LEN ); +strlcpy (mdiodev->name,"ep93xx_eth0" ,MDIO_NAME_LEN ); mdiodev->read = ep93xx_miiphy_read; mdiodev->write = ep93xx_miiphy_write;
Signature · 1 line
2.25.1
Re: [PATCH 07/25] net: ep93xx: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation
Quoted 34 lines · Vladimir Oltean
strncpy()simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.One possible way to address is to pass
MDIO_NAME_LEN- 1 and a previously zero-initialized destination string, but this is more difficult to maintain.The chosen alternative is to use
strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than thestrncpy()byte-by-byte implementation by using memcpy. The destination string returned bystrlcpy()is always NULL terminated.Signed-off-by Vladimir Oltean <[email protected]>--- drivers/net/ep93xx_eth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/ep93xx_eth.c +1
-2@@ -427,7 +427,7 @@ int ep93xx_miiphy_initialize(struct bd_info * const bd)struct mii_dev *mdiodev =mdio_alloc ();if (!mdiodev)return -ENOMEM ; -strncpy (mdiodev->name,"ep93xx_eth0" ,MDIO_NAME_LEN ); +strlcpy (mdiodev->name,"ep93xx_eth0" ,MDIO_NAME_LEN ); mdiodev->read = ep93xx_miiphy_read; mdiodev->write = ep93xx_miiphy_write; --
Quoted 2 lines
2.25.1
PATCH 8/25 net: enetc: ensure imdio.name is NULL terminated after MDIO_NAME_LEN truncation
In reply to Vladimir Olteanstrncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.
One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.
The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.
--- drivers/net/fsl_enetc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/fsl_enetc.c +1 -1
@@ -270,7 +270,7 @@ static void enetc_start_pcs(struct udevice *dev) priv->imdio.read = enetc_mdio_read; priv->imdio.write = enetc_mdio_write; priv->imdio.priv = priv->port_regs +ENETC_PM_IMDIO_BASE ; -strncpy (priv->imdio.name, dev->name,MDIO_NAME_LEN ); +strlcpy (priv->imdio.name, dev->name,MDIO_NAME_LEN );if (!miiphy_get_dev_by_name (priv->imdio.name))mdio_register (&priv->imdio); }
Signature · 1 line
2.25.1
Re: [PATCH 08/25] net: enetc: ensure imdio.name is NULL terminated after MDIO_NAME_LEN truncation
Quoted 34 lines · Vladimir Oltean
strncpy()simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.One possible way to address is to pass
MDIO_NAME_LEN- 1 and a previously zero-initialized destination string, but this is more difficult to maintain.The chosen alternative is to use
strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than thestrncpy()byte-by-byte implementation by using memcpy. The destination string returned bystrlcpy()is always NULL terminated.Signed-off-by Vladimir Oltean <[email protected]>--- drivers/net/fsl_enetc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/fsl_enetc.c +1
-2@@ -270,7 +270,7 @@ static void enetc_start_pcs(struct udevice *dev) priv->imdio.read = enetc_mdio_read; priv->imdio.write = enetc_mdio_write; priv->imdio.priv = priv->port_regs +ENETC_PM_IMDIO_BASE ; -strncpy (priv->imdio.name, dev->name,MDIO_NAME_LEN ); +strlcpy (priv->imdio.name, dev->name,MDIO_NAME_LEN );if (!miiphy_get_dev_by_name (priv->imdio.name))mdio_register (&priv->imdio); } --
Quoted 2 lines
2.25.1
PATCH 9/25 net: mcdmafec: ensure bus->name is NULL terminated after MDIO_NAME_LEN truncation
In reply to Vladimir Olteanstrncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.
One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.
The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.
--- drivers/net/fsl_mcdmafec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/fsl_mcdmafec.c +1 -1
@@ -541,7 +541,7 @@ static int mcdmafec_probe(struct udevice *dev) info->bus =mdio_alloc ();if (!info->bus)return -ENOMEM ; -strncpy (info->bus->name, dev->name,MDIO_NAME_LEN ); +strlcpy (info->bus->name, dev->name,MDIO_NAME_LEN ); info->bus->read = mcffec_miiphy_read; info->bus->write = mcffec_miiphy_write;
Signature · 1 line
2.25.1
Re: [PATCH 09/25] net: mcdmafec: ensure bus->name is NULL terminated after MDIO_NAME_LEN truncation
Quoted 34 lines · Vladimir Oltean
strncpy()simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.One possible way to address is to pass
MDIO_NAME_LEN- 1 and a previously zero-initialized destination string, but this is more difficult to maintain.The chosen alternative is to use
strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than thestrncpy()byte-by-byte implementation by using memcpy. The destination string returned bystrlcpy()is always NULL terminated.Signed-off-by Vladimir Oltean <[email protected]>--- drivers/net/fsl_mcdmafec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/fsl_mcdmafec.c +1
-2@@ -541,7 +541,7 @@ static int mcdmafec_probe(struct udevice *dev) info->bus =mdio_alloc ();if (!info->bus)return -ENOMEM ; -strncpy (info->bus->name, dev->name,MDIO_NAME_LEN ); +strlcpy (info->bus->name, dev->name,MDIO_NAME_LEN ); info->bus->read = mcffec_miiphy_read; info->bus->write = mcffec_miiphy_write; --
Quoted 2 lines
2.25.1
PATCH 10/25 net: ftmac110: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation
In reply to Vladimir Olteanstrncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.
One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.
The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.
--- drivers/net/ftmac110.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ftmac110.c +1 -1
@@ -476,7 +476,7 @@ int ftmac110_initialize(struct bd_info *bis)struct mii_dev *mdiodev =mdio_alloc ();if (!mdiodev)return -ENOMEM ; -strncpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); +strlcpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); mdiodev->read = ftmac110_mdio_read; mdiodev->write = ftmac110_mdio_write;
Signature · 1 line
2.25.1
Re: [PATCH 10/25] net: ftmac110: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation
Quoted 34 lines · Vladimir Oltean
strncpy()simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.One possible way to address is to pass
MDIO_NAME_LEN- 1 and a previously zero-initialized destination string, but this is more difficult to maintain.The chosen alternative is to use
strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than thestrncpy()byte-by-byte implementation by using memcpy. The destination string returned bystrlcpy()is always NULL terminated.Signed-off-by Vladimir Oltean <[email protected]>--- drivers/net/ftmac110.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/ftmac110.c +1
-2@@ -476,7 +476,7 @@ int ftmac110_initialize(struct bd_info *bis)struct mii_dev *mdiodev =mdio_alloc ();if (!mdiodev)return -ENOMEM ; -strncpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); +strlcpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); mdiodev->read = ftmac110_mdio_read; mdiodev->write = ftmac110_mdio_write; --
Quoted 2 lines
2.25.1
PATCH 11/25 net: lpc32xx: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation
In reply to Vladimir Olteanstrncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.
One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.
The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.
--- drivers/net/lpc32xx_eth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/lpc32xx_eth.c +1 -1
@@ -638,7 +638,7 @@ int lpc32xx_eth_initialize(struct bd_info *bis)struct mii_dev *mdiodev =mdio_alloc ();if (!mdiodev)return -ENOMEM ; -strncpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); +strlcpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); mdiodev->read = mii_reg_read; mdiodev->write = mii_reg_write;
Signature · 1 line
2.25.1
Re: [PATCH 11/25] net: lpc32xx: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation
Quoted 34 lines · Vladimir Oltean
strncpy()simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.One possible way to address is to pass
MDIO_NAME_LEN- 1 and a previously zero-initialized destination string, but this is more difficult to maintain.The chosen alternative is to use
strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than thestrncpy()byte-by-byte implementation by using memcpy. The destination string returned bystrlcpy()is always NULL terminated.Signed-off-by Vladimir Oltean <[email protected]>--- drivers/net/lpc32xx_eth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/lpc32xx_eth.c +1
-2@@ -638,7 +638,7 @@ int lpc32xx_eth_initialize(struct bd_info *bis)struct mii_dev *mdiodev =mdio_alloc ();if (!mdiodev)return -ENOMEM ; -strncpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); +strlcpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); mdiodev->read = mii_reg_read; mdiodev->write = mii_reg_write; --
Quoted 2 lines
2.25.1
PATCH 12/25 net: macb: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation
In reply to Vladimir Olteanstrncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.
One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.
The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.
--- drivers/net/macb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/macb.c +2 -2
@@ -1245,7 +1245,7 @@ int macb_eth_initialize(int id, void *regs, unsigned int phy_addr)struct mii_dev *mdiodev =mdio_alloc ();if (!mdiodev)return -ENOMEM ; -strncpy (mdiodev->name, netdev->name,MDIO_NAME_LEN ); +strlcpy (mdiodev->name, netdev->name,MDIO_NAME_LEN ); mdiodev->read = macb_miiphy_read; mdiodev->write = macb_miiphy_write;
@@ -1403,7 +1403,7 @@ static int macb_eth_probe(struct udevice *dev) macb->bus =mdio_alloc ();if (!macb->bus)return -ENOMEM ; -strncpy (macb->bus->name, dev->name,MDIO_NAME_LEN ); +strlcpy (macb->bus->name, dev->name,MDIO_NAME_LEN ); macb->bus->read = macb_miiphy_read; macb->bus->write = macb_miiphy_write;
Signature · 1 line
2.25.1
Re: [PATCH 12/25] net: macb: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation
Quoted 43 lines · Vladimir Oltean
strncpy()simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.One possible way to address is to pass
MDIO_NAME_LEN- 1 and a previously zero-initialized destination string, but this is more difficult to maintain.The chosen alternative is to use
strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than thestrncpy()byte-by-byte implementation by using memcpy. The destination string returned bystrlcpy()is always NULL terminated.Signed-off-by Vladimir Oltean <[email protected]>--- drivers/net/macb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/macb.c +2
-3@@ -1245,7 +1245,7 @@ int macb_eth_initialize(int id, void *regs, unsigned int phy_addr)struct mii_dev *mdiodev =mdio_alloc ();if (!mdiodev)return -ENOMEM ; -strncpy (mdiodev->name, netdev->name,MDIO_NAME_LEN ); +strlcpy (mdiodev->name, netdev->name,MDIO_NAME_LEN ); mdiodev->read = macb_miiphy_read; mdiodev->write = macb_miiphy_write;@@ -1403,7 +1403,7 @@ static int macb_eth_probe(struct udevice *dev) macb->bus =mdio_alloc ();if (!macb->bus)return -ENOMEM ; -strncpy (macb->bus->name, dev->name,MDIO_NAME_LEN ); +strlcpy (macb->bus->name, dev->name,MDIO_NAME_LEN ); macb->bus->read = macb_miiphy_read; macb->bus->write = macb_miiphy_write; --
Quoted 2 lines
2.25.1
PATCH 13/25 net: mpc8xx_fec: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation
In reply to Vladimir Olteanstrncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.
One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.
The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.
--- drivers/net/mpc8xx_fec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/mpc8xx_fec.c +1 -1
@@ -160,7 +160,7 @@ int fec_initialize(struct bd_info *bis)struct mii_dev *mdiodev =mdio_alloc ();if (!mdiodev)return -ENOMEM ; -strncpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); +strlcpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); mdiodev->read = fec8xx_miiphy_read; mdiodev->write = fec8xx_miiphy_write;
Signature · 1 line
2.25.1
Re: [PATCH 13/25] net: mpc8xx_fec: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation
Quoted 34 lines · Vladimir Oltean
strncpy()simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.One possible way to address is to pass
MDIO_NAME_LEN- 1 and a previously zero-initialized destination string, but this is more difficult to maintain.The chosen alternative is to use
strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than thestrncpy()byte-by-byte implementation by using memcpy. The destination string returned bystrlcpy()is always NULL terminated.Signed-off-by Vladimir Oltean <[email protected]>--- drivers/net/mpc8xx_fec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/mpc8xx_fec.c +1
-2@@ -160,7 +160,7 @@ int fec_initialize(struct bd_info *bis)struct mii_dev *mdiodev =mdio_alloc ();if (!mdiodev)return -ENOMEM ; -strncpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); +strlcpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); mdiodev->read = fec8xx_miiphy_read; mdiodev->write = fec8xx_miiphy_write; --
Quoted 2 lines
2.25.1
PATCH 14/25 net: dsa: felix: ensure mii_bus->name is NULL terminated after MDIO_NAME_LEN truncation
In reply to Vladimir Olteanstrncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.
One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.
The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.
--- drivers/net/mscc_eswitch/felix_switch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/mscc_eswitch/felix_switch.c +2 -2
@@ -258,7 +258,7 @@ static void felix_init(struct udevice *dev) priv->imdio.read = felix_mdio_read; priv->imdio.write = felix_mdio_write; priv->imdio.priv = priv->imdio_base +FELIX_PM_IMDIO_BASE ; -strncpy (priv->imdio.name, dev->name,MDIO_NAME_LEN ); +strlcpy (priv->imdio.name, dev->name,MDIO_NAME_LEN );/* set up CPU port */ out_le32(base + FELIX_QSYS_SYSTEM_EXT_CPU_CFG,
@@ -303,7 +303,7 @@ static int felix_probe(struct udevice *dev) mii_bus->read = felix_mdio_read; mii_bus->write = felix_mdio_write; mii_bus->priv = priv->imdio_base +FELIX_PM_IMDIO_BASE ; -strncpy (mii_bus->name, dev->name,MDIO_NAME_LEN ); +strlcpy (mii_bus->name, dev->name,MDIO_NAME_LEN );mdio_register (mii_bus); }
Signature · 1 line
2.25.1
Re: [PATCH 14/25] net: dsa: felix: ensure mii_bus->name is NULL terminated after MDIO_NAME_LEN truncation
Quoted 43 lines · Vladimir Oltean
strncpy()simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.One possible way to address is to pass
MDIO_NAME_LEN- 1 and a previously zero-initialized destination string, but this is more difficult to maintain.The chosen alternative is to use
strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than thestrncpy()byte-by-byte implementation by using memcpy. The destination string returned bystrlcpy()is always NULL terminated.Signed-off-by Vladimir Oltean <[email protected]>--- drivers/net/mscc_eswitch/felix_switch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/mscc_eswitch/felix_switch.c +2
-3@@ -258,7 +258,7 @@ static void felix_init(struct udevice *dev) priv->imdio.read = felix_mdio_read; priv->imdio.write = felix_mdio_write; priv->imdio.priv = priv->imdio_base +FELIX_PM_IMDIO_BASE ; -strncpy (priv->imdio.name, dev->name,MDIO_NAME_LEN ); +strlcpy (priv->imdio.name, dev->name,MDIO_NAME_LEN );/* set up CPU port */ out_le32(base + FELIX_QSYS_SYSTEM_EXT_CPU_CFG,@@ -303,7 +303,7 @@ static int felix_probe(struct udevice *dev) mii_bus->read = felix_mdio_read; mii_bus->write = felix_mdio_write; mii_bus->priv = priv->imdio_base +FELIX_PM_IMDIO_BASE ; -strncpy (mii_bus->name, dev->name,MDIO_NAME_LEN ); +strlcpy (mii_bus->name, dev->name,MDIO_NAME_LEN );mdio_register (mii_bus); } --
Quoted 2 lines
2.25.1
PATCH 15/25 net: mvgbe: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation
In reply to Vladimir Olteanstrncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.
One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.
The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.
--- drivers/net/mvgbe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/mvgbe.c +1 -1
@@ -883,7 +883,7 @@ int mvgbe_initialize(struct bd_info *bis)struct mii_dev *mdiodev =mdio_alloc ();if (!mdiodev)return -ENOMEM ; -strncpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); +strlcpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); mdiodev->read = smi_reg_read; mdiodev->write = smi_reg_write;
Signature · 1 line
2.25.1
Re: [PATCH 15/25] net: mvgbe: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation
Quoted 34 lines · Vladimir Oltean
strncpy()simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.One possible way to address is to pass
MDIO_NAME_LEN- 1 and a previously zero-initialized destination string, but this is more difficult to maintain.The chosen alternative is to use
strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than thestrncpy()byte-by-byte implementation by using memcpy. The destination string returned bystrlcpy()is always NULL terminated.Signed-off-by Vladimir Oltean <[email protected]>--- drivers/net/mvgbe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/mvgbe.c +1
-2@@ -883,7 +883,7 @@ int mvgbe_initialize(struct bd_info *bis)struct mii_dev *mdiodev =mdio_alloc ();if (!mdiodev)return -ENOMEM ; -strncpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); +strlcpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); mdiodev->read = smi_reg_read; mdiodev->write = smi_reg_write; --
Quoted 2 lines
2.25.1
PATCH 16/25 net: sh_eth: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation
In reply to Vladimir Olteanstrncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.
One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.
The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.
--- drivers/net/sh_eth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/sh_eth.c +1 -1
@@ -657,7 +657,7 @@ int sh_eth_initialize(struct bd_info *bd) mdiodev =mdio_alloc ();if (!mdiodev)return -ENOMEM ; -strncpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); +strlcpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); mdiodev->read = bb_miiphy_read; mdiodev->write = bb_miiphy_write;
Signature · 1 line
2.25.1
Re: [PATCH 16/25] net: sh_eth: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation
Quoted 34 lines · Vladimir Oltean
strncpy()simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.One possible way to address is to pass
MDIO_NAME_LEN- 1 and a previously zero-initialized destination string, but this is more difficult to maintain.The chosen alternative is to use
strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than thestrncpy()byte-by-byte implementation by using memcpy. The destination string returned bystrlcpy()is always NULL terminated.Signed-off-by Vladimir Oltean <[email protected]>--- drivers/net/sh_eth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/sh_eth.c +1
-2@@ -657,7 +657,7 @@ int sh_eth_initialize(struct bd_info *bd) mdiodev =mdio_alloc ();if (!mdiodev)return -ENOMEM ; -strncpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); +strlcpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); mdiodev->read = bb_miiphy_read; mdiodev->write = bb_miiphy_write; --
Quoted 2 lines
2.25.1
PATCH 17/25 net: smc911x: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation
In reply to Vladimir Olteanstrncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.
One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.
The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.
--- drivers/net/smc911x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/smc911x.c +1 -1
@@ -425,7 +425,7 @@ static int smc911x_initialize_mii(struct smc911x_priv *priv)if (!mdiodev)return -ENOMEM ; -strncpy (mdiodev->name, priv->dev.name,MDIO_NAME_LEN ); +strlcpy (mdiodev->name, priv->dev.name,MDIO_NAME_LEN ); mdiodev->read = smc911x_miiphy_read; mdiodev->write = smc911x_miiphy_write;
Signature · 1 line
2.25.1
Re: [PATCH 17/25] net: smc911x: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation
Quoted 34 lines · Vladimir Oltean
strncpy()simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.One possible way to address is to pass
MDIO_NAME_LEN- 1 and a previously zero-initialized destination string, but this is more difficult to maintain.The chosen alternative is to use
strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than thestrncpy()byte-by-byte implementation by using memcpy. The destination string returned bystrlcpy()is always NULL terminated.Signed-off-by Vladimir Oltean <[email protected]>--- drivers/net/smc911x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/smc911x.c +1
-2@@ -425,7 +425,7 @@ static int smc911x_initialize_mii(struct smc911x_priv *priv)if (!mdiodev)return -ENOMEM ; -strncpy (mdiodev->name, priv->dev.name,MDIO_NAME_LEN ); +strlcpy (mdiodev->name, priv->dev.name,MDIO_NAME_LEN ); mdiodev->read = smc911x_miiphy_read; mdiodev->write = smc911x_miiphy_write; --
Quoted 2 lines
2.25.1
PATCH 18/25 net: davinci_emac: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation
In reply to Vladimir Olteanstrncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.
One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.
The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.
--- drivers/net/ti/davinci_emac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ti/davinci_emac.c +1 -1
@@ -816,7 +816,7 @@ static int davinci_emac_probe(struct udevice *dev)struct mii_dev *mdiodev =mdio_alloc ();if (!mdiodev)return -ENOMEM ; -strncpy (mdiodev->name, phy[i].name,MDIO_NAME_LEN ); +strlcpy (mdiodev->name, phy[i].name,MDIO_NAME_LEN ); mdiodev->read = davinci_mii_phy_read; mdiodev->write = davinci_mii_phy_write;
Signature · 1 line
2.25.1
Re: [PATCH 18/25] net: davinci_emac: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation
Quoted 34 lines · Vladimir Oltean
strncpy()simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.One possible way to address is to pass
MDIO_NAME_LEN- 1 and a previously zero-initialized destination string, but this is more difficult to maintain.The chosen alternative is to use
strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than thestrncpy()byte-by-byte implementation by using memcpy. The destination string returned bystrlcpy()is always NULL terminated.Signed-off-by Vladimir Oltean <[email protected]>--- drivers/net/ti/davinci_emac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/ti/davinci_emac.c +1
-2@@ -816,7 +816,7 @@ static int davinci_emac_probe(struct udevice *dev)struct mii_dev *mdiodev =mdio_alloc ();if (!mdiodev)return -ENOMEM ; -strncpy (mdiodev->name, phy[i].name,MDIO_NAME_LEN ); +strlcpy (mdiodev->name, phy[i].name,MDIO_NAME_LEN ); mdiodev->read = davinci_mii_phy_read; mdiodev->write = davinci_mii_phy_write; --
Quoted 2 lines
2.25.1
PATCH 19/25 net: qe: uec: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation
In reply to Vladimir Olteanstrncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.
One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.
The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.
--- drivers/qe/uec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/qe/uec.c +1 -1
@@ -1407,7 +1407,7 @@ int uec_initialize(struct bd_info *bis, struct uec_inf *uec_info)if (!mdiodev)return -ENOMEM ; -strncpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); +strlcpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); mdiodev->read = uec_miiphy_read; mdiodev->write = uec_miiphy_write;
Signature · 1 line
2.25.1
Re: [PATCH 19/25] net: qe: uec: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation
Quoted 34 lines · Vladimir Oltean
strncpy()simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.One possible way to address is to pass
MDIO_NAME_LEN- 1 and a previously zero-initialized destination string, but this is more difficult to maintain.The chosen alternative is to use
strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than thestrncpy()byte-by-byte implementation by using memcpy. The destination string returned bystrlcpy()is always NULL terminated.Signed-off-by Vladimir Oltean <[email protected]>--- drivers/qe/uec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/qe/uec.c +1
-2@@ -1407,7 +1407,7 @@ int uec_initialize(struct bd_info *bis, struct uec_inf *uec_info)if (!mdiodev)return -ENOMEM ; -strncpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); +strlcpy (mdiodev->name, dev->name,MDIO_NAME_LEN ); mdiodev->read = uec_miiphy_read; mdiodev->write = uec_miiphy_write; --
Quoted 2 lines
2.25.1
PATCH 20/25 net: mdio-uclass: rewrite dm_mdio_post_probe using strlcpy
In reply to Vladimir Olteandm_mdio_post_probe used to be vulnerable after truncation, but has been patched by commit 398e7512d8d7 ("net: Fix Covarity Defect 244093"). Nonetheless, we can use strlcpy like the rest of the code base now, which yields the same result.
--- net/mdio-uclass.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/mdio-uclass.c +1 -1
@@ -101,7 +101,7 @@ static int dm_mdio_post_probe(struct udevice *dev) pdata->mii_bus->write = mdio_write; pdata->mii_bus->reset = mdio_reset; pdata->mii_bus->priv = dev; -strncpy (pdata->mii_bus->name, dev->name,MDIO_NAME_LEN -1 ); +strlcpy (pdata->mii_bus->name, dev->name,MDIO_NAME_LEN );return mdio_register (pdata->mii_bus); }
Signature · 1 line
2.25.1
Re: [PATCH 20/25] net: mdio-uclass: rewrite dm_mdio_post_probe using strlcpy
Quoted 25 lines · Vladimir Oltean
dm_mdio_post_probeused to be vulnerable after truncation, but has been patched by commit398e7512d8d7("net: Fix Covarity Defect 244093"). Nonetheless, we can use strlcpy like the rest of the code base now, which yields the same result.Signed-off-by Vladimir Oltean <[email protected]>--- net/mdio-uclass.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/mdio-uclass.c +1
-2@@ -101,7 +101,7 @@ static int dm_mdio_post_probe(struct udevice *dev) pdata->mii_bus->write = mdio_write; pdata->mii_bus->reset = mdio_reset; pdata->mii_bus->priv = dev; -strncpy (pdata->mii_bus->name, dev->name,MDIO_NAME_LEN -1 ); +strlcpy (pdata->mii_bus->name, dev->name,MDIO_NAME_LEN );return mdio_register (pdata->mii_bus); } --
Quoted 2 lines
2.25.1
PATCH 21/25 scripts: ensure the cocci script for miiphy_register does not leave NULL-unterminated strings
In reply to Vladimir Olteanstrncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.
One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.
The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.
--- scripts/coccinelle/net/mdio_register.cocci | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/coccinelle/net/mdio_register.cocci +1 -1
@@ -16,7 +16,7 @@ identifier readfunc, writefunc; - miiphy_register(devname, readfunc, writefunc); + struct mii_dev *mdiodev = mdio_alloc(); + if (!mdiodev) return -ENOMEM; -+ strncpy(mdiodev->name, devname, MDIO_NAME_LEN); ++ strlcpy(mdiodev->name, devname, MDIO_NAME_LEN); + mdiodev->read = readfunc; + mdiodev->write = writefunc; +
Signature · 1 line
2.25.1
PATCH 22/25 net: dsa: felix: check return code of mdio_alloc and mdio_register
In reply to Vladimir OlteanThese functions can return errors, it's best to catch them and trigger the driver unwind code path.
--- drivers/net/mscc_eswitch/felix_switch.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/net/mscc_eswitch/felix_switch.c +9 -1
@@ -276,6 +276,7 @@ static void felix_init(struct udevice *dev)static int felix_probe (struct udevice *dev) {struct felix_priv *priv =dev_get_priv (dev); +int err;if (ofnode_valid (dev_ofnode (dev)) && !ofnode_is_available (dev_ofnode (dev))) {
@@ -300,11 +301,18 @@ static int felix_probe(struct udevice *dev)struct mii_dev *mii_bus; mii_bus =mdio_alloc (); +if (!mii_bus) +return -ENOMEM ; + mii_bus->read = felix_mdio_read; mii_bus->write = felix_mdio_write; mii_bus->priv = priv->imdio_base +FELIX_PM_IMDIO_BASE ;strlcpy (mii_bus->name, dev->name,MDIO_NAME_LEN ); -mdio_register (mii_bus); + err =mdio_register (mii_bus); +if (err) { +mdio_free (mii_bus); +return err; + } }dm_pci_clrset_config16 (dev,PCI_COMMAND ,0 ,PCI_COMMAND_MEMORY );
Signature · 1 line
2.25.1
Re: [PATCH 22/25] net: dsa: felix: check return code of mdio_alloc and mdio_register
Quoted 42 lines · Vladimir Oltean
These functions can return errors, it's best to catch them and trigger the driver unwind code path.
Signed-off-by Vladimir Oltean <[email protected]>--- drivers/net/mscc_eswitch/felix_switch.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)drivers/net/mscc_eswitch/felix_switch.c +9
-2@@ -276,6 +276,7 @@ static void felix_init(struct udevice *dev)static int felix_probe (struct udevice *dev) {struct felix_priv *priv =dev_get_priv (dev); +int err;if (ofnode_valid (dev_ofnode (dev)) && !ofnode_is_available (dev_ofnode (dev))) {@@ -300,11 +301,18 @@ static int felix_probe(struct udevice *dev)struct mii_dev *mii_bus; mii_bus =mdio_alloc (); +if (!mii_bus) +return -ENOMEM ; + mii_bus->read = felix_mdio_read; mii_bus->write = felix_mdio_write; mii_bus->priv = priv->imdio_base +FELIX_PM_IMDIO_BASE ;strlcpy (mii_bus->name, dev->name,MDIO_NAME_LEN ); -mdio_register (mii_bus); + err =mdio_register (mii_bus); +if (err) { +mdio_free (mii_bus); +return err; + } }dm_pci_clrset_config16 (dev,PCI_COMMAND ,0 ,PCI_COMMAND_MEMORY ); --
Quoted 2 lines
2.25.1
PATCH 23/25 net: dsa: ensure port names are NULL-terminated after DSA_PORT_NAME_LENGTH truncation
In reply to Vladimir Olteanstrncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.
One possible way to address is to pass DSA_PORT_NAME_LENGTH - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.
The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.
--- net/dsa-uclass.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/dsa-uclass.c +2 -2
@@ -221,7 +221,7 @@ static int dsa_port_of_to_pdata(struct udevice *pdev) label =ofnode_read_string (dev_ofnode (pdev),"label" );if (label) -strncpy (port_pdata->name, label,DSA_PORT_NAME_LENGTH ); +strlcpy (port_pdata->name, label,DSA_PORT_NAME_LENGTH ); eth_pdata =dev_get_plat (pdev); eth_pdata->priv_pdata = port_pdata;
@@ -433,7 +433,7 @@ static int dsa_post_bind(struct udevice *dev)struct dsa_port_pdata *port_pdata; port_pdata =dev_get_parent_plat (pdev); -strncpy (port_pdata->name, name,DSA_PORT_NAME_LENGTH ); +strlcpy (port_pdata->name, name,DSA_PORT_NAME_LENGTH ); pdev->name = port_pdata->name; }
Signature · 1 line
2.25.1
Re: [PATCH 23/25] net: dsa: ensure port names are NULL-terminated after DSA_PORT_NAME_LENGTH truncation
Quoted 43 lines · Vladimir Oltean
strncpy()simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.One possible way to address is to pass
DSA_PORT_NAME_LENGTH- 1 and a previously zero-initialized destination string, but this is more difficult to maintain.The chosen alternative is to use
strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than thestrncpy()byte-by-byte implementation by using memcpy. The destination string returned bystrlcpy()is always NULL terminated.Signed-off-by Vladimir Oltean <[email protected]>--- net/dsa-uclass.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)net/dsa-uclass.c +2
-3@@ -221,7 +221,7 @@ static int dsa_port_of_to_pdata(struct udevice *pdev) label =ofnode_read_string (dev_ofnode (pdev),"label" );if (label) -strncpy (port_pdata->name, label,DSA_PORT_NAME_LENGTH ); +strlcpy (port_pdata->name, label,DSA_PORT_NAME_LENGTH ); eth_pdata =dev_get_plat (pdev); eth_pdata->priv_pdata = port_pdata;@@ -433,7 +433,7 @@ static int dsa_post_bind(struct udevice *dev)struct dsa_port_pdata *port_pdata; port_pdata =dev_get_parent_plat (pdev); -strncpy (port_pdata->name, name,DSA_PORT_NAME_LENGTH ); +strlcpy (port_pdata->name, name,DSA_PORT_NAME_LENGTH ); pdev->name = port_pdata->name; } --
Quoted 2 lines
2.25.1
PATCH 24/25 arch: powerpc: mpc85xx: free MDIO bus if mdio_register fails
In reply to Vladimir OlteanIf mdio_register fails, it is nice to not leave behind dangling allocated memory.
--- arch/powerpc/cpu/mpc85xx/ether_fcc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/cpu/mpc85xx/ether_fcc.c +3 -1
@@ -449,8 +449,10 @@ int fec_initialize(struct bd_info *bis) mdiodev->write = bb_miiphy_write; retval =mdio_register (mdiodev); -if (retval <0 ) +if (retval <0 ) { +mdio_free (mdiodev);return retval; + }#endif }
Signature · 1 line
2.25.1
Re: [PATCH 24/25] arch: powerpc: mpc85xx: free MDIO bus if mdio_register fails
Quoted 26 lines · Vladimir Oltean
If
mdio_registerfails, it is nice to not leave behind dangling allocated memory.Signed-off-by Vladimir Oltean <[email protected]>--- arch/powerpc/cpu/mpc85xx/ether_fcc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)arch/powerpc/cpu/mpc85xx/ether_fcc.c +3
-2@@ -449,8 +449,10 @@ int fec_initialize(struct bd_info *bis) mdiodev->write = bb_miiphy_write; retval =mdio_register (mdiodev); -if (retval <0 ) +if (retval <0 ) { +mdio_free (mdiodev);return retval; + }#endif } --
Quoted 2 lines
2.25.1
PATCH 25/25 scripts: ensure the cocci script for miiphy_register does not leak the MDIO bus
In reply to Vladimir OlteanWhen mdio_register fails, mdio_free should be called on the mdiodev that was previously allocated with mdio_alloc.
--- scripts/coccinelle/net/mdio_register.cocci | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/coccinelle/net/mdio_register.cocci +1 -1
@@ -21,7 +21,7 @@ identifier readfunc, writefunc; + mdiodev->write = writefunc; + + retval = mdio_register(mdiodev); -+ if (retval < 0) return retval; ++ if (retval < 0) { mdio_free(mdiodev); return retval; } @ update_read_sig @ identifier mii_reg.readfunc;
Signature · 1 line
2.25.1