Remark: src/tools/show.c

Markus Grundmann markus at activezone.de
Sat Aug 31 12:41:58 CEST 2019


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


More information about the WireGuard mailing list