aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorthegeorg <thegeorg@yandex-team.com>2023-10-23 12:13:05 +0300
committerthegeorg <thegeorg@yandex-team.com>2023-10-23 12:56:00 +0300
commita93ff99ad5b0c8afb235dae7f963c4f6c46706f7 (patch)
treee86d91799d9e001f33f6fe1d2f3371badcbad32e
parentc39e23f5aa5458cfea943752a5525f2dbd887583 (diff)
downloadydb-a93ff99ad5b0c8afb235dae7f963c4f6c46706f7.tar.gz
Update contrib/libs/c-ares to 1.20.1
-rw-r--r--build/conf/license.conf1
-rw-r--r--contrib/libs/c-ares/CMakeLists.darwin-x86_64.txt8
-rw-r--r--contrib/libs/c-ares/CMakeLists.linux-aarch64.txt8
-rw-r--r--contrib/libs/c-ares/CMakeLists.linux-x86_64.txt8
-rw-r--r--contrib/libs/c-ares/CMakeLists.windows-x86_64.txt8
-rw-r--r--contrib/libs/c-ares/INSTALL.md25
-rw-r--r--contrib/libs/c-ares/LICENSE.md32
-rw-r--r--contrib/libs/c-ares/README.md4
-rw-r--r--contrib/libs/c-ares/README.msvc2
-rw-r--r--contrib/libs/c-ares/RELEASE-NOTES103
-rw-r--r--contrib/libs/c-ares/RELEASE-PROCEDURE.md5
-rw-r--r--contrib/libs/c-ares/include/ares.h82
-rw-r--r--contrib/libs/c-ares/include/ares_build-ios.h52
-rw-r--r--contrib/libs/c-ares/include/ares_build-linux.h9
-rw-r--r--contrib/libs/c-ares/include/ares_build.h4
-rw-r--r--contrib/libs/c-ares/include/ares_dns.h41
-rw-r--r--contrib/libs/c-ares/include/ares_nameser.h26
-rw-r--r--contrib/libs/c-ares/include/ares_rules.h39
-rw-r--r--contrib/libs/c-ares/include/ares_version.h33
-rw-r--r--contrib/libs/c-ares/src/lib/ares__addrinfo2hostent.c41
-rw-r--r--contrib/libs/c-ares/src/lib/ares__addrinfo_localhost.c36
-rw-r--r--contrib/libs/c-ares/src/lib/ares__buf.c476
-rw-r--r--contrib/libs/c-ares/src/lib/ares__buf.h252
-rw-r--r--contrib/libs/c-ares/src/lib/ares__close_sockets.c145
-rw-r--r--contrib/libs/c-ares/src/lib/ares__get_hostent.c37
-rw-r--r--contrib/libs/c-ares/src/lib/ares__htable.c374
-rw-r--r--contrib/libs/c-ares/src/lib/ares__htable.h164
-rw-r--r--contrib/libs/c-ares/src/lib/ares__htable_asvp.c195
-rw-r--r--contrib/libs/c-ares/src/lib/ares__htable_asvp.h120
-rw-r--r--contrib/libs/c-ares/src/lib/ares__htable_stvp.c193
-rw-r--r--contrib/libs/c-ares/src/lib/ares__htable_stvp.h115
-rw-r--r--contrib/libs/c-ares/src/lib/ares__llist.c316
-rw-r--r--contrib/libs/c-ares/src/lib/ares__llist.h203
-rw-r--r--contrib/libs/c-ares/src/lib/ares__parse_into_addrinfo.c36
-rw-r--r--contrib/libs/c-ares/src/lib/ares__read_line.c37
-rw-r--r--contrib/libs/c-ares/src/lib/ares__readaddrinfo.c39
-rw-r--r--contrib/libs/c-ares/src/lib/ares__slist.c501
-rw-r--r--contrib/libs/c-ares/src/lib/ares__slist.h197
-rw-r--r--contrib/libs/c-ares/src/lib/ares__sortaddrinfo.c4
-rw-r--r--contrib/libs/c-ares/src/lib/ares__timeval.c34
-rw-r--r--contrib/libs/c-ares/src/lib/ares_android.c35
-rw-r--r--contrib/libs/c-ares/src/lib/ares_android.h35
-rw-r--r--contrib/libs/c-ares/src/lib/ares_cancel.c98
-rw-r--r--contrib/libs/c-ares/src/lib/ares_create_query.c37
-rw-r--r--contrib/libs/c-ares/src/lib/ares_data.c36
-rw-r--r--contrib/libs/c-ares/src/lib/ares_data.h41
-rw-r--r--contrib/libs/c-ares/src/lib/ares_destroy.c93
-rw-r--r--contrib/libs/c-ares/src/lib/ares_expand_name.c37
-rw-r--r--contrib/libs/c-ares/src/lib/ares_expand_string.c37
-rw-r--r--contrib/libs/c-ares/src/lib/ares_fds.c80
-rw-r--r--contrib/libs/c-ares/src/lib/ares_free_hostent.c37
-rw-r--r--contrib/libs/c-ares/src/lib/ares_free_string.c37
-rw-r--r--contrib/libs/c-ares/src/lib/ares_freeaddrinfo.c38
-rw-r--r--contrib/libs/c-ares/src/lib/ares_getaddrinfo.c169
-rw-r--r--contrib/libs/c-ares/src/lib/ares_getenv.c38
-rw-r--r--contrib/libs/c-ares/src/lib/ares_getenv.h42
-rw-r--r--contrib/libs/c-ares/src/lib/ares_gethostbyaddr.c50
-rw-r--r--contrib/libs/c-ares/src/lib/ares_gethostbyname.c36
-rw-r--r--contrib/libs/c-ares/src/lib/ares_getnameinfo.c50
-rw-r--r--contrib/libs/c-ares/src/lib/ares_getsock.c89
-rw-r--r--contrib/libs/c-ares/src/lib/ares_inet_net_pton.h40
-rw-r--r--contrib/libs/c-ares/src/lib/ares_init.c410
-rw-r--r--contrib/libs/c-ares/src/lib/ares_ipv6.h36
-rw-r--r--contrib/libs/c-ares/src/lib/ares_library_init.c38
-rw-r--r--contrib/libs/c-ares/src/lib/ares_llist.c63
-rw-r--r--contrib/libs/c-ares/src/lib/ares_llist.h39
-rw-r--r--contrib/libs/c-ares/src/lib/ares_mkquery.c37
-rw-r--r--contrib/libs/c-ares/src/lib/ares_nowarn.c37
-rw-r--r--contrib/libs/c-ares/src/lib/ares_nowarn.h41
-rw-r--r--contrib/libs/c-ares/src/lib/ares_options.c49
-rw-r--r--contrib/libs/c-ares/src/lib/ares_parse_a_reply.c38
-rw-r--r--contrib/libs/c-ares/src/lib/ares_parse_aaaa_reply.c40
-rw-r--r--contrib/libs/c-ares/src/lib/ares_parse_caa_reply.c36
-rw-r--r--contrib/libs/c-ares/src/lib/ares_parse_mx_reply.c38
-rw-r--r--contrib/libs/c-ares/src/lib/ares_parse_naptr_reply.c39
-rw-r--r--contrib/libs/c-ares/src/lib/ares_parse_ns_reply.c36
-rw-r--r--contrib/libs/c-ares/src/lib/ares_parse_ptr_reply.c37
-rw-r--r--contrib/libs/c-ares/src/lib/ares_parse_soa_reply.c38
-rw-r--r--contrib/libs/c-ares/src/lib/ares_parse_srv_reply.c38
-rw-r--r--contrib/libs/c-ares/src/lib/ares_parse_txt_reply.c38
-rw-r--r--contrib/libs/c-ares/src/lib/ares_parse_uri_reply.c41
-rw-r--r--contrib/libs/c-ares/src/lib/ares_platform.c39
-rw-r--r--contrib/libs/c-ares/src/lib/ares_platform.h43
-rw-r--r--contrib/libs/c-ares/src/lib/ares_private.h189
-rw-r--r--contrib/libs/c-ares/src/lib/ares_process.c1568
-rw-r--r--contrib/libs/c-ares/src/lib/ares_query.c85
-rw-r--r--contrib/libs/c-ares/src/lib/ares_rand.c161
-rw-r--r--contrib/libs/c-ares/src/lib/ares_search.c42
-rw-r--r--contrib/libs/c-ares/src/lib/ares_send.c83
-rw-r--r--contrib/libs/c-ares/src/lib/ares_setup.h39
-rw-r--r--contrib/libs/c-ares/src/lib/ares_strcasecmp.c38
-rw-r--r--contrib/libs/c-ares/src/lib/ares_strcasecmp.h42
-rw-r--r--contrib/libs/c-ares/src/lib/ares_strdup.c38
-rw-r--r--contrib/libs/c-ares/src/lib/ares_strdup.h42
-rw-r--r--contrib/libs/c-ares/src/lib/ares_strerror.c37
-rw-r--r--contrib/libs/c-ares/src/lib/ares_strsplit.c35
-rw-r--r--contrib/libs/c-ares/src/lib/ares_strsplit.h40
-rw-r--r--contrib/libs/c-ares/src/lib/ares_timeout.c113
-rw-r--r--contrib/libs/c-ares/src/lib/ares_version.c27
-rw-r--r--contrib/libs/c-ares/src/lib/ares_writev.c79
-rw-r--r--contrib/libs/c-ares/src/lib/ares_writev.h36
-rw-r--r--contrib/libs/c-ares/src/lib/bitncmp.c3
-rw-r--r--contrib/libs/c-ares/src/lib/bitncmp.h41
-rw-r--r--contrib/libs/c-ares/src/lib/config-win32.h38
-rw-r--r--contrib/libs/c-ares/src/lib/inet_net_pton.c3
-rw-r--r--contrib/libs/c-ares/src/lib/inet_ntop.c6
-rw-r--r--contrib/libs/c-ares/src/lib/setup_once.h43
-rw-r--r--contrib/libs/c-ares/src/lib/windows_port.c8
-rw-r--r--contrib/libs/c-ares/test/.yandex_meta/licenses.list.txt15
-rw-r--r--contrib/libs/c-ares/test/README.md1
-rw-r--r--contrib/libs/c-ares/test/ares-test-ai.h17
-rw-r--r--contrib/libs/c-ares/test/ares-test-init.cc17
-rw-r--r--contrib/libs/c-ares/test/ares-test-internal.cc57
-rw-r--r--contrib/libs/c-ares/test/ares-test-live.cc17
-rw-r--r--contrib/libs/c-ares/test/ares-test-misc.cc17
-rw-r--r--contrib/libs/c-ares/test/ares-test-mock-ai.cc26
-rw-r--r--contrib/libs/c-ares/test/ares-test-mock.cc154
-rw-r--r--contrib/libs/c-ares/test/ares-test-ns.cc17
-rw-r--r--contrib/libs/c-ares/test/ares-test-parse-a.cc17
-rw-r--r--contrib/libs/c-ares/test/ares-test-parse-aaaa.cc17
-rw-r--r--contrib/libs/c-ares/test/ares-test-parse-caa.cc17
-rw-r--r--contrib/libs/c-ares/test/ares-test-parse-mx.cc17
-rw-r--r--contrib/libs/c-ares/test/ares-test-parse-naptr.cc17
-rw-r--r--contrib/libs/c-ares/test/ares-test-parse-ns.cc17
-rw-r--r--contrib/libs/c-ares/test/ares-test-parse-ptr.cc17
-rw-r--r--contrib/libs/c-ares/test/ares-test-parse-soa-any.cc17
-rw-r--r--contrib/libs/c-ares/test/ares-test-parse-soa.cc17
-rw-r--r--contrib/libs/c-ares/test/ares-test-parse-srv.cc17
-rw-r--r--contrib/libs/c-ares/test/ares-test-parse-txt.cc17
-rw-r--r--contrib/libs/c-ares/test/ares-test-parse-uri.cc17
-rw-r--r--contrib/libs/c-ares/test/ares-test-parse.cc17
-rw-r--r--contrib/libs/c-ares/test/ares-test.cc64
-rw-r--r--contrib/libs/c-ares/test/ares-test.h32
-rw-r--r--contrib/libs/c-ares/test/config.h7
-rw-r--r--contrib/libs/c-ares/test/dns-proto-test.cc17
-rw-r--r--contrib/libs/c-ares/test/dns-proto.cc31
-rw-r--r--contrib/libs/c-ares/test/dns-proto.h17
-rw-r--r--contrib/libs/c-ares/test/ya.make4
-rw-r--r--contrib/libs/c-ares/ya.make16
139 files changed, 7325 insertions, 2669 deletions
diff --git a/build/conf/license.conf b/build/conf/license.conf
index c9265d7a55..37464288a6 100644
--- a/build/conf/license.conf
+++ b/build/conf/license.conf
@@ -314,6 +314,7 @@ LICENSES_REQUIRE_CITATION= \
libtiff \
LicenseRef-scancode-ams-fonts \
LicenseRef-scancode-bitstream \
+ LicenseRef-scancode-mit-no-advert-export-control \
LicenseRef-scancode-paul-mackerras-binary \
LicenseRef-scancode-swig \
Linux-OpenIB \
diff --git a/contrib/libs/c-ares/CMakeLists.darwin-x86_64.txt b/contrib/libs/c-ares/CMakeLists.darwin-x86_64.txt
index 1aff47860f..764aa16c70 100644
--- a/contrib/libs/c-ares/CMakeLists.darwin-x86_64.txt
+++ b/contrib/libs/c-ares/CMakeLists.darwin-x86_64.txt
@@ -31,11 +31,17 @@ target_link_libraries(contrib-libs-c-ares PUBLIC
target_sources(contrib-libs-c-ares PRIVATE
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__addrinfo2hostent.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__addrinfo_localhost.c
+ ${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__buf.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__close_sockets.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__get_hostent.c
+ ${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__htable.c
+ ${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__htable_asvp.c
+ ${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__htable_stvp.c
+ ${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__llist.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__parse_into_addrinfo.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__read_line.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__readaddrinfo.c
+ ${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__slist.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__sortaddrinfo.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__timeval.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_android.c
@@ -57,7 +63,6 @@ target_sources(contrib-libs-c-ares PRIVATE
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_getsock.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_init.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_library_init.c
- ${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_llist.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_mkquery.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_nowarn.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_options.c
@@ -84,7 +89,6 @@ target_sources(contrib-libs-c-ares PRIVATE
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_strsplit.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_timeout.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_version.c
- ${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_writev.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/atomic.cpp
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/bitncmp.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/inet_net_pton.c
diff --git a/contrib/libs/c-ares/CMakeLists.linux-aarch64.txt b/contrib/libs/c-ares/CMakeLists.linux-aarch64.txt
index 235658ca76..47673c0807 100644
--- a/contrib/libs/c-ares/CMakeLists.linux-aarch64.txt
+++ b/contrib/libs/c-ares/CMakeLists.linux-aarch64.txt
@@ -32,11 +32,17 @@ target_link_libraries(contrib-libs-c-ares PUBLIC
target_sources(contrib-libs-c-ares PRIVATE
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__addrinfo2hostent.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__addrinfo_localhost.c
+ ${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__buf.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__close_sockets.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__get_hostent.c
+ ${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__htable.c
+ ${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__htable_asvp.c
+ ${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__htable_stvp.c
+ ${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__llist.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__parse_into_addrinfo.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__read_line.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__readaddrinfo.c
+ ${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__slist.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__sortaddrinfo.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__timeval.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_android.c
@@ -58,7 +64,6 @@ target_sources(contrib-libs-c-ares PRIVATE
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_getsock.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_init.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_library_init.c
- ${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_llist.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_mkquery.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_nowarn.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_options.c
@@ -85,7 +90,6 @@ target_sources(contrib-libs-c-ares PRIVATE
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_strsplit.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_timeout.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_version.c
- ${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_writev.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/atomic.cpp
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/bitncmp.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/inet_net_pton.c
diff --git a/contrib/libs/c-ares/CMakeLists.linux-x86_64.txt b/contrib/libs/c-ares/CMakeLists.linux-x86_64.txt
index 235658ca76..47673c0807 100644
--- a/contrib/libs/c-ares/CMakeLists.linux-x86_64.txt
+++ b/contrib/libs/c-ares/CMakeLists.linux-x86_64.txt
@@ -32,11 +32,17 @@ target_link_libraries(contrib-libs-c-ares PUBLIC
target_sources(contrib-libs-c-ares PRIVATE
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__addrinfo2hostent.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__addrinfo_localhost.c
+ ${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__buf.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__close_sockets.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__get_hostent.c
+ ${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__htable.c
+ ${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__htable_asvp.c
+ ${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__htable_stvp.c
+ ${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__llist.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__parse_into_addrinfo.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__read_line.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__readaddrinfo.c
+ ${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__slist.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__sortaddrinfo.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__timeval.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_android.c
@@ -58,7 +64,6 @@ target_sources(contrib-libs-c-ares PRIVATE
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_getsock.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_init.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_library_init.c
- ${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_llist.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_mkquery.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_nowarn.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_options.c
@@ -85,7 +90,6 @@ target_sources(contrib-libs-c-ares PRIVATE
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_strsplit.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_timeout.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_version.c
- ${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_writev.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/atomic.cpp
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/bitncmp.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/inet_net_pton.c
diff --git a/contrib/libs/c-ares/CMakeLists.windows-x86_64.txt b/contrib/libs/c-ares/CMakeLists.windows-x86_64.txt
index 1aff47860f..764aa16c70 100644
--- a/contrib/libs/c-ares/CMakeLists.windows-x86_64.txt
+++ b/contrib/libs/c-ares/CMakeLists.windows-x86_64.txt
@@ -31,11 +31,17 @@ target_link_libraries(contrib-libs-c-ares PUBLIC
target_sources(contrib-libs-c-ares PRIVATE
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__addrinfo2hostent.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__addrinfo_localhost.c
+ ${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__buf.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__close_sockets.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__get_hostent.c
+ ${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__htable.c
+ ${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__htable_asvp.c
+ ${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__htable_stvp.c
+ ${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__llist.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__parse_into_addrinfo.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__read_line.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__readaddrinfo.c
+ ${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__slist.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__sortaddrinfo.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares__timeval.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_android.c
@@ -57,7 +63,6 @@ target_sources(contrib-libs-c-ares PRIVATE
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_getsock.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_init.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_library_init.c
- ${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_llist.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_mkquery.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_nowarn.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_options.c
@@ -84,7 +89,6 @@ target_sources(contrib-libs-c-ares PRIVATE
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_strsplit.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_timeout.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_version.c
- ${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/ares_writev.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/atomic.cpp
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/bitncmp.c
${CMAKE_SOURCE_DIR}/contrib/libs/c-ares/src/lib/inet_net_pton.c
diff --git a/contrib/libs/c-ares/INSTALL.md b/contrib/libs/c-ares/INSTALL.md
index 0f9d95a521..9b2f847be8 100644
--- a/contrib/libs/c-ares/INSTALL.md
+++ b/contrib/libs/c-ares/INSTALL.md
@@ -291,16 +291,12 @@ As a general rule, building a DLL with static CRT linkage is highly
discouraged, and intermixing CRTs in the same app is something to
avoid at any cost.
-Reading and comprehension of Microsoft Knowledge Base articles
-KB94248 and KB140584 is a must for any Windows developer. Especially
+Reading and comprehension of the following Microsoft Learn article
+is a must for any Windows developer. Especially
important is full understanding if you are not going to follow the
advice given above.
- - [KB94248](http://support.microsoft.com/kb/94248/en-us) - How To Use the C Run-Time
-
- - [KB140584](http://support.microsoft.com/kb/140584/en-us) - How to link with the correct C Run-Time (CRT) library
-
- - [KB190799](http://msdn.microsoft.com/en-us/library/ms235460) - Potential Errors Passing CRT Objects Across DLL Boundaries
+ - [Use the C Run-Time](https://learn.microsoft.com/en-us/troubleshoot/developer/visualstudio/cpp/libraries/use-c-run-time)
If your app is misbehaving in some strange way, or it is suffering
from memory corruption, before asking for further help, please try
@@ -397,6 +393,21 @@ You can build and install c-ares using [vcpkg](https://github.com/Microsoft/vcpk
The c-ares port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository.
+WATCOM
+=====
+
+To build c-ares with OpenWatcom, you need to have at least version 1.9 of OpenWatcom. You can get the latest version from [http://openwatcom.org/ftp/install/](http://openwatcom.org/ftp/install/). Install the version that corresponds to your current host platform.
+
+After installing OpenWatcom, open a new command prompt and execute the following commands:
+
+```
+ cd \path\to\cmake\source
+ buildconf.bat
+ wmake -u -f Makefile.Watcom
+```
+
+After running wmake, you should get adig.exe, ahost.exe, and the static and dynamic versions of libcares.
+
PORTS
=====
diff --git a/contrib/libs/c-ares/LICENSE.md b/contrib/libs/c-ares/LICENSE.md
index ad6bb52b72..134145428a 100644
--- a/contrib/libs/c-ares/LICENSE.md
+++ b/contrib/libs/c-ares/LICENSE.md
@@ -1,15 +1,27 @@
# c-ares license
-Copyright (c) 2007 - 2018, Daniel Stenberg with many contributors, see AUTHORS
+MIT License
+
+
+Copyright (c) 1998 Massachusetts Institute of Technology
+Copyright (c) 2007 - 2023 Daniel Stenberg with many contributors, see AUTHORS
file.
-Copyright 1998 by the Massachusetts Institute of Technology.
+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.
-Permission to use, copy, modify, and distribute this software and its
-documentation for any purpose and without fee is hereby granted, provided that
-the above copyright notice appear in all copies and that both that copyright
-notice and this permission notice appear in supporting documentation, and that
-the name of M.I.T. not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior permission.
-M.I.T. makes no representations about the suitability of this software for any
-purpose. It is provided "as is" without express or implied warranty.
+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.
diff --git a/contrib/libs/c-ares/README.md b/contrib/libs/c-ares/README.md
index b507a5c288..40d3c08114 100644
--- a/contrib/libs/c-ares/README.md
+++ b/contrib/libs/c-ares/README.md
@@ -6,7 +6,6 @@ c-ares
[![Coverage Status](https://coveralls.io/repos/github/c-ares/c-ares/badge.svg)](https://coveralls.io/github/c-ares/c-ares)
[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/291/badge)](https://bestpractices.coreinfrastructure.org/projects/291)
[![Fuzzing Status](https://oss-fuzz-build-logs.storage.googleapis.com/badges/c-ares.svg)](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:c-ares)
-[![Releases](https://coderelease.io/badge/c-ares/c-ares)](https://coderelease.io/github/repository/c-ares/c-ares)
This is c-ares, an asynchronous resolver library. It is intended for
applications which need to perform DNS queries without blocking, or need to
@@ -22,8 +21,7 @@ If you find bugs, correct flaws, have questions or have comments in general in
regard to c-ares (or by all means the original ares too), get in touch with us
on the c-ares mailing list: https://lists.haxx.se/listinfo/c-ares
-c-ares is of course distributed under the same MIT-style license as the
-original ares.
+c-ares is distributed the MIT license.
You'll find all c-ares details and news here:
https://c-ares.org/
diff --git a/contrib/libs/c-ares/README.msvc b/contrib/libs/c-ares/README.msvc
index 396f497db4..97d4f0cf58 100644
--- a/contrib/libs/c-ares/README.msvc
+++ b/contrib/libs/c-ares/README.msvc
@@ -28,7 +28,7 @@
depends on the MSVC compiler version being used to build c-ares.
Below the MSVCXX folder there will exist four folders named 'cares',
- 'ahost', 'acountry', and 'adig'. The 'cares' folder is the one that
+ 'ahost', and 'adig'. The 'cares' folder is the one that
holds the c-ares libraries you have just generated, the other three
hold sample programs that use the libraries.
diff --git a/contrib/libs/c-ares/RELEASE-NOTES b/contrib/libs/c-ares/RELEASE-NOTES
index 2524f3ccf4..169a39fcb3 100644
--- a/contrib/libs/c-ares/RELEASE-NOTES
+++ b/contrib/libs/c-ares/RELEASE-NOTES
@@ -1,57 +1,74 @@
-c-ares version 1.19.1
+c-ares version 1.20.1
-This is a security and bugfix release.
+This release resolves a significant issue in the 1.20.0 release.
-A special thanks goes out to the Open Source Technology Improvement Fund
-(https://ostif.org) for sponsoring a security audit of c-ares performed by X41
-(https://x41-dsec.de).
+Bug fixes:
+ o Resolve use-after-free issue when TCP connection is terminated before a
+ response is returned [17]
+ o Reduce number of queries for a load test case to prevent overloading some
+ build systems
+ o Fix fuzz test build target [18]
+
+
+c-ares 1.20.0 notes below:
+
+This is a feature and bugfix release with some significant internal changes.
-Security:
- o CVE-2023-32067. High. 0-byte UDP payload causes Denial of Service [12]
- o CVE-2023-31147. Moderate. Insufficient randomness in generation of DNS
- query IDs [13]
- o CVE-2023-31130. Moderate. Buffer Underwrite in ares_inet_net_pton() [14]
- o CVE-2023-31124. Low. AutoTools does not set CARES_RANDOM_FILE during cross
- compilation [15]
+Changes:
+ o Update from 1989 MIT license text to modern MIT license text [1]
+ o Remove acountry from built tools as nerd.dk is gone [3]
+ o Add new ARES_OPT_UDP_MAX_QUERIES configuration option to limit the number of
+ queries that can be made from a single ephemeral port [7]
+ o Default per-query timeout has been reduced to 2s with a 3x retry count [8]
+ o Modernization: start implementing some common data structures that are easy
+ to use and hard to misuse. This will make code refactoring easier and remove
+ some varied implementations in use. This change also makes ares_timeout()
+ more efficient [9]
+ o Use SPDX identifiers and a REUSE CI job to verify [12]
+ o rand: add support for getrandom() [14]
Bug fixes:
- o Fix uninitialized memory warning in test [1]
- o Turn off IPV6_V6ONLY on Windows to allow IPv4-mapped IPv6 addresses [2]
- o ares_getaddrinfo() should allow a port of 0 [3]
- o Fix memory leak in ares_send() on error [4]
- o Fix comment style in ares_data.h [5]
- o Remove unneeded ifdef for Windows [6]
- o Fix typo in ares_init_options.3 [7]
- o Re-add support for Watcom compiler [8]
- o Sync ax_pthread.m4 with upstream [9]
- o Windows: Invalid stack variable used out of scope for HOSTS path [10]
- o Sync ax_cxx_compile_stdcxx_11.m4 with upstream to fix uclibc support [11]
+ o TCP back to back queries were broken [2]
+ o Ensure queries for ares_getaddrinfo() are not requeued during destruction [4]
+ o ares_getaddrinfo() should not retry other address classes if one address
+ class has already been returned [5]
+ o Avoid production ill-formed result when qualifying a name with the root
+ domain [6]
+ o Fix missing prefix for CMake generated libcares.pc [10]
+ o DNS server ports will now be read from system configuration instead of
+ defaulting to port 53 [11]
+ o Remove some unreachable code [13]
+ o Replace usages of sprintf with snprintf [15]
+ o Fix Watcom instructions and update Windows URLs [16]
Thanks go to these friendly people for their efforts and contributions:
+ Alexey A Tikhonov (@alexey-tikhonov)
+ Ben Noordhuis (@bnoordhuis)
Brad House (@bradh352)
@Chilledheart
Daniel Stenberg (@bagder)
Douglas R. Reno (@renodr)
- Gregor Jasny (@gjasny)
- Jay Freeman (@saurik)
- @lifenjoiner
- Nikolaos Chatzikonstantinou (@createyourpersonalaccount)
- Yijie Ma (@yijiem)
+ Jérôme Duval (@korli)
+ Sam Morris (@yrro)
+ Tim Wojtulewicz (@timwoj)
(9 contributors)
References to bug reports and discussions on issues:
- [1] = https://github.com/c-ares/c-ares/pull/515
- [2] = https://github.com/c-ares/c-ares/pull/520
- [3] = https://github.com/c-ares/c-ares/issues/517
- [4] = https://github.com/c-ares/c-ares/pull/511
- [5] = https://github.com/c-ares/c-ares/pull/513
- [6] = https://github.com/c-ares/c-ares/pull/512
- [7] = https://github.com/c-ares/c-ares/pull/510
- [8] = https://github.com/c-ares/c-ares/pull/509
- [9] = https://github.com/c-ares/c-ares/pull/507
- [10] = https://github.com/c-ares/c-ares/pull/502
- [11] = https://github.com/c-ares/c-ares/pull/505
- [12] = https://github.com/c-ares/c-ares/security/advisories/GHSA-9g78-jv2r-p7vc
- [13] = https://github.com/c-ares/c-ares/security/advisories/GHSA-8r8p-23f3-64c2
- [14] = https://github.com/c-ares/c-ares/security/advisories/GHSA-x6mf-cxr9-8q6v
- [15] = https://github.com/c-ares/c-ares/security/advisories/GHSA-54xr-f67r-4pc4
+ [1] = https://github.com/c-ares/c-ares/pull/556
+ [2] = https://github.com/c-ares/c-ares/pull/552
+ [3] = https://github.com/c-ares/c-ares/pull/554
+ [4] = https://github.com/c-ares/c-ares/pull/553
+ [5] = https://github.com/c-ares/c-ares/pull/551
+ [6] = https://github.com/c-ares/c-ares/pull/546
+ [7] = https://github.com/c-ares/c-ares/pull/549
+ [8] = https://github.com/c-ares/c-ares/pull/542
+ [9] = https://github.com/c-ares/c-ares/pull/540
+ [10] = https://github.com/c-ares/c-ares/pull/530
+ [11] = https://github.com/c-ares/c-ares/pull/534
+ [12] = https://github.com/c-ares/c-ares/commit/c1b00c41
+ [13] = https://github.com/c-ares/c-ares/pull/527
+ [14] = https://github.com/c-ares/c-ares/pull/526
+ [15] = https://github.com/c-ares/c-ares/pull/525
+ [16] = https://github.com/c-ares/c-ares/pull/524
+ [17] = https://github.com/c-ares/c-ares/pull/562
+ [18] = https://github.com/c-ares/c-ares/pull/559
diff --git a/contrib/libs/c-ares/RELEASE-PROCEDURE.md b/contrib/libs/c-ares/RELEASE-PROCEDURE.md
index c167707889..1abc9a3822 100644
--- a/contrib/libs/c-ares/RELEASE-PROCEDURE.md
+++ b/contrib/libs/c-ares/RELEASE-PROCEDURE.md
@@ -10,6 +10,9 @@ in the source code repo
`CARES_LIB_VERSIONINFO` set to the same value to denote the current shared
object versioning.
+- edit `include/ares_version.h` and set `ARES_VERSION_*` definitions to reflect
+ the current version.
+
- make sure all relevant changes are committed on the master branch
- tag the git repo in this style: `git tag -a cares-1_14_0` -a annotates the
@@ -26,8 +29,6 @@ in the source code repo
- upload the resulting files to https://c-ares.org/download/
-- update `ares_version.h` for the next version
-
in the c-ares-www repo
----------------------
diff --git a/contrib/libs/c-ares/include/ares.h b/contrib/libs/c-ares/include/ares.h
index c48df2623e..ffee1e753f 100644
--- a/contrib/libs/c-ares/include/ares.h
+++ b/contrib/libs/c-ares/include/ares.h
@@ -1,18 +1,28 @@
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
- * Copyright (C) 2007-2013 by Daniel Stenberg
+/* MIT License
+ *
+ * Copyright (c) Massachusetts Institute of Technology
+ * Copyright (c) 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.
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * SPDX-License-Identifier: MIT
*/
#ifndef ARES__H
@@ -157,27 +167,28 @@ extern "C" {
#define ARES_FLAG_EDNS (1 << 8)
/* Option mask values */
-#define ARES_OPT_FLAGS (1 << 0)
-#define ARES_OPT_TIMEOUT (1 << 1)
-#define ARES_OPT_TRIES (1 << 2)
-#define ARES_OPT_NDOTS (1 << 3)
-#define ARES_OPT_UDP_PORT (1 << 4)
-#define ARES_OPT_TCP_PORT (1 << 5)
-#define ARES_OPT_SERVERS (1 << 6)
-#define ARES_OPT_DOMAINS (1 << 7)
-#define ARES_OPT_LOOKUPS (1 << 8)
-#define ARES_OPT_SOCK_STATE_CB (1 << 9)
-#define ARES_OPT_SORTLIST (1 << 10)
-#define ARES_OPT_SOCK_SNDBUF (1 << 11)
-#define ARES_OPT_SOCK_RCVBUF (1 << 12)
-#define ARES_OPT_TIMEOUTMS (1 << 13)
-#define ARES_OPT_ROTATE (1 << 14)
-#define ARES_OPT_EDNSPSZ (1 << 15)
-#define ARES_OPT_NOROTATE (1 << 16)
-#define ARES_OPT_RESOLVCONF (1 << 17)
-#define ARES_OPT_HOSTS_FILE (1 << 18)
-#define ARES_OPT_MAXTIMEOUTMS (1 << 19)
-#define ARES_OPT_JITTER (1 << 20)
+#define ARES_OPT_FLAGS (1 << 0)
+#define ARES_OPT_TIMEOUT (1 << 1)
+#define ARES_OPT_TRIES (1 << 2)
+#define ARES_OPT_NDOTS (1 << 3)
+#define ARES_OPT_UDP_PORT (1 << 4)
+#define ARES_OPT_TCP_PORT (1 << 5)
+#define ARES_OPT_SERVERS (1 << 6)
+#define ARES_OPT_DOMAINS (1 << 7)
+#define ARES_OPT_LOOKUPS (1 << 8)
+#define ARES_OPT_SOCK_STATE_CB (1 << 9)
+#define ARES_OPT_SORTLIST (1 << 10)
+#define ARES_OPT_SOCK_SNDBUF (1 << 11)
+#define ARES_OPT_SOCK_RCVBUF (1 << 12)
+#define ARES_OPT_TIMEOUTMS (1 << 13)
+#define ARES_OPT_ROTATE (1 << 14)
+#define ARES_OPT_EDNSPSZ (1 << 15)
+#define ARES_OPT_NOROTATE (1 << 16)
+#define ARES_OPT_RESOLVCONF (1 << 17)
+#define ARES_OPT_HOSTS_FILE (1 << 18)
+#define ARES_OPT_UDP_MAX_QUERIES (1 << 19)
+#define ARES_OPT_MAXTIMEOUTMS (1 << 20)
+#define ARES_OPT_JITTER (1 << 21)
/* Nameinfo flag values */
#define ARES_NI_NOFQDN (1 << 0)
@@ -291,6 +302,7 @@ struct ares_options {
int ednspsz;
char *resolvconf_path;
char *hosts_path;
+ int udp_max_queries;
};
struct hostent;
diff --git a/contrib/libs/c-ares/include/ares_build-ios.h b/contrib/libs/c-ares/include/ares_build-ios.h
new file mode 100644
index 0000000000..dc9849545d
--- /dev/null
+++ b/contrib/libs/c-ares/include/ares_build-ios.h
@@ -0,0 +1,52 @@
+#ifndef __CARES_BUILD_H
+#define __CARES_BUILD_H
+/*
+ * Copyright (C) The c-ares project and its contributors
+ * SPDX-License-Identifier: MIT
+ */
+
+#define CARES_TYPEOF_ARES_SOCKLEN_T socklen_t
+#define CARES_TYPEOF_ARES_SSIZE_T ssize_t
+
+/* Prefix names with CARES_ to make sure they don't conflict with other config.h
+ * files. We need to include some dependent headers that may be system specific
+ * for C-Ares */
+#define CARES_HAVE_SYS_TYPES_H
+/* #undef CARES_HAVE_SYS_RANDOM_H */
+#define CARES_HAVE_SYS_SOCKET_H
+/* #undef CARES_HAVE_WINDOWS_H */
+/* #undef CARES_HAVE_WS2TCPIP_H */
+/* #undef CARES_HAVE_WINSOCK2_H */
+/* #undef CARES_HAVE_WINDOWS_H */
+#define CARES_HAVE_ARPA_NAMESER_H
+#define CARES_HAVE_ARPA_NAMESER_COMPAT_H
+
+#ifdef CARES_HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+
+#ifdef CARES_HAVE_SYS_RANDOM_H
+# include <sys/random.h>
+#endif
+
+#ifdef CARES_HAVE_SYS_SOCKET_H
+# include <sys/socket.h>
+#endif
+
+#ifdef CARES_HAVE_WINSOCK2_H
+# include <winsock2.h>
+#endif
+
+#ifdef CARES_HAVE_WS2TCPIP_H
+# include <ws2tcpip.h>
+#endif
+
+#ifdef CARES_HAVE_WINDOWS_H
+# include <windows.h>
+#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/contrib/libs/c-ares/include/ares_build-linux.h b/contrib/libs/c-ares/include/ares_build-linux.h
index bf7402e799..3d4d7aed9c 100644
--- a/contrib/libs/c-ares/include/ares_build-linux.h
+++ b/contrib/libs/c-ares/include/ares_build-linux.h
@@ -1,5 +1,9 @@
#ifndef __CARES_BUILD_H
#define __CARES_BUILD_H
+/*
+ * Copyright (C) The c-ares project and its contributors
+ * SPDX-License-Identifier: MIT
+ */
#define CARES_TYPEOF_ARES_SOCKLEN_T socklen_t
#define CARES_TYPEOF_ARES_SSIZE_T ssize_t
@@ -8,6 +12,7 @@
* files. We need to include some dependent headers that may be system specific
* for C-Ares */
#define CARES_HAVE_SYS_TYPES_H
+#define CARES_HAVE_SYS_RANDOM_H
#define CARES_HAVE_SYS_SOCKET_H
/* #undef CARES_HAVE_WINDOWS_H */
/* #undef CARES_HAVE_WS2TCPIP_H */
@@ -20,6 +25,10 @@
# include <sys/types.h>
#endif
+#ifdef CARES_HAVE_SYS_RANDOM_H
+# include <sys/random.h>
+#endif
+
#ifdef CARES_HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif
diff --git a/contrib/libs/c-ares/include/ares_build.h b/contrib/libs/c-ares/include/ares_build.h
index 538479c3a6..69409e4c2b 100644
--- a/contrib/libs/c-ares/include/ares_build.h
+++ b/contrib/libs/c-ares/include/ares_build.h
@@ -1,6 +1,8 @@
#pragma once
-#if defined(_MSC_VER) && (defined(__x86_64__) || defined(_M_X64))
+#if defined(__IOS__)
+# include "ares_build-ios.h"
+#elif defined(_MSC_VER) && (defined(__x86_64__) || defined(_M_X64))
# include "ares_build-win-x86_64.h"
#else
# include "ares_build-linux.h"
diff --git a/contrib/libs/c-ares/include/ares_dns.h b/contrib/libs/c-ares/include/ares_dns.h
index bc8aa7b109..e49c3d26ab 100644
--- a/contrib/libs/c-ares/include/ares_dns.h
+++ b/contrib/libs/c-ares/include/ares_dns.h
@@ -1,20 +1,31 @@
-#ifndef HEADER_CARES_DNS_H
-#define HEADER_CARES_DNS_H
-
-/* Copyright 1998, 2011 by the Massachusetts Institute of Technology.
+/* MIT License
+ *
+ * Copyright (c) Massachusetts Institute of Technology
+ * Copyright (c) The c-ares project and its contributors
+ *
+ * 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:
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * 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 HEADER_CARES_DNS_H
+#define HEADER_CARES_DNS_H
/*
* NOTE TO INTEGRATORS:
diff --git a/contrib/libs/c-ares/include/ares_nameser.h b/contrib/libs/c-ares/include/ares_nameser.h
index 18a9e5ac0e..3138d89d74 100644
--- a/contrib/libs/c-ares/include/ares_nameser.h
+++ b/contrib/libs/c-ares/include/ares_nameser.h
@@ -1,3 +1,29 @@
+/* MIT License
+ *
+ * Copyright (c) Massachusetts Institute of Technology
+ * Copyright (c) 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 ARES_NAMESER_H
#define ARES_NAMESER_H
diff --git a/contrib/libs/c-ares/include/ares_rules.h b/contrib/libs/c-ares/include/ares_rules.h
index 1706ab7d00..f6b1f663e2 100644
--- a/contrib/libs/c-ares/include/ares_rules.h
+++ b/contrib/libs/c-ares/include/ares_rules.h
@@ -1,19 +1,30 @@
-#ifndef __CARES_RULES_H
-#define __CARES_RULES_H
-
-
-/* Copyright (C) 2009 - 2021 by Daniel Stenberg et al
+/* MIT License
+ *
+ * Copyright (c) 2009 Daniel Stenberg
*
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in advertising or
- * publicity pertaining to distribution of the software without specific,
- * written prior permission. M.I.T. makes no representations about the
- * suitability of this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * 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 */
diff --git a/contrib/libs/c-ares/include/ares_version.h b/contrib/libs/c-ares/include/ares_version.h
index 4d8d62fd18..34784e2ed4 100644
--- a/contrib/libs/c-ares/include/ares_version.h
+++ b/contrib/libs/c-ares/include/ares_version.h
@@ -1,17 +1,42 @@
+/* MIT License
+ *
+ * Copyright (c) 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 ARES__VERSION_H
#define ARES__VERSION_H
/* This is the global package copyright */
-#define ARES_COPYRIGHT "2004 - 2021 Daniel Stenberg, <daniel@haxx.se>."
+#define ARES_COPYRIGHT "2004 - 2023 Daniel Stenberg, <daniel@haxx.se>."
#define ARES_VERSION_MAJOR 1
-#define ARES_VERSION_MINOR 19
-#define ARES_VERSION_PATCH 0
+#define ARES_VERSION_MINOR 20
+#define ARES_VERSION_PATCH 1
#define ARES_VERSION ((ARES_VERSION_MAJOR<<16)|\
(ARES_VERSION_MINOR<<8)|\
(ARES_VERSION_PATCH))
-#define ARES_VERSION_STR "1.19.0"
+#define ARES_VERSION_STR "1.20.1"
#if (ARES_VERSION >= 0x010700)
# define CARES_HAVE_ARES_LIBRARY_INIT 1
diff --git a/contrib/libs/c-ares/src/lib/ares__addrinfo2hostent.c b/contrib/libs/c-ares/src/lib/ares__addrinfo2hostent.c
index efb145cd11..1798fc69fa 100644
--- a/contrib/libs/c-ares/src/lib/ares__addrinfo2hostent.c
+++ b/contrib/libs/c-ares/src/lib/ares__addrinfo2hostent.c
@@ -1,19 +1,30 @@
-/* Copyright 1998 by the Massachusetts Institute of Technology.
- * Copyright 2005 Dominick Meglio
- * Copyright (C) 2019 by Andrew Selivanov
- * Copyright (C) 2021 by Brad House
+/* MIT License
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * Copyright (c) 2005 Dominick Meglio
+ * Copyright (c) 2019 Andrew Selivanov
+ * Copyright (c) 2021 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_setup.h"
diff --git a/contrib/libs/c-ares/src/lib/ares__addrinfo_localhost.c b/contrib/libs/c-ares/src/lib/ares__addrinfo_localhost.c
index 5bc1e0bff0..a086d3f12f 100644
--- a/contrib/libs/c-ares/src/lib/ares__addrinfo_localhost.c
+++ b/contrib/libs/c-ares/src/lib/ares__addrinfo_localhost.c
@@ -1,16 +1,28 @@
-/* Copyright (C) 2021
+/* MIT License
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * Copyright (c) Massachusetts Institute of Technology
+ * Copyright (c) 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_setup.h"
diff --git a/contrib/libs/c-ares/src/lib/ares__buf.c b/contrib/libs/c-ares/src/lib/ares__buf.c
new file mode 100644
index 0000000000..777a5300c9
--- /dev/null
+++ b/contrib/libs/c-ares/src/lib/ares__buf.c
@@ -0,0 +1,476 @@
+/* MIT License
+ *
+ * Copyright (c) 2023 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_setup.h"
+#include "ares.h"
+#include "ares_private.h"
+#include "ares__buf.h"
+#include <limits.h>
+#ifdef HAVE_STDINT_H
+# include <stdint.h>
+#endif
+
+struct ares__buf {
+ const unsigned char *data; /*!< pointer to start of data buffer */
+ size_t data_len; /*!< total size of data in buffer */
+
+ unsigned char *alloc_buf; /*!< Pointer to allocated data buffer,
+ * not used for const buffers */
+ size_t alloc_buf_len; /*!< Size of allocated data buffer */
+
+ size_t offset; /*!< Current working offset in buffer */
+ size_t tag_offset; /*!< Tagged offset in buffer. Uses
+ * SIZE_MAX if not set. */
+};
+
+ares__buf_t *ares__buf_create(void)
+{
+ ares__buf_t *buf = ares_malloc(sizeof(*buf));
+ if (buf == NULL)
+ return NULL;
+
+ memset(buf, 0, sizeof(*buf));
+ buf->tag_offset = SIZE_MAX;
+ return buf;
+}
+
+
+ares__buf_t *ares__buf_create_const(const unsigned char *data, size_t data_len)
+{
+ ares__buf_t *buf;
+
+ if (data == NULL || data_len == 0)
+ return NULL;
+
+ buf = ares__buf_create();
+ if (buf == NULL)
+ return NULL;
+
+ buf->data = data;
+ buf->data_len = data_len;
+
+ return buf;
+}
+
+
+void ares__buf_destroy(ares__buf_t *buf)
+{
+ if (buf == NULL)
+ return;
+ ares_free(buf->alloc_buf);
+ ares_free(buf);
+}
+
+
+static int ares__buf_is_const(const ares__buf_t *buf)
+{
+ if (buf == NULL)
+ return 0;
+
+ if (buf->data != NULL && buf->alloc_buf == NULL)
+ return 1;
+
+ return 0;
+}
+
+
+static void ares__buf_reclaim(ares__buf_t *buf)
+{
+ size_t prefix_size;
+ size_t data_size;
+
+ if (buf == NULL)
+ return;
+
+ if (ares__buf_is_const(buf))
+ return;
+
+ if (buf->tag_offset != SIZE_MAX) {
+ prefix_size = buf->tag_offset;
+ } else {
+ prefix_size = buf->offset;
+ }
+
+ if (prefix_size == 0)
+ return;
+
+ data_size = buf->data_len - prefix_size;
+
+ memmove(buf->alloc_buf, buf->alloc_buf + prefix_size, data_size);
+ buf->data = buf->alloc_buf;
+ buf->data_len = data_size;
+ buf->offset -= prefix_size;
+ if (buf->tag_offset != SIZE_MAX)
+ buf->tag_offset -= prefix_size;
+
+ return;
+}
+
+
+static int ares__buf_ensure_space(ares__buf_t *buf, size_t needed_size)
+{
+ size_t remaining_size;
+ size_t alloc_size;
+ unsigned char *ptr;
+
+ if (buf == NULL)
+ return ARES_EFORMERR;
+
+ if (ares__buf_is_const(buf))
+ return ARES_EFORMERR;
+
+ /* When calling ares__buf_finish_str() we end up adding a null terminator,
+ * so we want to ensure the size is always sufficient for this as we don't
+ * want an ARES_ENOMEM at that point */
+ needed_size++;
+
+ /* No need to do an expensive move operation, we have enough to just append */
+ remaining_size = buf->alloc_buf_len - buf->data_len;
+ if (remaining_size >= needed_size)
+ return ARES_SUCCESS;
+
+ /* See if just moving consumed data frees up enough space */
+ ares__buf_reclaim(buf);
+
+ remaining_size = buf->alloc_buf_len - buf->data_len;
+ if (remaining_size >= needed_size)
+ return ARES_SUCCESS;
+
+ alloc_size = buf->alloc_buf_len;
+
+ /* Not yet started */
+ if (alloc_size == 0)
+ alloc_size = 16; /* Always shifts 1, so ends up being 32 minimum */
+
+ /* Increase allocation by powers of 2 */
+ do {
+ alloc_size <<= 1;
+ remaining_size = alloc_size - buf->data_len;
+ } while (remaining_size < needed_size);
+
+ ptr = ares_realloc(buf->alloc_buf, alloc_size);
+ if (ptr == NULL)
+ return ARES_ENOMEM;
+
+ buf->alloc_buf = ptr;
+ buf->alloc_buf_len = alloc_size;
+ buf->data = ptr;
+
+ return ARES_SUCCESS;
+}
+
+
+int ares__buf_append(ares__buf_t *buf, const unsigned char *data,
+ size_t data_len)
+{
+ int status;
+
+ if (data == NULL || data_len == 0)
+ return ARES_EFORMERR;
+
+ status = ares__buf_ensure_space(buf, data_len);
+ if (status != ARES_SUCCESS)
+ return status;
+
+ memcpy(buf->alloc_buf + buf->data_len, data, data_len);
+ buf->data_len += data_len;
+ return ARES_SUCCESS;
+}
+
+
+unsigned char *ares__buf_append_start(ares__buf_t *buf, size_t *len)
+{
+ int status;
+
+ if (len == NULL || *len == 0)
+ return NULL;
+
+ status = ares__buf_ensure_space(buf, *len);
+ if (status != ARES_SUCCESS)
+ return NULL;
+
+ *len = buf->alloc_buf_len - buf->data_len;
+ return buf->alloc_buf + buf->data_len;
+}
+
+
+void ares__buf_append_finish(ares__buf_t *buf, size_t len)
+{
+ if (buf == NULL)
+ return;
+
+ buf->data_len += len;
+}
+
+
+unsigned char *ares__buf_finish_bin(ares__buf_t *buf, size_t *len)
+{
+ unsigned char *ptr = NULL;
+ if (buf == NULL || len == NULL || ares__buf_is_const(buf))
+ return NULL;
+
+ ares__buf_reclaim(buf);
+ ptr = buf->alloc_buf;
+ *len = buf->data_len;
+ ares_free(buf);
+ return ptr;
+}
+
+
+char *ares__buf_finish_str(ares__buf_t *buf, size_t *len)
+{
+ char *ptr;
+ size_t mylen;
+
+ ptr = (char *)ares__buf_finish_bin(buf, &mylen);
+ if (ptr == NULL)
+ return NULL;
+
+ if (len != NULL)
+ *len = mylen;
+
+ /* NOTE: ensured via ares__buf_ensure_space() that there is always at least
+ * 1 extra byte available for this specific use-case */
+ ptr[mylen] = 0;
+
+ return ptr;
+}
+
+
+void ares__buf_tag(ares__buf_t *buf)
+{
+ if (buf == NULL)
+ return;
+
+ buf->tag_offset = buf->offset;
+}
+
+
+int ares__buf_tag_rollback(ares__buf_t *buf)
+{
+ if (buf == NULL || buf->tag_offset == SIZE_MAX)
+ return ARES_EFORMERR;
+
+ buf->offset = buf->tag_offset;
+ buf->tag_offset = SIZE_MAX;
+ return ARES_SUCCESS;
+}
+
+
+int ares__buf_tag_clear(ares__buf_t *buf)
+{
+ if (buf == NULL || buf->tag_offset == SIZE_MAX)
+ return ARES_EFORMERR;
+
+ buf->tag_offset = SIZE_MAX;
+ return ARES_SUCCESS;
+}
+
+
+const unsigned char *ares__buf_tag_fetch(const ares__buf_t *buf, size_t *len)
+{
+ if (buf == NULL || buf->tag_offset == SIZE_MAX || len == NULL)
+ return NULL;
+
+ *len = buf->offset - buf->tag_offset;
+ return buf->data + buf->tag_offset;
+}
+
+
+static const unsigned char *ares__buf_fetch(const ares__buf_t *buf, size_t *len)
+{
+ if (len != NULL)
+ *len = 0;
+
+ if (buf == NULL || len == NULL || buf->data == NULL)
+ return NULL;
+
+ *len = buf->data_len - buf->offset;
+ return buf->data + buf->offset;
+}
+
+
+int ares__buf_consume(ares__buf_t *buf, size_t len)
+{
+ size_t remaining_len;
+
+ ares__buf_fetch(buf, &remaining_len);
+
+ if (remaining_len < len)
+ return ARES_EBADRESP;
+
+ buf->offset += len;
+ return ARES_SUCCESS;
+}
+
+
+int ares__buf_fetch_be16(ares__buf_t *buf, unsigned short *u16)
+{
+ size_t remaining_len;
+ const unsigned char *ptr = ares__buf_fetch(buf, &remaining_len);
+
+ if (buf == NULL || u16 == NULL || remaining_len < sizeof(*u16))
+ return ARES_EBADRESP;
+
+ *u16 = (unsigned short)((unsigned short)(ptr[0]) << 8 | (unsigned short)ptr[1]);
+
+ return ares__buf_consume(buf, sizeof(*u16));
+}
+
+
+int ares__buf_fetch_bytes(ares__buf_t *buf, unsigned char *bytes,
+ size_t len)
+{
+ size_t remaining_len;
+ const unsigned char *ptr = ares__buf_fetch(buf, &remaining_len);
+
+ if (buf == NULL || bytes == NULL || len == 0 || remaining_len < len)
+ return ARES_EBADRESP;
+
+ memcpy(bytes, ptr, len);
+ return ares__buf_consume(buf, len);
+}
+
+
+size_t ares__buf_consume_whitespace(ares__buf_t *buf, int include_linefeed)
+{
+ size_t remaining_len = 0;
+ const unsigned char *ptr = ares__buf_fetch(buf, &remaining_len);
+ size_t i;
+
+ if (ptr == NULL)
+ return 0;
+
+ for (i=0; i<remaining_len; i++) {
+ switch(ptr[i]) {
+ case '\r':
+ case '\t':
+ case ' ':
+ case '\v':
+ case '\f':
+ break;
+ case '\n':
+ if (!include_linefeed)
+ goto done;
+ break;
+ default:
+ goto done;
+ }
+ }
+
+done:
+ if (i > 0)
+ ares__buf_consume(buf, i);
+ return i;
+}
+
+size_t ares__buf_consume_nonwhitespace(ares__buf_t *buf)
+{
+ size_t remaining_len = 0;
+ const unsigned char *ptr = ares__buf_fetch(buf, &remaining_len);
+ size_t i;
+
+ if (ptr == NULL)
+ return 0;
+
+ for (i=0; i<remaining_len; i++) {
+ switch(ptr[i]) {
+ case '\r':
+ case '\t':
+ case ' ':
+ case '\v':
+ case '\f':
+ case '\n':
+ goto done;
+ default:
+ break;
+ }
+ }
+
+done:
+ if (i > 0)
+ ares__buf_consume(buf, i);
+ return i;
+}
+
+size_t ares__buf_consume_line(ares__buf_t *buf, int include_linefeed)
+{
+ size_t remaining_len = 0;
+ const unsigned char *ptr = ares__buf_fetch(buf, &remaining_len);
+ size_t i;
+
+ if (ptr == NULL)
+ return 0;
+
+ for (i=0; i<remaining_len; i++) {
+ switch(ptr[i]) {
+ case '\n':
+ if (include_linefeed)
+ i++;
+ goto done;
+ default:
+ break;
+ }
+ }
+
+done:
+ if (i > 0)
+ ares__buf_consume(buf, i);
+ return i;
+}
+
+
+int ares__buf_begins_with(ares__buf_t *buf, const unsigned char *data,
+ size_t data_len)
+{
+ size_t remaining_len = 0;
+ const unsigned char *ptr = ares__buf_fetch(buf, &remaining_len);
+
+ if (ptr == NULL || data == NULL || data_len == 0)
+ return ARES_EFORMERR;
+
+ if (data_len > remaining_len)
+ return ARES_EBADRESP;
+
+ if (memcmp(ptr, data, data_len) == 0)
+ return ARES_EBADRESP;
+
+ return ARES_SUCCESS;
+}
+
+
+size_t ares__buf_len(const ares__buf_t *buf)
+{
+ size_t len = 0;
+ ares__buf_fetch(buf, &len);
+ return len;
+}
+
+
+const unsigned char *ares__buf_peek(const ares__buf_t *buf, size_t *len)
+{
+ return ares__buf_fetch(buf, len);
+}
+
diff --git a/contrib/libs/c-ares/src/lib/ares__buf.h b/contrib/libs/c-ares/src/lib/ares__buf.h
new file mode 100644
index 0000000000..d81fc26f42
--- /dev/null
+++ b/contrib/libs/c-ares/src/lib/ares__buf.h
@@ -0,0 +1,252 @@
+/* MIT License
+ *
+ * Copyright (c) 2023 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__BUF_H
+#define __ARES__BUF_H
+
+/*! \addtogroup ares__buf Safe Data Builder and buffer
+ *
+ * This is a buffer building and parsing framework with a focus on security over
+ * performance. All data to be read from the buffer will perform explicit length
+ * validation and return a success/fail result. There are also various helpers
+ * for writing data to the buffer which dynamically grows.
+ *
+ * The helpers for this object are meant to be added as needed. If you can't
+ * find it, write it!
+ *
+ * @{
+ */
+struct ares__buf;
+
+/*! Opaque data type for generic hash table implementation */
+typedef struct ares__buf ares__buf_t;
+
+/*! Create a new buffer object that dynamically allocates buffers for data.
+ *
+ * \return initialized buffer object or NULL if out of memory.
+ */
+ares__buf_t *ares__buf_create(void);
+
+/*! Create a new buffer object that uses a user-provided data pointer. The
+ * data provided will not be manipulated, and cannot be appended to. This
+ * is strictly used for parsing.
+ *
+ * \param[in] data Data to provide to buffer, must not be NULL.
+ * \param[in] data_len Size of buffer provided, must be > 0
+ *
+ * \return initialized buffer object or NULL if out of memory or misuse.
+ */
+ares__buf_t *ares__buf_create_const(const unsigned char *data, size_t data_len);
+
+/*! Destroy an initialized buffer object.
+ *
+ * \param[in] buf Initialized buf object
+ */
+void ares__buf_destroy(ares__buf_t *buf);
+
+/*! Append to a dynamic buffer object
+ *
+ * \param[in] buf Initialized buffer object
+ * \param[in] data Data to copy to buffer object
+ * \param[in] data_len Length of data to copy to buffer object.
+ * \return ARES_SUCCESS or one of the c-ares error codes
+ */
+int ares__buf_append(ares__buf_t *buf, const unsigned char *data,
+ size_t data_len);
+
+
+/*! Start a dynamic append operation that returns a buffer suitable for
+ * writing. A desired minimum length is passed in, and the actual allocated
+ * buffer size is returned which may be greater than the requested size.
+ * No operation other than ares__buf_append_finish() is allowed on the
+ * buffer after this request.
+ *
+ * \param[in] buf Initialized buffer object
+ * \param[in,out] len Desired non-zero length passed in, actual buffer size
+ * returned.
+ * \return Pointer to writable buffer or NULL on failure (usage, out of mem)
+ */
+unsigned char *ares__buf_append_start(ares__buf_t *buf, size_t *len);
+
+/*! Finish a dynamic append operation. Called after
+ * ares__buf_append_start() once desired data is written.
+ *
+ * \param[in] buf Initialized buffer object.
+ * \param[in] len Length of data written. May be zero to terminate
+ * operation. Must not be greater than returned from
+ * ares__buf_append_start().
+ */
+void ares__buf_append_finish(ares__buf_t *buf, size_t len);
+
+/*! Clean up ares__buf_t and return allocated pointer to unprocessed data. It
+ * is the responsibility of the caller to ares_free() the returned buffer.
+ * The passed in buf parameter is invalidated by this call.
+ *
+ * \param[in] buf Initialized buffer object. Can not be a "const" buffer.
+ * \param[out] len Length of data returned
+ * \return pointer to unprocessed data or NULL on error.
+ */
+unsigned char *ares__buf_finish_bin(ares__buf_t *buf, size_t *len);
+
+/*! Clean up ares__buf_t and return allocated pointer to unprocessed data and
+ * return it as a string (null terminated). It is the responsibility of the
+ * caller to ares_free() the returned buffer. The passed in buf parameter is
+ * invalidated by this call.
+ *
+ * This function in no way validates the data in this buffer is actually
+ * a string, that characters are printable, or that there aren't multiple
+ * NULL terminators. It is assumed that the caller will either validate that
+ * themselves or has built this buffer with only a valid character set.
+ *
+ * \param[in] buf Initialized buffer object. Can not be a "const" buffer.
+ * \param[out] len Optional. Length of data returned, or NULL if not needed.
+ * \return pointer to unprocessed data or NULL on error.
+ */
+char *ares__buf_finish_str(ares__buf_t *buf, size_t *len);
+
+/*! Tag a position to save in the buffer in case parsing needs to rollback,
+ * such as if insufficient data is available, but more data may be added in
+ * the future. Only a single tag can be set per buffer object. Setting a
+ * tag will override any pre-existing tag.
+ *
+ * \param[in] buf Initialized buffer object
+ */
+void ares__buf_tag(ares__buf_t *buf);
+
+/*! Rollback to a tagged position. Will automatically clear the tag.
+ *
+ * \param[in] buf Initialized buffer object
+ * \return ARES_SUCCESS or one of the c-ares error codes
+ */
+int ares__buf_tag_rollback(ares__buf_t *buf);
+
+/*! Clear the tagged position without rolling back. You should do this any
+ * time a tag is no longer needed as future append operations can reclaim
+ * buffer space.
+ *
+ * \param[in] buf Initialized buffer object
+ * \return ARES_SUCCESS or one of the c-ares error codes
+ */
+int ares__buf_tag_clear(ares__buf_t *buf);
+
+/*! Fetch the buffer and length of data starting from the tagged position up
+ * to the _current_ position. It will not unset the tagged position. The
+ * data may be invalidated by any future ares__buf_*() calls.
+ *
+ * \param[in] buf Initialized buffer object
+ * \param[out] len Length between tag and current offset in buffer
+ * \return NULL on failure (such as no tag), otherwise pointer to start of
+ * buffer
+ */
+const unsigned char *ares__buf_tag_fetch(const ares__buf_t *buf, size_t *len);
+
+/*! Consume the given number of bytes without reading them.
+ *
+ * \param[in] buf Initialized buffer object
+ * \param[in] len Length to consume
+ * \return ARES_SUCCESS or one of the c-ares error codes
+ */
+int ares__buf_consume(ares__buf_t *buf, size_t len);
+
+/*! Fetch a 16bit Big Endian number from the buffer.
+ *
+ * \param[in] buf Initialized buffer object
+ * \param[out] u16 Buffer to hold 16bit integer
+ * \return ARES_SUCCESS or one of the c-ares error codes
+ */
+int ares__buf_fetch_be16(ares__buf_t *buf, unsigned short *u16);
+
+/*! Fetch the requested number of bytes into the provided buffer
+ *
+ * \param[in] buf Initialized buffer object
+ * \param[out] bytes Buffer to hold data
+ * \param[in] len Requested number of bytes (must be > 0)
+ * \return ARES_SUCCESS or one of the c-ares error codes
+ */
+int ares__buf_fetch_bytes(ares__buf_t *buf, unsigned char *bytes,
+ size_t len);
+
+/*! Consume whitespace characters (0x09, 0x0B, 0x0C, 0x0D, 0x20, and optionally
+ * 0x0A).
+ *
+ * \param[in] buf Initialized buffer object
+ * \param[in] include_linefeed 1 to include consuming 0x0A, 0 otherwise.
+ * \return number of whitespace characters consumed
+ */
+size_t ares__buf_consume_whitespace(ares__buf_t *buf, int include_linefeed);
+
+
+/*! Consume any non-whitespace character (anything other than 0x09, 0x0B, 0x0C,
+ * 0x0D, 0x20, and 0x0A).
+ *
+ * \param[in] buf Initialized buffer object
+ * \return number of characters consumed
+ */
+size_t ares__buf_consume_nonwhitespace(ares__buf_t *buf);
+
+/*! Consume from the current position until the end of the line, and optionally
+ * the end of line character (0x0A) itself.
+ *
+ * \param[in] buf Initialized buffer object
+ * \param[in] include_linefeed 1 to include consuming 0x0A, 0 otherwise.
+ * \return number of characters consumed
+ */
+size_t ares__buf_consume_line(ares__buf_t *buf, int include_linefeed);
+
+
+/*! Check the unprocessed buffer to see if it begins with the sequence of
+ * characters provided.
+ *
+ * \param[in] buf Initialized buffer object
+ * \param[in] data Bytes of data to compare.
+ * \param[in] data_len Length of data to compare.
+ * \return ARES_SUCCESS or one of the c-ares error codes
+ */
+int ares__buf_begins_with(ares__buf_t *buf, const unsigned char *data,
+ size_t data_len);
+
+
+/*! Size of unprocessed remaining data length
+ *
+ * \param[in] buf Initialized buffer object
+ * \return length remaining
+ */
+size_t ares__buf_len(const ares__buf_t *buf);
+
+/*! Retrieve a pointer to the currently unprocessed data. Generally this isn't
+ * recommended to be used in practice. The returned pointer may be invalidated
+ * by any future ares__buf_*() calls.
+ *
+ * \param[in] buf Initialized buffer object
+ * \param[out] len Length of available data
+ * \return Pointer to buffer of unprocessed data
+ */
+const unsigned char *ares__buf_peek(const ares__buf_t *buf,
+ size_t *len);
+
+
+/*! @} */
+
+#endif /* __ARES__BUF_H */
diff --git a/contrib/libs/c-ares/src/lib/ares__close_sockets.c b/contrib/libs/c-ares/src/lib/ares__close_sockets.c
index 0477174e3e..fe64e54037 100644
--- a/contrib/libs/c-ares/src/lib/ares__close_sockets.c
+++ b/contrib/libs/c-ares/src/lib/ares__close_sockets.c
@@ -1,61 +1,104 @@
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
+/* MIT License
+ *
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * Copyright (c) The c-ares project and its contributors
+ *
+ * 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:
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * 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_setup.h"
#include "ares.h"
#include "ares_private.h"
+#include <assert.h>
+
-void ares__close_sockets(ares_channel channel, struct server_state *server)
+void ares__close_connection(struct server_connection *conn)
{
- struct send_request *sendreq;
-
- /* Free all pending output buffers. */
- while (server->qhead)
- {
- /* Advance server->qhead; pull out query as we go. */
- sendreq = server->qhead;
- server->qhead = sendreq->next;
- if (sendreq->data_storage != NULL)
- ares_free(sendreq->data_storage);
- ares_free(sendreq);
- }
- server->qtail = NULL;
-
- /* Reset any existing input buffer. */
- if (server->tcp_buffer)
- ares_free(server->tcp_buffer);
- server->tcp_buffer = NULL;
- server->tcp_lenbuf_pos = 0;
-
- /* Reset brokenness */
- server->is_broken = 0;
-
- /* Close the TCP and UDP sockets. */
- if (server->tcp_socket != ARES_SOCKET_BAD)
- {
- SOCK_STATE_CALLBACK(channel, server->tcp_socket, 0, 0);
- ares__close_socket(channel, server->tcp_socket);
- server->tcp_socket = ARES_SOCKET_BAD;
- server->tcp_connection_generation = ++channel->tcp_connection_generation;
- }
- if (server->udp_socket != ARES_SOCKET_BAD)
- {
- SOCK_STATE_CALLBACK(channel, server->udp_socket, 0, 0);
- ares__close_socket(channel, server->udp_socket);
- server->udp_socket = ARES_SOCKET_BAD;
- }
+ struct server_state *server = conn->server;
+ ares_channel channel = server->channel;
+
+ if (conn->is_tcp) {
+ /* Reset any existing input and output buffer. */
+ ares__buf_consume(server->tcp_parser, ares__buf_len(server->tcp_parser));
+ ares__buf_consume(server->tcp_send, ares__buf_len(server->tcp_send));
+ server->tcp_connection_generation = ++channel->tcp_connection_generation;
+ server->tcp_conn = NULL;
+ }
+
+
+ SOCK_STATE_CALLBACK(channel, conn->fd, 0, 0);
+ ares__close_socket(channel, conn->fd);
+ ares__llist_node_claim(
+ ares__htable_asvp_get_direct(channel->connnode_by_socket, conn->fd)
+ );
+ ares__htable_asvp_remove(channel->connnode_by_socket, conn->fd);
+
+#ifndef NDEBUG
+ assert(ares__llist_len(conn->queries_to_conn) == 0);
+#endif
+ ares__llist_destroy(conn->queries_to_conn);
+ ares_free(conn);
+}
+
+void ares__close_sockets(struct server_state *server)
+{
+ ares__llist_node_t *node;
+
+ while ((node = ares__llist_node_first(server->connections)) != NULL) {
+ struct server_connection *conn = ares__llist_node_val(node);
+ ares__close_connection(conn);
+ }
+}
+
+void ares__check_cleanup_conn(ares_channel channel, ares_socket_t fd)
+{
+ ares__llist_node_t *node;
+ struct server_connection *conn;
+ int do_cleanup = 0;
+
+ node = ares__htable_asvp_get_direct(channel->connnode_by_socket, fd);
+ if (node == NULL) {
+ return;
+ }
+
+ conn = ares__llist_node_val(node);
+
+ if (ares__llist_len(conn->queries_to_conn)) {
+ return;
+ }
+
+ /* If we are configured not to stay open, close it out */
+ if (!(channel->flags & ARES_FLAG_STAYOPEN)) {
+ do_cleanup = 1;
+ }
+
+ /* If the udp connection hit its max queries, always close it */
+ if (!conn->is_tcp && channel->udp_max_queries > 0 &&
+ conn->total_queries >= (size_t)channel->udp_max_queries) {
+ do_cleanup = 1;
+ }
+
+ if (do_cleanup) {
+ ares__close_connection(conn);
+ }
}
diff --git a/contrib/libs/c-ares/src/lib/ares__get_hostent.c b/contrib/libs/c-ares/src/lib/ares__get_hostent.c
index 367f39037b..8ac2425ed4 100644
--- a/contrib/libs/c-ares/src/lib/ares__get_hostent.c
+++ b/contrib/libs/c-ares/src/lib/ares__get_hostent.c
@@ -1,17 +1,28 @@
-
-/* Copyright 1998, 2011 by the Massachusetts Institute of Technology.
+/* MIT License
+ *
+ * Copyright (c) 1998, 2011 Massachusetts Institute of Technology
+ * Copyright (c) The c-ares project and its contributors
+ *
+ * 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.
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * SPDX-License-Identifier: MIT
*/
#include "ares_setup.h"
diff --git a/contrib/libs/c-ares/src/lib/ares__htable.c b/contrib/libs/c-ares/src/lib/ares__htable.c
new file mode 100644
index 0000000000..3ea65642d9
--- /dev/null
+++ b/contrib/libs/c-ares/src/lib/ares__htable.c
@@ -0,0 +1,374 @@
+/* MIT License
+ *
+ * Copyright (c) 2023 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_setup.h"
+#include "ares.h"
+#include "ares_private.h"
+#include "ares__llist.h"
+#include "ares__htable.h"
+
+#define ARES__HTABLE_MAX_BUCKETS (1U<<24)
+#define ARES__HTABLE_MIN_BUCKETS (1U<<4)
+#define ARES__HTABLE_EXPAND_PERCENT 75
+
+struct ares__htable {
+ ares__htable_hashfunc_t hash;
+ ares__htable_bucket_key_t bucket_key;
+ ares__htable_bucket_free_t bucket_free;
+ ares__htable_key_eq_t key_eq;
+ unsigned int seed;
+ unsigned int size;
+ size_t num_keys;
+ /* NOTE: if we converted buckets into ares__slist_t we could guarantee on
+ * hash collisions we would have O(log n) worst case insert and search
+ * performance. (We'd also need to make key_eq into a key_cmp to
+ * support sort). That said, risk with a random hash seed is near zero,
+ * and ares__slist_t is heavier weight so I think using ares__llist_t is
+ * is an overall win. */
+ ares__llist_t **buckets;
+};
+
+
+static unsigned int ares__htable_generate_seed(ares__htable_t *htable)
+{
+ unsigned int seed = 0;
+
+ /* Mix stack address, heap address, and time to generate a random seed, it
+ * doesn't have to be super secure, just quick. Likelihood of a hash
+ * collision attack is very low with a small amount of effort */
+ seed |= (unsigned int)((size_t)htable & 0xFFFFFFFF);
+ seed |= (unsigned int)((size_t)&seed & 0xFFFFFFFF);
+ seed |= (unsigned int)time(NULL) & 0xFFFFFFFF;
+ return seed;
+}
+
+static void ares__htable_buckets_destroy(ares__llist_t **buckets,
+ unsigned int size,
+ unsigned char destroy_vals)
+{
+ unsigned int i;
+
+ if (buckets == NULL)
+ return;
+
+ for (i=0; i<size; i++) {
+ if (buckets[i] == NULL)
+ continue;
+
+ if (!destroy_vals)
+ ares__llist_replace_destructor(buckets[i], NULL);
+
+ ares__llist_destroy(buckets[i]);
+ }
+
+ ares_free(buckets);
+}
+
+
+void ares__htable_destroy(ares__htable_t *htable)
+{
+ if (htable == NULL)
+ return;
+ ares__htable_buckets_destroy(htable->buckets, htable->size, 1);
+ ares_free(htable);
+}
+
+
+ares__htable_t *ares__htable_create(ares__htable_hashfunc_t hash_func,
+ ares__htable_bucket_key_t bucket_key,
+ ares__htable_bucket_free_t bucket_free,
+ ares__htable_key_eq_t key_eq)
+{
+ ares__htable_t *htable = NULL;
+
+ if (hash_func == NULL || bucket_key == NULL || bucket_free == NULL ||
+ key_eq == NULL) {
+ goto fail;
+ }
+
+ htable = ares_malloc(sizeof(*htable));
+ if (htable == NULL)
+ goto fail;
+
+ memset(htable, 0, sizeof(*htable));
+
+ htable->hash = hash_func;
+ htable->bucket_key = bucket_key;
+ htable->bucket_free = bucket_free;
+ htable->key_eq = key_eq;
+ htable->seed = ares__htable_generate_seed(htable);
+ htable->size = ARES__HTABLE_MIN_BUCKETS;
+ htable->buckets = ares_malloc(sizeof(*htable->buckets) * htable->size);
+
+ if (htable->buckets == NULL)
+ goto fail;
+
+ memset(htable->buckets, 0, sizeof(*htable->buckets) * htable->size);
+
+ return htable;
+
+fail:
+ ares__htable_destroy(htable);
+ return NULL;
+}
+
+
+/*! Grabs the Hashtable index from the key and length. The h index is
+ * the hash of the function reduced to the size of the bucket list.
+ * We are doing "hash & (size - 1)" since we are guaranteeing a power of
+ * 2 for size. This is equivalent to "hash % size", but should be more
+ * efficient */
+#define HASH_IDX(h, key) h->hash(key, h->seed) & (h->size - 1)
+
+static ares__llist_node_t *ares__htable_find(ares__htable_t *htable,
+ unsigned int idx,
+ const void *key)
+{
+ ares__llist_node_t *node = NULL;
+
+ for (node = ares__llist_node_first(htable->buckets[idx]);
+ node != NULL;
+ node = ares__llist_node_next(node)) {
+
+ if (htable->key_eq(key, htable->bucket_key(ares__llist_node_val(node))))
+ break;
+ }
+
+ return node;
+}
+
+
+static unsigned int ares__htable_expand(ares__htable_t *htable)
+{
+ ares__llist_t **buckets = NULL;
+ unsigned int old_size = htable->size;
+ size_t i;
+
+ /* Not a failure, just won't expand */
+ if (old_size == ARES__HTABLE_MAX_BUCKETS)
+ return 1;
+
+ htable->size <<= 1;
+
+ /* We must do this in 2 passes as we want it to be non-destructive in case
+ * there is a memory allocation failure. So we will actually use more
+ * memory doing it this way, but at least we might be able to gracefully
+ * recover */
+ buckets = ares_malloc(sizeof(*buckets) * htable->size);
+ if (buckets == NULL)
+ goto fail;
+
+ memset(buckets, 0, sizeof(*buckets) * htable->size);
+
+ for (i=0; i<old_size; i++) {
+ ares__llist_node_t *node;
+ for (node = ares__llist_node_first(htable->buckets[i]);
+ node != NULL;
+ node = ares__llist_node_next(node)) {
+
+ void *val = ares__llist_node_val(node);
+ size_t idx = HASH_IDX(htable, htable->bucket_key(val));
+
+ if (buckets[idx] == NULL) {
+ buckets[idx] = ares__llist_create(htable->bucket_free);
+ if (buckets[idx] == NULL)
+ goto fail;
+ }
+
+ if (ares__llist_insert_first(buckets[idx], val) == NULL) {
+ goto fail;
+ }
+
+ }
+ }
+
+ /* Swap out buckets */
+ ares__htable_buckets_destroy(htable->buckets, old_size, 0);
+ htable->buckets = buckets;
+ return 1;
+
+fail:
+ ares__htable_buckets_destroy(buckets, htable->size, 0);
+ htable->size = old_size;
+
+ return 0;
+}
+
+
+unsigned int ares__htable_insert(ares__htable_t *htable, void *bucket)
+{
+ unsigned int idx = 0;
+ ares__llist_node_t *node = NULL;
+ const void *key = NULL;
+
+ if (htable == NULL || bucket == NULL)
+ return 0;
+
+
+ key = htable->bucket_key(bucket);
+ idx = HASH_IDX(htable, key);
+
+ /* See if we have a matching bucket already, if so, replace it */
+ node = ares__htable_find(htable, idx, key);
+ if (node != NULL) {
+ ares__llist_node_replace(node, bucket);
+ return 1;
+ }
+
+ /* Check to see if we should rehash because likelihood of collisions has
+ * increased beyond our threshold */
+ if (htable->num_keys+1 > (htable->size * ARES__HTABLE_EXPAND_PERCENT) / 100) {
+ if (!ares__htable_expand(htable)) {
+ return 0;
+ }
+ /* If we expanded, need to calculate a new index */
+ idx = HASH_IDX(htable, key);
+ }
+
+ /* We lazily allocate the linked list */
+ if (htable->buckets[idx] == NULL) {
+ htable->buckets[idx] = ares__llist_create(htable->bucket_free);
+ if (htable->buckets[idx] == NULL)
+ return 0;
+ }
+
+ node = ares__llist_insert_first(htable->buckets[idx], bucket);
+ if (node == NULL)
+ return 0;
+
+ htable->num_keys++;
+
+ return 1;
+}
+
+
+void *ares__htable_get(ares__htable_t *htable, const void *key)
+{
+ unsigned int idx;
+
+ if (htable == NULL || key == NULL)
+ return NULL;
+
+ idx = HASH_IDX(htable, key);
+
+ return ares__llist_node_val(ares__htable_find(htable, idx, key));
+}
+
+
+unsigned int ares__htable_remove(ares__htable_t *htable, const void *key)
+{
+ ares__llist_node_t *node;
+ unsigned int idx;
+
+ if (htable == NULL || key == NULL)
+ return 0;
+
+ idx = HASH_IDX(htable, key);
+ node = ares__htable_find(htable, idx, key);
+ if (node == NULL)
+ return 0;
+
+ htable->num_keys--;
+ ares__llist_node_destroy(node);
+ return 1;
+}
+
+size_t ares__htable_num_keys(ares__htable_t *htable)
+{
+ if (htable == NULL)
+ return 0;
+ return htable->num_keys;
+}
+
+unsigned int ares__htable_hash_FNV1a(const unsigned char *key, size_t key_len,
+ unsigned int seed)
+{
+ /* recommended seed is 2166136261U, but we don't want collisions */
+ unsigned int hv = seed;
+ size_t i;
+
+ for (i = 0; i < key_len; i++) {
+ hv ^= (unsigned int)key[i];
+ /* hv *= 0x01000193 */
+ hv += (hv<<1) + (hv<<4) + (hv<<7) + (hv<<8) + (hv<<24);
+ }
+
+ return hv;
+}
+
+/* tolower() is locale-specific. Use a lookup table fast conversion that only
+ * operates on ASCII */
+static const unsigned char ares__tolower_lookup[] = {
+ 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
+ 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,
+ 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,
+ 0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,
+ 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,
+ 0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,
+ 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,
+ 0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,
+ 0x40,0x61,0x62,0x63,0x64,0x65,0x66,0x67,
+ 0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,
+ 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,
+ 0x78,0x79,0x7A,0x5B,0x5C,0x5D,0x5E,0x5F,
+ 0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,
+ 0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,
+ 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,
+ 0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,
+ 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,
+ 0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,
+ 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,
+ 0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F,
+ 0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,
+ 0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,
+ 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,
+ 0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF,
+ 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,
+ 0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,
+ 0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,
+ 0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF,
+ 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,
+ 0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,
+ 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,
+ 0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF
+};
+
+
+/* Case insensitive version, meant for ASCII strings */
+unsigned int ares__htable_hash_FNV1a_casecmp(const unsigned char *key, size_t key_len,
+ unsigned int seed)
+{
+ /* recommended seed is 2166136261U, but we don't want collisions */
+ unsigned int hv = seed;
+ size_t i;
+
+ for (i = 0; i < key_len; i++) {
+ hv ^= (unsigned int)ares__tolower_lookup[key[i]];
+ /* hv *= 0x01000193 */
+ hv += (hv<<1) + (hv<<4) + (hv<<7) + (hv<<8) + (hv<<24);
+ }
+
+ return hv;
+}
diff --git a/contrib/libs/c-ares/src/lib/ares__htable.h b/contrib/libs/c-ares/src/lib/ares__htable.h
new file mode 100644
index 0000000000..bbd36f779b
--- /dev/null
+++ b/contrib/libs/c-ares/src/lib/ares__htable.h
@@ -0,0 +1,164 @@
+/* MIT License
+ *
+ * Copyright (c) 2023 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__HTABLE_H
+#define __ARES__HTABLE_H
+
+
+/*! \addtogroup ares__htable Base HashTable Data Structure
+ *
+ * This is a basic hashtable data structure that is meant to be wrapped
+ * by a higher level implementation. This data structure is designed to
+ * be callback-based in order to facilitate wrapping without needing to
+ * worry about any underlying complexities of the hashtable implementation.
+ *
+ * This implementation supports automatic growing by powers of 2 when reaching
+ * 75% capacity. A rehash will be performed on the expanded bucket list.
+ *
+ * Average time complexity:
+ * - Insert: O(1)
+ * - Search: O(1)
+ * - Delete: O(1)
+ *
+ * @{
+ */
+
+struct ares__htable_t;
+
+/*! Opaque data type for generic hash table implementation */
+typedef struct ares__htable ares__htable_t;
+
+/*! Callback for generating a hash of the key.
+ *
+ * \param[in] key pointer to key to be hashed
+ * \param[in] seed randomly generated seed used by hash function.
+ * value is specific to the hashtable instance
+ * but otherwise will not change between calls.
+ * \return hash
+ */
+typedef unsigned int (*ares__htable_hashfunc_t)(const void *key,
+ unsigned int seed);
+
+/*! Callback to free the bucket
+ *
+ * \param[in] bucket user provided bucket
+ */
+typedef void (*ares__htable_bucket_free_t)(void *bucket);
+
+/*! Callback to extract the key from the user-provided bucket
+ *
+ * \param[in] bucket user provided bucket
+ * \return pointer to key held in bucket
+ */
+typedef const void *(*ares__htable_bucket_key_t)(const void *bucket);
+
+/*! Callback to compare two keys for equality
+ *
+ * \param[in] key1 first key
+ * \param[in] key2 second key
+ * \return 1 if equal, 0 if not
+ */
+typedef unsigned int (*ares__htable_key_eq_t)(const void *key1,
+ const void *key2);
+
+
+/*! Destroy the initialized hashtable
+ *
+ * \param[in] initialized hashtable
+ */
+void ares__htable_destroy(ares__htable_t *htable);
+
+/*! Create a new hashtable
+ *
+ * \param[in] hash_func Required. Callback for Hash function.
+ * \param[in] bucket_key Required. Callback to extract key from bucket.
+ * \param[in] bucket_free Required. Callback to free bucket.
+ * \param[in] key_eq Required. Callback to check for key equality.
+ * \return initialized hashtable. NULL if out of memory or misuse.
+ */
+ares__htable_t *ares__htable_create(ares__htable_hashfunc_t hash_func,
+ ares__htable_bucket_key_t bucket_key,
+ ares__htable_bucket_free_t bucket_free,
+ ares__htable_key_eq_t key_eq);
+
+/*! Count of keys from initialized hashtable
+ *
+ * \param[in] htable Initialized hashtable.
+ * \return count of keys
+ */
+size_t ares__htable_num_keys(ares__htable_t *htable);
+
+/*! Insert bucket into hashtable
+ *
+ * \param[in] htable Initialized hashtable.
+ * \param[in] bucket User-provided bucket to insert. Takes "ownership". Not
+ * allowed to be NULL.
+ * \return 1 on success, 0 if out of memory
+ */
+unsigned int ares__htable_insert(ares__htable_t *htable, void *bucket);
+
+/*! Retrieve bucket from hashtable based on key.
+ *
+ * \param[in] htable Initialized hashtable
+ * \param[in] key Pointer to key to use for comparison.
+ * \return matching bucket, or NULL if not found.
+ */
+void *ares__htable_get(ares__htable_t *htable, const void *key);
+
+/*! Remove bucket from hashtable by key
+ *
+ * \param[in] htable Initialized hashtable
+ * \param[in] key Pointer to key to use for comparison
+ * \return 1 if found, 0 if not found
+ */
+unsigned int ares__htable_remove(ares__htable_t *htable, const void *key);
+
+/*! FNV1a hash algorithm. Can be used as underlying primitive for building
+ * a wrapper hashtable.
+ *
+ * \param[in] key pointer to key
+ * \param[in] key_len Length of key
+ * \param[in] seed Seed for generating hash
+ * \return hash value
+ */
+unsigned int ares__htable_hash_FNV1a(const unsigned char *key, size_t key_len,
+ unsigned int seed);
+
+/*! FNV1a hash algorithm, but converts all characters to lowercase before
+ * hashing to make the hash case-insensitive. Can be used as underlying
+ * primitive for building a wrapper hashtable. Used on string-based keys.
+ *
+ * \param[in] key pointer to key
+ * \param[in] key_len Length of key
+ * \param[in] seed Seed for generating hash
+ * \return hash value
+ */
+unsigned int ares__htable_hash_FNV1a_casecmp(const unsigned char *key,
+ size_t key_len,
+ unsigned int seed);
+
+/*! @} */
+
+#endif /* __ARES__HTABLE_H */
diff --git a/contrib/libs/c-ares/src/lib/ares__htable_asvp.c b/contrib/libs/c-ares/src/lib/ares__htable_asvp.c
new file mode 100644
index 0000000000..7026524159
--- /dev/null
+++ b/contrib/libs/c-ares/src/lib/ares__htable_asvp.c
@@ -0,0 +1,195 @@
+/* MIT License
+ *
+ * Copyright (c) 2023 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_setup.h"
+#include "ares.h"
+#include "ares_private.h"
+#include "ares__htable.h"
+#include "ares__htable_asvp.h"
+
+
+struct ares__htable_asvp {
+ ares__htable_asvp_val_free_t free_val;
+ ares__htable_t *hash;
+};
+
+
+typedef struct {
+ ares_socket_t key;
+ void *val;
+ ares__htable_asvp_t *parent;
+} ares__htable_asvp_bucket_t;
+
+
+void ares__htable_asvp_destroy(ares__htable_asvp_t *htable)
+{
+ if (htable == NULL)
+ return;
+
+ ares__htable_destroy(htable->hash);
+ ares_free(htable);
+}
+
+
+static unsigned int hash_func(const void *key, unsigned int seed)
+{
+ const ares_socket_t *arg = key;
+ return ares__htable_hash_FNV1a((const unsigned char *)arg, sizeof(*arg),
+ seed);
+}
+
+
+static const void *bucket_key(const void *bucket)
+{
+ const ares__htable_asvp_bucket_t *arg = bucket;
+ return &arg->key;
+}
+
+
+static void bucket_free(void *bucket)
+{
+ ares__htable_asvp_bucket_t *arg = bucket;
+
+ if (arg->parent->free_val)
+ arg->parent->free_val(arg->val);
+
+ ares_free(arg);
+}
+
+
+static unsigned int key_eq(const void *key1, const void *key2)
+{
+ const ares_socket_t *k1 = key1;
+ const ares_socket_t *k2 = key2;
+
+ if (*k1 == *k2)
+ return 1;
+
+ return 0;
+}
+
+
+ares__htable_asvp_t *ares__htable_asvp_create(
+ ares__htable_asvp_val_free_t val_free)
+{
+ ares__htable_asvp_t *htable = ares_malloc(sizeof(*htable));
+ if (htable == NULL)
+ goto fail;
+
+ htable->hash = ares__htable_create(hash_func,
+ bucket_key,
+ bucket_free,
+ key_eq);
+ if (htable->hash == NULL)
+ goto fail;
+
+ htable->free_val = val_free;
+
+ return htable;
+
+fail:
+ if (htable) {
+ ares__htable_destroy(htable->hash);
+ ares_free(htable);
+ }
+ return NULL;
+}
+
+
+unsigned int ares__htable_asvp_insert(ares__htable_asvp_t *htable,
+ ares_socket_t key, void *val)
+{
+ ares__htable_asvp_bucket_t *bucket = NULL;
+
+ if (htable == NULL)
+ goto fail;
+
+ bucket = ares_malloc(sizeof(*bucket));
+ if (bucket == NULL)
+ goto fail;
+
+ bucket->parent = htable;
+ bucket->key = key;
+ bucket->val = val;
+
+ if (!ares__htable_insert(htable->hash, bucket))
+ goto fail;
+
+ return 1;
+
+fail:
+ if (bucket) {
+ ares_free(bucket);
+ }
+ return 0;
+}
+
+
+unsigned int ares__htable_asvp_get(ares__htable_asvp_t *htable,
+ ares_socket_t key, void **val)
+{
+ ares__htable_asvp_bucket_t *bucket = NULL;
+
+ if (val)
+ *val = NULL;
+
+ if (htable == NULL)
+ return 0;
+
+ bucket = ares__htable_get(htable->hash, &key);
+ if (bucket == NULL)
+ return 0;
+
+ if (val)
+ *val = bucket->val;
+ return 1;
+}
+
+
+void *ares__htable_asvp_get_direct(ares__htable_asvp_t *htable,
+ ares_socket_t key)
+{
+ void *val = NULL;
+ ares__htable_asvp_get(htable, key, &val);
+ return val;
+}
+
+
+unsigned int ares__htable_asvp_remove(ares__htable_asvp_t *htable,
+ ares_socket_t key)
+{
+ if (htable == NULL)
+ return 0;
+
+ return ares__htable_remove(htable->hash, &key);
+}
+
+
+size_t ares__htable_asvp_num_keys(ares__htable_asvp_t *htable)
+{
+ if (htable == NULL)
+ return 0;
+ return ares__htable_num_keys(htable->hash);
+}
diff --git a/contrib/libs/c-ares/src/lib/ares__htable_asvp.h b/contrib/libs/c-ares/src/lib/ares__htable_asvp.h
new file mode 100644
index 0000000000..f53b2775e0
--- /dev/null
+++ b/contrib/libs/c-ares/src/lib/ares__htable_asvp.h
@@ -0,0 +1,120 @@
+/* MIT License
+ *
+ * Copyright (c) 2023 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__HTABLE_ASVP_H
+#define __ARES__HTABLE_ASVP_H
+
+/*! \addtogroup ares__htable_asvp HashTable with ares_socket_t Key and
+ * void pointer Value
+ *
+ * This data structure wraps the base ares__htable data structure in order to
+ * split the key and value data types as ares_socket_t and void pointer,
+ * respectively.
+ *
+ * Average time complexity:
+ * - Insert: O(1)
+ * - Search: O(1)
+ * - Delete: O(1)
+ *
+ * @{
+ */
+
+struct ares__htable_asvp;
+
+/*! Opaque data type for ares_socket_t key, void pointer hash table
+ * implementation */
+typedef struct ares__htable_asvp ares__htable_asvp_t;
+
+/*! Callback to free value stored in hashtable
+ *
+ * \param[in] val user-supplied value
+ */
+typedef void (*ares__htable_asvp_val_free_t)(void *val);
+
+/*! Destroy hashtable
+ *
+ * \param[in] htable Initialized hashtable
+ */
+void ares__htable_asvp_destroy(ares__htable_asvp_t *htable);
+
+/*! Create size_t key, void pointer value hash table
+ *
+ * \param[in] val_free Optional. Call back to free user-supplied value. If
+ * NULL it is expected the caller will clean up any user
+ * supplied values.
+ */
+ares__htable_asvp_t *ares__htable_asvp_create(
+ ares__htable_asvp_val_free_t val_free);
+
+/*! Insert key/value into hash table
+ *
+ * \param[in] htable Initialized hash table
+ * \param[in] key key to associate with value
+ * \param[in] val value to store (takes ownership). May be NULL.
+ * \return 1 on success, 0 on out of memory or misuse
+ */
+unsigned int ares__htable_asvp_insert(ares__htable_asvp_t *htable,
+ ares_socket_t key, void *val);
+
+/*! Retrieve value from hashtable based on key
+ *
+ * \param[in] htable Initialized hash table
+ * \param[in] key key to use to search
+ * \param[out] val Optional. Pointer to store value.
+ * \return 1 on success, 0 on failure
+ */
+unsigned int ares__htable_asvp_get(ares__htable_asvp_t *htable,
+ ares_socket_t key, void **val);
+
+/*! Retrieve value from hashtable directly as return value. Caveat to this
+ * function over ares__htable_asvp_get() is that if a NULL value is stored
+ * you cannot determine if the key is not found or the value is NULL.
+ *
+ * \param[in] htable Initialized hash table
+ * \param[in] key key to use to search
+ * \return value associated with key in hashtable or NULL
+ */
+void *ares__htable_asvp_get_direct(ares__htable_asvp_t *htable,
+ ares_socket_t key);
+
+/*! Remove a value from the hashtable by key
+ *
+ * \param[in] htable Initialized hash table
+ * \param[in] key key to use to search
+ * \return 1 if found, 0 if not
+ */
+unsigned int ares__htable_asvp_remove(ares__htable_asvp_t *htable,
+ ares_socket_t key);
+
+/*! Retrieve the number of keys stored in the hash table
+ *
+ * \param[in] htable Initialized hash table
+ * \return count
+ */
+size_t ares__htable_asvp_num_keys(ares__htable_asvp_t *htable);
+
+/*! @} */
+
+#endif /* __ARES__HTABLE_ASVP_H */
diff --git a/contrib/libs/c-ares/src/lib/ares__htable_stvp.c b/contrib/libs/c-ares/src/lib/ares__htable_stvp.c
new file mode 100644
index 0000000000..7a4cd40a76
--- /dev/null
+++ b/contrib/libs/c-ares/src/lib/ares__htable_stvp.c
@@ -0,0 +1,193 @@
+/* MIT License
+ *
+ * Copyright (c) 2023 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_setup.h"
+#include "ares.h"
+#include "ares_private.h"
+#include "ares__htable.h"
+#include "ares__htable_stvp.h"
+
+
+struct ares__htable_stvp {
+ ares__htable_stvp_val_free_t free_val;
+ ares__htable_t *hash;
+};
+
+
+typedef struct {
+ size_t key;
+ void *val;
+ ares__htable_stvp_t *parent;
+} ares__htable_stvp_bucket_t;
+
+
+void ares__htable_stvp_destroy(ares__htable_stvp_t *htable)
+{
+ if (htable == NULL)
+ return;
+
+ ares__htable_destroy(htable->hash);
+ ares_free(htable);
+}
+
+
+static unsigned int hash_func(const void *key, unsigned int seed)
+{
+ const size_t *arg = key;
+ return ares__htable_hash_FNV1a((const unsigned char *)arg, sizeof(*arg),
+ seed);
+}
+
+
+static const void *bucket_key(const void *bucket)
+{
+ const ares__htable_stvp_bucket_t *arg = bucket;
+ return &arg->key;
+}
+
+
+static void bucket_free(void *bucket)
+{
+ ares__htable_stvp_bucket_t *arg = bucket;
+
+ if (arg->parent->free_val)
+ arg->parent->free_val(arg->val);
+
+ ares_free(arg);
+}
+
+
+static unsigned int key_eq(const void *key1, const void *key2)
+{
+ const size_t *k1 = key1;
+ const size_t *k2 = key2;
+
+ if (*k1 == *k2)
+ return 1;
+
+ return 0;
+}
+
+
+ares__htable_stvp_t *ares__htable_stvp_create(
+ ares__htable_stvp_val_free_t val_free)
+{
+ ares__htable_stvp_t *htable = ares_malloc(sizeof(*htable));
+ if (htable == NULL)
+ goto fail;
+
+ htable->hash = ares__htable_create(hash_func,
+ bucket_key,
+ bucket_free,
+ key_eq);
+ if (htable->hash == NULL)
+ goto fail;
+
+ htable->free_val = val_free;
+
+ return htable;
+
+fail:
+ if (htable) {
+ ares__htable_destroy(htable->hash);
+ ares_free(htable);
+ }
+ return NULL;
+}
+
+
+unsigned int ares__htable_stvp_insert(ares__htable_stvp_t *htable, size_t key,
+ void *val)
+{
+ ares__htable_stvp_bucket_t *bucket = NULL;
+
+ if (htable == NULL)
+ goto fail;
+
+ bucket = ares_malloc(sizeof(*bucket));
+ if (bucket == NULL)
+ goto fail;
+
+ bucket->parent = htable;
+ bucket->key = key;
+ bucket->val = val;
+
+ if (!ares__htable_insert(htable->hash, bucket))
+ goto fail;
+
+ return 1;
+
+fail:
+ if (bucket) {
+ ares_free(bucket);
+ }
+ return 0;
+}
+
+
+unsigned int ares__htable_stvp_get(ares__htable_stvp_t *htable, size_t key,
+ void **val)
+{
+ ares__htable_stvp_bucket_t *bucket = NULL;
+
+ if (val)
+ *val = NULL;
+
+ if (htable == NULL)
+ return 0;
+
+ bucket = ares__htable_get(htable->hash, &key);
+ if (bucket == NULL)
+ return 0;
+
+ if (val)
+ *val = bucket->val;
+ return 1;
+}
+
+
+void *ares__htable_stvp_get_direct(ares__htable_stvp_t *htable, size_t key)
+{
+ void *val = NULL;
+ ares__htable_stvp_get(htable, key, &val);
+ return val;
+}
+
+
+unsigned int ares__htable_stvp_remove(ares__htable_stvp_t *htable, size_t key)
+{
+ if (htable == NULL)
+ return 0;
+
+ return ares__htable_remove(htable->hash, &key);
+}
+
+
+size_t ares__htable_stvp_num_keys(ares__htable_stvp_t *htable)
+{
+ if (htable == NULL)
+ return 0;
+ return ares__htable_num_keys(htable->hash);
+}
diff --git a/contrib/libs/c-ares/src/lib/ares__htable_stvp.h b/contrib/libs/c-ares/src/lib/ares__htable_stvp.h
new file mode 100644
index 0000000000..11d9d5ed4c
--- /dev/null
+++ b/contrib/libs/c-ares/src/lib/ares__htable_stvp.h
@@ -0,0 +1,115 @@
+/* MIT License
+ *
+ * Copyright (c) 2023 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__HTABLE_STVP_H
+#define __ARES__HTABLE_STVP_H
+
+/*! \addtogroup ares__htable_stvp HashTable with size_t Key and void pointer Value
+ *
+ * This data structure wraps the base ares__htable data structure in order to
+ * split the key and value data types as size_t and void pointer, respectively.
+ *
+ * Average time complexity:
+ * - Insert: O(1)
+ * - Search: O(1)
+ * - Delete: O(1)
+ *
+ * @{
+ */
+
+struct ares__htable_stvp;
+
+/*! Opaque data type for size_t key, void pointer hash table implementation */
+typedef struct ares__htable_stvp ares__htable_stvp_t;
+
+/*! Callback to free value stored in hashtable
+ *
+ * \param[in] val user-supplied value
+ */
+typedef void (*ares__htable_stvp_val_free_t)(void *val);
+
+/*! Destroy hashtable
+ *
+ * \param[in] htable Initialized hashtable
+ */
+void ares__htable_stvp_destroy(ares__htable_stvp_t *htable);
+
+/*! Create size_t key, void pointer value hash table
+ *
+ * \param[in] val_free Optional. Call back to free user-supplied value. If
+ * NULL it is expected the caller will clean up any user
+ * supplied values.
+ */
+ares__htable_stvp_t *ares__htable_stvp_create(
+ ares__htable_stvp_val_free_t val_free);
+
+/*! Insert key/value into hash table
+ *
+ * \param[in] htable Initialized hash table
+ * \param[in] key key to associate with value
+ * \param[in] val value to store (takes ownership). May be NULL.
+ * \return 1 on success, 0 on out of memory or misuse
+ */
+unsigned int ares__htable_stvp_insert(ares__htable_stvp_t *htable, size_t key,
+ void *val);
+
+/*! Retrieve value from hashtable based on key
+ *
+ * \param[in] htable Initialized hash table
+ * \param[in] key key to use to search
+ * \param[out] val Optional. Pointer to store value.
+ * \return 1 on success, 0 on failure
+ */
+unsigned int ares__htable_stvp_get(ares__htable_stvp_t *htable, size_t key,
+ void **val);
+
+/*! Retrieve value from hashtable directly as return value. Caveat to this
+ * function over ares__htable_stvp_get() is that if a NULL value is stored
+ * you cannot determine if the key is not found or the value is NULL.
+ *
+ * \param[in] htable Initialized hash table
+ * \param[in] key key to use to search
+ * \return value associated with key in hashtable or NULL
+ */
+void *ares__htable_stvp_get_direct(ares__htable_stvp_t *htable, size_t key);
+
+/*! Remove a value from the hashtable by key
+ *
+ * \param[in] htable Initialized hash table
+ * \param[in] key key to use to search
+ * \return 1 if found, 0 if not
+ */
+unsigned int ares__htable_stvp_remove(ares__htable_stvp_t *htable, size_t key);
+
+/*! Retrieve the number of keys stored in the hash table
+ *
+ * \param[in] htable Initialized hash table
+ * \return count
+ */
+size_t ares__htable_stvp_num_keys(ares__htable_stvp_t *htable);
+
+/*! @} */
+
+#endif /* __ARES__HTABLE_STVP_H */
diff --git a/contrib/libs/c-ares/src/lib/ares__llist.c b/contrib/libs/c-ares/src/lib/ares__llist.c
new file mode 100644
index 0000000000..9ccda81a6a
--- /dev/null
+++ b/contrib/libs/c-ares/src/lib/ares__llist.c
@@ -0,0 +1,316 @@
+/* MIT License
+ *
+ * Copyright (c) 2023 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_setup.h"
+#include "ares.h"
+#include "ares_private.h"
+#include "ares__llist.h"
+
+struct ares__llist {
+ ares__llist_node_t *head;
+ ares__llist_node_t *tail;
+ ares__llist_destructor_t destruct;
+ size_t cnt;
+};
+
+
+struct ares__llist_node {
+ void *data;
+ ares__llist_node_t *prev;
+ ares__llist_node_t *next;
+ ares__llist_t *parent;
+};
+
+
+ares__llist_t *ares__llist_create(ares__llist_destructor_t destruct)
+{
+ ares__llist_t *list = ares_malloc(sizeof(*list));
+
+ if (list == NULL)
+ return NULL;
+
+ memset(list, 0, sizeof(*list));
+
+ list->destruct = destruct;
+
+ return list;
+}
+
+
+void ares__llist_replace_destructor(ares__llist_t *list,
+ ares__llist_destructor_t destruct)
+{
+ if (list == NULL)
+ return;
+
+ list->destruct = destruct;
+}
+
+
+typedef enum {
+ ARES__LLIST_INSERT_HEAD,
+ ARES__LLIST_INSERT_TAIL,
+ ARES__LLIST_INSERT_BEFORE
+} ares__llist_insert_type_t;
+
+
+static ares__llist_node_t *ares__llist_insert_at(ares__llist_t *list,
+ ares__llist_insert_type_t type,
+ ares__llist_node_t *at,
+ void *val)
+{
+ ares__llist_node_t *node = NULL;
+
+ if (list == NULL || val == NULL)
+ return NULL;
+
+ node = ares_malloc(sizeof(*node));
+
+ if (node == NULL)
+ return NULL;
+
+ memset(node, 0, sizeof(*node));
+ node->data = val;
+ node->parent = list;
+
+ if (type == ARES__LLIST_INSERT_BEFORE && (at == list->head || at == NULL)) {
+ type = ARES__LLIST_INSERT_HEAD;
+ }
+
+ switch (type) {
+ case ARES__LLIST_INSERT_HEAD:
+ node->next = list->head;
+ node->prev = NULL;
+ if (list->head)
+ list->head->prev = node;
+ list->head = node;
+ break;
+ case ARES__LLIST_INSERT_TAIL:
+ node->next = NULL;
+ node->prev = list->tail;
+ if (list->tail)
+ list->tail->next = node;
+ list->tail = node;
+ break;
+ case ARES__LLIST_INSERT_BEFORE:
+ node->next = at;
+ node->prev = at->prev;
+ at->prev = node;
+ break;
+ }
+ if (list->tail == NULL)
+ list->tail = node;
+ if (list->head == NULL)
+ list->head = node;
+
+ list->cnt++;
+
+ return node;
+}
+
+
+ares__llist_node_t *ares__llist_insert_first(ares__llist_t *list, void *val)
+{
+ return ares__llist_insert_at(list, ARES__LLIST_INSERT_HEAD, NULL, val);
+}
+
+
+ares__llist_node_t *ares__llist_insert_last(ares__llist_t *list, void *val)
+{
+ return ares__llist_insert_at(list, ARES__LLIST_INSERT_TAIL, NULL, val);
+}
+
+
+ares__llist_node_t *ares__llist_insert_before(ares__llist_node_t *node,
+ void *val)
+{
+ if (node == NULL)
+ return NULL;
+
+ return ares__llist_insert_at(node->parent, ARES__LLIST_INSERT_BEFORE, node,
+ val);
+}
+
+
+ares__llist_node_t *ares__llist_insert_after(ares__llist_node_t *node,
+ void *val)
+{
+ if (node == NULL)
+ return NULL;
+
+ if (node->next == NULL)
+ return ares__llist_insert_last(node->parent, val);
+
+ return ares__llist_insert_at(node->parent, ARES__LLIST_INSERT_BEFORE,
+ node->next, val);
+}
+
+
+ares__llist_node_t *ares__llist_node_first(ares__llist_t *list)
+{
+ if (list == NULL)
+ return NULL;
+ return list->head;
+}
+
+
+ares__llist_node_t *ares__llist_node_last(ares__llist_t *list)
+{
+ if (list == NULL)
+ return NULL;
+ return list->tail;
+}
+
+
+ares__llist_node_t *ares__llist_node_next(ares__llist_node_t *node)
+{
+ if (node == NULL)
+ return NULL;
+ return node->next;
+}
+
+
+ares__llist_node_t *ares__llist_node_prev(ares__llist_node_t *node)
+{
+ if (node == NULL)
+ return NULL;
+ return node->prev;
+}
+
+
+void *ares__llist_node_val(ares__llist_node_t *node)
+{
+ if (node == NULL)
+ return NULL;
+
+ return node->data;
+}
+
+
+size_t ares__llist_len(ares__llist_t *list)
+{
+ if (list == NULL)
+ return 0;
+ return list->cnt;
+}
+
+
+ares__llist_t *ares__llist_node_parent(ares__llist_node_t *node)
+{
+ if (node == NULL)
+ return NULL;
+ return node->parent;
+}
+
+
+void *ares__llist_first_val(ares__llist_t *list)
+{
+ return ares__llist_node_val(ares__llist_node_first(list));
+}
+
+
+void *ares__llist_last_val(ares__llist_t *list)
+{
+ return ares__llist_node_val(ares__llist_node_last(list));
+}
+
+
+void *ares__llist_node_claim(ares__llist_node_t *node)
+{
+ void *val;
+ ares__llist_t *list;
+
+ if (node == NULL)
+ return NULL;
+
+ list = node->parent;
+ val = node->data;
+
+ if (node->prev) {
+ node->prev->next = node->next;
+ }
+
+ if (node->next) {
+ node->next->prev = node->prev;
+ }
+
+ if (node == list->head) {
+ list->head = node->next;
+ }
+
+ if (node == list->tail) {
+ list->tail = node->prev;
+ }
+ ares_free(node);
+
+ list->cnt--;
+
+ return val;
+}
+
+
+void ares__llist_node_destroy(ares__llist_node_t *node)
+{
+ ares__llist_destructor_t destruct;
+ void *val;
+
+ if (node == NULL)
+ return;
+
+ destruct = node->parent->destruct;
+
+ val = ares__llist_node_claim(node);
+ if (val != NULL && destruct != NULL)
+ destruct(val);
+}
+
+
+void ares__llist_node_replace(ares__llist_node_t *node, void *val)
+{
+ ares__llist_destructor_t destruct;
+
+ if (node == NULL)
+ return;
+
+ destruct = node->parent->destruct;
+ if (destruct != NULL)
+ destruct(node->data);
+
+ node->data = val;
+}
+
+
+void ares__llist_destroy(ares__llist_t *list)
+{
+ ares__llist_node_t *node;
+
+ if (list == NULL)
+ return;
+
+ while ((node = ares__llist_node_first(list)) != NULL) {
+ ares__llist_node_destroy(node);
+ }
+ ares_free(list);
+}
diff --git a/contrib/libs/c-ares/src/lib/ares__llist.h b/contrib/libs/c-ares/src/lib/ares__llist.h
new file mode 100644
index 0000000000..950c7ac1d0
--- /dev/null
+++ b/contrib/libs/c-ares/src/lib/ares__llist.h
@@ -0,0 +1,203 @@
+/* MIT License
+ *
+ * Copyright (c) 2023 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__LLIST_H
+#define __ARES__LLIST_H
+
+/*! \addtogroup ares__llist LinkedList Data Structure
+ *
+ * This is a doubly-linked list data structure.
+ *
+ * Average time complexity:
+ * - Insert: O(1) -- head or tail
+ * - Search: O(n)
+ * - Delete: O(1) -- delete assumes you hold a node pointer
+ *
+ * @{
+ */
+
+struct ares__llist;
+
+/*! Opaque data structure for linked list */
+typedef struct ares__llist ares__llist_t;
+
+struct ares__llist_node;
+
+/*! Opaque data structure for a node in a linked list */
+typedef struct ares__llist_node ares__llist_node_t;
+
+/*! Callback to free user-defined node data
+ *
+ * \param[in] data user supplied data
+ */
+typedef void (*ares__llist_destructor_t)(void *data);
+
+/*! Create a linked list object
+ *
+ * \param[in] destruct Optional. Destructor to call on all removed nodes
+ * \return linked list object or NULL on out of memory
+ */
+ares__llist_t *ares__llist_create(ares__llist_destructor_t destruct);
+
+/*! Replace destructor for linked list nodes. Typically this is used
+ * when wanting to disable the destructor by using NULL.
+ *
+ * \param[in] list Initialized linked list object
+ * \param[in] destruct replacement destructor, NULL is allowed
+ */
+void ares__llist_replace_destructor(ares__llist_t *list,
+ ares__llist_destructor_t destruct);
+
+/*! Insert value as the first node in the linked list
+ *
+ * \param[in] list Initialized linked list object
+ * \param[in] val user-supplied value.
+ * \return node object referencing place in list, or null if out of memory or
+ * misuse
+ */
+ares__llist_node_t *ares__llist_insert_first(ares__llist_t *list, void *val);
+
+/*! Insert value as the last node in the linked list
+ *
+ * \param[in] list Initialized linked list object
+ * \param[in] val user-supplied value.
+ * \return node object referencing place in list, or null if out of memory or
+ * misuse
+ */
+ares__llist_node_t *ares__llist_insert_last(ares__llist_t *list, void *val);
+
+/*! Insert value before specified node in the linked list
+ *
+ * \param[in] node node referenced to insert before
+ * \param[in] val user-supplied value.
+ * \return node object referencing place in list, or null if out of memory or
+ * misuse
+ */
+ares__llist_node_t *ares__llist_insert_before(ares__llist_node_t *node,
+ void *val);
+
+/*! Insert value after specified node in the linked list
+ *
+ * \param[in] node node referenced to insert after
+ * \param[in] val user-supplied value.
+ * \return node object referencing place in list, or null if out of memory or
+ * misuse
+ */
+ares__llist_node_t *ares__llist_insert_after(ares__llist_node_t *node,
+ void *val);
+
+/*! Obtain first node in list
+ *
+ * \param[in] list Initialized list object
+ * \return first node in list or NULL if none
+ */
+ares__llist_node_t *ares__llist_node_first(ares__llist_t *list);
+
+/*! Obtain last node in list
+ *
+ * \param[in] list Initialized list object
+ * \return last node in list or NULL if none
+ */
+ares__llist_node_t *ares__llist_node_last(ares__llist_t *list);
+
+/*! Obtain next node in respect to specified node
+ *
+ * \param[in] node Node referenced
+ * \return node or NULL if none
+ */
+ares__llist_node_t *ares__llist_node_next(ares__llist_node_t *node);
+
+/*! Obtain previous node in respect to specified node
+ *
+ * \param[in] node Node referenced
+ * \return node or NULL if none
+ */
+ares__llist_node_t *ares__llist_node_prev(ares__llist_node_t *node);
+
+/*! Obtain value from node
+ *
+ * \param[in] node Node referenced
+ * \return user provided value from node
+ */
+void *ares__llist_node_val(ares__llist_node_t *node);
+
+/*! Obtain the number of entries in the list
+ *
+ * \param[in] list Initialized list object
+ * \return count
+ */
+size_t ares__llist_len(ares__llist_t *list);
+
+/*! Obtain list object from referenced node
+ *
+ * \param[in] node Node referenced
+ * \return list object node belongs to
+ */
+ares__llist_t *ares__llist_node_parent(ares__llist_node_t *node);
+
+/*! Obtain the first user-supplied value in the list
+ *
+ * \param[in] list Initialized list object
+ * \return first user supplied value or NULL if none
+ */
+void *ares__llist_first_val(ares__llist_t *list);
+
+/*! Obtain the last user-supplied value in the list
+ *
+ * \param[in] list Initialized list object
+ * \return last user supplied value or NULL if none
+ */
+void *ares__llist_last_val(ares__llist_t *list);
+
+/*! Take ownership of user-supplied value in list without calling destructor.
+ * Will unchain entry from list.
+ *
+ * \param[in] node Node referenced
+ * \return user supplied value
+ */
+void *ares__llist_node_claim(ares__llist_node_t *node);
+
+/*! Replace user-supplied value for node
+ *
+ * \param[in] node Node referenced
+ * \param[in] val new user-supplied value
+ */
+void ares__llist_node_replace(ares__llist_node_t *node, void *val);
+
+/*! Destroy the node, removing it from the list and calling destructor.
+ *
+ * \param[in] node Node referenced
+ */
+void ares__llist_node_destroy(ares__llist_node_t *node);
+
+/*! Destroy the list object and all nodes in the list.
+ *
+ * \param[in] list Initialized list object
+ */
+void ares__llist_destroy(ares__llist_t *list);
+
+/*! @} */
+
+#endif /* __ARES__LLIST_H */
diff --git a/contrib/libs/c-ares/src/lib/ares__parse_into_addrinfo.c b/contrib/libs/c-ares/src/lib/ares__parse_into_addrinfo.c
index 4393f04b96..73a17ea0ed 100644
--- a/contrib/libs/c-ares/src/lib/ares__parse_into_addrinfo.c
+++ b/contrib/libs/c-ares/src/lib/ares__parse_into_addrinfo.c
@@ -1,18 +1,28 @@
-/* Copyright (C) 2019 by Andrew Selivanov
+/* MIT License
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * Copyright (c) 2019 Andrew Selivanov
+ *
+ * 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_setup.h"
#ifdef HAVE_NETINET_IN_H
diff --git a/contrib/libs/c-ares/src/lib/ares__read_line.c b/contrib/libs/c-ares/src/lib/ares__read_line.c
index c62ad2a2b4..38beda6fb0 100644
--- a/contrib/libs/c-ares/src/lib/ares__read_line.c
+++ b/contrib/libs/c-ares/src/lib/ares__read_line.c
@@ -1,17 +1,28 @@
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
+/* MIT License
+ *
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * Copyright (c) The c-ares project and its contributors
+ *
+ * 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.
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * SPDX-License-Identifier: MIT
*/
#include "ares_setup.h"
diff --git a/contrib/libs/c-ares/src/lib/ares__readaddrinfo.c b/contrib/libs/c-ares/src/lib/ares__readaddrinfo.c
index 2315df9411..fe99946782 100644
--- a/contrib/libs/c-ares/src/lib/ares__readaddrinfo.c
+++ b/contrib/libs/c-ares/src/lib/ares__readaddrinfo.c
@@ -1,16 +1,27 @@
-/* Copyright (C) 2019 by Andrew Selivanov
+/* MIT License
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * Copyright (c) 2019 Andrew Selivanov
+ *
+ * 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_setup.h"
@@ -197,10 +208,6 @@ int ares__readaddrinfo(FILE *fp,
}
}
- if (status != ARES_SUCCESS)
- /* Ignore line if invalid address string for the requested family. */
- continue;
-
if (want_cname)
{
for (i = 0; i < alias_count; ++i)
diff --git a/contrib/libs/c-ares/src/lib/ares__slist.c b/contrib/libs/c-ares/src/lib/ares__slist.c
new file mode 100644
index 0000000000..9974bc045a
--- /dev/null
+++ b/contrib/libs/c-ares/src/lib/ares__slist.c
@@ -0,0 +1,501 @@
+/* MIT License
+ *
+ * Copyright (c) 2023 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_setup.h"
+#include "ares.h"
+#include "ares_private.h"
+#include "ares__slist.h"
+
+/* SkipList implementation */
+
+#define ARES__SLIST_START_LEVELS 4
+
+
+struct ares__slist {
+ ares_rand_state *rand_state;
+ unsigned char rand_data[8];
+ size_t rand_bits;
+
+ ares__slist_node_t **head;
+ size_t levels;
+ ares__slist_node_t *tail;
+
+ ares__slist_cmp_t cmp;
+ ares__slist_destructor_t destruct;
+ size_t cnt;
+};
+
+
+struct ares__slist_node {
+ void *data;
+ ares__slist_node_t **prev;
+ ares__slist_node_t **next;
+ size_t levels;
+ ares__slist_t *parent;
+};
+
+
+ares__slist_t *ares__slist_create(ares_rand_state *rand_state,
+ ares__slist_cmp_t cmp,
+ ares__slist_destructor_t destruct)
+{
+ ares__slist_t *list;
+
+ if (rand_state == NULL || cmp == NULL)
+ return NULL;
+
+ list = ares_malloc(sizeof(*list));
+
+ if (list == NULL)
+ return NULL;
+
+ memset(list, 0, sizeof(*list));
+
+ list->rand_state = rand_state;
+ list->cmp = cmp;
+ list->destruct = destruct;
+
+ list->levels = ARES__SLIST_START_LEVELS;
+ list->head = ares_malloc(sizeof(*list->head) * list->levels);
+ if (list->head == NULL) {
+ ares_free(list);
+ return NULL;
+ }
+
+ memset(list->head, 0, sizeof(*list->head) * list->levels);
+
+ return list;
+}
+
+
+static unsigned int ares__slist_coin_flip(ares__slist_t *list)
+{
+ size_t total_bits = sizeof(list->rand_data) * 8;
+ size_t bit;
+
+ /* Refill random data used for coin flips. We pull this in 8 byte chunks.
+ * ares__rand_bytes() has some built-in caching of its own so we don't need
+ * to be excessive in caching ourselves. Prefer to require less memory per
+ * skiplist */
+ if (list->rand_bits == 0) {
+ ares__rand_bytes(list->rand_state, list->rand_data,
+ sizeof(list->rand_data));
+ list->rand_bits = total_bits;
+ }
+
+ bit = total_bits - list->rand_bits;
+ list->rand_bits--;
+
+ return (list->rand_data[bit / 8] & (1 << (bit % 8)))?1:0;
+}
+
+
+void ares__slist_replace_destructor(ares__slist_t *list,
+ ares__slist_destructor_t destruct)
+{
+ if (list == NULL)
+ return;
+
+ list->destruct = destruct;
+}
+
+/* Uses public domain code snipets from http://graphics.stanford.edu/~seander/bithacks.html */
+
+static size_t ares__round_up_pow2(size_t n)
+{
+ n--;
+ n |= n >> 1;
+ n |= n >> 2;
+ n |= n >> 4;
+ n |= n >> 8;
+ n |= n >> 16;
+ if (sizeof(size_t) > 4)
+ n |= n >> 32;
+ n++;
+ return n;
+}
+
+
+static size_t ares__log2(size_t n)
+{
+ static const unsigned char tab32[32] = {
+ 0, 1, 28, 2, 29, 14, 24, 3,
+ 30, 22, 20, 15, 25, 17, 4, 8,
+ 31, 27, 13, 23, 21, 19, 16, 7,
+ 26, 12, 18, 6, 11, 5, 10, 9
+ };
+ static const unsigned char tab64[64] = {
+ 63, 0, 58, 1, 59, 47, 53, 2,
+ 60, 39, 48, 27, 54, 33, 42, 3,
+ 61, 51, 37, 40, 49, 18, 28, 20,
+ 55, 30, 34, 11, 43, 14, 22, 4,
+ 62, 57, 46, 52, 38, 26, 32, 41,
+ 50, 36, 17, 19, 29, 10, 13, 21,
+ 56, 45, 25, 31, 35, 16, 9, 12,
+ 44, 24, 15, 8, 23, 7, 6, 5
+ };
+
+ if (sizeof(size_t) == 4)
+ return tab32[(size_t)(n*0x077CB531) >> 27];
+
+ return tab64[((size_t)(n*0x07EDD5E59A4E28C2)) >> 58];
+}
+
+
+static size_t ares__slist_max_level(ares__slist_t *list)
+{
+ size_t max_level = 0;
+
+ if (list->cnt+1 <= (1 << ARES__SLIST_START_LEVELS)) {
+ max_level = ARES__SLIST_START_LEVELS;
+ } else {
+ max_level = ares__log2(ares__round_up_pow2(list->cnt+1));
+ }
+
+ if (list->levels > max_level)
+ max_level = list->levels;
+
+ return max_level;
+}
+
+
+static size_t ares__slist_calc_level(ares__slist_t *list)
+{
+ size_t max_level = ares__slist_max_level(list);
+ size_t level;
+
+ for (level=1; ares__slist_coin_flip(list) && level < max_level; level++)
+ ;
+
+ return level;
+}
+
+
+ares__slist_node_t *ares__slist_insert(ares__slist_t *list, void *val)
+{
+ ares__slist_node_t *node = NULL;
+ ares__slist_node_t *left = NULL;
+ size_t i;
+
+ if (list == NULL || val == NULL)
+ return NULL;
+
+ node = ares_malloc(sizeof(*node));
+
+ if (node == NULL)
+ goto fail;
+
+ memset(node, 0, sizeof(*node));
+ node->data = val;
+ node->parent = list;
+
+ /* Randomly determine the number of levels we want to use */
+ node->levels = ares__slist_calc_level(list);
+
+ /* Allocate array of next and prev nodes for linking each level */
+ node->next = ares_malloc(sizeof(*node->next) * node->levels);
+ if (node->next == NULL)
+ goto fail;
+
+ memset(node->next, 0, sizeof(*node->next) * node->levels);
+
+ node->prev = ares_malloc(sizeof(*node->prev) * node->levels);
+ if (node->prev == NULL)
+ goto fail;
+
+ memset(node->prev, 0, sizeof(*node->prev) * node->levels);
+
+ /* If the number of levels is greater than we currently support in the slist,
+ * increase the count */
+ if (list->levels < node->levels) {
+ size_t zero_len = sizeof(*list->head) * (node->levels - list->levels);
+ size_t offset = sizeof(*list->head) * list->levels;
+ void *ptr = ares_realloc(list->head, sizeof(*list->head) * node->levels);
+ if (ptr == NULL)
+ goto fail;
+
+ memset((unsigned char *)ptr + offset, 0, zero_len);
+ list->head = ptr;
+ list->levels = node->levels;
+ }
+
+
+ /* Scan from highest level in the slist, even if we're not using that number
+ * of levels for this entry as this is what makes it O(log n) */
+ for (i=list->levels; i-- > 0; ) {
+ /* set left if left is NULL and the current node value is greater than the
+ * head at this level */
+ if (left == NULL &&
+ list->head[i] != NULL &&
+ list->cmp(node->data, list->head[i]->data) > 0
+ ) {
+ left = list->head[i];
+ }
+
+ if (left != NULL) {
+ /* scan forward to find our insertion point */
+ while (left->next[i] != NULL &&
+ list->cmp(node->data, left->next[i]->data) > 0) {
+ left = left->next[i];
+ }
+ }
+
+ /* search only as we didn't randomly select this number of levels */
+ if (i >= node->levels)
+ continue;
+
+ if (left == NULL) {
+ /* head insertion */
+ node->next[i] = list->head[i];
+ node->prev[i] = NULL;
+ list->head[i] = node;
+ } else {
+ /* Chain */
+ node->next[i] = left->next[i];
+ node->prev[i] = left;
+ left->next[i] = node;
+ }
+
+ if (node->next[i] != NULL) {
+ /* chain prev */
+ node->next[i]->prev[i] = node;
+ } else {
+ if (i == 0) {
+ /* update tail */
+ list->tail = node;
+ }
+ }
+ }
+
+ list->cnt++;
+
+ return node;
+
+fail:
+ if (node) {
+ ares_free(node->prev);
+ ares_free(node->next);
+ ares_free(node);
+ }
+ return NULL;
+}
+
+
+ares__slist_node_t *ares__slist_node_find(ares__slist_t *list, const void *val)
+{
+ size_t i;
+ ares__slist_node_t *node = NULL;
+ int rv = -1;
+
+ if (list == NULL || val == NULL)
+ return NULL;
+
+ /* Scan nodes starting at the highest level. For each level scan forward
+ * until the value is between the prior and next node, or if equal quit
+ * as we found a match */
+ for (i=list->levels; i-- > 0; ) {
+ if (node == NULL)
+ node = list->head[i];
+
+ if (node == NULL)
+ continue;
+
+ do {
+ rv = list->cmp(val, node->data);
+
+ if (rv < 0) {
+ /* back off, our value is greater than current node reference */
+ node = node->prev[i];
+ } else if (rv > 0) {
+ /* move forward and try again. if it goes past, it will loop again and
+ * go to previous entry */
+ node = node->next[i];
+ }
+
+ /* rv == 0 will terminate loop */
+
+ } while (node != NULL && rv > 0);
+
+ /* Found a match, no need to continue */
+ if (rv == 0) {
+ break;
+ }
+ }
+
+ /* no match */
+ if (rv != 0) {
+ return NULL;
+ }
+
+ /* The list may have multiple entries that match. They're guaranteed to be
+ * in order, but we're not guaranteed to have selected the _first_ matching
+ * node. Lets scan backwards to find the first match */
+ while (node->prev[0] != NULL && list->cmp(node->prev[0]->data, val) == 0) {
+ node = node->prev[0];
+ }
+
+ return node;
+}
+
+
+ares__slist_node_t *ares__slist_node_first(ares__slist_t *list)
+{
+ if (list == NULL)
+ return NULL;
+
+ return list->head[0];
+}
+
+
+ares__slist_node_t *ares__slist_node_last(ares__slist_t *list)
+{
+ if (list == NULL)
+ return NULL;
+ return list->tail;
+}
+
+
+ares__slist_node_t *ares__slist_node_next(ares__slist_node_t *node)
+{
+ if (node == NULL)
+ return NULL;
+ return node->next[0];
+}
+
+
+ares__slist_node_t *ares__slist_node_prev(ares__slist_node_t *node)
+{
+ if (node == NULL)
+ return NULL;
+ return node->prev[0];
+}
+
+
+void *ares__slist_node_val(ares__slist_node_t *node)
+{
+ if (node == NULL)
+ return NULL;
+
+ return node->data;
+}
+
+
+size_t ares__slist_len(ares__slist_t *list)
+{
+ if (list == NULL)
+ return 0;
+ return list->cnt;
+}
+
+
+ares__slist_t *ares__slist_node_parent(ares__slist_node_t *node)
+{
+ if (node == NULL)
+ return NULL;
+ return node->parent;
+}
+
+
+void *ares__slist_first_val(ares__slist_t *list)
+{
+ return ares__slist_node_val(ares__slist_node_first(list));
+}
+
+
+void *ares__slist_last_val(ares__slist_t *list)
+{
+ return ares__slist_node_val(ares__slist_node_last(list));
+}
+
+
+void *ares__slist_node_claim(ares__slist_node_t *node)
+{
+ void *val;
+ ares__slist_t *list;
+ size_t i;
+
+ if (node == NULL)
+ return NULL;
+
+ list = node->parent;
+ val = node->data;
+
+ /* relink each node at each level */
+ for (i=node->levels; i-- > 0; ) {
+ if (node->next[i] == NULL) {
+ if (i == 0) {
+ list->tail = node->prev[0];
+ }
+ } else {
+ node->next[i]->prev[i] = node->prev[i];
+ }
+
+ if (node->prev[i] == NULL) {
+ list->head[i] = node->next[i];
+ } else {
+ node->prev[i]->next[i] = node->next[i];
+ }
+ }
+
+ ares_free(node->next);
+ ares_free(node->prev);
+ ares_free(node);
+
+ list->cnt--;
+
+ return val;
+}
+
+
+void ares__slist_node_destroy(ares__slist_node_t *node)
+{
+ ares__slist_destructor_t destruct;
+ void *val;
+
+ if (node == NULL)
+ return;
+
+ destruct = node->parent->destruct;
+ val = ares__slist_node_claim(node);
+
+ if (val != NULL && destruct != NULL)
+ destruct(val);
+}
+
+
+void ares__slist_destroy(ares__slist_t *list)
+{
+ ares__slist_node_t *node;
+
+ if (list == NULL)
+ return;
+
+ while ((node = ares__slist_node_first(list)) != NULL) {
+ ares__slist_node_destroy(node);
+ }
+
+ ares_free(list->head);
+ ares_free(list);
+}
diff --git a/contrib/libs/c-ares/src/lib/ares__slist.h b/contrib/libs/c-ares/src/lib/ares__slist.h
new file mode 100644
index 0000000000..2cce217164
--- /dev/null
+++ b/contrib/libs/c-ares/src/lib/ares__slist.h
@@ -0,0 +1,197 @@
+/* MIT License
+ *
+ * Copyright (c) 2023 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__SLIST_H
+#define __ARES__SLIST_H
+
+
+/*! \addtogroup ares__slist SkipList Data Structure
+ *
+ * This data structure is known as a Skip List, which in essence is a sorted
+ * linked list with multiple levels of linkage to gain some algorithmic
+ * advantages. The usage symantecs are almost identical to what you'd expect
+ * with a linked list.
+ *
+ * Average time complexity:
+ * - Insert: O(log n)
+ * - Search: O(log n)
+ * - Delete: O(1) -- delete assumes you hold a node pointer
+ *
+ * It should be noted, however, that "effort" involved with an insert or
+ * remove operation is higher than a normal linked list. For very small
+ * lists this may be less efficient, but for any list with a moderate number
+ * of entries this will prove much more efficient.
+ *
+ * This data structure is often compared with a Binary Search Tree in
+ * functionality and usage.
+ *
+ * @{
+ */
+struct ares__slist;
+
+/*! SkipList Object, opaque */
+typedef struct ares__slist ares__slist_t;
+
+struct ares__slist_node;
+
+/*! SkipList Node Object, opaque */
+typedef struct ares__slist_node ares__slist_node_t;
+
+/*! SkipList Node Value destructor callback
+ *
+ * \param[in] data User-defined data to destroy
+ */
+typedef void (*ares__slist_destructor_t)(void *data);
+
+/*! SkipList comparison function
+ *
+ * \param[in] data1 First user-defined data object
+ * \param[in] data2 Second user-defined data object
+ * \return < 0 if data1 < data1, > 0 if data1 > data2, 0 if data1 == data2
+ */
+typedef int (*ares__slist_cmp_t)(const void *data1, const void *data2);
+
+/*! Create SkipList
+ *
+ * \param[in] rand_state Initialized ares random state.
+ * \param[in] cmp SkipList comparison function
+ * \param[in] destruct SkipList Node Value Destructor. Optional, use NULL.
+ * \return Initialized SkipList Object or NULL on misuse or ENOMEM
+ */
+ares__slist_t *ares__slist_create(ares_rand_state *rand_state,
+ ares__slist_cmp_t cmp,
+ ares__slist_destructor_t destruct);
+
+/*! Replace SkipList Node Value Destructor
+ *
+ * \param[in] list Initialized SkipList Object
+ * \param[in] destruct Replacement destructor. May be NULL.
+ */
+void ares__slist_replace_destructor(ares__slist_t *list,
+ ares__slist_destructor_t destruct);
+
+/*! Insert Value into SkipList
+ *
+ * \param[in] list Initialized SkipList Object
+ * \param[in] val Node Value. Must not be NULL. Function takes ownership
+ * and will have destructor called.
+ * \return SkipList Node Object or NULL on misuse or ENOMEM
+ */
+ares__slist_node_t *ares__slist_insert(ares__slist_t *list, void *val);
+
+/*! Fetch first node in SkipList
+ *
+ * \param[in] list Initialized SkipList Object
+ * \return SkipList Node Object or NULL if none
+ */
+ares__slist_node_t *ares__slist_node_first(ares__slist_t *list);
+
+/*! Fetch last node in SkipList
+ *
+ * \param[in] list Initialized SkipList Object
+ * \return SkipList Node Object or NULL if none
+ */
+ares__slist_node_t *ares__slist_node_last(ares__slist_t *list);
+
+/*! Fetch next node in SkipList
+ *
+ * \param[in] node SkipList Node Object
+ * \return SkipList Node Object or NULL if none
+ */
+ares__slist_node_t *ares__slist_node_next(ares__slist_node_t *node);
+
+/*! Fetch previous node in SkipList
+ *
+ * \param[in] node SkipList Node Object
+ * \return SkipList Node Object or NULL if none
+ */
+ares__slist_node_t *ares__slist_node_prev(ares__slist_node_t *node);
+
+/*! Fetch SkipList Node Object by Value
+ *
+ * \param[in] list Initialized SkipList Object
+ * \param[in] val Object to use for comparison
+ * \return SkipList Node Object or NULL if not found
+ */
+ares__slist_node_t *ares__slist_node_find(ares__slist_t *list, const void *val);
+
+
+/*! Fetch Node Value
+ *
+ * \param[in] node SkipList Node Object
+ * \return user defined node value
+ */
+void *ares__slist_node_val(ares__slist_node_t *node);
+
+/*! Fetch number of entries in SkipList Object
+ *
+ * \param[in] list Initialized SkipList Object
+ * \return number of entries
+ */
+size_t ares__slist_len(ares__slist_t *list);
+
+/*! Fetch SkipList Object from SkipList Node
+ *
+ * \param[in] node SkipList Node Object
+ * \return SkipList Object
+ */
+ares__slist_t *ares__slist_node_parent(ares__slist_node_t *node);
+
+/*! Fetch first Node Value in SkipList
+ *
+ * \param[in] list Initialized SkipList Object
+ * \return user defined node value or NULL if none
+ */
+void *ares__slist_first_val(ares__slist_t *list);
+
+/*! Fetch last Node Value in SkipList
+ *
+ * \param[in] list Initialized SkipList Object
+ * \return user defined node value or NULL if none
+ */
+void *ares__slist_last_val(ares__slist_t *list);
+
+/*! Take back ownership of Node Value in SkipList, remove from SkipList.
+ *
+ * \param[in] node SkipList Node Object
+ * \return user defined node value
+ */
+void *ares__slist_node_claim(ares__slist_node_t *node);
+
+/*! Remove Node from SkipList, calling destructor for Node Value.
+ *
+ * \param[in] node SkipList Node Object
+ */
+void ares__slist_node_destroy(ares__slist_node_t *node);
+
+/*! Destroy SkipList Object. If there are any nodes, they will be destroyed.
+ *
+ * \param[in] list Initialized SkipList Object
+ */
+void ares__slist_destroy(ares__slist_t *list);
+
+/*! @} */
+
+#endif /* __ARES__SLIST_H */
diff --git a/contrib/libs/c-ares/src/lib/ares__sortaddrinfo.c b/contrib/libs/c-ares/src/lib/ares__sortaddrinfo.c
index 3f050cad00..78d8891614 100644
--- a/contrib/libs/c-ares/src/lib/ares__sortaddrinfo.c
+++ b/contrib/libs/c-ares/src/lib/ares__sortaddrinfo.c
@@ -6,7 +6,7 @@
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
* Copyright (C) 2018 The Android Open Source Project
- * Copyright (C) 2019 by Andrew Selivanov
+ * Copyright (C) 2019 Andrew Selivanov
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -32,6 +32,8 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
*/
#include "ares_setup.h"
diff --git a/contrib/libs/c-ares/src/lib/ares__timeval.c b/contrib/libs/c-ares/src/lib/ares__timeval.c
index 94efb7db1e..5716c53e50 100644
--- a/contrib/libs/c-ares/src/lib/ares__timeval.c
+++ b/contrib/libs/c-ares/src/lib/ares__timeval.c
@@ -1,15 +1,27 @@
-
-/* Copyright (C) 2008 by Daniel Stenberg et al
+/* MIT License
+ *
+ * Copyright (c) 2008 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.
*
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in advertising or
- * publicity pertaining to distribution of the software without specific,
- * written prior permission. M.I.T. makes no representations about the
- * suitability of this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * SPDX-License-Identifier: MIT
*/
#include "ares_setup.h"
diff --git a/contrib/libs/c-ares/src/lib/ares_android.c b/contrib/libs/c-ares/src/lib/ares_android.c
index 5b00b8065c..ec0a33872d 100644
--- a/contrib/libs/c-ares/src/lib/ares_android.c
+++ b/contrib/libs/c-ares/src/lib/ares_android.c
@@ -1,16 +1,27 @@
-/* Copyright (C) 2017 by John Schember <john@nachtimwald.com>
+/* MIT License
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * Copyright (c) John Schember
+ *
+ * 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
*/
#if defined(ANDROID) || defined(__ANDROID__)
diff --git a/contrib/libs/c-ares/src/lib/ares_android.h b/contrib/libs/c-ares/src/lib/ares_android.h
index 93fb75f585..73b8d8ee83 100644
--- a/contrib/libs/c-ares/src/lib/ares_android.h
+++ b/contrib/libs/c-ares/src/lib/ares_android.h
@@ -1,16 +1,27 @@
-/* Copyright (C) 2017 by John Schember <john@nachtimwald.com>
+/* MIT License
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * Copyright (c) John Schember
+ *
+ * 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_ANDROID_H__
diff --git a/contrib/libs/c-ares/src/lib/ares_cancel.c b/contrib/libs/c-ares/src/lib/ares_cancel.c
index 465cc9e95e..353624a111 100644
--- a/contrib/libs/c-ares/src/lib/ares_cancel.c
+++ b/contrib/libs/c-ares/src/lib/ares_cancel.c
@@ -1,15 +1,27 @@
-
-/* Copyright (C) 2004 by Daniel Stenberg et al
+/* 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.
*
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in advertising or
- * publicity pertaining to distribution of the software without specific,
- * written prior permission. M.I.T. makes no representations about the
- * suitability of this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * SPDX-License-Identifier: MIT
*/
#include "ares_setup.h"
@@ -25,39 +37,51 @@
*/
void ares_cancel(ares_channel channel)
{
- struct query *query;
- struct list_node list_head_copy;
- struct list_node* list_head;
- struct list_node* list_node;
- int i;
-
- if (!ares__is_list_empty(&(channel->all_queries)))
+ if (ares__llist_len(channel->all_queries) > 0)
{
+ ares__llist_node_t *node = NULL;
+ ares__llist_node_t *next = NULL;
+
/* Swap list heads, so that only those queries which were present on entry
* into this function are cancelled. New queries added by callbacks of
* queries being cancelled will not be cancelled themselves.
*/
- list_head = &(channel->all_queries);
- list_head_copy.prev = list_head->prev;
- list_head_copy.next = list_head->next;
- list_head_copy.prev->next = &list_head_copy;
- list_head_copy.next->prev = &list_head_copy;
- list_head->prev = list_head;
- list_head->next = list_head;
- for (list_node = list_head_copy.next; list_node != &list_head_copy; )
- {
- query = list_node->data;
- list_node = list_node->next; /* since we're deleting the query */
+ ares__llist_t *list_copy = channel->all_queries;
+ channel->all_queries = ares__llist_create(NULL);
+
+ /* Out of memory, this function doesn't return a result code though so we
+ * can't report to caller */
+ if (channel->all_queries == NULL) {
+ channel->all_queries = list_copy;
+ return;
+ }
+
+ node = ares__llist_node_first(list_copy);
+ while (node != NULL) {
+ struct query *query;
+ ares_socket_t fd = ARES_SOCKET_BAD;
+
+ /* Cache next since this node is being deleted */
+ next = ares__llist_node_next(node);
+
+ query = ares__llist_node_claim(node);
+ query->node_all_queries = NULL;
+
+ /* Cache file descriptor for connection so we can clean it up possibly */
+ if (query->conn)
+ fd = query->conn->fd;
+
+ /* NOTE: its possible this may enqueue new queries */
query->callback(query->arg, ARES_ECANCELLED, 0, NULL, 0);
ares__free_query(query);
+
+ /* See if the connection should be cleaned up */
+ if (fd != ARES_SOCKET_BAD)
+ ares__check_cleanup_conn(channel, fd);
+
+ node = next;
}
- }
- if (!(channel->flags & ARES_FLAG_STAYOPEN) && ares__is_list_empty(&(channel->all_queries)))
- {
- if (channel->servers)
- {
- for (i = 0; i < channel->nservers; i++)
- ares__close_sockets(channel, &channel->servers[i]);
- }
+
+ ares__llist_destroy(list_copy);
}
}
diff --git a/contrib/libs/c-ares/src/lib/ares_create_query.c b/contrib/libs/c-ares/src/lib/ares_create_query.c
index e3d874b450..21c6be08bd 100644
--- a/contrib/libs/c-ares/src/lib/ares_create_query.c
+++ b/contrib/libs/c-ares/src/lib/ares_create_query.c
@@ -1,17 +1,28 @@
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
+/* MIT License
+ *
+ * Copyright (c) Massachusetts Institute of Technology
+ * Copyright (c) The c-ares project and its contributors
+ *
+ * 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.
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * SPDX-License-Identifier: MIT
*/
#include "ares_setup.h"
diff --git a/contrib/libs/c-ares/src/lib/ares_data.c b/contrib/libs/c-ares/src/lib/ares_data.c
index 69dff06689..9e22339327 100644
--- a/contrib/libs/c-ares/src/lib/ares_data.c
+++ b/contrib/libs/c-ares/src/lib/ares_data.c
@@ -1,17 +1,27 @@
-
-/* Copyright (C) 2009-2013 by Daniel Stenberg
+/* 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.
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * SPDX-License-Identifier: MIT
*/
diff --git a/contrib/libs/c-ares/src/lib/ares_data.h b/contrib/libs/c-ares/src/lib/ares_data.h
index a682ad54cb..6965cf2a73 100644
--- a/contrib/libs/c-ares/src/lib/ares_data.h
+++ b/contrib/libs/c-ares/src/lib/ares_data.h
@@ -1,21 +1,30 @@
-#ifndef __ARES_DATA_H
-#define __ARES_DATA_H
-
-
-/* Copyright (C) 2009-2013 by Daniel Stenberg
+/* MIT License
+ *
+ * Copyright (c) 2009 Daniel Stenberg
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * 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_DATA_H
+#define __ARES_DATA_H
typedef enum {
ARES_DATATYPE_UNKNOWN = 1, /* unknown data type - introduced in 1.7.0 */
diff --git a/contrib/libs/c-ares/src/lib/ares_destroy.c b/contrib/libs/c-ares/src/lib/ares_destroy.c
index 62c899f82e..560082fd0c 100644
--- a/contrib/libs/c-ares/src/lib/ares_destroy.c
+++ b/contrib/libs/c-ares/src/lib/ares_destroy.c
@@ -1,18 +1,28 @@
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
- * Copyright (C) 2004-2011 by Daniel Stenberg
+/* MIT License
+ *
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * 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:
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * 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_setup.h"
@@ -44,45 +54,52 @@ void ares_destroy_options(struct ares_options *options)
void ares_destroy(ares_channel channel)
{
- int i;
- struct query *query;
- struct list_node* list_head;
- struct list_node* list_node;
+ int i;
+ ares__llist_node_t *node = NULL;
if (!channel)
return;
- list_head = &(channel->all_queries);
- for (list_node = list_head->next; list_node != list_head; )
- {
- query = list_node->data;
- list_node = list_node->next; /* since we're deleting the query */
- query->callback(query->arg, ARES_EDESTRUCTION, 0, NULL, 0);
- ares__free_query(query);
- }
+ /* Destroy all queries */
+ node = ares__llist_node_first(channel->all_queries);
+ while (node != NULL) {
+ ares__llist_node_t *next = ares__llist_node_next(node);
+ struct query *query = ares__llist_node_claim(node);
+
+ query->node_all_queries = NULL;
+ query->callback(query->arg, ARES_EDESTRUCTION, 0, NULL, 0);
+ ares__free_query(query);
+
+ node = next;
+ }
+
+
#ifndef NDEBUG
/* Freeing the query should remove it from all the lists in which it sits,
* so all query lists should be empty now.
*/
- assert(ares__is_list_empty(&(channel->all_queries)));
- for (i = 0; i < ARES_QID_TABLE_SIZE; i++)
- {
- assert(ares__is_list_empty(&(channel->queries_by_qid[i])));
- }
- for (i = 0; i < ARES_TIMEOUT_TABLE_SIZE; i++)
- {
- assert(ares__is_list_empty(&(channel->queries_by_timeout[i])));
- }
+ assert(ares__llist_len(channel->all_queries) == 0);
+ assert(ares__htable_stvp_num_keys(channel->queries_by_qid) == 0);
+ assert(ares__slist_len(channel->queries_by_timeout) == 0);
#endif
ares__destroy_servers_state(channel);
+#ifndef NDEBUG
+ assert(ares__htable_asvp_num_keys(channel->connnode_by_socket) == 0);
+#endif
+
if (channel->domains) {
for (i = 0; i < channel->ndomains; i++)
ares_free(channel->domains[i]);
ares_free(channel->domains);
}
+ ares__llist_destroy(channel->all_queries);
+ ares__slist_destroy(channel->queries_by_timeout);
+ ares__htable_stvp_destroy(channel->queries_by_qid);
+ ares__htable_asvp_destroy(channel->connnode_by_socket);
+
if(channel->sortlist)
ares_free(channel->sortlist);
@@ -111,8 +128,10 @@ void ares__destroy_servers_state(ares_channel channel)
for (i = 0; i < channel->nservers; i++)
{
server = &channel->servers[i];
- ares__close_sockets(channel, server);
- assert(ares__is_list_empty(&server->queries_to_server));
+ ares__close_sockets(server);
+ ares__llist_destroy(server->connections);
+ ares__buf_destroy(server->tcp_parser);
+ ares__buf_destroy(server->tcp_send);
}
ares_free(channel->servers);
channel->servers = NULL;
diff --git a/contrib/libs/c-ares/src/lib/ares_expand_name.c b/contrib/libs/c-ares/src/lib/ares_expand_name.c
index ad1c97f937..21c4e93d85 100644
--- a/contrib/libs/c-ares/src/lib/ares_expand_name.c
+++ b/contrib/libs/c-ares/src/lib/ares_expand_name.c
@@ -1,17 +1,28 @@
-
-/* Copyright 1998, 2011 by the Massachusetts Institute of Technology.
+/* MIT License
+ *
+ * Copyright (c) 1998, 2011 Massachusetts Institute of Technology
+ * Copyright (c) The c-ares project and its contributors
+ *
+ * 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.
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * SPDX-License-Identifier: MIT
*/
#include "ares_setup.h"
diff --git a/contrib/libs/c-ares/src/lib/ares_expand_string.c b/contrib/libs/c-ares/src/lib/ares_expand_string.c
index 03e3929975..2d6daa1497 100644
--- a/contrib/libs/c-ares/src/lib/ares_expand_string.c
+++ b/contrib/libs/c-ares/src/lib/ares_expand_string.c
@@ -1,17 +1,28 @@
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
+/* MIT License
+ *
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * Copyright (c) The c-ares project and its contributors
+ *
+ * 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.
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * SPDX-License-Identifier: MIT
*/
#include "ares_setup.h"
diff --git a/contrib/libs/c-ares/src/lib/ares_fds.c b/contrib/libs/c-ares/src/lib/ares_fds.c
index f405fc047c..5ee149f904 100644
--- a/contrib/libs/c-ares/src/lib/ares_fds.c
+++ b/contrib/libs/c-ares/src/lib/ares_fds.c
@@ -1,17 +1,28 @@
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
+/* MIT License
+ *
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * Copyright (c) The c-ares project and its contributors
+ *
+ * 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.
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * SPDX-License-Identifier: MIT
*/
#include "ares_setup.h"
@@ -27,33 +38,32 @@ int ares_fds(ares_channel channel, fd_set *read_fds, fd_set *write_fds)
int i;
/* Are there any active queries? */
- int active_queries = !ares__is_list_empty(&(channel->all_queries));
+ size_t active_queries = ares__llist_len(channel->all_queries);
nfds = 0;
- for (i = 0; i < channel->nservers; i++)
- {
- server = &channel->servers[i];
+ for (i = 0; i < channel->nservers; i++) {
+ ares__llist_node_t *node;
+ server = &channel->servers[i];
+
+ for (node = ares__llist_node_first(server->connections);
+ node != NULL;
+ node = ares__llist_node_next(node)) {
+ struct server_connection *conn = ares__llist_node_val(node);
+
/* We only need to register interest in UDP sockets if we have
* outstanding queries.
*/
- if (active_queries && server->udp_socket != ARES_SOCKET_BAD)
- {
- FD_SET(server->udp_socket, read_fds);
- if (server->udp_socket >= nfds)
- nfds = server->udp_socket + 1;
- }
- /* We always register for TCP events, because we want to know
- * when the other side closes the connection, so we don't waste
- * time trying to use a broken connection.
- */
- if (server->tcp_socket != ARES_SOCKET_BAD)
- {
- FD_SET(server->tcp_socket, read_fds);
- if (server->qhead)
- FD_SET(server->tcp_socket, write_fds);
- if (server->tcp_socket >= nfds)
- nfds = server->tcp_socket + 1;
- }
+ if (active_queries || conn->is_tcp) {
+ FD_SET(conn->fd, read_fds);
+ if (conn->fd >= nfds)
+ nfds = conn->fd + 1;
+ }
+
+ if (conn->is_tcp && ares__buf_len(server->tcp_send)) {
+ FD_SET(conn->fd, write_fds);
+ }
}
+ }
+
return (int)nfds;
}
diff --git a/contrib/libs/c-ares/src/lib/ares_free_hostent.c b/contrib/libs/c-ares/src/lib/ares_free_hostent.c
index ea28ff0e2c..0d20673163 100644
--- a/contrib/libs/c-ares/src/lib/ares_free_hostent.c
+++ b/contrib/libs/c-ares/src/lib/ares_free_hostent.c
@@ -1,17 +1,28 @@
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
+/* MIT License
+ *
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * Copyright (c) The c-ares project and its contributors
+ *
+ * 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.
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * SPDX-License-Identifier: MIT
*/
#include "ares_setup.h"
diff --git a/contrib/libs/c-ares/src/lib/ares_free_string.c b/contrib/libs/c-ares/src/lib/ares_free_string.c
index 024992e1c2..39773067bd 100644
--- a/contrib/libs/c-ares/src/lib/ares_free_string.c
+++ b/contrib/libs/c-ares/src/lib/ares_free_string.c
@@ -1,17 +1,28 @@
-
-/* Copyright 2000 by the Massachusetts Institute of Technology.
+/* MIT License
+ *
+ * Copyright (c) 2000 Massachusetts Institute of Technology
+ * Copyright (c) The c-ares project and its contributors
+ *
+ * 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.
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * SPDX-License-Identifier: MIT
*/
#include "ares_setup.h"
diff --git a/contrib/libs/c-ares/src/lib/ares_freeaddrinfo.c b/contrib/libs/c-ares/src/lib/ares_freeaddrinfo.c
index ab871363d5..fe458735ee 100644
--- a/contrib/libs/c-ares/src/lib/ares_freeaddrinfo.c
+++ b/contrib/libs/c-ares/src/lib/ares_freeaddrinfo.c
@@ -1,18 +1,28 @@
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
- * Copyright (C) 2019 by Andrew Selivanov
+/* MIT License
+ *
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * Copyright (c) 2019 Andrew Selivanov
+ *
+ * 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.
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * SPDX-License-Identifier: MIT
*/
#include "ares_setup.h"
diff --git a/contrib/libs/c-ares/src/lib/ares_getaddrinfo.c b/contrib/libs/c-ares/src/lib/ares_getaddrinfo.c
index cb494242f2..a3a2add1a2 100644
--- a/contrib/libs/c-ares/src/lib/ares_getaddrinfo.c
+++ b/contrib/libs/c-ares/src/lib/ares_getaddrinfo.c
@@ -1,19 +1,29 @@
-
-/* Copyright 1998, 2011, 2013 by the Massachusetts Institute of Technology.
- * Copyright (C) 2017 - 2018 by Christian Ammer
- * Copyright (C) 2019 by Andrew Selivanov
+/* MIT License
+ *
+ * Copyright (c) 1998, 2011, 2013 Massachusetts Institute of Technology
+ * Copyright (c) 2017 Christian Ammer
+ * Copyright (c) 2019 Andrew Selivanov
+ *
+ * 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:
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * 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_setup.h"
@@ -49,6 +59,7 @@
#include "ares.h"
#include "bitncmp.h"
#include "ares_private.h"
+#include "ares_dns.h"
#ifdef WATT32
#undef WIN32
@@ -70,9 +81,12 @@ struct host_query
const char *remaining_lookups; /* types of lookup we need to perform ("fb" by
default, file and dns respectively) */
struct ares_addrinfo *ai; /* store results between lookups */
+ unsigned short qid_a; /* qid for A request */
+ unsigned short qid_aaaa; /* qid for AAAA request */
int remaining; /* number of DNS answers waiting for */
int next_domain; /* next search domain to try */
int nodata_cnt; /* Track nodata responses to possibly override final result */
+
};
static const struct ares_addrinfo_hints default_hints = {
@@ -113,7 +127,7 @@ static int as_is_first(const struct host_query *hquery);
static int as_is_only(const struct host_query* hquery);
static int next_dns_lookup(struct host_query *hquery);
-struct ares_addrinfo_cname *ares__malloc_addrinfo_cname()
+static struct ares_addrinfo_cname *ares__malloc_addrinfo_cname(void)
{
struct ares_addrinfo_cname *cname = ares_malloc(sizeof(struct ares_addrinfo_cname));
if (!cname)
@@ -160,7 +174,7 @@ void ares__addrinfo_cat_cnames(struct ares_addrinfo_cname **head,
last->next = tail;
}
-struct ares_addrinfo *ares__malloc_addrinfo()
+static struct ares_addrinfo *ares__malloc_addrinfo(void)
{
struct ares_addrinfo *ai = ares_malloc(sizeof(struct ares_addrinfo));
if (!ai)
@@ -170,10 +184,10 @@ struct ares_addrinfo *ares__malloc_addrinfo()
return ai;
}
-struct ares_addrinfo_node *ares__malloc_addrinfo_node()
+static struct ares_addrinfo_node *ares__malloc_addrinfo_node(void)
{
struct ares_addrinfo_node *node =
- ares_malloc(sizeof(struct ares_addrinfo_node));
+ ares_malloc(sizeof(*node));
if (!node)
return NULL;
@@ -375,6 +389,7 @@ static void end_hquery(struct host_query *hquery, int status)
{
struct ares_addrinfo_node sentinel;
struct ares_addrinfo_node *next;
+
if (status == ARES_SUCCESS)
{
if (!(hquery->hints.ai_flags & ARES_AI_NOSORT) && hquery->ai->nodes)
@@ -563,59 +578,68 @@ static void next_lookup(struct host_query *hquery, int status)
}
}
+
+static void terminate_retries(struct host_query *hquery, unsigned short qid)
+{
+ unsigned short term_qid = (qid == hquery->qid_a)?hquery->qid_aaaa:hquery->qid_a;
+ ares_channel channel = hquery->channel;
+ struct query *query = NULL;
+
+ /* No other outstanding queries, nothing to do */
+ if (!hquery->remaining)
+ return;
+
+ query = ares__htable_stvp_get_direct(channel->queries_by_qid, term_qid);
+ if (query == NULL)
+ return;
+
+ query->no_retries = 1;
+}
+
+
static void host_callback(void *arg, int status, int timeouts,
unsigned char *abuf, int alen)
{
struct host_query *hquery = (struct host_query*)arg;
int addinfostatus = ARES_SUCCESS;
+ unsigned short qid = 0;
hquery->timeouts += timeouts;
hquery->remaining--;
- if (status == ARES_SUCCESS)
- {
- addinfostatus = ares__parse_into_addrinfo(abuf, alen, 1, hquery->port, hquery->ai);
+ if (status == ARES_SUCCESS) {
+ addinfostatus = ares__parse_into_addrinfo(abuf, alen, 1, hquery->port,
+ hquery->ai);
+ if (addinfostatus == ARES_SUCCESS && alen >= HFIXEDSZ) {
+ qid = DNS_HEADER_QID(abuf); /* Converts to host byte order */
+ terminate_retries(hquery, qid);
}
+ }
- if (!hquery->remaining)
- {
- if (addinfostatus != ARES_SUCCESS && addinfostatus != ARES_ENODATA)
- {
- /* error in parsing result e.g. no memory */
- if (addinfostatus == ARES_EBADRESP && hquery->ai->nodes)
- {
- /* We got a bad response from server, but at least one query
- * ended with ARES_SUCCESS */
- end_hquery(hquery, ARES_SUCCESS);
- }
- else
- {
- end_hquery(hquery, addinfostatus);
- }
- }
- else if (hquery->ai->nodes)
- {
- /* at least one query ended with ARES_SUCCESS */
- end_hquery(hquery, ARES_SUCCESS);
- }
- else if (status == ARES_ENOTFOUND || status == ARES_ENODATA ||
- addinfostatus == ARES_ENODATA)
- {
- if (status == ARES_ENODATA || addinfostatus == ARES_ENODATA)
- hquery->nodata_cnt++;
- next_lookup(hquery, hquery->nodata_cnt?ARES_ENODATA:status);
- }
- else if (status == ARES_EDESTRUCTION)
- {
- /* NOTE: Could also be ARES_EDESTRUCTION. We need to only call this
- * once all queries (there can be multiple for getaddrinfo) are
- * terminated. */
- end_hquery(hquery, status);
- }
- else
- {
- end_hquery(hquery, status);
- }
+ if (!hquery->remaining) {
+ if (addinfostatus != ARES_SUCCESS && addinfostatus != ARES_ENODATA) {
+ /* error in parsing result e.g. no memory */
+ if (addinfostatus == ARES_EBADRESP && hquery->ai->nodes) {
+ /* We got a bad response from server, but at least one query
+ * ended with ARES_SUCCESS */
+ end_hquery(hquery, ARES_SUCCESS);
+ } else {
+ end_hquery(hquery, addinfostatus);
+ }
+ } else if (hquery->ai->nodes) {
+ /* at least one query ended with ARES_SUCCESS */
+ end_hquery(hquery, ARES_SUCCESS);
+ } else if (status == ARES_EDESTRUCTION || status == ARES_ECANCELLED) {
+ /* must make sure we don't do next_lookup() on destroy or cancel */
+ end_hquery(hquery, status);
+ } else if (status == ARES_ENOTFOUND || status == ARES_ENODATA ||
+ addinfostatus == ARES_ENODATA) {
+ if (status == ARES_ENODATA || addinfostatus == ARES_ENODATA)
+ hquery->nodata_cnt++;
+ next_lookup(hquery, hquery->nodata_cnt?ARES_ENODATA:status);
+ } else {
+ end_hquery(hquery, status);
}
+ }
/* at this point we keep on waiting for the next query to finish */
}
@@ -715,7 +739,7 @@ void ares_getaddrinfo(ares_channel channel,
}
/* Allocate and fill in the host query structure. */
- hquery = ares_malloc(sizeof(struct host_query));
+ hquery = ares_malloc(sizeof(*hquery));
if (!hquery)
{
ares_free(alias_name);
@@ -723,7 +747,7 @@ void ares_getaddrinfo(ares_channel channel,
callback(arg, ARES_ENOMEM, 0, NULL);
return;
}
-
+ memset(hquery, 0, sizeof(*hquery));
hquery->name = ares_strdup(name);
ares_free(alias_name);
if (!hquery->name)
@@ -741,11 +765,8 @@ void ares_getaddrinfo(ares_channel channel,
hquery->callback = callback;
hquery->arg = arg;
hquery->remaining_lookups = channel->lookups;
- hquery->timeouts = 0;
hquery->ai = ai;
hquery->next_domain = -1;
- hquery->remaining = 0;
- hquery->nodata_cnt = 0;
/* Start performing lookups according to channel->lookups. */
next_lookup(hquery, ARES_ECONNREFUSED /* initial error code */);
@@ -790,20 +811,26 @@ static int next_dns_lookup(struct host_query *hquery)
if (s)
{
+ /* NOTE: hquery may be invalidated during the call to ares_query_qid(),
+ * so should not be referenced after this point */
switch (hquery->hints.ai_family)
{
case AF_INET:
hquery->remaining += 1;
- ares_query(hquery->channel, s, C_IN, T_A, host_callback, hquery);
+ ares_query_qid(hquery->channel, s, C_IN, T_A, host_callback, hquery,
+ &hquery->qid_a);
break;
case AF_INET6:
hquery->remaining += 1;
- ares_query(hquery->channel, s, C_IN, T_AAAA, host_callback, hquery);
+ ares_query_qid(hquery->channel, s, C_IN, T_AAAA, host_callback,
+ hquery, &hquery->qid_aaaa);
break;
case AF_UNSPEC:
hquery->remaining += 2;
- ares_query(hquery->channel, s, C_IN, T_A, host_callback, hquery);
- ares_query(hquery->channel, s, C_IN, T_AAAA, host_callback, hquery);
+ ares_query_qid(hquery->channel, s, C_IN, T_A, host_callback,
+ hquery, &hquery->qid_a);
+ ares_query_qid(hquery->channel, s, C_IN, T_AAAA, host_callback,
+ hquery, &hquery->qid_aaaa);
break;
default: break;
}
@@ -825,7 +852,7 @@ static int as_is_first(const struct host_query* hquery)
char* p;
int ndots = 0;
size_t nname = hquery->name?strlen(hquery->name):0;
- for (p = hquery->name; *p; p++)
+ for (p = hquery->name; p && *p; p++)
{
if (*p == '.')
{
diff --git a/contrib/libs/c-ares/src/lib/ares_getenv.c b/contrib/libs/c-ares/src/lib/ares_getenv.c
index f6e4dc2952..08601a61e5 100644
--- a/contrib/libs/c-ares/src/lib/ares_getenv.c
+++ b/contrib/libs/c-ares/src/lib/ares_getenv.c
@@ -1,18 +1,28 @@
-
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
+/* MIT License
+ *
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * Copyright (c) The c-ares project and its contributors
+ *
+ * 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.
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * SPDX-License-Identifier: MIT
*/
#include "ares_setup.h"
diff --git a/contrib/libs/c-ares/src/lib/ares_getenv.h b/contrib/libs/c-ares/src/lib/ares_getenv.h
index 6da6cc5081..d8bd3a2195 100644
--- a/contrib/libs/c-ares/src/lib/ares_getenv.h
+++ b/contrib/libs/c-ares/src/lib/ares_getenv.h
@@ -1,21 +1,31 @@
-#ifndef HEADER_CARES_GETENV_H
-#define HEADER_CARES_GETENV_H
-
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
+/* MIT License
+ *
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * Copyright (c) The c-ares project and its contributors
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * 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 HEADER_CARES_GETENV_H
+#define HEADER_CARES_GETENV_H
#include "ares_setup.h"
diff --git a/contrib/libs/c-ares/src/lib/ares_gethostbyaddr.c b/contrib/libs/c-ares/src/lib/ares_gethostbyaddr.c
index 1242a8f19a..90187e2842 100644
--- a/contrib/libs/c-ares/src/lib/ares_gethostbyaddr.c
+++ b/contrib/libs/c-ares/src/lib/ares_gethostbyaddr.c
@@ -1,18 +1,30 @@
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
+/* MIT License
+ *
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * Copyright (c) The c-ares project and its contributors
+ *
+ * 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:
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * 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_setup.h"
#ifdef HAVE_NETINET_IN_H
@@ -53,7 +65,7 @@ static void addr_callback(void *arg, int status, int timeouts,
static void end_aquery(struct addr_query *aquery, int status,
struct hostent *host);
static int file_lookup(struct ares_addr *addr, struct hostent **host);
-static void ptr_rr_name(char *name, const struct ares_addr *addr);
+static void ptr_rr_name(char *name, int name_size, const struct ares_addr *addr);
void ares_gethostbyaddr(ares_channel channel, const void *addr, int addrlen,
int family, ares_host_callback callback, void *arg)
@@ -105,7 +117,7 @@ static void next_lookup(struct addr_query *aquery)
switch (*p)
{
case 'b':
- ptr_rr_name(name, &aquery->addr);
+ ptr_rr_name(name, sizeof(name), &aquery->addr);
aquery->remaining_lookups = p + 1;
ares_query(aquery->channel, name, C_IN, T_PTR, addr_callback,
aquery);
@@ -255,7 +267,7 @@ static int file_lookup(struct ares_addr *addr, struct hostent **host)
return status;
}
-static void ptr_rr_name(char *name, const struct ares_addr *addr)
+static void ptr_rr_name(char *name, int name_size, const struct ares_addr *addr)
{
if (addr->family == AF_INET)
{
@@ -264,20 +276,20 @@ static void ptr_rr_name(char *name, const struct ares_addr *addr)
unsigned long a2 = (laddr >> 16UL) & 0xFFUL;
unsigned long a3 = (laddr >> 8UL) & 0xFFUL;
unsigned long a4 = laddr & 0xFFUL;
- sprintf(name, "%lu.%lu.%lu.%lu.in-addr.arpa", a4, a3, a2, a1);
+ snprintf(name, name_size, "%lu.%lu.%lu.%lu.in-addr.arpa", a4, a3, a2, a1);
}
else
{
unsigned char *bytes = (unsigned char *)&addr->addrV6;
/* There are too many arguments to do this in one line using
* minimally C89-compliant compilers */
- sprintf(name,
+ snprintf(name, name_size,
"%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.",
bytes[15]&0xf, bytes[15] >> 4, bytes[14]&0xf, bytes[14] >> 4,
bytes[13]&0xf, bytes[13] >> 4, bytes[12]&0xf, bytes[12] >> 4,
bytes[11]&0xf, bytes[11] >> 4, bytes[10]&0xf, bytes[10] >> 4,
bytes[9]&0xf, bytes[9] >> 4, bytes[8]&0xf, bytes[8] >> 4);
- sprintf(name+strlen(name),
+ snprintf(name+strlen(name), name_size-strlen(name),
"%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.ip6.arpa",
bytes[7]&0xf, bytes[7] >> 4, bytes[6]&0xf, bytes[6] >> 4,
bytes[5]&0xf, bytes[5] >> 4, bytes[4]&0xf, bytes[4] >> 4,
diff --git a/contrib/libs/c-ares/src/lib/ares_gethostbyname.c b/contrib/libs/c-ares/src/lib/ares_gethostbyname.c
index 8c71cc67f3..343bd7b733 100644
--- a/contrib/libs/c-ares/src/lib/ares_gethostbyname.c
+++ b/contrib/libs/c-ares/src/lib/ares_gethostbyname.c
@@ -1,16 +1,28 @@
-/* Copyright 1998, 2011, 2013 by the Massachusetts Institute of Technology.
+/* MIT License
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * Copyright (c) 1998, 2011, 2013 Massachusetts Institute of Technology
+ * Copyright (c) The c-ares project and its contributors
+ *
+ * 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_setup.h"
diff --git a/contrib/libs/c-ares/src/lib/ares_getnameinfo.c b/contrib/libs/c-ares/src/lib/ares_getnameinfo.c
index 966919ac23..0d97a318bf 100644
--- a/contrib/libs/c-ares/src/lib/ares_getnameinfo.c
+++ b/contrib/libs/c-ares/src/lib/ares_getnameinfo.c
@@ -1,17 +1,27 @@
-
-/* Copyright 2005 by Dominick Meglio
+/* MIT License
+ *
+ * Copyright (c) 2005, 2013 Dominick Meglio
+ *
+ * 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.
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * SPDX-License-Identifier: MIT
*/
#include "ares_setup.h"
@@ -327,7 +337,7 @@ static char *lookup_service(unsigned short port, int flags,
else
{
/* get port as a string */
- sprintf(tmpbuf, "%u", (unsigned int)ntohs(port));
+ snprintf(tmpbuf, sizeof(tmpbuf), "%u", (unsigned int)ntohs(port));
name = tmpbuf;
}
name_len = strlen(name);
@@ -364,11 +374,11 @@ static void append_scopeid(struct sockaddr_in6 *addr6, unsigned int flags,
{
if (is_scope_long)
{
- sprintf(&tmpbuf[1], "%lu", (unsigned long)addr6->sin6_scope_id);
+ snprintf(&tmpbuf[1], sizeof(tmpbuf)-1, "%lu", (unsigned long)addr6->sin6_scope_id);
}
else
{
- sprintf(&tmpbuf[1], "%u", (unsigned int)addr6->sin6_scope_id);
+ snprintf(&tmpbuf[1], sizeof(tmpbuf)-1, "%u", (unsigned int)addr6->sin6_scope_id);
}
}
else
@@ -377,22 +387,22 @@ static void append_scopeid(struct sockaddr_in6 *addr6, unsigned int flags,
{
if (is_scope_long)
{
- sprintf(&tmpbuf[1], "%lu", (unsigned long)addr6->sin6_scope_id);
+ snprintf(&tmpbuf[1], sizeof(tmpbuf)-1, "%lu", (unsigned long)addr6->sin6_scope_id);
}
else
{
- sprintf(&tmpbuf[1], "%u", (unsigned int)addr6->sin6_scope_id);
+ snprintf(&tmpbuf[1], sizeof(tmpbuf)-1, "%u", (unsigned int)addr6->sin6_scope_id);
}
}
}
#else
if (is_scope_long)
{
- sprintf(&tmpbuf[1], "%lu", (unsigned long)addr6->sin6_scope_id);
+ snprintf(&tmpbuf[1], sizeof(tmpbuf)-1, "%lu", (unsigned long)addr6->sin6_scope_id);
}
else
{
- sprintf(&tmpbuf[1], "%u", (unsigned int)addr6->sin6_scope_id);
+ snprintf(&tmpbuf[1], sizeof(tmpbuf)-1, "%u", (unsigned int)addr6->sin6_scope_id);
}
(void) flags;
#endif
diff --git a/contrib/libs/c-ares/src/lib/ares_getsock.c b/contrib/libs/c-ares/src/lib/ares_getsock.c
index 22d344679f..48c9076a66 100644
--- a/contrib/libs/c-ares/src/lib/ares_getsock.c
+++ b/contrib/libs/c-ares/src/lib/ares_getsock.c
@@ -1,15 +1,27 @@
-
-/* Copyright (C) 2005 - 2010, Daniel Stenberg
+/* MIT License
+ *
+ * Copyright (c) 2005 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:
*
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in advertising or
- * publicity pertaining to distribution of the software without specific,
- * written prior permission. M.I.T. makes no representations about the
- * suitability of this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * 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_setup.h"
@@ -28,39 +40,40 @@ int ares_getsock(ares_channel channel,
unsigned int setbits = 0xffffffff;
/* Are there any active queries? */
- int active_queries = !ares__is_list_empty(&(channel->all_queries));
+ size_t active_queries = ares__llist_len(channel->all_queries);
+
+ for (i = 0; i < channel->nservers; i++) {
+ ares__llist_node_t *node;
+ server = &channel->servers[i];
+
+ for (node = ares__llist_node_first(server->connections);
+ node != NULL;
+ node = ares__llist_node_next(node)) {
+
+ struct server_connection *conn = ares__llist_node_val(node);
+
+ if (sockindex >= numsocks || sockindex >= ARES_GETSOCK_MAXNUM)
+ break;
- for (i = 0; i < channel->nservers; i++)
- {
- server = &channel->servers[i];
/* We only need to register interest in UDP sockets if we have
* outstanding queries.
*/
- if (active_queries && server->udp_socket != ARES_SOCKET_BAD)
- {
- if(sockindex >= numsocks || sockindex >= ARES_GETSOCK_MAXNUM)
- break;
- socks[sockindex] = server->udp_socket;
- bitmap |= ARES_GETSOCK_READABLE(setbits, sockindex);
- sockindex++;
- }
- /* We always register for TCP events, because we want to know
- * when the other side closes the connection, so we don't waste
- * time trying to use a broken connection.
- */
- if (server->tcp_socket != ARES_SOCKET_BAD)
- {
- if(sockindex >= numsocks || sockindex >= ARES_GETSOCK_MAXNUM)
- break;
- socks[sockindex] = server->tcp_socket;
- bitmap |= ARES_GETSOCK_READABLE(setbits, sockindex);
+ if (!active_queries && !conn->is_tcp)
+ continue;
+
+ socks[sockindex] = conn->fd;
+
+ if (active_queries || conn->is_tcp) {
+ bitmap |= ARES_GETSOCK_READABLE(setbits, sockindex);
+ }
- if (server->qhead && active_queries)
- /* then the tcp socket is also writable! */
- bitmap |= ARES_GETSOCK_WRITABLE(setbits, sockindex);
+ if (conn->is_tcp && ares__buf_len(server->tcp_send)) {
+ /* then the tcp socket is also writable! */
+ bitmap |= ARES_GETSOCK_WRITABLE(setbits, sockindex);
+ }
- sockindex++;
- }
+ sockindex++;
}
+ }
return bitmap;
}
diff --git a/contrib/libs/c-ares/src/lib/ares_inet_net_pton.h b/contrib/libs/c-ares/src/lib/ares_inet_net_pton.h
index 90da2cc651..179d36d972 100644
--- a/contrib/libs/c-ares/src/lib/ares_inet_net_pton.h
+++ b/contrib/libs/c-ares/src/lib/ares_inet_net_pton.h
@@ -1,20 +1,30 @@
-#ifndef HEADER_CARES_INET_NET_PTON_H
-#define HEADER_CARES_INET_NET_PTON_H
-
-/* Copyright (C) 2005-2013 by Daniel Stenberg et al
+/* MIT License
+ *
+ * Copyright (c) 2005 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:
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * 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 HEADER_CARES_INET_NET_PTON_H
+#define HEADER_CARES_INET_NET_PTON_H
#ifdef HAVE_INET_NET_PTON
#define ares_inet_net_pton(w,x,y,z) inet_net_pton(w,x,y,z)
diff --git a/contrib/libs/c-ares/src/lib/ares_init.c b/contrib/libs/c-ares/src/lib/ares_init.c
index 31c60b340b..25f1d8dfc0 100644
--- a/contrib/libs/c-ares/src/lib/ares_init.c
+++ b/contrib/libs/c-ares/src/lib/ares_init.c
@@ -1,18 +1,28 @@
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
- * Copyright (C) 2007-2013 by Daniel Stenberg
+/* 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.
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * 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_setup.h"
@@ -71,7 +81,7 @@ static int init_by_defaults(ares_channel channel);
#ifndef WATT32
static int config_nameserver(struct server_state **servers, int *nservers,
- char *str);
+ const char *str);
#endif
static int set_search(ares_channel channel, const char *str);
static int set_options(ares_channel channel, const char *str);
@@ -103,24 +113,40 @@ int ares_init(ares_channel *channelptr)
return ares_init_options(channelptr, NULL, 0);
}
+static int ares_query_timeout_cmp_cb(const void *arg1, const void *arg2)
+{
+ const struct query *q1 = arg1;
+ const struct query *q2 = arg2;
+
+ if (q1->timeout.tv_sec > q2->timeout.tv_sec)
+ return 1;
+ if (q1->timeout.tv_sec < q2->timeout.tv_sec)
+ return -1;
+
+ if (q1->timeout.tv_usec > q2->timeout.tv_usec)
+ return 1;
+ if (q1->timeout.tv_usec < q2->timeout.tv_usec)
+ return -1;
+
+ return 0;
+}
+
int ares_init_options(ares_channel *channelptr, struct ares_options *options,
int optmask)
{
ares_channel channel;
- int i;
int status = ARES_SUCCESS;
- struct timeval now;
if (ares_library_initialized() != ARES_SUCCESS)
return ARES_ENOTINITIALIZED; /* LCOV_EXCL_LINE: n/a on non-WinSock */
- channel = ares_malloc(sizeof(struct ares_channeldata));
+ channel = ares_malloc(sizeof(*channel));
if (!channel) {
*channelptr = NULL;
return ARES_ENOMEM;
}
- now = ares__tvnow();
+ memset(channel, 0, sizeof(*channel));
/* Set everything to distinguished values so we know they haven't
* been set yet.
@@ -141,40 +167,43 @@ int ares_init_options(ares_channel *channelptr, struct ares_options *options,
channel->nservers = -1;
channel->ndomains = -1;
channel->nsort = -1;
- channel->tcp_connection_generation = 0;
- channel->lookups = NULL;
- channel->domains = NULL;
- channel->sortlist = NULL;
- channel->servers = NULL;
- channel->sock_state_cb = NULL;
- channel->sock_state_cb_data = NULL;
- channel->sock_create_cb = NULL;
- channel->sock_create_cb_data = NULL;
- channel->sock_config_cb = NULL;
- channel->sock_config_cb_data = NULL;
- channel->sock_funcs = NULL;
- channel->sock_func_cb_data = NULL;
- channel->resolvconf_path = NULL;
- channel->hosts_path = NULL;
- channel->rand_state = NULL;
-
- channel->last_server = 0;
- channel->last_timeout_processed = (time_t)now.tv_sec;
-
- memset(&channel->local_dev_name, 0, sizeof(channel->local_dev_name));
- channel->local_ip4 = 0;
- memset(&channel->local_ip6, 0, sizeof(channel->local_ip6));
+
+ /* Generate random key */
+
+ channel->rand_state = ares__init_rand_state();
+ if (channel->rand_state == NULL) {
+ status = ARES_ENOMEM;
+ DEBUGF(fprintf(stderr, "Error: init_id_key failed: %s\n",
+ ares_strerror(status)));
+ goto done;
+ }
/* Initialize our lists of queries */
- ares__init_list_head(&(channel->all_queries));
- for (i = 0; i < ARES_QID_TABLE_SIZE; i++)
- {
- ares__init_list_head(&(channel->queries_by_qid[i]));
- }
- for (i = 0; i < ARES_TIMEOUT_TABLE_SIZE; i++)
- {
- ares__init_list_head(&(channel->queries_by_timeout[i]));
- }
+ channel->all_queries = ares__llist_create(NULL);
+ if (channel->all_queries == NULL) {
+ status = ARES_ENOMEM;
+ goto done;
+ }
+
+ channel->queries_by_qid = ares__htable_stvp_create(NULL);
+ if (channel->queries_by_qid == NULL) {
+ status = ARES_ENOMEM;
+ goto done;
+ }
+
+ channel->queries_by_timeout = ares__slist_create(channel->rand_state,
+ ares_query_timeout_cmp_cb,
+ NULL);
+ if (channel->queries_by_timeout == NULL) {
+ status = ARES_ENOMEM;
+ goto done;
+ }
+
+ channel->connnode_by_socket = ares__htable_asvp_create(NULL);
+ if (channel->connnode_by_socket == NULL) {
+ status = ARES_ENOMEM;
+ goto done;
+ }
/* Initialize configuration by each of the four sources, from highest
* precedence to lowest.
@@ -207,27 +236,22 @@ int ares_init_options(ares_channel *channelptr, struct ares_options *options,
DEBUGF(fprintf(stderr, "Error: init_by_defaults failed: %s\n",
ares_strerror(status)));
- /* Generate random key */
-
- if (status == ARES_SUCCESS) {
- channel->rand_state = ares__init_rand_state();
- if (channel->rand_state == NULL) {
- status = ARES_ENOMEM;
- }
+ /* Trim to one server if ARES_FLAG_PRIMARY is set. */
+ if ((channel->flags & ARES_FLAG_PRIMARY) && channel->nservers > 1)
+ channel->nservers = 1;
- if (status == ARES_SUCCESS)
- channel->next_id = ares__generate_new_id(channel->rand_state);
- else
- DEBUGF(fprintf(stderr, "Error: init_id_key failed: %s\n",
- ares_strerror(status)));
+ status = ares__init_servers_state(channel);
+ if (status != ARES_SUCCESS) {
+ goto done;
}
done:
if (status != ARES_SUCCESS)
{
/* Something failed; clean up memory we may have allocated. */
- if (channel->servers)
+ if (channel->servers) {
ares_free(channel->servers);
+ }
if (channel->ndomains != -1)
ares__strsplit_free(channel->domains, channel->ndomains);
if (channel->sortlist)
@@ -240,16 +264,15 @@ done:
ares_free(channel->hosts_path);
if (channel->rand_state)
ares__destroy_rand_state(channel->rand_state);
+
+ ares__htable_stvp_destroy(channel->queries_by_qid);
+ ares__llist_destroy(channel->all_queries);
+ ares__slist_destroy(channel->queries_by_timeout);
+ ares__htable_asvp_destroy(channel->connnode_by_socket);
ares_free(channel);
return status;
}
- /* Trim to one server if ARES_FLAG_PRIMARY is set. */
- if ((channel->flags & ARES_FLAG_PRIMARY) && channel->nservers > 1)
- channel->nservers = 1;
-
- ares__init_servers_state(channel);
-
*channelptr = channel;
return ARES_SUCCESS;
}
@@ -384,6 +407,7 @@ int ares_save_options(ares_channel channel, struct ares_options *options,
options->servers = ares_malloc(ipv4_nservers * sizeof(struct in_addr));
if (!options->servers)
return ARES_ENOMEM;
+
for (i = j = 0; i < channel->nservers; i++)
{
if ((channel->servers[i].addr.family == AF_INET) &&
@@ -444,6 +468,11 @@ int ares_save_options(ares_channel channel, struct ares_options *options,
return ARES_ENOMEM;
}
+ if (channel->udp_max_queries > 0) {
+ (*optmask) |= ARES_OPT_UDP_MAX_QUERIES;
+ options->udp_max_queries = channel->udp_max_queries;
+ }
+
return ARES_SUCCESS;
}
@@ -501,9 +530,10 @@ static int init_by_options(ares_channel channel,
if (options->nservers > 0)
{
channel->servers =
- ares_malloc(options->nservers * sizeof(struct server_state));
+ ares_malloc(options->nservers * sizeof(*channel->servers));
if (!channel->servers)
return ARES_ENOMEM;
+ memset(channel->servers, 0, options->nservers * sizeof(*channel->servers));
for (i = 0; i < options->nservers; i++)
{
channel->servers[i].addr.family = AF_INET;
@@ -575,6 +605,9 @@ static int init_by_options(ares_channel channel,
return ARES_ENOMEM;
}
+ if (optmask & ARES_OPT_UDP_MAX_QUERIES)
+ channel->udp_max_queries = options->udp_max_queries;
+
channel->optmask = optmask;
return ARES_SUCCESS;
@@ -697,7 +730,7 @@ typedef struct
/* 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[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")];
+ char text[INET6_ADDRSTRLEN + 8]; /* [%s]:NNNNN */
} Address;
/* Sort Address values \a left and \a right by metric, returning the usual
@@ -894,6 +927,7 @@ static int get_DNS_Windows(char **outptr)
ipaDNSAddr;
ipaDNSAddr = ipaDNSAddr->Next)
{
+ char ipaddr[INET6_ADDRSTRLEN] = "";
namesrvr.sa = ipaDNSAddr->Address.lpSockaddr;
if (namesrvr.sa->sa_family == AF_INET)
@@ -923,10 +957,14 @@ static int get_DNS_Windows(char **outptr)
addresses[addressesIndex].orig_idx = addressesIndex;
if (!ares_inet_ntop(AF_INET, &namesrvr.sa4->sin_addr,
- addresses[addressesIndex].text,
- sizeof(addresses[0].text))) {
+ 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)
@@ -956,10 +994,14 @@ static int get_DNS_Windows(char **outptr)
addresses[addressesIndex].orig_idx = addressesIndex;
if (!ares_inet_ntop(AF_INET6, &namesrvr.sa6->sin6_addr,
- addresses[addressesIndex].text,
- sizeof(addresses[0].text))) {
+ ipaddr, sizeof(ipaddr))) {
continue;
}
+ snprintf(addresses[addressesIndex].text,
+ sizeof(addresses[addressesIndex].text),
+ "[%s]:%u",
+ ipaddr,
+ ntohs(namesrvr.sa6->sin6_port));
++addressesIndex;
}
else {
@@ -1173,11 +1215,11 @@ static int init_by_resolv_conf(ares_channel channel)
}
nservers = count4 + count6;
- servers = ares_malloc(nservers * sizeof(struct server_state));
+ servers = ares_malloc(nservers * sizeof(*servers));
if (!servers)
return ARES_ENOMEM;
- memset(servers, 0, nservers * sizeof(struct server_state));
+ memset(servers, 0, nservers * sizeof(*servers));
pserver = servers;
for (int i = 0; i < count4; ++i, ++pserver) {
@@ -1239,10 +1281,10 @@ static int init_by_resolv_conf(ares_channel channel)
return ARES_SUCCESS; /* use localhost DNS server */
nservers = i;
- servers = ares_malloc(sizeof(struct server_state));
+ servers = ares_malloc(sizeof(*servers));
if (!servers)
return ARES_ENOMEM;
- memset(servers, 0, sizeof(struct server_state));
+ memset(servers, 0, sizeof(*servers));
for (i = 0; def_nameservers[i]; i++)
{
@@ -1315,8 +1357,9 @@ static int init_by_resolv_conf(ares_channel channel)
# endif /* HAVE___SYSTEM_PROPERTY_GET */
#elif defined(CARES_USE_LIBRESOLV)
struct __res_state res;
+ int result;
memset(&res, 0, sizeof(res));
- int result = res_ninit(&res);
+ result = res_ninit(&res);
if (result == 0 && (res.options & RES_INIT)) {
status = ARES_EOF;
@@ -1325,18 +1368,28 @@ static int init_by_resolv_conf(ares_channel channel)
int nscount = res_getservers(&res, addr, MAXNS);
int i;
for (i = 0; i < nscount; ++i) {
- char str[INET6_ADDRSTRLEN];
+ char ipaddr[INET6_ADDRSTRLEN] = "";
+ char ipaddr_port[INET6_ADDRSTRLEN + 8]; /* [%s]:NNNNN */
+ unsigned short port = 0;
int config_status;
sa_family_t family = addr[i].sin.sin_family;
if (family == AF_INET) {
- ares_inet_ntop(family, &addr[i].sin.sin_addr, str, sizeof(str));
+ ares_inet_ntop(family, &addr[i].sin.sin_addr, ipaddr, sizeof(ipaddr));
+ port = ntohs(addr[i].sin.sin_port);
} else if (family == AF_INET6) {
- ares_inet_ntop(family, &addr[i].sin6.sin6_addr, str, sizeof(str));
+ ares_inet_ntop(family, &addr[i].sin6.sin6_addr, ipaddr, sizeof(ipaddr));
+ port = ntohs(addr[i].sin6.sin6_port);
} else {
continue;
}
- config_status = config_nameserver(&servers, &nservers, str);
+ if (port) {
+ snprintf(ipaddr_port, sizeof(ipaddr_port), "[%s]:%u", ipaddr, port);
+ } else {
+ snprintf(ipaddr_port, sizeof(ipaddr_port), "%s", ipaddr);
+ }
+
+ config_status = config_nameserver(&servers, &nservers, ipaddr_port);
if (config_status != ARES_SUCCESS) {
status = config_status;
break;
@@ -1592,11 +1645,12 @@ static int init_by_defaults(ares_channel channel)
if (channel->nservers == -1) {
/* If nobody specified servers, try a local named. */
- channel->servers = ares_malloc(sizeof(struct server_state));
+ channel->servers = ares_malloc(sizeof(*channel->servers));
if (!channel->servers) {
rc = ARES_ENOMEM;
goto error;
}
+ memset(channel->servers, 0, sizeof(*channel->servers));
channel->servers[0].addr.family = AF_INET;
channel->servers[0].addr.addrV4.s_addr = htonl(INADDR_LOOPBACK);
channel->servers[0].addr.udp_port = 0;
@@ -1690,6 +1744,7 @@ static int init_by_defaults(ares_channel channel)
ares_free(channel->servers);
channel->servers = NULL;
}
+ channel->nservers = 0;
if(channel->domains && channel->domains[0])
ares_free(channel->domains[0]);
@@ -1843,8 +1898,112 @@ static int ares_ipv6_server_blacklisted(const unsigned char ipaddr[16])
return 0;
}
-/* Add the IPv4 or IPv6 nameservers in str (separated by commas) to the
- * servers list, updating servers and nservers as required.
+/* Parse address and port in these formats, either ipv4 or ipv6 addresses
+ * are allowed:
+ * ipaddr
+ * [ipaddr]
+ * [ipaddr]:port
+ *
+ * If a port is not specified, will set port to 0.
+ *
+ * Will fail if an IPv6 nameserver as detected by
+ * ares_ipv6_server_blacklisted()
+ *
+ * Returns an error code on failure, else ARES_SUCCESS
+ */
+static int parse_dnsaddrport(const char *str, size_t len,
+ struct ares_addr *host, unsigned short *port)
+{
+ char ipaddr[INET6_ADDRSTRLEN] = "";
+ char ipport[6] = "";
+ size_t mylen;
+ const char *addr_start = NULL;
+ const char *addr_end = NULL;
+ const char *port_start = NULL;
+ const char *port_end = NULL;
+
+ /* Must start with [, hex digit or : */
+ if (len == 0 || (*str != '[' && !isxdigit(*str) && *str != ':')) {
+ return ARES_EBADSTR;
+ }
+
+ /* If it starts with a bracket, must end with a bracket */
+ if (*str == '[') {
+ const char *ptr;
+ addr_start = str+1;
+ ptr = memchr(addr_start, ']', len-1);
+ if (ptr == NULL) {
+ return ARES_EBADSTR;
+ }
+ addr_end = ptr-1;
+
+ /* Try to pull off port */
+ if ((size_t)(ptr - str) < len) {
+ ptr++;
+ if (*ptr != ':') {
+ return ARES_EBADSTR;
+ }
+
+ /* Missing port number */
+ if ((size_t)(ptr - str) == len) {
+ return ARES_EBADSTR;
+ }
+
+ port_start = ptr+1;
+ port_end = str+(len-1);
+ }
+ } else {
+ addr_start = str;
+ addr_end = str+(len-1);
+ }
+
+ mylen = (addr_end-addr_start)+1;
+ /* Larger than buffer with null term */
+ if (mylen+1 > sizeof(ipaddr)) {
+ return ARES_EBADSTR;
+ }
+
+ memset(ipaddr, 0, sizeof(ipaddr));
+ memcpy(ipaddr, addr_start, mylen);
+
+ if (port_start) {
+ mylen = (port_end-port_start)+1;
+ /* Larger than buffer with null term */
+ if (mylen+1 > sizeof(ipport)) {
+ return ARES_EBADSTR;
+ }
+ memset(ipport, 0, sizeof(ipport));
+ memcpy(ipport, port_start, mylen);
+ } else {
+ snprintf(ipport, sizeof(ipport), "0");
+ }
+
+ /* Convert textual address to binary format. */
+ if (ares_inet_pton(AF_INET, ipaddr, &host->addrV4) == 1) {
+ host->family = AF_INET;
+ } else if (ares_inet_pton(AF_INET6, ipaddr, &host->addrV6) == 1
+ /* Silently skip blacklisted IPv6 servers. */
+ && !ares_ipv6_server_blacklisted(
+ (const unsigned char *)&host->addrV6)) {
+ host->family = AF_INET6;
+ } else {
+ return ARES_EBADSTR;
+ }
+
+ *port = (unsigned short)atoi(ipport);
+ return ARES_SUCCESS;
+}
+
+/* Add the IPv4 or IPv6 nameservers in str (separated by commas or spaces) to
+ * the servers list, updating servers and nservers as required.
+ *
+ * If a nameserver is encapsulated in [ ] it may optionally include a port
+ * suffix, e.g.:
+ * [127.0.0.1]:59591
+ *
+ * The extended format is required to support OpenBSD's resolv.conf format:
+ * https://man.openbsd.org/OpenBSD-5.1/resolv.conf.5
+ * As well as MacOS libresolv that may include a non-default port number.
*
* This will silently ignore blacklisted IPv6 nameservers as detected by
* ares_ipv6_server_blacklisted().
@@ -1852,16 +2011,18 @@ static int ares_ipv6_server_blacklisted(const unsigned char ipaddr[16])
* Returns an error code on failure, else ARES_SUCCESS.
*/
static int config_nameserver(struct server_state **servers, int *nservers,
- char *str)
+ const char *str)
{
struct ares_addr host;
struct server_state *newserv;
- char *p, *txtaddr;
+ const char *p, *txtaddr;
/* On Windows, there may be more than one nameserver specified in the same
* registry key, so we parse input as a space or comma seperated list.
*/
for (p = str; p;)
{
+ unsigned short port;
+
/* Skip whitespace and commas. */
while (*p && (ISSPACE(*p) || (*p == ',')))
p++;
@@ -1875,34 +2036,24 @@ static int config_nameserver(struct server_state **servers, int *nservers,
/* Advance past this address. */
while (*p && !ISSPACE(*p) && (*p != ','))
p++;
- if (*p)
- /* Null terminate this address. */
- *p++ = '\0';
- else
- /* Reached end of input, done when this address is processed. */
- p = NULL;
- /* Convert textual address to binary format. */
- if (ares_inet_pton(AF_INET, txtaddr, &host.addrV4) == 1)
- host.family = AF_INET;
- else if (ares_inet_pton(AF_INET6, txtaddr, &host.addrV6) == 1
- /* Silently skip blacklisted IPv6 servers. */
- && !ares_ipv6_server_blacklisted(
- (const unsigned char *)&host.addrV6))
- host.family = AF_INET6;
- else
+ if (parse_dnsaddrport(txtaddr, p-txtaddr, &host, &port) !=
+ ARES_SUCCESS) {
continue;
+ }
/* Resize servers state array. */
newserv = ares_realloc(*servers, (*nservers + 1) *
- sizeof(struct server_state));
+ sizeof(*newserv));
if (!newserv)
return ARES_ENOMEM;
+ memset(((unsigned char *)newserv) + ((*nservers) * sizeof(*newserv)), 0, sizeof(*newserv));
+
/* Store address data. */
newserv[*nservers].addr.family = host.family;
- newserv[*nservers].addr.udp_port = 0;
- newserv[*nservers].addr.tcp_port = 0;
+ newserv[*nservers].addr.udp_port = htons(port);
+ newserv[*nservers].addr.tcp_port = htons(port);
if (host.family == AF_INET)
memcpy(&newserv[*nservers].addr.addrV4, &host.addrV4,
sizeof(host.addrV4));
@@ -2268,25 +2419,36 @@ int ares_set_sortlist(ares_channel channel, const char *sortstr)
return status;
}
-void ares__init_servers_state(ares_channel channel)
+int ares__init_servers_state(ares_channel channel)
{
struct server_state *server;
int i;
- for (i = 0; i < channel->nservers; i++)
- {
- server = &channel->servers[i];
- server->udp_socket = ARES_SOCKET_BAD;
- server->tcp_socket = ARES_SOCKET_BAD;
- server->tcp_connection_generation = ++channel->tcp_connection_generation;
- server->tcp_lenbuf_pos = 0;
- server->tcp_buffer_pos = 0;
- server->tcp_buffer = NULL;
- server->tcp_length = 0;
- server->qhead = NULL;
- server->qtail = NULL;
- ares__init_list_head(&server->queries_to_server);
- server->channel = channel;
- server->is_broken = 0;
+ for (i = 0; i < channel->nservers; i++) {
+ server = &channel->servers[i];
+
+ /* NOTE: Can't use memset() here because the server addresses have been
+ * filled in already */
+ server->tcp_parser = ares__buf_create();
+ if (server->tcp_parser == NULL)
+ return ARES_ENOMEM;
+
+ server->tcp_send = ares__buf_create();
+ if (server->tcp_send == NULL) {
+ ares__buf_destroy(server->tcp_parser);
+ return ARES_ENOMEM;
}
+
+ server->idx = i;
+ server->connections = ares__llist_create(NULL);
+ if (server->connections == NULL) {
+ ares__buf_destroy(server->tcp_parser);
+ ares__buf_destroy(server->tcp_send);
+ return ARES_ENOMEM;
+ }
+
+ server->tcp_connection_generation = ++channel->tcp_connection_generation;
+ server->channel = channel;
+ }
+ return ARES_SUCCESS;
}
diff --git a/contrib/libs/c-ares/src/lib/ares_ipv6.h b/contrib/libs/c-ares/src/lib/ares_ipv6.h
index fdbc21fe8f..edb305324b 100644
--- a/contrib/libs/c-ares/src/lib/ares_ipv6.h
+++ b/contrib/libs/c-ares/src/lib/ares_ipv6.h
@@ -1,17 +1,27 @@
-
-/* Copyright (C) 2005 by Dominick Meglio
+/* MIT License
+ *
+ * Copyright (c) 2005 Dominick Meglio
+ *
+ * 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.
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * SPDX-License-Identifier: MIT
*/
#ifndef ARES_IPV6_H
diff --git a/contrib/libs/c-ares/src/lib/ares_library_init.c b/contrib/libs/c-ares/src/lib/ares_library_init.c
index 0301015d2a..79f73b22d4 100644
--- a/contrib/libs/c-ares/src/lib/ares_library_init.c
+++ b/contrib/libs/c-ares/src/lib/ares_library_init.c
@@ -1,18 +1,28 @@
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
- * Copyright (C) 2004-2009 by Daniel Stenberg
+/* MIT License
+ *
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * 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.
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * SPDX-License-Identifier: MIT
*/
#include "ares_setup.h"
diff --git a/contrib/libs/c-ares/src/lib/ares_llist.c b/contrib/libs/c-ares/src/lib/ares_llist.c
deleted file mode 100644
index 36ca84c43e..0000000000
--- a/contrib/libs/c-ares/src/lib/ares_llist.c
+++ /dev/null
@@ -1,63 +0,0 @@
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
- *
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
- */
-
-#include "ares_setup.h"
-
-#include "ares.h"
-#include "ares_private.h"
-
-/* Routines for managing doubly-linked circular linked lists with a
- * dummy head.
- */
-
-/* Initialize a new head node */
-void ares__init_list_head(struct list_node* head) {
- head->prev = head;
- head->next = head;
- head->data = NULL;
-}
-
-/* Initialize a list node */
-void ares__init_list_node(struct list_node* node, void* d) {
- node->prev = NULL;
- node->next = NULL;
- node->data = d;
-}
-
-/* Returns true iff the given list is empty */
-int ares__is_list_empty(struct list_node* head) {
- return ((head->next == head) && (head->prev == head));
-}
-
-/* Inserts new_node before old_node */
-void ares__insert_in_list(struct list_node* new_node,
- struct list_node* old_node) {
- new_node->next = old_node;
- new_node->prev = old_node->prev;
- old_node->prev->next = new_node;
- old_node->prev = new_node;
-}
-
-/* Removes the node from the list it's in, if any */
-void ares__remove_from_list(struct list_node* node) {
- if (node->next != NULL) {
- node->prev->next = node->next;
- node->next->prev = node->prev;
- node->prev = NULL;
- node->next = NULL;
- }
-}
-
diff --git a/contrib/libs/c-ares/src/lib/ares_llist.h b/contrib/libs/c-ares/src/lib/ares_llist.h
deleted file mode 100644
index 20f4d1ce42..0000000000
--- a/contrib/libs/c-ares/src/lib/ares_llist.h
+++ /dev/null
@@ -1,39 +0,0 @@
-#ifndef __ARES_LLIST_H
-#define __ARES_LLIST_H
-
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
- *
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
- */
-
-
-/* Node definition for circular, doubly-linked list */
-struct list_node {
- struct list_node *prev;
- struct list_node *next;
- void* data;
-};
-
-void ares__init_list_head(struct list_node* head);
-
-void ares__init_list_node(struct list_node* node, void* d);
-
-int ares__is_list_empty(struct list_node* head);
-
-void ares__insert_in_list(struct list_node* new_node,
- struct list_node* old_node);
-
-void ares__remove_from_list(struct list_node* node);
-
-#endif /* __ARES_LLIST_H */
diff --git a/contrib/libs/c-ares/src/lib/ares_mkquery.c b/contrib/libs/c-ares/src/lib/ares_mkquery.c
index 5aea914bd0..da1898e74c 100644
--- a/contrib/libs/c-ares/src/lib/ares_mkquery.c
+++ b/contrib/libs/c-ares/src/lib/ares_mkquery.c
@@ -1,17 +1,28 @@
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
+/* MIT License
+ *
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * Copyright (c) The c-ares project and its contributors
+ *
+ * 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.
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * SPDX-License-Identifier: MIT
*/
#include "ares_setup.h"
diff --git a/contrib/libs/c-ares/src/lib/ares_nowarn.c b/contrib/libs/c-ares/src/lib/ares_nowarn.c
index f63d9135ec..65cabb37b2 100644
--- a/contrib/libs/c-ares/src/lib/ares_nowarn.c
+++ b/contrib/libs/c-ares/src/lib/ares_nowarn.c
@@ -1,20 +1,29 @@
-
-/* Copyright (C) 2010-2013 by Daniel Stenberg
+/* MIT License
+ *
+ * Copyright (c) 2010 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:
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * 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_setup.h"
#ifdef HAVE_ASSERT_H
diff --git a/contrib/libs/c-ares/src/lib/ares_nowarn.h b/contrib/libs/c-ares/src/lib/ares_nowarn.h
index 505e622098..3f5612dbb9 100644
--- a/contrib/libs/c-ares/src/lib/ares_nowarn.h
+++ b/contrib/libs/c-ares/src/lib/ares_nowarn.h
@@ -1,21 +1,30 @@
-#ifndef HEADER_CARES_NOWARN_H
-#define HEADER_CARES_NOWARN_H
-
-
-/* Copyright (C) 2010-2012 by Daniel Stenberg
+/* MIT License
+ *
+ * Copyright (c) 2010 Daniel Stenberg
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * 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 HEADER_CARES_NOWARN_H
+#define HEADER_CARES_NOWARN_H
long aresx_uztosl(size_t uznum);
int aresx_uztosi(size_t uznum);
diff --git a/contrib/libs/c-ares/src/lib/ares_options.c b/contrib/libs/c-ares/src/lib/ares_options.c
index de49de4625..78e16bb5d2 100644
--- a/contrib/libs/c-ares/src/lib/ares_options.c
+++ b/contrib/libs/c-ares/src/lib/ares_options.c
@@ -1,21 +1,30 @@
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
- * Copyright (C) 2008-2013 by Daniel Stenberg
+/* MIT License
+ *
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * Copyright (c) 2008 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:
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * 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_setup.h"
#ifdef HAVE_ARPA_INET_H
@@ -153,7 +162,7 @@ int ares_set_servers(ares_channel channel,
if (!channel)
return ARES_ENODATA;
- if (!ares__is_list_empty(&channel->all_queries))
+ if (ares__llist_len(channel->all_queries) != 0)
return ARES_ENOTIMP;
ares__destroy_servers_state(channel);
@@ -166,11 +175,12 @@ int ares_set_servers(ares_channel channel,
if (num_srvrs > 0)
{
/* Allocate storage for servers state */
- channel->servers = ares_malloc(num_srvrs * sizeof(struct server_state));
+ channel->servers = ares_malloc(num_srvrs * sizeof(*channel->servers));
if (!channel->servers)
{
return ARES_ENOMEM;
}
+ memset(channel->servers, 0, num_srvrs * sizeof(*channel->servers));
channel->nservers = num_srvrs;
/* Fill servers state address data */
for (i = 0, srvr = servers; srvr; i++, srvr = srvr->next)
@@ -205,7 +215,7 @@ int ares_set_servers_ports(ares_channel channel,
if (!channel)
return ARES_ENODATA;
- if (!ares__is_list_empty(&channel->all_queries))
+ if (ares__llist_len(channel->all_queries) != 0)
return ARES_ENOTIMP;
ares__destroy_servers_state(channel);
@@ -218,11 +228,12 @@ int ares_set_servers_ports(ares_channel channel,
if (num_srvrs > 0)
{
/* Allocate storage for servers state */
- channel->servers = ares_malloc(num_srvrs * sizeof(struct server_state));
+ channel->servers = ares_malloc(num_srvrs * sizeof(*channel->servers));
if (!channel->servers)
{
return ARES_ENOMEM;
}
+ memset(channel->servers, 0, num_srvrs * sizeof(*channel->servers));
channel->nservers = num_srvrs;
/* Fill servers state address data */
for (i = 0, srvr = servers; srvr; i++, srvr = srvr->next)
diff --git a/contrib/libs/c-ares/src/lib/ares_parse_a_reply.c b/contrib/libs/c-ares/src/lib/ares_parse_a_reply.c
index ee903c7510..b50dea3884 100644
--- a/contrib/libs/c-ares/src/lib/ares_parse_a_reply.c
+++ b/contrib/libs/c-ares/src/lib/ares_parse_a_reply.c
@@ -1,18 +1,28 @@
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
- * Copyright (C) 2019 by Andrew Selivanov
+/* MIT License
+ *
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * Copyright (c) 2019 Andrew Selivanov
+ *
+ * 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.
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * SPDX-License-Identifier: MIT
*/
#include "ares_setup.h"
diff --git a/contrib/libs/c-ares/src/lib/ares_parse_aaaa_reply.c b/contrib/libs/c-ares/src/lib/ares_parse_aaaa_reply.c
index 091065d317..7a839829eb 100644
--- a/contrib/libs/c-ares/src/lib/ares_parse_aaaa_reply.c
+++ b/contrib/libs/c-ares/src/lib/ares_parse_aaaa_reply.c
@@ -1,19 +1,29 @@
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
- * Copyright 2005 Dominick Meglio
- * Copyright (C) 2019 by Andrew Selivanov
+/* MIT License
+ *
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * Copyright (c) 2005 Dominick Meglio
+ * Copyright (c) 2019 Andrew Selivanov
+ *
+ * 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.
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * SPDX-License-Identifier: MIT
*/
#include "ares_setup.h"
diff --git a/contrib/libs/c-ares/src/lib/ares_parse_caa_reply.c b/contrib/libs/c-ares/src/lib/ares_parse_caa_reply.c
index f6d4d3c61f..f4581c124a 100644
--- a/contrib/libs/c-ares/src/lib/ares_parse_caa_reply.c
+++ b/contrib/libs/c-ares/src/lib/ares_parse_caa_reply.c
@@ -1,5 +1,37 @@
+/* MIT License
+ *
+ * Copyright (c) The c-ares project and its contributors
+ *
+ * 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
+ */
-/* Copyright 2020 by <danny.sonnenschein@platynum.ch>
+/* =============================================================================
+ * NOTE: The below copyright is preserved from the original author. In
+ * October 2023, there were attempts made to contact the author in order
+ * gain approval for relicensing to the modern MIT license from the
+ * below 1989 variant, but all contact information for the author is
+ * no longer valid.
+ *
+ * Copyright (c) 2020 <danny.sonnenschein@platynum.ch>
*
* Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without
@@ -12,6 +44,8 @@
* M.I.T. makes no representations about the suitability of
* this software for any purpose. It is provided "as is"
* without express or implied warranty.
+ *
+ * =============================================================================
*/
#include "ares_setup.h"
diff --git a/contrib/libs/c-ares/src/lib/ares_parse_mx_reply.c b/contrib/libs/c-ares/src/lib/ares_parse_mx_reply.c
index a57b282544..0015a1f76c 100644
--- a/contrib/libs/c-ares/src/lib/ares_parse_mx_reply.c
+++ b/contrib/libs/c-ares/src/lib/ares_parse_mx_reply.c
@@ -1,18 +1,28 @@
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
- * Copyright (C) 2010 Jeremy Lal <kapouer@melix.org>
+/* MIT License
+ *
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * Copyright (c) 2010 Jeremy Lal
+ *
+ * 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.
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * SPDX-License-Identifier: MIT
*/
#include "ares_setup.h"
diff --git a/contrib/libs/c-ares/src/lib/ares_parse_naptr_reply.c b/contrib/libs/c-ares/src/lib/ares_parse_naptr_reply.c
index 3a19b40ba6..d0eca374ec 100644
--- a/contrib/libs/c-ares/src/lib/ares_parse_naptr_reply.c
+++ b/contrib/libs/c-ares/src/lib/ares_parse_naptr_reply.c
@@ -1,20 +1,29 @@
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
- * Copyright (C) 2009 by Jakub Hrozek <jhrozek@redhat.com>
+/* MIT License
+ *
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * Copyright (c) 2009 Jakub Hrozek
+ *
+ * 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:
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * 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_setup.h"
#ifdef HAVE_NETINET_IN_H
diff --git a/contrib/libs/c-ares/src/lib/ares_parse_ns_reply.c b/contrib/libs/c-ares/src/lib/ares_parse_ns_reply.c
index 47d12994c9..28083d44c1 100644
--- a/contrib/libs/c-ares/src/lib/ares_parse_ns_reply.c
+++ b/contrib/libs/c-ares/src/lib/ares_parse_ns_reply.c
@@ -1,16 +1,28 @@
-/* Copyright 1998 by the Massachusetts Institute of Technology.
+/* MIT License
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * Copyright (c) The c-ares project and its contributors
+ *
+ * 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
*/
/*
diff --git a/contrib/libs/c-ares/src/lib/ares_parse_ptr_reply.c b/contrib/libs/c-ares/src/lib/ares_parse_ptr_reply.c
index 060a2019e2..9afb5e3e8c 100644
--- a/contrib/libs/c-ares/src/lib/ares_parse_ptr_reply.c
+++ b/contrib/libs/c-ares/src/lib/ares_parse_ptr_reply.c
@@ -1,17 +1,28 @@
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
+/* MIT License
+ *
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * Copyright (c) The c-ares project and its contributors
+ *
+ * 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.
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * SPDX-License-Identifier: MIT
*/
#include "ares_setup.h"
diff --git a/contrib/libs/c-ares/src/lib/ares_parse_soa_reply.c b/contrib/libs/c-ares/src/lib/ares_parse_soa_reply.c
index 48597d616d..8a205c84e1 100644
--- a/contrib/libs/c-ares/src/lib/ares_parse_soa_reply.c
+++ b/contrib/libs/c-ares/src/lib/ares_parse_soa_reply.c
@@ -1,18 +1,28 @@
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
- * Copyright (C) 2012 Marko Kreen <markokr@gmail.com>
+/* MIT License
+ *
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * Copyright (c) 2012 Marko Kreen
+ *
+ * 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.
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * SPDX-License-Identifier: MIT
*/
#include "ares_setup.h"
diff --git a/contrib/libs/c-ares/src/lib/ares_parse_srv_reply.c b/contrib/libs/c-ares/src/lib/ares_parse_srv_reply.c
index 8096381c30..0ff7659483 100644
--- a/contrib/libs/c-ares/src/lib/ares_parse_srv_reply.c
+++ b/contrib/libs/c-ares/src/lib/ares_parse_srv_reply.c
@@ -1,18 +1,28 @@
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
- * Copyright (C) 2009 by Jakub Hrozek <jhrozek@redhat.com>
+/* MIT License
+ *
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * Copyright (c) 2009 Jakub Hrozek
+ *
+ * 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.
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * SPDX-License-Identifier: MIT
*/
#include "ares_setup.h"
diff --git a/contrib/libs/c-ares/src/lib/ares_parse_txt_reply.c b/contrib/libs/c-ares/src/lib/ares_parse_txt_reply.c
index 2d4913d450..a0f998ec8a 100644
--- a/contrib/libs/c-ares/src/lib/ares_parse_txt_reply.c
+++ b/contrib/libs/c-ares/src/lib/ares_parse_txt_reply.c
@@ -1,18 +1,28 @@
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
- * Copyright (C) 2009 by Jakub Hrozek <jhrozek@redhat.com>
+/* MIT License
+ *
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * Copyright (c) 2009 Jakub Hrozek
+ *
+ * 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.
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * SPDX-License-Identifier: MIT
*/
#include "ares_setup.h"
diff --git a/contrib/libs/c-ares/src/lib/ares_parse_uri_reply.c b/contrib/libs/c-ares/src/lib/ares_parse_uri_reply.c
index d79b5c4d85..d5bb7ee45d 100644
--- a/contrib/libs/c-ares/src/lib/ares_parse_uri_reply.c
+++ b/contrib/libs/c-ares/src/lib/ares_parse_uri_reply.c
@@ -1,18 +1,28 @@
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
- * Copyright (C) 2009 by Jakub Hrozek <jhrozek@redhat.com>
+/* MIT License
+ *
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * Copyright (c) 2009 Jakub Hrozek
+ *
+ * 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:
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * 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_setup.h"
@@ -151,9 +161,6 @@ ares_parse_uri_reply (const unsigned char *abuf, int alen,
uri_curr->uri = strncpy(uri_curr->uri, (const char *)vptr, rr_len-4);
uri_curr->uri[rr_len-4]='\0';
uri_curr->ttl = rr_ttl;
-
- if (status != ARES_SUCCESS)
- break;
}
/* Don't lose memory in the next iteration */
diff --git a/contrib/libs/c-ares/src/lib/ares_platform.c b/contrib/libs/c-ares/src/lib/ares_platform.c
index 6c749dccb2..6fcbd49bb8 100644
--- a/contrib/libs/c-ares/src/lib/ares_platform.c
+++ b/contrib/libs/c-ares/src/lib/ares_platform.c
@@ -1,19 +1,28 @@
-
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
- * Copyright (C) 2004 - 2011 by Daniel Stenberg et al
+/* MIT License
+ *
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * 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.
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * SPDX-License-Identifier: MIT
*/
#include "ares_setup.h"
diff --git a/contrib/libs/c-ares/src/lib/ares_platform.h b/contrib/libs/c-ares/src/lib/ares_platform.h
index e6885ae546..44b2c03644 100644
--- a/contrib/libs/c-ares/src/lib/ares_platform.h
+++ b/contrib/libs/c-ares/src/lib/ares_platform.h
@@ -1,22 +1,31 @@
-#ifndef HEADER_CARES_PLATFORM_H
-#define HEADER_CARES_PLATFORM_H
-
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
- * Copyright (C) 2004 - 2011 by Daniel Stenberg et al
+/* MIT License
+ *
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * Copyright (c) 2004 Daniel Stenberg
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * 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 HEADER_CARES_PLATFORM_H
+#define HEADER_CARES_PLATFORM_H
#include "ares_setup.h"
diff --git a/contrib/libs/c-ares/src/lib/ares_private.h b/contrib/libs/c-ares/src/lib/ares_private.h
index e2df16c57d..2c30959e89 100644
--- a/contrib/libs/c-ares/src/lib/ares_private.h
+++ b/contrib/libs/c-ares/src/lib/ares_private.h
@@ -1,22 +1,31 @@
-#ifndef __ARES_PRIVATE_H
-#define __ARES_PRIVATE_H
-
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
- * Copyright (C) 2004-2010 by Daniel Stenberg
+/* MIT License
+ *
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * Copyright (c) 2010 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.
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * SPDX-License-Identifier: MIT
*/
+#ifndef __ARES_PRIVATE_H
+#define __ARES_PRIVATE_H
/*
* Define WIN32 when build target is Win32 API
@@ -33,12 +42,10 @@
#ifdef WATT32
#include <tcp.h>
#include <sys/ioctl.h>
-#define writev(s,v,c) writev_s(s,v,c)
-#define HAVE_WRITEV 1
#endif
-#define DEFAULT_TIMEOUT 5000 /* milliseconds */
-#define DEFAULT_TRIES 4
+#define DEFAULT_TIMEOUT 2000 /* milliseconds */
+#define DEFAULT_TRIES 3
#ifndef INADDR_NONE
#define INADDR_NONE 0xffffffff
#endif
@@ -102,7 +109,15 @@ W32_FUNC const char *_w32_GetHostsFile (void);
#endif
#include "ares_ipv6.h"
-#include "ares_llist.h"
+
+struct ares_rand_state;
+typedef struct ares_rand_state ares_rand_state;
+
+#include "ares__llist.h"
+#include "ares__slist.h"
+#include "ares__htable_stvp.h"
+#include "ares__htable_asvp.h"
+#include "ares__buf.h"
#ifndef HAVE_GETENV
# include "ares_getenv.h"
@@ -122,11 +137,6 @@ W32_FUNC const char *_w32_GetHostsFile (void);
# define strncasecmp(p1,p2,n) ares_strncasecmp(p1,p2,n)
#endif
-#ifndef HAVE_WRITEV
-# include "ares_writev.h"
-# define writev(s,ptr,cnt) ares_writev(s,ptr,cnt)
-#endif
-
/********* EDNS defines section ******/
#define EDNSPACKETSZ 1280 /* Reasonable UDP payload size, as suggested
in RFC2671 */
@@ -148,37 +158,31 @@ struct ares_addr {
struct query;
-struct send_request {
- /* Remaining data to send */
- const unsigned char *data;
- size_t len;
+struct server_state;
- /* The query for which we're sending this data */
- struct query* owner_query;
- /* The buffer we're using, if we have our own copy of the packet */
- unsigned char *data_storage;
-
- /* Next request in queue */
- struct send_request *next;
+struct server_connection {
+ struct server_state *server;
+ ares_socket_t fd;
+ int is_tcp;
+ /* total number of queries run on this connection since it was established */
+ size_t total_queries;
+ /* list of outstanding queries to this connection */
+ ares__llist_t *queries_to_conn;
};
struct server_state {
+ size_t idx; /* index for server in ares_channel */
struct ares_addr addr;
- ares_socket_t udp_socket;
- ares_socket_t tcp_socket;
- /* Mini-buffer for reading the length word */
- unsigned char tcp_lenbuf[2];
- int tcp_lenbuf_pos;
- int tcp_length;
+ ares__llist_t *connections;
+ struct server_connection *tcp_conn;
- /* Buffer for reading actual TCP data */
- unsigned char *tcp_buffer;
- int tcp_buffer_pos;
+ /* TCP buffer since multiple responses can come back in one read, or partial
+ * in a read */
+ ares__buf_t *tcp_parser;
/* TCP output queue */
- struct send_request *qhead;
- struct send_request *qtail;
+ ares__buf_t *tcp_send;
/* Which incarnation of this connection is this? We don't want to
* retransmit requests into the very same socket, but if the server
@@ -186,34 +190,27 @@ struct server_state {
* re-send. */
int tcp_connection_generation;
- /* Circular, doubly-linked list of outstanding queries to this server */
- struct list_node queries_to_server;
-
/* Link back to owning channel */
ares_channel channel;
-
- /* Is this server broken? We mark connections as broken when a
- * request that is queued for sending times out.
- */
- int is_broken;
};
/* State to represent a DNS query */
struct query {
/* Query ID from qbuf, for faster lookup, and current timeout */
- unsigned short qid;
+ unsigned short qid; /* host byte order */
struct timeval timeout;
+ ares_channel channel;
/*
- * Links for the doubly-linked lists in which we insert a query.
- * These circular, doubly-linked lists that are hash-bucketed based
- * the attributes we care about, help making most important
- * operations O(1).
+ * Node object for each list entry the query belongs to in order to
+ * make removal operations O(1).
*/
- struct list_node queries_by_qid; /* hopefully in same cache line as qid */
- struct list_node queries_by_timeout;
- struct list_node queries_to_server;
- struct list_node all_queries;
+ ares__slist_node_t *node_queries_by_timeout;
+ ares__llist_node_t *node_queries_to_conn;
+ ares__llist_node_t *node_all_queries;
+
+ /* connection handle for validation purposes */
+ const struct server_connection *conn;
/* Query buf with length at beginning, for TCP transmission */
unsigned char *tcpbuf;
@@ -232,6 +229,8 @@ struct query {
int using_tcp;
int error_status;
int timeouts; /* number of timeouts we saw for this request */
+ int no_retries; /* do not perform any additional retries, this is set when
+ * a query is to be canceled */
};
/* Per-server state for a query */
@@ -260,9 +259,6 @@ struct apattern {
unsigned short type;
};
-struct ares_rand_state;
-typedef struct ares_rand_state ares_rand_state;
-
struct ares_channeldata {
/* Configuration data */
int flags;
@@ -297,30 +293,28 @@ struct ares_channeldata {
struct server_state *servers;
int nservers;
- /* ID to use for next query */
- unsigned short next_id;
/* random state to use when generating new ids */
ares_rand_state *rand_state;
/* Generation number to use for the next TCP socket open/close */
int tcp_connection_generation;
- /* The time at which we last called process_timeouts(). Uses integer seconds
- just to draw the line somewhere. */
- time_t last_timeout_processed;
-
/* Last server we sent a query to. */
int last_server;
- /* Circular, doubly-linked list of queries, bucketed various ways.... */
- /* All active queries in a single list: */
- struct list_node all_queries;
+ /* All active queries in a single list */
+ ares__llist_t *all_queries;
/* Queries bucketed by qid, for quickly dispatching DNS responses: */
-#define ARES_QID_TABLE_SIZE 2048
- struct list_node queries_by_qid[ARES_QID_TABLE_SIZE];
+ ares__htable_stvp_t *queries_by_qid;
+
/* Queries bucketed by timeout, for quickly handling timeouts: */
-#define ARES_TIMEOUT_TABLE_SIZE 1024
- struct list_node queries_by_timeout[ARES_TIMEOUT_TABLE_SIZE];
+ ares__slist_t *queries_by_timeout;
+
+ /* Map linked list node member for connection to file descriptor. We use
+ * the node instead of the connection object itself so we can quickly look
+ * up a connection and remove it if necessary (as otherwise we'd have to
+ * scan all connections) */
+ ares__htable_asvp_t *connnode_by_socket;
ares_sock_state_cb sock_state_cb;
void *sock_state_cb_data;
@@ -339,6 +333,9 @@ struct ares_channeldata {
/* Path for hosts file, configurable via ares_options */
char *hosts_path;
+
+ /* Maximum UDP queries per connection allowed */
+ int udp_max_queries;
};
/* Does the domain end in ".onion" or ".onion."? Case-insensitive. */
@@ -353,15 +350,31 @@ extern void (*ares_free)(void *ptr);
int ares__timedout(struct timeval *now,
struct timeval *check);
-void ares__send_query(ares_channel channel, struct query *query,
- struct timeval *now);
-void ares__close_sockets(ares_channel channel, struct server_state *server);
+/* Returns one of the normal ares status codes like ARES_SUCCESS */
+int ares__send_query(ares_channel channel, struct query *query,
+ struct timeval *now);
+
+/* Identical to ares_query, but returns a normal ares return code like
+ * ARES_SUCCESS, and can be passed the qid by reference which will be
+ * filled in on ARES_SUCCESS */
+int ares_query_qid(ares_channel channel, const char *name,
+ int dnsclass, int type, ares_callback callback,
+ void *arg, unsigned short *qid);
+/* Identical to ares_send() except returns normal ares return codes like
+ * ARES_SUCCESS */
+int ares_send_ex(ares_channel channel, const unsigned char *qbuf, int qlen,
+ ares_callback callback, void *arg);
+void ares__close_connection(struct server_connection *conn);
+void ares__close_sockets(struct server_state *server);
+void ares__check_cleanup_conn(ares_channel channel, ares_socket_t fd);
int ares__get_hostent(FILE *fp, int family, struct hostent **host);
int ares__read_line(FILE *fp, char **buf, size_t *bufsize);
void ares__free_query(struct query *query);
ares_rand_state *ares__init_rand_state(void);
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);
struct timeval ares__tvnow(void);
int ares__expand_name_validated(const unsigned char *encoded,
@@ -371,7 +384,7 @@ int ares__expand_name_validated(const unsigned char *encoded,
int ares__expand_name_for_response(const unsigned char *encoded,
const unsigned char *abuf, int alen,
char **s, long *enclen, int is_hostname);
-void ares__init_servers_state(ares_channel channel);
+int ares__init_servers_state(ares_channel channel);
void ares__destroy_servers_state(ares_channel channel);
int ares__parse_qtype_reply(const unsigned char* abuf, int alen, int* qtype);
int ares__single_domain(ares_channel channel, const char *name, char **s);
@@ -381,16 +394,12 @@ int ares__readaddrinfo(FILE *fp, const char *name, unsigned short port,
const struct ares_addrinfo_hints *hints,
struct ares_addrinfo *ai);
-struct ares_addrinfo *ares__malloc_addrinfo(void);
-
-struct ares_addrinfo_node *ares__malloc_addrinfo_node(void);
void ares__freeaddrinfo_nodes(struct ares_addrinfo_node *ai_node);
struct ares_addrinfo_node *ares__append_addrinfo_node(struct ares_addrinfo_node **ai_node);
void ares__addrinfo_cat_nodes(struct ares_addrinfo_node **head,
struct ares_addrinfo_node *tail);
-struct ares_addrinfo_cname *ares__malloc_addrinfo_cname(void);
void ares__freeaddrinfo_cnames(struct ares_addrinfo_cname *ai_cname);
struct ares_addrinfo_cname *ares__append_addrinfo_cname(struct ares_addrinfo_cname **ai_cname);
diff --git a/contrib/libs/c-ares/src/lib/ares_process.c b/contrib/libs/c-ares/src/lib/ares_process.c
index f04008dd9a..a876f2a573 100644
--- a/contrib/libs/c-ares/src/lib/ares_process.c
+++ b/contrib/libs/c-ares/src/lib/ares_process.c
@@ -1,18 +1,28 @@
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
- * Copyright (C) 2004-2017 by Daniel Stenberg
+/* MIT License
+ *
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * Copyright (c) 2010 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:
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * 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_setup.h"
@@ -58,32 +68,27 @@
static int try_again(int errnum);
static void write_tcp_data(ares_channel channel, fd_set *write_fds,
ares_socket_t write_fd, struct timeval *now);
-static void read_tcp_data(ares_channel channel, fd_set *read_fds,
- ares_socket_t read_fd, struct timeval *now);
-static void read_udp_packets(ares_channel channel, fd_set *read_fds,
- ares_socket_t read_fd, struct timeval *now);
-static void advance_tcp_send_queue(ares_channel channel, int whichserver,
- ares_ssize_t num_bytes);
+static void read_packets(ares_channel channel, fd_set *read_fds,
+ ares_socket_t read_fd, struct timeval *now);
static void process_timeouts(ares_channel channel, struct timeval *now);
-static void process_broken_connections(ares_channel channel,
- struct timeval *now);
-static void process_answer(ares_channel channel, unsigned char *abuf,
- int alen, int whichserver, int tcp,
+static void process_answer(ares_channel channel, const unsigned char *abuf,
+ int alen, struct server_connection *conn, int tcp,
struct timeval *now);
-static void handle_error(ares_channel channel, int whichserver,
- struct timeval *now);
+static void handle_error(struct server_connection *conn, struct timeval *now);
static void skip_server(ares_channel channel, struct query *query,
- int whichserver);
-static void next_server(ares_channel channel, struct query *query,
+ struct server_state *server);
+static int next_server(ares_channel channel, struct query *query,
struct timeval *now);
-static int open_tcp_socket(ares_channel channel, struct server_state *server);
-static int open_udp_socket(ares_channel channel, struct server_state *server);
+static int open_socket(ares_channel channel, struct server_state *server,
+ int is_tcp);
static int same_questions(const unsigned char *qbuf, int qlen,
const unsigned char *abuf, int alen);
static int same_address(struct sockaddr *sa, struct ares_addr *aa);
static int has_opt_rr(const unsigned char *abuf, int alen);
static void end_query(ares_channel channel, struct query *query, int status,
- unsigned char *abuf, int alen);
+ const unsigned char *abuf, int alen);
+static ares_ssize_t ares__socket_write(ares_channel channel, ares_socket_t s,
+ const void * data, size_t len);
/* return true if now is exactly check time or later */
int ares__timedout(struct timeval *now,
@@ -122,10 +127,8 @@ static void processfds(ares_channel channel,
struct timeval now = ares__tvnow();
write_tcp_data(channel, write_fds, write_fd, &now);
- read_tcp_data(channel, read_fds, read_fd, &now);
- read_udp_packets(channel, read_fds, read_fd, &now);
+ read_packets(channel, read_fds, read_fd, &now);
process_timeouts(channel, &now);
- process_broken_connections(channel, &now);
}
/* Something interesting happened on the wire, or there was a timeout.
@@ -174,25 +177,6 @@ static int try_again(int errnum)
return 0;
}
-static ares_ssize_t socket_writev(ares_channel channel, ares_socket_t s, const struct iovec * vec, int len)
-{
- if (channel->sock_funcs)
- return channel->sock_funcs->asendv(s, vec, len, channel->sock_func_cb_data);
-
- return writev(s, vec, len);
-}
-
-static ares_ssize_t socket_write(ares_channel channel, ares_socket_t s, const void * data, size_t len)
-{
- if (channel->sock_funcs)
- {
- struct iovec vec;
- vec.iov_base = (void*)data;
- vec.iov_len = len;
- return channel->sock_funcs->asendv(s, &vec, 1, channel->sock_func_cb_data);
- }
- return swrite(s, data, len);
-}
/* If any TCP sockets select true for writing, write out queued data
* we have for them.
@@ -203,134 +187,60 @@ static void write_tcp_data(ares_channel channel,
struct timeval *now)
{
struct server_state *server;
- struct send_request *sendreq;
- struct iovec *vec;
int i;
- ares_ssize_t scount;
- ares_ssize_t wcount;
- size_t n;
- /* From writev manpage: An implementation can advertise its limit by defining
- IOV_MAX in <limits.h> or at run time via the return value from
- sysconf(_SC_IOV_MAX). On modern Linux systems, the limit is 1024. Back in
- Linux 2.0 days, this limit was 16. */
-#if defined(IOV_MAX)
- const size_t maxn = IOV_MAX; /* FreeBSD */
-#elif defined(_SC_IOV_MAX)
- const size_t maxn = sysconf(_SC_IOV_MAX); /* Linux */
-#else
- const size_t maxn = 16; /* Safe default */
-#endif
if(!write_fds && (write_fd == ARES_SOCKET_BAD))
/* no possible action */
return;
- for (i = 0; i < channel->nservers; i++)
- {
- /* Make sure server has data to send and is selected in write_fds or
- write_fd. */
- server = &channel->servers[i];
- if (!server->qhead || server->tcp_socket == ARES_SOCKET_BAD ||
- server->is_broken)
- continue;
-
- if(write_fds) {
- if(!FD_ISSET(server->tcp_socket, write_fds))
- continue;
- }
- else {
- if(server->tcp_socket != write_fd)
- continue;
- }
-
- if(write_fds)
- /* If there's an error and we close this socket, then open
- * another with the same fd to talk to another server, then we
- * don't want to think that it was the new socket that was
- * ready. This is not disastrous, but is likely to result in
- * extra system calls and confusion. */
- FD_CLR(server->tcp_socket, write_fds);
-
- /* Count the number of send queue items. */
- n = 0;
- for (sendreq = server->qhead; sendreq; sendreq = sendreq->next)
- n++;
-
- /* Allocate iovecs so we can send all our data at once. */
- vec = ares_malloc(n * sizeof(struct iovec));
- if (vec)
- {
- /* Fill in the iovecs and send. */
- n = 0;
- for (sendreq = server->qhead; sendreq; sendreq = sendreq->next)
- {
- vec[n].iov_base = (char *) sendreq->data;
- vec[n].iov_len = sendreq->len;
- n++;
- if(n >= maxn)
- break;
- }
- wcount = socket_writev(channel, server->tcp_socket, vec, (int)n);
- ares_free(vec);
- if (wcount < 0)
- {
- if (!try_again(SOCKERRNO))
- handle_error(channel, i, now);
- continue;
- }
+ for (i = 0; i < channel->nservers; i++) {
+ const unsigned char *data;
+ size_t data_len;
+ ares_ssize_t count;
- /* Advance the send queue by as many bytes as we sent. */
- advance_tcp_send_queue(channel, i, wcount);
- }
- else
- {
- /* Can't allocate iovecs; just send the first request. */
- sendreq = server->qhead;
+ /* Make sure server has data to send and is selected in write_fds or
+ write_fd. */
+ server = &channel->servers[i];
+ if (ares__buf_len(server->tcp_send) == 0 || server->tcp_conn == NULL)
+ continue;
- scount = socket_write(channel, server->tcp_socket, sendreq->data, sendreq->len);
- if (scount < 0)
- {
- if (!try_again(SOCKERRNO))
- handle_error(channel, i, now);
- continue;
- }
+ if (write_fds) {
+ if (!FD_ISSET(server->tcp_conn->fd, write_fds))
+ continue;
+ } else {
+ if (server->tcp_conn->fd != write_fd)
+ continue;
+ }
- /* Advance the send queue by as many bytes as we sent. */
- advance_tcp_send_queue(channel, i, scount);
- }
+ if (write_fds) {
+ /* If there's an error and we close this socket, then open
+ * another with the same fd to talk to another server, then we
+ * don't want to think that it was the new socket that was
+ * ready. This is not disastrous, but is likely to result in
+ * extra system calls and confusion. */
+ FD_CLR(server->tcp_conn->fd, write_fds);
}
-}
-/* Consume the given number of bytes from the head of the TCP send queue. */
-static void advance_tcp_send_queue(ares_channel channel, int whichserver,
- ares_ssize_t num_bytes)
-{
- struct send_request *sendreq;
- struct server_state *server = &channel->servers[whichserver];
- while (num_bytes > 0) {
- sendreq = server->qhead;
- if ((size_t)num_bytes >= sendreq->len) {
- num_bytes -= sendreq->len;
- server->qhead = sendreq->next;
- if (sendreq->data_storage)
- ares_free(sendreq->data_storage);
- ares_free(sendreq);
- if (server->qhead == NULL) {
- SOCK_STATE_CALLBACK(channel, server->tcp_socket, 1, 0);
- server->qtail = NULL;
-
- /* qhead is NULL so we cannot continue this loop */
- break;
+ data = ares__buf_peek(server->tcp_send, &data_len);
+ count = ares__socket_write(channel, server->tcp_conn->fd, data, data_len);
+ if (count <= 0) {
+ if (!try_again(SOCKERRNO)) {
+ handle_error(server->tcp_conn, now);
}
+ continue;
}
- else {
- sendreq->data += num_bytes;
- sendreq->len -= num_bytes;
- num_bytes = 0;
+
+ /* Strip data written from the buffer */
+ ares__buf_consume(server->tcp_send, count);
+
+ /* Notify state callback all data is written */
+ if (ares__buf_len(server->tcp_send) == 0) {
+ SOCK_STATE_CALLBACK(channel, server->tcp_conn->fd, 1, 0);
}
}
}
+
static ares_ssize_t socket_recvfrom(ares_channel channel,
ares_socket_t s,
void * data,
@@ -339,7 +249,7 @@ static ares_ssize_t socket_recvfrom(ares_channel channel,
struct sockaddr *from,
ares_socklen_t *from_len)
{
- if (channel->sock_funcs)
+ if (channel->sock_funcs && channel->sock_funcs->arecvfrom)
return channel->sock_funcs->arecvfrom(s, data, data_len,
flags, from, from_len,
channel->sock_func_cb_data);
@@ -356,122 +266,150 @@ static ares_ssize_t socket_recv(ares_channel channel,
void * data,
size_t data_len)
{
- if (channel->sock_funcs)
+ if (channel->sock_funcs && channel->sock_funcs->arecvfrom)
return channel->sock_funcs->arecvfrom(s, data, data_len, 0, 0, 0,
channel->sock_func_cb_data);
return sread(s, data, data_len);
}
+
/* If any TCP socket selects true for reading, read some data,
* allocate a buffer if we finish reading the length word, and process
* a packet if we finish reading one.
*/
-static void read_tcp_data(ares_channel channel, fd_set *read_fds,
- ares_socket_t read_fd, struct timeval *now)
+static void read_tcp_data(ares_channel channel, struct server_connection *conn,
+ struct timeval *now)
{
- struct server_state *server;
- int i;
- ares_ssize_t count;
+ ares_ssize_t count;
+ struct server_state *server = conn->server;
+
+ /* Fetch buffer to store data we are reading */
+ size_t ptr_len = 512;
+ unsigned char *ptr = ares__buf_append_start(server->tcp_parser,
+ &ptr_len);
+
+ if (ptr == NULL) {
+ handle_error(conn, now);
+ return; /* bail out on malloc failure. TODO: make this
+ function return error codes */
+ }
- if(!read_fds && (read_fd == ARES_SOCKET_BAD))
- /* no possible action */
+ /* Read from socket */
+ count = socket_recv(channel, conn->fd, ptr, ptr_len);
+ if (count <= 0) {
+ ares__buf_append_finish(server->tcp_parser, 0);
+ if (!(count == -1 && try_again(SOCKERRNO)))
+ handle_error(conn, now);
return;
+ }
- for (i = 0; i < channel->nservers; i++)
- {
- /* Make sure the server has a socket and is selected in read_fds. */
- server = &channel->servers[i];
- if (server->tcp_socket == ARES_SOCKET_BAD || server->is_broken)
- continue;
+ /* Record amount of data read */
+ ares__buf_append_finish(server->tcp_parser, count);
- if(read_fds) {
- if(!FD_ISSET(server->tcp_socket, read_fds))
- continue;
- }
- else {
- if(server->tcp_socket != read_fd)
- continue;
- }
+ /* Process all queued answers */
+ while (1) {
+ unsigned short dns_len = 0;
+ const unsigned char *data = NULL;
+ size_t data_len = 0;
- if(read_fds)
- /* If there's an error and we close this socket, then open another
- * with the same fd to talk to another server, then we don't want to
- * think that it was the new socket that was ready. This is not
- * disastrous, but is likely to result in extra system calls and
- * confusion. */
- FD_CLR(server->tcp_socket, read_fds);
+ /* Tag so we can roll back */
+ ares__buf_tag(server->tcp_parser);
- if (server->tcp_lenbuf_pos != 2)
- {
- /* We haven't yet read a length word, so read that (or
- * what's left to read of it).
- */
- count = socket_recv(channel, server->tcp_socket,
- server->tcp_lenbuf + server->tcp_lenbuf_pos,
- 2 - server->tcp_lenbuf_pos);
- if (count <= 0)
- {
- if (!(count == -1 && try_again(SOCKERRNO)))
- handle_error(channel, i, now);
- continue;
- }
+ /* Read length indicator */
+ if (ares__buf_fetch_be16(server->tcp_parser, &dns_len) != ARES_SUCCESS) {
+ ares__buf_tag_rollback(server->tcp_parser);
+ return;
+ }
- server->tcp_lenbuf_pos += (int)count;
- if (server->tcp_lenbuf_pos == 2)
- {
- /* We finished reading the length word. Decode the
- * length and allocate a buffer for the data.
- */
- server->tcp_length = server->tcp_lenbuf[0] << 8
- | server->tcp_lenbuf[1];
- server->tcp_buffer = ares_malloc(server->tcp_length);
- if (!server->tcp_buffer) {
- handle_error(channel, i, now);
- return; /* bail out on malloc failure. TODO: make this
- function return error codes */
- }
- server->tcp_buffer_pos = 0;
- }
- }
- else
- {
- /* Read data into the allocated buffer. */
- count = socket_recv(channel, server->tcp_socket,
- server->tcp_buffer + server->tcp_buffer_pos,
- server->tcp_length - server->tcp_buffer_pos);
- if (count <= 0)
- {
- if (!(count == -1 && try_again(SOCKERRNO)))
- handle_error(channel, i, now);
- continue;
- }
+ /* Not enough data for a full response yet */
+ if (ares__buf_consume(server->tcp_parser, dns_len) != ARES_SUCCESS) {
+ ares__buf_tag_rollback(server->tcp_parser);
+ return;
+ }
- server->tcp_buffer_pos += (int)count;
- if (server->tcp_buffer_pos == server->tcp_length)
- {
- /* We finished reading this answer; process it and
- * prepare to read another length word.
- */
- process_answer(channel, server->tcp_buffer, server->tcp_length,
- i, 1, now);
- ares_free(server->tcp_buffer);
- server->tcp_buffer = NULL;
- server->tcp_lenbuf_pos = 0;
- server->tcp_buffer_pos = 0;
- }
- }
+ /* Can't fail except for misuse */
+ data = ares__buf_tag_fetch(server->tcp_parser, &data_len);
+ if (data == NULL) {
+ ares__buf_tag_clear(server->tcp_parser);
+ return;
}
+
+ /* Strip off 2 bytes length */
+ data += 2;
+ data_len -= 2;
+
+ /* We finished reading this answer; process it */
+ process_answer(channel, data, (int)data_len, conn, 1, now);
+
+ /* Since we processed the answer, clear the tag so space can be reclaimed */
+ ares__buf_tag_clear(server->tcp_parser);
+ }
+}
+
+
+static int socket_list_append(ares_socket_t **socketlist, ares_socket_t fd,
+ size_t *alloc_cnt, size_t *num)
+{
+ if (*num >= *alloc_cnt) {
+ /* Grow by powers of 2 */
+ size_t new_alloc = (*alloc_cnt) << 1;
+ ares_socket_t *new_list = ares_realloc(socketlist,
+ new_alloc * sizeof(*new_list));
+ if (new_list == NULL)
+ return 0;
+ *alloc_cnt = new_alloc;
+ *socketlist = new_list;
+ }
+
+ (*socketlist)[(*num)++] = fd;
+ return 1;
+}
+
+
+static ares_socket_t *channel_socket_list(ares_channel channel, size_t *num)
+{
+ size_t alloc_cnt = 1 << 4;
+ int i;
+ ares_socket_t *out = ares_malloc(alloc_cnt * sizeof(*out));
+
+ *num = 0;
+
+ if (out == NULL)
+ return NULL;
+
+ for (i=0; i<channel->nservers; i++) {
+ ares__llist_node_t *node;
+ for (node = ares__llist_node_first(channel->servers[i].connections);
+ node != NULL;
+ node = ares__llist_node_next(node)) {
+ struct server_connection *conn = ares__llist_node_val(node);
+
+ if (conn->fd == ARES_SOCKET_BAD)
+ continue;
+
+ if (!socket_list_append(&out, conn->fd, &alloc_cnt, num))
+ goto fail;
+ }
+ }
+
+ return out;
+
+fail:
+ ares_free(out);
+ *num = 0;
+ return NULL;
}
/* If any UDP sockets select true for reading, process them. */
-static void read_udp_packets(ares_channel channel, fd_set *read_fds,
- ares_socket_t read_fd, struct timeval *now)
+static void read_udp_packets_fd(ares_channel channel,
+ struct server_connection *conn,
+ struct timeval *now)
{
- struct server_state *server;
- int i;
ares_ssize_t read_len;
unsigned char buf[MAXENDSSZ + 1];
+ ares_socket_t fd = conn->fd; /* Cache for validation */
+
#ifdef HAVE_RECVFROM
ares_socklen_t fromlen;
union {
@@ -481,148 +419,188 @@ static void read_udp_packets(ares_channel channel, fd_set *read_fds,
} from;
#endif
- if(!read_fds && (read_fd == ARES_SOCKET_BAD))
+ /* To reduce event loop overhead, read and process as many
+ * packets as we can. */
+ do {
+ if (conn->fd == ARES_SOCKET_BAD) {
+ read_len = -1;
+ } else {
+ if (conn->server->addr.family == AF_INET) {
+ fromlen = sizeof(from.sa4);
+ } else {
+ fromlen = sizeof(from.sa6);
+ }
+ read_len = socket_recvfrom(channel, conn->fd, (void *)buf,
+ sizeof(buf), 0, &from.sa, &fromlen);
+ }
+
+ if (read_len == 0) {
+ /* UDP is connectionless, so result code of 0 is a 0-length UDP
+ * packet, and not an indication the connection is closed like on
+ * tcp */
+ continue;
+ } else if (read_len < 0) {
+ if (try_again(SOCKERRNO))
+ continue;
+
+ handle_error(conn, now);
+ return;
+#ifdef HAVE_RECVFROM
+ } else if (!same_address(&from.sa, &conn->server->addr)) {
+ /* The address the response comes from does not match the address we
+ * sent the request to. Someone may be attempting to perform a cache
+ * poisoning attack. */
+ continue;
+#endif
+
+ } else {
+ process_answer(channel, buf, (int)read_len, conn, 0, now);
+ }
+ /* process_answer may invalidate "conn" and close the file descriptor, so
+ * check to see if file descriptor is still valid before looping! */
+ } while (read_len >= 0 &&
+ ares__htable_asvp_get_direct(channel->connnode_by_socket, fd) != NULL);
+
+}
+
+
+static void read_packets(ares_channel channel, fd_set *read_fds,
+ ares_socket_t read_fd, struct timeval *now)
+{
+ size_t i;
+ ares_socket_t *socketlist = NULL;
+ size_t num_sockets = 0;
+ struct server_connection *conn = NULL;
+ ares__llist_node_t *node = NULL;
+
+ if (!read_fds && (read_fd == ARES_SOCKET_BAD))
/* no possible action */
return;
- for (i = 0; i < channel->nservers; i++)
- {
- /* Make sure the server has a socket and is selected in read_fds. */
- server = &channel->servers[i];
+ /* Single socket specified */
+ if (!read_fds) {
+ node = ares__htable_asvp_get_direct(channel->connnode_by_socket, read_fd);
+ if (node == NULL)
+ return;
- if (server->udp_socket == ARES_SOCKET_BAD || server->is_broken)
- continue;
+ conn = ares__llist_node_val(node);
- if(read_fds) {
- if(!FD_ISSET(server->udp_socket, read_fds))
- continue;
- }
- else {
- if(server->udp_socket != read_fd)
- continue;
- }
+ if (conn->is_tcp) {
+ read_tcp_data(channel, conn, now);
+ } else {
+ read_udp_packets_fd(channel, conn, now);
+ }
- if(read_fds)
- /* If there's an error and we close this socket, then open
- * another with the same fd to talk to another server, then we
- * don't want to think that it was the new socket that was
- * ready. This is not disastrous, but is likely to result in
- * extra system calls and confusion. */
- FD_CLR(server->udp_socket, read_fds);
-
- /* To reduce event loop overhead, read and process as many
- * packets as we can. */
- do {
- if (server->udp_socket == ARES_SOCKET_BAD) {
- read_len = -1;
- } else {
- if (server->addr.family == AF_INET) {
- fromlen = sizeof(from.sa4);
- } else {
- fromlen = sizeof(from.sa6);
- }
- read_len = socket_recvfrom(channel, server->udp_socket, (void *)buf,
- sizeof(buf), 0, &from.sa, &fromlen);
- }
+ return;
+ }
- if (read_len == 0) {
- /* UDP is connectionless, so result code of 0 is a 0-length UDP
- * packet, and not an indication the connection is closed like on
- * tcp */
- continue;
- } else if (read_len < 0) {
- if (try_again(SOCKERRNO))
- continue;
+ /* There is no good way to iterate across an fd_set, instead we must pull a list
+ * of all known fds, and iterate across that checking against the fd_set. */
+ socketlist = channel_socket_list(channel, &num_sockets);
- handle_error(channel, i, now);
+ for (i=0; i<num_sockets; i++) {
+ if (!FD_ISSET(socketlist[i], read_fds))
+ continue;
-#ifdef HAVE_RECVFROM
- } else if (!same_address(&from.sa, &server->addr)) {
- /* The address the response comes from does not match the address we
- * sent the request to. Someone may be attempting to perform a cache
- * poisoning attack. */
- continue;
-#endif
+ /* If there's an error and we close this socket, then open
+ * another with the same fd to talk to another server, then we
+ * don't want to think that it was the new socket that was
+ * ready. This is not disastrous, but is likely to result in
+ * extra system calls and confusion. */
+ FD_CLR(socketlist[i], read_fds);
- } else {
- process_answer(channel, buf, (int)read_len, i, 0, now);
- }
- } while (read_len >= 0);
+ node = ares__htable_asvp_get_direct(channel->connnode_by_socket,
+ socketlist[i]);
+ if (node == NULL)
+ return;
+
+ conn = ares__llist_node_val(node);
+
+ if (conn->is_tcp) {
+ read_tcp_data(channel, conn, now);
+ } else {
+ read_udp_packets_fd(channel, conn, now);
}
+ }
+
+ ares_free(socketlist);
}
+
/* If any queries have timed out, note the timeout and move them on. */
static void process_timeouts(ares_channel channel, struct timeval *now)
{
- time_t t; /* the time of the timeouts we're processing */
- struct query *query;
- struct list_node* list_head;
- struct list_node* list_node;
+ ares__slist_node_t *node = ares__slist_node_first(channel->queries_by_timeout);
+ while (node != NULL) {
+ struct query *query = ares__slist_node_val(node);
+ /* Node might be removed, cache next */
+ ares__slist_node_t *next = ares__slist_node_next(node);
+ ares_socket_t fd;
+
+ /* Since this is sorted, as soon as we hit a query that isn't timed out, break */
+ if (!ares__timedout(now, &query->timeout)) {
+ break;
+ }
- /* Process all the timeouts that have fired since the last time we processed
- * timeouts. If things are going well, then we'll have hundreds/thousands of
- * queries that fall into future buckets, and only a handful of requests
- * that fall into the "now" bucket, so this should be quite quick.
- */
- for (t = channel->last_timeout_processed; t <= now->tv_sec; t++)
- {
- list_head = &(channel->queries_by_timeout[t % ARES_TIMEOUT_TABLE_SIZE]);
- for (list_node = list_head->next; list_node != list_head; )
- {
- query = list_node->data;
- list_node = list_node->next; /* in case the query gets deleted */
- if (query->timeout.tv_sec && ares__timedout(now, &query->timeout))
- {
- query->error_status = ARES_ETIMEOUT;
- ++query->timeouts;
- next_server(channel, query, now);
- }
- }
- }
- channel->last_timeout_processed = now->tv_sec;
+ query->error_status = ARES_ETIMEOUT;
+ query->timeouts++;
+
+
+ fd = query->conn->fd;
+ next_server(channel, query, now);
+ /* A timeout is a special case where we need to possibly cleanup a
+ * a connection */
+ ares__check_cleanup_conn(channel, fd);
+
+ node = next;
+ }
}
+
/* Handle an answer from a server. */
-static void process_answer(ares_channel channel, unsigned char *abuf,
- int alen, int whichserver, int tcp,
+static void process_answer(ares_channel channel, const unsigned char *abuf,
+ int alen, struct server_connection *conn, int tcp,
struct timeval *now)
{
int tc, rcode, packetsz;
unsigned short id;
struct query *query;
- struct list_node* list_head;
- struct list_node* list_node;
+ /* Cache these as once ares__send_query() gets called, it may end up
+ * invalidating the connection all-together */
+ struct server_state *server = conn->server;
+ ares_socket_t fd = conn->fd;
/* If there's no room in the answer for a header, we can't do much
* with it. */
- if (alen < HFIXEDSZ)
+ if (alen < HFIXEDSZ) {
return;
+ }
/* Grab the query ID, truncate bit, and response code from the packet. */
- id = DNS_HEADER_QID(abuf);
+ id = DNS_HEADER_QID(abuf); /* Converts to host byte order */
tc = DNS_HEADER_TC(abuf);
rcode = DNS_HEADER_RCODE(abuf);
/* Find the query corresponding to this packet. The queries are
- * hashed/bucketed by query id, so this lookup should be quick. Note that
- * both the query id and the questions must be the same; when the query id
- * wraps around we can have multiple outstanding queries with the same query
- * id, so we need to check both the id and question.
+ * hashed/bucketed by query id, so this lookup should be quick.
*/
- query = NULL;
- list_head = &(channel->queries_by_qid[id % ARES_QID_TABLE_SIZE]);
- for (list_node = list_head->next; list_node != list_head;
- list_node = list_node->next)
- {
- struct query *q = list_node->data;
- if ((q->qid == id) && same_questions(q->qbuf, q->qlen, abuf, alen))
- {
- query = q;
- break;
- }
- }
- if (!query)
+ query = ares__htable_stvp_get_direct(channel->queries_by_qid, id);
+ if (!query) {
+ return;
+ }
+
+ /* 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(query->qbuf, query->qlen, abuf, alen)) {
return;
+ }
+
+ /* At this point we know we've received an answer for this query, so we should
+ * remove it from the connection's queue so we can possibly invalidate the
+ * connection. Delay cleaning up the connection though as we may enqueue
+ * something new. */
+ ares__llist_node_destroy(query->node_queries_to_conn);
+ query->node_queries_to_conn = NULL;
packetsz = PACKETSZ;
/* If we use EDNS and server answers with FORMERR without an OPT RR, the protocol
@@ -643,6 +621,7 @@ static void process_answer(ares_channel channel, unsigned char *abuf,
query->tcpbuf = ares_realloc(query->tcpbuf, query->tcplen);
query->qbuf = query->tcpbuf + 2;
ares__send_query(channel, query, now);
+ ares__check_cleanup_conn(channel, fd);
return;
}
}
@@ -658,6 +637,7 @@ static void process_answer(ares_channel channel, unsigned char *abuf,
query->using_tcp = 1;
ares__send_query(channel, query, now);
}
+ ares__check_cleanup_conn(channel, fd);
return;
}
@@ -674,93 +654,62 @@ static void process_answer(ares_channel channel, unsigned char *abuf,
{
if (rcode == SERVFAIL || rcode == NOTIMP || rcode == REFUSED)
{
- skip_server(channel, query, whichserver);
- if (query->server == whichserver)
+ switch (rcode) {
+ case SERVFAIL:
+ query->error_status = ARES_ESERVFAIL;
+ break;
+ case NOTIMP:
+ query->error_status = ARES_ENOTIMP;
+ break;
+ case REFUSED:
+ query->error_status = ARES_EREFUSED;
+ break;
+ }
+ skip_server(channel, query, server);
+ if (query->server == (int)server->idx) /* Is this ever not true? */
next_server(channel, query, now);
+ ares__check_cleanup_conn(channel, fd);
return;
}
}
end_query(channel, query, ARES_SUCCESS, abuf, alen);
-}
-/* Close all the connections that are no longer usable. */
-static void process_broken_connections(ares_channel channel,
- struct timeval *now)
-{
- int i;
- for (i = 0; i < channel->nservers; i++)
- {
- struct server_state *server = &channel->servers[i];
- if (server->is_broken)
- {
- handle_error(channel, i, now);
- }
- }
+ ares__check_cleanup_conn(channel, fd);
}
-/* Swap the contents of two lists */
-static void swap_lists(struct list_node* head_a,
- struct list_node* head_b)
-{
- int is_a_empty = ares__is_list_empty(head_a);
- int is_b_empty = ares__is_list_empty(head_b);
- struct list_node old_a = *head_a;
- struct list_node old_b = *head_b;
-
- if (is_a_empty) {
- ares__init_list_head(head_b);
- } else {
- *head_b = old_a;
- old_a.next->prev = head_b;
- old_a.prev->next = head_b;
- }
- if (is_b_empty) {
- ares__init_list_head(head_a);
- } else {
- *head_a = old_b;
- old_b.next->prev = head_a;
- old_b.prev->next = head_a;
- }
-}
-static void handle_error(ares_channel channel, int whichserver,
+static void handle_error(struct server_connection *conn,
struct timeval *now)
{
- struct server_state *server;
- struct query *query;
- struct list_node list_head;
- struct list_node* list_node;
-
- server = &channel->servers[whichserver];
-
- /* Reset communications with this server. */
- ares__close_sockets(channel, server);
+ ares_channel channel = conn->server->channel;
+ struct server_state *server = conn->server;
+ ares__llist_t *list_copy;
+ ares__llist_node_t *node;
+
+ /* We steal the list from the connection then close the connection, then
+ * iterate across the list to requeue any inflight queries with the broken
+ * connection. Destroying the connection prior to requeuing ensures requests
+ * won't go back to the broken connection */
+ list_copy = conn->queries_to_conn;
+ conn->queries_to_conn = NULL;
+ ares__close_connection(conn);
+
+ while ((node = ares__llist_node_first(list_copy)) != NULL) {
+ struct query *query = ares__llist_node_val(node);
+
+ assert(query->server == (int)server->idx);
+ skip_server(channel, query, server);
+ /* next_server will remove the current node from the list */
+ next_server(channel, query, now);
+ }
- /* Tell all queries talking to this server to move on and not try this
- * server again. We steal the current list of queries that were in-flight to
- * this server, since when we call next_server this can cause the queries to
- * be re-sent to this server, which will re-insert these queries in that
- * same server->queries_to_server list.
- */
- ares__init_list_head(&list_head);
- swap_lists(&list_head, &(server->queries_to_server));
- for (list_node = list_head.next; list_node != &list_head; )
- {
- query = list_node->data;
- list_node = list_node->next; /* in case the query gets deleted */
- assert(query->server == whichserver);
- skip_server(channel, query, whichserver);
- next_server(channel, query, now);
- }
- /* Each query should have removed itself from our temporary list as
- * it re-sent itself or finished up...
- */
- assert(ares__is_list_empty(&list_head));
+ ares__llist_destroy(list_copy);
}
+
static void skip_server(ares_channel channel, struct query *query,
- int whichserver)
+ struct server_state *server)
{
/* The given server gave us problems with this query, so if we have the
* luxury of using other servers, then let's skip the potentially broken
@@ -772,186 +721,215 @@ static void skip_server(ares_channel channel, struct query *query,
*/
if (channel->nservers > 1)
{
- query->server_info[whichserver].skip_server = 1;
+ query->server_info[server->idx].skip_server = 1;
}
}
-static void next_server(ares_channel channel, struct query *query,
+static int next_server(ares_channel channel, struct query *query,
struct timeval *now)
{
+ int status;
/* We need to try each server channel->tries times. We have channel->nservers
* servers to try. In total, we need to do channel->nservers * channel->tries
* attempts. Use query->try to remember how many times we already attempted
- * this query. Use modular arithmetic to find the next server to try. */
- while (++(query->try_count) < (channel->nservers * channel->tries))
- {
- struct server_state *server;
-
- /* Move on to the next server. */
- query->server = (query->server + 1) % channel->nservers;
- server = &channel->servers[query->server];
-
- /* We don't want to use this server if (1) we decided this connection is
- * broken, and thus about to be closed, (2) we've decided to skip this
- * server because of earlier errors we encountered, or (3) we already
- * sent this query over this exact connection.
- */
- if (!server->is_broken &&
- !query->server_info[query->server].skip_server &&
- !(query->using_tcp &&
- (query->server_info[query->server].tcp_connection_generation ==
- server->tcp_connection_generation)))
- {
- ares__send_query(channel, query, now);
- return;
- }
-
- /* You might think that with TCP we only need one try. However, even
- * when using TCP, servers can time-out our connection just as we're
- * sending a request, or close our connection because they die, or never
- * send us a reply because they get wedged or tickle a bug that drops
- * our request.
- */
+ * this query. Use modular arithmetic to find the next server to try.
+ * A query can be requested be terminated at the next interval by setting
+ * query->no_retries */
+ while (++(query->try_count) < (channel->nservers * channel->tries) &&
+ !query->no_retries) {
+ struct server_state *server;
+
+ /* Move on to the next server. */
+ query->server = (query->server + 1) % channel->nservers;
+ server = &channel->servers[query->server];
+
+ /* We don't want to use this server if (1) we've decided to skip this
+ * server because of earlier errors we encountered, or (2) we already
+ * sent this query over this exact connection.
+ */
+ if (!query->server_info[query->server].skip_server &&
+ !(query->using_tcp &&
+ (query->server_info[query->server].tcp_connection_generation ==
+ server->tcp_connection_generation))) {
+ return ares__send_query(channel, query, now);
}
+ /* You might think that with TCP we only need one try. However, even
+ * when using TCP, servers can time-out our connection just as we're
+ * sending a request, or close our connection because they die, or never
+ * send us a reply because they get wedged or tickle a bug that drops
+ * our request.
+ */
+ }
+
/* If we are here, all attempts to perform query failed. */
+ status = query->error_status;
end_query(channel, query, query->error_status, NULL, 0);
+ return status;
}
-void ares__send_query(ares_channel channel, struct query *query,
+int ares__send_query(ares_channel channel, struct query *query,
struct timeval *now)
{
- struct send_request *sendreq;
struct server_state *server;
+ struct server_connection *conn;
int timeplus;
+ int status;
server = &channel->servers[query->server];
- if (query->using_tcp)
- {
- /* Make sure the TCP socket for this server is set up and queue
- * a send request.
- */
- if (server->tcp_socket == ARES_SOCKET_BAD)
- {
- if (open_tcp_socket(channel, server) == -1)
- {
- skip_server(channel, query, query->server);
- next_server(channel, query, now);
- return;
- }
- }
- sendreq = ares_malloc(sizeof(struct send_request));
- if (!sendreq)
- {
- end_query(channel, query, ARES_ENOMEM, NULL, 0);
- return;
- }
- memset(sendreq, 0, sizeof(struct send_request));
- /* To make the common case fast, we avoid copies by using the query's
- * tcpbuf for as long as the query is alive. In the rare case where the
- * query ends while it's queued for transmission, then we give the
- * sendreq its own copy of the request packet and put it in
- * sendreq->data_storage.
- */
- sendreq->data_storage = NULL;
- sendreq->data = query->tcpbuf;
- sendreq->len = query->tcplen;
- sendreq->owner_query = query;
- sendreq->next = NULL;
- if (server->qtail)
- server->qtail->next = sendreq;
- else
- {
- SOCK_STATE_CALLBACK(channel, server->tcp_socket, 1, 1);
- server->qhead = sendreq;
- }
- server->qtail = sendreq;
- query->server_info[query->server].tcp_connection_generation =
- server->tcp_connection_generation;
+ if (query->using_tcp) {
+ size_t prior_len = 0;
+ /* Make sure the TCP socket for this server is set up and queue
+ * a send request.
+ */
+ if (server->tcp_conn == NULL) {
+ int err = open_socket(channel, server, 1);
+ switch (err) {
+ /* Good result, continue on */
+ case ARES_SUCCESS:
+ break;
+
+ /* These conditions are retryable as they are server-specific
+ * error codes */
+ case ARES_ECONNREFUSED:
+ case ARES_EBADFAMILY:
+ skip_server(channel, query, server);
+ return next_server(channel, query, now);
+
+ /* Anything else is not retryable, likely ENOMEM */
+ default:
+ end_query(channel, query, err, NULL, 0);
+ return err;
+ }
}
- else
- {
- if (server->udp_socket == ARES_SOCKET_BAD)
- {
- if (open_udp_socket(channel, server) == -1)
- {
- skip_server(channel, query, query->server);
- next_server(channel, query, now);
- return;
- }
- }
- if (socket_write(channel, server->udp_socket, query->qbuf, query->qlen) == -1)
- {
- /* FIXME: Handle EAGAIN here since it likely can happen. */
- skip_server(channel, query, query->server);
- next_server(channel, query, now);
- return;
- }
+
+ conn = server->tcp_conn;
+
+ prior_len = ares__buf_len(server->tcp_send);
+
+ status = ares__buf_append(server->tcp_send, query->tcpbuf, query->tcplen);
+ if (status != ARES_SUCCESS) {
+ end_query(channel, query, status, NULL, 0);
+ return ARES_ENOMEM;
}
- /* For each trip through the entire server list, double the channel's
- * assigned timeout, avoiding overflow. If channel->timeout is negative,
- * leave it as-is, even though that should be impossible here.
- */
- timeplus = channel->timeout;
- {
- /* How many times do we want to double it? Presume sane values here. */
- const int shift = query->try_count / channel->nservers;
-
- /* Is there enough room to shift timeplus left that many times?
- *
- * To find out, confirm that all of the bits we'll shift away are zero.
- * Stop considering a shift if we get to the point where we could shift
- * a 1 into the sign bit (i.e. when shift is within two of the bit
- * count).
- *
- * This has the side benefit of leaving negative numbers unchanged.
- */
- if(shift <= (int)(sizeof(int) * CHAR_BIT - 1)
- && (timeplus >> (sizeof(int) * CHAR_BIT - 1 - shift)) == 0)
- {
- timeplus <<= shift;
+ if (prior_len == 0) {
+ SOCK_STATE_CALLBACK(channel, conn->fd, 1, 1);
+ }
+
+ query->server_info[query->server].tcp_connection_generation =
+ server->tcp_connection_generation;
+ } else {
+ ares__llist_node_t *node = ares__llist_node_first(server->connections);
+
+ /* Don't use the found connection if we've gone over the maximum number
+ * of queries. Also, skip over the TCP connection if it is the first in
+ * the list */
+ if (node != NULL) {
+ conn = ares__llist_node_val(node);
+ if (conn->is_tcp) {
+ node = NULL;
+ } else if (channel->udp_max_queries > 0 &&
+ conn->total_queries >= (size_t)channel->udp_max_queries) {
+ node = NULL;
}
}
- if (channel->maxtimeout != -1 && timeplus > channel->maxtimeout)
- timeplus = channel->maxtimeout;
+ if (node == NULL) {
+ int err = open_socket(channel, server, 0);
+ switch (err) {
+ /* Good result, continue on */
+ case ARES_SUCCESS:
+ break;
- if (channel->jitter != -1)
- {
- int r;
- #ifdef WIN32
- /* Windows does not have rand_r function, so we use regular rand().
- * It is thread-unsafe, but it is better than nothing.
- */
- r = rand();
- #else
- r = rand_r(&channel->jitter_rand_state);
- #endif
- long long delta = (long long)(r - (RAND_MAX >> 1)) * timeplus * channel->jitter;
- delta /= RAND_MAX;
- /* Recall that jitter is expressed in .001 */
- delta /= 1000;
- timeplus += delta;
+ /* These conditions are retryable as they are server-specific
+ * error codes */
+ case ARES_ECONNREFUSED:
+ case ARES_EBADFAMILY:
+ skip_server(channel, query, server);
+ return next_server(channel, query, now);
+
+ /* Anything else is not retryable, likely ENOMEM */
+ default:
+ end_query(channel, query, err, NULL, 0);
+ return err;
}
+ node = ares__llist_node_first(server->connections);
+ }
- query->timeout = *now;
- timeadd(&query->timeout, timeplus);
- /* Keep track of queries bucketed by timeout, so we can process
- * timeout events quickly.
- */
- ares__remove_from_list(&(query->queries_by_timeout));
- ares__insert_in_list(
- &(query->queries_by_timeout),
- &(channel->queries_by_timeout[query->timeout.tv_sec %
- ARES_TIMEOUT_TABLE_SIZE]));
-
- /* Keep track of queries bucketed by server, so we can process server
- * errors quickly.
+ conn = ares__llist_node_val(node);
+ if (ares__socket_write(channel, conn->fd, query->qbuf, query->qlen) == -1) {
+ /* FIXME: Handle EAGAIN here since it likely can happen. */
+ skip_server(channel, query, server);
+ return next_server(channel, query, now);
+ }
+ }
+
+ /* For each trip through the entire server list, double the channel's
+ * assigned timeout, avoiding overflow. If channel->timeout is negative,
+ * leave it as-is, even though that should be impossible here.
+ */
+ timeplus = channel->timeout;
+ {
+ /* How many times do we want to double it? Presume sane values here. */
+ const int shift = query->try_count / channel->nservers;
+
+ /* Is there enough room to shift timeplus left that many times?
+ *
+ * To find out, confirm that all of the bits we'll shift away are zero.
+ * Stop considering a shift if we get to the point where we could shift
+ * a 1 into the sign bit (i.e. when shift is within two of the bit
+ * count).
+ *
+ * This has the side benefit of leaving negative numbers unchanged.
*/
- ares__remove_from_list(&(query->queries_to_server));
- ares__insert_in_list(&(query->queries_to_server),
- &(server->queries_to_server));
+ if(shift <= (int)(sizeof(int) * CHAR_BIT - 1)
+ && (timeplus >> (sizeof(int) * CHAR_BIT - 1 - shift)) == 0)
+ {
+ timeplus <<= shift;
+ }
+ }
+
+ if (channel->maxtimeout != -1 && timeplus > channel->maxtimeout)
+ timeplus = channel->maxtimeout;
+
+ if (channel->jitter != -1) {
+ int r;
+ #ifdef WIN32
+ /* Windows does not have rand_r function, so we use regular rand().
+ * It is thread-unsafe, but it is better than nothing.
+ */
+ r = rand();
+ #else
+ r = rand_r(&channel->jitter_rand_state);
+ #endif
+ long long delta = (long long)(r - (RAND_MAX >> 1)) * timeplus * channel->jitter;
+ delta /= RAND_MAX;
+ /* Recall that jitter is expressed in .001 */
+ delta /= 1000;
+ timeplus += delta;
+ }
+
+ /* Keep track of queries bucketed by timeout, so we can process
+ * timeout events quickly.
+ */
+ ares__slist_node_destroy(query->node_queries_by_timeout);
+ 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) {
+ end_query(channel, query, ARES_ENOMEM, NULL, 0);
+ return ARES_ENOMEM;
+ }
+
+ /* Keep track of queries bucketed by connection, so we can process errors
+ * quickly. */
+ ares__llist_node_destroy(query->node_queries_to_conn);
+ query->node_queries_to_conn =
+ ares__llist_insert_last(conn->queries_to_conn, query);
+ query->conn = conn;
+ conn->total_queries++;
+ return ARES_SUCCESS;
}
/*
@@ -1034,7 +1012,7 @@ static int configure_socket(ares_socket_t s, int family, ares_channel channel)
} local;
/* do not set options for user-managed sockets */
- if (channel->sock_funcs)
+ if (channel->sock_funcs && channel->sock_funcs->asocket)
return 0;
(void)setsocknonblock(s, TRUE);
@@ -1093,7 +1071,8 @@ static int configure_socket(ares_socket_t s, int family, ares_channel channel)
return 0;
}
-static int open_tcp_socket(ares_channel channel, struct server_state *server)
+static int open_socket(ares_channel channel, struct server_state *server,
+ int is_tcp)
{
ares_socket_t s;
int opt;
@@ -1103,204 +1082,152 @@ static int open_tcp_socket(ares_channel channel, struct server_state *server)
struct sockaddr_in6 sa6;
} saddr;
struct sockaddr *sa;
+ unsigned short port;
+ struct server_connection *conn;
+ ares__llist_node_t *node;
- switch (server->addr.family)
- {
- case AF_INET:
- sa = (void *)&saddr.sa4;
- salen = sizeof(saddr.sa4);
- memset(sa, 0, salen);
- saddr.sa4.sin_family = AF_INET;
- if (server->addr.tcp_port) {
- saddr.sa4.sin_port = aresx_sitous(server->addr.tcp_port);
- } else {
- saddr.sa4.sin_port = aresx_sitous(channel->tcp_port);
- }
- memcpy(&saddr.sa4.sin_addr, &server->addr.addrV4,
- sizeof(server->addr.addrV4));
- break;
- case AF_INET6:
- sa = (void *)&saddr.sa6;
- salen = sizeof(saddr.sa6);
- memset(sa, 0, salen);
- saddr.sa6.sin6_family = AF_INET6;
- if (server->addr.tcp_port) {
- saddr.sa6.sin6_port = aresx_sitous(server->addr.tcp_port);
- } else {
- saddr.sa6.sin6_port = aresx_sitous(channel->tcp_port);
- }
- memcpy(&saddr.sa6.sin6_addr, &server->addr.addrV6,
- sizeof(server->addr.addrV6));
- break;
- default:
- return -1; /* LCOV_EXCL_LINE */
- }
+ if (is_tcp) {
+ port = aresx_sitous(server->addr.tcp_port?
+ server->addr.tcp_port:channel->tcp_port);
+ } else {
+ port = aresx_sitous(server->addr.udp_port?
+ server->addr.udp_port:channel->udp_port);
+ }
+
+ switch (server->addr.family) {
+ case AF_INET:
+ sa = (void *)&saddr.sa4;
+ salen = sizeof(saddr.sa4);
+ memset(sa, 0, salen);
+ saddr.sa4.sin_family = AF_INET;
+ saddr.sa4.sin_port = port;
+ memcpy(&saddr.sa4.sin_addr, &server->addr.addrV4,
+ sizeof(server->addr.addrV4));
+ break;
+ case AF_INET6:
+ sa = (void *)&saddr.sa6;
+ salen = sizeof(saddr.sa6);
+ memset(sa, 0, salen);
+ saddr.sa6.sin6_family = AF_INET6;
+ saddr.sa6.sin6_port = port;
+ memcpy(&saddr.sa6.sin6_addr, &server->addr.addrV6,
+ sizeof(server->addr.addrV6));
+ break;
+ default:
+ return ARES_EBADFAMILY; /* LCOV_EXCL_LINE */
+ }
/* Acquire a socket. */
- s = ares__open_socket(channel, server->addr.family, SOCK_STREAM, 0);
+ s = ares__open_socket(channel, server->addr.family,
+ is_tcp?SOCK_STREAM:SOCK_DGRAM, 0);
if (s == ARES_SOCKET_BAD)
- return -1;
+ return ARES_ECONNREFUSED;
/* Configure it. */
- if (configure_socket(s, server->addr.family, channel) < 0)
- {
- ares__close_socket(channel, s);
- return -1;
- }
+ if (configure_socket(s, server->addr.family, channel) < 0) {
+ ares__close_socket(channel, s);
+ return ARES_ECONNREFUSED;
+ }
#ifdef TCP_NODELAY
- /*
- * Disable the Nagle algorithm (only relevant for TCP sockets, and thus not
- * in configure_socket). In general, in DNS lookups we're pretty much
- * interested in firing off a single request and then waiting for a reply,
- * so batching isn't very interesting.
- */
- opt = 1;
- if (channel->sock_funcs == 0
- &&
- setsockopt(s, IPPROTO_TCP, TCP_NODELAY,
- (void *)&opt, sizeof(opt)) == -1)
- {
- ares__close_socket(channel, s);
- return -1;
+ if (is_tcp) {
+ /*
+ * Disable the Nagle algorithm (only relevant for TCP sockets, and thus not
+ * in configure_socket). In general, in DNS lookups we're pretty much
+ * interested in firing off a single request and then waiting for a reply,
+ * so batching isn't very interesting.
+ */
+ opt = 1;
+ if (!channel->sock_funcs || !channel->sock_funcs->asocket) {
+ if (setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (void *)&opt, sizeof(opt))
+ == -1) {
+ ares__close_socket(channel, s);
+ return ARES_ECONNREFUSED;
+ }
}
+ }
#endif
- if (channel->sock_config_cb)
- {
- int err = channel->sock_config_cb(s, SOCK_STREAM,
- channel->sock_config_cb_data);
- if (err < 0)
- {
- ares__close_socket(channel, s);
- return err;
- }
+ if (channel->sock_config_cb) {
+ int err = channel->sock_config_cb(s, SOCK_STREAM,
+ channel->sock_config_cb_data);
+ if (err < 0) {
+ ares__close_socket(channel, s);
+ return ARES_ECONNREFUSED;
}
+ }
/* Connect to the server. */
- if (ares__connect_socket(channel, s, sa, salen) == -1)
- {
- int err = SOCKERRNO;
-
- if (err != EINPROGRESS && err != EWOULDBLOCK)
- {
- ares__close_socket(channel, s);
- return -1;
- }
- }
+ if (ares__connect_socket(channel, s, sa, salen) == -1) {
+ int err = SOCKERRNO;
- if (channel->sock_create_cb)
- {
- int err = channel->sock_create_cb(s, SOCK_STREAM,
- channel->sock_create_cb_data);
- if (err < 0)
- {
- ares__close_socket(channel, s);
- return err;
- }
- }
-
- SOCK_STATE_CALLBACK(channel, s, 1, 0);
- server->tcp_buffer_pos = 0;
- server->tcp_socket = s;
- server->tcp_connection_generation = ++channel->tcp_connection_generation;
- return 0;
-}
-
-static int open_udp_socket(ares_channel channel, struct server_state *server)
-{
- ares_socket_t s;
- ares_socklen_t salen;
- union {
- struct sockaddr_in sa4;
- struct sockaddr_in6 sa6;
- } saddr;
- struct sockaddr *sa;
-
- switch (server->addr.family)
- {
- case AF_INET:
- sa = (void *)&saddr.sa4;
- salen = sizeof(saddr.sa4);
- memset(sa, 0, salen);
- saddr.sa4.sin_family = AF_INET;
- if (server->addr.udp_port) {
- saddr.sa4.sin_port = aresx_sitous(server->addr.udp_port);
- } else {
- saddr.sa4.sin_port = aresx_sitous(channel->udp_port);
- }
- memcpy(&saddr.sa4.sin_addr, &server->addr.addrV4,
- sizeof(server->addr.addrV4));
- break;
- case AF_INET6:
- sa = (void *)&saddr.sa6;
- salen = sizeof(saddr.sa6);
- memset(sa, 0, salen);
- saddr.sa6.sin6_family = AF_INET6;
- if (server->addr.udp_port) {
- saddr.sa6.sin6_port = aresx_sitous(server->addr.udp_port);
- } else {
- saddr.sa6.sin6_port = aresx_sitous(channel->udp_port);
- }
- memcpy(&saddr.sa6.sin6_addr, &server->addr.addrV6,
- sizeof(server->addr.addrV6));
- break;
- default:
- return -1; /* LCOV_EXCL_LINE */
- }
-
- /* Acquire a socket. */
- s = ares__open_socket(channel, server->addr.family, SOCK_DGRAM, 0);
- if (s == ARES_SOCKET_BAD)
- return -1;
-
- /* Set the socket non-blocking. */
- if (configure_socket(s, server->addr.family, channel) < 0)
- {
- ares__close_socket(channel, s);
- return -1;
+ if (err != EINPROGRESS && err != EWOULDBLOCK) {
+ ares__close_socket(channel, s);
+ return ARES_ECONNREFUSED;
}
+ }
- if (channel->sock_config_cb)
- {
- int err = channel->sock_config_cb(s, SOCK_DGRAM,
- channel->sock_config_cb_data);
- if (err < 0)
- {
- ares__close_socket(channel, s);
- return err;
- }
+ if (channel->sock_create_cb) {
+ int err = channel->sock_create_cb(s, SOCK_STREAM,
+ channel->sock_create_cb_data);
+ if (err < 0) {
+ ares__close_socket(channel, s);
+ return ARES_ECONNREFUSED;
}
+ }
- /* Connect to the server. */
- if (ares__connect_socket(channel, s, sa, salen) == -1)
- {
- int err = SOCKERRNO;
+ conn = ares_malloc(sizeof(*conn));
+ if (conn == NULL) {
+ ares__close_socket(channel, s);
+ return ARES_ENOMEM;
+ }
+ memset(conn, 0, sizeof(*conn));
+ conn->fd = s;
+ conn->server = server;
+ conn->queries_to_conn = ares__llist_create(NULL);
+ conn->is_tcp = is_tcp;
+ if (conn->queries_to_conn == NULL) {
+ ares__close_socket(channel, s);
+ ares_free(conn);
+ return ARES_ENOMEM;
+ }
- if (err != EINPROGRESS && err != EWOULDBLOCK)
- {
- ares__close_socket(channel, s);
- return -1;
- }
- }
+ /* TCP connections are thrown to the end as we don't spawn multiple TCP
+ * connections. UDP connections are put on front where the newest connection
+ * can be quickly pulled */
+ if (is_tcp) {
+ node = ares__llist_insert_last(server->connections, conn);
+ } else {
+ node = ares__llist_insert_first(server->connections, conn);
+ }
+ if (node == NULL) {
+ ares__close_socket(channel, s);
+ ares__llist_destroy(conn->queries_to_conn);
+ ares_free(conn);
+ return ARES_ENOMEM;
+ }
- if (channel->sock_create_cb)
- {
- int err = channel->sock_create_cb(s, SOCK_DGRAM,
- channel->sock_create_cb_data);
- if (err < 0)
- {
- ares__close_socket(channel, s);
- return err;
- }
- }
+ /* Register globally to quickly map event on file descriptor to connection
+ * node object */
+ if (!ares__htable_asvp_insert(channel->connnode_by_socket, s, node)) {
+ ares__close_socket(channel, s);
+ ares__llist_destroy(conn->queries_to_conn);
+ ares__llist_node_claim(node);
+ ares_free(conn);
+ return ARES_ENOMEM;
+ }
SOCK_STATE_CALLBACK(channel, s, 1, 0);
- server->udp_socket = s;
- return 0;
+ if (is_tcp) {
+ server->tcp_connection_generation = ++channel->tcp_connection_generation;
+ server->tcp_conn = conn;
+ }
+
+ return ARES_SUCCESS;
}
+
static int same_questions(const unsigned char *qbuf, int qlen,
const unsigned char *abuf, int alen)
{
@@ -1487,83 +1414,37 @@ static int has_opt_rr(const unsigned char *abuf, int alen)
return 0;
}
-static void end_query (ares_channel channel, struct query *query, int status,
- unsigned char *abuf, int alen)
+static void ares_detach_query(struct query *query)
{
- int i;
+ /* Remove the query from all the lists in which it is linked */
+ ares__htable_stvp_remove(query->channel->queries_by_qid, query->qid);
+ ares__slist_node_destroy(query->node_queries_by_timeout);
+ ares__llist_node_destroy(query->node_queries_to_conn);
+ ares__llist_node_destroy(query->node_all_queries);
+ query->node_queries_by_timeout = NULL;
+ query->node_queries_to_conn = NULL;
+ query->node_all_queries = NULL;
+}
- /* First we check to see if this query ended while one of our send
- * queues still has pointers to it.
- */
- for (i = 0; i < channel->nservers; i++)
- {
- struct server_state *server = &channel->servers[i];
- struct send_request *sendreq;
- for (sendreq = server->qhead; sendreq; sendreq = sendreq->next)
- if (sendreq->owner_query == query)
- {
- sendreq->owner_query = NULL;
- assert(sendreq->data_storage == NULL);
- if (status == ARES_SUCCESS)
- {
- /* We got a reply for this query, but this queued sendreq
- * points into this soon-to-be-gone query's tcpbuf. Probably
- * this means we timed out and queued the query for
- * retransmission, then received a response before actually
- * retransmitting. This is perfectly fine, so we want to keep
- * the connection running smoothly if we can. But in the worst
- * case we may have sent only some prefix of the query, with
- * some suffix of the query left to send. Also, the buffer may
- * be queued on multiple queues. To prevent dangling pointers
- * to the query's tcpbuf and handle these cases, we just give
- * such sendreqs their own copy of the query packet.
- */
- sendreq->data_storage = ares_malloc(sendreq->len);
- if (sendreq->data_storage != NULL)
- {
- memcpy(sendreq->data_storage, sendreq->data, sendreq->len);
- sendreq->data = sendreq->data_storage;
- }
- }
- if ((status != ARES_SUCCESS) || (sendreq->data_storage == NULL))
- {
- /* We encountered an error (probably a timeout, suggesting the
- * DNS server we're talking to is probably unreachable,
- * wedged, or severely overloaded) or we couldn't copy the
- * request, so mark the connection as broken. When we get to
- * process_broken_connections() we'll close the connection and
- * try to re-send requests to another server.
- */
- server->is_broken = 1;
- /* Just to be paranoid, zero out this sendreq... */
- sendreq->data = NULL;
- sendreq->len = 0;
- }
- }
- }
+static void end_query(ares_channel channel, struct query *query, int status,
+ const unsigned char *abuf, int alen)
+{
+ (void)channel;
- /* Invoke the callback */
- query->callback(query->arg, status, query->timeouts, abuf, alen);
- ares__free_query(query);
+ ares_detach_query(query);
- /* Simple cleanup policy: if no queries are remaining, close all network
- * sockets unless STAYOPEN is set.
- */
- if (!(channel->flags & ARES_FLAG_STAYOPEN) &&
- ares__is_list_empty(&(channel->all_queries)))
- {
- for (i = 0; i < channel->nservers; i++)
- ares__close_sockets(channel, &channel->servers[i]);
- }
+ /* Invoke the callback. */
+ query->callback(query->arg, status, query->timeouts,
+ /* due to prior design flaws, abuf isn't meant to be modified,
+ * but bad prototypes, ugh. Lets cast off constfor compat. */
+ (unsigned char *)((void *)((size_t)abuf)),
+ alen);
+ ares__free_query(query);
}
void ares__free_query(struct query *query)
{
- /* Remove the query from all the lists in which it is linked */
- ares__remove_from_list(&(query->queries_by_qid));
- ares__remove_from_list(&(query->queries_by_timeout));
- ares__remove_from_list(&(query->queries_to_server));
- ares__remove_from_list(&(query->all_queries));
+ ares_detach_query(query);
/* Zero out some important stuff, to help catch bugs */
query->callback = NULL;
query->arg = NULL;
@@ -1576,13 +1457,14 @@ void ares__free_query(struct query *query)
ares_socket_t ares__open_socket(ares_channel channel,
int af, int type, int protocol)
{
- if (channel->sock_funcs)
+ if (channel->sock_funcs && channel->sock_funcs->asocket) {
return channel->sock_funcs->asocket(af,
type,
protocol,
channel->sock_func_cb_data);
- else
- return socket(af, type, protocol);
+ }
+
+ return socket(af, type, protocol);
}
int ares__connect_socket(ares_channel channel,
@@ -1590,19 +1472,41 @@ int ares__connect_socket(ares_channel channel,
const struct sockaddr *addr,
ares_socklen_t addrlen)
{
- if (channel->sock_funcs)
+ if (channel->sock_funcs && channel->sock_funcs->aconnect) {
return channel->sock_funcs->aconnect(sockfd,
addr,
addrlen,
channel->sock_func_cb_data);
- else
- return connect(sockfd, addr, addrlen);
+ }
+
+ return connect(sockfd, addr, addrlen);
}
void ares__close_socket(ares_channel channel, ares_socket_t s)
{
- if (channel->sock_funcs)
+ if (channel->sock_funcs && channel->sock_funcs->aclose) {
channel->sock_funcs->aclose(s, channel->sock_func_cb_data);
- else
+ } else {
sclose(s);
+ }
+}
+
+#ifndef HAVE_WRITEV
+/* Structure for scatter/gather I/O. */
+struct iovec
+{
+ void *iov_base; /* Pointer to data. */
+ size_t iov_len; /* Length of data. */
+};
+#endif
+
+static ares_ssize_t ares__socket_write(ares_channel channel, ares_socket_t s, const void * data, size_t len)
+{
+ if (channel->sock_funcs && channel->sock_funcs->asendv) {
+ struct iovec vec;
+ vec.iov_base = (void*)data;
+ vec.iov_len = len;
+ return channel->sock_funcs->asendv(s, &vec, 1, channel->sock_func_cb_data);
+ }
+ return swrite(s, data, len);
}
diff --git a/contrib/libs/c-ares/src/lib/ares_query.c b/contrib/libs/c-ares/src/lib/ares_query.c
index 42323bec55..04521d1c85 100644
--- a/contrib/libs/c-ares/src/lib/ares_query.c
+++ b/contrib/libs/c-ares/src/lib/ares_query.c
@@ -1,17 +1,28 @@
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
+/* MIT License
+ *
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * Copyright (c) The c-ares project and its contributors
+ *
+ * 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.
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * SPDX-License-Identifier: MIT
*/
#include "ares_setup.h"
@@ -33,24 +44,6 @@ struct qquery {
static void qcallback(void *arg, int status, int timeouts, unsigned char *abuf, int alen);
-static struct query* find_query_by_id(ares_channel channel, unsigned short id)
-{
- unsigned short qid;
- struct list_node* list_head;
- struct list_node* list_node;
- DNS_HEADER_SET_QID(((unsigned char*)&qid), id);
-
- /* Find the query corresponding to this packet. */
- list_head = &(channel->queries_by_qid[qid % ARES_QID_TABLE_SIZE]);
- for (list_node = list_head->next; list_node != list_head;
- list_node = list_node->next)
- {
- struct query *q = list_node->data;
- if (q->qid == qid)
- return q;
- }
- return NULL;
-}
/* a unique query id is generated using an rc4 key. Since the id may already
be used by a running query (as infrequent as it may be), a lookup is
@@ -63,47 +56,59 @@ static unsigned short generate_unique_id(ares_channel channel)
do {
id = ares__generate_new_id(channel->rand_state);
- } while (find_query_by_id(channel, id));
+ } while (ares__htable_stvp_get(channel->queries_by_qid, id, NULL));
return (unsigned short)id;
}
-void ares_query(ares_channel channel, const char *name, int dnsclass,
- int type, ares_callback callback, void *arg)
+int ares_query_qid(ares_channel channel, const char *name,
+ int dnsclass, int type, ares_callback callback,
+ void *arg, unsigned short *qid)
{
struct qquery *qquery;
unsigned char *qbuf;
int qlen, rd, status;
+ unsigned short id = generate_unique_id(channel);
/* Compose the query. */
rd = !(channel->flags & ARES_FLAG_NORECURSE);
- status = ares_create_query(name, dnsclass, type, channel->next_id, rd, &qbuf,
+ status = ares_create_query(name, dnsclass, type, id, rd, &qbuf,
&qlen, (channel->flags & ARES_FLAG_EDNS) ? channel->ednspsz : 0);
if (status != ARES_SUCCESS)
{
if (qbuf != NULL) ares_free(qbuf);
callback(arg, status, 0, NULL, 0);
- return;
+ return status;
}
- channel->next_id = generate_unique_id(channel);
-
/* Allocate and fill in the query structure. */
qquery = ares_malloc(sizeof(struct qquery));
if (!qquery)
{
ares_free_string(qbuf);
callback(arg, ARES_ENOMEM, 0, NULL, 0);
- return;
+ return ARES_ENOMEM;
}
qquery->callback = callback;
qquery->arg = arg;
/* Send it off. qcallback will be called when we get an answer. */
- ares_send(channel, qbuf, qlen, qcallback, qquery);
+ status = ares_send_ex(channel, qbuf, qlen, qcallback, qquery);
ares_free_string(qbuf);
+
+ if (status == ARES_SUCCESS && qid)
+ *qid = id;
+
+ return status;
+}
+
+void ares_query(ares_channel channel, const char *name, int dnsclass,
+ int type, ares_callback callback, void *arg)
+{
+ ares_query_qid(channel, name, dnsclass, type, callback, arg, NULL);
}
+
static void qcallback(void *arg, int status, int timeouts, unsigned char *abuf, int alen)
{
struct qquery *qquery = (struct qquery *) arg;
diff --git a/contrib/libs/c-ares/src/lib/ares_rand.c b/contrib/libs/c-ares/src/lib/ares_rand.c
index 766c1e6ea9..99a5a04cff 100644
--- a/contrib/libs/c-ares/src/lib/ares_rand.c
+++ b/contrib/libs/c-ares/src/lib/ares_rand.c
@@ -1,17 +1,27 @@
-/* Copyright 1998 by the Massachusetts Institute of Technology.
- * Copyright (C) 2007-2013 by Daniel Stenberg
+/* MIT License
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * Copyright (c) 2023 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_setup.h"
@@ -20,12 +30,24 @@
#include "ares_nowarn.h"
#include <stdlib.h>
+#if !defined(HAVE_ARC4RANDOM_BUF) && !defined(HAVE_GETRANDOM) && !defined(_WIN32)
+# define ARES_NEEDS_RC4 1
+#endif
+
typedef enum {
ARES_RAND_OS = 1, /* OS-provided such as RtlGenRandom or arc4random */
ARES_RAND_FILE = 2, /* OS file-backed random number generator */
+#ifdef ARES_NEEDS_RC4
ARES_RAND_RC4 = 3 /* Internal RC4 based PRNG */
+#endif
} ares_rand_backend;
+
+/* Don't build RC4 code if it goes unused as it will generate dead code
+ * warnings */
+#ifdef ARES_NEEDS_RC4
+# define ARES_RC4_KEY_LEN 32 /* 256 bits */
+
typedef struct ares_rand_rc4
{
unsigned char S[256];
@@ -33,30 +55,6 @@ typedef struct ares_rand_rc4
size_t j;
} ares_rand_rc4;
-struct ares_rand_state
-{
- ares_rand_backend type;
- union {
- FILE *rand_file;
- ares_rand_rc4 rc4;
- } state;
-};
-
-
-/* Define RtlGenRandom = SystemFunction036. This is in advapi32.dll. There is
- * no need to dynamically load this, other software used widely does not.
- * http://blogs.msdn.com/michael_howard/archive/2005/01/14/353379.aspx
- * https://docs.microsoft.com/en-us/windows/win32/api/ntsecapi/nf-ntsecapi-rtlgenrandom
- */
-#ifdef _WIN32
-BOOLEAN WINAPI SystemFunction036(PVOID RandomBuffer, ULONG RandomBufferLength);
-# ifndef RtlGenRandom
-# define RtlGenRandom(a,b) SystemFunction036(a,b)
-# endif
-#endif
-
-
-#define ARES_RC4_KEY_LEN 32 /* 256 bits */
#ifdef _MSC_VER
typedef unsigned __int64 cares_u64;
@@ -64,6 +62,7 @@ typedef unsigned __int64 cares_u64;
typedef unsigned long long cares_u64;
#endif
+
static unsigned int ares_u32_from_ptr(void *addr)
{
if (sizeof(void *) == 8) {
@@ -130,6 +129,7 @@ static void ares_rc4_init(ares_rand_rc4 *rc4_state)
rc4_state->j = 0;
}
+
/* Just outputs the key schedule, no need to XOR with any data since we have none */
static void ares_rc4_prng(ares_rand_rc4 *rc4_state, unsigned char *buf, size_t len)
{
@@ -150,12 +150,47 @@ static void ares_rc4_prng(ares_rand_rc4 *rc4_state, unsigned char *buf, size_t l
rc4_state->j = j;
}
+#endif /* ARES_NEEDS_RC4 */
+
+
+struct ares_rand_state
+{
+ ares_rand_backend type;
+ union {
+ FILE *rand_file;
+#ifdef ARES_NEEDS_RC4
+ ares_rand_rc4 rc4;
+#endif
+ } state;
+
+ /* Since except for RC4, random data will likely result in a syscall, lets
+ * pre-pull 256 bytes at a time. Every query will pull 2 bytes off this so
+ * that means we should only need a syscall every 128 queries. 256bytes
+ * appears to be a sweet spot that may be able to be served without
+ * interruption */
+ unsigned char cache[256];
+ size_t cache_remaining;
+};
+
+
+/* Define RtlGenRandom = SystemFunction036. This is in advapi32.dll. There is
+ * no need to dynamically load this, other software used widely does not.
+ * http://blogs.msdn.com/michael_howard/archive/2005/01/14/353379.aspx
+ * https://docs.microsoft.com/en-us/windows/win32/api/ntsecapi/nf-ntsecapi-rtlgenrandom
+ */
+#ifdef _WIN32
+BOOLEAN WINAPI SystemFunction036(PVOID RandomBuffer, ULONG RandomBufferLength);
+# ifndef RtlGenRandom
+# define RtlGenRandom(a,b) SystemFunction036(a,b)
+# endif
+#endif
+
static int ares__init_rand_engine(ares_rand_state *state)
{
memset(state, 0, sizeof(*state));
-#if defined(HAVE_ARC4RANDOM_BUF) || defined(_WIN32)
+#if defined(HAVE_ARC4RANDOM_BUF) || defined(HAVE_GETRANDOM) || defined(_WIN32)
state->type = ARES_RAND_OS;
return 1;
#elif defined(CARES_RANDOM_FILE)
@@ -168,15 +203,17 @@ static int ares__init_rand_engine(ares_rand_state *state)
/* Fall-Thru on failure to RC4 */
#endif
+#ifdef ARES_NEEDS_RC4
state->type = ARES_RAND_RC4;
ares_rc4_init(&state->state.rc4);
/* Currently cannot fail */
return 1;
+#endif
}
-ares_rand_state *ares__init_rand_state()
+ares_rand_state *ares__init_rand_state(void)
{
ares_rand_state *state = NULL;
@@ -204,8 +241,10 @@ static void ares__clear_rand_state(ares_rand_state *state)
case ARES_RAND_FILE:
fclose(state->state.rand_file);
break;
+#ifdef ARES_NEEDS_RC4
case ARES_RAND_RC4:
break;
+#endif
}
}
@@ -227,7 +266,8 @@ void ares__destroy_rand_state(ares_rand_state *state)
}
-static void ares__rand_bytes(ares_rand_state *state, unsigned char *buf, size_t len)
+static void ares__rand_bytes_fetch(ares_rand_state *state, unsigned char *buf,
+ size_t len)
{
while (1) {
@@ -241,6 +281,21 @@ static void ares__rand_bytes(ares_rand_state *state, unsigned char *buf, size_t
#elif defined(HAVE_ARC4RANDOM_BUF)
arc4random_buf(buf, len);
return;
+#elif defined(HAVE_GETRANDOM)
+ while (1) {
+ size_t n = len - bytes_read;
+ /* getrandom() on Linux always succeeds and is never
+ * interrupted by a signal when requesting <= 256 bytes.
+ */
+ ssize_t rv = getrandom(buf + bytes_read, n > 256 ? 256 : n, 0);
+ if (rv <= 0)
+ continue; /* Just retry. */
+
+ bytes_read += rv;
+ if (bytes_read == len)
+ return;
+ }
+ break;
#else
/* Shouldn't be possible to be here */
break;
@@ -258,9 +313,11 @@ static void ares__rand_bytes(ares_rand_state *state, unsigned char *buf, size_t
}
break;
+#ifdef ARES_NEEDS_RC4
case ARES_RAND_RC4:
ares_rc4_prng(&state->state.rc4, buf, len);
return;
+#endif
}
/* If we didn't return before we got here, that means we had a critical rand
@@ -269,6 +326,30 @@ static void ares__rand_bytes(ares_rand_state *state, unsigned char *buf, size_t
}
}
+
+void ares__rand_bytes(ares_rand_state *state, unsigned char *buf, size_t len)
+{
+ /* See if we need to refill the cache to serve the request, but if len is
+ * excessive, we're not going to update our cache or serve from cache */
+ if (len > state->cache_remaining && len < sizeof(state->cache)) {
+ size_t fetch_size = sizeof(state->cache) - state->cache_remaining;
+ ares__rand_bytes_fetch(state, state->cache, fetch_size);
+ state->cache_remaining = sizeof(state->cache);
+ }
+
+ /* Serve from cache */
+ if (len <= state->cache_remaining) {
+ size_t offset = sizeof(state->cache) - state->cache_remaining;
+ memcpy(buf, state->cache + offset, len);
+ state->cache_remaining -= len;
+ return;
+ }
+
+ /* Serve direct due to excess size of request */
+ ares__rand_bytes_fetch(state, buf, len);
+}
+
+
unsigned short ares__generate_new_id(ares_rand_state *state)
{
unsigned short r=0;
diff --git a/contrib/libs/c-ares/src/lib/ares_search.c b/contrib/libs/c-ares/src/lib/ares_search.c
index c4b0424f5b..d72b4c444e 100644
--- a/contrib/libs/c-ares/src/lib/ares_search.c
+++ b/contrib/libs/c-ares/src/lib/ares_search.c
@@ -1,17 +1,28 @@
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
+/* MIT License
+ *
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * Copyright (c) The c-ares project and its contributors
+ *
+ * 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.
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * SPDX-License-Identifier: MIT
*/
#include "ares_setup.h"
@@ -221,6 +232,11 @@ int ares__cat_domain(const char *name, const char *domain, char **s)
return ARES_ENOMEM;
memcpy(*s, name, nlen);
(*s)[nlen] = '.';
+ if (strcmp(domain, ".") == 0) {
+ /* Avoid appending the root domain to the separator, which would set *s to
+ an ill-formed value (ending in two consequtive dots). */
+ dlen = 0;
+ }
memcpy(*s + nlen + 1, domain, dlen);
(*s)[nlen + 1 + dlen] = 0;
return ARES_SUCCESS;
diff --git a/contrib/libs/c-ares/src/lib/ares_send.c b/contrib/libs/c-ares/src/lib/ares_send.c
index 542cf45f11..9507796720 100644
--- a/contrib/libs/c-ares/src/lib/ares_send.c
+++ b/contrib/libs/c-ares/src/lib/ares_send.c
@@ -1,17 +1,28 @@
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
+/* MIT License
+ *
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * Copyright (c) The c-ares project and its contributors
+ *
+ * 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.
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * 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_setup.h"
@@ -26,8 +37,8 @@
#include "ares_dns.h"
#include "ares_private.h"
-void ares_send(ares_channel channel, const unsigned char *qbuf, int qlen,
- ares_callback callback, void *arg)
+int ares_send_ex(ares_channel channel, const unsigned char *qbuf, int qlen,
+ ares_callback callback, void *arg)
{
struct query *query;
int i, packetsz;
@@ -37,26 +48,28 @@ void ares_send(ares_channel channel, const unsigned char *qbuf, int qlen,
if (qlen < HFIXEDSZ || qlen >= (1 << 16))
{
callback(arg, ARES_EBADQUERY, 0, NULL, 0);
- return;
+ return ARES_EBADQUERY;
}
if (channel->nservers < 1)
{
callback(arg, ARES_ESERVFAIL, 0, NULL, 0);
- return;
+ return ARES_ESERVFAIL;
}
/* Allocate space for query and allocated fields. */
query = ares_malloc(sizeof(struct query));
if (!query)
{
callback(arg, ARES_ENOMEM, 0, NULL, 0);
- return;
+ return ARES_ENOMEM;
}
+ memset(query, 0, sizeof(*query));
+ query->channel = channel;
query->tcpbuf = ares_malloc(qlen + 2);
if (!query->tcpbuf)
{
ares_free(query);
callback(arg, ARES_ENOMEM, 0, NULL, 0);
- return;
+ return ARES_ENOMEM;
}
query->server_info = ares_malloc(channel->nservers *
sizeof(query->server_info[0]));
@@ -65,7 +78,7 @@ void ares_send(ares_channel channel, const unsigned char *qbuf, int qlen,
ares_free(query->tcpbuf);
ares_free(query);
callback(arg, ARES_ENOMEM, 0, NULL, 0);
- return;
+ return ARES_ENOMEM;
}
/* Compute the query ID. Start with no timeout. */
@@ -109,21 +122,33 @@ void ares_send(ares_channel channel, const unsigned char *qbuf, int qlen,
query->timeouts = 0;
/* Initialize our list nodes. */
- ares__init_list_node(&(query->queries_by_qid), query);
- ares__init_list_node(&(query->queries_by_timeout), query);
- ares__init_list_node(&(query->queries_to_server), query);
- ares__init_list_node(&(query->all_queries), query);
+ query->node_queries_by_timeout = NULL;
+ query->node_queries_to_conn = NULL;
/* Chain the query into the list of all queries. */
- ares__insert_in_list(&(query->all_queries), &(channel->all_queries));
+ query->node_all_queries = ares__llist_insert_last(channel->all_queries, query);
+ if (query->node_all_queries == NULL) {
+ callback(arg, ARES_ENOMEM, 0, NULL, 0);
+ ares__free_query(query);
+ return ARES_ENOMEM;
+ }
+
/* Keep track of queries bucketed by qid, so we can process DNS
* responses quickly.
*/
- ares__insert_in_list(
- &(query->queries_by_qid),
- &(channel->queries_by_qid[query->qid % ARES_QID_TABLE_SIZE]));
+ if (!ares__htable_stvp_insert(channel->queries_by_qid, query->qid, query)) {
+ callback(arg, ARES_ENOMEM, 0, NULL, 0);
+ ares__free_query(query);
+ return ARES_ENOMEM;
+ }
/* Perform the first query action. */
now = ares__tvnow();
- ares__send_query(channel, query, &now);
+ return ares__send_query(channel, query, &now);
+}
+
+void ares_send(ares_channel channel, const unsigned char *qbuf, int qlen,
+ ares_callback callback, void *arg)
+{
+ ares_send_ex(channel, qbuf, qlen, callback, arg);
}
diff --git a/contrib/libs/c-ares/src/lib/ares_setup.h b/contrib/libs/c-ares/src/lib/ares_setup.h
index 46dd440323..f1cd5c0cea 100644
--- a/contrib/libs/c-ares/src/lib/ares_setup.h
+++ b/contrib/libs/c-ares/src/lib/ares_setup.h
@@ -1,19 +1,30 @@
-#ifndef HEADER_CARES_SETUP_H
-#define HEADER_CARES_SETUP_H
-
-
-/* Copyright (C) 2004 - 2012 by Daniel Stenberg et al
+/* MIT License
+ *
+ * Copyright (c) 2004 Daniel Stenberg
*
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in advertising or
- * publicity pertaining to distribution of the software without specific,
- * written prior permission. M.I.T. makes no representations about the
- * suitability of this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * 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 HEADER_CARES_SETUP_H
+#define HEADER_CARES_SETUP_H
/*
* Define WIN32 when build target is Win32 API
diff --git a/contrib/libs/c-ares/src/lib/ares_strcasecmp.c b/contrib/libs/c-ares/src/lib/ares_strcasecmp.c
index f9c85e2096..e7fd527404 100644
--- a/contrib/libs/c-ares/src/lib/ares_strcasecmp.c
+++ b/contrib/libs/c-ares/src/lib/ares_strcasecmp.c
@@ -1,18 +1,28 @@
-
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
+/* MIT License
+ *
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * Copyright (c) The c-ares project and its contributors
+ *
+ * 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.
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * SPDX-License-Identifier: MIT
*/
#include "ares_setup.h"
diff --git a/contrib/libs/c-ares/src/lib/ares_strcasecmp.h b/contrib/libs/c-ares/src/lib/ares_strcasecmp.h
index 57d86f9634..31a66be717 100644
--- a/contrib/libs/c-ares/src/lib/ares_strcasecmp.h
+++ b/contrib/libs/c-ares/src/lib/ares_strcasecmp.h
@@ -1,21 +1,31 @@
-#ifndef HEADER_CARES_STRCASECMP_H
-#define HEADER_CARES_STRCASECMP_H
-
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
+/* MIT License
+ *
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * Copyright (c) The c-ares project and its contributors
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * 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 HEADER_CARES_STRCASECMP_H
+#define HEADER_CARES_STRCASECMP_H
#include "ares_setup.h"
diff --git a/contrib/libs/c-ares/src/lib/ares_strdup.c b/contrib/libs/c-ares/src/lib/ares_strdup.c
index 39fc8692e7..db5dd1d84b 100644
--- a/contrib/libs/c-ares/src/lib/ares_strdup.c
+++ b/contrib/libs/c-ares/src/lib/ares_strdup.c
@@ -1,18 +1,28 @@
-
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
+/* MIT License
+ *
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * Copyright (c) The c-ares project and its contributors
+ *
+ * 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.
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * SPDX-License-Identifier: MIT
*/
#include "ares_setup.h"
diff --git a/contrib/libs/c-ares/src/lib/ares_strdup.h b/contrib/libs/c-ares/src/lib/ares_strdup.h
index 67f2a74f5f..06e8cdccb5 100644
--- a/contrib/libs/c-ares/src/lib/ares_strdup.h
+++ b/contrib/libs/c-ares/src/lib/ares_strdup.h
@@ -1,21 +1,31 @@
-#ifndef HEADER_CARES_STRDUP_H
-#define HEADER_CARES_STRDUP_H
-
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
+/* MIT License
+ *
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * Copyright (c) The c-ares project and its contributors
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * 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 HEADER_CARES_STRDUP_H
+#define HEADER_CARES_STRDUP_H
#include "ares_setup.h"
diff --git a/contrib/libs/c-ares/src/lib/ares_strerror.c b/contrib/libs/c-ares/src/lib/ares_strerror.c
index c3ecbd7b43..7e301ff94f 100644
--- a/contrib/libs/c-ares/src/lib/ares_strerror.c
+++ b/contrib/libs/c-ares/src/lib/ares_strerror.c
@@ -1,17 +1,28 @@
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
+/* MIT License
+ *
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * Copyright (c) The c-ares project and its contributors
+ *
+ * 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.
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * SPDX-License-Identifier: MIT
*/
#include "ares_setup.h"
diff --git a/contrib/libs/c-ares/src/lib/ares_strsplit.c b/contrib/libs/c-ares/src/lib/ares_strsplit.c
index d3e90c4a8f..985a02dbbf 100644
--- a/contrib/libs/c-ares/src/lib/ares_strsplit.c
+++ b/contrib/libs/c-ares/src/lib/ares_strsplit.c
@@ -1,16 +1,27 @@
-/* Copyright (C) 2018 by John Schember <john@nachtimwald.com>
+/* MIT License
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * Copyright (c) 2018 John Schember
+ *
+ * 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
*/
#if defined(__MVS__)
diff --git a/contrib/libs/c-ares/src/lib/ares_strsplit.h b/contrib/libs/c-ares/src/lib/ares_strsplit.h
index 009ee51b7b..d3c258fec0 100644
--- a/contrib/libs/c-ares/src/lib/ares_strsplit.h
+++ b/contrib/libs/c-ares/src/lib/ares_strsplit.h
@@ -1,21 +1,31 @@
+/* MIT License
+ *
+ * Copyright (c) 2018 John Schember
+ *
+ * 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 HEADER_CARES_STRSPLIT_H
#define HEADER_CARES_STRSPLIT_H
-/* Copyright (C) 2018 by John Schember <john@nachtimwald.com>
- *
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
- */
-
#include "ares_setup.h"
/* Split a string on delms skipping empty or duplicate elements.
diff --git a/contrib/libs/c-ares/src/lib/ares_timeout.c b/contrib/libs/c-ares/src/lib/ares_timeout.c
index 293e4af021..7390ef9263 100644
--- a/contrib/libs/c-ares/src/lib/ares_timeout.c
+++ b/contrib/libs/c-ares/src/lib/ares_timeout.c
@@ -1,17 +1,28 @@
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
+/* MIT License
+ *
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * Copyright (c) The c-ares project and its contributors
+ *
+ * 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:
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * 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_setup.h"
@@ -30,59 +41,47 @@ static long timeoffset(struct timeval *now, struct timeval *check)
(check->tv_usec - now->tv_usec)/1000;
}
-/* WARNING: Beware that this is linear in the number of outstanding
- * requests! You are probably far better off just calling ares_process()
- * once per second, rather than calling ares_timeout() to figure out
- * when to next call ares_process().
- */
struct timeval *ares_timeout(ares_channel channel, struct timeval *maxtv,
struct timeval *tvbuf)
{
- struct query *query;
- struct list_node* list_head;
- struct list_node* list_node;
- struct timeval now;
- struct timeval nextstop;
- long offset, min_offset;
+ struct query *query;
+ ares__slist_node_t *node;
+ struct timeval now;
+ long offset;
- /* No queries, no timeout (and no fetch of the current time). */
- if (ares__is_list_empty(&(channel->all_queries)))
- return maxtv;
+ /* The minimum timeout of all queries is always the first entry in
+ * channel->queries_by_timeout */
+ node = ares__slist_node_first(channel->queries_by_timeout);
+ /* no queries/timeout */
+ if (node == NULL) {
+ return maxtv; /* <-- maxtv can be null though, hrm */
+ }
+
+ query = ares__slist_node_val(node);
- /* Find the minimum timeout for the current set of queries. */
now = ares__tvnow();
- min_offset = -1;
- list_head = &(channel->all_queries);
- for (list_node = list_head->next; list_node != list_head;
- list_node = list_node->next)
- {
- query = list_node->data;
- if (query->timeout.tv_sec == 0)
- continue;
- offset = timeoffset(&now, &query->timeout);
- if (offset < 0)
- offset = 0;
- if (min_offset == -1 || offset < min_offset)
- min_offset = offset;
- }
+ offset = timeoffset(&now, &query->timeout);
+ if (offset < 0)
+ offset = 0;
+ if (offset > (long)INT_MAX)
+ offset = INT_MAX;
+
+ tvbuf->tv_sec = offset / 1000;
+ tvbuf->tv_usec = (offset % 1000) * 1000;
- /* If we found a minimum timeout and it's sooner than the one specified in
- * maxtv (if any), return it. Otherwise go with maxtv.
- */
- if (min_offset != -1)
- {
- int ioffset = (min_offset > (long)INT_MAX) ? INT_MAX : (int)min_offset;
+ if (maxtv == NULL)
+ return tvbuf;
- nextstop.tv_sec = ioffset/1000;
- nextstop.tv_usec = (ioffset%1000)*1000;
+ /* Return the minimum time between maxtv and tvbuf */
- if (!maxtv || ares__timedout(maxtv, &nextstop))
- {
- *tvbuf = nextstop;
- return tvbuf;
- }
- }
+ if (tvbuf->tv_sec > maxtv->tv_sec)
+ return maxtv;
+ if (tvbuf->tv_sec < maxtv->tv_sec)
+ return tvbuf;
+
+ if (tvbuf->tv_usec > maxtv->tv_usec)
+ return maxtv;
- return maxtv;
+ return tvbuf;
}
diff --git a/contrib/libs/c-ares/src/lib/ares_version.c b/contrib/libs/c-ares/src/lib/ares_version.c
index 4f8c42f2c9..b6a62da86d 100644
--- a/contrib/libs/c-ares/src/lib/ares_version.c
+++ b/contrib/libs/c-ares/src/lib/ares_version.c
@@ -1,4 +1,29 @@
-
+/* MIT License
+ *
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * Copyright (c) The c-ares project and its contributors
+ *
+ * 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_setup.h"
#include "ares.h"
diff --git a/contrib/libs/c-ares/src/lib/ares_writev.c b/contrib/libs/c-ares/src/lib/ares_writev.c
deleted file mode 100644
index e812c09e1c..0000000000
--- a/contrib/libs/c-ares/src/lib/ares_writev.c
+++ /dev/null
@@ -1,79 +0,0 @@
-
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
- *
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
- */
-
-#include "ares_setup.h"
-
-#ifdef HAVE_LIMITS_H
-# include <limits.h>
-#endif
-
-#include "ares.h"
-#include "ares_private.h"
-
-#ifndef HAVE_WRITEV
-ares_ssize_t ares_writev(ares_socket_t s, const struct iovec *iov, int iovcnt)
-{
- char *buffer, *bp;
- int i;
- size_t bytes = 0;
- ares_ssize_t result;
-
- /* Validate iovcnt */
- if (iovcnt <= 0)
- {
- SET_ERRNO(EINVAL);
- return (-1);
- }
-
- /* Validate and find the sum of the iov_len values in the iov array */
- for (i = 0; i < iovcnt; i++)
- {
- if (iov[i].iov_len > INT_MAX - bytes)
- {
- SET_ERRNO(EINVAL);
- return (-1);
- }
- bytes += iov[i].iov_len;
- }
-
- if (bytes == 0)
- return (0);
-
- /* Allocate a temporary buffer to hold the data */
- buffer = ares_malloc(bytes);
- if (!buffer)
- {
- SET_ERRNO(ENOMEM);
- return (-1);
- }
-
- /* Copy the data into buffer */
- for (bp = buffer, i = 0; i < iovcnt; ++i)
- {
- memcpy (bp, iov[i].iov_base, iov[i].iov_len);
- bp += iov[i].iov_len;
- }
-
- /* Send buffer contents */
- result = swrite(s, buffer, bytes);
-
- ares_free(buffer);
-
- return (result);
-}
-#endif
-
diff --git a/contrib/libs/c-ares/src/lib/ares_writev.h b/contrib/libs/c-ares/src/lib/ares_writev.h
deleted file mode 100644
index 65cea8708f..0000000000
--- a/contrib/libs/c-ares/src/lib/ares_writev.h
+++ /dev/null
@@ -1,36 +0,0 @@
-#ifndef HEADER_CARES_WRITEV_H
-#define HEADER_CARES_WRITEV_H
-
-
-/* Copyright 1998 by the Massachusetts Institute of Technology.
- *
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
- */
-
-#include "ares_setup.h"
-#include "ares.h"
-
-#ifndef HAVE_WRITEV
-
-/* Structure for scatter/gather I/O. */
-struct iovec
-{
- void *iov_base; /* Pointer to data. */
- size_t iov_len; /* Length of data. */
-};
-
-extern ares_ssize_t ares_writev(ares_socket_t s, const struct iovec *iov, int iovcnt);
-
-#endif
-
-#endif /* HEADER_CARES_WRITEV_H */
diff --git a/contrib/libs/c-ares/src/lib/bitncmp.c b/contrib/libs/c-ares/src/lib/bitncmp.c
index 1468d4923a..5a5a07f8ac 100644
--- a/contrib/libs/c-ares/src/lib/bitncmp.c
+++ b/contrib/libs/c-ares/src/lib/bitncmp.c
@@ -1,4 +1,3 @@
-
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1996,1999 by Internet Software Consortium.
@@ -14,6 +13,8 @@
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * SPDX-License-Identifier: MIT
*/
#ifndef HAVE_BITNCMP
diff --git a/contrib/libs/c-ares/src/lib/bitncmp.h b/contrib/libs/c-ares/src/lib/bitncmp.h
index 7b8d66c166..8e39eb510c 100644
--- a/contrib/libs/c-ares/src/lib/bitncmp.h
+++ b/contrib/libs/c-ares/src/lib/bitncmp.h
@@ -1,21 +1,30 @@
-#ifndef __ARES_BITNCMP_H
-#define __ARES_BITNCMP_H
-
-
-/* Copyright (C) 2005, 2013 by Dominick Meglio
+/* MIT License
+ *
+ * Copyright (c) 2005 Dominick Meglio
*
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in
- * advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * 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_BITNCMP_H
+#define __ARES_BITNCMP_H
#ifndef HAVE_BITNCMP
int ares__bitncmp(const void *l, const void *r, int n);
diff --git a/contrib/libs/c-ares/src/lib/config-win32.h b/contrib/libs/c-ares/src/lib/config-win32.h
index da7eba44d8..94692d6c36 100644
--- a/contrib/libs/c-ares/src/lib/config-win32.h
+++ b/contrib/libs/c-ares/src/lib/config-win32.h
@@ -1,18 +1,30 @@
-#ifndef HEADER_CARES_CONFIG_WIN32_H
-#define HEADER_CARES_CONFIG_WIN32_H
-
-/* Copyright (C) 2004 - 2011 by Daniel Stenberg et al
+/* 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:
*
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in advertising or
- * publicity pertaining to distribution of the software without specific,
- * written prior permission. M.I.T. makes no representations about the
- * suitability of this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * 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 HEADER_CARES_CONFIG_WIN32_H
+#define HEADER_CARES_CONFIG_WIN32_H
/* ================================================================ */
/* c-ares/config-win32.h - Hand crafted config file for Windows */
diff --git a/contrib/libs/c-ares/src/lib/inet_net_pton.c b/contrib/libs/c-ares/src/lib/inet_net_pton.c
index 7130f0f1e2..d3924c3767 100644
--- a/contrib/libs/c-ares/src/lib/inet_net_pton.c
+++ b/contrib/libs/c-ares/src/lib/inet_net_pton.c
@@ -1,4 +1,3 @@
-
/*
* Copyright (c) 2012 by Gilles Chehade <gilles@openbsd.org>
* Copyright (c) 1996,1999 by Internet Software Consortium.
@@ -15,6 +14,8 @@
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
+ *
+ * SPDX-License-Identifier: MIT
*/
#include "ares_setup.h"
diff --git a/contrib/libs/c-ares/src/lib/inet_ntop.c b/contrib/libs/c-ares/src/lib/inet_ntop.c
index 6645c0a467..246d630647 100644
--- a/contrib/libs/c-ares/src/lib/inet_ntop.c
+++ b/contrib/libs/c-ares/src/lib/inet_ntop.c
@@ -13,6 +13,8 @@
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * SPDX-License-Identifier: MIT
*/
#include "ares_setup.h"
@@ -84,7 +86,7 @@ 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_t)sprintf(tmp, fmt, src[0], src[1], src[2], src[3]) >= size) {
+ if ((size_t)snprintf(tmp, sizeof(tmp), fmt, src[0], src[1], src[2], src[3]) >= size) {
SET_ERRNO(ENOSPC);
return (NULL);
}
@@ -171,7 +173,7 @@ inet_ntop6(const unsigned char *src, char *dst, size_t size)
tp += strlen(tp);
break;
}
- tp += sprintf(tp, "%x", words[i]);
+ tp += snprintf(tp, sizeof(tmp)-(tp-tmp), "%x", words[i]);
}
/* Was it a trailing run of 0x00's? */
if (best.base != -1 && (best.base + best.len) == (NS_IN6ADDRSZ / NS_INT16SZ))
diff --git a/contrib/libs/c-ares/src/lib/setup_once.h b/contrib/libs/c-ares/src/lib/setup_once.h
index d4b0a954ed..1e9c531a9d 100644
--- a/contrib/libs/c-ares/src/lib/setup_once.h
+++ b/contrib/libs/c-ares/src/lib/setup_once.h
@@ -1,19 +1,30 @@
-#ifndef __SETUP_ONCE_H
-#define __SETUP_ONCE_H
-
-
-/* Copyright (C) 2004 - 2013 by Daniel Stenberg et al
+/* 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:
*
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in advertising or
- * publicity pertaining to distribution of the software without specific,
- * written prior permission. M.I.T. makes no representations about the
- * suitability of this software for any purpose. It is provided "as is"
- * without express or implied warranty.
+ * 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
/********************************************************************
@@ -91,6 +102,10 @@
# endif
#endif
+#ifdef HAVE_SYS_RANDOM_H
+#include <sys/random.h>
+#endif
+
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
diff --git a/contrib/libs/c-ares/src/lib/windows_port.c b/contrib/libs/c-ares/src/lib/windows_port.c
index 03acd1c1e2..5977b8493e 100644
--- a/contrib/libs/c-ares/src/lib/windows_port.c
+++ b/contrib/libs/c-ares/src/lib/windows_port.c
@@ -1,3 +1,11 @@
+/**********************************************************************
+ *
+ * Copyright (c) 1998 Massachusetts Institute of Technology
+ * Copyright (C) Daniel Stenberg
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ */
#include "ares_setup.h"
diff --git a/contrib/libs/c-ares/test/.yandex_meta/licenses.list.txt b/contrib/libs/c-ares/test/.yandex_meta/licenses.list.txt
new file mode 100644
index 0000000000..c401eeebd7
--- /dev/null
+++ b/contrib/libs/c-ares/test/.yandex_meta/licenses.list.txt
@@ -0,0 +1,15 @@
+====================COPYRIGHT====================
+ * Copyright (C) Brad House
+
+
+====================COPYRIGHT====================
+ * Copyright (C) The c-ares project
+
+
+====================COPYRIGHT====================
+/* Copyright (C) The c-ares project and its contributors
+ * SPDX-License-Identifier: MIT
+
+
+====================MIT====================
+ * SPDX-License-Identifier: MIT
diff --git a/contrib/libs/c-ares/test/README.md b/contrib/libs/c-ares/test/README.md
index 9881446784..6a864767c3 100644
--- a/contrib/libs/c-ares/test/README.md
+++ b/contrib/libs/c-ares/test/README.md
@@ -1,7 +1,6 @@
c-ares Unit Test Suite
======================
-
This directory holds unit tests for the c-ares library. To build the tests:
- Build the main c-ares library first, in the directory above this. To
diff --git a/contrib/libs/c-ares/test/ares-test-ai.h b/contrib/libs/c-ares/test/ares-test-ai.h
index 7cf27e3306..e4d5b36a50 100644
--- a/contrib/libs/c-ares/test/ares-test-ai.h
+++ b/contrib/libs/c-ares/test/ares-test-ai.h
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) The c-ares project
+ *
+ * Permission to use, copy, modify, and distribute this
+ * software and its documentation for any purpose and without
+ * fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting
+ * documentation, and that the name of M.I.T. not be used in
+ * advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * SPDX-License-Identifier: MIT
+ */
#ifndef ARES_TEST_AI_H
#define ARES_TEST_AI_H
diff --git a/contrib/libs/c-ares/test/ares-test-init.cc b/contrib/libs/c-ares/test/ares-test-init.cc
index da47e7eca4..6c389d53c4 100644
--- a/contrib/libs/c-ares/test/ares-test-init.cc
+++ b/contrib/libs/c-ares/test/ares-test-init.cc
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) The c-ares project
+ *
+ * Permission to use, copy, modify, and distribute this
+ * software and its documentation for any purpose and without
+ * fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting
+ * documentation, and that the name of M.I.T. not be used in
+ * advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * SPDX-License-Identifier: MIT
+ */
#include "ares-test.h"
// library initialization is only needed for windows builds
diff --git a/contrib/libs/c-ares/test/ares-test-internal.cc b/contrib/libs/c-ares/test/ares-test-internal.cc
index 40cc82b86e..2cdb42f17e 100644
--- a/contrib/libs/c-ares/test/ares-test-internal.cc
+++ b/contrib/libs/c-ares/test/ares-test-internal.cc
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) The c-ares project
+ *
+ * Permission to use, copy, modify, and distribute this
+ * software and its documentation for any purpose and without
+ * fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting
+ * documentation, and that the name of M.I.T. not be used in
+ * advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * SPDX-License-Identifier: MIT
+ */
#include "ares-test.h"
#include "dns-proto.h"
@@ -508,6 +525,22 @@ TEST(Misc, OnionDomain) {
EXPECT_EQ(1, ares__is_onion_domain("YES.ONION"));
EXPECT_EQ(1, ares__is_onion_domain("YES.ONION."));
}
+
+TEST_F(LibraryTest, CatDomain) {
+ char *s;
+
+ ares__cat_domain("foo", "example.net", &s);
+ EXPECT_STREQ("foo.example.net", s);
+ ares_free(s);
+
+ ares__cat_domain("foo", ".", &s);
+ EXPECT_STREQ("foo.", s);
+ ares_free(s);
+
+ ares__cat_domain("foo", "example.net.", &s);
+ EXPECT_STREQ("foo.example.net.", s);
+ ares_free(s);
+}
#endif
#ifdef CARES_EXPOSE_STATICS
@@ -605,26 +638,10 @@ const struct ares_socket_functions VirtualizeIO::default_functions = {
}
return s;
},
- [](ares_socket_t s, void * p) {
- return :: sclose(s);
- },
- [](ares_socket_t s, const struct sockaddr * addr, socklen_t len, void *) {
- return ::connect(s, addr, len);
- },
- [](ares_socket_t s, void * dst, size_t len, int flags, struct sockaddr * addr, socklen_t * alen, void *) -> ares_ssize_t {
-#ifdef HAVE_RECVFROM
- return ::recvfrom(s, reinterpret_cast<RECV_TYPE_ARG2>(dst), len, flags, addr, alen);
-#else
- return sread(s, dst, len);
-#endif
- },
- [](ares_socket_t s, const struct iovec * vec, int len, void *) {
-#ifndef HAVE_WRITEV
- return ares_writev(s, vec, len);
-#else
- return :: writev(s, vec, len);
-#endif
- }
+ NULL,
+ NULL,
+ NULL,
+ NULL
};
diff --git a/contrib/libs/c-ares/test/ares-test-live.cc b/contrib/libs/c-ares/test/ares-test-live.cc
index 75950ae72d..5d640b8e68 100644
--- a/contrib/libs/c-ares/test/ares-test-live.cc
+++ b/contrib/libs/c-ares/test/ares-test-live.cc
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) The c-ares project
+ *
+ * Permission to use, copy, modify, and distribute this
+ * software and its documentation for any purpose and without
+ * fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting
+ * documentation, and that the name of M.I.T. not be used in
+ * advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * SPDX-License-Identifier: MIT
+ */
// This file includes tests that attempt to do real lookups
// of DNS names using the local machine's live infrastructure.
// As a result, we don't check the results very closely, to allow
diff --git a/contrib/libs/c-ares/test/ares-test-misc.cc b/contrib/libs/c-ares/test/ares-test-misc.cc
index f85a3bf604..96d0a20f86 100644
--- a/contrib/libs/c-ares/test/ares-test-misc.cc
+++ b/contrib/libs/c-ares/test/ares-test-misc.cc
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) The c-ares project
+ *
+ * Permission to use, copy, modify, and distribute this
+ * software and its documentation for any purpose and without
+ * fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting
+ * documentation, and that the name of M.I.T. not be used in
+ * advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * SPDX-License-Identifier: MIT
+ */
#include "ares-test.h"
#include "dns-proto.h"
diff --git a/contrib/libs/c-ares/test/ares-test-mock-ai.cc b/contrib/libs/c-ares/test/ares-test-mock-ai.cc
index afbec30ce1..7e69110306 100644
--- a/contrib/libs/c-ares/test/ares-test-mock-ai.cc
+++ b/contrib/libs/c-ares/test/ares-test-mock-ai.cc
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) The c-ares project
+ *
+ * Permission to use, copy, modify, and distribute this
+ * software and its documentation for any purpose and without
+ * fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting
+ * documentation, and that the name of M.I.T. not be used in
+ * advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * SPDX-License-Identifier: MIT
+ */
#include "ares-test-ai.h"
#include "dns-proto.h"
@@ -177,8 +194,7 @@ TEST_P(MockTCPChannelTestAI, ServFailResponse) {
ares_getaddrinfo(channel_, "www.google.com.", NULL, &hints, AddrInfoCallback, &result);
Process();
EXPECT_TRUE(result.done_);
- // ARES_FLAG_NOCHECKRESP not set, so SERVFAIL consumed
- EXPECT_EQ(ARES_ECONNREFUSED, result.status_);
+ EXPECT_EQ(ARES_ESERVFAIL, result.status_);
}
TEST_P(MockTCPChannelTestAI, NotImplResponse) {
@@ -196,8 +212,7 @@ TEST_P(MockTCPChannelTestAI, NotImplResponse) {
ares_getaddrinfo(channel_, "www.google.com.", NULL, &hints, AddrInfoCallback, &result);
Process();
EXPECT_TRUE(result.done_);
- // ARES_FLAG_NOCHECKRESP not set, so NOTIMP consumed
- EXPECT_EQ(ARES_ECONNREFUSED, result.status_);
+ EXPECT_EQ(ARES_ENOTIMP, result.status_);
}
TEST_P(MockTCPChannelTestAI, RefusedResponse) {
@@ -215,8 +230,7 @@ TEST_P(MockTCPChannelTestAI, RefusedResponse) {
ares_getaddrinfo(channel_, "www.google.com.", NULL, &hints, AddrInfoCallback, &result);
Process();
EXPECT_TRUE(result.done_);
- // ARES_FLAG_NOCHECKRESP not set, so REFUSED consumed
- EXPECT_EQ(ARES_ECONNREFUSED, result.status_);
+ EXPECT_EQ(ARES_EREFUSED, result.status_);
}
TEST_P(MockTCPChannelTestAI, YXDomainResponse) {
diff --git a/contrib/libs/c-ares/test/ares-test-mock.cc b/contrib/libs/c-ares/test/ares-test-mock.cc
index e29c050f39..0557c50ab7 100644
--- a/contrib/libs/c-ares/test/ares-test-mock.cc
+++ b/contrib/libs/c-ares/test/ares-test-mock.cc
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) The c-ares project
+ *
+ * Permission to use, copy, modify, and distribute this
+ * software and its documentation for any purpose and without
+ * fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting
+ * documentation, and that the name of M.I.T. not be used in
+ * advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * SPDX-License-Identifier: MIT
+ */
#include "ares-test.h"
#include "dns-proto.h"
@@ -202,7 +219,88 @@ TEST_P(MockChannelTest, SockConfigureFailCallback) {
EXPECT_EQ(ARES_ECONNREFUSED, result.status_);
}
-// TCP only to prevent retries
+#define MAXUDPQUERIES_TOTAL 32
+#define MAXUDPQUERIES_LIMIT 8
+
+class MockUDPMaxQueriesTest
+ : public MockChannelOptsTest,
+ public ::testing::WithParamInterface<int> {
+ public:
+ MockUDPMaxQueriesTest()
+ : MockChannelOptsTest(1, GetParam(), false,
+ FillOptions(&opts_),
+ ARES_OPT_UDP_MAX_QUERIES) {}
+ static struct ares_options* FillOptions(struct ares_options * opts) {
+ memset(opts, 0, sizeof(struct ares_options));
+ opts->udp_max_queries = MAXUDPQUERIES_LIMIT;
+ return opts;
+ }
+ private:
+ struct ares_options opts_;
+};
+
+TEST_P(MockUDPMaxQueriesTest, GetHostByNameParallelLookups) {
+ DNSPacket rsp;
+ rsp.set_response().set_aa()
+ .add_question(new DNSQuestion("www.google.com", T_A))
+ .add_answer(new DNSARR("www.google.com", 100, {2, 3, 4, 5}));
+ ON_CALL(server_, OnRequest("www.google.com", T_A))
+ .WillByDefault(SetReply(&server_, &rsp));
+
+ // Get notified of new sockets so we can validate how many are created
+ int rc = ARES_SUCCESS;
+ ares_set_socket_callback(channel_, SocketConnectCallback, &rc);
+ sock_cb_count = 0;
+
+ HostResult result[MAXUDPQUERIES_TOTAL];
+ for (size_t i=0; i<MAXUDPQUERIES_TOTAL; i++) {
+ ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result[i]);
+ }
+
+ Process();
+
+ EXPECT_EQ(MAXUDPQUERIES_TOTAL / MAXUDPQUERIES_LIMIT, sock_cb_count);
+
+ for (size_t i=0; i<MAXUDPQUERIES_TOTAL; i++) {
+ std::stringstream ss;
+ EXPECT_TRUE(result[i].done_);
+ ss << result[i].host_;
+ EXPECT_EQ("{'www.google.com' aliases=[] addrs=[2.3.4.5]}", ss.str());
+ }
+}
+
+#define TCPPARALLELLOOKUPS 32
+TEST_P(MockTCPChannelTest, GetHostByNameParallelLookups) {
+ DNSPacket rsp;
+ rsp.set_response().set_aa()
+ .add_question(new DNSQuestion("www.google.com", T_A))
+ .add_answer(new DNSARR("www.google.com", 100, {2, 3, 4, 5}));
+ ON_CALL(server_, OnRequest("www.google.com", T_A))
+ .WillByDefault(SetReply(&server_, &rsp));
+
+ // Get notified of new sockets so we can validate how many are created
+ int rc = ARES_SUCCESS;
+ ares_set_socket_callback(channel_, SocketConnectCallback, &rc);
+ sock_cb_count = 0;
+
+ HostResult result[TCPPARALLELLOOKUPS];
+ for (size_t i=0; i<TCPPARALLELLOOKUPS; i++) {
+ ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result[i]);
+ }
+
+ Process();
+
+ EXPECT_EQ(1, sock_cb_count);
+
+ for (size_t i=0; i<TCPPARALLELLOOKUPS; i++) {
+ std::stringstream ss;
+ EXPECT_TRUE(result[i].done_);
+ ss << result[i].host_;
+ EXPECT_EQ("{'www.google.com' aliases=[] addrs=[2.3.4.5]}", ss.str());
+ }
+}
+
+
TEST_P(MockTCPChannelTest, MalformedResponse) {
std::vector<byte> one = {0x01};
EXPECT_CALL(server_, OnRequest("www.google.com", T_A))
@@ -240,8 +338,7 @@ TEST_P(MockTCPChannelTest, ServFailResponse) {
ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
Process();
EXPECT_TRUE(result.done_);
- // ARES_FLAG_NOCHECKRESP not set, so SERVFAIL consumed
- EXPECT_EQ(ARES_ECONNREFUSED, result.status_);
+ EXPECT_EQ(ARES_ESERVFAIL, result.status_);
}
TEST_P(MockTCPChannelTest, NotImplResponse) {
@@ -255,8 +352,7 @@ TEST_P(MockTCPChannelTest, NotImplResponse) {
ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
Process();
EXPECT_TRUE(result.done_);
- // ARES_FLAG_NOCHECKRESP not set, so NOTIMP consumed
- EXPECT_EQ(ARES_ECONNREFUSED, result.status_);
+ EXPECT_EQ(ARES_ENOTIMP, result.status_);
}
TEST_P(MockTCPChannelTest, RefusedResponse) {
@@ -270,8 +366,7 @@ TEST_P(MockTCPChannelTest, RefusedResponse) {
ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
Process();
EXPECT_TRUE(result.done_);
- // ARES_FLAG_NOCHECKRESP not set, so REFUSED consumed
- EXPECT_EQ(ARES_ECONNREFUSED, result.status_);
+ EXPECT_EQ(ARES_EREFUSED, result.status_);
}
TEST_P(MockTCPChannelTest, YXDomainResponse) {
@@ -631,6 +726,29 @@ TEST_P(MockChannelTest, SearchHighNdots) {
ss.str());
}
+TEST_P(MockUDPChannelTest, V4WorksV6Timeout) {
+ std::vector<byte> nothing;
+ DNSPacket reply;
+ reply.set_response().set_aa()
+ .add_question(new DNSQuestion("www.google.com", T_A))
+ .add_answer(new DNSARR("www.google.com", 0x0100, {0x01, 0x02, 0x03, 0x04}));
+
+ ON_CALL(server_, OnRequest("www.google.com", T_A))
+ .WillByDefault(SetReply(&server_, &reply));
+
+ ON_CALL(server_, OnRequest("www.google.com", T_AAAA))
+ .WillByDefault(SetReplyData(&server_, nothing));
+
+ HostResult result;
+ ares_gethostbyname(channel_, "www.google.com.", AF_UNSPEC, HostCallback, &result);
+ Process();
+ EXPECT_TRUE(result.done_);
+ EXPECT_EQ(1, result.timeouts_);
+ std::stringstream ss;
+ ss << result.host_;
+ EXPECT_EQ("{'www.google.com' aliases=[] addrs=[1.2.3.4]}", ss.str());
+}
+
TEST_P(MockChannelTest, UnspecifiedFamilyV6) {
DNSPacket rsp6;
rsp6.set_response().set_aa()
@@ -923,6 +1041,26 @@ TEST_P(MockUDPChannelTest, CancelLater) {
EXPECT_EQ(0, result.timeouts_);
}
+TEST_P(MockChannelTest, DisconnectFirstAttempt) {
+ DNSPacket reply;
+ reply.set_response().set_aa()
+ .add_question(new DNSQuestion("www.google.com", T_A))
+ .add_answer(new DNSARR("www.google.com", 0x0100, {0x01, 0x02, 0x03, 0x04}));
+
+ // On second request, cancel the channel.
+ EXPECT_CALL(server_, OnRequest("www.google.com", T_A))
+ .WillOnce(Disconnect(&server_))
+ .WillOnce(SetReply(&server_, &reply));
+
+ HostResult result;
+ ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
+ Process();
+ EXPECT_TRUE(result.done_);
+ std::stringstream ss;
+ ss << result.host_;
+ EXPECT_EQ("{'www.google.com' aliases=[] addrs=[1.2.3.4]}", ss.str());
+}
+
TEST_P(MockChannelTest, GetHostByNameDestroyAbsolute) {
HostResult result;
ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
@@ -1183,6 +1321,8 @@ INSTANTIATE_TEST_SUITE_P(AddressFamilies, MockChannelTest, ::testing::ValuesIn(a
INSTANTIATE_TEST_SUITE_P(AddressFamilies, MockUDPChannelTest, ::testing::ValuesIn(ares::test::families));
+INSTANTIATE_TEST_SUITE_P(AddressFamilies, MockUDPMaxQueriesTest, ::testing::ValuesIn(ares::test::families));
+
INSTANTIATE_TEST_SUITE_P(AddressFamilies, MockTCPChannelTest, ::testing::ValuesIn(ares::test::families));
INSTANTIATE_TEST_SUITE_P(AddressFamilies, MockExtraOptsTest, ::testing::ValuesIn(ares::test::families_modes));
diff --git a/contrib/libs/c-ares/test/ares-test-ns.cc b/contrib/libs/c-ares/test/ares-test-ns.cc
index c3c455214d..a97d7e586f 100644
--- a/contrib/libs/c-ares/test/ares-test-ns.cc
+++ b/contrib/libs/c-ares/test/ares-test-ns.cc
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) The c-ares project
+ *
+ * Permission to use, copy, modify, and distribute this
+ * software and its documentation for any purpose and without
+ * fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting
+ * documentation, and that the name of M.I.T. not be used in
+ * advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * SPDX-License-Identifier: MIT
+ */
#include "ares-test.h"
#ifdef HAVE_CONTAINER
diff --git a/contrib/libs/c-ares/test/ares-test-parse-a.cc b/contrib/libs/c-ares/test/ares-test-parse-a.cc
index f8050ac708..6484ae0a7e 100644
--- a/contrib/libs/c-ares/test/ares-test-parse-a.cc
+++ b/contrib/libs/c-ares/test/ares-test-parse-a.cc
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) The c-ares project
+ *
+ * Permission to use, copy, modify, and distribute this
+ * software and its documentation for any purpose and without
+ * fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting
+ * documentation, and that the name of M.I.T. not be used in
+ * advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * SPDX-License-Identifier: MIT
+ */
#include "ares-test.h"
#include "dns-proto.h"
diff --git a/contrib/libs/c-ares/test/ares-test-parse-aaaa.cc b/contrib/libs/c-ares/test/ares-test-parse-aaaa.cc
index df56529680..223b1a3e2b 100644
--- a/contrib/libs/c-ares/test/ares-test-parse-aaaa.cc
+++ b/contrib/libs/c-ares/test/ares-test-parse-aaaa.cc
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) The c-ares project
+ *
+ * Permission to use, copy, modify, and distribute this
+ * software and its documentation for any purpose and without
+ * fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting
+ * documentation, and that the name of M.I.T. not be used in
+ * advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * SPDX-License-Identifier: MIT
+ */
#include "ares-test.h"
#include "dns-proto.h"
diff --git a/contrib/libs/c-ares/test/ares-test-parse-caa.cc b/contrib/libs/c-ares/test/ares-test-parse-caa.cc
index 99903edf71..4b35f5975f 100644
--- a/contrib/libs/c-ares/test/ares-test-parse-caa.cc
+++ b/contrib/libs/c-ares/test/ares-test-parse-caa.cc
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) The c-ares project
+ *
+ * Permission to use, copy, modify, and distribute this
+ * software and its documentation for any purpose and without
+ * fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting
+ * documentation, and that the name of M.I.T. not be used in
+ * advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * SPDX-License-Identifier: MIT
+ */
#include "ares-test.h"
#include "dns-proto.h"
diff --git a/contrib/libs/c-ares/test/ares-test-parse-mx.cc b/contrib/libs/c-ares/test/ares-test-parse-mx.cc
index db8fa89404..941afb873d 100644
--- a/contrib/libs/c-ares/test/ares-test-parse-mx.cc
+++ b/contrib/libs/c-ares/test/ares-test-parse-mx.cc
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) The c-ares project
+ *
+ * Permission to use, copy, modify, and distribute this
+ * software and its documentation for any purpose and without
+ * fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting
+ * documentation, and that the name of M.I.T. not be used in
+ * advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * SPDX-License-Identifier: MIT
+ */
#include "ares-test.h"
#include "dns-proto.h"
diff --git a/contrib/libs/c-ares/test/ares-test-parse-naptr.cc b/contrib/libs/c-ares/test/ares-test-parse-naptr.cc
index aa1a2a5029..a9cb603bb2 100644
--- a/contrib/libs/c-ares/test/ares-test-parse-naptr.cc
+++ b/contrib/libs/c-ares/test/ares-test-parse-naptr.cc
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) The c-ares project
+ *
+ * Permission to use, copy, modify, and distribute this
+ * software and its documentation for any purpose and without
+ * fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting
+ * documentation, and that the name of M.I.T. not be used in
+ * advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * SPDX-License-Identifier: MIT
+ */
#include "ares-test.h"
#include "dns-proto.h"
diff --git a/contrib/libs/c-ares/test/ares-test-parse-ns.cc b/contrib/libs/c-ares/test/ares-test-parse-ns.cc
index 316492174c..965ec299a7 100644
--- a/contrib/libs/c-ares/test/ares-test-parse-ns.cc
+++ b/contrib/libs/c-ares/test/ares-test-parse-ns.cc
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) The c-ares project
+ *
+ * Permission to use, copy, modify, and distribute this
+ * software and its documentation for any purpose and without
+ * fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting
+ * documentation, and that the name of M.I.T. not be used in
+ * advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * SPDX-License-Identifier: MIT
+ */
#include "ares-test.h"
#include "dns-proto.h"
diff --git a/contrib/libs/c-ares/test/ares-test-parse-ptr.cc b/contrib/libs/c-ares/test/ares-test-parse-ptr.cc
index e8fcac3224..a721823062 100644
--- a/contrib/libs/c-ares/test/ares-test-parse-ptr.cc
+++ b/contrib/libs/c-ares/test/ares-test-parse-ptr.cc
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) The c-ares project
+ *
+ * Permission to use, copy, modify, and distribute this
+ * software and its documentation for any purpose and without
+ * fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting
+ * documentation, and that the name of M.I.T. not be used in
+ * advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * SPDX-License-Identifier: MIT
+ */
#include "ares-test.h"
#include "dns-proto.h"
diff --git a/contrib/libs/c-ares/test/ares-test-parse-soa-any.cc b/contrib/libs/c-ares/test/ares-test-parse-soa-any.cc
index 700073c5c8..eccec0fe9c 100644
--- a/contrib/libs/c-ares/test/ares-test-parse-soa-any.cc
+++ b/contrib/libs/c-ares/test/ares-test-parse-soa-any.cc
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) The c-ares project
+ *
+ * Permission to use, copy, modify, and distribute this
+ * software and its documentation for any purpose and without
+ * fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting
+ * documentation, and that the name of M.I.T. not be used in
+ * advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * SPDX-License-Identifier: MIT
+ */
#include "ares-test.h"
#include "dns-proto.h"
diff --git a/contrib/libs/c-ares/test/ares-test-parse-soa.cc b/contrib/libs/c-ares/test/ares-test-parse-soa.cc
index 22a78e5f46..f32600e835 100644
--- a/contrib/libs/c-ares/test/ares-test-parse-soa.cc
+++ b/contrib/libs/c-ares/test/ares-test-parse-soa.cc
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) The c-ares project
+ *
+ * Permission to use, copy, modify, and distribute this
+ * software and its documentation for any purpose and without
+ * fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting
+ * documentation, and that the name of M.I.T. not be used in
+ * advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * SPDX-License-Identifier: MIT
+ */
#include "ares-test.h"
#include "dns-proto.h"
diff --git a/contrib/libs/c-ares/test/ares-test-parse-srv.cc b/contrib/libs/c-ares/test/ares-test-parse-srv.cc
index b004759801..2c5472fc00 100644
--- a/contrib/libs/c-ares/test/ares-test-parse-srv.cc
+++ b/contrib/libs/c-ares/test/ares-test-parse-srv.cc
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) The c-ares project
+ *
+ * Permission to use, copy, modify, and distribute this
+ * software and its documentation for any purpose and without
+ * fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting
+ * documentation, and that the name of M.I.T. not be used in
+ * advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * SPDX-License-Identifier: MIT
+ */
#include "ares-test.h"
#include "dns-proto.h"
diff --git a/contrib/libs/c-ares/test/ares-test-parse-txt.cc b/contrib/libs/c-ares/test/ares-test-parse-txt.cc
index b33fb2de0c..8caf28fc66 100644
--- a/contrib/libs/c-ares/test/ares-test-parse-txt.cc
+++ b/contrib/libs/c-ares/test/ares-test-parse-txt.cc
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) The c-ares project
+ *
+ * Permission to use, copy, modify, and distribute this
+ * software and its documentation for any purpose and without
+ * fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting
+ * documentation, and that the name of M.I.T. not be used in
+ * advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * SPDX-License-Identifier: MIT
+ */
#include "ares-test.h"
#include "dns-proto.h"
diff --git a/contrib/libs/c-ares/test/ares-test-parse-uri.cc b/contrib/libs/c-ares/test/ares-test-parse-uri.cc
index 4fbffd0afd..1e436970e6 100644
--- a/contrib/libs/c-ares/test/ares-test-parse-uri.cc
+++ b/contrib/libs/c-ares/test/ares-test-parse-uri.cc
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) The c-ares project
+ *
+ * Permission to use, copy, modify, and distribute this
+ * software and its documentation for any purpose and without
+ * fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting
+ * documentation, and that the name of M.I.T. not be used in
+ * advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * SPDX-License-Identifier: MIT
+ */
#include "ares-test.h"
#include "dns-proto.h"
diff --git a/contrib/libs/c-ares/test/ares-test-parse.cc b/contrib/libs/c-ares/test/ares-test-parse.cc
index 87ab0bd25f..8a3c863366 100644
--- a/contrib/libs/c-ares/test/ares-test-parse.cc
+++ b/contrib/libs/c-ares/test/ares-test-parse.cc
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) The c-ares project
+ *
+ * Permission to use, copy, modify, and distribute this
+ * software and its documentation for any purpose and without
+ * fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting
+ * documentation, and that the name of M.I.T. not be used in
+ * advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * SPDX-License-Identifier: MIT
+ */
#include "ares-test.h"
#include "dns-proto.h"
diff --git a/contrib/libs/c-ares/test/ares-test.cc b/contrib/libs/c-ares/test/ares-test.cc
index 7e8793d031..059f1cf736 100644
--- a/contrib/libs/c-ares/test/ares-test.cc
+++ b/contrib/libs/c-ares/test/ares-test.cc
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) Brad House
+ *
+ * Permission to use, copy, modify, and distribute this
+ * software and its documentation for any purpose and without
+ * fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting
+ * documentation, and that the name of M.I.T. not be used in
+ * advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * SPDX-License-Identifier: MIT
+ */
#include "ares_setup.h"
#include "ares.h"
#include "ares_nameser.h"
@@ -84,9 +101,11 @@ void ProcessWork(ares_channel channel,
}
}
- // Wait for activity or timeout.
- tv.tv_sec = 0;
- tv.tv_usec = 100000; // 100ms
+ /* If ares_timeout returns NULL, it means there are no requests in queue,
+ * so we can break out */
+ if (ares_timeout(channel, NULL, &tv) == NULL)
+ return;
+
count = select(nfds, &readers, &writers, nullptr, &tv);
if (count < 0) {
fprintf(stderr, "select() failed, errno %d\n", errno);
@@ -175,6 +194,8 @@ void DefaultChannelModeTest::Process() {
MockServer::MockServer(int family, int port)
: udpport_(port), tcpport_(port), qid_(-1) {
// Create a TCP socket to receive data on.
+ tcp_data_ = NULL;
+ tcp_data_len_ = 0;
tcpfd_ = socket(family, SOCK_STREAM, 0);
EXPECT_NE(-1, tcpfd_);
int optval = 1;
@@ -260,6 +281,7 @@ MockServer::~MockServer() {
}
sclose(tcpfd_);
sclose(udpfd_);
+ free(tcp_data_);
}
void MockServer::ProcessPacket(int fd, struct sockaddr_storage *addr, socklen_t addrlen,
@@ -345,36 +367,38 @@ void MockServer::ProcessFD(int fd) {
byte buffer[2048];
int len = recvfrom(fd, BYTE_CAST buffer, sizeof(buffer), 0,
(struct sockaddr *)&addr, &addrlen);
- byte* data = buffer;
if (fd != udpfd_) {
if (len == 0) {
connfds_.erase(std::find(connfds_.begin(), connfds_.end(), fd));
sclose(fd);
+ free(tcp_data_);
+ tcp_data_ = NULL;
+ tcp_data_len_ = 0;
return;
}
- if (len < 2) {
- std::cerr << "Packet too short (" << len << ")" << std::endl;
- return;
- }
+ tcp_data_ = (unsigned char *)realloc(tcp_data_, tcp_data_len_ + len);
+ memcpy(tcp_data_ + tcp_data_len_, buffer, len);
+ tcp_data_len_ += len;
+
/* TCP might aggregate the various requests into a single packet, so we
* need to split */
- while (len) {
- int tcplen = (data[0] << 8) + data[1];
- data += 2;
- len -= 2;
- if (tcplen > len) {
- std::cerr << "Warning: TCP length " << tcplen
- << " doesn't match remaining data length " << len << std::endl;
+ while (tcp_data_len_ > 2) {
+ size_t tcplen = (tcp_data_[0] << 8) + tcp_data_[1];
+ if (tcp_data_len_ - 2 < tcplen)
+ break;
+
+ ProcessPacket(fd, &addr, addrlen, tcp_data_ + 2, tcplen);
+
+ /* strip off processed data if connection not terminated */
+ if (tcp_data_ != NULL) {
+ memmove(tcp_data_, tcp_data_ + tcplen + 2, tcp_data_len_ - 2 - tcplen);
+ tcp_data_len_ -= 2 + tcplen;
}
- int process_len = (tcplen > len)?len:tcplen;
- ProcessPacket(fd, &addr, addrlen, data, process_len);
- len -= process_len;
- data += process_len;
}
} else {
/* UDP is always a single packet */
- ProcessPacket(fd, &addr, addrlen, data, len);
+ ProcessPacket(fd, &addr, addrlen, buffer, len);
}
}
diff --git a/contrib/libs/c-ares/test/ares-test.h b/contrib/libs/c-ares/test/ares-test.h
index da825eacfc..877a8e6cc2 100644
--- a/contrib/libs/c-ares/test/ares-test.h
+++ b/contrib/libs/c-ares/test/ares-test.h
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) The c-ares project
+ *
+ * Permission to use, copy, modify, and distribute this
+ * software and its documentation for any purpose and without
+ * fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting
+ * documentation, and that the name of M.I.T. not be used in
+ * advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * SPDX-License-Identifier: MIT
+ */
// -*- mode: c++ -*-
#ifndef ARES_TEST_H
#define ARES_TEST_H
@@ -145,6 +162,15 @@ class MockServer {
void SetReplyData(const std::vector<byte>& reply) { reply_ = reply; }
void SetReply(const DNSPacket* reply) { SetReplyData(reply->data()); }
void SetReplyQID(int qid) { qid_ = qid; }
+ void Disconnect() {
+ for (int fd : connfds_) {
+ sclose(fd);
+ }
+ connfds_.clear();
+ free(tcp_data_);
+ tcp_data_ = NULL;
+ tcp_data_len_ = 0;
+ }
// The set of file descriptors that the server handles.
std::set<int> fds() const;
@@ -168,6 +194,8 @@ class MockServer {
std::set<int> connfds_;
std::vector<byte> reply_;
int qid_;
+ unsigned char *tcp_data_;
+ size_t tcp_data_len_;
};
// Test fixture that uses a mock DNS server.
@@ -230,6 +258,10 @@ ACTION_P2(SetReplyQID, mockserver, qid) {
ACTION_P2(CancelChannel, mockserver, channel) {
ares_cancel(channel);
}
+// gMock action to disconnect all connections.
+ACTION_P2(Disconnect, mockserver) {
+ mockserver->Disconnect();
+}
// C++ wrapper for struct hostent.
struct HostEnt {
diff --git a/contrib/libs/c-ares/test/config.h b/contrib/libs/c-ares/test/config.h
index 8943509c56..fb69cd17c3 100644
--- a/contrib/libs/c-ares/test/config.h
+++ b/contrib/libs/c-ares/test/config.h
@@ -1,3 +1,7 @@
+/* Copyright (C) The c-ares project and its contributors
+ * SPDX-License-Identifier: MIT
+ */
+
/* Generated from ares_config.h.cmake */
/* Define if building universal (internal helper macro) */
@@ -123,6 +127,9 @@
/* Define to 1 if you have the getnameinfo function. */
#define HAVE_GETNAMEINFO
+/* Define to 1 if you have the getrandom function. */
+#define HAVE_GETRANDOM
+
/* Define to 1 if you have the getservbyport_r function. */
#define HAVE_GETSERVBYPORT_R
diff --git a/contrib/libs/c-ares/test/dns-proto-test.cc b/contrib/libs/c-ares/test/dns-proto-test.cc
index 3dadeeee1c..6fa3093ea1 100644
--- a/contrib/libs/c-ares/test/dns-proto-test.cc
+++ b/contrib/libs/c-ares/test/dns-proto-test.cc
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) The c-ares project
+ *
+ * Permission to use, copy, modify, and distribute this
+ * software and its documentation for any purpose and without
+ * fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting
+ * documentation, and that the name of M.I.T. not be used in
+ * advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * SPDX-License-Identifier: MIT
+ */
#include "ares-test.h"
#include "dns-proto.h"
diff --git a/contrib/libs/c-ares/test/dns-proto.cc b/contrib/libs/c-ares/test/dns-proto.cc
index e827810df9..a4eb0be382 100644
--- a/contrib/libs/c-ares/test/dns-proto.cc
+++ b/contrib/libs/c-ares/test/dns-proto.cc
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) The c-ares project
+ *
+ * Permission to use, copy, modify, and distribute this
+ * software and its documentation for any purpose and without
+ * fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting
+ * documentation, and that the name of M.I.T. not be used in
+ * advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * SPDX-License-Identifier: MIT
+ */
// Include ares internal file for DNS protocol details
#include "ares_setup.h"
@@ -16,7 +33,7 @@ std::string HexDump(std::vector<byte> data) {
std::stringstream ss;
for (size_t ii = 0; ii < data.size(); ii++) {
char buffer[2 + 1];
- sprintf(buffer, "%02x", data[ii]);
+ snprintf(buffer, sizeof(buffer), "%02x", data[ii]);
ss << buffer;
}
return ss.str();
@@ -159,17 +176,17 @@ std::string AddressToString(const void* vaddr, int len) {
std::stringstream ss;
if (len == 4) {
char buffer[4*4 + 3 + 1];
- sprintf(buffer, "%u.%u.%u.%u",
- (unsigned char)addr[0],
- (unsigned char)addr[1],
- (unsigned char)addr[2],
- (unsigned char)addr[3]);
+ snprintf(buffer, sizeof(buffer), "%u.%u.%u.%u",
+ (unsigned char)addr[0],
+ (unsigned char)addr[1],
+ (unsigned char)addr[2],
+ (unsigned char)addr[3]);
ss << buffer;
} else if (len == 16) {
for (int ii = 0; ii < 16; ii+=2) {
if (ii > 0) ss << ':';
char buffer[4 + 1];
- sprintf(buffer, "%02x%02x", (unsigned char)addr[ii], (unsigned char)addr[ii+1]);
+ snprintf(buffer, sizeof(buffer), "%02x%02x", (unsigned char)addr[ii], (unsigned char)addr[ii+1]);
ss << buffer;
}
} else {
diff --git a/contrib/libs/c-ares/test/dns-proto.h b/contrib/libs/c-ares/test/dns-proto.h
index d8a8e57993..048a161995 100644
--- a/contrib/libs/c-ares/test/dns-proto.h
+++ b/contrib/libs/c-ares/test/dns-proto.h
@@ -1,4 +1,21 @@
// -*- mode: c++ -*-
+/*
+ * Copyright (C) The c-ares project
+ *
+ * Permission to use, copy, modify, and distribute this
+ * software and its documentation for any purpose and without
+ * fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting
+ * documentation, and that the name of M.I.T. not be used in
+ * advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * SPDX-License-Identifier: MIT
+ */
#ifndef DNS_PROTO_H
#define DNS_PROTO_H
// Utilities for processing DNS packet contents
diff --git a/contrib/libs/c-ares/test/ya.make b/contrib/libs/c-ares/test/ya.make
index e53a94d0ba..9ef6814c9f 100644
--- a/contrib/libs/c-ares/test/ya.make
+++ b/contrib/libs/c-ares/test/ya.make
@@ -2,7 +2,9 @@
GTEST(arestest)
-WITHOUT_LICENSE_TEXTS()
+LICENSE(MIT)
+
+LICENSE_TEXTS(.yandex_meta/licenses.list.txt)
SIZE(MEDIUM)
diff --git a/contrib/libs/c-ares/ya.make b/contrib/libs/c-ares/ya.make
index 2f6bb86475..8fb90c7a20 100644
--- a/contrib/libs/c-ares/ya.make
+++ b/contrib/libs/c-ares/ya.make
@@ -5,15 +5,17 @@ LIBRARY()
LICENSE(
BSD-3-Clause AND
ISC AND
+ LicenseRef-scancode-mit-no-advert-export-control AND
MIT AND
- NTP
+ NTP AND
+ Public-Domain
)
LICENSE_TEXTS(.yandex_meta/licenses.list.txt)
-VERSION(1.19.1)
+VERSION(1.20.1)
-ORIGINAL_SOURCE(https://github.com/c-ares/c-ares/archive/cares-1_19_1.tar.gz)
+ORIGINAL_SOURCE(https://github.com/c-ares/c-ares/archive/cares-1_20_1.tar.gz)
PEERDIR(
contrib/libs/libc_compat
@@ -46,11 +48,17 @@ ENDIF()
SRCS(
src/lib/ares__addrinfo2hostent.c
src/lib/ares__addrinfo_localhost.c
+ src/lib/ares__buf.c
src/lib/ares__close_sockets.c
src/lib/ares__get_hostent.c
+ src/lib/ares__htable.c
+ src/lib/ares__htable_asvp.c
+ src/lib/ares__htable_stvp.c
+ src/lib/ares__llist.c
src/lib/ares__parse_into_addrinfo.c
src/lib/ares__read_line.c
src/lib/ares__readaddrinfo.c
+ src/lib/ares__slist.c
src/lib/ares__sortaddrinfo.c
src/lib/ares__timeval.c
src/lib/ares_android.c
@@ -72,7 +80,6 @@ SRCS(
src/lib/ares_getsock.c
src/lib/ares_init.c
src/lib/ares_library_init.c
- src/lib/ares_llist.c
src/lib/ares_mkquery.c
src/lib/ares_nowarn.c
src/lib/ares_options.c
@@ -99,7 +106,6 @@ SRCS(
src/lib/ares_strsplit.c
src/lib/ares_timeout.c
src/lib/ares_version.c
- src/lib/ares_writev.c
src/lib/atomic.cpp
src/lib/bitncmp.c
src/lib/inet_net_pton.c