* [PATCH 1/1] bfa: Fixes for 0-terminated strncpy and possible null pointer dereference
@ 2013-05-15 19:41 Jakob Normark
2013-05-23 12:09 ` Vijay Mohan Guvva
2013-06-26 15:37 ` James Bottomley
0 siblings, 2 replies; 3+ messages in thread
From: Jakob Normark @ 2013-05-15 19:41 UTC (permalink / raw)
To: Anil Gurumurthy, Vijaya Mohan Guvva, James E.J. Bottomley
Cc: linux-scsi, linux-kernel, Jakob Normark
This patch fixes two cppcheck errors in drivers/scsi/bfa/bfad_im.c
Kernel version: v3.10-rc1
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';
sprintf(fc_host_symbolic_name(host), "%s", symname);
fc_host_supported_speeds(host) = bfad_im_supported_speeds(&bfad->bfa);
--
1.7.9.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* RE: [PATCH 1/1] bfa: Fixes for 0-terminated strncpy and possible null pointer dereference
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
1 sibling, 0 replies; 3+ messages in thread
From: Vijay Mohan Guvva @ 2013-05-23 12:09 UTC (permalink / raw)
To: Jakob Normark, Anil Gurumurthy, James E.J. Bottomley
Cc: linux-scsi, linux-kernel
> -----Original Message-----
> From: linux-scsi-owner@vger.kernel.org [mailto:linux-scsi-
> owner@vger.kernel.org] On Behalf Of Jakob Normark
> Sent: Thursday, May 16, 2013 1:12 AM
> To: Anil Gurumurthy; Vijay Mohan Guvva; James E.J. Bottomley
> Cc: linux-scsi@vger.kernel.org; linux-kernel@vger.kernel.org; Jakob Normark
> Subject: [PATCH 1/1] bfa: Fixes for 0-terminated strncpy and possible null
> pointer dereference
>
> This patch fixes two cppcheck errors in drivers/scsi/bfa/bfad_im.c Kernel
> version: v3.10-rc1
>
> 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';
> sprintf(fc_host_symbolic_name(host), "%s", symname);
>
> fc_host_supported_speeds(host) =
> bfad_im_supported_speeds(&bfad->bfa);
> --
> 1.7.9.5
Changes looks good. Thanks for the patch.
Acked-by: Vijay Mohan Guvva <vmohan@brocade.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/1] bfa: Fixes for 0-terminated strncpy and possible null pointer dereference
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
1 sibling, 0 replies; 3+ messages in thread
From: James Bottomley @ 2013-06-26 15:37 UTC (permalink / raw)
To: Jakob Normark
Cc: Anil Gurumurthy, Vijaya Mohan Guvva, linux-scsi, linux-kernel
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-06-26 15:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 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.