From 094aa9c6e3ccd30ae05625de916d5d49cec1e797 Mon Sep 17 00:00:00 2001 From: Brad House Date: Tue, 16 Jul 2024 10:53:52 -0400 Subject: [PATCH] kill some compiler warnings on NetBSD --- src/lib/ares_dns_name.c | 4 ++-- src/lib/ares_event_kqueue.c | 2 +- src/lib/ares_getaddrinfo.c | 2 +- src/lib/ares_send.c | 2 +- src/lib/ares_str.h | 14 ++++++++++++++ src/lib/inet_net_pton.c | 23 +++++++++-------------- src/tools/adig.c | 37 ++++++++++++++++++++++--------------- 7 files changed, 50 insertions(+), 34 deletions(-) diff --git a/src/lib/ares_dns_name.c b/src/lib/ares_dns_name.c index 076d2664..b4bb0980 100644 --- a/src/lib/ares_dns_name.c +++ b/src/lib/ares_dns_name.c @@ -212,7 +212,7 @@ static ares_status_t ares_parse_dns_name_escape(ares__buf_t *namebuf, } /* If next character is a digit, read 2 more digits */ - if (isdigit(c)) { + if (ares__isdigit(c)) { size_t i; unsigned int val = 0; @@ -224,7 +224,7 @@ static ares_status_t ares_parse_dns_name_escape(ares__buf_t *namebuf, return ARES_EBADNAME; } - if (!isdigit(c)) { + if (!ares__isdigit(c)) { return ARES_EBADNAME; } val *= 10; diff --git a/src/lib/ares_event_kqueue.c b/src/lib/ares_event_kqueue.c index aedd99ec..b04e061a 100644 --- a/src/lib/ares_event_kqueue.c +++ b/src/lib/ares_event_kqueue.c @@ -198,7 +198,7 @@ static size_t ares_evsys_kqueue_wait(ares_event_thread_t *e, size_t cnt = 0; if (timeout_ms != 0) { - ts.tv_sec = timeout_ms / 1000; + ts.tv_sec = (time_t)timeout_ms / 1000; ts.tv_nsec = (timeout_ms % 1000) * 1000 * 1000; timeout = &ts; } diff --git a/src/lib/ares_getaddrinfo.c b/src/lib/ares_getaddrinfo.c index 8a195ed0..25825b76 100644 --- a/src/lib/ares_getaddrinfo.c +++ b/src/lib/ares_getaddrinfo.c @@ -252,7 +252,7 @@ static ares_bool_t fake_addrinfo(const char *name, unsigned short port, ares_bool_t valid = ARES_TRUE; const char *p; for (p = name; *p; p++) { - if (!isdigit(*p) && *p != '.') { + if (!ares__isdigit(*p) && *p != '.') { valid = ARES_FALSE; break; } else if (*p == '.') { diff --git a/src/lib/ares_send.c b/src/lib/ares_send.c index 94e7e12b..f6614c62 100644 --- a/src/lib/ares_send.c +++ b/src/lib/ares_send.c @@ -81,7 +81,7 @@ static ares_status_t ares_apply_dns0x20(ares_channel_t *channel, size_t bit; /* Only apply 0x20 to alpha characters */ - if (!isalpha(name[i])) { + if (!ares__isalpha(name[i])) { dns0x20name[i] = name[i]; continue; } diff --git a/src/lib/ares_str.h b/src/lib/ares_str.h index 81353221..d5731be4 100644 --- a/src/lib/ares_str.h +++ b/src/lib/ares_str.h @@ -72,5 +72,19 @@ ares_bool_t ares__is_hostname(const char *str); */ ares_bool_t ares__str_isprint(const char *str, size_t len); +/* We only care about ASCII rules */ +#define ares__isascii(x) (((unsigned char)x) <= 127) +#define ares__isdigit(x) (((unsigned char)x) >= '0' && \ + ((unsigned char)x) <= '9') +#define ares__isxdigit(x) (ares__isdigit(x) || \ + (((unsigned char)x) >= 'a' && \ + ((unsigned char)x) <= 'f') || \ + (((unsigned char)x) >= 'A' && \ + ((unsigned char)x) <= 'Z')) +#define ares__isupper(x) (((unsigned char)x) >= 'A' && \ + ((unsigned char)x) <= 'Z') +#define ares__islower(x) (((unsigned char)x) >= 'a' && \ + ((unsigned char)x) <= 'z') +#define ares__isalpha(x) (ares__islower(x) || ares__isupper(x)) #endif /* __ARES_STR_H */ diff --git a/src/lib/inet_net_pton.c b/src/lib/inet_net_pton.c index 935058da..6321d367 100644 --- a/src/lib/inet_net_pton.c +++ b/src/lib/inet_net_pton.c @@ -32,11 +32,6 @@ #include "ares_ipv6.h" #include "ares_inet_net_pton.h" -#define ISDIGIT(x) (isdigit((int)((unsigned char)x))) -#define ISXDIGIT(x) (isxdigit((int)((unsigned char)x))) -#define ISASCII(x) (((unsigned char)x) <= 127 ? 1 : 0) -#define ISUPPER(x) (isupper((int)((unsigned char)x))) - const struct ares_in6_addr ares_in6addr_any = { { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } } }; @@ -74,16 +69,16 @@ static int ares_inet_net_pton_ipv4(const char *src, unsigned char *dst, const unsigned char *odst = dst; ch = *src++; - if (ch == '0' && (src[0] == 'x' || src[0] == 'X') && ISASCII(src[1]) && - ISXDIGIT(src[1])) { + if (ch == '0' && (src[0] == 'x' || src[0] == 'X') && ares__isascii(src[1]) && + ares__isxdigit(src[1])) { /* Hexadecimal: Eat nybble string. */ if (!size) { goto emsgsize; } dirty = 0; src++; /* skip x or X. */ - while ((ch = *src++) != '\0' && ISASCII(ch) && ISXDIGIT(ch)) { - if (ISUPPER(ch)) { + while ((ch = *src++) != '\0' && ares__isascii(ch) && ares__isxdigit(ch)) { + if (ares__isupper(ch)) { ch = ares__tolower((unsigned char)ch); } n = (int)(strchr(xdigits, ch) - xdigits); @@ -106,7 +101,7 @@ static int ares_inet_net_pton_ipv4(const char *src, unsigned char *dst, } *dst++ = (unsigned char)(tmp << 4); } - } else if (ISASCII(ch) && ISDIGIT(ch)) { + } else if (ares__isascii(ch) && ares__isdigit(ch)) { /* Decimal: eat dotted digit string. */ for (;;) { tmp = 0; @@ -117,7 +112,7 @@ static int ares_inet_net_pton_ipv4(const char *src, unsigned char *dst, if (tmp > 255) { goto enoent; } - } while ((ch = *src++) != '\0' && ISASCII(ch) && ISDIGIT(ch)); + } while ((ch = *src++) != '\0' && ares__isascii(ch) && ares__isdigit(ch)); if (!size--) { goto emsgsize; } @@ -129,7 +124,7 @@ static int ares_inet_net_pton_ipv4(const char *src, unsigned char *dst, goto enoent; } ch = *src++; - if (!ISASCII(ch) || !ISDIGIT(ch)) { + if (!ares__isascii(ch) || !ares__isdigit(ch)) { goto enoent; } } @@ -138,7 +133,7 @@ static int ares_inet_net_pton_ipv4(const char *src, unsigned char *dst, } bits = -1; - if (ch == '/' && ISASCII(src[0]) && ISDIGIT(src[0]) && dst > odst) { + if (ch == '/' && ares__isascii(src[0]) && ares__isdigit(src[0]) && dst > odst) { /* CIDR width specifier. Nothing can follow it. */ ch = *src++; /* Skip over the /. */ bits = 0; @@ -149,7 +144,7 @@ static int ares_inet_net_pton_ipv4(const char *src, unsigned char *dst, if (bits > 32) { goto enoent; } - } while ((ch = *src++) != '\0' && ISASCII(ch) && ISDIGIT(ch)); + } while ((ch = *src++) != '\0' && ares__isascii(ch) && ares__isdigit(ch)); if (ch != '\0') { goto enoent; } diff --git a/src/tools/adig.c b/src/tools/adig.c index 026340c7..d0acb02e 100644 --- a/src/tools/adig.c +++ b/src/tools/adig.c @@ -219,26 +219,33 @@ static ares_bool_t read_cmdline(int argc, const char * const * argv, break; case 'T': - /* Set the TCP port number. */ - if (!isdigit(*state.optarg)) { - snprintf(config->error, sizeof(config->error), "invalid port number"); - return ARES_FALSE; + { + /* Set the TCP port number. */ + long port = strtol(state.optarg, NULL, 0); + + if (port <= 0 || port > 65535) { + snprintf(config->error, sizeof(config->error), "invalid port number"); + return ARES_FALSE; + } + config->options.tcp_port = (unsigned short)port; + config->options.flags |= ARES_FLAG_USEVC; + config->optmask |= ARES_OPT_TCP_PORT; } - config->options.tcp_port = - (unsigned short)strtol(state.optarg, NULL, 0); - config->options.flags |= ARES_FLAG_USEVC; - config->optmask |= ARES_OPT_TCP_PORT; break; case 'U': - /* Set the UDP port number. */ - if (!isdigit(*state.optarg)) { - snprintf(config->error, sizeof(config->error), "invalid port number"); - return ARES_FALSE; + { + /* Set the TCP port number. */ + long port = strtol(state.optarg, NULL, 0); + + if (port <= 0 || port > 65535) { + snprintf(config->error, sizeof(config->error), "invalid port number"); + return ARES_FALSE; + } + config->options.udp_port = (unsigned short)port; + config->options.flags |= ARES_FLAG_USEVC; + config->optmask |= ARES_OPT_UDP_PORT; } - config->options.udp_port = - (unsigned short)strtol(state.optarg, NULL, 0); - config->optmask |= ARES_OPT_UDP_PORT; break; case ':':