* Remark: src/tools/show.c
@ 2019-08-31 10:41 Markus Grundmann
2019-08-31 16:34 ` Derrick Lyndon Pallas
0 siblings, 1 reply; 2+ messages in thread
From: Markus Grundmann @ 2019-08-31 10:41 UTC (permalink / raw)
To: wireguard
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';
--
Best regards,
Markus
Better Privacy with PGP encrypted Mail: http://activezone.de/pgp/
Fingerprint: 58C5 8BAF 6FCE B24F 1881 B5B8 F2A8 E1D0 484B 0054
Threema ID: 7ZRET2JY
„Wer die Freiheit aufgibt um Sicherheit zu gewinnen,
der wird am Ende beides verlieren.“ -- Benjamin Franklin
_______________________________________________
WireGuard mailing list
WireGuard@lists.zx2c4.com
https://lists.zx2c4.com/mailman/listinfo/wireguard
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Remark: src/tools/show.c
2019-08-31 10:41 Remark: src/tools/show.c Markus Grundmann
@ 2019-08-31 16:34 ` Derrick Lyndon Pallas
0 siblings, 0 replies; 2+ messages in thread
From: Derrick Lyndon Pallas @ 2019-08-31 16:34 UTC (permalink / raw)
To: Markus Grundmann, wireguard
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-08-31 16:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-31 10:41 Remark: src/tools/show.c Markus Grundmann
2019-08-31 16:34 ` Derrick Lyndon Pallas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).