Re: [PATCH V2] net: ethernet: myricom: myri10ge: myri10ge.c: Cleaning up missing null-terminate after strncpy call

From: Jiri Pirko
Date: Wed Aug 13 2014 - 13:06:45 EST


Mon, Aug 11, 2014 at 09:18:16PM CEST, rickard_strandqvist@xxxxxxxxxxxxxxxxxx wrote:
>Added a guaranteed null-terminate after call to strncpy.
>
>Signed-off-by: Rickard Strandqvist <rickard_strandqvist@xxxxxxxxxxxxxxxxxx>
>---
> drivers/net/ethernet/myricom/myri10ge/myri10ge.c | 1 +
> 1 file changed, 1 insertion(+)
>
>diff --git a/drivers/net/ethernet/myricom/myri10ge/myri10ge.c b/drivers/net/ethernet/myricom/myri10ge/myri10ge.c
>index f3d5d79..69c26f0 100644
>--- a/drivers/net/ethernet/myricom/myri10ge/myri10ge.c
>+++ b/drivers/net/ethernet/myricom/myri10ge/myri10ge.c
>@@ -574,6 +574,7 @@ myri10ge_validate_firmware(struct myri10ge_priv *mgp,
>
> /* save firmware version for ethtool */
> strncpy(mgp->fw_version, hdr->version, sizeof(mgp->fw_version));
>+ mgp->fw_version[sizeof(mgp->fw_version) - 1] = '\0';

Why not to use strlcpy?

>
> sscanf(mgp->fw_version, "%d.%d.%d", &mgp->fw_ver_major,
> &mgp->fw_ver_minor, &mgp->fw_ver_tiny);
>--
>1.7.10.4
>
>--
>To unsubscribe from this list: send the line "unsubscribe netdev" in
>the body of a message to majordomo@xxxxxxxxxxxxxxx
>More majordomo info at http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/