public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: James Bottomley <James.Bottomley@HansenPartnership.com>
To: Jakob Normark <jakobnormark@gmail.com>
Cc: Anil Gurumurthy <agurumur@brocade.com>,
	Vijaya Mohan Guvva <vmohan@brocade.com>,
	linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/1] bfa: Fixes for 0-terminated strncpy and possible null pointer dereference
Date: Wed, 26 Jun 2013 08:37:25 -0700	[thread overview]
Message-ID: <1372261045.2168.33.camel@dabdike> (raw)
In-Reply-To: <1368646911-22620-1-git-send-email-jakobnormark@gmail.com>

On Wed, 2013-05-15 at 21:41 +0200, Jakob Normark wrote:
> This patch fixes two cppcheck errors in drivers/scsi/bfa/bfad_im.c
> 
> Signed-off-by: Jakob Normark <jakobnormark@gmail.com>
> ---
>  drivers/scsi/bfa/bfad_im.c |    9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/scsi/bfa/bfad_im.c b/drivers/scsi/bfa/bfad_im.c
> index 5864f98..9489c56 100644
> --- a/drivers/scsi/bfa/bfad_im.c
> +++ b/drivers/scsi/bfa/bfad_im.c
> @@ -944,13 +944,15 @@ static int
>  bfad_im_slave_alloc(struct scsi_device *sdev)
>  {
>  	struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
> -	struct bfad_itnim_data_s *itnim_data =
> -				(struct bfad_itnim_data_s *) rport->dd_data;
> -	struct bfa_s *bfa = itnim_data->itnim->bfa_itnim->bfa;
> +	struct bfad_itnim_data_s *itnim_data;
> +	struct bfa_s *bfa;
>  
>  	if (!rport || fc_remote_port_chkready(rport))
>  		return -ENXIO;
>  
> +	itnim_data = (struct bfad_itnim_data_s *) rport->dd_data;
> +	bfa = itnim_data->itnim->bfa_itnim->bfa;
> +
>  	if (bfa_get_lun_mask_status(bfa) == BFA_LUNMASK_ENABLED) {
>  		/*
>  		 * We should not mask LUN 0 - since this will translate
> @@ -1037,6 +1039,7 @@ bfad_fc_host_init(struct bfad_im_port_s *im_port)
>  
>  	strncpy(symname, bfad->bfa_fcs.fabric.bport.port_cfg.sym_name.symname,
>  		BFA_SYMNAME_MAXLEN);
> +	symname[BFA_SYMNAME_MAXLEN - 1] = '\0';

This isn't correct, it's effectively a handrolled version of strlcpy.
The correct fix is to replace strncpy with strlcpy.  I fixed it up in
the patch version.

James

      parent reply	other threads:[~2013-06-26 15:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-15 19:41 [PATCH 1/1] bfa: Fixes for 0-terminated strncpy and possible null pointer dereference Jakob Normark
2013-05-23 12:09 ` Vijay Mohan Guvva
2013-06-26 15:37 ` James Bottomley [this message]

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=1372261045.2168.33.camel@dabdike \
    --to=james.bottomley@hansenpartnership.com \
    --cc=agurumur@brocade.com \
    --cc=jakobnormark@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=vmohan@brocade.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