mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Justin Stitt <justinstitt@google.com>
To: yang.yang29@zte.com.cn
Cc: axboe@kernel.dk, linux-block@vger.kernel.org,
	linux-kernel@vger.kernel.org, xu.panda@zte.com.cn,
	linux-hardening@vger.kernel.org
Subject: Re: [PATCH linux-next] block: use strscpy() to instead of strncpy()
Date: Tue, 22 Aug 2023 23:31:56 +0000	[thread overview]
Message-ID: <20230822233156.54ah7nf56y53astz@google.com> (raw)
In-Reply-To: <202212031422587503771@zte.com.cn>

On Sat, Dec 03, 2022 at 02:22:58PM +0800, yang.yang29@zte.com.cn wrote:
> From: Xu Panda <xu.panda@zte.com.cn>
>
> The implementation of strscpy() is more robust and safer.
> That's now the recommended way to copy NUL terminated strings.
>
> Signed-off-by: Xu Panda <xu.panda@zte.com.cn>
> Signed-off-by: Yang Yang <yang.yang29@zte.com>
Reviewed-by: Justin Stitt <justinstitt@google.com>
Cc: linux-hardening@vger.kernel.org

> ---
>  block/partitions/cmdline.c | 12 ++++--------
>  1 file changed, 4 insertions(+), 8 deletions(-)
>
> diff --git a/block/partitions/cmdline.c b/block/partitions/cmdline.c
> index 1af610f0ba8c..c03bc105e575 100644
> --- a/block/partitions/cmdline.c
> +++ b/block/partitions/cmdline.c
> @@ -81,8 +81,7 @@ static int parse_subpart(struct cmdline_subpart **subpart, char *partdef)
>
>  		length = min_t(int, next - partdef,
>  			       sizeof(new_subpart->name) - 1);
> -		strncpy(new_subpart->name, partdef, length);
> -		new_subpart->name[length] = '\0';
> +		strscpy(new_subpart->name, partdef, length);
>
>  		partdef = ++next;
>  	} else
> @@ -140,8 +139,7 @@ static int parse_parts(struct cmdline_parts **parts, const char *bdevdef)
>  	}
>
>  	length = min_t(int, next - bdevdef, sizeof(newparts->name) - 1);
> -	strncpy(newparts->name, bdevdef, length);
> -	newparts->name[length] = '\0';
> +	strscpy(newparts->name, bdevdef, length);
>  	newparts->nr_subparts = 0;
>
>  	next_subpart = &newparts->subpart;
> @@ -153,8 +151,7 @@ static int parse_parts(struct cmdline_parts **parts, const char *bdevdef)
>  		length = (!next) ? (sizeof(buf) - 1) :
>  			min_t(int, next - bdevdef, sizeof(buf) - 1);
>
> -		strncpy(buf, bdevdef, length);
> -		buf[length] = '\0';
> +		strscpy(buf, bdevdef, length);
>
>  		ret = parse_subpart(next_subpart, buf);
>  		if (ret)
> @@ -267,8 +264,7 @@ static int add_part(int slot, struct cmdline_subpart *subpart,
>
>  	label_min = min_t(int, sizeof(info->volname) - 1,
>  			  sizeof(subpart->name));
> -	strncpy(info->volname, subpart->name, label_min);
> -	info->volname[label_min] = '\0';
> +	strscpy(info->volname, subpart->name, label_min);
>
>  	snprintf(tmp, sizeof(tmp), "(%s)", info->volname);
>  	strlcat(state->pp_buf, tmp, PAGE_SIZE);
> --
> 2.15.2

  reply	other threads:[~2023-08-22 23:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-03  6:22 yang.yang29
2023-08-22 23:31 ` Justin Stitt [this message]
2023-08-23  0:08 ` Jens Axboe

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=20230822233156.54ah7nf56y53astz@google.com \
    --to=justinstitt@google.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=xu.panda@zte.com.cn \
    --cc=yang.yang29@zte.com.cn \
    /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

all inboxes | Powered by JetHome®