Skip to content

Commit 995786b

Browse files
Jason Wangdavem330
authored andcommitted
dpaa2-eth: Replace strlcpy with strscpy
The strlcpy should not be used because it doesn't limit the source length. As linus says, it's a completely useless function if you can't implicitly trust the source string - but that is almost always why people think they should use it! All in all the BSD function will lead some potential bugs. But the strscpy doesn't require reading memory from the src string beyond the specified "count" bytes, and since the return value is easier to error-check than strlcpy()'s. In addition, the implementation is robust to the string changing out from underneath it, unlike the current strlcpy() implementation. Thus, We prefer using strscpy instead of strlcpy. Signed-off-by: Jason Wang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a731437 commit 995786b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/net/ethernet/freescale/dpaa2/dpaa2-ethtool.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ static void dpaa2_eth_get_drvinfo(struct net_device *net_dev,
7272
{
7373
struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
7474

75-
strlcpy(drvinfo->driver, KBUILD_MODNAME, sizeof(drvinfo->driver));
75+
strscpy(drvinfo->driver, KBUILD_MODNAME, sizeof(drvinfo->driver));
7676

7777
snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
7878
"%u.%u", priv->dpni_ver_major, priv->dpni_ver_minor);
7979

80-
strlcpy(drvinfo->bus_info, dev_name(net_dev->dev.parent->parent),
80+
strscpy(drvinfo->bus_info, dev_name(net_dev->dev.parent->parent),
8181
sizeof(drvinfo->bus_info));
8282
}
8383

@@ -191,11 +191,11 @@ static void dpaa2_eth_get_strings(struct net_device *netdev, u32 stringset,
191191
switch (stringset) {
192192
case ETH_SS_STATS:
193193
for (i = 0; i < DPAA2_ETH_NUM_STATS; i++) {
194-
strlcpy(p, dpaa2_ethtool_stats[i], ETH_GSTRING_LEN);
194+
strscpy(p, dpaa2_ethtool_stats[i], ETH_GSTRING_LEN);
195195
p += ETH_GSTRING_LEN;
196196
}
197197
for (i = 0; i < DPAA2_ETH_NUM_EXTRA_STATS; i++) {
198-
strlcpy(p, dpaa2_ethtool_extras[i], ETH_GSTRING_LEN);
198+
strscpy(p, dpaa2_ethtool_extras[i], ETH_GSTRING_LEN);
199199
p += ETH_GSTRING_LEN;
200200
}
201201
if (dpaa2_eth_has_mac(priv))

0 commit comments

Comments
 (0)