git: da4230af3fda - main - nvme/f: Use strlcpy instead of strncpy + manual string termination
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 13 May 2024 19:04:21 UTC
The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=da4230af3fda2d4d1898124689f2e07b1450876d commit da4230af3fda2d4d1898124689f2e07b1450876d Author: John Baldwin <jhb@FreeBSD.org> AuthorDate: 2024-05-13 19:04:03 +0000 Commit: John Baldwin <jhb@FreeBSD.org> CommitDate: 2024-05-13 19:04:03 +0000 nvme/f: Use strlcpy instead of strncpy + manual string termination Reviewed by: dab, imp Sponsored by: Chelsio Communications Differential Revision: https://reviews.freebsd.org/D45153 --- sys/dev/nvme/nvme_ctrlr.c | 3 +-- sys/dev/nvme/nvme_ns.c | 3 +-- sys/dev/nvmf/host/nvmf.c | 3 +-- sys/dev/nvmf/host/nvmf_ns.c | 3 +-- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/sys/dev/nvme/nvme_ctrlr.c b/sys/dev/nvme/nvme_ctrlr.c index b7b03082c54e..00e619bfdc46 100644 --- a/sys/dev/nvme/nvme_ctrlr.c +++ b/sys/dev/nvme/nvme_ctrlr.c @@ -1334,9 +1334,8 @@ nvme_ctrlr_ioctl(struct cdev *cdev, u_long cmd, caddr_t arg, int flag, case NVME_GET_NSID: { struct nvme_get_nsid *gnsid = (struct nvme_get_nsid *)arg; - strncpy(gnsid->cdev, device_get_nameunit(ctrlr->dev), + strlcpy(gnsid->cdev, device_get_nameunit(ctrlr->dev), sizeof(gnsid->cdev)); - gnsid->cdev[sizeof(gnsid->cdev) - 1] = '\0'; gnsid->nsid = 0; break; } diff --git a/sys/dev/nvme/nvme_ns.c b/sys/dev/nvme/nvme_ns.c index 360b9f982c20..e494b8cd857a 100644 --- a/sys/dev/nvme/nvme_ns.c +++ b/sys/dev/nvme/nvme_ns.c @@ -82,9 +82,8 @@ nvme_ns_ioctl(struct cdev *cdev, u_long cmd, caddr_t arg, int flag, case NVME_GET_NSID: { struct nvme_get_nsid *gnsid = (struct nvme_get_nsid *)arg; - strncpy(gnsid->cdev, device_get_nameunit(ctrlr->dev), + strlcpy(gnsid->cdev, device_get_nameunit(ctrlr->dev), sizeof(gnsid->cdev)); - gnsid->cdev[sizeof(gnsid->cdev) - 1] = '\0'; gnsid->nsid = ns->id; break; } diff --git a/sys/dev/nvmf/host/nvmf.c b/sys/dev/nvmf/host/nvmf.c index 0902bc78a7b5..e43d438aaa8c 100644 --- a/sys/dev/nvmf/host/nvmf.c +++ b/sys/dev/nvmf/host/nvmf.c @@ -872,9 +872,8 @@ nvmf_ioctl(struct cdev *cdev, u_long cmd, caddr_t arg, int flag, return (nvmf_passthrough_cmd(sc, pt, true)); case NVME_GET_NSID: gnsid = (struct nvme_get_nsid *)arg; - strncpy(gnsid->cdev, device_get_nameunit(sc->dev), + strlcpy(gnsid->cdev, device_get_nameunit(sc->dev), sizeof(gnsid->cdev)); - gnsid->cdev[sizeof(gnsid->cdev) - 1] = '\0'; gnsid->nsid = 0; return (0); case NVME_GET_MAX_XFER_SIZE: diff --git a/sys/dev/nvmf/host/nvmf_ns.c b/sys/dev/nvmf/host/nvmf_ns.c index 3ce434bf7c50..3428cbadc974 100644 --- a/sys/dev/nvmf/host/nvmf_ns.c +++ b/sys/dev/nvmf/host/nvmf_ns.c @@ -258,9 +258,8 @@ nvmf_ns_ioctl(struct cdev *dev, u_long cmd, caddr_t arg, int flag, return (nvmf_passthrough_cmd(ns->sc, pt, false)); case NVME_GET_NSID: gnsid = (struct nvme_get_nsid *)arg; - strncpy(gnsid->cdev, device_get_nameunit(ns->sc->dev), + strlcpy(gnsid->cdev, device_get_nameunit(ns->sc->dev), sizeof(gnsid->cdev)); - gnsid->cdev[sizeof(gnsid->cdev) - 1] = '\0'; gnsid->nsid = ns->id; return (0); case DIOCGMEDIASIZE: