From: "flichtenheld (Code Review)" Date: Thu, 12 Feb 2026 17:46:46 +0000 References: Reply-To: frank@...2641..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net Message-ID: <10a73d3395452121aa94f164456565a606d4db7c-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="VLIhj+mII18="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: DNS/DHCP: Make _len attributes consistently unsigned List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: openvpn-devel --VLIhj+mII18= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: plaisthos. Hello plaisthos, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/1520?usp=3Demail to review the following change. Change subject: DNS/DHCP: Make _len attributes consistently unsigned ...................................................................... DNS/DHCP: Make _len attributes consistently unsigned Use unsigned int instead of size_t since 32bit values are quite enough here and this avoids some unneccesary casts. Change-Id: Id2c5df9df32a02e944e13b55f57a2c1928b652f4 Signed-off-by: Frank Lichtenheld --- M include/openvpn-msg.h M src/openvpn/dns.h M src/openvpn/options.c M src/openvpn/tun.c M src/openvpn/tun.h M src/openvpnserv/interactive.c 6 files changed, 62 insertions(+), 78 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/20/1520/1 diff --git a/include/openvpn-msg.h b/include/openvpn-msg.h index 34f50c8..bef20cf 100644 --- a/include/openvpn-msg.h +++ b/include/openvpn-msg.h @@ -103,7 +103,7 @@ interface_t iface; char domains[512]; short family; - int addr_len; + unsigned int addr_len; inet_address_t addr[4]; /* support up to 4 dns addresses */ } dns_cfg_message_t; @@ -130,7 +130,7 @@ { message_header_t header; interface_t iface; - int addr_len; + unsigned int addr_len; inet_address_t addr[4]; /* support up to 4 dns addresses */ } wins_cfg_message_t; diff --git a/src/openvpn/dns.h b/src/openvpn/dns.h index 882e474..51bc2de 100644 --- a/src/openvpn/dns.h +++ b/src/openvpn/dns.h @@ -99,14 +99,14 @@ struct dhcp_options { in_addr_t dns[N_DHCP_ADDR]; - int dns_len; + unsigned int dns_len; struct in6_addr dns6[N_DHCP_ADDR]; - int dns6_len; + unsigned int dns6_len; =20 const char *domain; const char *domain_search_list[N_SEARCH_LIST_LEN]; - int domain_search_list_len; + unsigned int domain_search_list_len; }; struct dns_options diff --git a/src/openvpn/options.c b/src/openvpn/options.c index 6bebeb7..ddd1165 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -1271,23 +1271,21 @@ #ifndef ENABLE_SMALL static void -show_dhcp_option_list(const char *name, const char *const *array, int len) +show_dhcp_option_list(const char *name, const char *const *array, unsigned= int len) { - int i; - for (i =3D 0; i < len; ++i) + for (unsigned int i =3D 0; i < len; ++i) { - msg(D_SHOW_PARMS, " %s[%d] =3D %s", name, i, array[i]); + msg(D_SHOW_PARMS, " %s[%u] =3D %s", name, i, array[i]); } } static void -show_dhcp_option_addrs(const char *name, const in_addr_t *array, int len) +show_dhcp_option_addrs(const char *name, const in_addr_t *array, unsigned = int len) { struct gc_arena gc =3D gc_new(); - int i; - for (i =3D 0; i < len; ++i) + for (unsigned int i =3D 0; i < len; ++i) { - msg(D_SHOW_PARMS, " %s[%d] =3D %s", name, i, print_in_addr_t(arra= y[i], 0, &gc)); + msg(D_SHOW_PARMS, " %s[%u] =3D %s", name, i, print_in_addr_t(arra= y[i], 0, &gc)); } gc_free(&gc); } @@ -1319,12 +1317,12 @@ #endif /* ifdef _WIN32 */ static void -dhcp_option_dns6_parse(const char *parm, struct in6_addr *dns6_list, int *= len, msglvl_t msglevel) +dhcp_option_dns6_parse(const char *parm, struct in6_addr *dns6_list, unsig= ned int *len, msglvl_t msglevel) { struct in6_addr addr; if (*len >=3D N_DHCP_ADDR) { - msg(msglevel, "--dhcp-option DNS: maximum of %d IPv6 dns servers c= an be specified", + msg(msglevel, "--dhcp-option DNS: maximum of %u IPv6 dns servers c= an be specified", N_DHCP_ADDR); } else if (get_ipv6_addr(parm, &addr, NULL, msglevel)) @@ -1333,12 +1331,12 @@ } } static void -dhcp_option_address_parse(const char *name, const char *parm, in_addr_t *a= rray, int *len, +dhcp_option_address_parse(const char *name, const char *parm, in_addr_t *a= rray, unsigned int *len, msglvl_t msglevel) { if (*len >=3D N_DHCP_ADDR) { - msg(msglevel, "--dhcp-option %s: maximum of %d %s servers can be s= pecified", name, + msg(msglevel, "--dhcp-option %s: maximum of %u %s servers can be s= pecified", name, N_DHCP_ADDR, name); } else @@ -3664,7 +3662,7 @@ new->name =3D dhcp->domain; entry =3D &new->next; - for (int i =3D 0; i < dhcp->domain_search_list_len; ++i) + for (unsigned int i =3D 0; i < dhcp->domain_search_list_len; += +i) { ALLOC_OBJ_CLEAR_GC(*entry, struct dns_domain, &dns->gc); struct dns_domain *new =3D *entry; @@ -3674,13 +3672,13 @@ struct dns_server *server =3D dns_server_get(&dns->servers, 0,= &dns->gc); const size_t max_addrs =3D SIZE(server->addr); - for (int i =3D 0; i < dhcp->dns_len && server->addr_count < ma= x_addrs; ++i) + for (unsigned int i =3D 0; i < dhcp->dns_len && server->addr_c= ount < max_addrs; ++i) { server->addr[server->addr_count].in.a4.s_addr =3D htonl(dh= cp->dns[i]); server->addr[server->addr_count].family =3D AF_INET; server->addr_count +=3D 1; } - for (int i =3D 0; i < dhcp->dns6_len && server->addr_count < m= ax_addrs; ++i) + for (unsigned int i =3D 0; i < dhcp->dns6_len && server->addr_= count < max_addrs; ++i) { server->addr[server->addr_count].in.a6 =3D dhcp->dns6[i]; server->addr[server->addr_count].family =3D AF_INET6; diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c index 87b6569..1fa9ab0 100644 --- a/src/openvpn/tun.c +++ b/src/openvpn/tun.c @@ -103,7 +103,7 @@ static void windows_set_mtu(const int iface_index, const short family, con= st int mtu); -static void netsh_set_dns6_servers(const struct in6_addr *addr_list, const= int addr_len, +static void netsh_set_dns6_servers(const struct in6_addr *addr_list, const= unsigned int addr_len, DWORD adapter_index); static void netsh_command(const struct argv *a, int n, msglvl_t msglevel); @@ -112,11 +112,6 @@ static const char *netsh_get_id(const char *dev_node, struct gc_arena *gc); -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wsign-compare" -#endif - static bool do_address_service(const bool add, const short family, const struct tuntap= *tt) { @@ -247,8 +242,8 @@ ack_message_t ack; struct gc_arena gc =3D gc_new(); HANDLE pipe =3D tt->options.msg_channel; - int len =3D family =3D=3D AF_INET6 ? tt->options.dns6_len : tt->option= s.dns_len; - int addr_len =3D add ? len : 0; + unsigned int len =3D family =3D=3D AF_INET6 ? tt->options.dns6_len : t= t->options.dns_len; + unsigned int addr_len =3D add ? len : 0; const char *ip_proto_name =3D family =3D=3D AF_INET6 ? "IPv6" : "IPv4"; if (len =3D=3D 0) @@ -273,11 +268,11 @@ { addr_len =3D _countof(dns.addr); dns.addr_len =3D addr_len; - msg(M_WARN, "Number of %s DNS addresses sent to service truncated = to %d", ip_proto_name, - addr_len); + msg(M_WARN, "Number of %s DNS addresses sent to service truncated = to %u", + ip_proto_name, addr_len); } - for (int i =3D 0; i < addr_len; ++i) + for (unsigned int i =3D 0; i < addr_len; ++i) { if (family =3D=3D AF_INET6) { @@ -317,7 +312,7 @@ ack_message_t ack; struct gc_arena gc =3D gc_new(); HANDLE pipe =3D tt->options.msg_channel; - int addr_len =3D add ? tt->options.wins_len : 0; + unsigned int addr_len =3D add ? tt->options.wins_len : 0; if (tt->options.wins_len =3D=3D 0) { @@ -338,10 +333,10 @@ { addr_len =3D _countof(wins.addr); wins.addr_len =3D addr_len; - msg(M_WARN, "Number of WINS addresses sent to service truncated to= %d", addr_len); + msg(M_WARN, "Number of WINS addresses sent to service truncated to= %u", addr_len); } - for (int i =3D 0; i < addr_len; ++i) + for (unsigned int i =3D 0; i < addr_len; ++i) { wins.addr[i].ipv4.s_addr =3D htonl(tt->options.wins[i]); } @@ -368,10 +363,6 @@ gc_free(&gc); } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif - static bool do_set_mtu_service(const struct tuntap *tt, const short family, const int = mtu) { @@ -1998,13 +1989,13 @@ /* Prefer IPv6 DNS servers, * Android will use the DNS server in the order we specify*/ - for (int i =3D 0; i < tt->options.dns6_len; i++) + for (unsigned int i =3D 0; i < tt->options.dns6_len; i++) { management_android_control(management, "DNS6SERVER", print_in6_addr(tt->options.dns6[i], 0, = &gc)); } - for (int i =3D 0; i < tt->options.dns_len; i++) + for (unsigned int i =3D 0; i < tt->options.dns_len; i++) { management_android_control(management, "DNSSERVER", print_in_addr_t(tt->options.dns[i], 0, = &gc)); @@ -4922,10 +4913,10 @@ msg(D_TUNTAP_INFO, "End ipconfig commands for register-dns..."); } -void -ip_addr_string_to_array(in_addr_t *dest, int *dest_len, const IP_ADDR_STRI= NG *src) +static void +ip_addr_string_to_array(in_addr_t *dest, unsigned int *dest_len, const IP_= ADDR_STRING *src) { - int i =3D 0; + unsigned int i =3D 0; while (src) { const unsigned int getaddr_flags =3D GETADDR_HOST_ORDER; @@ -4967,11 +4958,11 @@ } static bool -ip_addr_one_to_one(const in_addr_t *a1, const int a1len, const IP_ADDR_STR= ING *ias) +ip_addr_one_to_one(const in_addr_t *a1, const unsigned int a1len, const IP= _ADDR_STRING *ias) { - in_addr_t a2[8]; - int a2len =3D SIZE(a2); - int i; +#define MAX_ADDRS 8 + in_addr_t a2[MAX_ADDRS]; + unsigned int a2len =3D MAX_ADDRS; ip_addr_string_to_array(a2, &a2len, ias); /*msg (M_INFO, "a1len=3D%d a2len=3D%d", a1len, a2len);*/ @@ -4980,7 +4971,7 @@ return false; } - for (i =3D 0; i < a1len; ++i) + for (unsigned int i =3D 0; i < a1len; ++i) { if (a1[i] !=3D a2[i]) { @@ -4993,12 +4984,11 @@ static bool ip_addr_member_of(const in_addr_t addr, const IP_ADDR_STRING *ias) { - in_addr_t aa[8]; - int len =3D SIZE(aa); - int i; + in_addr_t aa[MAX_ADDRS]; + unsigned int len =3D MAX_ADDRS; ip_addr_string_to_array(aa, &len, ias); - for (i =3D 0; i < len; ++i) + for (unsigned int i =3D 0; i < len; ++i) { if (addr =3D=3D aa[i]) { @@ -5007,6 +4997,7 @@ } return false; } +#undef MAX_ADDRS /** * Set the ipv6 dns servers on the specified interface. @@ -5014,7 +5005,7 @@ * are cleared first. */ static void -netsh_set_dns6_servers(const struct in6_addr *addr_list, const int addr_le= n, DWORD adapter_index) +netsh_set_dns6_servers(const struct in6_addr *addr_list, const unsigned in= t addr_len, DWORD adapter_index) { struct gc_arena gc =3D gc_new(); struct argv argv =3D argv_new(); @@ -5024,7 +5015,7 @@ NETSH_PATH_SUFFIX, adapter_index); netsh_command(&argv, 2, M_FATAL); - for (int i =3D 0; i < addr_len; ++i) + for (unsigned int i =3D 0; i < addr_len; ++i) { const char *fmt =3D (i =3D=3D 0) ? "%s%s interface ipv6 set dns %l= u static %s" : "%s%s interface ipv6 add dns %lu %s"; @@ -5043,7 +5034,7 @@ } static void -netsh_ifconfig_options(const char *type, const in_addr_t *addr_list, const= int addr_len, +netsh_ifconfig_options(const char *type, const in_addr_t *addr_list, const= unsigned int addr_len, const IP_ADDR_STRING *current, DWORD adapter_index,= const bool test_first) { struct gc_arena gc =3D gc_new(); @@ -5074,14 +5065,13 @@ /* add new DNS/WINS settings to TAP interface */ { - int count =3D 0; - int i; - for (i =3D 0; i < addr_len; ++i) + bool first =3D true; + for (unsigned int i =3D 0; i < addr_len; ++i) { if (delete_first || !test_first || !ip_addr_member_of(addr_lis= t[i], current)) { - const char *fmt =3D count ? "%s%s interface ip add %s %lu = %s" - : "%s%s interface ip set %s %lu st= atic %s"; + const char *fmt =3D first ? "%s%s interface ip set %s %lu = static %s" + : "%s%s interface ip add %s %lu %s= "; argv_printf(&argv, fmt, get_win_sys_path(), NETSH_PATH_SUF= FIX, type, adapter_index, print_in_addr_t(addr_list[i], 0, &gc)); @@ -5094,7 +5084,7 @@ netsh_command(&argv, 2, M_FATAL); - ++count; + first =3D false; } else { @@ -6094,7 +6084,7 @@ struct argv argv =3D argv_new(); /* delete ipvX dns servers if any were set */ - int len =3D ipv6 ? tt->options.dns6_len : tt->options.dns_len; + unsigned int len =3D ipv6 ? tt->options.dns6_len : tt->options.dns_len; if (len > 0) { argv_printf(&argv, "%s%s interface %s delete dns %lu all", get_win= _sys_path(), diff --git a/src/openvpn/tun.h b/src/openvpn/tun.h index 388f5b7..962a079 100644 --- a/src/openvpn/tun.h +++ b/src/openvpn/tun.h @@ -109,25 +109,25 @@ /* DNS (6) */ in_addr_t dns[N_DHCP_ADDR]; - int dns_len; + unsigned int dns_len; /* WINS (44) */ in_addr_t wins[N_DHCP_ADDR]; - int wins_len; + unsigned int wins_len; /* NTP (42) */ in_addr_t ntp[N_DHCP_ADDR]; - int ntp_len; + unsigned int ntp_len; /* NBDD (45) */ in_addr_t nbdd[N_DHCP_ADDR]; - int nbdd_len; + unsigned int nbdd_len; #define N_SEARCH_LIST_LEN 10 /* Max # of entries in domin-search list */ /* SEARCH (119), MacOS, Linux, Win10 1809+ */ const char *domain_search_list[N_SEARCH_LIST_LEN]; - int domain_search_list_len; + unsigned int domain_search_list_len; /* DISABLE_NBT (43, Vendor option 001) */ bool disable_nbt; @@ -138,7 +138,7 @@ bool register_dns; struct in6_addr dns6[N_DHCP_ADDR]; - int dns6_len; + unsigned int dns6_len; #if defined(TARGET_ANDROID) const char *http_proxy; int http_proxy_port; diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c index b50aeb3..c96d3f2 100644 --- a/src/openvpnserv/interactive.c +++ b/src/openvpnserv/interactive.c @@ -1814,10 +1814,10 @@ { DWORD err =3D 0; undo_type_t undo_type =3D (msg->family =3D=3D AF_INET6) ? undo_dns6 : = undo_dns4; - int addr_len =3D msg->addr_len; + unsigned int addr_len =3D msg->addr_len; /* sanity check */ - const int max_addrs =3D _countof(msg->addr); + const unsigned int max_addrs =3D _countof(msg->addr); if (addr_len > max_addrs) { addr_len =3D max_addrs; @@ -1875,7 +1875,7 @@ * time constant by all compilers and constexpr is C23 */ CHAR addrs[_countof(msg->addr) * 64]; /* 64 is enough for one IPv4= /6 address */ size_t offset =3D 0; - for (int i =3D 0; i < addr_len; ++i) + for (unsigned int i =3D 0; i < addr_len; ++i) { if (i !=3D 0) { @@ -2936,14 +2936,10 @@ { DWORD err =3D NO_ERROR; wchar_t addr[16]; /* large enough to hold string representation of an = ipv4 */ - int addr_len =3D msg->addr_len; + unsigned int addr_len =3D msg->addr_len; /* sanity check */ - if (addr_len < 0) - { - addr_len =3D 0; - } - if ((unsigned int)addr_len > _countof(msg->addr)) + if (addr_len > _countof(msg->addr)) { addr_len =3D _countof(msg->addr); } @@ -2971,7 +2967,7 @@ goto out; /* job done */ } - for (int i =3D 0; i < addr_len; ++i) + for (unsigned int i =3D 0; i < addr_len; ++i) { RtlIpv4AddressToStringW(&msg->addr[i].ipv4, addr); err =3D netsh_wins_cmd(i =3D=3D 0 ? L"set" : L"add", msg->iface.in= dex, addr); -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1520?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: newchange Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Id2c5df9df32a02e944e13b55f57a2c1928b652f4 Gerrit-Change-Number: 1520 Gerrit-PatchSet: 1 Gerrit-Owner: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos --VLIhj+mII18= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is cur= rently required from: plaisthos.

