From fb361064eb23474f201ce4ad1a2a245a69ffa68e Mon Sep 17 00:00:00 2001 From: Brad House Date: Tue, 31 Oct 2023 15:34:58 -0400 Subject: [PATCH] AppVeyor: update compiler versions, use Msys2, and Windows fixes (#593) AppVeyor was using Visual Studio 2015 along with old versions of MinGW. Update to the latest AppVeyor provides and also add an MSYS2 build test using MinGW which will use the bleeding edge version. When researching #590 this also uncovered a bug in cmake not properly detecting if_indextoname() on windows. This has been corrected as well as the underlying issue reported in #590. Fix By: Brad House (@bradh352) and Jonas Kvinge (@jonaski) --- CMakeLists.txt | 4 +++- Makefile.Watcom | 2 +- Makefile.m32 | 2 +- appveyor.yml | 33 +++++++++++++++++++++--------- configure.ac | 3 ++- src/lib/ares__addrinfo_localhost.c | 2 +- src/lib/ares__socket.c | 4 ++-- src/lib/ares__sortaddrinfo.c | 2 +- src/lib/ares__timeval.c | 4 ++-- src/lib/ares_config.h.cmake | 3 +++ src/lib/ares_fds.c | 2 +- src/lib/ares_getnameinfo.c | 27 ++++++++---------------- src/lib/ares_rand.c | 2 +- src/lib/inet_ntop.c | 4 ++-- test/Makefile.msvc | 4 ++-- 15 files changed, 53 insertions(+), 45 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 54b7a8fd..e19f7bbe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -219,6 +219,7 @@ CHECK_INCLUDE_FILES (sys/uio.h HAVE_SYS_UIO_H) CHECK_INCLUDE_FILES (time.h HAVE_TIME_H) CHECK_INCLUDE_FILES (dlfcn.h HAVE_DLFCN_H) CHECK_INCLUDE_FILES (unistd.h HAVE_UNISTD_H) +CHECK_INCLUDE_FILES (iphlpapi.h HAVE_IPHLPAPI_H) # On OpenBSD, you must include sys/types.h before netinet/tcp.h IF (HAVE_SYS_TYPES_H) @@ -249,7 +250,7 @@ ELSEIF (CMAKE_SYSTEM_NAME STREQUAL "AIX") ELSEIF (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") # Don't define _XOPEN_SOURCE on FreeBSD, it actually reduces visibility instead of increasing it ELSEIF (WIN32) - LIST (APPEND SYSFLAGS -DWIN32_LEAN_AND_MEAN -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -D_WIN32_WINNT=0x0600) + LIST (APPEND SYSFLAGS -DWIN32_LEAN_AND_MEAN -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -D_WIN32_WINNT=0x0602) ENDIF () ADD_DEFINITIONS(${SYSFLAGS}) @@ -316,6 +317,7 @@ CARES_EXTRAINCLUDE_IFSET (HAVE_FCNTL_H fcntl.h) CARES_EXTRAINCLUDE_IFSET (HAVE_UNISTD_H unistd.h) CARES_EXTRAINCLUDE_IFSET (HAVE_WINSOCK2_H winsock2.h) CARES_EXTRAINCLUDE_IFSET (HAVE_WS2TCPIP_H ws2tcpip.h) +CARES_EXTRAINCLUDE_IFSET (HAVE_IPHLPAPI_H iphlpapi.h) CARES_EXTRAINCLUDE_IFSET (HAVE_WINDOWS_H windows.h) # Check Types diff --git a/Makefile.Watcom b/Makefile.Watcom index 6ea10e53..ee31f47d 100644 --- a/Makefile.Watcom +++ b/Makefile.Watcom @@ -55,7 +55,7 @@ LFLAGS += debug all CFLAGS += -d0 !endif -CFLAGS += -d_WIN32_WINNT=0x0600 +CFLAGS += -d_WIN32_WINNT=0x0602 # # Change to suite. diff --git a/Makefile.m32 b/Makefile.m32 index e51e64b3..3d8121fd 100644 --- a/Makefile.m32 +++ b/Makefile.m32 @@ -19,7 +19,7 @@ RANLIB = $(CROSSPREFIX)ranlib #RM = rm -f CP = cp -afv -CFLAGS = $(CARES_CFLAG_EXTRAS) -O2 -Wall -I./include -I./src/lib -D_WIN32_WINNT=0x0600 +CFLAGS = $(CARES_CFLAG_EXTRAS) -O2 -Wall -I./include -I./src/lib -D_WIN32_WINNT=0x0602 CFLAGS += -DCARES_STATICLIB LDFLAGS = $(CARES_LDFLAG_EXTRAS) -s LIBS = -lws2_32 -liphlpapi diff --git a/appveyor.yml b/appveyor.yml index e6b429da..b4572c8c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,7 +1,7 @@ # Copyright (C) The c-ares project and its contributors # SPDX-License-Identifier: MIT -image: Visual Studio 2015 +image: Visual Studio 2022 # Github/Bitbucket only: get source code for one particular commit as zip archive, instead of git clone'ing. shallow_clone: true @@ -21,44 +21,50 @@ configuration: # CMAKE_EXTRA_OPTIONS: -DOPENSSL_ROOT_DIR=C:/OpenSSL-Win32 environment: matrix: + # MinGW via MSYS2 (latest version) + - COMPILER: MINGW + BUILDTOOL: MSYS2-CMAKE + MSYSTEM: MINGW64 + CHERE_INVOKING: YES + # MSVC 2015, 32-bit x86 (cmake) - COMPILER: MSVC BUILDTOOL: CMAKE MSVC_SETUP_ARG: x86 - MSVC_SETUP_PATH: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat + MSVC_SETUP_PATH: C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars32.bat # MSVC 2015, 64-bit x86 (cmake) - COMPILER: MSVC BUILDTOOL: CMAKE MSVC_SETUP_ARG: x64 - MSVC_SETUP_PATH: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat + MSVC_SETUP_PATH: C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat # MinGW, 32-bit x86 (cmake) - COMPILER: MINGW BUILDTOOL: CMAKE - PATH: C:\mingw-w64\i686-5.3.0-posix-dwarf-rt_v4-rev0\mingw32\bin;%PATH% + PATH: C:\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin;%PATH% # MinGW, 32-bit x86 (cmake static only) - COMPILER: MINGW BUILDTOOL: CMAKESTATIC - PATH: C:\mingw-w64\i686-5.3.0-posix-dwarf-rt_v4-rev0\mingw32\bin;%PATH% + PATH: C:\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin;%PATH% # MSVC 2015, 32-bit x86 (nmake) - COMPILER: MSVC BUILDTOOL: NMAKE MSVC_SETUP_ARG: x86 - MSVC_SETUP_PATH: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat + MSVC_SETUP_PATH: C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars32.bat # MSVC 2015, 64-bit x86 (nmake) - COMPILER: MSVC BUILDTOOL: NMAKE MSVC_SETUP_ARG: x64 - MSVC_SETUP_PATH: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat + MSVC_SETUP_PATH: C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat # MinGW, 32-bit x86 (makefiles) - COMPILER: MINGW BUILDTOOL: MAKE - PATH: C:\mingw-w64\i686-5.3.0-posix-dwarf-rt_v4-rev0\mingw32\bin;%PATH% + PATH: C:\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin;%PATH% install: - if "%COMPILER%" == "MINGW" rename "C:\Program Files\Git\usr\bin\sh.exe" "sh2.exe" @@ -67,8 +73,12 @@ before_build: # Setup build environment for the selected compiler (not all compilers need to do anything here). # -- Visual Studio -- - if "%COMPILER%" == "MSVC" call "%MSVC_SETUP_PATH%" %MSVC_SETUP_ARG% + - if "%BUILDTOOL%" == "MSYS2-CMAKE" C:\msys64\usr\bin\bash -lc "pacman --noconfirm -Syuu" + - if "%BUILDTOOL%" == "MSYS2-CMAKE" C:\msys64\usr\bin\bash -lc "pacman --noconfirm -Syu git mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake mingw-w64-x86_64-check mingw-w64-x86_64-ninja" build_script: + - if "%BUILDTOOL%" == "MSYS2-CMAKE" C:\msys64\usr\bin\bash -lc "cmake -GNinja -DCMAKE_BUILD_TYPE=%configuration% -DCMAKE_INSTALL_PREFIX=C:/projects/build-cares/test_install -DCARES_STATIC=ON -DCARES_STATIC_PIC=ON -DCARES_BUILD_TESTS=ON %CMAKE_EXTRA_OPTIONS% ." + - if "%BUILDTOOL%" == "MSYS2-CMAKE" C:\msys64\usr\bin\bash -lc "ninja -v install" - if "%BUILDTOOL%" == "NMAKE" copy .\include\ares_build.h.dist .\include\ares_build.h - if "%BUILDTOOL%" == "NMAKE" nmake /NOLOGO /f .\Makefile.msvc - if "%BUILDTOOL%" == "CMAKE" mkdir C:\projects\build-cares @@ -84,6 +94,9 @@ build_script: test_script: # We can't use powershell for tests due to treating stderr as an error + - if "%BUILDTOOL%" == "MSYS2-CMAKE" C:\msys64\usr\bin\bash -lc "./bin/adig.exe www.google.com" + - if "%BUILDTOOL%" == "MSYS2-CMAKE" C:\msys64\usr\bin\bash -lc "./bin/ahost.exe www.google.com" + - if "%BUILDTOOL%" == "MSYS2-CMAKE" C:\msys64\usr\bin\bash -lc "./bin/arestest.exe -4 -v --gtest_filter=-*LiveSearchTXT*:*LiveSearchANY*:*LiveGetLocalhostByAddr*" - if "%BUILDTOOL%" == "NMAKE" cd test - if "%BUILDTOOL%" == "NMAKE" nmake /NOLOGO /f .\Makefile.msvc vtest - if "%BUILDTOOL%" == "NMAKE" nmake /NOLOGO /f .\Makefile.msvc aresfuzz aresfuzzname dnsdump @@ -95,12 +108,12 @@ test_script: - if "%BUILDTOOL%" == "CMAKE" cd C:\projects\build-cares\bin - if "%BUILDTOOL%" == "CMAKE" .\adig.exe www.google.com - if "%BUILDTOOL%" == "CMAKE" .\ahost.exe www.google.com - - if "%BUILDTOOL%" == "CMAKE" .\arestest.exe -4 -v + - if "%BUILDTOOL%" == "CMAKE" .\arestest.exe -4 -v --gtest_filter=-*LiveSearchTXT*:*LiveSearchANY*:*LiveGetLocalhostByAddr* - if "%BUILDTOOL%" == "CMAKE" .\dnsdump.exe "%APPVEYOR_BUILD_FOLDER%\test\fuzzinput\answer_a" "%APPVEYOR_BUILD_FOLDER%\test\fuzzinput\answer_aaaa" - if "%BUILDTOOL%" == "CMAKESTATIC" cd C:\projects\build-cares\bin - if "%BUILDTOOL%" == "CMAKESTATIC" .\adig.exe www.google.com - if "%BUILDTOOL%" == "CMAKESTATIC" .\ahost.exe www.google.com - - if "%BUILDTOOL%" == "CMAKESTATIC" .\arestest.exe -4 -v + - if "%BUILDTOOL%" == "CMAKESTATIC" .\arestest.exe -4 -v --gtest_filter=-*LiveSearchTXT*:*LiveSearchANY*:*LiveGetLocalhostByAddr* - if "%BUILDTOOL%" == "CMAKESTATIC" .\dnsdump.exe "%APPVEYOR_BUILD_FOLDER%\test\fuzzinput\answer_a" "%APPVEYOR_BUILD_FOLDER%\test\fuzzinput\answer_aaaa" #on_finish: diff --git a/configure.ac b/configure.ac index 518daea1..64ceb904 100644 --- a/configure.ac +++ b/configure.ac @@ -276,7 +276,7 @@ case X-"$ac_cv_native_windows" in CURL_CHECK_HEADER_WINSOCK CURL_CHECK_HEADER_WINSOCK2 CURL_CHECK_HEADER_WS2TCPIP - CPPFLAGS="$CPPFLAGS -D_WIN32_WINNT=0x0600" + CPPFLAGS="$CPPFLAGS -D_WIN32_WINNT=0x0602" ;; *) ac_cv_header_winsock_h="no" @@ -570,6 +570,7 @@ AC_CHECK_HEADERS( sys/param.h \ sys/uio.h \ assert.h \ + iphlpapi.h \ netdb.h \ netinet/in.h \ netinet/tcp.h \ diff --git a/src/lib/ares__addrinfo_localhost.c b/src/lib/ares__addrinfo_localhost.c index 7cdc2f63..65bc412f 100644 --- a/src/lib/ares__addrinfo_localhost.c +++ b/src/lib/ares__addrinfo_localhost.c @@ -137,7 +137,7 @@ static ares_status_t *nodes = NULL; - if (GetUnicastIpAddressTable(aftype, &table) != NO_ERROR) { + if (GetUnicastIpAddressTable((ADDRESS_FAMILY)aftype, &table) != NO_ERROR) { return ARES_ENOTFOUND; } diff --git a/src/lib/ares__socket.c b/src/lib/ares__socket.c index a986c523..d9c6babe 100644 --- a/src/lib/ares__socket.c +++ b/src/lib/ares__socket.c @@ -260,7 +260,7 @@ ares_status_t ares__open_connection(ares_channel channel, case AF_INET: sa = (void *)&saddr.sa4; salen = sizeof(saddr.sa4); - memset(sa, 0, salen); + memset(sa, 0, (size_t)salen); saddr.sa4.sin_family = AF_INET; saddr.sa4.sin_port = port; memcpy(&saddr.sa4.sin_addr, &server->addr.addrV4, @@ -269,7 +269,7 @@ ares_status_t ares__open_connection(ares_channel channel, case AF_INET6: sa = (void *)&saddr.sa6; salen = sizeof(saddr.sa6); - memset(sa, 0, salen); + memset(sa, 0, (size_t)salen); saddr.sa6.sin6_family = AF_INET6; saddr.sa6.sin6_port = port; memcpy(&saddr.sa6.sin6_addr, &server->addr.addrV6, diff --git a/src/lib/ares__sortaddrinfo.c b/src/lib/ares__sortaddrinfo.c index 9093ada1..5a41faa1 100644 --- a/src/lib/ares__sortaddrinfo.c +++ b/src/lib/ares__sortaddrinfo.c @@ -70,7 +70,7 @@ struct addrinfo_sort_elem { #define ARES_IPV6_ADDR_SCOPE_ORGLOCAL 0x08 #define ARES_IPV6_ADDR_SCOPE_GLOBAL 0x0e -#define ARES_IN_LOOPBACK(a) ((((long int)(a)) & 0xff000000) == 0x7f000000) +#define ARES_IN_LOOPBACK(a) ((((long unsigned int)(a)) & 0xff000000) == 0x7f000000) /* RFC 4193. */ #define ARES_IN6_IS_ADDR_ULA(a) (((a)->s6_addr[0] & 0xfe) == 0xfc) diff --git a/src/lib/ares__timeval.c b/src/lib/ares__timeval.c index 68f67212..11996f9f 100644 --- a/src/lib/ares__timeval.c +++ b/src/lib/ares__timeval.c @@ -39,8 +39,8 @@ struct timeval ares__tvnow(void) */ struct timeval now; DWORD milliseconds = GetTickCount(); - now.tv_sec = milliseconds / 1000; - now.tv_usec = (milliseconds % 1000) * 1000; + now.tv_sec = (long)milliseconds / 1000; + now.tv_usec = (long)(milliseconds % 1000) * 1000; return now; } diff --git a/src/lib/ares_config.h.cmake b/src/lib/ares_config.h.cmake index 102805b6..b04d5653 100644 --- a/src/lib/ares_config.h.cmake +++ b/src/lib/ares_config.h.cmake @@ -179,6 +179,9 @@ /* Define to 1 if you have the `resolve' library (-lresolve). */ #cmakedefine HAVE_LIBRESOLV +/* Define to 1 if you have iphlpapi.h */ +#cmakedefine HAVE_IPHLPAPI_H + /* Define to 1 if you have the header file. */ #cmakedefine HAVE_LIMITS_H diff --git a/src/lib/ares_fds.c b/src/lib/ares_fds.c index c1fb794d..0bb4b179 100644 --- a/src/lib/ares_fds.c +++ b/src/lib/ares_fds.c @@ -64,5 +64,5 @@ int ares_fds(ares_channel channel, fd_set *read_fds, fd_set *write_fds) } } - return nfds; + return (int)nfds; } diff --git a/src/lib/ares_getnameinfo.c b/src/lib/ares_getnameinfo.c index b9de85e9..528bd1a1 100644 --- a/src/lib/ares_getnameinfo.c +++ b/src/lib/ares_getnameinfo.c @@ -47,6 +47,9 @@ #ifdef HAVE_NET_IF_H # include #endif +#ifdef HAVE_IPHLPAPI_H +# include +#endif #include "ares.h" #include "ares_ipv6.h" @@ -339,7 +342,6 @@ static void append_scopeid(const struct sockaddr_in6 *addr6, unsigned int flags, # endif char tmpbuf[IF_NAMESIZE + 2]; size_t bufl; - int is_scope_long = sizeof(addr6->sin6_scope_id) > sizeof(unsigned int); tmpbuf[0] = '%'; @@ -347,30 +349,17 @@ static void append_scopeid(const struct sockaddr_in6 *addr6, unsigned int flags, is_ll = IN6_IS_ADDR_LINKLOCAL(&addr6->sin6_addr); is_mcll = IN6_IS_ADDR_MC_LINKLOCAL(&addr6->sin6_addr); if ((flags & ARES_NI_NUMERICSCOPE) || (!is_ll && !is_mcll)) { - if (is_scope_long) { - snprintf(&tmpbuf[1], sizeof(tmpbuf) - 1, "%lu", - (unsigned long)addr6->sin6_scope_id); - } else { - snprintf(&tmpbuf[1], sizeof(tmpbuf) - 1, "%u", addr6->sin6_scope_id); - } + snprintf(&tmpbuf[1], sizeof(tmpbuf) - 1, "%lu", + (unsigned long)addr6->sin6_scope_id); } else { if (if_indextoname(addr6->sin6_scope_id, &tmpbuf[1]) == NULL) { - if (is_scope_long) { - snprintf(&tmpbuf[1], sizeof(tmpbuf) - 1, "%lu", - (unsigned long)addr6->sin6_scope_id); - } else { - snprintf(&tmpbuf[1], sizeof(tmpbuf) - 1, "%u", addr6->sin6_scope_id); - } + snprintf(&tmpbuf[1], sizeof(tmpbuf) - 1, "%lu", + (unsigned long)addr6->sin6_scope_id); } } # else - if (is_scope_long) { - snprintf(&tmpbuf[1], sizeof(tmpbuf) - 1, "%lu", + snprintf(&tmpbuf[1], sizeof(tmpbuf) - 1, "%lu", (unsigned long)addr6->sin6_scope_id); - } else { - snprintf(&tmpbuf[1], sizeof(tmpbuf) - 1, "%u", - (unsigned int)addr6->sin6_scope_id); - } (void)flags; # endif tmpbuf[IF_NAMESIZE + 1] = '\0'; diff --git a/src/lib/ares_rand.c b/src/lib/ares_rand.c index a02658eb..b4747d9f 100644 --- a/src/lib/ares_rand.c +++ b/src/lib/ares_rand.c @@ -273,7 +273,7 @@ static void ares__rand_bytes_fetch(ares_rand_state *state, unsigned char *buf, switch (state->type) { case ARES_RAND_OS: #ifdef _WIN32 - RtlGenRandom(buf, len); + RtlGenRandom(buf, (ULONG)len); return; #elif defined(HAVE_ARC4RANDOM_BUF) arc4random_buf(buf, len); diff --git a/src/lib/inet_ntop.c b/src/lib/inet_ntop.c index f342c5be..447696e3 100644 --- a/src/lib/inet_ntop.c +++ b/src/lib/inet_ntop.c @@ -178,13 +178,13 @@ static const char *inet_ntop6(const unsigned char *src, char *dst, size_t size) if (i == 6 && best.base == 0 && (best.len == 6 || (best.len == 7 && words[7] != 0x0001) || (best.len == 5 && words[5] == 0xffff))) { - if (!inet_ntop4(src + 12, tp, sizeof(tmp) - (tp - tmp))) { + if (!inet_ntop4(src + 12, tp, sizeof(tmp) - (size_t)(tp - tmp))) { return (NULL); } tp += ares_strlen(tp); break; } - tp += snprintf(tp, sizeof(tmp) - (tp - tmp), "%x", words[i]); + tp += snprintf(tp, sizeof(tmp) - (size_t)(tp - tmp), "%x", words[i]); } /* Was it a trailing run of 0x00's? */ if (best.base != -1 && diff --git a/test/Makefile.msvc b/test/Makefile.msvc index cd948c9a..1e0accd3 100644 --- a/test/Makefile.msvc +++ b/test/Makefile.msvc @@ -305,9 +305,9 @@ ALL: arestest aresfuzz aresfuzzname dnsdump @ test: arestest - $(PROG_OUTDIR)\arestest + $(PROG_OUTDIR)\arestest -4 --gtest_filter=-*LiveSearchTXT*:*LiveSearchANY*:*LiveGetLocalhostByAddr* vtest: arestest - $(PROG_OUTDIR)\arestest -v + $(PROG_OUTDIR)\arestest -4 -v --gtest_filter=-*LiveSearchTXT*:*LiveSearchANY*:*LiveGetLocalhostByAddr* arestest: $(TESTSOURCES) $(PROG_OUTDIR) $(PROG_OBJDIR) $(PROG_OBJS) $(GMOCK_GTEST_OBJ) $(SPROG_LINK) $(SPROG_LFLAGS) /out:$(PROG_OUTDIR)\arestest.exe $(PROG_OBJS) $(GMOCK_GTEST_OBJ)