From: Jes Sorensen <Jes.Sorensen@redhat.com>
To: Song Liu <songliubraving@fb.com>
Cc: linux-raid@vger.kernel.org
Subject: Re: [PATCH] mdadm: replace hard coded string length
Date: Thu, 15 Sep 2016 12:15:30 -0400 [thread overview]
Message-ID: <wrfjr38lxhp9.fsf@redhat.com> (raw)
In-Reply-To: <1473898407-3049094-1-git-send-email-songliubraving@fb.com> (Song Liu's message of "Wed, 14 Sep 2016 17:13:27 -0700")
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..7d03b1f 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(sb->set_name));
> 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(sb->set_name));
> info->name[32] = 0;
> }
I was about to apply this, but this is actually wrong. You need to use
the size of the destination, not of the source as the limit.
Sorry for the hassle.
Jes
next prev parent reply other threads:[~2016-09-15 16:15 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-15 0:13 [PATCH] mdadm: replace hard coded string length Song Liu
2016-09-15 16:15 ` Jes Sorensen [this message]
2016-09-15 18:10 ` Thomas Fjellstrom
2016-09-15 23:34 ` Adam Goryachev
2016-09-16 12:38 ` Jes Sorensen
2016-09-16 12:34 ` Jes Sorensen
2016-09-20 18:03 ` Thomas Fjellstrom
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=wrfjr38lxhp9.fsf@redhat.com \
--to=jes.sorensen@redhat.com \
--cc=linux-raid@vger.kernel.org \
--cc=songliubraving@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.