flichtenheld would like plaisthos to review this change.

V= iew Change

DNS/DHCP: Make _len attributes consistently=
 unsigned

Use unsigned int instead of size_t since 32bit
values a= re quite enough here and this avoids some
unneccesary casts.

Chan= ge-Id: Id2c5df9df32a02e944e13b55f57a2c1928b652f4
Signed-off-by: Frank Li= chtenheld <frank@...2641...>
---
M include/openvpn-msg.h
M s= rc/openvpn/dns.h
M src/openvpn/options.c
M src/openvpn/tun.c
M src= /openvpn/tun.h
M src/openvpnserv/interactive.c
6 files changed, 62 in= sertions(+), 78 deletions(-)

git pull ssh://gerr=
it.openvpn.net:29418/openvpn refs/changes/20/1520/1
diff --git a/in=
clude/openvpn-msg.h b/include/openvpn-msg.h
index 34f50c8..= bef20cf 100644
--- a/include/openvpn-msg.h
= +++ b/include/openvpn-msg.h
@@ -103,7 +103,7 @@
<= span> interface_t iface;
char domains[512];=
short family;
- int addr_len;
+ unsigned int addr_len;
inet_address_t addr[4]= ; /* support up to 4 dns addresses */
} dns_cfg_message_t;=

@@ -130,7 +130,7 @@
{
message_header_t header;
interface= _t iface;
- int addr= _len;
+ unsigned i= nt addr_len;
inet_address_t addr[4]; /* support up to = 4 dns addresses */
} wins_cfg_message_t;
=
diff --git a/src/openvpn/dns.h b/src/openvpn/dns.h<= br>index 882e474..51bc2de 100644
--- a/src/openvpn/dn= s.h
+++ b/src/openvpn/dns.h
@@ -99,14 +99,1= 4 @@
struct dhcp_options
{
in_addr_t dns[N_DHCP_ADDR];

- int dns_len;
+ unsigned int dns_len;

= struct in6_addr dns6[N_DHCP_ADDR];
- int dns6_len;
+ unsigned int dns6_len;

= const char *domain;
const char *domain_search_list[N= _SEARCH_LIST_LEN];
- = int domain_search_list_len;
+ unsigned int domain_search_list_len;
};

