2018-05-29 06:50:34

by Nick Desaulniers

[permalink] [raw]
Subject: [PATCH] nvme: prefer strlcpy to strncpy

Fixes a stringop-truncation warning from gcc-8.

Signed-off-by: Nick Desaulniers <[email protected]>
---
drivers/nvme/host/core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 99b857e..b823ecb 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -2017,7 +2017,7 @@ static void nvme_init_subnqn(struct nvme_subsystem *subsys, struct nvme_ctrl *ct

nqnlen = strnlen(id->subnqn, NVMF_NQN_SIZE);
if (nqnlen > 0 && nqnlen < NVMF_NQN_SIZE) {
- strncpy(subsys->subnqn, id->subnqn, NVMF_NQN_SIZE);
+ strlcpy(subsys->subnqn, id->subnqn, NVMF_NQN_SIZE);
return;
}

--
2.7.4



2018-05-29 08:06:28

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH] nvme: prefer strlcpy to strncpy

On Mon, May 28, 2018 at 11:49:18PM -0700, Nick Desaulniers wrote:
> Fixes a stringop-truncation warning from gcc-8.

What would that warning be? Maybe it actually is genuinly useful,
and switching to strlcpy just papers over it..

2018-05-30 02:03:27

by Nick Desaulniers

[permalink] [raw]
Subject: Re: [PATCH] nvme: prefer strlcpy to strncpy

On Tue, May 29, 2018 at 1:11 AM, Christoph Hellwig <[email protected]> wrote:
> On Mon, May 28, 2018 at 11:49:18PM -0700, Nick Desaulniers wrote:
>> Fixes a stringop-truncation warning from gcc-8.
>
> What would that warning be? Maybe it actually is genuinly useful,
> and switching to strlcpy just papers over it..

Eric also pointed out to me that strlcpy will not initialize the rest
of dest with zeros if size is less than the length of src.