linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff Moyer <jmoyer@redhat.com>
To: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
Cc: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>,
	Jens Axboe <axboe@kernel.dk>,
	linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] block: bsg.c:  Cleaning up missing null-terminate in conjunction with strncpy
Date: Mon, 28 Jul 2014 10:31:09 -0400	[thread overview]
Message-ID: <x49sillpnbm.fsf@segfault.boston.devel.redhat.com> (raw)
In-Reply-To: <1406383665-1670-1-git-send-email-rickard_strandqvist@spectrumdigital.se> (Rickard Strandqvist's message of "Sat, 26 Jul 2014 16:07:45 +0200")

Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se> writes:

> Replacing strncpy with strlcpy to avoid strings that lacks null terminate.
>
> Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
> ---
>  block/bsg.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/block/bsg.c b/block/bsg.c
> index ff46add..b2688c5 100644
> --- a/block/bsg.c
> +++ b/block/bsg.c
> @@ -790,7 +790,7 @@ static struct bsg_device *bsg_add_device(struct inode *inode,
>  	mutex_lock(&bsg_mutex);
>  	hlist_add_head(&bd->dev_list, bsg_dev_idx_hash(iminor(inode)));
>  
> -	strncpy(bd->name, dev_name(rq->bsg_dev.class_dev), sizeof(bd->name) - 1);
> +	strlcpy(bd->name, dev_name(rq->bsg_dev.class_dev), sizeof(bd->name));
>  	dprintk("bound to <%s>, max queue %d\n",
>  		format_dev_t(buf, inode->i_rdev), bd->max_queue);

NACK

The bsg data structure is allocated using kzalloc, so that last byte
will be zero.

  reply	other threads:[~2014-07-28 14:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-26 14:07 [PATCH] block: bsg.c: Cleaning up missing null-terminate in conjunction with strncpy Rickard Strandqvist
2014-07-28 14:31 ` Jeff Moyer [this message]
2014-07-29 19:09   ` Rickard Strandqvist

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=x49sillpnbm.fsf@segfault.boston.devel.redhat.com \
    --to=jmoyer@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=fujita.tomonori@lab.ntt.co.jp \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=rickard_strandqvist@spectrumdigital.se \
    /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;
as well as URLs for NNTP newsgroup(s).