All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] s390: scsi: zfcp_aux.c:  Cleaning up missing null-terminate after strncpy call
@ 2014-06-04 21:31 Rickard Strandqvist
  2014-06-04 21:59 ` Heiko Carstens
  0 siblings, 1 reply; 3+ messages in thread
From: Rickard Strandqvist @ 2014-06-04 21:31 UTC (permalink / raw)
  To: Steffen Maier, linux390
  Cc: Rickard Strandqvist, Martin Schwidefsky, Heiko Carstens,
	linux-s390, linux-kernel

Added a guaranteed null-terminate after call to strncpy.

This was partly found using a static code analysis program called cppcheck.

Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
---
 drivers/s390/scsi/zfcp_aux.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/s390/scsi/zfcp_aux.c b/drivers/s390/scsi/zfcp_aux.c
index 8004b07..138b84a 100644
--- a/drivers/s390/scsi/zfcp_aux.c
+++ b/drivers/s390/scsi/zfcp_aux.c
@@ -102,6 +102,7 @@ static void __init zfcp_init_device_setup(char *devstr)
 	if (!token || strlen(token) >= ZFCP_BUS_ID_SIZE)
 		goto err_out;
 	strncpy(busid, token, ZFCP_BUS_ID_SIZE);
+	busid[sizeof(busid) - 1] = '\0';
 
 	token = strsep(&str, ",");
 	if (!token || kstrtoull(token, 0, (unsigned long long *) &wwpn))
-- 
1.7.10.4

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

* Re: [PATCH] s390: scsi: zfcp_aux.c:  Cleaning up missing null-terminate after strncpy call
  2014-06-04 21:31 [PATCH] s390: scsi: zfcp_aux.c: Cleaning up missing null-terminate after strncpy call Rickard Strandqvist
@ 2014-06-04 21:59 ` Heiko Carstens
  2014-06-04 22:22   ` Rickard Strandqvist
  0 siblings, 1 reply; 3+ messages in thread
From: Heiko Carstens @ 2014-06-04 21:59 UTC (permalink / raw)
  To: Rickard Strandqvist
  Cc: Steffen Maier, linux390, Martin Schwidefsky, linux-s390,
	linux-kernel

On Wed, Jun 04, 2014 at 11:31:11PM +0200, Rickard Strandqvist wrote:
> Added a guaranteed null-terminate after call to strncpy.
> 
> This was partly found using a static code analysis program called cppcheck.
> 
> Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
> ---
>  drivers/s390/scsi/zfcp_aux.c |    1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/s390/scsi/zfcp_aux.c b/drivers/s390/scsi/zfcp_aux.c
> index 8004b07..138b84a 100644
> --- a/drivers/s390/scsi/zfcp_aux.c
> +++ b/drivers/s390/scsi/zfcp_aux.c
> @@ -102,6 +102,7 @@ static void __init zfcp_init_device_setup(char *devstr)
>  	if (!token || strlen(token) >= ZFCP_BUS_ID_SIZE)
>  		goto err_out;
>  	strncpy(busid, token, ZFCP_BUS_ID_SIZE);
> +	busid[sizeof(busid) - 1] = '\0';

Erm.. with
	char busid[ZFCP_BUS_ID_SIZE];
just a couple of lines above this seems to be rather pointless.
However _if_ we change the code then replacing strncpy() with strlcpy()
would be the way to go.

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

* Re: [PATCH] s390: scsi: zfcp_aux.c: Cleaning up missing null-terminate after strncpy call
  2014-06-04 21:59 ` Heiko Carstens
@ 2014-06-04 22:22   ` Rickard Strandqvist
  0 siblings, 0 replies; 3+ messages in thread
From: Rickard Strandqvist @ 2014-06-04 22:22 UTC (permalink / raw)
  To: Heiko Carstens
  Cc: Steffen Maier, linux390, Martin Schwidefsky, linux-s390,
	linux-kernel@vger.kernel.org

Hi

A little embarrassing, but I actually did not know that there was a
better replacement for strncpy.

Sorry, but I will send a new platch based on strlcpy instead then.


Best regards
Rickard Strandqvist


2014-06-04 23:59 GMT+02:00 Heiko Carstens <heiko.carstens@de.ibm.com>:
> On Wed, Jun 04, 2014 at 11:31:11PM +0200, Rickard Strandqvist wrote:
>> Added a guaranteed null-terminate after call to strncpy.
>>
>> This was partly found using a static code analysis program called cppcheck.
>>
>> Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
>> ---
>>  drivers/s390/scsi/zfcp_aux.c |    1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/drivers/s390/scsi/zfcp_aux.c b/drivers/s390/scsi/zfcp_aux.c
>> index 8004b07..138b84a 100644
>> --- a/drivers/s390/scsi/zfcp_aux.c
>> +++ b/drivers/s390/scsi/zfcp_aux.c
>> @@ -102,6 +102,7 @@ static void __init zfcp_init_device_setup(char *devstr)
>>       if (!token || strlen(token) >= ZFCP_BUS_ID_SIZE)
>>               goto err_out;
>>       strncpy(busid, token, ZFCP_BUS_ID_SIZE);
>> +     busid[sizeof(busid) - 1] = '\0';
>
> Erm.. with
>         char busid[ZFCP_BUS_ID_SIZE];
> just a couple of lines above this seems to be rather pointless.
> However _if_ we change the code then replacing strncpy() with strlcpy()
> would be the way to go.
>

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

end of thread, other threads:[~2014-06-04 22:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-04 21:31 [PATCH] s390: scsi: zfcp_aux.c: Cleaning up missing null-terminate after strncpy call Rickard Strandqvist
2014-06-04 21:59 ` Heiko Carstens
2014-06-04 22:22   ` Rickard Strandqvist

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.