Replacing strncpy with strlcpy to avoid strings that lacks null terminate.
And use the sizeof on the to string rather than strlen on the from string.

Signed-off-by: Rickard Strandqvist <rickard_strandqv...@spectrumdigital.se>
---
 drivers/scsi/bfa/bfa_fcbuild.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/bfa/bfa_fcbuild.c b/drivers/scsi/bfa/bfa_fcbuild.c
index dce787f..9294c14 100644
--- a/drivers/scsi/bfa/bfa_fcbuild.c
+++ b/drivers/scsi/bfa/bfa_fcbuild.c
@@ -1249,8 +1249,8 @@ fc_rspnid_build(struct fchs_s *fchs, void *pyld, u32 
s_id, u16 ox_id,
        memset(rspnid, 0, sizeof(struct fcgs_rspnid_req_s));
 
        rspnid->dap = s_id;
-       rspnid->spn_len = (u8) strlen((char *)name);
-       strncpy((char *)rspnid->spn, (char *)name, rspnid->spn_len);
+       strlcpy((char *)rspnid->spn, (char *)name, sizeof(rspnid->spn));
+       rspnid->spn_len = (u8) strlen((char *)rspnid->spn);
 
        return sizeof(struct fcgs_rspnid_req_s) + sizeof(struct ct_hdr_s);
 }
@@ -1270,8 +1270,8 @@ fc_rsnn_nn_build(struct fchs_s *fchs, void *pyld, u32 
s_id,
        memset(rsnn_nn, 0, sizeof(struct fcgs_rsnn_nn_req_s));
 
        rsnn_nn->node_name = node_name;
-       rsnn_nn->snn_len = (u8) strlen((char *)name);
-       strncpy((char *)rsnn_nn->snn, (char *)name, rsnn_nn->snn_len);
+       strlcpy((char *)rsnn_nn->snn, (char *)name, sizeof(rsnn_nn->snn));
+       rsnn_nn->snn_len = (u8) strlen((char *)rsnn_nn->snn);
 
        return sizeof(struct fcgs_rsnn_nn_req_s) + sizeof(struct ct_hdr_s);
 }
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to