nvmet: use strlcpy() instead of strcpy()
authorBart Van Assche <bvanassche@acm.org>
Mon, 8 Oct 2018 21:28:51 +0000 (14:28 -0700)
committerChristoph Hellwig <hch@lst.de>
Wed, 17 Oct 2018 06:58:26 +0000 (08:58 +0200)
Although the code modified by this patch looks fine to me, this patch avoids
that Coverity reports the following complaint (ID 1364971 and ID 1364973):
"You might overrun the 256-character fixed-size string id->subnqn".

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
drivers/nvme/target/admin-cmd.c
drivers/nvme/target/discovery.c

index 7a45f4477679ae2600025848101c06c527a9009d..1179f631432369030d09490382cb712393cc7d74 100644 (file)
@@ -353,7 +353,7 @@ static void nvmet_execute_identify_ctrl(struct nvmet_req *req)
        if (req->port->inline_data_size)
                id->sgls |= cpu_to_le32(1 << 20);
 
-       strcpy(id->subnqn, ctrl->subsys->subsysnqn);
+       strlcpy(id->subnqn, ctrl->subsys->subsysnqn, sizeof(id->subnqn));
 
        /* Max command capsule size is sqe + single page of in-capsule data */
        id->ioccsz = cpu_to_le32((sizeof(struct nvme_command) +
index d1954f4ca28d499d4009ca54adc47196f60b01cb..bc0aa0bf1543dc539256948f13663674dec5d166 100644 (file)
@@ -174,7 +174,7 @@ static void nvmet_execute_identify_disc_ctrl(struct nvmet_req *req)
        if (req->port->inline_data_size)
                id->sgls |= cpu_to_le32(1 << 20);
 
-       strcpy(id->subnqn, ctrl->subsys->subsysnqn);
+       strlcpy(id->subnqn, ctrl->subsys->subsysnqn, sizeof(id->subnqn));
 
        status = nvmet_copy_to_sgl(req, 0, id, sizeof(*id));