All of lore.kernel.org
 help / color / mirror / Atom feed
From: "NeilBrown" <neilb@suse.de>
To: "Nigel Croxon" <ncroxon@redhat.com>
Cc: jes@trained-monkey.org, xni@redhat.com,
	linux-raid@vger.kernel.org, mariusz.tkaczyk@linux.intel.com
Subject: Re: [PATCH V2] Fix buffer size warning for strcpy
Date: Fri, 20 Aug 2021 08:16:43 +1000	[thread overview]
Message-ID: <162941140310.9892.4439598009992795158@noble.neil.brown.name> (raw)
In-Reply-To: <20210819131017.2511208-1-ncroxon@redhat.com>

On Thu, 19 Aug 2021, Nigel Croxon wrote:
> To meet requirements of Common Criteria certification vulnerability
> assessment. Static code analysis has been run and found the following
> error:
> buffer_size_warning: Calling "strncpy" with a maximum size
> argument of 16 bytes on destination array "ve->name" of
> size 16 bytes might leave the destination string unterminated.
> 
> The change is to make the destination size to fit the allocated size.

You really should explain here why we change from filling with spaces to
filling with nuls.

> 
> V2: Change from zero-terminated to zero-padded on memset and
> change from using strncpy to memcpy, feedback from Neil Brown.
> 
> Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
> ---
>  super-ddf.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/super-ddf.c b/super-ddf.c
> index dc8e512..1771316 100644
> --- a/super-ddf.c
> +++ b/super-ddf.c
> @@ -2637,9 +2637,13 @@ static int init_super_ddf_bvd(struct supertype *st,
>  		ve->init_state = DDF_init_not;
>  
>  	memset(ve->pad1, 0xff, 14);
> -	memset(ve->name, ' ', 16);
> -	if (name)
> -		strncpy(ve->name, name, 16);
> +	memset(ve->name, '\0', sizeof(ve->name));
> +	if (name) {
> +		int l = strlen(ve->name);
> +		if (l > 16)
> +			l = 16;
> +		memcpy(ve->name, name, l);
> +	}

Reviewed-by: NeilBrown <neilb@suse.de>

Thanks,
NeilBrown

>  	ddf->virt->populated_vdes =
>  		cpu_to_be16(be16_to_cpu(ddf->virt->populated_vdes)+1);
>  
> -- 
> 2.29.2
> 
> 

  reply	other threads:[~2021-08-19 22:16 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 [this message]
2021-08-22 14:26   ` Gal Ofri
2021-08-22 14:30     ` Gal Ofri
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=162941140310.9892.4439598009992795158@noble.neil.brown.name \
    --to=neilb@suse.de \
    --cc=jes@trained-monkey.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=mariusz.tkaczyk@linux.intel.com \
    --cc=ncroxon@redhat.com \
    --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 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.