struct dns_options
diff --git= a/src/openvpn/options.c b/src/openvpn/options.c
index 6beb= eb7..ddd1165 100644
--- a/src/openvpn/options.c
<= span>+++ b/src/openvpn/options.c

@@ -1271,23 +1271,21 @@
#ifndef ENABLE_SMALL

stat= ic void
-show_dhcp_opti= on_list(const char *name, const char *const *array, int len)
+show_dhcp_option_list(const char *= name, const char *const *array, unsigned int len)

{=
- int i;
- for (i =3D 0; i < len; ++i)
+ for (unsigned int i = =3D 0; i < len; ++i)
{
- msg(D_SHOW_PARMS, " %s[%d] =3D %s&qu= ot;, name, i, array[i]);
+ msg(D_SHOW_PARMS, " %s[%u] =3D %s", name, i, array[= i]);
}
}

= static void
-sho= w_dhcp_option_addrs(const char *name, const in_addr_t *array, int len)
+show_dhcp_option_addrs(c= onst char *name, const in_addr_t *array, unsigned int len)
= {
struct gc_arena gc =3D gc_new();
- int i;
- for (i =3D 0; i < len; ++i)
+ for (unsigned int i =3D 0; i <= ; len; ++i)
{
- msg(D_SHOW_PARMS, " %s[%d] =3D %s", name, i= , print_in_addr_t(array[i], 0, &gc));
+ msg(D_SHOW_PARMS, " %s[%u] =3D %s"= , name, i, print_in_addr_t(array[i], 0, &gc));
}
gc_free(&gc);
}
@@= -1319,12 +1317,12 @@
#endif /* ifdef _WIN32 */
=
static void
-dhcp_option_dns6_parse(const char *parm, struct in6_addr *dn= s6_list, int *len, msglvl_t msglevel)
+dhcp_option_dns6_parse(const char *parm, struct in6_addr = *dns6_list, unsigned int *len, msglvl_t msglevel)
{=
struct in6_addr addr;
if (*len >=3D = N_DHCP_ADDR)
{
- msg(msglevel, "--dhcp-option DNS: maximum of %d = IPv6 dns servers can be specified",
+ msg(msglevel, "--dhcp-option DNS: maximum= of %u IPv6 dns servers can be specified",
= N_DHCP_ADDR);
}
else if (get_ip= v6_addr(parm, &addr, NULL, msglevel))
@@ -1333,12 +1331= ,12 @@
}
}
static vo= id
-dhcp_option_address= _parse(const char *name, const char *parm, in_addr_t *array, int *len,
+dhcp_option_address_pars= e(const char *name, const char *parm, in_addr_t *array, unsigned int *len,<= /span>
msglvl_t msglevel)
{

if (*len >=3D N_DHCP_ADDR)
= {
- msg(msgle= vel, "--dhcp-option %s: maximum of %d %s servers can be specified"= ;, name,
+ msg= (msglevel, "--dhcp-option %s: maximum of %u %s servers can be specifie= d", name,
N_DHCP_ADDR, name);
<= span> }

else
@@ -3664,7 +3662,7 @@=
new->name =3D dhcp->domain;
<= span> entry =3D &new->next;


= - for (int i =3D 0; i = < dhcp->domain_search_list_len; ++i)
+ for (unsigned int i =3D 0; i < dhcp-&= gt;domain_search_list_len; ++i)
{
ALLOC_OBJ_CLEAR_GC(*entry, struct dns_domain, &dns= ->gc);

struct dns_domain *new =3D *entr= y;
@@ -3674,13 +3672,13 @@

struct dns_server *server =3D dns_server_get(&dns->se= rvers, 0, &dns->gc);

const size_t max_a= ddrs =3D SIZE(server->addr);
- for (int i =3D 0; i < dhcp->dns_len && = server->addr_count < max_addrs; ++i)
+ for (unsigned int i =3D 0; i < dhcp-&= gt;dns_len && server->addr_count < max_addrs; ++i)
= {
server->addr[serve= r->addr_count].in.a4.s_addr =3D htonl(dhcp->dns[i]);
= server->addr[server->addr_count].family =3D AF_INET;=
server->addr_count +=3D 1;
<= span> }
- = for (int i =3D 0; i < dhcp->dns6_len && server->= addr_count < max_addrs; ++i)
+ for (unsigned int i =3D 0; i < dhcp->dns6_len= && server->addr_count < max_addrs; ++i)
= {
server->addr[server->addr= _count].in.a6 =3D dhcp->dns6[i];
server= ->addr[server->addr_count].family =3D AF_INET6;
diff = --git a/src/openvpn/tun.c b/src/openvpn/tun.c
index 87b6569= ..1fa9ab0 100644
--- a/src/openvpn/tun.c
++= + b/src/openvpn/tun.c
@@ -103,7 +103,7 @@
=
static void windows_set_mtu(const int iface_index, const = short family, const int mtu);

-static void netsh_set_dns6_servers(const struct i= n6_addr *addr_list, const int addr_len,
+static void netsh_set_dns6_servers(const struct in6_add= r *addr_list, const unsigned int addr_len,
= DWORD adapter_index);

static void netsh_command(const struct argv *a, int n, msglvl_t msglevel)= ;
@@ -112,11 +112,6 @@

s= tatic const char *netsh_get_id(const char *dev_node, struct gc_arena *gc);<= /span>

-#if = defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-compare= "
-#endif-
static bool<= /span>
do_address_service(const bool add, const short family, con= st struct tuntap *tt)
{
@@ -247,8 +242,8 @= @
ack_message_t ack;
struct gc_ar= ena gc =3D gc_new();
HANDLE pipe =3D tt->options.ms= g_channel;
- int len= =3D family =3D=3D AF_INET6 ? tt->options.dns6_len : tt->options.dns_= len;
- int addr_len = =3D add ? len : 0;
+ = unsigned int len =3D family =3D=3D AF_INET6 ? tt->options.dns6_len : = tt->options.dns_len;
+ unsigned int addr_len =3D add ? len : 0;
const= char *ip_proto_name =3D family =3D=3D AF_INET6 ? "IPv6" : "= IPv4";

if (len =3D=3D 0)=
@@ -273,11 +268,11 @@
{
= addr_len =3D _countof(dns.addr);
dns.addr_len= =3D addr_len;
- = msg(M_WARN, "Number of %s DNS addresses sent to service truncated to = %d", ip_proto_name,
+ msg(M_WARN, "Number of %s DNS addresses sent to service = truncated to %u",
- for (int i = =3D 0; i < addr_len; ++i)
+ for (unsigned int i =3D 0; i < addr_len; ++i)
{

if (family =3D=3D AF_INET6)
{

@@ -317,7 +312,7 @@
ack= _message_t ack;
struct gc_arena gc =3D gc_new();

HANDLE pipe =3D tt->options.msg_channel;
- int addr_len =3D add ? tt->opt= ions.wins_len : 0;
+ = unsigned int addr_len =3D add ? tt->options.wins_len : 0;
<= span>
if (tt->options.wins_len =3D=3D 0) {
@@ -338,10 +333,10 @@
{<= /span>
addr_len =3D _countof(wins.addr);
= wins.addr_len =3D addr_len;
- msg(M_WARN, "Number of WINS addresses sent to s= ervice truncated to %d", addr_len);
+ msg(M_WARN, "Number of WINS addresses sen= t to service truncated to %u", addr_len);
}


- for (= int i =3D 0; i < addr_len; ++i)
+ for (unsigned int i =3D 0; i < addr_len; ++i)<= br> {
wins.addr[i].ipv4.s_addr =3D htonl= (tt->options.wins[i]);
}
@@ -368,10= +363,6 @@
gc_free(&gc);
}=

-#if define= d(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
static bool
do_set_mtu_service(const s= truct tuntap *tt, const short family, const int mtu)
{
@@ -1998,13 +1989,13 @@

= /* Prefer IPv6 DNS servers,
* Android will use the D= NS server in the order we specify*/
- for (int i =3D 0; i < tt->options.dns6_len; i++)
+ for (unsigned int = i =3D 0; i < tt->options.dns6_len; i++)
{=
management_android_control(management, "DNS6SERVER&= quot;,
print_in6_addr(t= t->options.dns6[i], 0, &gc));
}

- for (int i =3D = 0; i < tt->options.dns_len; i++)
+ for (unsigned int i =3D 0; i < tt->options.dns= _len; i++)
{
management_andro= id_control(management, "DNSSERVER",
= print_in_addr_t(tt->options.dns[i], 0, &gc));=
@@ -4922,10 +4913,10 @@
msg(D_TUNTAP_= INFO, "End ipconfig commands for register-dns...");
}


-void
-ip_addr_string_= to_array(in_addr_t *dest, int *dest_len, const IP_ADDR_STRING *src)<= br>+static void
+ip_addr_string_to_array(in_addr_t *= dest, unsigned int *dest_len, const IP_ADDR_STRING *src)
{=
- int i =3D 0;
+ unsigned int i =3D 0= ;
while (src)
{
= const unsigned int getaddr_flags =3D GETADDR_HOST_ORDER;
= @@ -4967,11 +4958,11 @@
}
static bool
-i= p_addr_one_to_one(const in_addr_t *a1, const int a1len, const IP_ADDR_STRIN= G *ias)
+ip_addr_one_= to_one(const in_addr_t *a1, const unsigned int a1len, const IP_ADDR_STRING = *ias)
{
- int a2len =3D SIZE(a2);
- int i;
+#= define MAX_ADDRS 8
+ = in_addr_t a2[MAX_ADDRS];
+ unsigned int a2len =3D MAX_ADDRS;

<= span> ip_addr_string_to_array(a2, &a2len, ias);

= /*msg (M_INFO, "a1len=3D%d a2len=3D%d", a1len, a2len);*/=
@@ -4980,7 +4971,7 @@
return false;
}

- for (i =3D 0; i < a1len; ++i)
+ for (unsigned int i =3D 0; i < a1l= en; ++i)
{
if (a1[i] !=3D a2[= i])
{
@@ -4993,12 +4984,11 @@
static bool
ip_addr_member_of(const in_addr_t= addr, const IP_ADDR_STRING *ias)
{
- in_addr_t aa[8];
- int len =3D SIZE(aa);
- int i;
+ in_addr_t aa[MAX_ADDRS];
+ unsigned int len =3D MAX_ADDRS;

ip_addr_string_to_array(aa, &len, i= as);
- for (i =3D 0;= i < len; ++i)
+ = for (unsigned int i =3D 0; i < len; ++i)
{=
if (addr =3D=3D aa[i])
{=
@@ -5007,6 +4997,7 @@
}
= return false;
}
+#undef MAX_ADDRS

/**

* Set the ipv6 dns servers on the specified interface.<= br>@@ -5014,7 +5005,7 @@
* are cleared first.
*/
static void
-netsh_set_dns6_servers(const struct in6_addr *addr_l= ist, const int addr_len, DWORD adapter_index)
+netsh_set_dns6_servers(const struct in6_addr *add= r_list, const unsigned int addr_len, DWORD adapter_index)
= {
struct gc_arena gc =3D gc_new();
= struct argv argv =3D argv_new();
@@ -5024,7 +5015,7 @@
NETSH_PATH_SUFFIX, adapter_index); netsh_command(&argv, 2, M_FATAL);
<= br>- for (int i =3D 0; i < = addr_len; ++i)
+ f= or (unsigned int i =3D 0; i < addr_len; ++i)
{
const char *fmt =3D (i =3D=3D 0) ? "%s%s interfac= e ipv6 set dns %lu static %s"
= : "%s%s interface ipv6 add dns %lu %s";
@@ -5043,7 +5034,7 @@

}

static void

-netsh_= ifconfig_options(const char *type, const in_addr_t *addr_list, const int ad= dr_len,
+netsh_ifconf= ig_options(const char *type, const in_addr_t *addr_list, const unsigned int= addr_len,
const IP_ADDR_STRING *cu= rrent, DWORD adapter_index, const bool test_first)
{
struct gc_arena gc =3D gc_new();
@@ -5074,1= 4 +5065,13 @@

/* add new DNS/WINS se= ttings to TAP interface */
{
- int count =3D 0;
- int i;
- for (i =3D 0; i < addr_len; ++i)=
+ bool first =3D tru= e;
+ for (unsi= gned int i =3D 0; i < addr_len; ++i)
{ if (delete_first || !test_first || !ip_addr_member_of(= addr_list[i], current))
{
- const char *fmt =3D count = ? "%s%s interface ip add %s %lu %s"
- : "%s%= s interface ip set %s %lu static %s";
+ const char *fmt =3D first ? "%s= %s interface ip set %s %lu static %s"
+ : "%s%s= interface ip add %s %lu %s";

= argv_printf(&argv, fmt, get_win_sys_path(), NETSH_PATH_SUFFI= X, type, adapter_index,
print_= in_addr_t(addr_list[i], 0, &gc));
@@ -5094,7 +5084,7 @@=

netsh_command(&argv= , 2, M_FATAL);

- ++count;
+ first =3D false;
= }
else
{
@@ -6094,7 +6084,7 @@
struct argv argv =3D = argv_new();

/* delete ipvX dns serve= rs if any were set */
-= int len =3D ipv6 ? tt->options.dns6_len : tt->options.dns_len;
+ unsigned int len = =3D ipv6 ? tt->options.dns6_len : tt->options.dns_len;
if (len > 0)

{
argv= _printf(&argv, "%s%s interface %s delete dns %lu all", get_wi= n_sys_path(),
diff --git a/src/openvpn/tun.h b/src/openvpn/= tun.h
index 388f5b7..962a079 100644
--- a/s= rc/openvpn/tun.h
+++ b/src/openvpn/tun.h
@@= -109,25 +109,25 @@

/* DNS (6) */
in_addr_t dns[N_DHCP_ADDR];
- int dns_len;
+ unsigned int dns_len;
/* WINS (44) */
in_addr_t wins[N_DHCP_ADDR= ];
- int wins_len;
+ unsigned int wins= _len;

/* NTP (42) */
in_addr_t ntp[N_DHCP_ADDR];

- int ntp_len;
+ unsigned int ntp_len;

/= * NBDD (45) */
in_addr_t nbdd[N_DHCP_ADDR];
= - int nbdd_len;
+ unsigned int nbdd_len;
<= br>
#define N_SEARCH_LIST_LEN 10 /* Max # of entrie= s in domin-search list */

/* SEARCH = (119), MacOS, Linux, Win10 1809+ */
const char *domain= _search_list[N_SEARCH_LIST_LEN];
- int domain_search_list_len;
+ unsigned int domain_search_list_len;
<= span>

/* DISABLE_NBT (43, Vendor option 001) */
bool disable_nbt;
@@ -138,7 +138,7 @@
bool register_dns;

s= truct in6_addr dns6[N_DHCP_ADDR];
- int dns6_len;
+ unsigned int dns6_len;
#if defined(TARGET_AN= DROID)
const char *http_proxy;
in= t http_proxy_port;
diff --git a/src/openvpnserv/interactive= .c b/src/openvpnserv/interactive.c
index b50aeb3..c96d3f2 1= 00644
--- a/src/openvpnserv/interactive.c
+= ++ b/src/openvpnserv/interactive.c
@@ -1814,10 +1814,10 @@<= /span>
{
DWORD err =3D 0;
= undo_type_t undo_type =3D (msg->family =3D=3D AF_INET6) ? undo_dns6 := undo_dns4;
- int ad= dr_len =3D msg->addr_len;
+ unsigned int addr_len =3D msg->addr_len;
<= /span>
/* sanity check */
- const int max_addrs =3D _countof(msg->addr);
+ const unsigned int ma= x_addrs =3D _countof(msg->addr);
if (addr_len > = max_addrs)
{
addr_len =3D max= _addrs;
@@ -1875,7 +1875,7 @@
* t= ime constant by all compilers and constexpr is C23 */
= CHAR addrs[_countof(msg->addr) * 64]; /* 64 is enough for one IPv4/6= address */
size_t offset =3D 0;
- for (int i =3D 0; i < addr_l= en; ++i)
+ for= (unsigned int i =3D 0; i < addr_len; ++i)
{
if (i !=3D 0)
{
@@ -2936,14 +2936,10 @@
{
= DWORD err =3D NO_ERROR;
wchar_t addr[16]; /* large e= nough to hold string representation of an ipv4 */
- int addr_len =3D msg->addr_len;+ unsigned int addr_len = =3D msg->addr_len;

/* sanity chec= k */
- if (addr_len = < 0)
- {- addr_len =3D 0;=
- }
- if ((unsigned int)addr_len > _counto= f(msg->addr))
+ = if (addr_len > _countof(msg->addr))
{ addr_len =3D _countof(msg->addr);
}=
@@ -2971,7 +2967,7 @@
goto out; /= * job done */
}

- for (int i =3D 0; i < addr_len; ++i= )
+ for (unsigned = int i =3D 0; i < addr_len; ++i)
{
= RtlIpv4AddressToStringW(&msg->addr[i].ipv4, addr); err =3D netsh_wins_cmd(i =3D=3D 0 ? L"set" : L&qu= ot;add", msg->iface.index, addr);

=

To view, visit change 1520. To unsubscribe, or for help writing mail filters= , visit settings= .

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id2c5df9df32a02e944e13b55f57= a2c1928b652f4
Gerrit-Change-Number: 1520
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
= --VLIhj+mII18=--