From: Gal Ofri <gal.ofri@volumez.com>
To: "NeilBrown" <neilb@suse.de>, linux-raid@vger.kernel.org
Cc: "Nigel Croxon" <ncroxon@redhat.com>,
jes@trained-monkey.org, xni@redhat.com,
mariusz.tkaczyk@linux.intel.com
Subject: Re: [PATCH V2] Fix buffer size warning for strcpy
Date: Sun, 22 Aug 2021 17:30:40 +0300 [thread overview]
Message-ID: <20210822173040.532510ec@gofri-dell> (raw)
In-Reply-To: <20210822172657.2d3405db@gofri-dell>
> > You really should explain here why we change from filling with spaces to
> > filling with nuls.
> I guess that a commit-comment would still be needed, but I think that a
> more conventional approach could make it all clearer:
>
> - memset(ve->name, ' ', 16);
> - if (name)
> - strncpy(ve->name, name, 16);
> + int l = strnlen(ve->name, 16);
> + memcpy(ve->name, name, l);
> + if (l < 16) /* no null-termination expected when all the space is used */
> + ve->name[l] = '\0';
>
> Cheers,
> Gal
my bad - I obviously meant strnlen(name, 16).
next prev parent reply other threads:[~2021-08-22 14:30 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-19 13:10 [PATCH V2] Fix buffer size warning for strcpy Nigel Croxon
2021-08-19 22:16 ` NeilBrown
2021-08-22 14:26 ` Gal Ofri
2021-08-22 14:30 ` Gal Ofri [this message]
2021-08-22 22:05 ` NeilBrown
2021-08-23 6:55 ` Tkaczyk, Mariusz
2021-08-23 22:46 ` NeilBrown
2021-08-24 7:36 ` hillr
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=20210822173040.532510ec@gofri-dell \
--to=gal.ofri@volumez.com \
--cc=jes@trained-monkey.org \
--cc=linux-raid@vger.kernel.org \
--cc=mariusz.tkaczyk@linux.intel.com \
--cc=ncroxon@redhat.com \
--cc=neilb@suse.de \
--cc=xni@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox