diff --git a/deps/cares/CMakeLists.txt b/deps/cares/CMakeLists.txt index 0f3c77ba0aeb8e..d3da9afc75b27b 100644 --- a/deps/cares/CMakeLists.txt +++ b/deps/cares/CMakeLists.txt @@ -12,7 +12,7 @@ INCLUDE (CheckCSourceCompiles) INCLUDE (CheckStructHasMember) INCLUDE (CheckLibraryExists) -PROJECT (c-ares LANGUAGES C VERSION "1.31.0" ) +PROJECT (c-ares LANGUAGES C VERSION "1.32.0" ) # Set this version before release SET (CARES_VERSION "${PROJECT_VERSION}") @@ -30,7 +30,7 @@ INCLUDE (GNUInstallDirs) # include this *AFTER* PROJECT(), otherwise paths are w # For example, a version of 4:0:2 would generate output such as: # libname.so -> libname.so.2 # libname.so.2 -> libname.so.2.2.0 -SET (CARES_LIB_VERSIONINFO "18:0:16") +SET (CARES_LIB_VERSIONINFO "19:0:17") OPTION (CARES_STATIC "Build as a static library" OFF) @@ -62,8 +62,8 @@ ENDIF () INCLUDE (EnableWarnings) -# allow linking against the static runtime library in msvc IF (MSVC) + # allow linking against the static runtime library in msvc OPTION (CARES_MSVC_STATIC_RUNTIME "Link against the static runtime library" OFF) IF (CARES_MSVC_STATIC_RUNTIME) # CMAKE_CONFIGURATION_TYPES is empty on non-IDE generators (Ninja, NMake) @@ -564,7 +564,7 @@ SET (RECVFROM_TYPE_ARG5 "struct sockaddr *") SET (RECV_TYPE_ARG4 int) SET (GETNAMEINFO_TYPE_ARG1 "struct sockaddr *") SET (GETNAMEINFO_TYPE_ARG7 int) -SET (SEND_TYPE_ARG2 "void *") +SET (SEND_TYPE_ARG2 "const void *") SET (SEND_TYPE_ARG4 int) ################################################################################ @@ -663,6 +663,9 @@ ENDIF () IF (HAVE_SYS_SOCKET_H) SET (CARES_HAVE_SYS_SOCKET_H 1) ENDIF() +IF (HAVE_SYS_SELECT_H) + SET (CARES_HAVE_SYS_SELECT_H 1) +ENDIF() IF (HAVE_WS2TCPIP_H) SET (CARES_HAVE_WS2TCPIP_H 1) ENDIF() diff --git a/deps/cares/INSTALL.md b/deps/cares/INSTALL.md index 268157b737971c..dc58ab8c0457ca 100644 --- a/deps/cares/INSTALL.md +++ b/deps/cares/INSTALL.md @@ -42,7 +42,7 @@ unpacked the source archive): You probably need to be root when doing the last command. If you have checked out the sources from the git repository, read the -[GIT-INFO](GIT_INFO) on how to proceed. +[GIT-INFO](GIT-INFO) on how to proceed. Get a full listing of all available configure options by invoking it like: @@ -307,6 +307,16 @@ first to rebuild every single library your app uses as well as your app using the debug multithreaded dynamic C runtime. +### MSYS + +Building is supported for native windows via both AutoTools and CMake. When +building with autotools, you can only build either a shared version or a static +version (use `--disable-shared` or `--disable-static`). CMake can build both +simultaneously. + +All of the MSYS environments are supported: `MINGW32`, `MINGW64`, `UCRT64`, +`CLANG32`, `CLANG64`, `CLANGARM64`. + ### MingW32 Make sure that MinGW32's bin dir is in the search path, for example: @@ -339,6 +349,26 @@ add `-DCARES_STATICLIB` to your `CFLAGS`. Otherwise the linker will look for dynamic import symbols. +DOS +--- + +c-ares supports building as a 32bit protected mode application via +[DJGPP](https://www.delorie.com/djgpp/). It is recommended to use a DJGPP +cross compiler from [Andrew Wu](https://github.com/andrewwutw/build-djgpp) +as building directly in a DOS environment can be difficult. + +It is required to also have [Watt-32](https://www.watt-32.net/) available +built using the same compiler. It is recommended to build the latest `master` +branch from [GitHub](https://github.com/sezero/watt32/tree/master). + +Finally, the `DJ_PREFIX` and `WATT_ROOT` environment variables must be set +appropriately before calling `make Makefile.dj` to build c-ares. + +Please refer to our CI +[GitHub Actions Workflow](https://github.com/c-ares/c-ares/blob/main/.github/workflows/djgpp.yml) +for a full build example, including building the latest Watt-32 release. + + IBM OS/2 -------- @@ -418,20 +448,25 @@ This is a probably incomplete list of known hardware and operating systems that c-ares has been compiled for. If you know a system c-ares compiles and runs on, that isn't listed, please let us know! - - Alpha Tru64 v5.0 5.1 - - ARM Android 1.5, 2.1, 2.3 - - MIPS IRIX 6.2, 6.5 - - Power AIX 3.2.5, 4.2, 4.3.1, 4.3.2, 5.1, 5.2 - - i386 Linux 1.3, 2.0, 2.2, 2.3, 2.4, 2.6 - - i386 Novell NetWare - - i386 Windows 95, 98, ME, NT, 2000, XP, 2003 - - x86_64 Linux + - Linux (i686, x86_64, AARCH64, and more) + - MacOS 10.4+ + - iOS + - Windows 8+ (i686, x86_64) + - Android (ARM, AARCH64, x86_64) + - FreeBSD + - NetBSD + - OpenBSD + - Solaris (SPARC, x86_64) + - AIX (POWER) + - Tru64 (Alpha) + - IRIX (MIPS) + - Novell NetWare (i386) Useful URLs =========== - c-ares: https://c-ares.org/ - - MingW: http://www.mingw.org/ - MinGW-w64: http://mingw-w64.sourceforge.net/ + - MSYS2: https://msys2.org - OpenWatcom: http://www.openwatcom.org/ diff --git a/deps/cares/Makefile.dj b/deps/cares/Makefile.dj index 2f22188863886b..c28aefe9e225ea 100644 --- a/deps/cares/Makefile.dj +++ b/deps/cares/Makefile.dj @@ -20,10 +20,51 @@ WATT32_LIB = $(WATT32_ROOT)/lib/libwatt.a OBJ_DIR = djgpp CFLAGS = -g -O2 -I./include -I./src/lib \ - -I$(WATT32_ROOT)/inc -Wall \ + -I$(WATT32_ROOT)/inc \ + -Wall \ + -Wextra \ + -Waggregate-return \ + -Wcast-align \ + -Wcast-qual \ + -Wconversion \ + -Wdeclaration-after-statement \ + -Wdouble-promotion \ + -Wfloat-equal \ + -Winit-self \ + -Wjump-misses-init \ + -Wlogical-op \ + -Wmissing-braces \ + -Wmissing-declarations \ + -Wmissing-format-attribute \ + -Wmissing-include-dirs \ + -Wmissing-prototypes \ + -Wnested-externs \ + -Wno-coverage-mismatch \ + -Wold-style-definition \ + -Wpacked \ + -Wpointer-arith \ + -Wshadow \ + -Wsign-conversion \ + -Wstrict-overflow \ + -Wstrict-prototypes \ + -Wtrampolines \ + -Wundef \ + -Wunreachable-code \ + -Wunused \ + -Wvariadic-macros \ + -Wvla \ + -Wwrite-strings \ + -Werror=implicit-int \ + -Werror=implicit-function-declaration \ + -Wno-long-long \ -DWATT32 -DHAVE_CONFIG_H \ + -D_REENTRANT \ + -DCARES_NO_DEPRECATED \ -Dselect=select_s +# Can't enable -Wredundant-decls due to WATT32 issues + + LDFLAGS = -s ifeq ($(OS),Windows_NT) diff --git a/deps/cares/Makefile.m32 b/deps/cares/Makefile.m32 index a01fe235d1311c..36ae674c635194 100644 --- a/deps/cares/Makefile.m32 +++ b/deps/cares/Makefile.m32 @@ -64,7 +64,6 @@ install: ${INSTALL} -m 444 ${srcdir}/include/ares.h ${DESTDIR}${includedir} ${INSTALL} -m 444 ${srcdir}/include/ares_build.h ${DESTDIR}${includedir} ${INSTALL} -m 444 ${srcdir}/include/ares_dns_record.h ${DESTDIR}${includedir} - ${INSTALL} -m 444 ${srcdir}/include/ares_rules.h ${DESTDIR}${includedir} ${INSTALL} -m 444 ${srcdir}/include/ares_version.h ${DESTDIR}${includedir} (for man in $(MANPAGES); do \ ${INSTALL} -m 444 ${srcdir}/$${man} ${DESTDIR}${mandir}/man3; \ diff --git a/deps/cares/Makefile.msvc b/deps/cares/Makefile.msvc index 5969ec705aacd2..4b338f27999cd8 100644 --- a/deps/cares/Makefile.msvc +++ b/deps/cares/Makefile.msvc @@ -214,7 +214,7 @@ RT_ERROR_CHECKING = /RTCsu CC_CMD_REL = cl.exe /nologo $(RTLIB) /DNDEBUG /O2 CC_CMD_DBG = cl.exe /nologo $(RTLIBD) /D_DEBUG /Od /Zi $(RT_ERROR_CHECKING) -CC_CFLAGS = $(CFLAGS) /I.\src\lib /I.\include /W3 /EHsc /FD +CC_CFLAGS = $(CFLAGS) /D_REENTRANT /I.\src\lib /I.\include /W3 /EHsc /FD RC_CMD_REL = rc.exe /l 0x409 /d "NDEBUG" RC_CMD_DBG = rc.exe /l 0x409 /d "_DEBUG" @@ -440,7 +440,6 @@ install: @copy /y $(CARES_OUTDIR)\*.* "$(INSTALL_DIR_LIB)" >NUL @copy /y $(SRCDIR)\include\ares.h "$(INSTALL_DIR_INC)" >NUL @copy /y $(SRCDIR)\include\ares_build.h "$(INSTALL_DIR_INC)" >NUL - @copy /y $(SRCDIR)\include\ares_rules.h "$(INSTALL_DIR_INC)" >NUL @copy /y $(SRCDIR)\include\ares_version.h "$(INSTALL_DIR_INC)" >NUL @copy /y $(SRCDIR)\include\ares_dns_record.h "$(INSTALL_DIR_INC)" >NUL @echo Installed c-ares $(CFG) diff --git a/deps/cares/Makefile.netware b/deps/cares/Makefile.netware index 5ebbc76207dcfd..6cb00a7510066e 100644 --- a/deps/cares/Makefile.netware +++ b/deps/cares/Makefile.netware @@ -299,9 +299,8 @@ ifeq ($(LIBARCH),CLIB) @echo $(DL)#define RECVFROM_TYPE_ARG5 struct sockaddr$(DL) >> $@ @echo $(DL)#define RECVFROM_TYPE_ARG6 int$(DL) >> $@ @echo $(DL)#define RECVFROM_TYPE_RETV int$(DL) >> $@ - @echo $(DL)#define SEND_QUAL_ARG2$(DL) >> $@ @echo $(DL)#define SEND_TYPE_ARG1 int$(DL) >> $@ - @echo $(DL)#define SEND_TYPE_ARG2 char *$(DL) >> $@ + @echo $(DL)#define SEND_TYPE_ARG2 const char *$(DL) >> $@ @echo $(DL)#define SEND_TYPE_ARG3 int$(DL) >> $@ @echo $(DL)#define SEND_TYPE_ARG4 int$(DL) >> $@ @echo $(DL)#define SEND_TYPE_RETV int$(DL) >> $@ diff --git a/deps/cares/RELEASE-NOTES.md b/deps/cares/RELEASE-NOTES.md index eea305a5b6c2a0..545e3ca82746fa 100644 --- a/deps/cares/RELEASE-NOTES.md +++ b/deps/cares/RELEASE-NOTES.md @@ -1,24 +1,38 @@ -## c-ares version 1.31.0 - June 18 2024 +## c-ares version 1.32.0 - July 4 2024 -This is a maintenance and bugfix release. +This is a feature and bugfix release. + +Features: + +* Add support for DNS 0x20 to help prevent cache poisoning attacks, enabled + by specifying `ARES_FLAG_DNS0x20`. Disabled by default. [PR #800](https://github.com/c-ares/c-ares/pull/800) +* Rework query timeout logic to automatically adjust timeouts based on network + conditions. The timeout specified now is only used as a hint until there + is enough history to calculate a more valid timeout. [PR #794](https://github.com/c-ares/c-ares/pull/794) Changes: -* Enable Query Cache by default. [PR #786](https://github.com/c-ares/c-ares/pull/786) +* DNS RR TXT strings should not be automatically concatenated as there are use + cases outside of RFC 7208. In order to maintain ABI compliance, the ability + to retrieve TXT strings concatenated is retained as well as a new API to + retrieve the individual strings. This restores behavior from c-ares 1.20.0. + [PR #801](https://github.com/c-ares/c-ares/pull/801) +* Clean up header inclusion logic to make hacking on code easier. [PR #797](https://github.com/c-ares/c-ares/pull/797) +* GCC/Clang: Enable even more strict warnings to catch more coding flaws. [253bdee](https://github.com/c-ares/c-ares/commit/253bdee) +* MSVC: Enable `/W4` warning level. [PR #792](https://github.com/c-ares/c-ares/pull/792) Bugfixes: -* Enhance Windows DNS configuration change detection to also detect manual DNS - configuration changes. [PR #785](https://github.com/c-ares/c-ares/issues/785) -* Various legacy MacOS Build fixes. [Issue #782](https://github.com/c-ares/c-ares/issues/782) -* Ndots value of zero in resolv.conf was not being honored. [852a60a](https://github.com/c-ares/c-ares/commit/852a60a) -* Watt-32 build support had been broken for some time. [PR #781](https://github.com/c-ares/c-ares/pull/781) -* Distribute `ares_dns_rec_type_tostr` manpage. [PR #778](https://github.com/c-ares/c-ares/pull/778) +* Tests: Fix thread race condition in test cases for EventThread. [PR #803](https://github.com/c-ares/c-ares/pull/803) +* Windows: Fix building with UNICODE. [PR #802](https://github.com/c-ares/c-ares/pull/802) +* Thread Saftey: `ares_timeout()` was missing lock. [74a64e4](https://github.com/c-ares/c-ares/commit/74a64e4) +* Fix building with DJGPP (32bit protected mode DOS). [PR #789](https://github.com/c-ares/c-ares/pull/789) Thanks go to these friendly people for their efforts and contributions for this release: * Brad House (@bradh352) -* Gregor Jasny (@gjasny) +* Cheng (@zcbenz) + diff --git a/deps/cares/aminclude_static.am b/deps/cares/aminclude_static.am index 7cafa3443cd56d..7c89a366f80780 100644 --- a/deps/cares/aminclude_static.am +++ b/deps/cares/aminclude_static.am @@ -1,6 +1,6 @@ # aminclude_static.am generated automatically by Autoconf -# from AX_AM_MACROS_STATIC on Tue Jun 18 05:51:32 EDT 2024 +# from AX_AM_MACROS_STATIC on Thu Jul 4 07:03:12 EDT 2024 # Code coverage diff --git a/deps/cares/cares.gyp b/deps/cares/cares.gyp index d654a896f56ffd..ee0118016763c1 100644 --- a/deps/cares/cares.gyp +++ b/deps/cares/cares.gyp @@ -5,7 +5,6 @@ 'include/ares_dns.h', 'include/ares_dns_record.h', 'include/ares_nameser.h', - 'include/ares_rules.h', 'include/ares_version.h', 'src/lib/ares__addrinfo2hostent.c', 'src/lib/ares__addrinfo_localhost.c', @@ -43,6 +42,8 @@ 'src/lib/ares_data.h', 'src/lib/ares_destroy.c', 'src/lib/ares_dns_mapping.c', + 'src/lib/ares_dns_multistring.c', + 'src/lib/ares_dns_multistring.h', 'src/lib/ares_dns_name.c', 'src/lib/ares_dns_parse.c', 'src/lib/ares_dns_record.c', @@ -76,6 +77,7 @@ 'src/lib/ares_library_init.c', 'src/lib/ares_ipv6.h', 'src/lib/ares_math.c', + 'src/lib/ares_metrics.c', 'src/lib/ares_options.c', 'src/lib/ares_parse_a_reply.c', 'src/lib/ares_parse_aaaa_reply.c', @@ -112,7 +114,6 @@ 'src/lib/ares_version.c', 'src/lib/inet_net_pton.c', 'src/lib/inet_ntop.c', - 'src/lib/setup_once.h', 'src/tools/ares_getopt.c', 'src/tools/ares_getopt.h', ], @@ -122,6 +123,7 @@ 'src/lib/thirdparty/apple/dnsinfo.h', ], 'cares_sources_win': [ + 'src/lib/ares_sysconfig_win.c', 'src/lib/config-win32.h', 'src/lib/windows_port.c', ], diff --git a/deps/cares/cmake/EnableWarnings.cmake b/deps/cares/cmake/EnableWarnings.cmake index a394a8721f79b3..5bd68ec45c213e 100644 --- a/deps/cares/cmake/EnableWarnings.cmake +++ b/deps/cares/cmake/EnableWarnings.cmake @@ -39,6 +39,121 @@ include(CheckCXXCompilerFlag) get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES) +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Helper functions + + +# This function can be called in subdirectories, to prune out warnings that they don't want. +# vararg: warning flags to remove from list of enabled warnings. All "no" flags after EXPLICIT_DISABLE +# will be added to C flags. +# +# Ex.: remove_warnings(-Wall -Wdouble-promotion -Wcomment) prunes those warnings flags from the compile command. +function(remove_warnings) + get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES) + set(langs C) + if ("CXX" IN_LIST languages) + list(APPEND langs CXX) + endif () + + foreach(lang ${langs}) + set(toadd) + set(in_explicit_disable FALSE) + foreach (flag ${ARGN}) + if (flag STREQUAL "EXPLICIT_DISABLE") + set(in_explicit_disable TRUE) + elseif (in_explicit_disable) + list(APPEND toadd "${flag}") + else () + string(REGEX REPLACE "${flag}([ \t]+|$)" "" CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS}") + endif () + endforeach () + _int_enable_warnings_set_flags(lang ${toadd}) + string(STRIP "${CMAKE_${lang}_FLAGS}" CMAKE_${lang}_FLAGS) + set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS}" PARENT_SCOPE) + endforeach() +endfunction() + + +# Explicitly suppress all warnings. As long as this flag is the last warning flag, warnings will be +# suppressed even if earlier flags enabled warnings. +function(remove_all_warnings) + get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES) + set(langs C) + if ("CXX" IN_LIST languages) + list(APPEND langs CXX) + endif () + + foreach(lang ${langs}) + string(REGEX REPLACE "[-/][Ww][^ \t]*([ \t]+|$)" "" CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS}") + if (MSVC) + string(APPEND CMAKE_${lang}_FLAGS " /w") + else () + string(APPEND CMAKE_${lang}_FLAGS " -w") + endif () + string(STRIP "${CMAKE_${lang}_FLAGS}" CMAKE_${lang}_FLAGS) + set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS}" PARENT_SCOPE) + endforeach() +endfunction() + + +function(remove_all_warnings_from_targets) + foreach (target ${ARGN}) + if (MSVC) + target_compile_options(${target} PRIVATE "/w") + else () + target_compile_options(${target} PRIVATE "-w") + endif () + endforeach() +endfunction() + + +# Save the current warning settings to an internal variable. +function(push_warnings) + get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES) + set(langs C) + if ("CXX" IN_LIST languages) + list(APPEND langs CXX) + endif () + + foreach(lang ${langs}) + if (CMAKE_${lang}_FLAGS MATCHES ";") + message(AUTHOR_WARNING "Cannot push warnings for ${lang}, CMAKE_${lang}_FLAGS contains semicolons") + continue() + endif () + # Add current flags to end of internal list. + list(APPEND _enable_warnings_internal_${lang}_flags_stack "${CMAKE_${lang}_FLAGS}") + # Propagate results up to caller's scope. + set(_enable_warnings_internal_${lang}_flags_stack "${_enable_warnings_internal_${lang}_flags_stack}" PARENT_SCOPE) + endforeach() +endfunction() + + +# Restore the current warning settings from an internal variable. +function(pop_warnings) + get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES) + set(langs C) + if ("CXX" IN_LIST languages) + list(APPEND langs CXX) + endif () + + foreach(lang ${langs}) + if (NOT _enable_warnings_internal_${lang}_flags_stack) + continue() + endif () + # Pop flags off of end of list, overwrite current flags with whatever we popped off. + list(GET _enable_warnings_internal_${lang}_flags_stack -1 CMAKE_${lang}_FLAGS) + list(REMOVE_AT _enable_warnings_internal_${lang}_flags_stack -1) + # Propagate results up to caller's scope. + set(_enable_warnings_internal_${lang}_flags_stack "${_enable_warnings_internal_${lang}_flags_stack}" PARENT_SCOPE) + string(STRIP "${CMAKE_${lang}_FLAGS}" CMAKE_${lang}_FLAGS) + set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS}" PARENT_SCOPE) + endforeach() +endfunction() + + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Runs when included automatically + # internal helper: _int_enable_warnings_set_flags_ex(langs_var configs_var [warnings flags]) function(_int_enable_warnings_set_flags_ex langs_var configs_var) if (NOT ARGN) @@ -109,17 +224,42 @@ set(_debug_flags_C) set(_debug_flags_CXX) if (MSVC) + # Don't automatically set /W3 + CMAKE_POLICY (SET CMP0092 NEW) + # Visual Studio uses a completely different nomenclature for warnings than gcc/mingw/clang, so none of the # "-W[name]" warnings will work. - # W4 would be better but it produces unnecessary warnings like: - # * warning C4706: assignment within conditional expression - # Triggered when doing "while(1)" - # * warning C4115: 'timeval' : named type definition in parentheses - # * warning C4201: nonstandard extension used : nameless struct/union - # Triggered by system includes (commctrl.h, shtypes.h, Shlobj.h) set(_flags - /W3 + # Enable warnings + /W4 # Baseline reasonable warnings + /w14242 # 'identifier': conversion from 'type1' to 'type2', possible loss of data + /w14254 # 'operator': conversion from 'type1:field_bits' to 'type2:field_bits', possible loss of data + /w14263 # 'function': member function does not override any base class virtual member function + /w14265 # 'classname': class has virtual functions, but destructor is not virtual instances of this class may + # not be destructed correctly + /w14287 # 'operator': unsigned/negative constant mismatch + /we4289 # nonstandard extension used: 'variable': loop control variable declared in the for-loop is used outside + # the for-loop scope + /w14296 # 'operator': expression is always 'boolean_value' + /w14311 # 'variable': pointer truncation from 'type1' to 'type2' + /w14545 # expression before comma evaluates to a function which is missing an argument list + /w14546 # function call before comma missing argument list + /w14547 # 'operator': operator before comma has no effect; expected operator with side-effect + /w14549 # 'operator': operator before comma has no effect; did you intend 'operator'? + /w14555 # expression has no effect; expected expression with side- effect + /w14619 # pragma warning: there is no warning number 'number' + /w14640 # Enable warning on thread un-safe static member initialization + /w14826 # Conversion from 'type1' to 'type2' is sign-extended. This may cause unexpected runtime behavior. + /w14905 # wide string literal cast to 'LPSTR' + /w14906 # string literal cast to 'LPWSTR' + /w14928 # illegal copy-initialization; more than one user-defined conversion has been implicitly applied + + # Disable some warnings + /wd4201 # nonstandard extension used: nameless struct/union. Used in some windows headers, e.g. IO_STATUS_BLOCK, + # disable. + + # Turn some warnings into errors /we4013 # Treat "function undefined, assuming extern returning int" warning as an error. https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4013 ) @@ -157,7 +297,9 @@ else () -Wextra # Enable additional warnings not covered by Wall and Wextra. + -Waggregate-return -Wcast-align + -Wcast-qual -Wconversion -Wdeclaration-after-statement -Wdouble-promotion @@ -175,6 +317,7 @@ else () -Wno-coverage-mismatch -Wold-style-definition -Wpacked + -Wpedantic -Wpointer-arith -Wredundant-decls -Wshadow @@ -183,6 +326,7 @@ else () -Wstrict-prototypes -Wtrampolines -Wundef + -Wunreachable-code -Wunused -Wvariadic-macros -Wvla @@ -201,6 +345,8 @@ else () # Some clang versions might warn if an argument like "-I/path/to/headers" is unused, # silence these. -Qunused-arguments + + -Wno-long-long ) # C++ flags: @@ -285,115 +431,7 @@ foreach(_lang ${languages}) endif () endforeach() - - -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# Helper functions - - -# This function can be called in subdirectories, to prune out warnings that they don't want. -# vararg: warning flags to remove from list of enabled warnings. All "no" flags after EXPLICIT_DISABLE -# will be added to C flags. -# -# Ex.: remove_warnings(-Wall -Wdouble-promotion -Wcomment) prunes those warnings flags from the compile command. -function(remove_warnings) - get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES) - set(langs C) - if ("CXX" IN_LIST languages) - list(APPEND langs CXX) - endif () - - foreach(lang ${langs}) - set(toadd) - set(in_explicit_disable FALSE) - foreach (flag ${ARGN}) - if (flag STREQUAL "EXPLICIT_DISABLE") - set(in_explicit_disable TRUE) - elseif (in_explicit_disable) - list(APPEND toadd "${flag}") - else () - string(REGEX REPLACE "${flag}([ \t]+|$)" "" CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS}") - endif () - endforeach () - _int_enable_warnings_set_flags(lang ${toadd}) - string(STRIP "${CMAKE_${lang}_FLAGS}" CMAKE_${lang}_FLAGS) - set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS}" PARENT_SCOPE) - endforeach() -endfunction() - - -# Explicitly suppress all warnings. As long as this flag is the last warning flag, warnings will be -# suppressed even if earlier flags enabled warnings. -function(remove_all_warnings) - get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES) - set(langs C) - if ("CXX" IN_LIST languages) - list(APPEND langs CXX) - endif () - - foreach(lang ${langs}) - string(REGEX REPLACE "[-/][Ww][^ \t]*([ \t]+|$)" "" CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS}") - if (MSVC) - string(APPEND CMAKE_${lang}_FLAGS " /w") - else () - string(APPEND CMAKE_${lang}_FLAGS " -w") - endif () - string(STRIP "${CMAKE_${lang}_FLAGS}" CMAKE_${lang}_FLAGS) - set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS}" PARENT_SCOPE) - endforeach() -endfunction() - - -function(remove_all_warnings_from_targets) - foreach (target ${ARGN}) - if (MSVC) - target_compile_options(${target} PRIVATE "/w") - else () - target_compile_options(${target} PRIVATE "-w") - endif () - endforeach() -endfunction() - - -# Save the current warning settings to an internal variable. -function(push_warnings) - get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES) - set(langs C) - if ("CXX" IN_LIST languages) - list(APPEND langs CXX) - endif () - - foreach(lang ${langs}) - if (CMAKE_${lang}_FLAGS MATCHES ";") - message(AUTHOR_WARNING "Cannot push warnings for ${lang}, CMAKE_${lang}_FLAGS contains semicolons") - continue() - endif () - # Add current flags to end of internal list. - list(APPEND _enable_warnings_internal_${lang}_flags_stack "${CMAKE_${lang}_FLAGS}") - # Propagate results up to caller's scope. - set(_enable_warnings_internal_${lang}_flags_stack "${_enable_warnings_internal_${lang}_flags_stack}" PARENT_SCOPE) - endforeach() -endfunction() - - -# Restore the current warning settings from an internal variable. -function(pop_warnings) - get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES) - set(langs C) - if ("CXX" IN_LIST languages) - list(APPEND langs CXX) - endif () - - foreach(lang ${langs}) - if (NOT _enable_warnings_internal_${lang}_flags_stack) - continue() - endif () - # Pop flags off of end of list, overwrite current flags with whatever we popped off. - list(GET _enable_warnings_internal_${lang}_flags_stack -1 CMAKE_${lang}_FLAGS) - list(REMOVE_AT _enable_warnings_internal_${lang}_flags_stack -1) - # Propagate results up to caller's scope. - set(_enable_warnings_internal_${lang}_flags_stack "${_enable_warnings_internal_${lang}_flags_stack}" PARENT_SCOPE) - string(STRIP "${CMAKE_${lang}_FLAGS}" CMAKE_${lang}_FLAGS) - set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS}" PARENT_SCOPE) - endforeach() -endfunction() +# CMP0092 doesn't appear to really work, really remove the /W3 here. +if (MSVC) + remove_warnings(/W3) +endif () diff --git a/deps/cares/configure b/deps/cares/configure index a19193e42062e1..a309badc242b7b 100755 --- a/deps/cares/configure +++ b/deps/cares/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.72 for c-ares 1.31.0. +# Generated by GNU Autoconf 2.72 for c-ares 1.32.0. # # Report bugs to . # @@ -614,8 +614,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='c-ares' PACKAGE_TARNAME='c-ares' -PACKAGE_VERSION='1.31.0' -PACKAGE_STRING='c-ares 1.31.0' +PACKAGE_VERSION='1.32.0' +PACKAGE_STRING='c-ares 1.32.0' PACKAGE_BUGREPORT='c-ares mailing list: http://lists.haxx.se/listinfo/c-ares' PACKAGE_URL='' @@ -1415,7 +1415,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -'configure' configures c-ares 1.31.0 to adapt to many kinds of systems. +'configure' configures c-ares 1.32.0 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1486,7 +1486,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of c-ares 1.31.0:";; + short | recursive ) echo "Configuration of c-ares 1.32.0:";; esac cat <<\_ACEOF @@ -1623,7 +1623,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -c-ares configure 1.31.0 +c-ares configure 1.32.0 generated by GNU Autoconf 2.72 Copyright (C) 2023 Free Software Foundation, Inc. @@ -2267,7 +2267,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by c-ares $as_me 1.31.0, which was +It was created by c-ares $as_me 1.32.0, which was generated by GNU Autoconf 2.72. Invocation command line was $ $0$ac_configure_args_raw @@ -3259,7 +3259,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu -CARES_VERSION_INFO="18:0:16" +CARES_VERSION_INFO="19:0:17" @@ -5999,7 +5999,7 @@ fi # Define the identity of the package. PACKAGE='c-ares' - VERSION='1.31.0' + VERSION='1.32.0' printf "%s\n" "#define PACKAGE \"$PACKAGE\"" >>confdefs.h @@ -20682,42 +20682,7 @@ fi if test "$enable_warnings" = "yes"; then -for flag in -Wall \ - -Wextra \ - -Wcast-align \ - -Wconversion \ - -Wdeclaration-after-statement \ - -Wdouble-promotion \ - -Wfloat-equal \ - -Wformat-security \ - -Winit-self \ - -Wjump-misses-init \ - -Wlogical-op \ - -Wmissing-braces \ - -Wmissing-declarations \ - -Wmissing-format-attribute \ - -Wmissing-include-dirs \ - -Wmissing-prototypes \ - -Wnested-externs \ - -Wno-coverage-mismatch \ - -Wold-style-definition \ - -Wpacked \ - -Wpointer-arith \ - -Wredundant-decls \ - -Wshadow \ - -Wsign-conversion \ - -Wstrict-overflow \ - -Wstrict-prototypes \ - -Wtrampolines \ - -Wundef \ - -Wunused \ - -Wvariadic-macros \ - -Wvla \ - -Wwrite-strings \ - -Werror=implicit-int \ - -Werror=implicit-function-declaration \ - -Werror=partial-availability \ - ; do +for flag in -std=c90 -Wall -Wextra -Waggregate-return -Wcast-align -Wcast-qual -Wconversion -Wdeclaration-after-statement -Wdouble-promotion -Wfloat-equal -Wformat-security -Winit-self -Wjump-misses-init -Wlogical-op -Wmissing-braces -Wmissing-declarations -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-prototypes -Wnested-externs -Wno-coverage-mismatch -Wold-style-definition -Wpacked -Wpedantic -Wpointer-arith -Wredundant-decls -Wshadow -Wsign-conversion -Wstrict-overflow -Wstrict-prototypes -Wtrampolines -Wundef -Wunreachable-code -Wunused -Wvariadic-macros -Wvla -Wwrite-strings -Werror=implicit-int -Werror=implicit-function-declaration -Werror=partial-availability -Wno-long-long ; do as_CACHEVAR=`printf "%s\n" "ax_cv_check_cflags_-Werror_$flag" | sed "$as_sed_sh"` { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts $flag" >&5 printf %s "checking whether C compiler accepts $flag... " >&6; } @@ -23002,7 +22967,7 @@ recvfrom_type_arg5="struct sockaddr *" recv_type_arg4=int getnameinfo_type_arg1="struct sockaddr *" getnameinfo_type_arg7=int -send_type_arg2="void *" +send_type_arg2="const void *" send_type_arg4=int @@ -23053,9 +23018,6 @@ printf "%s\n" "#define SEND_TYPE_ARG1 ${send_type_arg1} " >>confdefs.h printf "%s\n" "#define SEND_TYPE_ARG2 ${send_type_arg2} " >>confdefs.h -printf "%s\n" "#define SEND_QUAL_ARG2 " >>confdefs.h - - printf "%s\n" "#define SEND_TYPE_ARG3 ${send_type_arg3} " >>confdefs.h @@ -23286,6 +23248,13 @@ cat >>confdefs.h <<_EOF #define CARES_HAVE_SYS_SOCKET_H 1 _EOF +fi +if test "x$ac_cv_header_sys_select_h" = "xyes" ; then + +cat >>confdefs.h <<_EOF +#define CARES_HAVE_SYS_SELECT_H 1 +_EOF + fi if test "x$ac_cv_header_ws2tcpip_h" = "xyes" ; then @@ -26370,7 +26339,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by c-ares $as_me 1.31.0, which was +This file was extended by c-ares $as_me 1.32.0, which was generated by GNU Autoconf 2.72. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -26438,7 +26407,7 @@ ac_cs_config_escaped=`printf "%s\n" "$ac_cs_config" | sed "s/^ //; s/'/'\\\\\\\\ cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config='$ac_cs_config_escaped' ac_cs_version="\\ -c-ares config.status 1.31.0 +c-ares config.status 1.32.0 configured by $0, generated by GNU Autoconf 2.72, with options \\"\$ac_cs_config\\" diff --git a/deps/cares/configure.ac b/deps/cares/configure.ac index 9e21619ae73dc1..d7deb430f8a2dd 100644 --- a/deps/cares/configure.ac +++ b/deps/cares/configure.ac @@ -2,10 +2,10 @@ dnl Copyright (C) The c-ares project and its contributors dnl SPDX-License-Identifier: MIT AC_PREREQ([2.69]) -AC_INIT([c-ares], [1.31.0], +AC_INIT([c-ares], [1.32.0], [c-ares mailing list: http://lists.haxx.se/listinfo/c-ares]) -CARES_VERSION_INFO="18:0:16" +CARES_VERSION_INFO="19:0:17" dnl This flag accepts an argument of the form current[:revision[:age]]. So, dnl passing -version-info 3:12:1 sets current to 3, revision to 12, and age to dnl 1. @@ -245,42 +245,8 @@ AC_SUBST(CARES_SYMBOL_HIDING_CFLAG) if test "$enable_warnings" = "yes"; then - AX_APPEND_COMPILE_FLAGS([-Wall \ - -Wextra \ - -Wcast-align \ - -Wconversion \ - -Wdeclaration-after-statement \ - -Wdouble-promotion \ - -Wfloat-equal \ - -Wformat-security \ - -Winit-self \ - -Wjump-misses-init \ - -Wlogical-op \ - -Wmissing-braces \ - -Wmissing-declarations \ - -Wmissing-format-attribute \ - -Wmissing-include-dirs \ - -Wmissing-prototypes \ - -Wnested-externs \ - -Wno-coverage-mismatch \ - -Wold-style-definition \ - -Wpacked \ - -Wpointer-arith \ - -Wredundant-decls \ - -Wshadow \ - -Wsign-conversion \ - -Wstrict-overflow \ - -Wstrict-prototypes \ - -Wtrampolines \ - -Wundef \ - -Wunused \ - -Wvariadic-macros \ - -Wvla \ - -Wwrite-strings \ - -Werror=implicit-int \ - -Werror=implicit-function-declaration \ - -Werror=partial-availability \ - ], [AM_CFLAGS], [-Werror]) + AX_APPEND_COMPILE_FLAGS([-std=c90 -Wall -Wextra -Waggregate-return -Wcast-align -Wcast-qual -Wconversion -Wdeclaration-after-statement -Wdouble-promotion -Wfloat-equal -Wformat-security -Winit-self -Wjump-misses-init -Wlogical-op -Wmissing-braces -Wmissing-declarations -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-prototypes -Wnested-externs -Wno-coverage-mismatch -Wold-style-definition -Wpacked -Wpedantic -Wpointer-arith -Wredundant-decls -Wshadow -Wsign-conversion -Wstrict-overflow -Wstrict-prototypes -Wtrampolines -Wundef -Wunreachable-code -Wunused -Wvariadic-macros -Wvla -Wwrite-strings -Werror=implicit-int -Werror=implicit-function-declaration -Werror=partial-availability -Wno-long-long ], + [AM_CFLAGS], [-Werror]) fi if test "$ax_cv_c_compiler_vendor" = "intel"; then @@ -294,17 +260,7 @@ if test "$ac_cv_native_windows" = "yes" ; then dnl other headers, AC_CHECK_HEADERS only allows you to specify headers that dnl must be included *before* the header being checked. - AC_CHECK_HEADERS( - windows.h \ - winsock2.h \ - ws2tcpip.h \ - iphlpapi.h \ - netioapi.h \ - ws2ipdef.h \ - winternl.h \ - ntdef.h \ - ntstatus.h \ - mswsock.h, + AC_CHECK_HEADERS([windows.h winsock2.h ws2tcpip.h iphlpapi.h netioapi.h ws2ipdef.h winternl.h ntdef.h ntstatus.h mswsock.h ], [], [], [-]) dnl Windows builds require linking to iphlpapi @@ -406,42 +362,10 @@ AS_HELP_STRING([--enable-libgcc],[use libgcc when linking]), AC_MSG_RESULT(no) ) -dnl check for a few basic system headers we need -AC_CHECK_HEADERS( - malloc.h \ - memory.h \ - AvailabilityMacros.h \ - sys/types.h \ - sys/time.h \ - sys/select.h \ - sys/socket.h \ - sys/filio.h \ - sys/ioctl.h \ - sys/param.h \ - sys/uio.h \ - sys/random.h \ - sys/event.h \ - sys/epoll.h \ - assert.h \ - iphlpapi.h \ - netioapi.h \ - netdb.h \ - netinet/in.h \ - netinet6/in6.h \ - netinet/tcp.h \ - net/if.h \ - ifaddrs.h \ - fcntl.h \ - errno.h \ - socket.h \ - strings.h \ - stdbool.h \ - time.h \ - poll.h \ - limits.h \ - arpa/nameser.h \ - arpa/nameser_compat.h \ - arpa/inet.h, +dnl check for a few basic system headers we need. It would be nice if we could +dnl split these on separate lines, but for some reason autotools on Windows doesn't +dnl allow this, even tried ending lines with a backslash. +AC_CHECK_HEADERS([malloc.h memory.h AvailabilityMacros.h sys/types.h sys/time.h sys/select.h sys/socket.h sys/filio.h sys/ioctl.h sys/param.h sys/uio.h sys/random.h sys/event.h sys/epoll.h assert.h iphlpapi.h netioapi.h netdb.h netinet/in.h netinet6/in6.h netinet/tcp.h net/if.h ifaddrs.h fcntl.h errno.h socket.h strings.h stdbool.h time.h poll.h limits.h arpa/nameser.h arpa/nameser_compat.h arpa/inet.h ], dnl to do if not found [], dnl to do if found @@ -705,7 +629,7 @@ recvfrom_type_arg5="struct sockaddr *" recv_type_arg4=int getnameinfo_type_arg1="struct sockaddr *" getnameinfo_type_arg7=int -send_type_arg2="void *" +send_type_arg2="const void *" send_type_arg4=int AC_DEFINE_UNQUOTED([RECVFROM_TYPE_RETV], [ ${recvfrom_type_retv} ], [ recvfrom() return value ]) @@ -725,7 +649,6 @@ AC_DEFINE_UNQUOTED([RECV_TYPE_ARG4], [ ${recv_type_arg4} ], [ re AC_DEFINE_UNQUOTED([SEND_TYPE_RETV], [ ${send_type_retv} ], [ send() return value ]) AC_DEFINE_UNQUOTED([SEND_TYPE_ARG1], [ ${send_type_arg1} ], [ send() arg1 type ]) AC_DEFINE_UNQUOTED([SEND_TYPE_ARG2], [ ${send_type_arg2} ], [ send() arg2 type ]) -AC_DEFINE_UNQUOTED([SEND_QUAL_ARG2], [ ], [ send() arg2 qualifier ]) AC_DEFINE_UNQUOTED([SEND_TYPE_ARG3], [ ${send_type_arg3} ], [ send() arg3 type ]) AC_DEFINE_UNQUOTED([SEND_TYPE_ARG4], [ ${send_type_arg4} ], [ send() arg4 type ]) @@ -808,6 +731,9 @@ fi if test "x$ac_cv_header_sys_socket_h" = "xyes" ; then CARES_DEFINE_UNQUOTED([CARES_HAVE_SYS_SOCKET_H],[1]) fi +if test "x$ac_cv_header_sys_select_h" = "xyes" ; then + CARES_DEFINE_UNQUOTED([CARES_HAVE_SYS_SELECT_H],[1]) +fi if test "x$ac_cv_header_ws2tcpip_h" = "xyes" ; then CARES_DEFINE_UNQUOTED([CARES_HAVE_WS2TCPIP_H],[1]) fi @@ -902,12 +828,12 @@ AC_SUBST(AM_CPPFLAGS) AC_SUBST(PKGCONFIG_CFLAGS) AC_SUBST(BUILD_SUBDIRS) -AC_CONFIG_FILES([Makefile \ - include/Makefile \ - src/Makefile \ - src/lib/Makefile \ - src/tools/Makefile \ - docs/Makefile \ +AC_CONFIG_FILES([Makefile + include/Makefile + src/Makefile + src/lib/Makefile + src/tools/Makefile + docs/Makefile libcares.pc ]) AM_COND_IF([BUILD_TESTS], [AC_CONFIG_FILES([test/Makefile])]) diff --git a/deps/cares/docs/Makefile.in b/deps/cares/docs/Makefile.in index d4bb7795a58786..6abb0e7f6bd62f 100644 --- a/deps/cares/docs/Makefile.in +++ b/deps/cares/docs/Makefile.in @@ -378,6 +378,10 @@ MANPAGES = ares_cancel.3 \ ares_dns_rec_type_tostr.3 \ ares_dns_rec_type_t.3 \ ares_dns_rr.3 \ + ares_dns_rr_add_abin.3 \ + ares_dns_rr_del_abin.3 \ + ares_dns_rr_get_abin.3 \ + ares_dns_rr_get_abin_cnt.3 \ ares_dns_rr_get_addr.3 \ ares_dns_rr_get_addr6.3 \ ares_dns_rr_get_bin.3 \ diff --git a/deps/cares/docs/Makefile.inc b/deps/cares/docs/Makefile.inc index 097bf26589be67..83d85ebf1d426e 100644 --- a/deps/cares/docs/Makefile.inc +++ b/deps/cares/docs/Makefile.inc @@ -40,6 +40,10 @@ MANPAGES = ares_cancel.3 \ ares_dns_rec_type_tostr.3 \ ares_dns_rec_type_t.3 \ ares_dns_rr.3 \ + ares_dns_rr_add_abin.3 \ + ares_dns_rr_del_abin.3 \ + ares_dns_rr_get_abin.3 \ + ares_dns_rr_get_abin_cnt.3 \ ares_dns_rr_get_addr.3 \ ares_dns_rr_get_addr6.3 \ ares_dns_rr_get_bin.3 \ diff --git a/deps/cares/docs/ares_dns_mapping.3 b/deps/cares/docs/ares_dns_mapping.3 index 690ad62be236af..451839153c5172 100644 --- a/deps/cares/docs/ares_dns_mapping.3 +++ b/deps/cares/docs/ares_dns_mapping.3 @@ -89,6 +89,13 @@ set and \fIares_dns_rr_get_bin(3)\fP to get. - Array of options. 16bit identifier, Binary data. Use \fIares_dns_rr_set_opt(3)\fP to set and \fIares_dns_rr_get_opt(3)\fP to get. .br +.B ARES_DATATYPE_ABINP +- Array of binary data, but likely printable. Guaranteed to have a NULL terminator +for convenience (not included in length). Use \fIares_dns_rr_add_abin(3)\fP to +set and \fIares_dns_rr_get_abin(3)\fP to get. Can also use +\fIares_dns_rr_set_bin(3)\fP and \fIares_dns_rr_get_bin(3)\fP if only concatenated +strings are desired. +.br .RE .B ares_dns_opt_datatype_t - diff --git a/deps/cares/docs/ares_dns_rr.3 b/deps/cares/docs/ares_dns_rr.3 index 1294fd55a44b9c..9d5ab37515e2bd 100644 --- a/deps/cares/docs/ares_dns_rr.3 +++ b/deps/cares/docs/ares_dns_rr.3 @@ -5,12 +5,14 @@ .SH NAME ares_dns_record_rr_add, ares_dns_record_rr_cnt, ares_dns_record_rr_del, ares_dns_record_rr_get, ares_dns_record_rr_get_const, ares_dns_rr_get_addr, -ares_dns_rr_get_addr6, ares_dns_rr_get_bin, ares_dns_rr_get_class, +ares_dns_rr_get_addr6, ares_dns_rr_get_bin, ares_dns_rr_get_abin_cnt, +ares_dns_rr_get_abin, ares_dns_rr_get_class, ares_dns_rr_get_name, ares_dns_rr_get_opt, ares_dns_rr_get_opt_byid, ares_dns_rr_get_opt_cnt, ares_dns_rr_get_str, ares_dns_rr_get_ttl, ares_dns_rr_get_type, ares_dns_rr_get_u16, ares_dns_rr_get_u32, ares_dns_rr_get_u8, ares_dns_rr_key_t, ares_dns_rr_set_addr, -ares_dns_rr_set_addr6, ares_dns_rr_set_bin, ares_dns_rr_set_opt, +ares_dns_rr_set_addr6, ares_dns_rr_set_bin, ares_dns_rr_add_abin, +ares_dns_rr_del_abin, ares_dns_rr_set_opt, ares_dns_rr_set_str, ares_dns_rr_set_u16, ares_dns_rr_set_u32, ares_dns_rr_set_u8, ares_dns_section_t, ares_tlsa_match_t, ares_tlsa_selector_t, ares_tlsa_usage_t \- @@ -79,6 +81,15 @@ ares_status_t ares_dns_rr_set_bin(ares_dns_rr_t *dns_rr, const unsigned char *val, size_t len); +ares_status_t ares_dns_rr_add_abin(ares_dns_rr_t *dns_rr, + ares_dns_rr_key_t key, + const unsigned char *val, + size_t len); + +ares_status_t ares_dns_rr_del_abin(ares_dns_rr_t *dns_rr, + ares_dns_rr_key_t key, + size_t idx); + ares_status_t ares_dns_rr_set_opt(ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key, unsigned short opt, @@ -107,6 +118,13 @@ const unsigned char *ares_dns_rr_get_bin(const ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key, size_t *len); +size_t ares_dns_rr_get_abin_cnt(const ares_dns_rr_t *dns_rr, + ares_dns_rr_key_t key); + +const unsigned char *ares_dns_rr_get_abin(const ares_dns_rr_t *dns_rr, + ares_dns_rr_key_t key, size_t idx, + size_t *len); + size_t ares_dns_rr_get_opt_cnt(const ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key); @@ -188,7 +206,7 @@ Keys used for handling RR record parameters: - MX Record. Exchange, domain. Datatype: \fIARES_DATATYPE_NAME\fP .br .B ARES_RR_TXT_DATA -- TXT Record. Data. Datatype: \fIARES_DATATYPE_BINP\fP +- TXT Record. Data. Datatype: \fIARES_DATATYPE_ABINP\fP .br .B ARES_RR_SIG_TYPE_COVERED - SIG Record. Type Covered. Datatype: \fIARES_DATATYPE_U16\fP @@ -497,7 +515,7 @@ parameter, and the value is provided in the .IR val parameter. -The \fIares_dns_rr_set_bin(3)\fP function is used to set an binary value for the +The \fIares_dns_rr_set_bin(3)\fP function is used to set a binary value for the associated resource record key/parameter when the datatype is \fIARES_DATATYPE_BIN\fP or \fIARES_DATATYPE_BINP\fP. The resource record to be modified is provided in the @@ -510,6 +528,30 @@ parameter. And the associated value length is provided in the .IR len parameter. +The \fIares_dns_rr_add_abin(3)\fP function is used to append a binary value in +the array for the associated resource record key/parameter when the datatype +is \fIARES_DATATYPE_ABINP\fP. +The resource record to be modified is provided in the +.IR dns_rr +parameter, the key/parameter is provided in the +.IR key +parameter, and the value is provided in the +.IR val +parameter. And the associated value length is provided in the +.IR len +parameter. + +The \fIares_dns_rr_del_abin(3)\fP function is used to delete a binary value in +the array for the associated resource record key/parameter when the datatype +is \fIARES_DATATYPE_ABINP\fP. +The resource record to be modified is provided in the +.IR dns_rr +parameter, the key/parameter is provided in the +.IR key +parameter, and the index to remove is provided in the +.IR idx +parameter. + The \fIares_dns_rr_set_opt(3)\fP function is used to set option/parameter keys and values for the resource record when the datatype if \fIARES_DATATYPE_OPT\fP. The resource record to be modified is provided in the @@ -584,6 +626,26 @@ parameter and the key/parameter to retrieve is provided in the parameter, and length is stored into the variable pointed to by .IR len. +The \fIares_dns_rr_get_abin_cnt(3)\fP function is used to retrieve the count +of the array of stored binary values from the resource record when the datatype +is \fIARES_DATATYPE_ABINP\fP. +The resource record is provided in the +.IR dns_rr +parameter and the key/parameter to retrieve is provided in the +.IR key +parameter. + +The \fIares_dns_rr_get_abin(3)\fP function is used to retrive binary data from +the resource record array when the datatype is \fIARES_DATATYPE_ABINP\fP. +The resource record is provided in the +.IR dns_rr +parameter and the key/parameter to retrieve is provided in the +.IR key +parameter, and the index to retrieve from the array is provided by the +.IR idx +parameter, and length is stored into the variable pointed to by +.IR len. + The \fIares_dns_rr_get_opt_cnt(3)\fP function is used to retrieve the count of options/parameters associated with the resource record when the datatype is \fIARES_DATATYPE_OPT\fP. @@ -630,8 +692,9 @@ respective counts. \fIares_dns_rr_set_addr(3)\fP, \fIares_dns_rr_set_addr6(3)\fP, \fIares_dns_rr_set_str(3)\fP, \fIares_dns_rr_set_u8(3)\fP, \fIares_dns_rr_set_u16(3)\fP, \fIares_dns_rr_set_u32(3)\fP, -\fIares_dns_rr_set_bin(3)\fP, and \fIares_dns_rr_set_opt(3)\fP all -return an \fIares_status_t\fP error code. +\fIares_dns_rr_set_bin(3)\fP, \fIares_dns_rr_add_abin(3)\fP, +\fIares_dns_rr_del_abin(3)\fP, +and \fIares_dns_rr_set_opt(3)\fP all return an \fIares_status_t\fP error code. .B ARES_SUCCESS is returned on success, .B ARES_ENOMEM @@ -645,7 +708,8 @@ is returned on misuse. \fIares_dns_rr_get_addr(3)\fP, \fIares_dns_rr_get_addr6(3)\fP, \fIares_dns_rr_get_str(3)\fP, \fIares_dns_rr_get_u8(3)\fP, \fIares_dns_rr_get_u16(3)\fP, \fIares_dns_rr_get_u32(3)\fP, -\fIares_dns_rr_get_bin(3)\fP, \fIares_dns_rr_get_opt(3)\fP all return their +\fIares_dns_rr_get_bin(3)\fP, \fIares_dns_rr_get_abin_cnt(3)\fP, +\fIares_dns_rr_get_abin(3)\fP, \fIares_dns_rr_get_opt(3)\fP all return their prescribed datatype values and in general can't fail except for misuse cases, in which a 0 (or NULL) may be returned, however 0 can also be a valid return value for most of these functions. diff --git a/deps/cares/docs/ares_dns_rr_add_abin.3 b/deps/cares/docs/ares_dns_rr_add_abin.3 new file mode 100644 index 00000000000000..b93e4cd4e37fa8 --- /dev/null +++ b/deps/cares/docs/ares_dns_rr_add_abin.3 @@ -0,0 +1,3 @@ +.\" Copyright (C) 2023 The c-ares project and its contributors. +.\" SPDX-License-Identifier: MIT +.so man3/ares_dns_rr.3 diff --git a/deps/cares/docs/ares_dns_rr_del_abin.3 b/deps/cares/docs/ares_dns_rr_del_abin.3 new file mode 100644 index 00000000000000..b93e4cd4e37fa8 --- /dev/null +++ b/deps/cares/docs/ares_dns_rr_del_abin.3 @@ -0,0 +1,3 @@ +.\" Copyright (C) 2023 The c-ares project and its contributors. +.\" SPDX-License-Identifier: MIT +.so man3/ares_dns_rr.3 diff --git a/deps/cares/docs/ares_dns_rr_get_abin.3 b/deps/cares/docs/ares_dns_rr_get_abin.3 new file mode 100644 index 00000000000000..b93e4cd4e37fa8 --- /dev/null +++ b/deps/cares/docs/ares_dns_rr_get_abin.3 @@ -0,0 +1,3 @@ +.\" Copyright (C) 2023 The c-ares project and its contributors. +.\" SPDX-License-Identifier: MIT +.so man3/ares_dns_rr.3 diff --git a/deps/cares/docs/ares_dns_rr_get_abin_cnt.3 b/deps/cares/docs/ares_dns_rr_get_abin_cnt.3 new file mode 100644 index 00000000000000..b93e4cd4e37fa8 --- /dev/null +++ b/deps/cares/docs/ares_dns_rr_get_abin_cnt.3 @@ -0,0 +1,3 @@ +.\" Copyright (C) 2023 The c-ares project and its contributors. +.\" SPDX-License-Identifier: MIT +.so man3/ares_dns_rr.3 diff --git a/deps/cares/docs/ares_init_options.3 b/deps/cares/docs/ares_init_options.3 index 3d983ebe6ddda4..694beb5ed28d13 100644 --- a/deps/cares/docs/ares_init_options.3 +++ b/deps/cares/docs/ares_init_options.3 @@ -130,27 +130,35 @@ v1.22, this is on by default if flags are otherwise not set. .B ARES_FLAG_NO_DFLT_SVR Do not attempt to add a default local named server if there are no other servers available. Instead, fail initialization with \fIARES_ENOSERVER\fP. +.TP 23 +.B ARES_FLAG_DNS0x20 +Enable support for DNS 0x20 as per https://datatracker.ietf.org/doc/html/draft-vixie-dnsext-dns0x20-00 +which adds additional entropy to the request by randomizing the case of the +query name. Integrators need to ensure they treat DNS name responses as +case-insensitive. In rare circumstances this may cause the inability to lookup +certain domains if the upstream server or the authoritative server for the +domain is non-compliant. .RE .TP 18 .B ARES_OPT_TIMEOUT .B int \fItimeout\fP; .br The number of seconds each name server is given to respond to a query on the -first try. (After the first try, the timeout algorithm becomes more -complicated, but scales linearly with the value of \fItimeout\fP.) The -default is two seconds. This option is being deprecated by -\fIARES_OPT_TIMEOUTMS\fP starting in c-ares 1.5.2. +first try. See \fIARES_OPT_TIMEOUTMS\fP which this value is converted into. .TP 18 .B ARES_OPT_TIMEOUTMS .B int \fItimeout\fP; .br The number of milliseconds each name server is given to respond to a query on -the first try. (After the first try, the timeout algorithm becomes more -complicated, but scales linearly with the value of \fItimeout\fP.) The -default is two seconds. Note that this option is specified with the same -struct field as the former \fIARES_OPT_TIMEOUT\fP, it is but the option bits -that tell c-ares how to interpret the number. This option was added in c-ares -1.5.2. +the first try of any given server. The default is two seconds, however any +value below 250ms will automatically be set to 250ms (roughly the RTT half-way +around the world). Note that this option is specified with the same struct field +as the former \fIARES_OPT_TIMEOUT\fP, it is but the option bits that tell c-ares +how to interpret the number. This option was added in c-ares 1.5.2. + +As of c-ares 1.32.0, this option is only honored on the first successful query +to any given server, after that the timeout is automatically calculated based +on prior query history. .TP 18 .B ARES_OPT_TRIES .B int \fItries\fP; @@ -227,7 +235,9 @@ The value of .I sock_state_cb_data will be passed as the .I data -argument. +argument. The channel lock is held during this callback, if in a multithreaded +application, care must be taken to ensure lock order is correct to be able to +handle this and avoid deadlocks. Cannot be used with \fBARES_OPT_EVENT_THREAD\fP. .TP 18 diff --git a/deps/cares/include/CMakeLists.txt b/deps/cares/include/CMakeLists.txt index e95a94dda16464..e01885ea1f06ab 100644 --- a/deps/cares/include/CMakeLists.txt +++ b/deps/cares/include/CMakeLists.txt @@ -5,6 +5,6 @@ CONFIGURE_FILE (ares_build.h.cmake ${PROJECT_BINARY_DIR}/ares_build.h) # Headers installation target IF (CARES_INSTALL) - SET (CARES_HEADERS ares.h ares_version.h "${PROJECT_BINARY_DIR}/ares_build.h" ares_rules.h ares_dns.h ares_dns_record.h ares_nameser.h) + SET (CARES_HEADERS ares.h ares_version.h "${PROJECT_BINARY_DIR}/ares_build.h" ares_dns.h ares_dns_record.h ares_nameser.h) INSTALL (FILES ${CARES_HEADERS} COMPONENT Devel DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) ENDIF () diff --git a/deps/cares/include/Makefile.am b/deps/cares/include/Makefile.am index e17790da4f4cc9..c2557d208bd1f2 100644 --- a/deps/cares/include/Makefile.am +++ b/deps/cares/include/Makefile.am @@ -4,6 +4,6 @@ AUTOMAKE_OPTIONS = foreign nostdinc 1.9.6 ACLOCAL_AMFLAGS = -I m4 --install # what headers to install on 'make install': -include_HEADERS = ares.h ares_version.h ares_build.h ares_rules.h ares_dns.h ares_dns_record.h ares_nameser.h +include_HEADERS = ares.h ares_version.h ares_build.h ares_dns.h ares_dns_record.h ares_nameser.h EXTRA_DIST = ares_build.h.cmake ares_build.h.in ares_build.h.dist CMakeLists.txt diff --git a/deps/cares/include/Makefile.in b/deps/cares/include/Makefile.in index 6e06995bfc5a3b..94e8e640fbe28c 100644 --- a/deps/cares/include/Makefile.in +++ b/deps/cares/include/Makefile.in @@ -352,7 +352,7 @@ AUTOMAKE_OPTIONS = foreign nostdinc 1.9.6 ACLOCAL_AMFLAGS = -I m4 --install # what headers to install on 'make install': -include_HEADERS = ares.h ares_version.h ares_build.h ares_rules.h ares_dns.h ares_dns_record.h ares_nameser.h +include_HEADERS = ares.h ares_version.h ares_build.h ares_dns.h ares_dns_record.h ares_nameser.h EXTRA_DIST = ares_build.h.cmake ares_build.h.in ares_build.h.dist CMakeLists.txt all: ares_build.h $(MAKE) $(AM_MAKEFLAGS) all-am diff --git a/deps/cares/include/ares.h b/deps/cares/include/ares.h index 58cac6cd71fcef..afff1759b39496 100644 --- a/deps/cares/include/ares.h +++ b/deps/cares/include/ares.h @@ -30,9 +30,43 @@ #include "ares_version.h" /* c-ares version defines */ #include "ares_build.h" /* c-ares build definitions */ -#include "ares_rules.h" /* c-ares rules enforcement */ -#include +#if defined(_WIN32) +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif +#endif + +#ifdef CARES_HAVE_SYS_TYPES_H +# include +#endif + +#ifdef CARES_HAVE_SYS_SOCKET_H +# include +#endif + +#ifdef CARES_HAVE_SYS_SELECT_H +# include +#endif + +#ifdef CARES_HAVE_WINSOCK2_H +# include +/* To aid with linking against a static c-ares build, lets tell the microsoft + * compiler to pull in needed dependencies */ +# ifdef _MSC_VER +# pragma comment(lib, "ws2_32") +# pragma comment(lib, "advapi32") +# pragma comment(lib, "iphlpapi") +# endif +#endif + +#ifdef CARES_HAVE_WS2TCPIP_H +# include +#endif + +#ifdef CARES_HAVE_WINDOWS_H +# include +#endif /* HP-UX systems version 9, 10 and 11 lack sys/select.h and so does oldish libc5-based Linux systems. Only include it on system that are known to @@ -43,43 +77,26 @@ defined(__QNXNTO__) || defined(__MVS__) || defined(__HAIKU__) # include #endif + #if (defined(NETWARE) && !defined(__NOVELL_LIBC__)) # include #endif -#if defined(_WIN32) -# ifndef WIN32_LEAN_AND_MEAN -# define WIN32_LEAN_AND_MEAN -# endif +#if !defined(_WIN32) +# include #endif -#if defined(WATT32) -# include -# include +#ifdef WATT32 # include -#elif defined(_WIN32_WCE) -# include -# include -#elif defined(_WIN32) -# include -# include -# include -/* To aid with linking against a static c-ares build, lets tell the microsoft - * compiler to pull in needed dependencies */ -# ifdef _MSC_VER -# pragma comment(lib, "ws2_32") -# pragma comment(lib, "advapi32") -# pragma comment(lib, "iphlpapi") -# endif -#else -# include -# include #endif #if defined(ANDROID) || defined(__ANDROID__) # include #endif +typedef CARES_TYPEOF_ARES_SOCKLEN_T ares_socklen_t; +typedef CARES_TYPEOF_ARES_SSIZE_T ares_ssize_t; + #ifdef __cplusplus extern "C" { #endif @@ -221,6 +238,7 @@ typedef enum { #define ARES_FLAG_NOCHECKRESP (1 << 7) #define ARES_FLAG_EDNS (1 << 8) #define ARES_FLAG_NO_DFLT_SVR (1 << 9) +#define ARES_FLAG_DNS0x20 (1 << 10) /* Option mask values */ #define ARES_OPT_FLAGS (1 << 0) diff --git a/deps/cares/include/ares_build.h b/deps/cares/include/ares_build.h index 0a2b7a711a3bf0..18a92606a81714 100644 --- a/deps/cares/include/ares_build.h +++ b/deps/cares/include/ares_build.h @@ -134,75 +134,61 @@ #elif defined(_WIN32_WCE) # define CARES_TYPEOF_ARES_SOCKLEN_T int -#elif defined(__MINGW32__) -# define CARES_TYPEOF_ARES_SOCKLEN_T int - #elif defined(__VMS) # define CARES_TYPEOF_ARES_SOCKLEN_T unsigned int #elif defined(__OS400__) # if defined(__ILEC400__) # define CARES_TYPEOF_ARES_SOCKLEN_T socklen_t -# define CARES_PULL_SYS_TYPES_H 1 -# define CARES_PULL_SYS_SOCKET_H 1 +# define CARES_HAVE_SYS_TYPES_H 1 +# define CARES_HAVE_SYS_SOCKET_H 1 +# define CARES_HAVE_SYS_SELECT_H 1 # endif #elif defined(__MVS__) # if defined(__IBMC__) || defined(__IBMCPP__) # define CARES_TYPEOF_ARES_SOCKLEN_T socklen_t -# define CARES_PULL_SYS_TYPES_H 1 -# define CARES_PULL_SYS_SOCKET_H 1 +# define CARES_HAVE_SYS_TYPES_H 1 +# define CARES_HAVE_SYS_SOCKET_H 1 +# define CARES_HAVE_SYS_SELECT_H 1 # endif #elif defined(__370__) # if defined(__IBMC__) || defined(__IBMCPP__) # define CARES_TYPEOF_ARES_SOCKLEN_T socklen_t -# define CARES_PULL_SYS_TYPES_H 1 -# define CARES_PULL_SYS_SOCKET_H 1 +# define CARES_HAVE_SYS_TYPES_H 1 +# define CARES_HAVE_SYS_SOCKET_H 1 +# define CARES_HAVE_SYS_SELECT_H 1 # endif #elif defined(TPF) # define CARES_TYPEOF_ARES_SOCKLEN_T int -/* ===================================== */ -/* KEEP MSVC THE PENULTIMATE ENTRY */ -/* ===================================== */ - -#elif defined(_MSC_VER) +#elif defined(_WIN32) +# define WIN32_LEAN_AND_MEAN # define CARES_TYPEOF_ARES_SOCKLEN_T int +# define CARES_HAVE_WINDOWS_H 1 +# define CARES_HAVE_SYS_TYPES_H 1 -/* ===================================== */ -/* KEEP GENERIC GCC THE LAST ENTRY */ -/* ===================================== */ +# if defined(WATT32) +# define CARES_HAVE_SYS_SOCKET_H 1 +# define CARES_HAVE_SYS_SELECT_H 1 +# else +# define CARES_HAVE_WS2TCPIP_H 1 +# define CARES_HAVE_WINSOCK2_H 1 +# endif #elif defined(__GNUC__) # define CARES_TYPEOF_ARES_SOCKLEN_T socklen_t -# define CARES_PULL_SYS_TYPES_H 1 -# define CARES_PULL_SYS_SOCKET_H 1 +# define CARES_HAVE_SYS_TYPES_H 1 +# define CARES_HAVE_SYS_SOCKET_H 1 +# define CARES_HAVE_SYS_SELECT_H 1 #else # error "Unknown non-configure build target!" Error Compilation_aborted_Unknown_non_configure_build_target #endif -/* CARES_PULL_SYS_TYPES_H is defined above when inclusion of header file */ -/* sys/types.h is required here to properly make type definitions below. */ -#ifdef CARES_PULL_SYS_TYPES_H -# include -#endif - -/* CARES_PULL_SYS_SOCKET_H is defined above when inclusion of header file */ -/* sys/socket.h is required here to properly make type definitions below. */ -#ifdef CARES_PULL_SYS_SOCKET_H -# include -#endif - -/* Data type definition of ares_socklen_t. */ - -#ifdef CARES_TYPEOF_ARES_SOCKLEN_T - typedef CARES_TYPEOF_ARES_SOCKLEN_T ares_socklen_t; -#endif - /* Data type definition of ares_ssize_t. */ #ifdef _WIN32 # ifdef _WIN64 @@ -214,6 +200,4 @@ # define CARES_TYPEOF_ARES_SSIZE_T ssize_t #endif -typedef CARES_TYPEOF_ARES_SSIZE_T ares_ssize_t; - #endif /* __CARES_BUILD_H */ diff --git a/deps/cares/include/ares_build.h.cmake b/deps/cares/include/ares_build.h.cmake index da8a7e064c0a45..2263c6c87ef18c 100644 --- a/deps/cares/include/ares_build.h.cmake +++ b/deps/cares/include/ares_build.h.cmake @@ -13,10 +13,10 @@ * for C-Ares */ #cmakedefine CARES_HAVE_SYS_TYPES_H #cmakedefine CARES_HAVE_SYS_SOCKET_H +#cmakedefine CARES_HAVE_SYS_SELECT_H #cmakedefine CARES_HAVE_WINDOWS_H #cmakedefine CARES_HAVE_WS2TCPIP_H #cmakedefine CARES_HAVE_WINSOCK2_H -#cmakedefine CARES_HAVE_WINDOWS_H #cmakedefine CARES_HAVE_ARPA_NAMESER_H #cmakedefine CARES_HAVE_ARPA_NAMESER_COMPAT_H @@ -28,6 +28,10 @@ # include #endif +#ifdef CARES_HAVE_SYS_SELECT_H +# include +#endif + #ifdef CARES_HAVE_WINSOCK2_H # include #endif @@ -40,8 +44,4 @@ # include #endif - -typedef CARES_TYPEOF_ARES_SOCKLEN_T ares_socklen_t; -typedef CARES_TYPEOF_ARES_SSIZE_T ares_ssize_t; - #endif /* __CARES_BUILD_H */ diff --git a/deps/cares/include/ares_build.h.in b/deps/cares/include/ares_build.h.in index e55b39b0e3e5bd..1327ed6d990f00 100644 --- a/deps/cares/include/ares_build.h.in +++ b/deps/cares/include/ares_build.h.in @@ -13,10 +13,10 @@ * for C-Ares */ #undef CARES_HAVE_SYS_TYPES_H #undef CARES_HAVE_SYS_SOCKET_H +#undef CARES_HAVE_SYS_SELECT_H #undef CARES_HAVE_WINDOWS_H #undef CARES_HAVE_WS2TCPIP_H #undef CARES_HAVE_WINSOCK2_H -#undef CARES_HAVE_WINDOWS_H #undef CARES_HAVE_ARPA_NAMESER_H #undef CARES_HAVE_ARPA_NAMESER_COMPAT_H @@ -28,6 +28,10 @@ # include #endif +#ifdef CARES_HAVE_SYS_SELECT_H +# include +#endif + #ifdef CARES_HAVE_WINSOCK2_H # include #endif @@ -40,8 +44,4 @@ # include #endif - -typedef CARES_TYPEOF_ARES_SOCKLEN_T ares_socklen_t; -typedef CARES_TYPEOF_ARES_SSIZE_T ares_ssize_t; - #endif /* __CARES_BUILD_H */ diff --git a/deps/cares/include/ares_dns_record.h b/deps/cares/include/ares_dns_record.h index 5533929f65f265..00b6809f124bf9 100644 --- a/deps/cares/include/ares_dns_record.h +++ b/deps/cares/include/ares_dns_record.h @@ -94,7 +94,7 @@ typedef enum { ARES_OPCODE_IQUERY = 1, /*!< Inverse query. Obsolete. */ ARES_OPCODE_STATUS = 2, /*!< Name server status query */ ARES_OPCODE_NOTIFY = 4, /*!< Zone change notification (RFC 1996) */ - ARES_OPCODE_UPDATE = 5, /*!< Zone update message (RFC2136) */ + ARES_OPCODE_UPDATE = 5 /*!< Zone update message (RFC2136) */ } ares_dns_opcode_t; /*! DNS Header flags */ @@ -108,7 +108,7 @@ typedef enum { ARES_FLAG_AD = 1 << 5, /*!< RFC 2065. Authentic Data bit indicates in a * response that the data included has been verified by * the server providing it */ - ARES_FLAG_CD = 1 << 6, /*!< RFC 2065. Checking Disabled bit indicates in a + ARES_FLAG_CD = 1 << 6 /*!< RFC 2065. Checking Disabled bit indicates in a * query that non-verified data is acceptable to the * resolver sending the query. */ } ares_dns_flags_t; @@ -152,25 +152,28 @@ typedef enum { ARES_RCODE_BADNAME = 20, /*!< RFC 2930. Duplicate Key Name */ ARES_RCODE_BADALG = 21, /*!< RFC 2930. Algorithm not supported */ ARES_RCODE_BADTRUNC = 22, /*!< RFC 8945. Bad Truncation */ - ARES_RCODE_BADCOOKIE = 23, /*!< RVC 7973. Bad/missing Server Cookie */ + ARES_RCODE_BADCOOKIE = 23 /*!< RVC 7973. Bad/missing Server Cookie */ } ares_dns_rcode_t; /*! Data types used */ typedef enum { - ARES_DATATYPE_INADDR = 1, /*!< struct in_addr * type */ - ARES_DATATYPE_INADDR6 = 2, /*!< struct ares_in6_addr * type */ - ARES_DATATYPE_U8 = 3, /*!< 8bit unsigned integer */ - ARES_DATATYPE_U16 = 4, /*!< 16bit unsigned integer */ - ARES_DATATYPE_U32 = 5, /*!< 32bit unsigned integer */ - ARES_DATATYPE_NAME = 6, /*!< Null-terminated string of a domain name */ - ARES_DATATYPE_STR = 7, /*!< Null-terminated string */ - ARES_DATATYPE_BIN = 8, /*!< Binary data */ - ARES_DATATYPE_BINP = 9, /*!< Officially defined as binary data, but likely - * printable. Guaranteed to have a NULL - * terminator for convenience (not included in - * length) */ - ARES_DATATYPE_OPT = 10, /*!< Array of options. 16bit identifier, BIN - * data. */ + ARES_DATATYPE_INADDR = 1, /*!< struct in_addr * type */ + ARES_DATATYPE_INADDR6 = 2, /*!< struct ares_in6_addr * type */ + ARES_DATATYPE_U8 = 3, /*!< 8bit unsigned integer */ + ARES_DATATYPE_U16 = 4, /*!< 16bit unsigned integer */ + ARES_DATATYPE_U32 = 5, /*!< 32bit unsigned integer */ + ARES_DATATYPE_NAME = 6, /*!< Null-terminated string of a domain name */ + ARES_DATATYPE_STR = 7, /*!< Null-terminated string */ + ARES_DATATYPE_BIN = 8, /*!< Binary data */ + ARES_DATATYPE_BINP = 9, /*!< Officially defined as binary data, but likely + * printable. Guaranteed to have a NULL + * terminator for convenience (not included in + * length) */ + ARES_DATATYPE_OPT = 10, /*!< Array of options. 16bit identifier, BIN + * data. */ + ARES_DATATYPE_ABINP = 11 /*!< Array of binary data, likely printable. + * Guaranteed to have a NULL terminator for + * convenience (not included in length) */ } ares_dns_datatype_t; /*! Keys used for all RR Types. We take the record type and multiply by 100 @@ -207,7 +210,7 @@ typedef enum { ARES_RR_MX_PREFERENCE = (ARES_REC_TYPE_MX * 100) + 1, /*! MX Record. Exchange, domain. Datatype: NAME */ ARES_RR_MX_EXCHANGE = (ARES_REC_TYPE_MX * 100) + 2, - /*! TXT Record. Data. Datatype: BINP */ + /*! TXT Record. Data. Datatype: ABINP */ ARES_RR_TXT_DATA = (ARES_REC_TYPE_TXT * 100) + 1, /*! SIG Record. Type Covered. Datatype: U16 */ ARES_RR_SIG_TYPE_COVERED = (ARES_REC_TYPE_SIG * 100) + 1, @@ -292,7 +295,7 @@ typedef enum { /*! RAW Record. RR Type. Datatype: U16 */ ARES_RR_RAW_RR_TYPE = (ARES_REC_TYPE_RAW_RR * 100) + 1, /*! RAW Record. RR Data. Datatype: BIN */ - ARES_RR_RAW_RR_DATA = (ARES_REC_TYPE_RAW_RR * 100) + 2, + ARES_RR_RAW_RR_DATA = (ARES_REC_TYPE_RAW_RR * 100) + 2 } ares_dns_rr_key_t; /*! TLSA Record ARES_RR_TLSA_CERT_USAGE known values */ @@ -372,7 +375,7 @@ typedef enum { /*! RFC 8145. Signaling Trust Anchor Knowledge in DNSSEC */ ARES_OPT_PARAM_EDNS_KEY_TAG = 14, /*! RFC 8914. Extended ERROR code and message */ - ARES_OPT_PARAM_EXTENDED_DNS_ERROR = 15, + ARES_OPT_PARAM_EXTENDED_DNS_ERROR = 15 } ares_opt_param_t; /*! Data type for option records for keys like ARES_RR_OPT_OPTIONS and @@ -600,6 +603,15 @@ CARES_EXTERN void ares_dns_record_destroy(ares_dns_record_t *dnsrec); CARES_EXTERN unsigned short ares_dns_record_get_id(const ares_dns_record_t *dnsrec); +/*! Overwrite the DNS query id + * + * \param[in] dnsrec Initialized record object + * \param[in] id DNS query id + * \return ARES_TRUE on success, ARES_FALSE on usage error + */ +CARES_EXTERN ares_bool_t + ares_dns_record_set_id(ares_dns_record_t *dnsrec, unsigned short id); + /*! Get the DNS Record Flags * * \param[in] dnsrec Initialized record object @@ -863,6 +875,34 @@ CARES_EXTERN ares_status_t ares_dns_rr_set_bin(ares_dns_rr_t *dns_rr, const unsigned char *val, size_t len); +/*! Add binary array value (ABINP) data for specified resource record and key. + * Can only be used on keys with datatype ARES_DATATYPE_ABINP. The value will + * Be added as the last element in the array. + * + * \param[in] dns_rr Pointer to resource record + * \param[in] key DNS Resource Record Key + * \param[in] val Pointer to binary data. + * \param[in] len Length of binary data + * \return ARES_SUCCESS on success + */ +CARES_EXTERN ares_status_t ares_dns_rr_add_abin(ares_dns_rr_t *dns_rr, + ares_dns_rr_key_t key, + const unsigned char *val, + size_t len); + +/*! Delete binary array value (ABINP) data for specified resource record and + * key by specified index. Can only be used on keys with datatype + * ARES_DATATYPE_ABINP. The value at the index will be deleted. + * + * \param[in] dns_rr Pointer to resource record + * \param[in] key DNS Resource Record Key + * \param[in] idx Index to delete + * \return ARES_SUCCESS on success + */ +CARES_EXTERN ares_status_t ares_dns_rr_del_abin(ares_dns_rr_t *dns_rr, + ares_dns_rr_key_t key, + size_t idx); + /*! Set the option for the RR * * \param[in] dns_rr Pointer to resource record @@ -939,8 +979,9 @@ CARES_EXTERN unsigned int ares_dns_rr_get_u32(const ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key); /*! Retrieve a pointer to the binary data. Can only be used on keys with - * datatype ARES_DATATYPE_BIN or ARES_DATATYPE_BINP. If BINP, the data is - * guaranteed to have a NULL terminator which is NOT included in the length. + * datatype ARES_DATATYPE_BIN, ARES_DATATYPE_BINP, or ARES_DATATYPE_ABINP. + * If BINP or ABINP, the data is guaranteed to have a NULL terminator which + * is NOT included in the length. * * \param[in] dns_rr Pointer to resource record * \param[in] key DNS Resource Record Key @@ -951,6 +992,32 @@ CARES_EXTERN const unsigned char * ares_dns_rr_get_bin(const ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key, size_t *len); +/*! Retrieve the count of the array of stored binary values. Can only be used on + * keys with datatype ARES_DATATYPE_ABINP. + * + * \param[in] dns_rr Pointer to resource record + * \param[in] key DNS Resource Record Key + * \return count of values + */ +CARES_EXTERN size_t ares_dns_rr_get_abin_cnt(const ares_dns_rr_t *dns_rr, + ares_dns_rr_key_t key); + +/*! Retrieve a pointer to the binary array data from the specified index. Can + * only be used on keys with datatype ARES_DATATYPE_ABINP. If ABINP, the data + * is guaranteed to have a NULL terminator which is NOT included in the length. + * If want all array membersconcatenated, may use ares_dns_rr_get_bin() + * instead. + * + * \param[in] dns_rr Pointer to resource record + * \param[in] key DNS Resource Record Key + * \param[in] idx Index of value to retrieve + * \param[out] len Length of binary data returned + * \return pointer binary data or NULL on error + */ +CARES_EXTERN const unsigned char *ares_dns_rr_get_abin( + const ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key, size_t idx, size_t *len); + + /*! Retrieve the number of options stored for the RR. * * \param[in] dns_rr Pointer to resource record diff --git a/deps/cares/include/ares_rules.h b/deps/cares/include/ares_rules.h deleted file mode 100644 index 450dc8ab2d5fd2..00000000000000 --- a/deps/cares/include/ares_rules.h +++ /dev/null @@ -1,133 +0,0 @@ -/* MIT License - * - * Copyright (c) 2009 Daniel Stenberg - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * SPDX-License-Identifier: MIT - */ -#ifndef __CARES_RULES_H -#define __CARES_RULES_H - -/* ================================================================ */ -/* COMPILE TIME SANITY CHECKS */ -/* ================================================================ */ - -/* - * NOTE 1: - * ------- - * - * All checks done in this file are intentionally placed in a public - * header file which is pulled by ares.h when an application is - * being built using an already built c-ares library. Additionally - * this file is also included and used when building the library. - * - * If compilation fails on this file it is certainly sure that the - * problem is elsewhere. It could be a problem in the ares_build.h - * header file, or simply that you are using different compilation - * settings than those used to build the library. - * - * Nothing in this file is intended to be modified or adjusted by the - * c-ares library user nor by the c-ares library builder. - * - * Do not deactivate any check, these are done to make sure that the - * library is properly built and used. - * - * You can find further help on the c-ares development mailing list: - * http://lists.haxx.se/listinfo/c-ares/ - * - * NOTE 2 - * ------ - * - * Some of the following compile time checks are based on the fact - * that the dimension of a constant array can not be a negative one. - * In this way if the compile time verification fails, the compilation - * will fail issuing an error. The error description wording is compiler - * dependent but it will be quite similar to one of the following: - * - * "negative subscript or subscript is too large" - * "array must have at least one element" - * "-1 is an illegal array size" - * "size of array is negative" - * - * If you are building an application which tries to use an already - * built c-ares library and you are getting this kind of errors on - * this file, it is a clear indication that there is a mismatch between - * how the library was built and how you are trying to use it for your - * application. Your already compiled or binary library provider is the - * only one who can give you the details you need to properly use it. - */ - -/* - * Verify that some macros are actually defined. - */ - -#ifndef CARES_TYPEOF_ARES_SOCKLEN_T -# error "CARES_TYPEOF_ARES_SOCKLEN_T definition is missing!" -Error Compilation_aborted_CARES_TYPEOF_ARES_SOCKLEN_T_is_missing -#endif - -/* - * Macros private to this header file. - */ - -#define CareschkszEQ(t, s) sizeof(t) == s ? 1 : -1 - -#define CareschkszGE(t1, t2) sizeof(t1) >= sizeof(t2) ? 1 : -1 - - /* - * Verify that the size previously defined and expected for - * ares_socklen_t is actually the same as the one reported - * by sizeof() at compile time. - */ - - typedef char __cares_rule_02__[CareschkszEQ( - ares_socklen_t, sizeof(CARES_TYPEOF_ARES_SOCKLEN_T))]; - -/* - * Verify at compile time that the size of ares_socklen_t as reported - * by sizeof() is greater or equal than the one reported for int for - * the current compilation. - */ - -typedef char __cares_rule_03__[CareschkszGE(ares_socklen_t, int)]; - -/* ================================================================ */ -/* EXTERNALLY AND INTERNALLY VISIBLE DEFINITIONS */ -/* ================================================================ */ - -/* - * Get rid of macros private to this header file. - */ - -#undef CareschkszEQ -#undef CareschkszGE - -/* - * Get rid of macros not intended to exist beyond this point. - */ - -#undef CARES_PULL_WS2TCPIP_H -#undef CARES_PULL_SYS_TYPES_H -#undef CARES_PULL_SYS_SOCKET_H - -#undef CARES_TYPEOF_ARES_SOCKLEN_T - -#endif /* __CARES_RULES_H */ diff --git a/deps/cares/include/ares_version.h b/deps/cares/include/ares_version.h index cd5a2551534589..7374767e98fce5 100644 --- a/deps/cares/include/ares_version.h +++ b/deps/cares/include/ares_version.h @@ -31,19 +31,14 @@ #define ARES_COPYRIGHT "2004 - 2024 Daniel Stenberg, ." #define ARES_VERSION_MAJOR 1 -#define ARES_VERSION_MINOR 31 +#define ARES_VERSION_MINOR 32 #define ARES_VERSION_PATCH 0 #define ARES_VERSION \ ((ARES_VERSION_MAJOR << 16) | (ARES_VERSION_MINOR << 8) | \ (ARES_VERSION_PATCH)) -#define ARES_VERSION_STR "1.31.0" +#define ARES_VERSION_STR "1.32.0" -#if (ARES_VERSION >= 0x010700) -# define CARES_HAVE_ARES_LIBRARY_INIT 1 -# define CARES_HAVE_ARES_LIBRARY_CLEANUP 1 -#else -# undef CARES_HAVE_ARES_LIBRARY_INIT -# undef CARES_HAVE_ARES_LIBRARY_CLEANUP -#endif +#define CARES_HAVE_ARES_LIBRARY_INIT 1 +#define CARES_HAVE_ARES_LIBRARY_CLEANUP 1 #endif diff --git a/deps/cares/src/lib/Makefile.in b/deps/cares/src/lib/Makefile.in index f9e7b7ea1ce29f..38e278a6d304a7 100644 --- a/deps/cares/src/lib/Makefile.in +++ b/deps/cares/src/lib/Makefile.in @@ -15,7 +15,7 @@ @SET_MAKE@ # aminclude_static.am generated automatically by Autoconf -# from AX_AM_MACROS_STATIC on Tue Jun 18 05:51:32 EDT 2024 +# from AX_AM_MACROS_STATIC on Thu Jul 4 07:03:12 EDT 2024 # Copyright (C) The c-ares project and its contributors # SPDX-License-Identifier: MIT @@ -175,6 +175,7 @@ am__objects_1 = libcares_la-ares__addrinfo2hostent.lo \ libcares_la-ares__timeval.lo libcares_la-ares_android.lo \ libcares_la-ares_cancel.lo libcares_la-ares_data.lo \ libcares_la-ares_destroy.lo libcares_la-ares_dns_mapping.lo \ + libcares_la-ares_dns_multistring.lo \ libcares_la-ares_dns_name.lo libcares_la-ares_dns_parse.lo \ libcares_la-ares_dns_record.lo libcares_la-ares_dns_write.lo \ libcares_la-ares_event_configchg.lo \ @@ -195,8 +196,9 @@ am__objects_1 = libcares_la-ares__addrinfo2hostent.lo \ libcares_la-ares_gethostbyname.lo \ libcares_la-ares_getnameinfo.lo libcares_la-ares_getsock.lo \ libcares_la-ares_init.lo libcares_la-ares_library_init.lo \ - libcares_la-ares_math.lo libcares_la-ares_create_query.lo \ - libcares_la-ares_options.lo libcares_la-ares_parse_a_reply.lo \ + libcares_la-ares_math.lo libcares_la-ares_metrics.lo \ + libcares_la-ares_create_query.lo libcares_la-ares_options.lo \ + libcares_la-ares_parse_a_reply.lo \ libcares_la-ares_parse_aaaa_reply.lo \ libcares_la-ares_parse_caa_reply.lo \ libcares_la-ares_parse_mx_reply.lo \ @@ -214,7 +216,8 @@ am__objects_1 = libcares_la-ares__addrinfo2hostent.lo \ libcares_la-ares_str.lo libcares_la-ares_strerror.lo \ libcares_la-ares_strsplit.lo libcares_la-ares_sysconfig.lo \ libcares_la-ares_sysconfig_files.lo \ - libcares_la-ares_sysconfig_mac.lo libcares_la-ares_timeout.lo \ + libcares_la-ares_sysconfig_mac.lo \ + libcares_la-ares_sysconfig_win.lo libcares_la-ares_timeout.lo \ libcares_la-ares_update_servers.lo libcares_la-ares_version.lo \ libcares_la-inet_net_pton.lo libcares_la-inet_ntop.lo \ libcares_la-windows_port.lo @@ -268,6 +271,7 @@ am__depfiles_remade = \ ./$(DEPDIR)/libcares_la-ares_data.Plo \ ./$(DEPDIR)/libcares_la-ares_destroy.Plo \ ./$(DEPDIR)/libcares_la-ares_dns_mapping.Plo \ + ./$(DEPDIR)/libcares_la-ares_dns_multistring.Plo \ ./$(DEPDIR)/libcares_la-ares_dns_name.Plo \ ./$(DEPDIR)/libcares_la-ares_dns_parse.Plo \ ./$(DEPDIR)/libcares_la-ares_dns_record.Plo \ @@ -295,6 +299,7 @@ am__depfiles_remade = \ ./$(DEPDIR)/libcares_la-ares_init.Plo \ ./$(DEPDIR)/libcares_la-ares_library_init.Plo \ ./$(DEPDIR)/libcares_la-ares_math.Plo \ + ./$(DEPDIR)/libcares_la-ares_metrics.Plo \ ./$(DEPDIR)/libcares_la-ares_options.Plo \ ./$(DEPDIR)/libcares_la-ares_parse_a_reply.Plo \ ./$(DEPDIR)/libcares_la-ares_parse_aaaa_reply.Plo \ @@ -321,6 +326,7 @@ am__depfiles_remade = \ ./$(DEPDIR)/libcares_la-ares_sysconfig.Plo \ ./$(DEPDIR)/libcares_la-ares_sysconfig_files.Plo \ ./$(DEPDIR)/libcares_la-ares_sysconfig_mac.Plo \ + ./$(DEPDIR)/libcares_la-ares_sysconfig_win.Plo \ ./$(DEPDIR)/libcares_la-ares_timeout.Plo \ ./$(DEPDIR)/libcares_la-ares_update_servers.Plo \ ./$(DEPDIR)/libcares_la-ares_version.Plo \ @@ -624,7 +630,7 @@ CSOURCES = ares__addrinfo2hostent.c \ ares__addrinfo_localhost.c \ ares__buf.c \ ares__close_sockets.c \ - ares__hosts_file.c \ + ares__hosts_file.c \ ares__htable.c \ ares__htable_asvp.c \ ares__htable_strvp.c \ @@ -643,11 +649,12 @@ CSOURCES = ares__addrinfo2hostent.c \ ares_data.c \ ares_destroy.c \ ares_dns_mapping.c \ + ares_dns_multistring.c \ ares_dns_name.c \ ares_dns_parse.c \ ares_dns_record.c \ ares_dns_write.c \ - ares_event_configchg.c \ + ares_event_configchg.c \ ares_event_epoll.c \ ares_event_kqueue.c \ ares_event_poll.c \ @@ -669,7 +676,8 @@ CSOURCES = ares__addrinfo2hostent.c \ ares_getsock.c \ ares_init.c \ ares_library_init.c \ - ares_math.c \ + ares_math.c \ + ares_metrics.c \ ares_create_query.c \ ares_options.c \ ares_parse_a_reply.c \ @@ -685,7 +693,7 @@ CSOURCES = ares__addrinfo2hostent.c \ ares_parse_uri_reply.c \ ares_platform.c \ ares_process.c \ - ares_qcache.c \ + ares_qcache.c \ ares_query.c \ ares_rand.c \ ares_search.c \ @@ -694,11 +702,12 @@ CSOURCES = ares__addrinfo2hostent.c \ ares_str.c \ ares_strerror.c \ ares_strsplit.c \ - ares_sysconfig.c \ - ares_sysconfig_files.c \ - ares_sysconfig_mac.c \ + ares_sysconfig.c \ + ares_sysconfig_files.c \ + ares_sysconfig_mac.c \ + ares_sysconfig_win.c \ ares_timeout.c \ - ares_update_servers.c \ + ares_update_servers.c \ ares_version.c \ inet_net_pton.c \ inet_ntop.c \ @@ -716,6 +725,7 @@ HHEADERS = ares__buf.h \ ares__threads.h \ ares_android.h \ ares_data.h \ + ares_dns_multistring.h \ ares_dns_private.h \ ares_event.h \ ares_event_win32.h \ @@ -728,7 +738,6 @@ HHEADERS = ares__buf.h \ ares_str.h \ ares_strsplit.h \ ares_setup.h \ - setup_once.h \ thirdparty/apple/dnsinfo.h @@ -853,6 +862,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcares_la-ares_data.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcares_la-ares_destroy.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcares_la-ares_dns_mapping.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcares_la-ares_dns_multistring.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcares_la-ares_dns_name.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcares_la-ares_dns_parse.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcares_la-ares_dns_record.Plo@am__quote@ # am--include-marker @@ -880,6 +890,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcares_la-ares_init.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcares_la-ares_library_init.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcares_la-ares_math.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcares_la-ares_metrics.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcares_la-ares_options.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcares_la-ares_parse_a_reply.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcares_la-ares_parse_aaaa_reply.Plo@am__quote@ # am--include-marker @@ -906,6 +917,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcares_la-ares_sysconfig.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcares_la-ares_sysconfig_files.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcares_la-ares_sysconfig_mac.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcares_la-ares_sysconfig_win.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcares_la-ares_timeout.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcares_la-ares_update_servers.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcares_la-ares_version.Plo@am__quote@ # am--include-marker @@ -1104,6 +1116,13 @@ libcares_la-ares_dns_mapping.lo: ares_dns_mapping.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libcares_la_CPPFLAGS) $(CPPFLAGS) $(libcares_la_CFLAGS) $(CFLAGS) -c -o libcares_la-ares_dns_mapping.lo `test -f 'ares_dns_mapping.c' || echo '$(srcdir)/'`ares_dns_mapping.c +libcares_la-ares_dns_multistring.lo: ares_dns_multistring.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libcares_la_CPPFLAGS) $(CPPFLAGS) $(libcares_la_CFLAGS) $(CFLAGS) -MT libcares_la-ares_dns_multistring.lo -MD -MP -MF $(DEPDIR)/libcares_la-ares_dns_multistring.Tpo -c -o libcares_la-ares_dns_multistring.lo `test -f 'ares_dns_multistring.c' || echo '$(srcdir)/'`ares_dns_multistring.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libcares_la-ares_dns_multistring.Tpo $(DEPDIR)/libcares_la-ares_dns_multistring.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='ares_dns_multistring.c' object='libcares_la-ares_dns_multistring.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libcares_la_CPPFLAGS) $(CPPFLAGS) $(libcares_la_CFLAGS) $(CFLAGS) -c -o libcares_la-ares_dns_multistring.lo `test -f 'ares_dns_multistring.c' || echo '$(srcdir)/'`ares_dns_multistring.c + libcares_la-ares_dns_name.lo: ares_dns_name.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libcares_la_CPPFLAGS) $(CPPFLAGS) $(libcares_la_CFLAGS) $(CFLAGS) -MT libcares_la-ares_dns_name.lo -MD -MP -MF $(DEPDIR)/libcares_la-ares_dns_name.Tpo -c -o libcares_la-ares_dns_name.lo `test -f 'ares_dns_name.c' || echo '$(srcdir)/'`ares_dns_name.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libcares_la-ares_dns_name.Tpo $(DEPDIR)/libcares_la-ares_dns_name.Plo @@ -1293,6 +1312,13 @@ libcares_la-ares_math.lo: ares_math.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libcares_la_CPPFLAGS) $(CPPFLAGS) $(libcares_la_CFLAGS) $(CFLAGS) -c -o libcares_la-ares_math.lo `test -f 'ares_math.c' || echo '$(srcdir)/'`ares_math.c +libcares_la-ares_metrics.lo: ares_metrics.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libcares_la_CPPFLAGS) $(CPPFLAGS) $(libcares_la_CFLAGS) $(CFLAGS) -MT libcares_la-ares_metrics.lo -MD -MP -MF $(DEPDIR)/libcares_la-ares_metrics.Tpo -c -o libcares_la-ares_metrics.lo `test -f 'ares_metrics.c' || echo '$(srcdir)/'`ares_metrics.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libcares_la-ares_metrics.Tpo $(DEPDIR)/libcares_la-ares_metrics.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='ares_metrics.c' object='libcares_la-ares_metrics.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libcares_la_CPPFLAGS) $(CPPFLAGS) $(libcares_la_CFLAGS) $(CFLAGS) -c -o libcares_la-ares_metrics.lo `test -f 'ares_metrics.c' || echo '$(srcdir)/'`ares_metrics.c + libcares_la-ares_create_query.lo: ares_create_query.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libcares_la_CPPFLAGS) $(CPPFLAGS) $(libcares_la_CFLAGS) $(CFLAGS) -MT libcares_la-ares_create_query.lo -MD -MP -MF $(DEPDIR)/libcares_la-ares_create_query.Tpo -c -o libcares_la-ares_create_query.lo `test -f 'ares_create_query.c' || echo '$(srcdir)/'`ares_create_query.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libcares_la-ares_create_query.Tpo $(DEPDIR)/libcares_la-ares_create_query.Plo @@ -1482,6 +1508,13 @@ libcares_la-ares_sysconfig_mac.lo: ares_sysconfig_mac.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libcares_la_CPPFLAGS) $(CPPFLAGS) $(libcares_la_CFLAGS) $(CFLAGS) -c -o libcares_la-ares_sysconfig_mac.lo `test -f 'ares_sysconfig_mac.c' || echo '$(srcdir)/'`ares_sysconfig_mac.c +libcares_la-ares_sysconfig_win.lo: ares_sysconfig_win.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libcares_la_CPPFLAGS) $(CPPFLAGS) $(libcares_la_CFLAGS) $(CFLAGS) -MT libcares_la-ares_sysconfig_win.lo -MD -MP -MF $(DEPDIR)/libcares_la-ares_sysconfig_win.Tpo -c -o libcares_la-ares_sysconfig_win.lo `test -f 'ares_sysconfig_win.c' || echo '$(srcdir)/'`ares_sysconfig_win.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libcares_la-ares_sysconfig_win.Tpo $(DEPDIR)/libcares_la-ares_sysconfig_win.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='ares_sysconfig_win.c' object='libcares_la-ares_sysconfig_win.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libcares_la_CPPFLAGS) $(CPPFLAGS) $(libcares_la_CFLAGS) $(CFLAGS) -c -o libcares_la-ares_sysconfig_win.lo `test -f 'ares_sysconfig_win.c' || echo '$(srcdir)/'`ares_sysconfig_win.c + libcares_la-ares_timeout.lo: ares_timeout.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libcares_la_CPPFLAGS) $(CPPFLAGS) $(libcares_la_CFLAGS) $(CFLAGS) -MT libcares_la-ares_timeout.lo -MD -MP -MF $(DEPDIR)/libcares_la-ares_timeout.Tpo -c -o libcares_la-ares_timeout.lo `test -f 'ares_timeout.c' || echo '$(srcdir)/'`ares_timeout.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libcares_la-ares_timeout.Tpo $(DEPDIR)/libcares_la-ares_timeout.Plo @@ -1755,6 +1788,7 @@ distclean: distclean-recursive -rm -f ./$(DEPDIR)/libcares_la-ares_data.Plo -rm -f ./$(DEPDIR)/libcares_la-ares_destroy.Plo -rm -f ./$(DEPDIR)/libcares_la-ares_dns_mapping.Plo + -rm -f ./$(DEPDIR)/libcares_la-ares_dns_multistring.Plo -rm -f ./$(DEPDIR)/libcares_la-ares_dns_name.Plo -rm -f ./$(DEPDIR)/libcares_la-ares_dns_parse.Plo -rm -f ./$(DEPDIR)/libcares_la-ares_dns_record.Plo @@ -1782,6 +1816,7 @@ distclean: distclean-recursive -rm -f ./$(DEPDIR)/libcares_la-ares_init.Plo -rm -f ./$(DEPDIR)/libcares_la-ares_library_init.Plo -rm -f ./$(DEPDIR)/libcares_la-ares_math.Plo + -rm -f ./$(DEPDIR)/libcares_la-ares_metrics.Plo -rm -f ./$(DEPDIR)/libcares_la-ares_options.Plo -rm -f ./$(DEPDIR)/libcares_la-ares_parse_a_reply.Plo -rm -f ./$(DEPDIR)/libcares_la-ares_parse_aaaa_reply.Plo @@ -1808,6 +1843,7 @@ distclean: distclean-recursive -rm -f ./$(DEPDIR)/libcares_la-ares_sysconfig.Plo -rm -f ./$(DEPDIR)/libcares_la-ares_sysconfig_files.Plo -rm -f ./$(DEPDIR)/libcares_la-ares_sysconfig_mac.Plo + -rm -f ./$(DEPDIR)/libcares_la-ares_sysconfig_win.Plo -rm -f ./$(DEPDIR)/libcares_la-ares_timeout.Plo -rm -f ./$(DEPDIR)/libcares_la-ares_update_servers.Plo -rm -f ./$(DEPDIR)/libcares_la-ares_version.Plo @@ -1883,6 +1919,7 @@ maintainer-clean: maintainer-clean-recursive -rm -f ./$(DEPDIR)/libcares_la-ares_data.Plo -rm -f ./$(DEPDIR)/libcares_la-ares_destroy.Plo -rm -f ./$(DEPDIR)/libcares_la-ares_dns_mapping.Plo + -rm -f ./$(DEPDIR)/libcares_la-ares_dns_multistring.Plo -rm -f ./$(DEPDIR)/libcares_la-ares_dns_name.Plo -rm -f ./$(DEPDIR)/libcares_la-ares_dns_parse.Plo -rm -f ./$(DEPDIR)/libcares_la-ares_dns_record.Plo @@ -1910,6 +1947,7 @@ maintainer-clean: maintainer-clean-recursive -rm -f ./$(DEPDIR)/libcares_la-ares_init.Plo -rm -f ./$(DEPDIR)/libcares_la-ares_library_init.Plo -rm -f ./$(DEPDIR)/libcares_la-ares_math.Plo + -rm -f ./$(DEPDIR)/libcares_la-ares_metrics.Plo -rm -f ./$(DEPDIR)/libcares_la-ares_options.Plo -rm -f ./$(DEPDIR)/libcares_la-ares_parse_a_reply.Plo -rm -f ./$(DEPDIR)/libcares_la-ares_parse_aaaa_reply.Plo @@ -1936,6 +1974,7 @@ maintainer-clean: maintainer-clean-recursive -rm -f ./$(DEPDIR)/libcares_la-ares_sysconfig.Plo -rm -f ./$(DEPDIR)/libcares_la-ares_sysconfig_files.Plo -rm -f ./$(DEPDIR)/libcares_la-ares_sysconfig_mac.Plo + -rm -f ./$(DEPDIR)/libcares_la-ares_sysconfig_win.Plo -rm -f ./$(DEPDIR)/libcares_la-ares_timeout.Plo -rm -f ./$(DEPDIR)/libcares_la-ares_update_servers.Plo -rm -f ./$(DEPDIR)/libcares_la-ares_version.Plo diff --git a/deps/cares/src/lib/Makefile.inc b/deps/cares/src/lib/Makefile.inc index a3e2453a04fa5a..a1f39609edc510 100644 --- a/deps/cares/src/lib/Makefile.inc +++ b/deps/cares/src/lib/Makefile.inc @@ -5,7 +5,7 @@ CSOURCES = ares__addrinfo2hostent.c \ ares__addrinfo_localhost.c \ ares__buf.c \ ares__close_sockets.c \ - ares__hosts_file.c \ + ares__hosts_file.c \ ares__htable.c \ ares__htable_asvp.c \ ares__htable_strvp.c \ @@ -24,11 +24,12 @@ CSOURCES = ares__addrinfo2hostent.c \ ares_data.c \ ares_destroy.c \ ares_dns_mapping.c \ + ares_dns_multistring.c \ ares_dns_name.c \ ares_dns_parse.c \ ares_dns_record.c \ ares_dns_write.c \ - ares_event_configchg.c \ + ares_event_configchg.c \ ares_event_epoll.c \ ares_event_kqueue.c \ ares_event_poll.c \ @@ -50,7 +51,8 @@ CSOURCES = ares__addrinfo2hostent.c \ ares_getsock.c \ ares_init.c \ ares_library_init.c \ - ares_math.c \ + ares_math.c \ + ares_metrics.c \ ares_create_query.c \ ares_options.c \ ares_parse_a_reply.c \ @@ -66,7 +68,7 @@ CSOURCES = ares__addrinfo2hostent.c \ ares_parse_uri_reply.c \ ares_platform.c \ ares_process.c \ - ares_qcache.c \ + ares_qcache.c \ ares_query.c \ ares_rand.c \ ares_search.c \ @@ -75,11 +77,12 @@ CSOURCES = ares__addrinfo2hostent.c \ ares_str.c \ ares_strerror.c \ ares_strsplit.c \ - ares_sysconfig.c \ - ares_sysconfig_files.c \ - ares_sysconfig_mac.c \ + ares_sysconfig.c \ + ares_sysconfig_files.c \ + ares_sysconfig_mac.c \ + ares_sysconfig_win.c \ ares_timeout.c \ - ares_update_servers.c \ + ares_update_servers.c \ ares_version.c \ inet_net_pton.c \ inet_ntop.c \ @@ -97,6 +100,7 @@ HHEADERS = ares__buf.h \ ares__threads.h \ ares_android.h \ ares_data.h \ + ares_dns_multistring.h \ ares_dns_private.h \ ares_event.h \ ares_event_win32.h \ @@ -109,6 +113,5 @@ HHEADERS = ares__buf.h \ ares_str.h \ ares_strsplit.h \ ares_setup.h \ - setup_once.h \ thirdparty/apple/dnsinfo.h diff --git a/deps/cares/src/lib/ares__addrinfo2hostent.c b/deps/cares/src/lib/ares__addrinfo2hostent.c index 3e22bc270f6ef7..9505af7340dc13 100644 --- a/deps/cares/src/lib/ares__addrinfo2hostent.c +++ b/deps/cares/src/lib/ares__addrinfo2hostent.c @@ -27,7 +27,7 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" +#include "ares_private.h" #ifdef HAVE_NETINET_IN_H # include @@ -47,8 +47,6 @@ # include #endif -#include "ares.h" -#include "ares_private.h" ares_status_t ares__addrinfo2hostent(const struct ares_addrinfo *ai, int family, struct hostent **host) @@ -165,13 +163,13 @@ ares_status_t ares__addrinfo2hostent(const struct ares_addrinfo *ai, int family, if (family == AF_INET6) { memcpy( (*host)->h_addr_list[i], - &(CARES_INADDR_CAST(struct sockaddr_in6 *, next->ai_addr)->sin6_addr), + &(CARES_INADDR_CAST(const struct sockaddr_in6 *, next->ai_addr)->sin6_addr), (size_t)(*host)->h_length); } if (family == AF_INET) { memcpy( (*host)->h_addr_list[i], - &(CARES_INADDR_CAST(struct sockaddr_in *, next->ai_addr)->sin_addr), + &(CARES_INADDR_CAST(const struct sockaddr_in *, next->ai_addr)->sin_addr), (size_t)(*host)->h_length); } ++i; @@ -195,7 +193,7 @@ ares_status_t ares__addrinfo2hostent(const struct ares_addrinfo *ai, int family, ares_free_hostent(*host); *host = NULL; return ARES_ENOMEM; -/* LCOV_EXCL_STOP */ + /* LCOV_EXCL_STOP */ } ares_status_t ares__addrinfo2addrttl(const struct ares_addrinfo *ai, int family, @@ -256,7 +254,7 @@ ares_status_t ares__addrinfo2addrttl(const struct ares_addrinfo *ai, int family, memcpy( &addr6ttls[*naddrttls].ip6addr, - &(CARES_INADDR_CAST(struct sockaddr_in6 *, next->ai_addr)->sin6_addr), + &(CARES_INADDR_CAST(const struct sockaddr_in6 *, next->ai_addr)->sin6_addr), sizeof(struct ares_in6_addr)); } else { if (next->ai_ttl > cname_ttl) { @@ -266,7 +264,7 @@ ares_status_t ares__addrinfo2addrttl(const struct ares_addrinfo *ai, int family, } memcpy( &addrttls[*naddrttls].ipaddr, - &(CARES_INADDR_CAST(struct sockaddr_in *, next->ai_addr)->sin_addr), + &(CARES_INADDR_CAST(const struct sockaddr_in *, next->ai_addr)->sin_addr), sizeof(struct in_addr)); } (*naddrttls)++; diff --git a/deps/cares/src/lib/ares__addrinfo_localhost.c b/deps/cares/src/lib/ares__addrinfo_localhost.c index 89ad35d6ec3bc0..e98dd4e277b056 100644 --- a/deps/cares/src/lib/ares__addrinfo_localhost.c +++ b/deps/cares/src/lib/ares__addrinfo_localhost.c @@ -25,7 +25,7 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" +#include "ares_private.h" #ifdef HAVE_NETINET_IN_H # include @@ -49,10 +49,6 @@ # endif #endif -#include "ares.h" -#include "ares_inet_net_pton.h" -#include "ares_private.h" - ares_status_t ares_append_ai_node(int aftype, unsigned short port, unsigned int ttl, const void *adata, struct ares_addrinfo_node **nodes) @@ -140,7 +136,7 @@ static ares_status_t !defined(__WATCOMC__) PMIB_UNICASTIPADDRESS_TABLE table; unsigned int i; - ares_status_t status; + ares_status_t status = ARES_ENOTFOUND; *nodes = NULL; @@ -208,7 +204,7 @@ ares_status_t ares__addrinfo_localhost(const char *name, unsigned short port, case AF_INET6: case AF_UNSPEC: break; - default: /* LCOV_EXCL_LINE: DefensiveCoding */ + default: /* LCOV_EXCL_LINE: DefensiveCoding */ return ARES_EBADFAMILY; /* LCOV_EXCL_LINE: DefensiveCoding */ } @@ -233,5 +229,5 @@ ares_status_t ares__addrinfo_localhost(const char *name, unsigned short port, ares_free(ai->name); ai->name = NULL; return ARES_ENOMEM; -/* LCOV_EXCL_STOP */ + /* LCOV_EXCL_STOP */ } diff --git a/deps/cares/src/lib/ares__buf.c b/deps/cares/src/lib/ares__buf.c index 4388a7d8918fad..320a73d6748aff 100644 --- a/deps/cares/src/lib/ares__buf.c +++ b/deps/cares/src/lib/ares__buf.c @@ -23,8 +23,6 @@ * * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" -#include "ares.h" #include "ares_private.h" #include "ares__buf.h" #include @@ -839,7 +837,7 @@ ares_status_t ares__buf_split(ares__buf_t *buf, const unsigned char *delims, } if (flags & ARES_BUF_SPLIT_RTRIM) { - while (len && ares__is_whitespace(ptr[len - 1], ARES_TRUE)) { + while (len > 0 && ares__is_whitespace(ptr[len - 1], ARES_TRUE)) { len--; } } @@ -939,13 +937,13 @@ ares_status_t ares__buf_set_position(ares__buf_t *buf, size_t idx) return ARES_SUCCESS; } -static ares_status_t ares__buf_parse_dns_binstr_int( - ares__buf_t *buf, size_t remaining_len, unsigned char **bin, size_t *bin_len, - ares_bool_t allow_multiple, ares_bool_t validate_printable) +ares_status_t ares__buf_parse_dns_abinstr(ares__buf_t *buf, + size_t remaining_len, + ares__dns_multistring_t **strs, + ares_bool_t validate_printable) { unsigned char len; - ares_status_t status; - ares__buf_t *binbuf = NULL; + ares_status_t status = ARES_EBADRESP; size_t orig_len = ares__buf_len(buf); if (buf == NULL) { @@ -956,9 +954,11 @@ static ares_status_t ares__buf_parse_dns_binstr_int( return ARES_EBADRESP; } - binbuf = ares__buf_create(); - if (binbuf == NULL) { - return ARES_ENOMEM; + if (strs != NULL) { + *strs = ares__dns_multistring_create(); + if (*strs == NULL) { + return ARES_ENOMEM; + } } while (orig_len - ares__buf_len(buf) < remaining_len) { @@ -979,22 +979,88 @@ static ares_status_t ares__buf_parse_dns_binstr_int( } } - if (bin != NULL) { - status = ares__buf_fetch_bytes_into_buf(buf, binbuf, len); + if (strs != NULL) { + unsigned char *data = NULL; + status = ares__buf_fetch_bytes_dup(buf, len, ARES_TRUE, &data); + if (status != ARES_SUCCESS) { + break; + } + status = ares__dns_multistring_add_own(*strs, data, len); + if (status != ARES_SUCCESS) { + ares_free(data); + break; + } } else { status = ares__buf_consume(buf, len); + if (status != ARES_SUCCESS) { + break; + } } - if (status != ARES_SUCCESS) { - break; + } + } + + if (status != ARES_SUCCESS && strs != NULL) { + ares__dns_multistring_destroy(*strs); + *strs = NULL; + } + + return status; +} + +static ares_status_t + ares__buf_parse_dns_binstr_int(ares__buf_t *buf, size_t remaining_len, + unsigned char **bin, size_t *bin_len, + ares_bool_t validate_printable) +{ + unsigned char len; + ares_status_t status = ARES_EBADRESP; + ares__buf_t *binbuf = NULL; + + if (buf == NULL) { + return ARES_EFORMERR; + } + + if (remaining_len == 0) { + return ARES_EBADRESP; + } + + binbuf = ares__buf_create(); + if (binbuf == NULL) { + return ARES_ENOMEM; + } + + status = ares__buf_fetch_bytes(buf, &len, 1); + if (status != ARES_SUCCESS) { + goto done; /* LCOV_EXCL_LINE: DefensiveCoding */ + } + + remaining_len--; + + if (len > remaining_len) { + status = ARES_EBADRESP; + goto done; + } + + if (len) { + /* When used by the _str() parser, it really needs to be validated to + * be a valid printable ascii string. Do that here */ + if (validate_printable && ares__buf_len(buf) >= len) { + size_t mylen; + const char *data = (const char *)ares__buf_peek(buf, &mylen); + if (!ares__str_isprint(data, len)) { + status = ARES_EBADSTR; + goto done; } } - if (!allow_multiple) { - break; + if (bin != NULL) { + status = ares__buf_fetch_bytes_into_buf(buf, binbuf, len); + } else { + status = ares__buf_consume(buf, len); } } - +done: if (status != ARES_SUCCESS) { ares__buf_destroy(binbuf); } else { @@ -1012,20 +1078,19 @@ static ares_status_t ares__buf_parse_dns_binstr_int( } ares_status_t ares__buf_parse_dns_binstr(ares__buf_t *buf, size_t remaining_len, - unsigned char **bin, size_t *bin_len, - ares_bool_t allow_multiple) + unsigned char **bin, size_t *bin_len) { return ares__buf_parse_dns_binstr_int(buf, remaining_len, bin, bin_len, - allow_multiple, ARES_FALSE); + ARES_FALSE); } ares_status_t ares__buf_parse_dns_str(ares__buf_t *buf, size_t remaining_len, - char **str, ares_bool_t allow_multiple) + char **str) { size_t len; - return ares__buf_parse_dns_binstr_int( - buf, remaining_len, (unsigned char **)str, &len, allow_multiple, ARES_TRUE); + return ares__buf_parse_dns_binstr_int(buf, remaining_len, + (unsigned char **)str, &len, ARES_TRUE); } ares_status_t ares__buf_append_num_dec(ares__buf_t *buf, size_t num, size_t len) @@ -1187,24 +1252,24 @@ ares_status_t ares__buf_load_file(const char *filename, ares__buf_t *buf) /* Get length portably, fstat() is POSIX, not C */ if (fseek(fp, 0, SEEK_END) != 0) { status = ARES_EFILE; /* LCOV_EXCL_LINE: DefensiveCoding */ - goto done; /* LCOV_EXCL_LINE: DefensiveCoding */ + goto done; /* LCOV_EXCL_LINE: DefensiveCoding */ } ftell_len = ftell(fp); if (ftell_len < 0) { status = ARES_EFILE; /* LCOV_EXCL_LINE: DefensiveCoding */ - goto done; /* LCOV_EXCL_LINE: DefensiveCoding */ + goto done; /* LCOV_EXCL_LINE: DefensiveCoding */ } len = (size_t)ftell_len; if (fseek(fp, 0, SEEK_SET) != 0) { status = ARES_EFILE; /* LCOV_EXCL_LINE: DefensiveCoding */ - goto done; /* LCOV_EXCL_LINE: DefensiveCoding */ + goto done; /* LCOV_EXCL_LINE: DefensiveCoding */ } if (len == 0) { status = ARES_SUCCESS; /* LCOV_EXCL_LINE: DefensiveCoding */ - goto done; /* LCOV_EXCL_LINE: DefensiveCoding */ + goto done; /* LCOV_EXCL_LINE: DefensiveCoding */ } /* Read entire data into buffer */ @@ -1212,13 +1277,13 @@ ares_status_t ares__buf_load_file(const char *filename, ares__buf_t *buf) ptr = ares__buf_append_start(buf, &ptr_len); if (ptr == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } ptr_len = fread(ptr, 1, len, fp); if (ptr_len != len) { status = ARES_EFILE; /* LCOV_EXCL_LINE: DefensiveCoding */ - goto done; /* LCOV_EXCL_LINE: DefensiveCoding */ + goto done; /* LCOV_EXCL_LINE: DefensiveCoding */ } ares__buf_append_finish(buf, len); diff --git a/deps/cares/src/lib/ares__buf.h b/deps/cares/src/lib/ares__buf.h index a9af6431e0f323..cb887aa27edcdf 100644 --- a/deps/cares/src/lib/ares__buf.h +++ b/deps/cares/src/lib/ares__buf.h @@ -554,13 +554,31 @@ size_t ares__buf_get_position(const ares__buf_t *buf); * \param[out] name Pointer passed by reference to be filled in with * allocated string of the parsed that must be * ares_free()'d by the caller. - * \param[in] allow_multiple ARES_TRUE if it should attempt to parse multiple - * strings back to back, and will concatenate in - * the returned str. * \return ARES_SUCCESS on success */ ares_status_t ares__buf_parse_dns_str(ares__buf_t *buf, size_t remaining_len, - char **name, ares_bool_t allow_multiple); + char **name); + +/*! Parse an array of character strings as defined in RFC1035, as binary, + * however, for convenience this does guarantee a NULL terminator (that is + * not included in the length for each value). + * + * \param[in] buf initialized buffer object + * \param[in] remaining_len maximum length that should be used for + * parsing the string, this is often less than + * the remaining buffer and is based on the RR + * record length. + * \param[out] strs Pointer passed by reference to be filled in + * with + * the array of values. + * \param[out] validate_printable Validate the strings contain only printable + * data. + * \return ARES_SUCCESS on success + */ +ares_status_t ares__buf_parse_dns_abinstr(ares__buf_t *buf, + size_t remaining_len, + ares__dns_multistring_t **strs, + ares_bool_t validate_printable); /*! Parse a character-string as defined in RFC1035, as binary, however for * convenience this does guarantee a NULL terminator (that is not included @@ -574,14 +592,10 @@ ares_status_t ares__buf_parse_dns_str(ares__buf_t *buf, size_t remaining_len, * allocated string of the parsed that must be * ares_free()'d by the caller. * \param[out] bin_len Length of returned string. - * \param[in] allow_multiple ARES_TRUE if it should attempt to parse multiple - * strings back to back, and will concatenate in - * the returned str. * \return ARES_SUCCESS on success */ ares_status_t ares__buf_parse_dns_binstr(ares__buf_t *buf, size_t remaining_len, - unsigned char **bin, size_t *bin_len, - ares_bool_t allow_multiple); + unsigned char **bin, size_t *bin_len); /*! Load data from specified file path into provided buffer. The entire file * is loaded into memory. diff --git a/deps/cares/src/lib/ares__close_sockets.c b/deps/cares/src/lib/ares__close_sockets.c index 06537a5de75f0b..8d7334b4c4dc11 100644 --- a/deps/cares/src/lib/ares__close_sockets.c +++ b/deps/cares/src/lib/ares__close_sockets.c @@ -25,16 +25,15 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" - -#include "ares.h" #include "ares_private.h" #include static void ares__requeue_queries(struct server_connection *conn) { struct query *query; - ares_timeval_t now = ares__tvnow(); + ares_timeval_t now; + + ares__tvnow(&now); while ((query = ares__llist_first_val(conn->queries_to_conn)) != NULL) { ares__requeue_query(query, &now); diff --git a/deps/cares/src/lib/ares__hosts_file.c b/deps/cares/src/lib/ares__hosts_file.c index 0f2875766586c7..271386e7b2524d 100644 --- a/deps/cares/src/lib/ares__hosts_file.c +++ b/deps/cares/src/lib/ares__hosts_file.c @@ -23,8 +23,6 @@ * * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" -#include "ares.h" #include "ares_private.h" #ifdef HAVE_SYS_TYPES_H # include @@ -316,7 +314,7 @@ static ares_status_t ares__hosts_file_add(ares_hosts_file_t *hosts, status = ares__hosts_file_merge_entry(hosts, match, entry, matchtype); if (status != ARES_SUCCESS) { ares__hosts_entry_destroy(entry); /* LCOV_EXCL_LINE: DefensiveCoding */ - return status; /* LCOV_EXCL_LINE: DefensiveCoding */ + return status; /* LCOV_EXCL_LINE: DefensiveCoding */ } /* entry was invalidated above by merging */ entry = match; @@ -617,7 +615,8 @@ static ares_bool_t ares__hosts_expired(const char *filename, /* Expire every 60s if we can't get a time */ if (mod_ts == 0) { - mod_ts = time(NULL) - 60; /* LCOV_EXCL_LINE: only on systems without stat() */ + mod_ts = + time(NULL) - 60; /* LCOV_EXCL_LINE: only on systems without stat() */ } /* If filenames are different, its expired */ @@ -779,7 +778,7 @@ ares_status_t ares__hosts_entry_to_hostent(const ares_hosts_entry_t *entry, *hostent = ares_malloc_zero(sizeof(**hostent)); if (*hostent == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto fail; /* LCOV_EXCL_LINE: OutOfMemory */ + goto fail; /* LCOV_EXCL_LINE: OutOfMemory */ } (*hostent)->h_addrtype = (HOSTENT_ADDRTYPE_TYPE)family; @@ -814,7 +813,7 @@ ares_status_t ares__hosts_entry_to_hostent(const ares_hosts_entry_t *entry, (idx + 2) * sizeof(*(*hostent)->h_addr_list)); if (temp == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto fail; /* LCOV_EXCL_LINE: OutOfMemory */ + goto fail; /* LCOV_EXCL_LINE: OutOfMemory */ } (*hostent)->h_addr_list = temp; @@ -822,7 +821,7 @@ ares_status_t ares__hosts_entry_to_hostent(const ares_hosts_entry_t *entry, (*hostent)->h_addr_list[idx] = ares_malloc(ptr_len); if ((*hostent)->h_addr_list[idx] == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto fail; /* LCOV_EXCL_LINE: OutOfMemory */ + goto fail; /* LCOV_EXCL_LINE: OutOfMemory */ } memcpy((*hostent)->h_addr_list[idx], ptr, ptr_len); @@ -840,7 +839,7 @@ ares_status_t ares__hosts_entry_to_hostent(const ares_hosts_entry_t *entry, (*hostent)->h_name = ares_strdup(ares__llist_first_val(entry->hosts)); if ((*hostent)->h_name == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto fail; /* LCOV_EXCL_LINE: OutOfMemory */ + goto fail; /* LCOV_EXCL_LINE: OutOfMemory */ } /* Copy aliases */ @@ -856,7 +855,7 @@ ares_status_t ares__hosts_entry_to_hostent(const ares_hosts_entry_t *entry, ares_malloc_zero((naliases + 1) * sizeof(*(*hostent)->h_aliases)); if ((*hostent)->h_aliases == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto fail; /* LCOV_EXCL_LINE: OutOfMemory */ + goto fail; /* LCOV_EXCL_LINE: OutOfMemory */ } /* Copy all entries to the alias except the first */ @@ -867,7 +866,7 @@ ares_status_t ares__hosts_entry_to_hostent(const ares_hosts_entry_t *entry, (*hostent)->h_aliases[idx] = ares_strdup(ares__llist_node_val(node)); if ((*hostent)->h_aliases[idx] == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto fail; /* LCOV_EXCL_LINE: OutOfMemory */ + goto fail; /* LCOV_EXCL_LINE: OutOfMemory */ } idx++; @@ -885,7 +884,7 @@ ares_status_t ares__hosts_entry_to_hostent(const ares_hosts_entry_t *entry, ares_free_hostent(*hostent); *hostent = NULL; return status; -/* LCOV_EXCL_STOP */ + /* LCOV_EXCL_STOP */ } static ares_status_t @@ -917,19 +916,19 @@ static ares_status_t cname = ares__append_addrinfo_cname(&cnames); if (cname == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } cname->alias = ares_strdup(host); if (cname->alias == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } cname->name = ares_strdup(primaryhost); if (cname->name == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } node = ares__llist_node_next(node); @@ -940,13 +939,13 @@ static ares_status_t cname = ares__append_addrinfo_cname(&cnames); if (cname == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } cname->name = ares_strdup(primaryhost); if (cname->name == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } } status = ARES_SUCCESS; @@ -954,7 +953,7 @@ static ares_status_t done: if (status != ARES_SUCCESS) { ares__freeaddrinfo_cnames(cnames); /* LCOV_EXCL_LINE: DefensiveCoding */ - return status; /* LCOV_EXCL_LINE: DefensiveCoding */ + return status; /* LCOV_EXCL_LINE: DefensiveCoding */ } *cnames_out = cnames; @@ -977,14 +976,14 @@ ares_status_t ares__hosts_entry_to_addrinfo(const ares_hosts_entry_t *entry, case AF_INET6: case AF_UNSPEC: break; - default: /* LCOV_EXCL_LINE: DefensiveCoding */ + default: /* LCOV_EXCL_LINE: DefensiveCoding */ return ARES_EBADFAMILY; /* LCOV_EXCL_LINE: DefensiveCoding */ } ai->name = ares_strdup(name); if (ai->name == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } for (node = ares__llist_node_first(entry->ips); node != NULL; diff --git a/deps/cares/src/lib/ares__htable.c b/deps/cares/src/lib/ares__htable.c index f09c9ea2951db9..d608d60ce3a51a 100644 --- a/deps/cares/src/lib/ares__htable.c +++ b/deps/cares/src/lib/ares__htable.c @@ -23,8 +23,6 @@ * * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" -#include "ares.h" #include "ares_private.h" #include "ares__llist.h" #include "ares__htable.h" @@ -207,7 +205,7 @@ static ares_bool_t ares__htable_expand(ares__htable_t *htable) * middle, we wouldn't be able to recover. */ buckets = ares_malloc_zero(sizeof(*buckets) * htable->size); if (buckets == NULL) { - goto done; /* LCOV_EXCL_LINE */ + goto done; /* LCOV_EXCL_LINE */ } /* The maximum number of new llists we'll need is the number of collisions @@ -270,7 +268,7 @@ static ares_bool_t ares__htable_expand(ares__htable_t *htable) if (buckets[idx] == NULL) { /* Silence static analysis, this isn't possible but it doesn't know */ if (prealloc_llist == NULL || prealloc_llist_len == 0) { - goto done; /* LCOV_EXCL_LINE */ + goto done; /* LCOV_EXCL_LINE */ } buckets[idx] = prealloc_llist[prealloc_llist_len - 1]; prealloc_llist_len--; @@ -304,7 +302,7 @@ static ares_bool_t ares__htable_expand(ares__htable_t *htable) /* On failure, we need to restore the htable size */ if (rv != ARES_TRUE) { - htable->size = old_size; /* LCOV_EXCL_LINE */ + htable->size = old_size; /* LCOV_EXCL_LINE */ } return rv; @@ -336,7 +334,7 @@ ares_bool_t ares__htable_insert(ares__htable_t *htable, void *bucket) if (htable->num_keys + 1 > (htable->size * ARES__HTABLE_EXPAND_PERCENT) / 100) { if (!ares__htable_expand(htable)) { - return ARES_FALSE; /* LCOV_EXCL_LINE */ + return ARES_FALSE; /* LCOV_EXCL_LINE */ } /* If we expanded, need to calculate a new index */ idx = HASH_IDX(htable, key); diff --git a/deps/cares/src/lib/ares__htable_asvp.c b/deps/cares/src/lib/ares__htable_asvp.c index 42951712934a86..4b9267ff6c14ee 100644 --- a/deps/cares/src/lib/ares__htable_asvp.c +++ b/deps/cares/src/lib/ares__htable_asvp.c @@ -23,8 +23,6 @@ * * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" -#include "ares.h" #include "ares_private.h" #include "ares__htable.h" #include "ares__htable_asvp.h" @@ -134,7 +132,7 @@ ares_socket_t *ares__htable_asvp_keys(const ares__htable_asvp_t *htable, out = ares_malloc_zero(sizeof(*out) * cnt); if (out == NULL) { ares_free(buckets); /* LCOV_EXCL_LINE: OutOfMemory */ - return NULL; /* LCOV_EXCL_LINE: OutOfMemory */ + return NULL; /* LCOV_EXCL_LINE: OutOfMemory */ } for (i = 0; i < cnt; i++) { diff --git a/deps/cares/src/lib/ares__htable_strvp.c b/deps/cares/src/lib/ares__htable_strvp.c index bfae4c3622891c..d73a1928a75f95 100644 --- a/deps/cares/src/lib/ares__htable_strvp.c +++ b/deps/cares/src/lib/ares__htable_strvp.c @@ -23,8 +23,6 @@ * * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" -#include "ares.h" #include "ares_private.h" #include "ares__htable.h" #include "ares__htable_strvp.h" diff --git a/deps/cares/src/lib/ares__htable_szvp.c b/deps/cares/src/lib/ares__htable_szvp.c index 33d8ed3a8dfb9f..b3e88d8b9a434a 100644 --- a/deps/cares/src/lib/ares__htable_szvp.c +++ b/deps/cares/src/lib/ares__htable_szvp.c @@ -23,8 +23,6 @@ * * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" -#include "ares.h" #include "ares_private.h" #include "ares__htable.h" #include "ares__htable_szvp.h" diff --git a/deps/cares/src/lib/ares__htable_vpvp.c b/deps/cares/src/lib/ares__htable_vpvp.c index e0c009a6401a1c..9042c48dd7fba2 100644 --- a/deps/cares/src/lib/ares__htable_vpvp.c +++ b/deps/cares/src/lib/ares__htable_vpvp.c @@ -23,8 +23,6 @@ * * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" -#include "ares.h" #include "ares_private.h" #include "ares__htable.h" #include "ares__htable_vpvp.h" @@ -114,7 +112,7 @@ ares__htable_vpvp_t * ares_free(htable); } return NULL; -/* LCOV_EXCL_STOP */ + /* LCOV_EXCL_STOP */ } ares_bool_t ares__htable_vpvp_insert(ares__htable_vpvp_t *htable, void *key, diff --git a/deps/cares/src/lib/ares__iface_ips.c b/deps/cares/src/lib/ares__iface_ips.c index bc120c7039310a..6c983cabb1cb8a 100644 --- a/deps/cares/src/lib/ares__iface_ips.c +++ b/deps/cares/src/lib/ares__iface_ips.c @@ -23,8 +23,7 @@ * * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" - +#include "ares_private.h" #ifdef USE_WINSOCK # include @@ -55,9 +54,10 @@ #ifdef HAVE_NETINET_IN_H # include #endif +#ifdef HAVE_NETDB_H +# include +#endif -#include "ares.h" -#include "ares_private.h" static ares_status_t ares__iface_ips_enumerate(ares__iface_ips_t *ips, const char *name); @@ -89,7 +89,7 @@ static ares__iface_ips_t *ares__iface_ips_alloc(ares__iface_ip_flags_t flags) ips->ips = ares_malloc_zero(ips->alloc_size * sizeof(*ips->ips)); if (ips->ips == NULL) { ares_free(ips); /* LCOV_EXCL_LINE: OutOfMemory */ - return NULL; /* LCOV_EXCL_LINE: OutOfMemory */ + return NULL; /* LCOV_EXCL_LINE: OutOfMemory */ } ips->enum_flags = flags; return ips; @@ -215,8 +215,8 @@ static ares_status_t /* Add */ idx = ips->cnt++; - ips->ips[idx].flags = flags; - ips->ips[idx].netmask = netmask; + ips->ips[idx].flags = flags; + ips->ips[idx].netmask = netmask; if (flags & ARES_IFACE_IP_LINKLOCAL) { ips->ips[idx].ll_scope = ll_scope; } @@ -526,8 +526,9 @@ static ares_status_t ares__iface_ips_enumerate(ares__iface_ips_t *ips, unsigned int ares__if_nametoindex(const char *name) { #ifdef HAVE_IF_NAMETOINDEX - if (name == NULL) + if (name == NULL) { return 0; + } return if_nametoindex(name); #else ares_status_t status; @@ -535,8 +536,9 @@ unsigned int ares__if_nametoindex(const char *name) size_t i; unsigned int index = 0; - if (name == NULL) + if (name == NULL) { return 0; + } status = ares__iface_ips(&ips, ARES_IFACE_IP_V6 | ARES_IFACE_IP_LINKLOCAL, name); diff --git a/deps/cares/src/lib/ares__llist.c b/deps/cares/src/lib/ares__llist.c index a094889d687acf..96936c1abe7c07 100644 --- a/deps/cares/src/lib/ares__llist.c +++ b/deps/cares/src/lib/ares__llist.c @@ -23,8 +23,6 @@ * * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" -#include "ares.h" #include "ares_private.h" #include "ares__llist.h" @@ -186,6 +184,26 @@ ares__llist_node_t *ares__llist_node_first(ares__llist_t *list) return list->head; } +ares__llist_node_t *ares__llist_node_idx(ares__llist_t *list, size_t idx) +{ + ares__llist_node_t *node; + size_t cnt; + + if (list == NULL) { + return NULL; + } + if (idx >= list->cnt) { + return NULL; + } + + node = list->head; + for (cnt = 0; node != NULL && cnt < idx; cnt++) { + node = node->next; + } + + return node; +} + ares__llist_node_t *ares__llist_node_last(ares__llist_t *list) { if (list == NULL) { @@ -323,7 +341,7 @@ void ares__llist_node_replace(ares__llist_node_t *node, void *val) node->data = val; } -void ares__llist_destroy(ares__llist_t *list) +void ares__llist_clear(ares__llist_t *list) { ares__llist_node_t *node; @@ -334,6 +352,14 @@ void ares__llist_destroy(ares__llist_t *list) while ((node = ares__llist_node_first(list)) != NULL) { ares__llist_node_destroy(node); } +} + +void ares__llist_destroy(ares__llist_t *list) +{ + if (list == NULL) { + return; + } + ares__llist_clear(list); ares_free(list); } diff --git a/deps/cares/src/lib/ares__llist.h b/deps/cares/src/lib/ares__llist.h index 7d57bdab3b077c..213f54134bcb55 100644 --- a/deps/cares/src/lib/ares__llist.h +++ b/deps/cares/src/lib/ares__llist.h @@ -122,6 +122,14 @@ ares__llist_node_t *ares__llist_node_first(ares__llist_t *list); */ ares__llist_node_t *ares__llist_node_last(ares__llist_t *list); +/*! Obtain a node based on its index. This is an O(n) operation. + * + * \param[in] list Initialized list object + * \param[in] idx Index of node to retrieve + * \return node at index or NULL if invalid index + */ +ares__llist_node_t *ares__llist_node_idx(ares__llist_t *list, size_t idx); + /*! Obtain next node in respect to specified node * * \param[in] node Node referenced @@ -136,6 +144,7 @@ ares__llist_node_t *ares__llist_node_next(ares__llist_node_t *node); */ ares__llist_node_t *ares__llist_node_prev(ares__llist_node_t *node); + /*! Obtain value from node * * \param[in] node Node referenced @@ -150,6 +159,12 @@ void *ares__llist_node_val(ares__llist_node_t *node); */ size_t ares__llist_len(const ares__llist_t *list); +/*! Clear all entries in the list, but don't destroy the list object. + * + * \param[in] list Initialized list object + */ +void ares__llist_clear(ares__llist_t *list); + /*! Obtain list object from referenced node * * \param[in] node Node referenced diff --git a/deps/cares/src/lib/ares__parse_into_addrinfo.c b/deps/cares/src/lib/ares__parse_into_addrinfo.c index e886585d06a386..65c94c0401441b 100644 --- a/deps/cares/src/lib/ares__parse_into_addrinfo.c +++ b/deps/cares/src/lib/ares__parse_into_addrinfo.c @@ -24,7 +24,7 @@ * * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" +#include "ares_private.h" #ifdef HAVE_NETINET_IN_H # include @@ -44,8 +44,6 @@ # include #endif -#include "ares.h" -#include "ares_private.h" ares_status_t ares__parse_into_addrinfo(const ares_dns_record_t *dnsrec, ares_bool_t cname_only_is_enodata, @@ -108,18 +106,18 @@ ares_status_t ares__parse_into_addrinfo(const ares_dns_record_t *dnsrec, cname = ares__append_addrinfo_cname(&cnames); if (cname == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } cname->ttl = (int)ares_dns_rr_get_ttl(rr); cname->alias = ares_strdup(ares_dns_rr_get_name(rr)); if (cname->alias == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } cname->name = ares_strdup(hostname); if (cname->name == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } } else if (rtype == ARES_REC_TYPE_A) { got_a = ARES_TRUE; @@ -154,7 +152,7 @@ ares_status_t ares__parse_into_addrinfo(const ares_dns_record_t *dnsrec, ai->name = ares_strdup(hostname); if (ai->name == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } } diff --git a/deps/cares/src/lib/ares__slist.c b/deps/cares/src/lib/ares__slist.c index 0c92b552ecb0d1..f0e3f8b14a9885 100644 --- a/deps/cares/src/lib/ares__slist.c +++ b/deps/cares/src/lib/ares__slist.c @@ -23,8 +23,6 @@ * * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" -#include "ares.h" #include "ares_private.h" #include "ares__slist.h" @@ -254,7 +252,7 @@ ares__slist_node_t *ares__slist_insert(ares__slist_t *list, void *val) ares_free(node); } return NULL; -/* LCOV_EXCL_STOP */ + /* LCOV_EXCL_STOP */ } static void ares__slist_node_pop(ares__slist_node_t *node) diff --git a/deps/cares/src/lib/ares__socket.c b/deps/cares/src/lib/ares__socket.c index 7c19574e9f763d..7796ab2cbef9d4 100644 --- a/deps/cares/src/lib/ares__socket.c +++ b/deps/cares/src/lib/ares__socket.c @@ -24,7 +24,7 @@ * * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" +#include "ares_private.h" #ifdef HAVE_SYS_UIO_H # include @@ -56,8 +56,6 @@ #include #include -#include "ares.h" -#include "ares_private.h" ares_ssize_t ares__socket_recvfrom(ares_channel_t *channel, ares_socket_t s, void *data, size_t data_len, int flags, @@ -305,7 +303,7 @@ ares_status_t ares__open_connection(ares_channel_t *channel, setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (void *)&opt, sizeof(opt)) == -1) { ares__close_socket(channel, s); /* LCOV_EXCL_LINE: UntestablePath */ - return ARES_ECONNREFUSED; /* LCOV_EXCL_LINE: UntestablePath */ + return ARES_ECONNREFUSED; /* LCOV_EXCL_LINE: UntestablePath */ } } #endif @@ -339,7 +337,7 @@ ares_status_t ares__open_connection(ares_channel_t *channel, conn = ares_malloc(sizeof(*conn)); if (conn == NULL) { ares__close_socket(channel, s); /* LCOV_EXCL_LINE: OutOfMemory */ - return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ + return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ } memset(conn, 0, sizeof(*conn)); conn->fd = s; diff --git a/deps/cares/src/lib/ares__sortaddrinfo.c b/deps/cares/src/lib/ares__sortaddrinfo.c index 155cc8caf4441d..e9bca4e386d523 100644 --- a/deps/cares/src/lib/ares__sortaddrinfo.c +++ b/deps/cares/src/lib/ares__sortaddrinfo.c @@ -36,7 +36,7 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#include "ares_setup.h" +#include "ares_private.h" #ifdef HAVE_NETINET_IN_H # include @@ -51,8 +51,6 @@ #include #include -#include "ares.h" -#include "ares_private.h" struct addrinfo_sort_elem { struct ares_addrinfo_node *ai; diff --git a/deps/cares/src/lib/ares__threads.c b/deps/cares/src/lib/ares__threads.c index efa0e09ef27b8e..ae3a66cc31bee6 100644 --- a/deps/cares/src/lib/ares__threads.c +++ b/deps/cares/src/lib/ares__threads.c @@ -23,8 +23,6 @@ * * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" -#include "ares.h" #include "ares_private.h" #ifdef CARES_THREADS @@ -219,34 +217,22 @@ struct ares__thread_mutex { ares__thread_mutex_t *ares__thread_mutex_create(void) { - pthread_mutexattr_t attr; ares__thread_mutex_t *mut = ares_malloc_zero(sizeof(*mut)); if (mut == NULL) { return NULL; } - if (pthread_mutexattr_init(&attr) != 0) { - ares_free(mut); /* LCOV_EXCL_LINE: UntestablePath */ - return NULL; /* LCOV_EXCL_LINE: UntestablePath */ - } - - if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0) { - goto fail; /* LCOV_EXCL_LINE: UntestablePath */ - } - - if (pthread_mutex_init(&mut->mutex, &attr) != 0) { + if (pthread_mutex_init(&mut->mutex, NULL) != 0) { goto fail; /* LCOV_EXCL_LINE: UntestablePath */ } - pthread_mutexattr_destroy(&attr); return mut; /* LCOV_EXCL_START: UntestablePath */ fail: - pthread_mutexattr_destroy(&attr); ares_free(mut); return NULL; -/* LCOV_EXCL_STOP */ + /* LCOV_EXCL_STOP */ } void ares__thread_mutex_destroy(ares__thread_mutex_t *mut) @@ -384,7 +370,7 @@ ares_status_t ares__thread_create(ares__thread_t **thread, return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ } if (pthread_create(&thr->thread, NULL, func, arg) != 0) { - ares_free(thr); /* LCOV_EXCL_LINE: UntestablePath */ + ares_free(thr); /* LCOV_EXCL_LINE: UntestablePath */ return ARES_ESERVFAIL; /* LCOV_EXCL_LINE: UntestablePath */ } @@ -564,7 +550,7 @@ ares_status_t ares_queue_wait_empty(ares_channel_t *channel, int timeout_ms) } if (timeout_ms >= 0) { - tout = ares__tvnow(); + ares__tvnow(&tout); tout.sec += (ares_int64_t)(timeout_ms / 1000); tout.usec += (unsigned int)(timeout_ms % 1000) * 1000; } @@ -575,9 +561,10 @@ ares_status_t ares_queue_wait_empty(ares_channel_t *channel, int timeout_ms) ares__thread_cond_wait(channel->cond_empty, channel->lock); } else { ares_timeval_t tv_remaining; - ares_timeval_t tv_now = ares__tvnow(); + ares_timeval_t tv_now; unsigned long tms; + ares__tvnow(&tv_now); ares__timeval_remaining(&tv_remaining, &tv_now, &tout); tms = (unsigned long)((tv_remaining.sec * 1000) + (tv_remaining.usec / 1000)); diff --git a/deps/cares/src/lib/ares__timeval.c b/deps/cares/src/lib/ares__timeval.c index a41c70631bba30..9c175a82a061fa 100644 --- a/deps/cares/src/lib/ares__timeval.c +++ b/deps/cares/src/lib/ares__timeval.c @@ -24,64 +24,55 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" -#include "ares.h" #include "ares_private.h" #if defined(_WIN32) && !defined(MSDOS) -ares_timeval_t ares__tvnow(void) +void ares__tvnow(ares_timeval_t *now) { /* GetTickCount64() is available on Windows Vista and higher */ - ares_timeval_t now; ULONGLONG milliseconds = GetTickCount64(); - now.sec = (ares_int64_t)milliseconds / 1000; - now.usec = (unsigned int)(milliseconds % 1000) * 1000; - return now; + now->sec = (ares_int64_t)milliseconds / 1000; + now->usec = (unsigned int)(milliseconds % 1000) * 1000; } #elif defined(HAVE_CLOCK_GETTIME_MONOTONIC) -ares_timeval_t ares__tvnow(void) +void ares__tvnow(ares_timeval_t *now) { /* clock_gettime() is guaranteed to be increased monotonically when the * monotonic clock is queried. Time starting point is unspecified, it * could be the system start-up time, the Epoch, or something else, * in any case the time starting point does not change once that the * system has started up. */ - ares_timeval_t now; struct timespec tsnow; if (clock_gettime(CLOCK_MONOTONIC, &tsnow) == 0) { - now.sec = (ares_int64_t)tsnow.tv_sec; - now.usec = (unsigned int)(tsnow.tv_nsec / 1000); + now->sec = (ares_int64_t)tsnow.tv_sec; + now->usec = (unsigned int)(tsnow.tv_nsec / 1000); } else { /* LCOV_EXCL_START: FallbackCode */ struct timeval tv; (void)gettimeofday(&tv, NULL); - now.sec = (ares_int64_t)tv.tv_sec; - now.usec = (unsigned int)tv.tv_usec; + now->sec = (ares_int64_t)tv.tv_sec; + now->usec = (unsigned int)tv.tv_usec; /* LCOV_EXCL_STOP */ } - return now; } #elif defined(HAVE_GETTIMEOFDAY) -ares_timeval_t ares__tvnow(void) +void ares__tvnow(ares_timeval_t *now) { /* gettimeofday() is not granted to be increased monotonically, due to * clock drifting and external source time synchronization it can jump * forward or backward in time. */ - ares_timeval_t now; struct timeval tv; (void)gettimeofday(&tv, NULL); - now.sec = (ares_int64_t)tv.tv_sec; - now.usec = (unsigned int)tv.tv_usec; - - return now; + now->sec = (ares_int64_t)tv.tv_sec; + now->usec = (unsigned int)tv.tv_usec; } #else diff --git a/deps/cares/src/lib/ares_android.c b/deps/cares/src/lib/ares_android.c index 778d4d10607fa3..67a9482d72ef22 100644 --- a/deps/cares/src/lib/ares_android.c +++ b/deps/cares/src/lib/ares_android.c @@ -24,13 +24,8 @@ * SPDX-License-Identifier: MIT */ #if defined(ANDROID) || defined(__ANDROID__) - -# include - -# include "ares_setup.h" -# include "ares.h" -# include "ares_android.h" # include "ares_private.h" +# include static JavaVM *android_jvm = NULL; static jobject android_connectivity_manager = NULL; diff --git a/deps/cares/src/lib/ares_cancel.c b/deps/cares/src/lib/ares_cancel.c index 8686c366594ccb..c47bdd8a2b7988 100644 --- a/deps/cares/src/lib/ares_cancel.c +++ b/deps/cares/src/lib/ares_cancel.c @@ -24,10 +24,6 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" -#include - -#include "ares.h" #include "ares_private.h" /* @@ -58,7 +54,7 @@ void ares_cancel(ares_channel_t *channel) * can't report to caller */ if (channel->all_queries == NULL) { channel->all_queries = list_copy; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } node = ares__llist_node_first(list_copy); diff --git a/deps/cares/src/lib/ares_config.h.cmake b/deps/cares/src/lib/ares_config.h.cmake index ffe4adf25ae138..cafdadd9bbc68e 100644 --- a/deps/cares/src/lib/ares_config.h.cmake +++ b/deps/cares/src/lib/ares_config.h.cmake @@ -377,12 +377,6 @@ /* Define to 1 if you have the __system_property_get function */ #cmakedefine HAVE___SYSTEM_PROPERTY_GET 1 -/* Define to 1 if you need the malloc.h header file even with stdlib.h */ -#cmakedefine NEED_MALLOC_H 1 - -/* Define to 1 if you need the memory.h header file even with stdlib.h */ -#cmakedefine NEED_MEMORY_H 1 - /* Define if have arc4random_buf() */ #cmakedefine HAVE_ARC4RANDOM_BUF 1 @@ -443,9 +437,6 @@ /* Define to the function return type for recv. */ #define RECV_TYPE_RETV @RECV_TYPE_RETV@ -/* Define to the type qualifier of arg 2 for send. */ -#define SEND_QUAL_ARG2 @SEND_QUAL_ARG2@ - /* Define to the type of arg 1 for send. */ #define SEND_TYPE_ARG1 @SEND_TYPE_ARG1@ diff --git a/deps/cares/src/lib/ares_config.h.in b/deps/cares/src/lib/ares_config.h.in index b75beb44dd6e56..0a4aa069580108 100644 --- a/deps/cares/src/lib/ares_config.h.in +++ b/deps/cares/src/lib/ares_config.h.in @@ -451,9 +451,6 @@ /* recv() return value */ #undef RECV_TYPE_RETV -/* send() arg2 qualifier */ -#undef SEND_QUAL_ARG2 - /* send() arg1 type */ #undef SEND_TYPE_ARG1 diff --git a/deps/cares/src/lib/ares_create_query.c b/deps/cares/src/lib/ares_create_query.c index a2f2caac6e95d9..f71a71c95136c4 100644 --- a/deps/cares/src/lib/ares_create_query.c +++ b/deps/cares/src/lib/ares_create_query.c @@ -24,8 +24,6 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" -#include "ares.h" #include "ares_private.h" static int ares_create_query_int(const char *name, int dnsclass, int type, diff --git a/deps/cares/src/lib/ares_data.c b/deps/cares/src/lib/ares_data.c index e37088283bafeb..d25c3fafff59a8 100644 --- a/deps/cares/src/lib/ares_data.c +++ b/deps/cares/src/lib/ares_data.c @@ -24,14 +24,10 @@ * SPDX-License-Identifier: MIT */ - -#include "ares_setup.h" - +#include "ares_private.h" #include - -#include "ares.h" +#include #include "ares_data.h" -#include "ares_private.h" /* ** ares_free_data() - c-ares external API function. diff --git a/deps/cares/src/lib/ares_destroy.c b/deps/cares/src/lib/ares_destroy.c index a19e6d0d97c482..ade986df6fdfc2 100644 --- a/deps/cares/src/lib/ares_destroy.c +++ b/deps/cares/src/lib/ares_destroy.c @@ -25,13 +25,9 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" - -#include - -#include "ares.h" #include "ares_private.h" #include "ares_event.h" +#include void ares_destroy(ares_channel_t *channel) { diff --git a/deps/cares/src/lib/ares_dns_mapping.c b/deps/cares/src/lib/ares_dns_mapping.c index 6c4362f000b7ab..738d2f3795ab3f 100644 --- a/deps/cares/src/lib/ares_dns_mapping.c +++ b/deps/cares/src/lib/ares_dns_mapping.c @@ -23,8 +23,6 @@ * * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" -#include "ares.h" #include "ares_private.h" ares_bool_t ares_dns_opcode_isvalid(ares_dns_opcode_t opcode) @@ -518,9 +516,11 @@ ares_dns_datatype_t ares_dns_rr_key_datatype(ares_dns_rr_key_t key) return ARES_DATATYPE_U8; case ARES_RR_CAA_VALUE: - case ARES_RR_TXT_DATA: return ARES_DATATYPE_BINP; + case ARES_RR_TXT_DATA: + return ARES_DATATYPE_ABINP; + case ARES_RR_SIG_SIGNATURE: case ARES_RR_TLSA_DATA: case ARES_RR_RAW_RR_DATA: @@ -548,18 +548,14 @@ static const ares_dns_rr_key_t rr_hinfo_keys[] = { ARES_RR_HINFO_CPU, ARES_RR_HINFO_OS }; static const ares_dns_rr_key_t rr_mx_keys[] = { ARES_RR_MX_PREFERENCE, ARES_RR_MX_EXCHANGE }; -static const ares_dns_rr_key_t rr_sig_keys[] = { ARES_RR_SIG_TYPE_COVERED, - ARES_RR_SIG_ALGORITHM, - ARES_RR_SIG_LABELS, - ARES_RR_SIG_ORIGINAL_TTL, - ARES_RR_SIG_EXPIRATION, - ARES_RR_SIG_INCEPTION, - ARES_RR_SIG_KEY_TAG, - ARES_RR_SIG_SIGNERS_NAME, - ARES_RR_SIG_SIGNATURE }; -static const ares_dns_rr_key_t rr_txt_keys[] = { ARES_RR_TXT_DATA }; -static const ares_dns_rr_key_t rr_aaaa_keys[] = { ARES_RR_AAAA_ADDR }; -static const ares_dns_rr_key_t rr_srv_keys[] = { +static const ares_dns_rr_key_t rr_sig_keys[] = { + ARES_RR_SIG_TYPE_COVERED, ARES_RR_SIG_ALGORITHM, ARES_RR_SIG_LABELS, + ARES_RR_SIG_ORIGINAL_TTL, ARES_RR_SIG_EXPIRATION, ARES_RR_SIG_INCEPTION, + ARES_RR_SIG_KEY_TAG, ARES_RR_SIG_SIGNERS_NAME, ARES_RR_SIG_SIGNATURE +}; +static const ares_dns_rr_key_t rr_txt_keys[] = { ARES_RR_TXT_DATA }; +static const ares_dns_rr_key_t rr_aaaa_keys[] = { ARES_RR_AAAA_ADDR }; +static const ares_dns_rr_key_t rr_srv_keys[] = { ARES_RR_SRV_PRIORITY, ARES_RR_SRV_WEIGHT, ARES_RR_SRV_PORT, ARES_RR_SRV_TARGET }; static const ares_dns_rr_key_t rr_naptr_keys[] = { diff --git a/deps/cares/src/lib/ares_dns_multistring.c b/deps/cares/src/lib/ares_dns_multistring.c new file mode 100644 index 00000000000000..b81c46c0eeea37 --- /dev/null +++ b/deps/cares/src/lib/ares_dns_multistring.c @@ -0,0 +1,207 @@ +/* MIT License + * + * Copyright (c) 2024 Brad House + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT + */ +#include "ares_private.h" +#include "ares_dns_private.h" + +typedef struct { + unsigned char *data; + size_t len; +} multistring_data_t; + +struct ares__dns_multistring { + /*! whether or not cached concatenated string is valid */ + ares_bool_t cache_invalidated; + /*! combined/concatenated string cache */ + unsigned char *cache_str; + /*! length of combined/concatenated string */ + size_t cache_str_len; + /*! Data making up strings */ + multistring_data_t *strs; + size_t cnt; + size_t alloc; +}; + +ares__dns_multistring_t *ares__dns_multistring_create(void) +{ + return ares_malloc_zero(sizeof(ares__dns_multistring_t)); +} + +void ares__dns_multistring_clear(ares__dns_multistring_t *strs) +{ + size_t i; + + if (strs == NULL) { + return; + } + + for (i = 0; i < strs->cnt; i++) { + ares_free(strs->strs[i].data); + memset(&strs->strs[i], 0, sizeof(strs->strs[i])); + } + strs->cnt = 0; +} + +void ares__dns_multistring_destroy(ares__dns_multistring_t *strs) +{ + if (strs == NULL) { + return; + } + ares__dns_multistring_clear(strs); + ares_free(strs->strs); + ares_free(strs->cache_str); + ares_free(strs); +} + +ares_status_t ares__dns_multistring_replace_own(ares__dns_multistring_t *strs, + size_t idx, unsigned char *str, + size_t len) +{ + if (strs == NULL || str == NULL || len == 0 || idx >= strs->cnt) { + return ARES_EFORMERR; + } + + strs->cache_invalidated = ARES_TRUE; + ares_free(strs->strs[idx].data); + strs->strs[idx].data = str; + strs->strs[idx].len = len; + return ARES_SUCCESS; +} + +ares_status_t ares__dns_multistring_del(ares__dns_multistring_t *strs, + size_t idx) +{ + size_t move_cnt; + + if (strs == NULL || idx >= strs->cnt) { + return ARES_EFORMERR; + } + + strs->cache_invalidated = ARES_TRUE; + + ares_free(strs->strs[idx].data); + + move_cnt = strs->cnt - idx - 1; + if (move_cnt) { + memmove(&strs->strs[idx], &strs->strs[idx + 1], + sizeof(*strs->strs) * move_cnt); + } + + strs->cnt--; + return ARES_SUCCESS; +} + +ares_status_t ares__dns_multistring_add_own(ares__dns_multistring_t *strs, + unsigned char *str, size_t len) +{ + if (strs == NULL) { + return ARES_EFORMERR; + } + + strs->cache_invalidated = ARES_TRUE; + + /* NOTE: its ok to have an empty string added */ + if (str == NULL && len != 0) { + return ARES_EFORMERR; + } + + if (strs->alloc < strs->cnt + 1) { + size_t newalloc = (strs->alloc == 0) ? 1 : (strs->alloc << 1); + void *ptr = ares_realloc_zero(strs->strs, strs->alloc * sizeof(*strs->strs), + (newalloc) * sizeof(*strs->strs)); + if (ptr == NULL) { + return ARES_ENOMEM; + } + strs->strs = ptr; + strs->alloc = newalloc; + } + + strs->strs[strs->cnt].data = str; + strs->strs[strs->cnt].len = len; + strs->cnt++; + + return ARES_SUCCESS; +} + +size_t ares__dns_multistring_cnt(const ares__dns_multistring_t *strs) +{ + if (strs == NULL) { + return 0; + } + return strs->cnt; +} + +const unsigned char *ares__dns_multistring_get( + const ares__dns_multistring_t *strs, size_t idx, size_t *len) +{ + if (strs == NULL || idx >= strs->cnt || len == NULL) { + return NULL; + } + + *len = strs->strs[idx].len; + return strs->strs[idx].data; +} + +const unsigned char * + ares__dns_multistring_get_combined(ares__dns_multistring_t *strs, size_t *len) +{ + ares__buf_t *buf = NULL; + size_t i; + + if (strs == NULL || len == NULL) { + return NULL; + } + + *len = 0; + + /* Return cache if possible */ + if (!strs->cache_invalidated) { + *len = strs->cache_str_len; + return strs->cache_str; + } + + /* Clear cache */ + ares_free(strs->cache_str); + strs->cache_str = NULL; + strs->cache_str_len = 0; + + buf = ares__buf_create(); + + for (i = 0; i < strs->cnt; i++) { + if (ares__buf_append(buf, strs->strs[i].data, strs->strs[i].len) != + ARES_SUCCESS) { + ares__buf_destroy(buf); + return NULL; + } + } + + strs->cache_str = + (unsigned char *)ares__buf_finish_str(buf, &strs->cache_str_len); + if (strs->cache_str != NULL) { + strs->cache_invalidated = ARES_FALSE; + } + *len = strs->cache_str_len; + return strs->cache_str; +} diff --git a/deps/cares/src/lib/ares_dns_multistring.h b/deps/cares/src/lib/ares_dns_multistring.h new file mode 100644 index 00000000000000..3588f5615c3fa4 --- /dev/null +++ b/deps/cares/src/lib/ares_dns_multistring.h @@ -0,0 +1,49 @@ +/* MIT License + * + * Copyright (c) 2024 Brad House + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT + */ +#ifndef __ARES_DNS_MULTISTRING_H +#define __ARES_DNS_MULTISTRING_H + +struct ares__dns_multistring; +typedef struct ares__dns_multistring ares__dns_multistring_t; + +ares__dns_multistring_t *ares__dns_multistring_create(void); +void ares__dns_multistring_clear(ares__dns_multistring_t *strs); +void ares__dns_multistring_destroy(ares__dns_multistring_t *strs); +ares_status_t ares__dns_multistring_replace_own(ares__dns_multistring_t *strs, + size_t idx, unsigned char *str, + size_t len); +ares_status_t ares__dns_multistring_del(ares__dns_multistring_t *strs, + size_t idx); +ares_status_t ares__dns_multistring_add_own(ares__dns_multistring_t *strs, + unsigned char *str, size_t len); +size_t ares__dns_multistring_cnt(const ares__dns_multistring_t *strs); +const unsigned char *ares__dns_multistring_get( + const ares__dns_multistring_t *strs, size_t idx, size_t *len); +const unsigned char * + ares__dns_multistring_get_combined(ares__dns_multistring_t *strs, + size_t *len); + +#endif diff --git a/deps/cares/src/lib/ares_dns_name.c b/deps/cares/src/lib/ares_dns_name.c index 754f9fadd2b5c8..076d26643eb735 100644 --- a/deps/cares/src/lib/ares_dns_name.c +++ b/deps/cares/src/lib/ares_dns_name.c @@ -23,8 +23,6 @@ * * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" -#include "ares.h" #include "ares_private.h" typedef struct { @@ -59,7 +57,7 @@ static ares_status_t ares__nameoffset_create(ares__llist_t **list, } if (*list == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto fail; /* LCOV_EXCL_LINE: OutOfMemory */ + goto fail; /* LCOV_EXCL_LINE: OutOfMemory */ } off = ares_malloc_zero(sizeof(*off)); @@ -73,7 +71,7 @@ static ares_status_t ares__nameoffset_create(ares__llist_t **list, if (ares__llist_insert_last(*list, off) == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto fail; /* LCOV_EXCL_LINE: OutOfMemory */ + goto fail; /* LCOV_EXCL_LINE: OutOfMemory */ } return ARES_SUCCESS; @@ -82,7 +80,7 @@ static ares_status_t ares__nameoffset_create(ares__llist_t **list, fail: ares__nameoffset_free(off); return status; -/* LCOV_EXCL_STOP */ + /* LCOV_EXCL_STOP */ } static const ares_nameoffset_t *ares__nameoffset_find(ares__llist_t *list, @@ -113,7 +111,10 @@ static const ares_nameoffset_t *ares__nameoffset_find(ares__llist_t *list, prefix_len = name_len - val->name_len; - if (strcasecmp(val->name, name + prefix_len) != 0) { + /* Due to DNS 0x20, lets not inadvertently mangle things, use case-sensitive + * matching instead of case-insensitive. This may result in slightly + * larger DNS queries overall. */ + if (strcmp(val->name, name + prefix_len) != 0) { continue; } @@ -269,7 +270,7 @@ static ares_status_t ares_split_dns_name(ares_dns_labels_t *labels, namebuf = ares__buf_create(); if (namebuf == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } if (*name != '\0') { @@ -284,7 +285,7 @@ static ares_status_t ares_split_dns_name(ares_dns_labels_t *labels, label = ares_dns_labels_add(labels); if (label == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } while (ares__buf_fetch_bytes(namebuf, &c, 1) == ARES_SUCCESS) { @@ -293,7 +294,7 @@ static ares_status_t ares_split_dns_name(ares_dns_labels_t *labels, label = ares_dns_labels_add(labels); if (label == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } continue; } @@ -663,7 +664,7 @@ ares_status_t ares__dns_name_parse(ares__buf_t *buf, char **name, *name = ares__buf_finish_str(namebuf, NULL); if (*name == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto fail; /* LCOV_EXCL_LINE: OutOfMemory */ + goto fail; /* LCOV_EXCL_LINE: OutOfMemory */ } } diff --git a/deps/cares/src/lib/ares_dns_parse.c b/deps/cares/src/lib/ares_dns_parse.c index 765f70ce636885..57cb0f714e12e1 100644 --- a/deps/cares/src/lib/ares_dns_parse.c +++ b/deps/cares/src/lib/ares_dns_parse.c @@ -23,8 +23,6 @@ * * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" -#include "ares.h" #include "ares_private.h" #include #ifdef HAVE_STDINT_H @@ -62,14 +60,16 @@ static ares_status_t ares_dns_parse_and_set_dns_name(ares__buf_t *buf, return ARES_SUCCESS; } -static ares_status_t ares_dns_parse_and_set_dns_str( - ares__buf_t *buf, size_t max_len, ares_bool_t allow_multiple, - ares_dns_rr_t *rr, ares_dns_rr_key_t key, ares_bool_t blank_allowed) +static ares_status_t ares_dns_parse_and_set_dns_str(ares__buf_t *buf, + size_t max_len, + ares_dns_rr_t *rr, + ares_dns_rr_key_t key, + ares_bool_t blank_allowed) { ares_status_t status; char *str = NULL; - status = ares__buf_parse_dns_str(buf, max_len, &str, allow_multiple); + status = ares__buf_parse_dns_str(buf, max_len, &str); if (status != ARES_SUCCESS) { return status; } @@ -88,23 +88,21 @@ static ares_status_t ares_dns_parse_and_set_dns_str( } static ares_status_t - ares_dns_parse_and_set_dns_binstr(ares__buf_t *buf, size_t max_len, - ares_bool_t allow_multiple, - ares_dns_rr_t *rr, ares_dns_rr_key_t key) + ares_dns_parse_and_set_dns_abin(ares__buf_t *buf, size_t max_len, + ares_dns_rr_t *rr, ares_dns_rr_key_t key, + ares_bool_t validate_printable) { - ares_status_t status; - unsigned char *bin = NULL; - size_t bin_len = 0; + ares_status_t status; + ares__dns_multistring_t *strs = NULL; - status = - ares__buf_parse_dns_binstr(buf, max_len, &bin, &bin_len, allow_multiple); + status = ares__buf_parse_dns_abinstr(buf, max_len, &strs, validate_printable); if (status != ARES_SUCCESS) { return status; } - status = ares_dns_rr_set_bin_own(rr, key, bin, bin_len); + status = ares_dns_rr_set_abin_own(rr, key, strs); if (status != ARES_SUCCESS) { - ares_free(bin); + ares__dns_multistring_destroy(strs); return status; } return ARES_SUCCESS; @@ -257,7 +255,7 @@ static ares_status_t ares_dns_parse_rr_hinfo(ares__buf_t *buf, /* CPU */ status = ares_dns_parse_and_set_dns_str( - buf, ares_dns_rr_remaining_len(buf, orig_len, rdlength), ARES_FALSE, rr, + buf, ares_dns_rr_remaining_len(buf, orig_len, rdlength), rr, ARES_RR_HINFO_CPU, ARES_TRUE); if (status != ARES_SUCCESS) { return status; @@ -265,7 +263,7 @@ static ares_status_t ares_dns_parse_rr_hinfo(ares__buf_t *buf, /* OS */ status = ares_dns_parse_and_set_dns_str( - buf, ares_dns_rr_remaining_len(buf, orig_len, rdlength), ARES_FALSE, rr, + buf, ares_dns_rr_remaining_len(buf, orig_len, rdlength), rr, ARES_RR_HINFO_OS, ARES_TRUE); return status; @@ -292,8 +290,8 @@ static ares_status_t ares_dns_parse_rr_mx(ares__buf_t *buf, ares_dns_rr_t *rr, static ares_status_t ares_dns_parse_rr_txt(ares__buf_t *buf, ares_dns_rr_t *rr, size_t rdlength) { - return ares_dns_parse_and_set_dns_binstr(buf, rdlength, ARES_TRUE, rr, - ARES_RR_TXT_DATA); + return ares_dns_parse_and_set_dns_abin(buf, rdlength, rr, ARES_RR_TXT_DATA, + ARES_FALSE); } static ares_status_t ares_dns_parse_rr_sig(ares__buf_t *buf, ares_dns_rr_t *rr, @@ -430,7 +428,7 @@ static ares_status_t ares_dns_parse_rr_naptr(ares__buf_t *buf, /* FLAGS */ status = ares_dns_parse_and_set_dns_str( - buf, ares_dns_rr_remaining_len(buf, orig_len, rdlength), ARES_FALSE, rr, + buf, ares_dns_rr_remaining_len(buf, orig_len, rdlength), rr, ARES_RR_NAPTR_FLAGS, ARES_TRUE); if (status != ARES_SUCCESS) { return status; @@ -438,7 +436,7 @@ static ares_status_t ares_dns_parse_rr_naptr(ares__buf_t *buf, /* SERVICES */ status = ares_dns_parse_and_set_dns_str( - buf, ares_dns_rr_remaining_len(buf, orig_len, rdlength), ARES_FALSE, rr, + buf, ares_dns_rr_remaining_len(buf, orig_len, rdlength), rr, ARES_RR_NAPTR_SERVICES, ARES_TRUE); if (status != ARES_SUCCESS) { return status; @@ -446,7 +444,7 @@ static ares_status_t ares_dns_parse_rr_naptr(ares__buf_t *buf, /* REGEXP */ status = ares_dns_parse_and_set_dns_str( - buf, ares_dns_rr_remaining_len(buf, orig_len, rdlength), ARES_FALSE, rr, + buf, ares_dns_rr_remaining_len(buf, orig_len, rdlength), rr, ARES_RR_NAPTR_REGEXP, ARES_TRUE); if (status != ARES_SUCCESS) { return status; @@ -731,7 +729,7 @@ static ares_status_t ares_dns_parse_rr_caa(ares__buf_t *buf, ares_dns_rr_t *rr, /* Tag */ status = ares_dns_parse_and_set_dns_str( - buf, ares_dns_rr_remaining_len(buf, orig_len, rdlength), ARES_FALSE, rr, + buf, ares_dns_rr_remaining_len(buf, orig_len, rdlength), rr, ARES_RR_CAA_TAG, ARES_FALSE); if (status != ARES_SUCCESS) { return status; diff --git a/deps/cares/src/lib/ares_dns_private.h b/deps/cares/src/lib/ares_dns_private.h index e8e783d559ca7f..c82fb6a9abe23f 100644 --- a/deps/cares/src/lib/ares_dns_private.h +++ b/deps/cares/src/lib/ares_dns_private.h @@ -41,6 +41,9 @@ ares_status_t ares_dns_rr_set_str_own(ares_dns_rr_t *dns_rr, ares_status_t ares_dns_rr_set_bin_own(ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key, unsigned char *val, size_t len); +ares_status_t ares_dns_rr_set_abin_own(ares_dns_rr_t *dns_rr, + ares_dns_rr_key_t key, + ares__dns_multistring_t *strs); ares_status_t ares_dns_rr_set_opt_own(ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key, unsigned short opt, unsigned char *val, size_t val_len); @@ -120,8 +123,7 @@ typedef struct { } ares__dns_mx_t; typedef struct { - char *data; - size_t data_len; + ares__dns_multistring_t *strs; } ares__dns_txt_t; typedef struct { diff --git a/deps/cares/src/lib/ares_dns_record.c b/deps/cares/src/lib/ares_dns_record.c index 5d109999946eef..0131743e4621d8 100644 --- a/deps/cares/src/lib/ares_dns_record.c +++ b/deps/cares/src/lib/ares_dns_record.c @@ -23,8 +23,6 @@ * * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" -#include "ares.h" #include "ares_private.h" #include #ifdef HAVE_STDINT_H @@ -68,6 +66,15 @@ unsigned short ares_dns_record_get_id(const ares_dns_record_t *dnsrec) return dnsrec->id; } +ares_bool_t ares_dns_record_set_id(ares_dns_record_t *dnsrec, unsigned short id) +{ + if (dnsrec == NULL) { + return ARES_FALSE; + } + dnsrec->id = id; + return ARES_TRUE; +} + unsigned short ares_dns_record_get_flags(const ares_dns_record_t *dnsrec) { if (dnsrec == NULL) { @@ -145,7 +152,7 @@ static void ares__dns_rr_free(ares_dns_rr_t *rr) break; case ARES_REC_TYPE_TXT: - ares_free(rr->r.txt.data); + ares__dns_multistring_destroy(rr->r.txt.strs); break; case ARES_REC_TYPE_SIG: @@ -293,7 +300,7 @@ ares_status_t ares_dns_record_query_set_name(ares_dns_record_t *dnsrec, dnsrec->qd[idx].name = ares_strdup(name); if (dnsrec->qd[idx].name == NULL) { dnsrec->qd[idx].name = orig_name; /* LCOV_EXCL_LINE: OutOfMemory */ - return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ + return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ } ares_free(orig_name); @@ -664,11 +671,7 @@ static void *ares_dns_rr_data_ptr(ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key, return &dns_rr->r.sig.signature; case ARES_RR_TXT_DATA: - if (lenptr == NULL) { - return NULL; - } - *lenptr = &dns_rr->r.txt.data_len; - return &dns_rr->r.txt.data; + return &dns_rr->r.txt.strs; case ARES_RR_SRV_PRIORITY: return &dns_rr->r.srv.priority; @@ -883,26 +886,138 @@ const unsigned char *ares_dns_rr_get_bin(const ares_dns_rr_t *dns_rr, size_t const *bin_len = NULL; if ((ares_dns_rr_key_datatype(key) != ARES_DATATYPE_BIN && - ares_dns_rr_key_datatype(key) != ARES_DATATYPE_BINP) || + ares_dns_rr_key_datatype(key) != ARES_DATATYPE_BINP && + ares_dns_rr_key_datatype(key) != ARES_DATATYPE_ABINP) || len == NULL) { return NULL; } + /* Array of strings, return concatenated version */ + if (ares_dns_rr_key_datatype(key) == ARES_DATATYPE_ABINP) { + ares__dns_multistring_t * const *strs = + ares_dns_rr_data_ptr_const(dns_rr, key, NULL); + + if (strs == NULL) { + return NULL; + } + + return ares__dns_multistring_get_combined(*strs, len); + } + + /* Not a multi-string, just straight binary data */ bin = ares_dns_rr_data_ptr_const(dns_rr, key, &bin_len); if (bin == NULL) { - return 0; + return NULL; } /* Shouldn't be possible */ if (bin_len == NULL) { return NULL; } - *len = *bin_len; return *bin; } +size_t ares_dns_rr_get_abin_cnt(const ares_dns_rr_t *dns_rr, + ares_dns_rr_key_t key) +{ + ares__dns_multistring_t * const *strs; + + if (ares_dns_rr_key_datatype(key) != ARES_DATATYPE_ABINP) { + return 0; + } + + strs = ares_dns_rr_data_ptr_const(dns_rr, key, NULL); + if (strs == NULL) { + return 0; + } + + return ares__dns_multistring_cnt(*strs); +} + +const unsigned char *ares_dns_rr_get_abin(const ares_dns_rr_t *dns_rr, + ares_dns_rr_key_t key, size_t idx, + size_t *len) +{ + ares__dns_multistring_t * const *strs; + + if (ares_dns_rr_key_datatype(key) != ARES_DATATYPE_ABINP) { + return NULL; + } + + strs = ares_dns_rr_data_ptr_const(dns_rr, key, NULL); + if (strs == NULL) { + return NULL; + } + + return ares__dns_multistring_get(*strs, idx, len); +} + +ares_status_t ares_dns_rr_del_abin(ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key, + size_t idx) +{ + ares__dns_multistring_t **strs; + + if (ares_dns_rr_key_datatype(key) != ARES_DATATYPE_ABINP) { + return ARES_EFORMERR; + } + + strs = ares_dns_rr_data_ptr(dns_rr, key, NULL); + if (strs == NULL) { + return ARES_EFORMERR; + } + + return ares__dns_multistring_del(*strs, idx); +} + +ares_status_t ares_dns_rr_add_abin(ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key, + const unsigned char *val, size_t len) +{ + ares_status_t status; + ares_dns_datatype_t datatype = ares_dns_rr_key_datatype(key); + ares_bool_t is_nullterm = + (datatype == ARES_DATATYPE_ABINP) ? ARES_TRUE : ARES_FALSE; + size_t alloclen = is_nullterm ? len + 1 : len; + unsigned char *temp; + ares__dns_multistring_t **strs; + + if (ares_dns_rr_key_datatype(key) != ARES_DATATYPE_ABINP) { + return ARES_EFORMERR; + } + + strs = ares_dns_rr_data_ptr(dns_rr, key, NULL); + if (strs == NULL) { + return ARES_EFORMERR; + } + + if (*strs == NULL) { + *strs = ares__dns_multistring_create(); + if (*strs == NULL) { + return ARES_ENOMEM; + } + } + + temp = ares_malloc(alloclen); + if (temp == NULL) { + return ARES_ENOMEM; + } + + memcpy(temp, val, len); + + /* NULL-term ABINP */ + if (is_nullterm) { + temp[len] = 0; + } + + status = ares__dns_multistring_add_own(*strs, temp, len); + if (status != ARES_SUCCESS) { + ares_free(temp); + } + + return status; +} + const char *ares_dns_rr_get_str(const ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key) { @@ -1115,10 +1230,30 @@ ares_status_t ares_dns_rr_set_bin_own(ares_dns_rr_t *dns_rr, size_t *bin_len = NULL; if (ares_dns_rr_key_datatype(key) != ARES_DATATYPE_BIN && - ares_dns_rr_key_datatype(key) != ARES_DATATYPE_BINP) { + ares_dns_rr_key_datatype(key) != ARES_DATATYPE_BINP && + ares_dns_rr_key_datatype(key) != ARES_DATATYPE_ABINP) { return ARES_EFORMERR; } + if (ares_dns_rr_key_datatype(key) == ARES_DATATYPE_ABINP) { + ares__dns_multistring_t **strs = ares_dns_rr_data_ptr(dns_rr, key, NULL); + if (strs == NULL) { + return ARES_EFORMERR; + } + + if (*strs == NULL) { + *strs = ares__dns_multistring_create(); + if (*strs == NULL) { + return ARES_ENOMEM; + } + } + + /* Clear all existing entries as this is an override */ + ares__dns_multistring_clear(*strs); + + return ares__dns_multistring_add_own(*strs, val, len); + } + bin = ares_dns_rr_data_ptr(dns_rr, key, &bin_len); if (bin == NULL || bin_len == NULL) { return ARES_EFORMERR; @@ -1138,7 +1273,11 @@ ares_status_t ares_dns_rr_set_bin(ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key, { ares_status_t status; ares_dns_datatype_t datatype = ares_dns_rr_key_datatype(key); - size_t alloclen = (datatype == ARES_DATATYPE_BINP) ? len + 1 : len; + ares_bool_t is_nullterm = + (datatype == ARES_DATATYPE_BINP || datatype == ARES_DATATYPE_ABINP) + ? ARES_TRUE + : ARES_FALSE; + size_t alloclen = is_nullterm ? len + 1 : len; unsigned char *temp = ares_malloc(alloclen); if (temp == NULL) { @@ -1148,7 +1287,7 @@ ares_status_t ares_dns_rr_set_bin(ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key, memcpy(temp, val, len); /* NULL-term BINP */ - if (datatype == ARES_DATATYPE_BINP) { + if (is_nullterm) { temp[len] = 0; } @@ -1204,6 +1343,29 @@ ares_status_t ares_dns_rr_set_str(ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key, return status; } +ares_status_t ares_dns_rr_set_abin_own(ares_dns_rr_t *dns_rr, + ares_dns_rr_key_t key, + ares__dns_multistring_t *strs) +{ + ares__dns_multistring_t **strs_ptr; + + if (ares_dns_rr_key_datatype(key) != ARES_DATATYPE_ABINP) { + return ARES_EFORMERR; + } + + strs_ptr = ares_dns_rr_data_ptr(dns_rr, key, NULL); + if (strs_ptr == NULL) { + return ARES_EFORMERR; + } + + if (*strs_ptr != NULL) { + ares__dns_multistring_destroy(*strs_ptr); + } + *strs_ptr = strs; + + return ARES_SUCCESS; +} + ares_status_t ares_dns_rr_set_opt_own(ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key, unsigned short opt, unsigned char *val, size_t val_len) diff --git a/deps/cares/src/lib/ares_dns_write.c b/deps/cares/src/lib/ares_dns_write.c index 6cf15bf4e614bc..60bbd702889a84 100644 --- a/deps/cares/src/lib/ares_dns_write.c +++ b/deps/cares/src/lib/ares_dns_write.c @@ -23,8 +23,6 @@ * * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" -#include "ares.h" #include "ares_private.h" #include #ifdef HAVE_STDINT_H @@ -220,20 +218,14 @@ static ares_status_t ares_dns_write_rr_str(ares__buf_t *buf, return ares__buf_append(buf, (const unsigned char *)str, len); } -static ares_status_t ares_dns_write_rr_binstrs(ares__buf_t *buf, - const ares_dns_rr_t *rr, - ares_dns_rr_key_t key) +static ares_status_t ares_dns_write_binstr(ares__buf_t *buf, + const unsigned char *bin, + size_t bin_len) { - const unsigned char *bin; const unsigned char *ptr; - size_t bin_len; size_t ptr_len; ares_status_t status; - bin = ares_dns_rr_get_bin(rr, key, &bin_len); - if (bin == NULL) { - return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */ - } /* split into possible multiple 255-byte or less length strings */ ptr = bin; ptr_len = bin_len; @@ -264,6 +256,33 @@ static ares_status_t ares_dns_write_rr_binstrs(ares__buf_t *buf, return ARES_SUCCESS; } +static ares_status_t ares_dns_write_rr_abin(ares__buf_t *buf, + const ares_dns_rr_t *rr, + ares_dns_rr_key_t key) +{ + ares_status_t status = ARES_EFORMERR; + size_t i; + size_t cnt = ares_dns_rr_get_abin_cnt(rr, key); + + if (cnt == 0) { + return ARES_EFORMERR; + } + + for (i = 0; i < cnt; i++) { + const unsigned char *bin; + size_t bin_len; + + bin = ares_dns_rr_get_abin(rr, key, i, &bin_len); + + status = ares_dns_write_binstr(buf, bin, bin_len); + if (status != ARES_SUCCESS) { + break; + } + } + + return status; +} + static ares_status_t ares_dns_write_rr_be32(ares__buf_t *buf, const ares_dns_rr_t *rr, ares_dns_rr_key_t key) @@ -421,7 +440,7 @@ static ares_status_t ares_dns_write_rr_txt(ares__buf_t *buf, ares__llist_t **namelist) { (void)namelist; - return ares_dns_write_rr_binstrs(buf, rr, ARES_RR_TXT_DATA); + return ares_dns_write_rr_abin(buf, rr, ARES_RR_TXT_DATA); } static ares_status_t ares_dns_write_rr_sig(ares__buf_t *buf, @@ -589,6 +608,12 @@ static ares_status_t ares_dns_write_rr_opt(ares__buf_t *buf, (void)namelist; + /* Coverity reports on this even though its not possible when taken + * into context */ + if (len == 0) { + return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */ + } + /* We need to go back and overwrite the class and ttl that were emitted as * the OPT record overloads them for its own use (yes, very strange!) */ status = ares__buf_set_length(buf, len - 2 /* RDLENGTH */ @@ -865,6 +890,12 @@ static ares_status_t ares_dns_write_rr_raw_rr(ares__buf_t *buf, (void)namelist; + /* Coverity reports on this even though its not possible when taken + * into context */ + if (len == 0) { + return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */ + } + /* We need to go back and overwrite the type that was emitted by the parent * function */ status = ares__buf_set_length(buf, len - 2 /* RDLENGTH */ diff --git a/deps/cares/src/lib/ares_event.h b/deps/cares/src/lib/ares_event.h index f5d044d2a6ca19..317731fc4289ad 100644 --- a/deps/cares/src/lib/ares_event.h +++ b/deps/cares/src/lib/ares_event.h @@ -26,8 +26,6 @@ #ifndef __ARES__EVENT_H #define __ARES__EVENT_H -#include "ares_setup.h" - struct ares_event; typedef struct ares_event ares_event_t; diff --git a/deps/cares/src/lib/ares_event_configchg.c b/deps/cares/src/lib/ares_event_configchg.c index b7c5ad8c75b621..efdfc0409d6be9 100644 --- a/deps/cares/src/lib/ares_event_configchg.c +++ b/deps/cares/src/lib/ares_event_configchg.c @@ -23,8 +23,6 @@ * * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" -#include "ares.h" #include "ares_private.h" #include "ares_event.h" @@ -149,7 +147,7 @@ ares_status_t ares_event_configchg_init(ares_event_configchg_t **configchg, c->inotify_fd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC); if (c->inotify_fd == -1) { status = ARES_ESERVFAIL; /* LCOV_EXCL_LINE: UntestablePath */ - goto done; /* LCOV_EXCL_LINE: UntestablePath */ + goto done; /* LCOV_EXCL_LINE: UntestablePath */ } /* We need to monitor /etc/resolv.conf, /etc/nsswitch.conf */ @@ -157,7 +155,7 @@ ares_status_t ares_event_configchg_init(ares_event_configchg_t **configchg, IN_CREATE | IN_MODIFY | IN_MOVED_TO | IN_ONLYDIR) == -1) { status = ARES_ESERVFAIL; /* LCOV_EXCL_LINE: UntestablePath */ - goto done; /* LCOV_EXCL_LINE: UntestablePath */ + goto done; /* LCOV_EXCL_LINE: UntestablePath */ } status = @@ -250,32 +248,29 @@ static void ares_event_configchg_ip_cb(PVOID CallerContext, } # endif -static ares_bool_t ares_event_configchg_regnotify(ares_event_configchg_t *configchg) +static ares_bool_t + ares_event_configchg_regnotify(ares_event_configchg_t *configchg) { # if defined(__WATCOMC__) && !defined(REG_NOTIFY_THREAD_AGNOSTIC) # define REG_NOTIFY_THREAD_AGNOSTIC 0x10000000L # endif - DWORD flags = - REG_NOTIFY_CHANGE_NAME|REG_NOTIFY_CHANGE_LAST_SET|REG_NOTIFY_THREAD_AGNOSTIC; + DWORD flags = REG_NOTIFY_CHANGE_NAME | REG_NOTIFY_CHANGE_LAST_SET | + REG_NOTIFY_THREAD_AGNOSTIC; - if (RegNotifyChangeKeyValue(configchg->regip4, TRUE, - flags, - configchg->regip4_event, - TRUE) != ERROR_SUCCESS) { + if (RegNotifyChangeKeyValue(configchg->regip4, TRUE, flags, + configchg->regip4_event, TRUE) != ERROR_SUCCESS) { return ARES_FALSE; } - if (RegNotifyChangeKeyValue(configchg->regip6, TRUE, - flags, - configchg->regip6_event, - TRUE) != ERROR_SUCCESS) { + if (RegNotifyChangeKeyValue(configchg->regip6, TRUE, flags, + configchg->regip6_event, TRUE) != ERROR_SUCCESS) { return ARES_FALSE; } return ARES_TRUE; } -static VOID CALLBACK ares_event_configchg_reg_cb(PVOID lpParameter, +static VOID CALLBACK ares_event_configchg_reg_cb(PVOID lpParameter, BOOLEAN TimerOrWaitFired) { ares_event_configchg_t *configchg = lpParameter; @@ -301,7 +296,7 @@ ares_status_t ares_event_configchg_init(ares_event_configchg_t **configchg, c->e = e; -#ifndef __WATCOMC__ +# ifndef __WATCOMC__ /* NOTE: If a user goes into the control panel and changes the network * adapter DNS addresses manually, this will NOT trigger a notification. * We've also tried listening on NotifyUnicastIpAddressChange(), but @@ -313,20 +308,22 @@ ares_status_t ares_event_configchg_init(ares_event_configchg_t **configchg, status = ARES_ESERVFAIL; goto done; } -#endif +# endif /* Monitor HKLM\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters\Interfaces * and HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces * for changes via RegNotifyChangeKeyValue() */ - if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, - "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces", - 0, KEY_NOTIFY, &c->regip4) != ERROR_SUCCESS) { + if (RegOpenKeyExW( + HKEY_LOCAL_MACHINE, + L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces", 0, + KEY_NOTIFY, &c->regip4) != ERROR_SUCCESS) { status = ARES_ESERVFAIL; goto done; } - if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, - "SYSTEM\\CurrentControlSet\\Services\\Tcpip6\\Parameters\\Interfaces", + if (RegOpenKeyExW( + HKEY_LOCAL_MACHINE, + L"SYSTEM\\CurrentControlSet\\Services\\Tcpip6\\Parameters\\Interfaces", 0, KEY_NOTIFY, &c->regip6) != ERROR_SUCCESS) { status = ARES_ESERVFAIL; goto done; @@ -345,13 +342,15 @@ ares_status_t ares_event_configchg_init(ares_event_configchg_t **configchg, } if (!RegisterWaitForSingleObject(&c->regip4_wait, c->regip4_event, - ares_event_configchg_reg_cb, c, INFINITE, WT_EXECUTEDEFAULT)) { + ares_event_configchg_reg_cb, c, INFINITE, + WT_EXECUTEDEFAULT)) { status = ARES_ESERVFAIL; goto done; } if (!RegisterWaitForSingleObject(&c->regip6_wait, c->regip6_event, - ares_event_configchg_reg_cb, c, INFINITE, WT_EXECUTEDEFAULT)) { + ares_event_configchg_reg_cb, c, INFINITE, + WT_EXECUTEDEFAULT)) { status = ARES_ESERVFAIL; goto done; } @@ -446,15 +445,16 @@ static void ares_event_configchg_cb(ares_event_thread_t *e, ares_socket_t fd, ares_status_t ares_event_configchg_init(ares_event_configchg_t **configchg, ares_event_thread_t *e) { - ares_status_t status = ARES_SUCCESS; - void *handle = NULL; - const char *(*pdns_configuration_notify_key)(void) = NULL; - const char *notify_key = NULL; - int flags; - size_t i; - const char *searchlibs[] = { + ares_status_t status = ARES_SUCCESS; + void *handle = NULL; + const char *(*pdns_configuration_notify_key)(void) = NULL; + const char *notify_key = NULL; + int flags; + size_t i; + const char *searchlibs[] = { "/usr/lib/libSystem.dylib", - "/System/Library/Frameworks/SystemConfiguration.framework/SystemConfiguration", + "/System/Library/Frameworks/SystemConfiguration.framework/" + "SystemConfiguration", NULL }; @@ -464,14 +464,15 @@ ares_status_t ares_event_configchg_init(ares_event_configchg_t **configchg, } /* Load symbol as it isn't normally public */ - for (i=0; searchlibs[i] != NULL; i++) { + for (i = 0; searchlibs[i] != NULL; i++) { handle = dlopen(searchlibs[i], RTLD_LAZY); if (handle == NULL) { /* Fail, loop! */ continue; } - pdns_configuration_notify_key = dlsym(handle, "dns_configuration_notify_key"); + pdns_configuration_notify_key = (const char *(*)(void)) + dlsym(handle, "dns_configuration_notify_key"); if (pdns_configuration_notify_key != NULL) { break; } @@ -548,10 +549,15 @@ static ares_status_t config_change_check(ares__htable_strvp_t *filestat, const char *resolvconf_path) { size_t i; - const char *configfiles[] = { resolvconf_path, "/etc/nsswitch.conf", - "/etc/netsvc.conf", "/etc/svc.conf", NULL }; + const char *configfiles[5]; ares_bool_t changed = ARES_FALSE; + configfiles[0] = resolvconf_path; + configfiles[1] = "/etc/nsswitch.conf"; + configfiles[2] = "/etc/netsvc.conf"; + configfiles[3] = "/etc/svc.conf"; + configfiles[4] = NULL; + for (i = 0; configfiles[i] != NULL; i++) { fileinfo_t *fi = ares__htable_strvp_get_direct(filestat, configfiles[i]); struct stat st; diff --git a/deps/cares/src/lib/ares_event_epoll.c b/deps/cares/src/lib/ares_event_epoll.c index 9ebd87c05c25ce..5eb25cccc9ed2a 100644 --- a/deps/cares/src/lib/ares_event_epoll.c +++ b/deps/cares/src/lib/ares_event_epoll.c @@ -23,8 +23,6 @@ * * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" -#include "ares.h" #include "ares_private.h" #include "ares_event.h" @@ -73,20 +71,16 @@ static ares_bool_t ares_evsys_epoll_init(ares_event_thread_t *e) e->ev_sys_data = ep; - ep->epoll_fd = epoll_create1(0); + ep->epoll_fd = epoll_create1(EPOLL_CLOEXEC); if (ep->epoll_fd == -1) { ares_evsys_epoll_destroy(e); /* LCOV_EXCL_LINE: UntestablePath */ - return ARES_FALSE; /* LCOV_EXCL_LINE: UntestablePath */ + return ARES_FALSE; /* LCOV_EXCL_LINE: UntestablePath */ } -# ifdef FD_CLOEXEC - fcntl(ep->epoll_fd, F_SETFD, FD_CLOEXEC); -# endif - e->ev_signal = ares_pipeevent_create(e); if (e->ev_signal == NULL) { ares_evsys_epoll_destroy(e); /* LCOV_EXCL_LINE: UntestablePath */ - return ARES_FALSE; /* LCOV_EXCL_LINE: UntestablePath */ + return ARES_FALSE; /* LCOV_EXCL_LINE: UntestablePath */ } return ARES_TRUE; diff --git a/deps/cares/src/lib/ares_event_kqueue.c b/deps/cares/src/lib/ares_event_kqueue.c index 7e2c60abf518d8..585033e05ae9ac 100644 --- a/deps/cares/src/lib/ares_event_kqueue.c +++ b/deps/cares/src/lib/ares_event_kqueue.c @@ -23,8 +23,6 @@ * * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" -#include "ares.h" #include "ares_private.h" #include "ares_event.h" diff --git a/deps/cares/src/lib/ares_event_poll.c b/deps/cares/src/lib/ares_event_poll.c index bcaac7919945f1..42ffd912e95c4b 100644 --- a/deps/cares/src/lib/ares_event_poll.c +++ b/deps/cares/src/lib/ares_event_poll.c @@ -23,8 +23,6 @@ * * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" -#include "ares.h" #include "ares_private.h" #include "ares_event.h" #ifdef HAVE_POLL_H diff --git a/deps/cares/src/lib/ares_event_select.c b/deps/cares/src/lib/ares_event_select.c index 89b399b92acad5..980652002c3372 100644 --- a/deps/cares/src/lib/ares_event_select.c +++ b/deps/cares/src/lib/ares_event_select.c @@ -29,8 +29,6 @@ * anyhow */ #define FD_SETSIZE 4096 -#include "ares_setup.h" -#include "ares.h" #include "ares_private.h" #include "ares_event.h" #ifdef HAVE_SYS_SELECT_H diff --git a/deps/cares/src/lib/ares_event_thread.c b/deps/cares/src/lib/ares_event_thread.c index e87313f6296b79..48aacdedd57589 100644 --- a/deps/cares/src/lib/ares_event_thread.c +++ b/deps/cares/src/lib/ares_event_thread.c @@ -23,8 +23,6 @@ * * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" -#include "ares.h" #include "ares_private.h" #include "ares_event.h" @@ -128,7 +126,7 @@ ares_status_t ares_event_update(ares_event_t **event, ares_event_thread_t *e, } if (ares__llist_insert_last(e->ev_updates, ev) == NULL) { - ares_free(ev); /* LCOV_EXCL_LINE: OutOfMemory */ + ares_free(ev); /* LCOV_EXCL_LINE: OutOfMemory */ return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ } } @@ -274,16 +272,19 @@ static void *ares_event_thread(void *arg) const struct timeval *tvout; unsigned long timeout_ms = 0; /* 0 = unlimited */ + ares_event_process_updates(e); + + /* Don't hold a mutex while waiting on events or calling into anything + * that might require a c-ares channel lock since a callback could be + * triggered cross-thread */ + ares__thread_mutex_unlock(e->mutex); + tvout = ares_timeout(e->channel, NULL, &tv); if (tvout != NULL) { timeout_ms = (unsigned long)((tvout->tv_sec * 1000) + (tvout->tv_usec / 1000) + 1); } - ares_event_process_updates(e); - - /* Don't hold a mutex while waiting on events */ - ares__thread_mutex_unlock(e->mutex); e->ev_sys->wait(e, timeout_ms); /* Each iteration should do timeout processing */ @@ -391,22 +392,23 @@ static const ares_event_sys_t *ares_event_fetch_sys(ares_evsys_t evsys) /* case ARES_EVSYS_DEFAULT: */ default: + break; + } + + /* default */ #if defined(USE_WINSOCK) - return &ares_evsys_win32; + return &ares_evsys_win32; #elif defined(HAVE_KQUEUE) - return &ares_evsys_kqueue; + return &ares_evsys_kqueue; #elif defined(HAVE_EPOLL) - return &ares_evsys_epoll; + return &ares_evsys_epoll; #elif defined(HAVE_POLL) - return &ares_evsys_poll; + return &ares_evsys_poll; #elif defined(HAVE_PIPE) - return &ares_evsys_select; + return &ares_evsys_select; #else - break; -#endif - } - return NULL; +#endif } ares_status_t ares_event_thread_init(ares_channel_t *channel) @@ -421,25 +423,25 @@ ares_status_t ares_event_thread_init(ares_channel_t *channel) e->mutex = ares__thread_mutex_create(); if (e->mutex == NULL) { ares_event_thread_destroy_int(e); /* LCOV_EXCL_LINE: OutOfMemory */ - return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ + return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ } e->ev_updates = ares__llist_create(NULL); if (e->ev_updates == NULL) { ares_event_thread_destroy_int(e); /* LCOV_EXCL_LINE: OutOfMemory */ - return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ + return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ } e->ev_sock_handles = ares__htable_asvp_create(ares_event_destroy_cb); if (e->ev_sock_handles == NULL) { ares_event_thread_destroy_int(e); /* LCOV_EXCL_LINE: OutOfMemory */ - return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ + return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ } e->ev_cust_handles = ares__htable_vpvp_create(NULL, ares_event_destroy_cb); if (e->ev_cust_handles == NULL) { ares_event_thread_destroy_int(e); /* LCOV_EXCL_LINE: OutOfMemory */ - return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ + return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ } e->channel = channel; @@ -447,7 +449,7 @@ ares_status_t ares_event_thread_init(ares_channel_t *channel) e->ev_sys = ares_event_fetch_sys(channel->evsys); if (e->ev_sys == NULL) { ares_event_thread_destroy_int(e); /* LCOV_EXCL_LINE: UntestablePath */ - return ARES_ENOTIMP; /* LCOV_EXCL_LINE: UntestablePath */ + return ARES_ENOTIMP; /* LCOV_EXCL_LINE: UntestablePath */ } channel->sock_state_cb = ares_event_thread_sockstate_cb; diff --git a/deps/cares/src/lib/ares_event_wake_pipe.c b/deps/cares/src/lib/ares_event_wake_pipe.c index c0aa70b5dea45f..282d013dc62b24 100644 --- a/deps/cares/src/lib/ares_event_wake_pipe.c +++ b/deps/cares/src/lib/ares_event_wake_pipe.c @@ -23,8 +23,6 @@ * * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" -#include "ares.h" #include "ares_private.h" #include "ares_event.h" #ifdef HAVE_UNISTD_H @@ -69,7 +67,7 @@ static ares_pipeevent_t *ares_pipeevent_init(void) # ifdef HAVE_PIPE2 if (pipe2(p->filedes, O_NONBLOCK | O_CLOEXEC) != 0) { ares_pipeevent_destroy(p); /* LCOV_EXCL_LINE: UntestablePath */ - return NULL; /* LCOV_EXCL_LINE: UntestablePath */ + return NULL; /* LCOV_EXCL_LINE: UntestablePath */ } # else if (pipe(p->filedes) != 0) { @@ -157,7 +155,7 @@ ares_event_t *ares_pipeevent_create(ares_event_thread_t *e) ares_pipeevent_signal); if (status != ARES_SUCCESS) { ares_pipeevent_destroy(p); /* LCOV_EXCL_LINE: DefensiveCoding */ - return NULL; /* LCOV_EXCL_LINE: DefensiveCoding */ + return NULL; /* LCOV_EXCL_LINE: DefensiveCoding */ } return event; diff --git a/deps/cares/src/lib/ares_event_win32.c b/deps/cares/src/lib/ares_event_win32.c index fa84864b4bedce..4e4b9c53c3389f 100644 --- a/deps/cares/src/lib/ares_event_win32.c +++ b/deps/cares/src/lib/ares_event_win32.c @@ -24,8 +24,12 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" -#include "ares.h" +/* Uses an anonymous union */ +#if defined(__clang__) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wc11-extensions" +#endif + #include "ares_private.h" #include "ares_event.h" #include "ares_event_win32.h" @@ -254,12 +258,28 @@ static ares_bool_t ares_evsys_win32_init(ares_event_thread_t *e) goto fail; } +#ifdef __GNUC__ +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wpedantic" +/* Without the (void *) cast we get: + * warning: cast between incompatible function types from 'FARPROC' {aka 'long long int (*)()'} to 'NTSTATUS (*)(...)'} [-Wcast-function-type] + * but with it we get: + * warning: ISO C forbids conversion of function pointer to object pointer type [-Wpedantic] + * look unsolvable short of killing the warning. + */ +#endif + + /* Load Internal symbols not typically accessible */ ew->NtDeviceIoControlFile = (NtDeviceIoControlFile_t)(void *)GetProcAddress( ntdll, "NtDeviceIoControlFile"); ew->NtCancelIoFileEx = (NtCancelIoFileEx_t)(void *)GetProcAddress(ntdll, "NtCancelIoFileEx"); +#ifdef __GNUC__ +# pragma GCC diagnostic pop +#endif + if (ew->NtCancelIoFileEx == NULL || ew->NtDeviceIoControlFile == NULL) { goto fail; } @@ -365,8 +385,6 @@ static ares_bool_t ares_evsys_win32_afd_enqueue(ares_event_t *event, IOCTL_AFD_POLL, &ed->afd_poll_info, sizeof(ed->afd_poll_info), &ed->afd_poll_info, sizeof(ed->afd_poll_info)); if (status != STATUS_SUCCESS && status != STATUS_PENDING) { - printf("%s(): failed to perform IOCTL_AFD_POLL operation\n", __FUNCTION__); - fflush(stdout); return ARES_FALSE; } @@ -441,8 +459,6 @@ static ares_bool_t ares_evsys_win32_event_add(ares_event_t *event) ed->base_socket = ares_evsys_win32_basesocket(ed->socket); if (ed->base_socket == ARES_SOCKET_BAD) { - fprintf(stderr, "%s(): could not determine base socket for fd %d\n", - __FUNCTION__, (int)event->fd); ares_evsys_win32_eventdata_destroy(ed); return ARES_FALSE; } @@ -451,9 +467,6 @@ static ares_bool_t ares_evsys_win32_event_add(ares_event_t *event) * socket handle */ if (WSADuplicateSocketW(ed->base_socket, GetCurrentProcessId(), &protocol_info) != 0) { - fprintf(stderr, - "%s(): could not retrieve protocol info for creating peer socket\n", - __FUNCTION__); ares_evsys_win32_eventdata_destroy(ed); return ARES_FALSE; } @@ -462,7 +475,6 @@ static ares_bool_t ares_evsys_win32_event_add(ares_event_t *event) WSASocketW(protocol_info.iAddressFamily, protocol_info.iSocketType, protocol_info.iProtocol, &protocol_info, 0, WSA_FLAG_OVERLAPPED); if (ed->peer_socket == ARES_SOCKET_BAD) { - fprintf(stderr, "%s(): could not create peer socket\n", __FUNCTION__); ares_evsys_win32_eventdata_destroy(ed); return ARES_FALSE; } @@ -471,7 +483,6 @@ static ares_bool_t ares_evsys_win32_event_add(ares_event_t *event) if (CreateIoCompletionPort((HANDLE)ed->peer_socket, ew->iocp_handle, (ULONG_PTR)ed, 0) == NULL) { - fprintf(stderr, "%s(): failed to bind peer socket to IOCP\n", __FUNCTION__); ares_evsys_win32_eventdata_destroy(ed); return ARES_FALSE; } @@ -599,3 +610,7 @@ const ares_event_sys_t ares_evsys_win32 = { "win32", ares_evsys_win32_event_mod, ares_evsys_win32_wait }; #endif + +#if defined(__clang__) +# pragma GCC diagnostic pop +#endif diff --git a/deps/cares/src/lib/ares_expand_name.c b/deps/cares/src/lib/ares_expand_name.c index 8f6728dedd315b..63bd64516682e3 100644 --- a/deps/cares/src/lib/ares_expand_name.c +++ b/deps/cares/src/lib/ares_expand_name.c @@ -25,7 +25,7 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" +#include "ares_private.h" #ifdef HAVE_NETINET_IN_H # include @@ -33,9 +33,6 @@ #include "ares_nameser.h" -#include "ares.h" -#include "ares_private.h" /* for the memdebug */ - ares_status_t ares__expand_name_validated(const unsigned char *encoded, const unsigned char *abuf, size_t alen, char **s, size_t *enclen, diff --git a/deps/cares/src/lib/ares_expand_string.c b/deps/cares/src/lib/ares_expand_string.c index 502125a8af5f67..570ccd917a32c0 100644 --- a/deps/cares/src/lib/ares_expand_string.c +++ b/deps/cares/src/lib/ares_expand_string.c @@ -25,7 +25,7 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" +#include "ares_private.h" #ifdef HAVE_NETINET_IN_H # include @@ -33,9 +33,6 @@ #include "ares_nameser.h" -#include "ares.h" -#include "ares_private.h" /* for the memdebug */ - /* Simply decodes a length-encoded character string. The first byte of the * input is the length of the string to be returned and the bytes thereafter * are the characters of the string. The returned result will be NULL @@ -78,7 +75,7 @@ ares_status_t ares_expand_string_ex(const unsigned char *encoded, start_len = ares__buf_len(buf); status = - ares__buf_parse_dns_binstr(buf, ares__buf_len(buf), s, &len, ARES_FALSE); + ares__buf_parse_dns_binstr(buf, ares__buf_len(buf), s, &len); /* hrm, no way to pass back 'len' with the prototype */ if (status != ARES_SUCCESS) { goto done; diff --git a/deps/cares/src/lib/ares_fds.c b/deps/cares/src/lib/ares_fds.c index e39823304a70ae..0502e71182ade7 100644 --- a/deps/cares/src/lib/ares_fds.c +++ b/deps/cares/src/lib/ares_fds.c @@ -25,9 +25,6 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" - -#include "ares.h" #include "ares_private.h" int ares_fds(const ares_channel_t *channel, fd_set *read_fds, fd_set *write_fds) diff --git a/deps/cares/src/lib/ares_free_hostent.c b/deps/cares/src/lib/ares_free_hostent.c index a088c1b15cdf8d..bf2037238b559e 100644 --- a/deps/cares/src/lib/ares_free_hostent.c +++ b/deps/cares/src/lib/ares_free_hostent.c @@ -24,16 +24,12 @@ * * SPDX-License-Identifier: MIT */ - -#include "ares_setup.h" +#include "ares_private.h" #ifdef HAVE_NETDB_H # include #endif -#include "ares.h" -#include "ares_private.h" /* for memdebug */ - void ares_free_hostent(struct hostent *host) { char **p; diff --git a/deps/cares/src/lib/ares_free_string.c b/deps/cares/src/lib/ares_free_string.c index 39773067bd2d85..048ad5d2ae242e 100644 --- a/deps/cares/src/lib/ares_free_string.c +++ b/deps/cares/src/lib/ares_free_string.c @@ -25,9 +25,6 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" - -#include "ares.h" #include "ares_private.h" void ares_free_string(void *str) diff --git a/deps/cares/src/lib/ares_freeaddrinfo.c b/deps/cares/src/lib/ares_freeaddrinfo.c index 45d931a3f86f8e..2a49f57531e9bb 100644 --- a/deps/cares/src/lib/ares_freeaddrinfo.c +++ b/deps/cares/src/lib/ares_freeaddrinfo.c @@ -25,15 +25,12 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" +#include "ares_private.h" #ifdef HAVE_NETDB_H # include #endif -#include "ares.h" -#include "ares_private.h" - void ares__freeaddrinfo_cnames(struct ares_addrinfo_cname *head) { struct ares_addrinfo_cname *current; diff --git a/deps/cares/src/lib/ares_getaddrinfo.c b/deps/cares/src/lib/ares_getaddrinfo.c index 51463402e2fc87..8a195ed0220d5d 100644 --- a/deps/cares/src/lib/ares_getaddrinfo.c +++ b/deps/cares/src/lib/ares_getaddrinfo.c @@ -26,7 +26,7 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" +#include "ares_private.h" #ifdef HAVE_GETSERVBYNAME_R # if !defined(GETSERVBYNAME_R_ARGS) || (GETSERVBYNAME_R_ARGS < 4) || \ @@ -56,8 +56,6 @@ # include #endif -#include "ares.h" -#include "ares_private.h" #include "ares_dns.h" #ifdef _WIN32 @@ -254,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 (!isdigit(*p) && *p != '.') { valid = ARES_FALSE; break; } else if (*p == '.') { @@ -275,7 +273,7 @@ static ares_bool_t fake_addrinfo(const char *name, unsigned short port, status = ares_append_ai_node(AF_INET, port, 0, &addr4, &ai->nodes); if (status != ARES_SUCCESS) { callback(arg, (int)status, 0, NULL); /* LCOV_EXCL_LINE: OutOfMemory */ - return ARES_TRUE; /* LCOV_EXCL_LINE: OutOfMemory */ + return ARES_TRUE; /* LCOV_EXCL_LINE: OutOfMemory */ } } } @@ -289,7 +287,7 @@ static ares_bool_t fake_addrinfo(const char *name, unsigned short port, status = ares_append_ai_node(AF_INET6, port, 0, &addr6, &ai->nodes); if (status != ARES_SUCCESS) { callback(arg, (int)status, 0, NULL); /* LCOV_EXCL_LINE: OutOfMemory */ - return ARES_TRUE; /* LCOV_EXCL_LINE: OutOfMemory */ + return ARES_TRUE; /* LCOV_EXCL_LINE: OutOfMemory */ } } } @@ -674,20 +672,20 @@ static ares_bool_t next_dns_lookup(struct host_query *hquery) switch (hquery->hints.ai_family) { case AF_INET: hquery->remaining += 1; - ares_query_dnsrec(hquery->channel, name, ARES_CLASS_IN, ARES_REC_TYPE_A, + ares_query_nolock(hquery->channel, name, ARES_CLASS_IN, ARES_REC_TYPE_A, host_callback, hquery, &hquery->qid_a); break; case AF_INET6: hquery->remaining += 1; - ares_query_dnsrec(hquery->channel, name, ARES_CLASS_IN, + ares_query_nolock(hquery->channel, name, ARES_CLASS_IN, ARES_REC_TYPE_AAAA, host_callback, hquery, &hquery->qid_aaaa); break; case AF_UNSPEC: hquery->remaining += 2; - ares_query_dnsrec(hquery->channel, name, ARES_CLASS_IN, ARES_REC_TYPE_A, + ares_query_nolock(hquery->channel, name, ARES_CLASS_IN, ARES_REC_TYPE_A, host_callback, hquery, &hquery->qid_a); - ares_query_dnsrec(hquery->channel, name, ARES_CLASS_IN, + ares_query_nolock(hquery->channel, name, ARES_CLASS_IN, ARES_REC_TYPE_AAAA, host_callback, hquery, &hquery->qid_aaaa); break; diff --git a/deps/cares/src/lib/ares_getenv.c b/deps/cares/src/lib/ares_getenv.c index 08601a61e54076..4f471673b9d3dd 100644 --- a/deps/cares/src/lib/ares_getenv.c +++ b/deps/cares/src/lib/ares_getenv.c @@ -25,7 +25,7 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" +#include "ares_private.h" #include "ares_getenv.h" #ifndef HAVE_GETENV diff --git a/deps/cares/src/lib/ares_getenv.h b/deps/cares/src/lib/ares_getenv.h index d8bd3a2195b417..490097fc8d35bc 100644 --- a/deps/cares/src/lib/ares_getenv.h +++ b/deps/cares/src/lib/ares_getenv.h @@ -27,8 +27,6 @@ #ifndef HEADER_CARES_GETENV_H #define HEADER_CARES_GETENV_H -#include "ares_setup.h" - #ifndef HAVE_GETENV extern char *ares_getenv(const char *name); #endif diff --git a/deps/cares/src/lib/ares_gethostbyaddr.c b/deps/cares/src/lib/ares_gethostbyaddr.c index 9676e17edfb12b..1db81ec2b48b9d 100644 --- a/deps/cares/src/lib/ares_gethostbyaddr.c +++ b/deps/cares/src/lib/ares_gethostbyaddr.c @@ -25,7 +25,7 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" +#include "ares_private.h" #ifdef HAVE_NETINET_IN_H # include @@ -38,11 +38,8 @@ #endif #include "ares_nameser.h" - -#include "ares.h" #include "ares_inet_net_pton.h" #include "ares_platform.h" -#include "ares_private.h" struct addr_query { /* Arguments passed to ares_gethostbyaddr() */ @@ -64,9 +61,9 @@ static ares_status_t file_lookup(ares_channel_t *channel, const struct ares_addr *addr, struct hostent **host); -static void ares_gethostbyaddr_int(ares_channel_t *channel, const void *addr, - int addrlen, int family, - ares_host_callback callback, void *arg) +void ares_gethostbyaddr_nolock(ares_channel_t *channel, const void *addr, + int addrlen, int family, + ares_host_callback callback, void *arg) { struct addr_query *aquery; @@ -116,7 +113,7 @@ void ares_gethostbyaddr(ares_channel_t *channel, const void *addr, int addrlen, return; } ares__channel_lock(channel); - ares_gethostbyaddr_int(channel, addr, addrlen, family, callback, arg); + ares_gethostbyaddr_nolock(channel, addr, addrlen, family, callback, arg); ares__channel_unlock(channel); } @@ -132,11 +129,12 @@ static void next_lookup(struct addr_query *aquery) case 'b': name = ares_dns_addr_to_ptr(&aquery->addr); if (name == NULL) { - end_aquery(aquery, ARES_ENOMEM, NULL); /* LCOV_EXCL_LINE: OutOfMemory */ - return; /* LCOV_EXCL_LINE: OutOfMemory */ + end_aquery(aquery, ARES_ENOMEM, + NULL); /* LCOV_EXCL_LINE: OutOfMemory */ + return; /* LCOV_EXCL_LINE: OutOfMemory */ } aquery->remaining_lookups = p + 1; - ares_query_dnsrec(aquery->channel, name, ARES_CLASS_IN, + ares_query_nolock(aquery->channel, name, ARES_CLASS_IN, ARES_REC_TYPE_PTR, addr_callback, aquery, NULL); ares_free(name); return; diff --git a/deps/cares/src/lib/ares_gethostbyname.c b/deps/cares/src/lib/ares_gethostbyname.c index 2a8ec555d4edbf..6db86e0eed1c65 100644 --- a/deps/cares/src/lib/ares_gethostbyname.c +++ b/deps/cares/src/lib/ares_gethostbyname.c @@ -25,7 +25,7 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" +#include "ares_private.h" #ifdef HAVE_NETINET_IN_H # include @@ -43,10 +43,8 @@ # include #endif -#include "ares.h" #include "ares_inet_net_pton.h" #include "ares_platform.h" -#include "ares_private.h" static void sort_addresses(const struct hostent *host, const struct apattern *sortlist, size_t nsort); @@ -102,13 +100,17 @@ static void ares_gethostbyname_callback(void *arg, int status, int timeouts, void ares_gethostbyname(ares_channel_t *channel, const char *name, int family, ares_host_callback callback, void *arg) { - const struct ares_addrinfo_hints hints = { ARES_AI_CANONNAME, family, 0, 0 }; - struct host_query *ghbn_arg; + struct ares_addrinfo_hints hints; + struct host_query *ghbn_arg; if (!callback) { return; } + memset(&hints, 0, sizeof(hints)); + hints.ai_flags = ARES_AI_CANONNAME; + hints.ai_family = family; + ghbn_arg = ares_malloc(sizeof(*ghbn_arg)); if (!ghbn_arg) { callback(arg, ARES_ENOMEM, 0, NULL); @@ -249,7 +251,7 @@ static ares_status_t ares__hostent_localhost(const char *name, int family, ai = ares_malloc_zero(sizeof(*ai)); if (ai == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } status = ares__addrinfo_localhost(name, 0, &hints, ai); diff --git a/deps/cares/src/lib/ares_getnameinfo.c b/deps/cares/src/lib/ares_getnameinfo.c index 57c6ddaf999046..622c1adb1c7342 100644 --- a/deps/cares/src/lib/ares_getnameinfo.c +++ b/deps/cares/src/lib/ares_getnameinfo.c @@ -23,7 +23,7 @@ * * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" +#include "ares_private.h" #ifdef HAVE_GETSERVBYPORT_R # if !defined(GETSERVBYPORT_R_ARGS) || (GETSERVBYPORT_R_ARGS < 4) || \ @@ -51,9 +51,7 @@ # include #endif -#include "ares.h" #include "ares_ipv6.h" -#include "ares_private.h" struct nameinfo_query { ares_nameinfo_callback callback; @@ -81,8 +79,8 @@ static void nameinfo_callback(void *arg, int status, int timeouts, static char *lookup_service(unsigned short port, unsigned int flags, char *buf, size_t buflen); #ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID -static void append_scopeid(const struct sockaddr_in6 *addr6, - unsigned int flags, char *buf, size_t buflen); +static void append_scopeid(const struct sockaddr_in6 *addr6, unsigned int flags, + char *buf, size_t buflen); #endif static char *ares_striendstr(const char *s1, const char *s2); @@ -100,11 +98,11 @@ static void ares_getnameinfo_int(ares_channel_t *channel, /* Validate socket address family and length */ if (sa && sa->sa_family == AF_INET && salen >= (ares_socklen_t)sizeof(struct sockaddr_in)) { - addr = CARES_INADDR_CAST(struct sockaddr_in *, sa); + addr = CARES_INADDR_CAST(const struct sockaddr_in *, sa); port = addr->sin_port; } else if (sa && sa->sa_family == AF_INET6 && salen >= (ares_socklen_t)sizeof(struct sockaddr_in6)) { - addr6 = CARES_INADDR_CAST(struct sockaddr_in6 *, sa); + addr6 = CARES_INADDR_CAST(const struct sockaddr_in6 *, sa); port = addr6->sin6_port; } else { callback(arg, ARES_ENOTIMP, 0, NULL, NULL); @@ -173,14 +171,15 @@ static void ares_getnameinfo_int(ares_channel_t *channel, if (sa->sa_family == AF_INET) { niquery->family = AF_INET; memcpy(&niquery->addr.addr4, addr, sizeof(niquery->addr.addr4)); - ares_gethostbyaddr(channel, &addr->sin_addr, sizeof(struct in_addr), - AF_INET, nameinfo_callback, niquery); + ares_gethostbyaddr_nolock(channel, &addr->sin_addr, + sizeof(struct in_addr), AF_INET, + nameinfo_callback, niquery); } else { niquery->family = AF_INET6; memcpy(&niquery->addr.addr6, addr6, sizeof(niquery->addr.addr6)); - ares_gethostbyaddr(channel, &addr6->sin6_addr, - sizeof(struct ares_in6_addr), AF_INET6, - nameinfo_callback, niquery); + ares_gethostbyaddr_nolock(channel, &addr6->sin6_addr, + sizeof(struct ares_in6_addr), AF_INET6, + nameinfo_callback, niquery); } } } @@ -411,8 +410,8 @@ static char *ares_striendstr(const char *s1, const char *s2) c1 = c1_begin; c2 = s2; while (c2 < s2 + s2_len) { - lo1 = TOLOWER(*c1); - lo2 = TOLOWER(*c2); + lo1 = ares__tolower((unsigned char)*c1); + lo2 = ares__tolower((unsigned char)*c2); if (lo1 != lo2) { return NULL; } else { diff --git a/deps/cares/src/lib/ares_getsock.c b/deps/cares/src/lib/ares_getsock.c index b64c075572dec5..836d9b973edd9c 100644 --- a/deps/cares/src/lib/ares_getsock.c +++ b/deps/cares/src/lib/ares_getsock.c @@ -24,9 +24,6 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" - -#include "ares.h" #include "ares_private.h" int ares_getsock(const ares_channel_t *channel, ares_socket_t *socks, diff --git a/deps/cares/src/lib/ares_init.c b/deps/cares/src/lib/ares_init.c index be3cfacf58109f..5456444ae492df 100644 --- a/deps/cares/src/lib/ares_init.c +++ b/deps/cares/src/lib/ares_init.c @@ -25,7 +25,7 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" +#include "ares_private.h" #ifdef HAVE_SYS_PARAM_H # include @@ -61,10 +61,8 @@ # include #endif -#include "ares.h" #include "ares_inet_net_pton.h" #include "ares_platform.h" -#include "ares_private.h" #include "ares_event.h" int ares_init(ares_channel_t **channelptr) @@ -197,7 +195,7 @@ static ares_status_t init_by_defaults(ares_channel_t *channel) hostname = ares_malloc(len); if (!hostname) { rc = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto error; /* LCOV_EXCL_LINE: OutOfMemory */ + goto error; /* LCOV_EXCL_LINE: OutOfMemory */ } do { @@ -210,7 +208,7 @@ static ares_status_t init_by_defaults(ares_channel_t *channel) p = ares_realloc(hostname, len); if (!p) { rc = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto error; /* LCOV_EXCL_LINE: OutOfMemory */ + goto error; /* LCOV_EXCL_LINE: OutOfMemory */ } hostname = p; continue; @@ -229,12 +227,12 @@ static ares_status_t init_by_defaults(ares_channel_t *channel) channel->domains = ares_malloc(sizeof(char *)); if (!channel->domains) { rc = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto error; /* LCOV_EXCL_LINE: OutOfMemory */ + goto error; /* LCOV_EXCL_LINE: OutOfMemory */ } channel->domains[0] = ares_strdup(dot + 1); if (!channel->domains[0]) { rc = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto error; /* LCOV_EXCL_LINE: OutOfMemory */ + goto error; /* LCOV_EXCL_LINE: OutOfMemory */ } channel->ndomains = 1; } @@ -488,7 +486,6 @@ int ares_dup(ares_channel_t **dest, const ares_channel_t *src) *dest = NULL; /* in case of failure return NULL explicitly */ - ares__channel_lock(src); /* First get the options supported by the old ares_save_options() function, which is most of them */ rc = (ares_status_t)ares_save_options(src, &opts, &optmask); @@ -507,6 +504,7 @@ int ares_dup(ares_channel_t **dest, const ares_channel_t *src) goto done; } + ares__channel_lock(src); /* Now clone the options that ares_save_options() doesn't support, but are * user-provided */ (*dest)->sock_create_cb = src->sock_create_cb; @@ -522,7 +520,7 @@ int ares_dup(ares_channel_t **dest, const ares_channel_t *src) sizeof((*dest)->local_dev_name)); (*dest)->local_ip4 = src->local_ip4; memcpy((*dest)->local_ip6, src->local_ip6, sizeof(src->local_ip6)); - + ares__channel_unlock(src); /* Servers are a bit unique as ares_init_options() only allows ipv4 servers * and not a port per server, but there are other user specified ways, that @@ -558,7 +556,6 @@ int ares_dup(ares_channel_t **dest, const ares_channel_t *src) rc = ARES_SUCCESS; done: - ares__channel_unlock(src); return (int)rc; /* everything went fine */ } diff --git a/deps/cares/src/lib/ares_library_init.c b/deps/cares/src/lib/ares_library_init.c index 1d98acc403e3ea..6c2f7c0f8ce9ee 100644 --- a/deps/cares/src/lib/ares_library_init.c +++ b/deps/cares/src/lib/ares_library_init.c @@ -25,9 +25,6 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" - -#include "ares.h" #include "ares_private.h" /* library-private global and unique instance vars */ diff --git a/deps/cares/src/lib/ares_math.c b/deps/cares/src/lib/ares_math.c index eaefd6c5de7fac..45999bdeababa6 100644 --- a/deps/cares/src/lib/ares_math.c +++ b/deps/cares/src/lib/ares_math.c @@ -23,8 +23,7 @@ * * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" -#include "ares.h" + #include "ares_private.h" /* Uses public domain code snippets from @@ -57,9 +56,23 @@ static ares_int64_t ares__round_up_pow2_u64(ares_int64_t n) return n; } +ares_bool_t ares__is_64bit(void) +{ +#ifdef _MSC_VER +# pragma warning(push) +# pragma warning(disable : 4127) +#endif + + return (sizeof(size_t) == 4) ? ARES_FALSE : ARES_TRUE; + +#ifdef _MSC_VER +# pragma warning(pop) +#endif +} + size_t ares__round_up_pow2(size_t n) { - if (sizeof(size_t) > 4) { + if (ares__is_64bit()) { return (size_t)ares__round_up_pow2_u64((ares_int64_t)n); } @@ -79,7 +92,7 @@ size_t ares__log2(size_t n) 56, 45, 25, 31, 35, 16, 9, 12, 44, 24, 15, 8, 23, 7, 6, 5 }; - if (sizeof(size_t) == 4) { + if (!ares__is_64bit()) { return tab32[(n * 0x077CB531) >> 27]; } diff --git a/deps/cares/src/lib/ares_metrics.c b/deps/cares/src/lib/ares_metrics.c new file mode 100644 index 00000000000000..4b40677239fdbe --- /dev/null +++ b/deps/cares/src/lib/ares_metrics.c @@ -0,0 +1,262 @@ +/* MIT License + * + * Copyright (c) 2024 Brad House + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT + */ + + +/* IMPLEMENTATION NOTES + * ==================== + * + * With very little effort we should be able to determine fairly proper timeouts + * we can use based on prior query history. We track in order to be able to + * auto-scale when network conditions change (e.g. maybe there is a provider + * failover and timings change due to that). Apple appears to do this within + * their system resolver in MacOS. Obviously we should have a minimum, maximum, + * and initial value to make sure the algorithm doesn't somehow go off the + * rails. + * + * Values: + * - Minimum Timeout: 250ms (approximate RTT half-way around the globe) + * - Maximum Timeout: 5000ms (Recommended timeout in RFC 1123), can be reduced + * by ARES_OPT_MAXTIMEOUTMS, but otherwise the bound specified by the option + * caps the retry timeout. + * - Initial Timeout: User-specified via configuration or ARES_OPT_TIMEOUTMS + * - Average latency multiplier: 5x (a local DNS server returning a cached value + * will be quicker than if it needs to recurse so we need to account for this) + * - Minimum Count for Average: 3. This is the minimum number of queries we + * need to form an average for the bucket. + * + * Per-server buckets for tracking latency over time (these are ephemeral + * meaning they don't persist once a channel is destroyed). We record both the + * current timespan for the bucket and the immediate preceding timespan in case + * of roll-overs we can still maintain recent metrics for calculations: + * - 1 minute + * - 15 minutes + * - 1 hr + * - 1 day + * - since inception + * + * Each bucket would contain: + * - timestamp (divided by interval) + * - minimum latency + * - maximum latency + * - total time + * - count + * NOTE: average latency is (total time / count), we will calculate this + * dynamically when needed + * + * Basic algorithm for calculating timeout to use would be: + * - Scan from most recent bucket to least recent + * - Check timestamp of bucket, if doesn't match current time, continue to next + * bucket + * - Check count of bucket, if its not at least the "Minimum Count for Average", + * check the previous bucket, otherwise continue to next bucket + * - If we reached the end with no bucket match, use "Initial Timeout" + * - If bucket is selected, take ("total time" / count) as Average latency, + * multiply by "Average Latency Multiplier", bound by "Minimum Timeout" and + * "Maximum Timeout" + * NOTE: The timeout calculated may not be the timeout used. If we are retrying + * the query on the same server another time, then it will use a larger value + * + * On each query reply where the response is legitimate (proper response or + * NXDOMAIN) and not something like a server error: + * - Cycle through each bucket in order + * - Check timestamp of bucket against current timestamp, if out of date + * overwrite previous entry with values, clear current values + * - Compare current minimum and maximum recorded latency against query time and + * adjust if necessary + * - Increment "count" by 1 and "total time" by the query time + * + * Other Notes: + * - This is always-on, the only user-configurable value is the initial + * timeout which will simply re-uses the current option. + * - Minimum and Maximum latencies for a bucket are currently unused but are + * there in case we find a need for them in the future. + */ + +#include "ares_private.h" + +/*! Minimum timeout value. Chosen due to it being approximately RTT half-way + * around the world */ +#define MIN_TIMEOUT_MS 250 + +/*! Multiplier to apply to average latency to come up with an initial timeout */ +#define AVG_TIMEOUT_MULTIPLIER 5 + +/*! Upper timeout bounds, only used if channel->maxtimeout not set */ +#define MAX_TIMEOUT_MS 5000 + +/*! Minimum queries required to form an average */ +#define MIN_COUNT_FOR_AVERAGE 3 + +static time_t ares_metric_timestamp(ares_server_bucket_t bucket, + const ares_timeval_t *now, + ares_bool_t is_previous) +{ + time_t divisor = 1; /* Silence bogus MSVC warning by setting default value */ + + switch (bucket) { + case ARES_METRIC_1MINUTE: + divisor = 60; + break; + case ARES_METRIC_15MINUTES: + divisor = 15 * 60; + break; + case ARES_METRIC_1HOUR: + divisor = 60 * 60; + break; + case ARES_METRIC_1DAY: + divisor = 24 * 60 * 60; + break; + case ARES_METRIC_INCEPTION: + return is_previous ? 0 : 1; + case ARES_METRIC_COUNT: + return 0; /* Invalid! */ + } + + if (is_previous) { + if (divisor >= now->sec) { + return 0; + } + return (time_t)((now->sec - divisor) / divisor); + } + + return (time_t)(now->sec / divisor); +} + +void ares_metrics_record(const struct query *query, struct server_state *server, + ares_status_t status, const ares_dns_record_t *dnsrec) +{ + ares_timeval_t now; + ares_timeval_t tvdiff; + unsigned int query_ms; + ares_dns_rcode_t rcode; + ares_server_bucket_t i; + + if (status != ARES_SUCCESS) { + return; + } + + if (server == NULL) { + return; + } + + ares__tvnow(&now); + + rcode = ares_dns_record_get_rcode(dnsrec); + if (rcode != ARES_RCODE_NOERROR && rcode != ARES_RCODE_NXDOMAIN) { + return; + } + + ares__timeval_diff(&tvdiff, &query->ts, &now); + query_ms = (unsigned int)(tvdiff.sec + (tvdiff.usec / 1000)); + if (query_ms == 0) { + query_ms = 1; + } + + /* Place in each bucket */ + for (i = 0; i < ARES_METRIC_COUNT; i++) { + time_t ts = ares_metric_timestamp(i, &now, ARES_FALSE); + + /* Copy metrics to prev and clear */ + if (ts != server->metrics[i].ts) { + server->metrics[i].prev_ts = server->metrics[i].ts; + server->metrics[i].prev_total_ms = server->metrics[i].total_ms; + server->metrics[i].prev_total_count = server->metrics[i].total_count; + server->metrics[i].ts = ts; + server->metrics[i].latency_min_ms = 0; + server->metrics[i].latency_max_ms = 0; + server->metrics[i].total_ms = 0; + server->metrics[i].total_count = 0; + } + + if (server->metrics[i].latency_min_ms == 0 || + server->metrics[i].latency_min_ms > query_ms) { + server->metrics[i].latency_min_ms = query_ms; + } + + if (query_ms > server->metrics[i].latency_max_ms) { + server->metrics[i].latency_min_ms = query_ms; + } + + server->metrics[i].total_count++; + server->metrics[i].total_ms += (ares_uint64_t)query_ms; + } +} + +size_t ares_metrics_server_timeout(const struct server_state *server, + const ares_timeval_t *now) +{ + const ares_channel_t *channel = server->channel; + ares_server_bucket_t i; + size_t timeout_ms = 0; + + + for (i = 0; i < ARES_METRIC_COUNT; i++) { + time_t ts = ares_metric_timestamp(i, now, ARES_FALSE); + + /* This ts has been invalidated, see if we should use the previous + * time period */ + if (ts != server->metrics[i].ts || + server->metrics[i].total_count < MIN_COUNT_FOR_AVERAGE) { + time_t prev_ts = ares_metric_timestamp(i, now, ARES_TRUE); + if (prev_ts != server->metrics[i].prev_ts || + server->metrics[i].prev_total_count < MIN_COUNT_FOR_AVERAGE) { + /* Move onto next bucket */ + continue; + } + /* Calculate average time for previous bucket */ + timeout_ms = (size_t)(server->metrics[i].prev_total_ms / + server->metrics[i].prev_total_count); + } else { + /* Calculate average time for current bucket*/ + timeout_ms = + (size_t)(server->metrics[i].total_ms / server->metrics[i].total_count); + } + + /* Multiply average by constant to get timeout value */ + timeout_ms *= AVG_TIMEOUT_MULTIPLIER; + break; + } + + /* If we're here, that means its the first query for the server, so we just + * use the initial default timeout */ + if (timeout_ms == 0) { + timeout_ms = channel->timeout; + } + + /* don't go below lower bounds */ + if (timeout_ms < MIN_TIMEOUT_MS) { + timeout_ms = MIN_TIMEOUT_MS; + } + + /* don't go above upper bounds */ + if (channel->maxtimeout && timeout_ms > channel->maxtimeout) { + timeout_ms = channel->maxtimeout; + } else if (timeout_ms > MAX_TIMEOUT_MS) { + timeout_ms = MAX_TIMEOUT_MS; + } + + return timeout_ms; +} diff --git a/deps/cares/src/lib/ares_options.c b/deps/cares/src/lib/ares_options.c index 959c4f7a8c9c5a..19ddf6d8ca1b0d 100644 --- a/deps/cares/src/lib/ares_options.c +++ b/deps/cares/src/lib/ares_options.c @@ -25,16 +25,14 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" +#include "ares_private.h" #ifdef HAVE_ARPA_INET_H # include #endif -#include "ares.h" #include "ares_data.h" #include "ares_inet_net_pton.h" -#include "ares_private.h" void ares_destroy_options(struct ares_options *options) { @@ -464,8 +462,8 @@ ares_status_t ares__init_by_options(ares_channel_t *channel, /* qcache_max_ttl is unsigned unlike the others */ channel->qcache_max_ttl = options->qcache_max_ttl; } else { - optmask |= ARES_OPT_QUERY_CACHE; - channel->qcache_max_ttl = 3600; + optmask |= ARES_OPT_QUERY_CACHE; + channel->qcache_max_ttl = 3600; } /* Initialize the ipv4 servers if provided */ diff --git a/deps/cares/src/lib/ares_parse_a_reply.c b/deps/cares/src/lib/ares_parse_a_reply.c index 2b7b0e6be2801d..0981b90eeaf595 100644 --- a/deps/cares/src/lib/ares_parse_a_reply.c +++ b/deps/cares/src/lib/ares_parse_a_reply.c @@ -25,7 +25,7 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" +#include "ares_private.h" #ifdef HAVE_NETINET_IN_H # include @@ -37,8 +37,6 @@ # include #endif -#include "ares_nameser.h" - #ifdef HAVE_STRINGS_H # include #endif @@ -47,10 +45,6 @@ # include #endif -#include "ares.h" -#include "ares_dns.h" -#include "ares_private.h" - int ares_parse_a_reply(const unsigned char *abuf, int alen, struct hostent **host, struct ares_addrttl *addrttls, int *naddrttls) diff --git a/deps/cares/src/lib/ares_parse_aaaa_reply.c b/deps/cares/src/lib/ares_parse_aaaa_reply.c index 6e2a466482a69d..3f6932643b2474 100644 --- a/deps/cares/src/lib/ares_parse_aaaa_reply.c +++ b/deps/cares/src/lib/ares_parse_aaaa_reply.c @@ -26,7 +26,7 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" +#include "ares_private.h" #ifdef HAVE_NETINET_IN_H # include @@ -38,8 +38,6 @@ # include #endif -#include "ares_nameser.h" - #ifdef HAVE_STRINGS_H # include #endif @@ -48,10 +46,7 @@ # include #endif -#include "ares.h" -#include "ares_dns.h" #include "ares_inet_net_pton.h" -#include "ares_private.h" int ares_parse_aaaa_reply(const unsigned char *abuf, int alen, struct hostent **host, struct ares_addr6ttl *addrttls, diff --git a/deps/cares/src/lib/ares_parse_caa_reply.c b/deps/cares/src/lib/ares_parse_caa_reply.c index 42f2525697d6c1..f74358f4566965 100644 --- a/deps/cares/src/lib/ares_parse_caa_reply.c +++ b/deps/cares/src/lib/ares_parse_caa_reply.c @@ -24,10 +24,8 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" -#include "ares.h" -#include "ares_data.h" #include "ares_private.h" +#include "ares_data.h" int ares_parse_caa_reply(const unsigned char *abuf, int alen_int, struct ares_caa_reply **caa_out) @@ -67,7 +65,7 @@ int ares_parse_caa_reply(const unsigned char *abuf, int alen_int, if (rr == NULL) { /* Shouldn't be possible */ status = ARES_EBADRESP; /* LCOV_EXCL_LINE: DefensiveCoding */ - goto done; /* LCOV_EXCL_LINE: DefensiveCoding */ + goto done; /* LCOV_EXCL_LINE: DefensiveCoding */ } /* XXX: Why do we allow Chaos class? */ @@ -85,7 +83,7 @@ int ares_parse_caa_reply(const unsigned char *abuf, int alen_int, caa_curr = ares_malloc_data(ARES_DATATYPE_CAA_REPLY); if (caa_curr == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } /* Link in the record */ @@ -101,7 +99,7 @@ int ares_parse_caa_reply(const unsigned char *abuf, int alen_int, (unsigned char *)ares_strdup(ares_dns_rr_get_str(rr, ARES_RR_CAA_TAG)); if (caa_curr->property == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - break; /* LCOV_EXCL_LINE: OutOfMemory */ + break; /* LCOV_EXCL_LINE: OutOfMemory */ } /* RFC6844 says this can only be ascii, so not sure why we're recording a * length */ @@ -110,14 +108,14 @@ int ares_parse_caa_reply(const unsigned char *abuf, int alen_int, ptr = ares_dns_rr_get_bin(rr, ARES_RR_CAA_VALUE, &ptr_len); if (ptr == NULL) { status = ARES_EBADRESP; /* LCOV_EXCL_LINE: DefensiveCoding */ - goto done; /* LCOV_EXCL_LINE: DefensiveCoding */ + goto done; /* LCOV_EXCL_LINE: DefensiveCoding */ } /* Wants NULL termination for some reason */ caa_curr->value = ares_malloc(ptr_len + 1); if (caa_curr->value == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } memcpy(caa_curr->value, ptr, ptr_len); caa_curr->value[ptr_len] = 0; diff --git a/deps/cares/src/lib/ares_parse_mx_reply.c b/deps/cares/src/lib/ares_parse_mx_reply.c index f9e5f025a8f7fe..480074f670c665 100644 --- a/deps/cares/src/lib/ares_parse_mx_reply.c +++ b/deps/cares/src/lib/ares_parse_mx_reply.c @@ -24,10 +24,8 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" -#include "ares.h" -#include "ares_data.h" #include "ares_private.h" +#include "ares_data.h" int ares_parse_mx_reply(const unsigned char *abuf, int alen_int, struct ares_mx_reply **mx_out) @@ -65,7 +63,7 @@ int ares_parse_mx_reply(const unsigned char *abuf, int alen_int, if (rr == NULL) { /* Shouldn't be possible */ status = ARES_EBADRESP; /* LCOV_EXCL_LINE: DefensiveCoding */ - goto done; /* LCOV_EXCL_LINE: DefensiveCoding */ + goto done; /* LCOV_EXCL_LINE: DefensiveCoding */ } if (ares_dns_rr_get_class(rr) != ARES_CLASS_IN || @@ -77,7 +75,7 @@ int ares_parse_mx_reply(const unsigned char *abuf, int alen_int, mx_curr = ares_malloc_data(ARES_DATATYPE_MX_REPLY); if (mx_curr == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } /* Link in the record */ @@ -93,7 +91,7 @@ int ares_parse_mx_reply(const unsigned char *abuf, int alen_int, if (mx_curr->host == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } } diff --git a/deps/cares/src/lib/ares_parse_naptr_reply.c b/deps/cares/src/lib/ares_parse_naptr_reply.c index 51ee6f38a5a0be..c00ce710666ab9 100644 --- a/deps/cares/src/lib/ares_parse_naptr_reply.c +++ b/deps/cares/src/lib/ares_parse_naptr_reply.c @@ -23,10 +23,8 @@ * * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" -#include "ares.h" -#include "ares_data.h" #include "ares_private.h" +#include "ares_data.h" int ares_parse_naptr_reply(const unsigned char *abuf, int alen_int, struct ares_naptr_reply **naptr_out) @@ -64,7 +62,7 @@ int ares_parse_naptr_reply(const unsigned char *abuf, int alen_int, if (rr == NULL) { /* Shouldn't be possible */ status = ARES_EBADRESP; /* LCOV_EXCL_LINE: DefensiveCoding */ - goto done; /* LCOV_EXCL_LINE: DefensiveCoding */ + goto done; /* LCOV_EXCL_LINE: DefensiveCoding */ } if (ares_dns_rr_get_class(rr) != ARES_CLASS_IN || @@ -76,7 +74,7 @@ int ares_parse_naptr_reply(const unsigned char *abuf, int alen_int, naptr_curr = ares_malloc_data(ARES_DATATYPE_NAPTR_REPLY); if (naptr_curr == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } /* Link in the record */ @@ -95,27 +93,27 @@ int ares_parse_naptr_reply(const unsigned char *abuf, int alen_int, ares_dns_rr_get_str(rr, ARES_RR_NAPTR_FLAGS)); if (naptr_curr->flags == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } /* XXX: Why is this unsigned char * ? */ naptr_curr->service = (unsigned char *)ares_strdup( ares_dns_rr_get_str(rr, ARES_RR_NAPTR_SERVICES)); if (naptr_curr->service == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } /* XXX: Why is this unsigned char * ? */ naptr_curr->regexp = (unsigned char *)ares_strdup( ares_dns_rr_get_str(rr, ARES_RR_NAPTR_REGEXP)); if (naptr_curr->regexp == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } naptr_curr->replacement = ares_strdup(ares_dns_rr_get_str(rr, ARES_RR_NAPTR_REPLACEMENT)); if (naptr_curr->replacement == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } } diff --git a/deps/cares/src/lib/ares_parse_ns_reply.c b/deps/cares/src/lib/ares_parse_ns_reply.c index 762353964e246d..fc9ab9219d399c 100644 --- a/deps/cares/src/lib/ares_parse_ns_reply.c +++ b/deps/cares/src/lib/ares_parse_ns_reply.c @@ -24,7 +24,7 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" +#include "ares_private.h" #ifdef HAVE_NETINET_IN_H # include @@ -36,9 +36,6 @@ # include #endif -#include "ares.h" -#include "ares_private.h" - int ares_parse_ns_reply(const unsigned char *abuf, int alen_int, struct hostent **host) { @@ -74,7 +71,7 @@ int ares_parse_ns_reply(const unsigned char *abuf, int alen_int, hostent = ares_malloc(sizeof(*hostent)); if (hostent == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } memset(hostent, 0, sizeof(*hostent)); @@ -82,7 +79,7 @@ int ares_parse_ns_reply(const unsigned char *abuf, int alen_int, hostent->h_addr_list = ares_malloc(sizeof(*hostent->h_addr_list)); if (hostent->h_addr_list == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } hostent->h_addr_list[0] = NULL; hostent->h_addrtype = AF_INET; @@ -96,14 +93,14 @@ int ares_parse_ns_reply(const unsigned char *abuf, int alen_int, hostent->h_name = ares_strdup(hostname); if (hostent->h_name == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } /* Preallocate the maximum number + 1 */ hostent->h_aliases = ares_malloc((ancount + 1) * sizeof(*hostent->h_aliases)); if (hostent->h_aliases == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } memset(hostent->h_aliases, 0, (ancount + 1) * sizeof(*hostent->h_aliases)); @@ -114,7 +111,7 @@ int ares_parse_ns_reply(const unsigned char *abuf, int alen_int, if (rr == NULL) { /* Shouldn't be possible */ status = ARES_EBADRESP; /* LCOV_EXCL_LINE: DefensiveCoding */ - goto done; /* LCOV_EXCL_LINE: DefensiveCoding */ + goto done; /* LCOV_EXCL_LINE: DefensiveCoding */ } if (ares_dns_rr_get_class(rr) != ARES_CLASS_IN || @@ -125,7 +122,7 @@ int ares_parse_ns_reply(const unsigned char *abuf, int alen_int, hostname = ares_dns_rr_get_str(rr, ARES_RR_NS_NSDNAME); if (hostname == NULL) { status = ARES_EBADRESP; /* LCOV_EXCL_LINE: DefensiveCoding */ - goto done; /* LCOV_EXCL_LINE: DefensiveCoding */ + goto done; /* LCOV_EXCL_LINE: DefensiveCoding */ } hostent->h_aliases[nscount] = ares_strdup(hostname); diff --git a/deps/cares/src/lib/ares_parse_ptr_reply.c b/deps/cares/src/lib/ares_parse_ptr_reply.c index 3f8cc122b0c421..56a7b5f94eb331 100644 --- a/deps/cares/src/lib/ares_parse_ptr_reply.c +++ b/deps/cares/src/lib/ares_parse_ptr_reply.c @@ -24,7 +24,7 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" +#include "ares_private.h" #ifdef HAVE_NETINET_IN_H # include @@ -33,8 +33,6 @@ # include #endif -#include "ares.h" -#include "ares_private.h" ares_status_t ares_parse_ptr_reply_dnsrec(const ares_dns_record_t *dnsrec, const void *addr, int addrlen, @@ -106,7 +104,7 @@ ares_status_t ares_parse_ptr_reply_dnsrec(const ares_dns_record_t *dnsrec, if (rr == NULL) { /* Shouldn't be possible */ status = ARES_EBADRESP; /* LCOV_EXCL_LINE: DefensiveCoding */ - goto done; /* LCOV_EXCL_LINE: DefensiveCoding */ + goto done; /* LCOV_EXCL_LINE: DefensiveCoding */ } if (ares_dns_rr_get_class(rr) != ARES_CLASS_IN) { @@ -118,7 +116,7 @@ ares_status_t ares_parse_ptr_reply_dnsrec(const ares_dns_record_t *dnsrec, ptrname = ares_dns_rr_get_str(rr, ARES_RR_CNAME_CNAME); if (ptrname == NULL) { status = ARES_EBADRESP; /* LCOV_EXCL_LINE: DefensiveCoding */ - goto done; /* LCOV_EXCL_LINE: DefensiveCoding */ + goto done; /* LCOV_EXCL_LINE: DefensiveCoding */ } } @@ -146,7 +144,7 @@ ares_status_t ares_parse_ptr_reply_dnsrec(const ares_dns_record_t *dnsrec, hostname = ares_dns_rr_get_str(rr, ARES_RR_PTR_DNAME); if (hostname == NULL) { status = ARES_EBADRESP; /* LCOV_EXCL_LINE: DefensiveCoding */ - goto done; /* LCOV_EXCL_LINE: DefensiveCoding */ + goto done; /* LCOV_EXCL_LINE: DefensiveCoding */ } /* Append as an alias */ @@ -169,7 +167,7 @@ ares_status_t ares_parse_ptr_reply_dnsrec(const ares_dns_record_t *dnsrec, hostent->h_name = ares_strdup(hostname); if (hostent->h_name == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } done: diff --git a/deps/cares/src/lib/ares_parse_soa_reply.c b/deps/cares/src/lib/ares_parse_soa_reply.c index d471471aad8b1d..46b40dedc4d3e2 100644 --- a/deps/cares/src/lib/ares_parse_soa_reply.c +++ b/deps/cares/src/lib/ares_parse_soa_reply.c @@ -24,10 +24,8 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" -#include "ares.h" -#include "ares_data.h" #include "ares_private.h" +#include "ares_data.h" int ares_parse_soa_reply(const unsigned char *abuf, int alen_int, struct ares_soa_reply **soa_out) @@ -63,7 +61,7 @@ int ares_parse_soa_reply(const unsigned char *abuf, int alen_int, if (rr == NULL) { /* Shouldn't be possible */ status = ARES_EBADRESP; /* LCOV_EXCL_LINE: DefensiveCoding */ - goto done; /* LCOV_EXCL_LINE: DefensiveCoding */ + goto done; /* LCOV_EXCL_LINE: DefensiveCoding */ } if (ares_dns_rr_get_class(rr) != ARES_CLASS_IN || @@ -75,7 +73,7 @@ int ares_parse_soa_reply(const unsigned char *abuf, int alen_int, soa = ares_malloc_data(ARES_DATATYPE_SOA_REPLY); if (soa == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } soa->serial = ares_dns_rr_get_u32(rr, ARES_RR_SOA_SERIAL); @@ -86,12 +84,12 @@ int ares_parse_soa_reply(const unsigned char *abuf, int alen_int, soa->nsname = ares_strdup(ares_dns_rr_get_str(rr, ARES_RR_SOA_MNAME)); if (soa->nsname == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } soa->hostmaster = ares_strdup(ares_dns_rr_get_str(rr, ARES_RR_SOA_RNAME)); if (soa->hostmaster == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } break; } diff --git a/deps/cares/src/lib/ares_parse_srv_reply.c b/deps/cares/src/lib/ares_parse_srv_reply.c index 438737b79ac90a..3f9fd95ebf684a 100644 --- a/deps/cares/src/lib/ares_parse_srv_reply.c +++ b/deps/cares/src/lib/ares_parse_srv_reply.c @@ -24,10 +24,8 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" -#include "ares.h" -#include "ares_data.h" #include "ares_private.h" +#include "ares_data.h" int ares_parse_srv_reply(const unsigned char *abuf, int alen_int, struct ares_srv_reply **srv_out) @@ -65,7 +63,7 @@ int ares_parse_srv_reply(const unsigned char *abuf, int alen_int, if (rr == NULL) { /* Shouldn't be possible */ status = ARES_EBADRESP; /* LCOV_EXCL_LINE: DefensiveCoding */ - goto done; /* LCOV_EXCL_LINE: DefensiveCoding */ + goto done; /* LCOV_EXCL_LINE: DefensiveCoding */ } if (ares_dns_rr_get_class(rr) != ARES_CLASS_IN || @@ -77,7 +75,7 @@ int ares_parse_srv_reply(const unsigned char *abuf, int alen_int, srv_curr = ares_malloc_data(ARES_DATATYPE_SRV_REPLY); if (srv_curr == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } /* Link in the record */ @@ -97,7 +95,7 @@ int ares_parse_srv_reply(const unsigned char *abuf, int alen_int, if (srv_curr->host == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } } diff --git a/deps/cares/src/lib/ares_parse_txt_reply.c b/deps/cares/src/lib/ares_parse_txt_reply.c index 2555734c7df033..cd280332d2350d 100644 --- a/deps/cares/src/lib/ares_parse_txt_reply.c +++ b/deps/cares/src/lib/ares_parse_txt_reply.c @@ -24,10 +24,8 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" -#include "ares.h" -#include "ares_data.h" #include "ares_private.h" +#include "ares_data.h" static int ares__parse_txt_reply(const unsigned char *abuf, size_t alen, ares_bool_t ex, void **txt_out) @@ -54,13 +52,14 @@ static int ares__parse_txt_reply(const unsigned char *abuf, size_t alen, for (i = 0; i < ares_dns_record_rr_cnt(dnsrec, ARES_SECTION_ANSWER); i++) { const ares_dns_rr_t *rr = ares_dns_record_rr_get(dnsrec, ARES_SECTION_ANSWER, i); - const unsigned char *ptr; - size_t ptr_len; + size_t j; + size_t cnt; + if (rr == NULL) { /* Shouldn't be possible */ status = ARES_EBADRESP; /* LCOV_EXCL_LINE: DefensiveCoding */ - goto done; /* LCOV_EXCL_LINE: DefensiveCoding */ + goto done; /* LCOV_EXCL_LINE: DefensiveCoding */ } /* XXX: Why Chaos? */ @@ -70,37 +69,44 @@ static int ares__parse_txt_reply(const unsigned char *abuf, size_t alen, continue; } - /* Allocate storage for this TXT answer appending it to the list */ - txt_curr = - ares_malloc_data(ex ? ARES_DATATYPE_TXT_EXT : ARES_DATATYPE_TXT_REPLY); - if (txt_curr == NULL) { - status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ - } - - /* Link in the record */ - if (txt_last) { - txt_last->next = txt_curr; - } else { - txt_head = txt_curr; - } - txt_last = txt_curr; - - /* These days, records are joined, always tag as start */ - if (ex) { - txt_curr->record_start = 1; - } - - ptr = ares_dns_rr_get_bin(rr, ARES_RR_TXT_DATA, &ptr_len); - - txt_curr->txt = ares_malloc(ptr_len + 1); - if (txt_curr->txt == NULL) { - status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + cnt = ares_dns_rr_get_abin_cnt(rr, ARES_RR_TXT_DATA); + + for (j=0; jnext = txt_curr; + } else { + txt_head = txt_curr; + } + txt_last = txt_curr; + + /* Tag start on first for each TXT record */ + if (ex && j == 0) { + txt_curr->record_start = 1; + } + + ptr = ares_dns_rr_get_abin(rr, ARES_RR_TXT_DATA, j, &ptr_len); + + txt_curr->txt = ares_malloc(ptr_len + 1); + if (txt_curr->txt == NULL) { + status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + } + memcpy(txt_curr->txt, ptr, ptr_len); + txt_curr->txt[ptr_len] = 0; + txt_curr->length = ptr_len; } - memcpy(txt_curr->txt, ptr, ptr_len); - txt_curr->txt[ptr_len] = 0; - txt_curr->length = ptr_len; } done: diff --git a/deps/cares/src/lib/ares_parse_uri_reply.c b/deps/cares/src/lib/ares_parse_uri_reply.c index 5966b946969e2a..317e204d5d80d1 100644 --- a/deps/cares/src/lib/ares_parse_uri_reply.c +++ b/deps/cares/src/lib/ares_parse_uri_reply.c @@ -24,10 +24,8 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" -#include "ares.h" -#include "ares_data.h" #include "ares_private.h" +#include "ares_data.h" int ares_parse_uri_reply(const unsigned char *abuf, int alen_int, struct ares_uri_reply **uri_out) @@ -65,7 +63,7 @@ int ares_parse_uri_reply(const unsigned char *abuf, int alen_int, if (rr == NULL) { /* Shouldn't be possible */ status = ARES_EBADRESP; /* LCOV_EXCL_LINE: DefensiveCoding */ - goto done; /* LCOV_EXCL_LINE: DefensiveCoding */ + goto done; /* LCOV_EXCL_LINE: DefensiveCoding */ } if (ares_dns_rr_get_class(rr) != ARES_CLASS_IN || @@ -77,7 +75,7 @@ int ares_parse_uri_reply(const unsigned char *abuf, int alen_int, uri_curr = ares_malloc_data(ARES_DATATYPE_URI_REPLY); if (uri_curr == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } /* Link in the record */ diff --git a/deps/cares/src/lib/ares_platform.c b/deps/cares/src/lib/ares_platform.c index cd1470f832f67d..8f0a1dbffb8173 100644 --- a/deps/cares/src/lib/ares_platform.c +++ b/deps/cares/src/lib/ares_platform.c @@ -25,11 +25,8 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" - -#include "ares.h" -#include "ares_platform.h" #include "ares_private.h" +#include "ares_platform.h" #if defined(_WIN32) && !defined(MSDOS) diff --git a/deps/cares/src/lib/ares_platform.h b/deps/cares/src/lib/ares_platform.h index df07f77a493190..768eaddddd9ce3 100644 --- a/deps/cares/src/lib/ares_platform.h +++ b/deps/cares/src/lib/ares_platform.h @@ -27,8 +27,6 @@ #ifndef HEADER_CARES_PLATFORM_H #define HEADER_CARES_PLATFORM_H -#include "ares_setup.h" - #if defined(_WIN32) && !defined(MSDOS) typedef enum { diff --git a/deps/cares/src/lib/ares_private.h b/deps/cares/src/lib/ares_private.h index 1fc4fda045baa5..3b5f627bd16d66 100644 --- a/deps/cares/src/lib/ares_private.h +++ b/deps/cares/src/lib/ares_private.h @@ -27,15 +27,19 @@ #ifndef __ARES_PRIVATE_H #define __ARES_PRIVATE_H +/* ============================================================================ + * NOTE: All c-ares source files should include ares_private.h as the first + * header. + * ============================================================================ + */ + +#include "ares_setup.h" +#include "ares.h" + #ifdef HAVE_NETINET_IN_H # include #endif -#ifdef WATT32 -# include -# include -#endif - #define DEFAULT_TIMEOUT 2000 /* milliseconds */ #define DEFAULT_TRIES 3 #ifndef INADDR_NONE @@ -46,7 +50,7 @@ * warning: cast from 'const struct sockaddr *' to 'const struct sockaddr_in6 *' * increases required alignment from 1 to 4 [-Wcast-align] */ -#define CARES_INADDR_CAST(type, var) ((type)((void *)var)) +#define CARES_INADDR_CAST(type, var) ((type)((const void *)var)) #if defined(USE_WINSOCK) @@ -107,6 +111,7 @@ typedef struct ares_rand_state ares_rand_state; #include "ares__htable_szvp.h" #include "ares__htable_asvp.h" #include "ares__htable_vpvp.h" +#include "ares_dns_multistring.h" #include "ares__buf.h" #include "ares_dns_private.h" #include "ares__iface_ips.h" @@ -175,6 +180,30 @@ typedef struct { unsigned int usec; /*!< Microseconds. Can't be negative. */ } ares_timeval_t; +/*! Various buckets for grouping history */ +typedef enum { + ARES_METRIC_1MINUTE = 0, /*!< Bucket for tracking over the last minute */ + ARES_METRIC_15MINUTES, /*!< Bucket for tracking over the last 15 minutes */ + ARES_METRIC_1HOUR, /*!< Bucket for tracking over the last hour */ + ARES_METRIC_1DAY, /*!< Bucket for tracking over the last day */ + ARES_METRIC_INCEPTION, /*!< Bucket for tracking since inception */ + ARES_METRIC_COUNT /*!< Count of buckets, not a real bucket */ +} ares_server_bucket_t; + +/*! Data metrics collected for each bucket */ +typedef struct { + time_t ts; /*!< Timestamp divided by bucket divisor */ + unsigned int latency_min_ms; /*!< Minimum latency for queries */ + unsigned int latency_max_ms; /*!< Maximum latency for queries */ + ares_uint64_t total_ms; /*!< Cumulative query time for bucket */ + ares_uint64_t total_count; /*!< Number of queries for bucket */ + + time_t prev_ts; /*!< Previous period bucket timestamp */ + ares_uint64_t + prev_total_ms; /*!< Previous period bucket cumulative query time */ + ares_uint64_t prev_total_count; /*!< Previous period bucket query count */ +} ares_server_metrics_t; + struct server_state { /* Configuration */ size_t idx; /* index for server in system configuration */ @@ -200,6 +229,9 @@ struct server_state { /* TCP output queue */ ares__buf_t *tcp_send; + /*! Buckets for collecting metrics about the server */ + ares_server_metrics_t metrics[ARES_METRIC_COUNT]; + /* Link back to owning channel */ ares_channel_t *channel; }; @@ -208,6 +240,7 @@ struct server_state { struct query { /* Query ID from qbuf, for faster lookup, and current timeout */ unsigned short qid; /* host byte order */ + ares_timeval_t ts; /*!< Timestamp query was sent */ ares_timeval_t timeout; ares_channel_t *channel; @@ -222,9 +255,8 @@ struct query { /* connection handle query is associated with */ struct server_connection *conn; - /* Arguments passed to ares_send() */ - unsigned char *qbuf; - size_t qlen; + /* Query */ + ares_dns_record_t *query; ares_callback_dnsrec callback; void *arg; @@ -411,22 +443,24 @@ void ares__destroy_rand_state(ares_rand_state *state); void ares__rand_bytes(ares_rand_state *state, unsigned char *buf, size_t len); unsigned short ares__generate_new_id(ares_rand_state *state); -ares_timeval_t ares__tvnow(void); +void ares__tvnow(ares_timeval_t *now); void ares__timeval_remaining(ares_timeval_t *remaining, const ares_timeval_t *now, const ares_timeval_t *tout); -ares_status_t ares__expand_name_validated(const unsigned char *encoded, - const unsigned char *abuf, - size_t alen, char **s, size_t *enclen, - ares_bool_t is_hostname); -ares_status_t ares_expand_string_ex(const unsigned char *encoded, - const unsigned char *abuf, size_t alen, - unsigned char **s, size_t *enclen); -ares_status_t ares__init_servers_state(ares_channel_t *channel); -ares_status_t ares__init_by_options(ares_channel_t *channel, - const struct ares_options *options, - int optmask); -ares_status_t ares__init_by_sysconfig(ares_channel_t *channel); +void ares__timeval_diff(ares_timeval_t *tvdiff, const ares_timeval_t *tvstart, + const ares_timeval_t *tvstop); +ares_status_t ares__expand_name_validated(const unsigned char *encoded, + const unsigned char *abuf, + size_t alen, char **s, size_t *enclen, + ares_bool_t is_hostname); +ares_status_t ares_expand_string_ex(const unsigned char *encoded, + const unsigned char *abuf, size_t alen, + unsigned char **s, size_t *enclen); +ares_status_t ares__init_servers_state(ares_channel_t *channel); +ares_status_t ares__init_by_options(ares_channel_t *channel, + const struct ares_options *options, + int optmask); +ares_status_t ares__init_by_sysconfig(ares_channel_t *channel); typedef struct { ares__llist_t *sconfig; @@ -452,6 +486,9 @@ ares_status_t ares__init_sysconfig_files(const ares_channel_t *channel, #ifdef __APPLE__ ares_status_t ares__init_sysconfig_macos(ares_sysconfig_t *sysconfig); #endif +#ifdef USE_WINSOCK +ares_status_t ares__init_sysconfig_windows(ares_sysconfig_t *sysconfig); +#endif ares_status_t ares__parse_sortlist(struct apattern **sortlist, size_t *nsort, const char *str); @@ -560,6 +597,26 @@ ares_status_t ares__hosts_entry_to_addrinfo(const ares_hosts_entry_t *entry, ares_bool_t want_cnames, struct ares_addrinfo *ai); +/* Same as ares_query_dnsrec() except does not take a channel lock. Use this + * if a channel lock is already held */ +ares_status_t ares_query_nolock(ares_channel_t *channel, const char *name, + ares_dns_class_t dnsclass, + ares_dns_rec_type_t type, + ares_callback_dnsrec callback, void *arg, + unsigned short *qid); + +/* Same as ares_send_dnsrec() except does not take a channel lock. Use this + * if a channel lock is already held */ +ares_status_t ares_send_nolock(ares_channel_t *channel, + const ares_dns_record_t *dnsrec, + ares_callback_dnsrec callback, + void *arg, unsigned short *qid); + +/* Same as ares_gethostbyaddr() except does not take a channel lock. Use this + * if a channel lock is already held */ +void ares_gethostbyaddr_nolock(ares_channel_t *channel, const void *addr, + int addrlen, int family, + ares_host_callback callback, void *arg); /*! Parse a compressed DNS name as defined in RFC1035 starting at the current * offset within the buffer. @@ -609,13 +666,6 @@ ares_status_t ares__dns_name_write(ares__buf_t *buf, ares__llist_t **list, void ares_queue_notify_empty(ares_channel_t *channel); -#define ARES_SWAP_BYTE(a, b) \ - do { \ - unsigned char swapByte = *(a); \ - *(a) = *(b); \ - *(b) = swapByte; \ - } while (0) - #define SOCK_STATE_CALLBACK(c, s, r, w) \ do { \ if ((c)->sock_state_cb) { \ @@ -632,6 +682,7 @@ ares_bool_t ares__subnet_match(const struct ares_addr *addr, unsigned char netmask); ares_bool_t ares__addr_is_linklocal(const struct ares_addr *addr); +ares_bool_t ares__is_64bit(void); size_t ares__round_up_pow2(size_t n); size_t ares__log2(size_t n); size_t ares__pow(size_t x, size_t y); @@ -652,6 +703,11 @@ ares_status_t ares_qcache_fetch(ares_channel_t *channel, const ares_dns_record_t *dnsrec, const ares_dns_record_t **dnsrec_resp); +void ares_metrics_record(const struct query *query, struct server_state *server, + ares_status_t status, const ares_dns_record_t *dnsrec); +size_t ares_metrics_server_timeout(const struct server_state *server, + const ares_timeval_t *now); + ares_status_t ares__channel_threading_init(ares_channel_t *channel); void ares__channel_threading_destroy(ares_channel_t *channel); void ares__channel_lock(const ares_channel_t *channel); diff --git a/deps/cares/src/lib/ares_process.c b/deps/cares/src/lib/ares_process.c index 6e50902b71d8f2..562d6b5e1b1e3c 100644 --- a/deps/cares/src/lib/ares_process.c +++ b/deps/cares/src/lib/ares_process.c @@ -25,8 +25,7 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" - +#include "ares_private.h" #ifdef HAVE_STRINGS_H # include @@ -45,10 +44,6 @@ #include #include -#include "ares.h" -#include "ares_private.h" -#include "ares_nameser.h" -#include "ares_dns.h" static void timeadd(ares_timeval_t *now, size_t millisecs); static ares_bool_t try_again(int errnum); @@ -65,16 +60,17 @@ static ares_status_t process_answer(ares_channel_t *channel, static void handle_conn_error(struct server_connection *conn, ares_bool_t critical_failure); -static ares_bool_t same_questions(const ares_dns_record_t *qrec, +static ares_bool_t same_questions(const struct query *query, const ares_dns_record_t *arec); static ares_bool_t same_address(const struct sockaddr *sa, const struct ares_addr *aa); -static void end_query(ares_channel_t *channel, struct query *query, - ares_status_t status, const ares_dns_record_t *dnsrec); +static void end_query(ares_channel_t *channel, struct server_state *server, + struct query *query, ares_status_t status, + const ares_dns_record_t *dnsrec); /* Invoke the server state callback after a success or failure */ -static void invoke_server_state_cb(const struct server_state *server, - ares_bool_t success, int flags) +static void invoke_server_state_cb(const struct server_state *server, + ares_bool_t success, int flags) { const ares_channel_t *channel = server->channel; ares__buf_t *buf; @@ -93,7 +89,7 @@ static void invoke_server_state_cb(const struct server_state *server, status = ares_get_server_addr(server, buf); if (status != ARES_SUCCESS) { ares__buf_destroy(buf); /* LCOV_EXCL_LINE: OutOfMemory */ - return; /* LCOV_EXCL_LINE: OutOfMemory */ + return; /* LCOV_EXCL_LINE: OutOfMemory */ } server_string = ares__buf_finish_str(buf, NULL); @@ -122,7 +118,7 @@ static void server_increment_failures(struct server_state *server, server->consec_failures++; ares__slist_node_reinsert(node); - next_retry_time = ares__tvnow(); + ares__tvnow(&next_retry_time); timeadd(&next_retry_time, channel->server_retry_delay); server->next_retry_time = next_retry_time; @@ -200,7 +196,7 @@ static void processfds(ares_channel_t *channel, fd_set *read_fds, ares__channel_lock(channel); - now = ares__tvnow(); + ares__tvnow(&now); read_packets(channel, read_fds, read_fd, &now); process_timeouts(channel, &now); /* Write last as the other 2 operations might have triggered writes */ @@ -380,7 +376,7 @@ static void read_tcp_data(ares_channel_t *channel, /* Can't fail except for misuse */ data = ares__buf_tag_fetch(server->tcp_parser, &data_len); - if (data == NULL) { + if (data == NULL || data_len < 2) { ares__buf_tag_clear(server->tcp_parser); break; } @@ -623,22 +619,19 @@ static void process_timeouts(ares_channel_t *channel, const ares_timeval_t *now) } } -static ares_status_t rewrite_without_edns(ares_dns_record_t *qdnsrec, - struct query *query) +static ares_status_t rewrite_without_edns(struct query *query) { - ares_status_t status; + ares_status_t status = ARES_SUCCESS; size_t i; ares_bool_t found_opt_rr = ARES_FALSE; - unsigned char *msg = NULL; - size_t msglen = 0; /* Find and remove the OPT RR record */ - for (i = 0; i < ares_dns_record_rr_cnt(qdnsrec, ARES_SECTION_ADDITIONAL); + for (i = 0; i < ares_dns_record_rr_cnt(query->query, ARES_SECTION_ADDITIONAL); i++) { const ares_dns_rr_t *rr; - rr = ares_dns_record_rr_get(qdnsrec, ARES_SECTION_ADDITIONAL, i); + rr = ares_dns_record_rr_get(query->query, ARES_SECTION_ADDITIONAL, i); if (ares_dns_rr_get_type(rr) == ARES_REC_TYPE_OPT) { - ares_dns_record_rr_del(qdnsrec, ARES_SECTION_ADDITIONAL, i); + ares_dns_record_rr_del(query->query, ARES_SECTION_ADDITIONAL, i); found_opt_rr = ARES_TRUE; break; } @@ -649,16 +642,6 @@ static ares_status_t rewrite_without_edns(ares_dns_record_t *qdnsrec, goto done; } - /* Rewrite the DNS message */ - status = ares_dns_write(qdnsrec, &msg, &msglen); - if (status != ARES_SUCCESS) { - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ - } - - ares_free(query->qbuf); - query->qbuf = msg; - query->qlen = msglen; - done: return status; } @@ -676,7 +659,6 @@ static ares_status_t process_answer(ares_channel_t *channel, * invalidating the connection all-together */ struct server_state *server = conn->server; ares_dns_record_t *rdnsrec = NULL; - ares_dns_record_t *qdnsrec = NULL; ares_status_t status; ares_bool_t is_cached = ARES_FALSE; @@ -699,16 +681,9 @@ static ares_status_t process_answer(ares_channel_t *channel, goto cleanup; } - /* Parse the question we sent as we use it to compare */ - status = ares_dns_parse(query->qbuf, query->qlen, 0, &qdnsrec); - if (status != ARES_SUCCESS) { - end_query(channel, query, status, NULL); - goto cleanup; - } - /* Both the query id and the questions must be the same. We will drop any * replies that aren't for the same query as this is considered invalid. */ - if (!same_questions(qdnsrec, rdnsrec)) { + if (!same_questions(query, rdnsrec)) { /* Possible qid conflict due to delayed response, that's ok */ status = ARES_SUCCESS; goto cleanup; @@ -725,10 +700,10 @@ static ares_status_t process_answer(ares_channel_t *channel, * protocol extension is not understood by the responder. We must retry the * query without EDNS enabled. */ if (ares_dns_record_get_rcode(rdnsrec) == ARES_RCODE_FORMERR && - ares_dns_has_opt_rr(qdnsrec) && !ares_dns_has_opt_rr(rdnsrec)) { - status = rewrite_without_edns(qdnsrec, query); + ares_dns_has_opt_rr(query->query) && !ares_dns_has_opt_rr(rdnsrec)) { + status = rewrite_without_edns(query); if (status != ARES_SUCCESS) { - end_query(channel, query, status, NULL); + end_query(channel, server, query, status, NULL); goto cleanup; } @@ -787,7 +762,7 @@ static ares_status_t process_answer(ares_channel_t *channel, } server_set_good(server, query->using_tcp); - end_query(channel, query, ARES_SUCCESS, rdnsrec); + end_query(channel, server, query, ARES_SUCCESS, rdnsrec); status = ARES_SUCCESS; @@ -797,7 +772,6 @@ static ares_status_t process_answer(ares_channel_t *channel, ares_dns_record_destroy(rdnsrec); } - ares_dns_record_destroy(qdnsrec); return status; } @@ -833,7 +807,7 @@ ares_status_t ares__requeue_query(struct query *query, query->error_status = ARES_ETIMEOUT; } - end_query(channel, query, query->error_status, NULL); + end_query(channel, NULL, query, query->error_status, NULL); return ARES_ETIMEOUT; } @@ -916,8 +890,10 @@ static struct server_state *ares__failover_server(ares_channel_t *channel) ares__rand_bytes(channel->rand_state, (unsigned char *)&r, sizeof(r)); if (r % channel->server_retry_chance == 0) { /* Select a suitable failed server to retry. */ - ares_timeval_t now = ares__tvnow(); + ares_timeval_t now; ares__slist_node_t *node; + + ares__tvnow(&now); for (node = ares__slist_node_first(channel->servers); node != NULL; node = ares__slist_node_next(node)) { struct server_state *node_val = ares__slist_node_val(node); @@ -936,18 +912,58 @@ static ares_status_t ares__append_tcpbuf(struct server_state *server, const struct query *query) { ares_status_t status; + unsigned char *qbuf = NULL; + size_t qbuf_len = 0; + + status = ares_dns_write(query->query, &qbuf, &qbuf_len); + if (status != ARES_SUCCESS) { + goto done; + } + + status = ares__buf_append_be16(server->tcp_send, (unsigned short)qbuf_len); + if (status != ARES_SUCCESS) { + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + } + + status = ares__buf_append(server->tcp_send, qbuf, qbuf_len); + +done: + ares_free(qbuf); + return status; +} + + +static ares_status_t ares__write_udpbuf(ares_channel_t *channel, + ares_socket_t fd, + const struct query *query) +{ + ares_status_t status; + unsigned char *qbuf = NULL; + size_t qbuf_len = 0; - status = ares__buf_append_be16(server->tcp_send, (unsigned short)query->qlen); + status = ares_dns_write(query->query, &qbuf, &qbuf_len); if (status != ARES_SUCCESS) { - return status; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; } - return ares__buf_append(server->tcp_send, query->qbuf, query->qlen); + + if (ares__socket_write(channel, fd, qbuf, qbuf_len) == -1) { + status = ARES_ESERVFAIL; + } else { + status = ARES_SUCCESS; + } + +done: + ares_free(qbuf); + return status; } -static size_t ares__calc_query_timeout(const struct query *query) +static size_t ares__calc_query_timeout(const struct query *query, + const struct server_state *server, + const ares_timeval_t *now) { const ares_channel_t *channel = query->channel; - size_t timeplus = channel->timeout; + size_t timeout = ares_metrics_server_timeout(server, now); + size_t timeplus = timeout; size_t rounds; size_t num_servers = ares__slist_len(channel->servers); @@ -986,8 +1002,8 @@ static size_t ares__calc_query_timeout(const struct query *query) /* We want explicitly guarantee that timeplus is greater or equal to timeout * specified in channel options. */ - if (timeplus < channel->timeout) { - timeplus = channel->timeout; + if (timeplus < timeout) { + timeplus = timeout; } return timeplus; @@ -1014,7 +1030,7 @@ ares_status_t ares__send_query(struct query *query, const ares_timeval_t *now) } if (server == NULL) { - end_query(channel, query, ARES_ENOSERVER /* ? */, NULL); + end_query(channel, server, query, ARES_ENOSERVER /* ? */, NULL); return ARES_ENOSERVER; } @@ -1041,7 +1057,7 @@ ares_status_t ares__send_query(struct query *query, const ares_timeval_t *now) /* Anything else is not retryable, likely ENOMEM */ default: - end_query(channel, query, status, NULL); + end_query(channel, server, query, status, NULL); return status; } } @@ -1052,7 +1068,7 @@ ares_status_t ares__send_query(struct query *query, const ares_timeval_t *now) status = ares__append_tcpbuf(server, query); if (status != ARES_SUCCESS) { - end_query(channel, query, status, NULL); + end_query(channel, server, query, status, NULL); /* Only safe to kill connection if it was new, otherwise it should be * cleaned up by another process later */ @@ -1100,14 +1116,22 @@ ares_status_t ares__send_query(struct query *query, const ares_timeval_t *now) /* Anything else is not retryable, likely ENOMEM */ default: - end_query(channel, query, status, NULL); + end_query(channel, server, query, status, NULL); return status; } node = ares__llist_node_first(server->connections); } conn = ares__llist_node_val(node); - if (ares__socket_write(channel, conn->fd, query->qbuf, query->qlen) == -1) { + + status = ares__write_udpbuf(channel, conn->fd, query); + if (status != ARES_SUCCESS) { + if (status == ARES_ENOMEM) { + /* Not retryable */ + end_query(channel, server, query, status, NULL); + return status; + } + /* FIXME: Handle EAGAIN here since it likely can happen. */ server_increment_failures(server, query->using_tcp); status = ares__requeue_query(query, now); @@ -1122,18 +1146,19 @@ ares_status_t ares__send_query(struct query *query, const ares_timeval_t *now) } } - timeplus = ares__calc_query_timeout(query); + timeplus = ares__calc_query_timeout(query, server, now); /* Keep track of queries bucketed by timeout, so we can process * timeout events quickly. */ ares__slist_node_destroy(query->node_queries_by_timeout); + query->ts = *now; query->timeout = *now; timeadd(&query->timeout, timeplus); query->node_queries_by_timeout = ares__slist_insert(channel->queries_by_timeout, query); if (!query->node_queries_by_timeout) { /* LCOV_EXCL_START: OutOfMemory */ - end_query(channel, query, ARES_ENOMEM, NULL); + end_query(channel, server, query, ARES_ENOMEM, NULL); /* Only safe to kill connection if it was new, otherwise it should be * cleaned up by another process later */ if (new_connection) { @@ -1151,7 +1176,7 @@ ares_status_t ares__send_query(struct query *query, const ares_timeval_t *now) if (query->node_queries_to_conn == NULL) { /* LCOV_EXCL_START: OutOfMemory */ - end_query(channel, query, ARES_ENOMEM, NULL); + end_query(channel, server, query, ARES_ENOMEM, NULL); /* Only safe to kill connection if it was new, otherwise it should be * cleaned up by another process later */ if (new_connection) { @@ -1166,11 +1191,13 @@ ares_status_t ares__send_query(struct query *query, const ares_timeval_t *now) return ARES_SUCCESS; } -static ares_bool_t same_questions(const ares_dns_record_t *qrec, +static ares_bool_t same_questions(const struct query *query, const ares_dns_record_t *arec) { - size_t i; - ares_bool_t rv = ARES_FALSE; + size_t i; + ares_bool_t rv = ARES_FALSE; + const ares_dns_record_t *qrec = query->query; + const ares_channel_t *channel = query->channel; if (ares_dns_record_query_cnt(qrec) != ares_dns_record_query_cnt(arec)) { @@ -1196,9 +1223,26 @@ static ares_bool_t same_questions(const ares_dns_record_t *qrec, aname == NULL) { goto done; } - if (strcasecmp(qname, aname) != 0 || qtype != atype || qclass != aclass) { + + if (qtype != atype || qclass != aclass) { goto done; } + + if (channel->flags & ARES_FLAG_DNS0x20 && !query->using_tcp) { + /* NOTE: for DNS 0x20, part of the protection is to use a case-sensitive + * comparison of the DNS query name. This expects the upstream DNS + * server to preserve the case of the name in the response packet. + * https://datatracker.ietf.org/doc/html/draft-vixie-dnsext-dns0x20-00 + */ + if (strcmp(qname, aname) != 0) { + goto done; + } + } else { + /* without DNS0x20 use case-insensitive matching */ + if (strcasecmp(qname, aname) != 0) { + goto done; + } + } } rv = ARES_TRUE; @@ -1217,14 +1261,14 @@ static ares_bool_t same_address(const struct sockaddr *sa, switch (aa->family) { case AF_INET: addr1 = &aa->addr.addr4; - addr2 = &(CARES_INADDR_CAST(struct sockaddr_in *, sa))->sin_addr; + addr2 = &(CARES_INADDR_CAST(const struct sockaddr_in *, sa))->sin_addr; if (memcmp(addr1, addr2, sizeof(aa->addr.addr4)) == 0) { return ARES_TRUE; /* match */ } break; case AF_INET6: addr1 = &aa->addr.addr6; - addr2 = &(CARES_INADDR_CAST(struct sockaddr_in6 *, sa))->sin6_addr; + addr2 = &(CARES_INADDR_CAST(const struct sockaddr_in6 *, sa))->sin6_addr; if (memcmp(addr1, addr2, sizeof(aa->addr.addr6)) == 0) { return ARES_TRUE; /* match */ } @@ -1248,9 +1292,12 @@ static void ares_detach_query(struct query *query) query->node_all_queries = NULL; } -static void end_query(ares_channel_t *channel, struct query *query, - ares_status_t status, const ares_dns_record_t *dnsrec) +static void end_query(ares_channel_t *channel, struct server_state *server, + struct query *query, ares_status_t status, + const ares_dns_record_t *dnsrec) { + ares_metrics_record(query, server, status, dnsrec); + /* Invoke the callback. */ query->callback(query->arg, status, query->timeouts, dnsrec); ares__free_query(query); @@ -1270,7 +1317,7 @@ void ares__free_query(struct query *query) query->callback = NULL; query->arg = NULL; /* Deallocate the memory associated with the query */ - ares_free(query->qbuf); + ares_dns_record_destroy(query->query); ares_free(query); } diff --git a/deps/cares/src/lib/ares_qcache.c b/deps/cares/src/lib/ares_qcache.c index e03d069222655d..2d9919fd104869 100644 --- a/deps/cares/src/lib/ares_qcache.c +++ b/deps/cares/src/lib/ares_qcache.c @@ -23,8 +23,6 @@ * * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" -#include "ares.h" #include "ares_private.h" struct ares__qcache { @@ -135,7 +133,7 @@ static char *ares__qcache_calc_key(const ares_dns_record_t *dnsrec) fail: ares__buf_destroy(buf); return NULL; -/* LCOV_EXCL_STOP */ + /* LCOV_EXCL_STOP */ } static void ares__qcache_expire(ares__qcache_t *cache, @@ -214,20 +212,20 @@ ares_status_t ares__qcache_create(ares_rand_state *rand_state, cache = ares_malloc_zero(sizeof(*cache)); if (cache == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } cache->cache = ares__htable_strvp_create(NULL); if (cache->cache == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } cache->expire = ares__slist_create(rand_state, ares__qcache_entry_sort_cb, ares__qcache_entry_destroy_cb); if (cache->expire == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } cache->max_ttl = max_ttl; @@ -301,37 +299,18 @@ static unsigned int ares__qcache_soa_minimum(ares_dns_record_t *dnsrec) return 0; } -static char *ares__qcache_calc_key_frombuf(const unsigned char *qbuf, - size_t qlen) -{ - ares_status_t status; - ares_dns_record_t *dnsrec = NULL; - char *key = NULL; - - status = ares_dns_parse(qbuf, qlen, 0, &dnsrec); - if (status != ARES_SUCCESS) { - goto done; - } - - key = ares__qcache_calc_key(dnsrec); - -done: - ares_dns_record_destroy(dnsrec); - return key; -} - /* On success, takes ownership of dnsrec */ -static ares_status_t ares__qcache_insert(ares__qcache_t *qcache, - ares_dns_record_t *dnsrec, - const unsigned char *qbuf, size_t qlen, - const ares_timeval_t *now) +static ares_status_t ares__qcache_insert(ares__qcache_t *qcache, + ares_dns_record_t *qresp, + const ares_dns_record_t *qreq, + const ares_timeval_t *now) { ares__qcache_entry_t *entry; unsigned int ttl; - ares_dns_rcode_t rcode = ares_dns_record_get_rcode(dnsrec); - ares_dns_flags_t flags = ares_dns_record_get_flags(dnsrec); + ares_dns_rcode_t rcode = ares_dns_record_get_rcode(qresp); + ares_dns_flags_t flags = ares_dns_record_get_flags(qresp); - if (qcache == NULL || dnsrec == NULL) { + if (qcache == NULL || qresp == NULL) { return ARES_EFORMERR; } @@ -347,9 +326,9 @@ static ares_status_t ares__qcache_insert(ares__qcache_t *qcache, /* Look at SOA for NXDOMAIN for minimum */ if (rcode == ARES_RCODE_NXDOMAIN) { - ttl = ares__qcache_soa_minimum(dnsrec); + ttl = ares__qcache_soa_minimum(qresp); } else { - ttl = ares__qcache_calc_minttl(dnsrec); + ttl = ares__qcache_calc_minttl(qresp); } if (ttl > qcache->max_ttl) { @@ -366,7 +345,7 @@ static ares_status_t ares__qcache_insert(ares__qcache_t *qcache, goto fail; /* LCOV_EXCL_LINE: OutOfMemory */ } - entry->dnsrec = dnsrec; + entry->dnsrec = qresp; entry->expire_ts = now->sec + (time_t)ttl; entry->insert_ts = now->sec; @@ -374,7 +353,7 @@ static ares_status_t ares__qcache_insert(ares__qcache_t *qcache, * request had, so we have to re-parse the request in order to generate the * key for caching, but we'll only do this once we know for sure we really * want to cache it */ - entry->key = ares__qcache_calc_key_frombuf(qbuf, qlen); + entry->key = ares__qcache_calc_key(qreq); if (entry->key == NULL) { goto fail; /* LCOV_EXCL_LINE: OutOfMemory */ } @@ -397,7 +376,7 @@ static ares_status_t ares__qcache_insert(ares__qcache_t *qcache, ares_free(entry); } return ARES_ENOMEM; -/* LCOV_EXCL_STOP */ + /* LCOV_EXCL_STOP */ } ares_status_t ares_qcache_fetch(ares_channel_t *channel, @@ -422,7 +401,7 @@ ares_status_t ares_qcache_fetch(ares_channel_t *channel, key = ares__qcache_calc_key(dnsrec); if (key == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } entry = ares__htable_strvp_get_direct(channel->qcache->cache, key); @@ -446,6 +425,6 @@ ares_status_t ares_qcache_insert(ares_channel_t *channel, const struct query *query, ares_dns_record_t *dnsrec) { - return ares__qcache_insert(channel->qcache, dnsrec, query->qbuf, query->qlen, + return ares__qcache_insert(channel->qcache, dnsrec, query->query, now); } diff --git a/deps/cares/src/lib/ares_query.c b/deps/cares/src/lib/ares_query.c index 35214bc4a5b627..4d0861a5f52d51 100644 --- a/deps/cares/src/lib/ares_query.c +++ b/deps/cares/src/lib/ares_query.c @@ -25,18 +25,12 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" +#include "ares_private.h" #ifdef HAVE_NETINET_IN_H # include #endif -#include "ares_nameser.h" - -#include "ares.h" -#include "ares_dns.h" -#include "ares_private.h" - typedef struct { ares_callback_dnsrec callback; void *arg; @@ -64,11 +58,11 @@ static void ares_query_dnsrec_cb(void *arg, ares_status_t status, ares_free(qquery); } -static ares_status_t ares_query_int(ares_channel_t *channel, const char *name, - ares_dns_class_t dnsclass, - ares_dns_rec_type_t type, - ares_callback_dnsrec callback, void *arg, - unsigned short *qid) +ares_status_t ares_query_nolock(ares_channel_t *channel, const char *name, + ares_dns_class_t dnsclass, + ares_dns_rec_type_t type, + ares_callback_dnsrec callback, void *arg, + unsigned short *qid) { ares_status_t status; ares_dns_record_t *dnsrec = NULL; @@ -94,7 +88,7 @@ static ares_status_t ares_query_int(ares_channel_t *channel, const char *name, (size_t)(channel->flags & ARES_FLAG_EDNS) ? channel->ednspsz : 0); if (status != ARES_SUCCESS) { callback(arg, status, 0, NULL); /* LCOV_EXCL_LINE: OutOfMemory */ - return status; /* LCOV_EXCL_LINE: OutOfMemory */ + return status; /* LCOV_EXCL_LINE: OutOfMemory */ } qquery = ares_malloc(sizeof(*qquery)); @@ -111,7 +105,7 @@ static ares_status_t ares_query_int(ares_channel_t *channel, const char *name, qquery->arg = arg; /* Send it off. qcallback will be called when we get an answer. */ - status = ares_send_dnsrec(channel, dnsrec, ares_query_dnsrec_cb, qquery, qid); + status = ares_send_nolock(channel, dnsrec, ares_query_dnsrec_cb, qquery, qid); ares_dns_record_destroy(dnsrec); return status; @@ -130,7 +124,7 @@ ares_status_t ares_query_dnsrec(ares_channel_t *channel, const char *name, } ares__channel_lock(channel); - status = ares_query_int(channel, name, dnsclass, type, callback, arg, qid); + status = ares_query_nolock(channel, name, dnsclass, type, callback, arg, qid); ares__channel_unlock(channel); return status; } @@ -147,7 +141,7 @@ void ares_query(ares_channel_t *channel, const char *name, int dnsclass, carg = ares__dnsrec_convert_arg(callback, arg); if (carg == NULL) { callback(arg, ARES_ENOMEM, 0, NULL, 0); /* LCOV_EXCL_LINE: OutOfMemory */ - return; /* LCOV_EXCL_LINE: OutOfMemory */ + return; /* LCOV_EXCL_LINE: OutOfMemory */ } ares_query_dnsrec(channel, name, (ares_dns_class_t)dnsclass, diff --git a/deps/cares/src/lib/ares_rand.c b/deps/cares/src/lib/ares_rand.c index e36cbc67d70dea..c57bb706e68e5b 100644 --- a/deps/cares/src/lib/ares_rand.c +++ b/deps/cares/src/lib/ares_rand.c @@ -24,8 +24,6 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" -#include "ares.h" #include "ares_private.h" #include @@ -43,7 +41,7 @@ typedef enum { ARES_RAND_OS = 1 << 0, /* OS-provided such as RtlGenRandom or arc4random */ ARES_RAND_FILE = 1 << 1, /* OS file-backed random number generator */ - ARES_RAND_RC4 = 1 << 2, /* Internal RC4 based PRNG */ + ARES_RAND_RC4 = 1 << 2 /* Internal RC4 based PRNG */ } ares_rand_backend; #define ARES_RC4_KEY_LEN 32 /* 256 bits */ @@ -57,7 +55,7 @@ typedef struct ares_rand_rc4 { static unsigned int ares_u32_from_ptr(void *addr) { /* LCOV_EXCL_START: FallbackCode */ - if (sizeof(void *) == 8) { + if (ares__is_64bit()) { return (unsigned int)((((ares_uint64_t)addr >> 32) & 0xFFFFFFFF) | ((ares_uint64_t)addr & 0xFFFFFFFF)); } @@ -91,7 +89,7 @@ static void ares_rc4_generate_key(ares_rand_rc4 *rc4_state, unsigned char *key, memcpy(key + len, &data, sizeof(data)); len += sizeof(data); - tv = ares__tvnow(); + ares__tvnow(&tv); data = (unsigned int)((tv.sec | tv.usec) & 0xFFFFFFFF); memcpy(key + len, &data, sizeof(data)); len += sizeof(data); @@ -105,6 +103,13 @@ static void ares_rc4_generate_key(ares_rand_rc4 *rc4_state, unsigned char *key, /* LCOV_EXCL_STOP */ } +#define ARES_SWAP_BYTE(a, b) \ + do { \ + unsigned char swapByte = *(a); \ + *(a) = *(b); \ + *(b) = swapByte; \ + } while (0) + static void ares_rc4_init(ares_rand_rc4 *rc4_state) { /* LCOV_EXCL_START: FallbackCode */ @@ -229,7 +234,7 @@ ares_rand_state *ares__init_rand_state(void) if (!ares__init_rand_engine(state)) { ares_free(state); /* LCOV_EXCL_LINE: UntestablePath */ - return NULL; /* LCOV_EXCL_LINE: UntestablePath */ + return NULL; /* LCOV_EXCL_LINE: UntestablePath */ } return state; @@ -250,7 +255,7 @@ static void ares__clear_rand_state(ares_rand_state *state) break; case ARES_RAND_RC4: break; - /* LCOV_EXCL_STOP */ + /* LCOV_EXCL_STOP */ } } @@ -313,7 +318,7 @@ static void ares__rand_bytes_fetch(ares_rand_state *state, unsigned char *buf, break; #endif - /* LCOV_EXCL_START: FallbackCode */ + /* LCOV_EXCL_START: FallbackCode */ case ARES_RAND_FILE: while (1) { @@ -334,8 +339,7 @@ static void ares__rand_bytes_fetch(ares_rand_state *state, unsigned char *buf, ares_rc4_prng(&state->state.rc4, buf, len); return; - /* LCOV_EXCL_STOP */ - + /* LCOV_EXCL_STOP */ } /* If we didn't return before we got here, that means we had a critical rand diff --git a/deps/cares/src/lib/ares_search.c b/deps/cares/src/lib/ares_search.c index 7403de1674dabc..ae98df39a80a8f 100644 --- a/deps/cares/src/lib/ares_search.c +++ b/deps/cares/src/lib/ares_search.c @@ -25,16 +25,12 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" +#include "ares_private.h" #ifdef HAVE_STRINGS_H # include #endif -#include "ares.h" -#include "ares_private.h" -#include "ares_dns.h" - struct search_query { /* Arguments passed to ares_search_dnsrec() */ ares_channel_t *channel; @@ -97,7 +93,7 @@ static ares_status_t ares_search_next(ares_channel_t *channel, } status = - ares_send_dnsrec(channel, squery->dnsrec, search_callback, squery, NULL); + ares_send_nolock(channel, squery->dnsrec, search_callback, squery, NULL); if (status != ARES_EFORMERR) { *skip_cleanup = ARES_TRUE; @@ -201,7 +197,7 @@ ares_status_t ares__search_name_list(const ares_channel_t *channel, list = ares_malloc_zero(sizeof(*list) * list_len); if (list == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } list[0] = alias; alias = NULL; @@ -216,7 +212,7 @@ ares_status_t ares__search_name_list(const ares_channel_t *channel, list = ares_malloc_zero(sizeof(*list) * list_len); if (list == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } list[0] = ares_strdup(name); if (list[0] == NULL) { @@ -323,7 +319,7 @@ static ares_status_t ares_search_int(ares_channel_t *channel, squery = ares_malloc_zero(sizeof(*squery)); if (squery == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto fail; /* LCOV_EXCL_LINE: OutOfMemory */ + goto fail; /* LCOV_EXCL_LINE: OutOfMemory */ } squery->channel = channel; @@ -332,7 +328,7 @@ static ares_status_t ares_search_int(ares_channel_t *channel, squery->dnsrec = ares_dns_record_duplicate(dnsrec); if (squery->dnsrec == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto fail; /* LCOV_EXCL_LINE: OutOfMemory */ + goto fail; /* LCOV_EXCL_LINE: OutOfMemory */ } squery->callback = callback; @@ -456,7 +452,7 @@ ares_status_t ares_search_dnsrec(ares_channel_t *channel, ares_status_t status; if (channel == NULL || dnsrec == NULL || callback == NULL) { - return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */ + return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */ } ares__channel_lock(channel); @@ -498,7 +494,7 @@ ares_status_t ares__lookup_hostaliases(const ares_channel_t *channel, ares__llist_node_t *node; if (channel == NULL || name == NULL || alias == NULL) { - return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */ + return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */ } *alias = NULL; @@ -521,8 +517,8 @@ ares_status_t ares__lookup_hostaliases(const ares_channel_t *channel, buf = ares__buf_create(); if (buf == NULL) { - status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } status = ares__buf_load_file(hostaliases, buf); @@ -581,8 +577,8 @@ ares_status_t ares__lookup_hostaliases(const ares_channel_t *channel, *alias = ares_strdup(fqdn); if (*alias == NULL) { - status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } /* Good! */ diff --git a/deps/cares/src/lib/ares_send.c b/deps/cares/src/lib/ares_send.c index 800edce63dcd44..94e7e12b42d0ce 100644 --- a/deps/cares/src/lib/ares_send.c +++ b/deps/cares/src/lib/ares_send.c @@ -25,18 +25,13 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" +#include "ares_private.h" #ifdef HAVE_NETINET_IN_H # include #endif - #include "ares_nameser.h" -#include "ares.h" -#include "ares_dns.h" -#include "ares_private.h" - static unsigned short generate_unique_qid(ares_channel_t *channel) { unsigned short id; @@ -48,18 +43,79 @@ static unsigned short generate_unique_qid(ares_channel_t *channel) return id; } -static ares_status_t ares_send_dnsrec_int(ares_channel_t *channel, - const ares_dns_record_t *dnsrec, - ares_callback_dnsrec callback, - void *arg, unsigned short *qid) + +/* https://datatracker.ietf.org/doc/html/draft-vixie-dnsext-dns0x20-00 */ +static ares_status_t ares_apply_dns0x20(ares_channel_t *channel, + ares_dns_record_t *dnsrec) +{ + ares_status_t status = ARES_SUCCESS; + const char *name = NULL; + char dns0x20name[256]; + unsigned char randdata[256 / 8]; + size_t len; + size_t remaining_bits; + size_t total_bits; + size_t i; + + status = ares_dns_record_query_get(dnsrec, 0, &name, NULL, NULL); + if (status != ARES_SUCCESS) { + goto done; + } + + len = ares_strlen(name); + if (len == 0 || len >= sizeof(dns0x20name)) { + status = ARES_EBADNAME; + goto done; + } + + memset(dns0x20name, 0, sizeof(dns0x20name)); + + /* Fetch the minimum amount of random data we'd need for the string, which + * is 1 bit per byte */ + total_bits = ((len + 7) / 8) * 8; + remaining_bits = total_bits; + ares__rand_bytes(channel->rand_state, randdata, total_bits / 8); + + /* Randomly apply 0x20 to name */ + for (i=0; iservers) == 0) { callback(arg, ARES_ENOSERVER, 0, NULL); return ARES_ENOSERVER; @@ -78,26 +134,36 @@ static ares_status_t ares_send_dnsrec_int(ares_channel_t *channel, query = ares_malloc(sizeof(struct query)); if (!query) { callback(arg, ARES_ENOMEM, 0, NULL); /* LCOV_EXCL_LINE: OutOfMemory */ - return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ + return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ } memset(query, 0, sizeof(*query)); - query->channel = channel; - - status = ares_dns_write(dnsrec, &query->qbuf, &query->qlen); - if (status != ARES_SUCCESS) { - ares_free(query); - callback(arg, status, 0, NULL); - return status; - } - + query->channel = channel; query->qid = id; query->timeout.sec = 0; query->timeout.usec = 0; + query->using_tcp = (channel->flags & ARES_FLAG_USEVC)?ARES_TRUE:ARES_FALSE; + + /* Duplicate Query */ + query->query = ares_dns_record_duplicate(dnsrec); + if (query->query == NULL) { + ares_free(query); + callback(arg, ARES_ENOMEM, 0, NULL); + return ARES_ENOMEM; + } - /* Ignore first 2 bytes, assign our own query id */ - query->qbuf[0] = (unsigned char)((id >> 8) & 0xFF); - query->qbuf[1] = (unsigned char)(id & 0xFF); + ares_dns_record_set_id(query->query, id); + + if (channel->flags & ARES_FLAG_DNS0x20 && !query->using_tcp) { + status = ares_apply_dns0x20(channel, query->query); + if (status != ARES_SUCCESS) { + /* LCOV_EXCL_START: OutOfMemory */ + callback(arg, status, 0, NULL); + ares__free_query(query); + return status; + /* LCOV_EXCL_STOP */ + } + } /* Fill in query arguments. */ query->callback = callback; @@ -106,9 +172,6 @@ static ares_status_t ares_send_dnsrec_int(ares_channel_t *channel, /* Initialize query status. */ query->try_count = 0; - packetsz = (channel->flags & ARES_FLAG_EDNS) ? channel->ednspsz : PACKETSZ; - query->using_tcp = - (channel->flags & ARES_FLAG_USEVC) || query->qlen > packetsz; query->error_status = ARES_SUCCESS; query->timeouts = 0; @@ -161,7 +224,7 @@ ares_status_t ares_send_dnsrec(ares_channel_t *channel, ares__channel_lock(channel); - status = ares_send_dnsrec_int(channel, dnsrec, callback, arg, qid); + status = ares_send_nolock(channel, dnsrec, callback, arg, qid); ares__channel_unlock(channel); diff --git a/deps/cares/src/lib/ares_setup.h b/deps/cares/src/lib/ares_setup.h index ea66b1115bf885..1b554f1974c4e8 100644 --- a/deps/cares/src/lib/ares_setup.h +++ b/deps/cares/src/lib/ares_setup.h @@ -23,8 +23,16 @@ * * SPDX-License-Identifier: MIT */ -#ifndef HEADER_CARES_SETUP_H -#define HEADER_CARES_SETUP_H +#ifndef __ARES_SETUP_H +#define __ARES_SETUP_H + +/* ============================================================================ + * NOTE: This file is automatically included by ares_private.h and should not + * typically be included directly. + * All c-ares source files should include ares_private.h as the + * first header. + * ============================================================================ + */ /* * Include configuration script results or hand-crafted @@ -34,62 +42,17 @@ #ifdef HAVE_CONFIG_H # include "ares_config.h" #else - # ifdef _WIN32 # include "config-win32.h" # endif - #endif /* HAVE_CONFIG_H */ -/* ================================================================ */ -/* Definition of preprocessor macros/symbols which modify compiler */ -/* behaviour or generated code characteristics must be done here, */ -/* as appropriate, before any system header file is included. It is */ -/* also possible to have them defined in the config file included */ -/* before this point. As a result of all this we frown inclusion of */ -/* system header files in our config files, avoid this at any cost. */ -/* ================================================================ */ - -/* - * AIX 4.3 and newer needs _THREAD_SAFE defined to build - * proper reentrant code. Others may also need it. - */ - -#ifdef NEED_THREAD_SAFE -# ifndef _THREAD_SAFE -# define _THREAD_SAFE -# endif -#endif - -/* - * Tru64 needs _REENTRANT set for a few function prototypes and - * things to appear in the system header files. Unixware needs it - * to build proper reentrant code. Others may also need it. - */ - -#ifdef NEED_REENTRANT -# ifndef _REENTRANT -# define _REENTRANT -# endif -#endif - -/* ================================================================ */ -/* If you need to include a system header file for your platform, */ -/* please, do it beyond the point further indicated in this file. */ -/* ================================================================ */ - /* * c-ares external interface definitions are also used internally, * and might also include required system header files to define them. */ -#include - -/* - * Compile time sanity checks must also be done when building the library. - */ - -#include +#include "ares_build.h" /* ================================================================= */ /* No system header file shall be included in this file before this */ @@ -107,6 +70,10 @@ * neither HAVE_WS2TCPIP_H when __CYGWIN__ is defined. */ +#ifdef USE_WINSOCK +# undef USE_WINSOCK +#endif + #ifdef HAVE_WINDOWS_H # ifndef WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN @@ -114,52 +81,56 @@ # include # ifdef HAVE_WINSOCK2_H # include +# define USE_WINSOCK 2 # ifdef HAVE_WS2TCPIP_H # include # endif # else # ifdef HAVE_WINSOCK_H # include +# define USE_WINSOCK 1 # endif # endif #endif -/* - * Define USE_WINSOCK to 2 if we have and use WINSOCK2 API, else - * define USE_WINSOCK to 1 if we have and use WINSOCK API, else - * undefine USE_WINSOCK. - */ -#ifdef USE_WINSOCK -# undef USE_WINSOCK +#include +#include +#include +#include +#include + +#ifdef HAVE_ERRNO_H +# include #endif -#ifdef HAVE_WINSOCK2_H -# define USE_WINSOCK 2 -#else -# ifdef HAVE_WINSOCK_H -# define USE_WINSOCK 1 -# endif + +#ifdef HAVE_SYS_TYPES_H +# include #endif -/* - * Work-arounds for systems without configure support - */ +#ifdef HAVE_MALLOC_H +# include +#endif -#ifndef HAVE_CONFIG_H +#ifdef HAVE_SYS_STAT_H +# include +#endif -# if !defined(HAVE_SYS_TIME_H) && !defined(_MSC_VER) && !defined(__WATCOMC__) -# define HAVE_SYS_TIME_H -# endif +#ifdef HAVE_SYS_TIME_H +# include +#endif -# if !defined(HAVE_UNISTD_H) && !defined(_MSC_VER) -# define HAVE_UNISTD_H 1 -# endif +#ifdef HAVE_TIME_H +# include +#endif -# if !defined(HAVE_SYS_UIO_H) && !defined(_WIN32) && !defined(MSDOS) -# define HAVE_SYS_UIO_H -# endif +#ifdef HAVE_UNISTD_H +# include +#endif -#endif /* HAVE_CONFIG_H */ +#ifdef HAVE_SYS_SOCKET_H +# include +#endif /* * Arg 2 type for gethostname in case it hasn't been defined in config file. @@ -227,12 +198,259 @@ # endif #endif + +#ifdef __hpux +# if !defined(_XOPEN_SOURCE_EXTENDED) || defined(_KERNEL) +# ifdef _APP32_64BIT_OFF_T +# define OLD_APP32_64BIT_OFF_T _APP32_64BIT_OFF_T +# undef _APP32_64BIT_OFF_T +# else +# undef OLD_APP32_64BIT_OFF_T +# endif +# endif +#endif + +#ifdef __hpux +# if !defined(_XOPEN_SOURCE_EXTENDED) || defined(_KERNEL) +# ifdef OLD_APP32_64BIT_OFF_T +# define _APP32_64BIT_OFF_T OLD_APP32_64BIT_OFF_T +# undef OLD_APP32_64BIT_OFF_T +# endif +# endif +#endif + + +/* + * Definition of timeval struct for platforms that don't have it. + */ + +#ifndef HAVE_STRUCT_TIMEVAL +struct timeval { + long tv_sec; + long tv_usec; +}; +#endif + + +/* + * If we have the MSG_NOSIGNAL define, make sure we use + * it as the fourth argument of function send() + */ + +#ifdef HAVE_MSG_NOSIGNAL +# define SEND_4TH_ARG MSG_NOSIGNAL +#else +# define SEND_4TH_ARG 0 +#endif + + +#if defined(__minix) +/* Minix doesn't support recv on TCP sockets */ +# define sread(x, y, z) \ + (ares_ssize_t) \ + read((RECV_TYPE_ARG1)(x), (RECV_TYPE_ARG2)(y), (RECV_TYPE_ARG3)(z)) + +#elif defined(HAVE_RECV) +/* + * The definitions for the return type and arguments types + * of functions recv() and send() belong and come from the + * configuration file. Do not define them in any other place. + * + * HAVE_RECV is defined if you have a function named recv() + * which is used to read incoming data from sockets. If your + * function has another name then don't define HAVE_RECV. + * + * If HAVE_RECV is defined then RECV_TYPE_ARG1, RECV_TYPE_ARG2, + * RECV_TYPE_ARG3, RECV_TYPE_ARG4 and RECV_TYPE_RETV must also + * be defined. + * + * HAVE_SEND is defined if you have a function named send() + * which is used to write outgoing data on a connected socket. + * If yours has another name then don't define HAVE_SEND. + * + * If HAVE_SEND is defined then SEND_TYPE_ARG1, + * SEND_TYPE_ARG2, SEND_TYPE_ARG3, SEND_TYPE_ARG4 and + * SEND_TYPE_RETV must also be defined. + */ + +# if !defined(RECV_TYPE_ARG1) || !defined(RECV_TYPE_ARG2) || \ + !defined(RECV_TYPE_ARG3) || !defined(RECV_TYPE_ARG4) || \ + !defined(RECV_TYPE_RETV) +/* */ +Error Missing_definition_of_return_and_arguments_types_of_recv +/* */ +# else +# define sread(x, y, z) \ + (ares_ssize_t) recv((RECV_TYPE_ARG1)(x), (RECV_TYPE_ARG2)(y), \ + (RECV_TYPE_ARG3)(z), (RECV_TYPE_ARG4)(0)) +# endif +#else /* HAVE_RECV */ +# ifndef sread +/* */ +Error Missing_definition_of_macro_sread +/* */ +# endif +#endif /* HAVE_RECV */ + + +#if defined(__minix) +/* Minix doesn't support send on TCP sockets */ +# define swrite(x, y, z) \ + (ares_ssize_t) \ + write((SEND_TYPE_ARG1)(x), (SEND_TYPE_ARG2)(y), (SEND_TYPE_ARG3)(z)) + +#elif defined(HAVE_SEND) +# if !defined(SEND_TYPE_ARG1) || \ + !defined(SEND_TYPE_ARG2) || !defined(SEND_TYPE_ARG3) || \ + !defined(SEND_TYPE_ARG4) || !defined(SEND_TYPE_RETV) + /* */ + Error Missing_definition_of_return_and_arguments_types_of_send +/* */ +# else +# define swrite(x, y, z) \ + (ares_ssize_t) send((SEND_TYPE_ARG1)(x), (SEND_TYPE_ARG2)(y), \ + (SEND_TYPE_ARG3)(z), (SEND_TYPE_ARG4)(SEND_4TH_ARG)) +# endif +#else /* HAVE_SEND */ +# ifndef swrite + /* */ + Error Missing_definition_of_macro_swrite +/* */ +# endif +#endif /* HAVE_SEND */ + + +/* + * Function-like macro definition used to close a socket. + */ + +#if defined(HAVE_CLOSESOCKET) +# define sclose(x) closesocket((x)) +#elif defined(HAVE_CLOSESOCKET_CAMEL) +# define sclose(x) CloseSocket((x)) +#elif defined(HAVE_CLOSE_S) +# define sclose(x) close_s((x)) +#else +# define sclose(x) close((x)) +#endif + /* - * Include macros and defines that should only be processed once. + * Macro used to include code only in debug builds. */ -#ifndef __SETUP_ONCE_H -# include "setup_once.h" +#ifdef DEBUGBUILD +# define DEBUGF(x) x +#else +# define DEBUGF(x) \ + do { \ + } while(0) +#endif + +/* + * Macro SOCKERRNO / SET_SOCKERRNO() returns / sets the *socket-related* errno + * (or equivalent) on this platform to hide platform details to code using it. + */ + +#ifdef USE_WINSOCK +# define SOCKERRNO ((int)WSAGetLastError()) +# define SET_SOCKERRNO(x) (WSASetLastError((int)(x))) +#else +# define SOCKERRNO (errno) +# define SET_SOCKERRNO(x) (errno = (x)) +#endif + + +/* + * Macro ERRNO / SET_ERRNO() returns / sets the NOT *socket-related* errno + * (or equivalent) on this platform to hide platform details to code using it. + */ + +#if defined(WIN32) && !defined(WATT32) +# define ERRNO ((int)GetLastError()) +# define SET_ERRNO(x) (SetLastError((DWORD)(x))) +#else +# define ERRNO (errno) +# define SET_ERRNO(x) (errno = (x)) +#endif + + +/* + * Portable error number symbolic names defined to Winsock error codes. + */ + +#ifdef USE_WINSOCK +# undef EBADF /* override definition in errno.h */ +# define EBADF WSAEBADF +# undef EINTR /* override definition in errno.h */ +# define EINTR WSAEINTR +# undef EINVAL /* override definition in errno.h */ +# define EINVAL WSAEINVAL +# undef EWOULDBLOCK /* override definition in errno.h */ +# define EWOULDBLOCK WSAEWOULDBLOCK +# undef EINPROGRESS /* override definition in errno.h */ +# define EINPROGRESS WSAEINPROGRESS +# undef EALREADY /* override definition in errno.h */ +# define EALREADY WSAEALREADY +# undef ENOTSOCK /* override definition in errno.h */ +# define ENOTSOCK WSAENOTSOCK +# undef EDESTADDRREQ /* override definition in errno.h */ +# define EDESTADDRREQ WSAEDESTADDRREQ +# undef EMSGSIZE /* override definition in errno.h */ +# define EMSGSIZE WSAEMSGSIZE +# undef EPROTOTYPE /* override definition in errno.h */ +# define EPROTOTYPE WSAEPROTOTYPE +# undef ENOPROTOOPT /* override definition in errno.h */ +# define ENOPROTOOPT WSAENOPROTOOPT +# undef EPROTONOSUPPORT /* override definition in errno.h */ +# define EPROTONOSUPPORT WSAEPROTONOSUPPORT +# define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT +# undef EOPNOTSUPP /* override definition in errno.h */ +# define EOPNOTSUPP WSAEOPNOTSUPP +# define EPFNOSUPPORT WSAEPFNOSUPPORT +# undef EAFNOSUPPORT /* override definition in errno.h */ +# define EAFNOSUPPORT WSAEAFNOSUPPORT +# undef EADDRINUSE /* override definition in errno.h */ +# define EADDRINUSE WSAEADDRINUSE +# undef EADDRNOTAVAIL /* override definition in errno.h */ +# define EADDRNOTAVAIL WSAEADDRNOTAVAIL +# undef ENETDOWN /* override definition in errno.h */ +# define ENETDOWN WSAENETDOWN +# undef ENETUNREACH /* override definition in errno.h */ +# define ENETUNREACH WSAENETUNREACH +# undef ENETRESET /* override definition in errno.h */ +# define ENETRESET WSAENETRESET +# undef ECONNABORTED /* override definition in errno.h */ +# define ECONNABORTED WSAECONNABORTED +# undef ECONNRESET /* override definition in errno.h */ +# define ECONNRESET WSAECONNRESET +# undef ENOBUFS /* override definition in errno.h */ +# define ENOBUFS WSAENOBUFS +# undef EISCONN /* override definition in errno.h */ +# define EISCONN WSAEISCONN +# undef ENOTCONN /* override definition in errno.h */ +# define ENOTCONN WSAENOTCONN +# define ESHUTDOWN WSAESHUTDOWN +# define ETOOMANYREFS WSAETOOMANYREFS +# undef ETIMEDOUT /* override definition in errno.h */ +# define ETIMEDOUT WSAETIMEDOUT +# undef ECONNREFUSED /* override definition in errno.h */ +# define ECONNREFUSED WSAECONNREFUSED +# undef ELOOP /* override definition in errno.h */ +# define ELOOP WSAELOOP +# ifndef ENAMETOOLONG /* possible previous definition in errno.h */ +# define ENAMETOOLONG WSAENAMETOOLONG +# endif +# define EHOSTDOWN WSAEHOSTDOWN +# undef EHOSTUNREACH /* override definition in errno.h */ +# define EHOSTUNREACH WSAEHOSTUNREACH +# ifndef ENOTEMPTY /* possible previous definition in errno.h */ +# define ENOTEMPTY WSAENOTEMPTY +# endif +# define EPROCLIM WSAEPROCLIM +# define EUSERS WSAEUSERS +# define EDQUOT WSAEDQUOT +# define ESTALE WSAESTALE +# define EREMOTE WSAEREMOTE #endif -#endif /* HEADER_CARES_SETUP_H */ +#endif /* __ARES_SETUP_H */ diff --git a/deps/cares/src/lib/ares_str.c b/deps/cares/src/lib/ares_str.c index db0a12bd2fda8a..ade61041eb920b 100644 --- a/deps/cares/src/lib/ares_str.c +++ b/deps/cares/src/lib/ares_str.c @@ -25,10 +25,8 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" -#include "ares_str.h" -#include "ares.h" #include "ares_private.h" +#include "ares_str.h" #ifdef HAVE_STDINT_H # include diff --git a/deps/cares/src/lib/ares_str.h b/deps/cares/src/lib/ares_str.h index 526a927a62869b..81353221407ed7 100644 --- a/deps/cares/src/lib/ares_str.h +++ b/deps/cares/src/lib/ares_str.h @@ -27,9 +27,6 @@ #ifndef __ARES_STR_H #define __ARES_STR_H -#include "ares_setup.h" -#include "ares.h" - char *ares_strdup(const char *s1); size_t ares_strlen(const char *str); diff --git a/deps/cares/src/lib/ares_strcasecmp.c b/deps/cares/src/lib/ares_strcasecmp.c index b91cbbe1544a84..76b835fd8e92f1 100644 --- a/deps/cares/src/lib/ares_strcasecmp.c +++ b/deps/cares/src/lib/ares_strcasecmp.c @@ -25,7 +25,7 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" +#include "ares_private.h" #include "ares_strcasecmp.h" #ifndef HAVE_STRCASECMP @@ -39,8 +39,8 @@ int ares_strcasecmp(const char *a, const char *b) size_t i; for (i = 0; i < (size_t)-1; i++) { - int c1 = ISUPPER(a[i]) ? tolower(a[i]) : a[i]; - int c2 = ISUPPER(b[i]) ? tolower(b[i]) : b[i]; + int c1 = ares__tolower(a[i]); + int c2 = ares__tolower(b[i]); if (c1 != c2) { return c1 - c2; } @@ -64,8 +64,8 @@ int ares_strncasecmp(const char *a, const char *b, size_t n) size_t i; for (i = 0; i < n; i++) { - int c1 = ISUPPER(a[i]) ? tolower(a[i]) : a[i]; - int c2 = ISUPPER(b[i]) ? tolower(b[i]) : b[i]; + int c1 = ares__tolower(a[i]); + int c2 = ares__tolower(b[i]); if (c1 != c2) { return c1 - c2; } diff --git a/deps/cares/src/lib/ares_strcasecmp.h b/deps/cares/src/lib/ares_strcasecmp.h index 31a66be7179d4e..a8097d2219e309 100644 --- a/deps/cares/src/lib/ares_strcasecmp.h +++ b/deps/cares/src/lib/ares_strcasecmp.h @@ -27,8 +27,6 @@ #ifndef HEADER_CARES_STRCASECMP_H #define HEADER_CARES_STRCASECMP_H -#include "ares_setup.h" - #ifndef HAVE_STRCASECMP extern int ares_strcasecmp(const char *a, const char *b); #endif diff --git a/deps/cares/src/lib/ares_strerror.c b/deps/cares/src/lib/ares_strerror.c index ae94f9619efa45..d9f641162026c0 100644 --- a/deps/cares/src/lib/ares_strerror.c +++ b/deps/cares/src/lib/ares_strerror.c @@ -25,9 +25,7 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" -#include -#include "ares.h" +#include "ares_private.h" const char *ares_strerror(int code) { diff --git a/deps/cares/src/lib/ares_strsplit.c b/deps/cares/src/lib/ares_strsplit.c index 432a2d6cebbbbb..dee307d7799f51 100644 --- a/deps/cares/src/lib/ares_strsplit.c +++ b/deps/cares/src/lib/ares_strsplit.c @@ -23,13 +23,6 @@ * * SPDX-License-Identifier: MIT */ - -#if defined(__MVS__) -# include -#endif - -#include "ares_setup.h" -#include "ares.h" #include "ares_private.h" void ares__strsplit_free(char **elms, size_t num_elm) @@ -64,7 +57,7 @@ char **ares__strsplit_duplicate(char **elms, size_t num_elm) out[i] = ares_strdup(elms[i]); if (out[i] == NULL) { ares__strsplit_free(out, num_elm); /* LCOV_EXCL_LINE: OutOfMemory */ - return NULL; /* LCOV_EXCL_LINE: OutOfMemory */ + return NULL; /* LCOV_EXCL_LINE: OutOfMemory */ } } @@ -109,7 +102,7 @@ char **ares__strsplit(const char *in, const char *delms, size_t *num_elm) out = ares_malloc_zero(cnt * sizeof(*out)); if (out == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } for (node = ares__llist_node_first(llist); node != NULL; diff --git a/deps/cares/src/lib/ares_strsplit.h b/deps/cares/src/lib/ares_strsplit.h index af650eee534809..ee997804f012f1 100644 --- a/deps/cares/src/lib/ares_strsplit.h +++ b/deps/cares/src/lib/ares_strsplit.h @@ -26,8 +26,6 @@ #ifndef HEADER_CARES_STRSPLIT_H #define HEADER_CARES_STRSPLIT_H -#include "ares_setup.h" - /* Split a string on delms skipping empty or duplicate elements. * * param in String to split. diff --git a/deps/cares/src/lib/ares_sysconfig.c b/deps/cares/src/lib/ares_sysconfig.c index 32f8b7f8ba1c08..2cd3df28235ec3 100644 --- a/deps/cares/src/lib/ares_sysconfig.c +++ b/deps/cares/src/lib/ares_sysconfig.c @@ -25,7 +25,7 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" +#include "ares_private.h" #ifdef HAVE_SYS_PARAM_H # include @@ -43,8 +43,6 @@ # include #endif -#include "ares_nameser.h" - #if defined(ANDROID) || defined(__ANDROID__) # include # include "ares_android.h" @@ -57,581 +55,9 @@ # include #endif -#if defined(USE_WINSOCK) -# if defined(HAVE_IPHLPAPI_H) -# include -# endif -# if defined(HAVE_NETIOAPI_H) -# include -# endif -#endif - -#include "ares.h" #include "ares_inet_net_pton.h" #include "ares_platform.h" -#include "ares_private.h" - -#if defined(USE_WINSOCK) -/* - * get_REG_SZ() - * - * Given a 'hKey' handle to an open registry key and a 'leafKeyName' pointer - * to the name of the registry leaf key to be queried, fetch it's string - * value and return a pointer in *outptr to a newly allocated memory area - * holding it as a null-terminated string. - * - * Returns 0 and nullifies *outptr upon inability to return a string value. - * - * Returns 1 and sets *outptr when returning a dynamically allocated string. - * - * Supported on Windows NT 3.5 and newer. - */ -static ares_bool_t get_REG_SZ(HKEY hKey, const char *leafKeyName, char **outptr) -{ - DWORD size = 0; - int res; - - *outptr = NULL; - - /* Find out size of string stored in registry */ - res = RegQueryValueExA(hKey, leafKeyName, 0, NULL, NULL, &size); - if ((res != ERROR_SUCCESS && res != ERROR_MORE_DATA) || !size) { - return ARES_FALSE; - } - - /* Allocate buffer of indicated size plus one given that string - might have been stored without null termination */ - *outptr = ares_malloc(size + 1); - if (!*outptr) { - return ARES_FALSE; - } - - /* Get the value for real */ - res = RegQueryValueExA(hKey, leafKeyName, 0, NULL, (unsigned char *)*outptr, - &size); - if ((res != ERROR_SUCCESS) || (size == 1)) { - ares_free(*outptr); - *outptr = NULL; - return ARES_FALSE; - } - - /* Null terminate buffer always */ - *(*outptr + size) = '\0'; - - return ARES_TRUE; -} - -static void commanjoin(char **dst, const char * const src, const size_t len) -{ - char *newbuf; - size_t newsize; - - /* 1 for terminating 0 and 2 for , and terminating 0 */ - newsize = len + (*dst ? (ares_strlen(*dst) + 2) : 1); - newbuf = ares_realloc(*dst, newsize); - if (!newbuf) { - return; - } - if (*dst == NULL) { - *newbuf = '\0'; - } - *dst = newbuf; - if (ares_strlen(*dst) != 0) { - strcat(*dst, ","); - } - strncat(*dst, src, len); -} - -/* - * commajoin() - * - * RTF code. - */ -static void commajoin(char **dst, const char *src) -{ - commanjoin(dst, src, ares_strlen(src)); -} - -/* A structure to hold the string form of IPv4 and IPv6 addresses so we can - * sort them by a metric. - */ -typedef struct { - /* The metric we sort them by. */ - ULONG metric; - - /* Original index of the item, used as a secondary sort parameter to make - * qsort() stable if the metrics are equal */ - size_t orig_idx; - - /* Room enough for the string form of any IPv4 or IPv6 address that - * ares_inet_ntop() will create. Based on the existing c-ares practice. - */ - char text[INET6_ADDRSTRLEN + 8 + 64]; /* [%s]:NNNNN%iface */ -} Address; - -/* Sort Address values \a left and \a right by metric, returning the usual - * indicators for qsort(). - */ -static int compareAddresses(const void *arg1, const void *arg2) -{ - const Address * const left = arg1; - const Address * const right = arg2; - /* Lower metric the more preferred */ - if (left->metric < right->metric) { - return -1; - } - if (left->metric > right->metric) { - return 1; - } - /* If metrics are equal, lower original index more preferred */ - if (left->orig_idx < right->orig_idx) { - return -1; - } - if (left->orig_idx > right->orig_idx) { - return 1; - } - return 0; -} - -/* There can be multiple routes to "the Internet". And there can be different - * DNS servers associated with each of the interfaces that offer those routes. - * We have to assume that any DNS server can serve any request. But, some DNS - * servers may only respond if requested over their associated interface. But - * we also want to use "the preferred route to the Internet" whenever possible - * (and not use DNS servers on a non-preferred route even by forcing request - * to go out on the associated non-preferred interface). i.e. We want to use - * the DNS servers associated with the same interface that we would use to - * make a general request to anything else. - * - * But, Windows won't sort the DNS servers by the metrics associated with the - * routes and interfaces _even_ though it obviously sends IP packets based on - * those same routes and metrics. So, we must do it ourselves. - * - * So, we sort the DNS servers by the same metric values used to determine how - * an outgoing IP packet will go, thus effectively using the DNS servers - * associated with the interface that the DNS requests themselves will - * travel. This gives us optimal routing and avoids issues where DNS servers - * won't respond to requests that don't arrive via some specific subnetwork - * (and thus some specific interface). - * - * This function computes the metric we use to sort. On the interface - * identified by \a luid, it determines the best route to \a dest and combines - * that route's metric with \a interfaceMetric to compute a metric for the - * destination address on that interface. This metric can be used as a weight - * to sort the DNS server addresses associated with each interface (lower is - * better). - * - * Note that by restricting the route search to the specific interface with - * which the DNS servers are associated, this function asks the question "What - * is the metric for sending IP packets to this DNS server?" which allows us - * to sort the DNS servers correctly. - */ -static ULONG getBestRouteMetric(IF_LUID * const luid, /* Can't be const :( */ - const SOCKADDR_INET * const dest, - const ULONG interfaceMetric) -{ - /* On this interface, get the best route to that destination. */ -# if defined(__WATCOMC__) - /* OpenWatcom's builtin Windows SDK does not have a definition for - * MIB_IPFORWARD_ROW2, and also does not allow the usage of SOCKADDR_INET - * as a variable. Let's work around this by returning the worst possible - * metric, but only when using the OpenWatcom compiler. - * It may be worth investigating using a different version of the Windows - * SDK with OpenWatcom in the future, though this may be fixed in OpenWatcom - * 2.0. - */ - return (ULONG)-1; -# else - MIB_IPFORWARD_ROW2 row; - SOCKADDR_INET ignored; - if (GetBestRoute2(/* The interface to use. The index is ignored since we are - * passing a LUID. - */ - luid, 0, - /* No specific source address. */ - NULL, - /* Our destination address. */ - dest, - /* No options. */ - 0, - /* The route row. */ - &row, - /* The best source address, which we don't need. */ - &ignored) != NO_ERROR - /* If the metric is "unused" (-1) or too large for us to add the two - * metrics, use the worst possible, thus sorting this last. - */ - || row.Metric == (ULONG)-1 || - row.Metric > ((ULONG)-1) - interfaceMetric) { - /* Return the worst possible metric. */ - return (ULONG)-1; - } - - /* Return the metric value from that row, plus the interface metric. - * - * See - * http://msdn.microsoft.com/en-us/library/windows/desktop/aa814494(v=vs.85).aspx - * which describes the combination as a "sum". - */ - return row.Metric + interfaceMetric; -# endif /* __WATCOMC__ */ -} - -/* - * get_DNS_Windows() - * - * Locates DNS info using GetAdaptersAddresses() function from the Internet - * Protocol Helper (IP Helper) API. When located, this returns a pointer - * in *outptr to a newly allocated memory area holding a null-terminated - * string with a space or comma separated list of DNS IP addresses. - * - * Returns 0 and nullifies *outptr upon inability to return DNSes string. - * - * Returns 1 and sets *outptr when returning a dynamically allocated string. - * - * Implementation supports Windows XP and newer. - */ -# define IPAA_INITIAL_BUF_SZ 15 * 1024 -# define IPAA_MAX_TRIES 3 - -static ares_bool_t get_DNS_Windows(char **outptr) -{ - IP_ADAPTER_DNS_SERVER_ADDRESS *ipaDNSAddr; - IP_ADAPTER_ADDRESSES *ipaa; - IP_ADAPTER_ADDRESSES *newipaa; - IP_ADAPTER_ADDRESSES *ipaaEntry; - ULONG ReqBufsz = IPAA_INITIAL_BUF_SZ; - ULONG Bufsz = IPAA_INITIAL_BUF_SZ; - ULONG AddrFlags = 0; - int trying = IPAA_MAX_TRIES; - ULONG res; - - /* The capacity of addresses, in elements. */ - size_t addressesSize; - /* The number of elements in addresses. */ - size_t addressesIndex = 0; - /* The addresses we will sort. */ - Address *addresses; - - union { - struct sockaddr *sa; - struct sockaddr_in *sa4; - struct sockaddr_in6 *sa6; - } namesrvr; - - *outptr = NULL; - - ipaa = ares_malloc(Bufsz); - if (!ipaa) { - return ARES_FALSE; - } - - /* Start with enough room for a few DNS server addresses and we'll grow it - * as we encounter more. - */ - addressesSize = 4; - addresses = (Address *)ares_malloc(sizeof(Address) * addressesSize); - if (addresses == NULL) { - /* We need room for at least some addresses to function. */ - ares_free(ipaa); - return ARES_FALSE; - } - - /* Usually this call succeeds with initial buffer size */ - res = GetAdaptersAddresses(AF_UNSPEC, AddrFlags, NULL, ipaa, &ReqBufsz); - if ((res != ERROR_BUFFER_OVERFLOW) && (res != ERROR_SUCCESS)) { - goto done; - } - - while ((res == ERROR_BUFFER_OVERFLOW) && (--trying)) { - if (Bufsz < ReqBufsz) { - newipaa = ares_realloc(ipaa, ReqBufsz); - if (!newipaa) { - goto done; - } - Bufsz = ReqBufsz; - ipaa = newipaa; - } - res = GetAdaptersAddresses(AF_UNSPEC, AddrFlags, NULL, ipaa, &ReqBufsz); - if (res == ERROR_SUCCESS) { - break; - } - } - if (res != ERROR_SUCCESS) { - goto done; - } - - for (ipaaEntry = ipaa; ipaaEntry; ipaaEntry = ipaaEntry->Next) { - if (ipaaEntry->OperStatus != IfOperStatusUp) { - continue; - } - - /* For each interface, find any associated DNS servers as IPv4 or IPv6 - * addresses. For each found address, find the best route to that DNS - * server address _on_ _that_ _interface_ (at this moment in time) and - * compute the resulting total metric, just as Windows routing will do. - * Then, sort all the addresses found by the metric. - */ - for (ipaDNSAddr = ipaaEntry->FirstDnsServerAddress; ipaDNSAddr; - ipaDNSAddr = ipaDNSAddr->Next) { - char ipaddr[INET6_ADDRSTRLEN] = ""; - namesrvr.sa = ipaDNSAddr->Address.lpSockaddr; - - if (namesrvr.sa->sa_family == AF_INET) { - if ((namesrvr.sa4->sin_addr.S_un.S_addr == INADDR_ANY) || - (namesrvr.sa4->sin_addr.S_un.S_addr == INADDR_NONE)) { - continue; - } - /* Allocate room for another address, if necessary, else skip. */ - if (addressesIndex == addressesSize) { - const size_t newSize = addressesSize + 4; - Address * const newMem = - (Address *)ares_realloc(addresses, sizeof(Address) * newSize); - if (newMem == NULL) { - continue; - } - addresses = newMem; - addressesSize = newSize; - } - - addresses[addressesIndex].metric = getBestRouteMetric( - &ipaaEntry->Luid, (SOCKADDR_INET *)((void *)(namesrvr.sa)), - ipaaEntry->Ipv4Metric); - - /* Record insertion index to make qsort stable */ - addresses[addressesIndex].orig_idx = addressesIndex; - - if (!ares_inet_ntop(AF_INET, &namesrvr.sa4->sin_addr, ipaddr, - sizeof(ipaddr))) { - continue; - } - snprintf(addresses[addressesIndex].text, - sizeof(addresses[addressesIndex].text), "[%s]:%u", ipaddr, - ntohs(namesrvr.sa4->sin_port)); - ++addressesIndex; - } else if (namesrvr.sa->sa_family == AF_INET6) { - unsigned int ll_scope = 0; - struct ares_addr addr; - - if (memcmp(&namesrvr.sa6->sin6_addr, &ares_in6addr_any, - sizeof(namesrvr.sa6->sin6_addr)) == 0) { - continue; - } - - /* Allocate room for another address, if necessary, else skip. */ - if (addressesIndex == addressesSize) { - const size_t newSize = addressesSize + 4; - Address * const newMem = - (Address *)ares_realloc(addresses, sizeof(Address) * newSize); - if (newMem == NULL) { - continue; - } - addresses = newMem; - addressesSize = newSize; - } - - /* See if its link-local */ - memset(&addr, 0, sizeof(addr)); - addr.family = AF_INET6; - memcpy(&addr.addr.addr6, &namesrvr.sa6->sin6_addr, 16); - if (ares__addr_is_linklocal(&addr)) { - ll_scope = ipaaEntry->Ipv6IfIndex; - } - - addresses[addressesIndex].metric = getBestRouteMetric( - &ipaaEntry->Luid, (SOCKADDR_INET *)((void *)(namesrvr.sa)), - ipaaEntry->Ipv6Metric); - - /* Record insertion index to make qsort stable */ - addresses[addressesIndex].orig_idx = addressesIndex; - - if (!ares_inet_ntop(AF_INET6, &namesrvr.sa6->sin6_addr, ipaddr, - sizeof(ipaddr))) { - continue; - } - - if (ll_scope) { - snprintf(addresses[addressesIndex].text, - sizeof(addresses[addressesIndex].text), "[%s]:%u%%%u", - ipaddr, ntohs(namesrvr.sa6->sin6_port), ll_scope); - } else { - snprintf(addresses[addressesIndex].text, - sizeof(addresses[addressesIndex].text), "[%s]:%u", ipaddr, - ntohs(namesrvr.sa6->sin6_port)); - } - ++addressesIndex; - } else { - /* Skip non-IPv4/IPv6 addresses completely. */ - continue; - } - } - } - - /* Sort all of the textual addresses by their metric (and original index if - * metrics are equal). */ - qsort(addresses, addressesIndex, sizeof(*addresses), compareAddresses); - - /* Join them all into a single string, removing duplicates. */ - { - size_t i; - for (i = 0; i < addressesIndex; ++i) { - size_t j; - /* Look for this address text appearing previously in the results. */ - for (j = 0; j < i; ++j) { - if (strcmp(addresses[j].text, addresses[i].text) == 0) { - break; - } - } - /* Iff we didn't emit this address already, emit it now. */ - if (j == i) { - /* Add that to outptr (if we can). */ - commajoin(outptr, addresses[i].text); - } - } - } - -done: - ares_free(addresses); - - if (ipaa) { - ares_free(ipaa); - } - - if (!*outptr) { - return ARES_FALSE; - } - - return ARES_TRUE; -} - -/* - * get_SuffixList_Windows() - * - * Reads the "DNS Suffix Search List" from registry and writes the list items - * whitespace separated to outptr. If the Search List is empty, the - * "Primary Dns Suffix" is written to outptr. - * - * Returns 0 and nullifies *outptr upon inability to return the suffix list. - * - * Returns 1 and sets *outptr when returning a dynamically allocated string. - * - * Implementation supports Windows Server 2003 and newer - */ -static ares_bool_t get_SuffixList_Windows(char **outptr) -{ - HKEY hKey; - HKEY hKeyEnum; - char keyName[256]; - DWORD keyNameBuffSize; - DWORD keyIdx = 0; - char *p = NULL; - - *outptr = NULL; - - if (ares__getplatform() != WIN_NT) { - return ARES_FALSE; - } - - /* 1. Global DNS Suffix Search List */ - if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, WIN_NS_NT_KEY, 0, KEY_READ, &hKey) == - ERROR_SUCCESS) { - get_REG_SZ(hKey, SEARCHLIST_KEY, outptr); - if (get_REG_SZ(hKey, DOMAIN_KEY, &p)) { - commajoin(outptr, p); - ares_free(p); - p = NULL; - } - RegCloseKey(hKey); - } - - if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, WIN_NT_DNSCLIENT, 0, KEY_READ, &hKey) == - ERROR_SUCCESS) { - if (get_REG_SZ(hKey, SEARCHLIST_KEY, &p)) { - commajoin(outptr, p); - ares_free(p); - p = NULL; - } - RegCloseKey(hKey); - } - - /* 2. Connection Specific Search List composed of: - * a. Primary DNS Suffix */ - if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, WIN_DNSCLIENT, 0, KEY_READ, &hKey) == - ERROR_SUCCESS) { - if (get_REG_SZ(hKey, PRIMARYDNSSUFFIX_KEY, &p)) { - commajoin(outptr, p); - ares_free(p); - p = NULL; - } - RegCloseKey(hKey); - } - - /* b. Interface SearchList, Domain, DhcpDomain */ - if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, WIN_NS_NT_KEY "\\" INTERFACES_KEY, 0, - KEY_READ, &hKey) == ERROR_SUCCESS) { - for (;;) { - keyNameBuffSize = sizeof(keyName); - if (RegEnumKeyExA(hKey, keyIdx++, keyName, &keyNameBuffSize, 0, NULL, - NULL, NULL) != ERROR_SUCCESS) { - break; - } - if (RegOpenKeyExA(hKey, keyName, 0, KEY_QUERY_VALUE, &hKeyEnum) != - ERROR_SUCCESS) { - continue; - } - /* p can be comma separated (SearchList) */ - if (get_REG_SZ(hKeyEnum, SEARCHLIST_KEY, &p)) { - commajoin(outptr, p); - ares_free(p); - p = NULL; - } - if (get_REG_SZ(hKeyEnum, DOMAIN_KEY, &p)) { - commajoin(outptr, p); - ares_free(p); - p = NULL; - } - if (get_REG_SZ(hKeyEnum, DHCPDOMAIN_KEY, &p)) { - commajoin(outptr, p); - ares_free(p); - p = NULL; - } - RegCloseKey(hKeyEnum); - } - RegCloseKey(hKey); - } - - return *outptr != NULL ? ARES_TRUE : ARES_FALSE; -} - -static ares_status_t ares__init_sysconfig_windows(ares_sysconfig_t *sysconfig) -{ - char *line = NULL; - ares_status_t status = ARES_SUCCESS; - - if (get_DNS_Windows(&line)) { - status = ares__sconfig_append_fromstr(&sysconfig->sconfig, line, ARES_TRUE); - ares_free(line); - if (status != ARES_SUCCESS) { - goto done; - } - } - - if (get_SuffixList_Windows(&line)) { - sysconfig->domains = ares__strsplit(line, ", ", &sysconfig->ndomains); - ares_free(line); - if (sysconfig->domains == NULL) { - status = ARES_EFILE; - } - if (status != ARES_SUCCESS) { - goto done; - } - } - -done: - return status; -} -#endif #if defined(__MVS__) static ares_status_t ares__init_sysconfig_mvs(ares_sysconfig_t *sysconfig) diff --git a/deps/cares/src/lib/ares_sysconfig_files.c b/deps/cares/src/lib/ares_sysconfig_files.c index f71043000a43a9..7b8bdbe41879d6 100644 --- a/deps/cares/src/lib/ares_sysconfig_files.c +++ b/deps/cares/src/lib/ares_sysconfig_files.c @@ -25,7 +25,7 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" +#include "ares_private.h" #ifdef HAVE_SYS_PARAM_H # include @@ -43,8 +43,6 @@ # include #endif -#include "ares_nameser.h" - #if defined(ANDROID) || defined(__ANDROID__) # include # include "ares_android.h" @@ -61,10 +59,8 @@ # include #endif -#include "ares.h" #include "ares_inet_net_pton.h" #include "ares_platform.h" -#include "ares_private.h" static unsigned char ip_natural_mask(const struct ares_addr *addr) { @@ -263,7 +259,7 @@ ares_status_t ares__parse_sortlist(struct apattern **sortlist, size_t *nsort, if (!sortlist_append(sortlist, nsort, &pat)) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } } diff --git a/deps/cares/src/lib/ares_sysconfig_mac.c b/deps/cares/src/lib/ares_sysconfig_mac.c index 6ec499e59f56b5..e2136201f68879 100644 --- a/deps/cares/src/lib/ares_sysconfig_mac.c +++ b/deps/cares/src/lib/ares_sysconfig_mac.c @@ -45,7 +45,14 @@ * private header extracted from: * https://opensource.apple.com/source/configd/configd-1109.140.1/dnsinfo/dnsinfo.h */ -# include "ares_setup.h" + +/* The apple header uses anonymous unions which came with C11 */ +# if defined(__clang__) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wc11-extensions" +# endif + +# include "ares_private.h" # include # include # include @@ -56,8 +63,6 @@ # if MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 /* MacOS 10.8 */ # include # endif -# include "ares.h" -# include "ares_private.h" typedef struct { void *handle; @@ -80,12 +85,13 @@ static void dnsinfo_destroy(dnsinfo_t *dnsinfo) static ares_status_t dnsinfo_init(dnsinfo_t **dnsinfo_out) { - dnsinfo_t *dnsinfo = NULL; - ares_status_t status = ARES_SUCCESS; + dnsinfo_t *dnsinfo = NULL; + ares_status_t status = ARES_SUCCESS; size_t i; - const char *searchlibs[] = { + const char *searchlibs[] = { "/usr/lib/libSystem.dylib", - "/System/Library/Frameworks/SystemConfiguration.framework/SystemConfiguration", + "/System/Library/Frameworks/SystemConfiguration.framework/" + "SystemConfiguration", NULL }; @@ -102,17 +108,17 @@ static ares_status_t dnsinfo_init(dnsinfo_t **dnsinfo_out) goto done; } - for (i=0; searchlibs[i] != NULL; i++) { + for (i = 0; searchlibs[i] != NULL; i++) { dnsinfo->handle = dlopen(searchlibs[i], RTLD_LAZY /* | RTLD_NOLOAD */); if (dnsinfo->handle == NULL) { /* Fail, loop */ continue; } - dnsinfo->dns_configuration_copy = + dnsinfo->dns_configuration_copy = (dns_config_t *(*)(void)) dlsym(dnsinfo->handle, "dns_configuration_copy"); - dnsinfo->dns_configuration_free = + dnsinfo->dns_configuration_free = (void (*)(dns_config_t *)) dlsym(dnsinfo->handle, "dns_configuration_free"); if (dnsinfo->dns_configuration_copy != NULL && @@ -162,7 +168,7 @@ static ares_status_t read_resolver(const dns_resolver_t *resolver, unsigned short port = 0; ares_status_t status = ARES_SUCCESS; -#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 /* MacOS 10.8 */ +# if MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 /* MacOS 10.8 */ /* XXX: resolver->domain is for domain-specific servers. When we implement * this support, we'll want to use this. But for now, we're going to * skip any servers which set this since we can't properly route. @@ -172,9 +178,9 @@ static ares_status_t read_resolver(const dns_resolver_t *resolver, if (resolver->domain != NULL) { return ARES_SUCCESS; } -#endif +# endif -#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 /* MacOS 10.8 */ +# if MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 /* MacOS 10.8 */ /* Check to see if DNS server should be used, base this on if the server is * reachable or can be reachable automatically if we send traffic that * direction. */ @@ -183,7 +189,7 @@ static ares_status_t read_resolver(const dns_resolver_t *resolver, kSCNetworkReachabilityFlagsConnectionOnTraffic))) { return ARES_SUCCESS; } -#endif +# endif /* NOTE: it doesn't look like resolver->flags is relevant */ @@ -296,8 +302,8 @@ static ares_status_t read_resolver(const dns_resolver_t *resolver, if_name = ares__if_indextoname(resolver->if_index, if_name_str, sizeof(if_name_str)); - status = ares__sconfig_append(&sysconfig->sconfig, &addr, addrport, - addrport, if_name); + status = ares__sconfig_append(&sysconfig->sconfig, &addr, addrport, + addrport, if_name); if (status != ARES_SUCCESS) { return status; } @@ -365,5 +371,13 @@ ares_status_t ares__init_sysconfig_macos(ares_sysconfig_t *sysconfig) return status; } +# if defined(__clang__) +# pragma GCC diagnostic pop +# endif + +#else + +/* Prevent compiler warnings due to empty translation unit */ +typedef int make_iso_compilers_happy; #endif diff --git a/deps/cares/src/lib/ares_sysconfig_win.c b/deps/cares/src/lib/ares_sysconfig_win.c new file mode 100644 index 00000000000000..5ca7ccb50cf18d --- /dev/null +++ b/deps/cares/src/lib/ares_sysconfig_win.c @@ -0,0 +1,618 @@ +/* MIT License + * + * Copyright (c) 1998 Massachusetts Institute of Technology + * Copyright (c) 2007 Daniel Stenberg + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT + */ + +#include "ares_private.h" + +#ifdef HAVE_SYS_PARAM_H +# include +#endif + +#ifdef HAVE_NETINET_IN_H +# include +#endif + +#ifdef HAVE_NETDB_H +# include +#endif + +#ifdef HAVE_ARPA_INET_H +# include +#endif + +#if defined(USE_WINSOCK) +# if defined(HAVE_IPHLPAPI_H) +# include +# endif +# if defined(HAVE_NETIOAPI_H) +# include +# endif +#endif + +#include "ares_inet_net_pton.h" +#include "ares_platform.h" + +#if defined(USE_WINSOCK) +/* + * get_REG_SZ() + * + * Given a 'hKey' handle to an open registry key and a 'leafKeyName' pointer + * to the name of the registry leaf key to be queried, fetch it's string + * value and return a pointer in *outptr to a newly allocated memory area + * holding it as a null-terminated string. + * + * Returns 0 and nullifies *outptr upon inability to return a string value. + * + * Returns 1 and sets *outptr when returning a dynamically allocated string. + * + * Supported on Windows NT 3.5 and newer. + */ +static ares_bool_t get_REG_SZ(HKEY hKey, const char *leafKeyName, char **outptr) +{ + DWORD size = 0; + int res; + + *outptr = NULL; + + /* Find out size of string stored in registry */ + res = RegQueryValueExA(hKey, leafKeyName, 0, NULL, NULL, &size); + if ((res != ERROR_SUCCESS && res != ERROR_MORE_DATA) || !size) { + return ARES_FALSE; + } + + /* Allocate buffer of indicated size plus one given that string + might have been stored without null termination */ + *outptr = ares_malloc(size + 1); + if (!*outptr) { + return ARES_FALSE; + } + + /* Get the value for real */ + res = RegQueryValueExA(hKey, leafKeyName, 0, NULL, (unsigned char *)*outptr, + &size); + if ((res != ERROR_SUCCESS) || (size == 1)) { + ares_free(*outptr); + *outptr = NULL; + return ARES_FALSE; + } + + /* Null terminate buffer always */ + *(*outptr + size) = '\0'; + + return ARES_TRUE; +} + +static void commanjoin(char **dst, const char * const src, const size_t len) +{ + char *newbuf; + size_t newsize; + + /* 1 for terminating 0 and 2 for , and terminating 0 */ + newsize = len + (*dst ? (ares_strlen(*dst) + 2) : 1); + newbuf = ares_realloc(*dst, newsize); + if (!newbuf) { + return; + } + if (*dst == NULL) { + *newbuf = '\0'; + } + *dst = newbuf; + if (ares_strlen(*dst) != 0) { + strcat(*dst, ","); + } + strncat(*dst, src, len); +} + +/* + * commajoin() + * + * RTF code. + */ +static void commajoin(char **dst, const char *src) +{ + commanjoin(dst, src, ares_strlen(src)); +} + +/* A structure to hold the string form of IPv4 and IPv6 addresses so we can + * sort them by a metric. + */ +typedef struct { + /* The metric we sort them by. */ + ULONG metric; + + /* Original index of the item, used as a secondary sort parameter to make + * qsort() stable if the metrics are equal */ + size_t orig_idx; + + /* Room enough for the string form of any IPv4 or IPv6 address that + * ares_inet_ntop() will create. Based on the existing c-ares practice. + */ + char text[INET6_ADDRSTRLEN + 8 + 64]; /* [%s]:NNNNN%iface */ +} Address; + +/* Sort Address values \a left and \a right by metric, returning the usual + * indicators for qsort(). + */ +static int compareAddresses(const void *arg1, const void *arg2) +{ + const Address * const left = arg1; + const Address * const right = arg2; + /* Lower metric the more preferred */ + if (left->metric < right->metric) { + return -1; + } + if (left->metric > right->metric) { + return 1; + } + /* If metrics are equal, lower original index more preferred */ + if (left->orig_idx < right->orig_idx) { + return -1; + } + if (left->orig_idx > right->orig_idx) { + return 1; + } + return 0; +} + +/* There can be multiple routes to "the Internet". And there can be different + * DNS servers associated with each of the interfaces that offer those routes. + * We have to assume that any DNS server can serve any request. But, some DNS + * servers may only respond if requested over their associated interface. But + * we also want to use "the preferred route to the Internet" whenever possible + * (and not use DNS servers on a non-preferred route even by forcing request + * to go out on the associated non-preferred interface). i.e. We want to use + * the DNS servers associated with the same interface that we would use to + * make a general request to anything else. + * + * But, Windows won't sort the DNS servers by the metrics associated with the + * routes and interfaces _even_ though it obviously sends IP packets based on + * those same routes and metrics. So, we must do it ourselves. + * + * So, we sort the DNS servers by the same metric values used to determine how + * an outgoing IP packet will go, thus effectively using the DNS servers + * associated with the interface that the DNS requests themselves will + * travel. This gives us optimal routing and avoids issues where DNS servers + * won't respond to requests that don't arrive via some specific subnetwork + * (and thus some specific interface). + * + * This function computes the metric we use to sort. On the interface + * identified by \a luid, it determines the best route to \a dest and combines + * that route's metric with \a interfaceMetric to compute a metric for the + * destination address on that interface. This metric can be used as a weight + * to sort the DNS server addresses associated with each interface (lower is + * better). + * + * Note that by restricting the route search to the specific interface with + * which the DNS servers are associated, this function asks the question "What + * is the metric for sending IP packets to this DNS server?" which allows us + * to sort the DNS servers correctly. + */ +static ULONG getBestRouteMetric(IF_LUID * const luid, /* Can't be const :( */ + const SOCKADDR_INET * const dest, + const ULONG interfaceMetric) +{ + /* On this interface, get the best route to that destination. */ +# if defined(__WATCOMC__) + /* OpenWatcom's builtin Windows SDK does not have a definition for + * MIB_IPFORWARD_ROW2, and also does not allow the usage of SOCKADDR_INET + * as a variable. Let's work around this by returning the worst possible + * metric, but only when using the OpenWatcom compiler. + * It may be worth investigating using a different version of the Windows + * SDK with OpenWatcom in the future, though this may be fixed in OpenWatcom + * 2.0. + */ + return (ULONG)-1; +# else + MIB_IPFORWARD_ROW2 row; + SOCKADDR_INET ignored; + if (GetBestRoute2(/* The interface to use. The index is ignored since we are + * passing a LUID. + */ + luid, 0, + /* No specific source address. */ + NULL, + /* Our destination address. */ + dest, + /* No options. */ + 0, + /* The route row. */ + &row, + /* The best source address, which we don't need. */ + &ignored) != NO_ERROR + /* If the metric is "unused" (-1) or too large for us to add the two + * metrics, use the worst possible, thus sorting this last. + */ + || row.Metric == (ULONG)-1 || + row.Metric > ((ULONG)-1) - interfaceMetric) { + /* Return the worst possible metric. */ + return (ULONG)-1; + } + + /* Return the metric value from that row, plus the interface metric. + * + * See + * http://msdn.microsoft.com/en-us/library/windows/desktop/aa814494(v=vs.85).aspx + * which describes the combination as a "sum". + */ + return row.Metric + interfaceMetric; +# endif /* __WATCOMC__ */ +} + +/* + * get_DNS_Windows() + * + * Locates DNS info using GetAdaptersAddresses() function from the Internet + * Protocol Helper (IP Helper) API. When located, this returns a pointer + * in *outptr to a newly allocated memory area holding a null-terminated + * string with a space or comma separated list of DNS IP addresses. + * + * Returns 0 and nullifies *outptr upon inability to return DNSes string. + * + * Returns 1 and sets *outptr when returning a dynamically allocated string. + * + * Implementation supports Windows XP and newer. + */ +# define IPAA_INITIAL_BUF_SZ 15 * 1024 +# define IPAA_MAX_TRIES 3 + +static ares_bool_t get_DNS_Windows(char **outptr) +{ + IP_ADAPTER_DNS_SERVER_ADDRESS *ipaDNSAddr; + IP_ADAPTER_ADDRESSES *ipaa; + IP_ADAPTER_ADDRESSES *newipaa; + IP_ADAPTER_ADDRESSES *ipaaEntry; + ULONG ReqBufsz = IPAA_INITIAL_BUF_SZ; + ULONG Bufsz = IPAA_INITIAL_BUF_SZ; + ULONG AddrFlags = 0; + int trying = IPAA_MAX_TRIES; + ULONG res; + + /* The capacity of addresses, in elements. */ + size_t addressesSize; + /* The number of elements in addresses. */ + size_t addressesIndex = 0; + /* The addresses we will sort. */ + Address *addresses; + + union { + struct sockaddr *sa; + struct sockaddr_in *sa4; + struct sockaddr_in6 *sa6; + } namesrvr; + + *outptr = NULL; + + ipaa = ares_malloc(Bufsz); + if (!ipaa) { + return ARES_FALSE; + } + + /* Start with enough room for a few DNS server addresses and we'll grow it + * as we encounter more. + */ + addressesSize = 4; + addresses = (Address *)ares_malloc(sizeof(Address) * addressesSize); + if (addresses == NULL) { + /* We need room for at least some addresses to function. */ + ares_free(ipaa); + return ARES_FALSE; + } + + /* Usually this call succeeds with initial buffer size */ + res = GetAdaptersAddresses(AF_UNSPEC, AddrFlags, NULL, ipaa, &ReqBufsz); + if ((res != ERROR_BUFFER_OVERFLOW) && (res != ERROR_SUCCESS)) { + goto done; + } + + while ((res == ERROR_BUFFER_OVERFLOW) && (--trying)) { + if (Bufsz < ReqBufsz) { + newipaa = ares_realloc(ipaa, ReqBufsz); + if (!newipaa) { + goto done; + } + Bufsz = ReqBufsz; + ipaa = newipaa; + } + res = GetAdaptersAddresses(AF_UNSPEC, AddrFlags, NULL, ipaa, &ReqBufsz); + if (res == ERROR_SUCCESS) { + break; + } + } + if (res != ERROR_SUCCESS) { + goto done; + } + + for (ipaaEntry = ipaa; ipaaEntry; ipaaEntry = ipaaEntry->Next) { + if (ipaaEntry->OperStatus != IfOperStatusUp) { + continue; + } + + /* For each interface, find any associated DNS servers as IPv4 or IPv6 + * addresses. For each found address, find the best route to that DNS + * server address _on_ _that_ _interface_ (at this moment in time) and + * compute the resulting total metric, just as Windows routing will do. + * Then, sort all the addresses found by the metric. + */ + for (ipaDNSAddr = ipaaEntry->FirstDnsServerAddress; ipaDNSAddr; + ipaDNSAddr = ipaDNSAddr->Next) { + char ipaddr[INET6_ADDRSTRLEN] = ""; + namesrvr.sa = ipaDNSAddr->Address.lpSockaddr; + + if (namesrvr.sa->sa_family == AF_INET) { + if ((namesrvr.sa4->sin_addr.S_un.S_addr == INADDR_ANY) || + (namesrvr.sa4->sin_addr.S_un.S_addr == INADDR_NONE)) { + continue; + } + + /* Allocate room for another address, if necessary, else skip. */ + if (addressesIndex == addressesSize) { + const size_t newSize = addressesSize + 4; + Address * const newMem = + (Address *)ares_realloc(addresses, sizeof(Address) * newSize); + if (newMem == NULL) { + continue; + } + addresses = newMem; + addressesSize = newSize; + } + + addresses[addressesIndex].metric = getBestRouteMetric( + &ipaaEntry->Luid, (SOCKADDR_INET *)((void *)(namesrvr.sa)), + ipaaEntry->Ipv4Metric); + + /* Record insertion index to make qsort stable */ + addresses[addressesIndex].orig_idx = addressesIndex; + + if (!ares_inet_ntop(AF_INET, &namesrvr.sa4->sin_addr, ipaddr, + sizeof(ipaddr))) { + continue; + } + snprintf(addresses[addressesIndex].text, + sizeof(addresses[addressesIndex].text), "[%s]:%u", ipaddr, + ntohs(namesrvr.sa4->sin_port)); + ++addressesIndex; + } else if (namesrvr.sa->sa_family == AF_INET6) { + unsigned int ll_scope = 0; + struct ares_addr addr; + + if (memcmp(&namesrvr.sa6->sin6_addr, &ares_in6addr_any, + sizeof(namesrvr.sa6->sin6_addr)) == 0) { + continue; + } + + /* Allocate room for another address, if necessary, else skip. */ + if (addressesIndex == addressesSize) { + const size_t newSize = addressesSize + 4; + Address * const newMem = + (Address *)ares_realloc(addresses, sizeof(Address) * newSize); + if (newMem == NULL) { + continue; + } + addresses = newMem; + addressesSize = newSize; + } + + /* See if its link-local */ + memset(&addr, 0, sizeof(addr)); + addr.family = AF_INET6; + memcpy(&addr.addr.addr6, &namesrvr.sa6->sin6_addr, 16); + if (ares__addr_is_linklocal(&addr)) { + ll_scope = ipaaEntry->Ipv6IfIndex; + } + + addresses[addressesIndex].metric = getBestRouteMetric( + &ipaaEntry->Luid, (SOCKADDR_INET *)((void *)(namesrvr.sa)), + ipaaEntry->Ipv6Metric); + + /* Record insertion index to make qsort stable */ + addresses[addressesIndex].orig_idx = addressesIndex; + + if (!ares_inet_ntop(AF_INET6, &namesrvr.sa6->sin6_addr, ipaddr, + sizeof(ipaddr))) { + continue; + } + + if (ll_scope) { + snprintf(addresses[addressesIndex].text, + sizeof(addresses[addressesIndex].text), "[%s]:%u%%%u", + ipaddr, ntohs(namesrvr.sa6->sin6_port), ll_scope); + } else { + snprintf(addresses[addressesIndex].text, + sizeof(addresses[addressesIndex].text), "[%s]:%u", ipaddr, + ntohs(namesrvr.sa6->sin6_port)); + } + ++addressesIndex; + } else { + /* Skip non-IPv4/IPv6 addresses completely. */ + continue; + } + } + } + + /* Sort all of the textual addresses by their metric (and original index if + * metrics are equal). */ + qsort(addresses, addressesIndex, sizeof(*addresses), compareAddresses); + + /* Join them all into a single string, removing duplicates. */ + { + size_t i; + for (i = 0; i < addressesIndex; ++i) { + size_t j; + /* Look for this address text appearing previously in the results. */ + for (j = 0; j < i; ++j) { + if (strcmp(addresses[j].text, addresses[i].text) == 0) { + break; + } + } + /* Iff we didn't emit this address already, emit it now. */ + if (j == i) { + /* Add that to outptr (if we can). */ + commajoin(outptr, addresses[i].text); + } + } + } + +done: + ares_free(addresses); + + if (ipaa) { + ares_free(ipaa); + } + + if (!*outptr) { + return ARES_FALSE; + } + + return ARES_TRUE; +} + +/* + * get_SuffixList_Windows() + * + * Reads the "DNS Suffix Search List" from registry and writes the list items + * whitespace separated to outptr. If the Search List is empty, the + * "Primary Dns Suffix" is written to outptr. + * + * Returns 0 and nullifies *outptr upon inability to return the suffix list. + * + * Returns 1 and sets *outptr when returning a dynamically allocated string. + * + * Implementation supports Windows Server 2003 and newer + */ +static ares_bool_t get_SuffixList_Windows(char **outptr) +{ + HKEY hKey; + HKEY hKeyEnum; + char keyName[256]; + DWORD keyNameBuffSize; + DWORD keyIdx = 0; + char *p = NULL; + + *outptr = NULL; + + if (ares__getplatform() != WIN_NT) { + return ARES_FALSE; + } + + /* 1. Global DNS Suffix Search List */ + if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, WIN_NS_NT_KEY, 0, KEY_READ, &hKey) == + ERROR_SUCCESS) { + get_REG_SZ(hKey, SEARCHLIST_KEY, outptr); + if (get_REG_SZ(hKey, DOMAIN_KEY, &p)) { + commajoin(outptr, p); + ares_free(p); + p = NULL; + } + RegCloseKey(hKey); + } + + if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, WIN_NT_DNSCLIENT, 0, KEY_READ, &hKey) == + ERROR_SUCCESS) { + if (get_REG_SZ(hKey, SEARCHLIST_KEY, &p)) { + commajoin(outptr, p); + ares_free(p); + p = NULL; + } + RegCloseKey(hKey); + } + + /* 2. Connection Specific Search List composed of: + * a. Primary DNS Suffix */ + if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, WIN_DNSCLIENT, 0, KEY_READ, &hKey) == + ERROR_SUCCESS) { + if (get_REG_SZ(hKey, PRIMARYDNSSUFFIX_KEY, &p)) { + commajoin(outptr, p); + ares_free(p); + p = NULL; + } + RegCloseKey(hKey); + } + + /* b. Interface SearchList, Domain, DhcpDomain */ + if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, WIN_NS_NT_KEY "\\" INTERFACES_KEY, 0, + KEY_READ, &hKey) == ERROR_SUCCESS) { + for (;;) { + keyNameBuffSize = sizeof(keyName); + if (RegEnumKeyExA(hKey, keyIdx++, keyName, &keyNameBuffSize, 0, NULL, + NULL, NULL) != ERROR_SUCCESS) { + break; + } + if (RegOpenKeyExA(hKey, keyName, 0, KEY_QUERY_VALUE, &hKeyEnum) != + ERROR_SUCCESS) { + continue; + } + /* p can be comma separated (SearchList) */ + if (get_REG_SZ(hKeyEnum, SEARCHLIST_KEY, &p)) { + commajoin(outptr, p); + ares_free(p); + p = NULL; + } + if (get_REG_SZ(hKeyEnum, DOMAIN_KEY, &p)) { + commajoin(outptr, p); + ares_free(p); + p = NULL; + } + if (get_REG_SZ(hKeyEnum, DHCPDOMAIN_KEY, &p)) { + commajoin(outptr, p); + ares_free(p); + p = NULL; + } + RegCloseKey(hKeyEnum); + } + RegCloseKey(hKey); + } + + return *outptr != NULL ? ARES_TRUE : ARES_FALSE; +} + +ares_status_t ares__init_sysconfig_windows(ares_sysconfig_t *sysconfig) +{ + char *line = NULL; + ares_status_t status = ARES_SUCCESS; + + if (get_DNS_Windows(&line)) { + status = ares__sconfig_append_fromstr(&sysconfig->sconfig, line, ARES_TRUE); + ares_free(line); + if (status != ARES_SUCCESS) { + goto done; + } + } + + if (get_SuffixList_Windows(&line)) { + sysconfig->domains = ares__strsplit(line, ", ", &sysconfig->ndomains); + ares_free(line); + if (sysconfig->domains == NULL) { + status = ARES_EFILE; + } + if (status != ARES_SUCCESS) { + goto done; + } + } + +done: + return status; +} +#endif diff --git a/deps/cares/src/lib/ares_timeout.c b/deps/cares/src/lib/ares_timeout.c index 3acc66a87fe28c..dac439b1b43e8c 100644 --- a/deps/cares/src/lib/ares_timeout.c +++ b/deps/cares/src/lib/ares_timeout.c @@ -25,14 +25,12 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" +#include "ares_private.h" #ifdef HAVE_LIMITS_H # include #endif -#include "ares.h" -#include "ares_private.h" void ares__timeval_remaining(ares_timeval_t *remaining, const ares_timeval_t *now, @@ -55,28 +53,38 @@ void ares__timeval_remaining(ares_timeval_t *remaining, } } -static struct timeval ares_timeval_to_struct_timeval(const ares_timeval_t *atv) +void ares__timeval_diff(ares_timeval_t *tvdiff, const ares_timeval_t *tvstart, + const ares_timeval_t *tvstop) { - struct timeval tv; - - tv.tv_sec = (time_t)atv->sec; - tv.tv_usec = (int)atv->usec; - - return tv; + tvdiff->sec = tvstop->sec - tvstart->sec; + if (tvstop->usec > tvstart->usec) { + tvdiff->usec = tvstop->usec - tvstart->usec; + } else { + tvdiff->sec -= 1; + tvdiff->usec = tvstop->usec + 1000000 - tvstart->usec; + } } -static ares_timeval_t struct_timeval_to_ares_timeval(const struct timeval *tv) +static void ares_timeval_to_struct_timeval(struct timeval *tv, const ares_timeval_t *atv) { - ares_timeval_t atv; +#ifdef USE_WINSOCK + tv->tv_sec = (long)atv->sec; +#else + tv->tv_sec = (time_t)atv->sec; +#endif - atv.sec = (ares_int64_t)tv->tv_sec; - atv.usec = (unsigned int)tv->tv_usec; + tv->tv_usec = (int)atv->usec; +} - return atv; +static void struct_timeval_to_ares_timeval(ares_timeval_t *atv, const struct timeval *tv) +{ + atv->sec = (ares_int64_t)tv->tv_sec; + atv->usec = (unsigned int)tv->tv_usec; } -struct timeval *ares_timeout(const ares_channel_t *channel, - struct timeval *maxtv, struct timeval *tvbuf) +static struct timeval *ares_timeout_int(const ares_channel_t *channel, + struct timeval *maxtv, + struct timeval *tvbuf) { const struct query *query; ares__slist_node_t *node; @@ -94,18 +102,18 @@ struct timeval *ares_timeout(const ares_channel_t *channel, query = ares__slist_node_val(node); - now = ares__tvnow(); + ares__tvnow(&now); ares__timeval_remaining(&atvbuf, &now, &query->timeout); - *tvbuf = ares_timeval_to_struct_timeval(&atvbuf); + ares_timeval_to_struct_timeval(tvbuf, &atvbuf); if (maxtv == NULL) { return tvbuf; } /* Return the minimum time between maxtv and tvbuf */ - amaxtv = struct_timeval_to_ares_timeval(maxtv); + struct_timeval_to_ares_timeval(&amaxtv, maxtv); if (atvbuf.sec > amaxtv.sec) { return maxtv; @@ -121,3 +129,20 @@ struct timeval *ares_timeout(const ares_channel_t *channel, return tvbuf; } + +struct timeval *ares_timeout(const ares_channel_t *channel, + struct timeval *maxtv, struct timeval *tvbuf) +{ + struct timeval *rv; + + if (channel == NULL || tvbuf == NULL) + return NULL; + + ares__channel_lock(channel); + + rv = ares_timeout_int(channel, maxtv, tvbuf); + + ares__channel_unlock(channel); + + return rv; +} diff --git a/deps/cares/src/lib/ares_update_servers.c b/deps/cares/src/lib/ares_update_servers.c index 77ed7dd25032eb..455e3001d5cfca 100644 --- a/deps/cares/src/lib/ares_update_servers.c +++ b/deps/cares/src/lib/ares_update_servers.c @@ -25,7 +25,7 @@ * * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" +#include "ares_private.h" #ifdef HAVE_ARPA_INET_H # include @@ -49,10 +49,8 @@ # endif #endif -#include "ares.h" #include "ares_data.h" #include "ares_inet_net_pton.h" -#include "ares_private.h" typedef struct { struct ares_addr addr; @@ -397,7 +395,7 @@ ares_status_t ares__sconfig_append(ares__llist_t **sconfig, *sconfig = ares__llist_create(ares_free); if (*sconfig == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto fail; /* LCOV_EXCL_LINE: OutOfMemory */ + goto fail; /* LCOV_EXCL_LINE: OutOfMemory */ } } @@ -423,7 +421,7 @@ ares_status_t ares__sconfig_append(ares__llist_t **sconfig, if (ares__llist_insert_last(*sconfig, s) == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto fail; /* LCOV_EXCL_LINE: OutOfMemory */ + goto fail; /* LCOV_EXCL_LINE: OutOfMemory */ } return ARES_SUCCESS; @@ -613,24 +611,24 @@ static ares_status_t ares__server_create(ares_channel_t *channel, server->tcp_parser = ares__buf_create(); if (server->tcp_parser == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } server->tcp_send = ares__buf_create(); if (server->tcp_send == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } server->connections = ares__llist_create(NULL); if (server->connections == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } if (ares__slist_insert(channel->servers, server) == NULL) { status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */ - goto done; /* LCOV_EXCL_LINE: OutOfMemory */ + goto done; /* LCOV_EXCL_LINE: OutOfMemory */ } status = ARES_SUCCESS; @@ -711,8 +709,6 @@ ares_status_t ares__servers_update(ares_channel_t *channel, return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */ } - ares__channel_lock(channel); - /* NOTE: a NULL or zero entry server list is considered valid due to * real-world people needing support for this for their test harnesses */ @@ -781,7 +777,6 @@ ares_status_t ares__servers_update(ares_channel_t *channel, status = ARES_SUCCESS; done: - ares__channel_unlock(channel); return status; } @@ -823,7 +818,7 @@ static ares_status_t if (ares__llist_insert_last(s, sconfig) == NULL) { ares_free(sconfig); /* LCOV_EXCL_LINE: OutOfMemory */ - goto fail; /* LCOV_EXCL_LINE: OutOfMemory */ + goto fail; /* LCOV_EXCL_LINE: OutOfMemory */ } } @@ -834,7 +829,7 @@ static ares_status_t fail: ares__llist_destroy(s); return ARES_ENOMEM; -/* LCOV_EXCL_STOP */ + /* LCOV_EXCL_STOP */ } static ares_status_t ares_addr_port_node_to_server_config_llist( @@ -877,7 +872,7 @@ static ares_status_t ares_addr_port_node_to_server_config_llist( if (ares__llist_insert_last(s, sconfig) == NULL) { ares_free(sconfig); /* LCOV_EXCL_LINE: OutOfMemory */ - goto fail; /* LCOV_EXCL_LINE: OutOfMemory */ + goto fail; /* LCOV_EXCL_LINE: OutOfMemory */ } } @@ -888,7 +883,7 @@ static ares_status_t ares_addr_port_node_to_server_config_llist( fail: ares__llist_destroy(s); return ARES_ENOMEM; -/* LCOV_EXCL_STOP */ + /* LCOV_EXCL_STOP */ } ares_status_t ares_in_addr_to_server_config_llist(const struct in_addr *servers, @@ -929,7 +924,7 @@ ares_status_t ares_in_addr_to_server_config_llist(const struct in_addr *servers, fail: ares__llist_destroy(s); return ARES_ENOMEM; -/* LCOV_EXCL_STOP */ + /* LCOV_EXCL_STOP */ } /* Write out the details of a server to a buffer */ @@ -1115,8 +1110,9 @@ int ares_set_servers(ares_channel_t *channel, return (int)status; } - /* NOTE: lock is in ares__servers_update() */ + ares__channel_lock(channel); status = ares__servers_update(channel, slist, ARES_TRUE); + ares__channel_unlock(channel); ares__llist_destroy(slist); @@ -1138,8 +1134,9 @@ int ares_set_servers_ports(ares_channel_t *channel, return (int)status; } - /* NOTE: lock is in ares__servers_update() */ + ares__channel_lock(channel); status = ares__servers_update(channel, slist, ARES_TRUE); + ares__channel_unlock(channel); ares__llist_destroy(slist); @@ -1157,11 +1154,12 @@ static ares_status_t set_servers_csv(ares_channel_t *channel, const char *_csv) return ARES_ENODATA; } - /* NOTE: lock is in ares__servers_update() */ - if (ares_strlen(_csv) == 0) { /* blank all servers */ - return ares__servers_update(channel, NULL, ARES_TRUE); + ares__channel_lock(channel); + status = ares__servers_update(channel, NULL, ARES_TRUE); + ares__channel_unlock(channel); + return status; } status = ares__sconfig_append_fromstr(&slist, _csv, ARES_FALSE); @@ -1170,8 +1168,9 @@ static ares_status_t set_servers_csv(ares_channel_t *channel, const char *_csv) return status; } - /* NOTE: lock is in ares__servers_update() */ + ares__channel_lock(channel); status = ares__servers_update(channel, slist, ARES_TRUE); + ares__channel_unlock(channel); ares__llist_destroy(slist); @@ -1181,13 +1180,11 @@ static ares_status_t set_servers_csv(ares_channel_t *channel, const char *_csv) /* We'll go ahead and honor ports anyhow */ int ares_set_servers_csv(ares_channel_t *channel, const char *_csv) { - /* NOTE: lock is in ares__servers_update() */ return (int)set_servers_csv(channel, _csv); } int ares_set_servers_ports_csv(ares_channel_t *channel, const char *_csv) { - /* NOTE: lock is in ares__servers_update() */ return (int)set_servers_csv(channel, _csv); } diff --git a/deps/cares/src/lib/ares_version.c b/deps/cares/src/lib/ares_version.c index ca15fa77dcfbe6..f50f65b0d61389 100644 --- a/deps/cares/src/lib/ares_version.c +++ b/deps/cares/src/lib/ares_version.c @@ -24,8 +24,7 @@ * * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" -#include "ares.h" +#include "ares_private.h" const char *ares_version(int *version) { diff --git a/deps/cares/src/lib/config-dos.h b/deps/cares/src/lib/config-dos.h index 6d99bd681c4621..db758fcca6619a 100644 --- a/deps/cares/src/lib/config-dos.h +++ b/deps/cares/src/lib/config-dos.h @@ -32,14 +32,13 @@ #define HAVE_TIME_H 1 #define HAVE_UNISTD_H 1 #define HAVE_WRITEV 1 - -#define NEED_MALLOC_H 1 +#define HAVE_STAT 1 +#define HAVE_MALLOC_H 1 /* Qualifiers for send(), recv(), recvfrom() and getnameinfo(). */ #define SEND_TYPE_ARG1 int -#define SEND_QUAL_ARG2 const -#define SEND_TYPE_ARG2 void * +#define SEND_TYPE_ARG2 const void * #define SEND_TYPE_ARG3 int #define SEND_TYPE_ARG4 int #define SEND_TYPE_RETV int @@ -73,7 +72,7 @@ # define HAVE_VARIADIC_MACROS_GCC 1 /* Because djgpp <= 2.03 doesn't have snprintf() etc. */ -# if (DJGPP_MINOR < 4) +# if defined(DJGPP_MINOR) && DJGPP_MINOR < 4 # define _MPRINTF_REPLACE # endif @@ -85,30 +84,30 @@ # define strerror(e) strerror_s_((e)) #endif +/* This seems odd, can DOS build without WATT32? */ #ifdef WATT32 -# define HAVE_AF_INET6 1 -# define HAVE_ARPA_INET_H 1 -# define HAVE_ARPA_NAMESER_H 1 -# define HAVE_CLOSE_S 1 -# define HAVE_GETHOSTNAME 1 -# define HAVE_NETDB_H 1 -# define HAVE_NETINET_IN_H 1 -# define HAVE_NETINET_TCP_H 1 -# define HAVE_PF_INET6 1 -# define HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID 1 -# define HAVE_STRUCT_ADDRINFO 1 -# define HAVE_STRUCT_IN6_ADDR 1 -# define HAVE_STRUCT_SOCKADDR_IN6 1 -# define HAVE_SYS_SOCKET_H 1 -# define HAVE_SYS_UIO_H 1 -# define NS_INADDRSZ 4 -# define HAVE_STRUCT_SOCKADDR_IN6 1 - -# define HAVE_GETSERVBYPORT_R 1 -# define GETSERVBYPORT_R_ARGS 5 +# define HAVE_AF_INET6 1 +# define HAVE_ARPA_INET_H 1 +# define HAVE_ARPA_NAMESER_H 1 +# define HAVE_CLOSE_S 1 +# define HAVE_GETHOSTNAME 1 +# define HAVE_NETDB_H 1 +# define HAVE_NETINET_IN_H 1 +# define HAVE_NETINET_TCP_H 1 +# define HAVE_PF_INET6 1 +# define HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID 1 +# define HAVE_STRUCT_ADDRINFO 1 +# define HAVE_STRUCT_IN6_ADDR 1 +# define HAVE_STRUCT_SOCKADDR_IN6 1 +# define HAVE_SYS_SOCKET_H 1 +# define HAVE_SYS_IOCTL_H 1 +# define HAVE_SYS_UIO_H 1 +# define NS_INADDRSZ 4 +# define HAVE_GETSERVBYPORT_R 1 +# define GETSERVBYPORT_R_ARGS 6 +# define HAVE_WRITEV 1 +# define HAVE_IF_NAMETOINDEX 1 +# define HAVE_IF_INDEXTONAME 1 #endif -#undef word -#undef byte - #endif /* HEADER_CONFIG_DOS_H */ diff --git a/deps/cares/src/lib/config-win32.h b/deps/cares/src/lib/config-win32.h index a55cf9e2dbbe3f..da5c7483879023 100644 --- a/deps/cares/src/lib/config-win32.h +++ b/deps/cares/src/lib/config-win32.h @@ -190,11 +190,8 @@ /* Define to the type of arg 1 for send. */ #define SEND_TYPE_ARG1 SOCKET -/* Define to the type qualifier of arg 2 for send. */ -#define SEND_QUAL_ARG2 const - /* Define to the type of arg 2 for send. */ -#define SEND_TYPE_ARG2 char * +#define SEND_TYPE_ARG2 const char * /* Define to the type of arg 3 for send. */ #define SEND_TYPE_ARG3 int @@ -212,19 +209,24 @@ # undef SEND_TYPE_ARG1 # define SEND_TYPE_ARG1 int # undef RECVFROM_TYPE_ARG1 -# define RECVFROM_TYPE_ARG1 int +# define RECVFROM_TYPE_ARG1 int # define NS_INADDRSZ 4 # define HAVE_ARPA_NAMESER_H 1 # define HAVE_ARPA_INET_H 1 # define HAVE_NETDB_H 1 # define HAVE_NETINET_IN_H 1 # define HAVE_SYS_SOCKET_H 1 +# define HAVE_SYS_IOCTL_H 1 # define HAVE_NETINET_TCP_H 1 # define HAVE_AF_INET6 1 # define HAVE_PF_INET6 1 # define HAVE_STRUCT_IN6_ADDR 1 # define HAVE_STRUCT_SOCKADDR_IN6 1 # define HAVE_WRITEV 1 +# define HAVE_IF_NAMETOINDEX 1 +# define HAVE_IF_INDEXTONAME 1 +# define HAVE_GETSERVBYPORT_R 1 +# define GETSERVBYPORT_R_ARGS 6 # undef HAVE_WINSOCK_H # undef HAVE_WINSOCK2_H # undef HAVE_WS2TCPIP_H @@ -351,7 +353,7 @@ #endif #if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600) && \ - !defined(__WATCOMC__) && !defined(WATT32) + !defined(__WATCOMC__) && !defined(WATT32) /* Define if you have if_nametoindex() */ # define HAVE_IF_NAMETOINDEX 1 /* Define if you have if_indextoname() */ diff --git a/deps/cares/src/lib/inet_net_pton.c b/deps/cares/src/lib/inet_net_pton.c index 19429f205d86ab..935058da9ce091 100644 --- a/deps/cares/src/lib/inet_net_pton.c +++ b/deps/cares/src/lib/inet_net_pton.c @@ -18,7 +18,7 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" +#include "ares_private.h" #ifdef HAVE_NETINET_IN_H # include @@ -29,11 +29,13 @@ #include "ares_nameser.h" -#include "ares.h" #include "ares_ipv6.h" #include "ares_inet_net_pton.h" -#include "ares_private.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 } } }; @@ -82,7 +84,7 @@ static int ares_inet_net_pton_ipv4(const char *src, unsigned char *dst, src++; /* skip x or X. */ while ((ch = *src++) != '\0' && ISASCII(ch) && ISXDIGIT(ch)) { if (ISUPPER(ch)) { - ch = tolower(ch); + ch = ares__tolower((unsigned char)ch); } n = (int)(strchr(xdigits, ch) - xdigits); if (dirty == 0) { diff --git a/deps/cares/src/lib/inet_ntop.c b/deps/cares/src/lib/inet_ntop.c index 622befa99582e2..8dee8d69da7d71 100644 --- a/deps/cares/src/lib/inet_ntop.c +++ b/deps/cares/src/lib/inet_ntop.c @@ -17,7 +17,7 @@ * SPDX-License-Identifier: MIT */ -#include "ares_setup.h" +#include "ares_private.h" #ifdef HAVE_NETINET_IN_H # include @@ -27,12 +27,7 @@ #endif #include "ares_nameser.h" - -#include "ares.h" #include "ares_ipv6.h" -#include "ares_private.h" - -#ifndef HAVE_INET_NTOP /* * WARNING: Don't even consider trying to compile this on a system where @@ -60,14 +55,14 @@ const char *ares_inet_ntop(int af, const void *src, char *dst, { switch (af) { case AF_INET: - return (inet_ntop4(src, dst, (size_t)size)); + return inet_ntop4(src, dst, (size_t)size); case AF_INET6: - return (inet_ntop6(src, dst, (size_t)size)); + return inet_ntop6(src, dst, (size_t)size); default: - SET_ERRNO(EAFNOSUPPORT); - return (NULL); + break; } - /* NOTREACHED */ + SET_ERRNO(EAFNOSUPPORT); + return NULL; } /* const char * @@ -86,13 +81,18 @@ static const char *inet_ntop4(const unsigned char *src, char *dst, size_t size) static const char fmt[] = "%u.%u.%u.%u"; char tmp[sizeof("255.255.255.255")]; + if (size < sizeof(tmp)) { + SET_ERRNO(ENOSPC); + return NULL; + } + if ((size_t)snprintf(tmp, sizeof(tmp), fmt, src[0], src[1], src[2], src[3]) >= size) { SET_ERRNO(ENOSPC); - return (NULL); + return NULL; } ares_strcpy(dst, tmp, size); - return (dst); + return dst; } /* const char * @@ -114,11 +114,12 @@ static const char *inet_ntop6(const unsigned char *src, char *dst, size_t size) char *tp; struct { - int base, len; + ares_ssize_t base; + size_t len; } best, cur; unsigned int words[NS_IN6ADDRSZ / NS_INT16SZ]; - int i; + size_t i; /* * Preprocess: @@ -136,7 +137,8 @@ static const char *inet_ntop6(const unsigned char *src, char *dst, size_t size) for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) { if (words[i] == 0) { if (cur.base == -1) { - cur.base = i, cur.len = 1; + cur.base = (ares_ssize_t)i; + cur.len = 1; } else { cur.len++; } @@ -164,8 +166,8 @@ static const char *inet_ntop6(const unsigned char *src, char *dst, size_t size) tp = tmp; for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) { /* Are we inside the best run of 0x00's? */ - if (best.base != -1 && i >= best.base && i < (best.base + best.len)) { - if (i == best.base) { + if (best.base != -1 && i >= (size_t)best.base && i < ((size_t)best.base + best.len)) { + if (i == (size_t)best.base) { *tp++ = ':'; } continue; @@ -188,7 +190,7 @@ static const char *inet_ntop6(const unsigned char *src, char *dst, size_t size) } /* Was it a trailing run of 0x00's? */ if (best.base != -1 && - (best.base + best.len) == (NS_IN6ADDRSZ / NS_INT16SZ)) { + ((size_t)best.base + best.len) == (NS_IN6ADDRSZ / NS_INT16SZ)) { *tp++ = ':'; } *tp++ = '\0'; @@ -198,19 +200,9 @@ static const char *inet_ntop6(const unsigned char *src, char *dst, size_t size) */ if ((size_t)(tp - tmp) > size) { SET_ERRNO(ENOSPC); - return (NULL); + return NULL; } ares_strcpy(dst, tmp, size); - return (dst); -} - -#else /* HAVE_INET_NTOP */ - -const char *ares_inet_ntop(int af, const void *src, char *dst, - ares_socklen_t size) -{ - /* just relay this to the underlying function */ - return inet_ntop(af, src, dst, size); + return dst; } -#endif /* HAVE_INET_NTOP */ diff --git a/deps/cares/src/lib/setup_once.h b/deps/cares/src/lib/setup_once.h deleted file mode 100644 index 649d6ac4d61523..00000000000000 --- a/deps/cares/src/lib/setup_once.h +++ /dev/null @@ -1,464 +0,0 @@ -/* MIT License - * - * Copyright (c) 2004 Daniel Stenberg - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * SPDX-License-Identifier: MIT - */ -#ifndef __SETUP_ONCE_H -#define __SETUP_ONCE_H - - -/******************************************************************** - * NOTICE * - * ======== * - * * - * Content of header files lib/setup_once.h and ares/setup_once.h * - * must be kept in sync. Modify the other one if you change this. * - * * - ********************************************************************/ - - -/* - * Inclusion of common header files. - */ - -#include -#include -#include -#include -#include - -#ifdef HAVE_ERRNO_H -# include -#endif - -#ifdef HAVE_SYS_TYPES_H -# include -#endif - -#ifdef NEED_MALLOC_H -# include -#endif - -#ifdef NEED_MEMORY_H -# include -#endif - -#ifdef HAVE_SYS_STAT_H -# include -#endif - -#ifdef HAVE_SYS_TIME_H -# include -#endif - -#ifdef HAVE_TIME_H -# include -#endif - -#ifdef HAVE_UNISTD_H -# include -#endif - -#ifdef __hpux -# if !defined(_XOPEN_SOURCE_EXTENDED) || defined(_KERNEL) -# ifdef _APP32_64BIT_OFF_T -# define OLD_APP32_64BIT_OFF_T _APP32_64BIT_OFF_T -# undef _APP32_64BIT_OFF_T -# else -# undef OLD_APP32_64BIT_OFF_T -# endif -# endif -#endif - -#ifdef HAVE_SYS_SOCKET_H -# include -#endif - -#ifdef __hpux -# if !defined(_XOPEN_SOURCE_EXTENDED) || defined(_KERNEL) -# ifdef OLD_APP32_64BIT_OFF_T -# define _APP32_64BIT_OFF_T OLD_APP32_64BIT_OFF_T -# undef OLD_APP32_64BIT_OFF_T -# endif -# endif -#endif - - -/* - * Definition of timeval struct for platforms that don't have it. - */ - -#ifndef HAVE_STRUCT_TIMEVAL -struct timeval { - long tv_sec; - long tv_usec; -}; -#endif - - -/* - * If we have the MSG_NOSIGNAL define, make sure we use - * it as the fourth argument of function send() - */ - -#ifdef HAVE_MSG_NOSIGNAL -# define SEND_4TH_ARG MSG_NOSIGNAL -#else -# define SEND_4TH_ARG 0 -#endif - - -#if defined(__minix) -/* Minix doesn't support recv on TCP sockets */ -# define sread(x, y, z) \ - (ares_ssize_t) \ - read((RECV_TYPE_ARG1)(x), (RECV_TYPE_ARG2)(y), (RECV_TYPE_ARG3)(z)) - -#elif defined(HAVE_RECV) -/* - * The definitions for the return type and arguments types - * of functions recv() and send() belong and come from the - * configuration file. Do not define them in any other place. - * - * HAVE_RECV is defined if you have a function named recv() - * which is used to read incoming data from sockets. If your - * function has another name then don't define HAVE_RECV. - * - * If HAVE_RECV is defined then RECV_TYPE_ARG1, RECV_TYPE_ARG2, - * RECV_TYPE_ARG3, RECV_TYPE_ARG4 and RECV_TYPE_RETV must also - * be defined. - * - * HAVE_SEND is defined if you have a function named send() - * which is used to write outgoing data on a connected socket. - * If yours has another name then don't define HAVE_SEND. - * - * If HAVE_SEND is defined then SEND_TYPE_ARG1, SEND_QUAL_ARG2, - * SEND_TYPE_ARG2, SEND_TYPE_ARG3, SEND_TYPE_ARG4 and - * SEND_TYPE_RETV must also be defined. - */ - -# if !defined(RECV_TYPE_ARG1) || !defined(RECV_TYPE_ARG2) || \ - !defined(RECV_TYPE_ARG3) || !defined(RECV_TYPE_ARG4) || \ - !defined(RECV_TYPE_RETV) -/* */ -Error Missing_definition_of_return_and_arguments_types_of_recv -/* */ -# else -# define sread(x, y, z) \ - (ares_ssize_t) recv((RECV_TYPE_ARG1)(x), (RECV_TYPE_ARG2)(y), \ - (RECV_TYPE_ARG3)(z), (RECV_TYPE_ARG4)(0)) -# endif -#else /* HAVE_RECV */ -# ifndef sread -/* */ -Error Missing_definition_of_macro_sread -/* */ -# endif -#endif /* HAVE_RECV */ - - -#if defined(__minix) -/* Minix doesn't support send on TCP sockets */ -# define swrite(x, y, z) \ - (ares_ssize_t) \ - write((SEND_TYPE_ARG1)(x), (SEND_TYPE_ARG2)(y), (SEND_TYPE_ARG3)(z)) - -#elif defined(HAVE_SEND) -# if !defined(SEND_TYPE_ARG1) || !defined(SEND_QUAL_ARG2) || \ - !defined(SEND_TYPE_ARG2) || !defined(SEND_TYPE_ARG3) || \ - !defined(SEND_TYPE_ARG4) || !defined(SEND_TYPE_RETV) - /* */ - Error Missing_definition_of_return_and_arguments_types_of_send -/* */ -# else -# define swrite(x, y, z) \ - (ares_ssize_t) send((SEND_TYPE_ARG1)(x), (SEND_TYPE_ARG2)(y), \ - (SEND_TYPE_ARG3)(z), (SEND_TYPE_ARG4)(SEND_4TH_ARG)) -# endif -#else /* HAVE_SEND */ -# ifndef swrite - /* */ - Error Missing_definition_of_macro_swrite -/* */ -# endif -#endif /* HAVE_SEND */ - - -#if 0 -# if defined(HAVE_RECVFROM) -/* - * Currently recvfrom is only used on udp sockets. - */ -# if !defined(RECVFROM_TYPE_ARG1) || !defined(RECVFROM_TYPE_ARG2) || \ - !defined(RECVFROM_TYPE_ARG3) || !defined(RECVFROM_TYPE_ARG4) || \ - !defined(RECVFROM_TYPE_ARG5) || !defined(RECVFROM_TYPE_ARG6) || \ - !defined(RECVFROM_TYPE_RETV) - /* */ - Error Missing_definition_of_return_and_arguments_types_of_recvfrom - /* */ -# else -# define sreadfrom(s, b, bl, f, fl) \ - (ares_ssize_t) \ - recvfrom((RECVFROM_TYPE_ARG1)(s), (RECVFROM_TYPE_ARG2 *)(b), \ - (RECVFROM_TYPE_ARG3)(bl), (RECVFROM_TYPE_ARG4)(0), \ - (RECVFROM_TYPE_ARG5 *)(f), (RECVFROM_TYPE_ARG6 *)(fl)) -# endif -# else /* HAVE_RECVFROM */ -# ifndef sreadfrom - /* */ - Error Missing_definition_of_macro_sreadfrom - /* */ -# endif -# endif /* HAVE_RECVFROM */ - - -# ifdef RECVFROM_TYPE_ARG6_IS_VOID -# define RECVFROM_ARG6_T int -# else -# define RECVFROM_ARG6_T RECVFROM_TYPE_ARG6 -# endif -#endif /* if 0 */ - - -/* - * Function-like macro definition used to close a socket. - */ - -#if defined(HAVE_CLOSESOCKET) -# define sclose(x) closesocket((x)) -#elif defined(HAVE_CLOSESOCKET_CAMEL) -# define sclose(x) CloseSocket((x)) -#elif defined(HAVE_CLOSE_S) -# define sclose(x) close_s((x)) -#else -# define sclose(x) close((x)) -#endif - - -/* - * Uppercase macro versions of ANSI/ISO is*() functions/macros which - * avoid negative number inputs with argument byte codes > 127. - */ - -#define ISSPACE(x) (isspace((int)((unsigned char)x))) -#define ISDIGIT(x) (isdigit((int)((unsigned char)x))) -#define ISALNUM(x) (isalnum((int)((unsigned char)x))) -#define ISXDIGIT(x) (isxdigit((int)((unsigned char)x))) -#define ISGRAPH(x) (isgraph((int)((unsigned char)x))) -#define ISALPHA(x) (isalpha((int)((unsigned char)x))) -#define ISPRINT(x) (isprint((int)((unsigned char)x))) -#define ISUPPER(x) (isupper((int)((unsigned char)x))) -#define ISLOWER(x) (islower((int)((unsigned char)x))) -#define ISASCII(x) (((unsigned char)x) <= 127 ? 1 : 0) - -#define ISBLANK(x) \ - (int)((((unsigned char)x) == ' ') || (((unsigned char)x) == '\t')) - -#define TOLOWER(x) (tolower((int)((unsigned char)x))) - - -/* - * Macro WHILE_FALSE may be used to build single-iteration do-while loops, - * avoiding compiler warnings. Mostly intended for other macro definitions. - */ - -#define WHILE_FALSE while (0) - -#if defined(_MSC_VER) && !defined(__POCC__) -# undef WHILE_FALSE -# if (_MSC_VER < 1500) -# define WHILE_FALSE while (1, 0) -# else -# define WHILE_FALSE \ - __pragma(warning(push)) __pragma(warning(disable : 4127)) while (0) \ - __pragma(warning(pop)) -# endif -#endif - - -/* - * Macro used to include code only in debug builds. - */ - -#ifdef DEBUGBUILD -# define DEBUGF(x) x -#else -# define DEBUGF(x) \ - do { \ - } \ - WHILE_FALSE -#endif - - -/* - * Macro used to include assertion code only in debug builds. - */ - -#if defined(DEBUGBUILD) && defined(HAVE_ASSERT_H) -# define DEBUGASSERT(x) assert(x) -#else -# define DEBUGASSERT(x) \ - do { \ - } \ - WHILE_FALSE -#endif - - -/* - * Macro SOCKERRNO / SET_SOCKERRNO() returns / sets the *socket-related* errno - * (or equivalent) on this platform to hide platform details to code using it. - */ - -#ifdef USE_WINSOCK -# define SOCKERRNO ((int)WSAGetLastError()) -# define SET_SOCKERRNO(x) (WSASetLastError((int)(x))) -#else -# define SOCKERRNO (errno) -# define SET_SOCKERRNO(x) (errno = (x)) -#endif - - -/* - * Macro ERRNO / SET_ERRNO() returns / sets the NOT *socket-related* errno - * (or equivalent) on this platform to hide platform details to code using it. - */ - -#if defined(WIN32) && !defined(WATT32) -# define ERRNO ((int)GetLastError()) -# define SET_ERRNO(x) (SetLastError((DWORD)(x))) -#else -# define ERRNO (errno) -# define SET_ERRNO(x) (errno = (x)) -#endif - - -/* - * Portable error number symbolic names defined to Winsock error codes. - */ - -#ifdef USE_WINSOCK -# undef EBADF /* override definition in errno.h */ -# define EBADF WSAEBADF -# undef EINTR /* override definition in errno.h */ -# define EINTR WSAEINTR -# undef EINVAL /* override definition in errno.h */ -# define EINVAL WSAEINVAL -# undef EWOULDBLOCK /* override definition in errno.h */ -# define EWOULDBLOCK WSAEWOULDBLOCK -# undef EINPROGRESS /* override definition in errno.h */ -# define EINPROGRESS WSAEINPROGRESS -# undef EALREADY /* override definition in errno.h */ -# define EALREADY WSAEALREADY -# undef ENOTSOCK /* override definition in errno.h */ -# define ENOTSOCK WSAENOTSOCK -# undef EDESTADDRREQ /* override definition in errno.h */ -# define EDESTADDRREQ WSAEDESTADDRREQ -# undef EMSGSIZE /* override definition in errno.h */ -# define EMSGSIZE WSAEMSGSIZE -# undef EPROTOTYPE /* override definition in errno.h */ -# define EPROTOTYPE WSAEPROTOTYPE -# undef ENOPROTOOPT /* override definition in errno.h */ -# define ENOPROTOOPT WSAENOPROTOOPT -# undef EPROTONOSUPPORT /* override definition in errno.h */ -# define EPROTONOSUPPORT WSAEPROTONOSUPPORT -# define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT -# undef EOPNOTSUPP /* override definition in errno.h */ -# define EOPNOTSUPP WSAEOPNOTSUPP -# define EPFNOSUPPORT WSAEPFNOSUPPORT -# undef EAFNOSUPPORT /* override definition in errno.h */ -# define EAFNOSUPPORT WSAEAFNOSUPPORT -# undef EADDRINUSE /* override definition in errno.h */ -# define EADDRINUSE WSAEADDRINUSE -# undef EADDRNOTAVAIL /* override definition in errno.h */ -# define EADDRNOTAVAIL WSAEADDRNOTAVAIL -# undef ENETDOWN /* override definition in errno.h */ -# define ENETDOWN WSAENETDOWN -# undef ENETUNREACH /* override definition in errno.h */ -# define ENETUNREACH WSAENETUNREACH -# undef ENETRESET /* override definition in errno.h */ -# define ENETRESET WSAENETRESET -# undef ECONNABORTED /* override definition in errno.h */ -# define ECONNABORTED WSAECONNABORTED -# undef ECONNRESET /* override definition in errno.h */ -# define ECONNRESET WSAECONNRESET -# undef ENOBUFS /* override definition in errno.h */ -# define ENOBUFS WSAENOBUFS -# undef EISCONN /* override definition in errno.h */ -# define EISCONN WSAEISCONN -# undef ENOTCONN /* override definition in errno.h */ -# define ENOTCONN WSAENOTCONN -# define ESHUTDOWN WSAESHUTDOWN -# define ETOOMANYREFS WSAETOOMANYREFS -# undef ETIMEDOUT /* override definition in errno.h */ -# define ETIMEDOUT WSAETIMEDOUT -# undef ECONNREFUSED /* override definition in errno.h */ -# define ECONNREFUSED WSAECONNREFUSED -# undef ELOOP /* override definition in errno.h */ -# define ELOOP WSAELOOP -# ifndef ENAMETOOLONG /* possible previous definition in errno.h */ -# define ENAMETOOLONG WSAENAMETOOLONG -# endif -# define EHOSTDOWN WSAEHOSTDOWN -# undef EHOSTUNREACH /* override definition in errno.h */ -# define EHOSTUNREACH WSAEHOSTUNREACH -# ifndef ENOTEMPTY /* possible previous definition in errno.h */ -# define ENOTEMPTY WSAENOTEMPTY -# endif -# define EPROCLIM WSAEPROCLIM -# define EUSERS WSAEUSERS -# define EDQUOT WSAEDQUOT -# define ESTALE WSAESTALE -# define EREMOTE WSAEREMOTE -#endif - - -/* - * Actually use __32_getpwuid() on 64-bit VMS builds for getpwuid() - */ - -#if defined(__VMS) && defined(__INITIAL_POINTER_SIZE) && \ - (__INITIAL_POINTER_SIZE == 64) -# define getpwuid __32_getpwuid -#endif - - -/* - * Macro argv_item_t hides platform details to code using it. - */ - -#ifdef __VMS -# define argv_item_t __char_ptr32 -#else -# define argv_item_t char * -#endif - - -/* - * We use this ZERO_NULL to avoid picky compiler warnings, - * when assigning a NULL pointer to a function pointer var. - */ - -#define ZERO_NULL 0 - - -#endif /* __SETUP_ONCE_H */ diff --git a/deps/cares/src/lib/windows_port.c b/deps/cares/src/lib/windows_port.c index 5395f203601e09..22f0dc020a0730 100644 --- a/deps/cares/src/lib/windows_port.c +++ b/deps/cares/src/lib/windows_port.c @@ -6,7 +6,7 @@ * SPDX-License-Identifier: MIT * */ -#include "ares_setup.h" +#include "ares_private.h" /* only do the following on windows diff --git a/deps/cares/src/tools/adig.c b/deps/cares/src/tools/adig.c index e0d5c915aa5e7c..026340c72bfccf 100644 --- a/deps/cares/src/tools/adig.c +++ b/deps/cares/src/tools/adig.c @@ -84,7 +84,9 @@ static const nv_t configflags[] = { { "igntc", ARES_FLAG_IGNTC }, { "norecurse", ARES_FLAG_NORECURSE }, { "stayopen", ARES_FLAG_STAYOPEN }, - { "noaliases", ARES_FLAG_NOALIASES } + { "noaliases", ARES_FLAG_NOALIASES }, + { "edns", ARES_FLAG_EDNS }, + { "dns0x20", ARES_FLAG_DNS0x20 } }; static const size_t nconfigflags = sizeof(configflags) / sizeof(*configflags); @@ -113,35 +115,48 @@ static void free_config(adig_config_t *config) static void print_help(void) { + /* Split due to maximum c89 string literal of 509 bytes */ printf("adig version %s\n\n", ares_version(NULL)); printf( "usage: adig [-h] [-d] [-f flag] [[-s server] ...] [-T|U port] [-c class]\n" - " [-t type] name ...\n\n" - " -h : Display this help and exit.\n" - " -d : Print some extra debugging output.\n" - " -f flag : Add a behavior control flag. Possible values are\n" + " [-t type] name ...\n\n"); + printf( + " -h : Display this help and exit.\n"); + printf( + " -d : Print some extra debugging output.\n"); + printf( + " -f flag : Add a behavior control flag. May be specified more than once\n" + " to add additional flags. Possible values are:\n" " igntc - do not retry a truncated query as TCP, just\n" " return the truncated answer\n" " noaliases - don't honor the HOSTALIASES environment\n" - " variable\n" + " variable\n"); + printf( " norecurse - don't query upstream servers recursively\n" " primary - use the first server\n" " stayopen - don't close the communication sockets\n" " usevc - use TCP only\n" + " edns - use EDNS\n" + " dns0x20 - enable DNS 0x20 support\n"); + printf( " -s server : Connect to the specified DNS server, instead of the\n" " system's default one(s). Servers are tried in round-robin,\n" - " if the previous one failed.\n" - " -T port : Connect to the specified TCP port of DNS server.\n" - " -U port : Connect to the specified UDP port of DNS server.\n" + " if the previous one failed.\n"); + printf( + " -T port : Connect to the specified TCP port of DNS server.\n"); + printf( + " -U port : Connect to the specified UDP port of DNS server.\n"); + printf( " -c class : Set the query class. Possible values for class are:\n" - " ANY, CHAOS, HS and IN (default)\n" + " ANY, CHAOS, HS and IN (default)\n"); + printf( " -t type : Query records of the specified type. Possible values for\n" " type are:\n" " A (default), AAAA, ANY, CNAME, HINFO, MX, NAPTR, NS, PTR,\n" " SOA, SRV, TXT, TLSA, URI, CAA, SVCB, HTTPS\n\n"); } -static ares_bool_t read_cmdline(int argc, const char **argv, +static ares_bool_t read_cmdline(int argc, const char * const * argv, adig_config_t *config) { ares_getopt_state_t state; @@ -613,6 +628,21 @@ static void print_binp(const ares_dns_rr_t *rr, ares_dns_rr_key_t key) print_opt_binp(binp, len); } +static void print_abinp(const ares_dns_rr_t *rr, ares_dns_rr_key_t key) +{ + size_t i; + size_t cnt = ares_dns_rr_get_abin_cnt(rr, key); + + for (i=0; iopterr = 1; diff --git a/deps/cares/src/tools/ares_getopt.h b/deps/cares/src/tools/ares_getopt.h index a14f7ab42d41f7..7ff1fdeeb282f2 100644 --- a/deps/cares/src/tools/ares_getopt.h +++ b/deps/cares/src/tools/ares_getopt.h @@ -40,10 +40,10 @@ typedef struct { int optopt; /* character checked for validity */ const char *place; int argc; - const char **argv; + const char * const *argv; } ares_getopt_state_t; -void ares_getopt_init(ares_getopt_state_t *state, int argc, const char **argv); +void ares_getopt_init(ares_getopt_state_t *state, int argc, const char * const * argv); int ares_getopt(ares_getopt_state_t *state, const char *ostr); #endif /* ARES_GETOPT_H */