2014-07-26 14:32:30

by Rickard Strandqvist

[permalink] [raw]
Subject: [PATCH] s390: net: ctcm_main.c: Cleaning up missing null-terminate in conjunction with strncpy

Replacing strncpy with strlcpy to avoid strings that lacks null terminate.

Signed-off-by: Rickard Strandqvist <[email protected]>
---
drivers/s390/net/ctcm_main.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/s390/net/ctcm_main.c b/drivers/s390/net/ctcm_main.c
index 03b6ad0..670fa7d 100644
--- a/drivers/s390/net/ctcm_main.c
+++ b/drivers/s390/net/ctcm_main.c
@@ -204,8 +204,8 @@ static void channel_remove(struct channel *ch)

if (ch == NULL)
return;
- else
- strncpy(chid, ch->id, CTCM_ID_SIZE);
+
+ strlcpy(chid, ch->id, CTCM_ID_SIZE);

channel_free(ch);
while (*c) {
--
1.7.10.4


2014-07-29 13:11:11

by Ursula Braun

[permalink] [raw]
Subject: Re: [PATCH] s390: net: ctcm_main.c: Cleaning up missing null-terminate in conjunction with strncpy

On Sat, 2014-07-26 at 16:33 +0200, Rickard Strandqvist wrote:
> Replacing strncpy with strlcpy to avoid strings that lacks null terminate.
>
> Signed-off-by: Rickard Strandqvist <[email protected]>
> ---
> drivers/s390/net/ctcm_main.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/s390/net/ctcm_main.c b/drivers/s390/net/ctcm_main.c
> index 03b6ad0..670fa7d 100644
> --- a/drivers/s390/net/ctcm_main.c
> +++ b/drivers/s390/net/ctcm_main.c
> @@ -204,8 +204,8 @@ static void channel_remove(struct channel *ch)
>
> if (ch == NULL)
> return;
> - else
> - strncpy(chid, ch->id, CTCM_ID_SIZE);
> +
> + strlcpy(chid, ch->id, CTCM_ID_SIZE);
>
> channel_free(ch);
> while (*c) {

It is guaranteed that the string ch->id always fits into CTCM_ID_SIZE.
What's in this case the benefit of replacing strncpy() by strlcpy()
here?

I agree to remove the useless "else".