bfa: Fixes for 0-terminated strncpy and possible null pointer dereference
Subsystems (2)
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
--- drivers/scsi/bfa/bfad_im.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/scsi/bfa/bfad_im.c +6 -3
@@ -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);
Signature · 1 line
1.7.9.5
Quoted 48 lines
-----Original Message-----
From: [email protected] [mailto:linux-scsi- [email protected]] On Behalf Of Jakob Normark
Sent: Thursday, May 16, 2013 1:12 AM
To: Anil Gurumurthy; Vijay Mohan Guvva; James E.J. Bottomley
Cc: [email protected]; [email protected]; Jakob Normark
Subject: [PATCH 1/1] bfa: Fixes for 0-terminated strncpy and possible null pointer dereferenceThis patch fixes two cppcheck errors in
drivers/scsi/bfa/bfad_im.cKernel
version: v3.10-rc1Signed-off-by Jakob Normark <[email protected]>--- drivers/scsi/bfa/bfad_im.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)drivers/scsi/bfa/bfad_im.c index renamed from drivers/scsi/bfa/bfad_im.c +0
-05864f98..9489c56 100644
drivers/scsi/bfa/bfad_im.c +5
-3@@ -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-
Quoted 1 line
bfa_fcs.fabric.bport.port_cfg.sym_name.symname,
drivers/scsi/bfa/bfad_im.c +1
-0BFA_SYMNAME_MAXLEN); + symname[BFA_SYMNAME_MAXLEN -1 ] ='\0' ;sprintf (fc_host_symbolic_name (host),"%s" , symname); fc_host_supported_speeds(host) =
Quoted 3 lines
bfad_im_supported_speeds(&bfad->bfa);
--
1.7.9.5
Changes looks good. Thanks for the patch.
James Bottomley
maintainerQuoted 31 lines · Jakob Normark
This patch fixes two cppcheck errors in
drivers/scsi/bfa/bfad_im.cSigned-off-by Jakob Normark <[email protected]>--- drivers/scsi/bfa/bfad_im.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)drivers/scsi/bfa/bfad_im.c +5
-3@@ -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
drivers/scsi/bfa/bfad_im.c bfad_fc_host_init(struct bfad_im_port_s *im_port) · line 1042
Quoted 4 lines
drivers/scsi/bfa/bfad_im.c +1
-0@@ -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