From c81fde1aa474108ba5c0b74e66b9e91a2a41b5e1 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 15 Apr 2020 16:40:14 +0200 Subject: [PATCH] Better document buffer lengths --- src/io.c | 2 +- src/ipv4.c | 12 ++++++++---- tests/lint/line_length.py | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/io.c b/src/io.c index 2c6abc5..ee4f028 100644 --- a/src/io.c +++ b/src/io.c @@ -473,7 +473,7 @@ static void *ssl_read(void *arg) if (tunnel->state == STATE_CONNECTING) { if (packet_is_ip_plus_dns(packet)) { - char line[57]; // 1 + 15 + 7 + 15 + 2 + 15 + 1 + 1 + char line[ARRAY_SIZE("[xxx.xxx.xxx.xxx], ns [xxx.xxx.xxx.xxx, xxx.xxx.xxx.xxx]")]; set_tunnel_ips(tunnel, packet); strcpy(line, "["); diff --git a/src/ipv4.c b/src/ipv4.c index 037ddea..fcc78a6 100644 --- a/src/ipv4.c +++ b/src/ipv4.c @@ -1056,8 +1056,10 @@ int ipv4_add_nameservers_to_resolv_conf(struct tunnel *tunnel) int ret = -1; FILE *file; struct stat stat; - char ns1[28], ns2[28]; // 11 + 15 + 1 + 1 - char dns_suffix[MAX_DOMAIN_LENGTH+8]; // 7 + MAX_DOMAIN_LENGTH + 1 + static const size_t NS_SIZE = ARRAY_SIZE("nameserver xxx.xxx.xxx.xxx"); + char ns1[NS_SIZE], ns2[NS_SIZE]; + static const size_t DNS_SUFFIX_SIZE = ARRAY_SIZE("search ") + MAX_DOMAIN_LENGTH; + char dns_suffix[DNS_SUFFIX_SIZE]; char *buffer = NULL; int use_resolvconf = 0; @@ -1254,8 +1256,10 @@ int ipv4_del_nameservers_from_resolv_conf(struct tunnel *tunnel) int ret = -1; FILE *file; struct stat stat; - char ns1[27], ns2[27]; // 11 + 15 + 1 - char dns_suffix[MAX_DOMAIN_LENGTH+8]; // 7 + MAX_DOMAIN_LENGTH + 1 + static const size_t NS_SIZE = ARRAY_SIZE("nameserver xxx.xxx.xxx.xxx"); + char ns1[NS_SIZE], ns2[NS_SIZE]; + static const size_t DNS_SUFFIX_SIZE = ARRAY_SIZE("search ") + MAX_DOMAIN_LENGTH; + char dns_suffix[DNS_SUFFIX_SIZE]; char *buffer = NULL; char *saveptr = NULL; diff --git a/tests/lint/line_length.py b/tests/lint/line_length.py index 9783910..3fc695f 100755 --- a/tests/lint/line_length.py +++ b/tests/lint/line_length.py @@ -39,7 +39,7 @@ def endswithstring(line): True if line ends with string, False otherwise. """ - for end in ('"', '",', '");', '";', '" \\'): + for end in ('"', '",', '");', '";', '" \\', ')];'): if line.endswith(end): return True return False -- GitLab