All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] mdadm: replace hard coded string length
@ 2016-09-16 15:51 Song Liu
  2016-09-17 21:06 ` Jes Sorensen
  0 siblings, 1 reply; 2+ messages in thread
From: Song Liu @ 2016-09-16 15:51 UTC (permalink / raw)
  To: linux-raid; +Cc: Jes.Sorensen, Song Liu

This patch replaces hard coded 32 with sizeof(sb->set_name) in a
couple places.

Signed-off-by: Song Liu <songliubraving@fb.com>
---
 super1.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/super1.c b/super1.c
index 9f62d23..729596f 100644
--- a/super1.c
+++ b/super1.c
@@ -1030,7 +1030,7 @@ static void getinfo_super1(struct supertype *st, struct mdinfo *info, char *map)
 
 	memcpy(info->uuid, sb->set_uuid, 16);
 
-	strncpy(info->name, sb->set_name, 32);
+	strncpy(info->name, sb->set_name, sizeof(info->name) - 1);
 	info->name[32] = 0;
 
 	if ((__le32_to_cpu(sb->feature_map)&MD_FEATURE_REPLACEMENT)) {
@@ -1124,7 +1124,7 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
 		if (c)
 			strncpy(info->name, c+1, 31 - (c-sb->set_name));
 		else
-			strncpy(info->name, sb->set_name, 32);
+			strncpy(info->name, sb->set_name, sizeof(info->name) - 1);
 		info->name[32] = 0;
 	}
 
-- 
2.8.0.rc2


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

* Re: [PATCH v2] mdadm: replace hard coded string length
  2016-09-16 15:51 [PATCH v2] mdadm: replace hard coded string length Song Liu
@ 2016-09-17 21:06 ` Jes Sorensen
  0 siblings, 0 replies; 2+ messages in thread
From: Jes Sorensen @ 2016-09-17 21:06 UTC (permalink / raw)
  To: Song Liu; +Cc: linux-raid

Song Liu <songliubraving@fb.com> writes:
> This patch replaces hard coded 32 with sizeof(sb->set_name) in a
> couple places.
>
> Signed-off-by: Song Liu <songliubraving@fb.com>
> ---
>  super1.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/super1.c b/super1.c
> index 9f62d23..729596f 100644
> --- a/super1.c
> +++ b/super1.c
> @@ -1030,7 +1030,7 @@ static void getinfo_super1(struct supertype *st, struct mdinfo *info, char *map)
>  
>  	memcpy(info->uuid, sb->set_uuid, 16);
>  
> -	strncpy(info->name, sb->set_name, 32);
> +	strncpy(info->name, sb->set_name, sizeof(info->name) - 1);
>  	info->name[32] = 0;
>  
>  	if ((__le32_to_cpu(sb->feature_map)&MD_FEATURE_REPLACEMENT)) {
> @@ -1124,7 +1124,7 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
>  		if (c)
>  			strncpy(info->name, c+1, 31 - (c-sb->set_name));
>  		else
> -			strncpy(info->name, sb->set_name, 32);
> +			strncpy(info->name, sb->set_name, sizeof(info->name) - 1);
>  		info->name[32] = 0;
>  	}

I had to check why this was OK, and technically it is, but I think you
should change the 'info->name[32] = 0' lines as well, to say
'info->name[sizeof(info->name) -1] = '\0'' too.

Sorry for the nitpicking, but I think it's better to be consistent
here.

Cheers,
Jes

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

end of thread, other threads:[~2016-09-17 21:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-16 15:51 [PATCH v2] mdadm: replace hard coded string length Song Liu
2016-09-17 21:06 ` Jes Sorensen

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.