[prev in list] [next in list] [prev in thread] [next in thread]
List: wireguard
Subject: Re: Remark: src/tools/show.c
From: Derrick Lyndon Pallas <derrick () pallas ! us>
Date: 2019-08-31 16:34:45
Message-ID: becd57f5-4c36-ac33-f616-f359c7221186 () pallas ! us
[Download RAW message or body]
Forcing later callers to assume state about a buffer is not better. Re:
strncpy, the explicit termination *is* required, since the destination
will not be null terminated if the source is the same size. Also,
doesn't this patch remove the "ago" response? ~Derrick
On 8/31/19 3:41 AM, Markus Grundmann wrote:
> I think the explicit termination (buf[] = '\0') is not needed. Personaly
> I would prefer memset() to clean up the buffer. strncopy() reduced by
> two instead of a single chars protects the last string terminator. But
> we will not die when it not was changed
>
> [src/tools/show.c]
> ==> endpoint() <==
> 122,123c122
> - strncpy(buf, gai_strerror(ret), sizeof(buf) - 1);
> - buf[sizeof(buf) - 1] = '\0';
> ---
> + strncpy(buf, gai_strerror(ret), sizeof(buf) - 2);
> 162a162
> + memset(buf, 0, sizeof(buf));
> 164c164
> - strncpy(buf, "Now", sizeof(buf) - 1);
> ---
> + strncpy(buf, "Now", sizeof(buf) - 2);
>
> ==> ago() <==
> 166c166
> - strncpy(buf, "(" TERMINAL_FG_RED "System clock wound backward;
> connection problems may ensue." TERMINAL_RESET ")", sizeof(buf) - 1);
> ---
> + strncpy(buf, "(" TERMINAL_FG_RED "System clock wound backward;
> connection problems may ensue." TERMINAL_RESET ")", sizeof(buf) - 2);
> 169c169
> - strncpy(buf + offset, " ago", sizeof(buf) - offset - 1);
> ---
> - strncpy(buf + offset, " ago", sizeof(buf) - offset - 2);
> 171d170
> - buf[sizeof(buf) - 1] = '\0';
>
_______________________________________________
WireGuard mailing list
WireGuard@lists.zx2c4.com
https://lists.zx2c4.com/mailman/listinfo/wireguard
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic