netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2] net: ethernet: myricom: myri10ge: myri10ge.c:  Cleaning up missing null-terminate after strncpy call
@ 2014-08-11 19:18 Rickard Strandqvist
  2014-08-11 21:57 ` David Miller
  2014-08-13 17:06 ` Jiri Pirko
  0 siblings, 2 replies; 4+ messages in thread
From: Rickard Strandqvist @ 2014-08-11 19:18 UTC (permalink / raw)
  To: Hyong-Youb Kim, netdev; +Cc: Rickard Strandqvist, linux-kernel

Added a guaranteed null-terminate after call to strncpy.

Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
---
 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';
 
 	sscanf(mgp->fw_version, "%d.%d.%d", &mgp->fw_ver_major,
 	       &mgp->fw_ver_minor, &mgp->fw_ver_tiny);
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH V2] net: ethernet: myricom: myri10ge: myri10ge.c: Cleaning up missing null-terminate after strncpy call
  2014-08-11 19:18 [PATCH V2] net: ethernet: myricom: myri10ge: myri10ge.c: Cleaning up missing null-terminate after strncpy call Rickard Strandqvist
@ 2014-08-11 21:57 ` David Miller
  2014-08-13 17:06 ` Jiri Pirko
  1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2014-08-11 21:57 UTC (permalink / raw)
  To: rickard_strandqvist; +Cc: hykim, netdev, linux-kernel

From: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
Date: Mon, 11 Aug 2014 21:18:16 +0200

> Added a guaranteed null-terminate after call to strncpy.
> 
> Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>

Applied.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH V2] net: ethernet: myricom: myri10ge: myri10ge.c: Cleaning up missing null-terminate after strncpy call
  2014-08-11 19:18 [PATCH V2] net: ethernet: myricom: myri10ge: myri10ge.c: Cleaning up missing null-terminate after strncpy call Rickard Strandqvist
  2014-08-11 21:57 ` David Miller
@ 2014-08-13 17:06 ` Jiri Pirko
  2014-08-16 21:18   ` Rickard Strandqvist
  1 sibling, 1 reply; 4+ messages in thread
From: Jiri Pirko @ 2014-08-13 17:06 UTC (permalink / raw)
  To: Rickard Strandqvist; +Cc: Hyong-Youb Kim, netdev, linux-kernel

Mon, Aug 11, 2014 at 09:18:16PM CEST, rickard_strandqvist@spectrumdigital.se wrote:
>Added a guaranteed null-terminate after call to strncpy.
>
>Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
>---
> 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@vger.kernel.org
>More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH V2] net: ethernet: myricom: myri10ge: myri10ge.c: Cleaning up missing null-terminate after strncpy call
  2014-08-13 17:06 ` Jiri Pirko
@ 2014-08-16 21:18   ` Rickard Strandqvist
  0 siblings, 0 replies; 4+ messages in thread
From: Rickard Strandqvist @ 2014-08-16 21:18 UTC (permalink / raw)
  To: Jiri Pirko; +Cc: Hyong-Youb Kim, Network Development, linux-kernel

2014-08-13 19:06 GMT+02:00 Jiri Pirko <jiri@resnulli.us>:
> Mon, Aug 11, 2014 at 09:18:16PM CEST, rickard_strandqvist@spectrumdigital.se wrote:
>>Added a guaranteed null-terminate after call to strncpy.
>>
>>Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
>>---
>> 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


Hi

Sure, strlcpy is preferable in many ways if we only can guarantee that
it is safe.
I have seldom received so much criticism when I start switching to
strlcpy, although much of it was justified :)
Even Linus was getting into the debate.  See more:

https://plus.google.com/111049168280159033135/posts/1amLbuhWbh5


I change to strlcpy only when I'm sure it will not cause any other problems.
But if you or anyone else can guarantee that in this case, so I'd make
a new patch with strlcpy.


Kind regards

Rickard Strandqvist

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-08-16 21:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-11 19:18 [PATCH V2] net: ethernet: myricom: myri10ge: myri10ge.c: Cleaning up missing null-terminate after strncpy call Rickard Strandqvist
2014-08-11 21:57 ` David Miller
2014-08-13 17:06 ` Jiri Pirko
2014-08-16 21:18   ` Rickard Strandqvist

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).