Remark: src/tools/show.c
Derrick Lyndon Pallas
derrick at pallas.us
Sat Aug 31 18:34:45 CEST 2019
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';
>
More information about the WireGuard
mailing list