diff --git a/DEPENDENCIES b/DEPENDENCIES index 0a8150d0..a8472a38 100644 --- a/DEPENDENCIES +++ b/DEPENDENCIES @@ -2,5 +2,5 @@ vendorpull https://github.com/sourcemeta/vendorpull 1dcbac42809cf87cb5b045106b86 core https://github.com/sourcemeta/core 94ff49bd58ca63c5e5a7fb2435b3bc72872517c4 jsonbinpack https://github.com/sourcemeta/jsonbinpack 8fae212dc7ec02af4bb0cd4e7fccd42a2471f1c1 blaze https://github.com/sourcemeta/blaze 8dba65f8aebfe1ac976168b76e01c20dd406c517 -hydra https://github.com/sourcemeta/hydra af9f2c54709d620872ead0c3f8f683c15a0fa702 +hydra https://github.com/sourcemeta/hydra c86d2165a2f27f838837af1a5af24b1055a35317 ctrf https://github.com/ctrf-io/ctrf 93ea827d951390190171d37443bff169cf47c808 diff --git a/vendor/hydra/DEPENDENCIES b/vendor/hydra/DEPENDENCIES index d02c3036..5d7b1b9e 100644 --- a/vendor/hydra/DEPENDENCIES +++ b/vendor/hydra/DEPENDENCIES @@ -1,8 +1,8 @@ vendorpull https://github.com/sourcemeta/vendorpull 1dcbac42809cf87cb5b045106b863e17ad84ba02 mbedtls https://github.com/Mbed-TLS/mbedtls v3.6.5 zlib https://github.com/madler/zlib v1.3.1 -curl https://github.com/curl/curl curl-8_17_0 +curl https://github.com/curl/curl curl-8_18_0 nghttp2 https://github.com/nghttp2/nghttp2 v1.67.1 -cpr https://github.com/libcpr/cpr 1.13.0 +cpr https://github.com/libcpr/cpr 1.14.1 c-ares https://github.com/c-ares/c-ares v1.34.5 libpsl https://github.com/rockdaboot/libpsl 0.21.5 diff --git a/vendor/hydra/cmake/FindCPR.cmake b/vendor/hydra/cmake/FindCPR.cmake index e1302d6d..e97f1a87 100644 --- a/vendor/hydra/cmake/FindCPR.cmake +++ b/vendor/hydra/cmake/FindCPR.cmake @@ -45,6 +45,7 @@ if(NOT CPR_FOUND) "${CPR_DIR}/include/cpr/secure_string.h" "${CPR_DIR}/include/cpr/session.h" "${CPR_DIR}/include/cpr/singleton.h" + "${CPR_DIR}/include/cpr/sse.h" "${CPR_DIR}/include/cpr/ssl_ctx.h" "${CPR_DIR}/include/cpr/ssl_options.h" "${CPR_DIR}/include/cpr/status_codes.h" @@ -81,6 +82,7 @@ if(NOT CPR_FOUND) "${CPR_DIR}/cpr/redirect.cpp" "${CPR_DIR}/cpr/response.cpp" "${CPR_DIR}/cpr/session.cpp" + "${CPR_DIR}/cpr/sse.cpp" "${CPR_DIR}/cpr/ssl_ctx.cpp" "${CPR_DIR}/cpr/threadpool.cpp" "${CPR_DIR}/cpr/timeout.cpp" diff --git a/vendor/hydra/cmake/FindCURL.cmake b/vendor/hydra/cmake/FindCURL.cmake index c8d9b094..52806e55 100644 --- a/vendor/hydra/cmake/FindCURL.cmake +++ b/vendor/hydra/cmake/FindCURL.cmake @@ -37,7 +37,6 @@ if(NOT CURL_FOUND) "${CURL_DIR}/lib/pingpong.c" "${CURL_DIR}/lib/httpsrr.c" "${CURL_DIR}/lib/socks_gssapi.c" - "${CURL_DIR}/lib/memdebug.h" "${CURL_DIR}/lib/psl.c" "${CURL_DIR}/lib/progress.h" "${CURL_DIR}/lib/url.c" @@ -93,9 +92,9 @@ if(NOT CURL_FOUND) "${CURL_DIR}/lib/splay.h" "${CURL_DIR}/lib/escape.c" "${CURL_DIR}/lib/easy.c" - "${CURL_DIR}/lib/rename.c" + "${CURL_DIR}/lib/ratelimit.c" "${CURL_DIR}/lib/pop3.h" - "${CURL_DIR}/lib/share.c" + "${CURL_DIR}/lib/curl_share.c" "${CURL_DIR}/lib/slist.c" "${CURL_DIR}/lib/tftp.c" "${CURL_DIR}/lib/curl_ntlm_core.h" @@ -134,7 +133,7 @@ if(NOT CURL_FOUND) "${CURL_DIR}/lib/hostip4.c" "${CURL_DIR}/lib/cw-out.h" "${CURL_DIR}/lib/http1.c" - "${CURL_DIR}/lib/speedcheck.h" + "${CURL_DIR}/lib/ratelimit.h" "${CURL_DIR}/lib/urlapi.c" "${CURL_DIR}/lib/ftplistparser.h" "${CURL_DIR}/lib/openldap.c" @@ -163,7 +162,6 @@ if(NOT CURL_FOUND) "${CURL_DIR}/lib/multi.c" "${CURL_DIR}/lib/asyn-base.c" "${CURL_DIR}/lib/sendf.h" - "${CURL_DIR}/lib/curl_memory.h" "${CURL_DIR}/lib/cf-https-connect.h" "${CURL_DIR}/lib/formdata.h" "${CURL_DIR}/lib/urldata.h" @@ -211,8 +209,7 @@ if(NOT CURL_FOUND) "${CURL_DIR}/lib/curl_ntlm_core.c" "${CURL_DIR}/lib/tftp.h" "${CURL_DIR}/lib/slist.h" - "${CURL_DIR}/lib/share.h" - "${CURL_DIR}/lib/rename.h" + "${CURL_DIR}/lib/curl_share.h" "${CURL_DIR}/lib/pop3.c" "${CURL_DIR}/lib/arpa_telnet.h" "${CURL_DIR}/lib/noproxy.c" @@ -250,6 +247,10 @@ if(NOT CURL_FOUND) "${CURL_DIR}/lib/curlx/strparse.c" "${CURL_DIR}/lib/curlx/multibyte.h" "${CURL_DIR}/lib/curlx/nonblock.h" + "${CURL_DIR}/lib/curlx/strcopy.c" + "${CURL_DIR}/lib/curlx/strcopy.h" + "${CURL_DIR}/lib/curlx/snprintf.h" + "${CURL_DIR}/lib/curlx/binmode.h" "${CURL_DIR}/lib/setup-vms.h" "${CURL_DIR}/lib/hostip.h" "${CURL_DIR}/lib/content_encoding.h" @@ -322,7 +323,6 @@ if(NOT CURL_FOUND) "${CURL_DIR}/lib/vtls/cipher_suite.h" "${CURL_DIR}/lib/vtls/schannel_verify.c" "${CURL_DIR}/lib/vtls/x509asn1.h" - "${CURL_DIR}/lib/vtls/mbedtls_threadlock.h" "${CURL_DIR}/lib/vtls/vtls.c" "${CURL_DIR}/lib/vtls/hostcheck.h" "${CURL_DIR}/lib/vtls/gtls.h" @@ -336,16 +336,15 @@ if(NOT CURL_FOUND) "${CURL_DIR}/lib/vtls/openssl.c" "${CURL_DIR}/lib/vtls/vtls_spack.c" "${CURL_DIR}/lib/vtls/schannel.h" - "${CURL_DIR}/lib/vtls/mbedtls_threadlock.c" "${CURL_DIR}/lib/vtls/x509asn1.c" "${CURL_DIR}/lib/parsedate.h" "${CURL_DIR}/lib/curl_trc.h" "${CURL_DIR}/lib/socks.h" "${CURL_DIR}/lib/vssh/libssh.c" "${CURL_DIR}/lib/vssh/libssh2.c" - "${CURL_DIR}/lib/vssh/curl_path.h" + "${CURL_DIR}/lib/vssh/vssh.h" "${CURL_DIR}/lib/vssh/ssh.h" - "${CURL_DIR}/lib/vssh/curl_path.c" + "${CURL_DIR}/lib/vssh/vssh.c" "${CURL_DIR}/lib/asyn-ares.c" "${CURL_DIR}/lib/imap.c" "${CURL_DIR}/lib/headers.c" @@ -366,7 +365,6 @@ if(NOT CURL_FOUND) "${CURL_DIR}/lib/sigpipe.h" "${CURL_DIR}/lib/fake_addrinfo.c" "${CURL_DIR}/lib/getinfo.c" - "${CURL_DIR}/lib/speedcheck.c" "${CURL_DIR}/lib/http1.h" "${CURL_DIR}/lib/cw-out.c" "${CURL_DIR}/lib/curl_rtmp.h" @@ -375,7 +373,7 @@ if(NOT CURL_FOUND) "${CURL_DIR}/lib/select.h") if(HYDRA_COMPILER_MSVC) - target_compile_options(curl PRIVATE /W3 /MP /wd4996 /GS-) + target_compile_options(curl PRIVATE /W3 /MP /wd4996 /wd4273 /wd4311 /GS-) target_compile_definitions(curl PRIVATE _CRT_SECURE_NO_WARNINGS) target_compile_definitions(curl PUBLIC _SSIZE_T_DEFINED) if(CMAKE_SIZEOF_VOID_P EQUAL 8) @@ -423,117 +421,126 @@ if(NOT CURL_FOUND) endif() endif() - target_compile_definitions(curl PRIVATE BUILDING_LIBCURL) - target_compile_definitions(curl PRIVATE UNICODE) - target_compile_definitions(curl PRIVATE _UNICODE) - target_compile_definitions(curl PRIVATE HTTP_ONLY) - target_compile_definitions(curl PRIVATE ENABLE_IPV6) - target_compile_definitions(curl PRIVATE SIZEOF_CURL_OFF_T=8) - - if(NOT BUILD_SHARED_LIBS) - target_compile_definitions(curl PUBLIC CURL_STATICLIB) - endif() - - target_compile_definitions(curl PRIVATE HAVE_LIBZ) - target_link_libraries(curl PRIVATE ZLIB::ZLIB) - - target_compile_definitions(curl PRIVATE USE_NGHTTP2) - target_link_libraries(curl PRIVATE Nghttp2::nghttp2) - - target_compile_definitions(curl PRIVATE USE_LIBPSL) - target_link_libraries(curl PRIVATE PSL::psl) + # Common configuration variables for curl_config.h + set(USE_IPV6 ON) + set(HAVE_LIBZ ON) + set(USE_NGHTTP2 ON) + set(USE_LIBPSL ON) + set(HAVE_LONGLONG ON) + set(HAVE_RECV ON) + set(HAVE_SEND ON) + set(HAVE_SOCKET ON) + set(HAVE_SNPRINTF ON) + set(HAVE_SELECT ON) + set(HAVE_STRUCT_TIMEVAL ON) + set(HAVE_GETSOCKNAME ON) + set(SIZEOF_CURL_OFF_T_CODE "#define SIZEOF_CURL_OFF_T 8") if(WIN32) - target_compile_definitions(curl PRIVATE CURL_OS="Windows") - target_compile_definitions(curl PRIVATE USE_SCHANNEL) - target_compile_definitions(curl PRIVATE USE_WINDOWS_SSPI) - target_compile_definitions(curl PRIVATE USE_THREADS_WIN32) + set(CURL_OS "\"Windows\"") + set(USE_SCHANNEL ON) + set(USE_WINDOWS_SSPI ON) + set(USE_THREADS_WIN32 ON) + set(HAVE_GETADDRINFO ON) + set(HAVE_FREEADDRINFO ON) + set(HAVE_CLOSESOCKET ON) + set(HAVE_IOCTLSOCKET ON) + set(HAVE_IOCTLSOCKET_FIONBIO ON) + set(HAVE_WS2TCPIP_H ON) + set(HAVE_WINSOCK2_H ON) + set(HAVE_WINDOWS_H ON) + set(HAVE_FCNTL_H ON) + set(HAVE_IO_H ON) target_link_libraries(curl PRIVATE ws2_32) target_link_libraries(curl PRIVATE Crypt32) target_link_libraries(curl PRIVATE Secur32) elseif(CMAKE_SYSTEM_NAME STREQUAL "MSYS") - target_compile_definitions(curl PRIVATE CURL_OS="MSYS") - target_compile_definitions(curl PRIVATE CURL_CA_BUNDLE="/usr/ssl/certs/ca-bundle.crt") - target_compile_definitions(curl PRIVATE CURL_CA_PATH="/usr/ssl/certs") - target_compile_definitions(curl PRIVATE USE_MBEDTLS) - target_compile_definitions(curl PRIVATE USE_THREADS_POSIX) + set(CURL_OS "\"MSYS\"") + set(CURL_CA_BUNDLE "/usr/ssl/certs/ca-bundle.crt") + set(CURL_CA_PATH "/usr/ssl/certs") + set(USE_MBEDTLS ON) + set(USE_THREADS_POSIX ON) + set(HAVE_POLL ON) + set(HAVE_FCNTL_O_NONBLOCK ON) + set(HAVE_FCNTL_H ON) + set(HAVE_STDINT_H ON) + set(HAVE_NETDB_H ON) + set(HAVE_ARPA_INET_H ON) + set(HAVE_UNISTD_H ON) + set(HAVE_SYS_TYPES_H ON) + set(HAVE_SYS_SOCKET_H ON) + set(HAVE_NETINET_IN_H ON) + set(HAVE_PTHREAD_H ON) + set(HAVE_GETADDRINFO ON) + set(HAVE_GETADDRINFO_THREADSAFE ON) + set(HAVE_FREEADDRINFO ON) target_compile_definitions(curl PRIVATE _POSIX_C_SOURCE=200809L) target_compile_definitions(curl PRIVATE HAVE_SYS_TIME_H) - target_compile_definitions(curl PRIVATE HAVE_LONGLONG) - target_compile_definitions(curl PRIVATE HAVE_RECV) - target_compile_definitions(curl PRIVATE HAVE_SEND) - target_compile_definitions(curl PRIVATE HAVE_SOCKET) - target_compile_definitions(curl PRIVATE HAVE_NETDB_H) - target_compile_definitions(curl PRIVATE HAVE_ARPA_INET_H) - target_compile_definitions(curl PRIVATE HAVE_SNPRINTF) - target_compile_definitions(curl PRIVATE HAVE_UNISTD_H) target_compile_definitions(curl PRIVATE HAVE_SYS_STAT_H) - target_compile_definitions(curl PRIVATE HAVE_FCNTL_H) - target_compile_definitions(curl PRIVATE HAVE_SELECT) - target_compile_definitions(curl PRIVATE HAVE_POLL) - target_compile_definitions(curl PRIVATE HAVE_FCNTL_O_NONBLOCK) - target_compile_definitions(curl PRIVATE HAVE_STRUCT_TIMEVAL) - target_compile_definitions(curl PRIVATE HAVE_GETSOCKNAME) - target_compile_definitions(curl PRIVATE HAVE_GETADDRINFO) - target_compile_definitions(curl PRIVATE HAVE_GETADDRINFO_THREADSAFE) - target_compile_definitions(curl PRIVATE HAVE_FREEADDRINFO) - target_compile_definitions(curl PRIVATE HAVE_SYS_TYPES_H) - target_compile_definitions(curl PRIVATE HAVE_SYS_SOCKET_H) - target_compile_definitions(curl PRIVATE HAVE_NETINET_IN_H) - target_compile_definitions(curl PRIVATE HAVE_PTHREAD_H) target_link_libraries(curl PRIVATE MbedTLS::mbedtls) target_link_libraries(curl PRIVATE pthread) elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") - target_compile_definitions(curl PRIVATE CURL_OS="Linux") - target_compile_definitions(curl PRIVATE CURL_CA_BUNDLE="/etc/ssl/certs/ca-certificates.crt") - target_compile_definitions(curl PRIVATE CURL_CA_PATH="/etc/ssl/certs") - target_compile_definitions(curl PRIVATE USE_MBEDTLS) - target_compile_definitions(curl PRIVATE USE_ARES) + set(CURL_OS "\"Linux\"") + set(CURL_CA_BUNDLE "/etc/ssl/certs/ca-certificates.crt") + set(CURL_CA_PATH "/etc/ssl/certs") + set(USE_MBEDTLS ON) + set(USE_ARES ON) + set(HAVE_POLL ON) + set(HAVE_FCNTL_O_NONBLOCK ON) + set(HAVE_FCNTL_H ON) + set(HAVE_STDINT_H ON) + set(HAVE_NETDB_H ON) + set(HAVE_ARPA_INET_H ON) + set(HAVE_UNISTD_H ON) + set(HAVE_SYS_TYPES_H ON) + set(HAVE_SYS_SOCKET_H ON) + set(HAVE_NETINET_IN_H ON) + target_compile_definitions(curl PRIVATE _POSIX_C_SOURCE=200809L) target_compile_definitions(curl PRIVATE HAVE_SYS_TIME_H) - target_compile_definitions(curl PRIVATE HAVE_LONGLONG) - target_compile_definitions(curl PRIVATE HAVE_RECV) - target_compile_definitions(curl PRIVATE HAVE_SEND) - target_compile_definitions(curl PRIVATE HAVE_SOCKET) - target_compile_definitions(curl PRIVATE HAVE_NETDB_H) - target_compile_definitions(curl PRIVATE HAVE_ARPA_INET_H) - target_compile_definitions(curl PRIVATE HAVE_SNPRINTF) - target_compile_definitions(curl PRIVATE HAVE_UNISTD_H) target_compile_definitions(curl PRIVATE HAVE_SYS_STAT_H) - target_compile_definitions(curl PRIVATE HAVE_FCNTL_H) - target_compile_definitions(curl PRIVATE HAVE_SELECT) - target_compile_definitions(curl PRIVATE HAVE_POLL) - target_compile_definitions(curl PRIVATE HAVE_FCNTL_O_NONBLOCK) - target_compile_definitions(curl PRIVATE HAVE_STRUCT_TIMEVAL) - target_compile_definitions(curl PRIVATE HAVE_GETSOCKNAME) - target_compile_definitions(curl PRIVATE _POSIX_C_SOURCE=200809L) target_link_libraries(curl PRIVATE MbedTLS::mbedtls) target_link_libraries(curl PRIVATE c-ares::cares) elseif(APPLE) - target_compile_definitions(curl PRIVATE CURL_OS="Darwin") - target_compile_definitions(curl PRIVATE CURL_CA_BUNDLE="/etc/ssl/cert.pem") - target_compile_definitions(curl PRIVATE CURL_CA_PATH="/etc/ssl/certs") - target_compile_definitions(curl PRIVATE USE_MBEDTLS) - target_compile_definitions(curl PRIVATE USE_ARES) - target_compile_definitions(curl PRIVATE HAVE_RECV) - target_compile_definitions(curl PRIVATE HAVE_SEND) - target_compile_definitions(curl PRIVATE HAVE_SOCKET) - target_compile_definitions(curl PRIVATE HAVE_NETDB_H) - target_compile_definitions(curl PRIVATE HAVE_SNPRINTF) - target_compile_definitions(curl PRIVATE HAVE_UNISTD_H) - target_compile_definitions(curl PRIVATE HAVE_SYS_STAT_H) - target_compile_definitions(curl PRIVATE HAVE_FCNTL_H) - target_compile_definitions(curl PRIVATE HAVE_SELECT) - target_compile_definitions(curl PRIVATE HAVE_POLL) - target_compile_definitions(curl PRIVATE HAVE_FCNTL_O_NONBLOCK) - target_compile_definitions(curl PRIVATE HAVE_STRUCT_TIMEVAL) - target_compile_definitions(curl PRIVATE HAVE_GETSOCKNAME) + set(CURL_OS "\"Darwin\"") + set(CURL_CA_BUNDLE "/etc/ssl/cert.pem") + set(CURL_CA_PATH "/etc/ssl/certs") + set(USE_MBEDTLS ON) + set(USE_ARES ON) + set(HAVE_POLL ON) + set(HAVE_FCNTL_O_NONBLOCK ON) + set(HAVE_FCNTL_H ON) + set(HAVE_NETDB_H ON) + set(HAVE_UNISTD_H ON) + set(HAVE_SYS_TYPES_H ON) + set(HAVE_SYS_SOCKET_H ON) + set(HAVE_NETINET_IN_H ON) target_link_libraries(curl PRIVATE MbedTLS::mbedtls) target_link_libraries(curl PRIVATE c-ares::cares) target_link_libraries(curl PRIVATE "-framework Foundation") target_link_libraries(curl PRIVATE "-framework SystemConfiguration") endif() + # Generate curl_config.h from template + configure_file( + "${CURL_DIR}/lib/curl_config-cmake.h.in" + "${CMAKE_CURRENT_BINARY_DIR}/curl_config.h") + + target_compile_definitions(curl PRIVATE BUILDING_LIBCURL) + target_compile_definitions(curl PRIVATE UNICODE) + target_compile_definitions(curl PRIVATE _UNICODE) + target_compile_definitions(curl PRIVATE HTTP_ONLY) + target_compile_definitions(curl PRIVATE HAVE_CONFIG_H) + + if(NOT BUILD_SHARED_LIBS) + target_compile_definitions(curl PUBLIC CURL_STATICLIB) + endif() + + target_link_libraries(curl PRIVATE ZLIB::ZLIB) + target_link_libraries(curl PRIVATE Nghttp2::nghttp2) + target_link_libraries(curl PRIVATE PSL::psl) + target_include_directories(curl PRIVATE "${CURL_DIR}/lib") + target_include_directories(curl PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") target_include_directories(curl PUBLIC "$" "$") diff --git a/vendor/hydra/vendor/cpr/cpr/session.cpp b/vendor/hydra/vendor/cpr/cpr/session.cpp index 8c93c56c..a62c8dd5 100644 --- a/vendor/hydra/vendor/cpr/cpr/session.cpp +++ b/vendor/hydra/vendor/cpr/cpr/session.cpp @@ -233,7 +233,7 @@ void Session::prepareCommon() { // Set Content: prepareBodyPayloadOrMultipart(); - if (!cbs_->writecb_.callback) { + if (!cbs_->writecb_.callback && !cbs_->ssecb_.callback) { curl_easy_setopt(curl_->handle, CURLOPT_WRITEFUNCTION, cpr::util::writeFunction); curl_easy_setopt(curl_->handle, CURLOPT_WRITEDATA, &response_string_); } @@ -322,6 +322,12 @@ void Session::SetWriteCallback(const WriteCallback& write) { curl_easy_setopt(curl_->handle, CURLOPT_WRITEDATA, &cbs_->writecb_); } +void Session::SetServerSentEventCallback(const ServerSentEventCallback& sse) { + curl_easy_setopt(curl_->handle, CURLOPT_WRITEFUNCTION, cpr::util::writeSSEFunction); + cbs_->ssecb_ = sse; + curl_easy_setopt(curl_->handle, CURLOPT_WRITEDATA, &cbs_->ssecb_); +} + void Session::SetProgressCallback(const ProgressCallback& progress) { cbs_->progresscb_ = progress; if (isCancellable) { @@ -529,7 +535,7 @@ void Session::SetSslOptions(const SslOptions& options) { } } #if SUPPORT_CURLOPT_SSLCERT_BLOB - else if(!options.cert_blob.empty()) { + else if (!options.cert_blob.empty()) { std::string cert_blob(options.cert_blob); curl_blob blob{}; // NOLINTNEXTLINE (readability-container-data-pointer) @@ -1079,6 +1085,7 @@ void Session::SetOption(const HeaderCallback& header) { SetHeaderCallback(header void Session::SetOption(const WriteCallback& write) { SetWriteCallback(write); } void Session::SetOption(const ProgressCallback& progress) { SetProgressCallback(progress); } void Session::SetOption(const DebugCallback& debug) { SetDebugCallback(debug); } +void Session::SetOption(const ServerSentEventCallback& sse) { SetServerSentEventCallback(sse); } void Session::SetOption(const Url& url) { SetUrl(url); } void Session::SetOption(const Parameters& parameters) { SetParameters(parameters); } void Session::SetOption(Parameters&& parameters) { SetParameters(std::move(parameters)); } diff --git a/vendor/hydra/vendor/cpr/cpr/sse.cpp b/vendor/hydra/vendor/cpr/cpr/sse.cpp new file mode 100644 index 00000000..05ab06fe --- /dev/null +++ b/vendor/hydra/vendor/cpr/cpr/sse.cpp @@ -0,0 +1,122 @@ +#include "cpr/sse.h" + +#include +#include +#include +#include +#include +#include +#include + +namespace cpr { + +bool ServerSentEventParser::parse(std::string_view data, const std::function& callback) { + // Append incoming data to buffer + buffer_.append(data); + + // Process complete lines + size_t pos = 0; + while ((pos = buffer_.find('\n')) != std::string::npos) { + std::string line = buffer_.substr(0, pos); + buffer_.erase(0, pos + 1); + + // Remove trailing \r if present (handles both \n and \r\n) + if (!line.empty() && line.back() == '\r') { + line.pop_back(); + } + + if (!processLine(line, callback)) { + return false; + } + } + + return true; +} + +void ServerSentEventParser::reset() { + buffer_.clear(); + current_event_ = ServerSentEvent(); +} + +bool ServerSentEventParser::processLine(const std::string& line, const std::function& callback) { + // Empty line means end of event + if (line.empty()) { + return dispatchEvent(callback); + } + + // Lines starting with ':' are comments, ignore them + if (line[0] == ':') { + return true; + } + + // Find the colon separator + const size_t colon_pos = line.find(':'); + + std::string field; + std::string value; + + if (colon_pos == std::string::npos) { + // No colon, entire line is the field name + field = line; + value = ""; + } else { + field = line.substr(0, colon_pos); + // Skip the colon and optional leading space + size_t value_start = colon_pos + 1; + if (value_start < line.size() && line[value_start] == ' ') { + value_start++; + } + value = line.substr(value_start); + } + + // Process the field + if (field == "event") { + current_event_.event = value; + } else if (field == "data") { + // Multiple data fields are concatenated with newlines + if (!current_event_.data.empty()) { + current_event_.data += '\n'; + } + current_event_.data += value; + } else if (field == "id") { + // Only set id if the value doesn't contain null character + if (value.find('\0') == std::string::npos) { + current_event_.id = value; + } + } else if (field == "retry") { + // Parse retry value as integer + size_t retry_value = 0; + const std::string_view sv(value); + const char* begin = sv.data(); + const char* end = begin + sv.size(); // NOLINT (cppcoreguidelines-pro-bounds-pointer-arithmetic) Required here since Windows and Clang/GCC have different std::string_view iterator implementations + auto [ptr, ec] = std::from_chars(begin, end, retry_value); + if (ec == std::errc()) { + current_event_.retry = retry_value; + } + } + // Unknown fields are ignored per spec + + return true; +} + +bool ServerSentEventParser::dispatchEvent(const std::function& callback) { + // Don't dispatch if data is empty + if (current_event_.data.empty()) { + current_event_ = ServerSentEvent(); + return true; + } + + // Invoke callback with the current event + const bool continue_parsing = callback(std::move(current_event_)); + + // Reset for next event (but keep event type as "message") + current_event_ = ServerSentEvent(); + + return continue_parsing; +} + +bool ServerSentEventCallback::handleData(std::string_view data) { + return parser_.parse(data, [this](ServerSentEvent&& event) { return (*this)(std::move(event)); }); +} + +} // namespace cpr diff --git a/vendor/hydra/vendor/cpr/cpr/util.cpp b/vendor/hydra/vendor/cpr/cpr/util.cpp index c622450e..8bf5426a 100644 --- a/vendor/hydra/vendor/cpr/cpr/util.cpp +++ b/vendor/hydra/vendor/cpr/cpr/util.cpp @@ -4,6 +4,7 @@ #include "cpr/cprtypes.h" #include "cpr/curlholder.h" #include "cpr/secure_string.h" +#include "cpr/sse.h" #include #include #include @@ -152,6 +153,11 @@ size_t writeUserFunction(char* ptr, size_t size, size_t nmemb, const WriteCallba return (*write)({ptr, size}) ? size : 0; } +size_t writeSSEFunction(char* ptr, size_t size, size_t nmemb, ServerSentEventCallback* sse) { + size *= nmemb; + return sse->handleData({ptr, size}) ? size : 0; +} + int debugUserFunction(CURL* /*handle*/, curl_infotype type, char* data, size_t size, const DebugCallback* debug) { (*debug)(static_cast(type), std::string(data, size)); return 0; diff --git a/vendor/hydra/vendor/cpr/include/cpr/cpr.h b/vendor/hydra/vendor/cpr/include/cpr/cpr.h index 5c20f7dd..a42058fb 100644 --- a/vendor/hydra/vendor/cpr/include/cpr/cpr.h +++ b/vendor/hydra/vendor/cpr/include/cpr/cpr.h @@ -33,6 +33,7 @@ #include "cpr/resolve.h" #include "cpr/response.h" #include "cpr/session.h" +#include "cpr/sse.h" #include "cpr/ssl_ctx.h" #include "cpr/ssl_options.h" #include "cpr/status_codes.h" diff --git a/vendor/hydra/vendor/cpr/include/cpr/error.h b/vendor/hydra/vendor/cpr/include/cpr/error.h index 6f598f16..0548ba9e 100644 --- a/vendor/hydra/vendor/cpr/include/cpr/error.h +++ b/vendor/hydra/vendor/cpr/include/cpr/error.h @@ -1,9 +1,9 @@ #ifndef CPR_ERROR_H #define CPR_ERROR_H -#include #include #include +#include #include "cpr/cprtypes.h" #include @@ -90,70 +90,74 @@ enum class ErrorCode { UNKNOWN_ERROR = 1000, }; -inline const std::unordered_map error_code_to_string_mapping = {{ErrorCode::OK, "OK"}, - {ErrorCode::UNSUPPORTED_PROTOCOL, "UNSUPPORTED_PROTOCOL"}, - {ErrorCode::FAILED_INIT, "FAILED_INIT"}, - {ErrorCode::URL_MALFORMAT, "URL_MALFORMAT"}, - {ErrorCode::NOT_BUILT_IN, "NOT_BUILT_IN"}, - {ErrorCode::COULDNT_RESOLVE_PROXY, "COULDNT_RESOLVE_PROXY"}, - {ErrorCode::COULDNT_RESOLVE_HOST, "COULDNT_RESOLVE_HOST"}, - {ErrorCode::COULDNT_CONNECT, "COULDNT_CONNECT"}, - {ErrorCode::WEIRD_SERVER_REPLY, "WEIRD_SERVER_REPLY"}, - {ErrorCode::REMOTE_ACCESS_DENIED, "REMOTE_ACCESS_DENIED"}, - {ErrorCode::HTTP2, "HTTP2"}, - {ErrorCode::PARTIAL_FILE, "PARTIAL_FILE"}, - {ErrorCode::QUOTE_ERROR, "QUOTE_ERROR"}, - {ErrorCode::HTTP_RETURNED_ERROR, "HTTP_RETURNED_ERROR"}, - {ErrorCode::WRITE_ERROR, "WRITE_ERROR"}, - {ErrorCode::UPLOAD_FAILED, "UPLOAD_FAILED"}, - {ErrorCode::READ_ERROR, "READ_ERROR"}, - {ErrorCode::OUT_OF_MEMORY, "OUT_OF_MEMORY"}, - {ErrorCode::OPERATION_TIMEDOUT, "OPERATION_TIMEDOUT"}, - {ErrorCode::RANGE_ERROR, "RANGE_ERROR"}, - {ErrorCode::HTTP_POST_ERROR, "HTTP_POST_ERROR"}, - {ErrorCode::SSL_CONNECT_ERROR, "SSL_CONNECT_ERROR"}, - {ErrorCode::BAD_DOWNLOAD_RESUME, "BAD_DOWNLOAD_RESUME"}, - {ErrorCode::FILE_COULDNT_READ_FILE, "FILE_COULDNT_READ_FILE"}, - {ErrorCode::FUNCTION_NOT_FOUND, "FUNCTION_NOT_FOUND"}, - {ErrorCode::ABORTED_BY_CALLBACK, "ABORTED_BY_CALLBACK"}, - {ErrorCode::BAD_FUNCTION_ARGUMENT, "BAD_FUNCTION_ARGUMENT"}, - {ErrorCode::INTERFACE_FAILED, "INTERFACE_FAILED"}, - {ErrorCode::TOO_MANY_REDIRECTS, "TOO_MANY_REDIRECTS"}, - {ErrorCode::UNKNOWN_OPTION, "UNKNOWN_OPTION"}, - {ErrorCode::SETOPT_OPTION_SYNTAX, "SETOPT_OPTION_SYNTAX"}, - {ErrorCode::GOT_NOTHING, "GOT_NOTHING"}, - {ErrorCode::SSL_ENGINE_NOTFOUND, "SSL_ENGINE_NOTFOUND"}, - {ErrorCode::SSL_ENGINE_SETFAILED, "SSL_ENGINE_SETFAILED"}, - {ErrorCode::SEND_ERROR, "SEND_ERROR"}, - {ErrorCode::RECV_ERROR, "RECV_ERROR"}, - {ErrorCode::SSL_CERTPROBLEM, "SSL_CERTPROBLEM"}, - {ErrorCode::SSL_CIPHER, "SSL_CIPHER"}, - {ErrorCode::PEER_FAILED_VERIFICATION, "PEER_FAILED_VERIFICATION"}, - {ErrorCode::BAD_CONTENT_ENCODING, "BAD_CONTENT_ENCODING"}, - {ErrorCode::FILESIZE_EXCEEDED, "FILESIZE_EXCEEDED"}, - {ErrorCode::USE_SSL_FAILED, "USE_SSL_FAILED"}, - {ErrorCode::SEND_FAIL_REWIND, "SEND_FAIL_REWIND"}, - {ErrorCode::SSL_ENGINE_INITFAILED, "SSL_ENGINE_INITFAILED"}, - {ErrorCode::LOGIN_DENIED, "LOGIN_DENIED"}, - {ErrorCode::SSL_CACERT_BADFILE, "SSL_CACERT_BADFILE"}, - {ErrorCode::SSL_SHUTDOWN_FAILED, "SSL_SHUTDOWN_FAILED"}, - {ErrorCode::AGAIN, "AGAIN"}, - {ErrorCode::SSL_CRL_BADFILE, "SSL_CRL_BADFILE"}, - {ErrorCode::SSL_ISSUER_ERROR, "SSL_ISSUER_ERROR"}, - {ErrorCode::CHUNK_FAILED, "CHUNK_FAILED"}, - {ErrorCode::NO_CONNECTION_AVAILABLE, "NO_CONNECTION_AVAILABLE"}, - {ErrorCode::SSL_PINNEDPUBKEYNOTMATCH, "SSL_PINNEDPUBKEYNOTMATCH"}, - {ErrorCode::SSL_INVALIDCERTSTATUS, "SSL_INVALIDCERTSTATUS"}, - {ErrorCode::HTTP2_STREAM, "HTTP2_STREAM"}, - {ErrorCode::RECURSIVE_API_CALL, "RECURSIVE_API_CALL"}, - {ErrorCode::AUTH_ERROR, "AUTH_ERROR"}, - {ErrorCode::HTTP3, "HTTP3"}, - {ErrorCode::QUIC_CONNECT_ERROR, "QUIC_CONNECT_ERROR"}, - {ErrorCode::PROXY, "PROXY"}, - {ErrorCode::SSL_CLIENTCERT, "SSL_CLIENTCERT"}, - {ErrorCode::UNRECOVERABLE_POLL, "UNRECOVERABLE_POLL"}, - {ErrorCode::TOO_LARGE, "TOO_LARGE"}, - {ErrorCode::UNKNOWN_ERROR, "UNKNOWN_ERROR"}}; +inline const std::unordered_map& get_error_code_to_string_mapping() { + // Use a function-local static rather than inline global objects to avoid the 'double-destructor' problem in MSVC when using /MT flags. + static const std::unordered_map mapping = {{ErrorCode::OK, "OK"}, + {ErrorCode::UNSUPPORTED_PROTOCOL, "UNSUPPORTED_PROTOCOL"}, + {ErrorCode::FAILED_INIT, "FAILED_INIT"}, + {ErrorCode::URL_MALFORMAT, "URL_MALFORMAT"}, + {ErrorCode::NOT_BUILT_IN, "NOT_BUILT_IN"}, + {ErrorCode::COULDNT_RESOLVE_PROXY, "COULDNT_RESOLVE_PROXY"}, + {ErrorCode::COULDNT_RESOLVE_HOST, "COULDNT_RESOLVE_HOST"}, + {ErrorCode::COULDNT_CONNECT, "COULDNT_CONNECT"}, + {ErrorCode::WEIRD_SERVER_REPLY, "WEIRD_SERVER_REPLY"}, + {ErrorCode::REMOTE_ACCESS_DENIED, "REMOTE_ACCESS_DENIED"}, + {ErrorCode::HTTP2, "HTTP2"}, + {ErrorCode::PARTIAL_FILE, "PARTIAL_FILE"}, + {ErrorCode::QUOTE_ERROR, "QUOTE_ERROR"}, + {ErrorCode::HTTP_RETURNED_ERROR, "HTTP_RETURNED_ERROR"}, + {ErrorCode::WRITE_ERROR, "WRITE_ERROR"}, + {ErrorCode::UPLOAD_FAILED, "UPLOAD_FAILED"}, + {ErrorCode::READ_ERROR, "READ_ERROR"}, + {ErrorCode::OUT_OF_MEMORY, "OUT_OF_MEMORY"}, + {ErrorCode::OPERATION_TIMEDOUT, "OPERATION_TIMEDOUT"}, + {ErrorCode::RANGE_ERROR, "RANGE_ERROR"}, + {ErrorCode::HTTP_POST_ERROR, "HTTP_POST_ERROR"}, + {ErrorCode::SSL_CONNECT_ERROR, "SSL_CONNECT_ERROR"}, + {ErrorCode::BAD_DOWNLOAD_RESUME, "BAD_DOWNLOAD_RESUME"}, + {ErrorCode::FILE_COULDNT_READ_FILE, "FILE_COULDNT_READ_FILE"}, + {ErrorCode::FUNCTION_NOT_FOUND, "FUNCTION_NOT_FOUND"}, + {ErrorCode::ABORTED_BY_CALLBACK, "ABORTED_BY_CALLBACK"}, + {ErrorCode::BAD_FUNCTION_ARGUMENT, "BAD_FUNCTION_ARGUMENT"}, + {ErrorCode::INTERFACE_FAILED, "INTERFACE_FAILED"}, + {ErrorCode::TOO_MANY_REDIRECTS, "TOO_MANY_REDIRECTS"}, + {ErrorCode::UNKNOWN_OPTION, "UNKNOWN_OPTION"}, + {ErrorCode::SETOPT_OPTION_SYNTAX, "SETOPT_OPTION_SYNTAX"}, + {ErrorCode::GOT_NOTHING, "GOT_NOTHING"}, + {ErrorCode::SSL_ENGINE_NOTFOUND, "SSL_ENGINE_NOTFOUND"}, + {ErrorCode::SSL_ENGINE_SETFAILED, "SSL_ENGINE_SETFAILED"}, + {ErrorCode::SEND_ERROR, "SEND_ERROR"}, + {ErrorCode::RECV_ERROR, "RECV_ERROR"}, + {ErrorCode::SSL_CERTPROBLEM, "SSL_CERTPROBLEM"}, + {ErrorCode::SSL_CIPHER, "SSL_CIPHER"}, + {ErrorCode::PEER_FAILED_VERIFICATION, "PEER_FAILED_VERIFICATION"}, + {ErrorCode::BAD_CONTENT_ENCODING, "BAD_CONTENT_ENCODING"}, + {ErrorCode::FILESIZE_EXCEEDED, "FILESIZE_EXCEEDED"}, + {ErrorCode::USE_SSL_FAILED, "USE_SSL_FAILED"}, + {ErrorCode::SEND_FAIL_REWIND, "SEND_FAIL_REWIND"}, + {ErrorCode::SSL_ENGINE_INITFAILED, "SSL_ENGINE_INITFAILED"}, + {ErrorCode::LOGIN_DENIED, "LOGIN_DENIED"}, + {ErrorCode::SSL_CACERT_BADFILE, "SSL_CACERT_BADFILE"}, + {ErrorCode::SSL_SHUTDOWN_FAILED, "SSL_SHUTDOWN_FAILED"}, + {ErrorCode::AGAIN, "AGAIN"}, + {ErrorCode::SSL_CRL_BADFILE, "SSL_CRL_BADFILE"}, + {ErrorCode::SSL_ISSUER_ERROR, "SSL_ISSUER_ERROR"}, + {ErrorCode::CHUNK_FAILED, "CHUNK_FAILED"}, + {ErrorCode::NO_CONNECTION_AVAILABLE, "NO_CONNECTION_AVAILABLE"}, + {ErrorCode::SSL_PINNEDPUBKEYNOTMATCH, "SSL_PINNEDPUBKEYNOTMATCH"}, + {ErrorCode::SSL_INVALIDCERTSTATUS, "SSL_INVALIDCERTSTATUS"}, + {ErrorCode::HTTP2_STREAM, "HTTP2_STREAM"}, + {ErrorCode::RECURSIVE_API_CALL, "RECURSIVE_API_CALL"}, + {ErrorCode::AUTH_ERROR, "AUTH_ERROR"}, + {ErrorCode::HTTP3, "HTTP3"}, + {ErrorCode::QUIC_CONNECT_ERROR, "QUIC_CONNECT_ERROR"}, + {ErrorCode::PROXY, "PROXY"}, + {ErrorCode::SSL_CLIENTCERT, "SSL_CLIENTCERT"}, + {ErrorCode::UNRECOVERABLE_POLL, "UNRECOVERABLE_POLL"}, + {ErrorCode::TOO_LARGE, "TOO_LARGE"}, + {ErrorCode::UNKNOWN_ERROR, "UNKNOWN_ERROR"}}; + return mapping; +} class Error { public: @@ -176,7 +180,7 @@ class Error { namespace std { inline std::string to_string(const cpr::ErrorCode& code) { - return cpr::error_code_to_string_mapping.at(code); + return cpr::get_error_code_to_string_mapping().at(code); } } // namespace std diff --git a/vendor/hydra/vendor/cpr/include/cpr/session.h b/vendor/hydra/vendor/cpr/include/cpr/session.h index 483b7ef2..0781559f 100644 --- a/vendor/hydra/vendor/cpr/include/cpr/session.h +++ b/vendor/hydra/vendor/cpr/include/cpr/session.h @@ -38,6 +38,7 @@ #include "cpr/reserve_size.h" #include "cpr/resolve.h" #include "cpr/response.h" +#include "cpr/sse.h" #include "cpr/ssl_options.h" #include "cpr/timeout.h" #include "cpr/unix_socket.h" @@ -103,6 +104,7 @@ class Session : public std::enable_shared_from_this { void SetWriteCallback(const WriteCallback& write); void SetProgressCallback(const ProgressCallback& progress); void SetDebugCallback(const DebugCallback& debug); + void SetServerSentEventCallback(const ServerSentEventCallback& sse); void SetVerbose(const Verbose& verbose); void SetInterface(const Interface& iface); void SetLocalPort(const LocalPort& local_port); @@ -165,6 +167,7 @@ class Session : public std::enable_shared_from_this { void SetOption(const WriteCallback& write); void SetOption(const ProgressCallback& progress); void SetOption(const DebugCallback& debug); + void SetOption(const ServerSentEventCallback& sse); void SetOption(const LowSpeed& low_speed); void SetOption(const VerifySsl& verify); void SetOption(const Verbose& verbose); @@ -276,6 +279,7 @@ class Session : public std::enable_shared_from_this { ProgressCallback progresscb_; DebugCallback debugcb_; CancellationCallback cancellationcb_; + ServerSentEventCallback ssecb_; }; std::unique_ptr cbs_{std::make_unique()}; diff --git a/vendor/hydra/vendor/cpr/include/cpr/sse.h b/vendor/hydra/vendor/cpr/include/cpr/sse.h new file mode 100644 index 00000000..2a137b36 --- /dev/null +++ b/vendor/hydra/vendor/cpr/include/cpr/sse.h @@ -0,0 +1,102 @@ +#ifndef CPR_SSE_H +#define CPR_SSE_H + +#include +#include +#include +#include +#include +#include + +namespace cpr { + +/** + * Represents a Server-Sent Event (SSE) as defined in the HTML5 specification. + * https://html.spec.whatwg.org/multipage/server-sent-events.html + */ +struct ServerSentEvent { + /** + * The event ID. Can be used to track the last received event and resume from there. + */ + std::optional id; + + /** + * The event type. If not specified, defaults to "message". + */ + std::string event{"message"}; + + /** + * The event data. Multiple data fields are concatenated with newlines. + */ + std::string data; + + /** + * The retry time in milliseconds. Used to set the reconnection time. + */ + std::optional retry; + + ServerSentEvent() = default; +}; + +/** + * Parser for Server-Sent Events (SSE) streams. + * This parser handles incoming SSE data according to the HTML5 specification. + */ +class ServerSentEventParser { + public: + ServerSentEventParser() = default; + + /** + * Parse incoming SSE data and invoke the callback for each complete event. + * @param data The incoming data chunk + * @param callback The callback to invoke for each parsed event + * @return true to continue receiving data, false to abort + */ + bool parse(std::string_view data, const std::function& callback); + + /** + * Reset the parser state. + */ + void reset(); + + private: + std::string buffer_; + ServerSentEvent current_event_; + + bool processLine(const std::string& line, const std::function& callback); + bool dispatchEvent(const std::function& callback); +}; + +/** + * Callback for handling Server-Sent Events. + * The callback receives each parsed SSE event and can return false to abort the connection. + */ +class ServerSentEventCallback { + public: + ServerSentEventCallback() = default; + // NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions) + ServerSentEventCallback(std::function p_callback, intptr_t p_userdata = 0) : userdata(p_userdata), callback(std::move(p_callback)) {} + + bool operator()(ServerSentEvent&& event) const { + if (!callback) { + return true; + } + return callback(std::move(event), userdata); + } + + /** + * Internal function used to handle raw data chunks and parse them into SSE events. + * This is called by the underlying write callback mechanism. + */ + bool handleData(std::string_view data); + + intptr_t userdata{}; + std::function callback; + + private: + ServerSentEventParser parser_; +}; + +} // namespace cpr + +#endif diff --git a/vendor/hydra/vendor/cpr/include/cpr/util.h b/vendor/hydra/vendor/cpr/include/cpr/util.h index 67a67812..4ffd02df 100644 --- a/vendor/hydra/vendor/cpr/include/cpr/util.h +++ b/vendor/hydra/vendor/cpr/include/cpr/util.h @@ -10,6 +10,7 @@ #include "cpr/cookies.h" #include "cpr/cprtypes.h" #include "cpr/secure_string.h" +#include "cpr/sse.h" namespace cpr::util { @@ -20,6 +21,7 @@ size_t headerUserFunction(char* ptr, size_t size, size_t nmemb, const HeaderCall size_t writeFunction(char* ptr, size_t size, size_t nmemb, void* data); size_t writeFileFunction(char* ptr, size_t size, size_t nmemb, std::ofstream* file); size_t writeUserFunction(char* ptr, size_t size, size_t nmemb, const WriteCallback* write); +size_t writeSSEFunction(char* ptr, size_t size, size_t nmemb, ServerSentEventCallback* sse); template int progressUserFunction(const T* progress, cpr_pf_arg_t dltotal, cpr_pf_arg_t dlnow, cpr_pf_arg_t ultotal, cpr_pf_arg_t ulnow) { diff --git a/vendor/hydra/vendor/curl/include/curl/curl.h b/vendor/hydra/vendor/curl/include/curl/curl.h index 9e07527d..e755f098 100644 --- a/vendor/hydra/vendor/curl/include/curl/curl.h +++ b/vendor/hydra/vendor/curl/include/curl/curl.h @@ -202,22 +202,22 @@ struct curl_httppost { long flags; /* as defined below */ /* specified content is a filename */ -#define CURL_HTTPPOST_FILENAME (1<<0) +#define CURL_HTTPPOST_FILENAME (1 << 0) /* specified content is a filename */ -#define CURL_HTTPPOST_READFILE (1<<1) +#define CURL_HTTPPOST_READFILE (1 << 1) /* name is only stored pointer do not free in formfree */ -#define CURL_HTTPPOST_PTRNAME (1<<2) +#define CURL_HTTPPOST_PTRNAME (1 << 2) /* contents is only stored pointer do not free in formfree */ -#define CURL_HTTPPOST_PTRCONTENTS (1<<3) +#define CURL_HTTPPOST_PTRCONTENTS (1 << 3) /* upload file from buffer */ -#define CURL_HTTPPOST_BUFFER (1<<4) +#define CURL_HTTPPOST_BUFFER (1 << 4) /* upload file from pointer contents */ -#define CURL_HTTPPOST_PTRBUFFER (1<<5) +#define CURL_HTTPPOST_PTRBUFFER (1 << 5) /* upload file contents by using the regular read callback to get the data and pass the given pointer as custom pointer */ -#define CURL_HTTPPOST_CALLBACK (1<<6) +#define CURL_HTTPPOST_CALLBACK (1 << 6) /* use size in 'contentlen', added in 7.46.0 */ -#define CURL_HTTPPOST_LARGE (1<<7) +#define CURL_HTTPPOST_LARGE (1 << 7) char *showfilename; /* The filename to show. If not set, the actual filename will be used (if this @@ -229,7 +229,6 @@ struct curl_httppost { set. Added in 7.46.0 */ }; - /* This is a return code for the progress callback that, when returned, will signal libcurl to continue executing the default progress function */ #define CURL_PROGRESSFUNC_CONTINUE 0x10000001 @@ -304,14 +303,14 @@ typedef enum { CURLFILETYPE_UNKNOWN /* should never occur */ } curlfiletype; -#define CURLFINFOFLAG_KNOWN_FILENAME (1<<0) -#define CURLFINFOFLAG_KNOWN_FILETYPE (1<<1) -#define CURLFINFOFLAG_KNOWN_TIME (1<<2) -#define CURLFINFOFLAG_KNOWN_PERM (1<<3) -#define CURLFINFOFLAG_KNOWN_UID (1<<4) -#define CURLFINFOFLAG_KNOWN_GID (1<<5) -#define CURLFINFOFLAG_KNOWN_SIZE (1<<6) -#define CURLFINFOFLAG_KNOWN_HLINKCOUNT (1<<7) +#define CURLFINFOFLAG_KNOWN_FILENAME (1 << 0) +#define CURLFINFOFLAG_KNOWN_FILETYPE (1 << 1) +#define CURLFINFOFLAG_KNOWN_TIME (1 << 2) +#define CURLFINFOFLAG_KNOWN_PERM (1 << 3) +#define CURLFINFOFLAG_KNOWN_UID (1 << 4) +#define CURLFINFOFLAG_KNOWN_GID (1 << 5) +#define CURLFINFOFLAG_KNOWN_SIZE (1 << 6) +#define CURLFINFOFLAG_KNOWN_HLINKCOUNT (1 << 7) /* Information about a single file, used when doing FTP wildcard matching */ struct curl_fileinfo { @@ -827,34 +826,34 @@ typedef enum { */ #define CURLAUTH_NONE ((unsigned long)0) -#define CURLAUTH_BASIC (((unsigned long)1)<<0) -#define CURLAUTH_DIGEST (((unsigned long)1)<<1) -#define CURLAUTH_NEGOTIATE (((unsigned long)1)<<2) +#define CURLAUTH_BASIC (((unsigned long)1) << 0) +#define CURLAUTH_DIGEST (((unsigned long)1) << 1) +#define CURLAUTH_NEGOTIATE (((unsigned long)1) << 2) /* Deprecated since the advent of CURLAUTH_NEGOTIATE */ #define CURLAUTH_GSSNEGOTIATE CURLAUTH_NEGOTIATE /* Used for CURLOPT_SOCKS5_AUTH to stay terminologically correct */ #define CURLAUTH_GSSAPI CURLAUTH_NEGOTIATE -#define CURLAUTH_NTLM (((unsigned long)1)<<3) -#define CURLAUTH_DIGEST_IE (((unsigned long)1)<<4) +#define CURLAUTH_NTLM (((unsigned long)1) << 3) +#define CURLAUTH_DIGEST_IE (((unsigned long)1) << 4) #ifndef CURL_NO_OLDIES /* functionality removed since 8.8.0 */ -#define CURLAUTH_NTLM_WB (((unsigned long)1)<<5) +#define CURLAUTH_NTLM_WB (((unsigned long)1) << 5) #endif -#define CURLAUTH_BEARER (((unsigned long)1)<<6) -#define CURLAUTH_AWS_SIGV4 (((unsigned long)1)<<7) -#define CURLAUTH_ONLY (((unsigned long)1)<<31) +#define CURLAUTH_BEARER (((unsigned long)1) << 6) +#define CURLAUTH_AWS_SIGV4 (((unsigned long)1) << 7) +#define CURLAUTH_ONLY (((unsigned long)1) << 31) #define CURLAUTH_ANY (~CURLAUTH_DIGEST_IE) -#define CURLAUTH_ANYSAFE (~(CURLAUTH_BASIC|CURLAUTH_DIGEST_IE)) - -#define CURLSSH_AUTH_ANY ~0L /* all types supported by the server */ -#define CURLSSH_AUTH_NONE 0L /* none allowed, silly but complete */ -#define CURLSSH_AUTH_PUBLICKEY (1L<<0) /* public/private key files */ -#define CURLSSH_AUTH_PASSWORD (1L<<1) /* password */ -#define CURLSSH_AUTH_HOST (1L<<2) /* host key files */ -#define CURLSSH_AUTH_KEYBOARD (1L<<3) /* keyboard interactive */ -#define CURLSSH_AUTH_AGENT (1L<<4) /* agent (ssh-agent, pageant...) */ -#define CURLSSH_AUTH_GSSAPI (1L<<5) /* gssapi (kerberos, ...) */ -#define CURLSSH_AUTH_DEFAULT CURLSSH_AUTH_ANY +#define CURLAUTH_ANYSAFE (~(CURLAUTH_BASIC | CURLAUTH_DIGEST_IE)) + +#define CURLSSH_AUTH_ANY ~0L /* all types supported by server */ +#define CURLSSH_AUTH_NONE 0L /* none allowed, silly but complete */ +#define CURLSSH_AUTH_PUBLICKEY (1L << 0) /* public/private key files */ +#define CURLSSH_AUTH_PASSWORD (1L << 1) /* password */ +#define CURLSSH_AUTH_HOST (1L << 2) /* host key files */ +#define CURLSSH_AUTH_KEYBOARD (1L << 3) /* keyboard interactive */ +#define CURLSSH_AUTH_AGENT (1L << 4) /* agent (ssh-agent, pageant...) */ +#define CURLSSH_AUTH_GSSAPI (1L << 5) /* gssapi (kerberos, ...) */ +#define CURLSSH_AUTH_DEFAULT CURLSSH_AUTH_ANY #define CURLGSSAPI_DELEGATION_NONE 0L /* no delegation (default) */ #define CURLGSSAPI_DELEGATION_POLICY_FLAG (1L<<0) /* if permitted by policy */ @@ -916,7 +915,6 @@ typedef int /* return CURLE_OK to accept */ /* or something else to refuse */ - /* parameter for the CURLOPT_USE_SSL option */ #define CURLUSESSL_NONE 0L /* do not attempt to use SSL */ #define CURLUSESSL_TRY 1L /* try using SSL, proceed anyway otherwise */ @@ -934,31 +932,31 @@ typedef enum { have introduced work-arounds for this flaw but those work-arounds sometimes make the SSL communication fail. To regain functionality with those broken servers, a user can this way allow the vulnerability back. */ -#define CURLSSLOPT_ALLOW_BEAST (1L<<0) +#define CURLSSLOPT_ALLOW_BEAST (1L << 0) /* - NO_REVOKE tells libcurl to disable certificate revocation checks for those SSL backends where such behavior is present. */ -#define CURLSSLOPT_NO_REVOKE (1L<<1) +#define CURLSSLOPT_NO_REVOKE (1L << 1) /* - NO_PARTIALCHAIN tells libcurl to *NOT* accept a partial certificate chain if possible. The OpenSSL backend has this ability. */ -#define CURLSSLOPT_NO_PARTIALCHAIN (1L<<2) +#define CURLSSLOPT_NO_PARTIALCHAIN (1L << 2) /* - REVOKE_BEST_EFFORT tells libcurl to ignore certificate revocation offline checks and ignore missing revocation list for those SSL backends where such behavior is present. */ -#define CURLSSLOPT_REVOKE_BEST_EFFORT (1L<<3) +#define CURLSSLOPT_REVOKE_BEST_EFFORT (1L << 3) /* - CURLSSLOPT_NATIVE_CA tells libcurl to use standard certificate store of operating system. Currently implemented under MS-Windows. */ -#define CURLSSLOPT_NATIVE_CA (1L<<4) +#define CURLSSLOPT_NATIVE_CA (1L << 4) /* - CURLSSLOPT_AUTO_CLIENT_CERT tells libcurl to automatically locate and use a client certificate for authentication. (Schannel) */ -#define CURLSSLOPT_AUTO_CLIENT_CERT (1L<<5) +#define CURLSSLOPT_AUTO_CLIENT_CERT (1L << 5) /* If possible, send data using TLS 1.3 early data */ -#define CURLSSLOPT_EARLYDATA (1L<<6) +#define CURLSSLOPT_EARLYDATA (1L << 6) /* The default connection attempt delay in milliseconds for happy eyeballs. CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS.3 and happy-eyeballs-timeout-ms.d document @@ -1025,20 +1023,20 @@ typedef enum { /* bitmask defines for CURLOPT_HEADEROPT */ #define CURLHEADER_UNIFIED 0L -#define CURLHEADER_SEPARATE (1L<<0) +#define CURLHEADER_SEPARATE (1L << 0) /* CURLALTSVC_* are bits for the CURLOPT_ALTSVC_CTRL option */ -#define CURLALTSVC_READONLYFILE (1L<<2) -#define CURLALTSVC_H1 (1L<<3) -#define CURLALTSVC_H2 (1L<<4) -#define CURLALTSVC_H3 (1L<<5) +#define CURLALTSVC_READONLYFILE (1L << 2) +#define CURLALTSVC_H1 (1L << 3) +#define CURLALTSVC_H2 (1L << 4) +#define CURLALTSVC_H3 (1L << 5) /* bitmask values for CURLOPT_UPLOAD_FLAGS */ -#define CURLULFLAG_ANSWERED (1L<<0) -#define CURLULFLAG_DELETED (1L<<1) -#define CURLULFLAG_DRAFT (1L<<2) -#define CURLULFLAG_FLAGGED (1L<<3) -#define CURLULFLAG_SEEN (1L<<4) +#define CURLULFLAG_ANSWERED (1L << 0) +#define CURLULFLAG_DELETED (1L << 1) +#define CURLULFLAG_DRAFT (1L << 2) +#define CURLULFLAG_FLAGGED (1L << 3) +#define CURLULFLAG_SEEN (1L << 4) struct curl_hstsentry { char *name; @@ -1067,41 +1065,41 @@ typedef CURLSTScode (*curl_hstswrite_callback)(CURL *easy, void *userp); /* CURLHSTS_* are bits for the CURLOPT_HSTS option */ -#define CURLHSTS_ENABLE (1L<<0) -#define CURLHSTS_READONLYFILE (1L<<1) +#define CURLHSTS_ENABLE (1L << 0) +#define CURLHSTS_READONLYFILE (1L << 1) /* The CURLPROTO_ defines below are for the **deprecated** CURLOPT_*PROTOCOLS options. Do not use. */ -#define CURLPROTO_HTTP (1L<<0) -#define CURLPROTO_HTTPS (1L<<1) -#define CURLPROTO_FTP (1L<<2) -#define CURLPROTO_FTPS (1L<<3) -#define CURLPROTO_SCP (1L<<4) -#define CURLPROTO_SFTP (1L<<5) -#define CURLPROTO_TELNET (1L<<6) -#define CURLPROTO_LDAP (1L<<7) -#define CURLPROTO_LDAPS (1L<<8) -#define CURLPROTO_DICT (1L<<9) -#define CURLPROTO_FILE (1L<<10) -#define CURLPROTO_TFTP (1L<<11) -#define CURLPROTO_IMAP (1L<<12) -#define CURLPROTO_IMAPS (1L<<13) -#define CURLPROTO_POP3 (1L<<14) -#define CURLPROTO_POP3S (1L<<15) -#define CURLPROTO_SMTP (1L<<16) -#define CURLPROTO_SMTPS (1L<<17) -#define CURLPROTO_RTSP (1L<<18) -#define CURLPROTO_RTMP (1L<<19) -#define CURLPROTO_RTMPT (1L<<20) -#define CURLPROTO_RTMPE (1L<<21) -#define CURLPROTO_RTMPTE (1L<<22) -#define CURLPROTO_RTMPS (1L<<23) -#define CURLPROTO_RTMPTS (1L<<24) -#define CURLPROTO_GOPHER (1L<<25) -#define CURLPROTO_SMB (1L<<26) -#define CURLPROTO_SMBS (1L<<27) -#define CURLPROTO_MQTT (1L<<28) -#define CURLPROTO_GOPHERS (1L<<29) +#define CURLPROTO_HTTP (1L << 0) +#define CURLPROTO_HTTPS (1L << 1) +#define CURLPROTO_FTP (1L << 2) +#define CURLPROTO_FTPS (1L << 3) +#define CURLPROTO_SCP (1L << 4) +#define CURLPROTO_SFTP (1L << 5) +#define CURLPROTO_TELNET (1L << 6) +#define CURLPROTO_LDAP (1L << 7) +#define CURLPROTO_LDAPS (1L << 8) +#define CURLPROTO_DICT (1L << 9) +#define CURLPROTO_FILE (1L << 10) +#define CURLPROTO_TFTP (1L << 11) +#define CURLPROTO_IMAP (1L << 12) +#define CURLPROTO_IMAPS (1L << 13) +#define CURLPROTO_POP3 (1L << 14) +#define CURLPROTO_POP3S (1L << 15) +#define CURLPROTO_SMTP (1L << 16) +#define CURLPROTO_SMTPS (1L << 17) +#define CURLPROTO_RTSP (1L << 18) +#define CURLPROTO_RTMP (1L << 19) +#define CURLPROTO_RTMPT (1L << 20) +#define CURLPROTO_RTMPE (1L << 21) +#define CURLPROTO_RTMPTE (1L << 22) +#define CURLPROTO_RTMPS (1L << 23) +#define CURLPROTO_RTMPTS (1L << 24) +#define CURLPROTO_GOPHER (1L << 25) +#define CURLPROTO_SMB (1L << 26) +#define CURLPROTO_SMBS (1L << 27) +#define CURLPROTO_MQTT (1L << 28) +#define CURLPROTO_GOPHERS (1L << 29) #define CURLPROTO_ALL (~0L) /* enable everything */ /* long may be 32 or 64 bits, but we should never depend on anything else @@ -1115,7 +1113,6 @@ typedef CURLSTScode (*curl_hstswrite_callback)(CURL *easy, /* *STRINGPOINT is an alias for OBJECTPOINT to allow tools to extract the string options from the header file */ - #define CURLOPT(na,t,nu) na = t + nu #define CURLOPTDEPRECATED(na,t,nu,v,m) na CURL_DEPRECATED(v,m) = t + nu @@ -1874,9 +1871,7 @@ typedef enum { libcurl will ask for the compressed methods it knows of, and if that is not any, it will not ask for transfer-encoding at all even if this - option is set to 1. - - */ + option is set to 1. */ CURLOPT(CURLOPT_TRANSFER_ENCODING, CURLOPTTYPE_LONG, 207), /* Callback function for closing socket (instead of close(2)). The callback @@ -2294,10 +2289,9 @@ typedef enum { #undef CURLOPT_DNS_USE_GLOBAL_CACHE /* soon obsolete */ #endif - - /* Below here follows defines for the CURLOPT_IPRESOLVE option. If a host - name resolves addresses using more than one IP protocol version, this - option might be handy to force libcurl to use a specific IP version. */ +/* Below here follows defines for the CURLOPT_IPRESOLVE option. If a host + name resolves addresses using more than one IP protocol version, this + option might be handy to force libcurl to use a specific IP version. */ #define CURL_IPRESOLVE_WHATEVER 0L /* default, uses addresses to all IP versions that your system allows */ #define CURL_IPRESOLVE_V4 1L /* uses only IPv4 addresses/connections */ @@ -2381,7 +2375,7 @@ enum CURL_NETRC_OPTION { #define CURL_SSLVERSION_MAX_TLSv1_2 (CURL_SSLVERSION_TLSv1_2 << 16) #define CURL_SSLVERSION_MAX_TLSv1_3 (CURL_SSLVERSION_TLSv1_3 << 16) - /* never use, keep last */ +/* never use, keep last */ #define CURL_SSLVERSION_MAX_LAST (CURL_SSLVERSION_LAST << 16) #define CURL_TLSAUTH_NONE 0L @@ -2403,7 +2397,7 @@ enum CURL_TLSAUTH { #define CURL_REDIR_POST_302 2L #define CURL_REDIR_POST_303 4L #define CURL_REDIR_POST_ALL \ - (CURL_REDIR_POST_301|CURL_REDIR_POST_302|CURL_REDIR_POST_303) + (CURL_REDIR_POST_301 | CURL_REDIR_POST_302 | CURL_REDIR_POST_303) #define CURL_TIMECOND_NONE 0L #define CURL_TIMECOND_IFMODSINCE 1L @@ -2418,7 +2412,7 @@ typedef enum { } curl_TimeCond; /* Special size_t value signaling a null-terminated string. */ -#define CURL_ZERO_TERMINATED ((size_t) -1) +#define CURL_ZERO_TERMINATED ((size_t)-1) /* curl_strequal() and curl_strnequal() are subject for removal in a future release */ @@ -2430,7 +2424,7 @@ typedef struct curl_mime curl_mime; /* Mime context. */ typedef struct curl_mimepart curl_mimepart; /* Mime part context. */ /* CURLMIMEOPT_ defines are for the CURLOPT_MIME_OPTIONS option. */ -#define CURLMIMEOPT_FORMESCAPE (1L<<0) /* Use backslash-escaping for forms. */ +#define CURLMIMEOPT_FORMESCAPE (1L << 0) /* Use backslash-escaping for forms */ /* * NAME curl_mime_init() @@ -2705,7 +2699,6 @@ CURL_EXTERN char *curl_easy_escape(CURL *handle, CURL_EXTERN char *curl_escape(const char *string, int length); - /* * NAME curl_easy_unescape() * @@ -2743,10 +2736,9 @@ CURL_EXTERN void curl_free(void *p); * * curl_global_init() should be invoked exactly once for each application that * uses libcurl and before any call of other libcurl functions. - + * * This function is thread-safe if CURL_VERSION_THREADSAFE is set in the * curl_version_info_data.features flag (fetch by curl_version_info()). - */ CURL_EXTERN CURLcode curl_global_init(long flags); @@ -2787,10 +2779,9 @@ CURL_EXTERN void curl_global_cleanup(void); * * curl_global_trace() can be invoked at application start to * configure which components in curl should participate in tracing. - + * * This function is thread-safe if CURL_VERSION_THREADSAFE is set in the * curl_version_info_data.features flag (fetch by curl_version_info()). - */ CURL_EXTERN CURLcode curl_global_trace(const char *config); @@ -3015,13 +3006,12 @@ typedef enum { CURLCLOSEPOLICY_LAST /* last, never use this */ } curl_closepolicy; -#define CURL_GLOBAL_SSL (1<<0) /* no purpose since 7.57.0 */ -#define CURL_GLOBAL_WIN32 (1<<1) -#define CURL_GLOBAL_ALL (CURL_GLOBAL_SSL|CURL_GLOBAL_WIN32) +#define CURL_GLOBAL_SSL (1 << 0) /* no purpose since 7.57.0 */ +#define CURL_GLOBAL_WIN32 (1 << 1) +#define CURL_GLOBAL_ALL (CURL_GLOBAL_SSL | CURL_GLOBAL_WIN32) #define CURL_GLOBAL_NOTHING 0 #define CURL_GLOBAL_DEFAULT CURL_GLOBAL_ALL -#define CURL_GLOBAL_ACK_EINTR (1<<2) - +#define CURL_GLOBAL_ACK_EINTR (1 << 2) /***************************************************************************** * Setup defines, protos etc for the sharing stuff. @@ -3060,7 +3050,6 @@ typedef void (*curl_unlock_function)(CURL *handle, curl_lock_data data, void *userptr); - typedef enum { CURLSHE_OK, /* all is fine */ CURLSHE_BAD_OPTION, /* 1 */ @@ -3258,14 +3247,14 @@ CURL_EXTERN const char *curl_share_strerror(CURLSHcode); */ CURL_EXTERN CURLcode curl_easy_pause(CURL *handle, int bitmask); -#define CURLPAUSE_RECV (1<<0) +#define CURLPAUSE_RECV (1 << 0) #define CURLPAUSE_RECV_CONT (0) -#define CURLPAUSE_SEND (1<<2) +#define CURLPAUSE_SEND (1 << 2) #define CURLPAUSE_SEND_CONT (0) -#define CURLPAUSE_ALL (CURLPAUSE_RECV|CURLPAUSE_SEND) -#define CURLPAUSE_CONT (CURLPAUSE_RECV_CONT|CURLPAUSE_SEND_CONT) +#define CURLPAUSE_ALL (CURLPAUSE_RECV | CURLPAUSE_SEND) +#define CURLPAUSE_CONT (CURLPAUSE_RECV_CONT | CURLPAUSE_SEND_CONT) /* * NAME curl_easy_ssls_import() @@ -3310,7 +3299,6 @@ CURL_EXTERN CURLcode curl_easy_ssls_export(CURL *handle, curl_ssls_export_cb *export_fn, void *userptr); - #ifdef __cplusplus } /* end of extern "C" */ #endif diff --git a/vendor/hydra/vendor/curl/include/curl/curlver.h b/vendor/hydra/vendor/curl/include/curl/curlver.h index 19b2bf87..2ce526ea 100644 --- a/vendor/hydra/vendor/curl/include/curl/curlver.h +++ b/vendor/hydra/vendor/curl/include/curl/curlver.h @@ -32,12 +32,12 @@ /* This is the version number of the libcurl package from which this header file origins: */ -#define LIBCURL_VERSION "8.17.0-DEV" +#define LIBCURL_VERSION "8.18.0-DEV" /* The numeric version number is also available "in parts" by using these defines: */ #define LIBCURL_VERSION_MAJOR 8 -#define LIBCURL_VERSION_MINOR 17 +#define LIBCURL_VERSION_MINOR 18 #define LIBCURL_VERSION_PATCH 0 /* This is the numeric version of the libcurl version number, meant for easier parsing and comparisons by programs. The LIBCURL_VERSION_NUM define will @@ -58,7 +58,7 @@ CURL_VERSION_BITS() macro since curl's own configure script greps for it and needs it to contain the full number. */ -#define LIBCURL_VERSION_NUM 0x081100 +#define LIBCURL_VERSION_NUM 0x081200 /* * This is the date and time when the full source package was created. The @@ -71,8 +71,8 @@ */ #define LIBCURL_TIMESTAMP "[unreleased]" -#define CURL_VERSION_BITS(x,y,z) ((x)<<16|(y)<<8|(z)) -#define CURL_AT_LEAST_VERSION(x,y,z) \ +#define CURL_VERSION_BITS(x, y, z) ((x) << 16 | (y) << 8 | (z)) +#define CURL_AT_LEAST_VERSION(x, y, z) \ (LIBCURL_VERSION_NUM >= CURL_VERSION_BITS(x, y, z)) #endif /* CURLINC_CURLVER_H */ diff --git a/vendor/hydra/vendor/curl/include/curl/easy.h b/vendor/hydra/vendor/curl/include/curl/easy.h index fa135649..5b3cdbd6 100644 --- a/vendor/hydra/vendor/curl/include/curl/easy.h +++ b/vendor/hydra/vendor/curl/include/curl/easy.h @@ -50,7 +50,7 @@ CURL_EXTERN void curl_easy_cleanup(CURL *curl); * * Request internal information from the curl session with this function. * The third argument MUST be pointing to the specific type of the used option - * which is documented in each manpage of the option. The data pointed to + * which is documented in each man page of the option. The data pointed to * will be filled in accordingly and can be relied upon only if the function * returns CURLE_OK. This function is intended to get used *AFTER* a performed * transfer, all results from this function are undefined until the transfer @@ -58,7 +58,6 @@ CURL_EXTERN void curl_easy_cleanup(CURL *curl); */ CURL_EXTERN CURLcode curl_easy_getinfo(CURL *curl, CURLINFO info, ...); - /* * NAME curl_easy_duphandle() * @@ -67,7 +66,7 @@ CURL_EXTERN CURLcode curl_easy_getinfo(CURL *curl, CURLINFO info, ...); * Creates a new curl session handle with the same options set for the handle * passed in. Duplicating a handle could only be a matter of cloning data and * options, internal state info and things like persistent connections cannot - * be transferred. It is useful in multithreaded applications when you can run + * be transferred. It is useful in multi-threaded applications when you can run * curl_easy_duphandle() for each new thread to avoid a series of identical * curl_easy_setopt() invokes in every thread. */ @@ -108,7 +107,6 @@ CURL_EXTERN CURLcode curl_easy_recv(CURL *curl, void *buffer, size_t buflen, CURL_EXTERN CURLcode curl_easy_send(CURL *curl, const void *buffer, size_t buflen, size_t *n); - /* * NAME curl_easy_upkeep() * diff --git a/vendor/hydra/vendor/curl/include/curl/header.h b/vendor/hydra/vendor/curl/include/curl/header.h index 7465274b..e7334b5a 100644 --- a/vendor/hydra/vendor/curl/include/curl/header.h +++ b/vendor/hydra/vendor/curl/include/curl/header.h @@ -38,11 +38,11 @@ struct curl_header { }; /* 'origin' bits */ -#define CURLH_HEADER (1<<0) /* plain server header */ -#define CURLH_TRAILER (1<<1) /* trailers */ -#define CURLH_CONNECT (1<<2) /* CONNECT headers */ -#define CURLH_1XX (1<<3) /* 1xx headers */ -#define CURLH_PSEUDO (1<<4) /* pseudo headers */ +#define CURLH_HEADER (1 << 0) /* plain server header */ +#define CURLH_TRAILER (1 << 1) /* trailers */ +#define CURLH_CONNECT (1 << 2) /* CONNECT headers */ +#define CURLH_1XX (1 << 3) /* 1xx headers */ +#define CURLH_PSEUDO (1 << 4) /* pseudo headers */ typedef enum { CURLHE_OK, diff --git a/vendor/hydra/vendor/curl/include/curl/multi.h b/vendor/hydra/vendor/curl/include/curl/multi.h index 4e30637e..531c1a95 100644 --- a/vendor/hydra/vendor/curl/include/curl/multi.h +++ b/vendor/hydra/vendor/curl/include/curl/multi.h @@ -136,25 +136,25 @@ CURL_EXTERN CURLM *curl_multi_init(void); CURL_EXTERN CURLMcode curl_multi_add_handle(CURLM *multi_handle, CURL *curl_handle); - /* - * Name: curl_multi_remove_handle() - * - * Desc: removes a curl handle from the multi stack again - * - * Returns: CURLMcode type, general multi error code. - */ +/* + * Name: curl_multi_remove_handle() + * + * Desc: removes a curl handle from the multi stack again + * + * Returns: CURLMcode type, general multi error code. + */ CURL_EXTERN CURLMcode curl_multi_remove_handle(CURLM *multi_handle, CURL *curl_handle); - /* - * Name: curl_multi_fdset() - * - * Desc: Ask curl for its fd_set sets. The app can use these to select() or - * poll() on. We want curl_multi_perform() called as soon as one of - * them are ready. - * - * Returns: CURLMcode type, general multi error code. - */ +/* + * Name: curl_multi_fdset() + * + * Desc: Ask curl for its fd_set sets. The app can use these to select() or + * poll() on. We want curl_multi_perform() called as soon as one of + * them are ready. + * + * Returns: CURLMcode type, general multi error code. + */ CURL_EXTERN CURLMcode curl_multi_fdset(CURLM *multi_handle, fd_set *read_fd_set, fd_set *write_fd_set, @@ -198,35 +198,35 @@ CURL_EXTERN CURLMcode curl_multi_poll(CURLM *multi_handle, */ CURL_EXTERN CURLMcode curl_multi_wakeup(CURLM *multi_handle); - /* - * Name: curl_multi_perform() - * - * Desc: When the app thinks there is data available for curl it calls this - * function to read/write whatever there is right now. This returns - * as soon as the reads and writes are done. This function does not - * require that there actually is data available for reading or that - * data can be written, it can be called just in case. It returns - * the number of handles that still transfer data in the second - * argument's integer-pointer. - * - * Returns: CURLMcode type, general multi error code. *NOTE* that this only - * returns errors etc regarding the whole multi stack. There might - * still have occurred problems on individual transfers even when - * this returns OK. - */ +/* + * Name: curl_multi_perform() + * + * Desc: When the app thinks there is data available for curl it calls this + * function to read/write whatever there is right now. This returns + * as soon as the reads and writes are done. This function does not + * require that there actually is data available for reading or that + * data can be written, it can be called just in case. It returns + * the number of handles that still transfer data in the second + * argument's integer-pointer. + * + * Returns: CURLMcode type, general multi error code. *NOTE* that this only + * returns errors etc regarding the whole multi stack. There might + * still have occurred problems on individual transfers even when + * this returns OK. + */ CURL_EXTERN CURLMcode curl_multi_perform(CURLM *multi_handle, int *running_handles); - /* - * Name: curl_multi_cleanup() - * - * Desc: Cleans up and removes a whole multi stack. It does not free or - * touch any individual easy handles in any way. We need to define - * in what state those handles will be if this function is called - * in the middle of a transfer. - * - * Returns: CURLMcode type, general multi error code. - */ +/* + * Name: curl_multi_cleanup() + * + * Desc: Cleans up and removes a whole multi stack. It does not free or + * touch any individual easy handles in any way. We need to define + * in what state those handles will be if this function is called + * in the middle of a transfer. + * + * Returns: CURLMcode type, general multi error code. + */ CURL_EXTERN CURLMcode curl_multi_cleanup(CURLM *multi_handle); /* @@ -278,7 +278,7 @@ CURL_EXTERN const char *curl_multi_strerror(CURLMcode); * Desc: An alternative version of curl_multi_perform() that allows the * application to pass in one of the file descriptors that have been * detected to have "action" on them and let libcurl perform. - * See manpage for details. + * See man page for details. */ #define CURL_POLL_NONE 0 #define CURL_POLL_IN 1 @@ -327,8 +327,8 @@ curl_multi_socket_all(CURLM *multi_handle, int *running_handles); #ifndef CURL_ALLOW_OLD_MULTI_SOCKET /* This macro below was added in 7.16.3 to push users who recompile to use - the new curl_multi_socket_action() instead of the old curl_multi_socket() -*/ + * the new curl_multi_socket_action() instead of the old curl_multi_socket() + */ #define curl_multi_socket(x,y,z) curl_multi_socket_action(x,y,0,z) #endif @@ -351,10 +351,10 @@ typedef enum { /* This is the argument passed to the socket callback */ CURLOPT(CURLMOPT_SOCKETDATA, CURLOPTTYPE_OBJECTPOINT, 2), - /* set to 1 to enable pipelining for this multi handle */ + /* set to 1 to enable pipelining for this multi handle */ CURLOPT(CURLMOPT_PIPELINING, CURLOPTTYPE_LONG, 3), - /* This is the timer callback function pointer */ + /* This is the timer callback function pointer */ CURLOPT(CURLMOPT_TIMERFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 4), /* This is the argument passed to the timer callback */ @@ -412,12 +412,12 @@ typedef enum { /* - CURLMNWC_CLEAR_CONNS tells libcurl to prevent further reuse of existing connections. Connections that are idle will be closed. Ongoing transfers will continue with the connection they have. */ -#define CURLMNWC_CLEAR_CONNS (1L<<0) +#define CURLMNWC_CLEAR_CONNS (1L << 0) /* - CURLMNWC_CLEAR_DNS tells libcurl to prevent further reuse of existing connections. Connections that are idle will be closed. Ongoing transfers will continue with the connection they have. */ -#define CURLMNWC_CLEAR_DNS (1L<<0) +#define CURLMNWC_CLEAR_DNS (1L << 0) /* * Name: curl_multi_setopt() @@ -429,7 +429,6 @@ typedef enum { CURL_EXTERN CURLMcode curl_multi_setopt(CURLM *multi_handle, CURLMoption option, ...); - /* * Name: curl_multi_assign() * @@ -454,7 +453,6 @@ CURL_EXTERN CURLMcode curl_multi_assign(CURLM *multi_handle, */ CURL_EXTERN CURL **curl_multi_get_handles(CURLM *multi_handle); - typedef enum { CURLMINFO_NONE, /* first, never use this */ /* The number of easy handles currently managed by the multi handle, diff --git a/vendor/hydra/vendor/curl/include/curl/options.h b/vendor/hydra/vendor/curl/include/curl/options.h index 77cab776..835a722e 100644 --- a/vendor/hydra/vendor/curl/include/curl/options.h +++ b/vendor/hydra/vendor/curl/include/curl/options.h @@ -44,7 +44,7 @@ typedef enum { /* "alias" means it is provided for old programs to remain functional, we prefer another name */ -#define CURLOT_FLAG_ALIAS (1<<0) +#define CURLOT_FLAG_ALIAS (1 << 0) /* The CURLOPTTYPE_* id ranges can still be used to figure out what type/size to use for curl_easy_setopt() for the given id */ diff --git a/vendor/hydra/vendor/curl/include/curl/system.h b/vendor/hydra/vendor/curl/include/curl/system.h index 62ed2b0f..a5b3e9eb 100644 --- a/vendor/hydra/vendor/curl/include/curl/system.h +++ b/vendor/hydra/vendor/curl/include/curl/system.h @@ -135,21 +135,12 @@ # endif #elif defined(UNDER_CE) -# ifdef __MINGW32CE__ -# define CURL_TYPEOF_CURL_OFF_T long long -# define CURL_FORMAT_CURL_OFF_T "lld" -# define CURL_FORMAT_CURL_OFF_TU "llu" -# define CURL_SUFFIX_CURL_OFF_T LL -# define CURL_SUFFIX_CURL_OFF_TU ULL -# define CURL_TYPEOF_CURL_SOCKLEN_T int -# else -# define CURL_TYPEOF_CURL_OFF_T __int64 -# define CURL_FORMAT_CURL_OFF_T "I64d" -# define CURL_FORMAT_CURL_OFF_TU "I64u" -# define CURL_SUFFIX_CURL_OFF_T i64 -# define CURL_SUFFIX_CURL_OFF_TU ui64 -# define CURL_TYPEOF_CURL_SOCKLEN_T int -# endif +# define CURL_TYPEOF_CURL_OFF_T __int64 +# define CURL_FORMAT_CURL_OFF_T "I64d" +# define CURL_FORMAT_CURL_OFF_TU "I64u" +# define CURL_SUFFIX_CURL_OFF_T i64 +# define CURL_SUFFIX_CURL_OFF_TU ui64 +# define CURL_TYPEOF_CURL_SOCKLEN_T int #elif defined(__MINGW32__) # include diff --git a/vendor/hydra/vendor/curl/include/curl/typecheck-gcc.h b/vendor/hydra/vendor/curl/include/curl/typecheck-gcc.h index 063cea57..0642afd9 100644 --- a/vendor/hydra/vendor/curl/include/curl/typecheck-gcc.h +++ b/vendor/hydra/vendor/curl/include/curl/typecheck-gcc.h @@ -24,7 +24,7 @@ * ***************************************************************************/ -/* wraps curl_easy_setopt() with typechecking */ +/* wraps curl_easy_setopt() with type checking */ /* To add a new kind of warning, add an * if(curlcheck_sometype_option(_curl_opt)) @@ -159,7 +159,7 @@ curl_easy_setopt(handle, option, value); \ }) -/* wraps curl_easy_getinfo() with typechecking */ +/* wraps curl_easy_getinfo() with type checking */ #define curl_easy_getinfo(handle, info, arg) \ __extension__({ \ if(__builtin_constant_p(info)) { \ @@ -264,7 +264,6 @@ */ #define curl_share_setopt(share,opt,param) curl_share_setopt(share,opt,param) - /* the actual warnings, triggered by calling the Wcurl_easy_setopt_err* * functions */ @@ -590,8 +589,9 @@ CURLWARNING(Wcurl_easy_getinfo_err_curl_off_t, #define curlcheck_off_t_info(info) \ (CURLINFO_OFF_T < (info)) - -/* typecheck helpers -- check whether given expression has requested type */ +/* + * typecheck helpers -- check whether given expression has requested type + */ /* For pointers, you can use the curlcheck_ptr/curlcheck_arr macros, * otherwise define a new macro. Search for __builtin_types_compatible_p @@ -641,7 +641,6 @@ CURLWARNING(Wcurl_easy_getinfo_err_curl_off_t, (curlcheck_NULL(expr) || \ __builtin_types_compatible_p(__typeof__(expr), CURL *)) - /* evaluates to true if expr is a long (no matter the signedness) * XXX: for now, int is also accepted (and therefore short and char, which * are promoted to int when passed to a variadic function) */ diff --git a/vendor/hydra/vendor/curl/include/curl/urlapi.h b/vendor/hydra/vendor/curl/include/curl/urlapi.h index 34c11a6b..dabe44a4 100644 --- a/vendor/hydra/vendor/curl/include/curl/urlapi.h +++ b/vendor/hydra/vendor/curl/include/curl/urlapi.h @@ -81,28 +81,28 @@ typedef enum { CURLUPART_ZONEID /* added in 7.65.0 */ } CURLUPart; -#define CURLU_DEFAULT_PORT (1<<0) /* return default port number */ -#define CURLU_NO_DEFAULT_PORT (1<<1) /* act as if no port number was set, - if the port number matches the - default for the scheme */ -#define CURLU_DEFAULT_SCHEME (1<<2) /* return default scheme if - missing */ -#define CURLU_NON_SUPPORT_SCHEME (1<<3) /* allow non-supported scheme */ -#define CURLU_PATH_AS_IS (1<<4) /* leave dot sequences */ -#define CURLU_DISALLOW_USER (1<<5) /* no user+password allowed */ -#define CURLU_URLDECODE (1<<6) /* URL decode on get */ -#define CURLU_URLENCODE (1<<7) /* URL encode on set */ -#define CURLU_APPENDQUERY (1<<8) /* append a form style part */ -#define CURLU_GUESS_SCHEME (1<<9) /* legacy curl-style guessing */ -#define CURLU_NO_AUTHORITY (1<<10) /* Allow empty authority when the - scheme is unknown. */ -#define CURLU_ALLOW_SPACE (1<<11) /* Allow spaces in the URL */ -#define CURLU_PUNYCODE (1<<12) /* get the hostname in punycode */ -#define CURLU_PUNY2IDN (1<<13) /* punycode => IDN conversion */ -#define CURLU_GET_EMPTY (1<<14) /* allow empty queries and fragments - when extracting the URL or the - components */ -#define CURLU_NO_GUESS_SCHEME (1<<15) /* for get, do not accept a guess */ +#define CURLU_DEFAULT_PORT (1 << 0) /* return default port number */ +#define CURLU_NO_DEFAULT_PORT (1 << 1) /* act as if no port number was set, + if the port number matches the + default for the scheme */ +#define CURLU_DEFAULT_SCHEME (1 << 2) /* return default scheme if + missing */ +#define CURLU_NON_SUPPORT_SCHEME (1 << 3) /* allow non-supported scheme */ +#define CURLU_PATH_AS_IS (1 << 4) /* leave dot sequences */ +#define CURLU_DISALLOW_USER (1 << 5) /* no user+password allowed */ +#define CURLU_URLDECODE (1 << 6) /* URL decode on get */ +#define CURLU_URLENCODE (1 << 7) /* URL encode on set */ +#define CURLU_APPENDQUERY (1 << 8) /* append a form style part */ +#define CURLU_GUESS_SCHEME (1 << 9) /* legacy curl-style guessing */ +#define CURLU_NO_AUTHORITY (1 << 10) /* Allow empty authority when the + scheme is unknown. */ +#define CURLU_ALLOW_SPACE (1 << 11) /* Allow spaces in the URL */ +#define CURLU_PUNYCODE (1 << 12) /* get the hostname in punycode */ +#define CURLU_PUNY2IDN (1 << 13) /* punycode => IDN conversion */ +#define CURLU_GET_EMPTY (1 << 14) /* allow empty queries and fragments + when extracting the URL or the + components */ +#define CURLU_NO_GUESS_SCHEME (1 << 15) /* for get, do not accept a guess */ typedef struct Curl_URL CURLU; diff --git a/vendor/hydra/vendor/curl/include/curl/websockets.h b/vendor/hydra/vendor/curl/include/curl/websockets.h index df8590f3..402a2ca0 100644 --- a/vendor/hydra/vendor/curl/include/curl/websockets.h +++ b/vendor/hydra/vendor/curl/include/curl/websockets.h @@ -37,12 +37,12 @@ struct curl_ws_frame { }; /* flag bits */ -#define CURLWS_TEXT (1<<0) -#define CURLWS_BINARY (1<<1) -#define CURLWS_CONT (1<<2) -#define CURLWS_CLOSE (1<<3) -#define CURLWS_PING (1<<4) -#define CURLWS_OFFSET (1<<5) +#define CURLWS_TEXT (1 << 0) +#define CURLWS_BINARY (1 << 1) +#define CURLWS_CONT (1 << 2) +#define CURLWS_CLOSE (1 << 3) +#define CURLWS_PING (1 << 4) +#define CURLWS_OFFSET (1 << 5) /* * NAME curl_ws_recv() @@ -57,7 +57,7 @@ CURL_EXTERN CURLcode curl_ws_recv(CURL *curl, void *buffer, size_t buflen, const struct curl_ws_frame **metap); /* flags for curl_ws_send() */ -#define CURLWS_PONG (1<<6) +#define CURLWS_PONG (1 << 6) /* * NAME curl_ws_send() @@ -86,8 +86,8 @@ CURL_EXTERN CURLcode curl_ws_start_frame(CURL *curl, curl_off_t frame_len); /* bits for the CURLOPT_WS_OPTIONS bitmask: */ -#define CURLWS_RAW_MODE (1L<<0) -#define CURLWS_NOAUTOPONG (1L<<1) +#define CURLWS_RAW_MODE (1L << 0) +#define CURLWS_NOAUTOPONG (1L << 1) CURL_EXTERN const struct curl_ws_frame *curl_ws_meta(CURL *curl); diff --git a/vendor/hydra/vendor/curl/lib/altsvc.c b/vendor/hydra/vendor/curl/lib/altsvc.c index d9933f22..7006333b 100644 --- a/vendor/hydra/vendor/curl/lib/altsvc.c +++ b/vendor/hydra/vendor/curl/lib/altsvc.c @@ -28,25 +28,17 @@ #include "curl_setup.h" #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_ALTSVC) -#include #include "urldata.h" #include "altsvc.h" #include "curl_fopen.h" #include "curl_get_line.h" #include "parsedate.h" -#include "sendf.h" -#include "curlx/warnless.h" -#include "rename.h" -#include "strdup.h" +#include "curl_trc.h" #include "curlx/inet_pton.h" #include "curlx/strparse.h" #include "connect.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - -#define MAX_ALTSVC_LINE 4095 +#define MAX_ALTSVC_LINE 4095 #define MAX_ALTSVC_DATELEN 256 #define MAX_ALTSVC_HOSTLEN 2048 #define MAX_ALTSVC_ALPNLEN 10 @@ -68,13 +60,7 @@ const char *Curl_alpnid2str(enum alpnid id) } } - -static void altsvc_free(struct altsvc *as) -{ - free(as->src.host); - free(as->dst.host); - free(as); -} +#define altsvc_free(x) curlx_free(x) static struct altsvc *altsvc_createid(const char *srchost, size_t hlen, @@ -85,38 +71,35 @@ static struct altsvc *altsvc_createid(const char *srchost, size_t srcport, size_t dstport) { - struct altsvc *as = calloc(1, sizeof(struct altsvc)); - if(!as) - return NULL; - DEBUGASSERT(hlen); - DEBUGASSERT(dlen); - if(!hlen || !dlen) - /* bad input */ - goto error; + struct altsvc *as; if((hlen > 2) && srchost[0] == '[') { /* IPv6 address, strip off brackets */ srchost++; hlen -= 2; } - else if(srchost[hlen - 1] == '.') { + else if(hlen && (srchost[hlen - 1] == '.')) { /* strip off trailing dot */ hlen--; - if(!hlen) - goto error; } if((dlen > 2) && dsthost[0] == '[') { /* IPv6 address, strip off brackets */ dsthost++; dlen -= 2; } + if(!hlen || !dlen) + /* bad input */ + return NULL; + /* struct size plus both strings */ + as = curlx_calloc(1, sizeof(struct altsvc) + (hlen + 1) + (dlen + 1)); + if(!as) + return NULL; + as->src.host = (char *)as + sizeof(struct altsvc); + memcpy(as->src.host, srchost, hlen); + /* the null terminator is already there */ - as->src.host = Curl_memdup0(srchost, hlen); - if(!as->src.host) - goto error; - - as->dst.host = Curl_memdup0(dsthost, dlen); - if(!as->dst.host) - goto error; + as->dst.host = (char *)as + sizeof(struct altsvc) + hlen + 1; + memcpy(as->dst.host, dsthost, dlen); + /* the null terminator is already there */ as->src.alpnid = srcalpnid; as->dst.alpnid = dstalpnid; @@ -124,9 +107,6 @@ static struct altsvc *altsvc_createid(const char *srchost, as->dst.port = (unsigned short)dstport; return as; -error: - altsvc_free(as); - return NULL; } static struct altsvc *altsvc_create(struct Curl_str *srchost, @@ -136,10 +116,8 @@ static struct altsvc *altsvc_create(struct Curl_str *srchost, size_t srcport, size_t dstport) { - enum alpnid dstalpnid = - Curl_alpn2alpnid(curlx_str(dstalpn), curlx_strlen(dstalpn)); - enum alpnid srcalpnid = - Curl_alpn2alpnid(curlx_str(srcalpn), curlx_strlen(srcalpn)); + enum alpnid dstalpnid = Curl_str2alpnid(dstalpn); + enum alpnid srcalpnid = Curl_str2alpnid(srcalpn); if(!srcalpnid || !dstalpnid) return NULL; return altsvc_createid(curlx_str(srchost), curlx_strlen(srchost), @@ -201,6 +179,8 @@ static CURLcode altsvc_add(struct altsvcinfo *asi, const char *line) as->persist = persist ? 1 : 0; Curl_llist_append(&asi->list, as, &as->node); } + else + return CURLE_OUT_OF_MEMORY; } return CURLE_OK; @@ -221,8 +201,8 @@ static CURLcode altsvc_load(struct altsvcinfo *asi, const char *file) /* we need a private copy of the filename so that the altsvc cache file name survives an easy handle reset */ - free(asi->filename); - asi->filename = strdup(file); + curlx_free(asi->filename); + asi->filename = curlx_strdup(file); if(!asi->filename) return CURLE_OUT_OF_MEMORY; @@ -257,7 +237,7 @@ static CURLcode altsvc_out(struct altsvc *as, FILE *fp) const char *dst6_post = ""; const char *src6_pre = ""; const char *src6_post = ""; - CURLcode result = Curl_gmtime(as->expires, &stamp); + CURLcode result = curlx_gmtime(as->expires, &stamp); if(result) return result; #ifdef USE_IPV6 @@ -301,7 +281,7 @@ static CURLcode altsvc_out(struct altsvc *as, FILE *fp) */ struct altsvcinfo *Curl_altsvc_init(void) { - struct altsvcinfo *asi = calloc(1, sizeof(struct altsvcinfo)); + struct altsvcinfo *asi = curlx_calloc(1, sizeof(struct altsvcinfo)); if(!asi) return NULL; Curl_llist_init(&asi->list, NULL); @@ -352,8 +332,8 @@ void Curl_altsvc_cleanup(struct altsvcinfo **altsvcp) n = Curl_node_next(e); altsvc_free(as); } - free(altsvc->filename); - free(altsvc); + curlx_free(altsvc->filename); + curlx_free(altsvc); *altsvcp = NULL; /* clear the pointer */ } } @@ -395,13 +375,13 @@ CURLcode Curl_altsvc_save(struct Curl_easy *data, break; } curlx_fclose(out); - if(!result && tempstore && Curl_rename(tempstore, file)) + if(!result && tempstore && curlx_rename(tempstore, file)) result = CURLE_WRITE_ERROR; if(result && tempstore) unlink(tempstore); } - free(tempstore); + curlx_free(tempstore); return result; } @@ -479,9 +459,6 @@ CURLcode Curl_altsvc_parse(struct Curl_easy *data, unsigned short dstport = srcport; /* the same by default */ size_t entries = 0; struct Curl_str alpn; - const char *sp; - time_t maxage = 24 * 3600; /* default is 24 hours */ - bool persist = FALSE; #ifdef CURL_DISABLE_VERBOSE_STRINGS (void)data; #endif @@ -506,47 +483,12 @@ CURLcode Curl_altsvc_parse(struct Curl_easy *data, curlx_str_trimblanks(&alpn); - /* Handle the optional 'ma' and 'persist' flags once first, as they need to - be known for each alternative service. Unknown flags are skipped. */ - sp = strchr(p, ';'); - if(sp) { - sp++; /* pass the semicolon */ - for(;;) { - struct Curl_str name; - struct Curl_str val; - const char *vp; - curl_off_t num; - bool quoted; - /* allow some extra whitespaces around name and value */ - if(curlx_str_until(&sp, &name, 20, '=') || - curlx_str_single(&sp, '=') || - curlx_str_until(&sp, &val, 80, ';')) - break; - curlx_str_trimblanks(&name); - curlx_str_trimblanks(&val); - /* the value might be quoted */ - vp = curlx_str(&val); - quoted = (*vp == '\"'); - if(quoted) - vp++; - if(!curlx_str_number(&vp, &num, TIME_T_MAX)) { - if(curlx_str_casecompare(&name, "ma")) - maxage = (time_t)num; - else if(curlx_str_casecompare(&name, "persist") && (num == 1)) - persist = TRUE; - } - if(quoted && curlx_str_single(&sp, '\"')) - break; - if(curlx_str_single(&sp, ';')) - break; - } - } - do { if(!curlx_str_single(&p, '=')) { + time_t maxage = 24 * 3600; /* default is 24 hours */ + bool persist = FALSE; /* [protocol]="[host][:port], [protocol]="[host][:port]" */ - enum alpnid dstalpnid = - Curl_alpn2alpnid(curlx_str(&alpn), curlx_strlen(&alpn)); + enum alpnid dstalpnid = Curl_str2alpnid(&alpn); if(!curlx_str_single(&p, '\"')) { struct Curl_str dsthost; curl_off_t port = 0; @@ -559,7 +501,7 @@ CURLcode Curl_altsvc_parse(struct Curl_easy *data, } } else { - /* IPv6 host name */ + /* IPv6 hostname */ if(curlx_str_until(&p, &dsthost, MAX_IPADR_LEN, ']') || curlx_str_single(&p, ']')) { infof(data, "Bad alt-svc IPv6 hostname, ignoring."); @@ -583,6 +525,45 @@ CURLcode Curl_altsvc_parse(struct Curl_easy *data, if(curlx_str_single(&p, '\"')) break; + /* Handle the optional 'ma' and 'persist' flags. Unknown flags are + skipped. */ + curlx_str_passblanks(&p); + if(!curlx_str_single(&p, ';')) { + for(;;) { + struct Curl_str name; + struct Curl_str val; + const char *vp; + curl_off_t num; + bool quoted; + /* allow some extra whitespaces around name and value */ + if(curlx_str_until(&p, &name, 20, '=') || + curlx_str_single(&p, '=') || + curlx_str_cspn(&p, &val, ",;")) + break; + curlx_str_trimblanks(&name); + curlx_str_trimblanks(&val); + /* the value might be quoted */ + vp = curlx_str(&val); + quoted = (*vp == '\"'); + if(quoted) + vp++; + if(!curlx_str_number(&vp, &num, TIME_T_MAX)) { + if(curlx_str_casecompare(&name, "ma")) + maxage = (time_t)num; + else if(curlx_str_casecompare(&name, "persist") && (num == 1)) + persist = TRUE; + } + else + break; + p = vp; /* point to the byte ending the value */ + curlx_str_passblanks(&p); + if(quoted && curlx_str_single(&p, '\"')) + break; + curlx_str_passblanks(&p); + if(curlx_str_single(&p, ';')) + break; + } + } if(dstalpnid) { if(!entries++) /* Flush cached alternatives for this source origin, if any - when @@ -608,6 +589,8 @@ CURLcode Curl_altsvc_parse(struct Curl_easy *data, (int)curlx_strlen(&dsthost), curlx_str(&dsthost), dstport, Curl_alpnid2str(dstalpnid)); } + else + return CURLE_OUT_OF_MEMORY; } } else @@ -637,7 +620,8 @@ bool Curl_altsvc_lookup(struct altsvcinfo *asi, enum alpnid srcalpnid, const char *srchost, int srcport, struct altsvc **dstentry, - const int versions) /* one or more bits */ + const int versions, /* one or more bits */ + bool *psame_destination) { struct Curl_llist_node *e; struct Curl_llist_node *n; @@ -646,6 +630,7 @@ bool Curl_altsvc_lookup(struct altsvcinfo *asi, DEBUGASSERT(srchost); DEBUGASSERT(dstentry); + *psame_destination = FALSE; for(e = Curl_llist_head(&asi->list); e; e = n) { struct altsvc *as = Curl_node_elem(e); n = Curl_node_next(e); @@ -661,6 +646,8 @@ bool Curl_altsvc_lookup(struct altsvcinfo *asi, (versions & (int)as->dst.alpnid)) { /* match */ *dstentry = as; + *psame_destination = (srcport == as->dst.port) && + hostcompare(srchost, as->dst.host); return TRUE; } } diff --git a/vendor/hydra/vendor/curl/lib/altsvc.h b/vendor/hydra/vendor/curl/lib/altsvc.h index 831cd097..b82eaa8f 100644 --- a/vendor/hydra/vendor/curl/lib/altsvc.h +++ b/vendor/hydra/vendor/curl/lib/altsvc.h @@ -26,7 +26,6 @@ #include "curl_setup.h" #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_ALTSVC) -#include #include "llist.h" struct althost { @@ -65,10 +64,11 @@ bool Curl_altsvc_lookup(struct altsvcinfo *asi, enum alpnid srcalpnid, const char *srchost, int srcport, struct altsvc **dstentry, - const int versions); /* CURLALTSVC_H* bits */ + const int versions, /* CURLALTSVC_H* bits */ + bool *psame_destination); #else /* disabled */ -#define Curl_altsvc_save(a,b,c) +#define Curl_altsvc_save(a, b, c) #define Curl_altsvc_cleanup(x) #endif /* !CURL_DISABLE_HTTP && !CURL_DISABLE_ALTSVC */ #endif /* HEADER_CURL_ALTSVC_H */ diff --git a/vendor/hydra/vendor/curl/lib/amigaos.c b/vendor/hydra/vendor/curl/lib/amigaos.c index e51236d1..7ce50458 100644 --- a/vendor/hydra/vendor/curl/lib/amigaos.c +++ b/vendor/hydra/vendor/curl/lib/amigaos.c @@ -21,18 +21,15 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifdef __AMIGA__ -#include - #include "hostip.h" #include "amigaos.h" #ifdef HAVE_PROTO_BSDSOCKET_H -# if defined(__amigaos4__) +# ifdef __amigaos4__ # include # elif !defined(USE_AMISSL) # include @@ -42,10 +39,6 @@ # endif #endif -/* The last #include files should be: */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef HAVE_PROTO_BSDSOCKET_H #ifdef __amigaos4__ @@ -120,12 +113,11 @@ void Curl_amiga_cleanup(void) * Because we need to handle the different cases in hostip4.c at runtime, * not at compile-time, based on what was detected in Curl_amiga_init(), * we replace it completely with our own as to not complicate the baseline - * code. Assumes malloc/calloc/free are thread safe because Curl_he2ai() + * code. Assumes malloc/calloc/free are thread-safe because Curl_he2ai() * allocates memory also. */ -struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, - int port) +struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, int port) { struct Curl_addrinfo *ai = NULL; struct hostent *h; @@ -135,7 +127,7 @@ struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, LONG h_errnop = 0; struct hostent *buf; - buf = calloc(1, CURL_HOSTENT_SIZE); + buf = curlx_calloc(1, CURL_HOSTENT_SIZE); if(buf) { h = gethostbyname_r((STRPTR)hostname, buf, (char *)buf + sizeof(struct hostent), @@ -144,12 +136,12 @@ struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, if(h) { ai = Curl_he2ai(h, port); } - free(buf); + curlx_free(buf); } } else { - #ifdef CURLRES_THREADED - /* gethostbyname() is not thread safe, so we need to reopen bsdsocket +#ifdef CURLRES_THREADED + /* gethostbyname() is not thread-safe, so we need to reopen bsdsocket * on the thread's context */ struct Library *base = OpenLibrary("bsdsocket.library", 4); @@ -164,13 +156,13 @@ struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, } CloseLibrary(base); } - #else +#else /* not using threaded resolver - safe to use this as-is */ h = gethostbyname(hostname); if(h) { ai = Curl_he2ai(h, port); } - #endif +#endif } return ai; @@ -223,8 +215,7 @@ CURLcode Curl_amiga_init(void) } if(SocketBaseTags(SBTM_SETVAL(SBTC_ERRNOPTR(sizeof(errno))), (ULONG)&errno, - SBTM_SETVAL(SBTC_LOGTAGPTR), (ULONG)"curl", - TAG_DONE)) { + SBTM_SETVAL(SBTC_LOGTAGPTR), (ULONG)"curl", TAG_DONE)) { CURL_AMIGA_REQUEST("SocketBaseTags ERROR"); return CURLE_FAILED_INIT; } diff --git a/vendor/hydra/vendor/curl/lib/amigaos.h b/vendor/hydra/vendor/curl/lib/amigaos.h index c99d963e..58278f09 100644 --- a/vendor/hydra/vendor/curl/lib/amigaos.h +++ b/vendor/hydra/vendor/curl/lib/amigaos.h @@ -33,7 +33,7 @@ void Curl_amiga_cleanup(void); #else -#define Curl_amiga_init() CURLE_OK +#define Curl_amiga_init() CURLE_OK #define Curl_amiga_cleanup() Curl_nop_stmt #endif diff --git a/vendor/hydra/vendor/curl/lib/arpa_telnet.h b/vendor/hydra/vendor/curl/lib/arpa_telnet.h index d641a01d..daf2487f 100644 --- a/vendor/hydra/vendor/curl/lib/arpa_telnet.h +++ b/vendor/hydra/vendor/curl/lib/arpa_telnet.h @@ -43,8 +43,7 @@ /* * The telnet options represented as strings */ -static const char * const telnetoptions[]= -{ +static const char * const telnetoptions[] = { "BINARY", "ECHO", "RCP", "SUPPRESS GO AHEAD", "NAME", "STATUS", "TIMING MARK", "RCTE", "NAOL", "NAOP", "NAOCRD", "NAOHTS", @@ -79,15 +78,14 @@ static const char * const telnetoptions[]= #define CURL_WILL 251 /* Our side WILL use this option */ #define CURL_WONT 252 /* Our side will not use this option */ #define CURL_DO 253 /* DO use this option! */ -#define CURL_DONT 254 /* DON'T use this option! */ +#define CURL_DONT 254 /* DO NOT use this option! */ #define CURL_IAC 255 /* Interpret As Command */ #ifndef CURL_DISABLE_VERBOSE_STRINGS /* * Then those numbers represented as strings: */ -static const char * const telnetcmds[]= -{ +static const char * const telnetcmds[] = { "EOF", "SUSP", "ABORT", "EOR", "SE", "NOP", "DMARK", "BRK", "IP", "AO", "AYT", "EC", "EL", "GA", "SB", @@ -103,11 +101,11 @@ static const char * const telnetcmds[]= #define CURL_TELQUAL_INFO 2 #define CURL_TELQUAL_NAME 3 -#define CURL_TELCMD_OK(x) ( ((unsigned int)(x) >= CURL_TELCMD_MINIMUM) && \ - ((unsigned int)(x) <= CURL_TELCMD_MAXIMUM) ) +#define CURL_TELCMD_OK(x) (((unsigned int)(x) >= CURL_TELCMD_MINIMUM) && \ + ((unsigned int)(x) <= CURL_TELCMD_MAXIMUM)) #ifndef CURL_DISABLE_VERBOSE_STRINGS -#define CURL_TELCMD(x) telnetcmds[(x)-CURL_TELCMD_MINIMUM] +#define CURL_TELCMD(x) telnetcmds[(x) - CURL_TELCMD_MINIMUM] #else #define CURL_TELCMD(x) "" #endif diff --git a/vendor/hydra/vendor/curl/lib/asyn-ares.c b/vendor/hydra/vendor/curl/lib/asyn-ares.c index 09c94f97..7544140d 100644 --- a/vendor/hydra/vendor/curl/lib/asyn-ares.c +++ b/vendor/hydra/vendor/curl/lib/asyn-ares.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifdef CURLRES_ARES @@ -32,7 +31,6 @@ * as defined in asyn.h, nothing else belongs in this file! **********************************************************************/ -#include #ifdef HAVE_NETINET_IN_H #include #endif @@ -49,10 +47,8 @@ #include "urldata.h" #include "cfilters.h" -#include "sendf.h" +#include "curl_trc.h" #include "hostip.h" -#include "hash.h" -#include "share.h" #include "url.h" #include "multiif.h" #include "curlx/inet_pton.h" @@ -88,7 +84,7 @@ /* How long we are willing to wait for additional parallel responses after obtaining a "definitive" one. For old c-ares without getaddrinfo. - This is intended to equal the c-ares default timeout. cURL always uses that + This is intended to equal the c-ares default timeout. curl always uses that default value. Unfortunately, c-ares does not expose its default timeout in its API, but it is officially documented as 5 seconds. @@ -104,10 +100,6 @@ #define HTTPSRR_WORKS #endif -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #define CARES_TIMEOUT_PER_ATTEMPT 2000 static int ares_ver = 0; @@ -144,7 +136,6 @@ void Curl_async_global_cleanup(void) #endif } - static void sock_state_cb(void *data, ares_socket_t socket_fd, int readable, int writable) { @@ -185,8 +176,7 @@ static CURLcode async_ares_init(struct Curl_easy *data) status = ares_init_options(&ares->channel, &options, optmask); if(status != ARES_SUCCESS) { ares->channel = NULL; - rc = (status == ARES_ENOMEM) ? - CURLE_OUT_OF_MEMORY : CURLE_FAILED_INIT; + rc = (status == ARES_ENOMEM) ? CURLE_OUT_OF_MEMORY : CURLE_FAILED_INIT; goto out; } @@ -313,12 +303,13 @@ CURLcode Curl_async_is_resolved(struct Curl_easy *data, /* Now that we have checked for any last minute results above, see if there are any responses still pending when the EXPIRE_HAPPY_EYEBALLS_DNS timer expires. */ - if(ares->num_pending + if(ares->num_pending && /* This is only set to non-zero if the timer was started. */ - && (ares->happy_eyeballs_dns_time.tv_sec - || ares->happy_eyeballs_dns_time.tv_usec) - && (curlx_timediff(curlx_now(), ares->happy_eyeballs_dns_time) - >= HAPPY_EYEBALLS_DNS_TIMEOUT)) { + (ares->happy_eyeballs_dns_time.tv_sec || + ares->happy_eyeballs_dns_time.tv_usec) && + (curlx_ptimediff_ms(Curl_pgrs_now(data), + &ares->happy_eyeballs_dns_time) >= + HAPPY_EYEBALLS_DNS_TIMEOUT)) { /* Remember that the EXPIRE_HAPPY_EYEBALLS_DNS timer is no longer running. */ memset(&ares->happy_eyeballs_dns_time, 0, @@ -343,7 +334,8 @@ CURLcode Curl_async_is_resolved(struct Curl_easy *data, Curl_dnscache_mk_entry(data, ares->temp_ai, data->state.async.hostname, 0, data->state.async.port, FALSE); - ares->temp_ai = NULL; /* temp_ai now owned by entry */ + if(data->state.async.dns) + ares->temp_ai = NULL; /* temp_ai now owned by entry */ #ifdef HTTPSRR_WORKS if(data->state.async.dns) { struct Curl_https_rrinfo *lhrr = Curl_httpsrr_dup_move(&ares->hinfo); @@ -394,47 +386,46 @@ CURLcode Curl_async_await(struct Curl_easy *data, { struct async_ares_ctx *ares = &data->state.async.ares; CURLcode result = CURLE_OK; - timediff_t timeout; - struct curltime now = curlx_now(); + timediff_t timeout_ms; DEBUGASSERT(entry); *entry = NULL; /* clear on entry */ - timeout = Curl_timeleft(data, &now, TRUE); - if(timeout < 0) { + timeout_ms = Curl_timeleft_ms(data, TRUE); + if(timeout_ms < 0) { /* already expired! */ connclose(data->conn, "Timed out before name resolve started"); return CURLE_OPERATION_TIMEDOUT; } - if(!timeout) - timeout = CURL_TIMEOUT_RESOLVE * 1000; /* default name resolve timeout */ + if(!timeout_ms) + timeout_ms = CURL_TIMEOUT_RESOLVE * 1000; /* default name resolve */ /* Wait for the name resolve query to complete. */ while(!result) { - struct timeval *tvp, tv, store; - int itimeout; - timediff_t timeout_ms; + struct timeval *real_timeout, time_buf, max_timeout; + int itimeout_ms; + timediff_t call_timeout_ms; #if TIMEDIFF_T_MAX > INT_MAX - itimeout = (timeout > INT_MAX) ? INT_MAX : (int)timeout; + itimeout_ms = (timeout_ms > INT_MAX) ? INT_MAX : (int)timeout_ms; #else - itimeout = (int)timeout; + itimeout_ms = (int)timeout_ms; #endif - store.tv_sec = itimeout/1000; - store.tv_usec = (itimeout%1000)*1000; + max_timeout.tv_sec = itimeout_ms / 1000; + max_timeout.tv_usec = (itimeout_ms % 1000) * 1000; - tvp = ares_timeout(ares->channel, &store, &tv); + real_timeout = ares_timeout(ares->channel, &max_timeout, &time_buf); /* use the timeout period ares returned to us above if less than one second is left, otherwise just use 1000ms to make sure the progress callback gets called frequent enough */ - if(!tvp->tv_sec) - timeout_ms = (timediff_t)(tvp->tv_usec/1000); + if(!real_timeout->tv_sec) + call_timeout_ms = (timediff_t)(real_timeout->tv_usec / 1000); else - timeout_ms = 1000; + call_timeout_ms = 1000; - if(Curl_ares_perform(ares->channel, timeout_ms) < 0) + if(Curl_ares_perform(ares->channel, call_timeout_ms) < 0) return CURLE_UNRECOVERABLE_POLL; result = Curl_async_is_resolved(data, entry); @@ -444,17 +435,16 @@ CURLcode Curl_async_await(struct Curl_easy *data, if(Curl_pgrsUpdate(data)) result = CURLE_ABORTED_BY_CALLBACK; else { - struct curltime now2 = curlx_now(); - timediff_t timediff = curlx_timediff(now2, now); /* spent time */ - if(timediff <= 0) - timeout -= 1; /* always deduct at least 1 */ - else if(timediff > timeout) - timeout = -1; + struct curltime now = curlx_now(); /* update in loop */ + timediff_t elapsed_ms = curlx_ptimediff_ms(&now, Curl_pgrs_now(data)); + if(elapsed_ms <= 0) + timeout_ms -= 1; /* always deduct at least 1 */ + else if(elapsed_ms > timeout_ms) + timeout_ms = -1; else - timeout -= timediff; - now = now2; /* for next loop */ + timeout_ms -= elapsed_ms; } - if(timeout < 0) + if(timeout_ms < 0) result = CURLE_OPERATION_TIMEDOUT; } @@ -521,7 +511,7 @@ static void async_ares_hostbyname_cb(void *user_data, if(ARES_SUCCESS == status) { ares->ares_status = status; /* one success overrules any error */ async_addr_concat(&ares->temp_ai, - Curl_he2ai(hostent, data->state.async.port)); + Curl_he2ai(hostent, data->state.async.port)); } else if(ares->ares_status != ARES_SUCCESS) { /* no success so far, remember last error */ @@ -566,7 +556,7 @@ static void async_ares_hostbyname_cb(void *user_data, So, now that we have a usable answer (some IPv4 addresses, some IPv6 addresses, or "no such domain"), we start a timeout for the remaining pending responses. Even though it is typical that this resolved - request came back quickly, that needn't be the case. It might be that + request came back quickly, that need not be the case. It might be that this completing request did not get a result from the first DNS server or even the first round of the whole DNS server pool. So it could already be quite some time after we issued the DNS queries in @@ -588,9 +578,8 @@ static void async_ares_hostbyname_cb(void *user_data, timeout to prevent it. After all, we do not even know where in the c-ares retry cycle each request is. */ - ares->happy_eyeballs_dns_time = curlx_now(); - Curl_expire(data, HAPPY_EYEBALLS_DNS_TIMEOUT, - EXPIRE_HAPPY_EYEBALLS_DNS); + ares->happy_eyeballs_dns_time = *Curl_pgrs_now(data); + Curl_expire(data, HAPPY_EYEBALLS_DNS_TIMEOUT, EXPIRE_HAPPY_EYEBALLS_DNS); } } @@ -632,7 +621,7 @@ async_ares_node2addr(struct ares_addrinfo_node *node) if((size_t)ai->ai_addrlen < ss_size) continue; - ca = malloc(sizeof(struct Curl_addrinfo) + ss_size); + ca = curlx_malloc(sizeof(struct Curl_addrinfo) + ss_size); if(!ca) { error = EAI_MEMORY; break; @@ -718,40 +707,31 @@ static void async_ares_rr_done(void *user_data, ares_status_t status, /* * Curl_async_getaddrinfo() - when using ares * - * Returns name information about the given hostname and port number. If - * successful, the 'hostent' is returned and the fourth argument will point to - * memory we need to free after use. That memory *MUST* be freed with - * Curl_freeaddrinfo(), nothing else. + * Starts a name resolve for the given hostname and port number. */ -struct Curl_addrinfo *Curl_async_getaddrinfo(struct Curl_easy *data, - const char *hostname, - int port, - int ip_version, - int *waitp) +CURLcode Curl_async_getaddrinfo(struct Curl_easy *data, const char *hostname, + int port, int ip_version) { struct async_ares_ctx *ares = &data->state.async.ares; #ifdef USE_HTTPSRR char *rrname = NULL; #endif - *waitp = 0; /* default to synchronous response */ if(async_ares_init_lazy(data)) - return NULL; + return CURLE_FAILED_INIT; data->state.async.done = FALSE; /* not done */ data->state.async.dns = NULL; /* clear */ data->state.async.port = port; data->state.async.ip_version = ip_version; - data->state.async.hostname = strdup(hostname); + data->state.async.hostname = curlx_strdup(hostname); if(!data->state.async.hostname) - return NULL; + return CURLE_OUT_OF_MEMORY; #ifdef USE_HTTPSRR if(port != 443) { rrname = curl_maprintf("_%d_.https.%s", port, hostname); - if(!rrname) { - free(data->state.async.hostname); - return NULL; - } + if(!rrname) + return CURLE_OUT_OF_MEMORY; } #endif @@ -838,9 +818,8 @@ struct Curl_addrinfo *Curl_async_getaddrinfo(struct Curl_easy *data, async_ares_rr_done, data, NULL); } #endif - *waitp = 1; /* expect asynchronous response */ - return NULL; /* no struct yet */ + return CURLE_OK; } /* Set what DNS server are is to use. This is called in 2 situations: @@ -892,7 +871,7 @@ static CURLcode async_ares_set_dns_servers(struct Curl_easy *data, result = CURLE_BAD_FUNCTION_ARGUMENT; break; } -#else /* too old c-ares version! */ +#else /* c-ares version too old! */ (void)data; (void)(ares_result); #endif diff --git a/vendor/hydra/vendor/curl/lib/asyn-base.c b/vendor/hydra/vendor/curl/lib/asyn-base.c index eb2240b8..02797f1a 100644 --- a/vendor/hydra/vendor/curl/lib/asyn-base.c +++ b/vendor/hydra/vendor/curl/lib/asyn-base.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifdef HAVE_NETINET_IN_H @@ -40,29 +39,21 @@ #ifdef USE_ARES #include -#include /* really old c-ares did not include this by - itself */ +#include /* really old c-ares did not include it by itself */ #endif #include "urldata.h" #include "asyn.h" -#include "sendf.h" #include "hostip.h" -#include "hash.h" #include "multiif.h" #include "select.h" -#include "share.h" #include "url.h" -#include "curl_memory.h" -/* The last #include file should be: */ -#include "memdebug.h" /*********************************************************************** * Only for builds using asynchronous name resolves **********************************************************************/ #ifdef CURLRES_ASYNCH - #ifdef USE_ARES #if ARES_VERSION < 0x010600 @@ -77,8 +68,6 @@ * * Returns: sockets-in-use-bitmap */ - - CURLcode Curl_ares_pollset(struct Curl_easy *data, ares_channel channel, struct easy_pollset *ps) @@ -127,8 +116,7 @@ CURLcode Curl_ares_pollset(struct Curl_easy *data, * * return number of sockets it worked on, or -1 on error */ -int Curl_ares_perform(ares_channel channel, - timediff_t timeout_ms) +int Curl_ares_perform(ares_channel channel, timediff_t timeout_ms) { int nfds; int bitmask; @@ -147,11 +135,11 @@ int Curl_ares_perform(ares_channel channel, pfd[i].revents = 0; if(ARES_GETSOCK_READABLE(bitmask, i)) { pfd[i].fd = socks[i]; - pfd[i].events |= POLLRDNORM|POLLIN; + pfd[i].events |= POLLRDNORM | POLLIN; } if(ARES_GETSOCK_WRITABLE(bitmask, i)) { pfd[i].fd = socks[i]; - pfd[i].events |= POLLWRNORM|POLLOUT; + pfd[i].events |= POLLWRNORM | POLLOUT; } if(pfd[i].events) num++; @@ -175,15 +163,15 @@ int Curl_ares_perform(ares_channel channel, /* move through the descriptors and ask for processing on them */ for(i = 0; i < num; i++) ares_process_fd(channel, - (pfd[i].revents & (POLLRDNORM|POLLIN)) ? + (pfd[i].revents & (POLLRDNORM | POLLIN)) ? pfd[i].fd : ARES_SOCKET_BAD, - (pfd[i].revents & (POLLWRNORM|POLLOUT)) ? + (pfd[i].revents & (POLLWRNORM | POLLOUT)) ? pfd[i].fd : ARES_SOCKET_BAD); } return nfds; } -#endif +#endif /* USE_ARES */ #endif /* CURLRES_ASYNCH */ diff --git a/vendor/hydra/vendor/curl/lib/asyn-thrdd.c b/vendor/hydra/vendor/curl/lib/asyn-thrdd.c index da83cca8..690e8139 100644 --- a/vendor/hydra/vendor/curl/lib/asyn-thrdd.c +++ b/vendor/hydra/vendor/curl/lib/asyn-thrdd.c @@ -21,15 +21,15 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include "socketpair.h" /*********************************************************************** * Only for threaded name resolves builds **********************************************************************/ #ifdef CURLRES_THREADED +#include "socketpair.h" + #ifdef HAVE_NETINET_IN_H #include #endif @@ -45,24 +45,23 @@ #endif #if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H) -# include +#include #endif #ifdef HAVE_GETADDRINFO -# define RESOLVER_ENOMEM EAI_MEMORY /* = WSA_NOT_ENOUGH_MEMORY on Windows */ +#define RESOLVER_ENOMEM EAI_MEMORY /* = WSA_NOT_ENOUGH_MEMORY on Windows */ #else -# define RESOLVER_ENOMEM SOCKENOMEM +#define RESOLVER_ENOMEM SOCKENOMEM #endif #include "urldata.h" #include "cfilters.h" -#include "sendf.h" +#include "curl_trc.h" #include "hostip.h" -#include "hash.h" -#include "share.h" #include "url.h" #include "multiif.h" #include "curl_threads.h" +#include "progress.h" #include "select.h" #ifdef USE_ARES @@ -72,10 +71,6 @@ #endif #endif -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* * Curl_async_global_init() @@ -136,7 +131,7 @@ static void addr_ctx_unlink(struct async_thrdd_addr_ctx **paddr_ctx, if(destroy) { Curl_mutex_destroy(&addr_ctx->mutx); - free(addr_ctx->hostname); + curlx_free(addr_ctx->hostname); if(addr_ctx->res) Curl_freeaddrinfo(addr_ctx->res); #ifndef CURL_DISABLE_SOCKETPAIR @@ -145,7 +140,7 @@ static void addr_ctx_unlink(struct async_thrdd_addr_ctx **paddr_ctx, #endif wakeup_close(addr_ctx->sock_pair[0]); #endif - free(addr_ctx); + curlx_free(addr_ctx); } *paddr_ctx = NULL; } @@ -156,7 +151,7 @@ addr_ctx_create(struct Curl_easy *data, const char *hostname, int port, const struct addrinfo *hints) { - struct async_thrdd_addr_ctx *addr_ctx = calloc(1, sizeof(*addr_ctx)); + struct async_thrdd_addr_ctx *addr_ctx = curlx_calloc(1, sizeof(*addr_ctx)); if(!addr_ctx) return NULL; @@ -186,7 +181,7 @@ addr_ctx_create(struct Curl_easy *data, /* Copying hostname string because original can be destroyed by parent * thread during gethostbyname execution. */ - addr_ctx->hostname = strdup(hostname); + addr_ctx->hostname = curlx_strdup(hostname); if(!addr_ctx->hostname) goto err_exit; @@ -249,7 +244,6 @@ static CURL_THREAD_RETURN_T CURL_STDCALL getaddrinfo_thread(void *arg) } } #endif - } addr_ctx_unlink(&addr_ctx, NULL); @@ -376,14 +370,17 @@ static CURLcode async_rr_start(struct Curl_easy *data, int port) status = ares_init_options(&thrdd->rr.channel, NULL, 0); if(status != ARES_SUCCESS) { thrdd->rr.channel = NULL; + curlx_free(rrname); return CURLE_FAILED_INIT; } #ifdef CURLDEBUG if(getenv("CURL_DNS_SERVER")) { const char *servers = getenv("CURL_DNS_SERVER"); status = ares_set_servers_ports_csv(thrdd->rr.channel, servers); - if(status) + if(status) { + curlx_free(rrname); return CURLE_FAILED_INIT; + } } #endif @@ -432,8 +429,8 @@ static bool async_thrdd_init(struct Curl_easy *data, data->state.async.done = FALSE; data->state.async.port = port; data->state.async.ip_version = ip_version; - free(data->state.async.hostname); - data->state.async.hostname = strdup(hostname); + curlx_free(data->state.async.hostname); + data->state.async.hostname = curlx_strdup(hostname); if(!data->state.async.hostname) goto err_exit; @@ -444,7 +441,7 @@ static bool async_thrdd_init(struct Curl_easy *data, /* passing addr_ctx to the thread adds a reference */ addr_ctx->ref_count = 2; - addr_ctx->start = curlx_now(); + addr_ctx->start = *Curl_pgrs_now(data); #ifdef HAVE_GETADDRINFO addr_ctx->thread_hnd = Curl_thread_create(getaddrinfo_thread, addr_ctx); @@ -470,7 +467,7 @@ static bool async_thrdd_init(struct Curl_easy *data, err_exit: CURL_TRC_DNS(data, "resolve thread failed init: %d", err); async_thrdd_destroy(data); - CURL_SETERRNO(err); + errno = err; return FALSE; } @@ -487,8 +484,8 @@ static void async_thrdd_shutdown(struct Curl_easy *data) Curl_mutex_acquire(&addr_ctx->mutx); #ifndef CURL_DISABLE_SOCKETPAIR - if(!addr_ctx->do_abort) - Curl_multi_will_close(data, addr_ctx->sock_pair[0]); + if(!addr_ctx->do_abort) + Curl_multi_will_close(data, addr_ctx->sock_pair[0]); #endif addr_ctx->do_abort = TRUE; done = addr_ctx->thrd_done; @@ -657,8 +654,8 @@ CURLcode Curl_async_is_resolved(struct Curl_easy *data, else { /* poll for name lookup done with exponential backoff up to 250ms */ /* should be fine even if this converts to 32-bit */ - timediff_t elapsed = curlx_timediff(curlx_now(), - data->progress.t_startsingle); + timediff_t elapsed = curlx_ptimediff_ms(Curl_pgrs_now(data), + &data->progress.t_startsingle); if(elapsed < 0) elapsed = 0; @@ -666,7 +663,7 @@ CURLcode Curl_async_is_resolved(struct Curl_easy *data, /* Start at 1ms poll interval */ thrdd->addr->poll_interval = 1; else if(elapsed >= thrdd->addr->interval_end) - /* Back-off exponentially if last interval expired */ + /* Back-off exponentially if last interval expired */ thrdd->addr->poll_interval *= 2; if(thrdd->addr->poll_interval > 250) @@ -704,15 +701,16 @@ CURLcode Curl_async_pollset(struct Curl_easy *data, struct easy_pollset *ps) if(!thrd_done) { #ifndef CURL_DISABLE_SOCKETPAIR - /* return read fd to client for polling the DNS resolution status */ + /* return read fd to client for polling the DNS resolution status */ result = Curl_pollset_add_in(data, ps, thrdd->addr->sock_pair[0]); #else timediff_t milli; - timediff_t ms = curlx_timediff(curlx_now(), thrdd->addr->start); + timediff_t ms = + curlx_ptimediff_ms(Curl_pgrs_now(data), &thrdd->addr->start); if(ms < 3) milli = 0; else if(ms <= 50) - milli = ms/3; + milli = ms / 3; else if(ms <= 250) milli = 50; else @@ -727,24 +725,18 @@ CURLcode Curl_async_pollset(struct Curl_easy *data, struct easy_pollset *ps) /* * Curl_async_getaddrinfo() - for platforms without getaddrinfo */ -struct Curl_addrinfo *Curl_async_getaddrinfo(struct Curl_easy *data, - const char *hostname, - int port, - int ip_version, - int *waitp) +CURLcode Curl_async_getaddrinfo(struct Curl_easy *data, const char *hostname, + int port, int ip_version) { (void)ip_version; - *waitp = 0; /* default to synchronous response */ /* fire up a new resolver thread! */ if(async_thrdd_init(data, hostname, port, ip_version, NULL)) { - *waitp = 1; /* expect asynchronous response */ - return NULL; + return CURLE_OK; } failf(data, "getaddrinfo() thread failed"); - - return NULL; + return CURLE_FAILED_INIT; } #else /* !HAVE_GETADDRINFO */ @@ -752,15 +744,11 @@ struct Curl_addrinfo *Curl_async_getaddrinfo(struct Curl_easy *data, /* * Curl_async_getaddrinfo() - for getaddrinfo */ -struct Curl_addrinfo *Curl_async_getaddrinfo(struct Curl_easy *data, - const char *hostname, - int port, - int ip_version, - int *waitp) +CURLcode Curl_async_getaddrinfo(struct Curl_easy *data, const char *hostname, + int port, int ip_version) { struct addrinfo hints; int pf = PF_INET; - *waitp = 0; /* default to synchronous response */ CURL_TRC_DNS(data, "init threaded resolve of %s:%d", hostname, port); #ifdef CURLRES_IPV6 @@ -782,14 +770,11 @@ struct Curl_addrinfo *Curl_async_getaddrinfo(struct Curl_easy *data, SOCK_STREAM : SOCK_DGRAM; /* fire up a new resolver thread! */ - if(async_thrdd_init(data, hostname, port, ip_version, &hints)) { - *waitp = 1; /* expect asynchronous response */ - return NULL; - } + if(async_thrdd_init(data, hostname, port, ip_version, &hints)) + return CURLE_OK; failf(data, "getaddrinfo() thread failed to start"); - return NULL; - + return CURLE_FAILED_INIT; } #endif /* !HAVE_GETADDRINFO */ diff --git a/vendor/hydra/vendor/curl/lib/asyn.h b/vendor/hydra/vendor/curl/lib/asyn.h index 7863042b..b9610810 100644 --- a/vendor/hydra/vendor/curl/lib/asyn.h +++ b/vendor/hydra/vendor/curl/lib/asyn.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" struct Curl_easy; @@ -118,11 +117,8 @@ CURLcode Curl_async_await(struct Curl_easy *data, * Each resolver backend must of course make sure to return data in the * correct format to comply with this. */ -struct Curl_addrinfo *Curl_async_getaddrinfo(struct Curl_easy *data, - const char *hostname, - int port, - int ip_version, - int *waitp); +CURLcode Curl_async_getaddrinfo(struct Curl_easy *data, const char *hostname, + int port, int ip_version); #ifdef USE_ARES /* common functions for c-ares and threaded resolver with HTTPSRR */ @@ -132,19 +128,18 @@ CURLcode Curl_ares_pollset(struct Curl_easy *data, ares_channel channel, struct easy_pollset *ps); -int Curl_ares_perform(ares_channel channel, - timediff_t timeout_ms); +int Curl_ares_perform(ares_channel channel, timediff_t timeout_ms); #endif #ifdef CURLRES_ARES /* async resolving implementation using c-ares alone */ struct async_ares_ctx { ares_channel channel; - int num_pending; /* number of outstanding c-ares requests */ + int num_pending; /* number of outstanding c-ares requests */ struct Curl_addrinfo *temp_ai; /* intermediary result while fetching c-ares parts */ - int ares_status; /* ARES_SUCCESS, ARES_ENOTFOUND, etc. */ - CURLcode result; /* CURLE_OK or error handling response */ + int ares_status; /* ARES_SUCCESS, ARES_ENOTFOUND, etc. */ + CURLcode result; /* CURLE_OK or error handling response */ #ifndef HAVE_CARES_GETADDRINFO struct curltime happy_eyeballs_dns_time; /* when this timer started, or 0 */ #endif @@ -226,11 +221,11 @@ struct doh_probes; #else /* CURLRES_ASYNCH */ /* convert these functions if an asynch resolver is not used */ -#define Curl_async_get_impl(x,y) (*(y) = NULL, CURLE_OK) -#define Curl_async_is_resolved(x,y) CURLE_COULDNT_RESOLVE_HOST -#define Curl_async_await(x,y) CURLE_COULDNT_RESOLVE_HOST -#define Curl_async_global_init() CURLE_OK -#define Curl_async_global_cleanup() Curl_nop_stmt +#define Curl_async_get_impl(x, y) (*(y) = NULL, CURLE_OK) +#define Curl_async_is_resolved(x, y) CURLE_COULDNT_RESOLVE_HOST +#define Curl_async_await(x, y) CURLE_COULDNT_RESOLVE_HOST +#define Curl_async_global_init() CURLE_OK +#define Curl_async_global_cleanup() Curl_nop_stmt #endif /* !CURLRES_ASYNCH */ @@ -270,9 +265,8 @@ void Curl_async_shutdown(struct Curl_easy *data); void Curl_async_destroy(struct Curl_easy *data); #else /* !USE_CURL_ASYNC */ #define Curl_async_shutdown(x) Curl_nop_stmt -#define Curl_async_destroy(x) Curl_nop_stmt +#define Curl_async_destroy(x) Curl_nop_stmt #endif /* USE_CURL_ASYNC */ - /********** end of generic resolver interface functions *****************/ #endif /* HEADER_CURL_ASYN_H */ diff --git a/vendor/hydra/vendor/curl/lib/bufq.c b/vendor/hydra/vendor/curl/lib/bufq.c index e429ccf8..750d8688 100644 --- a/vendor/hydra/vendor/curl/lib/bufq.c +++ b/vendor/hydra/vendor/curl/lib/bufq.c @@ -21,13 +21,9 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include "bufq.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" +#include "bufq.h" static bool chunk_is_empty(const struct buf_chunk *chunk) { @@ -51,9 +47,9 @@ static void chunk_reset(struct buf_chunk *chunk) } static size_t chunk_append(struct buf_chunk *chunk, - const unsigned char *buf, size_t len) + const uint8_t *buf, size_t len) { - unsigned char *p = &chunk->x.data[chunk->w_offset]; + uint8_t *p = &chunk->x.data[chunk->w_offset]; size_t n = chunk->dlen - chunk->w_offset; DEBUGASSERT(chunk->dlen >= chunk->w_offset); if(n) { @@ -65,9 +61,9 @@ static size_t chunk_append(struct buf_chunk *chunk, } static size_t chunk_read(struct buf_chunk *chunk, - unsigned char *buf, size_t len) + uint8_t *buf, size_t len) { - unsigned char *p = &chunk->x.data[chunk->r_offset]; + uint8_t *p = &chunk->x.data[chunk->r_offset]; size_t n = chunk->w_offset - chunk->r_offset; DEBUGASSERT(chunk->w_offset >= chunk->r_offset); if(!n) { @@ -89,7 +85,7 @@ static CURLcode chunk_slurpn(struct buf_chunk *chunk, size_t max_len, Curl_bufq_reader *reader, void *reader_ctx, size_t *pnread) { - unsigned char *p = &chunk->x.data[chunk->w_offset]; + uint8_t *p = &chunk->x.data[chunk->w_offset]; size_t n = chunk->dlen - chunk->w_offset; /* free amount */ CURLcode result; @@ -108,7 +104,7 @@ static CURLcode chunk_slurpn(struct buf_chunk *chunk, size_t max_len, } static void chunk_peek(const struct buf_chunk *chunk, - const unsigned char **pbuf, size_t *plen) + const uint8_t **pbuf, size_t *plen) { DEBUGASSERT(chunk->w_offset >= chunk->r_offset); *pbuf = &chunk->x.data[chunk->r_offset]; @@ -116,7 +112,7 @@ static void chunk_peek(const struct buf_chunk *chunk, } static void chunk_peek_at(const struct buf_chunk *chunk, size_t offset, - const unsigned char **pbuf, size_t *plen) + const uint8_t **pbuf, size_t *plen) { offset += chunk->r_offset; DEBUGASSERT(chunk->w_offset >= offset); @@ -143,11 +139,10 @@ static void chunk_list_free(struct buf_chunk **anchor) while(*anchor) { chunk = *anchor; *anchor = chunk->next; - free(chunk); + curlx_free(chunk); } } - void Curl_bufcp_init(struct bufc_pool *pool, size_t chunk_size, size_t spare_max) { @@ -178,7 +173,7 @@ static CURLcode bufcp_take(struct bufc_pool *pool, return CURLE_OUT_OF_MEMORY; } - chunk = calloc(1, sizeof(*chunk) + pool->chunk_size); + chunk = curlx_calloc(1, sizeof(*chunk) + pool->chunk_size); if(!chunk) { *pchunk = NULL; return CURLE_OUT_OF_MEMORY; @@ -192,7 +187,7 @@ static void bufcp_put(struct bufc_pool *pool, struct buf_chunk *chunk) { if(pool->spare_count >= pool->spare_max) { - free(chunk); + curlx_free(chunk); } else { chunk_reset(chunk); @@ -311,7 +306,7 @@ static struct buf_chunk *get_spare(struct bufq *q) return NULL; } - chunk = calloc(1, sizeof(*chunk) + q->chunk_size); + chunk = curlx_calloc(1, sizeof(*chunk) + q->chunk_size); if(!chunk) return NULL; chunk->dlen = q->chunk_size; @@ -334,11 +329,11 @@ static void prune_head(struct bufq *q) --q->chunk_count; } else if((q->chunk_count > q->max_chunks) || - (q->opts & BUFQ_OPT_NO_SPARES)) { + (q->opts & BUFQ_OPT_NO_SPARES)) { /* SOFT_LIMIT allowed us more than max. free spares until * we are at max again. Or free them if we are configured * to not use spares. */ - free(chunk); + curlx_free(chunk); --q->chunk_count; } else { @@ -370,7 +365,7 @@ static struct buf_chunk *get_non_full_tail(struct bufq *q) } CURLcode Curl_bufq_write(struct bufq *q, - const unsigned char *buf, size_t len, + const uint8_t *buf, size_t len, size_t *pnwritten) { struct buf_chunk *tail; @@ -400,10 +395,10 @@ CURLcode Curl_bufq_cwrite(struct bufq *q, const char *buf, size_t len, size_t *pnwritten) { - return Curl_bufq_write(q, (const unsigned char *)buf, len, pnwritten); + return Curl_bufq_write(q, (const uint8_t *)buf, len, pnwritten); } -CURLcode Curl_bufq_read(struct bufq *q, unsigned char *buf, size_t len, +CURLcode Curl_bufq_read(struct bufq *q, uint8_t *buf, size_t len, size_t *pnread) { *pnread = 0; @@ -422,11 +417,11 @@ CURLcode Curl_bufq_read(struct bufq *q, unsigned char *buf, size_t len, CURLcode Curl_bufq_cread(struct bufq *q, char *buf, size_t len, size_t *pnread) { - return Curl_bufq_read(q, (unsigned char *)buf, len, pnread); + return Curl_bufq_read(q, (uint8_t *)buf, len, pnread); } bool Curl_bufq_peek(struct bufq *q, - const unsigned char **pbuf, size_t *plen) + const uint8_t **pbuf, size_t *plen) { if(q->head && chunk_is_empty(q->head)) { prune_head(q); @@ -441,7 +436,7 @@ bool Curl_bufq_peek(struct bufq *q, } bool Curl_bufq_peek_at(struct bufq *q, size_t offset, - const unsigned char **pbuf, size_t *plen) + const uint8_t **pbuf, size_t *plen) { struct buf_chunk *c = q->head; size_t clen; @@ -477,7 +472,7 @@ void Curl_bufq_skip(struct bufq *q, size_t amount) CURLcode Curl_bufq_pass(struct bufq *q, Curl_bufq_writer *writer, void *writer_ctx, size_t *pwritten) { - const unsigned char *buf; + const uint8_t *buf; size_t blen; CURLcode result = CURLE_OK; @@ -507,7 +502,7 @@ CURLcode Curl_bufq_pass(struct bufq *q, Curl_bufq_writer *writer, } CURLcode Curl_bufq_write_pass(struct bufq *q, - const unsigned char *buf, size_t len, + const uint8_t *buf, size_t len, Curl_bufq_writer *writer, void *writer_ctx, size_t *pwritten) { diff --git a/vendor/hydra/vendor/curl/lib/bufq.h b/vendor/hydra/vendor/curl/lib/bufq.h index ad8e6435..bcd7df2a 100644 --- a/vendor/hydra/vendor/curl/lib/bufq.h +++ b/vendor/hydra/vendor/curl/lib/bufq.h @@ -25,8 +25,6 @@ ***************************************************************************/ #include "curl_setup.h" -#include - /** * A chunk of bytes for reading and writing. * The size is fixed a creation with read and write offset @@ -38,7 +36,7 @@ struct buf_chunk { size_t r_offset; /* first unread bytes */ size_t w_offset; /* one after last written byte */ union { - unsigned char data[1]; /* the buffer for `dlen` bytes */ + uint8_t data[1]; /* the buffer for `dlen` bytes */ void *dummy; /* alignment */ } x; }; @@ -166,7 +164,7 @@ bool Curl_bufq_is_full(const struct bufq *q); * CURLE_AGAIN is returned if the buffer queue is full. */ CURLcode Curl_bufq_write(struct bufq *q, - const unsigned char *buf, size_t len, + const uint8_t *buf, size_t len, size_t *pnwritten); CURLcode Curl_bufq_cwrite(struct bufq *q, @@ -177,7 +175,7 @@ CURLcode Curl_bufq_cwrite(struct bufq *q, * Read buf from the start of the buffer queue. The buf is copied * and the amount of copied bytes is returned. */ -CURLcode Curl_bufq_read(struct bufq *q, unsigned char *buf, size_t len, +CURLcode Curl_bufq_read(struct bufq *q, uint8_t *buf, size_t len, size_t *pnread); CURLcode Curl_bufq_cread(struct bufq *q, char *buf, size_t len, @@ -193,10 +191,10 @@ CURLcode Curl_bufq_cread(struct bufq *q, char *buf, size_t len, * is modified, see `Curl_bufq_skip()`` */ bool Curl_bufq_peek(struct bufq *q, - const unsigned char **pbuf, size_t *plen); + const uint8_t **pbuf, size_t *plen); bool Curl_bufq_peek_at(struct bufq *q, size_t offset, - const unsigned char **pbuf, size_t *plen); + const uint8_t **pbuf, size_t *plen); /** * Tell the buffer queue to discard `amount` buf bytes at the head @@ -206,7 +204,7 @@ bool Curl_bufq_peek_at(struct bufq *q, size_t offset, void Curl_bufq_skip(struct bufq *q, size_t amount); typedef CURLcode Curl_bufq_writer(void *writer_ctx, - const unsigned char *buf, size_t len, + const uint8_t *buf, size_t len, size_t *pwritten); /** * Passes the chunks in the buffer queue to the writer and returns @@ -221,7 +219,7 @@ CURLcode Curl_bufq_pass(struct bufq *q, Curl_bufq_writer *writer, void *writer_ctx, size_t *pwritten); typedef CURLcode Curl_bufq_reader(void *reader_ctx, - unsigned char *buf, size_t len, + uint8_t *buf, size_t len, size_t *pnread); /** @@ -253,7 +251,7 @@ CURLcode Curl_bufq_sipn(struct bufq *q, size_t max_len, * amount buffered, chunk size, etc. */ CURLcode Curl_bufq_write_pass(struct bufq *q, - const unsigned char *buf, size_t len, + const uint8_t *buf, size_t len, Curl_bufq_writer *writer, void *writer_ctx, size_t *pwritten); diff --git a/vendor/hydra/vendor/curl/lib/bufref.c b/vendor/hydra/vendor/curl/lib/bufref.c index ac061207..b1272d58 100644 --- a/vendor/hydra/vendor/curl/lib/bufref.c +++ b/vendor/hydra/vendor/curl/lib/bufref.c @@ -21,15 +21,12 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" + #include "urldata.h" #include "bufref.h" #include "strdup.h" -#include "curl_memory.h" -#include "memdebug.h" - #ifdef DEBUGBUILD #define SIGNATURE 0x5c48e9b2 /* Random pattern. */ #endif @@ -79,7 +76,7 @@ void Curl_bufref_set(struct bufref *br, const void *ptr, size_t len, DEBUGASSERT(len <= CURL_MAX_INPUT_LENGTH); Curl_bufref_free(br); - br->ptr = (const unsigned char *) ptr; + br->ptr = (const unsigned char *)ptr; br->len = len; br->dtor = dtor; } @@ -87,7 +84,7 @@ void Curl_bufref_set(struct bufref *br, const void *ptr, size_t len, /* * Get a pointer to the referenced buffer. */ -const unsigned char *Curl_bufref_ptr(const struct bufref *br) +const unsigned char *Curl_bufref_uptr(const struct bufref *br) { DEBUGASSERT(br); DEBUGASSERT(br->signature == SIGNATURE); @@ -96,6 +93,18 @@ const unsigned char *Curl_bufref_ptr(const struct bufref *br) return br->ptr; } +/* + * Get a pointer to the referenced string. + */ +const char *Curl_bufref_ptr(const struct bufref *br) +{ + DEBUGASSERT(br); + DEBUGASSERT(br->signature == SIGNATURE); + DEBUGASSERT(br->ptr || !br->len); + + return (const char *)br->ptr; +} + /* * Get the length of the referenced buffer data. */ @@ -108,7 +117,7 @@ size_t Curl_bufref_len(const struct bufref *br) return br->len; } -CURLcode Curl_bufref_memdup(struct bufref *br, const void *ptr, size_t len) +CURLcode Curl_bufref_memdup0(struct bufref *br, const void *ptr, size_t len) { unsigned char *cpy = NULL; diff --git a/vendor/hydra/vendor/curl/lib/bufref.h b/vendor/hydra/vendor/curl/lib/bufref.h index dd424f18..5d331adb 100644 --- a/vendor/hydra/vendor/curl/lib/bufref.h +++ b/vendor/hydra/vendor/curl/lib/bufref.h @@ -36,13 +36,16 @@ struct bufref { #endif }; - void Curl_bufref_init(struct bufref *br); void Curl_bufref_set(struct bufref *br, const void *ptr, size_t len, void (*dtor)(void *)); -const unsigned char *Curl_bufref_ptr(const struct bufref *br); +const char *Curl_bufref_ptr(const struct bufref *br); +const unsigned char *Curl_bufref_uptr(const struct bufref *br); size_t Curl_bufref_len(const struct bufref *br); -CURLcode Curl_bufref_memdup(struct bufref *br, const void *ptr, size_t len); +CURLcode Curl_bufref_memdup0(struct bufref *br, const void *ptr, size_t len); void Curl_bufref_free(struct bufref *br); +/* return a strdup() version of the buffer */ +#define Curl_bufref_dup(x) curlx_strdup(Curl_bufref_ptr(x)) + #endif diff --git a/vendor/hydra/vendor/curl/lib/cf-h1-proxy.c b/vendor/hydra/vendor/curl/lib/cf-h1-proxy.c index e65aa74d..c41a68de 100644 --- a/vendor/hydra/vendor/curl/lib/cf-h1-proxy.c +++ b/vendor/hydra/vendor/curl/lib/cf-h1-proxy.c @@ -21,12 +21,10 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #if !defined(CURL_DISABLE_PROXY) && !defined(CURL_DISABLE_HTTP) -#include #include "urldata.h" #include "curlx/dynbuf.h" #include "sendf.h" @@ -41,23 +39,17 @@ #include "connect.h" #include "curl_trc.h" #include "strcase.h" -#include "vtls/vtls.h" #include "transfer.h" -#include "multiif.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - typedef enum { - H1_TUNNEL_INIT, /* init/default/no tunnel state */ - H1_TUNNEL_CONNECT, /* CONNECT request is being send */ - H1_TUNNEL_RECEIVE, /* CONNECT answer is being received */ - H1_TUNNEL_RESPONSE, /* CONNECT response received completely */ - H1_TUNNEL_ESTABLISHED, - H1_TUNNEL_FAILED + H1_TUNNEL_INIT, /* init/default/no tunnel state */ + H1_TUNNEL_CONNECT, /* CONNECT request is being send */ + H1_TUNNEL_RECEIVE, /* CONNECT answer is being received */ + H1_TUNNEL_RESPONSE, /* CONNECT response received completely */ + H1_TUNNEL_ESTABLISHED, + H1_TUNNEL_FAILED } h1_tunnel_state; /* struct for HTTP CONNECT tunneling */ @@ -76,9 +68,10 @@ struct h1_tunnel_state { h1_tunnel_state tunnel_state; BIT(chunked_encoding); BIT(close_connection); + BIT(maybe_folded); + BIT(leading_unfold); }; - static bool tunnel_is_established(struct h1_tunnel_state *ts) { return ts && (ts->tunnel_state == H1_TUNNEL_ESTABLISHED); @@ -102,6 +95,8 @@ static CURLcode tunnel_reinit(struct Curl_cfilter *cf, ts->keepon = KEEPON_CONNECT; ts->cl = 0; ts->close_connection = FALSE; + ts->maybe_folded = FALSE; + ts->leading_unfold = FALSE; return CURLE_OK; } @@ -116,7 +111,7 @@ static CURLcode tunnel_init(struct Curl_cfilter *cf, return CURLE_UNSUPPORTED_PROTOCOL; } - ts = calloc(1, sizeof(*ts)); + ts = curlx_calloc(1, sizeof(*ts)); if(!ts) return CURLE_OUT_OF_MEMORY; @@ -126,8 +121,7 @@ static CURLcode tunnel_init(struct Curl_cfilter *cf, curlx_dyn_init(&ts->request_data, DYN_HTTP_REQUEST); Curl_httpchunk_init(data, &ts->ch, TRUE); - *pts = ts; - connkeep(cf->conn, "HTTP proxy CONNECT"); + *pts = ts; return tunnel_reinit(cf, data, ts); } @@ -175,7 +169,7 @@ static void h1_tunnel_go_state(struct Curl_cfilter *cf, curlx_dyn_reset(&ts->rcvbuf); curlx_dyn_reset(&ts->request_data); /* restore the protocol pointer */ - data->info.httpcode = 0; /* clear it as it might've been used for the + data->info.httpcode = 0; /* clear it as it might have been used for the proxy */ /* If a proxy-authorization header was used for the proxy, then we should make sure that it is not accidentally used for the document request @@ -195,7 +189,7 @@ static void tunnel_free(struct Curl_cfilter *cf, curlx_dyn_free(&ts->rcvbuf); curlx_dyn_free(&ts->request_data); Curl_httpchunk_free(data, &ts->ch); - free(ts); + curlx_free(ts); cf->ctx = NULL; } } @@ -214,9 +208,9 @@ static CURLcode start_CONNECT(struct Curl_cfilter *cf, int http_minor; CURLcode result; - /* This only happens if we have looped here due to authentication - reasons, and we do not really use the newly cloned URL here - then. Just free() it. */ + /* This only happens if we have looped here due to authentication + reasons, and we do not really use the newly cloned URL here + then. Just free it. */ Curl_safefree(data->req.newurl); result = Curl_http_proxy_create_CONNECT(&req, cf, data, 1); @@ -247,7 +241,7 @@ static CURLcode send_CONNECT(struct Curl_cfilter *cf, struct h1_tunnel_state *ts, bool *done) { - char *buf = curlx_dyn_ptr(&ts->request_data); + uint8_t *buf = curlx_dyn_uptr(&ts->request_data); size_t request_len = curlx_dyn_len(&ts->request_data); size_t blen = request_len; CURLcode result = CURLE_OK; @@ -268,7 +262,7 @@ static CURLcode send_CONNECT(struct Curl_cfilter *cf, DEBUGASSERT(blen >= nwritten); ts->nsent += nwritten; - Curl_debug(data, CURLINFO_HEADER_OUT, buf, (size_t)nwritten); + Curl_debug(data, CURLINFO_HEADER_OUT, (char *)buf, nwritten); out: if(result) @@ -286,10 +280,8 @@ static CURLcode on_resp_header(struct Curl_cfilter *cf, struct SingleRequest *k = &data->req; (void)cf; - if((checkprefix("WWW-Authenticate:", header) && - (401 == k->httpcode)) || - (checkprefix("Proxy-authenticate:", header) && - (407 == k->httpcode))) { + if((checkprefix("WWW-Authenticate:", header) && (401 == k->httpcode)) || + (checkprefix("Proxy-authenticate:", header) && (407 == k->httpcode))) { bool proxy = (k->httpcode == 407); char *auth = Curl_copy_header_value(header); @@ -299,13 +291,13 @@ static CURLcode on_resp_header(struct Curl_cfilter *cf, CURL_TRC_CF(data, cf, "CONNECT: fwd auth header '%s'", header); result = Curl_http_input_auth(data, proxy, auth); - free(auth); + curlx_free(auth); if(result) return result; } else if(checkprefix("Content-Length:", header)) { - if(k->httpcode/100 == 2) { + if(k->httpcode / 100 == 2) { /* A client MUST ignore any Content-Length or Transfer-Encoding header fields received in a successful response to CONNECT. "Successful" described as: 2xx (Successful). RFC 7231 4.3.6 */ @@ -324,7 +316,7 @@ static CURLcode on_resp_header(struct Curl_cfilter *cf, STRCONST("Connection:"), STRCONST("close"))) ts->close_connection = TRUE; else if(checkprefix("Transfer-Encoding:", header)) { - if(k->httpcode/100 == 2) { + if(k->httpcode / 100 == 2) { /* A client MUST ignore any Content-Length or Transfer-Encoding header fields received in a successful response to CONNECT. "Successful" described as: 2xx (Successful). RFC 7231 4.3.6 */ @@ -350,22 +342,88 @@ static CURLcode on_resp_header(struct Curl_cfilter *cf, ISDIGIT(header[9]) && ISDIGIT(header[10]) && ISDIGIT(header[11]) && !ISDIGIT(header[12])) { /* store the HTTP code from the proxy */ - data->info.httpproxycode = k->httpcode = (header[9] - '0') * 100 + + data->info.httpproxycode = k->httpcode = (header[9] - '0') * 100 + (header[10] - '0') * 10 + (header[11] - '0'); } return result; } +static CURLcode single_header(struct Curl_cfilter *cf, + struct Curl_easy *data, + struct h1_tunnel_state *ts) +{ + CURLcode result = CURLE_OK; + char *linep = curlx_dyn_ptr(&ts->rcvbuf); + size_t line_len = curlx_dyn_len(&ts->rcvbuf); /* bytes in this line */ + struct SingleRequest *k = &data->req; + int writetype; + ts->headerlines++; + + /* output debug if that is requested */ + Curl_debug(data, CURLINFO_HEADER_IN, linep, line_len); + + /* send the header to the callback */ + writetype = CLIENTWRITE_HEADER | CLIENTWRITE_CONNECT | + (ts->headerlines == 1 ? CLIENTWRITE_STATUS : 0); + result = Curl_client_write(data, writetype, linep, line_len); + if(result) + return result; + + result = Curl_bump_headersize(data, line_len, TRUE); + if(result) + return result; + + /* Newlines are CRLF, so the CR is ignored as the line is not + really terminated until the LF comes. Treat a following CR + as end-of-headers as well.*/ + + if(ISNEWLINE(linep[0])) { + /* end of response-headers from the proxy */ + + if((407 == k->httpcode) && !data->state.authproblem) { + /* If we get a 407 response code with content length + when we have no auth problem, we must ignore the + whole response-body */ + ts->keepon = KEEPON_IGNORE; + + if(ts->cl) { + infof(data, "Ignore %" FMT_OFF_T " bytes of response-body", ts->cl); + } + else if(ts->chunked_encoding) { + infof(data, "Ignore chunked response-body"); + } + else { + /* without content-length or chunked encoding, we + cannot keep the connection alive since the close is + the end signal so we bail out at once instead */ + CURL_TRC_CF(data, cf, "CONNECT: no content-length or chunked"); + ts->keepon = KEEPON_DONE; + } + } + else { + ts->keepon = KEEPON_DONE; + } + + DEBUGASSERT(ts->keepon == KEEPON_IGNORE || + ts->keepon == KEEPON_DONE); + return result; + } + + result = on_resp_header(cf, data, ts, linep); + if(result) + return result; + + curlx_dyn_reset(&ts->rcvbuf); + return result; +} + static CURLcode recv_CONNECT_resp(struct Curl_cfilter *cf, struct Curl_easy *data, struct h1_tunnel_state *ts, bool *done) { CURLcode result = CURLE_OK; - struct SingleRequest *k = &data->req; - char *linep; - size_t line_len; - int error, writetype; + int error; #define SELECT_OK 0 #define SELECT_ERROR 1 @@ -384,8 +442,8 @@ static CURLcode recv_CONNECT_resp(struct Curl_cfilter *cf, /* socket buffer drained, return */ return CURLE_OK; - if(Curl_pgrsUpdate(data)) - return CURLE_ABORTED_BY_CALLBACK; + if(!result) + result = Curl_pgrsUpdate(data); if(result) { ts->keepon = KEEPON_DONE; @@ -439,6 +497,31 @@ static CURLcode recv_CONNECT_resp(struct Curl_cfilter *cf, continue; } + if(ts->maybe_folded) { + if(ISBLANK(byte)) { + Curl_http_to_fold(&ts->rcvbuf); + ts->leading_unfold = TRUE; + } + else { + result = single_header(cf, data, ts); + if(result) + return result; + /* now handle the new byte */ + } + ts->maybe_folded = FALSE; + } + + if(ts->leading_unfold) { + if(ISBLANK(byte)) + /* skip a bit brother */ + continue; + /* non-blank, insert a space then continue the unfolding */ + if(curlx_dyn_addn(&ts->rcvbuf, " ", 1)) { + failf(data, "CONNECT response too large"); + return CURLE_RECV_ERROR; + } + ts->leading_unfold = FALSE; + } if(curlx_dyn_addn(&ts->rcvbuf, &byte, 1)) { failf(data, "CONNECT response too large"); return CURLE_RECV_ERROR; @@ -447,73 +530,25 @@ static CURLcode recv_CONNECT_resp(struct Curl_cfilter *cf, /* if this is not the end of a header line then continue */ if(byte != 0x0a) continue; - - ts->headerlines++; - linep = curlx_dyn_ptr(&ts->rcvbuf); - line_len = curlx_dyn_len(&ts->rcvbuf); /* amount of bytes in this line */ - - /* output debug if that is requested */ - Curl_debug(data, CURLINFO_HEADER_IN, linep, line_len); - - /* send the header to the callback */ - writetype = CLIENTWRITE_HEADER | CLIENTWRITE_CONNECT | - (ts->headerlines == 1 ? CLIENTWRITE_STATUS : 0); - result = Curl_client_write(data, writetype, linep, line_len); - if(result) - return result; - - result = Curl_bump_headersize(data, line_len, TRUE); - if(result) - return result; - - /* Newlines are CRLF, so the CR is ignored as the line is not - really terminated until the LF comes. Treat a following CR - as end-of-headers as well.*/ - - if(('\r' == linep[0]) || - ('\n' == linep[0])) { - /* end of response-headers from the proxy */ - - if((407 == k->httpcode) && !data->state.authproblem) { - /* If we get a 407 response code with content length - when we have no auth problem, we must ignore the - whole response-body */ - ts->keepon = KEEPON_IGNORE; - - if(ts->cl) { - infof(data, "Ignore %" FMT_OFF_T " bytes of response-body", ts->cl); - } - else if(ts->chunked_encoding) { - infof(data, "Ignore chunked response-body"); - } - else { - /* without content-length or chunked encoding, we - cannot keep the connection alive since the close is - the end signal so we bail out at once instead */ - CURL_TRC_CF(data, cf, "CONNECT: no content-length or chunked"); - ts->keepon = KEEPON_DONE; - } - } - else { - ts->keepon = KEEPON_DONE; + else { + char *linep = curlx_dyn_ptr(&ts->rcvbuf); + size_t hlen = curlx_dyn_len(&ts->rcvbuf); + if(hlen && ISNEWLINE(linep[0])) { + /* end of headers */ + result = single_header(cf, data, ts); + if(result) + return result; } - - DEBUGASSERT(ts->keepon == KEEPON_IGNORE - || ts->keepon == KEEPON_DONE); - continue; + else + ts->maybe_folded = TRUE; } - result = on_resp_header(cf, data, ts, linep); - if(result) - return result; - - curlx_dyn_reset(&ts->rcvbuf); } /* while there is buffer left and loop is requested */ if(error) result = CURLE_RECV_ERROR; *done = (ts->keepon == KEEPON_DONE); - if(!result && *done && data->info.httpproxycode/100 != 2) { + if(!result && *done && data->info.httpproxycode / 100 != 2) { /* Deal with the possibly already received authenticate headers. 'newurl' is set to a new URL if we must loop. */ result = Curl_http_auth_act(data); @@ -535,10 +570,8 @@ static CURLcode H1_CONNECT(struct Curl_cfilter *cf, return CURLE_RECV_ERROR; /* Need a cfilter close and new bootstrap */ do { - timediff_t check; - check = Curl_timeleft(data, NULL, TRUE); - if(check <= 0) { + if(Curl_timeleft_ms(data, TRUE) < 0) { failf(data, "Proxy CONNECT aborted due to timeout"); result = CURLE_OPERATION_TIMEDOUT; goto out; @@ -567,10 +600,8 @@ static CURLcode H1_CONNECT(struct Curl_cfilter *cf, /* read what is there */ CURL_TRC_CF(data, cf, "CONNECT receive"); result = recv_CONNECT_resp(cf, data, ts, &done); - if(Curl_pgrsUpdate(data)) { - result = CURLE_ABORTED_BY_CALLBACK; - goto out; - } + if(!result) + result = Curl_pgrsUpdate(data); /* error or not complete yet. return for more multi-multi */ if(result || !done) goto out; @@ -595,7 +626,6 @@ static CURLcode H1_CONNECT(struct Curl_cfilter *cf, CURL_TRC_CF(data, cf, "CONNECT need to close+open"); infof(data, "Connect me again please"); Curl_conn_cf_close(cf, data); - connkeep(conn, "HTTP proxy CONNECT"); result = Curl_conn_cf_connect(cf->next, data, &done); goto out; } @@ -613,11 +643,9 @@ static CURLcode H1_CONNECT(struct Curl_cfilter *cf, } while(data->req.newurl); DEBUGASSERT(ts->tunnel_state == H1_TUNNEL_RESPONSE); - if(data->info.httpproxycode/100 != 2) { + if(data->info.httpproxycode / 100 != 2) { /* a non-2xx response and we have no next URL to try. */ Curl_safefree(data->req.newurl); - /* failure, close this connection to avoid reuse */ - streamclose(conn, "proxy CONNECT failure"); h1_tunnel_go_state(cf, ts, H1_TUNNEL_FAILED, data); failf(data, "CONNECT tunnel failed, response %d", data->req.httpcode); return CURLE_RECV_ERROR; @@ -673,8 +701,7 @@ static CURLcode cf_h1_proxy_connect(struct Curl_cfilter *cf, /* The real request will follow the CONNECT, reset request partially */ Curl_req_soft_reset(&data->req, data); Curl_client_reset(data); - Curl_pgrsSetUploadCounter(data, 0); - Curl_pgrsSetDownloadCounter(data, 0); + Curl_pgrsReset(data); tunnel_free(cf, data); } @@ -729,10 +756,9 @@ static void cf_h1_proxy_close(struct Curl_cfilter *cf, } } - struct Curl_cftype Curl_cft_h1_proxy = { "H1-PROXY", - CF_TYPE_IP_CONNECT|CF_TYPE_PROXY, + CF_TYPE_IP_CONNECT | CF_TYPE_PROXY, 0, cf_h1_proxy_destroy, cf_h1_proxy_connect, @@ -761,4 +787,4 @@ CURLcode Curl_cf_h1_proxy_insert_after(struct Curl_cfilter *cf_at, return result; } -#endif /* !CURL_DISABLE_PROXY && ! CURL_DISABLE_HTTP */ +#endif /* !CURL_DISABLE_PROXY && !CURL_DISABLE_HTTP */ diff --git a/vendor/hydra/vendor/curl/lib/cf-h1-proxy.h b/vendor/hydra/vendor/curl/lib/cf-h1-proxy.h index ac5bed0b..e48d8278 100644 --- a/vendor/hydra/vendor/curl/lib/cf-h1-proxy.h +++ b/vendor/hydra/vendor/curl/lib/cf-h1-proxy.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #if !defined(CURL_DISABLE_PROXY) && !defined(CURL_DISABLE_HTTP) @@ -33,7 +32,6 @@ CURLcode Curl_cf_h1_proxy_insert_after(struct Curl_cfilter *cf, extern struct Curl_cftype Curl_cft_h1_proxy; - #endif /* !CURL_DISABLE_PROXY && !CURL_DISABLE_HTTP */ #endif /* HEADER_CURL_H1_PROXY_H */ diff --git a/vendor/hydra/vendor/curl/lib/cf-h2-proxy.c b/vendor/hydra/vendor/curl/lib/cf-h2-proxy.c index 8baa227a..4f101a05 100644 --- a/vendor/hydra/vendor/curl/lib/cf-h2-proxy.c +++ b/vendor/hydra/vendor/curl/lib/cf-h2-proxy.c @@ -21,13 +21,13 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_PROXY) && \ defined(USE_NGHTTP2) #include + #include "urldata.h" #include "url.h" #include "cfilters.h" @@ -36,7 +36,6 @@ #include "bufq.h" #include "curlx/dynbuf.h" #include "dynhds.h" -#include "http1.h" #include "http2.h" #include "http_proxy.h" #include "multiif.h" @@ -44,16 +43,12 @@ #include "select.h" #include "cf-h2-proxy.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - -#define PROXY_H2_CHUNK_SIZE (16*1024) +#define PROXY_H2_CHUNK_SIZE (16 * 1024) #define PROXY_HTTP2_HUGE_WINDOW_SIZE (100 * 1024 * 1024) #define H2_TUNNEL_WINDOW_SIZE (10 * 1024 * 1024) -#define PROXY_H2_NW_RECV_CHUNKS (H2_TUNNEL_WINDOW_SIZE / PROXY_H2_CHUNK_SIZE) +#define PROXY_H2_NW_RECV_CHUNKS (H2_TUNNEL_WINDOW_SIZE / PROXY_H2_CHUNK_SIZE) #define PROXY_H2_NW_SEND_CHUNKS 1 #define H2_TUNNEL_RECV_CHUNKS (H2_TUNNEL_WINDOW_SIZE / PROXY_H2_CHUNK_SIZE) @@ -61,11 +56,11 @@ typedef enum { - H2_TUNNEL_INIT, /* init/default/no tunnel state */ - H2_TUNNEL_CONNECT, /* CONNECT request is being send */ - H2_TUNNEL_RESPONSE, /* CONNECT response received completely */ - H2_TUNNEL_ESTABLISHED, - H2_TUNNEL_FAILED + H2_TUNNEL_INIT, /* init/default/no tunnel state */ + H2_TUNNEL_CONNECT, /* CONNECT request is being send */ + H2_TUNNEL_RESPONSE, /* CONNECT response received completely */ + H2_TUNNEL_ESTABLISHED, + H2_TUNNEL_FAILED } h2_tunnel_state; struct tunnel_stream { @@ -87,7 +82,6 @@ static CURLcode tunnel_stream_init(struct Curl_cfilter *cf, const char *hostname; int port; bool ipv6_ip; - CURLcode result; ts->state = H2_TUNNEL_INIT; ts->stream_id = -1; @@ -95,13 +89,11 @@ static CURLcode tunnel_stream_init(struct Curl_cfilter *cf, BUFQ_OPT_SOFT_LIMIT); Curl_bufq_init(&ts->sendbuf, PROXY_H2_CHUNK_SIZE, H2_TUNNEL_SEND_CHUNKS); - result = Curl_http_proxy_get_destination(cf, &hostname, &port, &ipv6_ip); - if(result) - return result; + Curl_http_proxy_get_destination(cf, &hostname, &port, &ipv6_ip); - ts->authority = /* host:port with IPv6 support */ - curl_maprintf("%s%s%s:%d", ipv6_ip ? "[":"", hostname, - ipv6_ip ? "]" : "", port); + /* host:port with IPv6 support */ + ts->authority = curl_maprintf("%s%s%s:%d", ipv6_ip ? "[" : "", hostname, + ipv6_ip ? "]" : "", port); if(!ts->authority) return CURLE_OUT_OF_MEMORY; @@ -190,8 +182,7 @@ struct cf_h2_proxy_ctx { /* How to access `call_data` from a cf_h2 filter */ #undef CF_CTX_CALL_DATA -#define CF_CTX_CALL_DATA(cf) \ - ((struct cf_h2_proxy_ctx *)(cf)->ctx)->call_data +#define CF_CTX_CALL_DATA(cf) ((struct cf_h2_proxy_ctx *)(cf)->ctx)->call_data static void cf_h2_proxy_ctx_clear(struct cf_h2_proxy_ctx *ctx) { @@ -211,7 +202,7 @@ static void cf_h2_proxy_ctx_free(struct cf_h2_proxy_ctx *ctx) { if(ctx) { cf_h2_proxy_ctx_clear(ctx); - free(ctx); + curlx_free(ctx); } } @@ -227,7 +218,7 @@ static void drain_tunnel(struct Curl_cfilter *cf, } static CURLcode proxy_h2_nw_out_writer(void *writer_ctx, - const unsigned char *buf, size_t buflen, + const uint8_t *buf, size_t buflen, size_t *pnwritten) { struct Curl_cfilter *cf = writer_ctx; @@ -235,7 +226,7 @@ static CURLcode proxy_h2_nw_out_writer(void *writer_ctx, if(cf) { struct Curl_easy *data = CF_DATA_CURRENT(cf); CURLcode result; - result = Curl_conn_cf_send(cf->next, data, (const char *)buf, buflen, + result = Curl_conn_cf_send(cf->next, data, buf, buflen, FALSE, pnwritten); CURL_TRC_CF(data, cf, "[0] nw_out_writer(len=%zu) -> %d, %zu", buflen, result, *pnwritten); @@ -249,8 +240,8 @@ static int proxy_h2_client_new(struct Curl_cfilter *cf, { struct cf_h2_proxy_ctx *ctx = cf->ctx; nghttp2_option *o; - nghttp2_mem mem = {NULL, Curl_nghttp2_malloc, Curl_nghttp2_free, - Curl_nghttp2_calloc, Curl_nghttp2_realloc}; + nghttp2_mem mem = { NULL, Curl_nghttp2_malloc, Curl_nghttp2_free, + Curl_nghttp2_calloc, Curl_nghttp2_realloc }; int rc = nghttp2_option_new(&o); if(rc) @@ -314,7 +305,7 @@ static CURLcode cf_h2_proxy_ctx_init(struct Curl_cfilter *cf, rc = nghttp2_session_callbacks_new(&cbs); if(rc) { - failf(data, "Couldn't initialize nghttp2 callbacks"); + failf(data, "Could not initialize nghttp2 callbacks"); goto out; } @@ -334,7 +325,7 @@ static CURLcode cf_h2_proxy_ctx_init(struct Curl_cfilter *cf, /* The nghttp2 session is not yet setup, do it */ rc = proxy_h2_client_new(cf, cbs); if(rc) { - failf(data, "Couldn't initialize nghttp2"); + failf(data, "Could not initialize nghttp2"); goto out; } @@ -365,7 +356,6 @@ static CURLcode cf_h2_proxy_ctx_init(struct Curl_cfilter *cf, goto out; } - /* all set, traffic will be send on connect */ result = CURLE_OK; @@ -412,32 +402,30 @@ static CURLcode proxy_h2_nw_out_flush(struct Curl_cfilter *cf, * This function returns 0 if it succeeds, or -1 and error code will * be assigned to *err. */ -static int proxy_h2_process_pending_input(struct Curl_cfilter *cf, - struct Curl_easy *data, - CURLcode *err) +static CURLcode proxy_h2_process_pending_input(struct Curl_cfilter *cf, + struct Curl_easy *data) { struct cf_h2_proxy_ctx *ctx = cf->ctx; const unsigned char *buf; - size_t blen; + size_t blen, nread; ssize_t rv; while(Curl_bufq_peek(&ctx->inbufq, &buf, &blen)) { rv = nghttp2_session_mem_recv(ctx->h2, (const uint8_t *)buf, blen); CURL_TRC_CF(data, cf, "[0] %zu bytes to nghttp2 -> %zd", blen, rv); - if(rv < 0) { + if(!curlx_sztouz(rv, &nread)) { failf(data, "process_pending_input: nghttp2_session_mem_recv() returned " "%zd:%s", rv, nghttp2_strerror((int)rv)); - *err = CURLE_RECV_ERROR; - return -1; + return CURLE_RECV_ERROR; } - else if(!rv) { + else if(!nread) { /* nghttp2 does not want to process more, but has no error. This * probably cannot happen, but be safe. */ break; } - Curl_bufq_skip(&ctx->inbufq, (size_t)rv); + Curl_bufq_skip(&ctx->inbufq, nread); if(Curl_bufq_is_empty(&ctx->inbufq)) { CURL_TRC_CF(data, cf, "[0] all data in connection buffer processed"); break; @@ -447,8 +435,7 @@ static int proxy_h2_process_pending_input(struct Curl_cfilter *cf, "in connection buffer", Curl_bufq_len(&ctx->inbufq)); } } - - return 0; + return CURLE_OK; } static CURLcode proxy_h2_progress_ingress(struct Curl_cfilter *cf, @@ -458,18 +445,19 @@ static CURLcode proxy_h2_progress_ingress(struct Curl_cfilter *cf, CURLcode result = CURLE_OK; size_t nread; - /* Process network input buffer fist */ + /* Process network input buffer first */ if(!Curl_bufq_is_empty(&ctx->inbufq)) { CURL_TRC_CF(data, cf, "[0] process %zu bytes in connection buffer", Curl_bufq_len(&ctx->inbufq)); - if(proxy_h2_process_pending_input(cf, data, &result) < 0) + result = proxy_h2_process_pending_input(cf, data); + if(result) return result; } /* Receive data from the "lower" filters, e.g. network until * it is time to stop or we have enough data for this stream */ - while(!ctx->conn_closed && /* not closed the connection */ - !ctx->tunnel.closed && /* nor the tunnel */ + while(!ctx->conn_closed && /* not closed the connection */ + !ctx->tunnel.closed && /* nor the tunnel */ Curl_bufq_is_empty(&ctx->inbufq) && /* and we consumed our input */ !Curl_bufq_is_full(&ctx->tunnel.recvbuf)) { @@ -488,14 +476,11 @@ static CURLcode proxy_h2_progress_ingress(struct Curl_cfilter *cf, break; } - if(proxy_h2_process_pending_input(cf, data, &result)) + result = proxy_h2_process_pending_input(cf, data); + if(result) return result; } - if(ctx->conn_closed && Curl_bufq_is_empty(&ctx->inbufq)) { - connclose(cf->conn, "GOAWAY received"); - } - return CURLE_OK; } @@ -554,70 +539,70 @@ static int proxy_h2_fr_print(const nghttp2_frame *frame, char *buffer, size_t blen) { switch(frame->hd.type) { - case NGHTTP2_DATA: { - return curl_msnprintf(buffer, blen, - "FRAME[DATA, len=%d, eos=%d, padlen=%d]", - (int)frame->hd.length, - !!(frame->hd.flags & NGHTTP2_FLAG_END_STREAM), - (int)frame->data.padlen); - } - case NGHTTP2_HEADERS: { - return curl_msnprintf(buffer, blen, - "FRAME[HEADERS, len=%d, hend=%d, eos=%d]", - (int)frame->hd.length, - !!(frame->hd.flags & NGHTTP2_FLAG_END_HEADERS), - !!(frame->hd.flags & NGHTTP2_FLAG_END_STREAM)); - } - case NGHTTP2_PRIORITY: { - return curl_msnprintf(buffer, blen, - "FRAME[PRIORITY, len=%d, flags=%d]", - (int)frame->hd.length, frame->hd.flags); - } - case NGHTTP2_RST_STREAM: { - return curl_msnprintf(buffer, blen, - "FRAME[RST_STREAM, len=%d, flags=%d, error=%u]", - (int)frame->hd.length, frame->hd.flags, - frame->rst_stream.error_code); - } - case NGHTTP2_SETTINGS: { - if(frame->hd.flags & NGHTTP2_FLAG_ACK) { - return curl_msnprintf(buffer, blen, "FRAME[SETTINGS, ack=1]"); - } - return curl_msnprintf(buffer, blen, - "FRAME[SETTINGS, len=%d]", (int)frame->hd.length); + case NGHTTP2_DATA: { + return curl_msnprintf(buffer, blen, + "FRAME[DATA, len=%d, eos=%d, padlen=%d]", + (int)frame->hd.length, + !!(frame->hd.flags & NGHTTP2_FLAG_END_STREAM), + (int)frame->data.padlen); + } + case NGHTTP2_HEADERS: { + return curl_msnprintf(buffer, blen, + "FRAME[HEADERS, len=%d, hend=%d, eos=%d]", + (int)frame->hd.length, + !!(frame->hd.flags & NGHTTP2_FLAG_END_HEADERS), + !!(frame->hd.flags & NGHTTP2_FLAG_END_STREAM)); + } + case NGHTTP2_PRIORITY: { + return curl_msnprintf(buffer, blen, + "FRAME[PRIORITY, len=%d, flags=%d]", + (int)frame->hd.length, frame->hd.flags); + } + case NGHTTP2_RST_STREAM: { + return curl_msnprintf(buffer, blen, + "FRAME[RST_STREAM, len=%d, flags=%d, error=%u]", + (int)frame->hd.length, frame->hd.flags, + frame->rst_stream.error_code); + } + case NGHTTP2_SETTINGS: { + if(frame->hd.flags & NGHTTP2_FLAG_ACK) { + return curl_msnprintf(buffer, blen, "FRAME[SETTINGS, ack=1]"); } - case NGHTTP2_PUSH_PROMISE: - return curl_msnprintf(buffer, blen, - "FRAME[PUSH_PROMISE, len=%d, hend=%d]", - (int)frame->hd.length, - !!(frame->hd.flags & NGHTTP2_FLAG_END_HEADERS)); - case NGHTTP2_PING: - return curl_msnprintf(buffer, blen, - "FRAME[PING, len=%d, ack=%d]", - (int)frame->hd.length, - frame->hd.flags & NGHTTP2_FLAG_ACK); - case NGHTTP2_GOAWAY: { - char scratch[128]; - size_t s_len = CURL_ARRAYSIZE(scratch); - size_t len = (frame->goaway.opaque_data_len < s_len) ? - frame->goaway.opaque_data_len : s_len-1; - if(len) - memcpy(scratch, frame->goaway.opaque_data, len); - scratch[len] = '\0'; - return curl_msnprintf(buffer, blen, - "FRAME[GOAWAY, error=%d, reason='%s', " - "last_stream=%d]", frame->goaway.error_code, - scratch, frame->goaway.last_stream_id); - } - case NGHTTP2_WINDOW_UPDATE: { - return curl_msnprintf(buffer, blen, - "FRAME[WINDOW_UPDATE, incr=%d]", - frame->window_update.window_size_increment); - } - default: - return curl_msnprintf(buffer, blen, "FRAME[%d, len=%d, flags=%d]", - frame->hd.type, (int)frame->hd.length, - frame->hd.flags); + return curl_msnprintf(buffer, blen, + "FRAME[SETTINGS, len=%d]", (int)frame->hd.length); + } + case NGHTTP2_PUSH_PROMISE: + return curl_msnprintf(buffer, blen, + "FRAME[PUSH_PROMISE, len=%d, hend=%d]", + (int)frame->hd.length, + !!(frame->hd.flags & NGHTTP2_FLAG_END_HEADERS)); + case NGHTTP2_PING: + return curl_msnprintf(buffer, blen, + "FRAME[PING, len=%d, ack=%d]", + (int)frame->hd.length, + frame->hd.flags & NGHTTP2_FLAG_ACK); + case NGHTTP2_GOAWAY: { + char scratch[128]; + size_t s_len = CURL_ARRAYSIZE(scratch); + size_t len = (frame->goaway.opaque_data_len < s_len) ? + frame->goaway.opaque_data_len : s_len-1; + if(len) + memcpy(scratch, frame->goaway.opaque_data, len); + scratch[len] = '\0'; + return curl_msnprintf(buffer, blen, + "FRAME[GOAWAY, error=%d, reason='%s', " + "last_stream=%d]", frame->goaway.error_code, + scratch, frame->goaway.last_stream_id); + } + case NGHTTP2_WINDOW_UPDATE: { + return curl_msnprintf(buffer, blen, + "FRAME[WINDOW_UPDATE, incr=%d]", + frame->window_update.window_size_increment); + } + default: + return curl_msnprintf(buffer, blen, "FRAME[%d, len=%d, flags=%d]", + frame->hd.type, (int)frame->hd.length, + frame->hd.flags); } } @@ -633,7 +618,7 @@ static int proxy_h2_on_frame_send(nghttp2_session *session, if(data && Curl_trc_cf_is_verbose(cf, data)) { char buffer[256]; int len; - len = proxy_h2_fr_print(frame, buffer, sizeof(buffer)-1); + len = proxy_h2_fr_print(frame, buffer, sizeof(buffer) - 1); buffer[len] = 0; CURL_TRC_CF(data, cf, "[%d] -> %s", frame->hd.stream_id, buffer); } @@ -656,9 +641,9 @@ static int proxy_h2_on_frame_recv(nghttp2_session *session, if(Curl_trc_cf_is_verbose(cf, data)) { char buffer[256]; int len; - len = proxy_h2_fr_print(frame, buffer, sizeof(buffer)-1); + len = proxy_h2_fr_print(frame, buffer, sizeof(buffer) - 1); buffer[len] = 0; - CURL_TRC_CF(data, cf, "[%d] <- %s",frame->hd.stream_id, buffer); + CURL_TRC_CF(data, cf, "[%d] <- %s", frame->hd.stream_id, buffer); } #endif /* !CURL_DISABLE_VERBOSE_STRINGS */ @@ -851,7 +836,7 @@ static int tunnel_recv_callback(nghttp2_session *session, uint8_t flags, #endif } /* tunnel.recbuf has soft limit, any success MUST add all data */ - DEBUGASSERT((size_t)nwritten == len); + DEBUGASSERT(nwritten == len); return 0; } @@ -927,7 +912,7 @@ static CURLcode proxy_h2_submit(int32_t *pstream_id, result = CURLE_OK; out: - free(nva); + curlx_free(nva); Curl_dynhds_free(&h2_headers); *pstream_id = stream_id; return result; @@ -974,7 +959,7 @@ static CURLcode inspect_response(struct Curl_cfilter *cf, (void)cf; DEBUGASSERT(ts->resp); - if(ts->resp->status/100 == 2) { + if(ts->resp->status / 100 == 2) { infof(data, "CONNECT tunnel established, response %d", ts->resp->status); h2_tunnel_go_state(cf, ts, H2_TUNNEL_ESTABLISHED, data); return CURLE_OK; @@ -1077,7 +1062,6 @@ static CURLcode cf_h2_proxy_connect(struct Curl_cfilter *cf, struct cf_h2_proxy_ctx *ctx = cf->ctx; CURLcode result = CURLE_OK; struct cf_call_data save; - timediff_t check; struct tunnel_stream *ts = &ctx->tunnel; if(cf->connected) { @@ -1102,8 +1086,7 @@ static CURLcode cf_h2_proxy_connect(struct Curl_cfilter *cf, } DEBUGASSERT(ts->authority); - check = Curl_timeleft(data, NULL, TRUE); - if(check <= 0) { + if(Curl_timeleft_ms(data, TRUE) < 0) { failf(data, "Proxy CONNECT aborted due to timeout"); result = CURLE_OPERATION_TIMEDOUT; goto out; @@ -1234,7 +1217,7 @@ static CURLcode cf_h2_proxy_adjust_pollset(struct Curl_cfilter *cf, c_exhaust = !nghttp2_session_get_remote_window_size(ctx->h2); s_exhaust = ctx->tunnel.stream_id >= 0 && !nghttp2_session_get_stream_remote_window_size( - ctx->h2, ctx->tunnel.stream_id); + ctx->h2, ctx->tunnel.stream_id); want_recv = (want_recv || c_exhaust || s_exhaust); want_send = (!s_exhaust && want_send) || (!c_exhaust && nghttp2_session_want_write(ctx->h2)) || @@ -1271,7 +1254,7 @@ static CURLcode h2_handle_tunnel_close(struct Curl_cfilter *cf, if(ctx->tunnel.error == NGHTTP2_REFUSED_STREAM) { CURL_TRC_CF(data, cf, "[%d] REFUSED_STREAM, try again on a new " "connection", ctx->tunnel.stream_id); - connclose(cf->conn, "REFUSED_STREAM"); /* do not use this anymore */ + failf(data, "proxy server refused HTTP/2 stream"); return CURLE_RECV_ERROR; /* trigger Curl_retry_request() later */ } else if(ctx->tunnel.error != NGHTTP2_NO_ERROR) { @@ -1366,7 +1349,7 @@ static CURLcode cf_h2_proxy_recv(struct Curl_cfilter *cf, static CURLcode cf_h2_proxy_send(struct Curl_cfilter *cf, struct Curl_easy *data, - const void *buf, size_t len, bool eos, + const uint8_t *buf, size_t len, bool eos, size_t *pnwritten) { struct cf_h2_proxy_ctx *ctx = cf->ctx; @@ -1428,7 +1411,7 @@ static CURLcode cf_h2_proxy_send(struct Curl_cfilter *cf, "h2 windows %d-%d (stream-conn), buffers %zu-%zu (stream-conn)", ctx->tunnel.stream_id, len, result, *pnwritten, nghttp2_session_get_stream_remote_window_size( - ctx->h2, ctx->tunnel.stream_id), + ctx->h2, ctx->tunnel.stream_id), nghttp2_session_get_remote_window_size(ctx->h2), Curl_bufq_len(&ctx->tunnel.sendbuf), Curl_bufq_len(&ctx->outbufq)); @@ -1489,7 +1472,7 @@ static bool proxy_h2_connisalive(struct Curl_cfilter *cf, *input_pending = FALSE; result = Curl_cf_recv_bufq(cf->next, data, &ctx->inbufq, 0, &nread); if(!result) { - if(proxy_h2_process_pending_input(cf, data, &result) < 0) + if(proxy_h2_process_pending_input(cf, data)) /* immediate error, considered dead */ alive = FALSE; else { @@ -1580,7 +1563,7 @@ static CURLcode cf_h2_proxy_cntrl(struct Curl_cfilter *cf, struct Curl_cftype Curl_cft_h2_proxy = { "H2-PROXY", - CF_TYPE_IP_CONNECT|CF_TYPE_PROXY, + CF_TYPE_IP_CONNECT | CF_TYPE_PROXY, CURL_LOG_LVL_NONE, cf_h2_proxy_destroy, cf_h2_proxy_connect, @@ -1604,7 +1587,7 @@ CURLcode Curl_cf_h2_proxy_insert_after(struct Curl_cfilter *cf, CURLcode result = CURLE_OUT_OF_MEMORY; (void)data; - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) goto out; diff --git a/vendor/hydra/vendor/curl/lib/cf-h2-proxy.h b/vendor/hydra/vendor/curl/lib/cf-h2-proxy.h index 1b3f85aa..318ce197 100644 --- a/vendor/hydra/vendor/curl/lib/cf-h2-proxy.h +++ b/vendor/hydra/vendor/curl/lib/cf-h2-proxy.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #if defined(USE_NGHTTP2) && !defined(CURL_DISABLE_PROXY) diff --git a/vendor/hydra/vendor/curl/lib/cf-haproxy.c b/vendor/hydra/vendor/curl/lib/cf-haproxy.c index 32317910..6c9bfdd1 100644 --- a/vendor/hydra/vendor/curl/lib/cf-haproxy.c +++ b/vendor/hydra/vendor/curl/lib/cf-haproxy.c @@ -21,28 +21,21 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifndef CURL_DISABLE_PROXY -#include #include "urldata.h" #include "cfilters.h" #include "cf-haproxy.h" #include "curl_trc.h" -#include "multiif.h" #include "select.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - typedef enum { - HAPROXY_INIT, /* init/default/no tunnel state */ - HAPROXY_SEND, /* data_out being sent */ - HAPROXY_DONE /* all work done */ + HAPROXY_INIT, /* init/default/no tunnel state */ + HAPROXY_SEND, /* data_out being sent */ + HAPROXY_DONE /* all work done */ } haproxy_state; struct cf_haproxy_ctx { @@ -61,11 +54,11 @@ static void cf_haproxy_ctx_free(struct cf_haproxy_ctx *ctx) { if(ctx) { curlx_dyn_free(&ctx->data_out); - free(ctx); + curlx_free(ctx); } } -static CURLcode cf_haproxy_date_out_set(struct Curl_cfilter*cf, +static CURLcode cf_haproxy_date_out_set(struct Curl_cfilter *cf, struct Curl_easy *data) { struct cf_haproxy_ctx *ctx = cf->ctx; @@ -133,7 +126,7 @@ static CURLcode cf_haproxy_connect(struct Curl_cfilter *cf, if(len > 0) { size_t nwritten; result = Curl_conn_cf_send(cf->next, data, - curlx_dyn_ptr(&ctx->data_out), len, FALSE, + curlx_dyn_uptr(&ctx->data_out), len, FALSE, &nwritten); if(result) { if(result != CURLE_AGAIN) @@ -217,7 +210,7 @@ static CURLcode cf_haproxy_create(struct Curl_cfilter **pcf, CURLcode result; (void)data; - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { result = CURLE_OUT_OF_MEMORY; goto out; diff --git a/vendor/hydra/vendor/curl/lib/cf-haproxy.h b/vendor/hydra/vendor/curl/lib/cf-haproxy.h index 9190dd5b..6d67597c 100644 --- a/vendor/hydra/vendor/curl/lib/cf-haproxy.h +++ b/vendor/hydra/vendor/curl/lib/cf-haproxy.h @@ -23,8 +23,8 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" + #include "urldata.h" #ifndef CURL_DISABLE_PROXY diff --git a/vendor/hydra/vendor/curl/lib/cf-https-connect.c b/vendor/hydra/vendor/curl/lib/cf-https-connect.c index 5d6724db..d2a08d12 100644 --- a/vendor/hydra/vendor/curl/lib/cf-https-connect.c +++ b/vendor/hydra/vendor/curl/lib/cf-https-connect.c @@ -21,13 +21,11 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifndef CURL_DISABLE_HTTP #include "urldata.h" -#include #include "curl_trc.h" #include "cfilters.h" #include "connect.h" @@ -35,13 +33,10 @@ #include "multiif.h" #include "cf-https-connect.h" #include "http2.h" +#include "progress.h" #include "select.h" #include "vquic/vquic.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - typedef enum { CF_HC_INIT, CF_HC_CONNECT, @@ -55,7 +50,7 @@ struct cf_hc_baller { CURLcode result; struct curltime started; int reply_ms; - unsigned char transport; + uint8_t transport; enum alpnid alpn_id; BIT(shutdown); }; @@ -124,7 +119,7 @@ struct cf_hc_ctx { static void cf_hc_baller_assign(struct cf_hc_baller *b, enum alpnid alpn_id, - unsigned char def_transport) + uint8_t def_transport) { b->alpn_id = alpn_id; b->transport = def_transport; @@ -148,12 +143,12 @@ static void cf_hc_baller_assign(struct cf_hc_baller *b, static void cf_hc_baller_init(struct cf_hc_baller *b, struct Curl_cfilter *cf, struct Curl_easy *data, - int transport) + uint8_t transport) { struct Curl_cfilter *save = cf->next; cf->next = NULL; - b->started = curlx_now(); + b->started = *Curl_pgrs_now(data); switch(b->alpn_id) { case ALPN_h3: transport = TRNSPRT_QUIC; @@ -215,12 +210,13 @@ static CURLcode baller_connected(struct Curl_cfilter *cf, reply_ms = cf_hc_baller_reply_ms(winner, data); if(reply_ms >= 0) CURL_TRC_CF(data, cf, "connect+handshake %s: %dms, 1st data: %dms", - winner->name, (int)curlx_timediff(curlx_now(), - winner->started), reply_ms); + winner->name, + (int)curlx_ptimediff_ms(Curl_pgrs_now(data), + &winner->started), reply_ms); else CURL_TRC_CF(data, cf, "deferred handshake %s: %dms", - winner->name, (int)curlx_timediff(curlx_now(), - winner->started)); + winner->name, (int)curlx_ptimediff_ms(Curl_pgrs_now(data), + &winner->started)); /* install the winning filter below this one. */ cf->next = winner->cf; @@ -247,7 +243,6 @@ static CURLcode baller_connected(struct Curl_cfilter *cf, return result; } - static bool time_to_start_next(struct Curl_cfilter *cf, struct Curl_easy *data, size_t idx, struct curltime now) @@ -269,7 +264,7 @@ static bool time_to_start_next(struct Curl_cfilter *cf, ctx->ballers[idx].name); return TRUE; } - elapsed_ms = curlx_timediff(now, ctx->started); + elapsed_ms = curlx_ptimediff_ms(&now, &ctx->started); if(elapsed_ms >= ctx->hard_eyeballs_timeout_ms) { CURL_TRC_CF(data, cf, "hard timeout of %" FMT_TIMEDIFF_T "ms reached, " "starting %s", @@ -297,7 +292,6 @@ static CURLcode cf_hc_connect(struct Curl_cfilter *cf, bool *done) { struct cf_hc_ctx *ctx = cf->ctx; - struct curltime now; CURLcode result = CURLE_OK; size_t i, failed_ballers; @@ -307,14 +301,13 @@ static CURLcode cf_hc_connect(struct Curl_cfilter *cf, } *done = FALSE; - now = curlx_now(); switch(ctx->state) { case CF_HC_INIT: DEBUGASSERT(!cf->next); for(i = 0; i < ctx->baller_count; i++) DEBUGASSERT(!ctx->ballers[i].cf); CURL_TRC_CF(data, cf, "connect, init"); - ctx->started = now; + ctx->started = *Curl_pgrs_now(data); cf_hc_baller_init(&ctx->ballers[0], cf, data, ctx->ballers[0].transport); if(ctx->baller_count > 1) { Curl_expire(data, ctx->soft_eyeballs_timeout_ms, EXPIRE_ALPN_EYEBALLS); @@ -333,7 +326,7 @@ static CURLcode cf_hc_connect(struct Curl_cfilter *cf, } } - if(time_to_start_next(cf, data, 1, now)) { + if(time_to_start_next(cf, data, 1, *Curl_pgrs_now(data))) { cf_hc_baller_init(&ctx->ballers[1], cf, data, ctx->ballers[1].transport); } @@ -474,7 +467,7 @@ static struct curltime cf_get_max_baller_time(struct Curl_cfilter *cf, struct Curl_cfilter *cfb = ctx->ballers[i].cf; memset(&t, 0, sizeof(t)); if(cfb && !cfb->cft->query(cfb, data, query, NULL, &t)) { - if((t.tv_sec || t.tv_usec) && curlx_timediff_us(t, tmax) > 0) + if((t.tv_sec || t.tv_usec) && curlx_ptimediff_us(&t, &tmax) > 0) tmax = t; } } @@ -580,27 +573,29 @@ struct Curl_cftype Curl_cft_http_connect = { static CURLcode cf_hc_create(struct Curl_cfilter **pcf, struct Curl_easy *data, enum alpnid *alpnids, size_t alpn_count, - unsigned char def_transport) + uint8_t def_transport) { struct Curl_cfilter *cf = NULL; struct cf_hc_ctx *ctx; CURLcode result = CURLE_OK; size_t i; + ctx = curlx_calloc(1, sizeof(*ctx)); + if(!ctx) { + result = CURLE_OUT_OF_MEMORY; + goto out; + } + DEBUGASSERT(alpnids); DEBUGASSERT(alpn_count); DEBUGASSERT(alpn_count <= CURL_ARRAYSIZE(ctx->ballers)); if(!alpn_count || (alpn_count > CURL_ARRAYSIZE(ctx->ballers))) { failf(data, "https-connect filter create with unsupported %zu ALPN ids", alpn_count); - return CURLE_FAILED_INIT; - } - - ctx = calloc(1, sizeof(*ctx)); - if(!ctx) { - result = CURLE_OUT_OF_MEMORY; + result = CURLE_FAILED_INIT; goto out; } + for(i = 0; i < alpn_count; ++i) cf_hc_baller_assign(&ctx->ballers[i], alpnids[i], def_transport); for(; i < CURL_ARRAYSIZE(ctx->ballers); ++i) @@ -615,7 +610,7 @@ static CURLcode cf_hc_create(struct Curl_cfilter **pcf, out: *pcf = result ? NULL : cf; - free(ctx); + curlx_free(ctx); return result; } @@ -623,7 +618,7 @@ static CURLcode cf_http_connect_add(struct Curl_easy *data, struct connectdata *conn, int sockindex, enum alpnid *alpn_ids, size_t alpn_count, - unsigned char def_transport) + uint8_t def_transport) { struct Curl_cfilter *cf; CURLcode result = CURLE_OK; @@ -712,6 +707,31 @@ CURLcode Curl_cf_https_setup(struct Curl_easy *data, } #endif + /* Add preferred HTTP version ALPN first */ + if(data->state.http_neg.preferred && + (alpn_count < CURL_ARRAYSIZE(alpn_ids)) && + (data->state.http_neg.preferred & data->state.http_neg.allowed)) { + enum alpnid alpn_pref = ALPN_none; + switch(data->state.http_neg.preferred) { + case CURL_HTTP_V3x: + if(!Curl_conn_may_http3(data, conn, conn->transport_wanted)) + alpn_pref = ALPN_h3; + break; + case CURL_HTTP_V2x: + alpn_pref = ALPN_h2; + break; + case CURL_HTTP_V1x: + alpn_pref = ALPN_h1; + break; + default: + break; + } + if(alpn_pref && + !cf_https_alpns_contain(alpn_pref, alpn_ids, alpn_count)) { + alpn_ids[alpn_count++] = alpn_pref; + } + } + if((alpn_count < CURL_ARRAYSIZE(alpn_ids)) && (data->state.http_neg.wanted & CURL_HTTP_V3x) && !cf_https_alpns_contain(ALPN_h3, alpn_ids, alpn_count)) { diff --git a/vendor/hydra/vendor/curl/lib/cf-https-connect.h b/vendor/hydra/vendor/curl/lib/cf-https-connect.h index df51b624..df29c8dd 100644 --- a/vendor/hydra/vendor/curl/lib/cf-https-connect.h +++ b/vendor/hydra/vendor/curl/lib/cf-https-connect.h @@ -44,6 +44,5 @@ CURLcode Curl_cf_https_setup(struct Curl_easy *data, struct connectdata *conn, int sockindex); - #endif /* !CURL_DISABLE_HTTP */ #endif /* HEADER_CURL_CF_HTTP_H */ diff --git a/vendor/hydra/vendor/curl/lib/cf-ip-happy.c b/vendor/hydra/vendor/curl/lib/cf-ip-happy.c index 6b7130be..05e9505e 100644 --- a/vendor/hydra/vendor/curl/lib/cf-ip-happy.c +++ b/vendor/hydra/vendor/curl/lib/cf-ip-happy.c @@ -21,15 +21,11 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifdef HAVE_NETINET_IN_H #include /* may need it */ #endif -#ifdef HAVE_SYS_UN_H -#include /* for sockaddr_un */ -#endif #ifdef HAVE_LINUX_TCP_H #include #elif defined(HAVE_NETINET_TCP_H) @@ -60,13 +56,9 @@ #include "select.h" #include "vquic/vquic.h" /* for quic cfilters */ -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - struct transport_provider { - int transport; + uint8_t transport; cf_ip_connect_create *cf_create; }; @@ -87,7 +79,7 @@ struct transport_provider transport_providers[] = { #endif }; -static cf_ip_connect_create *get_cf_create(int transport) +static cf_ip_connect_create *get_cf_create(uint8_t transport) { size_t i; for(i = 0; i < CURL_ARRAYSIZE(transport_providers); ++i) { @@ -99,7 +91,7 @@ static cf_ip_connect_create *get_cf_create(int transport) #ifdef UNITTESTS /* used by unit2600.c */ -void Curl_debug_set_transport_provider(int transport, +void Curl_debug_set_transport_provider(uint8_t transport, cf_ip_connect_create *cf_create) { size_t i; @@ -112,7 +104,6 @@ void Curl_debug_set_transport_provider(int transport, } #endif /* UNITTESTS */ - struct cf_ai_iter { const struct Curl_addrinfo *head; const struct Curl_addrinfo *last; @@ -172,7 +163,7 @@ struct cf_ip_attempt { struct curltime started; /* start of current attempt */ CURLcode result; int ai_family; - int transport; + uint8_t transport; int error; BIT(connected); /* cf has connected */ BIT(shutdown); /* cf has shutdown */ @@ -186,7 +177,7 @@ static void cf_ip_attempt_free(struct cf_ip_attempt *a, if(a) { if(a->cf) Curl_conn_cf_discard_chain(&a->cf, data); - free(a); + curlx_free(a); } } @@ -195,7 +186,7 @@ static CURLcode cf_ip_attempt_new(struct cf_ip_attempt **pa, struct Curl_easy *data, const struct Curl_addrinfo *addr, int ai_family, - int transport, + uint8_t transport, cf_ip_connect_create *cf_create) { struct Curl_cfilter *wcf; @@ -203,7 +194,7 @@ static CURLcode cf_ip_attempt_new(struct cf_ip_attempt **pa, CURLcode result = CURLE_OK; *pa = NULL; - a = calloc(1, sizeof(*a)); + a = curlx_calloc(1, sizeof(*a)); if(!a) return CURLE_OUT_OF_MEMORY; @@ -237,7 +228,7 @@ static CURLcode cf_ip_attempt_connect(struct cf_ip_attempt *a, bool *connected) { *connected = a->connected; - if(!a->result && !*connected) { + if(!a->result && !*connected) { /* evaluate again */ a->result = Curl_conn_cf_connect(a->cf, data, connected); @@ -264,7 +255,7 @@ struct cf_ip_ballers { struct curltime last_attempt_started; timediff_t attempt_delay_ms; int last_attempt_ai_family; - int transport; + uint8_t transport; }; static CURLcode cf_ip_attempt_restart(struct cf_ip_attempt *a, @@ -315,7 +306,7 @@ static void cf_ip_ballers_clear(struct Curl_cfilter *cf, static CURLcode cf_ip_ballers_init(struct cf_ip_ballers *bs, int ip_version, const struct Curl_addrinfo *addr_list, cf_ip_connect_create *cf_create, - int transport, + uint8_t transport, timediff_t attempt_delay_ms) { memset(bs, 0, sizeof(*bs)); @@ -358,7 +349,6 @@ static CURLcode cf_ip_ballers_run(struct cf_ip_ballers *bs, CURLcode result = CURLE_OK; struct cf_ip_attempt *a = NULL, **panchor; bool do_more; - struct curltime now; timediff_t next_expire_ms; int i, inconclusive, ongoing; @@ -366,7 +356,6 @@ static CURLcode cf_ip_ballers_run(struct cf_ip_ballers *bs, return CURLE_OK; evaluate: - now = curlx_now(); ongoing = inconclusive = 0; /* check if a running baller connects now */ @@ -403,7 +392,7 @@ static CURLcode cf_ip_ballers_run(struct cf_ip_ballers *bs, /* no attempt connected yet, start another one? */ if(!ongoing) { if(!bs->started.tv_sec && !bs->started.tv_usec) - bs->started = now; + bs->started = *Curl_pgrs_now(data); do_more = TRUE; } else { @@ -413,8 +402,8 @@ static CURLcode cf_ip_ballers_run(struct cf_ip_ballers *bs, more_possible = cf_ai_iter_has_more(&bs->ipv6_iter); #endif do_more = more_possible && - (curlx_timediff(now, bs->last_attempt_started) >= - bs->attempt_delay_ms); + (curlx_ptimediff_ms(Curl_pgrs_now(data), &bs->last_attempt_started) >= + bs->attempt_delay_ms); if(do_more) CURL_TRC_CF(data, cf, "happy eyeballs timeout expired, " "start next attempt"); @@ -427,9 +416,9 @@ static CURLcode cf_ip_ballers_run(struct cf_ip_ballers *bs, int ai_family = 0; #ifdef USE_IPV6 if((bs->last_attempt_ai_family == AF_INET) || - !cf_ai_iter_has_more(&bs->addr_iter)) { - addr = cf_ai_iter_next(&bs->ipv6_iter); - ai_family = bs->ipv6_iter.ai_family; + !cf_ai_iter_has_more(&bs->addr_iter)) { + addr = cf_ai_iter_next(&bs->ipv6_iter); + ai_family = bs->ipv6_iter.ai_family; } #endif if(!addr) { @@ -452,7 +441,7 @@ static CURLcode cf_ip_ballers_run(struct cf_ip_ballers *bs, while(*panchor) panchor = &((*panchor)->next); *panchor = a; - bs->last_attempt_started = now; + bs->last_attempt_started = *Curl_pgrs_now(data); bs->last_attempt_ai_family = ai_family; /* and run everything again */ goto evaluate; @@ -460,7 +449,8 @@ static CURLcode cf_ip_ballers_run(struct cf_ip_ballers *bs, else if(inconclusive) { /* tried all addresses, no success but some where inconclusive. * Let's restart the inconclusive ones. */ - timediff_t since_ms = curlx_timediff(now, bs->last_attempt_started); + timediff_t since_ms = + curlx_ptimediff_ms(Curl_pgrs_now(data), &bs->last_attempt_started); timediff_t delay_ms = bs->attempt_delay_ms - since_ms; if(delay_ms <= 0) { CURL_TRC_CF(data, cf, "all attempts inconclusive, restarting one"); @@ -473,7 +463,7 @@ static CURLcode cf_ip_ballers_run(struct cf_ip_ballers *bs, CURL_TRC_CF(data, cf, "restarted baller %d -> %d", i, result); if(result) /* serious failure */ goto out; - bs->last_attempt_started = now; + bs->last_attempt_started = *Curl_pgrs_now(data); goto evaluate; } DEBUGASSERT(0); /* should not come here */ @@ -505,10 +495,11 @@ static CURLcode cf_ip_ballers_run(struct cf_ip_ballers *bs, bool more_possible; /* when do we need to be called again? */ - next_expire_ms = Curl_timeleft(data, &now, TRUE); + next_expire_ms = Curl_timeleft_ms(data, TRUE); if(next_expire_ms <= 0) { failf(data, "Connection timeout after %" FMT_OFF_T " ms", - curlx_timediff(now, data->progress.t_startsingle)); + curlx_ptimediff_ms(Curl_pgrs_now(data), + &data->progress.t_startsingle)); return CURLE_OPERATION_TIMEDOUT; } @@ -519,14 +510,15 @@ static CURLcode cf_ip_ballers_run(struct cf_ip_ballers *bs, #endif if(more_possible) { timediff_t expire_ms, elapsed_ms; - elapsed_ms = curlx_timediff(now, bs->last_attempt_started); + elapsed_ms = + curlx_ptimediff_ms(Curl_pgrs_now(data), &bs->last_attempt_started); expire_ms = CURLMAX(bs->attempt_delay_ms - elapsed_ms, 0); next_expire_ms = CURLMIN(next_expire_ms, expire_ms); if(next_expire_ms <= 0) { - CURL_TRC_CF(data, cf, "HAPPY_EYBALLS timeout due, re-evaluate"); + CURL_TRC_CF(data, cf, "HAPPY_EYEBALLS timeout due, re-evaluate"); goto evaluate; } - CURL_TRC_CF(data, cf, "next HAPPY_EYBALLS timeout in %" FMT_TIMEDIFF_T + CURL_TRC_CF(data, cf, "next HAPPY_EYEBALLS timeout in %" FMT_TIMEDIFF_T "ms", next_expire_ms); Curl_expire(data, next_expire_ms, EXPIRE_HAPPY_EYEBALLS); } @@ -595,7 +587,7 @@ static struct curltime cf_ip_ballers_max_time(struct cf_ip_ballers *bs, for(a = bs->running; a; a = a->next) { memset(&t, 0, sizeof(t)); if(!a->cf->cft->query(a->cf, data, query, NULL, &t)) { - if((t.tv_sec || t.tv_usec) && curlx_timediff_us(t, tmax) > 0) + if((t.tv_sec || t.tv_usec) && curlx_ptimediff_us(&t, &tmax) > 0) tmax = t; } } @@ -618,7 +610,6 @@ static int cf_ip_ballers_min_reply_ms(struct cf_ip_ballers *bs, return reply_ms; } - typedef enum { SCFST_INIT, SCFST_WAITING, @@ -626,14 +617,13 @@ typedef enum { } cf_connect_state; struct cf_ip_happy_ctx { - int transport; + uint8_t transport; cf_ip_connect_create *cf_create; cf_connect_state state; struct cf_ip_ballers ballers; struct curltime started; }; - static CURLcode is_connected(struct Curl_cfilter *cf, struct Curl_easy *data, bool *connected) @@ -682,7 +672,8 @@ static CURLcode is_connected(struct Curl_cfilter *cf, proxy_name ? "via " : "", proxy_name ? proxy_name : "", proxy_name ? " " : "", - curlx_timediff(curlx_now(), data->progress.t_startsingle), + curlx_ptimediff_ms(Curl_pgrs_now(data), + &data->progress.t_startsingle), curl_easy_strerror(result)); } @@ -707,14 +698,14 @@ static CURLcode start_connect(struct Curl_cfilter *cf, if(!dns) return CURLE_FAILED_INIT; - if(Curl_timeleft(data, NULL, TRUE) < 0) { + if(Curl_timeleft_ms(data, TRUE) < 0) { /* a precaution, no need to continue if time already is up */ failf(data, "Connection time-out"); return CURLE_OPERATION_TIMEDOUT; } - CURL_TRC_CF(data, cf, "init ip ballers for transport %d", ctx->transport); - ctx->started = curlx_now(); + CURL_TRC_CF(data, cf, "init ip ballers for transport %u", ctx->transport); + ctx->started = *Curl_pgrs_now(data); return cf_ip_ballers_init(&ctx->ballers, cf->conn->ip_version, dns->addr, ctx->cf_create, ctx->transport, data->set.happy_eyeballs_timeout); @@ -778,50 +769,50 @@ static CURLcode cf_ip_happy_connect(struct Curl_cfilter *cf, *done = FALSE; switch(ctx->state) { - case SCFST_INIT: - DEBUGASSERT(CURL_SOCKET_BAD == Curl_conn_cf_get_socket(cf, data)); - DEBUGASSERT(!cf->connected); - result = start_connect(cf, data); - if(result) - return result; - ctx->state = SCFST_WAITING; - FALLTHROUGH(); - case SCFST_WAITING: - result = is_connected(cf, data, done); - if(!result && *done) { - DEBUGASSERT(ctx->ballers.winner); - DEBUGASSERT(ctx->ballers.winner->cf); - DEBUGASSERT(ctx->ballers.winner->cf->connected); - /* we have a winner. Install and activate it. - * close/free all others. */ - ctx->state = SCFST_DONE; - cf->connected = TRUE; - cf->next = ctx->ballers.winner->cf; - ctx->ballers.winner->cf = NULL; - cf_ip_happy_ctx_clear(cf, data); - Curl_expire_done(data, EXPIRE_HAPPY_EYEBALLS); - - if(cf->conn->handler->protocol & PROTO_FAMILY_SSH) - Curl_pgrsTime(data, TIMER_APPCONNECT); /* we are connected already */ + case SCFST_INIT: + DEBUGASSERT(CURL_SOCKET_BAD == Curl_conn_cf_get_socket(cf, data)); + DEBUGASSERT(!cf->connected); + result = start_connect(cf, data); + if(result) + return result; + ctx->state = SCFST_WAITING; + FALLTHROUGH(); + case SCFST_WAITING: + result = is_connected(cf, data, done); + if(!result && *done) { + DEBUGASSERT(ctx->ballers.winner); + DEBUGASSERT(ctx->ballers.winner->cf); + DEBUGASSERT(ctx->ballers.winner->cf->connected); + /* we have a winner. Install and activate it. + * close/free all others. */ + ctx->state = SCFST_DONE; + cf->connected = TRUE; + cf->next = ctx->ballers.winner->cf; + ctx->ballers.winner->cf = NULL; + cf_ip_happy_ctx_clear(cf, data); + Curl_expire_done(data, EXPIRE_HAPPY_EYEBALLS); + + if(cf->conn->handler->protocol & PROTO_FAMILY_SSH) + Curl_pgrsTime(data, TIMER_APPCONNECT); /* we are connected already */ #ifndef CURL_DISABLE_VERBOSE_STRINGS - if(Curl_trc_cf_is_verbose(cf, data)) { - struct ip_quadruple ipquad; - bool is_ipv6; - if(!Curl_conn_cf_get_ip_info(cf->next, data, &is_ipv6, &ipquad)) { - const char *host; - int port; - Curl_conn_get_current_host(data, cf->sockindex, &host, &port); - CURL_TRC_CF(data, cf, "Connected to %s (%s) port %u", - host, ipquad.remote_ip, ipquad.remote_port); - } + if(Curl_trc_cf_is_verbose(cf, data)) { + struct ip_quadruple ipquad; + bool is_ipv6; + if(!Curl_conn_cf_get_ip_info(cf->next, data, &is_ipv6, &ipquad)) { + const char *host; + int port; + Curl_conn_get_current_host(data, cf->sockindex, &host, &port); + CURL_TRC_CF(data, cf, "Connected to %s (%s) port %u", + host, ipquad.remote_ip, ipquad.remote_port); } -#endif - data->info.numconnects++; /* to track the # of connections made */ } - break; - case SCFST_DONE: - *done = TRUE; - break; +#endif + data->info.numconnects++; /* to track the # of connections made */ + } + break; + case SCFST_DONE: + *done = TRUE; + break; } return result; } @@ -933,7 +924,7 @@ static CURLcode cf_ip_happy_create(struct Curl_cfilter **pcf, struct Curl_easy *data, struct connectdata *conn, cf_ip_connect_create *cf_create, - int transport) + uint8_t transport) { struct cf_ip_happy_ctx *ctx = NULL; CURLcode result; @@ -941,7 +932,7 @@ static CURLcode cf_ip_happy_create(struct Curl_cfilter **pcf, (void)data; (void)conn; *pcf = NULL; - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -954,14 +945,14 @@ static CURLcode cf_ip_happy_create(struct Curl_cfilter **pcf, out: if(result) { Curl_safefree(*pcf); - free(ctx); + curlx_free(ctx); } return result; } CURLcode cf_ip_happy_insert_after(struct Curl_cfilter *cf_at, struct Curl_easy *data, - int transport) + uint8_t transport) { cf_ip_connect_create *cf_create; struct Curl_cfilter *cf; @@ -971,7 +962,7 @@ CURLcode cf_ip_happy_insert_after(struct Curl_cfilter *cf_at, DEBUGASSERT(cf_at); cf_create = get_cf_create(transport); if(!cf_create) { - CURL_TRC_CF(data, cf_at, "unsupported transport type %d", transport); + CURL_TRC_CF(data, cf_at, "unsupported transport type %u", transport); return CURLE_UNSUPPORTED_PROTOCOL; } result = cf_ip_happy_create(&cf, data, cf_at->conn, cf_create, transport); diff --git a/vendor/hydra/vendor/curl/lib/cf-ip-happy.h b/vendor/hydra/vendor/curl/lib/cf-ip-happy.h index 96e619ae..71f21225 100644 --- a/vendor/hydra/vendor/curl/lib/cf-ip-happy.h +++ b/vendor/hydra/vendor/curl/lib/cf-ip-happy.h @@ -25,9 +25,6 @@ ***************************************************************************/ #include "curl_setup.h" -#include "curlx/nonblock.h" /* for curlx_nonblock() */ -#include "sockaddr.h" - /** * Create a cfilter for making an "ip" connection to the * given address, using parameters from `conn`. The "ip" connection @@ -43,16 +40,16 @@ typedef CURLcode cf_ip_connect_create(struct Curl_cfilter **pcf, struct Curl_easy *data, struct connectdata *conn, const struct Curl_addrinfo *ai, - int transport); + uint8_t transport); CURLcode cf_ip_happy_insert_after(struct Curl_cfilter *cf_at, struct Curl_easy *data, - int transport); + uint8_t transport); extern struct Curl_cftype Curl_cft_ip_happy; #ifdef UNITTESTS -void Curl_debug_set_transport_provider(int transport, +void Curl_debug_set_transport_provider(uint8_t transport, cf_ip_connect_create *cf_create); #endif diff --git a/vendor/hydra/vendor/curl/lib/cf-socket.c b/vendor/hydra/vendor/curl/lib/cf-socket.c index 92fe433a..ce728f5b 100644 --- a/vendor/hydra/vendor/curl/lib/cf-socket.c +++ b/vendor/hydra/vendor/curl/lib/cf-socket.c @@ -21,15 +21,11 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifdef HAVE_NETINET_IN_H #include /* may need it */ #endif -#ifdef HAVE_SYS_UN_H -#include /* for sockaddr_un */ -#endif #ifdef HAVE_LINUX_TCP_H #include #elif defined(HAVE_NETINET_TCP_H) @@ -60,61 +56,41 @@ #include "urldata.h" #include "bufq.h" -#include "sendf.h" +#include "curl_trc.h" #include "if2ip.h" #include "cfilters.h" #include "cf-socket.h" #include "connect.h" #include "select.h" -#include "url.h" /* for Curl_safefree() */ #include "multiif.h" -#include "sockaddr.h" /* required for Curl_sockaddr_storage */ #include "curlx/inet_pton.h" #include "progress.h" -#include "curlx/warnless.h" #include "conncache.h" #include "multihandle.h" #include "rand.h" -#include "share.h" #include "strdup.h" #include "system_win32.h" +#include "curlx/nonblock.h" #include "curlx/version_win32.h" #include "curlx/strerr.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - - -#if defined(USE_IPV6) && defined(IPV6_V6ONLY) && defined(_WIN32) -/* It makes support for IPv4-mapped IPv6 addresses. - * Linux kernel, NetBSD, FreeBSD and Darwin: default is off; - * Windows Vista and later: default is on; - * DragonFly BSD: acts like off, and dummy setting; - * OpenBSD and earlier Windows: unsupported. - * Linux: controlled by /proc/sys/net/ipv6/bindv6only. - */ -static void set_ipv6_v6only(curl_socket_t sockfd, int on) -{ - (void)setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&on, sizeof(on)); -} -#else -#define set_ipv6_v6only(x,y) -#endif -static void tcpnodelay(struct Curl_easy *data, curl_socket_t sockfd) +static void tcpnodelay(struct Curl_cfilter *cf, + struct Curl_easy *data, + curl_socket_t sockfd) { #if defined(TCP_NODELAY) && defined(CURL_TCP_NODELAY_SUPPORTED) - curl_socklen_t onoff = (curl_socklen_t) 1; + curl_socklen_t onoff = (curl_socklen_t)1; int level = IPPROTO_TCP; char buffer[STRERROR_LEN]; if(setsockopt(sockfd, level, TCP_NODELAY, (void *)&onoff, sizeof(onoff)) < 0) - infof(data, "Could not set TCP_NODELAY: %s", - curlx_strerror(SOCKERRNO, buffer, sizeof(buffer))); + CURL_TRC_CF(data, cf, "Could not set TCP_NODELAY: %s", + curlx_strerror(SOCKERRNO, buffer, sizeof(buffer))); #else + (void)cf; (void)data; (void)sockfd; #endif @@ -125,31 +101,28 @@ static void tcpnodelay(struct Curl_easy *data, curl_socket_t sockfd) sending data to a dead peer (instead of relying on the 4th argument to send being MSG_NOSIGNAL). Possibly also existing and in use on other BSD systems? */ -static void nosigpipe(struct Curl_easy *data, +static void nosigpipe(struct Curl_cfilter *cf, + struct Curl_easy *data, curl_socket_t sockfd) { int onoff = 1; - (void)data; if(setsockopt(sockfd, SOL_SOCKET, SO_NOSIGPIPE, (void *)&onoff, sizeof(onoff)) < 0) { #ifndef CURL_DISABLE_VERBOSE_STRINGS char buffer[STRERROR_LEN]; - infof(data, "Could not set SO_NOSIGPIPE: %s", - curlx_strerror(SOCKERRNO, buffer, sizeof(buffer))); + CURL_TRC_CF(data, cf, "Could not set SO_NOSIGPIPE: %s", + curlx_strerror(SOCKERRNO, buffer, sizeof(buffer))); +#else + (void)cf; + (void)data; #endif } } #else -#define nosigpipe(x,y) Curl_nop_stmt +#define nosigpipe(x, y, z) Curl_nop_stmt #endif -#if defined(USE_WINSOCK) && \ - defined(TCP_KEEPIDLE) && defined(TCP_KEEPINTVL) && defined(TCP_KEEPCNT) -/* Win 10, v 1709 (10.0.16299) and later can use SetSockOpt TCP_KEEP____ - * so should use seconds */ -#define CURL_WINSOCK_KEEP_SSO -#define KEEPALIVE_FACTOR(x) -#elif defined(USE_WINSOCK) || \ +#if defined(USE_WINSOCK) || \ (defined(__sun) && !defined(TCP_KEEPIDLE)) || \ (defined(__DragonFly__) && __DragonFly_version < 500702) || \ (defined(_WIN32) && !defined(TCP_KEEPIDLE)) @@ -160,82 +133,91 @@ static void nosigpipe(struct Curl_easy *data, #define KEEPALIVE_FACTOR(x) #endif -/* Offered by mingw-w64 and MS SDK. Latter only when targeting Win7+. */ -#if defined(USE_WINSOCK) && !defined(SIO_KEEPALIVE_VALS) -#define SIO_KEEPALIVE_VALS _WSAIOW(IOC_VENDOR,4) - -struct tcp_keepalive { - u_long onoff; - u_long keepalivetime; - u_long keepaliveinterval; -}; -#endif - -static void -tcpkeepalive(struct Curl_easy *data, - curl_socket_t sockfd) +static void tcpkeepalive(struct Curl_cfilter *cf, + struct Curl_easy *data, + curl_socket_t sockfd) { int optval = data->set.tcp_keepalive ? 1 : 0; /* only set IDLE and INTVL if setting KEEPALIVE is successful */ if(setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, (void *)&optval, sizeof(optval)) < 0) { - infof(data, "Failed to set SO_KEEPALIVE on fd " - "%" FMT_SOCKET_T ": errno %d", - sockfd, SOCKERRNO); + CURL_TRC_CF(data, cf, "Failed to set SO_KEEPALIVE on fd " + "%" FMT_SOCKET_T ": errno %d", sockfd, SOCKERRNO); } else { -#ifdef SIO_KEEPALIVE_VALS /* Windows */ -/* Windows 10, version 1709 (10.0.16299) and later versions */ -#ifdef CURL_WINSOCK_KEEP_SSO - optval = curlx_sltosi(data->set.tcp_keepidle); - KEEPALIVE_FACTOR(optval); - if(setsockopt(sockfd, IPPROTO_TCP, TCP_KEEPIDLE, - (const char *)&optval, sizeof(optval)) < 0) { - infof(data, "Failed to set TCP_KEEPIDLE on fd " - "%" FMT_SOCKET_T ": errno %d", - sockfd, SOCKERRNO); - } - optval = curlx_sltosi(data->set.tcp_keepintvl); - KEEPALIVE_FACTOR(optval); - if(setsockopt(sockfd, IPPROTO_TCP, TCP_KEEPINTVL, - (const char *)&optval, sizeof(optval)) < 0) { - infof(data, "Failed to set TCP_KEEPINTVL on fd " - "%" FMT_SOCKET_T ": errno %d", - sockfd, SOCKERRNO); - } - optval = curlx_sltosi(data->set.tcp_keepcnt); - if(setsockopt(sockfd, IPPROTO_TCP, TCP_KEEPCNT, - (const char *)&optval, sizeof(optval)) < 0) { - infof(data, "Failed to set TCP_KEEPCNT on fd " - "%" FMT_SOCKET_T ": errno %d", - sockfd, SOCKERRNO); +#ifdef USE_WINSOCK + /* Windows 10, version 1709 (10.0.16299) and later versions can use + setsockopt() TCP_KEEP*. Older versions return with failure. */ + if(curlx_verify_windows_version(10, 0, 16299, PLATFORM_WINNT, + VERSION_GREATER_THAN_EQUAL)) { + CURL_TRC_CF(data, cf, "Set TCP_KEEP* on fd=%" FMT_SOCKET_T, sockfd); + optval = curlx_sltosi(data->set.tcp_keepidle); +/* Offered by mingw-w64 v12+. MS SDK 6.0A+. */ +#ifndef TCP_KEEPALIVE +#define TCP_KEEPALIVE 3 +#endif +/* Offered by mingw-w64 v12+. MS SDK ~10+/~VS2017+. */ +#ifndef TCP_KEEPCNT +#define TCP_KEEPCNT 16 +#endif +#ifndef TCP_KEEPIDLE +#define TCP_KEEPIDLE TCP_KEEPALIVE +#endif +#ifndef TCP_KEEPINTVL +#define TCP_KEEPINTVL 17 +#endif + if(setsockopt(sockfd, IPPROTO_TCP, TCP_KEEPIDLE, + (const char *)&optval, sizeof(optval)) < 0) { + CURL_TRC_CF(data, cf, "Failed to set TCP_KEEPIDLE on fd " + "%" FMT_SOCKET_T ": errno %d", sockfd, SOCKERRNO); + } + optval = curlx_sltosi(data->set.tcp_keepintvl); + if(setsockopt(sockfd, IPPROTO_TCP, TCP_KEEPINTVL, + (const char *)&optval, sizeof(optval)) < 0) { + CURL_TRC_CF(data, cf, "Failed to set TCP_KEEPINTVL on fd " + "%" FMT_SOCKET_T ": errno %d", sockfd, SOCKERRNO); + } + optval = curlx_sltosi(data->set.tcp_keepcnt); + if(setsockopt(sockfd, IPPROTO_TCP, TCP_KEEPCNT, + (const char *)&optval, sizeof(optval)) < 0) { + CURL_TRC_CF(data, cf, "Failed to set TCP_KEEPCNT on fd " + "%" FMT_SOCKET_T ": errno %d", sockfd, SOCKERRNO); + } } -#else /* Windows < 10.0.16299 */ - struct tcp_keepalive vals; - DWORD dummy; - vals.onoff = 1; - optval = curlx_sltosi(data->set.tcp_keepidle); - KEEPALIVE_FACTOR(optval); - vals.keepalivetime = (u_long)optval; - optval = curlx_sltosi(data->set.tcp_keepintvl); - KEEPALIVE_FACTOR(optval); - vals.keepaliveinterval = (u_long)optval; - if(WSAIoctl(sockfd, SIO_KEEPALIVE_VALS, (LPVOID) &vals, sizeof(vals), - NULL, 0, &dummy, NULL, NULL) != 0) { - infof(data, "Failed to set SIO_KEEPALIVE_VALS on fd " - "%" FMT_SOCKET_T ": errno %d", sockfd, SOCKERRNO); + else { +/* Offered by mingw-w64 and MS SDK. Latter only when targeting Win7+. */ +#ifndef SIO_KEEPALIVE_VALS +#define SIO_KEEPALIVE_VALS _WSAIOW(IOC_VENDOR, 4) + struct tcp_keepalive { + u_long onoff; + u_long keepalivetime; + u_long keepaliveinterval; + }; +#endif + struct tcp_keepalive vals; + DWORD dummy; + vals.onoff = 1; + optval = curlx_sltosi(data->set.tcp_keepidle); + KEEPALIVE_FACTOR(optval); + vals.keepalivetime = (u_long)optval; + optval = curlx_sltosi(data->set.tcp_keepintvl); + KEEPALIVE_FACTOR(optval); + vals.keepaliveinterval = (u_long)optval; + if(WSAIoctl(sockfd, SIO_KEEPALIVE_VALS, (LPVOID)&vals, sizeof(vals), + NULL, 0, &dummy, NULL, NULL) != 0) { + CURL_TRC_CF(data, cf, "Failed to set SIO_KEEPALIVE_VALS on fd " + "%" FMT_SOCKET_T ": errno %d", sockfd, SOCKERRNO); + } } -#endif -#else /* !Windows */ +#else /* !USE_WINSOCK */ #ifdef TCP_KEEPIDLE optval = curlx_sltosi(data->set.tcp_keepidle); KEEPALIVE_FACTOR(optval); if(setsockopt(sockfd, IPPROTO_TCP, TCP_KEEPIDLE, (void *)&optval, sizeof(optval)) < 0) { - infof(data, "Failed to set TCP_KEEPIDLE on fd " - "%" FMT_SOCKET_T ": errno %d", - sockfd, SOCKERRNO); + CURL_TRC_CF(data, cf, "Failed to set TCP_KEEPIDLE on fd " + "%" FMT_SOCKET_T ": errno %d", sockfd, SOCKERRNO); } #elif defined(TCP_KEEPALIVE) /* macOS style */ @@ -243,9 +225,8 @@ tcpkeepalive(struct Curl_easy *data, KEEPALIVE_FACTOR(optval); if(setsockopt(sockfd, IPPROTO_TCP, TCP_KEEPALIVE, (void *)&optval, sizeof(optval)) < 0) { - infof(data, "Failed to set TCP_KEEPALIVE on fd " - "%" FMT_SOCKET_T ": errno %d", - sockfd, SOCKERRNO); + CURL_TRC_CF(data, cf, "Failed to set TCP_KEEPALIVE on fd " + "%" FMT_SOCKET_T ": errno %d", sockfd, SOCKERRNO); } #elif defined(TCP_KEEPALIVE_THRESHOLD) /* Solaris <11.4 style */ @@ -253,9 +234,8 @@ tcpkeepalive(struct Curl_easy *data, KEEPALIVE_FACTOR(optval); if(setsockopt(sockfd, IPPROTO_TCP, TCP_KEEPALIVE_THRESHOLD, (void *)&optval, sizeof(optval)) < 0) { - infof(data, "Failed to set TCP_KEEPALIVE_THRESHOLD on fd " - "%" FMT_SOCKET_T ": errno %d", - sockfd, SOCKERRNO); + CURL_TRC_CF(data, cf, "Failed to set TCP_KEEPALIVE_THRESHOLD on fd " + "%" FMT_SOCKET_T ": errno %d", sockfd, SOCKERRNO); } #endif #ifdef TCP_KEEPINTVL @@ -263,9 +243,8 @@ tcpkeepalive(struct Curl_easy *data, KEEPALIVE_FACTOR(optval); if(setsockopt(sockfd, IPPROTO_TCP, TCP_KEEPINTVL, (void *)&optval, sizeof(optval)) < 0) { - infof(data, "Failed to set TCP_KEEPINTVL on fd " - "%" FMT_SOCKET_T ": errno %d", - sockfd, SOCKERRNO); + CURL_TRC_CF(data, cf, "Failed to set TCP_KEEPINTVL on fd " + "%" FMT_SOCKET_T ": errno %d", sockfd, SOCKERRNO); } #elif defined(TCP_KEEPALIVE_ABORT_THRESHOLD) /* Solaris <11.4 style */ @@ -284,19 +263,19 @@ tcpkeepalive(struct Curl_easy *data, KEEPALIVE_FACTOR(optval); if(setsockopt(sockfd, IPPROTO_TCP, TCP_KEEPALIVE_ABORT_THRESHOLD, (void *)&optval, sizeof(optval)) < 0) { - infof(data, "Failed to set TCP_KEEPALIVE_ABORT_THRESHOLD on fd " - "%" FMT_SOCKET_T ": errno %d", sockfd, SOCKERRNO); + CURL_TRC_CF(data, cf, "Failed to set TCP_KEEPALIVE_ABORT_THRESHOLD" + " on fd %" FMT_SOCKET_T ": errno %d", sockfd, SOCKERRNO); } #endif #ifdef TCP_KEEPCNT optval = curlx_sltosi(data->set.tcp_keepcnt); if(setsockopt(sockfd, IPPROTO_TCP, TCP_KEEPCNT, (void *)&optval, sizeof(optval)) < 0) { - infof(data, "Failed to set TCP_KEEPCNT on fd " - "%" FMT_SOCKET_T ": errno %d", sockfd, SOCKERRNO); + CURL_TRC_CF(data, cf, "Failed to set TCP_KEEPCNT on fd " + "%" FMT_SOCKET_T ": errno %d", sockfd, SOCKERRNO); } #endif -#endif +#endif /* USE_WINSOCK */ } } @@ -306,7 +285,7 @@ tcpkeepalive(struct Curl_easy *data, */ static CURLcode sock_assign_addr(struct Curl_sockaddr_ex *dest, const struct Curl_addrinfo *ai, - int transport) + uint8_t transport) { /* * The Curl_sockaddr_ex structure is basically libcurl's external API @@ -349,15 +328,15 @@ static CURLcode socket_open(struct Curl_easy *data, DEBUGASSERT(data); DEBUGASSERT(data->conn); if(data->set.fopensocket) { - /* - * If the opensocket callback is set, all the destination address - * information is passed to the callback. Depending on this information the - * callback may opt to abort the connection, this is indicated returning - * CURL_SOCKET_BAD; otherwise it will return a not-connected socket. When - * the callback returns a valid socket the destination address information - * might have been changed and this 'new' address will actually be used - * here to connect. - */ + /* + * If the opensocket callback is set, all the destination address + * information is passed to the callback. Depending on this information the + * callback may opt to abort the connection, this is indicated returning + * CURL_SOCKET_BAD; otherwise it will return a not-connected socket. When + * the callback returns a valid socket the destination address information + * might have been changed and this 'new' address will actually be used + * here to connect. + */ Curl_set_in_callback(data, TRUE); *sockfd = data->set.fopensocket(data->set.opensocket_client, CURLSOCKTYPE_IPCXN, @@ -367,6 +346,8 @@ static CURLcode socket_open(struct Curl_easy *data, else { /* opensocket callback not set, so simply create the socket now */ *sockfd = CURL_SOCKET(addr->family, addr->socktype, addr->protocol); + if((*sockfd == CURL_SOCKET_BAD) && (SOCKERRNO == SOCKENOMEM)) + return CURLE_OUT_OF_MEMORY; } if(*sockfd == CURL_SOCKET_BAD) { @@ -407,7 +388,7 @@ static CURLcode socket_open(struct Curl_easy *data, CURLcode Curl_socket_open(struct Curl_easy *data, const struct Curl_addrinfo *ai, struct Curl_sockaddr_ex *addr, - int transport, + uint8_t transport, curl_socket_t *sockfd) { struct Curl_sockaddr_ex dummy; @@ -558,7 +539,7 @@ CURLcode Curl_parse_interface(const char *input, ++host_part; *host = Curl_memdup0(host_part, len - (host_part - input)); if(!*host) { - free(*iface); + curlx_free(*iface); *iface = NULL; return CURLE_OUT_OF_MEMORY; } @@ -607,7 +588,7 @@ static CURLcode bindlocal(struct Curl_easy *data, struct connectdata *conn, if(!iface && !host && !port) /* no local kind of binding was requested */ return CURLE_OK; - else if(iface && (strlen(iface) >= 255) ) + else if(iface && (strlen(iface) >= 255)) return CURLE_BAD_FUNCTION_ARGUMENT; memset(&sa, 0, sizeof(struct Curl_sockaddr_storage)); @@ -647,33 +628,33 @@ static CURLcode bindlocal(struct Curl_easy *data, struct connectdata *conn, /* Discover IP from input device, then bind to it */ if2ip_result = Curl_if2ip(af, #ifdef USE_IPV6 - scope, conn->scope_id, + scope, conn->scope_id, #endif - iface, myhost, sizeof(myhost)); + iface, myhost, sizeof(myhost)); } switch(if2ip_result) { - case IF2IP_NOT_FOUND: - if(iface_input && !host_input) { - /* Do not fall back to treating it as a hostname */ - char buffer[STRERROR_LEN]; - data->state.os_errno = error = SOCKERRNO; - failf(data, "Couldn't bind to interface '%s' with errno %d: %s", - iface, error, curlx_strerror(error, buffer, sizeof(buffer))); - return CURLE_INTERFACE_FAILED; - } - break; - case IF2IP_AF_NOT_SUPPORTED: - /* Signal the caller to try another address family if available */ - return CURLE_UNSUPPORTED_PROTOCOL; - case IF2IP_FOUND: - /* - * We now have the numerical IP address in the 'myhost' buffer - */ - host = myhost; - infof(data, "Local Interface %s is ip %s using address family %i", - iface, host, af); - done = 1; - break; + case IF2IP_NOT_FOUND: + if(iface_input && !host_input) { + /* Do not fall back to treating it as a hostname */ + char buffer[STRERROR_LEN]; + data->state.os_errno = error = SOCKERRNO; + failf(data, "Could not bind to interface '%s' with errno %d: %s", + iface, error, curlx_strerror(error, buffer, sizeof(buffer))); + return CURLE_INTERFACE_FAILED; + } + break; + case IF2IP_AF_NOT_SUPPORTED: + /* Signal the caller to try another address family if available */ + return CURLE_UNSUPPORTED_PROTOCOL; + case IF2IP_FOUND: + /* + * We now have the numerical IP address in the 'myhost' buffer + */ + host = myhost; + infof(data, "Local Interface %s is ip %s using address family %i", + iface, host, af); + done = 1; + break; } if(!iface_input || host_input) { /* @@ -735,7 +716,7 @@ static CURLcode bindlocal(struct Curl_easy *data, struct connectdata *conn, present, is known to be numeric */ curl_off_t scope_id; if(curlx_str_number((const char **)CURL_UNCONST(&scope_ptr), - &scope_id, UINT_MAX)) + &scope_id, UINT_MAX)) return CURLE_UNSUPPORTED_PROTOCOL; si6->sin6_scope_id = (unsigned int)scope_id; } @@ -761,7 +742,7 @@ static CURLcode bindlocal(struct Curl_easy *data, struct connectdata *conn, char buffer[STRERROR_LEN]; data->state.errorbuf = FALSE; data->state.os_errno = error = SOCKERRNO; - failf(data, "Couldn't bind to '%s' with errno %d: %s", host, + failf(data, "Could not bind to '%s' with errno %d: %s", host, error, curlx_strerror(error, buffer, sizeof(buffer))); return CURLE_INTERFACE_FAILED; } @@ -846,24 +827,11 @@ static bool verifyconnect(curl_socket_t sockfd, int *error) * * Someone got to verify this on Win-NT 4.0, 2000." */ - -#ifdef UNDER_CE - Sleep(0); -#else SleepEx(0, FALSE); -#endif - #endif if(getsockopt(sockfd, SOL_SOCKET, SO_ERROR, (void *)&err, &errSize)) err = SOCKERRNO; -#ifdef UNDER_CE - /* Old Windows CE versions do not support SO_ERROR */ - if(WSAENOPROTOOPT == err) { - SET_SOCKERRNO(0); - err = 0; - } -#endif #if defined(EBADIOCTL) && defined(__minix) /* Minix 3.1.x does not support getsockopt on UDP sockets */ if(EBADIOCTL == err) { @@ -925,7 +893,7 @@ static CURLcode socket_connect_result(struct Curl_easy *data, } struct cf_socket_ctx { - int transport; + uint8_t transport; struct Curl_sockaddr_ex addr; /* address to connect to */ curl_socket_t sock; /* current attempt socket */ struct ip_quadruple ip; /* The IP quadruple 2x(addr+port) */ @@ -941,7 +909,7 @@ struct cf_socket_ctx { int wblock_percent; /* percent of writes doing EAGAIN */ int wpartial_percent; /* percent of bytes written in send */ int rblock_percent; /* percent of reads doing EAGAIN */ - size_t recv_max; /* max enforced read size */ + size_t recv_max; /* max enforced read size */ #endif BIT(got_first_byte); /* if first byte was received */ BIT(listening); /* socket is listening */ @@ -952,7 +920,7 @@ struct cf_socket_ctx { static CURLcode cf_socket_ctx_init(struct cf_socket_ctx *ctx, const struct Curl_addrinfo *ai, - int transport) + uint8_t transport) { CURLcode result; @@ -1042,7 +1010,7 @@ static void cf_socket_destroy(struct Curl_cfilter *cf, struct Curl_easy *data) cf_socket_close(cf, data); CURL_TRC_CF(data, cf, "destroy"); - free(ctx); + curlx_free(ctx); cf->ctx = NULL; } @@ -1051,7 +1019,7 @@ static void set_local_ip(struct Curl_cfilter *cf, { struct cf_socket_ctx *ctx = cf->ctx; ctx->ip.local_ip[0] = 0; - ctx->ip.local_port = -1; + ctx->ip.local_port = 0; #ifdef HAVE_GETSOCKNAME if((ctx->sock != CURL_SOCKET_BAD) && @@ -1063,12 +1031,12 @@ static void set_local_ip(struct Curl_cfilter *cf, curl_socklen_t slen = sizeof(struct Curl_sockaddr_storage); memset(&ssloc, 0, sizeof(ssloc)); - if(getsockname(ctx->sock, (struct sockaddr*) &ssloc, &slen)) { + if(getsockname(ctx->sock, (struct sockaddr *)&ssloc, &slen)) { int error = SOCKERRNO; infof(data, "getsockname() failed with errno %d: %s", error, curlx_strerror(error, buffer, sizeof(buffer))); } - else if(!Curl_addr2string((struct sockaddr*)&ssloc, slen, + else if(!Curl_addr2string((struct sockaddr *)&ssloc, slen, ctx->ip.local_ip, &ctx->ip.local_port)) { infof(data, "ssloc inet_ntop() failed with errno %d: %s", errno, curlx_strerror(errno, buffer, sizeof(buffer))); @@ -1085,6 +1053,7 @@ static CURLcode set_remote_ip(struct Curl_cfilter *cf, struct cf_socket_ctx *ctx = cf->ctx; /* store remote address and port used in this connection attempt */ + ctx->ip.transport = ctx->transport; if(!Curl_addr2string(&ctx->addr.curl_sa_addr, (curl_socklen_t)ctx->addr.addrlen, ctx->ip.remote_ip, &ctx->ip.remote_port)) { @@ -1110,7 +1079,7 @@ static CURLcode cf_socket_open(struct Curl_cfilter *cf, (void)data; DEBUGASSERT(ctx->sock == CURL_SOCKET_BAD); - ctx->started_at = curlx_now(); + ctx->started_at = *Curl_pgrs_now(data); #ifdef SOCK_NONBLOCK /* Do not tuck SOCK_NONBLOCK into socktype when opensocket callback is set * because we would not know how socketype is about to be used in the @@ -1134,7 +1103,18 @@ static CURLcode cf_socket_open(struct Curl_cfilter *cf, #ifdef USE_IPV6 if(ctx->addr.family == AF_INET6) { - set_ipv6_v6only(ctx->sock, 0); +#ifdef USE_WINSOCK + /* Turn on support for IPv4-mapped IPv6 addresses. + * Linux kernel, NetBSD, FreeBSD, Darwin, lwIP: default is off; + * Windows Vista and later: default is on; + * DragonFly BSD: acts like off, and dummy setting; + * OpenBSD and earlier Windows: unsupported. + * Linux: controlled by /proc/sys/net/ipv6/bindv6only. + */ + int on = 0; + (void)setsockopt(ctx->sock, IPPROTO_IPV6, IPV6_V6ONLY, + (void *)&on, sizeof(on)); +#endif infof(data, " Trying [%s]:%d...", ctx->ip.remote_ip, ctx->ip.remote_port); } else @@ -1142,22 +1122,22 @@ static CURLcode cf_socket_open(struct Curl_cfilter *cf, infof(data, " Trying %s:%d...", ctx->ip.remote_ip, ctx->ip.remote_port); #ifdef USE_IPV6 - is_tcp = (ctx->addr.family == AF_INET - || ctx->addr.family == AF_INET6) && + is_tcp = (ctx->addr.family == AF_INET || + ctx->addr.family == AF_INET6) && ctx->addr.socktype == SOCK_STREAM; #else is_tcp = (ctx->addr.family == AF_INET) && ctx->addr.socktype == SOCK_STREAM; #endif if(is_tcp && data->set.tcp_nodelay) - tcpnodelay(data, ctx->sock); + tcpnodelay(cf, data, ctx->sock); - nosigpipe(data, ctx->sock); + nosigpipe(cf, data, ctx->sock); Curl_sndbuf_init(ctx->sock); if(is_tcp && data->set.tcp_keepalive) - tcpkeepalive(data, ctx->sock); + tcpkeepalive(cf, data, ctx->sock); if(data->set.fsockopt) { /* activate callback for setting socket options */ @@ -1226,7 +1206,7 @@ static CURLcode cf_socket_open(struct Curl_cfilter *cf, } else if(isconnected) { set_local_ip(cf, data); - ctx->connected_at = curlx_now(); + ctx->connected_at = *Curl_pgrs_now(data); cf->connected = TRUE; } CURL_TRC_CF(data, cf, "cf_socket_open() -> %d, fd=%" FMT_SOCKET_T, @@ -1271,8 +1251,8 @@ static int do_connect(struct Curl_cfilter *cf, struct Curl_easy *data, #elif defined(TCP_FASTOPEN_CONNECT) /* Linux >= 4.11 */ if(setsockopt(ctx->sock, IPPROTO_TCP, TCP_FASTOPEN_CONNECT, (void *)&optval, sizeof(optval)) < 0) - infof(data, "Failed to enable TCP Fast Open on fd %" FMT_SOCKET_T, - ctx->sock); + CURL_TRC_CF(data, cf, "Failed to enable TCP Fast Open on fd %" + FMT_SOCKET_T, ctx->sock); rc = connect(ctx->sock, &ctx->addr.curl_sa_addr, ctx->addr.addrlen); #elif defined(MSG_FASTOPEN) /* old Linux */ @@ -1339,14 +1319,13 @@ static CURLcode cf_tcp_connect(struct Curl_cfilter *cf, rc = SOCKET_WRITABLE(ctx->sock, 0); if(rc == 0) { /* no connection yet */ - CURL_TRC_CF(data, cf, "not connected yet on fd=%" FMT_SOCKET_T, - ctx->sock); + CURL_TRC_CF(data, cf, "not connected yet on fd=%" FMT_SOCKET_T, ctx->sock); return CURLE_OK; } else if(rc == CURL_CSELECT_OUT || cf->conn->bits.tcp_fastopen) { if(verifyconnect(ctx->sock, &ctx->error)) { /* we are connected with TCP, awesome! */ - ctx->connected_at = curlx_now(); + ctx->connected_at = *Curl_pgrs_now(data); set_local_ip(cf, data); *done = TRUE; cf->connected = TRUE; @@ -1422,33 +1401,34 @@ static CURLcode cf_socket_adjust_pollset(struct Curl_cfilter *cf, #define SIO_IDEAL_SEND_BACKLOG_QUERY 0x4004747B #endif -static void win_update_sndbuf_size(struct cf_socket_ctx *ctx) +static void win_update_sndbuf_size(struct Curl_easy *data, + struct cf_socket_ctx *ctx) { ULONG ideal; DWORD ideallen; - struct curltime n = curlx_now(); - if(curlx_timediff(n, ctx->last_sndbuf_query_at) > 1000) { + if(curlx_ptimediff_ms(Curl_pgrs_now(data), + &ctx->last_sndbuf_query_at) > 1000) { if(!WSAIoctl(ctx->sock, SIO_IDEAL_SEND_BACKLOG_QUERY, 0, 0, - &ideal, sizeof(ideal), &ideallen, 0, 0) && + &ideal, sizeof(ideal), &ideallen, 0, 0) && ideal != ctx->sndbuf_size && !setsockopt(ctx->sock, SOL_SOCKET, SO_SNDBUF, (const char *)&ideal, sizeof(ideal))) { ctx->sndbuf_size = ideal; } - ctx->last_sndbuf_query_at = n; + ctx->last_sndbuf_query_at = *Curl_pgrs_now(data); } } #endif /* USE_WINSOCK */ static CURLcode cf_socket_send(struct Curl_cfilter *cf, struct Curl_easy *data, - const void *buf, size_t len, bool eos, + const uint8_t *buf, size_t len, bool eos, size_t *pnwritten) { struct cf_socket_ctx *ctx = cf->ctx; curl_socket_t fdsave; - ssize_t nwritten; + ssize_t rv; size_t orig_len = len; CURLcode result = CURLE_OK; @@ -1462,7 +1442,7 @@ static CURLcode cf_socket_send(struct Curl_cfilter *cf, struct Curl_easy *data, if(ctx->wblock_percent > 0) { unsigned char c = 0; Curl_rand_bytes(data, FALSE, &c, 1); - if(c >= ((100-ctx->wblock_percent)*256/100)) { + if(c >= ((100 - ctx->wblock_percent) * 256 / 100)) { CURL_TRC_CF(data, cf, "send(len=%zu) SIMULATE EWOULDBLOCK", orig_len); cf->conn->sock[cf->sockindex] = fdsave; return CURLE_AGAIN; @@ -1479,15 +1459,15 @@ static CURLcode cf_socket_send(struct Curl_cfilter *cf, struct Curl_easy *data, #if defined(MSG_FASTOPEN) && !defined(TCP_FASTOPEN_CONNECT) /* Linux */ if(cf->conn->bits.tcp_fastopen) { - nwritten = sendto(ctx->sock, buf, len, MSG_FASTOPEN, - &ctx->addr.curl_sa_addr, ctx->addr.addrlen); + rv = sendto(ctx->sock, buf, len, MSG_FASTOPEN, + &ctx->addr.curl_sa_addr, ctx->addr.addrlen); cf->conn->bits.tcp_fastopen = FALSE; } else #endif - nwritten = swrite(ctx->sock, buf, len); + rv = swrite(ctx->sock, buf, len); - if(nwritten < 0) { + if(!curlx_sztouz(rv, pnwritten)) { int sockerr = SOCKERRNO; if( @@ -1514,12 +1494,10 @@ static CURLcode cf_socket_send(struct Curl_cfilter *cf, struct Curl_easy *data, result = CURLE_SEND_ERROR; } } - else - *pnwritten = (size_t)nwritten; #ifdef USE_WINSOCK if(!result) - win_update_sndbuf_size(ctx); + win_update_sndbuf_size(data, ctx); #endif CURL_TRC_CF(data, cf, "send(len=%zu) -> %d, %zu", @@ -1533,7 +1511,7 @@ static CURLcode cf_socket_recv(struct Curl_cfilter *cf, struct Curl_easy *data, { struct cf_socket_ctx *ctx = cf->ctx; CURLcode result = CURLE_OK; - ssize_t nread; + ssize_t rv; *pnread = 0; #ifdef DEBUGBUILD @@ -1541,7 +1519,7 @@ static CURLcode cf_socket_recv(struct Curl_cfilter *cf, struct Curl_easy *data, if(cf->cft != &Curl_cft_udp && ctx->rblock_percent > 0) { unsigned char c = 0; Curl_rand(data, &c, 1); - if(c >= ((100-ctx->rblock_percent)*256/100)) { + if(c >= ((100 - ctx->rblock_percent) * 256 / 100)) { CURL_TRC_CF(data, cf, "recv(len=%zu) SIMULATE EWOULDBLOCK", len); return CURLE_AGAIN; } @@ -1554,9 +1532,9 @@ static CURLcode cf_socket_recv(struct Curl_cfilter *cf, struct Curl_easy *data, } #endif - nread = sread(ctx->sock, buf, len); + rv = sread(ctx->sock, buf, len); - if(nread < 0) { + if(!curlx_sztouz(rv, pnread)) { int sockerr = SOCKERRNO; if( @@ -1582,12 +1560,10 @@ static CURLcode cf_socket_recv(struct Curl_cfilter *cf, struct Curl_easy *data, result = CURLE_RECV_ERROR; } } - else - *pnread = (size_t)nread; CURL_TRC_CF(data, cf, "recv(len=%zu) -> %d, %zu", len, result, *pnread); if(!result && !ctx->got_first_byte) { - ctx->first_byte_at = curlx_now(); + ctx->first_byte_at = *Curl_pgrs_now(data); ctx->got_first_byte = TRUE; } return result; @@ -1657,7 +1633,7 @@ static bool cf_socket_conn_is_alive(struct Curl_cfilter *cf, /* Check with 0 timeout if there are any events pending on the socket */ pfd[0].fd = ctx->sock; - pfd[0].events = POLLRDNORM|POLLIN|POLLRDBAND|POLLPRI; + pfd[0].events = POLLRDNORM | POLLIN | POLLRDBAND | POLLPRI; pfd[0].revents = 0; r = Curl_poll(pfd, 1, 0); @@ -1669,7 +1645,7 @@ static bool cf_socket_conn_is_alive(struct Curl_cfilter *cf, CURL_TRC_CF(data, cf, "is_alive: poll timeout, assume alive"); return TRUE; } - else if(pfd[0].revents & (POLLERR|POLLHUP|POLLPRI|POLLNVAL)) { + else if(pfd[0].revents & (POLLERR | POLLHUP | POLLPRI | POLLNVAL)) { CURL_TRC_CF(data, cf, "is_alive: err/hup/etc events, assume dead"); return FALSE; } @@ -1701,7 +1677,8 @@ static CURLcode cf_socket_query(struct Curl_cfilter *cf, return CURLE_OK; case CF_QUERY_CONNECT_REPLY_MS: if(ctx->got_first_byte) { - timediff_t ms = curlx_timediff(ctx->first_byte_at, ctx->started_at); + timediff_t ms = curlx_ptimediff_ms(&ctx->first_byte_at, + &ctx->started_at); *pres1 = (ms < INT_MAX) ? (int)ms : INT_MAX; } else @@ -1763,7 +1740,7 @@ CURLcode Curl_cf_tcp_create(struct Curl_cfilter **pcf, struct Curl_easy *data, struct connectdata *conn, const struct Curl_addrinfo *ai, - int transport) + uint8_t transport) { struct cf_socket_ctx *ctx = NULL; struct Curl_cfilter *cf = NULL; @@ -1777,7 +1754,7 @@ CURLcode Curl_cf_tcp_create(struct Curl_cfilter **pcf, goto out; } - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -1799,14 +1776,49 @@ CURLcode Curl_cf_tcp_create(struct Curl_cfilter **pcf, return result; } +#ifdef __linux__ +static void linux_quic_mtu(struct cf_socket_ctx *ctx) +{ + int val; + switch(ctx->addr.family) { +#ifdef IP_MTU_DISCOVER + case AF_INET: + val = IP_PMTUDISC_DO; + (void)setsockopt(ctx->sock, IPPROTO_IP, IP_MTU_DISCOVER, &val, + sizeof(val)); + break; +#endif +#ifdef IPV6_MTU_DISCOVER + case AF_INET6: + val = IPV6_PMTUDISC_DO; + (void)setsockopt(ctx->sock, IPPROTO_IPV6, IPV6_MTU_DISCOVER, &val, + sizeof(val)); + break; +#endif + } +} +#else +#define linux_quic_mtu(x) +#endif + +#if defined(UDP_GRO) && \ + (defined(HAVE_SENDMMSG) || defined(HAVE_SENDMSG)) && \ + ((defined(USE_NGTCP2) && defined(USE_NGHTTP3)) || defined(USE_QUICHE)) +static void linux_quic_gro(struct cf_socket_ctx *ctx) +{ + int one = 1; + (void)setsockopt(ctx->sock, IPPROTO_UDP, UDP_GRO, &one, + (socklen_t)sizeof(one)); +} +#else +#define linux_quic_gro(x) +#endif + static CURLcode cf_udp_setup_quic(struct Curl_cfilter *cf, struct Curl_easy *data) { struct cf_socket_ctx *ctx = cf->ctx; int rc; - int one = 1; - - (void)one; /* QUIC needs a connected socket, nonblocking */ DEBUGASSERT(ctx->sock != CURL_SOCKET_BAD); @@ -1831,33 +1843,8 @@ static CURLcode cf_udp_setup_quic(struct Curl_cfilter *cf, * non-blocking socket created by cf_socket_open() to it. Thus, we * do not need to call curlx_nonblock() in cf_udp_setup_quic() anymore. */ -#ifdef __linux__ - switch(ctx->addr.family) { -#ifdef IP_MTU_DISCOVER - case AF_INET: { - int val = IP_PMTUDISC_DO; - (void)setsockopt(ctx->sock, IPPROTO_IP, IP_MTU_DISCOVER, &val, - sizeof(val)); - break; - } -#endif -#ifdef IPV6_MTU_DISCOVER - case AF_INET6: { - int val = IPV6_PMTUDISC_DO; - (void)setsockopt(ctx->sock, IPPROTO_IPV6, IPV6_MTU_DISCOVER, &val, - sizeof(val)); - break; - } -#endif - } - -#if defined(UDP_GRO) && \ - (defined(HAVE_SENDMMSG) || defined(HAVE_SENDMSG)) && \ - ((defined(USE_NGTCP2) && defined(USE_NGHTTP3)) || defined(USE_QUICHE)) - (void)setsockopt(ctx->sock, IPPROTO_UDP, UDP_GRO, &one, - (socklen_t)sizeof(one)); -#endif -#endif + linux_quic_mtu(ctx); + linux_quic_gro(ctx); return CURLE_OK; } @@ -1919,7 +1906,7 @@ CURLcode Curl_cf_udp_create(struct Curl_cfilter **pcf, struct Curl_easy *data, struct connectdata *conn, const struct Curl_addrinfo *ai, - int transport) + uint8_t transport) { struct cf_socket_ctx *ctx = NULL; struct Curl_cfilter *cf = NULL; @@ -1928,7 +1915,7 @@ CURLcode Curl_cf_udp_create(struct Curl_cfilter **pcf, (void)data; (void)conn; DEBUGASSERT(transport == TRNSPRT_UDP || transport == TRNSPRT_QUIC); - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -1973,7 +1960,7 @@ CURLcode Curl_cf_unix_create(struct Curl_cfilter **pcf, struct Curl_easy *data, struct connectdata *conn, const struct Curl_addrinfo *ai, - int transport) + uint8_t transport) { struct cf_socket_ctx *ctx = NULL; struct Curl_cfilter *cf = NULL; @@ -1982,7 +1969,7 @@ CURLcode Curl_cf_unix_create(struct Curl_cfilter **pcf, (void)data; (void)conn; DEBUGASSERT(transport == TRNSPRT_UNIX); - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -2009,24 +1996,22 @@ static timediff_t cf_tcp_accept_timeleft(struct Curl_cfilter *cf, { struct cf_socket_ctx *ctx = cf->ctx; timediff_t timeout_ms = DEFAULT_ACCEPT_TIMEOUT; - timediff_t other; - struct curltime now; + timediff_t other_ms; #ifndef CURL_DISABLE_FTP if(data->set.accepttimeout > 0) timeout_ms = data->set.accepttimeout; #endif - now = curlx_now(); /* check if the generic timeout possibly is set shorter */ - other = Curl_timeleft(data, &now, FALSE); - if(other && (other < timeout_ms)) - /* note that this also works fine for when other happens to be negative + other_ms = Curl_timeleft_ms(data, FALSE); + if(other_ms && (other_ms < timeout_ms)) + /* note that this also works fine for when other_ms happens to be negative due to it already having elapsed */ - timeout_ms = other; + timeout_ms = other_ms; else { /* subtract elapsed time */ - timeout_ms -= curlx_timediff(now, ctx->started_at); + timeout_ms -= curlx_ptimediff_ms(Curl_pgrs_now(data), &ctx->started_at); if(!timeout_ms) /* avoid returning 0 as that means no timeout! */ timeout_ms = -1; @@ -2047,13 +2032,13 @@ static void cf_tcp_set_accepted_remote_ip(struct Curl_cfilter *cf, ctx->ip.remote_port = 0; plen = sizeof(ssrem); memset(&ssrem, 0, plen); - if(getpeername(ctx->sock, (struct sockaddr*) &ssrem, &plen)) { + if(getpeername(ctx->sock, (struct sockaddr *)&ssrem, &plen)) { int error = SOCKERRNO; failf(data, "getpeername() failed with errno %d: %s", error, curlx_strerror(error, buffer, sizeof(buffer))); return; } - if(!Curl_addr2string((struct sockaddr*)&ssrem, plen, + if(!Curl_addr2string((struct sockaddr *)&ssrem, plen, ctx->ip.remote_ip, &ctx->ip.remote_port)) { failf(data, "ssrem inet_ntop() failed with errno %d: %s", errno, curlx_strerror(errno, buffer, sizeof(buffer))); @@ -2077,7 +2062,7 @@ static CURLcode cf_tcp_accept_connect(struct Curl_cfilter *cf, #else struct sockaddr_in add; #endif - curl_socklen_t size = (curl_socklen_t) sizeof(add); + curl_socklen_t size = (curl_socklen_t)sizeof(add); curl_socket_t s_accepted = CURL_SOCKET_BAD; timediff_t timeout_ms; int socketstate = 0; @@ -2100,8 +2085,7 @@ static CURLcode cf_tcp_accept_connect(struct Curl_cfilter *cf, CURL_TRC_CF(data, cf, "Checking for incoming on fd=%" FMT_SOCKET_T " ip=%s:%d", ctx->sock, ctx->ip.local_ip, ctx->ip.local_port); - socketstate = Curl_socket_check(ctx->sock, CURL_SOCKET_BAD, - CURL_SOCKET_BAD, 0); + socketstate = SOCKET_READABLE(ctx->sock, 0); CURL_TRC_CF(data, cf, "socket_check -> %x", socketstate); switch(socketstate) { case -1: /* error */ @@ -2123,10 +2107,10 @@ static CURLcode cf_tcp_accept_connect(struct Curl_cfilter *cf, size = sizeof(add); #ifdef HAVE_ACCEPT4 - s_accepted = CURL_ACCEPT4(ctx->sock, (struct sockaddr *) &add, &size, + s_accepted = CURL_ACCEPT4(ctx->sock, (struct sockaddr *)&add, &size, SOCK_NONBLOCK | SOCK_CLOEXEC); #else - s_accepted = CURL_ACCEPT(ctx->sock, (struct sockaddr *) &add, &size); + s_accepted = CURL_ACCEPT(ctx->sock, (struct sockaddr *)&add, &size); #endif if(CURL_SOCKET_BAD == s_accepted) { @@ -2134,15 +2118,22 @@ static CURLcode cf_tcp_accept_connect(struct Curl_cfilter *cf, curlx_strerror(SOCKERRNO, errbuf, sizeof(errbuf))); return CURLE_FTP_ACCEPT_FAILED; } -#if !defined(HAVE_ACCEPT4) && defined(HAVE_FCNTL) - if((fcntl(s_accepted, F_SETFD, FD_CLOEXEC) < 0) || - (curlx_nonblock(s_accepted, TRUE) < 0)) { - failf(data, "fcntl set CLOEXEC/NONBLOCK: %s", +#ifndef HAVE_ACCEPT4 +#ifdef HAVE_FCNTL + if(fcntl(s_accepted, F_SETFD, FD_CLOEXEC) < 0) { + failf(data, "fcntl set CLOEXEC: %s", curlx_strerror(SOCKERRNO, errbuf, sizeof(errbuf))); Curl_socket_close(data, cf->conn, s_accepted); return CURLE_FTP_ACCEPT_FAILED; } -#endif +#endif /* HAVE_FCNTL */ + if(curlx_nonblock(s_accepted, TRUE) < 0) { + failf(data, "set socket NONBLOCK: %s", + curlx_strerror(SOCKERRNO, errbuf, sizeof(errbuf))); + Curl_socket_close(data, cf->conn, s_accepted); + return CURLE_FTP_ACCEPT_FAILED; + } +#endif /* !HAVE_ACCEPT4 */ infof(data, "Connection accepted from server"); /* Replace any filter on SECONDARY with one listening on this socket */ @@ -2155,7 +2146,7 @@ static CURLcode cf_tcp_accept_connect(struct Curl_cfilter *cf, cf_tcp_set_accepted_remote_ip(cf, data); set_local_ip(cf, data); ctx->active = TRUE; - ctx->connected_at = curlx_now(); + ctx->connected_at = *Curl_pgrs_now(data); cf->connected = TRUE; CURL_TRC_CF(data, cf, "accepted_set(sock=%" FMT_SOCKET_T ", remote=%s port=%d)", @@ -2207,7 +2198,7 @@ CURLcode Curl_conn_tcp_listen_set(struct Curl_easy *data, Curl_conn_cf_discard_all(data, conn, sockindex); DEBUGASSERT(conn->sock[sockindex] == CURL_SOCKET_BAD); - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -2221,7 +2212,7 @@ CURLcode Curl_conn_tcp_listen_set(struct Curl_easy *data, goto out; Curl_conn_cf_add(data, conn, sockindex, cf); - ctx->started_at = curlx_now(); + ctx->started_at = *Curl_pgrs_now(data); conn->sock[sockindex] = ctx->sock; set_local_ip(cf, data); CURL_TRC_CF(data, cf, "set filter for listen socket fd=%" FMT_SOCKET_T diff --git a/vendor/hydra/vendor/curl/lib/cf-socket.h b/vendor/hydra/vendor/curl/lib/cf-socket.h index e5fc176e..9db492e1 100644 --- a/vendor/hydra/vendor/curl/lib/cf-socket.h +++ b/vendor/hydra/vendor/curl/lib/cf-socket.h @@ -25,8 +25,7 @@ ***************************************************************************/ #include "curl_setup.h" -#include "curlx/nonblock.h" /* for curlx_nonblock() */ -#include "sockaddr.h" +#include "sockaddr.h" /* required for Curl_sockaddr_storage */ struct Curl_addrinfo; struct Curl_cfilter; @@ -52,12 +51,12 @@ struct Curl_sockaddr_ex { struct Curl_sockaddr_storage buf; } addr; }; -#define curl_sa_addr addr.sa +#define curl_sa_addr addr.sa #define curl_sa_addrbuf addr.buf /* * Parse interface option, and return the interface name and the host part. -*/ + */ CURLcode Curl_parse_interface(const char *input, char **dev, char **iface, char **host); @@ -71,7 +70,7 @@ CURLcode Curl_parse_interface(const char *input, CURLcode Curl_socket_open(struct Curl_easy *data, const struct Curl_addrinfo *ai, struct Curl_sockaddr_ex *addr, - int transport, + uint8_t transport, curl_socket_t *sockfd); int Curl_socket_close(struct Curl_easy *data, struct connectdata *conn, @@ -103,7 +102,7 @@ CURLcode Curl_cf_tcp_create(struct Curl_cfilter **pcf, struct Curl_easy *data, struct connectdata *conn, const struct Curl_addrinfo *ai, - int transport); + uint8_t transport); /** * Creates a cfilter that opens a UDP socket to the given address @@ -116,7 +115,7 @@ CURLcode Curl_cf_udp_create(struct Curl_cfilter **pcf, struct Curl_easy *data, struct connectdata *conn, const struct Curl_addrinfo *ai, - int transport); + uint8_t transport); /** * Creates a cfilter that opens a UNIX socket to the given address @@ -129,7 +128,7 @@ CURLcode Curl_cf_unix_create(struct Curl_cfilter **pcf, struct Curl_easy *data, struct connectdata *conn, const struct Curl_addrinfo *ai, - int transport); + uint8_t transport); /** * Creates a cfilter that keeps a listening socket. diff --git a/vendor/hydra/vendor/curl/lib/cfilters.c b/vendor/hydra/vendor/curl/lib/cfilters.c index 090365fd..b91d30c2 100644 --- a/vendor/hydra/vendor/curl/lib/cfilters.c +++ b/vendor/hydra/vendor/curl/lib/cfilters.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #include "urldata.h" @@ -29,18 +28,11 @@ #include "cfilters.h" #include "connect.h" #include "url.h" -#include "sendf.h" -#include "sockaddr.h" /* required for Curl_sockaddr_storage */ -#include "multiif.h" +#include "curl_trc.h" #include "progress.h" #include "select.h" -#include "curlx/warnless.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - static void cf_cntrl_update_info(struct Curl_easy *data, struct connectdata *conn); @@ -63,8 +55,8 @@ CURLcode Curl_cf_def_shutdown(struct Curl_cfilter *cf, return CURLE_OK; } -static void conn_report_connect_stats(struct Curl_easy *data, - struct connectdata *conn); +static void conn_report_connect_stats(struct Curl_cfilter *cf, + struct Curl_easy *data); CURLcode Curl_cf_def_adjust_pollset(struct Curl_cfilter *cf, struct Curl_easy *data, @@ -85,7 +77,7 @@ bool Curl_cf_def_data_pending(struct Curl_cfilter *cf, } CURLcode Curl_cf_def_send(struct Curl_cfilter *cf, struct Curl_easy *data, - const void *buf, size_t len, bool eos, + const uint8_t *buf, size_t len, bool eos, size_t *pnwritten) { if(cf->next) @@ -143,7 +135,7 @@ void Curl_conn_cf_discard_chain(struct Curl_cfilter **pcf, */ cf->next = NULL; cf->cft->destroy(cf, data); - free(cf); + curlx_free(cf); cf = cfn; } } @@ -173,7 +165,6 @@ CURLcode Curl_conn_shutdown(struct Curl_easy *data, int sockindex, bool *done) struct Curl_cfilter *cf; CURLcode result = CURLE_OK; timediff_t timeout_ms; - struct curltime now; DEBUGASSERT(data->conn); @@ -191,14 +182,13 @@ CURLcode Curl_conn_shutdown(struct Curl_easy *data, int sockindex, bool *done) } *done = FALSE; - now = curlx_now(); if(!Curl_shutdown_started(data, sockindex)) { CURL_TRC_M(data, "shutdown start on%s connection", sockindex ? " secondary" : ""); - Curl_shutdown_start(data, sockindex, 0, &now); + Curl_shutdown_start(data, sockindex, 0); } else { - timeout_ms = Curl_shutdown_timeleft(data->conn, sockindex, &now); + timeout_ms = Curl_shutdown_timeleft(data, data->conn, sockindex); if(timeout_ms < 0) { /* info message, since this might be regarded as acceptable */ infof(data, "shutdown timeout"); @@ -246,7 +236,7 @@ CURLcode Curl_cf_recv(struct Curl_easy *data, int num, char *buf, } CURLcode Curl_cf_send(struct Curl_easy *data, int num, - const void *mem, size_t len, bool eos, + const uint8_t *mem, size_t len, bool eos, size_t *pnwritten) { struct Curl_cfilter *cf; @@ -296,12 +286,11 @@ CURLcode Curl_cf_recv_bufq(struct Curl_cfilter *cf, } static CURLcode cf_bufq_writer(void *writer_ctx, - const unsigned char *buf, size_t buflen, + const uint8_t *buf, size_t buflen, size_t *pnwritten) { struct cf_io_ctx *io = writer_ctx; - return Curl_conn_cf_send(io->cf, io->data, (const char *)buf, - buflen, FALSE, pnwritten); + return Curl_conn_cf_send(io->cf, io->data, buf, buflen, FALSE, pnwritten); } CURLcode Curl_cf_send_bufq(struct Curl_cfilter *cf, @@ -333,7 +322,7 @@ CURLcode Curl_cf_create(struct Curl_cfilter **pcf, CURLcode result = CURLE_OUT_OF_MEMORY; DEBUGASSERT(cft); - cf = calloc(1, sizeof(*cf)); + cf = curlx_calloc(1, sizeof(*cf)); if(!cf) goto out; @@ -422,7 +411,7 @@ void Curl_conn_cf_close(struct Curl_cfilter *cf, struct Curl_easy *data) } CURLcode Curl_conn_cf_send(struct Curl_cfilter *cf, struct Curl_easy *data, - const void *buf, size_t len, bool eos, + const uint8_t *buf, size_t len, bool eos, size_t *pnwritten) { if(cf) @@ -508,17 +497,16 @@ CURLcode Curl_conn_connect(struct Curl_easy *data, * persist information at the connection. E.g. cf-socket sets the * socket and ip related information. */ cf_cntrl_update_info(data, data->conn); - conn_report_connect_stats(data, data->conn); - data->conn->keepalive = curlx_now(); + conn_report_connect_stats(cf, data); + data->conn->keepalive = *Curl_pgrs_now(data); #ifndef CURL_DISABLE_VERBOSE_STRINGS result = cf_verboseconnect(data, cf); #endif goto out; } else if(result) { - CURL_TRC_CF(data, cf, "Curl_conn_connect(), filter returned %d", - result); - conn_report_connect_stats(data, data->conn); + CURL_TRC_CF(data, cf, "Curl_conn_connect(), filter returned %d", result); + conn_report_connect_stats(cf, data); goto out; } @@ -526,7 +514,7 @@ CURLcode Curl_conn_connect(struct Curl_easy *data, goto out; else { /* check allowed time left */ - const timediff_t timeout_ms = Curl_timeleft(data, NULL, TRUE); + const timediff_t timeout_ms = Curl_timeleft_ms(data, TRUE); curl_socket_t sockfd = Curl_conn_cf_get_socket(cf, data); int rc; @@ -583,7 +571,11 @@ bool Curl_conn_is_connected(struct connectdata *conn, int sockindex) if(!CONN_SOCK_IDX_VALID(sockindex)) return FALSE; cf = conn->cfilter[sockindex]; - return cf && cf->connected; + if(cf) + return cf->connected; + else if(conn->handler->flags & PROTOPT_NONETWORK) + return TRUE; + return FALSE; } bool Curl_conn_is_ip_connected(struct Curl_easy *data, int sockindex) @@ -658,7 +650,7 @@ bool Curl_conn_is_multiplex(struct connectdata *conn, int sockindex) for(; cf; cf = cf->next) { if(cf->cft->flags & CF_TYPE_MULTIPLEX) return TRUE; - if(cf->cft->flags & (CF_TYPE_IP_CONNECT|CF_TYPE_SSL)) + if(cf->cft->flags & (CF_TYPE_IP_CONNECT | CF_TYPE_SSL)) return FALSE; } return FALSE; @@ -696,7 +688,7 @@ unsigned char Curl_conn_http_version(struct Curl_easy *data, v = (unsigned char)value; break; } - if(cf->cft->flags & (CF_TYPE_IP_CONNECT|CF_TYPE_SSL)) + if(cf->cft->flags & (CF_TYPE_IP_CONNECT | CF_TYPE_SSL)) break; } return (unsigned char)(result ? 0 : v); @@ -808,9 +800,9 @@ void Curl_conn_get_current_host(struct Curl_easy *data, int sockindex, cf = CONN_SOCK_IDX_VALID(sockindex) ? data->conn->cfilter[sockindex] : NULL; /* Find the "lowest" tunneling proxy filter that has not connected yet. */ while(cf && !cf->connected) { - if((cf->cft->flags & (CF_TYPE_IP_CONNECT|CF_TYPE_PROXY)) == - (CF_TYPE_IP_CONNECT|CF_TYPE_PROXY)) - cf_proxy = cf; + if((cf->cft->flags & (CF_TYPE_IP_CONNECT | CF_TYPE_PROXY)) == + (CF_TYPE_IP_CONNECT | CF_TYPE_PROXY)) + cf_proxy = cf; cf = cf->next; } /* cf_proxy (!= NULL) is not connected yet. It is talking @@ -931,19 +923,6 @@ Curl_conn_get_remote_addr(struct Curl_easy *data, int sockindex) return cf ? cf_get_remote_addr(cf, data) : NULL; } -void Curl_conn_forget_socket(struct Curl_easy *data, int sockindex) -{ - struct connectdata *conn = data->conn; - if(conn && CONN_SOCK_IDX_VALID(sockindex)) { - struct Curl_cfilter *cf = conn->cfilter[sockindex]; - if(cf) - (void)Curl_conn_cf_cntrl(cf, data, TRUE, - CF_CTRL_FORGET_SOCKET, 0, NULL); - fake_sclose(conn->sock[sockindex]); - conn->sock[sockindex] = CURL_SOCKET_BAD; - } -} - static CURLcode cf_cntrl_all(struct connectdata *conn, struct Curl_easy *data, bool ignore_result, @@ -963,8 +942,7 @@ static CURLcode cf_cntrl_all(struct connectdata *conn, CURLcode Curl_conn_ev_data_setup(struct Curl_easy *data) { - return cf_cntrl_all(data->conn, data, FALSE, - CF_CTRL_DATA_SETUP, 0, NULL); + return cf_cntrl_all(data->conn, data, FALSE, CF_CTRL_DATA_SETUP, 0, NULL); } CURLcode Curl_conn_flush(struct Curl_easy *data, int sockindex) @@ -1008,10 +986,9 @@ static void cf_cntrl_update_info(struct Curl_easy *data, /** * Update connection statistics */ -static void conn_report_connect_stats(struct Curl_easy *data, - struct connectdata *conn) +static void conn_report_connect_stats(struct Curl_cfilter *cf, + struct Curl_easy *data) { - struct Curl_cfilter *cf = conn->cfilter[FIRSTSOCKET]; if(cf) { struct curltime connected; struct curltime appconnected; @@ -1119,8 +1096,7 @@ CURLcode Curl_conn_send(struct Curl_easy *data, int sockindex, return CURLE_BAD_FUNCTION_ARGUMENT; #ifdef DEBUGBUILD if(write_len) { - /* Allow debug builds to override this logic to force short sends - */ + /* Allow debug builds to override this logic to force short sends */ const char *p = getenv("CURL_SMALLSENDS"); if(p) { curl_off_t altsize; diff --git a/vendor/hydra/vendor/curl/lib/cfilters.h b/vendor/hydra/vendor/curl/lib/cfilters.h index 6cb4a690..9faf01de 100644 --- a/vendor/hydra/vendor/curl/lib/cfilters.h +++ b/vendor/hydra/vendor/curl/lib/cfilters.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curlx/timediff.h" struct bufq; @@ -89,7 +88,7 @@ typedef bool Curl_cft_data_pending(struct Curl_cfilter *cf, typedef CURLcode Curl_cft_send(struct Curl_cfilter *cf, struct Curl_easy *data, /* transfer */ - const void *buf, /* data to write */ + const uint8_t *buf, /* data to write */ size_t len, /* amount to write */ bool eos, /* last chunk */ size_t *pnwritten); /* how much sent */ @@ -116,16 +115,16 @@ typedef CURLcode Curl_cft_conn_keep_alive(struct Curl_cfilter *cf, * "ignored" meaning return values are ignored and the event is distributed * to all filters in the chain. Overall result is always CURLE_OK. */ -/* data event arg1 arg2 return */ -#define CF_CTRL_DATA_SETUP 4 /* 0 NULL first fail */ -/* unused now 5 */ -#define CF_CTRL_DATA_PAUSE 6 /* on/off NULL first fail */ -#define CF_CTRL_DATA_DONE 7 /* premature NULL ignored */ -#define CF_CTRL_DATA_DONE_SEND 8 /* 0 NULL ignored */ +/* data event arg1 arg2 return */ +#define CF_CTRL_DATA_SETUP 4 /* 0 NULL first fail */ +/* unused now 5 */ +#define CF_CTRL_DATA_PAUSE 6 /* on/off NULL first fail */ +#define CF_CTRL_DATA_DONE 7 /* premature NULL ignored */ +#define CF_CTRL_DATA_DONE_SEND 8 /* 0 NULL ignored */ /* update conn info at connection and data */ -#define CF_CTRL_CONN_INFO_UPDATE (256+0) /* 0 NULL ignored */ -#define CF_CTRL_FORGET_SOCKET (256+1) /* 0 NULL ignored */ -#define CF_CTRL_FLUSH (256+2) /* 0 NULL first fail */ +#define CF_CTRL_CONN_INFO_UPDATE (256 + 0) /* 0 NULL ignored */ +#define CF_CTRL_FORGET_SOCKET (256 + 1) /* 0 NULL ignored */ +#define CF_CTRL_FLUSH (256 + 2) /* 0 NULL first fail */ /** * Handle event/control for the filter. @@ -135,7 +134,6 @@ typedef CURLcode Curl_cft_cntrl(struct Curl_cfilter *cf, struct Curl_easy *data, int event, int arg1, void *arg2); - /** * Queries to ask via a `Curl_cft_query *query` method on a cfilter chain. * - MAX_CONCURRENT: the maximum number of parallel transfers the filter @@ -210,21 +208,21 @@ typedef CURLcode Curl_cft_query(struct Curl_cfilter *cf, /* A connection filter type, e.g. specific implementation. */ struct Curl_cftype { - const char *name; /* name of the filter type */ - int flags; /* flags of filter type */ - int log_level; /* log level for such filters */ - Curl_cft_destroy_this *destroy; /* destroy resources of this cf */ - Curl_cft_connect *do_connect; /* establish connection */ - Curl_cft_close *do_close; /* close conn */ - Curl_cft_shutdown *do_shutdown; /* shutdown conn */ + const char *name; /* name of the filter type */ + int flags; /* flags of filter type */ + int log_level; /* log level for such filters */ + Curl_cft_destroy_this *destroy; /* destroy resources of this cf */ + Curl_cft_connect *do_connect; /* establish connection */ + Curl_cft_close *do_close; /* close conn */ + Curl_cft_shutdown *do_shutdown; /* shutdown conn */ Curl_cft_adjust_pollset *adjust_pollset; /* adjust transfer poll set */ - Curl_cft_data_pending *has_data_pending;/* conn has data pending */ - Curl_cft_send *do_send; /* send data */ - Curl_cft_recv *do_recv; /* receive data */ - Curl_cft_cntrl *cntrl; /* events/control */ - Curl_cft_conn_is_alive *is_alive; /* FALSE if conn is dead, Jim! */ - Curl_cft_conn_keep_alive *keep_alive; /* try to keep it alive */ - Curl_cft_query *query; /* query filter chain */ + Curl_cft_data_pending *has_data_pending; /* conn has data pending */ + Curl_cft_send *do_send; /* send data */ + Curl_cft_recv *do_recv; /* receive data */ + Curl_cft_cntrl *cntrl; /* events/control */ + Curl_cft_conn_is_alive *is_alive; /* FALSE if conn is dead, Jim! */ + Curl_cft_conn_keep_alive *keep_alive; /* try to keep it alive */ + Curl_cft_query *query; /* query filter chain */ }; /* A connection filter instance, e.g. registered at a connection */ @@ -250,7 +248,7 @@ CURLcode Curl_cf_def_adjust_pollset(struct Curl_cfilter *cf, bool Curl_cf_def_data_pending(struct Curl_cfilter *cf, const struct Curl_easy *data); CURLcode Curl_cf_def_send(struct Curl_cfilter *cf, struct Curl_easy *data, - const void *buf, size_t len, bool eos, + const uint8_t *buf, size_t len, bool eos, size_t *pnwritten); CURLcode Curl_cf_def_recv(struct Curl_cfilter *cf, struct Curl_easy *data, char *buf, size_t len, size_t *pnread); @@ -317,13 +315,12 @@ void Curl_conn_cf_discard_all(struct Curl_easy *data, struct connectdata *conn, int sockindex); - CURLcode Curl_conn_cf_connect(struct Curl_cfilter *cf, struct Curl_easy *data, bool *done); void Curl_conn_cf_close(struct Curl_cfilter *cf, struct Curl_easy *data); CURLcode Curl_conn_cf_send(struct Curl_cfilter *cf, struct Curl_easy *data, - const void *buf, size_t len, bool eos, + const uint8_t *buf, size_t len, bool eos, size_t *pnwritten); CURLcode Curl_conn_cf_recv(struct Curl_cfilter *cf, struct Curl_easy *data, char *buf, size_t len, size_t *pnread); @@ -426,7 +423,7 @@ const char *Curl_conn_get_alpn_negotiated(struct Curl_easy *data, /** * Close the filter chain at `sockindex` for connection `data->conn`. - * Filters remain in place and may be connected again afterwards. + * Filters remain in place and may be connected again afterwards. */ void Curl_conn_close(struct Curl_easy *data, int sockindex); @@ -508,7 +505,7 @@ CURLcode Curl_cf_recv(struct Curl_easy *data, int sockindex, char *buf, * in `*pnwritten` or on error. */ CURLcode Curl_cf_send(struct Curl_easy *data, int sockindex, - const void *buf, size_t len, bool eos, + const uint8_t *buf, size_t len, bool eos, size_t *pnwritten); /** @@ -622,7 +619,6 @@ CURLcode Curl_conn_send(struct Curl_easy *data, int sockindex, const void *buf, size_t blen, bool eos, size_t *pnwritten); - /** * Types and macros used to keep the current easy handle in filter calls, * allowing for nested invocations. See #10336. @@ -654,7 +650,7 @@ struct cf_call_data { * a member in the cfilter's `ctx`. * * #define CF_CTX_CALL_DATA(cf) -> struct cf_call_data instance -*/ + */ #ifdef DEBUGBUILD @@ -688,7 +684,6 @@ struct cf_call_data { #endif /* !DEBUGBUILD */ -#define CF_DATA_CURRENT(cf) \ - ((cf)? (CF_CTX_CALL_DATA(cf).data) : NULL) +#define CF_DATA_CURRENT(cf) ((cf) ? (CF_CTX_CALL_DATA(cf).data) : NULL) #endif /* HEADER_CURL_CFILTERS_H */ diff --git a/vendor/hydra/vendor/curl/lib/config-os400.h b/vendor/hydra/vendor/curl/lib/config-os400.h index bccdb4a8..ec6c002e 100644 --- a/vendor/hydra/vendor/curl/lib/config-os400.h +++ b/vendor/hydra/vendor/curl/lib/config-os400.h @@ -38,9 +38,9 @@ /* OS400 supports a 3-argument ASCII version of gethostbyaddr_r(), but its * prototype is incompatible with the "standard" one (1st argument is not * const). However, getaddrinfo() is supported (ASCII version defined as - * a local wrapper in setup-os400.h) in a threadsafe way: we can then + * a local wrapper in setup-os400.h) in a thread-safe way: we can then * configure getaddrinfo() as such and get rid of gethostbyname_r() without - * loss of threadsafeness. */ + * loss of thread-safeness. */ #undef HAVE_GETHOSTBYNAME_R #undef HAVE_GETHOSTBYNAME_R_3 #undef HAVE_GETHOSTBYNAME_R_5 @@ -102,9 +102,15 @@ /* Define if you have GSS API. */ #define HAVE_GSSAPI +/* Define if you have the header file. */ +#define HAVE_GSSAPI_H + /* Define if you have the GNU gssapi libraries */ #undef HAVE_GSSGNU +/* Define if you have the `localtime_r' function. */ +#define HAVE_LOCALTIME_R + /* Define if you have the header file. */ #define HAVE_NETDB_H @@ -129,7 +135,6 @@ /* Define if you have the `socket' function. */ #define HAVE_SOCKET - /* The following define is needed on OS400 to enable strcmpi(), stricmp() and strdup(). */ #define __cplusplus__strings__ diff --git a/vendor/hydra/vendor/curl/lib/config-plan9.h b/vendor/hydra/vendor/curl/lib/config-plan9.h index 68d0cf7f..616b8e26 100644 --- a/vendor/hydra/vendor/curl/lib/config-plan9.h +++ b/vendor/hydra/vendor/curl/lib/config-plan9.h @@ -86,6 +86,7 @@ #define HAVE_LIBGEN_H 1 #define HAVE_LIBZ 1 #define HAVE_LOCALE_H 1 +#define HAVE_LOCALTIME_R 1 #define HAVE_LONGLONG 1 #define HAVE_NETDB_H 1 #define HAVE_NETINET_IN_H 1 diff --git a/vendor/hydra/vendor/curl/lib/config-win32.h b/vendor/hydra/vendor/curl/lib/config-win32.h index 408606d6..002782c6 100644 --- a/vendor/hydra/vendor/curl/lib/config-win32.h +++ b/vendor/hydra/vendor/curl/lib/config-win32.h @@ -28,8 +28,6 @@ /* Hand crafted config file for Windows */ /* ================================================================ */ -#ifndef UNDER_CE - /* Define some minimum and default build targets for Visual Studio */ #ifdef _MSC_VER /* VS2012 default target settings and minimum build target check. */ @@ -58,63 +56,45 @@ # error VS2012 does not support build targets prior to Windows Vista # endif # endif - /* Default target settings and minimum build target check for - VS2008 and VS2010 */ + /* VS2010 default target settings and minimum build target check. */ # else -# define VS2008_MIN_TARGET 0x0501 /* XP */ - /* VS2008 default build target is Windows Vista (0x0600). + /* VS2010 default build target is Windows 7 (0x0601). We override default target to be Windows XP. */ -# define VS2008_DEF_TARGET 0x0501 /* XP */ +# define VS2010_MIN_TARGET 0x0501 /* XP */ +# define VS2010_DEF_TARGET 0x0501 /* XP */ # ifndef _WIN32_WINNT -# define _WIN32_WINNT VS2008_DEF_TARGET +# define _WIN32_WINNT VS2010_DEF_TARGET # endif # ifndef WINVER -# define WINVER VS2008_DEF_TARGET +# define WINVER VS2010_DEF_TARGET # endif -# if (_WIN32_WINNT < VS2008_MIN_TARGET) || (WINVER < VS2008_MIN_TARGET) -# error VS2008 does not support build targets prior to Windows XP +# if (_WIN32_WINNT < VS2010_MIN_TARGET) || (WINVER < VS2010_MIN_TARGET) +# error VS2010 does not support build targets prior to Windows XP # endif # endif #endif /* _MSC_VER */ -#endif /* UNDER_CE */ - /* ---------------------------------------------------------------- */ /* HEADER FILES */ /* ---------------------------------------------------------------- */ -/* Define if you have the header file. */ -/* #define HAVE_ARPA_INET_H 1 */ - -#ifndef UNDER_CE - /* Define if you have the header file. */ -#define HAVE_FCNTL_H 1 /* exists on __MINGW32CE__ */ +#define HAVE_FCNTL_H 1 /* Define if you have the header file. */ -#define HAVE_IO_H 1 /* exists on __MINGW32CE__ */ +#define HAVE_IO_H 1 /* Define if you have the header file. */ #define HAVE_LOCALE_H 1 -#endif - -/* Define if you have the header file. */ -/* #define HAVE_NETDB_H 1 */ - -/* Define if you have the header file. */ -/* #define HAVE_NETINET_IN_H 1 */ - /* Define to 1 if you have the header file. */ -#ifndef UNDER_CE #if (defined(_MSC_VER) && (_MSC_VER >= 1800)) || defined(__MINGW32__) -#define HAVE_STDBOOL_H 1 /* exists on __MINGW32CE__ */ -#endif +#define HAVE_STDBOOL_H 1 #endif /* Define to 1 if you have the header file. */ -#if (defined(_MSC_VER) && (_MSC_VER >= 1600)) || defined(__MINGW32__) +#if defined(_MSC_VER) || defined(__MINGW32__) #define HAVE_STDINT_H 1 #endif @@ -123,24 +103,12 @@ #define HAVE_SYS_PARAM_H 1 #endif -/* Define if you have the header file. */ -/* #define HAVE_SYS_SELECT_H 1 */ - -/* Define if you have the header file. */ -/* #define HAVE_SYS_SOCKIO_H 1 */ - /* Define if you have the header file. */ #define HAVE_SYS_TYPES_H 1 /* Define if you have the header file. */ #define HAVE_SYS_UTIME_H 1 -/* Define if you have the header file. */ -/* #define HAVE_TERMIO_H 1 */ - -/* Define if you have the header file. */ -/* #define HAVE_TERMIOS_H 1 */ - /* Define if you have the header file. */ #ifdef __MINGW32__ #define HAVE_UNISTD_H 1 @@ -159,10 +127,8 @@ #define STDC_HEADERS 1 /* Define to 1 if bool is an available type. */ -#ifndef UNDER_CE #if (defined(_MSC_VER) && (_MSC_VER >= 1800)) || defined(__MINGW32__) -#define HAVE_BOOL_T 1 /* exists on __MINGW32CE__ */ -#endif +#define HAVE_BOOL_T 1 #endif /* ---------------------------------------------------------------- */ @@ -200,7 +166,6 @@ /* Define if you have the select function. */ #define HAVE_SELECT 1 -#ifndef UNDER_CE /* Define if you have the setlocale function. */ #define HAVE_SETLOCALE 1 @@ -209,7 +174,6 @@ /* Define if you have the _setmode function. */ #define HAVE__SETMODE 1 -#endif /* Define if you have the socket function. */ #define HAVE_SOCKET 1 @@ -276,9 +240,7 @@ #endif /* Define to 1 if you have the signal function. */ -#ifndef UNDER_CE #define HAVE_SIGNAL 1 -#endif /* ---------------------------------------------------------------- */ /* TYPEDEF REPLACEMENTS */ @@ -303,9 +265,6 @@ /* Define to the size of `int', as computed by sizeof. */ #define SIZEOF_INT 4 -/* Define to the size of `long long', as computed by sizeof. */ -/* #define SIZEOF_LONG_LONG 8 */ - /* Define to the size of `long', as computed by sizeof. */ #define SIZEOF_LONG 4 @@ -323,15 +282,6 @@ /* COMPILER SPECIFIC */ /* ---------------------------------------------------------------- */ -/* Define to nothing if compiler does not support 'const' qualifier. */ -/* #define const */ - -/* Define to nothing if compiler does not support 'volatile' qualifier. */ -/* #define volatile */ - -/* Windows should not have HAVE_GMTIME_R defined */ -/* #undef HAVE_GMTIME_R */ - /* Define if the compiler supports the 'long long' data type. */ #if defined(_MSC_VER) || defined(__MINGW32__) #define HAVE_LONGLONG 1 @@ -347,11 +297,9 @@ #endif /* Windows XP is required for freeaddrinfo, getaddrinfo */ -#ifndef UNDER_CE #define HAVE_FREEADDRINFO 1 #define HAVE_GETADDRINFO 1 #define HAVE_GETADDRINFO_THREADSAFE 1 -#endif /* ---------------------------------------------------------------- */ /* STRUCT RELATED */ @@ -370,28 +318,19 @@ /* LARGE FILE SUPPORT */ /* ---------------------------------------------------------------- */ -#ifndef UNDER_CE - -#if defined(_MSC_VER) || defined(__MINGW32__) -# define USE_WIN32_LARGE_FILES /* Number of bits in a file offset, on hosts where this is settable. */ -# ifdef __MINGW32__ -# ifndef _FILE_OFFSET_BITS -# define _FILE_OFFSET_BITS 64 -# endif -# endif +#ifdef __MINGW32__ +# undef _FILE_OFFSET_BITS +# define _FILE_OFFSET_BITS 64 #endif /* Define to the size of `off_t', as computed by sizeof. */ -#if defined(__MINGW32__) && \ - defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64) +#ifdef __MINGW32__ # define SIZEOF_OFF_T 8 #else # define SIZEOF_OFF_T 4 #endif -#endif /* UNDER_CE */ - /* ---------------------------------------------------------------- */ /* DNS RESOLVER SPECIALTY */ /* ---------------------------------------------------------------- */ @@ -400,9 +339,6 @@ * Undefine both USE_ARES and USE_THREADS_WIN32 for synchronous DNS. */ -/* Define to enable c-ares asynchronous DNS lookups. */ -/* #define USE_ARES 1 */ - /* Default define to enable threaded asynchronous DNS lookups. */ #if !defined(USE_SYNC_DNS) && !defined(USE_ARES) && \ !defined(USE_THREADS_WIN32) @@ -417,10 +353,7 @@ /* LDAP SUPPORT */ /* ---------------------------------------------------------------- */ -#ifdef CURL_HAS_OPENLDAP_LDAPSDK -#undef USE_WIN32_LDAP -#define HAVE_LDAP_URL_PARSE 1 -#elif !defined(CURL_WINDOWS_UWP) && !defined(UNDER_CE) +#ifndef CURL_WINDOWS_UWP #undef HAVE_LDAP_URL_PARSE #define HAVE_LDAP_SSL 1 #define USE_WIN32_LDAP 1 @@ -432,9 +365,7 @@ #endif /* Define to use Unix sockets. */ -#ifndef UNDER_CE #define USE_UNIX_SOCKETS -#endif /* ---------------------------------------------------------------- */ /* ADDITIONAL DEFINITIONS */ @@ -442,52 +373,19 @@ /* Define cpu-machine-OS */ #ifndef CURL_OS -# ifdef UNDER_CE -# ifdef _M_ARM -# define CURL_OS "arm-pc-win32ce" -# else -# define CURL_OS "i386-pc-win32ce" -# endif -# else /* !UNDER_CE */ -# if defined(_M_IX86) || defined(__i386__) /* x86 (MSVC or gcc) */ -# define CURL_OS "i386-pc-win32" -# elif defined(_M_X64) || defined(__x86_64__) /* x86_64 (VS2005+ or gcc) */ -# define CURL_OS "x86_64-pc-win32" -# elif defined(_M_IA64) || defined(__ia64__) /* Itanium */ -# define CURL_OS "ia64-pc-win32" -# elif defined(_M_ARM_NT) || defined(__arm__) /* ARMv7-Thumb2 */ -# define CURL_OS "thumbv7a-pc-win32" -# elif defined(_M_ARM64) || defined(__aarch64__) /* ARM64 (Windows 10) */ -# define CURL_OS "aarch64-pc-win32" -# else -# define CURL_OS "unknown-pc-win32" -# endif -# endif /* UNDER_CE */ +# if defined(_M_IX86) || defined(__i386__) /* x86 (MSVC or gcc) */ +# define CURL_OS "i386-pc-win32" +# elif defined(_M_X64) || defined(__x86_64__) /* x86_64 (VS2005+ or gcc) */ +# define CURL_OS "x86_64-pc-win32" +# elif defined(_M_IA64) || defined(__ia64__) /* Itanium */ +# define CURL_OS "ia64-pc-win32" +# elif defined(_M_ARM_NT) || defined(__arm__) /* ARMv7-Thumb2 */ +# define CURL_OS "thumbv7a-pc-win32" +# elif defined(_M_ARM64) || defined(__aarch64__) /* ARM64 (Windows 10) */ +# define CURL_OS "aarch64-pc-win32" +# else +# define CURL_OS "unknown-pc-win32" +# endif #endif /* !CURL_OS */ -/* ---------------------------------------------------------------- */ -/* Windows CE */ -/* ---------------------------------------------------------------- */ - -#ifdef UNDER_CE - -#ifndef UNICODE -#define UNICODE -#endif - -#ifndef _UNICODE -#define _UNICODE -#endif - -#define CURL_DISABLE_FILE 1 -#define CURL_DISABLE_TELNET 1 -#define CURL_DISABLE_LDAP 1 - -#ifndef _MSC_VER -/* !checksrc! disable BANNEDFUNC 1 */ -extern int stat(const char *path, struct stat *buffer); -#endif - -#endif /* UNDER_CE */ - #endif /* HEADER_CURL_CONFIG_WIN32_H */ diff --git a/vendor/hydra/vendor/curl/lib/conncache.c b/vendor/hydra/vendor/curl/lib/conncache.c index 5c4bc357..1a3dba7f 100644 --- a/vendor/hydra/vendor/curl/lib/conncache.c +++ b/vendor/hydra/vendor/curl/lib/conncache.c @@ -22,39 +22,28 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include - #include "urldata.h" #include "url.h" #include "cfilters.h" #include "progress.h" #include "multiif.h" -#include "multi_ev.h" -#include "sendf.h" +#include "curl_trc.h" #include "cshutdn.h" #include "conncache.h" -#include "http_negotiate.h" -#include "http_ntlm.h" -#include "share.h" +#include "curl_share.h" #include "sigpipe.h" #include "connect.h" #include "select.h" #include "curlx/strparse.h" -#include "uint-table.h" - -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" #define CPOOL_IS_LOCKED(c) ((c) && (c)->locked) -#define CPOOL_LOCK(c,d) \ +#define CPOOL_LOCK(c, d) \ do { \ - if((c)) { \ + if(c) { \ if(CURL_SHARE_KEEP_CONNECT((c)->share)) \ Curl_share_lock((d), CURL_LOCK_DATA_CONNECT, \ CURL_LOCK_ACCESS_SINGLE); \ @@ -63,9 +52,9 @@ } \ } while(0) -#define CPOOL_UNLOCK(c,d) \ +#define CPOOL_UNLOCK(c,d) \ do { \ - if((c)) { \ + if(c) { \ DEBUGASSERT((c)->locked); \ (c)->locked = FALSE; \ if(CURL_SHARE_KEEP_CONNECT((c)->share)) \ @@ -73,7 +62,6 @@ } \ } while(0) - /* A list of connections to the same destination. */ struct cpool_bundle { struct Curl_llist conns; /* connections in the bundle */ @@ -81,7 +69,6 @@ struct cpool_bundle { char dest[1]; /* destination of bundle, allocated to keep dest_len bytes */ }; - static void cpool_discard_conn(struct cpool *cpool, struct Curl_easy *data, struct connectdata *conn, @@ -92,7 +79,7 @@ static struct cpool_bundle *cpool_bundle_create(const char *dest) struct cpool_bundle *bundle; size_t dest_len = strlen(dest) + 1; - bundle = calloc(1, sizeof(*bundle) + dest_len - 1); + bundle = curlx_calloc(1, sizeof(*bundle) + dest_len - 1); if(!bundle) return NULL; Curl_llist_init(&bundle->conns, NULL); @@ -104,7 +91,7 @@ static struct cpool_bundle *cpool_bundle_create(const char *dest) static void cpool_bundle_destroy(struct cpool_bundle *bundle) { DEBUGASSERT(!Curl_llist_count(&bundle->conns)); - free(bundle); + curlx_free(bundle); } /* Add a connection to a bundle */ @@ -165,7 +152,6 @@ static struct connectdata *cpool_get_first(struct cpool *cpool) return NULL; } - static struct cpool_bundle *cpool_find_bundle(struct cpool *cpool, struct connectdata *conn) { @@ -173,7 +159,6 @@ static struct cpool_bundle *cpool_find_bundle(struct cpool *cpool, conn->destination, strlen(conn->destination) + 1); } - static void cpool_remove_bundle(struct cpool *cpool, struct cpool_bundle *bundle) { @@ -182,7 +167,6 @@ static void cpool_remove_bundle(struct cpool *cpool, Curl_hash_delete(&cpool->dest2bundle, bundle->dest, bundle->dest_len); } - static void cpool_remove_conn(struct cpool *cpool, struct connectdata *conn) { @@ -220,7 +204,6 @@ void Curl_cpool_destroy(struct cpool *cpool) while(conn) { cpool_remove_conn(cpool, conn); sigpipe_apply(cpool->idata, &pipe_st); - connclose(conn, "kill all"); cpool_discard_conn(cpool, cpool->idata, conn, FALSE); conn = cpool_get_first(cpool); } @@ -265,8 +248,8 @@ void Curl_cpool_xfer_init(struct Curl_easy *data) } } -static struct cpool_bundle * -cpool_add_bundle(struct cpool *cpool, struct connectdata *conn) +static struct cpool_bundle *cpool_add_bundle(struct cpool *cpool, + struct connectdata *conn) { struct cpool_bundle *bundle; @@ -283,23 +266,22 @@ cpool_add_bundle(struct cpool *cpool, struct connectdata *conn) } static struct connectdata * -cpool_bundle_get_oldest_idle(struct cpool_bundle *bundle) +cpool_bundle_get_oldest_idle(struct cpool_bundle *bundle, + const struct curltime *pnow) { struct Curl_llist_node *curr; timediff_t highscore = -1; timediff_t score; - struct curltime now; struct connectdata *oldest_idle = NULL; struct connectdata *conn; - now = curlx_now(); curr = Curl_llist_head(&bundle->conns); while(curr) { conn = Curl_node_elem(curr); if(!CONN_INUSE(conn)) { /* Set higher score for the age passed since the connection was used */ - score = curlx_timediff(now, conn->lastused); + score = curlx_ptimediff_ms(pnow, &conn->lastused); if(score > highscore) { highscore = score; @@ -311,18 +293,17 @@ cpool_bundle_get_oldest_idle(struct cpool_bundle *bundle) return oldest_idle; } -static struct connectdata *cpool_get_oldest_idle(struct cpool *cpool) +static struct connectdata *cpool_get_oldest_idle(struct cpool *cpool, + const struct curltime *pnow) { struct Curl_hash_iterator iter; struct Curl_llist_node *curr; struct Curl_hash_element *he; struct connectdata *oldest_idle = NULL; struct cpool_bundle *bundle; - struct curltime now; timediff_t highscore = -1; timediff_t score; - now = curlx_now(); Curl_hash_start_iterate(&cpool->dest2bundle, &iter); for(he = Curl_hash_next_element(&iter); he; @@ -336,7 +317,7 @@ static struct connectdata *cpool_get_oldest_idle(struct cpool *cpool) if(CONN_INUSE(conn) || conn->bits.close || conn->connect_only) continue; /* Set higher score for the age passed since the connection was used */ - score = curlx_timediff(now, conn->lastused); + score = curlx_ptimediff_ms(pnow, &conn->lastused); if(score > highscore) { highscore = score; oldest_idle = conn; @@ -346,7 +327,6 @@ static struct connectdata *cpool_get_oldest_idle(struct cpool *cpool) return oldest_idle; } - int Curl_cpool_check_limits(struct Curl_easy *data, struct connectdata *conn) { @@ -375,7 +355,7 @@ int Curl_cpool_check_limits(struct Curl_easy *data, bundle = cpool_find_bundle(cpool, conn); live = bundle ? Curl_llist_count(&bundle->conns) : 0; shutdowns = Curl_cshutdn_dest_count(data, conn->destination); - while((live + shutdowns) >= dest_limit) { + while((live + shutdowns) >= dest_limit) { if(shutdowns) { /* close one connection in shutdown right away, if we can */ if(!Curl_cshutdn_close_oldest(data, conn->destination)) @@ -387,14 +367,15 @@ int Curl_cpool_check_limits(struct Curl_easy *data, struct connectdata *oldest_idle = NULL; /* The bundle is full. Extract the oldest connection that may * be removed now, if there is one. */ - oldest_idle = cpool_bundle_get_oldest_idle(bundle); + oldest_idle = cpool_bundle_get_oldest_idle(bundle, + Curl_pgrs_now(data)); if(!oldest_idle) break; /* disconnect the old conn and continue */ - CURL_TRC_M(data, "Discarding connection #%" - FMT_OFF_T " from %zu to reach destination " - "limit of %zu", oldest_idle->connection_id, - Curl_llist_count(&bundle->conns), dest_limit); + CURL_TRC_M(data, "Discarding connection #%" FMT_OFF_T + " from %zu to reach destination limit of %zu", + oldest_idle->connection_id, + Curl_llist_count(&bundle->conns), dest_limit); Curl_conn_terminate(cpool->idata, oldest_idle, FALSE); /* in case the bundle was destroyed in disconnect, look it up again */ @@ -418,7 +399,8 @@ int Curl_cpool_check_limits(struct Curl_easy *data, break; } else { - struct connectdata *oldest_idle = cpool_get_oldest_idle(cpool); + struct connectdata *oldest_idle = + cpool_get_oldest_idle(cpool, Curl_pgrs_now(data)); if(!oldest_idle) break; /* disconnect the old conn and continue */ @@ -536,6 +518,9 @@ bool Curl_cpool_conn_now_idle(struct Curl_easy *data, struct cpool *cpool = cpool_get_instance(data); bool kept = TRUE; + if(!data) + return kept; + if(!data->multi->maxconnects) { unsigned int running = Curl_multi_xfers_running(data->multi); maxconnects = (running <= UINT_MAX / 4) ? running * 4 : UINT_MAX; @@ -544,7 +529,7 @@ bool Curl_cpool_conn_now_idle(struct Curl_easy *data, maxconnects = data->multi->maxconnects; } - conn->lastused = curlx_now(); /* it was used up until now */ + conn->lastused = *Curl_pgrs_now(data); /* it was used up until now */ if(cpool && maxconnects) { /* may be called form a callback already under lock */ bool do_lock = !CPOOL_IS_LOCKED(cpool); @@ -554,7 +539,7 @@ bool Curl_cpool_conn_now_idle(struct Curl_easy *data, infof(data, "Connection pool is full, closing the oldest of %zu/%u", cpool->num_conn, maxconnects); - oldest_idle = cpool_get_oldest_idle(cpool); + oldest_idle = cpool_get_oldest_idle(cpool, Curl_pgrs_now(data)); kept = (oldest_idle != conn); if(oldest_idle) { Curl_conn_terminate(data, oldest_idle, FALSE); @@ -626,7 +611,7 @@ static void cpool_discard_conn(struct cpool *cpool, if(CONN_INUSE(conn) && !aborted) { CURL_TRC_M(data, "[CPOOL] not discarding #%" FMT_OFF_T " still in use by %u transfers", conn->connection_id, - CONN_ATTACHED(conn)); + conn->attached_xfers); return; } @@ -670,7 +655,7 @@ void Curl_conn_terminate(struct Curl_easy *data, * are other users of it */ if(CONN_INUSE(conn) && !aborted) { DEBUGASSERT(0); /* does this ever happen? */ - DEBUGF(infof(data, "Curl_disconnect when inuse: %u", CONN_ATTACHED(conn))); + DEBUGF(infof(data, "conn terminate when inuse: %u", conn->attached_xfers)); return; } @@ -706,18 +691,24 @@ void Curl_conn_terminate(struct Curl_easy *data, CPOOL_UNLOCK(cpool, data); } - struct cpool_reaper_ctx { - struct curltime now; + size_t checked; + size_t reaped; }; static int cpool_reap_dead_cb(struct Curl_easy *data, struct connectdata *conn, void *param) { - struct cpool_reaper_ctx *rctx = param; - if((!CONN_INUSE(conn) && conn->bits.no_reuse) || - Curl_conn_seems_dead(conn, data, &rctx->now)) { + struct cpool_reaper_ctx *reaper = param; + bool terminate = !CONN_INUSE(conn) && conn->bits.no_reuse; + + if(!terminate) { + reaper->checked++; + terminate = Curl_conn_seems_dead(conn, data); + } + if(terminate) { /* stop the iteration here, pass back the connection that was pruned */ + reaper->reaped++; Curl_conn_terminate(data, conn, FALSE); return 1; } @@ -734,20 +725,20 @@ static int cpool_reap_dead_cb(struct Curl_easy *data, void Curl_cpool_prune_dead(struct Curl_easy *data) { struct cpool *cpool = cpool_get_instance(data); - struct cpool_reaper_ctx rctx; + struct cpool_reaper_ctx reaper; timediff_t elapsed; if(!cpool) return; - rctx.now = curlx_now(); + memset(&reaper, 0, sizeof(reaper)); CPOOL_LOCK(cpool, data); - elapsed = curlx_timediff(rctx.now, cpool->last_cleanup); + elapsed = curlx_ptimediff_ms(Curl_pgrs_now(data), &cpool->last_cleanup); if(elapsed >= 1000L) { - while(cpool_foreach(data, cpool, &rctx, cpool_reap_dead_cb)) + while(cpool_foreach(data, cpool, &reaper, cpool_reap_dead_cb)) ; - cpool->last_cleanup = rctx.now; + cpool->last_cleanup = *Curl_pgrs_now(data); } CPOOL_UNLOCK(cpool, data); } @@ -756,21 +747,20 @@ static int conn_upkeep(struct Curl_easy *data, struct connectdata *conn, void *param) { - struct curltime *now = param; - Curl_conn_upkeep(data, conn, now); + (void)param; + Curl_conn_upkeep(data, conn); return 0; /* continue iteration */ } -CURLcode Curl_cpool_upkeep(void *data) +CURLcode Curl_cpool_upkeep(struct Curl_easy *data) { struct cpool *cpool = cpool_get_instance(data); - struct curltime now = curlx_now(); if(!cpool) return CURLE_OK; CPOOL_LOCK(cpool, data); - cpool_foreach(data, cpool, &now, conn_upkeep); + cpool_foreach(data, cpool, NULL, conn_upkeep); CPOOL_UNLOCK(cpool, data); return CURLE_OK; } diff --git a/vendor/hydra/vendor/curl/lib/conncache.h b/vendor/hydra/vendor/curl/lib/conncache.h index a5f13334..9b392af0 100644 --- a/vendor/hydra/vendor/curl/lib/conncache.h +++ b/vendor/hydra/vendor/curl/lib/conncache.h @@ -24,8 +24,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - -#include #include "curlx/timeval.h" struct connectdata; @@ -49,7 +47,7 @@ void Curl_conn_terminate(struct Curl_easy *data, bool aborted); struct cpool { - /* the pooled connections, bundled per destination */ + /* the pooled connections, bundled per destination */ struct Curl_hash dest2bundle; size_t num_conn; curl_off_t next_connection_id; @@ -139,7 +137,7 @@ void Curl_cpool_prune_dead(struct Curl_easy *data); /** * Perform upkeep actions on connections in the transfer's pool. */ -CURLcode Curl_cpool_upkeep(void *data); +CURLcode Curl_cpool_upkeep(struct Curl_easy *data); typedef void Curl_cpool_conn_do_cb(struct connectdata *conn, struct Curl_easy *data, @@ -166,5 +164,4 @@ void Curl_cpool_do_locked(struct Curl_easy *data, /* Close all unused connections, prevent reuse of existing ones. */ void Curl_cpool_nw_changed(struct Curl_easy *data); - #endif /* HEADER_CURL_CONNCACHE_H */ diff --git a/vendor/hydra/vendor/curl/lib/connect.c b/vendor/hydra/vendor/curl/lib/connect.c index e3295524..6e178345 100644 --- a/vendor/hydra/vendor/curl/lib/connect.c +++ b/vendor/hydra/vendor/curl/lib/connect.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifdef HAVE_NETINET_IN_H @@ -51,8 +50,7 @@ #endif #include "urldata.h" -#include "sendf.h" -#include "if2ip.h" +#include "curl_trc.h" #include "strerror.h" #include "cfilters.h" #include "connect.h" @@ -60,63 +58,59 @@ #include "cf-https-connect.h" #include "cf-ip-happy.h" #include "cf-socket.h" -#include "select.h" -#include "url.h" /* for Curl_safefree() */ #include "multiif.h" -#include "sockaddr.h" /* required for Curl_sockaddr_storage */ #include "curlx/inet_ntop.h" -#include "curlx/inet_pton.h" +#include "curlx/strparse.h" #include "vtls/vtls.h" /* for vtsl cfilters */ #include "progress.h" -#include "curlx/warnless.h" #include "conncache.h" #include "multihandle.h" -#include "share.h" #include "http_proxy.h" #include "socks.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #if !defined(CURL_DISABLE_ALTSVC) || defined(USE_HTTPSRR) -enum alpnid Curl_alpn2alpnid(const char *name, size_t len) +enum alpnid Curl_alpn2alpnid(const unsigned char *name, size_t len) { if(len == 2) { - if(curl_strnequal(name, "h1", 2)) + if(!memcmp(name, "h1", 2)) return ALPN_h1; - if(curl_strnequal(name, "h2", 2)) + if(!memcmp(name, "h2", 2)) return ALPN_h2; - if(curl_strnequal(name, "h3", 2)) + if(!memcmp(name, "h3", 2)) return ALPN_h3; } else if(len == 8) { - if(curl_strnequal(name, "http/1.1", 8)) + if(!memcmp(name, "http/1.1", 8)) return ALPN_h1; } return ALPN_none; /* unknown, probably rubbish input */ } +enum alpnid Curl_str2alpnid(const struct Curl_str *cstr) +{ + return Curl_alpn2alpnid((const unsigned char *)curlx_str(cstr), + curlx_strlen(cstr)); +} + #endif /* - * Curl_timeleft() returns the amount of milliseconds left allowed for the + * Curl_timeleft_ms() returns the amount of milliseconds left allowed for the * transfer/connection. If the value is 0, there is no timeout (ie there is * infinite time left). If the value is negative, the timeout time has already * elapsed. * @param data the transfer to check on - * @param nowp timestamp to use for calculation, NULL to use curlx_now() * @param duringconnect TRUE iff connect timeout is also taken into account. * @unittest: 1303 */ -timediff_t Curl_timeleft(struct Curl_easy *data, - struct curltime *nowp, - bool duringconnect) +timediff_t Curl_timeleft_now_ms(struct Curl_easy *data, + const struct curltime *pnow, + bool duringconnect) { timediff_t timeleft_ms = 0; timediff_t ctimeleft_ms = 0; - struct curltime now; + timediff_t ctimeout_ms; /* The duration of a connect and the total transfer are calculated from two different time-stamps. It can end up with the total timeout being reached @@ -126,90 +120,76 @@ timediff_t Curl_timeleft(struct Curl_easy *data, if((!data->set.timeout || data->set.connect_only) && !duringconnect) return 0; /* no timeout in place or checked, return "no limit" */ - if(!nowp) { - now = curlx_now(); - nowp = &now; - } - if(data->set.timeout) { timeleft_ms = data->set.timeout - - curlx_timediff(*nowp, data->progress.t_startop); + curlx_ptimediff_ms(pnow, &data->progress.t_startop); if(!timeleft_ms) timeleft_ms = -1; /* 0 is "no limit", fake 1 ms expiry */ - if(!duringconnect) - return timeleft_ms; /* no connect check, this is it */ } - if(duringconnect) { - timediff_t ctimeout_ms = (data->set.connecttimeout > 0) ? - data->set.connecttimeout : DEFAULT_CONNECT_TIMEOUT; - ctimeleft_ms = ctimeout_ms - - curlx_timediff(*nowp, data->progress.t_startsingle); - if(!ctimeleft_ms) - ctimeleft_ms = -1; /* 0 is "no limit", fake 1 ms expiry */ - if(!timeleft_ms) - return ctimeleft_ms; /* no general timeout, this is it */ - } + if(!duringconnect) + return timeleft_ms; /* no connect check, this is it */ + ctimeout_ms = (data->set.connecttimeout > 0) ? + data->set.connecttimeout : DEFAULT_CONNECT_TIMEOUT; + ctimeleft_ms = ctimeout_ms - + curlx_ptimediff_ms(pnow, &data->progress.t_startsingle); + if(!ctimeleft_ms) + ctimeleft_ms = -1; /* 0 is "no limit", fake 1 ms expiry */ + if(!timeleft_ms) + return ctimeleft_ms; /* no general timeout, this is it */ + /* return minimal time left or max amount already expired */ return (ctimeleft_ms < timeleft_ms) ? ctimeleft_ms : timeleft_ms; } +timediff_t Curl_timeleft_ms(struct Curl_easy *data, + bool duringconnect) +{ + return Curl_timeleft_now_ms(data, Curl_pgrs_now(data), duringconnect); +} + void Curl_shutdown_start(struct Curl_easy *data, int sockindex, - int timeout_ms, struct curltime *nowp) + int timeout_ms) { - struct curltime now; struct connectdata *conn = data->conn; DEBUGASSERT(conn); - if(!nowp) { - now = curlx_now(); - nowp = &now; - } - conn->shutdown.start[sockindex] = *nowp; + conn->shutdown.start[sockindex] = *Curl_pgrs_now(data); conn->shutdown.timeout_ms = (timeout_ms > 0) ? (timediff_t)timeout_ms : ((data->set.shutdowntimeout > 0) ? data->set.shutdowntimeout : DEFAULT_SHUTDOWN_TIMEOUT_MS); /* Set a timer, unless we operate on the admin handle */ if(data->mid) - Curl_expire_ex(data, nowp, conn->shutdown.timeout_ms, - EXPIRE_SHUTDOWN); + Curl_expire_ex(data, conn->shutdown.timeout_ms, EXPIRE_SHUTDOWN); } -timediff_t Curl_shutdown_timeleft(struct connectdata *conn, int sockindex, - struct curltime *nowp) +timediff_t Curl_shutdown_timeleft(struct Curl_easy *data, + struct connectdata *conn, + int sockindex) { - struct curltime now; timediff_t left_ms; if(!conn->shutdown.start[sockindex].tv_sec || (conn->shutdown.timeout_ms <= 0)) return 0; /* not started or no limits */ - if(!nowp) { - now = curlx_now(); - nowp = &now; - } left_ms = conn->shutdown.timeout_ms - - curlx_timediff(*nowp, conn->shutdown.start[sockindex]); + curlx_ptimediff_ms(Curl_pgrs_now(data), + &conn->shutdown.start[sockindex]); return left_ms ? left_ms : -1; } -timediff_t Curl_conn_shutdown_timeleft(struct connectdata *conn, - struct curltime *nowp) +timediff_t Curl_conn_shutdown_timeleft(struct Curl_easy *data, + struct connectdata *conn) { timediff_t left_ms = 0, ms; - struct curltime now; int i; for(i = 0; conn->shutdown.timeout_ms && (i < 2); ++i) { if(!conn->shutdown.start[i].tv_sec) continue; - if(!nowp) { - now = curlx_now(); - nowp = &now; - } - ms = Curl_shutdown_timeleft(conn, i, nowp); + ms = Curl_shutdown_timeleft(data, conn, i); if(ms && (!left_ms || ms < left_ms)) left_ms = ms; } @@ -231,56 +211,53 @@ bool Curl_shutdown_started(struct Curl_easy *data, int sockindex) /* retrieves ip address and port from a sockaddr structure. note it calls curlx_inet_ntop which sets errno on fail, not SOCKERRNO. */ bool Curl_addr2string(struct sockaddr *sa, curl_socklen_t salen, - char *addr, int *port) + char *addr, uint16_t *port) { struct sockaddr_in *si = NULL; #ifdef USE_IPV6 struct sockaddr_in6 *si6 = NULL; #endif -#if (defined(HAVE_SYS_UN_H) || defined(WIN32_SOCKADDR_UN)) && defined(AF_UNIX) +#ifdef USE_UNIX_SOCKETS struct sockaddr_un *su = NULL; #else (void)salen; #endif switch(sa->sa_family) { - case AF_INET: - si = (struct sockaddr_in *)(void *) sa; - if(curlx_inet_ntop(sa->sa_family, &si->sin_addr, addr, MAX_IPADR_LEN)) { - unsigned short us_port = ntohs(si->sin_port); - *port = us_port; - return TRUE; - } - break; + case AF_INET: + si = (struct sockaddr_in *)(void *)sa; + if(curlx_inet_ntop(sa->sa_family, &si->sin_addr, addr, MAX_IPADR_LEN)) { + *port = ntohs(si->sin_port); + return TRUE; + } + break; #ifdef USE_IPV6 - case AF_INET6: - si6 = (struct sockaddr_in6 *)(void *) sa; - if(curlx_inet_ntop(sa->sa_family, &si6->sin6_addr, addr, - MAX_IPADR_LEN)) { - unsigned short us_port = ntohs(si6->sin6_port); - *port = us_port; - return TRUE; - } - break; -#endif -#if (defined(HAVE_SYS_UN_H) || defined(WIN32_SOCKADDR_UN)) && defined(AF_UNIX) - case AF_UNIX: - if(salen > (curl_socklen_t)sizeof(CURL_SA_FAMILY_T)) { - su = (struct sockaddr_un*)sa; - curl_msnprintf(addr, MAX_IPADR_LEN, "%s", su->sun_path); - } - else - addr[0] = 0; /* socket with no name */ - *port = 0; + case AF_INET6: + si6 = (struct sockaddr_in6 *)(void *)sa; + if(curlx_inet_ntop(sa->sa_family, &si6->sin6_addr, addr, MAX_IPADR_LEN)) { + *port = ntohs(si6->sin6_port); return TRUE; + } + break; #endif - default: - break; +#ifdef USE_UNIX_SOCKETS + case AF_UNIX: + if(salen > (curl_socklen_t)sizeof(CURL_SA_FAMILY_T)) { + su = (struct sockaddr_un *)sa; + curl_msnprintf(addr, MAX_IPADR_LEN, "%s", su->sun_path); + } + else + addr[0] = 0; /* socket with no name */ + *port = 0; + return TRUE; +#endif + default: + break; } addr[0] = '\0'; *port = 0; - CURL_SETERRNO(SOCKEAFNOSUPPORT); + errno = SOCKEAFNOSUPPORT; return FALSE; } @@ -337,7 +314,7 @@ void Curl_conncontrol(struct connectdata *conn, #endif is_multiplex = Curl_conn_is_multiplex(conn, FIRSTSOCKET); closeit = (ctrl == CONNCTRL_CONNECTION) || - ((ctrl == CONNCTRL_STREAM) && !is_multiplex); + ((ctrl == CONNCTRL_STREAM) && !is_multiplex); if((ctrl == CONNCTRL_STREAM) && is_multiplex) ; /* stream signal on multiplex conn never affects close state */ else if((bit)closeit != conn->bits.close) { @@ -359,7 +336,7 @@ typedef enum { struct cf_setup_ctx { cf_setup_state state; int ssl_mode; - int transport; + uint8_t transport; }; static CURLcode cf_setup_connect(struct Curl_cfilter *cf, @@ -408,8 +385,8 @@ static CURLcode cf_setup_connect(struct Curl_cfilter *cf, if(ctx->state < CF_SETUP_CNNCT_HTTP_PROXY && cf->conn->bits.httpproxy) { #ifdef USE_SSL - if(IS_HTTPS_PROXY(cf->conn->http_proxy.proxytype) - && !Curl_conn_is_ssl(cf->conn, cf->sockindex)) { + if(IS_HTTPS_PROXY(cf->conn->http_proxy.proxytype) && + !Curl_conn_is_ssl(cf->conn, cf->sockindex)) { result = Curl_cf_ssl_proxy_insert_after(cf, data); if(result) return result; @@ -449,9 +426,9 @@ static CURLcode cf_setup_connect(struct Curl_cfilter *cf, if(ctx->state < CF_SETUP_CNNCT_SSL) { #ifdef USE_SSL - if((ctx->ssl_mode == CURL_CF_SSL_ENABLE - || (ctx->ssl_mode != CURL_CF_SSL_DISABLE - && cf->conn->handler->flags & PROTOPT_SSL)) /* we want SSL */ + if((ctx->ssl_mode == CURL_CF_SSL_ENABLE || + (ctx->ssl_mode != CURL_CF_SSL_DISABLE && + cf->conn->handler->flags & PROTOPT_SSL)) /* we want SSL */ && !Curl_conn_is_ssl(cf->conn, cf->sockindex)) { /* it is missing */ result = Curl_cf_ssl_insert_after(cf, data); if(result) @@ -493,7 +470,6 @@ static void cf_setup_destroy(struct Curl_cfilter *cf, struct Curl_easy *data) Curl_safefree(ctx); } - struct Curl_cftype Curl_cft_setup = { "SETUP", 0, @@ -514,7 +490,7 @@ struct Curl_cftype Curl_cft_setup = { static CURLcode cf_setup_create(struct Curl_cfilter **pcf, struct Curl_easy *data, - int transport, + uint8_t transport, int ssl_mode) { struct Curl_cfilter *cf = NULL; @@ -522,7 +498,7 @@ static CURLcode cf_setup_create(struct Curl_cfilter **pcf, CURLcode result = CURLE_OK; (void)data; - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -539,7 +515,7 @@ static CURLcode cf_setup_create(struct Curl_cfilter **pcf, out: *pcf = result ? NULL : cf; if(ctx) { - free(ctx); + curlx_free(ctx); } return result; } @@ -547,7 +523,7 @@ static CURLcode cf_setup_create(struct Curl_cfilter **pcf, static CURLcode cf_setup_add(struct Curl_easy *data, struct connectdata *conn, int sockindex, - int transport, + uint8_t transport, int ssl_mode) { struct Curl_cfilter *cf; @@ -564,7 +540,7 @@ static CURLcode cf_setup_add(struct Curl_easy *data, CURLcode Curl_cf_setup_insert_after(struct Curl_cfilter *cf_at, struct Curl_easy *data, - int transport, + uint8_t transport, int ssl_mode) { struct Curl_cfilter *cf; diff --git a/vendor/hydra/vendor/curl/lib/connect.h b/vendor/hydra/vendor/curl/lib/connect.h index cb185b2c..01e9dfc0 100644 --- a/vendor/hydra/vendor/curl/lib/connect.h +++ b/vendor/hydra/vendor/curl/lib/connect.h @@ -25,37 +25,40 @@ ***************************************************************************/ #include "curl_setup.h" -#include "curlx/nonblock.h" /* for curlx_nonblock() */ -#include "sockaddr.h" #include "curlx/timeval.h" struct Curl_dns_entry; struct ip_quadruple; +struct Curl_str; -enum alpnid Curl_alpn2alpnid(const char *name, size_t len); +enum alpnid Curl_alpn2alpnid(const unsigned char *name, size_t len); +enum alpnid Curl_str2alpnid(const struct Curl_str *str); /* generic function that returns how much time there is left to run, according to the timeouts set */ -timediff_t Curl_timeleft(struct Curl_easy *data, - struct curltime *nowp, - bool duringconnect); +timediff_t Curl_timeleft_ms(struct Curl_easy *data, + bool duringconnect); +timediff_t Curl_timeleft_now_ms(struct Curl_easy *data, + const struct curltime *pnow, + bool duringconnect); #define DEFAULT_CONNECT_TIMEOUT 300000 /* milliseconds == five minutes */ #define DEFAULT_SHUTDOWN_TIMEOUT_MS (2 * 1000) void Curl_shutdown_start(struct Curl_easy *data, int sockindex, - int timeout_ms, struct curltime *nowp); + int timeout_ms); /* return how much time there is left to shutdown the connection at * sockindex. Returns 0 if there is no limit or shutdown has not started. */ -timediff_t Curl_shutdown_timeleft(struct connectdata *conn, int sockindex, - struct curltime *nowp); +timediff_t Curl_shutdown_timeleft(struct Curl_easy *data, + struct connectdata *conn, + int sockindex); /* return how much time there is left to shutdown the connection. * Returns 0 if there is no limit or shutdown has not started. */ -timediff_t Curl_conn_shutdown_timeleft(struct connectdata *conn, - struct curltime *nowp); +timediff_t Curl_conn_shutdown_timeleft(struct Curl_easy *data, + struct connectdata *conn); void Curl_shutdown_clear(struct Curl_easy *data, int sockindex); @@ -72,7 +75,7 @@ curl_socket_t Curl_getconnectinfo(struct Curl_easy *data, struct connectdata **connp); bool Curl_addr2string(struct sockaddr *sa, curl_socklen_t salen, - char *addr, int *port); + char *addr, uint16_t *port); /* * Curl_conncontrol() marks the end of a connection/stream. The 'closeit' @@ -98,18 +101,18 @@ void Curl_conncontrol(struct connectdata *conn, ); #if defined(DEBUGBUILD) && !defined(CURL_DISABLE_VERBOSE_STRINGS) -#define streamclose(x,y) Curl_conncontrol(x, CONNCTRL_STREAM, y) -#define connclose(x,y) Curl_conncontrol(x, CONNCTRL_CONNECTION, y) -#define connkeep(x,y) Curl_conncontrol(x, CONNCTRL_KEEP, y) +#define streamclose(x, y) Curl_conncontrol(x, CONNCTRL_STREAM, y) +#define connclose(x, y) Curl_conncontrol(x, CONNCTRL_CONNECTION, y) +#define connkeep(x, y) Curl_conncontrol(x, CONNCTRL_KEEP, y) #else /* if !DEBUGBUILD || CURL_DISABLE_VERBOSE_STRINGS */ -#define streamclose(x,y) Curl_conncontrol(x, CONNCTRL_STREAM) -#define connclose(x,y) Curl_conncontrol(x, CONNCTRL_CONNECTION) -#define connkeep(x,y) Curl_conncontrol(x, CONNCTRL_KEEP) +#define streamclose(x, y) Curl_conncontrol(x, CONNCTRL_STREAM) +#define connclose(x, y) Curl_conncontrol(x, CONNCTRL_CONNECTION) +#define connkeep(x, y) Curl_conncontrol(x, CONNCTRL_KEEP) #endif CURLcode Curl_cf_setup_insert_after(struct Curl_cfilter *cf_at, struct Curl_easy *data, - int transport, + uint8_t transport, int ssl_mode); /** diff --git a/vendor/hydra/vendor/curl/lib/content_encoding.c b/vendor/hydra/vendor/curl/lib/content_encoding.c index b724b576..70fb5692 100644 --- a/vendor/hydra/vendor/curl/lib/content_encoding.c +++ b/vendor/hydra/vendor/curl/lib/content_encoding.c @@ -21,12 +21,10 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #include "urldata.h" -#include -#include +#include "curlx/dynbuf.h" #ifdef HAVE_LIBZ #include @@ -49,13 +47,9 @@ #endif #include "sendf.h" -#include "http.h" +#include "curl_trc.h" #include "content_encoding.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #define CONTENT_ENCODING_DEFAULT "identity" #ifndef CURL_DISABLE_HTTP @@ -90,24 +84,20 @@ struct zlib_writer { z_stream z; /* State structure for zlib. */ }; - -static voidpf -zalloc_cb(voidpf opaque, unsigned int items, unsigned int size) +static voidpf zalloc_cb(voidpf opaque, unsigned int items, unsigned int size) { (void)opaque; - /* not a typo, keep it calloc() */ - return (voidpf) calloc(items, size); + /* not a typo, keep it curlx_calloc() */ + return (voidpf)curlx_calloc(items, size); } -static void -zfree_cb(voidpf opaque, voidpf ptr) +static void zfree_cb(voidpf opaque, voidpf ptr) { (void)opaque; - free(ptr); + curlx_free(ptr); } -static CURLcode -process_zlib_error(struct Curl_easy *data, z_stream *z) +static CURLcode process_zlib_error(struct Curl_easy *data, z_stream *z) { if(z->msg) failf(data, "Error while processing content unencoding: %s", @@ -119,9 +109,8 @@ process_zlib_error(struct Curl_easy *data, z_stream *z) return CURLE_BAD_CONTENT_ENCODING; } -static CURLcode -exit_zlib(struct Curl_easy *data, - z_stream *z, zlibInitState *zlib_init, CURLcode result) +static CURLcode exit_zlib(struct Curl_easy *data, z_stream *z, + zlibInitState *zlib_init, CURLcode result) { if(*zlib_init != ZLIB_UNINIT) { if(inflateEnd(z) != Z_OK && result == CURLE_OK) @@ -132,8 +121,7 @@ exit_zlib(struct Curl_easy *data, return result; } -static CURLcode process_trailer(struct Curl_easy *data, - struct zlib_writer *zp) +static CURLcode process_trailer(struct Curl_easy *data, struct zlib_writer *zp) { z_stream *z = &zp->z; CURLcode result = CURLE_OK; @@ -160,7 +148,7 @@ static CURLcode inflate_stream(struct Curl_easy *data, struct Curl_cwriter *writer, int type, zlibInitState started) { - struct zlib_writer *zp = (struct zlib_writer *) writer; + struct zlib_writer *zp = (struct zlib_writer *)writer; z_stream *z = &zp->z; /* zlib state structure */ uInt nread = z->avail_in; z_const Bytef *orig_in = z->next_in; @@ -180,7 +168,7 @@ static CURLcode inflate_stream(struct Curl_easy *data, done = TRUE; /* (re)set buffer for decompressed output for every iteration */ - z->next_out = (Bytef *) zp->buffer; + z->next_out = (Bytef *)zp->buffer; z->avail_out = DECOMPRESS_BUFFER_SIZE; status = inflate(z, Z_BLOCK); @@ -241,17 +229,16 @@ static CURLcode inflate_stream(struct Curl_easy *data, return result; } - /* Deflate handler. */ static CURLcode deflate_do_init(struct Curl_easy *data, struct Curl_cwriter *writer) { - struct zlib_writer *zp = (struct zlib_writer *) writer; + struct zlib_writer *zp = (struct zlib_writer *)writer; z_stream *z = &zp->z; /* zlib state structure */ /* Initialize zlib */ - z->zalloc = (alloc_func) zalloc_cb; - z->zfree = (free_func) zfree_cb; + z->zalloc = (alloc_func)zalloc_cb; + z->zfree = (free_func)zfree_cb; if(inflateInit(z) != Z_OK) return process_zlib_error(data, z); @@ -263,7 +250,7 @@ static CURLcode deflate_do_write(struct Curl_easy *data, struct Curl_cwriter *writer, int type, const char *buf, size_t nbytes) { - struct zlib_writer *zp = (struct zlib_writer *) writer; + struct zlib_writer *zp = (struct zlib_writer *)writer; z_stream *z = &zp->z; /* zlib state structure */ if(!(type & CLIENTWRITE_BODY) || !nbytes) @@ -283,7 +270,7 @@ static CURLcode deflate_do_write(struct Curl_easy *data, static void deflate_do_close(struct Curl_easy *data, struct Curl_cwriter *writer) { - struct zlib_writer *zp = (struct zlib_writer *) writer; + struct zlib_writer *zp = (struct zlib_writer *)writer; z_stream *z = &zp->z; /* zlib state structure */ exit_zlib(data, z, &zp->zlib_init, CURLE_OK); @@ -298,17 +285,19 @@ static const struct Curl_cwtype deflate_encoding = { sizeof(struct zlib_writer) }; +/* + * Gzip handler. + */ -/* Gzip handler. */ static CURLcode gzip_do_init(struct Curl_easy *data, struct Curl_cwriter *writer) { - struct zlib_writer *zp = (struct zlib_writer *) writer; + struct zlib_writer *zp = (struct zlib_writer *)writer; z_stream *z = &zp->z; /* zlib state structure */ /* Initialize zlib */ - z->zalloc = (alloc_func) zalloc_cb; - z->zfree = (free_func) zfree_cb; + z->zalloc = (alloc_func)zalloc_cb; + z->zfree = (free_func)zfree_cb; if(inflateInit2(z, MAX_WBITS + 32) != Z_OK) return process_zlib_error(data, z); @@ -321,7 +310,7 @@ static CURLcode gzip_do_write(struct Curl_easy *data, struct Curl_cwriter *writer, int type, const char *buf, size_t nbytes) { - struct zlib_writer *zp = (struct zlib_writer *) writer; + struct zlib_writer *zp = (struct zlib_writer *)writer; z_stream *z = &zp->z; /* zlib state structure */ if(!(type & CLIENTWRITE_BODY) || !nbytes) @@ -342,7 +331,7 @@ static CURLcode gzip_do_write(struct Curl_easy *data, static void gzip_do_close(struct Curl_easy *data, struct Curl_cwriter *writer) { - struct zlib_writer *zp = (struct zlib_writer *) writer; + struct zlib_writer *zp = (struct zlib_writer *)writer; z_stream *z = &zp->z; /* zlib state structure */ exit_zlib(data, z, &zp->zlib_init, CURLE_OK); @@ -384,12 +373,10 @@ static CURLcode brotli_map_error(BrotliDecoderErrorCode be) case BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS: case BROTLI_DECODER_ERROR_FORMAT_PADDING_1: case BROTLI_DECODER_ERROR_FORMAT_PADDING_2: -#ifdef BROTLI_DECODER_ERROR_COMPOUND_DICTIONARY +#ifdef BROTLI_DECODER_ERROR_COMPOUND_DICTIONARY /* brotli v1.1.0+ */ case BROTLI_DECODER_ERROR_COMPOUND_DICTIONARY: #endif -#ifdef BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET case BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET: -#endif case BROTLI_DECODER_ERROR_INVALID_ARGUMENTS: return CURLE_BAD_CONTENT_ENCODING; case BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES: @@ -408,7 +395,7 @@ static CURLcode brotli_map_error(BrotliDecoderErrorCode be) static CURLcode brotli_do_init(struct Curl_easy *data, struct Curl_cwriter *writer) { - struct brotli_writer *bp = (struct brotli_writer *) writer; + struct brotli_writer *bp = (struct brotli_writer *)writer; (void)data; bp->br = BrotliDecoderCreateInstance(NULL, NULL, NULL); @@ -419,8 +406,8 @@ static CURLcode brotli_do_write(struct Curl_easy *data, struct Curl_cwriter *writer, int type, const char *buf, size_t nbytes) { - struct brotli_writer *bp = (struct brotli_writer *) writer; - const uint8_t *src = (const uint8_t *) buf; + struct brotli_writer *bp = (struct brotli_writer *)writer; + const uint8_t *src = (const uint8_t *)buf; uint8_t *dst; size_t dstleft; CURLcode result = CURLE_OK; @@ -434,7 +421,7 @@ static CURLcode brotli_do_write(struct Curl_easy *data, while((nbytes || r == BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT) && result == CURLE_OK) { - dst = (uint8_t *) bp->buffer; + dst = (uint8_t *)bp->buffer; dstleft = DECOMPRESS_BUFFER_SIZE; r = BrotliDecoderDecompressStream(bp->br, &nbytes, &src, &dstleft, &dst, NULL); @@ -463,7 +450,7 @@ static CURLcode brotli_do_write(struct Curl_easy *data, static void brotli_do_close(struct Curl_easy *data, struct Curl_cwriter *writer) { - struct brotli_writer *bp = (struct brotli_writer *) writer; + struct brotli_writer *bp = (struct brotli_writer *)writer; (void)data; if(bp->br) { @@ -507,7 +494,7 @@ static void Curl_zstd_free(void *opaque, void *address) static CURLcode zstd_do_init(struct Curl_easy *data, struct Curl_cwriter *writer) { - struct zstd_writer *zp = (struct zstd_writer *) writer; + struct zstd_writer *zp = (struct zstd_writer *)writer; (void)data; @@ -529,7 +516,7 @@ static CURLcode zstd_do_write(struct Curl_easy *data, const char *buf, size_t nbytes) { CURLcode result = CURLE_OK; - struct zstd_writer *zp = (struct zstd_writer *) writer; + struct zstd_writer *zp = (struct zstd_writer *)writer; ZSTD_inBuffer in; ZSTD_outBuffer out; size_t errorCode; @@ -566,7 +553,7 @@ static CURLcode zstd_do_write(struct Curl_easy *data, static void zstd_do_close(struct Curl_easy *data, struct Curl_cwriter *writer) { - struct zstd_writer *zp = (struct zstd_writer *) writer; + struct zstd_writer *zp = (struct zstd_writer *)writer; (void)data; if(zp->zds) { @@ -619,41 +606,27 @@ static const struct Curl_cwtype * const transfer_unencoders[] = { NULL }; -/* Provide a list of comma-separated names of supported encodings. -*/ -void Curl_all_content_encodings(char *buf, size_t blen) +/* Return the list of comma-separated names of supported encodings. + */ +char *Curl_get_content_encodings(void) { - size_t len = 0; + struct dynbuf enc; const struct Curl_cwtype * const *cep; - const struct Curl_cwtype *ce; - - DEBUGASSERT(buf); - DEBUGASSERT(blen); - buf[0] = 0; - - for(cep = general_unencoders; *cep; cep++) { - ce = *cep; - if(!curl_strequal(ce->name, CONTENT_ENCODING_DEFAULT)) - len += strlen(ce->name) + 2; - } + CURLcode result = CURLE_OK; + curlx_dyn_init(&enc, 255); - if(!len) { - if(blen >= sizeof(CONTENT_ENCODING_DEFAULT)) - strcpy(buf, CONTENT_ENCODING_DEFAULT); - } - else if(blen > len) { - char *p = buf; - for(cep = general_unencoders; *cep; cep++) { - ce = *cep; - if(!curl_strequal(ce->name, CONTENT_ENCODING_DEFAULT)) { - strcpy(p, ce->name); - p += strlen(p); - *p++ = ','; - *p++ = ' '; - } + for(cep = general_unencoders; *cep && !result; cep++) { + const struct Curl_cwtype *ce = *cep; + if(!curl_strequal(ce->name, CONTENT_ENCODING_DEFAULT)) { + if(curlx_dyn_len(&enc)) + result = curlx_dyn_addn(&enc, ", ", 2); + if(!result) + result = curlx_dyn_add(&enc, ce->name); } - p[-2] = '\0'; } + if(!result) + return curlx_dyn_ptr(&enc); + return NULL; } /* Deferred error dummy writer. */ @@ -675,12 +648,7 @@ static CURLcode error_do_write(struct Curl_easy *data, if(!(type & CLIENTWRITE_BODY) || !nbytes) return Curl_cwriter_write(data, writer->next, type, buf, nbytes); - else { - char all[256]; - (void)Curl_all_content_encodings(all, sizeof(all)); - failf(data, "Unrecognized content encoding type. " - "libcurl understands %s content encodings.", all); - } + failf(data, "Unrecognized content encoding type"); return CURLE_BAD_CONTENT_ENCODING; } @@ -847,14 +815,9 @@ CURLcode Curl_build_unencoding_stack(struct Curl_easy *data, return CURLE_NOT_BUILT_IN; } -void Curl_all_content_encodings(char *buf, size_t blen) +char *Curl_get_content_encodings(void) { - DEBUGASSERT(buf); - DEBUGASSERT(blen); - if(blen < sizeof(CONTENT_ENCODING_DEFAULT)) - buf[0] = 0; - else - strcpy(buf, CONTENT_ENCODING_DEFAULT); + return curlx_strdup(CONTENT_ENCODING_DEFAULT); } #endif /* CURL_DISABLE_HTTP */ diff --git a/vendor/hydra/vendor/curl/lib/content_encoding.h b/vendor/hydra/vendor/curl/lib/content_encoding.h index 1addf230..e84a7397 100644 --- a/vendor/hydra/vendor/curl/lib/content_encoding.h +++ b/vendor/hydra/vendor/curl/lib/content_encoding.h @@ -27,7 +27,8 @@ struct Curl_cwriter; -void Curl_all_content_encodings(char *buf, size_t blen); +/* returns an allocated string or NULL */ +char *Curl_get_content_encodings(void); CURLcode Curl_build_unencoding_stack(struct Curl_easy *data, const char *enclist, int is_transfer); diff --git a/vendor/hydra/vendor/curl/lib/cookie.c b/vendor/hydra/vendor/curl/lib/cookie.c index 35b25297..c8072228 100644 --- a/vendor/hydra/vendor/curl/lib/cookie.c +++ b/vendor/hydra/vendor/curl/lib/cookie.c @@ -21,54 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - -/*** - - -RECEIVING COOKIE INFORMATION -============================ - -Curl_cookie_init() - - Inits a cookie struct to store data in a local file. This is always - called before any cookies are set. - -Curl_cookie_add() - - Adds a cookie to the in-memory cookie jar. - - -SENDING COOKIE INFORMATION -========================== - -Curl_cookie_getlist() - - For a given host and path, return a linked list of cookies that - the client should send to the server if used now. The secure - boolean informs the cookie if a secure connection is achieved or - not. - - It shall only return cookies that have not expired. - -Example set of cookies: - - Set-cookie: PRODUCTINFO=webxpress; domain=.fidelity.com; path=/; secure - Set-cookie: PERSONALIZE=none;expires=Monday, 13-Jun-1988 03:04:55 GMT; - domain=.fidelity.com; path=/ftgw; secure - Set-cookie: FidHist=none;expires=Monday, 13-Jun-1988 03:04:55 GMT; - domain=.fidelity.com; path=/; secure - Set-cookie: FidOrder=none;expires=Monday, 13-Jun-1988 03:04:55 GMT; - domain=.fidelity.com; path=/; secure - Set-cookie: DisPend=none;expires=Monday, 13-Jun-1988 03:04:55 GMT; - domain=.fidelity.com; path=/; secure - Set-cookie: FidDis=none;expires=Monday, 13-Jun-1988 03:04:55 GMT; - domain=.fidelity.com; path=/; secure - Set-cookie: - Session_Key@6791a9e0-901a-11d0-a1c8-9b012c88aa77=none;expires=Monday, - 13-Jun-1988 03:04:55 GMT; domain=.fidelity.com; path=/; secure -****/ - - #include "curl_setup.h" #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES) @@ -76,27 +28,21 @@ Example set of cookies: #include "urldata.h" #include "cookie.h" #include "psl.h" -#include "sendf.h" +#include "curl_trc.h" #include "slist.h" -#include "share.h" +#include "curl_share.h" #include "strcase.h" #include "curl_fopen.h" #include "curl_get_line.h" #include "curl_memrchr.h" #include "parsedate.h" -#include "rename.h" #include "strdup.h" #include "llist.h" +#include "bufref.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - -static void strstore(char **str, const char *newstr, size_t len); - /* number of seconds in 400 days */ -#define COOKIES_MAXAGE (400*24*3600) +#define COOKIES_MAXAGE (400 * 24 * 3600) /* Make sure cookies never expire further away in time than 400 days into the future. (from RFC6265bis draft-19) @@ -110,19 +56,19 @@ static void cap_expires(time_t now, struct Cookie *co) timediff_t cap = now + COOKIES_MAXAGE; if(co->expires > cap) { cap += 30; - co->expires = (cap/60)*60; + co->expires = (cap / 60) * 60; } } } -static void freecookie(struct Cookie *co) +static void freecookie(struct Cookie *co, bool maintoo) { - free(co->domain); - free(co->path); - free(co->spath); - free(co->name); - free(co->value); - free(co); + curlx_free(co->domain); + curlx_free(co->path); + curlx_free(co->name); + curlx_free(co->value); + if(maintoo) + curlx_free(co); } static bool cookie_tailmatch(const char *cookie_domain, @@ -135,7 +81,7 @@ static bool cookie_tailmatch(const char *cookie_domain, return FALSE; if(!curl_strnequal(cookie_domain, - hostname + hostname_len-cookie_domain_len, + hostname + hostname_len - cookie_domain_len, cookie_domain_len)) return FALSE; @@ -278,22 +224,21 @@ static size_t cookiehash(const char * const domain) /* * cookie path sanitize */ -static char *sanitize_cookie_path(const char *cookie_path) +static char *sanitize_cookie_path(const char *cookie_path, size_t len) { - size_t len = strlen(cookie_path); - /* some sites send path attribute within '"'. */ - if(cookie_path[0] == '\"') { + if(len && (cookie_path[0] == '\"')) { cookie_path++; len--; + + if(len && (cookie_path[len - 1] == '\"')) + len--; } - if(len && (cookie_path[len - 1] == '\"')) - len--; /* RFC6265 5.2.4 The Path Attribute */ - if(cookie_path[0] != '/') + if(!len || (cookie_path[0] != '/')) /* Let cookie-path be the default-path. */ - return strdup("/"); + return curlx_strdup("/"); /* remove trailing slash when path is non-empty */ /* convert /hoge/ to /hoge */ @@ -303,34 +248,6 @@ static char *sanitize_cookie_path(const char *cookie_path) return Curl_memdup0(cookie_path, len); } -/* - * Load cookies from all given cookie files (CURLOPT_COOKIEFILE). - * - * NOTE: OOM or cookie parsing failures are ignored. - */ -void Curl_cookie_loadfiles(struct Curl_easy *data) -{ - struct curl_slist *list = data->state.cookielist; - if(list) { - Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE); - while(list) { - struct CookieInfo *ci = - Curl_cookie_init(data, list->data, data->cookies, - data->set.cookiesession); - if(!ci) - /* - * Failure may be due to OOM or a bad cookie; both are ignored - * but only the first should be - */ - infof(data, "ignoring failed cookie_init for %s", list->data); - else - data->cookies = ci; - list = list->next; - } - Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE); - } -} - /* * strstore * @@ -340,15 +257,17 @@ void Curl_cookie_loadfiles(struct Curl_easy *data) * parsing in a last-wins scenario. The caller is responsible for checking * for OOM errors. */ -static void strstore(char **str, const char *newstr, size_t len) +static CURLcode strstore(char **str, const char *newstr, size_t len) { DEBUGASSERT(str); - free(*str); if(!len) { len++; newstr = ""; } *str = Curl_memdup0(newstr, len); + if(!*str) + return CURLE_OUT_OF_MEMORY; + return CURLE_OK; } /* @@ -390,7 +309,7 @@ static void remove_expired(struct CookieInfo *ci) if(co->expires) { if(co->expires < now) { Curl_node_remove(n); - freecookie(co); + freecookie(co, TRUE); ci->numcookies--; } else if(co->expires < ci->next_expiration) @@ -433,37 +352,19 @@ static bool bad_domain(const char *domain, size_t len) fine. The prime reason for filtering out control bytes is that some HTTP servers return 400 for requests that contain such. */ -static bool invalid_octets(const char *ptr) +static bool invalid_octets(const char *ptr, size_t len) { const unsigned char *p = (const unsigned char *)ptr; /* Reject all bytes \x01 - \x1f (*except* \x09, TAB) + \x7f */ - while(*p) { + while(len && *p) { if(((*p != 9) && (*p < 0x20)) || (*p == 0x7f)) return TRUE; p++; + len--; } return FALSE; } -#define CERR_OK 0 -#define CERR_TOO_LONG 1 /* input line too long */ -#define CERR_TAB 2 /* in a wrong place */ -#define CERR_TOO_BIG 3 /* name/value too large */ -#define CERR_BAD 4 /* deemed incorrect */ -#define CERR_NO_SEP 5 /* semicolon problem */ -#define CERR_NO_NAME_VALUE 6 /* name or value problem */ -#define CERR_INVALID_OCTET 7 /* bad content */ -#define CERR_BAD_SECURE 8 /* secure in a bad place */ -#define CERR_OUT_OF_MEMORY 9 -#define CERR_NO_TAILMATCH 10 -#define CERR_COMMENT 11 /* a commented line */ -#define CERR_RANGE 12 /* expire range problem */ -#define CERR_FIELDS 13 /* incomplete netscape line */ -#ifdef USE_LIBPSL -#define CERR_PSL 14 /* a public suffix */ -#endif -#define CERR_LIVE_WINS 15 - /* The maximum length we accept a date string for the 'expire' keyword. The standard date formats are within the 30 bytes range. This adds an extra margin just to make sure it realistically works with what is used out @@ -471,10 +372,64 @@ static bool invalid_octets(const char *ptr) */ #define MAX_DATE_LENGTH 80 -static int +#define COOKIE_NAME 0 +#define COOKIE_VALUE 1 +#define COOKIE_DOMAIN 2 +#define COOKIE_PATH 3 + +#define COOKIE_PIECES 4 /* the list above */ + +static CURLcode storecookie(struct Cookie *co, struct Curl_str *cp, + const char *path, const char *domain) +{ + CURLcode result; + result = strstore(&co->name, curlx_str(&cp[COOKIE_NAME]), + curlx_strlen(&cp[COOKIE_NAME])); + if(!result) + result = strstore(&co->value, curlx_str(&cp[COOKIE_VALUE]), + curlx_strlen(&cp[COOKIE_VALUE])); + if(!result) { + size_t plen = 0; + if(curlx_strlen(&cp[COOKIE_PATH])) { + path = curlx_str(&cp[COOKIE_PATH]); + plen = curlx_strlen(&cp[COOKIE_PATH]); + } + else if(path) { + /* No path was given in the header line, set the default */ + const char *endslash = strrchr(path, '/'); + if(endslash) + plen = (endslash - path + 1); /* include end slash */ + else + plen = strlen(path); + } + + if(path) { + co->path = sanitize_cookie_path(path, plen); + if(!co->path) + result = CURLE_OUT_OF_MEMORY; + } + } + if(!result) { + if(curlx_strlen(&cp[COOKIE_DOMAIN])) + result = strstore(&co->domain, curlx_str(&cp[COOKIE_DOMAIN]), + curlx_strlen(&cp[COOKIE_DOMAIN])); + else if(domain) { + /* no domain was given in the header line, set the default */ + co->domain = curlx_strdup(domain); + if(!co->domain) + result = CURLE_OUT_OF_MEMORY; + } + } + return result; +} + +/* this function return errors on OOM etc, not on plain cookie format + problems */ +static CURLcode parse_cookie_header(struct Curl_easy *data, struct Cookie *co, struct CookieInfo *ci, + bool *okay, /* if the cookie was fine */ const char *ptr, const char *domain, /* default domain */ const char *path, /* full path used when this cookie is @@ -484,121 +439,97 @@ parse_cookie_header(struct Curl_easy *data, origin */ { /* This line was read off an HTTP-header */ - time_t now; + time_t now = 0; size_t linelength = strlen(ptr); + CURLcode result = CURLE_OK; + struct Curl_str cookie[COOKIE_PIECES]; + *okay = FALSE; if(linelength > MAX_COOKIE_LINE) /* discard overly long lines at once */ - return CERR_TOO_LONG; + return CURLE_OK; - now = time(NULL); + /* memset instead of initializer because gcc 4.8.1 is silly */ + memset(cookie, 0, sizeof(cookie)); do { struct Curl_str name; struct Curl_str val; /* we have a = pair or a stand-alone word here */ if(!curlx_str_cspn(&ptr, &name, ";\t\r\n=")) { - bool done = FALSE; bool sep = FALSE; curlx_str_trimblanks(&name); if(!curlx_str_single(&ptr, '=')) { sep = TRUE; /* a '=' was used */ - if(!curlx_str_cspn(&ptr, &val, ";\r\n")) { + if(!curlx_str_cspn(&ptr, &val, ";\r\n")) curlx_str_trimblanks(&val); - - /* Reject cookies with a TAB inside the value */ - if(memchr(curlx_str(&val), '\t', curlx_strlen(&val))) { - infof(data, "cookie contains TAB, dropping"); - return CERR_TAB; - } - } } - else { + else curlx_str_init(&val); - } - - /* - * Check for too long individual name or contents, or too long - * combination of name + contents. Chrome and Firefox support 4095 or - * 4096 bytes combo - */ - if(curlx_strlen(&name) >= (MAX_NAME-1) || - curlx_strlen(&val) >= (MAX_NAME-1) || - ((curlx_strlen(&name) + curlx_strlen(&val)) > MAX_NAME)) { - infof(data, "oversized cookie dropped, name/val %zu + %zu bytes", - curlx_strlen(&name), curlx_strlen(&val)); - return CERR_TOO_BIG; - } - /* - * Check if we have a reserved prefix set before anything else, as we - * otherwise have to test for the prefix in both the cookie name and - * "the rest". Prefixes must start with '__' and end with a '-', so - * only test for names where that can possibly be true. - */ - if(!strncmp("__Secure-", curlx_str(&name), 9)) - co->prefix_secure = TRUE; - else if(!strncmp("__Host-", curlx_str(&name), 7)) - co->prefix_host = TRUE; + if(!curlx_strlen(&cookie[COOKIE_NAME])) { + /* The first name/value pair is the actual cookie name */ + if(!sep || + /* Bad name/value pair. */ + invalid_octets(curlx_str(&name), curlx_strlen(&name)) || + invalid_octets(curlx_str(&val), curlx_strlen(&val)) || + !curlx_strlen(&name)) { + infof(data, "invalid octets in name/value, cookie dropped"); + return CURLE_OK; + } - /* - * Use strstore() below to properly deal with received cookie - * headers that have the same string property set more than once, - * and then we use the last one. - */ + /* + * Check for too long individual name or contents, or too long + * combination of name + contents. Chrome and Firefox support 4095 or + * 4096 bytes combo + */ + if(curlx_strlen(&name) >= (MAX_NAME - 1) || + curlx_strlen(&val) >= (MAX_NAME - 1) || + ((curlx_strlen(&name) + curlx_strlen(&val)) > MAX_NAME)) { + infof(data, "oversized cookie dropped, name/val %zu + %zu bytes", + curlx_strlen(&name), curlx_strlen(&val)); + return CURLE_OK; + } - if(!co->name) { - /* The very first name/value pair is the actual cookie name */ - if(!sep) - /* Bad name/value pair. */ - return CERR_NO_SEP; + /* Reject cookies with a TAB inside the value */ + if(curlx_strlen(&val) && + memchr(curlx_str(&val), '\t', curlx_strlen(&val))) { + infof(data, "cookie contains TAB, dropping"); + return CURLE_OK; + } - strstore(&co->name, curlx_str(&name), curlx_strlen(&name)); - strstore(&co->value, curlx_str(&val), curlx_strlen(&val)); - done = TRUE; - if(!co->name || !co->value) - return CERR_NO_NAME_VALUE; + /* Check if we have a reserved prefix set. */ + if(!strncmp("__Secure-", curlx_str(&name), 9)) + co->prefix_secure = TRUE; + else if(!strncmp("__Host-", curlx_str(&name), 7)) + co->prefix_host = TRUE; - if(invalid_octets(co->value) || invalid_octets(co->name)) { - infof(data, "invalid octets in name/value, cookie dropped"); - return CERR_INVALID_OCTET; - } + cookie[COOKIE_NAME] = name; + cookie[COOKIE_VALUE] = val; } - else if(!curlx_strlen(&val)) { + else if(!sep) { /* - * this was a "=" with no content, and we must allow - * 'secure' and 'httponly' specified this weirdly + * this is a "" with no content */ - done = TRUE; + /* * secure cookies are only allowed to be set when the connection is * using a secure protocol, or when the cookie is being set by * reading from file */ if(curlx_str_casecompare(&name, "secure")) { - if(secure || !ci->running) { + if(secure || !ci->running) co->secure = TRUE; - } else { - return CERR_BAD_SECURE; + infof(data, "skipped cookie because not 'secure'"); + return CURLE_OK; } } else if(curlx_str_casecompare(&name, "httponly")) co->httponly = TRUE; - else if(sep) - /* there was a '=' so we are not done parsing this field */ - done = FALSE; } - if(done) - ; else if(curlx_str_casecompare(&name, "path")) { - strstore(&co->path, curlx_str(&val), curlx_strlen(&val)); - if(!co->path) - return CERR_OUT_OF_MEMORY; - free(co->spath); /* if this is set again */ - co->spath = sanitize_cookie_path(co->path); - if(!co->spath) - return CERR_OUT_OF_MEMORY; + cookie[COOKIE_PATH] = val; } else if(curlx_str_casecompare(&name, "domain") && curlx_strlen(&val)) { bool is_ip; @@ -623,16 +554,13 @@ parse_cookie_header(struct Curl_easy *data, is_ip = Curl_host_is_ipnum(domain ? domain : curlx_str(&val)); - if(!domain - || (is_ip && !strncmp(curlx_str(&val), domain, - curlx_strlen(&val)) && - (curlx_strlen(&val) == strlen(domain))) - || (!is_ip && cookie_tailmatch(curlx_str(&val), + if(!domain || + (is_ip && + !strncmp(curlx_str(&val), domain, curlx_strlen(&val)) && + (curlx_strlen(&val) == strlen(domain))) || + (!is_ip && cookie_tailmatch(curlx_str(&val), curlx_strlen(&val), domain))) { - strstore(&co->domain, curlx_str(&val), curlx_strlen(&val)); - if(!co->domain) - return CERR_OUT_OF_MEMORY; - + cookie[COOKIE_DOMAIN] = val; if(!is_ip) co->tailmatch = TRUE; /* we always do that if the domain name was given */ @@ -644,12 +572,9 @@ parse_cookie_header(struct Curl_easy *data, */ infof(data, "skipped cookie with bad tailmatch domain: %s", curlx_str(&val)); - return CERR_NO_TAILMATCH; + return CURLE_OK; } } - else if(curlx_str_casecompare(&name, "version")) { - /* just ignore */ - } else if(curlx_str_casecompare(&name, "max-age") && curlx_strlen(&val)) { /* * Defined in RFC2109: @@ -665,6 +590,8 @@ parse_cookie_header(struct Curl_easy *data, if(*maxage == '\"') maxage++; rc = curlx_str_number(&maxage, &co->expires, CURL_OFF_T_MAX); + if(!now) + now = time(NULL); switch(rc) { case STRE_OVERFLOW: /* overflow, used max value */ @@ -686,79 +613,47 @@ parse_cookie_header(struct Curl_easy *data, } cap_expires(now, co); } - else if(curlx_str_casecompare(&name, "expires") && curlx_strlen(&val)) { - if(!co->expires && (curlx_strlen(&val) < MAX_DATE_LENGTH)) { - /* - * Let max-age have priority. - * - * If the date cannot get parsed for whatever reason, the cookie - * will be treated as a session cookie - */ - char dbuf[MAX_DATE_LENGTH + 1]; - time_t date = 0; - memcpy(dbuf, curlx_str(&val), curlx_strlen(&val)); - dbuf[curlx_strlen(&val)] = 0; - if(!Curl_getdate_capped(dbuf, &date)) { - if(!date) - date++; - co->expires = (curl_off_t)date; - } - else - co->expires = 0; - cap_expires(now, co); + else if(curlx_str_casecompare(&name, "expires") && curlx_strlen(&val) && + !co->expires && (curlx_strlen(&val) < MAX_DATE_LENGTH)) { + /* + * Let max-age have priority. + * + * If the date cannot get parsed for whatever reason, the cookie + * will be treated as a session cookie + */ + char dbuf[MAX_DATE_LENGTH + 1]; + time_t date = 0; + memcpy(dbuf, curlx_str(&val), curlx_strlen(&val)); + dbuf[curlx_strlen(&val)] = 0; + if(!Curl_getdate_capped(dbuf, &date)) { + if(!date) + date++; + co->expires = (curl_off_t)date; } + else + co->expires = 0; + if(!now) + now = time(NULL); + cap_expires(now, co); } - - /* - * Else, this is the second (or more) name we do not know about! - */ } + } while(!curlx_str_single(&ptr, ';')); - if(curlx_str_single(&ptr, ';')) - break; - } while(1); - - if(!co->domain && domain) { - /* no domain was given in the header line, set the default */ - co->domain = strdup(domain); - if(!co->domain) - return CERR_OUT_OF_MEMORY; - } - - if(!co->path && path) { - /* - * No path was given in the header line, set the default. - */ - const char *endslash = strrchr(path, '/'); - if(endslash) { - size_t pathlen = (endslash - path + 1); /* include end slash */ - co->path = Curl_memdup0(path, pathlen); - if(co->path) { - co->spath = sanitize_cookie_path(co->path); - if(!co->spath) - return CERR_OUT_OF_MEMORY; - } - else - return CERR_OUT_OF_MEMORY; - } + if(curlx_strlen(&cookie[COOKIE_NAME])) { + /* the header was fine, now store the data */ + result = storecookie(co, &cookie[0], path, domain); + if(!result) + *okay = TRUE; } - - /* - * If we did not get a cookie name, or a bad one, the this is an illegal - * line so bail out. - */ - if(!co->name) - return CERR_BAD; - - return CERR_OK; + return result; } -static int -parse_netscape(struct Cookie *co, - struct CookieInfo *ci, - const char *lineptr, - bool secure) /* TRUE if connection is over secure - origin */ +static CURLcode parse_netscape(struct Cookie *co, + struct CookieInfo *ci, + bool *okay, + const char *lineptr, + bool secure) /* TRUE if connection is over + secure origin */ { /* * This line is NOT an HTTP header style line, we do offer support for @@ -767,6 +662,7 @@ parse_netscape(struct Cookie *co, const char *ptr, *next; int fields; size_t len; + *okay = FALSE; /* * In 2008, Internet Explorer introduced HTTP-only cookies to prevent XSS @@ -779,9 +675,9 @@ parse_netscape(struct Cookie *co, co->httponly = TRUE; } - if(lineptr[0]=='#') + if(lineptr[0] == '#') /* do not even try the comments */ - return CERR_COMMENT; + return CURLE_OK; /* * Now loop through the fields and init the struct we already have @@ -794,13 +690,13 @@ parse_netscape(struct Cookie *co, next = (ptr[len] == '\t' ? &ptr[len + 1] : NULL); switch(fields) { case 0: - if(ptr[0]=='.') { /* skip preceding dots */ + if(ptr[0] == '.') { /* skip preceding dots */ ptr++; len--; } co->domain = Curl_memdup0(ptr, len); if(!co->domain) - return CERR_OUT_OF_MEMORY; + return CURLE_OUT_OF_MEMORY; break; case 1: /* @@ -814,23 +710,17 @@ parse_netscape(struct Cookie *co, /* The file format allows the path field to remain not filled in */ if(strncmp("TRUE", ptr, len) && strncmp("FALSE", ptr, len)) { /* only if the path does not look like a boolean option! */ - co->path = Curl_memdup0(ptr, len); + co->path = sanitize_cookie_path(ptr, len); if(!co->path) - return CERR_OUT_OF_MEMORY; - else { - co->spath = sanitize_cookie_path(co->path); - if(!co->spath) - return CERR_OUT_OF_MEMORY; - } + return CURLE_OUT_OF_MEMORY; break; } - /* this does not look like a path, make one up! */ - co->path = strdup("/"); - if(!co->path) - return CERR_OUT_OF_MEMORY; - co->spath = strdup("/"); - if(!co->spath) - return CERR_OUT_OF_MEMORY; + else { + /* this does not look like a path, make one up! */ + co->path = curlx_strdup("/"); + if(!co->path) + return CURLE_OUT_OF_MEMORY; + } fields++; /* add a field and fall down to secure */ FALLTHROUGH(); case 3: @@ -839,17 +729,17 @@ parse_netscape(struct Cookie *co, if(secure || ci->running) co->secure = TRUE; else - return CERR_BAD_SECURE; + return CURLE_OK; } break; case 4: if(curlx_str_number(&ptr, &co->expires, CURL_OFF_T_MAX)) - return CERR_RANGE; + return CURLE_OK; break; case 5: co->name = Curl_memdup0(ptr, len); if(!co->name) - return CERR_OUT_OF_MEMORY; + return CURLE_OUT_OF_MEMORY; else { /* For Netscape file format cookies we check prefix on the name */ if(curl_strnequal("__Secure-", co->name, 9)) @@ -861,30 +751,30 @@ parse_netscape(struct Cookie *co, case 6: co->value = Curl_memdup0(ptr, len); if(!co->value) - return CERR_OUT_OF_MEMORY; + return CURLE_OUT_OF_MEMORY; break; } } if(fields == 6) { /* we got a cookie with blank contents, fix it */ - co->value = strdup(""); + co->value = curlx_strdup(""); if(!co->value) - return CERR_OUT_OF_MEMORY; + return CURLE_OUT_OF_MEMORY; else fields++; } if(fields != 7) /* we did not find the sufficient number of fields */ - return CERR_FIELDS; + return CURLE_OK; - return CERR_OK; + *okay = TRUE; + return CURLE_OK; } -static int -is_public_suffix(struct Curl_easy *data, - struct Cookie *co, - const char *domain) +static bool is_public_suffix(struct Curl_easy *data, + struct Cookie *co, + const char *domain) { #ifdef USE_LIBPSL /* @@ -916,7 +806,7 @@ is_public_suffix(struct Curl_easy *data, if(!acceptable) { infof(data, "cookie '%s' dropped, domain '%s' must not " "set cookies for '%s'", co->name, domain, co->domain); - return CERR_PSL; + return TRUE; } } #else @@ -926,15 +816,15 @@ is_public_suffix(struct Curl_easy *data, DEBUGF(infof(data, "NO PSL to check set-cookie '%s' for domain=%s in %s", co->name, co->domain, domain)); #endif - return CERR_OK; + return FALSE; } -static int -replace_existing(struct Curl_easy *data, - struct Cookie *co, - struct CookieInfo *ci, - bool secure, - bool *replacep) +/* returns TRUE when replaced */ +static bool replace_existing(struct Curl_easy *data, + struct Cookie *co, + struct CookieInfo *ci, + bool secure, + bool *replacep) { bool replace_old = FALSE; struct Curl_llist_node *replace_n = NULL; @@ -955,7 +845,7 @@ replace_existing(struct Curl_easy *data, matching_domains = TRUE; if(matching_domains && /* the domains were identical */ - clist->spath && co->spath && /* both have paths */ + clist->path && co->path && /* both have paths */ clist->secure && !co->secure && !secure) { size_t cllen; const char *sep = NULL; @@ -967,18 +857,18 @@ replace_existing(struct Curl_easy *data, * "/loginhelper" is ok. */ - DEBUGASSERT(clist->spath[0]); - if(clist->spath[0]) - sep = strchr(clist->spath + 1, '/'); + DEBUGASSERT(clist->path[0]); + if(clist->path[0]) + sep = strchr(clist->path + 1, '/'); if(sep) - cllen = sep - clist->spath; + cllen = sep - clist->path; else - cllen = strlen(clist->spath); + cllen = strlen(clist->path); - if(curl_strnequal(clist->spath, co->spath, cllen)) { + if(curl_strnequal(clist->path, co->path, cllen)) { infof(data, "cookie '%s' for domain '%s' dropped, would " "overlay an existing cookie", co->name, co->domain); - return CERR_BAD_SECURE; + return FALSE; } } } @@ -988,7 +878,7 @@ replace_existing(struct Curl_easy *data, if(clist->domain && co->domain) { if(curl_strequal(clist->domain, co->domain) && - (clist->tailmatch == co->tailmatch)) + (clist->tailmatch == co->tailmatch)) /* The domains are identical */ replace_old = TRUE; } @@ -998,10 +888,10 @@ replace_existing(struct Curl_easy *data, if(replace_old) { /* the domains were identical */ - if(clist->spath && co->spath && - !curl_strequal(clist->spath, co->spath)) + if(clist->path && co->path && + !curl_strequal(clist->path, co->path)) replace_old = FALSE; - else if(!clist->spath != !co->spath) + else if(!clist->path != !co->path) replace_old = FALSE; } @@ -1012,7 +902,7 @@ replace_existing(struct Curl_easy *data, * was read from a file and thus is not "live". "live" cookies are * preferred so the new cookie is freed. */ - return CERR_LIVE_WINS; + return FALSE; } if(replace_old) replace_n = n; @@ -1028,10 +918,10 @@ replace_existing(struct Curl_easy *data, Curl_node_remove(replace_n); /* free the old cookie */ - freecookie(repl); + freecookie(repl, TRUE); } *replacep = replace_old; - return CERR_OK; + return TRUE; } /* @@ -1041,10 +931,8 @@ replace_existing(struct Curl_easy *data, * sometimes we get an IP-only hostname, and that might also be a numerical * IPv6 address. * - * Returns NULL on out of memory or invalid cookie. This is suboptimal, - * as they should be treated separately. */ -struct Cookie * +CURLcode Curl_cookie_add(struct Curl_easy *data, struct CookieInfo *ci, bool httpheader, /* TRUE if HTTP header-style line */ @@ -1056,27 +944,28 @@ Curl_cookie_add(struct Curl_easy *data, unless set */ bool secure) /* TRUE if connection is over secure origin */ { + struct Cookie comem; struct Cookie *co; size_t myhash; - int rc; + CURLcode result; bool replaces = FALSE; + bool okay; DEBUGASSERT(data); DEBUGASSERT(MAX_SET_COOKIE_AMOUNT <= 255); /* counter is an unsigned char */ if(data->req.setcookies >= MAX_SET_COOKIE_AMOUNT) - return NULL; + return CURLE_OK; /* silently ignore */ - /* First, alloc and init a new struct for it */ - co = calloc(1, sizeof(struct Cookie)); - if(!co) - return NULL; /* bail out if we are this low on memory */ + co = &comem; + memset(co, 0, sizeof(comem)); if(httpheader) - rc = parse_cookie_header(data, co, ci, lineptr, domain, path, secure); + result = parse_cookie_header(data, co, ci, &okay, + lineptr, domain, path, secure); else - rc = parse_netscape(co, ci, lineptr, secure); + result = parse_netscape(co, ci, &okay, lineptr, secure); - if(rc) + if(result || !okay) goto fail; if(co->prefix_secure && !co->secure) @@ -1088,7 +977,7 @@ Curl_cookie_add(struct Curl_easy *data, * The __Host- prefix requires the cookie to be secure, have a "/" path * and not have a domain set. */ - if(co->secure && co->path && strcmp(co->path, "/") == 0 && !co->tailmatch) + if(co->secure && co->path && !strcmp(co->path, "/") && !co->tailmatch) ; else goto fail; @@ -1115,9 +1004,17 @@ Curl_cookie_add(struct Curl_easy *data, if(is_public_suffix(data, co, domain)) goto fail; - if(replace_existing(data, co, ci, secure, &replaces)) + if(!replace_existing(data, co, ci, secure, &replaces)) goto fail; + /* clone the stack struct into heap */ + co = Curl_memdup(&comem, sizeof(comem)); + if(!co) { + co = &comem; + result = CURLE_OUT_OF_MEMORY; + goto fail; /* bail out if we are this low on memory */ + } + /* add this cookie to the list */ myhash = cookiehash(co->domain); Curl_llist_append(&ci->cookielist[myhash], co, &co->node); @@ -1126,7 +1023,7 @@ Curl_cookie_add(struct Curl_easy *data, /* Only show this when NOT reading the cookies from a file */ infof(data, "%s cookie %s=\"%s\" for domain %s, path %s, " "expire %" FMT_OFF_T, - replaces ? "Replaced":"Added", co->name, co->value, + replaces ? "Replaced" : "Added", co->name, co->value, co->domain, co->path, co->expires); if(!replaces) @@ -1142,13 +1039,12 @@ Curl_cookie_add(struct Curl_easy *data, if(httpheader) data->req.setcookies++; - return co; + return result; fail: - freecookie(co); - return NULL; + freecookie(co, FALSE); + return result; } - /* * Curl_cookie_init() * @@ -1161,89 +1057,127 @@ Curl_cookie_add(struct Curl_easy *data, * Note that 'data' might be called as NULL pointer. If data is NULL, 'file' * will be ignored. * - * Returns NULL on out of memory. Invalid cookies are ignored. + * Returns NULL on out of memory. */ -struct CookieInfo *Curl_cookie_init(struct Curl_easy *data, - const char *file, - struct CookieInfo *ci, - bool newsession) +struct CookieInfo *Curl_cookie_init(void) { - FILE *handle = NULL; + int i; + struct CookieInfo *ci = curlx_calloc(1, sizeof(struct CookieInfo)); + if(!ci) + return NULL; - if(!ci) { - int i; + /* This does not use the destructor callback since we want to add + and remove to lists while keeping the cookie struct intact */ + for(i = 0; i < COOKIE_HASH_SIZE; i++) + Curl_llist_init(&ci->cookielist[i], NULL); + /* + * Initialize the next_expiration time to signal that we do not have enough + * information yet. + */ + ci->next_expiration = CURL_OFF_T_MAX; - /* we did not get a struct, create one */ - ci = calloc(1, sizeof(struct CookieInfo)); - if(!ci) - return NULL; /* failed to get memory */ + return ci; +} - /* This does not use the destructor callback since we want to add - and remove to lists while keeping the cookie struct intact */ - for(i = 0; i < COOKIE_HASH_SIZE; i++) - Curl_llist_init(&ci->cookielist[i], NULL); - /* - * Initialize the next_expiration time to signal that we do not have enough - * information yet. - */ - ci->next_expiration = CURL_OFF_T_MAX; - } - ci->newsession = newsession; /* new session? */ +/* + * cookie_load() + * + * Reads cookies from a local file. This is always called before any cookies + * are set. If file is "-" then STDIN is read. + * + * If 'newsession' is TRUE, discard all "session cookies" on read from file. + * + */ +static CURLcode cookie_load(struct Curl_easy *data, const char *file, + struct CookieInfo *ci, bool newsession) +{ + FILE *handle = NULL; + CURLcode result = CURLE_OK; + FILE *fp = NULL; + DEBUGASSERT(ci); + DEBUGASSERT(data); + DEBUGASSERT(file); - if(data) { - FILE *fp = NULL; - if(file && *file) { - if(!strcmp(file, "-")) - fp = stdin; - else { - fp = curlx_fopen(file, "rb"); - if(!fp) - infof(data, "WARNING: failed to open cookie file \"%s\"", file); - else - handle = fp; - } + ci->newsession = newsession; /* new session? */ + ci->running = FALSE; /* this is not running, this is init */ + + if(file && *file) { + if(!strcmp(file, "-")) + fp = stdin; + else { + fp = curlx_fopen(file, "rb"); + if(!fp) + infof(data, "WARNING: failed to open cookie file \"%s\"", file); + else + handle = fp; } + } - ci->running = FALSE; /* this is not running, this is init */ - if(fp) { - struct dynbuf buf; - bool eof = FALSE; - CURLcode result; - curlx_dyn_init(&buf, MAX_COOKIE_LINE); - do { - result = Curl_get_line(&buf, fp, &eof); - if(!result) { - const char *lineptr = curlx_dyn_ptr(&buf); - bool headerline = FALSE; - if(checkprefix("Set-Cookie:", lineptr)) { - /* This is a cookie line, get it! */ - lineptr += 11; - headerline = TRUE; - curlx_str_passblanks(&lineptr); - } - - (void)Curl_cookie_add(data, ci, headerline, TRUE, lineptr, NULL, - NULL, TRUE); - /* File reading cookie failures are not propagated back to the - caller because there is no way to do that */ + if(fp) { + struct dynbuf buf; + bool eof = FALSE; + curlx_dyn_init(&buf, MAX_COOKIE_LINE); + do { + result = Curl_get_line(&buf, fp, &eof); + if(!result) { + const char *lineptr = curlx_dyn_ptr(&buf); + bool headerline = FALSE; + if(checkprefix("Set-Cookie:", lineptr)) { + /* This is a cookie line, get it! */ + lineptr += 11; + headerline = TRUE; + curlx_str_passblanks(&lineptr); } - } while(!result && !eof); - curlx_dyn_free(&buf); /* free the line buffer */ - /* - * Remove expired cookies from the hash. We must make sure to run this - * after reading the file, and not on every cookie. - */ - remove_expired(ci); + result = Curl_cookie_add(data, ci, headerline, TRUE, lineptr, NULL, + NULL, TRUE); + /* File reading cookie failures are not propagated back to the + caller because there is no way to do that */ + } + } while(!result && !eof); + curlx_dyn_free(&buf); /* free the line buffer */ - if(handle) - curlx_fclose(handle); - } - data->state.cookie_engine = TRUE; + /* + * Remove expired cookies from the hash. We must make sure to run this + * after reading the file, and not on every cookie. + */ + remove_expired(ci); + + if(handle) + curlx_fclose(handle); } + data->state.cookie_engine = TRUE; ci->running = TRUE; /* now, we are running */ - return ci; + return result; +} + +/* + * Load cookies from all given cookie files (CURLOPT_COOKIEFILE). + */ +CURLcode Curl_cookie_loadfiles(struct Curl_easy *data) +{ + CURLcode result = CURLE_OK; + struct curl_slist *list = data->state.cookielist; + if(list) { + Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE); + if(!data->cookies) + data->cookies = Curl_cookie_init(); + if(!data->cookies) + result = CURLE_OUT_OF_MEMORY; + else { + data->state.cookie_engine = TRUE; + while(list) { + result = cookie_load(data, list->data, data->cookies, + data->set.cookiesession); + if(result) + break; + list = list->next; + } + } + Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE); + } + return result; } /* @@ -1300,7 +1234,7 @@ static int cookie_sort_ct(const void *p1, const void *p2) bool Curl_secure_context(struct connectdata *conn, const char *host) { - return conn->handler->protocol&(CURLPROTO_HTTPS|CURLPROTO_WSS) || + return conn->handler->protocol & (CURLPROTO_HTTPS | CURLPROTO_WSS) || curl_strequal("localhost", host) || !strcmp(host, "127.0.0.1") || !strcmp(host, "::1"); @@ -1315,12 +1249,13 @@ bool Curl_secure_context(struct connectdata *conn, const char *host) * * It shall only return cookies that have not expired. * - * Returns 0 when there is a list returned. Otherwise non-zero. + * 'okay' is TRUE when there is a list returned. */ -int Curl_cookie_getlist(struct Curl_easy *data, - struct connectdata *conn, - const char *host, - struct Curl_llist *list) +CURLcode Curl_cookie_getlist(struct Curl_easy *data, + struct connectdata *conn, + bool *okay, + const char *host, + struct Curl_llist *list) { size_t matches = 0; const bool is_ip = Curl_host_is_ipnum(host); @@ -1329,17 +1264,18 @@ int Curl_cookie_getlist(struct Curl_easy *data, const bool secure = Curl_secure_context(conn, host); struct CookieInfo *ci = data->cookies; const char *path = data->state.up.path; + CURLcode result = CURLE_OK; + *okay = FALSE; Curl_llist_init(list, NULL); if(!ci || !Curl_llist_count(&ci->cookielist[myhash])) - return 1; /* no cookie struct or no cookies in the struct */ + return CURLE_OK; /* no cookie struct or no cookies in the struct */ /* at first, remove expired cookies */ remove_expired(ci); - for(n = Curl_llist_head(&ci->cookielist[myhash]); - n; n = Curl_node_next(n)) { + for(n = Curl_llist_head(&ci->cookielist[myhash]); n; n = Curl_node_next(n)) { struct Cookie *co = Curl_node_elem(n); /* if the cookie requires we are secure we must only continue if we are! */ @@ -1349,7 +1285,7 @@ int Curl_cookie_getlist(struct Curl_easy *data, if(!co->domain || (co->tailmatch && !is_ip && cookie_tailmatch(co->domain, strlen(co->domain), host)) || - ((!co->tailmatch || is_ip) && curl_strequal(host, co->domain)) ) { + ((!co->tailmatch || is_ip) && curl_strequal(host, co->domain))) { /* * the right part of the host matches the domain stuff in the * cookie data @@ -1359,7 +1295,7 @@ int Curl_cookie_getlist(struct Curl_easy *data, * now check the left part of the path with the cookies path * requirement */ - if(!co->spath || pathmatch(co->spath, path) ) { + if(!co->path || pathmatch(co->path, path)) { /* * This is a match and we add it to the return-linked-list @@ -1386,9 +1322,11 @@ int Curl_cookie_getlist(struct Curl_easy *data, size_t i; /* alloc an array and store all cookie pointers */ - array = malloc(sizeof(struct Cookie *) * matches); - if(!array) + array = curlx_malloc(sizeof(struct Cookie *) * matches); + if(!array) { + result = CURLE_OUT_OF_MEMORY; goto fail; + } n = Curl_llist_head(list); @@ -1404,15 +1342,16 @@ int Curl_cookie_getlist(struct Curl_easy *data, for(i = 0; i < matches; i++) Curl_llist_append(list, array[i], &array[i]->getnode); - free(array); /* remove the temporary data again */ + curlx_free(array); /* remove the temporary data again */ } - return 0; /* success */ + *okay = TRUE; + return CURLE_OK; /* success */ fail: /* failure, clear up the allocated chain and return NULL */ Curl_llist_destroy(list, NULL); - return 2; /* error */ + return result; /* error */ } /* @@ -1430,7 +1369,7 @@ void Curl_cookie_clearall(struct CookieInfo *ci) struct Cookie *c = Curl_node_elem(n); struct Curl_llist_node *e = Curl_node_next(n); Curl_node_remove(n); - freecookie(c); + freecookie(c, TRUE); n = e; } } @@ -1459,7 +1398,7 @@ void Curl_cookie_clearsess(struct CookieInfo *ci) e = Curl_node_next(n); /* in case the node is removed, get it early */ if(!curr->expires) { Curl_node_remove(n); - freecookie(curr); + freecookie(curr, TRUE); ci->numcookies--; } } @@ -1475,7 +1414,7 @@ void Curl_cookie_cleanup(struct CookieInfo *ci) { if(ci) { Curl_cookie_clearall(ci); - free(ci); /* free the base struct as well */ + curlx_free(ci); /* free the base struct as well */ } } @@ -1489,14 +1428,14 @@ void Curl_cookie_cleanup(struct CookieInfo *ci) static char *get_netscape_format(const struct Cookie *co) { return curl_maprintf( - "%s" /* httponly preamble */ - "%s%s\t" /* domain */ - "%s\t" /* tailmatch */ - "%s\t" /* path */ - "%s\t" /* secure */ - "%" FMT_OFF_T "\t" /* expires */ - "%s\t" /* name */ - "%s", /* value */ + "%s" /* httponly preamble */ + "%s%s\t" /* domain */ + "%s\t" /* tailmatch */ + "%s\t" /* path */ + "%s\t" /* secure */ + "%" FMT_OFF_T "\t" /* expires */ + "%s\t" /* name */ + "%s", /* value */ co->httponly ? "#HttpOnly_" : "", /* * Make sure all domains are prefixed with a dot if they allow @@ -1558,7 +1497,7 @@ static CURLcode cookie_output(struct Curl_easy *data, struct Cookie **array; struct Curl_llist_node *n; - array = calloc(1, sizeof(struct Cookie *) * ci->numcookies); + array = curlx_calloc(1, sizeof(struct Cookie *) * ci->numcookies); if(!array) { error = CURLE_OUT_OF_MEMORY; goto error; @@ -1566,8 +1505,7 @@ static CURLcode cookie_output(struct Curl_easy *data, /* only sort the cookies with a domain property */ for(i = 0; i < COOKIE_HASH_SIZE; i++) { - for(n = Curl_llist_head(&ci->cookielist[i]); n; - n = Curl_node_next(n)) { + for(n = Curl_llist_head(&ci->cookielist[i]); n; n = Curl_node_next(n)) { struct Cookie *co = Curl_node_elem(n); if(!co->domain) continue; @@ -1580,21 +1518,21 @@ static CURLcode cookie_output(struct Curl_easy *data, for(i = 0; i < nvalid; i++) { char *format_ptr = get_netscape_format(array[i]); if(!format_ptr) { - free(array); + curlx_free(array); error = CURLE_OUT_OF_MEMORY; goto error; } curl_mfprintf(out, "%s\n", format_ptr); - free(format_ptr); + curlx_free(format_ptr); } - free(array); + curlx_free(array); } if(!use_stdout) { curlx_fclose(out); out = NULL; - if(tempstore && Curl_rename(tempstore, filename)) { + if(tempstore && curlx_rename(tempstore, filename)) { error = CURLE_WRITE_ERROR; goto error; } @@ -1605,7 +1543,7 @@ static CURLcode cookie_output(struct Curl_easy *data, * no need to inspect the error, any error case should have jumped into the * error block below. */ - free(tempstore); + curlx_free(tempstore); return CURLE_OK; error: @@ -1613,7 +1551,7 @@ static CURLcode cookie_output(struct Curl_easy *data, curlx_fclose(out); if(tempstore) { unlink(tempstore); - free(tempstore); + curlx_free(tempstore); } return error; } @@ -1645,7 +1583,7 @@ static struct curl_slist *cookie_list(struct Curl_easy *data) } beg = Curl_slist_append_nodup(list, line); if(!beg) { - free(line); + curlx_free(line); curl_slist_free_all(list); return NULL; } @@ -1667,26 +1605,35 @@ struct curl_slist *Curl_cookie_list(struct Curl_easy *data) void Curl_flush_cookies(struct Curl_easy *data, bool cleanup) { - CURLcode res; - Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE); - /* only save the cookie file if a transfer was started (data->state.url is + /* only save the cookie file if a transfer was started (cookies->running is set), as otherwise the cookies were not completely initialized and there - might be cookie files that weren't loaded so saving the file is the wrong - thing. */ - if(data->set.str[STRING_COOKIEJAR] && data->state.url) { - /* if we have a destination file for all the cookies to get dumped to */ - res = cookie_output(data, data->cookies, data->set.str[STRING_COOKIEJAR]); - if(res) - infof(data, "WARNING: failed to save cookies in %s: %s", - data->set.str[STRING_COOKIEJAR], curl_easy_strerror(res)); - } + might be cookie files that were not loaded so saving the file is the + wrong thing. */ + if(data->cookies) { + if(data->set.str[STRING_COOKIEJAR] && data->cookies->running) { + /* if we have a destination file for all the cookies to get dumped to */ + CURLcode result = cookie_output(data, data->cookies, + data->set.str[STRING_COOKIEJAR]); + if(result) + infof(data, "WARNING: failed to save cookies in %s: %s", + data->set.str[STRING_COOKIEJAR], curl_easy_strerror(result)); + } - if(cleanup && (!data->share || (data->cookies != data->share->cookies))) { - Curl_cookie_cleanup(data->cookies); - data->cookies = NULL; + if(cleanup && (!data->share || (data->cookies != data->share->cookies))) { + Curl_cookie_cleanup(data->cookies); + data->cookies = NULL; + } } Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE); } +void Curl_cookie_run(struct Curl_easy *data) +{ + Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE); + if(data->cookies) + data->cookies->running = TRUE; + Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE); +} + #endif /* CURL_DISABLE_HTTP || CURL_DISABLE_COOKIES */ diff --git a/vendor/hydra/vendor/curl/lib/cookie.h b/vendor/hydra/vendor/curl/lib/cookie.h index 99aa20af..cbc7b748 100644 --- a/vendor/hydra/vendor/curl/lib/cookie.h +++ b/vendor/hydra/vendor/curl/lib/cookie.h @@ -25,34 +25,31 @@ ***************************************************************************/ #include "curl_setup.h" -#include - #include "llist.h" struct Cookie { - struct Curl_llist_node node; /* for the main cookie list */ + struct Curl_llist_node node; /* for the main cookie list */ struct Curl_llist_node getnode; /* for getlist */ - char *name; /* = value */ - char *value; /* name = */ - char *path; /* path = which is in Set-Cookie: */ - char *spath; /* sanitized cookie path */ - char *domain; /* domain = */ - curl_off_t expires; /* expires = */ - unsigned int creationtime; /* time when the cookie was written */ - BIT(tailmatch); /* tail-match the domain name */ - BIT(secure); /* the 'secure' keyword was used */ - BIT(livecookie); /* updated from a server, not a stored file */ - BIT(httponly); /* the httponly directive is present */ - BIT(prefix_secure); /* secure prefix is set */ - BIT(prefix_host); /* host prefix is set */ + char *name; /* = value */ + char *value; /* name = */ + char *path; /* canonical path */ + char *domain; /* domain = */ + curl_off_t expires; /* expires = */ + unsigned int creationtime; /* time when the cookie was written */ + BIT(tailmatch); /* tail-match the domain name */ + BIT(secure); /* the 'secure' keyword was used */ + BIT(livecookie); /* updated from server, not a stored file */ + BIT(httponly); /* the httponly directive is present */ + BIT(prefix_secure); /* secure prefix is set */ + BIT(prefix_host); /* host prefix is set */ }; /* * Available cookie prefixes, as defined in * draft-ietf-httpbis-rfc6265bis-02 */ -#define COOKIE_PREFIX__SECURE (1<<0) -#define COOKIE_PREFIX__HOST (1<<1) +#define COOKIE_PREFIX__SECURE (1 << 0) +#define COOKIE_PREFIX__HOST (1 << 1) #define COOKIE_HASH_SIZE 63 @@ -60,9 +57,9 @@ struct CookieInfo { /* linked lists of cookies we know of */ struct Curl_llist cookielist[COOKIE_HASH_SIZE]; curl_off_t next_expiration; /* the next time at which expiration happens */ - unsigned int numcookies; /* number of cookies in the "jar" */ - unsigned int lastct; /* last creation-time used in the jar */ - BIT(running); /* state info, for cookie adding information */ + unsigned int numcookies; /* number of cookies in the "jar" */ + unsigned int lastct; /* last creation-time used in the jar */ + BIT(running); /* state info, for cookie adding information */ BIT(newsession); /* new session, discard session cookies on load */ }; @@ -113,30 +110,31 @@ struct connectdata; */ bool Curl_secure_context(struct connectdata *conn, const char *host); -struct Cookie *Curl_cookie_add(struct Curl_easy *data, - struct CookieInfo *c, bool header, - bool noexpiry, const char *lineptr, - const char *domain, const char *path, - bool secure); -int Curl_cookie_getlist(struct Curl_easy *data, struct connectdata *conn, - const char *host, struct Curl_llist *list); +CURLcode Curl_cookie_add(struct Curl_easy *data, + struct CookieInfo *c, bool header, + bool noexpiry, const char *lineptr, + const char *domain, const char *path, + bool secure) WARN_UNUSED_RESULT; +CURLcode Curl_cookie_getlist(struct Curl_easy *data, struct connectdata *conn, + bool *okay, const char *host, + struct Curl_llist *list) WARN_UNUSED_RESULT; void Curl_cookie_clearall(struct CookieInfo *cookies); void Curl_cookie_clearsess(struct CookieInfo *cookies); #if defined(CURL_DISABLE_HTTP) || defined(CURL_DISABLE_COOKIES) #define Curl_cookie_list(x) NULL -#define Curl_cookie_loadfiles(x) Curl_nop_stmt -#define Curl_cookie_init(x,y,z,w) NULL +#define Curl_cookie_loadfiles(x) CURLE_OK +#define Curl_cookie_init() NULL +#define Curl_cookie_run(x) Curl_nop_stmt #define Curl_cookie_cleanup(x) Curl_nop_stmt -#define Curl_flush_cookies(x,y) Curl_nop_stmt +#define Curl_flush_cookies(x, y) Curl_nop_stmt #else void Curl_flush_cookies(struct Curl_easy *data, bool cleanup); void Curl_cookie_cleanup(struct CookieInfo *c); -struct CookieInfo *Curl_cookie_init(struct Curl_easy *data, - const char *file, struct CookieInfo *inc, - bool newsession); +struct CookieInfo *Curl_cookie_init(void); struct curl_slist *Curl_cookie_list(struct Curl_easy *data); -void Curl_cookie_loadfiles(struct Curl_easy *data); +CURLcode Curl_cookie_loadfiles(struct Curl_easy *data) WARN_UNUSED_RESULT; +void Curl_cookie_run(struct Curl_easy *data); #endif #endif /* HEADER_CURL_COOKIE_H */ diff --git a/vendor/hydra/vendor/curl/lib/cshutdn.c b/vendor/hydra/vendor/curl/lib/cshutdn.c index c2788e77..84e5b2a1 100644 --- a/vendor/hydra/vendor/curl/lib/cshutdn.c +++ b/vendor/hydra/vendor/curl/lib/cshutdn.c @@ -22,30 +22,21 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include - #include "urldata.h" #include "url.h" #include "cfilters.h" #include "progress.h" #include "multiif.h" #include "multi_ev.h" -#include "sendf.h" +#include "curl_trc.h" #include "cshutdn.h" -#include "http_negotiate.h" -#include "http_ntlm.h" #include "sigpipe.h" #include "connect.h" #include "select.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - static void cshutdn_run_conn_handler(struct Curl_easy *data, struct connectdata *conn) @@ -123,7 +114,6 @@ void Curl_cshutdn_run_once(struct Curl_easy *data, Curl_detach_connection(data); } - void Curl_cshutdn_terminate(struct Curl_easy *data, struct connectdata *conn, bool do_shutdown) @@ -231,15 +221,12 @@ static CURLcode cshutdn_wait(struct cshutdn *cshutdn, return result; } - static void cshutdn_perform(struct cshutdn *cshutdn, struct Curl_easy *data) { struct Curl_llist_node *e = Curl_llist_head(&cshutdn->list); struct Curl_llist_node *enext; struct connectdata *conn; - struct curltime *nowp = NULL; - struct curltime now; timediff_t next_expire_ms = 0, ms; bool done; @@ -259,11 +246,7 @@ static void cshutdn_perform(struct cshutdn *cshutdn, else { /* idata has one timer list, but maybe more than one connection. * Set EXPIRE_SHUTDOWN to the smallest time left for all. */ - if(!nowp) { - now = curlx_now(); - nowp = &now; - } - ms = Curl_conn_shutdown_timeleft(conn, nowp); + ms = Curl_conn_shutdown_timeleft(data, conn); if(ms && ms < next_expire_ms) next_expire_ms = ms; } @@ -271,15 +254,14 @@ static void cshutdn_perform(struct cshutdn *cshutdn, } if(next_expire_ms) - Curl_expire_ex(data, nowp, next_expire_ms, EXPIRE_SHUTDOWN); + Curl_expire_ex(data, next_expire_ms, EXPIRE_SHUTDOWN); } - static void cshutdn_terminate_all(struct cshutdn *cshutdn, struct Curl_easy *data, int timeout_ms) { - struct curltime started = curlx_now(); + struct curltime started = *Curl_pgrs_now(data); struct Curl_llist_node *e; SIGPIPE_VARIABLE(pipe_st); @@ -291,7 +273,7 @@ static void cshutdn_terminate_all(struct cshutdn *cshutdn, sigpipe_apply(data, &pipe_st); while(Curl_llist_head(&cshutdn->list)) { - timediff_t timespent; + timediff_t spent_ms; int remain_ms; cshutdn_perform(cshutdn, data); @@ -302,14 +284,14 @@ static void cshutdn_terminate_all(struct cshutdn *cshutdn, } /* wait for activity, timeout or "nothing" */ - timespent = curlx_timediff(curlx_now(), started); - if(timespent >= (timediff_t)timeout_ms) { + spent_ms = curlx_ptimediff_ms(Curl_pgrs_now(data), &started); + if(spent_ms >= (timediff_t)timeout_ms) { CURL_TRC_M(data, "[SHUTDOWN] shutdown finished, %s", - (timeout_ms > 0) ? "timeout" : "best effort done"); + (timeout_ms > 0) ? "timeout" : "best effort done"); break; } - remain_ms = timeout_ms - (int)timespent; + remain_ms = timeout_ms - (int)spent_ms; if(cshutdn_wait(cshutdn, data, remain_ms)) { CURL_TRC_M(data, "[SHUTDOWN] shutdown finished, aborted"); break; @@ -329,7 +311,6 @@ static void cshutdn_terminate_all(struct cshutdn *cshutdn, sigpipe_restore(&pipe_st); } - int Curl_cshutdn_init(struct cshutdn *cshutdn, struct Curl_multi *multi) { @@ -340,7 +321,6 @@ int Curl_cshutdn_init(struct cshutdn *cshutdn, return 0; /* good */ } - void Curl_cshutdn_destroy(struct cshutdn *cshutdn, struct Curl_easy *data) { @@ -392,7 +372,6 @@ size_t Curl_cshutdn_dest_count(struct Curl_easy *data, return 0; } - static CURLMcode cshutdn_update_ev(struct cshutdn *cshutdn, struct Curl_easy *data, struct connectdata *conn) @@ -408,14 +387,12 @@ static CURLMcode cshutdn_update_ev(struct cshutdn *cshutdn, return mresult; } - void Curl_cshutdn_add(struct cshutdn *cshutdn, struct connectdata *conn, size_t conns_in_pool) { struct Curl_easy *data = cshutdn->multi->admin; - size_t max_total = (cshutdn->multi->max_total_connections > 0) ? - (size_t)cshutdn->multi->max_total_connections : 0; + size_t max_total = cshutdn->multi->max_total_connections; /* Add the connection to our shutdown list for non-blocking shutdown * during multi processing. */ @@ -441,7 +418,6 @@ void Curl_cshutdn_add(struct cshutdn *cshutdn, conn->connection_id, Curl_llist_count(&cshutdn->list)); } - static void cshutdn_multi_socket(struct cshutdn *cshutdn, struct Curl_easy *data, curl_socket_t s) @@ -466,7 +442,6 @@ static void cshutdn_multi_socket(struct cshutdn *cshutdn, } } - void Curl_cshutdn_perform(struct cshutdn *cshutdn, struct Curl_easy *data, curl_socket_t s) @@ -488,8 +463,7 @@ void Curl_cshutdn_setfds(struct cshutdn *cshutdn, struct easy_pollset ps; Curl_pollset_init(&ps); - for(e = Curl_llist_head(&cshutdn->list); e; - e = Curl_node_next(e)) { + for(e = Curl_llist_head(&cshutdn->list); e; e = Curl_node_next(e)) { unsigned int i; struct connectdata *conn = Curl_node_elem(e); CURLcode result; @@ -503,20 +477,23 @@ void Curl_cshutdn_setfds(struct cshutdn *cshutdn, continue; for(i = 0; i < ps.n; i++) { + curl_socket_t sock = ps.sockets[i]; + if(!FDSET_SOCK(sock)) + continue; #ifdef __DJGPP__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Warith-conversion" #endif if(ps.actions[i] & CURL_POLL_IN) - FD_SET(ps.sockets[i], read_fd_set); + FD_SET(sock, read_fd_set); if(ps.actions[i] & CURL_POLL_OUT) - FD_SET(ps.sockets[i], write_fd_set); + FD_SET(sock, write_fd_set); #ifdef __DJGPP__ #pragma GCC diagnostic pop #endif if((ps.actions[i] & (CURL_POLL_OUT | CURL_POLL_IN)) && - ((int)ps.sockets[i] > *maxfd)) - *maxfd = (int)ps.sockets[i]; + ((int)sock > *maxfd)) + *maxfd = (int)sock; } } Curl_pollset_cleanup(&ps); @@ -537,8 +514,7 @@ unsigned int Curl_cshutdn_add_waitfds(struct cshutdn *cshutdn, CURLcode result; Curl_pollset_init(&ps); - for(e = Curl_llist_head(&cshutdn->list); e; - e = Curl_node_next(e)) { + for(e = Curl_llist_head(&cshutdn->list); e; e = Curl_node_next(e)) { conn = Curl_node_elem(e); Curl_pollset_reset(&ps); Curl_attach_connection(data, conn); @@ -565,8 +541,7 @@ CURLcode Curl_cshutdn_add_pollfds(struct cshutdn *cshutdn, struct connectdata *conn; Curl_pollset_init(&ps); - for(e = Curl_llist_head(&cshutdn->list); e; - e = Curl_node_next(e)) { + for(e = Curl_llist_head(&cshutdn->list); e; e = Curl_node_next(e)) { conn = Curl_node_elem(e); Curl_pollset_reset(&ps); Curl_attach_connection(data, conn); diff --git a/vendor/hydra/vendor/curl/lib/cshutdn.h b/vendor/hydra/vendor/curl/lib/cshutdn.h index 510d5bf5..0a15d39f 100644 --- a/vendor/hydra/vendor/curl/lib/cshutdn.h +++ b/vendor/hydra/vendor/curl/lib/cshutdn.h @@ -24,10 +24,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - -#include -#include "curlx/timeval.h" - struct connectdata; struct Curl_easy; struct curl_pollfds; diff --git a/vendor/hydra/vendor/curl/lib/curl_addrinfo.c b/vendor/hydra/vendor/curl/lib/curl_addrinfo.c index e26ee656..61c8b188 100644 --- a/vendor/hydra/vendor/curl/lib/curl_addrinfo.c +++ b/vendor/hydra/vendor/curl/lib/curl_addrinfo.c @@ -21,11 +21,8 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include - #ifdef HAVE_NETINET_IN_H # include #endif @@ -47,16 +44,11 @@ # include #endif -#include +#include /* for offsetof() */ #include "curl_addrinfo.h" #include "fake_addrinfo.h" #include "curlx/inet_pton.h" -#include "curlx/warnless.h" - -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" /* * Curl_freeaddrinfo() @@ -68,26 +60,24 @@ */ #if defined(__INTEL_COMPILER) && (__INTEL_COMPILER == 910) && \ - defined(__OPTIMIZE__) && defined(__unix__) && defined(__i386__) + defined(__OPTIMIZE__) && defined(__unix__) && defined(__i386__) /* workaround icc 9.1 optimizer issue */ # define vqualifier volatile #else # define vqualifier #endif -void -Curl_freeaddrinfo(struct Curl_addrinfo *cahead) +void Curl_freeaddrinfo(struct Curl_addrinfo *cahead) { struct Curl_addrinfo *vqualifier canext; struct Curl_addrinfo *ca; for(ca = cahead; ca; ca = canext) { canext = ca->ai_next; - free(ca); + curlx_free(ca); } } - #ifdef HAVE_GETADDRINFO /* * Curl_getaddrinfo_ex() @@ -102,12 +92,10 @@ Curl_freeaddrinfo(struct Curl_addrinfo *cahead) * There should be no single call to system's getaddrinfo() in the * whole library, any such call should be 'routed' through this one. */ - -int -Curl_getaddrinfo_ex(const char *nodename, - const char *servname, - const struct addrinfo *hints, - struct Curl_addrinfo **result) +int Curl_getaddrinfo_ex(const char *nodename, + const char *servname, + const struct addrinfo *hints, + struct Curl_addrinfo **result) { const struct addrinfo *ai; struct addrinfo *aihead; @@ -146,7 +134,7 @@ Curl_getaddrinfo_ex(const char *nodename, if((size_t)ai->ai_addrlen < ss_size) continue; - ca = malloc(sizeof(struct Curl_addrinfo) + ss_size + namelen); + ca = curlx_malloc(sizeof(struct Curl_addrinfo) + ss_size + namelen); if(!ca) { error = EAI_MEMORY; break; @@ -180,7 +168,6 @@ Curl_getaddrinfo_ex(const char *nodename, if(calast) calast->ai_next = ca; calast = ca; - } /* destroy the addrinfo list */ @@ -212,7 +199,6 @@ Curl_getaddrinfo_ex(const char *nodename, } #endif /* HAVE_GETADDRINFO */ - /* * Curl_he2ai() * @@ -252,10 +238,8 @@ Curl_getaddrinfo_ex(const char *nodename, * * #define h_addr h_addr_list[0] */ - #if !(defined(HAVE_GETADDRINFO) && defined(HAVE_GETADDRINFO_THREADSAFE)) -struct Curl_addrinfo * -Curl_he2ai(const struct hostent *he, int port) +struct Curl_addrinfo *Curl_he2ai(const struct hostent *he, int port) { struct Curl_addrinfo *ai; struct Curl_addrinfo *prevai = NULL; @@ -285,7 +269,7 @@ Curl_he2ai(const struct hostent *he, int port) ss_size = sizeof(struct sockaddr_in); /* allocate memory to hold the struct, the address and the name */ - ai = calloc(1, sizeof(struct Curl_addrinfo) + ss_size + namelen); + ai = curlx_calloc(1, sizeof(struct Curl_addrinfo) + ss_size + namelen); if(!ai) { result = CURLE_OUT_OF_MEMORY; break; @@ -347,16 +331,15 @@ Curl_he2ai(const struct hostent *he, int port) #endif /* - * Curl_ip2addr() + * ip2addr() * * This function takes an Internet address, in binary form, as input parameter * along with its address family and the string version of the address, and it * returns a Curl_addrinfo chain filled in correctly with information for the * given address/host */ - -struct Curl_addrinfo * -Curl_ip2addr(int af, const void *inaddr, const char *hostname, int port) +static CURLcode ip2addr(struct Curl_addrinfo **addrp, int af, + const void *inaddr, const char *hostname, int port) { struct Curl_addrinfo *ai; size_t addrsize; @@ -369,6 +352,7 @@ Curl_ip2addr(int af, const void *inaddr, const char *hostname, int port) DEBUGASSERT(inaddr && hostname); namelen = strlen(hostname) + 1; + *addrp = NULL; if(af == AF_INET) addrsize = sizeof(struct sockaddr_in); @@ -377,12 +361,12 @@ Curl_ip2addr(int af, const void *inaddr, const char *hostname, int port) addrsize = sizeof(struct sockaddr_in6); #endif else - return NULL; + return CURLE_BAD_FUNCTION_ARGUMENT; /* allocate memory to hold the struct, the address and the name */ - ai = calloc(1, sizeof(struct Curl_addrinfo) + addrsize + namelen); + ai = curlx_calloc(1, sizeof(struct Curl_addrinfo) + addrsize + namelen); if(!ai) - return NULL; + return CURLE_OUT_OF_MEMORY; /* put the address after the struct */ ai->ai_addr = (void *)((char *)ai + sizeof(struct Curl_addrinfo)); /* then put the name after the address */ @@ -412,29 +396,46 @@ Curl_ip2addr(int af, const void *inaddr, const char *hostname, int port) break; #endif } - - return ai; + *addrp = ai; + return CURLE_OK; } /* * Given an IPv4 or IPv6 dotted string address, this converts it to a proper * allocated Curl_addrinfo struct and returns it. */ -struct Curl_addrinfo *Curl_str2addr(char *address, int port) +CURLcode Curl_str2addr(const char *address, int port, + struct Curl_addrinfo **addrp) { struct in_addr in; if(curlx_inet_pton(AF_INET, address, &in) > 0) /* This is a dotted IP address 123.123.123.123-style */ - return Curl_ip2addr(AF_INET, &in, address, port); + return ip2addr(addrp, AF_INET, &in, address, port); +#ifdef USE_IPV6 + { + struct in6_addr in6; + if(curlx_inet_pton(AF_INET6, address, &in6) > 0) + /* This is a dotted IPv6 address ::1-style */ + return ip2addr(addrp, AF_INET6, &in6, address, port); + } +#endif + return CURLE_BAD_FUNCTION_ARGUMENT; /* bad input format */ +} + +bool Curl_is_ipaddr(const char *address) +{ + struct in_addr in; + if(curlx_inet_pton(AF_INET, address, &in) > 0) + return TRUE; #ifdef USE_IPV6 { struct in6_addr in6; if(curlx_inet_pton(AF_INET6, address, &in6) > 0) /* This is a dotted IPv6 address ::1-style */ - return Curl_ip2addr(AF_INET6, &in6, address, port); + return TRUE; } #endif - return NULL; /* bad input format */ + return FALSE; } #ifdef USE_UNIX_SOCKETS @@ -452,18 +453,19 @@ struct Curl_addrinfo *Curl_unix2addr(const char *path, bool *longpath, *longpath = FALSE; - ai = calloc(1, sizeof(struct Curl_addrinfo) + sizeof(struct sockaddr_un)); + ai = curlx_calloc(1, + sizeof(struct Curl_addrinfo) + sizeof(struct sockaddr_un)); if(!ai) return NULL; ai->ai_addr = (void *)((char *)ai + sizeof(struct Curl_addrinfo)); - sa_un = (void *) ai->ai_addr; + sa_un = (void *)ai->ai_addr; sa_un->sun_family = AF_UNIX; /* sun_path must be able to store the null-terminated path */ path_len = strlen(path) + 1; if(path_len > sizeof(sa_un->sun_path)) { - free(ai); + curlx_free(ai); *longpath = TRUE; return NULL; } @@ -492,10 +494,8 @@ struct Curl_addrinfo *Curl_unix2addr(const char *path, bool *longpath, * family otherwise present in memdebug.c. I put these ones here since they * require a bunch of structs I did not want to include in memdebug.c */ - -void -curl_dbg_freeaddrinfo(struct addrinfo *freethis, - int line, const char *source) +void curl_dbg_freeaddrinfo(struct addrinfo *freethis, + int line, const char *source) { curl_dbg_log("ADDR %s:%d freeaddrinfo(%p)\n", source, line, (void *)freethis); @@ -517,7 +517,6 @@ curl_dbg_freeaddrinfo(struct addrinfo *freethis, } #endif /* CURLDEBUG && HAVE_FREEADDRINFO */ - #if defined(CURLDEBUG) && defined(HAVE_GETADDRINFO) /* * curl_dbg_getaddrinfo() @@ -526,13 +525,11 @@ curl_dbg_freeaddrinfo(struct addrinfo *freethis, * family otherwise present in memdebug.c. I put these ones here since they * require a bunch of structs I did not want to include in memdebug.c */ - -int -curl_dbg_getaddrinfo(const char *hostname, - const char *service, - const struct addrinfo *hints, - struct addrinfo **result, - int line, const char *source) +int curl_dbg_getaddrinfo(const char *hostname, + const char *service, + const struct addrinfo *hints, + struct addrinfo **result, + int line, const char *source) { #ifdef USE_LWIPSOCK int res = lwip_getaddrinfo(hostname, service, hints, result); @@ -550,11 +547,10 @@ curl_dbg_getaddrinfo(const char *hostname, #endif if(res == 0) /* success */ - curl_dbg_log("ADDR %s:%d getaddrinfo() = %p\n", - source, line, (void *)*result); + curl_dbg_log("ADDR %s:%d getaddrinfo() = %p\n", source, line, + (void *)*result); else - curl_dbg_log("ADDR %s:%d getaddrinfo() failed\n", - source, line); + curl_dbg_log("ADDR %s:%d getaddrinfo() failed\n", source, line); return res; } #endif /* CURLDEBUG && HAVE_GETADDRINFO */ diff --git a/vendor/hydra/vendor/curl/lib/curl_addrinfo.h b/vendor/hydra/vendor/curl/lib/curl_addrinfo.h index 2303e95e..ca80f3a4 100644 --- a/vendor/hydra/vendor/curl/lib/curl_addrinfo.h +++ b/vendor/hydra/vendor/curl/lib/curl_addrinfo.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifdef HAVE_NETINET_IN_H @@ -60,26 +59,21 @@ struct Curl_addrinfo { struct Curl_addrinfo *ai_next; }; -void -Curl_freeaddrinfo(struct Curl_addrinfo *cahead); +void Curl_freeaddrinfo(struct Curl_addrinfo *cahead); #ifdef HAVE_GETADDRINFO -int -Curl_getaddrinfo_ex(const char *nodename, - const char *servname, - const struct addrinfo *hints, - struct Curl_addrinfo **result); +int Curl_getaddrinfo_ex(const char *nodename, + const char *servname, + const struct addrinfo *hints, + struct Curl_addrinfo **result); #endif #if !(defined(HAVE_GETADDRINFO) && defined(HAVE_GETADDRINFO_THREADSAFE)) -struct Curl_addrinfo * -Curl_he2ai(const struct hostent *he, int port); +struct Curl_addrinfo *Curl_he2ai(const struct hostent *he, int port); #endif -struct Curl_addrinfo * -Curl_ip2addr(int af, const void *inaddr, const char *hostname, int port); - -struct Curl_addrinfo *Curl_str2addr(char *dotted, int port); +bool Curl_is_ipaddr(const char *address); +CURLcode Curl_str2addr(const char *dotted, int port, struct Curl_addrinfo **); #ifdef USE_UNIX_SOCKETS struct Curl_addrinfo *Curl_unix2addr(const char *path, bool *longpath, @@ -87,23 +81,23 @@ struct Curl_addrinfo *Curl_unix2addr(const char *path, bool *longpath, #endif #if defined(CURLDEBUG) && defined(HAVE_GETADDRINFO) && \ - defined(HAVE_FREEADDRINFO) -void -curl_dbg_freeaddrinfo(struct addrinfo *freethis, int line, const char *source); + defined(HAVE_FREEADDRINFO) +void curl_dbg_freeaddrinfo(struct addrinfo *freethis, int line, + const char *source); #endif #if defined(CURLDEBUG) && defined(HAVE_GETADDRINFO) -int -curl_dbg_getaddrinfo(const char *hostname, const char *service, - const struct addrinfo *hints, struct addrinfo **result, - int line, const char *source); +int curl_dbg_getaddrinfo(const char *hostname, const char *service, + const struct addrinfo *hints, + struct addrinfo **result, int line, + const char *source); #endif #ifdef HAVE_GETADDRINFO #ifdef USE_RESOLVE_ON_IPS void Curl_addrinfo_set_port(struct Curl_addrinfo *addrinfo, int port); #else -#define Curl_addrinfo_set_port(x,y) +#define Curl_addrinfo_set_port(x, y) #endif #endif diff --git a/vendor/hydra/vendor/curl/lib/curl_config-cmake.h.in b/vendor/hydra/vendor/curl/lib/curl_config-cmake.h.in new file mode 100644 index 00000000..d8d9d7ec --- /dev/null +++ b/vendor/hydra/vendor/curl/lib/curl_config-cmake.h.in @@ -0,0 +1,819 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + * SPDX-License-Identifier: curl + * + ***************************************************************************/ + +/* Location of default ca bundle */ +#cmakedefine CURL_CA_BUNDLE "${CURL_CA_BUNDLE}" + +/* define "1" to use built-in ca store of TLS backend */ +#cmakedefine CURL_CA_FALLBACK 1 + +/* Location of default ca path */ +#cmakedefine CURL_CA_PATH "${CURL_CA_PATH}" + +/* Default SSL backend */ +#cmakedefine CURL_DEFAULT_SSL_BACKEND "${CURL_DEFAULT_SSL_BACKEND}" + +/* disables alt-svc */ +#cmakedefine CURL_DISABLE_ALTSVC 1 + +/* disables cookies support */ +#cmakedefine CURL_DISABLE_COOKIES 1 + +/* disables Basic authentication */ +#cmakedefine CURL_DISABLE_BASIC_AUTH 1 + +/* disables Bearer authentication */ +#cmakedefine CURL_DISABLE_BEARER_AUTH 1 + +/* disables Digest authentication */ +#cmakedefine CURL_DISABLE_DIGEST_AUTH 1 + +/* disables Kerberos authentication */ +#cmakedefine CURL_DISABLE_KERBEROS_AUTH 1 + +/* disables negotiate authentication */ +#cmakedefine CURL_DISABLE_NEGOTIATE_AUTH 1 + +/* disables aws-sigv4 */ +#cmakedefine CURL_DISABLE_AWS 1 + +/* disables DICT */ +#cmakedefine CURL_DISABLE_DICT 1 + +/* disables DNS-over-HTTPS */ +#cmakedefine CURL_DISABLE_DOH 1 + +/* disables FILE */ +#cmakedefine CURL_DISABLE_FILE 1 + +/* disables form api */ +#cmakedefine CURL_DISABLE_FORM_API 1 + +/* disables FTP */ +#cmakedefine CURL_DISABLE_FTP 1 + +/* disables curl_easy_options API for existing options to curl_easy_setopt */ +#cmakedefine CURL_DISABLE_GETOPTIONS 1 + +/* disables GOPHER */ +#cmakedefine CURL_DISABLE_GOPHER 1 + +/* disables headers-api support */ +#cmakedefine CURL_DISABLE_HEADERS_API 1 + +/* disables HSTS support */ +#cmakedefine CURL_DISABLE_HSTS 1 + +/* disables HTTP */ +#cmakedefine CURL_DISABLE_HTTP 1 + +/* disabled all HTTP authentication methods */ +#cmakedefine CURL_DISABLE_HTTP_AUTH 1 + +/* disables IMAP */ +#cmakedefine CURL_DISABLE_IMAP 1 + +/* disables LDAP */ +#cmakedefine CURL_DISABLE_LDAP 1 + +/* disables LDAPS */ +#cmakedefine CURL_DISABLE_LDAPS 1 + +/* disables --libcurl option from the curl tool */ +#cmakedefine CURL_DISABLE_LIBCURL_OPTION 1 + +/* disables MIME support */ +#cmakedefine CURL_DISABLE_MIME 1 + +/* disables local binding support */ +#cmakedefine CURL_DISABLE_BINDLOCAL 1 + +/* disables MQTT */ +#cmakedefine CURL_DISABLE_MQTT 1 + +/* disables netrc parser */ +#cmakedefine CURL_DISABLE_NETRC 1 + +/* disables NTLM support */ +#cmakedefine CURL_DISABLE_NTLM 1 + +/* disables date parsing */ +#cmakedefine CURL_DISABLE_PARSEDATE 1 + +/* disables POP3 */ +#cmakedefine CURL_DISABLE_POP3 1 + +/* disables built-in progress meter */ +#cmakedefine CURL_DISABLE_PROGRESS_METER 1 + +/* disables proxies */ +#cmakedefine CURL_DISABLE_PROXY 1 + +/* disables IPFS from the curl tool */ +#cmakedefine CURL_DISABLE_IPFS 1 + +/* disables RTSP */ +#cmakedefine CURL_DISABLE_RTSP 1 + +/* disables SHA-512/256 hash algorithm */ +#cmakedefine CURL_DISABLE_SHA512_256 1 + +/* disabled shuffle DNS feature */ +#cmakedefine CURL_DISABLE_SHUFFLE_DNS 1 + +/* disables SMB */ +#cmakedefine CURL_DISABLE_SMB 1 + +/* disables SMTP */ +#cmakedefine CURL_DISABLE_SMTP 1 + +/* disabled WebSocket */ +#cmakedefine CURL_DISABLE_WEBSOCKETS 1 + +/* disables use of socketpair for curl_multi_poll() */ +#cmakedefine CURL_DISABLE_SOCKETPAIR 1 + +/* disables TELNET */ +#cmakedefine CURL_DISABLE_TELNET 1 + +/* disables TFTP */ +#cmakedefine CURL_DISABLE_TFTP 1 + +/* disables curl_easy_setopt()/curl_easy_getinfo() type checking */ +#cmakedefine CURL_DISABLE_TYPECHECK 1 + +/* disables verbose strings */ +#cmakedefine CURL_DISABLE_VERBOSE_STRINGS 1 + +/* disables unsafe CA bundle search on Windows from the curl tool */ +#cmakedefine CURL_DISABLE_CA_SEARCH 1 + +/* safe CA bundle search (within the curl tool directory) on Windows */ +#cmakedefine CURL_CA_SEARCH_SAFE 1 + +/* to make a symbol visible */ +#cmakedefine CURL_EXTERN_SYMBOL ${CURL_EXTERN_SYMBOL} +/* Ensure using CURL_EXTERN_SYMBOL is possible */ +#ifndef CURL_EXTERN_SYMBOL +#define CURL_EXTERN_SYMBOL +#endif + +/* Allow SMB to work on Windows */ +#cmakedefine USE_WIN32_CRYPTO 1 + +/* Use Windows LDAP implementation */ +#cmakedefine USE_WIN32_LDAP 1 + +/* Define if you want to enable IPv6 support */ +#cmakedefine USE_IPV6 1 + +/* Define to 1 if you have the alarm function. */ +#cmakedefine HAVE_ALARM 1 + +/* Define to 1 if you have the arc4random function. */ +#cmakedefine HAVE_ARC4RANDOM 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_ARPA_INET_H 1 + +/* Define to 1 if you have _Atomic support. */ +#cmakedefine HAVE_ATOMIC 1 + +/* Define to 1 if you have the `accept4' function. */ +#cmakedefine HAVE_ACCEPT4 1 + +/* Define to 1 if you have the `fnmatch' function. */ +#cmakedefine HAVE_FNMATCH 1 + +/* Define to 1 if you have the `basename' function. */ +#cmakedefine HAVE_BASENAME 1 + +/* Define to 1 if bool is an available type. */ +#cmakedefine HAVE_BOOL_T 1 + +/* Define to 1 if you have the __builtin_available function. */ +#cmakedefine HAVE_BUILTIN_AVAILABLE 1 + +/* Define to 1 if you have the clock_gettime function and monotonic timer. */ +#cmakedefine HAVE_CLOCK_GETTIME_MONOTONIC 1 + +/* Define to 1 if you have the clock_gettime function and raw monotonic timer. + */ +#cmakedefine HAVE_CLOCK_GETTIME_MONOTONIC_RAW 1 + +/* Define to 1 if you have the `closesocket' function. */ +#cmakedefine HAVE_CLOSESOCKET 1 + +/* Define to 1 if you have the `CloseSocket' function. */ +#cmakedefine HAVE_CLOSESOCKET_CAMEL 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_DIRENT_H 1 + +/* Define to 1 if you have the `opendir' function. */ +#cmakedefine HAVE_OPENDIR 1 + +/* Define to 1 if you have the fcntl function. */ +#cmakedefine HAVE_FCNTL 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_FCNTL_H 1 + +/* Define to 1 if you have a working fcntl O_NONBLOCK function. */ +#cmakedefine HAVE_FCNTL_O_NONBLOCK 1 + +/* Define to 1 if you have the freeaddrinfo function. */ +#cmakedefine HAVE_FREEADDRINFO 1 + +/* Define to 1 if you have the fseeko function. */ +#cmakedefine HAVE_FSEEKO 1 + +/* Define to 1 if you have the fseeko declaration. */ +#cmakedefine HAVE_DECL_FSEEKO 1 + +/* Define to 1 if you have the ftruncate function. */ +#cmakedefine HAVE_FTRUNCATE 1 + +/* Define to 1 if you have a working getaddrinfo function. */ +#cmakedefine HAVE_GETADDRINFO 1 + +/* Define to 1 if the getaddrinfo function is threadsafe. */ +#cmakedefine HAVE_GETADDRINFO_THREADSAFE 1 + +/* Define to 1 if you have the `geteuid' function. */ +#cmakedefine HAVE_GETEUID 1 + +/* Define to 1 if you have the `getppid' function. */ +#cmakedefine HAVE_GETPPID 1 + +/* Define to 1 if you have the gethostbyname_r function. */ +#cmakedefine HAVE_GETHOSTBYNAME_R 1 + +/* gethostbyname_r() takes 3 args */ +#cmakedefine HAVE_GETHOSTBYNAME_R_3 1 + +/* gethostbyname_r() takes 5 args */ +#cmakedefine HAVE_GETHOSTBYNAME_R_5 1 + +/* gethostbyname_r() takes 6 args */ +#cmakedefine HAVE_GETHOSTBYNAME_R_6 1 + +/* Define to 1 if you have the gethostname function. */ +#cmakedefine HAVE_GETHOSTNAME 1 + +/* Define to 1 if you have a working getifaddrs function. */ +#cmakedefine HAVE_GETIFADDRS 1 + +/* Define to 1 if you have the `getpass_r' function. */ +#cmakedefine HAVE_GETPASS_R 1 + +/* Define to 1 if you have the `getpeername' function. */ +#cmakedefine HAVE_GETPEERNAME 1 + +/* Define to 1 if you have the `getsockname' function. */ +#cmakedefine HAVE_GETSOCKNAME 1 + +/* Define to 1 if you have the `if_nametoindex' function. */ +#cmakedefine HAVE_IF_NAMETOINDEX 1 + +/* Define to 1 if you have the `getpwuid' function. */ +#cmakedefine HAVE_GETPWUID 1 + +/* Define to 1 if you have the `getpwuid_r' function. */ +#cmakedefine HAVE_GETPWUID_R 1 + +/* Define to 1 if you have the `getrlimit' function. */ +#cmakedefine HAVE_GETRLIMIT 1 + +/* Define to 1 if you have the `gettimeofday' function. */ +#cmakedefine HAVE_GETTIMEOFDAY 1 + +/* Define to 1 if you have a working glibc-style strerror_r function. */ +#cmakedefine HAVE_GLIBC_STRERROR_R 1 + +/* Define to 1 if you have a working gmtime_r function. */ +#cmakedefine HAVE_GMTIME_R 1 + +/* if you have the gssapi libraries */ +#cmakedefine HAVE_GSSAPI 1 + +/* if you have the GNU gssapi libraries */ +#cmakedefine HAVE_GSSGNU 1 + +/* MIT Kerberos version */ +#cmakedefine CURL_KRB5_VERSION ${CURL_KRB5_VERSION} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_IFADDRS_H 1 + +/* Define to 1 if you have an IPv6 capable working inet_ntop function. */ +#cmakedefine HAVE_INET_NTOP 1 + +/* Define to 1 if you have an IPv6 capable working inet_pton function. */ +#cmakedefine HAVE_INET_PTON 1 + +/* Define to 1 if symbol `sa_family_t' exists */ +#cmakedefine HAVE_SA_FAMILY_T 1 + +/* Define to 1 if you have the ioctlsocket function. */ +#cmakedefine HAVE_IOCTLSOCKET 1 + +/* Define to 1 if you have the IoctlSocket camel case function. */ +#cmakedefine HAVE_IOCTLSOCKET_CAMEL 1 + +/* Define to 1 if you have a working IoctlSocket camel case FIONBIO function. + */ +#cmakedefine HAVE_IOCTLSOCKET_CAMEL_FIONBIO 1 + +/* Define to 1 if you have a working ioctlsocket FIONBIO function. */ +#cmakedefine HAVE_IOCTLSOCKET_FIONBIO 1 + +/* Define to 1 if you have a working ioctl FIONBIO function. */ +#cmakedefine HAVE_IOCTL_FIONBIO 1 + +/* Define to 1 if you have a working ioctl SIOCGIFADDR function. */ +#cmakedefine HAVE_IOCTL_SIOCGIFADDR 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_IO_H 1 + +/* Define to 1 if you have the lber.h header file. */ +#cmakedefine HAVE_LBER_H 1 + +/* Use LDAPS implementation */ +#cmakedefine HAVE_LDAP_SSL 1 + +/* Define to 1 if you have the ldap_ssl.h header file. */ +#cmakedefine HAVE_LDAP_SSL_H 1 + +/* Define to 1 if you have the `ldap_url_parse' function. */ +#cmakedefine HAVE_LDAP_URL_PARSE 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LIBGEN_H 1 + +/* Define to 1 if you have the `idn2' library (-lidn2). */ +#cmakedefine HAVE_LIBIDN2 1 + +/* Define to 1 if you have the idn2.h header file. */ +#cmakedefine HAVE_IDN2_H 1 + +/* if zlib is available */ +#cmakedefine HAVE_LIBZ 1 + +/* if brotli is available */ +#cmakedefine HAVE_BROTLI 1 + +/* if zstd is available */ +#cmakedefine HAVE_ZSTD 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LOCALE_H 1 + +/* Define to 1 if you have a working localtime_r function. */ +#cmakedefine HAVE_LOCALTIME_R 1 + +/* Define to 1 if the compiler supports the 'long long' data type. */ +#cmakedefine HAVE_LONGLONG 1 + +/* Define to 1 if you have the 'suseconds_t' data type. */ +#cmakedefine HAVE_SUSECONDS_T 1 + +/* Define to 1 if you have the MSG_NOSIGNAL flag. */ +#cmakedefine HAVE_MSG_NOSIGNAL 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_NETDB_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_NETINET_IN_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_NETINET_IN6_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_NETINET_TCP_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_NETINET_UDP_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LINUX_TCP_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_NET_IF_H 1 + +/* Define to 1 if you have the `pipe' function. */ +#cmakedefine HAVE_PIPE 1 + +/* Define to 1 if you have the `pipe2' function. */ +#cmakedefine HAVE_PIPE2 1 + +/* Define to 1 if you have the `eventfd' function. */ +#cmakedefine HAVE_EVENTFD 1 + +/* If you have poll */ +#cmakedefine HAVE_POLL 1 + +/* If you have realpath */ +#cmakedefine HAVE_REALPATH 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_POLL_H 1 + +/* Define to 1 if you have a working POSIX-style strerror_r function. */ +#cmakedefine HAVE_POSIX_STRERROR_R 1 + +/* Define to 1 if you have the header file */ +#cmakedefine HAVE_PTHREAD_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_PWD_H 1 + +/* Define to 1 if OpenSSL has the `SSL_set0_wbio` function. */ +#cmakedefine HAVE_SSL_SET0_WBIO 1 + +/* Define to 1 if you have the recv function. */ +#cmakedefine HAVE_RECV 1 + +/* Define to 1 if you have the select function. */ +#cmakedefine HAVE_SELECT 1 + +/* Define to 1 if you have the sched_yield function. */ +#cmakedefine HAVE_SCHED_YIELD 1 + +/* Define to 1 if you have the send function. */ +#cmakedefine HAVE_SEND 1 + +/* Define to 1 if you have the sendmsg function. */ +#cmakedefine HAVE_SENDMSG 1 + +/* Define to 1 if you have the sendmmsg function. */ +#cmakedefine HAVE_SENDMMSG 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STDINT_H 1 + +/* Define to 1 if you have the 'fsetxattr' function. */ +#cmakedefine HAVE_FSETXATTR 1 + +/* fsetxattr() takes 5 args */ +#cmakedefine HAVE_FSETXATTR_5 1 + +/* fsetxattr() takes 6 args */ +#cmakedefine HAVE_FSETXATTR_6 1 + +/* Define to 1 if you have the `setlocale' function. */ +#cmakedefine HAVE_SETLOCALE 1 + +/* Define to 1 if you have the `setmode' function. */ +#cmakedefine HAVE_SETMODE 1 + +/* Define to 1 if you have the `_setmode' function. */ +#cmakedefine HAVE__SETMODE 1 + +/* Define to 1 if you have the `setrlimit' function. */ +#cmakedefine HAVE_SETRLIMIT 1 + +/* Define to 1 if you have a working setsockopt SO_NONBLOCK function. */ +#cmakedefine HAVE_SETSOCKOPT_SO_NONBLOCK 1 + +/* Define to 1 if you have the sigaction function. */ +#cmakedefine HAVE_SIGACTION 1 + +/* Define to 1 if you have the siginterrupt function. */ +#cmakedefine HAVE_SIGINTERRUPT 1 + +/* Define to 1 if you have the signal function. */ +#cmakedefine HAVE_SIGNAL 1 + +/* Define to 1 if you have the sigsetjmp function or macro. */ +#cmakedefine HAVE_SIGSETJMP 1 + +/* Define to 1 if you have the `snprintf' function. */ +#cmakedefine HAVE_SNPRINTF 1 + +/* Define to 1 if struct sockaddr_in6 has the sin6_scope_id member */ +#cmakedefine HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID 1 + +/* Define to 1 if you have the `socket' function. */ +#cmakedefine HAVE_SOCKET 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_PROTO_BSDSOCKET_H 1 + +/* Define to 1 if you have the socketpair function. */ +#cmakedefine HAVE_SOCKETPAIR 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STDATOMIC_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STDBOOL_H 1 + +/* Define to 1 if you have the strcasecmp function. */ +#cmakedefine HAVE_STRCASECMP 1 + +/* Define to 1 if you have the strcmpi function. */ +#cmakedefine HAVE_STRCMPI 1 + +/* Define to 1 if you have the strdup function. */ +#cmakedefine HAVE_STRDUP 1 + +/* Define to 1 if you have the strerror_r function. */ +#cmakedefine HAVE_STRERROR_R 1 + +/* Define to 1 if you have the stricmp function. */ +#cmakedefine HAVE_STRICMP 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STROPTS_H 1 + +/* Define to 1 if you have the memrchr function. */ +#cmakedefine HAVE_MEMRCHR 1 + +/* if struct sockaddr_storage is defined */ +#cmakedefine HAVE_STRUCT_SOCKADDR_STORAGE 1 + +/* Define to 1 if you have the timeval struct. */ +#cmakedefine HAVE_STRUCT_TIMEVAL 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_EVENTFD_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_FILIO_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_IOCTL_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_PARAM_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_POLL_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_RESOURCE_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_SELECT_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_SOCKIO_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_UN_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_UTIME_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_TERMIOS_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_TERMIO_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_UNISTD_H 1 + +/* Define to 1 if you have the `utime' function. */ +#cmakedefine HAVE_UTIME 1 + +/* Define to 1 if you have the `utimes' function. */ +#cmakedefine HAVE_UTIMES 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_UTIME_H 1 + +/* Define this symbol if your OS supports changing the contents of argv */ +#cmakedefine HAVE_WRITABLE_ARGV 1 + +/* Define this if time_t is unsigned */ +#cmakedefine HAVE_TIME_T_UNSIGNED 1 + +/* Define to 1 if _REENTRANT preprocessor symbol must be defined. */ +#cmakedefine NEED_REENTRANT 1 + +/* cpu-machine-OS */ +#cmakedefine CURL_OS ${CURL_OS} + +/* + Note: SIZEOF_* variables are fetched with CMake through check_type_size(). + As per CMake documentation on CheckTypeSize, C preprocessor code is + generated by CMake into SIZEOF_*_CODE. This is what we use in the + following statements. + + Reference: https://cmake.org/cmake/help/latest/module/CheckTypeSize.html +*/ + +/* The size of `int', as computed by sizeof. */ +${SIZEOF_INT_CODE} + +/* The size of `long', as computed by sizeof. */ +${SIZEOF_LONG_CODE} + +/* The size of `long long', as computed by sizeof. */ +${SIZEOF_LONG_LONG_CODE} + +/* The size of `off_t', as computed by sizeof. */ +${SIZEOF_OFF_T_CODE} + +/* The size of `curl_off_t', as computed by sizeof. */ +${SIZEOF_CURL_OFF_T_CODE} + +/* The size of `curl_socket_t', as computed by sizeof. */ +${SIZEOF_CURL_SOCKET_T_CODE} + +/* The size of `size_t', as computed by sizeof. */ +${SIZEOF_SIZE_T_CODE} + +/* The size of `time_t', as computed by sizeof. */ +${SIZEOF_TIME_T_CODE} + +/* Define to 1 if you have the ANSI C header files. */ +#cmakedefine STDC_HEADERS 1 + +/* Define if you want to enable c-ares support */ +#cmakedefine USE_ARES 1 + +/* Define if you want to enable POSIX threaded DNS lookup */ +#cmakedefine USE_THREADS_POSIX 1 + +/* Define if you want to enable Win32 threaded DNS lookup */ +#cmakedefine USE_THREADS_WIN32 1 + +/* if GnuTLS is enabled */ +#cmakedefine USE_GNUTLS 1 + +/* if SSL session export support is available */ +#cmakedefine USE_SSLS_EXPORT 1 + +/* if mbedTLS is enabled */ +#cmakedefine USE_MBEDTLS 1 + +/* if mbedTLS <4 has the mbedtls_des_crypt_ecb function. */ +#cmakedefine HAVE_MBEDTLS_DES_CRYPT_ECB 1 + +/* if Rustls is enabled */ +#cmakedefine USE_RUSTLS 1 + +/* if wolfSSL is enabled */ +#cmakedefine USE_WOLFSSL 1 + +/* if wolfSSL has the wolfSSL_get_peer_certificate function. */ +#cmakedefine HAVE_WOLFSSL_GET_PEER_CERTIFICATE 1 + +/* if wolfSSL has the wolfSSL_UseALPN function. */ +#cmakedefine HAVE_WOLFSSL_USEALPN 1 + +/* if wolfSSL has the wolfSSL_DES_ecb_encrypt function. */ +#cmakedefine HAVE_WOLFSSL_DES_ECB_ENCRYPT 1 + +/* if wolfSSL has the wolfSSL_BIO_new function. */ +#cmakedefine HAVE_WOLFSSL_BIO_NEW 1 + +/* if wolfSSL has the wolfSSL_BIO_set_shutdown function. */ +#cmakedefine HAVE_WOLFSSL_BIO_SET_SHUTDOWN 1 + +/* if libssh is in use */ +#cmakedefine USE_LIBSSH 1 + +/* if libssh2 is in use */ +#cmakedefine USE_LIBSSH2 1 + +/* if libpsl is in use */ +#cmakedefine USE_LIBPSL 1 + +/* if you want to use OpenLDAP code instead of legacy ldap implementation */ +#cmakedefine USE_OPENLDAP 1 + +/* if OpenSSL is in use */ +#cmakedefine USE_OPENSSL 1 + +/* if AmiSSL is in use */ +#cmakedefine USE_AMISSL 1 + +/* if librtmp/rtmpdump is in use */ +#cmakedefine USE_LIBRTMP 1 + +/* if GSASL is in use */ +#cmakedefine USE_GSASL 1 + +/* if libuv is in use */ +#cmakedefine USE_LIBUV 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_UV_H 1 + +/* if libbacktrace is in use */ +#cmakedefine USE_BACKTRACE 1 + +/* Define to 1 if you do not want the OpenSSL configuration to be loaded + automatically */ +#cmakedefine CURL_DISABLE_OPENSSL_AUTO_LOAD_CONFIG 1 + +/* to enable NGHTTP2 */ +#cmakedefine USE_NGHTTP2 1 + +/* to enable NGTCP2 */ +#cmakedefine USE_NGTCP2 1 + +/* to enable NGHTTP3 */ +#cmakedefine USE_NGHTTP3 1 + +/* to enable quiche */ +#cmakedefine USE_QUICHE 1 + +/* to enable openssl + nghttp3 */ +#cmakedefine USE_OPENSSL_QUIC 1 + +/* to enable openssl + ngtcp2 + nghttp3 */ +#cmakedefine OPENSSL_QUIC_API2 1 + +/* Define to 1 if you have the quiche_conn_set_qlog_fd function. */ +#cmakedefine HAVE_QUICHE_CONN_SET_QLOG_FD 1 + +/* if Unix domain sockets are enabled */ +#cmakedefine USE_UNIX_SOCKETS 1 + +/* to enable SSPI support */ +#cmakedefine USE_WINDOWS_SSPI 1 + +/* to enable Windows SSL */ +#cmakedefine USE_SCHANNEL 1 + +/* if Watt-32 is in use */ +#cmakedefine USE_WATT32 1 + +/* enable multiple SSL backends */ +#cmakedefine CURL_WITH_MULTI_SSL 1 + +/* Number of bits in a file offset, on hosts where this is settable. */ +#cmakedefine _FILE_OFFSET_BITS ${_FILE_OFFSET_BITS} + +/* the signed version of size_t */ +#cmakedefine ssize_t ${ssize_t} + +/* Define to 1 if you have the mach_absolute_time function. */ +#cmakedefine HAVE_MACH_ABSOLUTE_TIME 1 + +/* to enable Windows IDN */ +#cmakedefine USE_WIN32_IDN 1 + +/* to enable Apple IDN */ +#cmakedefine USE_APPLE_IDN 1 + +/* to enable Apple OS-native certificate verification */ +#cmakedefine USE_APPLE_SECTRUST 1 + +/* Define to 1 if OpenSSL has the SSL_CTX_set_srp_username function. */ +#cmakedefine HAVE_OPENSSL_SRP 1 + +/* Define to 1 if GnuTLS has the gnutls_srp_verifier function. */ +#cmakedefine HAVE_GNUTLS_SRP 1 + +/* Define to 1 to enable TLS-SRP support. */ +#cmakedefine USE_TLS_SRP 1 + +/* Define to 1 to query for HTTPSRR when using DoH */ +#cmakedefine USE_HTTPSRR 1 + +/* if ECH support is available */ +#cmakedefine USE_ECH 1 + +/* Define to 1 if you have the wolfSSL_CTX_GenerateEchConfig function. */ +#cmakedefine HAVE_WOLFSSL_CTX_GENERATEECHCONFIG 1 + +/* Define to 1 if you have the SSL_set1_ech_config_list function. */ +#cmakedefine HAVE_SSL_SET1_ECH_CONFIG_LIST 1 + +/* Define to 1 if OpenSSL has the DES_ecb_encrypt function. */ +#cmakedefine HAVE_DES_ECB_ENCRYPT 1 diff --git a/vendor/hydra/vendor/curl/lib/curl_ctype.h b/vendor/hydra/vendor/curl/lib/curl_ctype.h index 48c3c37c..153a8f9c 100644 --- a/vendor/hydra/vendor/curl/lib/curl_ctype.h +++ b/vendor/hydra/vendor/curl/lib/curl_ctype.h @@ -25,17 +25,17 @@ ***************************************************************************/ #define ISLOWHEXALHA(x) (((x) >= 'a') && ((x) <= 'f')) -#define ISUPHEXALHA(x) (((x) >= 'A') && ((x) <= 'F')) +#define ISUPHEXALHA(x) (((x) >= 'A') && ((x) <= 'F')) #define ISLOWCNTRL(x) ((unsigned char)(x) <= 0x1f) -#define IS7F(x) ((x) == 0x7f) +#define IS7F(x) ((x) == 0x7f) #define ISLOWPRINT(x) (((x) >= 9) && ((x) <= 0x0d)) #define ISPRINT(x) (ISLOWPRINT(x) || (((x) >= ' ') && ((x) <= 0x7e))) #define ISGRAPH(x) (ISLOWPRINT(x) || (((x) > ' ') && ((x) <= 0x7e))) -#define ISCNTRL(x) (ISLOWCNTRL(x) || IS7F(x)) -#define ISALPHA(x) (ISLOWER(x) || ISUPPER(x)) +#define ISCNTRL(x) (ISLOWCNTRL(x) || IS7F(x)) +#define ISALPHA(x) (ISLOWER(x) || ISUPPER(x)) #define ISXDIGIT(x) (ISDIGIT(x) || ISLOWHEXALHA(x) || ISUPHEXALHA(x)) #define ISODIGIT(x) (((x) >= '0') && ((x) <= '7')) #define ISALNUM(x) (ISDIGIT(x) || ISLOWER(x) || ISUPPER(x)) diff --git a/vendor/hydra/vendor/curl/lib/curl_endian.c b/vendor/hydra/vendor/curl/lib/curl_endian.c index d982e312..864b411b 100644 --- a/vendor/hydra/vendor/curl/lib/curl_endian.c +++ b/vendor/hydra/vendor/curl/lib/curl_endian.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #include "curl_endian.h" diff --git a/vendor/hydra/vendor/curl/lib/curl_fnmatch.c b/vendor/hydra/vendor/curl/lib/curl_fnmatch.c index 66b9739f..8e35edee 100644 --- a/vendor/hydra/vendor/curl/lib/curl_fnmatch.c +++ b/vendor/hydra/vendor/curl/lib/curl_fnmatch.c @@ -21,16 +21,11 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" + #ifndef CURL_DISABLE_FTP -#include #include "curl_fnmatch.h" -#include "curl_memory.h" - -/* The last #include file should be: */ -#include "memdebug.h" #ifndef HAVE_FNMATCH @@ -243,7 +238,7 @@ static int setcharset(const unsigned char **p, unsigned char *charset) case CURLFNM_SCHS_RIGHTBRLEFTBR: if(c == ']') return SETCHARSET_OK; - state = CURLFNM_SCHS_DEFAULT; + state = CURLFNM_SCHS_DEFAULT; charset[c] = 1; (*p)++; break; @@ -361,7 +356,8 @@ int Curl_fnmatch(void *ptr, const char *pattern, const char *string) return loop((const unsigned char *)pattern, (const unsigned char *)string, 2); } -#else +#else /* HAVE_FNMATCH */ + #include /* * @unittest: 1307 @@ -384,7 +380,6 @@ int Curl_fnmatch(void *ptr, const char *pattern, const char *string) } /* not reached */ } +#endif /* !HAVE_FNMATCH */ -#endif - -#endif /* if FTP is disabled */ +#endif /* !CURL_DISABLE_FTP */ diff --git a/vendor/hydra/vendor/curl/lib/curl_fnmatch.h b/vendor/hydra/vendor/curl/lib/curl_fnmatch.h index b8c2a435..61d2a0c4 100644 --- a/vendor/hydra/vendor/curl/lib/curl_fnmatch.h +++ b/vendor/hydra/vendor/curl/lib/curl_fnmatch.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #define CURL_FNMATCH_MATCH 0 #define CURL_FNMATCH_NOMATCH 1 #define CURL_FNMATCH_FAIL 2 diff --git a/vendor/hydra/vendor/curl/lib/curl_fopen.c b/vendor/hydra/vendor/curl/lib/curl_fopen.c index c41cff21..9559c0d0 100644 --- a/vendor/hydra/vendor/curl/lib/curl_fopen.c +++ b/vendor/hydra/vendor/curl/lib/curl_fopen.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #if !defined(CURL_DISABLE_COOKIES) || !defined(CURL_DISABLE_ALTSVC) || \ @@ -31,10 +30,6 @@ #include "rand.h" #include "curl_fopen.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* The dirslash() function breaks a null-terminated pathname string into directory and filename components then returns the directory component up @@ -66,10 +61,10 @@ static char *dirslash(const char *path) n = strlen(path); if(n) { /* find the rightmost path separator, if any */ - while(n && !IS_SEP(path[n-1])) + while(n && !IS_SEP(path[n - 1])) --n; /* skip over all the path separators, if any */ - while(n && IS_SEP(path[n-1])) + while(n && IS_SEP(path[n - 1])) --n; } if(curlx_dyn_addn(&out, path, n)) @@ -93,25 +88,22 @@ CURLcode Curl_fopen(struct Curl_easy *data, const char *filename, CURLcode result = CURLE_WRITE_ERROR; unsigned char randbuf[41]; char *tempstore = NULL; +#ifndef _WIN32 struct_stat sb; +#endif int fd = -1; char *dir = NULL; *tempname = NULL; +#ifndef _WIN32 *fh = curlx_fopen(filename, FOPEN_WRITETEXT); if(!*fh) goto fail; - if( -#ifdef UNDER_CE - /* !checksrc! disable BANNEDFUNC 1 */ - stat(filename, &sb) == -1 -#else - fstat(fileno(*fh), &sb) == -1 -#endif - || !S_ISREG(sb.st_mode)) { + if(fstat(fileno(*fh), &sb) == -1 || !S_ISREG(sb.st_mode)) { return CURLE_OK; } curlx_fclose(*fh); +#endif *fh = NULL; result = Curl_rand_alnum(data, randbuf, sizeof(randbuf)); @@ -123,7 +115,7 @@ CURLcode Curl_fopen(struct Curl_easy *data, const char *filename, /* The temp filename should not end up too long for the target file system */ tempstore = curl_maprintf("%s%s.tmp", dir, randbuf); - free(dir); + curlx_free(dir); } if(!tempstore) { @@ -132,13 +124,16 @@ CURLcode Curl_fopen(struct Curl_easy *data, const char *filename, } result = CURLE_WRITE_ERROR; -#if (defined(ANDROID) || defined(__ANDROID__)) && \ +#ifdef _WIN32 + fd = curlx_open(tempstore, O_WRONLY | O_CREAT | O_EXCL, + S_IREAD | S_IWRITE); +#elif (defined(ANDROID) || defined(__ANDROID__)) && \ (defined(__i386__) || defined(__arm__)) fd = curlx_open(tempstore, O_WRONLY | O_CREAT | O_EXCL, - (mode_t)(0600 | sb.st_mode)); + (mode_t)(S_IRUSR | S_IWUSR | sb.st_mode)); #else fd = curlx_open(tempstore, O_WRONLY | O_CREAT | O_EXCL, - 0600 | sb.st_mode); + S_IRUSR | S_IWUSR | sb.st_mode); #endif if(fd == -1) goto fail; @@ -156,8 +151,8 @@ CURLcode Curl_fopen(struct Curl_easy *data, const char *filename, unlink(tempstore); } - free(tempstore); + curlx_free(tempstore); return result; } -#endif /* ! disabled */ +#endif /* !disabled */ diff --git a/vendor/hydra/vendor/curl/lib/curl_fopen.h b/vendor/hydra/vendor/curl/lib/curl_fopen.h index a3dc1382..bd402d44 100644 --- a/vendor/hydra/vendor/curl/lib/curl_fopen.h +++ b/vendor/hydra/vendor/curl/lib/curl_fopen.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curlx/fopen.h" CURLcode Curl_fopen(struct Curl_easy *data, const char *filename, diff --git a/vendor/hydra/vendor/curl/lib/curl_get_line.c b/vendor/hydra/vendor/curl/lib/curl_get_line.c index d5ab7b84..46c12879 100644 --- a/vendor/hydra/vendor/curl/lib/curl_get_line.c +++ b/vendor/hydra/vendor/curl/lib/curl_get_line.c @@ -21,19 +21,14 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #if !defined(CURL_DISABLE_COOKIES) || !defined(CURL_DISABLE_ALTSVC) || \ !defined(CURL_DISABLE_HSTS) || !defined(CURL_DISABLE_NETRC) #include "curl_get_line.h" -#include "curl_memory.h" -/* The last #include file should be: */ -#include "memdebug.h" -#define appendnl(b) \ - curlx_dyn_addn(buf, "\n", 1) +#define appendnl(b) curlx_dyn_addn(buf, "\n", 1) /* * Curl_get_line() returns only complete whole lines that end with newline. @@ -60,7 +55,7 @@ CURLcode Curl_get_line(struct dynbuf *buf, FILE *input, bool *eof) /* now check the full line */ rlen = curlx_dyn_len(buf); b = curlx_dyn_ptr(buf); - if(rlen && (b[rlen-1] == '\n')) + if(rlen && (b[rlen - 1] == '\n')) /* LF at end of the line */ return CURLE_OK; /* all good */ if(*eof) diff --git a/vendor/hydra/vendor/curl/lib/curl_get_line.h b/vendor/hydra/vendor/curl/lib/curl_get_line.h index 176d5f7a..6b90ac47 100644 --- a/vendor/hydra/vendor/curl/lib/curl_get_line.h +++ b/vendor/hydra/vendor/curl/lib/curl_get_line.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curlx/dynbuf.h" /* Curl_get_line() returns complete lines that end with a newline. */ diff --git a/vendor/hydra/vendor/curl/lib/curl_gethostname.c b/vendor/hydra/vendor/curl/lib/curl_gethostname.c index c3fa864e..f154c837 100644 --- a/vendor/hydra/vendor/curl/lib/curl_gethostname.c +++ b/vendor/hydra/vendor/curl/lib/curl_gethostname.c @@ -21,10 +21,10 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #include "curl_gethostname.h" +#include "curlx/strcopy.h" /* * Curl_gethostname() is a wrapper around gethostname() which allows @@ -60,9 +60,9 @@ int Curl_gethostname(char * const name, GETHOSTNAME_TYPE_ARG2 namelen) const char *force_hostname = getenv("CURL_GETHOSTNAME"); if(force_hostname) { if(strlen(force_hostname) < (size_t)namelen) - strcpy(name, force_hostname); + curlx_strcopy(name, namelen, force_hostname, strlen(force_hostname)); else - return 1; /* can't do it */ + return 1; /* cannot do it */ err = 0; } else { @@ -93,5 +93,4 @@ int Curl_gethostname(char * const name, GETHOSTNAME_TYPE_ARG2 namelen) return 0; #endif - } diff --git a/vendor/hydra/vendor/curl/lib/curl_gssapi.c b/vendor/hydra/vendor/curl/lib/curl_gssapi.c index 74128559..8c82f778 100644 --- a/vendor/hydra/vendor/curl/lib/curl_gssapi.c +++ b/vendor/hydra/vendor/curl/lib/curl_gssapi.c @@ -21,20 +21,18 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifdef HAVE_GSSAPI #include "curl_gssapi.h" -#include "sendf.h" +#include "curl_trc.h" +#include "curlx/strcopy.h" #ifdef DEBUGBUILD #if defined(HAVE_GSSGNU) || !defined(_WIN32) -/* To avoid memdebug macro replacement, wrap the name in parentheses to call - the original version. It is freed via the GSS API gss_release_buffer(). */ -#define Curl_gss_alloc (malloc) -#define Curl_gss_free (free) +#define Curl_gss_alloc malloc /* freed via the GSS API gss_release_buffer() */ +#define Curl_gss_free free /* pair of the above */ #define CURL_GSS_STUB /* For correctness this would be required for all platforms, not only Windows, but, as of v1.22.1, MIT Kerberos uses a special allocator only for Windows, @@ -51,10 +49,6 @@ #endif #endif /* DEBUGBUILD */ -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef __GNUC__ #define CURL_ALIGN8 __attribute__((aligned(8))) #else @@ -160,7 +154,7 @@ stub_gss_init_sec_context(OM_uint32 *min, } /* Server response, either D (RA==) or C (Qw==) */ - if(((char *) input_token->value)[0] == 'D') { + if(((char *)input_token->value)[0] == 'D') { /* Done */ switch(ctx->sent) { case STUB_GSS_KRB5: @@ -176,7 +170,7 @@ stub_gss_init_sec_context(OM_uint32 *min, } } - if(((char *) input_token->value)[0] != 'C') { + if(((char *)input_token->value)[0] != 'C') { /* We only support Done or Continue */ *min = STUB_GSS_SERVER_ERR; return GSS_S_FAILURE; @@ -208,7 +202,7 @@ stub_gss_init_sec_context(OM_uint32 *min, return GSS_S_FAILURE; } - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { *min = STUB_GSS_NO_MEMORY; return GSS_S_FAILURE; @@ -225,18 +219,18 @@ stub_gss_init_sec_context(OM_uint32 *min, else if(ctx->have_ntlm) ctx->sent = STUB_GSS_NTLM1; else { - free(ctx); + curlx_free(ctx); *min = STUB_GSS_NO_MECH; return GSS_S_FAILURE; } - strcpy(ctx->creds, creds); + curlx_strcopy(ctx->creds, sizeof(ctx->creds), creds, strlen(creds)); ctx->flags = req_flags; } token = Curl_gss_alloc(length); if(!token) { - free(ctx); + curlx_free(ctx); *min = STUB_GSS_NO_MEMORY; return GSS_S_FAILURE; } @@ -250,14 +244,14 @@ stub_gss_init_sec_context(OM_uint32 *min, &target_desc, &name_type); if(GSS_ERROR(major_status)) { Curl_gss_free(token); - free(ctx); + curlx_free(ctx); *min = STUB_GSS_NO_MEMORY; return GSS_S_FAILURE; } if(strlen(creds) + target_desc.length + 5 >= sizeof(ctx->creds)) { Curl_gss_free(token); - free(ctx); + curlx_free(ctx); *min = STUB_GSS_NO_MEMORY; return GSS_S_FAILURE; } @@ -273,7 +267,7 @@ stub_gss_init_sec_context(OM_uint32 *min, if(used >= length) { Curl_gss_free(token); - free(ctx); + curlx_free(ctx); *min = STUB_GSS_NO_MEMORY; return GSS_S_FAILURE; } @@ -308,7 +302,7 @@ stub_gss_delete_sec_context(OM_uint32 *min, return GSS_S_FAILURE; } - free(*context); + curlx_free(*context); *context = NULL; *min = 0; @@ -392,7 +386,8 @@ OM_uint32 Curl_gss_delete_sec_context(OM_uint32 *min, #define GSS_LOG_BUFFER_LEN 1024 static size_t display_gss_error(OM_uint32 status, int type, - char *buf, size_t len) { + char *buf, size_t len) +{ OM_uint32 maj_stat; OM_uint32 min_stat; OM_uint32 msg_ctx = 0; @@ -433,7 +428,7 @@ static size_t display_gss_error(OM_uint32 status, int type, void Curl_gss_log_error(struct Curl_easy *data, const char *prefix, OM_uint32 major, OM_uint32 minor) { - char buf[GSS_LOG_BUFFER_LEN]; + char buf[GSS_LOG_BUFFER_LEN] = ""; size_t len = 0; if(major != GSS_S_FAILURE) diff --git a/vendor/hydra/vendor/curl/lib/curl_gssapi.h b/vendor/hydra/vendor/curl/lib/curl_gssapi.h index 1a2bbabd..8c09c72c 100644 --- a/vendor/hydra/vendor/curl/lib/curl_gssapi.h +++ b/vendor/hydra/vendor/curl/lib/curl_gssapi.h @@ -23,16 +23,11 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" + #include "urldata.h" #ifdef HAVE_GSSAPI - -#ifdef GSS_C_CHANNEL_BOUND_FLAG /* MIT Kerberos 1.19+, missing from GNU GSS */ -#define CURL_GSSAPI_HAS_CHANNEL_BINDING -#endif - extern gss_OID_desc Curl_spnego_mech_oid; extern gss_OID_desc Curl_krb5_mech_oid; diff --git a/vendor/hydra/vendor/curl/lib/curl_hmac.h b/vendor/hydra/vendor/curl/lib/curl_hmac.h index 9675c6c5..4759ff6e 100644 --- a/vendor/hydra/vendor/curl/lib/curl_hmac.h +++ b/vendor/hydra/vendor/curl/lib/curl_hmac.h @@ -28,8 +28,6 @@ !defined(CURL_DISABLE_AWS) || !defined(CURL_DISABLE_DIGEST_AUTH) || \ defined(USE_LIBSSH2) || defined(USE_SSL) -#include - #define HMAC_MD5_LENGTH 16 typedef CURLcode (*HMAC_hinit)(void *context); @@ -48,7 +46,6 @@ struct HMAC_params { unsigned int resultlen; /* Result length (bytes). */ }; - /* HMAC computation context. */ struct HMAC_context { const struct HMAC_params *hash; /* Hash function definition. */ @@ -56,7 +53,6 @@ struct HMAC_context { void *hashctxt2; /* Hash function context 2. */ }; - /* Prototypes. */ struct HMAC_context *Curl_HMAC_init(const struct HMAC_params *hashparams, const unsigned char *key, diff --git a/vendor/hydra/vendor/curl/lib/curl_ldap.h b/vendor/hydra/vendor/curl/lib/curl_ldap.h index 8a1d807e..5ef32a5a 100644 --- a/vendor/hydra/vendor/curl/lib/curl_ldap.h +++ b/vendor/hydra/vendor/curl/lib/curl_ldap.h @@ -26,11 +26,12 @@ #ifndef CURL_DISABLE_LDAP extern const struct Curl_handler Curl_handler_ldap; -#if !defined(CURL_DISABLE_LDAPS) && \ - ((defined(USE_OPENLDAP) && defined(USE_SSL)) || \ - (!defined(USE_OPENLDAP) && defined(HAVE_LDAP_SSL))) +#if !defined(CURL_DISABLE_LDAPS) && \ + ((defined(USE_OPENLDAP) && defined(USE_SSL)) || \ + (!defined(USE_OPENLDAP) && defined(HAVE_LDAP_SSL))) extern const struct Curl_handler Curl_handler_ldaps; #endif +void Curl_ldap_version(char *buf, size_t bufsz); #endif #endif /* HEADER_CURL_LDAP_H */ diff --git a/vendor/hydra/vendor/curl/lib/curl_md4.h b/vendor/hydra/vendor/curl/lib/curl_md4.h index f103d38b..05d16249 100644 --- a/vendor/hydra/vendor/curl/lib/curl_md4.h +++ b/vendor/hydra/vendor/curl/lib/curl_md4.h @@ -23,9 +23,7 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include #ifdef USE_CURL_NTLM_CORE diff --git a/vendor/hydra/vendor/curl/lib/curl_memory.h b/vendor/hydra/vendor/curl/lib/curl_memory.h deleted file mode 100644 index 7793bb63..00000000 --- a/vendor/hydra/vendor/curl/lib/curl_memory.h +++ /dev/null @@ -1,89 +0,0 @@ -#ifndef HEADER_CURL_MEMORY_H -#define HEADER_CURL_MEMORY_H -/*************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ - * \___|\___/|_| \_\_____| - * - * Copyright (C) Daniel Stenberg, , et al. - * - * This software is licensed as described in the file COPYING, which - * you should have received as part of this distribution. The terms - * are also available at https://curl.se/docs/copyright.html. - * - * You may opt to use, copy, modify, merge, publish, distribute and/or sell - * copies of the Software, and permit persons to whom the Software is - * furnished to do so, under the terms of the COPYING file. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - * SPDX-License-Identifier: curl - * - ***************************************************************************/ - -/* - * Nasty internal details ahead... - * - * File curl_memory.h must be included by _all_ *.c source files - * that use memory related functions strdup, malloc, calloc, realloc - * or free, and given source file is used to build libcurl library. - * It should be included immediately before memdebug.h as the last files - * included to avoid undesired interaction with other memory function - * headers in dependent libraries. - * - * There is nearly no exception to above rule. All libcurl source - * files in 'lib' subdirectory as well as those living deep inside - * 'packages' subdirectories and linked together in order to build - * libcurl library shall follow it. - * - * File lib/strdup.c is an exception, given that it provides a strdup - * clone implementation while using malloc. Extra care needed inside - * this one. - * - * The need for curl_memory.h inclusion is due to libcurl's feature - * of allowing library user to provide memory replacement functions, - * memory callbacks, at runtime with curl_global_init_mem() - * - * Any *.c source file used to build libcurl library that does not - * include curl_memory.h and uses any memory function of the five - * mentioned above will compile without any indication, but it will - * trigger weird memory related issues at runtime. - * - */ - -#ifndef CURLDEBUG - -/* - * libcurl's 'memory tracking' system defines strdup, malloc, calloc, - * realloc and free, along with others, in memdebug.h in a different - * way although still using memory callbacks forward declared above. - * When using the 'memory tracking' system (CURLDEBUG defined) we do - * not define here the five memory functions given that definitions - * from memdebug.h are the ones that shall be used. - */ - -#undef strdup -#define strdup(ptr) Curl_cstrdup(ptr) -#undef malloc -#define malloc(size) Curl_cmalloc(size) -#undef calloc -#define calloc(nbelem,size) Curl_ccalloc(nbelem, size) -#undef realloc -#define realloc(ptr,size) Curl_crealloc(ptr, size) -#undef free -#define free(ptr) Curl_cfree(ptr) - -#ifdef _WIN32 -#undef Curl_tcsdup -#ifdef UNICODE -#define Curl_tcsdup(ptr) Curl_wcsdup(ptr) -#else -#define Curl_tcsdup(ptr) Curl_cstrdup(ptr) -#endif -#endif /* _WIN32 */ - -#endif /* CURLDEBUG */ -#endif /* HEADER_CURL_MEMORY_H */ diff --git a/vendor/hydra/vendor/curl/lib/curl_memrchr.c b/vendor/hydra/vendor/curl/lib/curl_memrchr.c index 5b6a39c0..59ee176b 100644 --- a/vendor/hydra/vendor/curl/lib/curl_memrchr.c +++ b/vendor/hydra/vendor/curl/lib/curl_memrchr.c @@ -21,16 +21,9 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include - #include "curl_memrchr.h" -#include "curl_memory.h" - -/* The last #include file should be: */ -#include "memdebug.h" #ifndef HAVE_MEMRCHR /* @@ -41,9 +34,7 @@ * backwards from the end of the n bytes pointed to by s instead of forward * from the beginning. */ - -void * -Curl_memrchr(const void *s, int c, size_t n) +void *Curl_memrchr(const void *s, int c, size_t n) { if(n > 0) { const unsigned char *p = s; diff --git a/vendor/hydra/vendor/curl/lib/curl_memrchr.h b/vendor/hydra/vendor/curl/lib/curl_memrchr.h index 3c7dda96..248368b2 100644 --- a/vendor/hydra/vendor/curl/lib/curl_memrchr.h +++ b/vendor/hydra/vendor/curl/lib/curl_memrchr.h @@ -23,19 +23,17 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifdef HAVE_MEMRCHR -#include #ifdef HAVE_STRINGS_H # include #endif #else /* HAVE_MEMRCHR */ void *Curl_memrchr(const void *s, int c, size_t n); -#define memrchr(x,y,z) Curl_memrchr((x),(y),(z)) +#define memrchr(x, y, z) Curl_memrchr(x, y, z) #endif /* HAVE_MEMRCHR */ diff --git a/vendor/hydra/vendor/curl/lib/curl_ntlm_core.c b/vendor/hydra/vendor/curl/lib/curl_ntlm_core.c index 9c5e8047..2f4f7c3a 100644 --- a/vendor/hydra/vendor/curl/lib/curl_ntlm_core.c +++ b/vendor/hydra/vendor/curl/lib/curl_ntlm_core.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifdef USE_CURL_NTLM_CORE @@ -53,7 +52,7 @@ #ifdef USE_MBEDTLS #include #if MBEDTLS_VERSION_NUMBER < 0x03020000 - #error "mbedTLS 3.2.0 or later required" +#error "mbedTLS 3.2.0 or later required" #endif #endif @@ -69,8 +68,6 @@ #ifdef USE_OPENSSL # include -# include -# include # ifdef OPENSSL_IS_AWSLC /* for versions 1.2.0 to 1.30.1 */ # define DES_set_key_unchecked (void)DES_set_key # endif @@ -78,16 +75,22 @@ #else # include # include -# include -# include +# include # ifdef OPENSSL_COEXIST -# define DES_key_schedule WOLFSSL_DES_key_schedule -# define DES_cblock WOLFSSL_DES_cblock -# define DES_set_odd_parity wolfSSL_DES_set_odd_parity -# define DES_set_key wolfSSL_DES_set_key +# define DES_key_schedule WOLFSSL_DES_key_schedule +# define DES_cblock WOLFSSL_DES_cblock +# define DES_set_odd_parity wolfSSL_DES_set_odd_parity +# define DES_set_key wolfSSL_DES_set_key # define DES_set_key_unchecked wolfSSL_DES_set_key_unchecked -# define DES_ecb_encrypt wolfSSL_DES_ecb_encrypt -# define DESKEY(x) ((WOLFSSL_DES_key_schedule *)(x)) +# define DES_ecb_encrypt wolfSSL_DES_ecb_encrypt +# define DESKEY(x) ((WOLFSSL_DES_key_schedule *)(x)) + +# if defined(LIBWOLFSSL_VERSION_HEX) && \ + (LIBWOLFSSL_VERSION_HEX >= 0x05007006) +# define DES_ENCRYPT WC_DES_ENCRYPT +# define DES_DECRYPT WC_DES_DECRYPT +# endif + # else # define DESKEY(x) &x # endif @@ -118,13 +121,8 @@ #include "curl_ntlm_core.h" #include "curl_md5.h" #include "curl_hmac.h" -#include "curlx/warnless.h" -#include "curl_endian.h" #include "curl_md4.h" - -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" +#include "vauth/vauth.h" #ifdef USE_CURL_DES_SET_ODD_PARITY /* @@ -165,8 +163,8 @@ static void curl_des_set_odd_parity(unsigned char *bytes, size_t len) #endif /* USE_CURL_DES_SET_ODD_PARITY */ /* -* Turns a 56-bit key into being 64-bit wide. -*/ + * Turns a 56-bit key into being 64-bit wide. + */ static void extend_key_56_to_64(const unsigned char *key_56, char *key) { key[0] = (char)key_56[0]; @@ -190,7 +188,7 @@ static void setup_des_key(const unsigned char *key_56, DES_cblock key; /* Expand the 56-bit key to 64 bits */ - extend_key_56_to_64(key_56, (char *) &key); + extend_key_56_to_64(key_56, (char *)&key); /* Set the key parity to odd */ DES_set_odd_parity(&key); @@ -201,8 +199,7 @@ static void setup_des_key(const unsigned char *key_56, #elif defined(USE_GNUTLS) -static void setup_des_key(const unsigned char *key_56, - struct des_ctx *des) +static void setup_des_key(const unsigned char *key_56, struct des_ctx *des) { char key[8]; @@ -210,10 +207,10 @@ static void setup_des_key(const unsigned char *key_56, extend_key_56_to_64(key_56, key); /* Set the key parity to odd */ - curl_des_set_odd_parity((unsigned char *) key, sizeof(key)); + curl_des_set_odd_parity((unsigned char *)key, sizeof(key)); /* Set the key */ - des_set_key(des, (const uint8_t *) key); + des_set_key(des, (const uint8_t *)key); } #elif defined(USE_MBEDTLS_DES) @@ -228,11 +225,11 @@ static bool encrypt_des(const unsigned char *in, unsigned char *out, extend_key_56_to_64(key_56, key); /* Set the key parity to odd */ - mbedtls_des_key_set_parity((unsigned char *) key); + mbedtls_des_key_set_parity((unsigned char *)key); /* Perform the encryption */ mbedtls_des_init(&ctx); - mbedtls_des_setkey_enc(&ctx, (unsigned char *) key); + mbedtls_des_setkey_enc(&ctx, (unsigned char *)key); return mbedtls_des_crypt_ecb(&ctx, in, out) == 0; } @@ -252,10 +249,10 @@ static bool encrypt_des(const unsigned char *in, unsigned char *out, extend_key_56_to_64(key_56, ctl.Crypto_Key); /* Set the key parity to odd */ - curl_des_set_odd_parity((unsigned char *) ctl.Crypto_Key, ctl.Data_Len); + curl_des_set_odd_parity((unsigned char *)ctl.Crypto_Key, ctl.Data_Len); /* Perform the encryption */ - _CIPHER((_SPCPTR *) &out, &ctl, (_SPCPTR *) &in); + _CIPHER((_SPCPTR *)&out, &ctl, (_SPCPTR *)&in); return TRUE; } @@ -290,10 +287,10 @@ static bool encrypt_des(const unsigned char *in, unsigned char *out, extend_key_56_to_64(key_56, blob.key); /* Set the key parity to odd */ - curl_des_set_odd_parity((unsigned char *) blob.key, sizeof(blob.key)); + curl_des_set_odd_parity((unsigned char *)blob.key, sizeof(blob.key)); /* Import the key */ - if(!CryptImportKey(hprov, (BYTE *) &blob, sizeof(blob), 0, 0, &hkey)) { + if(!CryptImportKey(hprov, (BYTE *)&blob, sizeof(blob), 0, 0, &hkey)) { CryptReleaseContext(hprov, 0); return FALSE; @@ -312,11 +309,11 @@ static bool encrypt_des(const unsigned char *in, unsigned char *out, #endif /* USE_WIN32_CRYPTO */ - /* - * takes a 21 byte array and treats it as 3 56-bit DES keys. The - * 8 byte plaintext is encrypted with each key and the resulting 24 - * bytes are stored in the results array. - */ +/* + * takes a 21 byte array and treats it as 3 56-bit DES keys. The + * 8 byte plaintext is encrypted with each key and the resulting 24 + * bytes are stored in the results array. + */ void Curl_ntlm_core_lm_resp(const unsigned char *keys, const unsigned char *plaintext, unsigned char *results) @@ -325,16 +322,16 @@ void Curl_ntlm_core_lm_resp(const unsigned char *keys, DES_key_schedule ks; setup_des_key(keys, DESKEY(ks)); - DES_ecb_encrypt((DES_cblock*)CURL_UNCONST(plaintext), - (DES_cblock*)results, DESKEY(ks), DES_ENCRYPT); + DES_ecb_encrypt((DES_cblock *)CURL_UNCONST(plaintext), + (DES_cblock *)results, DESKEY(ks), DES_ENCRYPT); setup_des_key(keys + 7, DESKEY(ks)); - DES_ecb_encrypt((DES_cblock*)CURL_UNCONST(plaintext), - (DES_cblock*)(results + 8), DESKEY(ks), DES_ENCRYPT); + DES_ecb_encrypt((DES_cblock *)CURL_UNCONST(plaintext), + (DES_cblock *)(results + 8), DESKEY(ks), DES_ENCRYPT); setup_des_key(keys + 14, DESKEY(ks)); - DES_ecb_encrypt((DES_cblock*)CURL_UNCONST(plaintext), - (DES_cblock*)(results + 16), DESKEY(ks), DES_ENCRYPT); + DES_ecb_encrypt((DES_cblock *)CURL_UNCONST(plaintext), + (DES_cblock *)(results + 16), DESKEY(ks), DES_ENCRYPT); #elif defined(USE_GNUTLS) struct des_ctx des; setup_des_key(keys, &des); @@ -435,9 +432,9 @@ CURLcode Curl_ntlm_core_mk_nt_hash(const char *password, size_t len = strlen(password); unsigned char *pw; CURLcode result; - if(len > SIZE_MAX/2) /* avoid integer overflow */ + if(len > SIZE_MAX / 2) /* avoid integer overflow */ return CURLE_OUT_OF_MEMORY; - pw = len ? malloc(len * 2) : (unsigned char *)strdup(""); + pw = len ? curlx_malloc(len * 2) : (unsigned char *)curlx_strdup(""); if(!pw) return CURLE_OUT_OF_MEMORY; @@ -448,7 +445,7 @@ CURLcode Curl_ntlm_core_mk_nt_hash(const char *password, if(!result) memset(ntbuffer + 16, 0, 21 - 16); - free(pw); + curlx_free(pw); return result; } @@ -456,7 +453,7 @@ CURLcode Curl_ntlm_core_mk_nt_hash(const char *password, #ifndef USE_WINDOWS_SSPI #define NTLMv2_BLOB_SIGNATURE "\x01\x01\x00\x00" -#define NTLMv2_BLOB_LEN (44 -16 + ntlm->target_info_len + 4) +#define NTLMv2_BLOB_LEN (44 - 16 + ntlm->target_info_len + 4) /* Timestamp in tenths of a microsecond since January 1, 1601 00:00:00 UTC. */ struct ms_filetime { @@ -469,20 +466,20 @@ static void time2filetime(struct ms_filetime *ft, time_t t) { #if SIZEOF_TIME_T > 4 t = (t + (curl_off_t)11644473600) * 10000000; - ft->dwLowDateTime = (unsigned int) (t & 0xFFFFFFFF); - ft->dwHighDateTime = (unsigned int) (t >> 32); + ft->dwLowDateTime = (unsigned int)(t & 0xFFFFFFFF); + ft->dwHighDateTime = (unsigned int)(t >> 32); #else unsigned int r, s; unsigned int i; - ft->dwLowDateTime = (unsigned int)t & 0xFFFFFFFF; + ft->dwLowDateTime = (unsigned int)(t & 0xFFFFFFFF); ft->dwHighDateTime = 0; -# ifndef HAVE_TIME_T_UNSIGNED +#ifndef HAVE_TIME_T_UNSIGNED /* Extend sign if needed. */ if(ft->dwLowDateTime & 0x80000000) ft->dwHighDateTime = ~(unsigned int)0; -# endif +#endif /* Bias seconds to Jan 1, 1601. 134774 days = 11644473600 seconds = 0x2B6109100 */ @@ -525,7 +522,7 @@ CURLcode Curl_ntlm_core_mk_ntlmv2_hash(const char *user, size_t userlen, return CURLE_OUT_OF_MEMORY; identity_len = (userlen + domlen) * 2; - identity = malloc(identity_len + 1); + identity = curlx_malloc(identity_len + 1); if(!identity) return CURLE_OUT_OF_MEMORY; @@ -535,7 +532,7 @@ CURLcode Curl_ntlm_core_mk_ntlmv2_hash(const char *user, size_t userlen, result = Curl_hmacit(&Curl_HMAC_MD5, ntlmhash, 16, identity, identity_len, ntlmv2hash); - free(identity); + curlx_free(identity); return result; } @@ -563,20 +560,20 @@ CURLcode Curl_ntlm_core_mk_ntlmv2_resp(unsigned char *ntlmv2hash, unsigned char **ntresp, unsigned int *ntresp_len) { -/* NTLMv2 response structure : ------------------------------------------------------------------------------- -0 HMAC MD5 16 bytes -------BLOB-------------------------------------------------------------------- -16 Signature 0x01010000 -20 Reserved long (0x00000000) -24 Timestamp LE, 64-bit signed value representing the number of - tenths of a microsecond since January 1, 1601. -32 Client Nonce 8 bytes -40 Unknown 4 bytes -44 Target Info N bytes (from the type-2 message) -44+N Unknown 4 bytes ------------------------------------------------------------------------------- -*/ + /* NTLMv2 response structure : + ----------------------------------------------------------------------------- + 0 HMAC MD5 16 bytes + ------BLOB------------------------------------------------------------------- + 16 Signature 0x01010000 + 20 Reserved long (0x00000000) + 24 Timestamp LE, 64-bit signed value representing the number of + tenths of a microsecond since January 1, 1601. + 32 Client Nonce 8 bytes + 40 Unknown 4 bytes + 44 Target Info N bytes (from the type-2 message) + 44+N Unknown 4 bytes + ----------------------------------------------------------------------------- + */ unsigned int len = 0; unsigned char *ptr = NULL; @@ -589,7 +586,7 @@ CURLcode Curl_ntlm_core_mk_ntlmv2_resp(unsigned char *ntlmv2hash, #ifdef DEBUGBUILD char *force_timestamp = getenv("CURL_FORCETIME"); if(force_timestamp) - time2filetime(&tw, (time_t) 0); + time2filetime(&tw, (time_t)0); else #endif time2filetime(&tw, time(NULL)); @@ -598,7 +595,7 @@ CURLcode Curl_ntlm_core_mk_ntlmv2_resp(unsigned char *ntlmv2hash, len = HMAC_MD5_LENGTH + NTLMv2_BLOB_LEN; /* Allocate the response */ - ptr = calloc(1, len); + ptr = curlx_calloc(1, len); if(!ptr) return CURLE_OUT_OF_MEMORY; @@ -622,7 +619,7 @@ CURLcode Curl_ntlm_core_mk_ntlmv2_resp(unsigned char *ntlmv2hash, result = Curl_hmacit(&Curl_HMAC_MD5, ntlmv2hash, HMAC_MD5_LENGTH, ptr + 8, NTLMv2_BLOB_LEN + 8, hmac_output); if(result) { - free(ptr); + curlx_free(ptr); return result; } @@ -650,10 +647,10 @@ CURLcode Curl_ntlm_core_mk_ntlmv2_resp(unsigned char *ntlmv2hash, * * Returns CURLE_OK on success. */ -CURLcode Curl_ntlm_core_mk_lmv2_resp(unsigned char *ntlmv2hash, - unsigned char *challenge_client, - unsigned char *challenge_server, - unsigned char *lmresp) +CURLcode Curl_ntlm_core_mk_lmv2_resp(unsigned char *ntlmv2hash, + unsigned char *challenge_client, + unsigned char *challenge_server, + unsigned char *lmresp) { unsigned char data[16]; unsigned char hmac_output[16]; diff --git a/vendor/hydra/vendor/curl/lib/curl_ntlm_core.h b/vendor/hydra/vendor/curl/lib/curl_ntlm_core.h index 584f4a17..947b8369 100644 --- a/vendor/hydra/vendor/curl/lib/curl_ntlm_core.h +++ b/vendor/hydra/vendor/curl/lib/curl_ntlm_core.h @@ -23,13 +23,10 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifdef USE_CURL_NTLM_CORE -#include "vauth/vauth.h" - struct ntlmdata; /* Helpers to generate function byte arguments in little endian order */ @@ -58,16 +55,16 @@ CURLcode Curl_ntlm_core_mk_ntlmv2_hash(const char *user, size_t userlen, unsigned char *ntlmhash, unsigned char *ntlmv2hash); -CURLcode Curl_ntlm_core_mk_ntlmv2_resp(unsigned char *ntlmv2hash, - unsigned char *challenge_client, - struct ntlmdata *ntlm, - unsigned char **ntresp, - unsigned int *ntresp_len); +CURLcode Curl_ntlm_core_mk_ntlmv2_resp(unsigned char *ntlmv2hash, + unsigned char *challenge_client, + struct ntlmdata *ntlm, + unsigned char **ntresp, + unsigned int *ntresp_len); -CURLcode Curl_ntlm_core_mk_lmv2_resp(unsigned char *ntlmv2hash, - unsigned char *challenge_client, - unsigned char *challenge_server, - unsigned char *lmresp); +CURLcode Curl_ntlm_core_mk_lmv2_resp(unsigned char *ntlmv2hash, + unsigned char *challenge_client, + unsigned char *challenge_server, + unsigned char *lmresp); #endif /* !USE_WINDOWS_SSPI */ diff --git a/vendor/hydra/vendor/curl/lib/curl_range.c b/vendor/hydra/vendor/curl/lib/curl_range.c index e9620a29..14218f1e 100644 --- a/vendor/hydra/vendor/curl/lib/curl_range.c +++ b/vendor/hydra/vendor/curl/lib/curl_range.c @@ -21,20 +21,19 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include + #include "curl_range.h" -#include "sendf.h" +#include "curl_trc.h" #include "curlx/strparse.h" /* Only include this function if one or more of FTP, FILE are enabled. */ #if !defined(CURL_DISABLE_FTP) || !defined(CURL_DISABLE_FILE) - /* - Check if this is a range download, and if so, set the internal variables - properly. - */ +/* + Check if this is a range download, and if so, set the internal variables + properly. +*/ CURLcode Curl_range(struct Curl_easy *data) { if(data->state.use_range && data->state.range) { diff --git a/vendor/hydra/vendor/curl/lib/curl_range.h b/vendor/hydra/vendor/curl/lib/curl_range.h index 77679e2b..97354677 100644 --- a/vendor/hydra/vendor/curl/lib/curl_range.h +++ b/vendor/hydra/vendor/curl/lib/curl_range.h @@ -23,8 +23,8 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" + #include "urldata.h" CURLcode Curl_range(struct Curl_easy *data); diff --git a/vendor/hydra/vendor/curl/lib/curl_rtmp.c b/vendor/hydra/vendor/curl/lib/curl_rtmp.c index 7006ca5e..98816f82 100644 --- a/vendor/hydra/vendor/curl/lib/curl_rtmp.c +++ b/vendor/hydra/vendor/curl/lib/curl_rtmp.c @@ -22,7 +22,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifdef USE_LIBRTMP @@ -30,27 +29,20 @@ #include "curl_rtmp.h" #include "urldata.h" #include "url.h" -#include "curlx/nonblock.h" /* for curlx_nonblock */ +#include "curlx/nonblock.h" #include "progress.h" /* for Curl_pgrsSetUploadSize */ #include "transfer.h" -#include "curlx/warnless.h" -#include -#include +#include "bufref.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" +#include -#if defined(_WIN32) && !defined(USE_LWIPSOCK) -#define setsockopt(a,b,c,d,e) (setsockopt)(a,b,c,(const char *)d,(int)e) -#define SET_RCVTIMEO(tv,s) int tv = s*1000 -#elif defined(LWIP_SO_SNDRCVTIMEO_NONSTANDARD) -#define SET_RCVTIMEO(tv,s) int tv = s*1000 +#if defined(USE_WINSOCK) || defined(LWIP_SO_SNDRCVTIMEO_NONSTANDARD) +#define SET_RCVTIMEO(tv, s) int tv = s * 1000 #else -#define SET_RCVTIMEO(tv,s) struct timeval tv = {s,0} +#define SET_RCVTIMEO(tv, s) struct timeval tv = { s, 0 } #endif -#define DEF_BUFTIME (2*60*60*1000) /* 2 hours */ +#define DEF_BUFTIME (2 * 60 * 60 * 1000) /* 2 hours */ /* meta key for storing RTMP* at connection */ #define CURL_META_RTMP_CONN "meta:proto:rtmp:conn" @@ -68,7 +60,7 @@ static Curl_recv rtmp_recv; static Curl_send rtmp_send; /* - * RTMP protocol handler.h, based on https://rtmpdump.mplayerhq.hu + * RTMP protocol handler.h, based on https://rtmpdump.mplayerhq.hu/ */ const struct Curl_handler Curl_handler_rtmp = { @@ -240,10 +232,9 @@ static CURLcode rtmp_setup_connection(struct Curl_easy *data, RTMP_Init(r); RTMP_SetBufferMS(r, DEF_BUFTIME); - if(!RTMP_SetupURL(r, data->state.url)) { - RTMP_Free(r); + if(!RTMP_SetupURL(r, CURL_UNCONST(Curl_bufref_ptr(&data->state.url)))) + /* rtmp_conn_dtor() performs the cleanup */ return CURLE_URL_MALFORMAT; - } return CURLE_OK; } @@ -256,6 +247,11 @@ static CURLcode rtmp_connect(struct Curl_easy *data, bool *done) if(!r) return CURLE_FAILED_INIT; + if(conn->sock[FIRSTSOCKET] > INT_MAX) { + /* The socket value is invalid for rtmp. */ + return CURLE_FAILED_INIT; + } + r->m_sb.sb_socket = (int)conn->sock[FIRSTSOCKET]; /* We have to know if it is a write before we send the @@ -331,15 +327,15 @@ static CURLcode rtmp_recv(struct Curl_easy *data, int sockindex, char *buf, struct connectdata *conn = data->conn; RTMP *r = Curl_conn_meta_get(conn, CURL_META_RTMP_CONN); CURLcode result = CURLE_OK; - ssize_t nread; + ssize_t rv; (void)sockindex; *pnread = 0; if(!r) return CURLE_FAILED_INIT; - nread = RTMP_Read(r, buf, curlx_uztosi(len)); - if(nread < 0) { + rv = RTMP_Read(r, buf, curlx_uztosi(len)); + if(!curlx_sztouz(rv, pnread)) { if(r->m_read.status == RTMP_READ_COMPLETE || r->m_read.status == RTMP_READ_EOF) { data->req.size = data->req.bytecount; @@ -347,19 +343,17 @@ static CURLcode rtmp_recv(struct Curl_easy *data, int sockindex, char *buf, else result = CURLE_RECV_ERROR; } - else - *pnread = (size_t)nread; return result; } static CURLcode rtmp_send(struct Curl_easy *data, int sockindex, - const void *buf, size_t len, bool eos, + const uint8_t *buf, size_t len, bool eos, size_t *pnwritten) { struct connectdata *conn = data->conn; RTMP *r = Curl_conn_meta_get(conn, CURL_META_RTMP_CONN); - ssize_t nwritten; + ssize_t rv; (void)sockindex; (void)eos; @@ -367,11 +361,10 @@ static CURLcode rtmp_send(struct Curl_easy *data, int sockindex, if(!r) return CURLE_FAILED_INIT; - nwritten = RTMP_Write(r, (const char *)buf, curlx_uztosi(len)); - if(nwritten < 0) + rv = RTMP_Write(r, (const char *)buf, curlx_uztosi(len)); + if(!curlx_sztouz(rv, pnwritten)) return CURLE_SEND_ERROR; - *pnwritten = (size_t)nwritten; return CURLE_OK; } @@ -390,4 +383,4 @@ void Curl_rtmp_version(char *version, size_t len) suff); } -#endif /* USE_LIBRTMP */ +#endif /* USE_LIBRTMP */ diff --git a/vendor/hydra/vendor/curl/lib/curl_sasl.c b/vendor/hydra/vendor/curl/lib/curl_sasl.c index 043786f7..123c1c14 100644 --- a/vendor/hydra/vendor/curl/lib/curl_sasl.c +++ b/vendor/hydra/vendor/curl/lib/curl_sasl.c @@ -32,28 +32,18 @@ * Draft LOGIN SASL Mechanism * ***************************************************************************/ - #include "curl_setup.h" #if !defined(CURL_DISABLE_IMAP) || !defined(CURL_DISABLE_SMTP) || \ !defined(CURL_DISABLE_POP3) || \ (!defined(CURL_DISABLE_LDAP) && defined(USE_OPENLDAP)) -#include #include "urldata.h" - #include "curlx/base64.h" #include "vauth/vauth.h" #include "cfilters.h" -#include "vtls/vtls.h" -#include "curl_hmac.h" #include "curl_sasl.h" -#include "curlx/warnless.h" -#include "sendf.h" - -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" +#include "curl_trc.h" /* Supported mechanisms */ static const struct { @@ -96,7 +86,7 @@ unsigned short Curl_sasl_decode_mech(const char *ptr, size_t maxlen, for(i = 0; mechtable[i].name; i++) { if(maxlen >= mechtable[i].len && - !memcmp(ptr, mechtable[i].name, mechtable[i].len)) { + curl_strnequal(ptr, mechtable[i].name, mechtable[i].len)) { if(len) *len = mechtable[i].len; @@ -239,7 +229,7 @@ static CURLcode get_server_message(struct SASL *sasl, struct Curl_easy *data, if(!result && (sasl->params->flags & SASL_FLAG_BASE64)) { unsigned char *msg; size_t msglen; - const char *serverdata = (const char *) Curl_bufref_ptr(out); + const char *serverdata = Curl_bufref_ptr(out); if(!*serverdata || *serverdata == '=') Curl_bufref_set(out, NULL, 0, NULL); @@ -267,7 +257,7 @@ static CURLcode build_message(struct SASL *sasl, struct bufref *msg) char *base64; size_t base64len; - result = curlx_base64_encode((const char *) Curl_bufref_ptr(msg), + result = curlx_base64_encode(Curl_bufref_uptr(msg), Curl_bufref_len(msg), &base64, &base64len); if(!result) Curl_bufref_set(msg, base64, base64len, curl_free); @@ -285,7 +275,7 @@ static CURLcode build_message(struct SASL *sasl, struct bufref *msg) bool Curl_sasl_can_authenticate(struct SASL *sasl, struct Curl_easy *data) { /* Have credentials been provided? */ - if(data->state.aptr.user) + if(data->conn->user[0]) return TRUE; /* EXTERNAL can authenticate without a username and/or password */ @@ -298,7 +288,6 @@ bool Curl_sasl_can_authenticate(struct SASL *sasl, struct Curl_easy *data) struct sasl_ctx { struct SASL *sasl; struct connectdata *conn; - const char *user; unsigned short enabledmechs; const char *mech; saslstate state1; @@ -324,8 +313,7 @@ static bool sasl_choose_external(struct Curl_easy *data, struct sasl_ctx *sctx) #ifdef USE_KERBEROS5 static bool sasl_choose_krb5(struct Curl_easy *data, struct sasl_ctx *sctx) { - if(sctx->user && - (sctx->enabledmechs & SASL_MECH_GSSAPI) && + if((sctx->enabledmechs & SASL_MECH_GSSAPI) && Curl_auth_is_gssapi_supported() && Curl_auth_user_contains_domain(sctx->conn->user)) { const char *service = data->set.str[STRING_SERVICE_NAME] ? @@ -359,8 +347,8 @@ static bool sasl_choose_gsasl(struct Curl_easy *data, struct sasl_ctx *sctx) struct gsasldata *gsasl; struct bufref nullmsg; - if(sctx->user && - (sctx->enabledmechs & (SASL_MECH_SCRAM_SHA_256|SASL_MECH_SCRAM_SHA_1))) { + if((sctx->enabledmechs & + (SASL_MECH_SCRAM_SHA_256 | SASL_MECH_SCRAM_SHA_1))) { gsasl = Curl_auth_gsasl_get(sctx->conn); if(!gsasl) { sctx->result = CURLE_OUT_OF_MEMORY; @@ -368,14 +356,14 @@ static bool sasl_choose_gsasl(struct Curl_easy *data, struct sasl_ctx *sctx) } if((sctx->enabledmechs & SASL_MECH_SCRAM_SHA_256) && - Curl_auth_gsasl_is_supported(data, SASL_MECH_STRING_SCRAM_SHA_256, - gsasl)) { + Curl_auth_gsasl_is_supported(data, SASL_MECH_STRING_SCRAM_SHA_256, + gsasl)) { sctx->mech = SASL_MECH_STRING_SCRAM_SHA_256; sctx->sasl->authused = SASL_MECH_SCRAM_SHA_256; } else if((sctx->enabledmechs & SASL_MECH_SCRAM_SHA_1) && - Curl_auth_gsasl_is_supported(data, SASL_MECH_STRING_SCRAM_SHA_1, - gsasl)) { + Curl_auth_gsasl_is_supported(data, SASL_MECH_STRING_SCRAM_SHA_1, + gsasl)) { sctx->mech = SASL_MECH_STRING_SCRAM_SHA_1; sctx->sasl->authused = SASL_MECH_SCRAM_SHA_1; } @@ -400,9 +388,7 @@ static bool sasl_choose_gsasl(struct Curl_easy *data, struct sasl_ctx *sctx) static bool sasl_choose_digest(struct Curl_easy *data, struct sasl_ctx *sctx) { (void)data; - if(!sctx->user) - return FALSE; - else if((sctx->enabledmechs & SASL_MECH_DIGEST_MD5) && + if((sctx->enabledmechs & SASL_MECH_DIGEST_MD5) && Curl_auth_is_digest_supported()) { sctx->mech = SASL_MECH_STRING_DIGEST_MD5; sctx->state1 = SASL_DIGESTMD5; @@ -422,10 +408,8 @@ static bool sasl_choose_digest(struct Curl_easy *data, struct sasl_ctx *sctx) #ifdef USE_NTLM static bool sasl_choose_ntlm(struct Curl_easy *data, struct sasl_ctx *sctx) { - if(!sctx->user) - return FALSE; - else if((sctx->enabledmechs & SASL_MECH_NTLM) && - Curl_auth_is_ntlm_supported()) { + if((sctx->enabledmechs & SASL_MECH_NTLM) && + Curl_auth_is_ntlm_supported()) { const char *service = data->set.str[STRING_SERVICE_NAME] ? data->set.str[STRING_SERVICE_NAME] : sctx->sasl->params->service; @@ -456,10 +440,11 @@ static bool sasl_choose_ntlm(struct Curl_easy *data, struct sasl_ctx *sctx) static bool sasl_choose_oauth(struct Curl_easy *data, struct sasl_ctx *sctx) { - const char *oauth_bearer = data->set.str[STRING_BEARER]; + const char *oauth_bearer = + (!data->state.this_is_a_follow || data->set.allow_auth_to_other_hosts) ? + data->set.str[STRING_BEARER] : NULL; - if(sctx->user && oauth_bearer && - (sctx->enabledmechs & SASL_MECH_OAUTHBEARER)) { + if(oauth_bearer && (sctx->enabledmechs & SASL_MECH_OAUTHBEARER)) { const char *hostname; int port; Curl_conn_get_current_host(data, FIRSTSOCKET, &hostname, &port); @@ -481,10 +466,11 @@ static bool sasl_choose_oauth(struct Curl_easy *data, struct sasl_ctx *sctx) static bool sasl_choose_oauth2(struct Curl_easy *data, struct sasl_ctx *sctx) { - const char *oauth_bearer = data->set.str[STRING_BEARER]; + const char *oauth_bearer = + (!data->state.this_is_a_follow || data->set.allow_auth_to_other_hosts) ? + data->set.str[STRING_BEARER] : NULL; - if(sctx->user && oauth_bearer && - (sctx->enabledmechs & SASL_MECH_XOAUTH2)) { + if(oauth_bearer && (sctx->enabledmechs & SASL_MECH_XOAUTH2)) { sctx->mech = SASL_MECH_STRING_XOAUTH2; sctx->state1 = SASL_OAUTH2; sctx->sasl->authused = SASL_MECH_XOAUTH2; @@ -500,7 +486,7 @@ static bool sasl_choose_oauth2(struct Curl_easy *data, struct sasl_ctx *sctx) static bool sasl_choose_plain(struct Curl_easy *data, struct sasl_ctx *sctx) { - if(sctx->user && (sctx->enabledmechs & SASL_MECH_PLAIN)) { + if(sctx->enabledmechs & SASL_MECH_PLAIN) { sctx->mech = SASL_MECH_STRING_PLAIN; sctx->state1 = SASL_PLAIN; sctx->sasl->authused = SASL_MECH_PLAIN; @@ -517,7 +503,7 @@ static bool sasl_choose_plain(struct Curl_easy *data, struct sasl_ctx *sctx) static bool sasl_choose_login(struct Curl_easy *data, struct sasl_ctx *sctx) { - if(sctx->user && (sctx->enabledmechs & SASL_MECH_LOGIN)) { + if(sctx->enabledmechs & SASL_MECH_LOGIN) { sctx->mech = SASL_MECH_STRING_LOGIN; sctx->state1 = SASL_LOGIN; sctx->state2 = SASL_LOGIN_PASSWD; @@ -547,7 +533,6 @@ CURLcode Curl_sasl_start(struct SASL *sasl, struct Curl_easy *data, memset(&sctx, 0, sizeof(sctx)); sctx.sasl = sasl; sctx.conn = data->conn; - sctx.user = data->state.aptr.user; Curl_bufref_init(&sctx.resp); sctx.enabledmechs = sasl->authmechs & sasl->prefmech; sctx.state1 = SASL_STOP; @@ -709,7 +694,7 @@ CURLcode Curl_sasl_continue(struct SASL *sasl, struct Curl_easy *data, case SASL_NTLM_TYPE2MSG: { /* Decode the type-2 message */ struct ntlmdata *ntlm = Curl_auth_ntlm_get(conn, FALSE); - result = !ntlm ? CURLE_FAILED_INIT : + result = !ntlm ? CURLE_OUT_OF_MEMORY : get_server_message(sasl, data, &serverdata); if(!result) result = Curl_auth_decode_ntlm_type2_message(data, &serverdata, ntlm); @@ -876,7 +861,7 @@ static void sasl_unchosen(struct Curl_easy *data, unsigned short mech, else { if(param_missing) infof(data, "SASL: %s is missing %s", mname, param_missing); - if(!data->state.aptr.user) + if(!data->conn->user[0]) infof(data, "SASL: %s is missing username", mname); } } @@ -932,10 +917,10 @@ CURLcode Curl_sasl_is_blocked(struct SASL *sasl, struct Curl_easy *data) CURL_SASL_DIGEST, TRUE, NULL); sasl_unchosen(data, SASL_MECH_NTLM, enabledmechs, CURL_SASL_NTLM, Curl_auth_is_ntlm_supported(), NULL); - sasl_unchosen(data, SASL_MECH_OAUTHBEARER, enabledmechs, TRUE, TRUE, + sasl_unchosen(data, SASL_MECH_OAUTHBEARER, enabledmechs, TRUE, TRUE, data->set.str[STRING_BEARER] ? NULL : "CURLOPT_XOAUTH2_BEARER"); - sasl_unchosen(data, SASL_MECH_XOAUTH2, enabledmechs, TRUE, TRUE, + sasl_unchosen(data, SASL_MECH_XOAUTH2, enabledmechs, TRUE, TRUE, data->set.str[STRING_BEARER] ? NULL : "CURLOPT_XOAUTH2_BEARER"); } diff --git a/vendor/hydra/vendor/curl/lib/curl_sasl.h b/vendor/hydra/vendor/curl/lib/curl_sasl.h index 0674d56f..8432d261 100644 --- a/vendor/hydra/vendor/curl/lib/curl_sasl.h +++ b/vendor/hydra/vendor/curl/lib/curl_sasl.h @@ -23,9 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - -#include - #include "bufref.h" struct Curl_easy; diff --git a/vendor/hydra/vendor/curl/lib/curl_setup.h b/vendor/hydra/vendor/curl/lib/curl_setup.h index 7c033623..05b4aff6 100644 --- a/vendor/hydra/vendor/curl/lib/curl_setup.h +++ b/vendor/hydra/vendor/curl/lib/curl_setup.h @@ -75,14 +75,14 @@ #endif #endif -#if defined(__MINGW32__) && !defined(__MINGW32CE__) && \ +#if defined(__MINGW32__) && \ (!defined(__MINGW64_VERSION_MAJOR) || (__MINGW64_VERSION_MAJOR < 3)) #error "Building curl requires mingw-w64 3.0 or later" #endif -/* Visual Studio 2008 is the minimum Visual Studio version we support. +/* Visual Studio 2010 is the minimum Visual Studio version we support. Workarounds for older versions of Visual Studio have been removed. */ -#if defined(_MSC_VER) && (_MSC_VER < 1500) +#if defined(_MSC_VER) && (_MSC_VER < 1600) #error "Ancient versions of Visual Studio are no longer supported due to bugs." #endif @@ -90,11 +90,11 @@ /* Disable Visual Studio warnings: 4127 "conditional expression is constant" */ #pragma warning(disable:4127) /* Avoid VS2005 and upper complaining about portable C functions. */ -#ifndef _CRT_NONSTDC_NO_DEPRECATE -#define _CRT_NONSTDC_NO_DEPRECATE /* for strdup(), write(), etc. */ +#ifndef _CRT_NONSTDC_NO_DEPRECATE /* mingw-w64 v2+. MS SDK ~10+/~VS2017+. */ +#define _CRT_NONSTDC_NO_DEPRECATE /* for close(), fileno(), unlink(), etc. */ #endif -#ifndef _CRT_SECURE_NO_DEPRECATE -#define _CRT_SECURE_NO_DEPRECATE /* for fopen(), getenv(), etc. */ +#ifndef _CRT_SECURE_NO_WARNINGS +#define _CRT_SECURE_NO_WARNINGS /* for getenv(), tests: sscanf() */ #endif #endif /* _MSC_VER */ @@ -122,14 +122,6 @@ # endif #endif -/* Avoid bogus format check warnings with mingw32ce gcc 4.4.0 in - C99 (-std=gnu99) mode */ -#if defined(__MINGW32CE__) && !defined(CURL_NO_FMT_CHECKS) && \ - (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) && \ - (defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 4)) -#define CURL_NO_FMT_CHECKS -#endif - /* Compatibility */ #ifdef ENABLE_IPV6 #define USE_IPV6 1 @@ -170,7 +162,7 @@ /* ================================================================ */ /* Definition of preprocessor macros/symbols which modify compiler */ -/* behavior or generated code characteristics must be done here, */ +/* behavior or generated code characteristics must be done here, */ /* as appropriate, before any system header file is included. It is */ /* also possible to have them defined in the config file included */ /* before this point. As a result of all this we frown inclusion of */ @@ -187,7 +179,6 @@ * AIX 4.3 and newer needs _THREAD_SAFE defined to build * proper reentrant code. Others may also need it. */ - #ifdef NEED_THREAD_SAFE # ifndef _THREAD_SAFE # define _THREAD_SAFE @@ -199,7 +190,6 @@ * things to appear in the system header files. Unixware needs it * to build proper reentrant code. Others may also need it. */ - #ifdef NEED_REENTRANT # ifndef _REENTRANT # define _REENTRANT @@ -226,7 +216,6 @@ /* * Disable other protocols when http is the only one desired. */ - #ifdef HTTP_ONLY # ifndef CURL_DISABLE_DICT # define CURL_DISABLE_DICT @@ -275,7 +264,6 @@ /* * When http is disabled rtsp is not supported. */ - #if defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_RTSP) # define CURL_DISABLE_RTSP #endif @@ -283,7 +271,6 @@ /* * When HTTP is disabled, disable HTTP-only features */ - #ifdef CURL_DISABLE_HTTP # define CURL_DISABLE_ALTSVC 1 # define CURL_DISABLE_COOKIES 1 @@ -305,7 +292,6 @@ /* * OS/400 setup file includes some system headers. */ - #ifdef __OS400__ # include "setup-os400.h" #endif @@ -313,7 +299,6 @@ /* * VMS setup file includes some system headers. */ - #ifdef __VMS # include "setup-vms.h" #endif @@ -321,7 +306,6 @@ /* * Windows setup file includes some system headers. */ - #ifdef _WIN32 # include "setup-win32.h" #endif @@ -332,8 +316,8 @@ * Direct macros concatenation does not work because macros * are not expanded before direct concatenation. */ -#define CURL_CONC_MACROS_(A,B) A ## B -#define CURL_CONC_MACROS(A,B) CURL_CONC_MACROS_(A,B) +#define CURL_CONC_MACROS_(A, B) A ## B +#define CURL_CONC_MACROS(A, B) CURL_CONC_MACROS_(A, B) /* curl uses its own printf() function internally. It understands the GNU * format. Use this format, so that it matches the GNU format attribute we @@ -347,7 +331,6 @@ #endif /* based on logic in "curl/mprintf.h" */ - #if (defined(__GNUC__) || defined(__clang__) || \ defined(__IAR_SYSTEMS_ICC__)) && \ defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \ @@ -438,9 +421,9 @@ # ifdef __amigaos4__ int Curl_amiga_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *timeout); -# define select(a,b,c,d,e) Curl_amiga_select(a,b,c,d,e) +# define select(a, b, c, d, e) Curl_amiga_select(a, b, c, d, e) # else -# define select(a,b,c,d,e) WaitSelect(a,b,c,d,e,0) +# define select(a, b, c, d, e) WaitSelect(a, b, c, d, e, 0) # endif /* must not use libc's fcntl() on bsdsocket.library sockfds! */ # undef HAVE_FCNTL @@ -466,7 +449,7 @@ #include #ifdef __TANDEM /* for ns*-tandem-nsk systems */ -# if ! defined __LP64 +# ifndef __LP64 # include /* FLOSS is only used for 32-bit builds. */ # endif #endif @@ -487,31 +470,19 @@ # endif # include # include -# ifdef USE_WIN32_LARGE_FILES - /* Large file (>2Gb) support using Win32 functions. */ -# undef lseek -# define lseek(fdes, offset, whence) _lseeki64(fdes, offset, whence) -# undef fstat -# define fstat(fdes,stp) _fstati64(fdes, stp) -# undef stat -# define struct_stat struct _stati64 -# define LSEEK_ERROR (__int64)-1 -# else - /* Small file (<2Gb) support using Win32 functions. */ -# ifndef UNDER_CE -# undef lseek -# define lseek(fdes, offset, whence) _lseek(fdes, (long)offset, whence) -# define fstat(fdes, stp) _fstat(fdes, stp) -# define struct_stat struct _stat -# endif -# define LSEEK_ERROR (long)-1 -# endif + /* Large file (>2Gb) support using Win32 functions. */ +# undef lseek +# define lseek(fdes, offset, whence) _lseeki64(fdes, offset, whence) +# undef fstat +# define fstat(fdes, stp) _fstati64(fdes, stp) +# define struct_stat struct _stati64 +# define LSEEK_ERROR (__int64)-1 #elif defined(__DJGPP__) /* Requires DJGPP 2.04 */ # include # undef lseek -# define lseek(fdes,offset,whence) llseek(fdes, offset, whence) -# define LSEEK_ERROR (offset_t)-1 +# define lseek(fdes, offset, whence) llseek(fdes, offset, whence) +# define LSEEK_ERROR (offset_t)-1 #endif #ifndef struct_stat @@ -538,9 +509,13 @@ #endif #if SIZEOF_CURL_SOCKET_T < 8 +#ifdef _WIN32 +# define FMT_SOCKET_T "u" +#else # define FMT_SOCKET_T "d" -#elif defined(__MINGW32__) -# define FMT_SOCKET_T "zd" +#endif +#elif defined(_WIN32) +# define FMT_SOCKET_T "zu" #else # define FMT_SOCKET_T "qd" #endif @@ -580,21 +555,7 @@ #endif #define CURL_OFF_T_MIN (-CURL_OFF_T_MAX - 1) -#if (SIZEOF_CURL_OFF_T != 8) -# error "curl_off_t must be exactly 64 bits" -#else - typedef unsigned CURL_TYPEOF_CURL_OFF_T curl_uint64_t; - typedef CURL_TYPEOF_CURL_OFF_T curl_int64_t; -# ifndef CURL_SUFFIX_CURL_OFF_TU -# error "CURL_SUFFIX_CURL_OFF_TU must be defined" -# endif -# define CURL_UINT64_SUFFIX CURL_SUFFIX_CURL_OFF_TU -# define CURL_UINT64_C(val) CURL_CONC_MACROS(val,CURL_UINT64_SUFFIX) -# define FMT_PRId64 CURL_FORMAT_CURL_OFF_T -# define FMT_PRIu64 CURL_FORMAT_CURL_OFF_TU -#endif - -#define FMT_OFF_T CURL_FORMAT_CURL_OFF_T +#define FMT_OFF_T CURL_FORMAT_CURL_OFF_T #define FMT_OFF_TU CURL_FORMAT_CURL_OFF_TU #if (SIZEOF_TIME_T == 4) @@ -633,10 +594,13 @@ #endif #endif +#if SIZEOF_LONG > SIZEOF_SIZE_T +#error "unexpected: 'long' is larger than 'size_t'" +#endif + /* * Arg 2 type for gethostname in case it has not been defined in config file. */ - #ifndef GETHOSTNAME_TYPE_ARG2 # ifdef USE_WINSOCK # define GETHOSTNAME_TYPE_ARG2 int @@ -646,10 +610,9 @@ #endif /* Below we define some functions. They should - 4. set the SIGALRM signal timeout 5. set dir/file naming defines - */ + */ #ifdef _WIN32 @@ -660,8 +623,8 @@ # ifdef MSDOS /* Watt-32 */ # include -# define select(n,r,w,x,t) select_s(n,r,w,x,t) -# define ioctl(x,y,z) ioctlsocket(x,y,(char *)(z)) +# define select(n, r, w, x, t) select_s(n, r, w, x, t) +# define ioctl(x, y, z) ioctlsocket(x, y, (char *)(z)) # include # undef word # undef byte @@ -685,7 +648,6 @@ /* * Mutually exclusive CURLRES_* definitions. */ - #if defined(USE_IPV6) && defined(HAVE_GETADDRINFO) # define CURLRES_IPV6 #elif defined(USE_IPV6) && (defined(_WIN32) || defined(__CYGWIN__)) @@ -813,44 +775,32 @@ /* * Include macros and defines that should only be processed once. */ - #ifndef HEADER_CURL_SETUP_ONCE_H #include "curl_setup_once.h" #endif -#ifdef UNDER_CE -#define getenv curl_getenv /* Windows CE does not support getenv() */ -#define raise(s) ((void)(s)) -/* Terrible workarounds to make Windows CE compile */ -#define errno 0 -#define CURL_SETERRNO(x) ((void)(x)) -#define EINTR 4 -#define EAGAIN 11 -#define ENOMEM 12 -#define EACCES 13 -#define EEXIST 17 -#define EISDIR 21 -#define EINVAL 22 -#define ENOSPC 28 -#define strerror(x) "?" -#undef STDIN_FILENO -#define STDIN_FILENO 0 -#else -#define CURL_SETERRNO(x) (errno = (x)) +/* + * Macros and functions to safely suppress warnings + */ +#include "curlx/warnless.h" + +#ifdef _WIN32 +# undef read +# define read(fd, buf, count) (ssize_t)_read(fd, buf, curlx_uztoui(count)) +# undef write +# define write(fd, buf, count) (ssize_t)_write(fd, buf, curlx_uztoui(count)) #endif /* * Definition of our NOP statement Object-like macro */ - #ifndef Curl_nop_stmt -#define Curl_nop_stmt do { } while(0) +#define Curl_nop_stmt do {} while(0) #endif /* * Ensure that Winsock and lwIP TCP/IP stacks are not mixed. */ - #if defined(__LWIP_OPT_H__) || defined(LWIP_HDR_OPT_H) # if defined(SOCKET) || defined(USE_WINSOCK) # error "Winsock and lwIP TCP/IP stack definitions shall not coexist!" @@ -860,7 +810,6 @@ /* * shutdown() flags for systems that do not define them */ - #ifndef SHUT_RD #define SHUT_RD 0x00 #endif @@ -906,8 +855,8 @@ Therefore we specify it explicitly. https://github.com/curl/curl/pull/258 */ #if defined(_WIN32) || defined(MSDOS) -#define FOPEN_READTEXT "rt" -#define FOPEN_WRITETEXT "wt" +#define FOPEN_READTEXT "rt" +#define FOPEN_WRITETEXT "wt" #define FOPEN_APPENDTEXT "at" #elif defined(__CYGWIN__) /* Cygwin has specific behavior we need to address when _WIN32 is not defined. @@ -916,18 +865,18 @@ For write we want our output to have line endings of LF and be compatible with other Cygwin utilities. For read we want to handle input that may have line endings either CRLF or LF so 't' is appropriate. */ -#define FOPEN_READTEXT "rt" -#define FOPEN_WRITETEXT "w" +#define FOPEN_READTEXT "rt" +#define FOPEN_WRITETEXT "w" #define FOPEN_APPENDTEXT "a" #else -#define FOPEN_READTEXT "r" -#define FOPEN_WRITETEXT "w" +#define FOPEN_READTEXT "r" +#define FOPEN_WRITETEXT "w" #define FOPEN_APPENDTEXT "a" #endif /* for systems that do not detect this in configure */ #ifndef CURL_SA_FAMILY_T -# if defined(_WIN32) && !defined(UNDER_CE) +# ifdef _WIN32 # define CURL_SA_FAMILY_T ADDRESS_FAMILY # elif defined(HAVE_SA_FAMILY_T) # define CURL_SA_FAMILY_T sa_family_t @@ -941,15 +890,15 @@ endings either CRLF or LF so 't' is appropriate. /* Some convenience macros to get the larger/smaller value out of two given. We prefix with CURL to prevent name collisions. */ -#define CURLMAX(x,y) ((x)>(y)?(x):(y)) -#define CURLMIN(x,y) ((x)<(y)?(x):(y)) +#define CURLMAX(x, y) ((x) > (y) ? (x) : (y)) +#define CURLMIN(x, y) ((x) < (y) ? (x) : (y)) /* A convenience macro to provide both the string literal and the length of the string literal in one go, useful for functions that take "string,len" as their argument */ -#define STRCONST(x) x,sizeof(x)-1 +#define STRCONST(x) x, sizeof(x) - 1 -#define CURL_ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0])) +#define CURL_ARRAYSIZE(A) (sizeof(A) / sizeof((A)[0])) /* Buffer size for error messages retrieved via curlx_strerror() and Curl_sspi_strerror() */ @@ -982,9 +931,12 @@ extern curl_calloc_callback Curl_ccalloc; * This macro also assigns NULL to given pointer when free'd. */ #define Curl_safefree(ptr) \ - do { free((ptr)); (ptr) = NULL;} while(0) + do { \ + curlx_free(ptr); \ + (ptr) = NULL; \ + } while(0) -#include /* for CURL_EXTERN, mprintf.h */ +#include /* for CURL_EXTERN, curl_socket_t, mprintf.h */ #ifdef CURLDEBUG #ifdef __clang__ @@ -1051,49 +1003,36 @@ CURL_EXTERN int curl_dbg_socketpair(int domain, int type, int protocol, int line, const char *source); #endif -/* send/receive sockets */ -CURL_EXTERN SEND_TYPE_RETV curl_dbg_send(SEND_TYPE_ARG1 sockfd, - SEND_QUAL_ARG2 SEND_TYPE_ARG2 buf, - SEND_TYPE_ARG3 len, - SEND_TYPE_ARG4 flags, int line, - const char *source); -CURL_EXTERN RECV_TYPE_RETV curl_dbg_recv(RECV_TYPE_ARG1 sockfd, - RECV_TYPE_ARG2 buf, - RECV_TYPE_ARG3 len, - RECV_TYPE_ARG4 flags, int line, - const char *source); - /* FILE functions */ CURL_EXTERN int curl_dbg_fclose(FILE *file, int line, const char *source); -CURL_EXTERN ALLOC_FUNC - FILE *curl_dbg_fopen(const char *file, const char *mode, - int line, const char *source); -CURL_EXTERN ALLOC_FUNC - FILE *curl_dbg_fdopen(int filedes, const char *mode, - int line, const char *source); - -#define sclose(sockfd) curl_dbg_sclose(sockfd,__LINE__,__FILE__) -#define fake_sclose(sockfd) curl_dbg_mark_sclose(sockfd,__LINE__,__FILE__) - -#define CURL_GETADDRINFO(host,serv,hint,res) \ +CURL_EXTERN ALLOC_FUNC FILE *curl_dbg_fopen(const char *file, const char *mode, + int line, const char *source); +CURL_EXTERN ALLOC_FUNC FILE *curl_dbg_freopen(const char *file, + const char *mode, FILE *fh, + int line, const char *source); +CURL_EXTERN ALLOC_FUNC FILE *curl_dbg_fdopen(int filedes, const char *mode, + int line, const char *source); + +#define sclose(sockfd) curl_dbg_sclose(sockfd, __LINE__, __FILE__) +#define fake_sclose(sockfd) curl_dbg_mark_sclose(sockfd, __LINE__, __FILE__) + +#define CURL_GETADDRINFO(host, serv, hint, res) \ curl_dbg_getaddrinfo(host, serv, hint, res, __LINE__, __FILE__) #define CURL_FREEADDRINFO(data) \ curl_dbg_freeaddrinfo(data, __LINE__, __FILE__) -#define CURL_SOCKET(domain,type,protocol) \ +#define CURL_SOCKET(domain, type, protocol) \ curl_dbg_socket((int)domain, type, protocol, __LINE__, __FILE__) #ifdef HAVE_SOCKETPAIR -#define CURL_SOCKETPAIR(domain,type,protocol,socket_vector) \ +#define CURL_SOCKETPAIR(domain, type, protocol, socket_vector) \ curl_dbg_socketpair((int)domain, type, protocol, socket_vector, \ __LINE__, __FILE__) #endif -#define CURL_ACCEPT(sock,addr,len) \ +#define CURL_ACCEPT(sock, addr, len) \ curl_dbg_accept(sock, addr, len, __LINE__, __FILE__) #ifdef HAVE_ACCEPT4 -#define CURL_ACCEPT4(sock,addr,len,flags) \ +#define CURL_ACCEPT4(sock, addr, len, flags) \ curl_dbg_accept4(sock, addr, len, flags, __LINE__, __FILE__) #endif -#define CURL_SEND(a,b,c,d) curl_dbg_send(a,b,c,d, __LINE__, __FILE__) -#define CURL_RECV(a,b,c,d) curl_dbg_recv(a,b,c,d, __LINE__, __FILE__) #else /* !CURLDEBUG */ @@ -1110,8 +1049,56 @@ CURL_EXTERN ALLOC_FUNC #ifdef HAVE_ACCEPT4 #define CURL_ACCEPT4 accept4 #endif -#define CURL_SEND send -#define CURL_RECV recv + +#endif /* CURLDEBUG */ + +/* Allocator macros */ + +#ifdef CURLDEBUG + +#define curlx_strdup(ptr) curl_dbg_strdup(ptr, __LINE__, __FILE__) +#define curlx_malloc(size) curl_dbg_malloc(size, __LINE__, __FILE__) +#define curlx_calloc(nbelem, size) \ + curl_dbg_calloc(nbelem, size, __LINE__, __FILE__) +#define curlx_realloc(ptr, size) \ + curl_dbg_realloc(ptr, size, __LINE__, __FILE__) +#define curlx_free(ptr) curl_dbg_free(ptr, __LINE__, __FILE__) + +#ifdef _WIN32 +#ifdef UNICODE +#define curlx_tcsdup(ptr) curl_dbg_wcsdup(ptr, __LINE__, __FILE__) +#else +#define curlx_tcsdup(ptr) curlx_strdup(ptr) +#endif +#endif /* _WIN32 */ + +#else /* !CURLDEBUG */ + +#ifdef BUILDING_LIBCURL +#define curlx_strdup(ptr) Curl_cstrdup(ptr) +#define curlx_malloc(size) Curl_cmalloc(size) +#define curlx_calloc(nbelem, size) Curl_ccalloc(nbelem, size) +#define curlx_realloc(ptr, size) Curl_crealloc(ptr, size) +#define curlx_free(ptr) Curl_cfree(ptr) +#else /* !BUILDING_LIBCURL */ +#ifdef _WIN32 +#define curlx_strdup(ptr) _strdup(ptr) +#else +#define curlx_strdup(ptr) strdup(ptr) +#endif +#define curlx_malloc(size) malloc(size) +#define curlx_calloc(nbelem, size) calloc(nbelem, size) +#define curlx_realloc(ptr, size) realloc(ptr, size) +#define curlx_free(ptr) free(ptr) +#endif /* BUILDING_LIBCURL */ + +#ifdef _WIN32 +#ifdef UNICODE +#define curlx_tcsdup(ptr) Curl_wcsdup(ptr) +#else +#define curlx_tcsdup(ptr) curlx_strdup(ptr) +#endif +#endif /* _WIN32 */ #endif /* CURLDEBUG */ @@ -1134,8 +1121,8 @@ int getpwuid_r(uid_t uid, struct passwd *pwd, char *buf, #endif #if (defined(USE_NGTCP2) && defined(USE_NGHTTP3)) || \ - (defined(USE_OPENSSL_QUIC) && defined(USE_NGHTTP3)) || \ - defined(USE_QUICHE) + (defined(USE_OPENSSL_QUIC) && defined(USE_NGHTTP3)) || \ + defined(USE_QUICHE) #ifdef CURL_WITH_MULTI_SSL #error "MultiSSL combined with QUIC is not supported" @@ -1157,17 +1144,17 @@ int getpwuid_r(uid_t uid, struct passwd *pwd, char *buf, #endif #if defined(USE_UNIX_SOCKETS) && defined(_WIN32) -# ifndef UNIX_PATH_MAX - /* Replicating logic present in afunix.h - (distributed with newer Windows 10 SDK versions only) */ -# define UNIX_PATH_MAX 108 - /* !checksrc! disable TYPEDEFSTRUCT 1 */ - typedef struct sockaddr_un { - CURL_SA_FAMILY_T sun_family; - char sun_path[UNIX_PATH_MAX]; - } SOCKADDR_UN, *PSOCKADDR_UN; -# define WIN32_SOCKADDR_UN -# endif +/* Offered by mingw-w64 v10+. MS SDK 10.17763/~VS2017+. */ +#if defined(__MINGW32__) && (__MINGW64_VERSION_MAJOR >= 10) +# include +#elif !defined(UNIX_PATH_MAX) /* Replicate logic present in afunix.h */ +# define UNIX_PATH_MAX 108 +/* !checksrc! disable TYPEDEFSTRUCT 1 */ +typedef struct sockaddr_un { + CURL_SA_FAMILY_T sun_family; + char sun_path[UNIX_PATH_MAX]; +} SOCKADDR_UN, *PSOCKADDR_UN; +#endif #endif #ifdef USE_OPENSSL @@ -1205,5 +1192,3 @@ int getpwuid_r(uid_t uid, struct passwd *pwd, char *buf, #endif #endif /* HEADER_CURL_SETUP_H */ - -#include "curl_mem_undef.h" diff --git a/vendor/hydra/vendor/curl/lib/curl_setup_once.h b/vendor/hydra/vendor/curl/lib/curl_setup_once.h index 7a54760e..06ccc986 100644 --- a/vendor/hydra/vendor/curl/lib/curl_setup_once.h +++ b/vendor/hydra/vendor/curl/lib/curl_setup_once.h @@ -28,14 +28,11 @@ * Inclusion of common header files. */ -#include #include #include #include #include -#ifndef UNDER_CE #include -#endif #ifdef HAVE_SYS_TYPES_H #include @@ -67,8 +64,6 @@ Use it for APIs that do not or cannot support the const qualifier. */ #ifdef HAVE_STDINT_H # define CURL_UNCONST(p) ((void *)(uintptr_t)(const void *)(p)) -#elif defined(_WIN32) /* for VS2008 */ -# define CURL_UNCONST(p) ((void *)(ULONG_PTR)(const void *)(p)) #else # define CURL_UNCONST(p) ((void *)(p)) /* Fall back to simple cast */ #endif @@ -108,7 +103,6 @@ /* * Definition of timeval struct for platforms that do not have it. */ - #ifndef HAVE_STRUCT_TIMEVAL struct timeval { long tv_sec; @@ -116,24 +110,21 @@ struct timeval { }; #endif - /* * If we have the MSG_NOSIGNAL define, make sure we use * it as the fourth argument of function send() */ - #ifdef HAVE_MSG_NOSIGNAL #define SEND_4TH_ARG MSG_NOSIGNAL #else #define SEND_4TH_ARG 0 #endif - #ifdef __minix /* Minix does not support recv on TCP sockets */ -#define sread(x,y,z) (ssize_t)read((RECV_TYPE_ARG1)(x), \ - (RECV_TYPE_ARG2)(y), \ - (RECV_TYPE_ARG3)(z)) +#define sread(x, y, z) (ssize_t)read((RECV_TYPE_ARG1)(x), \ + (RECV_TYPE_ARG2)(y), \ + (RECV_TYPE_ARG3)(z)) #elif defined(HAVE_RECV) /* @@ -158,48 +149,45 @@ struct timeval { * SEND_TYPE_RETV must also be defined. */ -#define sread(x,y,z) (ssize_t)recv((RECV_TYPE_ARG1)(x), \ - (RECV_TYPE_ARG2)(y), \ - (RECV_TYPE_ARG3)(z), \ - (RECV_TYPE_ARG4)(0)) +#define sread(x, y, z) (ssize_t)recv((RECV_TYPE_ARG1)(x), \ + (RECV_TYPE_ARG2)(y), \ + (RECV_TYPE_ARG3)(z), \ + (RECV_TYPE_ARG4)(0)) #else /* HAVE_RECV */ #ifndef sread #error "Missing definition of macro sread!" #endif #endif /* HAVE_RECV */ - #ifdef __minix /* Minix does not support send on TCP sockets */ -#define swrite(x,y,z) (ssize_t)write((SEND_TYPE_ARG1)(x), \ - (SEND_TYPE_ARG2)CURL_UNCONST(y), \ - (SEND_TYPE_ARG3)(z)) +#define swrite(x, y, z) (ssize_t)write((SEND_TYPE_ARG1)(x), \ + (SEND_TYPE_ARG2)CURL_UNCONST(y), \ + (SEND_TYPE_ARG3)(z)) #elif defined(HAVE_SEND) -#define swrite(x,y,z) (ssize_t)send((SEND_TYPE_ARG1)(x), \ +#define swrite(x, y, z) (ssize_t)send((SEND_TYPE_ARG1)(x), \ (SEND_QUAL_ARG2 SEND_TYPE_ARG2)CURL_UNCONST(y), \ - (SEND_TYPE_ARG3)(z), \ - (SEND_TYPE_ARG4)(SEND_4TH_ARG)) + (SEND_TYPE_ARG3)(z), \ + (SEND_TYPE_ARG4)(SEND_4TH_ARG)) #else /* HAVE_SEND */ #ifndef swrite #error "Missing definition of macro swrite!" #endif #endif /* HAVE_SEND */ - /* * Function-like macro definition used to close a socket. */ - #ifdef HAVE_CLOSESOCKET -# define CURL_SCLOSE(x) closesocket((x)) +# define CURL_SCLOSE(x) closesocket(x) #elif defined(HAVE_CLOSESOCKET_CAMEL) -# define CURL_SCLOSE(x) CloseSocket((x)) +# define CURL_SCLOSE(x) CloseSocket(x) #elif defined(MSDOS) /* Watt-32 */ -# define CURL_SCLOSE(x) close_s((x)) +# define CURL_SCLOSE(x) close_s(x) #elif defined(USE_LWIPSOCK) -# define CURL_SCLOSE(x) lwip_close((x)) +# define CURL_SCLOSE(x) lwip_close(x) #else -# define CURL_SCLOSE(x) close((x)) +# define CURL_SCLOSE(x) close(x) #endif /* @@ -214,7 +202,6 @@ struct timeval { /* * 'bool' stuff compatible with HP-UX headers. */ - #if defined(__hpux) && !defined(HAVE_BOOL_T) typedef int bool; # define false 0 @@ -222,14 +209,12 @@ struct timeval { # define HAVE_BOOL_T #endif - /* * 'bool' exists on platforms with , i.e. C99 platforms. * On non-C99 platforms there is no bool, so define an enum for that. * On C99 platforms 'false' and 'true' also exist. Enum uses a * global namespace though, so use bool_false and bool_true. */ - #ifndef HAVE_BOOL_T typedef enum { bool_false = 0, @@ -262,7 +247,6 @@ typedef unsigned int bit; * 'bool found = TRUE' will not. Change tested on IRIX/MIPSPro, * AIX 5.1/Xlc, Tru64 5.1/cc, w/make test too. */ - #ifndef TRUE #define TRUE true #endif @@ -272,35 +256,29 @@ typedef unsigned int bit; #include "curl_ctype.h" - /* * Macro used to include code only in debug builds. */ - #ifdef DEBUGBUILD #define DEBUGF(x) x #else -#define DEBUGF(x) do { } while(0) +#define DEBUGF(x) do {} while(0) #endif - /* * Macro used to include assertion code only in debug builds. */ - #undef DEBUGASSERT #ifdef DEBUGBUILD #define DEBUGASSERT(x) assert(x) #else -#define DEBUGASSERT(x) do { } while(0) +#define DEBUGASSERT(x) do {} while(0) #endif - /* * Macro SOCKERRNO / SET_SOCKERRNO() returns / sets the *socket-related* errno * (or equivalent) on this platform to hide platform details to code using it. */ - #ifdef USE_WINSOCK #define SOCKERRNO ((int)WSAGetLastError()) #define SET_SOCKERRNO(x) (WSASetLastError((int)(x))) @@ -309,11 +287,9 @@ typedef unsigned int bit; #define SET_SOCKERRNO(x) (errno = (x)) #endif - /* * Portable error number symbolic names defined to Winsock error codes. */ - #ifdef USE_WINSOCK #define SOCKEACCES WSAEACCES #define SOCKEADDRINUSE WSAEADDRINUSE @@ -353,22 +329,18 @@ typedef unsigned int bit; /* * Macro argv_item_t hides platform details to code using it. */ - #ifdef __VMS #define argv_item_t __char_ptr32 -#elif defined(_UNICODE) && !defined(UNDER_CE) +#elif defined(_UNICODE) #define argv_item_t wchar_t * #else #define argv_item_t char * #endif - /* * We use this ZERO_NULL to avoid picky compiler warnings, * when assigning a NULL pointer to a function pointer var. */ - #define ZERO_NULL 0 - #endif /* HEADER_CURL_SETUP_ONCE_H */ diff --git a/vendor/hydra/vendor/curl/lib/curl_sha256.h b/vendor/hydra/vendor/curl/lib/curl_sha256.h index caa5080b..0aaa4126 100644 --- a/vendor/hydra/vendor/curl/lib/curl_sha256.h +++ b/vendor/hydra/vendor/curl/lib/curl_sha256.h @@ -24,11 +24,11 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ +#include "curl_setup.h" #if !defined(CURL_DISABLE_AWS) || !defined(CURL_DISABLE_DIGEST_AUTH) || \ defined(USE_LIBSSH2) || defined(USE_SSL) -#include #include "curl_hmac.h" extern const struct HMAC_params Curl_HMAC_SHA256; diff --git a/vendor/hydra/vendor/curl/lib/curl_sha512_256.c b/vendor/hydra/vendor/curl/lib/curl_sha512_256.c index 7e9b2233..44ba9be5 100644 --- a/vendor/hydra/vendor/curl/lib/curl_sha512_256.c +++ b/vendor/hydra/vendor/curl/lib/curl_sha512_256.c @@ -21,35 +21,29 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #if !defined(CURL_DISABLE_DIGEST_AUTH) && !defined(CURL_DISABLE_SHA512_256) #include "curl_sha512_256.h" -#include "curlx/warnless.h" /* The recommended order of the TLS backends: - * * OpenSSL - * * GnuTLS - * * wolfSSL - * * Schannel SSPI - * * mbedTLS - * * Rustls + * 1. OpenSSL + * 2. GnuTLS + * 3. wolfSSL + * 4. Schannel SSPI + * 5. mbedTLS + * 6. Rustls * Skip the backend if it does not support the required algorithm */ #ifdef USE_OPENSSL # include -# if (!defined(LIBRESSL_VERSION_NUMBER) && \ - OPENSSL_VERSION_NUMBER >= 0x10101000L) || \ - (defined(LIBRESSL_VERSION_NUMBER) && \ - LIBRESSL_VERSION_NUMBER >= 0x3080000fL) -# include -# if !defined(OPENSSL_NO_SHA) && !defined(OPENSSL_NO_SHA512) -# include -# define USE_OPENSSL_SHA512_256 1 -# define HAS_SHA512_256_IMPLEMENTATION 1 -# ifdef __NetBSD__ +# if !defined(LIBRESSL_VERSION_NUMBER) || \ + (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER >= 0x3080000fL) +# include +# define USE_OPENSSL_SHA512_256 1 +# define HAS_SHA512_256_IMPLEMENTATION 1 +# ifdef __NetBSD__ /* Some NetBSD versions has a bug in SHA-512/256. * See https://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=58039 * The problematic versions: @@ -60,27 +54,24 @@ * NetBSD 10.99.11 development. * It is safe to apply the workaround even if the bug is not present, as * the workaround just reduces performance slightly. */ -# include -# if __NetBSD_Version__ < 904000000 || \ - (__NetBSD_Version__ >= 999000000 && \ - __NetBSD_Version__ < 1000000000) || \ - (__NetBSD_Version__ >= 1099000000 && \ - __NetBSD_Version__ < 1099001100) -# define NEED_NETBSD_SHA512_256_WORKAROUND 1 -# include -# endif +# include +# if __NetBSD_Version__ < 904000000 || \ + (__NetBSD_Version__ >= 999000000 && \ + __NetBSD_Version__ < 1000000000) || \ + (__NetBSD_Version__ >= 1099000000 && \ + __NetBSD_Version__ < 1099001100) +# define NEED_NETBSD_SHA512_256_WORKAROUND 1 # endif # endif # endif #endif /* USE_OPENSSL */ - #if !defined(HAS_SHA512_256_IMPLEMENTATION) && defined(USE_GNUTLS) # include # ifdef SHA512_256_DIGEST_SIZE # define USE_GNUTLS_SHA512_256 1 # endif -#endif /* ! HAS_SHA512_256_IMPLEMENTATION && USE_GNUTLS */ +#endif /* !HAS_SHA512_256_IMPLEMENTATION && USE_GNUTLS */ #ifdef USE_OPENSSL_SHA512_256 @@ -111,7 +102,7 @@ typedef EVP_MD_CTX *Curl_sha512_256_ctx; */ static CURLcode Curl_sha512_256_init(void *context) { - Curl_sha512_256_ctx *const ctx = (Curl_sha512_256_ctx *)context; + Curl_sha512_256_ctx * const ctx = (Curl_sha512_256_ctx *)context; *ctx = EVP_MD_CTX_create(); if(!*ctx) @@ -131,7 +122,6 @@ static CURLcode Curl_sha512_256_init(void *context) return CURLE_FAILED_INIT; } - /** * Process portion of bytes. * @@ -144,7 +134,7 @@ static CURLcode Curl_sha512_256_update(void *context, const unsigned char *data, size_t length) { - Curl_sha512_256_ctx *const ctx = (Curl_sha512_256_ctx *)context; + Curl_sha512_256_ctx * const ctx = (Curl_sha512_256_ctx *)context; if(!EVP_DigestUpdate(*ctx, data, length)) return CURLE_SSL_CIPHER; @@ -152,7 +142,6 @@ static CURLcode Curl_sha512_256_update(void *context, return CURLE_OK; } - /** * Finalise SHA-512/256 calculation, return digest. * @@ -165,7 +154,7 @@ static CURLcode Curl_sha512_256_update(void *context, static CURLcode Curl_sha512_256_finish(unsigned char *digest, void *context) { CURLcode ret; - Curl_sha512_256_ctx *const ctx = (Curl_sha512_256_ctx *)context; + Curl_sha512_256_ctx * const ctx = (Curl_sha512_256_ctx *)context; #ifdef NEED_NETBSD_SHA512_256_WORKAROUND /* Use a larger buffer to work around a bug in NetBSD: @@ -176,9 +165,9 @@ static CURLcode Curl_sha512_256_finish(unsigned char *digest, void *context) if(ret == CURLE_OK) memcpy(digest, tmp_digest, CURL_SHA512_256_DIGEST_SIZE); explicit_memset(tmp_digest, 0, sizeof(tmp_digest)); -#else /* ! NEED_NETBSD_SHA512_256_WORKAROUND */ +#else /* !NEED_NETBSD_SHA512_256_WORKAROUND */ ret = EVP_DigestFinal_ex(*ctx, digest, NULL) ? CURLE_OK : CURLE_SSL_CIPHER; -#endif /* ! NEED_NETBSD_SHA512_256_WORKAROUND */ +#endif /* NEED_NETBSD_SHA512_256_WORKAROUND */ EVP_MD_CTX_destroy(*ctx); *ctx = NULL; @@ -204,7 +193,7 @@ typedef struct sha512_256_ctx Curl_sha512_256_ctx; */ static CURLcode Curl_sha512_256_init(void *context) { - Curl_sha512_256_ctx *const ctx = (Curl_sha512_256_ctx *)context; + Curl_sha512_256_ctx * const ctx = (Curl_sha512_256_ctx *)context; /* Check whether the header and this file use the same numbers */ DEBUGASSERT(CURL_SHA512_256_DIGEST_LENGTH == CURL_SHA512_256_DIGEST_SIZE); @@ -214,7 +203,6 @@ static CURLcode Curl_sha512_256_init(void *context) return CURLE_OK; } - /** * Process portion of bytes. * @@ -227,7 +215,7 @@ static CURLcode Curl_sha512_256_update(void *context, const unsigned char *data, size_t length) { - Curl_sha512_256_ctx *const ctx = (Curl_sha512_256_ctx *)context; + Curl_sha512_256_ctx * const ctx = (Curl_sha512_256_ctx *)context; DEBUGASSERT((data != NULL) || (length == 0)); @@ -236,7 +224,6 @@ static CURLcode Curl_sha512_256_update(void *context, return CURLE_OK; } - /** * Finalise SHA-512/256 calculation, return digest. * @@ -245,10 +232,9 @@ static CURLcode Curl_sha512_256_update(void *context, # bytes * @return always CURLE_OK */ -static CURLcode Curl_sha512_256_finish(unsigned char *digest, - void *context) +static CURLcode Curl_sha512_256_finish(unsigned char *digest, void *context) { - Curl_sha512_256_ctx *const ctx = (Curl_sha512_256_ctx *)context; + Curl_sha512_256_ctx * const ctx = (Curl_sha512_256_ctx *)context; sha512_256_digest(ctx, (size_t)CURL_SHA512_256_DIGEST_SIZE, (uint8_t *)digest); @@ -288,32 +274,32 @@ static CURLcode Curl_sha512_256_finish(unsigned char *digest, /* Bits manipulation macros and functions. Can be moved to other headers to reuse. */ -#define CURL_GET_64BIT_BE(ptr) \ - ( ((curl_uint64_t)(((const unsigned char*)(ptr))[0]) << 56) | \ - ((curl_uint64_t)(((const unsigned char*)(ptr))[1]) << 48) | \ - ((curl_uint64_t)(((const unsigned char*)(ptr))[2]) << 40) | \ - ((curl_uint64_t)(((const unsigned char*)(ptr))[3]) << 32) | \ - ((curl_uint64_t)(((const unsigned char*)(ptr))[4]) << 24) | \ - ((curl_uint64_t)(((const unsigned char*)(ptr))[5]) << 16) | \ - ((curl_uint64_t)(((const unsigned char*)(ptr))[6]) << 8) | \ - (curl_uint64_t)(((const unsigned char*)(ptr))[7]) ) - -#define CURL_PUT_64BIT_BE(ptr,val) do { \ - ((unsigned char*)(ptr))[7]=(unsigned char)((curl_uint64_t)(val)); \ - ((unsigned char*)(ptr))[6]=(unsigned char)(((curl_uint64_t)(val)) >> 8); \ - ((unsigned char*)(ptr))[5]=(unsigned char)(((curl_uint64_t)(val)) >> 16); \ - ((unsigned char*)(ptr))[4]=(unsigned char)(((curl_uint64_t)(val)) >> 24); \ - ((unsigned char*)(ptr))[3]=(unsigned char)(((curl_uint64_t)(val)) >> 32); \ - ((unsigned char*)(ptr))[2]=(unsigned char)(((curl_uint64_t)(val)) >> 40); \ - ((unsigned char*)(ptr))[1]=(unsigned char)(((curl_uint64_t)(val)) >> 48); \ - ((unsigned char*)(ptr))[0]=(unsigned char)(((curl_uint64_t)(val)) >> 56); \ +#define CURL_GET_64BIT_BE(ptr) \ + (((uint64_t)(((const uint8_t *)(ptr))[0]) << 56) | \ + ((uint64_t)(((const uint8_t *)(ptr))[1]) << 48) | \ + ((uint64_t)(((const uint8_t *)(ptr))[2]) << 40) | \ + ((uint64_t)(((const uint8_t *)(ptr))[3]) << 32) | \ + ((uint64_t)(((const uint8_t *)(ptr))[4]) << 24) | \ + ((uint64_t)(((const uint8_t *)(ptr))[5]) << 16) | \ + ((uint64_t)(((const uint8_t *)(ptr))[6]) << 8) | \ + (uint64_t)(((const uint8_t *)(ptr))[7])) + +#define CURL_PUT_64BIT_BE(ptr, val) \ + do { \ + ((uint8_t *)(ptr))[7] = (uint8_t)((uint64_t)(val)); \ + ((uint8_t *)(ptr))[6] = (uint8_t)(((uint64_t)(val)) >> 8); \ + ((uint8_t *)(ptr))[5] = (uint8_t)(((uint64_t)(val)) >> 16); \ + ((uint8_t *)(ptr))[4] = (uint8_t)(((uint64_t)(val)) >> 24); \ + ((uint8_t *)(ptr))[3] = (uint8_t)(((uint64_t)(val)) >> 32); \ + ((uint8_t *)(ptr))[2] = (uint8_t)(((uint64_t)(val)) >> 40); \ + ((uint8_t *)(ptr))[1] = (uint8_t)(((uint64_t)(val)) >> 48); \ + ((uint8_t *)(ptr))[0] = (uint8_t)(((uint64_t)(val)) >> 56); \ } while(0) /* Defined as a function. The macro version may duplicate the binary code * size as each argument is used twice, so if any calculation is used * as an argument, the calculation could be done twice. */ -static CURL_FORCEINLINE curl_uint64_t Curl_rotr64(curl_uint64_t value, - unsigned int bits) +static CURL_FORCEINLINE uint64_t Curl_rotr64(uint64_t value, unsigned int bits) { bits %= 64; if(bits == 0) @@ -344,7 +330,7 @@ static CURL_FORCEINLINE curl_uint64_t Curl_rotr64(curl_uint64_t value, * Size of the SHA-512/256 resulting digest in words. * This is the final digest size, not intermediate hash. */ -#define SHA512_256_DIGEST_SIZE_WORDS (SHA512_256_HASH_SIZE_WORDS / 2) +#define SHA512_256_DIGEST_SIZE_WORDS (SHA512_256_HASH_SIZE_WORDS / 2) /** * Size of the SHA-512/256 resulting digest in bytes @@ -378,22 +364,22 @@ struct Curl_sha512_256ctx { * compilers may automatically use fast load/store instruction for big * endian data on little endian machine. */ - curl_uint64_t H[SHA512_256_HASH_SIZE_WORDS]; + uint64_t H[SHA512_256_HASH_SIZE_WORDS]; /** * SHA-512/256 input data buffer. The buffer is properly aligned. Smart * compilers may automatically use fast load/store instruction for big * endian data on little endian machine. */ - curl_uint64_t buffer[SHA512_256_BLOCK_SIZE_WORDS]; + uint64_t buffer[SHA512_256_BLOCK_SIZE_WORDS]; /** * The number of bytes, lower part */ - curl_uint64_t count; + uint64_t count; /** * The number of bits, high part. Unlike lower part, this counts the number * of bits, not bytes. */ - curl_uint64_t count_bits_hi; + uint64_t count_bits_hi; }; /** @@ -401,7 +387,6 @@ struct Curl_sha512_256ctx { */ typedef struct Curl_sha512_256ctx Curl_sha512_256_ctx; - /** * Initialise structure for SHA-512/256 calculation. * @@ -410,119 +395,117 @@ typedef struct Curl_sha512_256ctx Curl_sha512_256_ctx; */ static CURLcode Curl_sha512_256_init(void *context) { - struct Curl_sha512_256ctx *const ctx = (struct Curl_sha512_256ctx *)context; + struct Curl_sha512_256ctx * const ctx = (struct Curl_sha512_256ctx *)context; /* Check whether the header and this file use the same numbers */ DEBUGASSERT(CURL_SHA512_256_DIGEST_LENGTH == CURL_SHA512_256_DIGEST_SIZE); - DEBUGASSERT(sizeof(curl_uint64_t) == 8); + DEBUGASSERT(sizeof(uint64_t) == 8); /* Initial hash values, see FIPS PUB 180-4 section 5.3.6.2 */ /* Values generated by "IV Generation Function" as described in * section 5.3.6 */ - ctx->H[0] = CURL_UINT64_C(0x22312194FC2BF72C); - ctx->H[1] = CURL_UINT64_C(0x9F555FA3C84C64C2); - ctx->H[2] = CURL_UINT64_C(0x2393B86B6F53B151); - ctx->H[3] = CURL_UINT64_C(0x963877195940EABD); - ctx->H[4] = CURL_UINT64_C(0x96283EE2A88EFFE3); - ctx->H[5] = CURL_UINT64_C(0xBE5E1E2553863992); - ctx->H[6] = CURL_UINT64_C(0x2B0199FC2C85B8AA); - ctx->H[7] = CURL_UINT64_C(0x0EB72DDC81C52CA2); + ctx->H[0] = UINT64_C(0x22312194FC2BF72C); + ctx->H[1] = UINT64_C(0x9F555FA3C84C64C2); + ctx->H[2] = UINT64_C(0x2393B86B6F53B151); + ctx->H[3] = UINT64_C(0x963877195940EABD); + ctx->H[4] = UINT64_C(0x96283EE2A88EFFE3); + ctx->H[5] = UINT64_C(0xBE5E1E2553863992); + ctx->H[6] = UINT64_C(0x2B0199FC2C85B8AA); + ctx->H[7] = UINT64_C(0x0EB72DDC81C52CA2); /* Initialise number of bytes and high part of number of bits. */ - ctx->count = CURL_UINT64_C(0); - ctx->count_bits_hi = CURL_UINT64_C(0); + ctx->count = UINT64_C(0); + ctx->count_bits_hi = UINT64_C(0); return CURLE_OK; } - /** * Base of the SHA-512/256 transformation. * Gets a full 128 bytes block of data and updates hash values; * @param H hash values * @param data the data buffer with #CURL_SHA512_256_BLOCK_SIZE bytes block */ -static -void Curl_sha512_256_transform(curl_uint64_t H[SHA512_256_HASH_SIZE_WORDS], - const void *data) +static void Curl_sha512_256_transform(uint64_t H[SHA512_256_HASH_SIZE_WORDS], + const void *data) { /* Working variables, see FIPS PUB 180-4 section 6.7, 6.4. */ - curl_uint64_t a = H[0]; - curl_uint64_t b = H[1]; - curl_uint64_t c = H[2]; - curl_uint64_t d = H[3]; - curl_uint64_t e = H[4]; - curl_uint64_t f = H[5]; - curl_uint64_t g = H[6]; - curl_uint64_t h = H[7]; + uint64_t a = H[0]; + uint64_t b = H[1]; + uint64_t c = H[2]; + uint64_t d = H[3]; + uint64_t e = H[4]; + uint64_t f = H[5]; + uint64_t g = H[6]; + uint64_t h = H[7]; /* Data buffer, used as a cyclic buffer. See FIPS PUB 180-4 section 5.2.2, 6.7, 6.4. */ - curl_uint64_t W[16]; + uint64_t W[16]; /* 'Ch' and 'Maj' macro functions are defined with widely-used optimization. See FIPS PUB 180-4 formulae 4.8, 4.9. */ -#define Sha512_Ch(x,y,z) ( (z) ^ ((x) & ((y) ^ (z))) ) -#define Sha512_Maj(x,y,z) ( ((x) & (y)) ^ ((z) & ((x) ^ (y))) ) +#define Sha512_Ch(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) +#define Sha512_Maj(x, y, z) (((x) & (y)) ^ ((z) & ((x) ^ (y)))) /* Four 'Sigma' macro functions. See FIPS PUB 180-4 formulae 4.10, 4.11, 4.12, 4.13. */ #define SIG0(x) \ - ( Curl_rotr64((x), 28) ^ Curl_rotr64((x), 34) ^ Curl_rotr64((x), 39) ) + (Curl_rotr64((x), 28) ^ Curl_rotr64((x), 34) ^ Curl_rotr64((x), 39)) #define SIG1(x) \ - ( Curl_rotr64((x), 14) ^ Curl_rotr64((x), 18) ^ Curl_rotr64((x), 41) ) -#define sig0(x) \ - ( Curl_rotr64((x), 1) ^ Curl_rotr64((x), 8) ^ ((x) >> 7) ) -#define sig1(x) \ - ( Curl_rotr64((x), 19) ^ Curl_rotr64((x), 61) ^ ((x) >> 6) ) + (Curl_rotr64((x), 14) ^ Curl_rotr64((x), 18) ^ Curl_rotr64((x), 41)) +#define sig0(x) \ + (Curl_rotr64((x), 1) ^ Curl_rotr64((x), 8) ^ ((x) >> 7)) +#define sig1(x) \ + (Curl_rotr64((x), 19) ^ Curl_rotr64((x), 61) ^ ((x) >> 6)) if(1) { unsigned int t; /* K constants array. See FIPS PUB 180-4 section 4.2.3 for K values. */ - static const curl_uint64_t K[80] = { - CURL_UINT64_C(0x428a2f98d728ae22), CURL_UINT64_C(0x7137449123ef65cd), - CURL_UINT64_C(0xb5c0fbcfec4d3b2f), CURL_UINT64_C(0xe9b5dba58189dbbc), - CURL_UINT64_C(0x3956c25bf348b538), CURL_UINT64_C(0x59f111f1b605d019), - CURL_UINT64_C(0x923f82a4af194f9b), CURL_UINT64_C(0xab1c5ed5da6d8118), - CURL_UINT64_C(0xd807aa98a3030242), CURL_UINT64_C(0x12835b0145706fbe), - CURL_UINT64_C(0x243185be4ee4b28c), CURL_UINT64_C(0x550c7dc3d5ffb4e2), - CURL_UINT64_C(0x72be5d74f27b896f), CURL_UINT64_C(0x80deb1fe3b1696b1), - CURL_UINT64_C(0x9bdc06a725c71235), CURL_UINT64_C(0xc19bf174cf692694), - CURL_UINT64_C(0xe49b69c19ef14ad2), CURL_UINT64_C(0xefbe4786384f25e3), - CURL_UINT64_C(0x0fc19dc68b8cd5b5), CURL_UINT64_C(0x240ca1cc77ac9c65), - CURL_UINT64_C(0x2de92c6f592b0275), CURL_UINT64_C(0x4a7484aa6ea6e483), - CURL_UINT64_C(0x5cb0a9dcbd41fbd4), CURL_UINT64_C(0x76f988da831153b5), - CURL_UINT64_C(0x983e5152ee66dfab), CURL_UINT64_C(0xa831c66d2db43210), - CURL_UINT64_C(0xb00327c898fb213f), CURL_UINT64_C(0xbf597fc7beef0ee4), - CURL_UINT64_C(0xc6e00bf33da88fc2), CURL_UINT64_C(0xd5a79147930aa725), - CURL_UINT64_C(0x06ca6351e003826f), CURL_UINT64_C(0x142929670a0e6e70), - CURL_UINT64_C(0x27b70a8546d22ffc), CURL_UINT64_C(0x2e1b21385c26c926), - CURL_UINT64_C(0x4d2c6dfc5ac42aed), CURL_UINT64_C(0x53380d139d95b3df), - CURL_UINT64_C(0x650a73548baf63de), CURL_UINT64_C(0x766a0abb3c77b2a8), - CURL_UINT64_C(0x81c2c92e47edaee6), CURL_UINT64_C(0x92722c851482353b), - CURL_UINT64_C(0xa2bfe8a14cf10364), CURL_UINT64_C(0xa81a664bbc423001), - CURL_UINT64_C(0xc24b8b70d0f89791), CURL_UINT64_C(0xc76c51a30654be30), - CURL_UINT64_C(0xd192e819d6ef5218), CURL_UINT64_C(0xd69906245565a910), - CURL_UINT64_C(0xf40e35855771202a), CURL_UINT64_C(0x106aa07032bbd1b8), - CURL_UINT64_C(0x19a4c116b8d2d0c8), CURL_UINT64_C(0x1e376c085141ab53), - CURL_UINT64_C(0x2748774cdf8eeb99), CURL_UINT64_C(0x34b0bcb5e19b48a8), - CURL_UINT64_C(0x391c0cb3c5c95a63), CURL_UINT64_C(0x4ed8aa4ae3418acb), - CURL_UINT64_C(0x5b9cca4f7763e373), CURL_UINT64_C(0x682e6ff3d6b2b8a3), - CURL_UINT64_C(0x748f82ee5defb2fc), CURL_UINT64_C(0x78a5636f43172f60), - CURL_UINT64_C(0x84c87814a1f0ab72), CURL_UINT64_C(0x8cc702081a6439ec), - CURL_UINT64_C(0x90befffa23631e28), CURL_UINT64_C(0xa4506cebde82bde9), - CURL_UINT64_C(0xbef9a3f7b2c67915), CURL_UINT64_C(0xc67178f2e372532b), - CURL_UINT64_C(0xca273eceea26619c), CURL_UINT64_C(0xd186b8c721c0c207), - CURL_UINT64_C(0xeada7dd6cde0eb1e), CURL_UINT64_C(0xf57d4f7fee6ed178), - CURL_UINT64_C(0x06f067aa72176fba), CURL_UINT64_C(0x0a637dc5a2c898a6), - CURL_UINT64_C(0x113f9804bef90dae), CURL_UINT64_C(0x1b710b35131c471b), - CURL_UINT64_C(0x28db77f523047d84), CURL_UINT64_C(0x32caab7b40c72493), - CURL_UINT64_C(0x3c9ebe0a15c9bebc), CURL_UINT64_C(0x431d67c49c100d4c), - CURL_UINT64_C(0x4cc5d4becb3e42b6), CURL_UINT64_C(0x597f299cfc657e2a), - CURL_UINT64_C(0x5fcb6fab3ad6faec), CURL_UINT64_C(0x6c44198c4a475817) + static const uint64_t K[80] = { + UINT64_C(0x428a2f98d728ae22), UINT64_C(0x7137449123ef65cd), + UINT64_C(0xb5c0fbcfec4d3b2f), UINT64_C(0xe9b5dba58189dbbc), + UINT64_C(0x3956c25bf348b538), UINT64_C(0x59f111f1b605d019), + UINT64_C(0x923f82a4af194f9b), UINT64_C(0xab1c5ed5da6d8118), + UINT64_C(0xd807aa98a3030242), UINT64_C(0x12835b0145706fbe), + UINT64_C(0x243185be4ee4b28c), UINT64_C(0x550c7dc3d5ffb4e2), + UINT64_C(0x72be5d74f27b896f), UINT64_C(0x80deb1fe3b1696b1), + UINT64_C(0x9bdc06a725c71235), UINT64_C(0xc19bf174cf692694), + UINT64_C(0xe49b69c19ef14ad2), UINT64_C(0xefbe4786384f25e3), + UINT64_C(0x0fc19dc68b8cd5b5), UINT64_C(0x240ca1cc77ac9c65), + UINT64_C(0x2de92c6f592b0275), UINT64_C(0x4a7484aa6ea6e483), + UINT64_C(0x5cb0a9dcbd41fbd4), UINT64_C(0x76f988da831153b5), + UINT64_C(0x983e5152ee66dfab), UINT64_C(0xa831c66d2db43210), + UINT64_C(0xb00327c898fb213f), UINT64_C(0xbf597fc7beef0ee4), + UINT64_C(0xc6e00bf33da88fc2), UINT64_C(0xd5a79147930aa725), + UINT64_C(0x06ca6351e003826f), UINT64_C(0x142929670a0e6e70), + UINT64_C(0x27b70a8546d22ffc), UINT64_C(0x2e1b21385c26c926), + UINT64_C(0x4d2c6dfc5ac42aed), UINT64_C(0x53380d139d95b3df), + UINT64_C(0x650a73548baf63de), UINT64_C(0x766a0abb3c77b2a8), + UINT64_C(0x81c2c92e47edaee6), UINT64_C(0x92722c851482353b), + UINT64_C(0xa2bfe8a14cf10364), UINT64_C(0xa81a664bbc423001), + UINT64_C(0xc24b8b70d0f89791), UINT64_C(0xc76c51a30654be30), + UINT64_C(0xd192e819d6ef5218), UINT64_C(0xd69906245565a910), + UINT64_C(0xf40e35855771202a), UINT64_C(0x106aa07032bbd1b8), + UINT64_C(0x19a4c116b8d2d0c8), UINT64_C(0x1e376c085141ab53), + UINT64_C(0x2748774cdf8eeb99), UINT64_C(0x34b0bcb5e19b48a8), + UINT64_C(0x391c0cb3c5c95a63), UINT64_C(0x4ed8aa4ae3418acb), + UINT64_C(0x5b9cca4f7763e373), UINT64_C(0x682e6ff3d6b2b8a3), + UINT64_C(0x748f82ee5defb2fc), UINT64_C(0x78a5636f43172f60), + UINT64_C(0x84c87814a1f0ab72), UINT64_C(0x8cc702081a6439ec), + UINT64_C(0x90befffa23631e28), UINT64_C(0xa4506cebde82bde9), + UINT64_C(0xbef9a3f7b2c67915), UINT64_C(0xc67178f2e372532b), + UINT64_C(0xca273eceea26619c), UINT64_C(0xd186b8c721c0c207), + UINT64_C(0xeada7dd6cde0eb1e), UINT64_C(0xf57d4f7fee6ed178), + UINT64_C(0x06f067aa72176fba), UINT64_C(0x0a637dc5a2c898a6), + UINT64_C(0x113f9804bef90dae), UINT64_C(0x1b710b35131c471b), + UINT64_C(0x28db77f523047d84), UINT64_C(0x32caab7b40c72493), + UINT64_C(0x3c9ebe0a15c9bebc), UINT64_C(0x431d67c49c100d4c), + UINT64_C(0x4cc5d4becb3e42b6), UINT64_C(0x597f299cfc657e2a), + UINT64_C(0x5fcb6fab3ad6faec), UINT64_C(0x6c44198c4a475817) }; /* One step of SHA-512/256 computation, @@ -535,38 +518,41 @@ void Curl_sha512_256_transform(curl_uint64_t H[SHA512_256_HASH_SIZE_WORDS], * Note: 'wt' must be used exactly one time in this macro as macro for 'wt' calculation may change other data as well every time when used. */ -#define SHA2STEP64(vA,vB,vC,vD,vE,vF,vG,vH,kt,wt) do { \ - (vD) += ((vH) += SIG1((vE)) + Sha512_Ch((vE),(vF),(vG)) + (kt) + (wt)); \ - (vH) += SIG0((vA)) + Sha512_Maj((vA),(vB),(vC)); } while (0) +#define SHA2STEP64(vA, vB, vC, vD, vE, vF, vG, vH, kt, wt) \ + do { \ + (vD) += ((vH) += SIG1((vE)) + Sha512_Ch((vE), (vF), (vG)) + (kt) + (wt)); \ + (vH) += SIG0((vA)) + Sha512_Maj((vA), (vB), (vC)); \ + } while(0) /* One step of SHA-512/256 computation with working variables rotation, see FIPS PUB 180-4 section 6.4.2 step 3. This macro version reassigns all working variables on each step. */ -#define SHA2STEP64RV(vA,vB,vC,vD,vE,vF,vG,vH,kt,wt) do { \ - curl_uint64_t tmp_h_ = (vH); \ - SHA2STEP64((vA),(vB),(vC),(vD),(vE),(vF),(vG),tmp_h_,(kt),(wt)); \ - (vH) = (vG); \ - (vG) = (vF); \ - (vF) = (vE); \ - (vE) = (vD); \ - (vD) = (vC); \ - (vC) = (vB); \ - (vB) = (vA); \ - (vA) = tmp_h_; } while(0) +#define SHA2STEP64RV(vA, vB, vC, vD, vE, vF, vG, vH, kt, wt) \ + do { \ + uint64_t tmp_h_ = (vH); \ + SHA2STEP64((vA), (vB), (vC), (vD), (vE), (vF), (vG), tmp_h_, (kt), (wt)); \ + (vH) = (vG); \ + (vG) = (vF); \ + (vF) = (vE); \ + (vE) = (vD); \ + (vD) = (vC); \ + (vC) = (vB); \ + (vB) = (vA); \ + (vA) = tmp_h_; \ + } while(0) /* Get value of W(t) from input data buffer for 0 <= t <= 15, See FIPS PUB 180-4 section 6.2. Input data must be read in big-endian bytes order, see FIPS PUB 180-4 section 3.1.2. */ -#define SHA512_GET_W_FROM_DATA(buf,t) \ - CURL_GET_64BIT_BE( \ - ((const unsigned char*) (buf)) + (t) * SHA512_256_BYTES_IN_WORD) +#define SHA512_GET_W_FROM_DATA(buf, t) \ + CURL_GET_64BIT_BE(((const uint8_t *)(buf)) + (t) * SHA512_256_BYTES_IN_WORD) /* During first 16 steps, before making any calculation on each step, the W element is read from the input data buffer as a big-endian value and stored in the array of W elements. */ for(t = 0; t < 16; ++t) { - SHA2STEP64RV(a, b, c, d, e, f, g, h, K[t], \ + SHA2STEP64RV(a, b, c, d, e, f, g, h, K[t], W[t] = SHA512_GET_W_FROM_DATA(data, t)); } @@ -575,15 +561,15 @@ void Curl_sha512_256_transform(curl_uint64_t H[SHA512_256_HASH_SIZE_WORDS], As only the last 16 'W' are used in calculations, it is possible to use 16 elements array of W as a cyclic buffer. Note: ((t-16) & 15) have same value as (t & 15) */ -#define Wgen(w,t) \ - (curl_uint64_t)( (w)[(t - 16) & 15] + sig1((w)[((t) - 2) & 15]) \ - + (w)[((t) - 7) & 15] + sig0((w)[((t) - 15) & 15]) ) +#define Wgen(w, t) \ + (uint64_t)((w)[((t) - 16) & 15] + sig1((w)[((t) - 2) & 15]) + \ + (w)[((t) - 7) & 15] + sig0((w)[((t) - 15) & 15])) /* During the last 64 steps, before making any calculation on each step, current W element is generated from other W elements of the cyclic buffer and the generated value is stored back in the cyclic buffer. */ for(t = 16; t < 80; ++t) { - SHA2STEP64RV(a, b, c, d, e, f, g, h, K[t], \ + SHA2STEP64RV(a, b, c, d, e, f, g, h, K[t], W[t & 15] = Wgen(W, t)); } } @@ -600,7 +586,6 @@ void Curl_sha512_256_transform(curl_uint64_t H[SHA512_256_HASH_SIZE_WORDS], H[7] += h; } - /** * Process portion of bytes. * @@ -613,10 +598,10 @@ static CURLcode Curl_sha512_256_update(void *context, const unsigned char *data, size_t length) { - unsigned int bytes_have; /**< Number of bytes in the context buffer */ - struct Curl_sha512_256ctx *const ctx = (struct Curl_sha512_256ctx *)context; + unsigned int bytes_have; /* Number of bytes in the context buffer */ + struct Curl_sha512_256ctx * const ctx = (struct Curl_sha512_256ctx *)context; /* the void pointer here is required to mute Intel compiler warning */ - void *const ctx_buf = ctx->buffer; + void * const ctx_buf = ctx->buffer; DEBUGASSERT((data != NULL) || (length == 0)); @@ -625,21 +610,19 @@ static CURLcode Curl_sha512_256_update(void *context, /* Note: (count & (CURL_SHA512_256_BLOCK_SIZE-1)) equals (count % CURL_SHA512_256_BLOCK_SIZE) for this block size. */ - bytes_have = (unsigned int) (ctx->count & (CURL_SHA512_256_BLOCK_SIZE - 1)); + bytes_have = (unsigned int)(ctx->count & (CURL_SHA512_256_BLOCK_SIZE - 1)); ctx->count += length; if(length > ctx->count) ctx->count_bits_hi += 1U << 3; /* Value wrap */ ctx->count_bits_hi += ctx->count >> 61; - ctx->count &= CURL_UINT64_C(0x1FFFFFFFFFFFFFFF); + ctx->count &= UINT64_C(0x1FFFFFFFFFFFFFFF); if(bytes_have) { unsigned int bytes_left = CURL_SHA512_256_BLOCK_SIZE - bytes_have; if(length >= bytes_left) { /* Combine new data with data in the buffer and process the full block. */ - memcpy(((unsigned char *) ctx_buf) + bytes_have, - data, - bytes_left); + memcpy((unsigned char *)ctx_buf + bytes_have, data, bytes_left); data += bytes_left; length -= bytes_left; Curl_sha512_256_transform(ctx->H, ctx->buffer); @@ -658,13 +641,12 @@ static CURLcode Curl_sha512_256_update(void *context, if(length) { /* Copy incomplete block of new data (if any) to the buffer. */ - memcpy(((unsigned char *) ctx_buf) + bytes_have, data, length); + memcpy((unsigned char *)ctx_buf + bytes_have, data, length); } return CURLE_OK; } - /** * Size of "length" insertion in bits. * See FIPS PUB 180-4 section 5.1.2. @@ -686,11 +668,11 @@ static CURLcode Curl_sha512_256_update(void *context, */ static CURLcode Curl_sha512_256_finish(unsigned char *digest, void *context) { - struct Curl_sha512_256ctx *const ctx = (struct Curl_sha512_256ctx *)context; - curl_uint64_t num_bits; /**< Number of processed bits */ - unsigned int bytes_have; /**< Number of bytes in the context buffer */ + struct Curl_sha512_256ctx * const ctx = (struct Curl_sha512_256ctx *)context; + uint64_t num_bits; /* Number of processed bits */ + unsigned int bytes_have; /* Number of bytes in the context buffer */ /* the void pointer here is required to mute Intel compiler warning */ - void *const ctx_buf = ctx->buffer; + void * const ctx_buf = ctx->buffer; /* Memorise the number of processed bits. The padding and other data added here during the postprocessing must @@ -699,7 +681,7 @@ static CURLcode Curl_sha512_256_finish(unsigned char *digest, void *context) /* Note: (count & (CURL_SHA512_256_BLOCK_SIZE-1)) equals (count % CURL_SHA512_256_BLOCK_SIZE) for this block size. */ - bytes_have = (unsigned int) (ctx->count & (CURL_SHA512_256_BLOCK_SIZE - 1)); + bytes_have = (unsigned int)(ctx->count & (CURL_SHA512_256_BLOCK_SIZE - 1)); /* Input data must be padded with a single bit "1", then with zeros and the finally the length of data in bits must be added as the final bytes @@ -711,13 +693,13 @@ static CURLcode Curl_sha512_256_finish(unsigned char *digest, void *context) predefined (0x80). */ /* Buffer always have space at least for one byte (as full buffers are processed when formed). */ - ((unsigned char *) ctx_buf)[bytes_have++] = 0x80U; + ((unsigned char *)ctx_buf)[bytes_have++] = 0x80U; if(CURL_SHA512_256_BLOCK_SIZE - bytes_have < SHA512_256_SIZE_OF_LEN_ADD) { /* No space in the current block to put the total length of message. Pad the current block with zeros and process it. */ if(bytes_have < CURL_SHA512_256_BLOCK_SIZE) - memset(((unsigned char *) ctx_buf) + bytes_have, 0, + memset((unsigned char *)ctx_buf + bytes_have, 0, CURL_SHA512_256_BLOCK_SIZE - bytes_have); /* Process the full block. */ Curl_sha512_256_transform(ctx->H, ctx->buffer); @@ -726,31 +708,29 @@ static CURLcode Curl_sha512_256_finish(unsigned char *digest, void *context) } /* Pad the rest of the buffer with zeros. */ - memset(((unsigned char *) ctx_buf) + bytes_have, 0, + memset((unsigned char *)ctx_buf + bytes_have, 0, CURL_SHA512_256_BLOCK_SIZE - SHA512_256_SIZE_OF_LEN_ADD - bytes_have); /* Put high part of number of bits in processed message and then lower part of number of bits as big-endian values. See FIPS PUB 180-4 section 5.1.2. */ /* Note: the target location is predefined and buffer is always aligned */ - CURL_PUT_64BIT_BE(((unsigned char *) ctx_buf) \ - + CURL_SHA512_256_BLOCK_SIZE \ - - SHA512_256_SIZE_OF_LEN_ADD, \ - ctx->count_bits_hi); - CURL_PUT_64BIT_BE(((unsigned char *) ctx_buf) \ - + CURL_SHA512_256_BLOCK_SIZE \ - - SHA512_256_SIZE_OF_LEN_ADD \ - + SHA512_256_BYTES_IN_WORD, \ - num_bits); + CURL_PUT_64BIT_BE((unsigned char *)ctx_buf + + CURL_SHA512_256_BLOCK_SIZE - SHA512_256_SIZE_OF_LEN_ADD, + ctx->count_bits_hi); + CURL_PUT_64BIT_BE((unsigned char *)ctx_buf + + CURL_SHA512_256_BLOCK_SIZE - SHA512_256_SIZE_OF_LEN_ADD + + SHA512_256_BYTES_IN_WORD, + num_bits); /* Process the full final block. */ Curl_sha512_256_transform(ctx->H, ctx->buffer); /* Put in BE mode the leftmost part of the hash as the final digest. See FIPS PUB 180-4 section 6.7. */ - CURL_PUT_64BIT_BE((digest + 0 * SHA512_256_BYTES_IN_WORD), ctx->H[0]); - CURL_PUT_64BIT_BE((digest + 1 * SHA512_256_BYTES_IN_WORD), ctx->H[1]); - CURL_PUT_64BIT_BE((digest + 2 * SHA512_256_BYTES_IN_WORD), ctx->H[2]); - CURL_PUT_64BIT_BE((digest + 3 * SHA512_256_BYTES_IN_WORD), ctx->H[3]); + CURL_PUT_64BIT_BE(digest + 0 * SHA512_256_BYTES_IN_WORD, ctx->H[0]); + CURL_PUT_64BIT_BE(digest + 1 * SHA512_256_BYTES_IN_WORD, ctx->H[1]); + CURL_PUT_64BIT_BE(digest + 2 * SHA512_256_BYTES_IN_WORD, ctx->H[2]); + CURL_PUT_64BIT_BE(digest + 3 * SHA512_256_BYTES_IN_WORD, ctx->H[3]); /* Erase potentially sensitive data. */ memset(ctx, 0, sizeof(struct Curl_sha512_256ctx)); @@ -760,7 +740,6 @@ static CURLcode Curl_sha512_256_finish(unsigned char *digest, void *context) #endif /* Local SHA-512/256 code */ - /** * Compute SHA-512/256 hash for the given data in one function call * @param[out] output the pointer to put the hash @@ -778,7 +757,7 @@ CURLcode Curl_sha512_256it(unsigned char *output, const unsigned char *input, if(res != CURLE_OK) return res; - res = Curl_sha512_256_update(&ctx, (const void *) input, input_size); + res = Curl_sha512_256_update(&ctx, (const void *)input, input_size); if(res != CURLE_OK) { (void)Curl_sha512_256_finish(output, &ctx); diff --git a/vendor/hydra/vendor/curl/lib/curl_sha512_256.h b/vendor/hydra/vendor/curl/lib/curl_sha512_256.h index a84e77bc..ddaf8be9 100644 --- a/vendor/hydra/vendor/curl/lib/curl_sha512_256.h +++ b/vendor/hydra/vendor/curl/lib/curl_sha512_256.h @@ -23,10 +23,10 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ +#include "curl_setup.h" #if !defined(CURL_DISABLE_DIGEST_AUTH) && !defined(CURL_DISABLE_SHA512_256) -#include #include "curl_hmac.h" #define CURL_HAVE_SHA512_256 @@ -35,9 +35,8 @@ extern const struct HMAC_params Curl_HMAC_SHA512_256[1]; #define CURL_SHA512_256_DIGEST_LENGTH 32 -CURLcode -Curl_sha512_256it(unsigned char *output, const unsigned char *input, - size_t input_size); +CURLcode Curl_sha512_256it(unsigned char *output, const unsigned char *input, + size_t input_size); #endif /* !CURL_DISABLE_DIGEST_AUTH && !CURL_DISABLE_SHA512_256 */ diff --git a/vendor/hydra/vendor/curl/lib/share.c b/vendor/hydra/vendor/curl/lib/curl_share.c similarity index 89% rename from vendor/hydra/vendor/curl/lib/share.c rename to vendor/hydra/vendor/curl/lib/curl_share.c index 711622a1..3ff27556 100644 --- a/vendor/hydra/vendor/curl/lib/share.c +++ b/vendor/hydra/vendor/curl/lib/curl_share.c @@ -21,34 +21,26 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include #include "urldata.h" #include "connect.h" -#include "share.h" -#include "psl.h" +#include "curl_share.h" #include "vtls/vtls.h" #include "vtls/vtls_scache.h" #include "hsts.h" #include "url.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - -CURLSH * -curl_share_init(void) +CURLSH *curl_share_init(void) { - struct Curl_share *share = calloc(1, sizeof(struct Curl_share)); + struct Curl_share *share = curlx_calloc(1, sizeof(struct Curl_share)); if(share) { share->magic = CURL_GOOD_SHARE; share->specifier |= (1 << CURL_LOCK_DATA_SHARE); Curl_dnscache_init(&share->dnscache, 23); share->admin = curl_easy_init(); if(!share->admin) { - free(share); + curlx_free(share); return NULL; } /* admin handles have mid 0 */ @@ -64,8 +56,7 @@ curl_share_init(void) } #undef curl_share_setopt -CURLSHcode -curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) +CURLSHcode curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) { va_list param; int type; @@ -97,11 +88,11 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) case CURL_LOCK_DATA_COOKIE: #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES) if(!share->cookies) { - share->cookies = Curl_cookie_init(NULL, NULL, NULL, TRUE); + share->cookies = Curl_cookie_init(); if(!share->cookies) res = CURLSHE_NOMEM; } -#else /* CURL_DISABLE_HTTP */ +#else /* CURL_DISABLE_HTTP || CURL_DISABLE_COOKIES */ res = CURLSHE_NOT_BUILT_IN; #endif break; @@ -113,7 +104,7 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) if(!share->hsts) res = CURLSHE_NOMEM; } -#else /* CURL_DISABLE_HSTS */ +#else /* CURL_DISABLE_HSTS */ res = CURLSHE_NOT_BUILT_IN; #endif break; @@ -168,7 +159,7 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) Curl_cookie_cleanup(share->cookies); share->cookies = NULL; } -#else /* CURL_DISABLE_HTTP */ +#else /* CURL_DISABLE_HTTP || CURL_DISABLE_COOKIES */ res = CURLSHE_NOT_BUILT_IN; #endif break; @@ -178,7 +169,7 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) if(share->hsts) { Curl_hsts_cleanup(&share->hsts); } -#else /* CURL_DISABLE_HSTS */ +#else /* CURL_DISABLE_HSTS */ res = CURLSHE_NOT_BUILT_IN; #endif break; @@ -228,8 +219,7 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) return res; } -CURLSHcode -curl_share_cleanup(CURLSH *sh) +CURLSHcode curl_share_cleanup(CURLSH *sh) { struct Curl_share *share = sh; if(!GOOD_SHARE_HANDLE(share)) @@ -272,15 +262,13 @@ curl_share_cleanup(CURLSH *sh) if(share->unlockfunc) share->unlockfunc(NULL, CURL_LOCK_DATA_SHARE, share->clientdata); share->magic = 0; - free(share); + curlx_free(share); return CURLSHE_OK; } - -CURLSHcode -Curl_share_lock(struct Curl_easy *data, curl_lock_data type, - curl_lock_access accesstype) +CURLSHcode Curl_share_lock(struct Curl_easy *data, curl_lock_data type, + curl_lock_access accesstype) { struct Curl_share *share = data->share; @@ -296,8 +284,7 @@ Curl_share_lock(struct Curl_easy *data, curl_lock_data type, return CURLSHE_OK; } -CURLSHcode -Curl_share_unlock(struct Curl_easy *data, curl_lock_data type) +CURLSHcode Curl_share_unlock(struct Curl_easy *data, curl_lock_data type) { struct Curl_share *share = data->share; @@ -306,7 +293,7 @@ Curl_share_unlock(struct Curl_easy *data, curl_lock_data type) if(share->specifier & (unsigned int)(1 << type)) { if(share->unlockfunc) /* only call this if set! */ - share->unlockfunc (data, type, share->clientdata); + share->unlockfunc(data, type, share->clientdata); } return CURLSHE_OK; diff --git a/vendor/hydra/vendor/curl/lib/share.h b/vendor/hydra/vendor/curl/lib/curl_share.h similarity index 93% rename from vendor/hydra/vendor/curl/lib/share.h rename to vendor/hydra/vendor/curl/lib/curl_share.h index 974c99dc..fcd9e329 100644 --- a/vendor/hydra/vendor/curl/lib/share.h +++ b/vendor/hydra/vendor/curl/lib/curl_share.h @@ -23,9 +23,8 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include + #include "cookie.h" #include "psl.h" #include "urldata.h" @@ -38,7 +37,7 @@ struct Curl_ssl_scache; #define GOOD_SHARE_HANDLE(x) ((x) && (x)->magic == CURL_GOOD_SHARE) #define CURL_SHARE_KEEP_CONNECT(s) \ - ((s) && ((s)->specifier & (1<< CURL_LOCK_DATA_CONNECT))) + ((s) && ((s)->specifier & (1 << CURL_LOCK_DATA_CONNECT))) /* this struct is libcurl-private, do not export details */ struct Curl_share { @@ -71,8 +70,8 @@ CURLSHcode Curl_share_lock(struct Curl_easy *, curl_lock_data, CURLSHcode Curl_share_unlock(struct Curl_easy *, curl_lock_data); /* convenience macro to check if this handle is using a shared SSL spool */ -#define CURL_SHARE_ssl_scache(data) (data->share && \ +#define CURL_SHARE_ssl_scache(data) (data->share && \ (data->share->specifier & \ - (1< #include "curl_sspi.h" #include "strdup.h" #include "curlx/multibyte.h" -#include "system_win32.h" -#include "curlx/warnless.h" - -/* The last #include files should be: */ -#include "curl_memory.h" -#include "memdebug.h" /* Pointer to SSPI dispatch table */ PSecurityFunctionTable Curl_pSecFn = NULL; @@ -62,11 +54,7 @@ CURLcode Curl_sspi_global_init(void) /* If security interface is not yet initialized try to do this */ if(!Curl_pSecFn) { /* Get pointer to Security Service Provider Interface dispatch table */ -#ifdef __MINGW32CE__ - Curl_pSecFn = InitSecurityInterfaceW(); -#else Curl_pSecFn = InitSecurityInterface(); -#endif if(!Curl_pSecFn) return CURLE_FAILED_INIT; } @@ -138,43 +126,54 @@ CURLcode Curl_create_sspi_identity(const char *userp, const char *passwdp, } /* Setup the identity's user and length */ - dup_user.tchar_ptr = Curl_tcsdup(user.tchar_ptr); + dup_user.tchar_ptr = curlx_tcsdup(user.tchar_ptr); if(!dup_user.tchar_ptr) { - curlx_unicodefree(useranddomain.tchar_ptr); + curlx_free(useranddomain.tchar_ptr); return CURLE_OUT_OF_MEMORY; } - identity->User = dup_user.tbyte_ptr; - identity->UserLength = curlx_uztoul(_tcslen(dup_user.tchar_ptr)); - dup_user.tchar_ptr = NULL; /* Setup the identity's domain and length */ - dup_domain.tchar_ptr = malloc(sizeof(TCHAR) * (domlen + 1)); + dup_domain.tchar_ptr = curlx_malloc(sizeof(TCHAR) * (domlen + 1)); if(!dup_domain.tchar_ptr) { - curlx_unicodefree(useranddomain.tchar_ptr); + curlx_free(dup_user.tchar_ptr); + curlx_free(useranddomain.tchar_ptr); + return CURLE_OUT_OF_MEMORY; + } + if(_tcsncpy_s(dup_domain.tchar_ptr, domlen + 1, domain.tchar_ptr, domlen)) { + curlx_free(dup_user.tchar_ptr); + curlx_free(dup_domain.tchar_ptr); + curlx_free(useranddomain.tchar_ptr); return CURLE_OUT_OF_MEMORY; } - _tcsncpy(dup_domain.tchar_ptr, domain.tchar_ptr, domlen); - *(dup_domain.tchar_ptr + domlen) = TEXT('\0'); - identity->Domain = dup_domain.tbyte_ptr; - identity->DomainLength = curlx_uztoul(domlen); - dup_domain.tchar_ptr = NULL; - curlx_unicodefree(useranddomain.tchar_ptr); + curlx_free(useranddomain.tchar_ptr); /* Setup the identity's password and length */ passwd.tchar_ptr = curlx_convert_UTF8_to_tchar(passwdp); - if(!passwd.tchar_ptr) + if(!passwd.tchar_ptr) { + curlx_free(dup_user.tchar_ptr); + curlx_free(dup_domain.tchar_ptr); return CURLE_OUT_OF_MEMORY; - dup_passwd.tchar_ptr = Curl_tcsdup(passwd.tchar_ptr); + } + dup_passwd.tchar_ptr = curlx_tcsdup(passwd.tchar_ptr); if(!dup_passwd.tchar_ptr) { - curlx_unicodefree(passwd.tchar_ptr); + curlx_free(dup_user.tchar_ptr); + curlx_free(dup_domain.tchar_ptr); + curlx_free(passwd.tchar_ptr); return CURLE_OUT_OF_MEMORY; } identity->Password = dup_passwd.tbyte_ptr; identity->PasswordLength = curlx_uztoul(_tcslen(dup_passwd.tchar_ptr)); dup_passwd.tchar_ptr = NULL; - curlx_unicodefree(passwd.tchar_ptr); + curlx_free(passwd.tchar_ptr); + + identity->User = dup_user.tbyte_ptr; + identity->UserLength = curlx_uztoul(_tcslen(dup_user.tchar_ptr)); + dup_user.tchar_ptr = NULL; + identity->Domain = dup_domain.tbyte_ptr; + identity->DomainLength = curlx_uztoul(domlen); + dup_domain.tchar_ptr = NULL; /* Setup the identity's flags */ identity->Flags = (unsigned long) diff --git a/vendor/hydra/vendor/curl/lib/curl_sspi.h b/vendor/hydra/vendor/curl/lib/curl_sspi.h index 8ecd81fd..0fba5103 100644 --- a/vendor/hydra/vendor/curl/lib/curl_sspi.h +++ b/vendor/hydra/vendor/curl/lib/curl_sspi.h @@ -23,13 +23,10 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifdef USE_WINDOWS_SSPI -#include - /* * When including the following three headers, it is mandatory to define either * SECURITY_WIN32 or SECURITY_KERNEL, indicating who is compiling the code. @@ -70,225 +67,6 @@ extern PSecurityFunctionTable Curl_pSecFn; #define ISC_REQ_USE_HTTP_STYLE 0x01000000 #endif -#ifdef __MINGW32CE__ -#ifndef ISC_RET_REPLAY_DETECT -#define ISC_RET_REPLAY_DETECT 0x00000004 -#endif -#ifndef ISC_RET_SEQUENCE_DETECT -#define ISC_RET_SEQUENCE_DETECT 0x00000008 -#endif -#ifndef ISC_RET_CONFIDENTIALITY -#define ISC_RET_CONFIDENTIALITY 0x00000010 -#endif -#ifndef ISC_RET_ALLOCATED_MEMORY -#define ISC_RET_ALLOCATED_MEMORY 0x00000100 -#endif -#ifndef ISC_RET_STREAM -#define ISC_RET_STREAM 0x00008000 -#endif - -#ifndef SEC_E_INSUFFICIENT_MEMORY -#define SEC_E_INSUFFICIENT_MEMORY ((HRESULT)0x80090300L) -#endif -#ifndef SEC_E_INVALID_HANDLE -#define SEC_E_INVALID_HANDLE ((HRESULT)0x80090301L) -#endif -#ifndef SEC_E_UNSUPPORTED_FUNCTION -#define SEC_E_UNSUPPORTED_FUNCTION ((HRESULT)0x80090302L) -#endif -#ifndef SEC_E_TARGET_UNKNOWN -#define SEC_E_TARGET_UNKNOWN ((HRESULT)0x80090303L) -#endif -#ifndef SEC_E_INTERNAL_ERROR -#define SEC_E_INTERNAL_ERROR ((HRESULT)0x80090304L) -#endif -#ifndef SEC_E_SECPKG_NOT_FOUND -#define SEC_E_SECPKG_NOT_FOUND ((HRESULT)0x80090305L) -#endif -#ifndef SEC_E_NOT_OWNER -#define SEC_E_NOT_OWNER ((HRESULT)0x80090306L) -#endif -#ifndef SEC_E_CANNOT_INSTALL -#define SEC_E_CANNOT_INSTALL ((HRESULT)0x80090307L) -#endif -#ifndef SEC_E_INVALID_TOKEN -#define SEC_E_INVALID_TOKEN ((HRESULT)0x80090308L) -#endif -#ifndef SEC_E_CANNOT_PACK -#define SEC_E_CANNOT_PACK ((HRESULT)0x80090309L) -#endif -#ifndef SEC_E_QOP_NOT_SUPPORTED -#define SEC_E_QOP_NOT_SUPPORTED ((HRESULT)0x8009030AL) -#endif -#ifndef SEC_E_NO_IMPERSONATION -#define SEC_E_NO_IMPERSONATION ((HRESULT)0x8009030BL) -#endif -#ifndef SEC_E_LOGON_DENIED -#define SEC_E_LOGON_DENIED ((HRESULT)0x8009030CL) -#endif -#ifndef SEC_E_UNKNOWN_CREDENTIALS -#define SEC_E_UNKNOWN_CREDENTIALS ((HRESULT)0x8009030DL) -#endif -#ifndef SEC_E_NO_CREDENTIALS -#define SEC_E_NO_CREDENTIALS ((HRESULT)0x8009030EL) -#endif -#ifndef SEC_E_MESSAGE_ALTERED -#define SEC_E_MESSAGE_ALTERED ((HRESULT)0x8009030FL) -#endif -#ifndef SEC_E_OUT_OF_SEQUENCE -#define SEC_E_OUT_OF_SEQUENCE ((HRESULT)0x80090310L) -#endif -#ifndef SEC_E_NO_AUTHENTICATING_AUTHORITY -#define SEC_E_NO_AUTHENTICATING_AUTHORITY ((HRESULT)0x80090311L) -#endif -#ifndef SEC_E_BAD_PKGID -#define SEC_E_BAD_PKGID ((HRESULT)0x80090316L) -#endif -#ifndef SEC_E_CONTEXT_EXPIRED -#define SEC_E_CONTEXT_EXPIRED ((HRESULT)0x80090317L) -#endif -#ifndef SEC_E_INCOMPLETE_MESSAGE -#define SEC_E_INCOMPLETE_MESSAGE ((HRESULT)0x80090318L) -#endif -#ifndef SEC_E_INCOMPLETE_CREDENTIALS -#define SEC_E_INCOMPLETE_CREDENTIALS ((HRESULT)0x80090320L) -#endif -#ifndef SEC_E_BUFFER_TOO_SMALL -#define SEC_E_BUFFER_TOO_SMALL ((HRESULT)0x80090321L) -#endif -#ifndef SEC_E_WRONG_PRINCIPAL -#define SEC_E_WRONG_PRINCIPAL ((HRESULT)0x80090322L) -#endif -#ifndef SEC_E_TIME_SKEW -#define SEC_E_TIME_SKEW ((HRESULT)0x80090324L) -#endif -#ifndef SEC_E_UNTRUSTED_ROOT -#define SEC_E_UNTRUSTED_ROOT ((HRESULT)0x80090325L) -#endif -#ifndef SEC_E_ILLEGAL_MESSAGE -#define SEC_E_ILLEGAL_MESSAGE ((HRESULT)0x80090326L) -#endif -#ifndef SEC_E_CERT_UNKNOWN -#define SEC_E_CERT_UNKNOWN ((HRESULT)0x80090327L) -#endif -#ifndef SEC_E_CERT_EXPIRED -#define SEC_E_CERT_EXPIRED ((HRESULT)0x80090328L) -#endif -#ifndef SEC_E_ENCRYPT_FAILURE -#define SEC_E_ENCRYPT_FAILURE ((HRESULT)0x80090329L) -#endif -#ifndef SEC_E_DECRYPT_FAILURE -#define SEC_E_DECRYPT_FAILURE ((HRESULT)0x80090330L) -#endif -#ifndef SEC_E_ALGORITHM_MISMATCH -#define SEC_E_ALGORITHM_MISMATCH ((HRESULT)0x80090331L) -#endif -#ifndef SEC_E_SECURITY_QOS_FAILED -#define SEC_E_SECURITY_QOS_FAILED ((HRESULT)0x80090332L) -#endif -#ifndef SEC_E_UNFINISHED_CONTEXT_DELETED -#define SEC_E_UNFINISHED_CONTEXT_DELETED ((HRESULT)0x80090333L) -#endif -#ifndef SEC_E_NO_TGT_REPLY -#define SEC_E_NO_TGT_REPLY ((HRESULT)0x80090334L) -#endif -#ifndef SEC_E_NO_IP_ADDRESSES -#define SEC_E_NO_IP_ADDRESSES ((HRESULT)0x80090335L) -#endif -#ifndef SEC_E_WRONG_CREDENTIAL_HANDLE -#define SEC_E_WRONG_CREDENTIAL_HANDLE ((HRESULT)0x80090336L) -#endif -#ifndef SEC_E_CRYPTO_SYSTEM_INVALID -#define SEC_E_CRYPTO_SYSTEM_INVALID ((HRESULT)0x80090337L) -#endif -#ifndef SEC_E_MAX_REFERRALS_EXCEEDED -#define SEC_E_MAX_REFERRALS_EXCEEDED ((HRESULT)0x80090338L) -#endif -#ifndef SEC_E_MUST_BE_KDC -#define SEC_E_MUST_BE_KDC ((HRESULT)0x80090339L) -#endif -#ifndef SEC_E_STRONG_CRYPTO_NOT_SUPPORTED -#define SEC_E_STRONG_CRYPTO_NOT_SUPPORTED ((HRESULT)0x8009033AL) -#endif -#ifndef SEC_E_TOO_MANY_PRINCIPALS -#define SEC_E_TOO_MANY_PRINCIPALS ((HRESULT)0x8009033BL) -#endif -#ifndef SEC_E_NO_PA_DATA -#define SEC_E_NO_PA_DATA ((HRESULT)0x8009033CL) -#endif -#ifndef SEC_E_PKINIT_NAME_MISMATCH -#define SEC_E_PKINIT_NAME_MISMATCH ((HRESULT)0x8009033DL) -#endif -#ifndef SEC_E_SMARTCARD_LOGON_REQUIRED -#define SEC_E_SMARTCARD_LOGON_REQUIRED ((HRESULT)0x8009033EL) -#endif -#ifndef SEC_E_SHUTDOWN_IN_PROGRESS -#define SEC_E_SHUTDOWN_IN_PROGRESS ((HRESULT)0x8009033FL) -#endif -#ifndef SEC_E_KDC_INVALID_REQUEST -#define SEC_E_KDC_INVALID_REQUEST ((HRESULT)0x80090340L) -#endif -#ifndef SEC_E_KDC_UNABLE_TO_REFER -#define SEC_E_KDC_UNABLE_TO_REFER ((HRESULT)0x80090341L) -#endif -#ifndef SEC_E_KDC_UNKNOWN_ETYPE -#define SEC_E_KDC_UNKNOWN_ETYPE ((HRESULT)0x80090342L) -#endif -#ifndef SEC_E_UNSUPPORTED_PREAUTH -#define SEC_E_UNSUPPORTED_PREAUTH ((HRESULT)0x80090343L) -#endif -#ifndef SEC_E_DELEGATION_REQUIRED -#define SEC_E_DELEGATION_REQUIRED ((HRESULT)0x80090345L) -#endif -#ifndef SEC_E_BAD_BINDINGS -#define SEC_E_BAD_BINDINGS ((HRESULT)0x80090346L) -#endif -#ifndef SEC_E_MULTIPLE_ACCOUNTS -#define SEC_E_MULTIPLE_ACCOUNTS ((HRESULT)0x80090347L) -#endif -#ifndef SEC_E_NO_KERB_KEY -#define SEC_E_NO_KERB_KEY ((HRESULT)0x80090348L) -#endif -#ifndef SEC_E_CERT_WRONG_USAGE -#define SEC_E_CERT_WRONG_USAGE ((HRESULT)0x80090349L) -#endif -#ifndef SEC_E_DOWNGRADE_DETECTED -#define SEC_E_DOWNGRADE_DETECTED ((HRESULT)0x80090350L) -#endif -#ifndef SEC_E_SMARTCARD_CERT_REVOKED -#define SEC_E_SMARTCARD_CERT_REVOKED ((HRESULT)0x80090351L) -#endif -#ifndef SEC_E_ISSUING_CA_UNTRUSTED -#define SEC_E_ISSUING_CA_UNTRUSTED ((HRESULT)0x80090352L) -#endif -#ifndef SEC_E_REVOCATION_OFFLINE_C -#define SEC_E_REVOCATION_OFFLINE_C ((HRESULT)0x80090353L) -#endif -#ifndef SEC_E_PKINIT_CLIENT_FAILURE -#define SEC_E_PKINIT_CLIENT_FAILURE ((HRESULT)0x80090354L) -#endif -#ifndef SEC_E_SMARTCARD_CERT_EXPIRED -#define SEC_E_SMARTCARD_CERT_EXPIRED ((HRESULT)0x80090355L) -#endif -#ifndef SEC_E_NO_S4U_PROT_SUPPORT -#define SEC_E_NO_S4U_PROT_SUPPORT ((HRESULT)0x80090356L) -#endif -#ifndef SEC_E_CROSSREALM_DELEGATION_FAILURE -#define SEC_E_CROSSREALM_DELEGATION_FAILURE ((HRESULT)0x80090357L) -#endif -#ifndef SEC_E_REVOCATION_OFFLINE_KDC -#define SEC_E_REVOCATION_OFFLINE_KDC ((HRESULT)0x80090358L) -#endif -#ifndef SEC_E_ISSUING_CA_UNTRUSTED_KDC -#define SEC_E_ISSUING_CA_UNTRUSTED_KDC ((HRESULT)0x80090359L) -#endif -#ifndef SEC_E_KDC_CERT_EXPIRED -#define SEC_E_KDC_CERT_EXPIRED ((HRESULT)0x8009035AL) -#endif -#ifndef SEC_E_KDC_CERT_REVOKED -#define SEC_E_KDC_CERT_REVOKED ((HRESULT)0x8009035BL) -#endif -#endif /* __MINGW32CE__ */ /* Offered by mingw-w64 v8+. MS SDK 6.0A+. */ #ifndef SEC_E_INVALID_PARAMETER #define SEC_E_INVALID_PARAMETER ((HRESULT)0x8009035DL) @@ -302,44 +80,11 @@ extern PSecurityFunctionTable Curl_pSecFn; #define SEC_E_POLICY_NLTM_ONLY ((HRESULT)0x8009035FL) #endif -#ifdef __MINGW32CE__ -#ifndef SEC_I_CONTINUE_NEEDED -#define SEC_I_CONTINUE_NEEDED ((HRESULT)0x00090312L) -#endif -#ifndef SEC_I_COMPLETE_NEEDED -#define SEC_I_COMPLETE_NEEDED ((HRESULT)0x00090313L) -#endif -#ifndef SEC_I_COMPLETE_AND_CONTINUE -#define SEC_I_COMPLETE_AND_CONTINUE ((HRESULT)0x00090314L) -#endif -#ifndef SEC_I_LOCAL_LOGON -#define SEC_I_LOCAL_LOGON ((HRESULT)0x00090315L) -#endif -#ifndef SEC_I_CONTEXT_EXPIRED -#define SEC_I_CONTEXT_EXPIRED ((HRESULT)0x00090317L) -#endif -#ifndef SEC_I_INCOMPLETE_CREDENTIALS -#define SEC_I_INCOMPLETE_CREDENTIALS ((HRESULT)0x00090320L) -#endif -#ifndef SEC_I_RENEGOTIATE -#define SEC_I_RENEGOTIATE ((HRESULT)0x00090321L) -#endif -#ifndef SEC_I_NO_LSA_CONTEXT -#define SEC_I_NO_LSA_CONTEXT ((HRESULT)0x00090323L) -#endif -#endif /* __MINGW32CE__ */ - /* Offered by mingw-w64 v8+. MS SDK 6.0A+. */ #ifndef SEC_I_SIGNATURE_NEEDED #define SEC_I_SIGNATURE_NEEDED ((HRESULT)0x0009035CL) #endif -#ifdef __MINGW32CE__ -#ifndef CRYPT_E_NOT_IN_REVOCATION_DATABASE -#define CRYPT_E_NOT_IN_REVOCATION_DATABASE ((HRESULT)0x80092014L) -#endif -#endif /* __MINGW32CE__ */ - /* * Definitions required from ntsecapi.h are directly provided below this point * to avoid including ntsecapi.h due to a conflict with OpenSSL's safestack.h diff --git a/vendor/hydra/vendor/curl/lib/curl_threads.c b/vendor/hydra/vendor/curl/lib/curl_threads.c index 68bfdddd..f5fea980 100644 --- a/vendor/hydra/vendor/curl/lib/curl_threads.c +++ b/vendor/hydra/vendor/curl/lib/curl_threads.c @@ -21,19 +21,13 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include - #if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H) #include #endif #include "curl_threads.h" -#include "curl_memory.h" -/* The last #include FILE should be: */ -#include "memdebug.h" #ifdef USE_THREADS_POSIX @@ -48,7 +42,7 @@ static void *curl_thread_create_thunk(void *arg) unsigned int (*func)(void *) = ac->func; void *real_arg = ac->arg; - free(ac); + curlx_free(ac); (*func)(real_arg); @@ -58,9 +52,12 @@ static void *curl_thread_create_thunk(void *arg) curl_thread_t Curl_thread_create(CURL_THREAD_RETURN_T (CURL_STDCALL *func) (void *), void *arg) { - curl_thread_t t = malloc(sizeof(pthread_t)); - struct Curl_actual_call *ac = malloc(sizeof(struct Curl_actual_call)); + curl_thread_t t = curlx_malloc(sizeof(pthread_t)); + struct Curl_actual_call *ac = NULL; int rc; + + if(t) + ac = curlx_malloc(sizeof(struct Curl_actual_call)); if(!(ac && t)) goto err; @@ -69,15 +66,15 @@ curl_thread_t Curl_thread_create(CURL_THREAD_RETURN_T rc = pthread_create(t, NULL, curl_thread_create_thunk, ac); if(rc) { - CURL_SETERRNO(rc); + errno = rc; goto err; } return t; err: - free(t); - free(ac); + curlx_free(t); + curlx_free(ac); return curl_thread_t_null; } @@ -85,7 +82,7 @@ void Curl_thread_destroy(curl_thread_t *hnd) { if(*hnd != curl_thread_t_null) { pthread_detach(**hnd); - free(*hnd); + curlx_free(*hnd); *hnd = curl_thread_t_null; } } @@ -94,7 +91,7 @@ int Curl_thread_join(curl_thread_t *hnd) { int ret = (pthread_join(**hnd, NULL) == 0); - free(*hnd); + curlx_free(*hnd); *hnd = curl_thread_t_null; return ret; @@ -109,10 +106,9 @@ curl_thread_t Curl_thread_create(CURL_THREAD_RETURN_T if(!t) { DWORD gle = GetLastError(); /* !checksrc! disable ERRNOVAR 1 */ - int err = (gle == ERROR_ACCESS_DENIED || - gle == ERROR_NOT_ENOUGH_MEMORY) ? - EACCES : EINVAL; - CURL_SETERRNO(err); + errno = (gle == ERROR_ACCESS_DENIED || + gle == ERROR_NOT_ENOUGH_MEMORY) ? + EACCES : EINVAL; return curl_thread_t_null; } return t; @@ -128,11 +124,7 @@ void Curl_thread_destroy(curl_thread_t *hnd) int Curl_thread_join(curl_thread_t *hnd) { -#ifdef UNDER_CE - int ret = (WaitForSingleObject(*hnd, INFINITE) == WAIT_OBJECT_0); -#else int ret = (WaitForSingleObjectEx(*hnd, INFINITE, FALSE) == WAIT_OBJECT_0); -#endif Curl_thread_destroy(hnd); diff --git a/vendor/hydra/vendor/curl/lib/curl_trc.c b/vendor/hydra/vendor/curl/lib/curl_trc.c index 0b91315e..565d1b45 100644 --- a/vendor/hydra/vendor/curl/lib/curl_trc.c +++ b/vendor/hydra/vendor/curl/lib/curl_trc.c @@ -21,20 +21,15 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include - #include "curl_trc.h" #include "urldata.h" -#include "easyif.h" #include "cfilters.h" #include "multiif.h" #include "cf-socket.h" #include "connect.h" -#include "doh.h" #include "http2.h" #include "http_proxy.h" #include "cf-h1-proxy.h" @@ -42,14 +37,12 @@ #include "cf-haproxy.h" #include "cf-https-connect.h" #include "cf-ip-happy.h" +#include "progress.h" #include "socks.h" #include "curlx/strparse.h" #include "vtls/vtls.h" #include "vquic/vquic.h" - -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" +#include "curlx/strcopy.h" static void trc_write(struct Curl_easy *data, curl_infotype type, const char *ptr, size_t size) @@ -92,8 +85,8 @@ static struct curl_trc_feat Curl_trc_feat_ids = { CURL_LOG_LVL_NONE, }; #define CURL_TRC_IDS(data) \ - (Curl_trc_is_verbose(data) && \ - Curl_trc_feat_ids.log_level >= CURL_LOG_LVL_INFO) + (Curl_trc_is_verbose(data) && \ + Curl_trc_feat_ids.log_level >= CURL_LOG_LVL_INFO) static size_t trc_print_ids(struct Curl_easy *data, char *buf, size_t maxlen) { @@ -191,7 +184,7 @@ void Curl_failf(struct Curl_easy *data, const char *fmt, ...) len = curl_mvsnprintf(error, CURL_ERROR_SIZE, fmt, ap); if(data->set.errorbuffer && !data->state.errorbuf) { - strcpy(data->set.errorbuffer, error); + curlx_strcopy(data->set.errorbuffer, CURL_ERROR_SIZE, error, len); data->state.errorbuf = TRUE; /* wrote error string */ } error[len++] = '\n'; @@ -276,7 +269,7 @@ struct curl_trc_feat Curl_trc_feat_timer = { CURL_LOG_LVL_NONE, }; -static const char * const Curl_trc_timer_names[]={ +static const char * const Curl_trc_timer_names[] = { "100_TIMEOUT", "ASYNC_NAME", "CONNECTTIMEOUT", @@ -318,25 +311,24 @@ void Curl_trc_easy_timers(struct Curl_easy *data) if(CURL_TRC_TIMER_is_verbose(data)) { struct Curl_llist_node *e = Curl_llist_head(&data->state.timeoutlist); if(e) { - struct curltime now = curlx_now(); + const struct curltime *pnow = Curl_pgrs_now(data); while(e) { struct time_node *n = Curl_node_elem(e); e = Curl_node_next(e); CURL_TRC_TIMER(data, n->eid, "expires in %" FMT_TIMEDIFF_T "ns", - curlx_timediff_us(n->time, now)); + curlx_ptimediff_us(&n->time, pnow)); } } } } -static const char * const Curl_trc_mstate_names[]={ +static const char * const Curl_trc_mstate_names[] = { "INIT", "PENDING", "SETUP", "CONNECT", "RESOLVING", "CONNECTING", - "TUNNELING", "PROTOCONNECT", "PROTOCONNECTING", "DO", @@ -457,6 +449,24 @@ void Curl_trc_ssls(struct Curl_easy *data, const char *fmt, ...) } #endif /* USE_SSL */ +#ifdef USE_SSH +struct curl_trc_feat Curl_trc_feat_ssh = { + "SSH", + CURL_LOG_LVL_NONE, +}; + +void Curl_trc_ssh(struct Curl_easy *data, const char *fmt, ...) +{ + DEBUGASSERT(!strchr(fmt, '\n')); + if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ssh)) { + va_list ap; + va_start(ap, fmt); + trc_infof(data, &Curl_trc_feat_ssh, NULL, 0, fmt, ap); + va_end(ap); + } +} +#endif /* USE_SSH */ + #if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP) struct curl_trc_feat Curl_trc_feat_ws = { "WS", @@ -476,10 +486,10 @@ void Curl_trc_ws(struct Curl_easy *data, const char *fmt, ...) #endif /* !CURL_DISABLE_WEBSOCKETS && !CURL_DISABLE_HTTP */ #define TRC_CT_NONE (0) -#define TRC_CT_PROTOCOL (1<<(0)) -#define TRC_CT_NETWORK (1<<(1)) -#define TRC_CT_PROXY (1<<(2)) -#define TRC_CT_INTERNALS (1<<(3)) +#define TRC_CT_PROTOCOL (1 << 0) +#define TRC_CT_NETWORK (1 << 1) +#define TRC_CT_PROXY (1 << 2) +#define TRC_CT_INTERNALS (1 << 3) struct trc_feat_def { struct curl_trc_feat *feat; @@ -496,14 +506,15 @@ static struct trc_feat_def trc_feats[] = { #ifndef CURL_DISABLE_FTP { &Curl_trc_feat_ftp, TRC_CT_PROTOCOL }, #endif -#ifndef CURL_DISABLE_DOH -#endif #ifndef CURL_DISABLE_SMTP { &Curl_trc_feat_smtp, TRC_CT_PROTOCOL }, #endif #ifdef USE_SSL { &Curl_trc_feat_ssls, TRC_CT_NETWORK }, #endif +#ifdef USE_SSH + { &Curl_trc_feat_ssh, TRC_CT_PROTOCOL }, +#endif #if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP) { &Curl_trc_feat_ws, TRC_CT_PROTOCOL }, #endif @@ -648,56 +659,75 @@ CURLcode Curl_trc_init(void) void Curl_infof(struct Curl_easy *data, const char *fmt, ...) { - (void)data; (void)fmt; + (void)data; + (void)fmt; } void Curl_trc_cf_infof(struct Curl_easy *data, const struct Curl_cfilter *cf, const char *fmt, ...) { - (void)data; (void)cf; (void)fmt; + (void)data; + (void)cf; + (void)fmt; } void Curl_trc_multi(struct Curl_easy *data, const char *fmt, ...) { - (void)data; (void)fmt; + (void)data; + (void)fmt; } void Curl_trc_write(struct Curl_easy *data, const char *fmt, ...) { - (void)data; (void)fmt; + (void)data; + (void)fmt; } void Curl_trc_dns(struct Curl_easy *data, const char *fmt, ...) { - (void)data; (void)fmt; + (void)data; + (void)fmt; } void Curl_trc_timer(struct Curl_easy *data, int tid, const char *fmt, ...) { - (void)data; (void)tid; (void)fmt; + (void)data; + (void)tid; + (void)fmt; } void Curl_trc_read(struct Curl_easy *data, const char *fmt, ...) { - (void)data; (void)fmt; + (void)data; + (void)fmt; } #ifndef CURL_DISABLE_FTP void Curl_trc_ftp(struct Curl_easy *data, const char *fmt, ...) { - (void)data; (void)fmt; + (void)data; + (void)fmt; } #endif #ifndef CURL_DISABLE_SMTP void Curl_trc_smtp(struct Curl_easy *data, const char *fmt, ...) { - (void)data; (void)fmt; + (void)data; + (void)fmt; } #endif #if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP) void Curl_trc_ws(struct Curl_easy *data, const char *fmt, ...) { - (void)data; (void)fmt; + (void)data; + (void)fmt; +} +#endif +#ifdef USE_SSH +void Curl_trc_ssh(struct Curl_easy *data, const char *fmt, ...) +{ + (void)data; + (void)fmt; } #endif #ifdef USE_SSL diff --git a/vendor/hydra/vendor/curl/lib/curl_trc.h b/vendor/hydra/vendor/curl/lib/curl_trc.h index 1a3f8f37..ff085d6a 100644 --- a/vendor/hydra/vendor/curl/lib/curl_trc.h +++ b/vendor/hydra/vendor/curl/lib/curl_trc.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - struct Curl_easy; struct Curl_cfilter; @@ -65,7 +64,6 @@ void Curl_failf(struct Curl_easy *data, #define CURL_LOG_LVL_NONE 0 #define CURL_LOG_LVL_INFO 1 - #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L #define CURL_HAVE_C99 #endif @@ -117,6 +115,11 @@ extern struct curl_trc_feat Curl_trc_feat_ssls; void Curl_trc_ssls(struct Curl_easy *data, const char *fmt, ...) CURL_PRINTF(2, 3); #endif +#ifdef USE_SSH +extern struct curl_trc_feat Curl_trc_feat_ssh; +void Curl_trc_ssh(struct Curl_easy *data, + const char *fmt, ...) CURL_PRINTF(2, 3); +#endif #if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP) extern struct curl_trc_feat Curl_trc_feat_ws; void Curl_trc_ws(struct Curl_easy *data, @@ -131,54 +134,83 @@ void Curl_trc_ws(struct Curl_easy *data, Curl_trc_ft_is_verbose(data, &Curl_trc_feat_timer) #if defined(CURL_HAVE_C99) && !defined(CURL_DISABLE_VERBOSE_STRINGS) -#define infof(data, ...) \ - do { if(Curl_trc_is_verbose(data)) \ - Curl_infof(data, __VA_ARGS__); } while(0) -#define CURL_TRC_M(data, ...) \ - do { if(CURL_TRC_M_is_verbose(data)) \ - Curl_trc_multi(data, __VA_ARGS__); } while(0) -#define CURL_TRC_CF(data, cf, ...) \ - do { if(Curl_trc_cf_is_verbose(cf, data)) \ - Curl_trc_cf_infof(data, cf, __VA_ARGS__); } while(0) -#define CURL_TRC_WRITE(data, ...) \ - do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_write)) \ - Curl_trc_write(data, __VA_ARGS__); } while(0) -#define CURL_TRC_READ(data, ...) \ - do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_read)) \ - Curl_trc_read(data, __VA_ARGS__); } while(0) -#define CURL_TRC_DNS(data, ...) \ - do { if(CURL_TRC_DNS_is_verbose(data)) \ - Curl_trc_dns(data, __VA_ARGS__); } while(0) -#define CURL_TRC_TIMER(data, tid, ...) \ - do { if(CURL_TRC_TIMER_is_verbose(data)) \ - Curl_trc_timer(data, tid, __VA_ARGS__); } while(0) +#define infof(data, ...) \ + do { \ + if(Curl_trc_is_verbose(data)) \ + Curl_infof(data, __VA_ARGS__); \ + } while(0) +#define CURL_TRC_M(data, ...) \ + do { \ + if(CURL_TRC_M_is_verbose(data)) \ + Curl_trc_multi(data, __VA_ARGS__); \ + } while(0) +#define CURL_TRC_CF(data, cf, ...) \ + do { \ + if(Curl_trc_cf_is_verbose(cf, data)) \ + Curl_trc_cf_infof(data, cf, __VA_ARGS__); \ + } while(0) +#define CURL_TRC_WRITE(data, ...) \ + do { \ + if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_write)) \ + Curl_trc_write(data, __VA_ARGS__); \ + } while(0) +#define CURL_TRC_READ(data, ...) \ + do { \ + if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_read)) \ + Curl_trc_read(data, __VA_ARGS__); \ + } while(0) +#define CURL_TRC_DNS(data, ...) \ + do { \ + if(CURL_TRC_DNS_is_verbose(data)) \ + Curl_trc_dns(data, __VA_ARGS__); \ + } while(0) +#define CURL_TRC_TIMER(data, tid, ...) \ + do { \ + if(CURL_TRC_TIMER_is_verbose(data)) \ + Curl_trc_timer(data, tid, __VA_ARGS__); \ + } while(0) #ifndef CURL_DISABLE_FTP -#define CURL_TRC_FTP(data, ...) \ - do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ftp)) \ - Curl_trc_ftp(data, __VA_ARGS__); } while(0) +#define CURL_TRC_FTP(data, ...) \ + do { \ + if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ftp)) \ + Curl_trc_ftp(data, __VA_ARGS__); \ + } while(0) #endif /* !CURL_DISABLE_FTP */ #ifndef CURL_DISABLE_SMTP -#define CURL_TRC_SMTP(data, ...) \ - do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_smtp)) \ - Curl_trc_smtp(data, __VA_ARGS__); } while(0) +#define CURL_TRC_SMTP(data, ...) \ + do { \ + if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_smtp)) \ + Curl_trc_smtp(data, __VA_ARGS__); \ + } while(0) #endif /* !CURL_DISABLE_SMTP */ #ifdef USE_SSL -#define CURL_TRC_SSLS(data, ...) \ - do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ssls)) \ - Curl_trc_ssls(data, __VA_ARGS__); } while(0) +#define CURL_TRC_SSLS(data, ...) \ + do { \ + if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ssls)) \ + Curl_trc_ssls(data, __VA_ARGS__); \ + } while(0) #endif /* USE_SSL */ +#ifdef USE_SSH +#define CURL_TRC_SSH(data, ...) \ + do { \ + if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ssh)) \ + Curl_trc_ssh(data, __VA_ARGS__); \ + } while(0) +#endif /* USE_SSH */ #if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP) -#define CURL_TRC_WS(data, ...) \ - do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ws)) \ - Curl_trc_ws(data, __VA_ARGS__); } while(0) +#define CURL_TRC_WS(data, ...) \ + do { \ + if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ws)) \ + Curl_trc_ws(data, __VA_ARGS__); \ + } while(0) #endif /* !CURL_DISABLE_WEBSOCKETS && !CURL_DISABLE_HTTP */ #else /* CURL_HAVE_C99 */ -#define infof Curl_infof -#define CURL_TRC_M Curl_trc_multi -#define CURL_TRC_CF Curl_trc_cf_infof +#define infof Curl_infof +#define CURL_TRC_M Curl_trc_multi +#define CURL_TRC_CF Curl_trc_cf_infof #define CURL_TRC_WRITE Curl_trc_write #define CURL_TRC_READ Curl_trc_read #define CURL_TRC_DNS Curl_trc_dns @@ -193,6 +225,9 @@ void Curl_trc_ws(struct Curl_easy *data, #ifdef USE_SSL #define CURL_TRC_SSLS Curl_trc_ssls #endif +#ifdef USE_SSH +#define CURL_TRC_SSH Curl_trc_ssh +#endif #if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP) #define CURL_TRC_WS Curl_trc_ws #endif @@ -208,27 +243,29 @@ extern struct curl_trc_feat Curl_trc_feat_write; extern struct curl_trc_feat Curl_trc_feat_dns; extern struct curl_trc_feat Curl_trc_feat_timer; -#define Curl_trc_is_verbose(data) \ - ((data) && (data)->set.verbose && \ - (!(data)->state.feat || \ - ((data)->state.feat->log_level >= CURL_LOG_LVL_INFO))) -#define Curl_trc_cf_is_verbose(cf, data) \ - (Curl_trc_is_verbose(data) && \ - (cf) && (cf)->cft->log_level >= CURL_LOG_LVL_INFO) +#define Curl_trc_is_verbose(data) \ + ((data) && (data)->set.verbose && \ + (!(data)->state.feat || \ + ((data)->state.feat->log_level >= CURL_LOG_LVL_INFO))) +#define Curl_trc_cf_is_verbose(cf, data) \ + (Curl_trc_is_verbose(data) && \ + (cf) && (cf)->cft->log_level >= CURL_LOG_LVL_INFO) #define Curl_trc_ft_is_verbose(data, ft) \ - (Curl_trc_is_verbose(data) && \ - (ft)->log_level >= CURL_LOG_LVL_INFO) + (Curl_trc_is_verbose(data) && \ + (ft)->log_level >= CURL_LOG_LVL_INFO) #define CURL_MSTATE_NAME(s) Curl_trc_mstate_name((int)(s)) -#define CURL_TRC_EASY_TIMERS(data) \ - do { if(CURL_TRC_TIMER_is_verbose(data)) \ - Curl_trc_easy_timers(data); } while(0) +#define CURL_TRC_EASY_TIMERS(data) \ + do { \ + if(CURL_TRC_TIMER_is_verbose(data)) \ + Curl_trc_easy_timers(data); \ + } while(0) #else /* CURL_DISABLE_VERBOSE_STRINGS */ /* All informational messages are not compiled in for size savings */ #define Curl_trc_is_verbose(d) (FALSE) -#define Curl_trc_cf_is_verbose(x,y) (FALSE) -#define Curl_trc_ft_is_verbose(x,y) (FALSE) +#define Curl_trc_cf_is_verbose(x, y) (FALSE) +#define Curl_trc_ft_is_verbose(x, y) (FALSE) #define CURL_MSTATE_NAME(x) ((void)(x), "-") #define CURL_TRC_EASY_TIMERS(x) Curl_nop_stmt diff --git a/vendor/hydra/vendor/curl/lib/curlx/base64.c b/vendor/hydra/vendor/curl/lib/curlx/base64.c index ef07243d..0e44eae7 100644 --- a/vendor/hydra/vendor/curl/lib/curlx/base64.c +++ b/vendor/hydra/vendor/curl/lib/curlx/base64.c @@ -26,31 +26,24 @@ #include "../curl_setup.h" -#include -#include "warnless.h" #include "base64.h" -/* The last 2 #include files should be in this order */ -#ifdef BUILDING_LIBCURL -#include "../curl_memory.h" -#endif -#include "../memdebug.h" - /* ---- Base64 Encoding/Decoding Table --- */ -const char Curl_base64encdec[]= +const char curlx_base64encdec[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; /* The Base 64 encoding with a URL and filename safe alphabet, RFC 4648 section 5 */ -static const char base64url[]= +static const char base64url[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; -static const unsigned char decodetable[] = -{ 62, 255, 255, 255, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, 255, 255, - 255, 255, 255, 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, - 17, 18, 19, 20, 21, 22, 23, 24, 25, 255, 255, 255, 255, 255, 255, 26, 27, 28, - 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51 }; +static const unsigned char decodetable[] = { + 62, 255, 255, 255, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, + 255, 255, 255, 255, 255, 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, + 255, 255, 255, 255, 255, 255, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 +}; /* * curlx_base64_decode() * @@ -66,7 +59,7 @@ static const unsigned char decodetable[] = * @unittest: 1302 */ CURLcode curlx_base64_decode(const char *src, - unsigned char **outptr, size_t *outlen) + uint8_t **outptr, size_t *outlen) { size_t srclen = 0; size_t padding = 0; @@ -103,7 +96,7 @@ CURLcode curlx_base64_decode(const char *src, rawlen = (numQuantums * 3) - padding; /* Allocate our buffer including room for a null-terminator */ - newstr = malloc(rawlen + 1); + newstr = curlx_malloc(rawlen + 1); if(!newstr) return CURLE_OUT_OF_MEMORY; @@ -165,13 +158,13 @@ CURLcode curlx_base64_decode(const char *src, return CURLE_OK; bad: - free(newstr); + curlx_free(newstr); return CURLE_BAD_CONTENT_ENCODING; } static CURLcode base64_encode(const char *table64, - unsigned char padbyte, - const char *inputbuff, size_t insize, + uint8_t padbyte, + const uint8_t *inputbuff, size_t insize, char **outptr, size_t *outlen) { char *output; @@ -189,23 +182,23 @@ static CURLcode base64_encode(const char *table64, if(insize > CURL_MAX_BASE64_INPUT) return CURLE_TOO_LARGE; - base64data = output = malloc((insize + 2) / 3 * 4 + 1); + base64data = output = curlx_malloc((insize + 2) / 3 * 4 + 1); if(!output) return CURLE_OUT_OF_MEMORY; while(insize >= 3) { - *output++ = table64[ in[0] >> 2 ]; - *output++ = table64[ ((in[0] & 0x03) << 4) | (in[1] >> 4) ]; - *output++ = table64[ ((in[1] & 0x0F) << 2) | ((in[2] & 0xC0) >> 6) ]; - *output++ = table64[ in[2] & 0x3F ]; + *output++ = table64[in[0] >> 2]; + *output++ = table64[((in[0] & 0x03) << 4) | (in[1] >> 4)]; + *output++ = table64[((in[1] & 0x0F) << 2) | ((in[2] & 0xC0) >> 6)]; + *output++ = table64[in[2] & 0x3F]; insize -= 3; in += 3; } if(insize) { /* this is only one or two bytes now */ - *output++ = table64[ in[0] >> 2 ]; + *output++ = table64[in[0] >> 2]; if(insize == 1) { - *output++ = table64[ ((in[0] & 0x03) << 4) ]; + *output++ = table64[((in[0] & 0x03) << 4)]; if(padbyte) { *output++ = padbyte; *output++ = padbyte; @@ -213,8 +206,8 @@ static CURLcode base64_encode(const char *table64, } else { /* insize == 2 */ - *output++ = table64[ ((in[0] & 0x03) << 4) | ((in[1] & 0xF0) >> 4) ]; - *output++ = table64[ ((in[1] & 0x0F) << 2) ]; + *output++ = table64[((in[0] & 0x03) << 4) | ((in[1] & 0xF0) >> 4)]; + *output++ = table64[((in[1] & 0x0F) << 2)]; if(padbyte) *output++ = padbyte; } @@ -245,10 +238,10 @@ static CURLcode base64_encode(const char *table64, * * @unittest: 1302 */ -CURLcode curlx_base64_encode(const char *inputbuff, size_t insize, +CURLcode curlx_base64_encode(const uint8_t *inputbuff, size_t insize, char **outptr, size_t *outlen) { - return base64_encode(Curl_base64encdec, '=', + return base64_encode(curlx_base64encdec, '=', inputbuff, insize, outptr, outlen); } @@ -267,7 +260,7 @@ CURLcode curlx_base64_encode(const char *inputbuff, size_t insize, * * @unittest: 1302 */ -CURLcode curlx_base64url_encode(const char *inputbuff, size_t insize, +CURLcode curlx_base64url_encode(const uint8_t *inputbuff, size_t insize, char **outptr, size_t *outlen) { return base64_encode(base64url, 0, inputbuff, insize, outptr, outlen); diff --git a/vendor/hydra/vendor/curl/lib/curlx/base64.h b/vendor/hydra/vendor/curl/lib/curlx/base64.h index 31cfcb36..2e778148 100644 --- a/vendor/hydra/vendor/curl/lib/curlx/base64.h +++ b/vendor/hydra/vendor/curl/lib/curlx/base64.h @@ -24,14 +24,14 @@ * ***************************************************************************/ -CURLcode curlx_base64_encode(const char *inputbuff, size_t insize, +CURLcode curlx_base64_encode(const uint8_t *inputbuff, size_t insize, char **outptr, size_t *outlen); -CURLcode curlx_base64url_encode(const char *inputbuff, size_t insize, +CURLcode curlx_base64url_encode(const uint8_t *inputbuff, size_t insize, char **outptr, size_t *outlen); CURLcode curlx_base64_decode(const char *src, - unsigned char **outptr, size_t *outlen); + uint8_t **outptr, size_t *outlen); -extern const char Curl_base64encdec[]; +extern const char curlx_base64encdec[]; /* maximum input length acceptable to base64 encode, here to catch and prevent mistakes */ diff --git a/vendor/hydra/vendor/curl/lib/curlx/binmode.h b/vendor/hydra/vendor/curl/lib/curlx/binmode.h index 3f356edd..991cc890 100644 --- a/vendor/hydra/vendor/curl/lib/curlx/binmode.h +++ b/vendor/hydra/vendor/curl/lib/curlx/binmode.h @@ -33,7 +33,7 @@ # define CURLX_SET_BINMODE(stream) (void)setmode(fileno(stream), O_BINARY) #endif #else -# define CURLX_SET_BINMODE(stream) (void)stream; Curl_nop_stmt +# define CURLX_SET_BINMODE(stream) (void)stream #endif #endif /* HEADER_CURL_TOOL_BINMODE_H */ diff --git a/vendor/hydra/vendor/curl/lib/curlx/curlx.h b/vendor/hydra/vendor/curl/lib/curlx/curlx.h index 480e9195..817acb07 100644 --- a/vendor/hydra/vendor/curl/lib/curlx/curlx.h +++ b/vendor/hydra/vendor/curl/lib/curlx/curlx.h @@ -37,14 +37,6 @@ #include "nonblock.h" /* "nonblock.h" provides curlx_nonblock() */ -#include "warnless.h" -/* "warnless.h" provides functions: - - curlx_ultous() - curlx_ultouc() - curlx_uztosi() -*/ - #include "multibyte.h" /* "multibyte.h" provides these functions and macros: @@ -52,7 +44,6 @@ curlx_convert_wchar_to_UTF8() curlx_convert_UTF8_to_tchar() curlx_convert_tchar_to_UTF8() - curlx_unicodefree() */ #include "version_win32.h" @@ -64,6 +55,9 @@ #include "strparse.h" /* The curlx_str_* parsing functions */ +#include "strcopy.h" +/* curlx_strcopy */ + #include "dynbuf.h" /* The curlx_dyn_* functions */ diff --git a/vendor/hydra/vendor/curl/lib/curlx/dynbuf.c b/vendor/hydra/vendor/curl/lib/curlx/dynbuf.c index 447203e4..158d4d04 100644 --- a/vendor/hydra/vendor/curl/lib/curlx/dynbuf.c +++ b/vendor/hydra/vendor/curl/lib/curlx/dynbuf.c @@ -21,14 +21,10 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "../curl_setup.h" + #include "dynbuf.h" #include "../curl_printf.h" -#ifdef BUILDING_LIBCURL -#include "../curl_memory.h" -#endif -#include "../memdebug.h" #define MIN_FIRST_ALLOC 32 @@ -108,7 +104,7 @@ static CURLcode dyn_nappend(struct dynbuf *s, if(a != s->allc) { /* this logic is not using Curl_saferealloc() to make the tool not have to include that as well when it uses this code */ - void *p = realloc(s->bufr, a); + void *p = curlx_realloc(s->bufr, a); if(!p) { curlx_dyn_free(s); return CURLE_OUT_OF_MEMORY; @@ -160,7 +156,6 @@ CURLcode curlx_dyn_tail(struct dynbuf *s, size_t trail) s->bufr[s->leng] = 0; } return CURLE_OK; - } /* @@ -212,7 +207,7 @@ CURLcode curlx_dyn_vaddf(struct dynbuf *s, const char *fmt, va_list ap) if(str) { CURLcode result = dyn_nappend(s, (const unsigned char *)str, strlen(str)); - free(str); + curlx_free(str); return result; } /* If we failed, we cleanup the whole buffer and return error */ diff --git a/vendor/hydra/vendor/curl/lib/curlx/dynbuf.h b/vendor/hydra/vendor/curl/lib/curlx/dynbuf.h index 00ca0478..6f09e132 100644 --- a/vendor/hydra/vendor/curl/lib/curlx/dynbuf.h +++ b/vendor/hydra/vendor/curl/lib/curlx/dynbuf.h @@ -24,15 +24,13 @@ * ***************************************************************************/ -#include - struct dynbuf { char *bufr; /* point to a null-terminated allocated buffer */ size_t leng; /* number of bytes *EXCLUDING* the null-terminator */ size_t allc; /* size of the current allocation */ size_t toobig; /* size limit for the buffer */ #ifdef DEBUGBUILD - int init; /* detect API usage mistakes */ + int init; /* detect API usage mistakes */ #endif }; @@ -62,24 +60,24 @@ int curlx_dyn_vprintf(struct dynbuf *dyn, const char *format, va_list ap_save); char *curlx_dyn_take(struct dynbuf *s, size_t *plen); /* Dynamic buffer max sizes */ -#define MAX_DYNBUF_SIZE (SIZE_MAX/2) +#define MAX_DYNBUF_SIZE (SIZE_MAX / 2) #define DYN_DOH_RESPONSE 3000 #define DYN_DOH_CNAME 256 #define DYN_PAUSE_BUFFER (64 * 1024 * 1024) #define DYN_HAXPROXY 2048 -#define DYN_HTTP_REQUEST (1024*1024) +#define DYN_HTTP_REQUEST (1024 * 1024) #define DYN_APRINTF 8000000 -#define DYN_RTSP_REQ_HEADER (64*1024) -#define DYN_TRAILERS (64*1024) +#define DYN_RTSP_REQ_HEADER (64 * 1024) +#define DYN_TRAILERS (64 * 1024) #define DYN_PROXY_CONNECT_HEADERS 16384 #define DYN_QLOG_NAME 1024 #define DYN_H1_TRAILER 4096 -#define DYN_PINGPPONG_CMD (64*1024) -#define DYN_IMAP_CMD (64*1024) -#define DYN_MQTT_RECV (64*1024) +#define DYN_PINGPPONG_CMD (64 * 1024) +#define DYN_IMAP_CMD (64 * 1024) +#define DYN_MQTT_RECV (64 * 1024) #define DYN_MQTT_SEND 0xFFFFFFF -#define DYN_CRLFILE_SIZE (400*1024*1024) /* 400mb */ -#define DYN_CERTFILE_SIZE (100*1024) /* 100KiB */ -#define DYN_KEYFILE_SIZE (100*1024) /* 100KiB */ +#define DYN_CRLFILE_SIZE (400 * 1024 * 1024) /* 400MiB */ +#define DYN_CERTFILE_SIZE (100 * 1024) /* 100KiB */ +#define DYN_KEYFILE_SIZE (100 * 1024) /* 100KiB */ #endif diff --git a/vendor/hydra/vendor/curl/lib/curlx/fopen.c b/vendor/hydra/vendor/curl/lib/curlx/fopen.c index cc164c8c..e9eb6df3 100644 --- a/vendor/hydra/vendor/curl/lib/curlx/fopen.c +++ b/vendor/hydra/vendor/curl/lib/curlx/fopen.c @@ -21,22 +21,13 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - -/* - * This file is 'mem-include-scan' clean, which means its memory allocations - * are not tracked by the curl memory tracker memdebug, so they must not use - * `CURLDEBUG` macro replacements in memdebug.h for free, malloc, etc. To avoid - * these macro replacements, wrap the names in parentheses to call the original - * versions: `ptr = (malloc)(123)`, `(free)(ptr)`, etc. - */ - #include "../curl_setup.h" #include "fopen.h" int curlx_fseek(void *stream, curl_off_t offset, int whence) { -#if defined(_WIN32) && defined(USE_WIN32_LARGE_FILES) +#ifdef _WIN32 return _fseeki64(stream, (__int64)offset, whence); #elif defined(HAVE_FSEEKO) && defined(HAVE_DECL_FSEEKO) return fseeko(stream, (off_t)offset, whence); @@ -47,9 +38,47 @@ int curlx_fseek(void *stream, curl_off_t offset, int whence) #endif } -#if defined(_WIN32) && !defined(UNDER_CE) +#ifdef _WIN32 + +#include /* for _SH_DENYNO */ #include "multibyte.h" +#include "timeval.h" + +#ifdef CURLDEBUG +/* + * Use system allocators to avoid infinite recursion when called by curl's + * memory tracker memdebug functions. + */ +#define CURLX_MALLOC(x) malloc(x) +#define CURLX_FREE(x) free(x) +#else +#define CURLX_MALLOC(x) curlx_malloc(x) +#define CURLX_FREE(x) curlx_free(x) +#endif + +#ifdef _UNICODE +static wchar_t *fn_convert_UTF8_to_wchar(const char *str_utf8) +{ + wchar_t *str_w = NULL; + + if(str_utf8) { + int str_w_len = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, + str_utf8, -1, NULL, 0); + if(str_w_len > 0) { + str_w = CURLX_MALLOC(str_w_len * sizeof(wchar_t)); + if(str_w) { + if(MultiByteToWideChar(CP_UTF8, 0, + str_utf8, -1, str_w, str_w_len) == 0) { + CURLX_FREE(str_w); + return NULL; + } + } + } + } + return str_w; +} +#endif /* declare GetFullPathNameW for mingw-w64 UWP builds targeting old windows */ #if defined(CURL_WINDOWS_UWP) && defined(__MINGW32__) && \ @@ -97,15 +126,16 @@ static bool fix_excessive_path(const TCHAR *in, TCHAR **out) #ifndef _UNICODE /* convert multibyte input to unicode */ - needed = mbstowcs(NULL, in, 0); - if(needed == (size_t)-1 || needed >= max_path_len) + if(mbstowcs_s(&needed, NULL, 0, in, 0)) goto cleanup; - ++needed; /* for NUL */ - ibuf = (malloc)(needed * sizeof(wchar_t)); + if(!needed || needed >= max_path_len) + goto cleanup; + ibuf = CURLX_MALLOC(needed * sizeof(wchar_t)); if(!ibuf) goto cleanup; - count = mbstowcs(ibuf, in, needed); - if(count == (size_t)-1 || count >= needed) + if(mbstowcs_s(&count, ibuf, needed, in, needed - 1)) + goto cleanup; + if(count != needed) goto cleanup; in_w = ibuf; #else @@ -121,7 +151,7 @@ static bool fix_excessive_path(const TCHAR *in, TCHAR **out) /* skip paths that are not excessive and do not need modification */ if(needed <= MAX_PATH) goto cleanup; - fbuf = (malloc)(needed * sizeof(wchar_t)); + fbuf = CURLX_MALLOC(needed * sizeof(wchar_t)); if(!fbuf) goto cleanup; count = (size_t)GetFullPathNameW(in_w, (DWORD)needed, fbuf, NULL); @@ -142,7 +172,7 @@ static bool fix_excessive_path(const TCHAR *in, TCHAR **out) else if(!wcsncmp(fbuf, L"\\\\.\\", 4)) fbuf[2] = '?'; else if(!wcsncmp(fbuf, L"\\\\.", 3) || !wcsncmp(fbuf, L"\\\\?", 3)) { - /* Unexpected, not UNC. The formatting doc doesn't allow this AFAICT. */ + /* Unexpected, not UNC. The formatting doc does not allow this AFAICT. */ goto cleanup; } else { @@ -154,12 +184,18 @@ static bool fix_excessive_path(const TCHAR *in, TCHAR **out) if(needed > max_path_len) goto cleanup; - temp = (malloc)(needed * sizeof(wchar_t)); + temp = CURLX_MALLOC(needed * sizeof(wchar_t)); if(!temp) goto cleanup; - wcsncpy(temp, L"\\\\?\\UNC\\", 8); - wcscpy(temp + 8, fbuf + 2); + if(wcsncpy_s(temp, needed, L"\\\\?\\UNC\\", 8)) { + CURLX_FREE(temp); + goto cleanup; + } + if(wcscpy_s(temp + 8, needed, fbuf + 2)) { + CURLX_FREE(temp); + goto cleanup; + } } else { /* "\\?\" + full path + null */ @@ -167,29 +203,36 @@ static bool fix_excessive_path(const TCHAR *in, TCHAR **out) if(needed > max_path_len) goto cleanup; - temp = (malloc)(needed * sizeof(wchar_t)); + temp = CURLX_MALLOC(needed * sizeof(wchar_t)); if(!temp) goto cleanup; - wcsncpy(temp, L"\\\\?\\", 4); - wcscpy(temp + 4, fbuf); + if(wcsncpy_s(temp, needed, L"\\\\?\\", 4)) { + CURLX_FREE(temp); + goto cleanup; + } + if(wcscpy_s(temp + 4, needed, fbuf)) { + CURLX_FREE(temp); + goto cleanup; + } } - (free)(fbuf); + CURLX_FREE(fbuf); fbuf = temp; } #ifndef _UNICODE /* convert unicode full path to multibyte output */ - needed = wcstombs(NULL, fbuf, 0); - if(needed == (size_t)-1 || needed >= max_path_len) + if(wcstombs_s(&needed, NULL, 0, fbuf, 0)) + goto cleanup; + if(!needed || needed >= max_path_len) goto cleanup; - ++needed; /* for NUL */ - obuf = (malloc)(needed); + obuf = CURLX_MALLOC(needed); if(!obuf) goto cleanup; - count = wcstombs(obuf, fbuf, needed); - if(count == (size_t)-1 || count >= needed) + if(wcstombs_s(&count, obuf, needed, fbuf, needed - 1)) + goto cleanup; + if(count != needed) goto cleanup; *out = obuf; obuf = NULL; @@ -199,14 +242,57 @@ static bool fix_excessive_path(const TCHAR *in, TCHAR **out) #endif cleanup: - (free)(fbuf); + CURLX_FREE(fbuf); #ifndef _UNICODE - (free)(ibuf); - (free)(obuf); + CURLX_FREE(ibuf); + CURLX_FREE(obuf); #endif return *out ? true : false; } +#ifndef CURL_WINDOWS_UWP +HANDLE curlx_CreateFile(const char *filename, + DWORD dwDesiredAccess, + DWORD dwShareMode, + LPSECURITY_ATTRIBUTES lpSecurityAttributes, + DWORD dwCreationDisposition, + DWORD dwFlagsAndAttributes, + HANDLE hTemplateFile) +{ + HANDLE handle = INVALID_HANDLE_VALUE; + +#ifdef UNICODE + TCHAR *filename_t = curlx_convert_UTF8_to_wchar(filename); +#else + const TCHAR *filename_t = filename; +#endif + + if(filename_t) { + TCHAR *fixed = NULL; + const TCHAR *target = NULL; + + if(fix_excessive_path(filename_t, &fixed)) + target = fixed; + else + target = filename_t; + /* !checksrc! disable BANNEDFUNC 1 */ + handle = CreateFile(target, + dwDesiredAccess, + dwShareMode, + lpSecurityAttributes, + dwCreationDisposition, + dwFlagsAndAttributes, + hTemplateFile); + CURLX_FREE(fixed); +#ifdef UNICODE + curlx_free(filename_t); +#endif + } + + return handle; +} +#endif /* !CURL_WINDOWS_UWP */ + int curlx_win32_open(const char *filename, int oflag, ...) { int pmode = 0; @@ -215,7 +301,7 @@ int curlx_win32_open(const char *filename, int oflag, ...) const TCHAR *target = NULL; #ifdef _UNICODE - wchar_t *filename_w = curlx_convert_UTF8_to_wchar(filename); + wchar_t *filename_w = fn_convert_UTF8_to_wchar(filename); #endif va_list param; @@ -230,21 +316,21 @@ int curlx_win32_open(const char *filename, int oflag, ...) target = fixed; else target = filename_w; - result = _wopen(target, oflag, pmode); - curlx_unicodefree(filename_w); + errno = _wsopen_s(&result, target, oflag, _SH_DENYNO, pmode); + CURLX_FREE(filename_w); } else /* !checksrc! disable ERRNOVAR 1 */ - CURL_SETERRNO(EINVAL); + errno = EINVAL; #else if(fix_excessive_path(filename, &fixed)) target = fixed; else target = filename; - result = _open(target, oflag, pmode); + errno = _sopen_s(&result, target, oflag, _SH_DENYNO, pmode); #endif - (free)(fixed); + CURLX_FREE(fixed); return result; } @@ -255,30 +341,67 @@ FILE *curlx_win32_fopen(const char *filename, const char *mode) const TCHAR *target = NULL; #ifdef _UNICODE - wchar_t *filename_w = curlx_convert_UTF8_to_wchar(filename); - wchar_t *mode_w = curlx_convert_UTF8_to_wchar(mode); + wchar_t *filename_w = fn_convert_UTF8_to_wchar(filename); + wchar_t *mode_w = fn_convert_UTF8_to_wchar(mode); + if(filename_w && mode_w) { + if(fix_excessive_path(filename_w, &fixed)) + target = fixed; + else + target = filename_w; + result = _wfsopen(target, mode_w, _SH_DENYNO); + } + else + /* !checksrc! disable ERRNOVAR 1 */ + errno = EINVAL; + CURLX_FREE(filename_w); + CURLX_FREE(mode_w); +#else + if(fix_excessive_path(filename, &fixed)) + target = fixed; + else + target = filename; + result = _fsopen(target, mode, _SH_DENYNO); +#endif + + CURLX_FREE(fixed); + return result; +} + +#if defined(__MINGW32__) && (__MINGW64_VERSION_MAJOR < 5) +_CRTIMP errno_t __cdecl freopen_s(FILE **file, const char *filename, + const char *mode, FILE *stream); +#endif + +FILE *curlx_win32_freopen(const char *filename, const char *mode, FILE *fp) +{ + FILE *result = NULL; + TCHAR *fixed = NULL; + const TCHAR *target = NULL; + +#ifdef _UNICODE + wchar_t *filename_w = fn_convert_UTF8_to_wchar(filename); + wchar_t *mode_w = fn_convert_UTF8_to_wchar(mode); if(filename_w && mode_w) { if(fix_excessive_path(filename_w, &fixed)) target = fixed; else target = filename_w; - result = _wfopen(target, mode_w); + errno = _wfreopen_s(&result, target, mode_w, fp); } else /* !checksrc! disable ERRNOVAR 1 */ - CURL_SETERRNO(EINVAL); - curlx_unicodefree(filename_w); - curlx_unicodefree(mode_w); + errno = EINVAL; + CURLX_FREE(filename_w); + CURLX_FREE(mode_w); #else if(fix_excessive_path(filename, &fixed)) target = fixed; else target = filename; - /* !checksrc! disable BANNEDFUNC 1 */ - result = fopen(target, mode); + errno = freopen_s(&result, target, mode, fp); #endif - (free)(fixed); + CURLX_FREE(fixed); return result; } @@ -295,30 +418,91 @@ int curlx_win32_stat(const char *path, struct_stat *buffer) target = fixed; else target = path_w; -#ifndef USE_WIN32_LARGE_FILES - result = _wstat(target, buffer); -#else result = _wstati64(target, buffer); -#endif - curlx_unicodefree(path_w); + curlx_free(path_w); } else /* !checksrc! disable ERRNOVAR 1 */ - CURL_SETERRNO(EINVAL); + errno = EINVAL; #else if(fix_excessive_path(path, &fixed)) target = fixed; else target = path; -#ifndef USE_WIN32_LARGE_FILES - result = _stat(target, buffer); -#else result = _stati64(target, buffer); -#endif #endif - (free)(fixed); + CURLX_FREE(fixed); return result; } -#endif /* _WIN32 && !UNDER_CE */ +#if !defined(CURL_DISABLE_HTTP) || !defined(CURL_DISABLE_COOKIES) || \ + !defined(CURL_DISABLE_ALTSVC) +/* rename() on Windows does not overwrite, so we cannot use it here. + MoveFileEx() will overwrite and is usually atomic, however it fails + when there are open handles to the file. */ +int curlx_win32_rename(const char *oldpath, const char *newpath) +{ + int res = -1; /* fail */ + +#ifdef UNICODE + TCHAR *tchar_oldpath = curlx_convert_UTF8_to_wchar(oldpath); + TCHAR *tchar_newpath = curlx_convert_UTF8_to_wchar(newpath); +#else + const TCHAR *tchar_oldpath = oldpath; + const TCHAR *tchar_newpath = newpath; +#endif + + if(tchar_oldpath && tchar_newpath) { + const int max_wait_ms = 1000; + struct curltime start; + + TCHAR *oldpath_fixed = NULL; + TCHAR *newpath_fixed = NULL; + const TCHAR *target_oldpath; + const TCHAR *target_newpath; + + if(fix_excessive_path(tchar_oldpath, &oldpath_fixed)) + target_oldpath = oldpath_fixed; + else + target_oldpath = tchar_oldpath; + + if(fix_excessive_path(tchar_newpath, &newpath_fixed)) + target_newpath = newpath_fixed; + else + target_newpath = tchar_newpath; + + start = curlx_now(); + + for(;;) { + timediff_t diff; + /* !checksrc! disable BANNEDFUNC 1 */ + if(MoveFileEx(target_oldpath, target_newpath, + MOVEFILE_REPLACE_EXISTING)) { + res = 0; /* success */ + break; + } + diff = curlx_timediff_ms(curlx_now(), start); + if(diff < 0 || diff > max_wait_ms) { + break; + } + Sleep(1); + } + + CURLX_FREE(oldpath_fixed); + CURLX_FREE(newpath_fixed); + } + +#ifdef UNICODE + curlx_free(tchar_oldpath); + curlx_free(tchar_newpath); +#endif + + return res; +} +#endif + +#undef CURLX_MALLOC +#undef CURLX_FREE + +#endif /* _WIN32 */ diff --git a/vendor/hydra/vendor/curl/lib/curlx/fopen.h b/vendor/hydra/vendor/curl/lib/curlx/fopen.h index 51f4dbca..53c079ee 100644 --- a/vendor/hydra/vendor/curl/lib/curlx/fopen.h +++ b/vendor/hydra/vendor/curl/lib/curlx/fopen.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "../curl_setup.h" #include "multibyte.h" @@ -34,25 +33,44 @@ int curlx_fseek(void *stream, curl_off_t offset, int whence); -#if defined(_WIN32) && !defined(UNDER_CE) +#ifdef _WIN32 +#ifndef CURL_WINDOWS_UWP +HANDLE curlx_CreateFile(const char *filename, + DWORD dwDesiredAccess, + DWORD dwShareMode, + LPSECURITY_ATTRIBUTES lpSecurityAttributes, + DWORD dwCreationDisposition, + DWORD dwFlagsAndAttributes, + HANDLE hTemplateFile); +#endif /* !CURL_WINDOWS_UWP */ FILE *curlx_win32_fopen(const char *filename, const char *mode); +FILE *curlx_win32_freopen(const char *filename, const char *mode, FILE *fh); int curlx_win32_stat(const char *path, struct_stat *buffer); int curlx_win32_open(const char *filename, int oflag, ...); -#define CURLX_FOPEN_LOW(fname, mode) curlx_win32_fopen(fname, mode) -#define curlx_stat(fname, stp) curlx_win32_stat(fname, stp) -#define curlx_open curlx_win32_open +int curlx_win32_rename(const char *oldpath, const char *newpath); +#define CURLX_FOPEN_LOW(fname, mode) curlx_win32_fopen(fname, mode) +#define CURLX_FREOPEN_LOW(fname, mode, fh) curlx_win32_freopen(fname, mode, fh) +#define curlx_stat(fname, stp) curlx_win32_stat(fname, stp) +#define curlx_open curlx_win32_open +#define curlx_rename curlx_win32_rename #else -#define CURLX_FOPEN_LOW fopen -#define curlx_stat(fname, stp) stat(fname, stp) -#define curlx_open open +#define CURLX_FOPEN_LOW fopen +#define CURLX_FREOPEN_LOW freopen +#define curlx_stat(fname, stp) stat(fname, stp) +#define curlx_open open +#define curlx_rename rename #endif #ifdef CURLDEBUG -#define curlx_fopen(file,mode) curl_dbg_fopen(file,mode,__LINE__,__FILE__) -#define curlx_fdopen(file,mode) curl_dbg_fdopen(file,mode,__LINE__,__FILE__) -#define curlx_fclose(file) curl_dbg_fclose(file,__LINE__,__FILE__) +#define curlx_fopen(file, mode) curl_dbg_fopen(file, mode, __LINE__, __FILE__) +#define curlx_freopen(file, mode, fh) \ + curl_dbg_freopen(file, mode, fh, __LINE__, __FILE__) +#define curlx_fdopen(file, mode) \ + curl_dbg_fdopen(file, mode, __LINE__, __FILE__) +#define curlx_fclose(file) curl_dbg_fclose(file, __LINE__, __FILE__) #else #define curlx_fopen CURLX_FOPEN_LOW +#define curlx_freopen CURLX_FREOPEN_LOW #define curlx_fdopen fdopen #define curlx_fclose fclose #endif diff --git a/vendor/hydra/vendor/curl/lib/curlx/inet_ntop.c b/vendor/hydra/vendor/curl/lib/curlx/inet_ntop.c index 884cfb79..6bea5e1d 100644 --- a/vendor/hydra/vendor/curl/lib/curlx/inet_ntop.c +++ b/vendor/hydra/vendor/curl/lib/curlx/inet_ntop.c @@ -16,7 +16,6 @@ * * SPDX-License-Identifier: ISC */ - #include "../curl_setup.h" #ifndef HAVE_INET_NTOP @@ -32,6 +31,8 @@ #endif #include "inet_ntop.h" +#include "snprintf.h" +#include "strcopy.h" #define IN6ADDRSZ 16 /* #define INADDRSZ 4 */ @@ -61,24 +62,23 @@ static char *inet_ntop4(const unsigned char *src, char *dst, size_t size) DEBUGASSERT(size >= 16); - /* this sprintf() does not overflow the buffer. Avoids snprintf to work more - widely. Avoids the msnprintf family to work as a curlx function. */ - (void)(sprintf)(tmp, "%d.%d.%d.%d", - ((int)((unsigned char)src[0])) & 0xff, - ((int)((unsigned char)src[1])) & 0xff, - ((int)((unsigned char)src[2])) & 0xff, - ((int)((unsigned char)src[3])) & 0xff); + /* this snprintf() does not overflow the buffer. */ + SNPRINTF(tmp, sizeof(tmp), "%d.%d.%d.%d", + ((int)((unsigned char)src[0])) & 0xff, + ((int)((unsigned char)src[1])) & 0xff, + ((int)((unsigned char)src[2])) & 0xff, + ((int)((unsigned char)src[3])) & 0xff); len = strlen(tmp); if(len == 0 || len >= size) { #ifdef USE_WINSOCK - CURL_SETERRNO(WSAEINVAL); + errno = WSAEINVAL; #else - CURL_SETERRNO(ENOSPC); + errno = ENOSPC; #endif return NULL; } - strcpy(dst, tmp); + curlx_strcopy(dst, size, tmp, len); return dst; } @@ -109,17 +109,18 @@ static char *inet_ntop6(const unsigned char *src, char *dst, size_t size) */ memset(words, '\0', sizeof(words)); for(i = 0; i < IN6ADDRSZ; i++) - words[i/2] |= ((unsigned int)src[i] << ((1 - (i % 2)) << 3)); + words[i / 2] |= ((unsigned int)src[i] << ((1 - (i % 2)) << 3)); best.base = -1; - cur.base = -1; + cur.base = -1; best.len = 0; cur.len = 0; for(i = 0; i < (IN6ADDRSZ / INT16SZ); i++) { if(words[i] == 0) { if(cur.base == -1) { - cur.base = i; cur.len = 1; + cur.base = i; + cur.len = 1; } else cur.len++; @@ -152,7 +153,7 @@ static char *inet_ntop6(const unsigned char *src, char *dst, size_t size) /* Is this address an encapsulated IPv4? */ if(i == 6 && best.base == 0 && - (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) { + (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) { if(!inet_ntop4(src + 12, tp, sizeof(tmp) - (tp - tmp))) { return NULL; } @@ -160,7 +161,7 @@ static char *inet_ntop6(const unsigned char *src, char *dst, size_t size) break; } else { - /* Lower-case digits. Can't use the set from mprintf.c since this + /* Lower-case digits. Cannot use the set from mprintf.c since this needs to work as a curlx function */ static const unsigned char ldigits[] = "0123456789abcdef"; @@ -180,19 +181,18 @@ static char *inet_ntop6(const unsigned char *src, char *dst, size_t size) */ if(best.base != -1 && (best.base + best.len) == (IN6ADDRSZ / INT16SZ)) *tp++ = ':'; - *tp++ = '\0'; - /* Check for overflow, copy, and we are done. - */ - if((size_t)(tp - tmp) > size) { + /* Check for overflow, copy, and we are done. */ + if((size_t)(tp - tmp) >= size) { #ifdef USE_WINSOCK - CURL_SETERRNO(WSAEINVAL); + errno = WSAEINVAL; #else - CURL_SETERRNO(ENOSPC); + errno = ENOSPC; #endif return NULL; } - strcpy(dst, tmp); + + curlx_strcopy(dst, size, tmp, tp - tmp); return dst; } @@ -215,8 +215,8 @@ char *curlx_inet_ntop(int af, const void *src, char *buf, size_t size) case AF_INET6: return inet_ntop6((const unsigned char *)src, buf, size); default: - CURL_SETERRNO(SOCKEAFNOSUPPORT); + errno = SOCKEAFNOSUPPORT; return NULL; } } -#endif /* HAVE_INET_NTOP */ +#endif /* HAVE_INET_NTOP */ diff --git a/vendor/hydra/vendor/curl/lib/curlx/inet_ntop.h b/vendor/hydra/vendor/curl/lib/curlx/inet_ntop.h index 490f49e8..45b63d97 100644 --- a/vendor/hydra/vendor/curl/lib/curlx/inet_ntop.h +++ b/vendor/hydra/vendor/curl/lib/curlx/inet_ntop.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "../curl_setup.h" #ifdef HAVE_INET_NTOP @@ -37,11 +36,11 @@ #include #endif #ifdef __AMIGA__ -#define curlx_inet_ntop(af,addr,buf,size) \ +#define curlx_inet_ntop(af, addr, buf, size) \ (char *)inet_ntop(af, CURL_UNCONST(addr), (unsigned char *)buf, \ (curl_socklen_t)(size)) #else -#define curlx_inet_ntop(af,addr,buf,size) \ +#define curlx_inet_ntop(af, addr, buf, size) \ inet_ntop(af, addr, buf, (curl_socklen_t)(size)) #endif #else diff --git a/vendor/hydra/vendor/curl/lib/curlx/inet_pton.c b/vendor/hydra/vendor/curl/lib/curlx/inet_pton.c index d2b39ae9..703a7b96 100644 --- a/vendor/hydra/vendor/curl/lib/curlx/inet_pton.c +++ b/vendor/hydra/vendor/curl/lib/curlx/inet_pton.c @@ -17,9 +17,8 @@ * * SPDX-License-Identifier: ISC */ - #include "../curl_setup.h" -#include "../curl_ctype.h" + #include "strparse.h" #ifndef HAVE_INET_PTON @@ -54,8 +53,8 @@ * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. */ -static int inet_pton4(const char *src, unsigned char *dst); -static int inet_pton6(const char *src, unsigned char *dst); +static int inet_pton4(const char *src, unsigned char *dst); +static int inet_pton6(const char *src, unsigned char *dst); /* int * inet_pton(af, src, dst) @@ -73,8 +72,7 @@ static int inet_pton6(const char *src, unsigned char *dst); * author: * Paul Vixie, 1996. */ -int -curlx_inet_pton(int af, const char *src, void *dst) +int curlx_inet_pton(int af, const char *src, void *dst) { switch(af) { case AF_INET: @@ -82,7 +80,7 @@ curlx_inet_pton(int af, const char *src, void *dst) case AF_INET6: return inet_pton6(src, (unsigned char *)dst); default: - CURL_SETERRNO(SOCKEAFNOSUPPORT); + errno = SOCKEAFNOSUPPORT; return -1; } /* NOTREACHED */ @@ -98,8 +96,7 @@ curlx_inet_pton(int af, const char *src, void *dst) * author: * Paul Vixie, 1996. */ -static int -inet_pton4(const char *src, unsigned char *dst) +static int inet_pton4(const char *src, unsigned char *dst) { int saw_digit, octets, ch; unsigned char tmp[INADDRSZ], *tp; @@ -151,8 +148,7 @@ inet_pton4(const char *src, unsigned char *dst) * author: * Paul Vixie, 1996. */ -static int -inet_pton6(const char *src, unsigned char *dst) +static int inet_pton6(const char *src, unsigned char *dst) { unsigned char tmp[IN6ADDRSZ], *tp, *endp, *colonp; const char *curtok; @@ -172,7 +168,7 @@ inet_pton6(const char *src, unsigned char *dst) while((ch = *src++) != '\0') { if(ISXDIGIT(ch)) { val <<= 4; - val |= Curl_hexval(ch); + val |= curlx_hexval(ch); if(++saw_xdigit > 4) return 0; continue; @@ -187,14 +183,14 @@ inet_pton6(const char *src, unsigned char *dst) } if(tp + INT16SZ > endp) return 0; - *tp++ = (unsigned char) ((val >> 8) & 0xff); - *tp++ = (unsigned char) (val & 0xff); + *tp++ = (unsigned char)((val >> 8) & 0xff); + *tp++ = (unsigned char)(val & 0xff); saw_xdigit = 0; val = 0; continue; } if(ch == '.' && ((tp + INADDRSZ) <= endp) && - inet_pton4(curtok, tp) > 0) { + inet_pton4(curtok, tp) > 0) { tp += INADDRSZ; saw_xdigit = 0; break; /* '\0' was seen by inet_pton4(). */ @@ -204,8 +200,8 @@ inet_pton6(const char *src, unsigned char *dst) if(saw_xdigit) { if(tp + INT16SZ > endp) return 0; - *tp++ = (unsigned char) ((val >> 8) & 0xff); - *tp++ = (unsigned char) (val & 0xff); + *tp++ = (unsigned char)((val >> 8) & 0xff); + *tp++ = (unsigned char)(val & 0xff); } if(colonp) { /* diff --git a/vendor/hydra/vendor/curl/lib/curlx/inet_pton.h b/vendor/hydra/vendor/curl/lib/curlx/inet_pton.h index a9ad24c9..fc3ae3d2 100644 --- a/vendor/hydra/vendor/curl/lib/curlx/inet_pton.h +++ b/vendor/hydra/vendor/curl/lib/curlx/inet_pton.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "../curl_setup.h" #ifdef HAVE_INET_PTON @@ -37,9 +36,11 @@ #include #endif #ifdef __AMIGA__ -#define curlx_inet_pton(x,y,z) inet_pton(x,(unsigned char *)CURL_UNCONST(y),z) +#define curlx_inet_pton(x, y, z) \ + inet_pton(x, (unsigned char *)CURL_UNCONST(y), z) #else -#define curlx_inet_pton(x,y,z) inet_pton(x,y,z) +#define curlx_inet_pton(x, y, z) \ + inet_pton(x, y, z) #endif #else int curlx_inet_pton(int, const char *, void *); diff --git a/vendor/hydra/vendor/curl/lib/curlx/multibyte.c b/vendor/hydra/vendor/curl/lib/curlx/multibyte.c index 9e60edf7..529091ad 100644 --- a/vendor/hydra/vendor/curl/lib/curlx/multibyte.c +++ b/vendor/hydra/vendor/curl/lib/curlx/multibyte.c @@ -21,18 +21,9 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - -/* - * This file is 'mem-include-scan' clean, which means its memory allocations - * are not tracked by the curl memory tracker memdebug, so they must not use - * `CURLDEBUG` macro replacements in memdebug.h for free, malloc, etc. To avoid - * these macro replacements, wrap the names in parentheses to call the original - * versions: `ptr = (malloc)(123)`, `(free)(ptr)`, etc. - */ - #include "../curl_setup.h" -#ifdef _WIN32 +#if defined(_WIN32) && defined(UNICODE) #include "multibyte.h" @@ -48,11 +39,11 @@ wchar_t *curlx_convert_UTF8_to_wchar(const char *str_utf8) int str_w_len = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, str_utf8, -1, NULL, 0); if(str_w_len > 0) { - str_w = (malloc)(str_w_len * sizeof(wchar_t)); + str_w = curlx_malloc(str_w_len * sizeof(wchar_t)); if(str_w) { if(MultiByteToWideChar(CP_UTF8, 0, str_utf8, -1, str_w, str_w_len) == 0) { - (free)(str_w); + curlx_free(str_w); return NULL; } } @@ -70,11 +61,11 @@ char *curlx_convert_wchar_to_UTF8(const wchar_t *str_w) int bytes = WideCharToMultiByte(CP_UTF8, 0, str_w, -1, NULL, 0, NULL, NULL); if(bytes > 0) { - str_utf8 = (malloc)(bytes); + str_utf8 = curlx_malloc(bytes); if(str_utf8) { if(WideCharToMultiByte(CP_UTF8, 0, str_w, -1, str_utf8, bytes, NULL, NULL) == 0) { - (free)(str_utf8); + curlx_free(str_utf8); return NULL; } } @@ -84,4 +75,4 @@ char *curlx_convert_wchar_to_UTF8(const wchar_t *str_w) return str_utf8; } -#endif /* _WIN32 */ +#endif /* _WIN32 && UNICODE */ diff --git a/vendor/hydra/vendor/curl/lib/curlx/multibyte.h b/vendor/hydra/vendor/curl/lib/curlx/multibyte.h index c60ce258..26da0f08 100644 --- a/vendor/hydra/vendor/curl/lib/curlx/multibyte.h +++ b/vendor/hydra/vendor/curl/lib/curlx/multibyte.h @@ -26,35 +26,27 @@ #include "../curl_setup.h" #ifdef _WIN32 -/* MultiByte conversions using Windows kernel32 library. */ -wchar_t *curlx_convert_UTF8_to_wchar(const char *str_utf8); -char *curlx_convert_wchar_to_UTF8(const wchar_t *str_w); -#endif /* * Macros curlx_convert_UTF8_to_tchar(), curlx_convert_tchar_to_UTF8() - * and curlx_unicodefree() main purpose is to minimize the number of - * preprocessor conditional directives needed by code using these - * to differentiate Unicode from non-Unicode builds. + * main purpose is to minimize the number of preprocessor conditional + * directives needed by code using these to differentiate Unicode from + * non-Unicode builds. * * In the case of a non-Unicode build the tchar strings are char strings that * are duplicated via strdup and remain in whatever the passed in encoding is, * which is assumed to be UTF-8 but may be other encoding. Therefore the * significance of the conversion functions is primarily for Unicode builds. - * - * Allocated memory should be free'd with curlx_unicodefree(). - * - * Note: Because these are curlx functions their memory usage is not tracked - * by the curl memory tracker memdebug. you will notice that curlx - * function-like macros call free and strdup in parentheses, eg (strdup)(ptr), - * and that is to ensure that the curl memdebug override macros do not replace - * them. */ -#if defined(UNICODE) && defined(_WIN32) +#ifdef UNICODE -#define curlx_convert_UTF8_to_tchar(ptr) curlx_convert_UTF8_to_wchar((ptr)) -#define curlx_convert_tchar_to_UTF8(ptr) curlx_convert_wchar_to_UTF8((ptr)) +/* MultiByte conversions using Windows kernel32 library. */ +wchar_t *curlx_convert_UTF8_to_wchar(const char *str_utf8); +char *curlx_convert_wchar_to_UTF8(const wchar_t *str_w); + +#define curlx_convert_UTF8_to_tchar(ptr) curlx_convert_UTF8_to_wchar(ptr) +#define curlx_convert_tchar_to_UTF8(ptr) curlx_convert_wchar_to_UTF8(ptr) typedef union { unsigned short *tchar_ptr; @@ -63,10 +55,10 @@ typedef union { const unsigned short *const_tbyte_ptr; } xcharp_u; -#else +#else /* !UNICODE */ -#define curlx_convert_UTF8_to_tchar(ptr) (strdup)(ptr) -#define curlx_convert_tchar_to_UTF8(ptr) (strdup)(ptr) +#define curlx_convert_UTF8_to_tchar(ptr) curlx_strdup(ptr) +#define curlx_convert_tchar_to_UTF8(ptr) curlx_strdup(ptr) typedef union { char *tchar_ptr; @@ -75,9 +67,7 @@ typedef union { const unsigned char *const_tbyte_ptr; } xcharp_u; -#endif /* UNICODE && _WIN32 */ - -/* the purpose of this macro is to free() without being traced by memdebug */ -#define curlx_unicodefree(ptr) (free)(CURL_UNCONST(ptr)) +#endif /* UNICODE */ +#endif /* _WIN32 */ #endif /* HEADER_CURL_MULTIBYTE_H */ diff --git a/vendor/hydra/vendor/curl/lib/curlx/nonblock.c b/vendor/hydra/vendor/curl/lib/curlx/nonblock.c index b944f954..96bf3db6 100644 --- a/vendor/hydra/vendor/curl/lib/curlx/nonblock.c +++ b/vendor/hydra/vendor/curl/lib/curlx/nonblock.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "../curl_setup.h" #ifdef HAVE_SYS_IOCTL_H @@ -88,6 +87,6 @@ int curlx_nonblock(curl_socket_t sockfd, /* operate on this */ return setsockopt(sockfd, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b)); #else -# error "no non-blocking method was found/used/set" +#error "no non-blocking method was found/used/set" #endif } diff --git a/vendor/hydra/vendor/curl/lib/curlx/nonblock.h b/vendor/hydra/vendor/curl/lib/curlx/nonblock.h index 4a1a6151..ee2cd286 100644 --- a/vendor/hydra/vendor/curl/lib/curlx/nonblock.h +++ b/vendor/hydra/vendor/curl/lib/curlx/nonblock.h @@ -24,8 +24,6 @@ * ***************************************************************************/ -#include /* for curl_socket_t */ - int curlx_nonblock(curl_socket_t sockfd, /* operate on this */ int nonblock /* TRUE or FALSE */); diff --git a/vendor/hydra/vendor/curl/lib/rename.h b/vendor/hydra/vendor/curl/lib/curlx/snprintf.h similarity index 75% rename from vendor/hydra/vendor/curl/lib/rename.h rename to vendor/hydra/vendor/curl/lib/curlx/snprintf.h index 04440820..266ea137 100644 --- a/vendor/hydra/vendor/curl/lib/rename.h +++ b/vendor/hydra/vendor/curl/lib/curlx/snprintf.h @@ -1,5 +1,3 @@ -#ifndef HEADER_CURL_RENAME_H -#define HEADER_CURL_RENAME_H /*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | @@ -24,6 +22,15 @@ * ***************************************************************************/ -int Curl_rename(const char *oldpath, const char *newpath); +/* Raw snprintf() for curlx */ -#endif /* HEADER_CURL_RENAME_H */ +#ifdef WITHOUT_LIBCURL /* when built for the test servers */ +#if defined(_MSC_VER) && (_MSC_VER < 1900) /* adjust for old MSVC */ +#define SNPRINTF _snprintf +#else +#define SNPRINTF snprintf +#endif +#else /* !WITHOUT_LIBCURL */ +#include +#define SNPRINTF curl_msnprintf +#endif /* WITHOUT_LIBCURL */ diff --git a/vendor/hydra/vendor/curl/lib/vtls/mbedtls_threadlock.h b/vendor/hydra/vendor/curl/lib/curlx/strcopy.c similarity index 55% rename from vendor/hydra/vendor/curl/lib/vtls/mbedtls_threadlock.h rename to vendor/hydra/vendor/curl/lib/curlx/strcopy.c index 9402af6e..d6bff153 100644 --- a/vendor/hydra/vendor/curl/lib/vtls/mbedtls_threadlock.h +++ b/vendor/hydra/vendor/curl/lib/curlx/strcopy.c @@ -1,5 +1,3 @@ -#ifndef HEADER_CURL_MBEDTLS_THREADLOCK_H -#define HEADER_CURL_MBEDTLS_THREADLOCK_H /*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | @@ -8,7 +6,6 @@ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. - * Copyright (C) Hoi-Ho Chan, * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -26,25 +23,28 @@ ***************************************************************************/ #include "../curl_setup.h" -#ifdef USE_MBEDTLS +#include "strcopy.h" -#if (defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)) || \ - defined(_WIN32) - -int Curl_mbedtlsthreadlock_thread_setup(void); -int Curl_mbedtlsthreadlock_thread_cleanup(void); -int Curl_mbedtlsthreadlock_lock_function(int n); -int Curl_mbedtlsthreadlock_unlock_function(int n); - -#else - -#define Curl_mbedtlsthreadlock_thread_setup() 1 -#define Curl_mbedtlsthreadlock_thread_cleanup() 1 -#define Curl_mbedtlsthreadlock_lock_function(x) 1 -#define Curl_mbedtlsthreadlock_unlock_function(x) 1 - -#endif /* (USE_THREADS_POSIX && HAVE_PTHREAD_H) || _WIN32 */ - -#endif /* USE_MBEDTLS */ - -#endif /* HEADER_CURL_MBEDTLS_THREADLOCK_H */ +/* + * curlx_strcopy() is a replacement for strcpy. + * + * Provide the target buffer @dest and size of the target buffer @dsize, If + * the source string @src with its *string length* @slen fits in the target + * buffer it will be copied there - including storing a null terminator. + * + * If the target buffer is too small, the copy is not performed but if the + * target buffer has a non-zero size it will get a null terminator stored. + */ +void curlx_strcopy(char *dest, /* destination buffer */ + size_t dsize, /* size of target buffer */ + const char *src, /* source string */ + size_t slen) /* length of source string to copy */ +{ + DEBUGASSERT(slen < dsize); + if(slen < dsize) { + memcpy(dest, src, slen); + dest[slen] = 0; + } + else if(dsize) + dest[0] = 0; +} diff --git a/vendor/hydra/vendor/curl/lib/curl_mem_undef.h b/vendor/hydra/vendor/curl/lib/curlx/strcopy.h similarity index 78% rename from vendor/hydra/vendor/curl/lib/curl_mem_undef.h rename to vendor/hydra/vendor/curl/lib/curlx/strcopy.h index 2be114cb..d671149c 100644 --- a/vendor/hydra/vendor/curl/lib/curl_mem_undef.h +++ b/vendor/hydra/vendor/curl/lib/curlx/strcopy.h @@ -1,3 +1,5 @@ +#ifndef HEADER_CURLX_STRCOPY_H +#define HEADER_CURLX_STRCOPY_H /*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | @@ -22,16 +24,9 @@ * ***************************************************************************/ -/* Unset redefined system symbols. */ +void curlx_strcopy(char *dest, + size_t dsize, /* size of target buffer */ + const char *src, + size_t slen); /* length of string to copy */ -#undef strdup -#undef malloc -#undef calloc -#undef realloc -#undef free -#ifdef _WIN32 -#undef Curl_tcsdup -#endif - -#undef HEADER_CURL_MEMORY_H -#undef HEADER_CURL_MEMDEBUG_H +#endif /* HEADER_CURLX_STRCOPY_H */ diff --git a/vendor/hydra/vendor/curl/lib/curlx/strerr.c b/vendor/hydra/vendor/curl/lib/curlx/strerr.c index e5227554..3f1b1f5c 100644 --- a/vendor/hydra/vendor/curl/lib/curlx/strerr.c +++ b/vendor/hydra/vendor/curl/lib/curlx/strerr.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "../curl_setup.h" #ifdef HAVE_STRERROR_R @@ -32,35 +31,17 @@ # endif #endif -#include - -#ifndef WITHOUT_LIBCURL -#include -#define SNPRINTF curl_msnprintf -#else -/* when built for the test servers */ - -/* adjust for old MSVC */ -#if defined(_MSC_VER) && (_MSC_VER < 1900) -#define SNPRINTF _snprintf -#else -#define SNPRINTF snprintf -#endif -#endif /* !WITHOUT_LIBCURL */ - #include "winapi.h" +#include "snprintf.h" #include "strerr.h" -/* The last 2 #include files should be in this order */ -#include "../curl_memory.h" -#include "../memdebug.h" +#include "strcopy.h" #ifdef USE_WINSOCK /* This is a helper function for curlx_strerror that converts Winsock error * codes (WSAGetLastError) to error messages. * Returns NULL if no error message was found for error code. */ -static const char * -get_winsock_error(int err, char *buf, size_t len) +static const char *get_winsock_error(int err, char *buf, size_t len) { #ifndef CURL_DISABLE_VERBOSE_STRINGS const char *p; @@ -243,8 +224,7 @@ get_winsock_error(int err, char *buf, size_t len) return NULL; } alen = strlen(p); - if(alen < len) - strcpy(buf, p); + curlx_strcopy(buf, len, p, alen); return buf; #endif } @@ -287,20 +267,12 @@ const char *curlx_strerror(int err, char *buf, size_t buflen) *buf = '\0'; #ifdef _WIN32 -#ifndef UNDER_CE - /* 'sys_nerr' is the maximum errno number, it is not widely portable */ - if(err >= 0 && err < sys_nerr) - SNPRINTF(buf, buflen, "%s", sys_errlist[err]); - else -#endif - { - if( + if((!strerror_s(buf, buflen, err) || !strcmp(buf, "Unknown error")) && #ifdef USE_WINSOCK - !get_winsock_error(err, buf, buflen) && + !get_winsock_error(err, buf, buflen) && #endif - !curlx_get_winapi_error((DWORD)err, buf, buflen)) - SNPRINTF(buf, buflen, "Unknown error %d (%#x)", err, err); - } + !curlx_get_winapi_error((DWORD)err, buf, buflen)) + SNPRINTF(buf, buflen, "Unknown error %d (%#x)", err, err); #else /* !_WIN32 */ #if defined(HAVE_STRERROR_R) && defined(HAVE_POSIX_STRERROR_R) @@ -350,7 +322,7 @@ const char *curlx_strerror(int err, char *buf, size_t buflen) *p = '\0'; if(errno != old_errno) - CURL_SETERRNO(old_errno); + errno = old_errno; #ifdef _WIN32 if(old_win_err != GetLastError()) diff --git a/vendor/hydra/vendor/curl/lib/curlx/strparse.c b/vendor/hydra/vendor/curl/lib/curlx/strparse.c index a29d8be2..f11b58b7 100644 --- a/vendor/hydra/vendor/curl/lib/curlx/strparse.c +++ b/vendor/hydra/vendor/curl/lib/curlx/strparse.c @@ -21,13 +21,8 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "strparse.h" -#ifndef WITHOUT_LIBCURL -#include /* for curl_strnequal() */ -#endif - void curlx_str_init(struct Curl_str *out) { out->str = NULL; @@ -66,8 +61,7 @@ int curlx_str_until(const char **linep, struct Curl_str *out, /* Get a word until the first space or end of string. At least one byte long. return non-zero on error */ -int curlx_str_word(const char **linep, struct Curl_str *out, - const size_t max) +int curlx_str_word(const char **linep, struct Curl_str *out, const size_t max) { return curlx_str_until(linep, out, max, ' '); } @@ -95,8 +89,7 @@ int curlx_str_untilnl(const char **linep, struct Curl_str *out, return STRE_OK; } - -/* Get a "quoted" word. No escaping possible. +/* Get a "quoted" word. Escaped quotes are supported. return non-zero on error */ int curlx_str_quotedword(const char **linep, struct Curl_str *out, const size_t max) @@ -110,6 +103,11 @@ int curlx_str_quotedword(const char **linep, struct Curl_str *out, return STRE_BEGQUOTE; s++; while(*s && (*s != '\"')) { + if(*s == '\\' && s[1]) { + s++; + if(++len > max) + return STRE_BIG; + } s++; if(++len > max) return STRE_BIG; @@ -141,13 +139,13 @@ int curlx_str_singlespace(const char **linep) } /* given an ASCII character and max ascii, return TRUE if valid */ -#define valid_digit(x,m) \ - (((x) >= '0') && ((x) <= m) && Curl_hexasciitable[(x)-'0']) +#define valid_digit(x, m) \ + (((x) >= '0') && ((x) <= m) && curlx_hexasciitable[(x) - '0']) /* We use 16 for the zero index (and the necessary bitwise AND in the loop) to be able to have a non-zero value there to make valid_digit() able to use the info */ -const unsigned char Curl_hexasciitable[] = { +const unsigned char curlx_hexasciitable[] = { 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 0x30: 0 - 9 */ 0, 0, 0, 0, 0, 0, 0, 10, 11, 12, 13, 14, 15, /* 0x41: A - F */ @@ -173,7 +171,7 @@ static int str_num_base(const char **linep, curl_off_t *nump, curl_off_t max, if(max < base) { /* special-case low max scenario because check needs to be different */ do { - int n = Curl_hexval(*p++); + int n = curlx_hexval(*p++); num = num * base + n; if(num > max) return STRE_OVERFLOW; @@ -181,7 +179,7 @@ static int str_num_base(const char **linep, curl_off_t *nump, curl_off_t max, } else { do { - int n = Curl_hexval(*p++); + int n = curlx_hexval(*p++); if(num > ((max - n) / base)) return STRE_OVERFLOW; num = num * base + n; diff --git a/vendor/hydra/vendor/curl/lib/curlx/strparse.h b/vendor/hydra/vendor/curl/lib/curlx/strparse.h index 6a0bf28d..ae8fd19d 100644 --- a/vendor/hydra/vendor/curl/lib/curlx/strparse.h +++ b/vendor/hydra/vendor/curl/lib/curlx/strparse.h @@ -45,7 +45,7 @@ struct Curl_str { void curlx_str_init(struct Curl_str *out); void curlx_str_assign(struct Curl_str *out, const char *str, size_t len); -#define curlx_str(x) ((x)->str) +#define curlx_str(x) ((x)->str) #define curlx_strlen(x) ((x)->len) /* Get a word until the first space @@ -62,7 +62,7 @@ int curlx_str_until(const char **linep, struct Curl_str *out, const size_t max, int curlx_str_untilnl(const char **linep, struct Curl_str *out, const size_t max); -/* Get a "quoted" word. No escaping possible. +/* Get a "quoted" word. Escaped quotes are supported. return non-zero on error */ int curlx_str_quotedword(const char **linep, struct Curl_str *out, const size_t max); @@ -106,7 +106,7 @@ void curlx_str_passblanks(const char **linep); returns 10. THIS ONLY WORKS ON VALID HEXADECIMAL LETTER INPUT. Verify before calling this! */ -extern const unsigned char Curl_hexasciitable[]; -#define Curl_hexval(x) (unsigned char)(Curl_hexasciitable[(x) - '0'] & 0x0f) +extern const unsigned char curlx_hexasciitable[]; +#define curlx_hexval(x) (unsigned char)(curlx_hexasciitable[(x) - '0'] & 0x0f) #endif /* HEADER_CURL_STRPARSE_H */ diff --git a/vendor/hydra/vendor/curl/lib/curlx/timediff.c b/vendor/hydra/vendor/curl/lib/curlx/timediff.c index a90da961..694c8d83 100644 --- a/vendor/hydra/vendor/curl/lib/curlx/timediff.c +++ b/vendor/hydra/vendor/curl/lib/curlx/timediff.c @@ -21,11 +21,8 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "timediff.h" -#include - /* * Converts number of milliseconds into a timeval structure. * @@ -84,5 +81,5 @@ struct timeval *curlx_mstotv(struct timeval *tv, timediff_t ms) */ timediff_t curlx_tvtoms(struct timeval *tv) { - return (tv->tv_sec*1000) + (timediff_t)(tv->tv_usec/1000); + return (tv->tv_sec * 1000) + (timediff_t)(tv->tv_usec / 1000); } diff --git a/vendor/hydra/vendor/curl/lib/curlx/timediff.h b/vendor/hydra/vendor/curl/lib/curlx/timediff.h index aa224381..e19b0f44 100644 --- a/vendor/hydra/vendor/curl/lib/curlx/timediff.h +++ b/vendor/hydra/vendor/curl/lib/curlx/timediff.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "../curl_setup.h" /* Use a larger type even for 32-bit time_t systems so that we can keep diff --git a/vendor/hydra/vendor/curl/lib/curlx/timeval.c b/vendor/hydra/vendor/curl/lib/curlx/timeval.c index bd8b9bce..fa7e528d 100644 --- a/vendor/hydra/vendor/curl/lib/curlx/timeval.c +++ b/vendor/hydra/vendor/curl/lib/curlx/timeval.c @@ -21,12 +21,10 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "timeval.h" #ifdef _WIN32 -#include #include "version_win32.h" #include "../system_win32.h" @@ -47,9 +45,8 @@ void curlx_now_init(void) } /* In case of bug fix this function has a counterpart in tool_util.c */ -struct curltime curlx_now(void) +void curlx_pnow(struct curltime *pnow) { - struct curltime now; bool isVistaOrGreater; isVistaOrGreater = Curl_isVistaOrGreater; if(isVistaOrGreater) { /* QPC timer might have issues pre-Vista */ @@ -58,8 +55,8 @@ struct curltime curlx_now(void) freq = Curl_freq; DEBUGASSERT(freq.QuadPart); QueryPerformanceCounter(&count); - now.tv_sec = (time_t)(count.QuadPart / freq.QuadPart); - now.tv_usec = (int)((count.QuadPart % freq.QuadPart) * 1000000 / + pnow->tv_sec = (time_t)(count.QuadPart / freq.QuadPart); + pnow->tv_usec = (int)((count.QuadPart % freq.QuadPart) * 1000000 / freq.QuadPart); } else { @@ -73,16 +70,15 @@ struct curltime curlx_now(void) #pragma warning(pop) #endif - now.tv_sec = (time_t)(milliseconds / 1000); - now.tv_usec = (int)((milliseconds % 1000) * 1000); + pnow->tv_sec = (time_t)(milliseconds / 1000); + pnow->tv_usec = (int)((milliseconds % 1000) * 1000); } - return now; } -#elif defined(HAVE_CLOCK_GETTIME_MONOTONIC) || \ +#elif defined(HAVE_CLOCK_GETTIME_MONOTONIC) || \ defined(HAVE_CLOCK_GETTIME_MONOTONIC_RAW) -struct curltime curlx_now(void) +void curlx_pnow(struct curltime *pnow) { /* ** clock_gettime() is granted to be increased monotonically when the @@ -91,10 +87,6 @@ struct curltime curlx_now(void) ** in any case the time starting point does not change once that the ** system has started up. */ -#ifdef HAVE_GETTIMEOFDAY - struct timeval now; -#endif - struct curltime cnow; struct timespec tsnow; /* @@ -103,7 +95,7 @@ struct curltime curlx_now(void) ** called on unsupported OS version. */ #if defined(__APPLE__) && defined(HAVE_BUILTIN_AVAILABLE) && \ - (HAVE_BUILTIN_AVAILABLE == 1) + (HAVE_BUILTIN_AVAILABLE == 1) bool have_clock_gettime = FALSE; if(__builtin_available(macOS 10.12, iOS 10, tvOS 10, watchOS 3, *)) have_clock_gettime = TRUE; @@ -111,25 +103,25 @@ struct curltime curlx_now(void) #ifdef HAVE_CLOCK_GETTIME_MONOTONIC_RAW if( -#if defined(__APPLE__) && defined(HAVE_BUILTIN_AVAILABLE) && \ - (HAVE_BUILTIN_AVAILABLE == 1) +#if defined(__APPLE__) && defined(HAVE_BUILTIN_AVAILABLE) && \ + (HAVE_BUILTIN_AVAILABLE == 1) have_clock_gettime && #endif (clock_gettime(CLOCK_MONOTONIC_RAW, &tsnow) == 0)) { - cnow.tv_sec = tsnow.tv_sec; - cnow.tv_usec = (int)(tsnow.tv_nsec / 1000); + pnow->tv_sec = tsnow.tv_sec; + pnow->tv_usec = (int)(tsnow.tv_nsec / 1000); } else #endif if( #if defined(__APPLE__) && defined(HAVE_BUILTIN_AVAILABLE) && \ - (HAVE_BUILTIN_AVAILABLE == 1) + (HAVE_BUILTIN_AVAILABLE == 1) have_clock_gettime && #endif (clock_gettime(CLOCK_MONOTONIC, &tsnow) == 0)) { - cnow.tv_sec = tsnow.tv_sec; - cnow.tv_usec = (int)(tsnow.tv_nsec / 1000); + pnow->tv_sec = tsnow.tv_sec; + pnow->tv_usec = (int)(tsnow.tv_nsec / 1000); } /* ** Even when the configure process has truly detected monotonic clock @@ -138,17 +130,17 @@ struct curltime curlx_now(void) */ #ifdef HAVE_GETTIMEOFDAY else { + struct timeval now; (void)gettimeofday(&now, NULL); - cnow.tv_sec = now.tv_sec; - cnow.tv_usec = (int)now.tv_usec; + pnow->tv_sec = now.tv_sec; + pnow->tv_usec = (int)now.tv_usec; } #else else { - cnow.tv_sec = time(NULL); - cnow.tv_usec = 0; + pnow->tv_sec = time(NULL); + pnow->tv_usec = 0; } #endif - return cnow; } #elif defined(HAVE_MACH_ABSOLUTE_TIME) @@ -156,7 +148,7 @@ struct curltime curlx_now(void) #include #include -struct curltime curlx_now(void) +void curlx_pnow(struct curltime *pnow) { /* ** Monotonic timer on macOS is provided by mach_absolute_time(), which @@ -165,7 +157,6 @@ struct curltime curlx_now(void) ** mach_timebase_info(). */ static mach_timebase_info_data_t timebase; - struct curltime cnow; uint64_t usecs; if(timebase.denom == 0) @@ -176,15 +167,13 @@ struct curltime curlx_now(void) usecs /= timebase.denom; usecs /= 1000; - cnow.tv_sec = usecs / 1000000; - cnow.tv_usec = (int)(usecs % 1000000); - - return cnow; + pnow->tv_sec = usecs / 1000000; + pnow->tv_usec = (int)(usecs % 1000000); } #elif defined(HAVE_GETTIMEOFDAY) -struct curltime curlx_now(void) +void curlx_pnow(struct curltime *pnow) { /* ** gettimeofday() is not granted to be increased monotonically, due to @@ -192,68 +181,121 @@ struct curltime curlx_now(void) ** forward or backward in time. */ struct timeval now; - struct curltime ret; (void)gettimeofday(&now, NULL); - ret.tv_sec = now.tv_sec; - ret.tv_usec = (int)now.tv_usec; - return ret; + pnow->tv_sec = now.tv_sec; + pnow->tv_usec = (int)now.tv_usec; } #else -struct curltime curlx_now(void) +void curlx_pnow(struct curltime *pnow) { /* ** time() returns the value of time in seconds since the Epoch. */ - struct curltime now; - now.tv_sec = time(NULL); - now.tv_usec = 0; - return now; + pnow->tv_sec = time(NULL); + pnow->tv_usec = 0; } #endif +struct curltime curlx_now(void) +{ + struct curltime now; + curlx_pnow(&now); + return now; +} + /* * Returns: time difference in number of milliseconds. For too large diffs it * returns max value. * * @unittest: 1323 */ -timediff_t curlx_timediff(struct curltime newer, struct curltime older) +timediff_t curlx_ptimediff_ms(const struct curltime *newer, + const struct curltime *older) { - timediff_t diff = (timediff_t)newer.tv_sec-older.tv_sec; - if(diff >= (TIMEDIFF_T_MAX/1000)) + timediff_t diff = (timediff_t)newer->tv_sec - older->tv_sec; + if(diff >= (TIMEDIFF_T_MAX / 1000)) return TIMEDIFF_T_MAX; - else if(diff <= (TIMEDIFF_T_MIN/1000)) + else if(diff <= (TIMEDIFF_T_MIN / 1000)) return TIMEDIFF_T_MIN; - return diff * 1000 + (newer.tv_usec-older.tv_usec)/1000; + return diff * 1000 + (newer->tv_usec - older->tv_usec) / 1000; +} + + +timediff_t curlx_timediff_ms(struct curltime newer, struct curltime older) +{ + return curlx_ptimediff_ms(&newer, &older); } /* * Returns: time difference in number of milliseconds, rounded up. * For too large diffs it returns max value. */ -timediff_t curlx_timediff_ceil(struct curltime newer, struct curltime older) +timediff_t curlx_timediff_ceil_ms(struct curltime newer, + struct curltime older) { - timediff_t diff = (timediff_t)newer.tv_sec-older.tv_sec; - if(diff >= (TIMEDIFF_T_MAX/1000)) + timediff_t diff = (timediff_t)newer.tv_sec - older.tv_sec; + if(diff >= (TIMEDIFF_T_MAX / 1000)) return TIMEDIFF_T_MAX; - else if(diff <= (TIMEDIFF_T_MIN/1000)) + else if(diff <= (TIMEDIFF_T_MIN / 1000)) return TIMEDIFF_T_MIN; - return diff * 1000 + (newer.tv_usec - older.tv_usec + 999)/1000; + return diff * 1000 + (newer.tv_usec - older.tv_usec + 999) / 1000; } /* * Returns: time difference in number of microseconds. For too large diffs it * returns max value. */ -timediff_t curlx_timediff_us(struct curltime newer, struct curltime older) +timediff_t curlx_ptimediff_us(const struct curltime *newer, + const struct curltime *older) { - timediff_t diff = (timediff_t)newer.tv_sec-older.tv_sec; - if(diff >= (TIMEDIFF_T_MAX/1000000)) + timediff_t diff = (timediff_t)newer->tv_sec - older->tv_sec; + if(diff >= (TIMEDIFF_T_MAX / 1000000)) return TIMEDIFF_T_MAX; - else if(diff <= (TIMEDIFF_T_MIN/1000000)) + else if(diff <= (TIMEDIFF_T_MIN / 1000000)) return TIMEDIFF_T_MIN; - return diff * 1000000 + newer.tv_usec-older.tv_usec; + return diff * 1000000 + newer->tv_usec - older->tv_usec; +} + +timediff_t curlx_timediff_us(struct curltime newer, struct curltime older) +{ + return curlx_ptimediff_us(&newer, &older); +} + +#if defined(__MINGW32__) && (__MINGW64_VERSION_MAJOR <= 3) +#include /* for _gmtime32_s(), _gmtime64_s() */ +#ifdef _USE_32BIT_TIME_T +#define gmtime_s _gmtime32_s +#else +#define gmtime_s _gmtime64_s +#endif +#endif + +/* + * curlx_gmtime() is a gmtime() replacement for portability. Do not use + * the gmtime_s(), gmtime_r() or gmtime() functions anywhere else but here. + */ +CURLcode curlx_gmtime(time_t intime, struct tm *store) +{ +#ifdef _WIN32 + if(gmtime_s(store, &intime)) /* thread-safe */ + return CURLE_BAD_FUNCTION_ARGUMENT; +#elif defined(HAVE_GMTIME_R) + const struct tm *tm; + tm = gmtime_r(&intime, store); /* thread-safe */ + if(!tm) + return CURLE_BAD_FUNCTION_ARGUMENT; +#else + const struct tm *tm; + /* !checksrc! disable BANNEDFUNC 1 */ + tm = gmtime(&intime); /* not thread-safe */ + if(tm) + *store = *tm; /* copy the pointed struct to the local copy */ + else + return CURLE_BAD_FUNCTION_ARGUMENT; +#endif + + return CURLE_OK; } diff --git a/vendor/hydra/vendor/curl/lib/curlx/timeval.h b/vendor/hydra/vendor/curl/lib/curlx/timeval.h index 1f8fe5e8..4aab1751 100644 --- a/vendor/hydra/vendor/curl/lib/curlx/timeval.h +++ b/vendor/hydra/vendor/curl/lib/curlx/timeval.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "../curl_setup.h" #include "timediff.h" @@ -39,6 +38,7 @@ void curlx_now_init(void); #endif struct curltime curlx_now(void); +void curlx_pnow(struct curltime *pnow); /* * Make sure that the first argument (newer) is the more recent time and older @@ -46,7 +46,9 @@ struct curltime curlx_now(void); * * Returns: the time difference in number of milliseconds. */ -timediff_t curlx_timediff(struct curltime newer, struct curltime older); +timediff_t curlx_timediff_ms(struct curltime newer, struct curltime older); +timediff_t curlx_ptimediff_ms(const struct curltime *newer, + const struct curltime *older); /* * Make sure that the first argument (newer) is the more recent time and older @@ -54,7 +56,8 @@ timediff_t curlx_timediff(struct curltime newer, struct curltime older); * * Returns: the time difference in number of milliseconds, rounded up. */ -timediff_t curlx_timediff_ceil(struct curltime newer, struct curltime older); +timediff_t curlx_timediff_ceil_ms(struct curltime newer, + struct curltime older); /* * Make sure that the first argument (newer) is the more recent time and older @@ -63,5 +66,9 @@ timediff_t curlx_timediff_ceil(struct curltime newer, struct curltime older); * Returns: the time difference in number of microseconds. */ timediff_t curlx_timediff_us(struct curltime newer, struct curltime older); +timediff_t curlx_ptimediff_us(const struct curltime *newer, + const struct curltime *older); + +CURLcode curlx_gmtime(time_t intime, struct tm *store); #endif /* HEADER_CURL_TIMEVAL_H */ diff --git a/vendor/hydra/vendor/curl/lib/curlx/version_win32.c b/vendor/hydra/vendor/curl/lib/curlx/version_win32.c index 7e415dfe..a9a4ee38 100644 --- a/vendor/hydra/vendor/curl/lib/curlx/version_win32.c +++ b/vendor/hydra/vendor/curl/lib/curlx/version_win32.c @@ -21,18 +21,11 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "../curl_setup.h" #ifdef _WIN32 -#include #include "version_win32.h" -#include "warnless.h" - -/* The last 2 #include files should be in this order */ -#include "../curl_memory.h" -#include "../memdebug.h" /* This Unicode version struct works for VerifyVersionInfoW (OSVERSIONINFOEXW) and RtlVerifyVersionInfo (RTLOSVERSIONINFOEXW) */ @@ -111,12 +104,6 @@ bool curlx_verify_windows_version(const unsigned int majorVersion, /* we are always running on PLATFORM_WINNT */ matched = FALSE; } -#elif defined(UNDER_CE) - (void)majorVersion; - (void)minorVersion; - (void)buildVersion; - (void)platform; - (void)condition; #else ULONGLONG cm = 0; struct OUR_OSVERSIONINFOEXW osver; @@ -139,7 +126,7 @@ bool curlx_verify_windows_version(const unsigned int majorVersion, #pragma clang diagnostic ignored "-Wcast-function-type-strict" #endif pRtlVerifyVersionInfo = CURLX_FUNCTION_CAST(RTLVERIFYVERSIONINFO_FN, - GetProcAddress(GetModuleHandleA("ntdll"), "RtlVerifyVersionInfo")); + GetProcAddress(GetModuleHandle(TEXT("ntdll")), "RtlVerifyVersionInfo")); #if defined(__clang__) && __clang_major__ >= 16 #pragma clang diagnostic pop #endif diff --git a/vendor/hydra/vendor/curl/lib/curlx/version_win32.h b/vendor/hydra/vendor/curl/lib/curlx/version_win32.h index 471100a6..a5fb8ff3 100644 --- a/vendor/hydra/vendor/curl/lib/curlx/version_win32.h +++ b/vendor/hydra/vendor/curl/lib/curlx/version_win32.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "../curl_setup.h" #ifdef _WIN32 diff --git a/vendor/hydra/vendor/curl/lib/curlx/wait.c b/vendor/hydra/vendor/curl/lib/curlx/wait.c index 4e10a829..2a9f54bb 100644 --- a/vendor/hydra/vendor/curl/lib/curlx/wait.c +++ b/vendor/hydra/vendor/curl/lib/curlx/wait.c @@ -21,15 +21,12 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "../curl_setup.h" #ifndef HAVE_SELECT #error "We cannot compile without select() support." #endif -#include - #ifdef HAVE_SYS_SELECT_H #include #elif defined(HAVE_UNISTD_H) @@ -74,7 +71,7 @@ int curlx_wait_ms(timediff_t timeout_ms) /* prevent overflow, timeout_ms is typecast to ULONG/DWORD. */ #if TIMEDIFF_T_MAX >= ULONG_MAX if(timeout_ms >= ULONG_MAX) - timeout_ms = ULONG_MAX-1; + timeout_ms = ULONG_MAX - 1; /* do not use ULONG_MAX, because that is equal to INFINITE */ #endif Sleep((DWORD)timeout_ms); diff --git a/vendor/hydra/vendor/curl/lib/curlx/wait.h b/vendor/hydra/vendor/curl/lib/curlx/wait.h index 208bc20a..c140194a 100644 --- a/vendor/hydra/vendor/curl/lib/curlx/wait.h +++ b/vendor/hydra/vendor/curl/lib/curlx/wait.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "../curl_setup.h" int curlx_wait_ms(timediff_t timeout_ms); diff --git a/vendor/hydra/vendor/curl/lib/curlx/warnless.c b/vendor/hydra/vendor/curl/lib/curlx/warnless.c index bb636a93..8c1be2d5 100644 --- a/vendor/hydra/vendor/curl/lib/curlx/warnless.c +++ b/vendor/hydra/vendor/curl/lib/curlx/warnless.c @@ -21,22 +21,21 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ +#include "../curl_setup.h" #include "warnless.h" #if defined(__INTEL_COMPILER) && defined(__unix__) #ifdef HAVE_NETINET_IN_H -# include +#include #endif #ifdef HAVE_ARPA_INET_H -# include +#include #endif #endif /* __INTEL_COMPILER && __unix__ */ -#include - #define CURL_MASK_UCHAR ((unsigned char)~0) #define CURL_MASK_USHORT ((unsigned short)~0) @@ -56,15 +55,15 @@ unsigned char curlx_ultouc(unsigned long ulnum) { #ifdef __INTEL_COMPILER -# pragma warning(push) -# pragma warning(disable:810) /* conversion may lose significant bits */ +#pragma warning(push) +#pragma warning(disable:810) /* conversion may lose significant bits */ #endif - DEBUGASSERT(ulnum <= (unsigned long) CURL_MASK_UCHAR); - return (unsigned char)(ulnum & (unsigned long) CURL_MASK_UCHAR); + DEBUGASSERT(ulnum <= (unsigned long)CURL_MASK_UCHAR); + return (unsigned char)(ulnum & (unsigned long)CURL_MASK_UCHAR); #ifdef __INTEL_COMPILER -# pragma warning(pop) +#pragma warning(pop) #endif } @@ -75,15 +74,15 @@ unsigned char curlx_ultouc(unsigned long ulnum) int curlx_uztosi(size_t uznum) { #ifdef __INTEL_COMPILER -# pragma warning(push) -# pragma warning(disable:810) /* conversion may lose significant bits */ +#pragma warning(push) +#pragma warning(disable:810) /* conversion may lose significant bits */ #endif - DEBUGASSERT(uznum <= (size_t) CURL_MASK_SINT); - return (int)(uznum & (size_t) CURL_MASK_SINT); + DEBUGASSERT(uznum <= (size_t)CURL_MASK_SINT); + return (int)(uznum & (size_t)CURL_MASK_SINT); #ifdef __INTEL_COMPILER -# pragma warning(pop) +#pragma warning(pop) #endif } @@ -94,17 +93,17 @@ int curlx_uztosi(size_t uznum) unsigned long curlx_uztoul(size_t uznum) { #ifdef __INTEL_COMPILER -# pragma warning(push) -# pragma warning(disable:810) /* conversion may lose significant bits */ +#pragma warning(push) +#pragma warning(disable:810) /* conversion may lose significant bits */ #endif #if ULONG_MAX < SIZE_MAX - DEBUGASSERT(uznum <= (size_t) CURL_MASK_ULONG); + DEBUGASSERT(uznum <= (size_t)CURL_MASK_ULONG); #endif - return (unsigned long)(uznum & (size_t) CURL_MASK_ULONG); + return (unsigned long)(uznum & (size_t)CURL_MASK_ULONG); #ifdef __INTEL_COMPILER -# pragma warning(pop) +#pragma warning(pop) #endif } @@ -115,17 +114,17 @@ unsigned long curlx_uztoul(size_t uznum) unsigned int curlx_uztoui(size_t uznum) { #ifdef __INTEL_COMPILER -# pragma warning(push) -# pragma warning(disable:810) /* conversion may lose significant bits */ +#pragma warning(push) +#pragma warning(disable:810) /* conversion may lose significant bits */ #endif #if UINT_MAX < SIZE_MAX - DEBUGASSERT(uznum <= (size_t) CURL_MASK_UINT); + DEBUGASSERT(uznum <= (size_t)CURL_MASK_UINT); #endif - return (unsigned int)(uznum & (size_t) CURL_MASK_UINT); + return (unsigned int)(uznum & (size_t)CURL_MASK_UINT); #ifdef __INTEL_COMPILER -# pragma warning(pop) +#pragma warning(pop) #endif } @@ -136,18 +135,18 @@ unsigned int curlx_uztoui(size_t uznum) int curlx_sltosi(long slnum) { #ifdef __INTEL_COMPILER -# pragma warning(push) -# pragma warning(disable:810) /* conversion may lose significant bits */ +#pragma warning(push) +#pragma warning(disable:810) /* conversion may lose significant bits */ #endif DEBUGASSERT(slnum >= 0); #if INT_MAX < LONG_MAX - DEBUGASSERT((unsigned long) slnum <= (unsigned long) CURL_MASK_SINT); + DEBUGASSERT((unsigned long)slnum <= (unsigned long)CURL_MASK_SINT); #endif - return (int)(slnum & (long) CURL_MASK_SINT); + return (int)(slnum & (long)CURL_MASK_SINT); #ifdef __INTEL_COMPILER -# pragma warning(pop) +#pragma warning(pop) #endif } @@ -158,18 +157,18 @@ int curlx_sltosi(long slnum) unsigned int curlx_sltoui(long slnum) { #ifdef __INTEL_COMPILER -# pragma warning(push) -# pragma warning(disable:810) /* conversion may lose significant bits */ +#pragma warning(push) +#pragma warning(disable:810) /* conversion may lose significant bits */ #endif DEBUGASSERT(slnum >= 0); #if UINT_MAX < LONG_MAX - DEBUGASSERT((unsigned long) slnum <= (unsigned long) CURL_MASK_UINT); + DEBUGASSERT((unsigned long)slnum <= (unsigned long)CURL_MASK_UINT); #endif - return (unsigned int)(slnum & (long) CURL_MASK_UINT); + return (unsigned int)(slnum & (long)CURL_MASK_UINT); #ifdef __INTEL_COMPILER -# pragma warning(pop) +#pragma warning(pop) #endif } @@ -180,16 +179,16 @@ unsigned int curlx_sltoui(long slnum) unsigned short curlx_sltous(long slnum) { #ifdef __INTEL_COMPILER -# pragma warning(push) -# pragma warning(disable:810) /* conversion may lose significant bits */ +#pragma warning(push) +#pragma warning(disable:810) /* conversion may lose significant bits */ #endif DEBUGASSERT(slnum >= 0); - DEBUGASSERT((unsigned long) slnum <= (unsigned long) CURL_MASK_USHORT); - return (unsigned short)(slnum & (long) CURL_MASK_USHORT); + DEBUGASSERT((unsigned long)slnum <= (unsigned long)CURL_MASK_USHORT); + return (unsigned short)(slnum & (long)CURL_MASK_USHORT); #ifdef __INTEL_COMPILER -# pragma warning(pop) +#pragma warning(pop) #endif } @@ -200,15 +199,15 @@ unsigned short curlx_sltous(long slnum) ssize_t curlx_uztosz(size_t uznum) { #ifdef __INTEL_COMPILER -# pragma warning(push) -# pragma warning(disable:810) /* conversion may lose significant bits */ +#pragma warning(push) +#pragma warning(disable:810) /* conversion may lose significant bits */ #endif - DEBUGASSERT(uznum <= (size_t) CURL_MASK_SSIZE_T); - return (ssize_t)(uznum & (size_t) CURL_MASK_SSIZE_T); + DEBUGASSERT(uznum <= (size_t)CURL_MASK_SSIZE_T); + return (ssize_t)(uznum & (size_t)CURL_MASK_SSIZE_T); #ifdef __INTEL_COMPILER -# pragma warning(pop) +#pragma warning(pop) #endif } @@ -219,15 +218,15 @@ ssize_t curlx_uztosz(size_t uznum) size_t curlx_sotouz(curl_off_t sonum) { #ifdef __INTEL_COMPILER -# pragma warning(push) -# pragma warning(disable:810) /* conversion may lose significant bits */ +#pragma warning(push) +#pragma warning(disable:810) /* conversion may lose significant bits */ #endif DEBUGASSERT(sonum >= 0); - return (size_t)(sonum & (curl_off_t) CURL_MASK_USIZE_T); + return (size_t)(sonum & (curl_off_t)CURL_MASK_USIZE_T); #ifdef __INTEL_COMPILER -# pragma warning(pop) +#pragma warning(pop) #endif } @@ -238,18 +237,18 @@ size_t curlx_sotouz(curl_off_t sonum) int curlx_sztosi(ssize_t sznum) { #ifdef __INTEL_COMPILER -# pragma warning(push) -# pragma warning(disable:810) /* conversion may lose significant bits */ +#pragma warning(push) +#pragma warning(disable:810) /* conversion may lose significant bits */ #endif DEBUGASSERT(sznum >= 0); #if INT_MAX < SSIZE_MAX - DEBUGASSERT((size_t) sznum <= (size_t) CURL_MASK_SINT); + DEBUGASSERT((size_t)sznum <= (size_t)CURL_MASK_SINT); #endif - return (int)(sznum & (ssize_t) CURL_MASK_SINT); + return (int)(sznum & (ssize_t)CURL_MASK_SINT); #ifdef __INTEL_COMPILER -# pragma warning(pop) +#pragma warning(pop) #endif } @@ -260,15 +259,15 @@ int curlx_sztosi(ssize_t sznum) unsigned short curlx_uitous(unsigned int uinum) { #ifdef __INTEL_COMPILER -# pragma warning(push) -# pragma warning(disable:810) /* conversion may lose significant bits */ +#pragma warning(push) +#pragma warning(disable:810) /* conversion may lose significant bits */ #endif - DEBUGASSERT(uinum <= (unsigned int) CURL_MASK_USHORT); - return (unsigned short) (uinum & (unsigned int) CURL_MASK_USHORT); + DEBUGASSERT(uinum <= (unsigned int)CURL_MASK_USHORT); + return (unsigned short)(uinum & (unsigned int)CURL_MASK_USHORT); #ifdef __INTEL_COMPILER -# pragma warning(pop) +#pragma warning(pop) #endif } @@ -279,14 +278,76 @@ unsigned short curlx_uitous(unsigned int uinum) size_t curlx_sitouz(int sinum) { #ifdef __INTEL_COMPILER -# pragma warning(push) -# pragma warning(disable:810) /* conversion may lose significant bits */ +#pragma warning(push) +#pragma warning(disable:810) /* conversion may lose significant bits */ #endif DEBUGASSERT(sinum >= 0); - return (size_t) sinum; + return (size_t)sinum; #ifdef __INTEL_COMPILER -# pragma warning(pop) +#pragma warning(pop) +#endif +} + +size_t curlx_uitouz(unsigned int uinum) +{ + return (size_t)uinum; +} + +size_t curlx_sotouz_range(curl_off_t sonum, size_t uzmin, size_t uzmax) +{ + if(sonum < 0) + return uzmin; +#if SIZEOF_CURL_OFF_T > SIZEOF_SIZE_T + if(sonum > SIZE_MAX) + return uzmax; +#endif + return CURLMIN(CURLMAX((size_t)sonum, uzmin), uzmax); +} + +bool curlx_sztouz(ssize_t sznum, size_t *puznum) +{ + if(sznum < 0) { + *puznum = 0; + return FALSE; + } + *puznum = (size_t)sznum; + return TRUE; +} + +bool curlx_sotouz_fits(curl_off_t sonum, size_t *puznum) +{ + if(sonum < 0) { + *puznum = 0; + return FALSE; + } +#if SIZEOF_CURL_OFF_T > SIZEOF_SIZE_T + if(sonum > SIZE_MAX) { + *puznum = 0; + return FALSE; + } +#endif + *puznum = (size_t)sonum; + return TRUE; +} + +bool curlx_sltouz(long slnum, size_t *puznum) +{ + if(slnum < 0) { + *puznum = 0; + return FALSE; + } + /* We error in curl_setup.h if SIZEOF_LONG > SIZEOF_SIZE_T */ + *puznum = (size_t)slnum; + return TRUE; +} + +curl_off_t curlx_uztoso(size_t uznum) +{ +#if SIZEOF_SIZE_T >= SIZEOF_CURL_OFF_T + if(uznum > (size_t)CURL_OFF_T_MAX) + return CURL_OFF_T_MAX; #endif + return (curl_off_t)uznum; } diff --git a/vendor/hydra/vendor/curl/lib/curlx/warnless.h b/vendor/hydra/vendor/curl/lib/curlx/warnless.h index 0a0c6080..8a62ccf6 100644 --- a/vendor/hydra/vendor/curl/lib/curlx/warnless.h +++ b/vendor/hydra/vendor/curl/lib/curlx/warnless.h @@ -24,14 +24,8 @@ * ***************************************************************************/ -#include "../curl_setup.h" - -#ifdef USE_WINSOCK -#include /* for curl_socket_t */ -#endif - #define CURLX_FUNCTION_CAST(target_type, func) \ - (target_type)(void (*) (void))(func) + (target_type)(void (*)(void))(func) unsigned char curlx_ultouc(unsigned long ulnum); @@ -57,11 +51,24 @@ unsigned short curlx_uitous(unsigned int uinum); size_t curlx_sitouz(int sinum); -#ifdef _WIN32 -#undef read -#define read(fd, buf, count) (ssize_t)_read(fd, buf, curlx_uztoui(count)) -#undef write -#define write(fd, buf, count) (ssize_t)_write(fd, buf, curlx_uztoui(count)) -#endif +size_t curlx_uitouz(unsigned int uinum); + +/* Convert a curl_off_t to fit into size_t interval [uzmin, uzmax]. + * values outside this interval give the lower/upper bound. */ +size_t curlx_sotouz_range(curl_off_t sonum, size_t uzmin, size_t uzmax); + +/* Convert a size_t to curl_off_t, return CURL_OFF_T_MAX if too large. */ +curl_off_t curlx_uztoso(size_t uznum); + +/* Convert a ssize_t to size_t, return FALSE if negative and set 0 */ +bool curlx_sztouz(ssize_t sznum, size_t *puznum); + +/* Convert a curl_off_t to size_t, return FALSE if negative or + * too large and set 0 */ +bool curlx_sotouz_fits(curl_off_t sonum, size_t *puznum); + +/* Convert a long to size_t, return FALSE if negative or too large + * and set 0 */ +bool curlx_sltouz(long sznum, size_t *puznum); #endif /* HEADER_CURL_WARNLESS_H */ diff --git a/vendor/hydra/vendor/curl/lib/curlx/winapi.c b/vendor/hydra/vendor/curl/lib/curlx/winapi.c index de1218ce..b46a5bf0 100644 --- a/vendor/hydra/vendor/curl/lib/curlx/winapi.c +++ b/vendor/hydra/vendor/curl/lib/curlx/winapi.c @@ -29,20 +29,8 @@ */ #ifdef _WIN32 #include "winapi.h" - -#ifndef WITHOUT_LIBCURL -#include -#define SNPRINTF curl_msnprintf -#else -/* when built for the test servers */ - -/* adjust for old MSVC */ -#if defined(_MSC_VER) && (_MSC_VER < 1900) -#define SNPRINTF _snprintf -#else -#define SNPRINTF snprintf -#endif -#endif /* !WITHOUT_LIBCURL */ +#include "snprintf.h" +#include "strcopy.h" /* This is a helper function for curlx_strerror that converts Windows API error * codes (GetLastError) to error messages. @@ -52,6 +40,7 @@ const char *curlx_get_winapi_error(DWORD err, char *buf, size_t buflen) { char *p; wchar_t wbuf[256]; + DWORD wlen; if(!buflen) return NULL; @@ -61,25 +50,19 @@ const char *curlx_get_winapi_error(DWORD err, char *buf, size_t buflen) /* We return the local codepage version of the error string because if it is output to the user's terminal it will likely be with functions which - expect the local codepage (eg fprintf, failf, infof). - FormatMessageW -> wcstombs is used for Windows CE compatibility. */ - if(FormatMessageW((FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS), NULL, err, - LANG_NEUTRAL, wbuf, CURL_ARRAYSIZE(wbuf), NULL)) { - size_t written = wcstombs(buf, wbuf, buflen - 1); - if(written != (size_t)-1) - buf[written] = '\0'; - else - *buf = '\0'; - } - - /* Truncate multiple lines */ - p = strchr(buf, '\n'); - if(p) { - if(p > buf && *(p-1) == '\r') - *(p-1) = '\0'; - else - *p = '\0'; + expect the local codepage (eg fprintf, failf, infof). */ + wlen = FormatMessageW((FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS), NULL, err, + LANG_NEUTRAL, wbuf, CURL_ARRAYSIZE(wbuf), NULL); + if(wlen && !wcstombs_s(NULL, buf, buflen, wbuf, wlen)) { + /* Truncate multiple lines */ + p = strchr(buf, '\n'); + if(p) { + if(p > buf && *(p - 1) == '\r') + *(p - 1) = '\0'; + else + *p = '\0'; + } } return *buf ? buf : NULL; @@ -107,18 +90,16 @@ const char *curlx_winapi_strerror(DWORD err, char *buf, size_t buflen) #if defined(__GNUC__) && __GNUC__ >= 7 #pragma GCC diagnostic pop #endif - } #else { const char *txt = (err == ERROR_SUCCESS) ? "No error" : "Error"; - if(strlen(txt) < buflen) - strcpy(buf, txt); + curlx_strcopy(buf, buflen, txt, strlen(txt)); } #endif if(errno != old_errno) - CURL_SETERRNO(old_errno); + errno = old_errno; if(old_win_err != GetLastError()) SetLastError(old_win_err); diff --git a/vendor/hydra/vendor/curl/lib/cw-out.c b/vendor/hydra/vendor/curl/lib/cw-out.c index 9c0a36e7..69fb344f 100644 --- a/vendor/hydra/vendor/curl/lib/cw-out.c +++ b/vendor/hydra/vendor/curl/lib/cw-out.c @@ -21,24 +21,17 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include - #include "urldata.h" #include "cfilters.h" -#include "headers.h" #include "multiif.h" #include "sendf.h" +#include "curl_trc.h" #include "transfer.h" #include "cw-out.h" #include "cw-pause.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /** * OVERALL DESIGN of this client writer @@ -85,7 +78,7 @@ struct cw_out_buf { static struct cw_out_buf *cw_out_buf_create(cw_out_type otype) { - struct cw_out_buf *cwbuf = calloc(1, sizeof(*cwbuf)); + struct cw_out_buf *cwbuf = curlx_calloc(1, sizeof(*cwbuf)); if(cwbuf) { cwbuf->type = otype; curlx_dyn_init(&cwbuf->b, DYN_PAUSE_BUFFER); @@ -97,7 +90,7 @@ static void cw_out_buf_free(struct cw_out_buf *cwbuf) { if(cwbuf) { curlx_dyn_free(&cwbuf->b); - free(cwbuf); + curlx_free(cwbuf); } } @@ -252,7 +245,7 @@ static CURLcode cw_out_ptr_flush(struct cw_out_ctx *ctx, size_t wlen, nwritten; CURLcode result; - /* If we errored once, we do not invoke the client callback again */ + /* If we errored once, we do not invoke the client callback again */ if(ctx->errored) return CURLE_WRITE_ERROR; @@ -453,7 +446,7 @@ static CURLcode cw_out_write(struct Curl_easy *data, return result; } - if(type & (CLIENTWRITE_HEADER|CLIENTWRITE_INFO)) { + if(type & (CLIENTWRITE_HEADER | CLIENTWRITE_INFO)) { result = cw_out_do_write(ctx, data, CW_OUT_HDS, flush_all, buf, blen); if(result) return result; diff --git a/vendor/hydra/vendor/curl/lib/cw-out.h b/vendor/hydra/vendor/curl/lib/cw-out.h index 89b9985b..7de6524b 100644 --- a/vendor/hydra/vendor/curl/lib/cw-out.h +++ b/vendor/hydra/vendor/curl/lib/cw-out.h @@ -23,10 +23,9 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include "sendf.h" +struct Curl_easy; /** * The client writer type "cw-out" that does the actual writing to diff --git a/vendor/hydra/vendor/curl/lib/cw-pause.c b/vendor/hydra/vendor/curl/lib/cw-pause.c index 1af4e8fa..481b9fb2 100644 --- a/vendor/hydra/vendor/curl/lib/cw-pause.c +++ b/vendor/hydra/vendor/curl/lib/cw-pause.c @@ -21,23 +21,15 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include - #include "urldata.h" #include "bufq.h" #include "cfilters.h" -#include "headers.h" -#include "multiif.h" #include "sendf.h" +#include "curl_trc.h" #include "cw-pause.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* body dynbuf sizes */ #define CW_PAUSE_BUF_CHUNK (16 * 1024) @@ -52,12 +44,12 @@ struct cw_pause_buf { static struct cw_pause_buf *cw_pause_buf_create(int type, size_t buflen) { - struct cw_pause_buf *cwbuf = calloc(1, sizeof(*cwbuf)); + struct cw_pause_buf *cwbuf = curlx_calloc(1, sizeof(*cwbuf)); if(cwbuf) { cwbuf->type = type; if(type & CLIENTWRITE_BODY) Curl_bufq_init2(&cwbuf->b, CW_PAUSE_BUF_CHUNK, 1, - (BUFQ_OPT_SOFT_LIMIT|BUFQ_OPT_NO_SPARES)); + (BUFQ_OPT_SOFT_LIMIT | BUFQ_OPT_NO_SPARES)); else Curl_bufq_init(&cwbuf->b, buflen, 1); } @@ -68,7 +60,7 @@ static void cw_pause_buf_free(struct cw_pause_buf *cwbuf) { if(cwbuf) { Curl_bufq_free(&cwbuf->b); - free(cwbuf); + curlx_free(cwbuf); } } diff --git a/vendor/hydra/vendor/curl/lib/cw-pause.h b/vendor/hydra/vendor/curl/lib/cw-pause.h index 2aa1a499..544cbfa5 100644 --- a/vendor/hydra/vendor/curl/lib/cw-pause.h +++ b/vendor/hydra/vendor/curl/lib/cw-pause.h @@ -23,10 +23,9 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include "sendf.h" +struct Curl_easy; /** * The client writer type "cw-pause" that buffers writes for @@ -36,5 +35,4 @@ extern const struct Curl_cwtype Curl_cwt_pause; CURLcode Curl_cw_pause_flush(struct Curl_easy *data); - #endif /* HEADER_CURL_CW_PAUSE_H */ diff --git a/vendor/hydra/vendor/curl/lib/dict.c b/vendor/hydra/vendor/curl/lib/dict.c index 3296a454..5839e804 100644 --- a/vendor/hydra/vendor/curl/lib/dict.c +++ b/vendor/hydra/vendor/curl/lib/dict.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifndef CURL_DISABLE_DICT @@ -53,22 +52,15 @@ #endif #include "urldata.h" -#include #include "transfer.h" -#include "sendf.h" +#include "curl_trc.h" #include "escape.h" -#include "progress.h" #include "dict.h" -/* The last 2 #include files should be: */ -#include "curl_memory.h" -#include "memdebug.h" - - -#define DICT_MATCH "/MATCH:" -#define DICT_MATCH2 "/M:" -#define DICT_MATCH3 "/FIND:" -#define DICT_DEFINE "/DEFINE:" +#define DICT_MATCH "/MATCH:" +#define DICT_MATCH2 "/M:" +#define DICT_MATCH3 "/FIND:" +#define DICT_DEFINE "/DEFINE:" #define DICT_DEFINE2 "/D:" #define DICT_DEFINE3 "/LOOKUP:" @@ -160,9 +152,9 @@ static CURLcode sendf(struct Curl_easy *data, const char *fmt, ...) if(result) break; - Curl_debug(data, CURLINFO_DATA_OUT, sptr, (size_t)bytes_written); + Curl_debug(data, CURLINFO_DATA_OUT, sptr, bytes_written); - if((size_t)bytes_written != write_len) { + if(bytes_written != write_len) { /* if not all was written at once, we must advance the pointer, decrease the size left and try again! */ write_len -= bytes_written; @@ -172,7 +164,7 @@ static CURLcode sendf(struct Curl_easy *data, const char *fmt, ...) break; } - free(s); /* free the output string */ + curlx_free(s); /* free the output string */ return result; } @@ -197,9 +189,9 @@ static CURLcode dict_do(struct Curl_easy *data, bool *done) if(result) return result; - if(curl_strnequal(path, DICT_MATCH, sizeof(DICT_MATCH)-1) || - curl_strnequal(path, DICT_MATCH2, sizeof(DICT_MATCH2)-1) || - curl_strnequal(path, DICT_MATCH3, sizeof(DICT_MATCH3)-1)) { + if(curl_strnequal(path, DICT_MATCH, sizeof(DICT_MATCH) - 1) || + curl_strnequal(path, DICT_MATCH2, sizeof(DICT_MATCH2) - 1) || + curl_strnequal(path, DICT_MATCH3, sizeof(DICT_MATCH3) - 1)) { word = strchr(path, ':'); if(word) { @@ -244,9 +236,9 @@ static CURLcode dict_do(struct Curl_easy *data, bool *done) } Curl_xfer_setup_recv(data, FIRSTSOCKET, -1); } - else if(curl_strnequal(path, DICT_DEFINE, sizeof(DICT_DEFINE)-1) || - curl_strnequal(path, DICT_DEFINE2, sizeof(DICT_DEFINE2)-1) || - curl_strnequal(path, DICT_DEFINE3, sizeof(DICT_DEFINE3)-1)) { + else if(curl_strnequal(path, DICT_DEFINE, sizeof(DICT_DEFINE) - 1) || + curl_strnequal(path, DICT_DEFINE2, sizeof(DICT_DEFINE2) - 1) || + curl_strnequal(path, DICT_DEFINE3, sizeof(DICT_DEFINE3) - 1)) { word = strchr(path, ':'); if(word) { @@ -310,8 +302,8 @@ static CURLcode dict_do(struct Curl_easy *data, bool *done) } error: - free(eword); - free(path); + curlx_free(eword); + curlx_free(path); return result; } #endif /* CURL_DISABLE_DICT */ diff --git a/vendor/hydra/vendor/curl/lib/dict.h b/vendor/hydra/vendor/curl/lib/dict.h index ba9a9271..4025c8bc 100644 --- a/vendor/hydra/vendor/curl/lib/dict.h +++ b/vendor/hydra/vendor/curl/lib/dict.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #ifndef CURL_DISABLE_DICT extern const struct Curl_handler Curl_handler_dict; #endif diff --git a/vendor/hydra/vendor/curl/lib/doh.c b/vendor/hydra/vendor/curl/lib/doh.c index ec97bd73..9052fab2 100644 --- a/vendor/hydra/vendor/curl/lib/doh.c +++ b/vendor/hydra/vendor/curl/lib/doh.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifndef CURL_DISABLE_DOH @@ -30,25 +29,19 @@ #include "curl_addrinfo.h" #include "doh.h" -#include "sendf.h" +#include "curl_trc.h" #include "multiif.h" #include "url.h" -#include "share.h" -#include "curlx/base64.h" #include "connect.h" #include "strdup.h" #include "curlx/dynbuf.h" #include "escape.h" #include "urlapi-int.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #define DNS_CLASS_IN 0x01 #ifndef CURL_DISABLE_VERBOSE_STRINGS -static const char * const errors[]={ +static const char * const errors[] = { "", "Bad label", "Out of range", @@ -79,7 +72,7 @@ static const char *doh_strerror(DOHcode code) UNITTEST DOHcode doh_req_encode(const char *host, DNStype dnstype, unsigned char *dnsp, /* buffer */ - size_t len, /* buffer size */ + size_t len, /* buffer size */ size_t *olen) /* output length */ { const size_t hostlen = strlen(host); @@ -111,7 +104,7 @@ UNITTEST DOHcode doh_req_encode(const char *host, size_t expected_len; DEBUGASSERT(hostlen); expected_len = 12 + 1 + hostlen + 4; - if(host[hostlen-1]!='.') + if(host[hostlen - 1] != '.') expected_len++; if(expected_len > DOH_MAX_DNSREQ_SIZE) @@ -158,9 +151,9 @@ UNITTEST DOHcode doh_req_encode(const char *host, *dnsp++ = 0; /* append zero-length label for root */ - /* There are assigned TYPE codes beyond 255: use range [1..65535] */ + /* There are assigned TYPE codes beyond 255: use range [1..65535] */ *dnsp++ = (unsigned char)(255 & (dnstype >> 8)); /* upper 8 bit TYPE */ - *dnsp++ = (unsigned char)(255 & dnstype); /* lower 8 bit TYPE */ + *dnsp++ = (unsigned char)(255 & dnstype); /* lower 8 bit TYPE */ *dnsp++ = '\0'; /* upper 8 bit CLASS */ *dnsp++ = DNS_CLASS_IN; /* IN - "the Internet" */ @@ -173,8 +166,8 @@ UNITTEST DOHcode doh_req_encode(const char *host, return DOH_OK; } -static size_t -doh_probe_write_cb(char *contents, size_t size, size_t nmemb, void *userp) +static size_t doh_probe_write_cb(char *contents, size_t size, size_t nmemb, + void *userp) { size_t realsize = size * nmemb; struct Curl_easy *data = userp; @@ -269,11 +262,11 @@ static void doh_probe_dtor(void *key, size_t klen, void *e) struct doh_request *doh_req = e; curl_slist_free_all(doh_req->req_hds); curlx_dyn_free(&doh_req->resp_body); - free(e); + curlx_free(e); } } -#define ERROR_CHECK_SETOPT(x,y) \ +#define ERROR_CHECK_SETOPT(x, y) \ do { \ result = curl_easy_setopt((CURL *)doh, x, y); \ if(result && \ @@ -286,7 +279,7 @@ static CURLcode doh_probe_run(struct Curl_easy *data, DNStype dnstype, const char *host, const char *url, CURLM *multi, - unsigned int *pmid) + uint32_t *pmid) { struct Curl_easy *doh = NULL; CURLcode result = CURLE_OK; @@ -294,9 +287,9 @@ static CURLcode doh_probe_run(struct Curl_easy *data, struct doh_request *doh_req; DOHcode d; - *pmid = UINT_MAX; + *pmid = UINT32_MAX; - doh_req = calloc(1, sizeof(*doh_req)); + doh_req = curlx_calloc(1, sizeof(*doh_req)); if(!doh_req) return CURLE_OUT_OF_MEMORY; doh_req->dnstype = dnstype; @@ -311,7 +304,7 @@ static CURLcode doh_probe_run(struct Curl_easy *data, goto error; } - timeout_ms = Curl_timeleft(data, NULL, TRUE); + timeout_ms = Curl_timeleft_ms(data, TRUE); if(timeout_ms <= 0) { result = CURLE_OPERATION_TIMEDOUT; goto error; @@ -350,7 +343,7 @@ static CURLcode doh_probe_run(struct Curl_easy *data, ERROR_CHECK_SETOPT(CURLOPT_PROTOCOLS, CURLPROTO_HTTPS); #else /* in debug mode, also allow http */ - ERROR_CHECK_SETOPT(CURLOPT_PROTOCOLS, CURLPROTO_HTTP|CURLPROTO_HTTPS); + ERROR_CHECK_SETOPT(CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); #endif ERROR_CHECK_SETOPT(CURLOPT_TIMEOUT_MS, (long)timeout_ms); ERROR_CHECK_SETOPT(CURLOPT_SHARE, (CURLSH *)data->share); @@ -362,11 +355,11 @@ static CURLcode doh_probe_run(struct Curl_easy *data, ERROR_CHECK_SETOPT(CURLOPT_NOSIGNAL, 1L); ERROR_CHECK_SETOPT(CURLOPT_SSL_VERIFYHOST, - data->set.doh_verifyhost ? 2L : 0L); + data->set.doh_verifyhost ? 2L : 0L); ERROR_CHECK_SETOPT(CURLOPT_SSL_VERIFYPEER, - data->set.doh_verifypeer ? 1L : 0L); + data->set.doh_verifypeer ? 1L : 0L); ERROR_CHECK_SETOPT(CURLOPT_SSL_VERIFYSTATUS, - data->set.doh_verifystatus ? 1L : 0L); + data->set.doh_verifystatus ? 1L : 0L); /* Inherit *some* SSL options from the user's transfer. This is a best-guess as to which options are needed for compatibility. #3661 @@ -380,20 +373,16 @@ static CURLcode doh_probe_run(struct Curl_easy *data, doh->set.ssl.custom_capath = data->set.ssl.custom_capath; doh->set.ssl.custom_cablob = data->set.ssl.custom_cablob; if(data->set.str[STRING_SSL_CAFILE]) { - ERROR_CHECK_SETOPT(CURLOPT_CAINFO, - data->set.str[STRING_SSL_CAFILE]); + ERROR_CHECK_SETOPT(CURLOPT_CAINFO, data->set.str[STRING_SSL_CAFILE]); } if(data->set.blobs[BLOB_CAINFO]) { - ERROR_CHECK_SETOPT(CURLOPT_CAINFO_BLOB, - data->set.blobs[BLOB_CAINFO]); + ERROR_CHECK_SETOPT(CURLOPT_CAINFO_BLOB, data->set.blobs[BLOB_CAINFO]); } if(data->set.str[STRING_SSL_CAPATH]) { - ERROR_CHECK_SETOPT(CURLOPT_CAPATH, - data->set.str[STRING_SSL_CAPATH]); + ERROR_CHECK_SETOPT(CURLOPT_CAPATH, data->set.str[STRING_SSL_CAPATH]); } if(data->set.str[STRING_SSL_CRLFILE]) { - ERROR_CHECK_SETOPT(CURLOPT_CRLFILE, - data->set.str[STRING_SSL_CRLFILE]); + ERROR_CHECK_SETOPT(CURLOPT_CRLFILE, data->set.str[STRING_SSL_CRLFILE]); } if(data->set.ssl.certinfo) ERROR_CHECK_SETOPT(CURLOPT_CERTINFO, 1L); @@ -441,15 +430,12 @@ static CURLcode doh_probe_run(struct Curl_easy *data, } /* - * Curl_doh() resolves a name using DoH. It resolves a name and returns a - * 'Curl_addrinfo *' with the address information. + * Curl_doh() starts a name resolve using DoH. It resolves a name and returns + * a 'Curl_addrinfo *' with the address information. */ -struct Curl_addrinfo *Curl_doh(struct Curl_easy *data, - const char *hostname, - int port, - int ip_version, - int *waitp) +CURLcode Curl_doh(struct Curl_easy *data, const char *hostname, + int port, int ip_version) { CURLcode result = CURLE_OK; struct doh_probes *dohp = NULL; @@ -465,17 +451,17 @@ struct Curl_addrinfo *Curl_doh(struct Curl_easy *data, data->state.async.done = FALSE; data->state.async.port = port; data->state.async.ip_version = ip_version; - data->state.async.hostname = strdup(hostname); + data->state.async.hostname = curlx_strdup(hostname); if(!data->state.async.hostname) - return NULL; + return CURLE_OUT_OF_MEMORY; /* start clean, consider allocating this struct on demand */ - data->state.async.doh = dohp = calloc(1, sizeof(struct doh_probes)); + data->state.async.doh = dohp = curlx_calloc(1, sizeof(struct doh_probes)); if(!dohp) - return NULL; + return CURLE_OUT_OF_MEMORY; for(i = 0; i < DOH_SLOT_COUNT; ++i) { - dohp->probe_resp[i].probe_mid = UINT_MAX; + dohp->probe_resp[i].probe_mid = UINT32_MAX; curlx_dyn_init(&dohp->probe_resp[i].body, DYN_DOH_RESPONSE); } @@ -521,18 +507,17 @@ struct Curl_addrinfo *Curl_doh(struct Curl_easy *data, qname ? qname : hostname, data->set.str[STRING_DOH], data->multi, &dohp->probe_resp[DOH_SLOT_HTTPS_RR].probe_mid); - free(qname); + curlx_free(qname); if(result) goto error; dohp->pending++; } #endif - *waitp = TRUE; /* this never returns synchronously */ - return NULL; + return CURLE_OK; error: Curl_doh_cleanup(data); - return NULL; + return result; } static DOHcode doh_skipqname(const unsigned char *doh, size_t dohlen, @@ -677,7 +662,7 @@ static DOHcode doh_rdata(const unsigned char *doh, struct dohentry *d) { /* RDATA - - A (TYPE 1): 4 bytes + - A (TYPE 1): 4 bytes - AAAA (TYPE 28): 16 bytes - NS (TYPE 2): N bytes - HTTPS (TYPE 65): N bytes */ @@ -707,7 +692,7 @@ static DOHcode doh_rdata(const unsigned char *doh, return rc; break; case CURL_DNS_TYPE_DNAME: - /* explicit for clarity; just skip; rely on synthesized CNAME */ + /* explicit for clarity; just skip; rely on synthesized CNAME */ break; default: /* unsupported type, just skip it */ @@ -725,7 +710,6 @@ UNITTEST void de_init(struct dohentry *de) curlx_dyn_init(&de->cname[i], DYN_DOH_CNAME); } - UNITTEST DOHcode doh_resp_decode(const unsigned char *doh, size_t dohlen, DNStype dnstype, @@ -859,7 +843,7 @@ UNITTEST DOHcode doh_resp_decode(const unsigned char *doh, #ifdef USE_HTTTPS if((type != CURL_DNS_TYPE_NS) && !d->numcname && !d->numaddr && - !d->numhttps_rrs) + !d->numhttps_rrs) #else if((type != CURL_DNS_TYPE_NS) && !d->numcname && !d->numaddr) #endif @@ -903,8 +887,7 @@ static void doh_show(struct Curl_easy *data, #ifdef USE_HTTPSRR for(i = 0; i < d->numhttps_rrs; i++) { # ifdef DEBUGBUILD - doh_print_buf(data, "DoH HTTPS", - d->https_rrs[i].val, d->https_rrs[i].len); + doh_print_buf(data, "DoH HTTPS", d->https_rrs[i].val, d->https_rrs[i].len); # else infof(data, "DoH HTTPS RR: length %d", d->https_rrs[i].len); # endif @@ -915,7 +898,7 @@ static void doh_show(struct Curl_easy *data, } } #else -#define doh_show(x,y) +#define doh_show(x, y) #endif /* @@ -967,7 +950,7 @@ static CURLcode doh2ai(const struct dohentry *de, const char *hostname, addrtype = AF_INET; } - ai = calloc(1, sizeof(struct Curl_addrinfo) + ss_size + hostlen); + ai = curlx_calloc(1, sizeof(struct Curl_addrinfo) + ss_size + hostlen); if(!ai) { result = CURLE_OUT_OF_MEMORY; break; @@ -1030,16 +1013,16 @@ static CURLcode doh2ai(const struct dohentry *de, const char *hostname, static const char *doh_type2name(DNStype dnstype) { switch(dnstype) { - case CURL_DNS_TYPE_A: - return "A"; - case CURL_DNS_TYPE_AAAA: - return "AAAA"; + case CURL_DNS_TYPE_A: + return "A"; + case CURL_DNS_TYPE_AAAA: + return "AAAA"; #ifdef USE_HTTPSRR - case CURL_DNS_TYPE_HTTPS: - return "HTTPS"; + case CURL_DNS_TYPE_HTTPS: + return "HTTPS"; #endif - default: - return "unknown"; + default: + return "unknown"; } } #endif @@ -1134,7 +1117,7 @@ UNITTEST CURLcode doh_resp_decode_httpsrr(struct Curl_easy *data, *hrr = NULL; if(len <= 2) return CURLE_BAD_FUNCTION_ARGUMENT; - lhrr = calloc(1, sizeof(struct Curl_https_rrinfo)); + lhrr = curlx_calloc(1, sizeof(struct Curl_https_rrinfo)); if(!lhrr) return CURLE_OUT_OF_MEMORY; lhrr->priority = doh_get16bit(cp, 0); @@ -1182,8 +1165,7 @@ UNITTEST void doh_print_httpsrr(struct Curl_easy *data, struct Curl_https_rrinfo *hrr) { DEBUGASSERT(hrr); - infof(data, "HTTPS RR: priority %d, target: %s", - hrr->priority, hrr->target); + infof(data, "HTTPS RR: priority %d, target: %s", hrr->priority, hrr->target); if(hrr->alpns[0] != ALPN_none) infof(data, "HTTPS RR: alpns %u %u %u %u", hrr->alpns[0], hrr->alpns[1], hrr->alpns[2], hrr->alpns[3]); @@ -1226,8 +1208,8 @@ CURLcode Curl_doh_is_resolved(struct Curl_easy *data, if(!dohp) return CURLE_OUT_OF_MEMORY; - if(dohp->probe_resp[DOH_SLOT_IPV4].probe_mid == UINT_MAX && - dohp->probe_resp[DOH_SLOT_IPV6].probe_mid == UINT_MAX) { + if(dohp->probe_resp[DOH_SLOT_IPV4].probe_mid == UINT32_MAX && + dohp->probe_resp[DOH_SLOT_IPV6].probe_mid == UINT32_MAX) { failf(data, "Could not DoH-resolve: %s", dohp->host); return CONN_IS_PROXIED(data->conn) ? CURLE_COULDNT_RESOLVE_PROXY : CURLE_COULDNT_RESOLVE_HOST; @@ -1293,13 +1275,15 @@ CURLcode Curl_doh_is_resolved(struct Curl_easy *data, doh_print_httpsrr(data, hrr); # endif dns->hinfo = hrr; - } + } #endif /* and add the entry to the cache */ data->state.async.dns = dns; result = Curl_dnscache_add(data, dns); *dnsp = data->state.async.dns; } + else + Curl_freeaddrinfo(ai); } /* address processing done */ /* All done */ @@ -1320,17 +1304,16 @@ void Curl_doh_close(struct Curl_easy *data) struct doh_probes *doh = data->state.async.doh; if(doh && data->multi) { struct Curl_easy *probe_data; - unsigned int mid; + uint32_t mid; size_t slot; for(slot = 0; slot < DOH_SLOT_COUNT; slot++) { mid = doh->probe_resp[slot].probe_mid; - if(mid == UINT_MAX) + if(mid == UINT32_MAX) continue; - doh->probe_resp[slot].probe_mid = UINT_MAX; + doh->probe_resp[slot].probe_mid = UINT32_MAX; /* should have been called before data is removed from multi handle */ DEBUGASSERT(data->multi); - probe_data = data->multi ? Curl_multi_get_easy(data->multi, mid) : - NULL; + probe_data = data->multi ? Curl_multi_get_easy(data->multi, mid) : NULL; if(!probe_data) { DEBUGF(infof(data, "Curl_doh_close: xfer for mid=%u not found!", doh->probe_resp[slot].probe_mid)); diff --git a/vendor/hydra/vendor/curl/lib/doh.h b/vendor/hydra/vendor/curl/lib/doh.h index 3fd7de2c..43bc3234 100644 --- a/vendor/hydra/vendor/curl/lib/doh.h +++ b/vendor/hydra/vendor/curl/lib/doh.h @@ -96,7 +96,7 @@ struct doh_request { }; struct doh_response { - unsigned int probe_mid; + uint32_t probe_mid; struct dynbuf body; DNStype dnstype; CURLcode result; @@ -112,20 +112,17 @@ struct doh_probes { }; /* - * Curl_doh() resolve a name using DoH (DNS-over-HTTPS). It resolves a name - * and returns a 'Curl_addrinfo *' with the address information. + * Curl_doh() starts a name resolve using DoH (DNS-over-HTTPS). It resolves a + * name and returns a 'Curl_addrinfo *' with the address information. */ -struct Curl_addrinfo *Curl_doh(struct Curl_easy *data, - const char *hostname, - int port, - int ip_version, - int *waitp); +CURLcode Curl_doh(struct Curl_easy *data, const char *hostname, + int port, int ip_version); CURLcode Curl_doh_is_resolved(struct Curl_easy *data, struct Curl_dns_entry **dns); -#define DOH_MAX_ADDR 24 +#define DOH_MAX_ADDR 24 #define DOH_MAX_CNAME 4 #define DOH_MAX_HTTPS 4 @@ -182,9 +179,9 @@ UNITTEST void de_init(struct dohentry *d); UNITTEST void de_cleanup(struct dohentry *d); #endif -#else /* if DoH is disabled */ -#define Curl_doh(a,b,c,d,e) NULL -#define Curl_doh_is_resolved(x,y) CURLE_COULDNT_RESOLVE_HOST -#endif +#else /* CURL_DISABLE_DOH */ +#define Curl_doh(a, b, c, d, e) NULL +#define Curl_doh_is_resolved(x, y) CURLE_COULDNT_RESOLVE_HOST +#endif /* !CURL_DISABLE_DOH */ #endif /* HEADER_CURL_DOH_H */ diff --git a/vendor/hydra/vendor/curl/lib/dynhds.c b/vendor/hydra/vendor/curl/lib/dynhds.c index 95d415bf..c69d312f 100644 --- a/vendor/hydra/vendor/curl/lib/dynhds.c +++ b/vendor/hydra/vendor/curl/lib/dynhds.c @@ -21,8 +21,8 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" + #include "dynhds.h" #include "strcase.h" @@ -31,24 +31,19 @@ #include #endif /* USE_NGHTTP2 */ -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - - -static struct dynhds_entry * -entry_new(const char *name, size_t namelen, - const char *value, size_t valuelen, int opts) +static struct dynhds_entry *entry_new(const char *name, size_t namelen, + const char *value, size_t valuelen, + int opts) { struct dynhds_entry *e; char *p; DEBUGASSERT(name); DEBUGASSERT(value); - e = calloc(1, sizeof(*e) + namelen + valuelen + 2); + e = curlx_calloc(1, sizeof(*e) + namelen + valuelen + 2); if(!e) return NULL; - e->name = p = ((char *)e) + sizeof(*e); + e->name = p = (char *)e + sizeof(*e); memcpy(p, name, namelen); e->namelen = namelen; e->value = p += namelen + 1; /* leave a \0 at the end of name */ @@ -59,33 +54,9 @@ entry_new(const char *name, size_t namelen, return e; } -static struct dynhds_entry * -entry_append(struct dynhds_entry *e, - const char *value, size_t valuelen) -{ - struct dynhds_entry *e2; - size_t valuelen2 = e->valuelen + 1 + valuelen; - char *p; - - DEBUGASSERT(value); - e2 = calloc(1, sizeof(*e) + e->namelen + valuelen2 + 2); - if(!e2) - return NULL; - e2->name = p = ((char *)e2) + sizeof(*e2); - memcpy(p, e->name, e->namelen); - e2->namelen = e->namelen; - e2->value = p += e->namelen + 1; /* leave a \0 at the end of name */ - memcpy(p, e->value, e->valuelen); - p += e->valuelen; - p[0] = ' '; - memcpy(p + 1, value, valuelen); - e2->valuelen = valuelen2; - return e2; -} - static void entry_free(struct dynhds_entry *e) { - free(e); + curlx_free(e); } void Curl_dynhds_init(struct dynhds *dynhds, size_t max_entries, @@ -175,7 +146,7 @@ CURLcode Curl_dynhds_add(struct dynhds *dynhds, if(dynhds->strs_len + namelen + valuelen > dynhds->max_strs_size) return CURLE_OUT_OF_MEMORY; -entry = entry_new(name, namelen, value, valuelen, dynhds->opts); + entry = entry_new(name, namelen, value, valuelen, dynhds->opts); if(!entry) goto out; @@ -186,7 +157,7 @@ entry = entry_new(name, namelen, value, valuelen, dynhds->opts); if(dynhds->max_entries && nallc > dynhds->max_entries) nallc = dynhds->max_entries; - nhds = calloc(nallc, sizeof(struct dynhds_entry *)); + nhds = curlx_calloc(nallc, sizeof(struct dynhds_entry *)); if(!nhds) goto out; if(dynhds->hds) { @@ -226,48 +197,26 @@ CURLcode Curl_dynhds_h1_add_line(struct dynhds *dynhds, if(!line || !line_len) return CURLE_OK; - if((line[0] == ' ') || (line[0] == '\t')) { - struct dynhds_entry *e, *e2; - /* header continuation, yikes! */ - if(!dynhds->hds_len) - return CURLE_BAD_FUNCTION_ARGUMENT; - - while(line_len && ISBLANK(line[0])) { - ++line; - --line_len; - } - if(!line_len) - return CURLE_BAD_FUNCTION_ARGUMENT; - e = dynhds->hds[dynhds->hds_len-1]; - e2 = entry_append(e, line, line_len); - if(!e2) - return CURLE_OUT_OF_MEMORY; - dynhds->hds[dynhds->hds_len-1] = e2; - entry_free(e); - return CURLE_OK; + p = memchr(line, ':', line_len); + if(!p) + return CURLE_BAD_FUNCTION_ARGUMENT; + name = line; + namelen = p - line; + p++; /* move past the colon */ + for(i = namelen + 1; i < line_len; ++i, ++p) { + if(!ISBLANK(*p)) + break; } - else { - p = memchr(line, ':', line_len); - if(!p) - return CURLE_BAD_FUNCTION_ARGUMENT; - name = line; - namelen = p - line; - p++; /* move past the colon */ - for(i = namelen + 1; i < line_len; ++i, ++p) { - if(!ISBLANK(*p)) - break; - } - value = p; - valuelen = line_len - i; + value = p; + valuelen = line_len - i; - p = memchr(value, '\r', valuelen); - if(!p) - p = memchr(value, '\n', valuelen); - if(p) - valuelen = (size_t)(p - value); + p = memchr(value, '\r', valuelen); + if(!p) + p = memchr(value, '\n', valuelen); + if(p) + valuelen = (size_t)(p - value); - return Curl_dynhds_add(dynhds, name, namelen, value, valuelen); - } + return Curl_dynhds_add(dynhds, name, namelen, value, valuelen); } CURLcode Curl_dynhds_h1_cadd_line(struct dynhds *dynhds, const char *line) @@ -374,7 +323,7 @@ CURLcode Curl_dynhds_h1_dprint(struct dynhds *dynhds, struct dynbuf *dbuf) nghttp2_nv *Curl_dynhds_to_nva(struct dynhds *dynhds, size_t *pcount) { - nghttp2_nv *nva = calloc(1, sizeof(nghttp2_nv) * dynhds->hds_len); + nghttp2_nv *nva = curlx_calloc(1, sizeof(nghttp2_nv) * dynhds->hds_len); size_t i; *pcount = 0; diff --git a/vendor/hydra/vendor/curl/lib/dynhds.h b/vendor/hydra/vendor/curl/lib/dynhds.h index e533dcc3..170721cf 100644 --- a/vendor/hydra/vendor/curl/lib/dynhds.h +++ b/vendor/hydra/vendor/curl/lib/dynhds.h @@ -25,7 +25,6 @@ ***************************************************************************/ #include "curl_setup.h" -#include #include "curlx/dynbuf.h" struct dynbuf; @@ -126,7 +125,6 @@ size_t Curl_dynhds_remove(struct dynhds *dynhds, const char *name, size_t namelen); size_t Curl_dynhds_cremove(struct dynhds *dynhds, const char *name); - /** * Set the give header name and value, replacing any entries with * the same name. The header is added at the end of all (remaining) diff --git a/vendor/hydra/vendor/curl/lib/easy.c b/vendor/hydra/vendor/curl/lib/easy.c index 4236a01d..398b20ed 100644 --- a/vendor/hydra/vendor/curl/lib/easy.c +++ b/vendor/hydra/vendor/curl/lib/easy.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifdef HAVE_NETINET_IN_H @@ -45,7 +44,6 @@ #endif #include "urldata.h" -#include #include "transfer.h" #include "vtls/vtls.h" #include "vtls/vtls_scache.h" @@ -53,37 +51,32 @@ #include "url.h" #include "getinfo.h" #include "hostip.h" -#include "share.h" #include "strdup.h" -#include "progress.h" #include "easyif.h" #include "multiif.h" +#include "multi_ev.h" #include "select.h" #include "cfilters.h" -#include "sendf.h" /* for failf function prototype */ +#include "sendf.h" +#include "curl_trc.h" #include "connect.h" /* for Curl_getconnectinfo */ #include "slist.h" #include "mime.h" #include "amigaos.h" #include "macos.h" -#include "curlx/warnless.h" #include "curlx/wait.h" #include "sigpipe.h" #include "vssh/ssh.h" #include "setopt.h" #include "http_digest.h" #include "system_win32.h" -#include "http2.h" #include "curlx/dynbuf.h" +#include "bufref.h" #include "altsvc.h" #include "hsts.h" #include "easy_lock.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* true globals -- for curl_global_init() and curl_global_cleanup() */ static unsigned int initialized; static long easy_init_flags; @@ -91,7 +84,7 @@ static long easy_init_flags; #ifdef GLOBAL_INIT_IS_THREADSAFE static curl_simple_lock s_lock = CURL_SIMPLE_LOCK_INIT; -#define global_init_lock() curl_simple_lock_lock(&s_lock) +#define global_init_lock() curl_simple_lock_lock(&s_lock) #define global_init_unlock() curl_simple_lock_unlock(&s_lock) #else @@ -106,13 +99,15 @@ static curl_simple_lock s_lock = CURL_SIMPLE_LOCK_INIT; * ways, but at this point it must be defined as the system-supplied strdup * so the callback pointer is initialized correctly. */ -#ifdef UNDER_CE +#ifdef HAVE_STRDUP +#ifdef _WIN32 #define system_strdup _strdup -#elif !defined(HAVE_STRDUP) -#define system_strdup Curl_strdup #else #define system_strdup strdup #endif +#else +#define system_strdup Curl_strdup +#endif #if defined(_MSC_VER) && defined(_DLL) # pragma warning(push) @@ -200,7 +195,7 @@ static CURLcode global_init(long flags, bool memoryfuncs) #ifdef DEBUGBUILD if(getenv("CURL_GLOBAL_INIT")) /* alloc data that will leak if *cleanup() is not called! */ - leakpointer = malloc(1); + leakpointer = curlx_malloc(1); #endif return CURLE_OK; @@ -210,7 +205,6 @@ static CURLcode global_init(long flags, bool memoryfuncs) return CURLE_FAILED_INIT; } - /** * curl_global_init() globally initializes curl given a bitwise set of the * different features of what to initialize. @@ -299,7 +293,7 @@ void curl_global_cleanup(void) Curl_ssh_cleanup(); #ifdef DEBUGBUILD - free(leakpointer); + curlx_free(leakpointer); #endif easy_init_flags = 0; @@ -413,7 +407,6 @@ static int events_timer(CURLM *multi, /* multi handle */ return 0; } - /* poll2cselect * * convert from poll() bit definitions to libcurl's CURL_CSELECT_* ones @@ -430,7 +423,6 @@ static int poll2cselect(int pollmask) return omask; } - /* socketcb2poll * * convert from libcurl' CURL_POLL_* bit definitions to poll()'s @@ -480,17 +472,16 @@ static int events_socket(CURL *easy, /* easy handle */ prev->next = nxt; else ev->list = nxt; - free(m); + curlx_free(m); infof(data, "socket cb: socket %" FMT_SOCKET_T " REMOVED", s); } else { /* The socket 's' is already being monitored, update the activity mask. Convert from libcurl bitmask to the poll one. */ m->socket.events = socketcb2poll(what); - infof(data, "socket cb: socket %" FMT_SOCKET_T - " UPDATED as %s%s", s, - (what&CURL_POLL_IN) ? "IN" : "", - (what&CURL_POLL_OUT) ? "OUT" : ""); + infof(data, "socket cb: socket %" FMT_SOCKET_T " UPDATED as %s%s", s, + (what & CURL_POLL_IN) ? "IN" : "", + (what & CURL_POLL_OUT) ? "OUT" : ""); } break; } @@ -506,7 +497,7 @@ static int events_socket(CURL *easy, /* easy handle */ DEBUGASSERT(0); } else { - m = malloc(sizeof(struct socketmonitor)); + m = curlx_malloc(sizeof(struct socketmonitor)); if(m) { m->next = ev->list; m->socket.fd = s; @@ -514,8 +505,8 @@ static int events_socket(CURL *easy, /* easy handle */ m->socket.revents = 0; ev->list = m; infof(data, "socket cb: socket %" FMT_SOCKET_T " ADDED as %s%s", s, - (what&CURL_POLL_IN) ? "IN" : "", - (what&CURL_POLL_OUT) ? "OUT" : ""); + (what & CURL_POLL_IN) ? "IN" : "", + (what & CURL_POLL_OUT) ? "OUT" : ""); } else return CURLE_OUT_OF_MEMORY; @@ -525,7 +516,6 @@ static int events_socket(CURL *easy, /* easy handle */ return 0; } - /* * events_setup() * @@ -606,18 +596,18 @@ static CURLcode poll_fds(struct events *ev, static CURLcode wait_or_timeout(struct Curl_multi *multi, struct events *ev) { bool done = FALSE; - CURLMcode mcode = CURLM_OK; + CURLMcode mresult = CURLM_OK; CURLcode result = CURLE_OK; while(!done) { CURLMsg *msg; struct pollfd fds[4]; int pollrc; - struct curltime before; + struct curltime start; const unsigned int numfds = populate_fds(fds, ev); /* get the time stamp to use to figure out how long poll takes */ - before = curlx_now(); + curlx_pnow(&start); result = poll_fds(ev, fds, numfds, &pollrc); if(result) @@ -629,8 +619,8 @@ static CURLcode wait_or_timeout(struct Curl_multi *multi, struct events *ev) /* timeout! */ ev->ms = 0; /* curl_mfprintf(stderr, "call curl_multi_socket_action(TIMEOUT)\n"); */ - mcode = curl_multi_socket_action(multi, CURL_SOCKET_TIMEOUT, 0, - &ev->running_handles); + mresult = curl_multi_socket_action(multi, CURL_SOCKET_TIMEOUT, 0, + &ev->running_handles); } else { /* here pollrc is > 0 */ @@ -644,31 +634,30 @@ static CURLcode wait_or_timeout(struct Curl_multi *multi, struct events *ev) /* sending infof "randomly" to the first easy handle */ infof(multi->admin, "call curl_multi_socket_action(socket " "%" FMT_SOCKET_T ")", (curl_socket_t)fds[i].fd); - mcode = curl_multi_socket_action(multi, fds[i].fd, act, - &ev->running_handles); + mresult = curl_multi_socket_action(multi, fds[i].fd, act, + &ev->running_handles); } } - if(!ev->msbump && ev->ms >= 0) { /* If nothing updated the timeout, we decrease it by the spent time. * If it was updated, it has the new timeout time stored already. */ - timediff_t timediff = curlx_timediff(curlx_now(), before); - if(timediff > 0) { + timediff_t spent_ms = curlx_timediff_ms(curlx_now(), start); + if(spent_ms > 0) { #if DEBUG_EV_POLL curl_mfprintf(stderr, "poll timeout %ldms not updated, decrease by " - "time spent %ldms\n", ev->ms, (long)timediff); + "time spent %ldms\n", ev->ms, (long)spent_ms); #endif - if(timediff > ev->ms) + if(spent_ms > ev->ms) ev->ms = 0; else - ev->ms -= (long)timediff; + ev->ms -= (long)spent_ms; } } } - if(mcode) + if(mresult) return CURLE_URL_MALFORMAT; /* we do not really care about the "msgs_in_queue" value returned in the @@ -683,7 +672,6 @@ static CURLcode wait_or_timeout(struct Curl_multi *multi, struct events *ev) return result; } - /* easy_events() * * Runs a transfer in a blocking manner using the events-based API @@ -692,7 +680,7 @@ static CURLcode easy_events(struct Curl_multi *multi) { /* this struct is made static to allow it to be used after this function returns and curl_multi_remove_handle() is called */ - static struct events evs = {-1, FALSE, 0, NULL, 0}; + static struct events evs = { -1, FALSE, 0, NULL, 0 }; /* if running event-based, do some further multi inits */ events_setup(multi, &evs); @@ -707,19 +695,19 @@ static CURLcode easy_events(struct Curl_multi *multi) static CURLcode easy_transfer(struct Curl_multi *multi) { bool done = FALSE; - CURLMcode mcode = CURLM_OK; + CURLMcode mresult = CURLM_OK; CURLcode result = CURLE_OK; - while(!done && !mcode) { + while(!done && !mresult) { int still_running = 0; - mcode = curl_multi_poll(multi, NULL, 0, 1000, NULL); + mresult = curl_multi_poll(multi, NULL, 0, 1000, NULL); - if(!mcode) - mcode = curl_multi_perform(multi, &still_running); + if(!mresult) + mresult = curl_multi_perform(multi, &still_running); /* only read 'still_running' if curl_multi_perform() return OK */ - if(!mcode && !still_running) { + if(!mresult && !still_running) { int rc; CURLMsg *msg = curl_multi_info_read(multi, &rc); if(msg) { @@ -730,8 +718,8 @@ static CURLcode easy_transfer(struct Curl_multi *multi) } /* Make sure to return some kind of error if there was a multi problem */ - if(mcode) { - result = (mcode == CURLM_OUT_OF_MEMORY) ? CURLE_OUT_OF_MEMORY : + if(mresult) { + result = (mresult == CURLM_OUT_OF_MEMORY) ? CURLE_OUT_OF_MEMORY : /* The other multi errors should never happen, so return something suitably generic */ CURLE_BAD_FUNCTION_ARGUMENT; @@ -740,7 +728,6 @@ static CURLcode easy_transfer(struct Curl_multi *multi) return result; } - /* * easy_perform() is the internal interface that performs a blocking * transfer as previously setup. @@ -761,7 +748,7 @@ static CURLcode easy_transfer(struct Curl_multi *multi) static CURLcode easy_perform(struct Curl_easy *data, bool events) { struct Curl_multi *multi; - CURLMcode mcode; + CURLMcode mresult; CURLcode result = CURLE_OK; SIGPIPE_VARIABLE(pipe_st); @@ -809,10 +796,10 @@ static CURLcode easy_perform(struct Curl_easy *data, bool events) curl_multi_setopt(multi, CURLMOPT_MAXCONNECTS, (long)data->set.maxconnects); data->multi_easy = NULL; /* pretend it does not exist */ - mcode = curl_multi_add_handle(multi, data); - if(mcode) { + mresult = curl_multi_add_handle(multi, data); + if(mresult) { curl_multi_cleanup(multi); - if(mcode == CURLM_OUT_OF_MEMORY) + if(mresult == CURLM_OUT_OF_MEMORY) return CURLE_OUT_OF_MEMORY; return CURLE_FAILED_INIT; } @@ -929,7 +916,7 @@ static CURLcode dupset(struct Curl_easy *dst, struct Curl_easy *src) i = STRING_COPYPOSTFIELDS; if(src->set.str[i]) { if(src->set.postfieldsize == -1) - dst->set.str[i] = strdup(src->set.str[i]); + dst->set.str[i] = curlx_strdup(src->set.str[i]); else /* postfieldsize is curl_off_t, Curl_memdup() takes a size_t ... */ dst->set.str[i] = Curl_memdup(src->set.str[i], @@ -970,7 +957,7 @@ CURL *curl_easy_duphandle(CURL *d) if(!GOOD_EASY_HANDLE(data)) goto fail; - outcurl = calloc(1, sizeof(struct Curl_easy)); + outcurl = curlx_calloc(1, sizeof(struct Curl_easy)); if(!outcurl) goto fail; @@ -984,14 +971,16 @@ CURL *curl_easy_duphandle(CURL *d) Curl_hash_init(&outcurl->meta_hash, 23, Curl_hash_str, curlx_str_key_compare, dupeasy_meta_freeentry); curlx_dyn_init(&outcurl->state.headerb, CURL_MAX_HTTP_HEADER); + Curl_bufref_init(&outcurl->state.url); + Curl_bufref_init(&outcurl->state.referer); Curl_netrc_init(&outcurl->state.netrc); /* the connection pool is setup on demand */ outcurl->state.lastconnect_id = -1; outcurl->state.recent_conn_id = -1; outcurl->id = -1; - outcurl->mid = UINT_MAX; - outcurl->master_mid = UINT_MAX; + outcurl->mid = UINT32_MAX; + outcurl->master_mid = UINT32_MAX; #ifndef CURL_DISABLE_HTTP Curl_llist_init(&outcurl->state.httphdrs, NULL); @@ -1010,10 +999,10 @@ CURL *curl_easy_duphandle(CURL *d) if(data->cookies && data->state.cookie_engine) { /* If cookies are enabled in the parent handle, we enable them in the clone as well! */ - outcurl->cookies = Curl_cookie_init(outcurl, NULL, outcurl->cookies, - data->set.cookiesession); + outcurl->cookies = Curl_cookie_init(); if(!outcurl->cookies) goto fail; + outcurl->state.cookie_engine = TRUE; } if(data->state.cookielist) { @@ -1023,18 +1012,19 @@ CURL *curl_easy_duphandle(CURL *d) } #endif - if(data->state.url) { - outcurl->state.url = strdup(data->state.url); - if(!outcurl->state.url) + if(Curl_bufref_ptr(&data->state.url)) { + Curl_bufref_set(&outcurl->state.url, + Curl_bufref_dup(&data->state.url), 0, + curl_free); + if(!Curl_bufref_ptr(&outcurl->state.url)) goto fail; - outcurl->state.url_alloc = TRUE; } - - if(data->state.referer) { - outcurl->state.referer = strdup(data->state.referer); - if(!outcurl->state.referer) + if(Curl_bufref_ptr(&data->state.referer)) { + Curl_bufref_set(&outcurl->state.referer, + Curl_bufref_dup(&data->state.referer), 0, + curl_free); + if(!Curl_bufref_ptr(&outcurl->state.referer)) goto fail; - outcurl->state.referer_alloc = TRUE; } /* Reinitialize an SSL engine for the new handle @@ -1075,13 +1065,13 @@ CURL *curl_easy_duphandle(CURL *d) if(outcurl) { #ifndef CURL_DISABLE_COOKIES - free(outcurl->cookies); + curlx_free(outcurl->cookies); #endif curlx_dyn_free(&outcurl->state.headerb); Curl_altsvc_cleanup(&outcurl->asi); Curl_hsts_cleanup(&outcurl->hsts); Curl_freeset(outcurl); - free(outcurl); + curlx_free(outcurl); } return NULL; @@ -1128,7 +1118,7 @@ void curl_easy_reset(CURL *d) #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_DIGEST_AUTH) Curl_http_auth_cleanup_digest(data); #endif - data->master_mid = UINT_MAX; + data->master_mid = UINT32_MAX; } /* @@ -1203,7 +1193,6 @@ CURLcode curl_easy_pause(CURL *d, int action) return result; } - static CURLcode easy_connection(struct Curl_easy *data, struct connectdata **connp) { diff --git a/vendor/hydra/vendor/curl/lib/easy_lock.h b/vendor/hydra/vendor/curl/lib/easy_lock.h index f8998cc5..10c84c6a 100644 --- a/vendor/hydra/vendor/curl/lib/easy_lock.h +++ b/vendor/hydra/vendor/curl/lib/easy_lock.h @@ -23,17 +23,16 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #define GLOBAL_INIT_IS_THREADSAFE #if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x600 -#define curl_simple_lock SRWLOCK +#define curl_simple_lock SRWLOCK #define CURL_SIMPLE_LOCK_INIT SRWLOCK_INIT -#define curl_simple_lock_lock(m) AcquireSRWLockExclusive(m) +#define curl_simple_lock_lock(m) AcquireSRWLockExclusive(m) #define curl_simple_lock_unlock(m) ReleaseSRWLockExclusive(m) #elif defined(HAVE_ATOMIC) && defined(HAVE_STDATOMIC_H) @@ -42,7 +41,7 @@ #include #endif -#define curl_simple_lock atomic_int +#define curl_simple_lock atomic_int #define CURL_SIMPLE_LOCK_INIT 0 #ifndef __INTEL_COMPILER @@ -59,7 +58,7 @@ #endif #endif -#endif +#endif /* !__INTEL_COMPILER */ static CURL_INLINE void curl_simple_lock_lock(curl_simple_lock *lock) { @@ -91,14 +90,14 @@ static CURL_INLINE void curl_simple_lock_unlock(curl_simple_lock *lock) #include -#define curl_simple_lock pthread_mutex_t -#define CURL_SIMPLE_LOCK_INIT PTHREAD_MUTEX_INITIALIZER -#define curl_simple_lock_lock(m) pthread_mutex_lock(m) +#define curl_simple_lock pthread_mutex_t +#define CURL_SIMPLE_LOCK_INIT PTHREAD_MUTEX_INITIALIZER +#define curl_simple_lock_lock(m) pthread_mutex_lock(m) #define curl_simple_lock_unlock(m) pthread_mutex_unlock(m) #else -#undef GLOBAL_INIT_IS_THREADSAFE +#undef GLOBAL_INIT_IS_THREADSAFE #endif diff --git a/vendor/hydra/vendor/curl/lib/easygetopt.c b/vendor/hydra/vendor/curl/lib/easygetopt.c index 7ac39bc6..2685adae 100644 --- a/vendor/hydra/vendor/curl/lib/easygetopt.c +++ b/vendor/hydra/vendor/curl/lib/easygetopt.c @@ -21,8 +21,8 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" + #include "easyoptions.h" #ifndef CURL_DISABLE_GETOPTIONS diff --git a/vendor/hydra/vendor/curl/lib/easyif.h b/vendor/hydra/vendor/curl/lib/easyif.h index 181ce38f..213fd027 100644 --- a/vendor/hydra/vendor/curl/lib/easyif.h +++ b/vendor/hydra/vendor/curl/lib/easyif.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - /* * Prototypes for library-wide functions provided by easy.c */ diff --git a/vendor/hydra/vendor/curl/lib/easyoptions.c b/vendor/hydra/vendor/curl/lib/easyoptions.c index 03d676df..4c0b4f0c 100644 --- a/vendor/hydra/vendor/curl/lib/easyoptions.c +++ b/vendor/hydra/vendor/curl/lib/easyoptions.c @@ -25,352 +25,357 @@ /* This source code is generated by optiontable.pl - DO NOT EDIT BY HAND */ #include "curl_setup.h" + #include "easyoptions.h" /* all easy setopt options listed in alphabetical order */ const struct curl_easyoption Curl_easyopts[] = { - {"ABSTRACT_UNIX_SOCKET", CURLOPT_ABSTRACT_UNIX_SOCKET, CURLOT_STRING, 0}, - {"ACCEPTTIMEOUT_MS", CURLOPT_ACCEPTTIMEOUT_MS, CURLOT_LONG, 0}, - {"ACCEPT_ENCODING", CURLOPT_ACCEPT_ENCODING, CURLOT_STRING, 0}, - {"ADDRESS_SCOPE", CURLOPT_ADDRESS_SCOPE, CURLOT_LONG, 0}, - {"ALTSVC", CURLOPT_ALTSVC, CURLOT_STRING, 0}, - {"ALTSVC_CTRL", CURLOPT_ALTSVC_CTRL, CURLOT_LONG, 0}, - {"APPEND", CURLOPT_APPEND, CURLOT_LONG, 0}, - {"AUTOREFERER", CURLOPT_AUTOREFERER, CURLOT_LONG, 0}, - {"AWS_SIGV4", CURLOPT_AWS_SIGV4, CURLOT_STRING, 0}, - {"BUFFERSIZE", CURLOPT_BUFFERSIZE, CURLOT_LONG, 0}, - {"CAINFO", CURLOPT_CAINFO, CURLOT_STRING, 0}, - {"CAINFO_BLOB", CURLOPT_CAINFO_BLOB, CURLOT_BLOB, 0}, - {"CAPATH", CURLOPT_CAPATH, CURLOT_STRING, 0}, - {"CA_CACHE_TIMEOUT", CURLOPT_CA_CACHE_TIMEOUT, CURLOT_LONG, 0}, - {"CERTINFO", CURLOPT_CERTINFO, CURLOT_LONG, 0}, - {"CHUNK_BGN_FUNCTION", CURLOPT_CHUNK_BGN_FUNCTION, CURLOT_FUNCTION, 0}, - {"CHUNK_DATA", CURLOPT_CHUNK_DATA, CURLOT_CBPTR, 0}, - {"CHUNK_END_FUNCTION", CURLOPT_CHUNK_END_FUNCTION, CURLOT_FUNCTION, 0}, - {"CLOSESOCKETDATA", CURLOPT_CLOSESOCKETDATA, CURLOT_CBPTR, 0}, - {"CLOSESOCKETFUNCTION", CURLOPT_CLOSESOCKETFUNCTION, CURLOT_FUNCTION, 0}, - {"CONNECTTIMEOUT", CURLOPT_CONNECTTIMEOUT, CURLOT_LONG, 0}, - {"CONNECTTIMEOUT_MS", CURLOPT_CONNECTTIMEOUT_MS, CURLOT_LONG, 0}, - {"CONNECT_ONLY", CURLOPT_CONNECT_ONLY, CURLOT_LONG, 0}, - {"CONNECT_TO", CURLOPT_CONNECT_TO, CURLOT_SLIST, 0}, - {"CONV_FROM_NETWORK_FUNCTION", CURLOPT_CONV_FROM_NETWORK_FUNCTION, - CURLOT_FUNCTION, 0}, - {"CONV_FROM_UTF8_FUNCTION", CURLOPT_CONV_FROM_UTF8_FUNCTION, - CURLOT_FUNCTION, 0}, - {"CONV_TO_NETWORK_FUNCTION", CURLOPT_CONV_TO_NETWORK_FUNCTION, - CURLOT_FUNCTION, 0}, - {"COOKIE", CURLOPT_COOKIE, CURLOT_STRING, 0}, - {"COOKIEFILE", CURLOPT_COOKIEFILE, CURLOT_STRING, 0}, - {"COOKIEJAR", CURLOPT_COOKIEJAR, CURLOT_STRING, 0}, - {"COOKIELIST", CURLOPT_COOKIELIST, CURLOT_STRING, 0}, - {"COOKIESESSION", CURLOPT_COOKIESESSION, CURLOT_LONG, 0}, - {"COPYPOSTFIELDS", CURLOPT_COPYPOSTFIELDS, CURLOT_OBJECT, 0}, - {"CRLF", CURLOPT_CRLF, CURLOT_LONG, 0}, - {"CRLFILE", CURLOPT_CRLFILE, CURLOT_STRING, 0}, - {"CURLU", CURLOPT_CURLU, CURLOT_OBJECT, 0}, - {"CUSTOMREQUEST", CURLOPT_CUSTOMREQUEST, CURLOT_STRING, 0}, - {"DEBUGDATA", CURLOPT_DEBUGDATA, CURLOT_CBPTR, 0}, - {"DEBUGFUNCTION", CURLOPT_DEBUGFUNCTION, CURLOT_FUNCTION, 0}, - {"DEFAULT_PROTOCOL", CURLOPT_DEFAULT_PROTOCOL, CURLOT_STRING, 0}, - {"DIRLISTONLY", CURLOPT_DIRLISTONLY, CURLOT_LONG, 0}, - {"DISALLOW_USERNAME_IN_URL", CURLOPT_DISALLOW_USERNAME_IN_URL, - CURLOT_LONG, 0}, - {"DNS_CACHE_TIMEOUT", CURLOPT_DNS_CACHE_TIMEOUT, CURLOT_LONG, 0}, - {"DNS_INTERFACE", CURLOPT_DNS_INTERFACE, CURLOT_STRING, 0}, - {"DNS_LOCAL_IP4", CURLOPT_DNS_LOCAL_IP4, CURLOT_STRING, 0}, - {"DNS_LOCAL_IP6", CURLOPT_DNS_LOCAL_IP6, CURLOT_STRING, 0}, - {"DNS_SERVERS", CURLOPT_DNS_SERVERS, CURLOT_STRING, 0}, - {"DNS_SHUFFLE_ADDRESSES", CURLOPT_DNS_SHUFFLE_ADDRESSES, CURLOT_LONG, 0}, - {"DNS_USE_GLOBAL_CACHE", CURLOPT_DNS_USE_GLOBAL_CACHE, CURLOT_LONG, 0}, - {"DOH_SSL_VERIFYHOST", CURLOPT_DOH_SSL_VERIFYHOST, CURLOT_LONG, 0}, - {"DOH_SSL_VERIFYPEER", CURLOPT_DOH_SSL_VERIFYPEER, CURLOT_LONG, 0}, - {"DOH_SSL_VERIFYSTATUS", CURLOPT_DOH_SSL_VERIFYSTATUS, CURLOT_LONG, 0}, - {"DOH_URL", CURLOPT_DOH_URL, CURLOT_STRING, 0}, - {"ECH", CURLOPT_ECH, CURLOT_STRING, 0}, - {"EGDSOCKET", CURLOPT_EGDSOCKET, CURLOT_STRING, 0}, - {"ENCODING", CURLOPT_ACCEPT_ENCODING, CURLOT_STRING, CURLOT_FLAG_ALIAS}, - {"ERRORBUFFER", CURLOPT_ERRORBUFFER, CURLOT_OBJECT, 0}, - {"EXPECT_100_TIMEOUT_MS", CURLOPT_EXPECT_100_TIMEOUT_MS, CURLOT_LONG, 0}, - {"FAILONERROR", CURLOPT_FAILONERROR, CURLOT_LONG, 0}, - {"FILE", CURLOPT_WRITEDATA, CURLOT_CBPTR, CURLOT_FLAG_ALIAS}, - {"FILETIME", CURLOPT_FILETIME, CURLOT_LONG, 0}, - {"FNMATCH_DATA", CURLOPT_FNMATCH_DATA, CURLOT_CBPTR, 0}, - {"FNMATCH_FUNCTION", CURLOPT_FNMATCH_FUNCTION, CURLOT_FUNCTION, 0}, - {"FOLLOWLOCATION", CURLOPT_FOLLOWLOCATION, CURLOT_LONG, 0}, - {"FORBID_REUSE", CURLOPT_FORBID_REUSE, CURLOT_LONG, 0}, - {"FRESH_CONNECT", CURLOPT_FRESH_CONNECT, CURLOT_LONG, 0}, - {"FTPAPPEND", CURLOPT_APPEND, CURLOT_LONG, CURLOT_FLAG_ALIAS}, - {"FTPLISTONLY", CURLOPT_DIRLISTONLY, CURLOT_LONG, CURLOT_FLAG_ALIAS}, - {"FTPPORT", CURLOPT_FTPPORT, CURLOT_STRING, 0}, - {"FTPSSLAUTH", CURLOPT_FTPSSLAUTH, CURLOT_VALUES, 0}, - {"FTP_ACCOUNT", CURLOPT_FTP_ACCOUNT, CURLOT_STRING, 0}, - {"FTP_ALTERNATIVE_TO_USER", CURLOPT_FTP_ALTERNATIVE_TO_USER, - CURLOT_STRING, 0}, - {"FTP_CREATE_MISSING_DIRS", CURLOPT_FTP_CREATE_MISSING_DIRS, - CURLOT_LONG, 0}, - {"FTP_FILEMETHOD", CURLOPT_FTP_FILEMETHOD, CURLOT_VALUES, 0}, - {"FTP_RESPONSE_TIMEOUT", CURLOPT_SERVER_RESPONSE_TIMEOUT, - CURLOT_LONG, CURLOT_FLAG_ALIAS}, - {"FTP_SKIP_PASV_IP", CURLOPT_FTP_SKIP_PASV_IP, CURLOT_LONG, 0}, - {"FTP_SSL", CURLOPT_USE_SSL, CURLOT_VALUES, CURLOT_FLAG_ALIAS}, - {"FTP_SSL_CCC", CURLOPT_FTP_SSL_CCC, CURLOT_LONG, 0}, - {"FTP_USE_EPRT", CURLOPT_FTP_USE_EPRT, CURLOT_LONG, 0}, - {"FTP_USE_EPSV", CURLOPT_FTP_USE_EPSV, CURLOT_LONG, 0}, - {"FTP_USE_PRET", CURLOPT_FTP_USE_PRET, CURLOT_LONG, 0}, - {"GSSAPI_DELEGATION", CURLOPT_GSSAPI_DELEGATION, CURLOT_VALUES, 0}, - {"HAPPY_EYEBALLS_TIMEOUT_MS", CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS, - CURLOT_LONG, 0}, - {"HAPROXYPROTOCOL", CURLOPT_HAPROXYPROTOCOL, CURLOT_LONG, 0}, - {"HAPROXY_CLIENT_IP", CURLOPT_HAPROXY_CLIENT_IP, CURLOT_STRING, 0}, - {"HEADER", CURLOPT_HEADER, CURLOT_LONG, 0}, - {"HEADERDATA", CURLOPT_HEADERDATA, CURLOT_CBPTR, 0}, - {"HEADERFUNCTION", CURLOPT_HEADERFUNCTION, CURLOT_FUNCTION, 0}, - {"HEADEROPT", CURLOPT_HEADEROPT, CURLOT_VALUES, 0}, - {"HSTS", CURLOPT_HSTS, CURLOT_STRING, 0}, - {"HSTSREADDATA", CURLOPT_HSTSREADDATA, CURLOT_CBPTR, 0}, - {"HSTSREADFUNCTION", CURLOPT_HSTSREADFUNCTION, CURLOT_FUNCTION, 0}, - {"HSTSWRITEDATA", CURLOPT_HSTSWRITEDATA, CURLOT_CBPTR, 0}, - {"HSTSWRITEFUNCTION", CURLOPT_HSTSWRITEFUNCTION, CURLOT_FUNCTION, 0}, - {"HSTS_CTRL", CURLOPT_HSTS_CTRL, CURLOT_LONG, 0}, - {"HTTP09_ALLOWED", CURLOPT_HTTP09_ALLOWED, CURLOT_LONG, 0}, - {"HTTP200ALIASES", CURLOPT_HTTP200ALIASES, CURLOT_SLIST, 0}, - {"HTTPAUTH", CURLOPT_HTTPAUTH, CURLOT_VALUES, 0}, - {"HTTPGET", CURLOPT_HTTPGET, CURLOT_LONG, 0}, - {"HTTPHEADER", CURLOPT_HTTPHEADER, CURLOT_SLIST, 0}, - {"HTTPPOST", CURLOPT_HTTPPOST, CURLOT_OBJECT, 0}, - {"HTTPPROXYTUNNEL", CURLOPT_HTTPPROXYTUNNEL, CURLOT_LONG, 0}, - {"HTTP_CONTENT_DECODING", CURLOPT_HTTP_CONTENT_DECODING, CURLOT_LONG, 0}, - {"HTTP_TRANSFER_DECODING", CURLOPT_HTTP_TRANSFER_DECODING, CURLOT_LONG, 0}, - {"HTTP_VERSION", CURLOPT_HTTP_VERSION, CURLOT_VALUES, 0}, - {"IGNORE_CONTENT_LENGTH", CURLOPT_IGNORE_CONTENT_LENGTH, CURLOT_LONG, 0}, - {"INFILE", CURLOPT_READDATA, CURLOT_CBPTR, CURLOT_FLAG_ALIAS}, - {"INFILESIZE", CURLOPT_INFILESIZE, CURLOT_LONG, 0}, - {"INFILESIZE_LARGE", CURLOPT_INFILESIZE_LARGE, CURLOT_OFF_T, 0}, - {"INTERFACE", CURLOPT_INTERFACE, CURLOT_STRING, 0}, - {"INTERLEAVEDATA", CURLOPT_INTERLEAVEDATA, CURLOT_CBPTR, 0}, - {"INTERLEAVEFUNCTION", CURLOPT_INTERLEAVEFUNCTION, CURLOT_FUNCTION, 0}, - {"IOCTLDATA", CURLOPT_IOCTLDATA, CURLOT_CBPTR, 0}, - {"IOCTLFUNCTION", CURLOPT_IOCTLFUNCTION, CURLOT_FUNCTION, 0}, - {"IPRESOLVE", CURLOPT_IPRESOLVE, CURLOT_VALUES, 0}, - {"ISSUERCERT", CURLOPT_ISSUERCERT, CURLOT_STRING, 0}, - {"ISSUERCERT_BLOB", CURLOPT_ISSUERCERT_BLOB, CURLOT_BLOB, 0}, - {"KEEP_SENDING_ON_ERROR", CURLOPT_KEEP_SENDING_ON_ERROR, CURLOT_LONG, 0}, - {"KEYPASSWD", CURLOPT_KEYPASSWD, CURLOT_STRING, 0}, - {"KRB4LEVEL", CURLOPT_KRBLEVEL, CURLOT_STRING, CURLOT_FLAG_ALIAS}, - {"KRBLEVEL", CURLOPT_KRBLEVEL, CURLOT_STRING, 0}, - {"LOCALPORT", CURLOPT_LOCALPORT, CURLOT_LONG, 0}, - {"LOCALPORTRANGE", CURLOPT_LOCALPORTRANGE, CURLOT_LONG, 0}, - {"LOGIN_OPTIONS", CURLOPT_LOGIN_OPTIONS, CURLOT_STRING, 0}, - {"LOW_SPEED_LIMIT", CURLOPT_LOW_SPEED_LIMIT, CURLOT_LONG, 0}, - {"LOW_SPEED_TIME", CURLOPT_LOW_SPEED_TIME, CURLOT_LONG, 0}, - {"MAIL_AUTH", CURLOPT_MAIL_AUTH, CURLOT_STRING, 0}, - {"MAIL_FROM", CURLOPT_MAIL_FROM, CURLOT_STRING, 0}, - {"MAIL_RCPT", CURLOPT_MAIL_RCPT, CURLOT_SLIST, 0}, - {"MAIL_RCPT_ALLLOWFAILS", CURLOPT_MAIL_RCPT_ALLOWFAILS, - CURLOT_LONG, CURLOT_FLAG_ALIAS}, - {"MAIL_RCPT_ALLOWFAILS", CURLOPT_MAIL_RCPT_ALLOWFAILS, CURLOT_LONG, 0}, - {"MAXAGE_CONN", CURLOPT_MAXAGE_CONN, CURLOT_LONG, 0}, - {"MAXCONNECTS", CURLOPT_MAXCONNECTS, CURLOT_LONG, 0}, - {"MAXFILESIZE", CURLOPT_MAXFILESIZE, CURLOT_LONG, 0}, - {"MAXFILESIZE_LARGE", CURLOPT_MAXFILESIZE_LARGE, CURLOT_OFF_T, 0}, - {"MAXLIFETIME_CONN", CURLOPT_MAXLIFETIME_CONN, CURLOT_LONG, 0}, - {"MAXREDIRS", CURLOPT_MAXREDIRS, CURLOT_LONG, 0}, - {"MAX_RECV_SPEED_LARGE", CURLOPT_MAX_RECV_SPEED_LARGE, CURLOT_OFF_T, 0}, - {"MAX_SEND_SPEED_LARGE", CURLOPT_MAX_SEND_SPEED_LARGE, CURLOT_OFF_T, 0}, - {"MIMEPOST", CURLOPT_MIMEPOST, CURLOT_OBJECT, 0}, - {"MIME_OPTIONS", CURLOPT_MIME_OPTIONS, CURLOT_LONG, 0}, - {"NETRC", CURLOPT_NETRC, CURLOT_VALUES, 0}, - {"NETRC_FILE", CURLOPT_NETRC_FILE, CURLOT_STRING, 0}, - {"NEW_DIRECTORY_PERMS", CURLOPT_NEW_DIRECTORY_PERMS, CURLOT_LONG, 0}, - {"NEW_FILE_PERMS", CURLOPT_NEW_FILE_PERMS, CURLOT_LONG, 0}, - {"NOBODY", CURLOPT_NOBODY, CURLOT_LONG, 0}, - {"NOPROGRESS", CURLOPT_NOPROGRESS, CURLOT_LONG, 0}, - {"NOPROXY", CURLOPT_NOPROXY, CURLOT_STRING, 0}, - {"NOSIGNAL", CURLOPT_NOSIGNAL, CURLOT_LONG, 0}, - {"OPENSOCKETDATA", CURLOPT_OPENSOCKETDATA, CURLOT_CBPTR, 0}, - {"OPENSOCKETFUNCTION", CURLOPT_OPENSOCKETFUNCTION, CURLOT_FUNCTION, 0}, - {"PASSWORD", CURLOPT_PASSWORD, CURLOT_STRING, 0}, - {"PATH_AS_IS", CURLOPT_PATH_AS_IS, CURLOT_LONG, 0}, - {"PINNEDPUBLICKEY", CURLOPT_PINNEDPUBLICKEY, CURLOT_STRING, 0}, - {"PIPEWAIT", CURLOPT_PIPEWAIT, CURLOT_LONG, 0}, - {"PORT", CURLOPT_PORT, CURLOT_LONG, 0}, - {"POST", CURLOPT_POST, CURLOT_LONG, 0}, - {"POST301", CURLOPT_POSTREDIR, CURLOT_VALUES, CURLOT_FLAG_ALIAS}, - {"POSTFIELDS", CURLOPT_POSTFIELDS, CURLOT_OBJECT, 0}, - {"POSTFIELDSIZE", CURLOPT_POSTFIELDSIZE, CURLOT_LONG, 0}, - {"POSTFIELDSIZE_LARGE", CURLOPT_POSTFIELDSIZE_LARGE, CURLOT_OFF_T, 0}, - {"POSTQUOTE", CURLOPT_POSTQUOTE, CURLOT_SLIST, 0}, - {"POSTREDIR", CURLOPT_POSTREDIR, CURLOT_VALUES, 0}, - {"PREQUOTE", CURLOPT_PREQUOTE, CURLOT_SLIST, 0}, - {"PREREQDATA", CURLOPT_PREREQDATA, CURLOT_CBPTR, 0}, - {"PREREQFUNCTION", CURLOPT_PREREQFUNCTION, CURLOT_FUNCTION, 0}, - {"PRE_PROXY", CURLOPT_PRE_PROXY, CURLOT_STRING, 0}, - {"PRIVATE", CURLOPT_PRIVATE, CURLOT_OBJECT, 0}, - {"PROGRESSDATA", CURLOPT_XFERINFODATA, CURLOT_CBPTR, CURLOT_FLAG_ALIAS}, - {"PROGRESSFUNCTION", CURLOPT_PROGRESSFUNCTION, CURLOT_FUNCTION, 0}, - {"PROTOCOLS", CURLOPT_PROTOCOLS, CURLOT_LONG, 0}, - {"PROTOCOLS_STR", CURLOPT_PROTOCOLS_STR, CURLOT_STRING, 0}, - {"PROXY", CURLOPT_PROXY, CURLOT_STRING, 0}, - {"PROXYAUTH", CURLOPT_PROXYAUTH, CURLOT_VALUES, 0}, - {"PROXYHEADER", CURLOPT_PROXYHEADER, CURLOT_SLIST, 0}, - {"PROXYPASSWORD", CURLOPT_PROXYPASSWORD, CURLOT_STRING, 0}, - {"PROXYPORT", CURLOPT_PROXYPORT, CURLOT_LONG, 0}, - {"PROXYTYPE", CURLOPT_PROXYTYPE, CURLOT_VALUES, 0}, - {"PROXYUSERNAME", CURLOPT_PROXYUSERNAME, CURLOT_STRING, 0}, - {"PROXYUSERPWD", CURLOPT_PROXYUSERPWD, CURLOT_STRING, 0}, - {"PROXY_CAINFO", CURLOPT_PROXY_CAINFO, CURLOT_STRING, 0}, - {"PROXY_CAINFO_BLOB", CURLOPT_PROXY_CAINFO_BLOB, CURLOT_BLOB, 0}, - {"PROXY_CAPATH", CURLOPT_PROXY_CAPATH, CURLOT_STRING, 0}, - {"PROXY_CRLFILE", CURLOPT_PROXY_CRLFILE, CURLOT_STRING, 0}, - {"PROXY_ISSUERCERT", CURLOPT_PROXY_ISSUERCERT, CURLOT_STRING, 0}, - {"PROXY_ISSUERCERT_BLOB", CURLOPT_PROXY_ISSUERCERT_BLOB, CURLOT_BLOB, 0}, - {"PROXY_KEYPASSWD", CURLOPT_PROXY_KEYPASSWD, CURLOT_STRING, 0}, - {"PROXY_PINNEDPUBLICKEY", CURLOPT_PROXY_PINNEDPUBLICKEY, CURLOT_STRING, 0}, - {"PROXY_SERVICE_NAME", CURLOPT_PROXY_SERVICE_NAME, CURLOT_STRING, 0}, - {"PROXY_SSLCERT", CURLOPT_PROXY_SSLCERT, CURLOT_STRING, 0}, - {"PROXY_SSLCERTTYPE", CURLOPT_PROXY_SSLCERTTYPE, CURLOT_STRING, 0}, - {"PROXY_SSLCERT_BLOB", CURLOPT_PROXY_SSLCERT_BLOB, CURLOT_BLOB, 0}, - {"PROXY_SSLKEY", CURLOPT_PROXY_SSLKEY, CURLOT_STRING, 0}, - {"PROXY_SSLKEYTYPE", CURLOPT_PROXY_SSLKEYTYPE, CURLOT_STRING, 0}, - {"PROXY_SSLKEY_BLOB", CURLOPT_PROXY_SSLKEY_BLOB, CURLOT_BLOB, 0}, - {"PROXY_SSLVERSION", CURLOPT_PROXY_SSLVERSION, CURLOT_VALUES, 0}, - {"PROXY_SSL_CIPHER_LIST", CURLOPT_PROXY_SSL_CIPHER_LIST, CURLOT_STRING, 0}, - {"PROXY_SSL_OPTIONS", CURLOPT_PROXY_SSL_OPTIONS, CURLOT_LONG, 0}, - {"PROXY_SSL_VERIFYHOST", CURLOPT_PROXY_SSL_VERIFYHOST, CURLOT_LONG, 0}, - {"PROXY_SSL_VERIFYPEER", CURLOPT_PROXY_SSL_VERIFYPEER, CURLOT_LONG, 0}, - {"PROXY_TLS13_CIPHERS", CURLOPT_PROXY_TLS13_CIPHERS, CURLOT_STRING, 0}, - {"PROXY_TLSAUTH_PASSWORD", CURLOPT_PROXY_TLSAUTH_PASSWORD, - CURLOT_STRING, 0}, - {"PROXY_TLSAUTH_TYPE", CURLOPT_PROXY_TLSAUTH_TYPE, CURLOT_STRING, 0}, - {"PROXY_TLSAUTH_USERNAME", CURLOPT_PROXY_TLSAUTH_USERNAME, - CURLOT_STRING, 0}, - {"PROXY_TRANSFER_MODE", CURLOPT_PROXY_TRANSFER_MODE, CURLOT_LONG, 0}, - {"PUT", CURLOPT_PUT, CURLOT_LONG, 0}, - {"QUICK_EXIT", CURLOPT_QUICK_EXIT, CURLOT_LONG, 0}, - {"QUOTE", CURLOPT_QUOTE, CURLOT_SLIST, 0}, - {"RANDOM_FILE", CURLOPT_RANDOM_FILE, CURLOT_STRING, 0}, - {"RANGE", CURLOPT_RANGE, CURLOT_STRING, 0}, - {"READDATA", CURLOPT_READDATA, CURLOT_CBPTR, 0}, - {"READFUNCTION", CURLOPT_READFUNCTION, CURLOT_FUNCTION, 0}, - {"REDIR_PROTOCOLS", CURLOPT_REDIR_PROTOCOLS, CURLOT_LONG, 0}, - {"REDIR_PROTOCOLS_STR", CURLOPT_REDIR_PROTOCOLS_STR, CURLOT_STRING, 0}, - {"REFERER", CURLOPT_REFERER, CURLOT_STRING, 0}, - {"REQUEST_TARGET", CURLOPT_REQUEST_TARGET, CURLOT_STRING, 0}, - {"RESOLVE", CURLOPT_RESOLVE, CURLOT_SLIST, 0}, - {"RESOLVER_START_DATA", CURLOPT_RESOLVER_START_DATA, CURLOT_CBPTR, 0}, - {"RESOLVER_START_FUNCTION", CURLOPT_RESOLVER_START_FUNCTION, - CURLOT_FUNCTION, 0}, - {"RESUME_FROM", CURLOPT_RESUME_FROM, CURLOT_LONG, 0}, - {"RESUME_FROM_LARGE", CURLOPT_RESUME_FROM_LARGE, CURLOT_OFF_T, 0}, - {"RTSPHEADER", CURLOPT_HTTPHEADER, CURLOT_SLIST, CURLOT_FLAG_ALIAS}, - {"RTSP_CLIENT_CSEQ", CURLOPT_RTSP_CLIENT_CSEQ, CURLOT_LONG, 0}, - {"RTSP_REQUEST", CURLOPT_RTSP_REQUEST, CURLOT_VALUES, 0}, - {"RTSP_SERVER_CSEQ", CURLOPT_RTSP_SERVER_CSEQ, CURLOT_LONG, 0}, - {"RTSP_SESSION_ID", CURLOPT_RTSP_SESSION_ID, CURLOT_STRING, 0}, - {"RTSP_STREAM_URI", CURLOPT_RTSP_STREAM_URI, CURLOT_STRING, 0}, - {"RTSP_TRANSPORT", CURLOPT_RTSP_TRANSPORT, CURLOT_STRING, 0}, - {"SASL_AUTHZID", CURLOPT_SASL_AUTHZID, CURLOT_STRING, 0}, - {"SASL_IR", CURLOPT_SASL_IR, CURLOT_LONG, 0}, - {"SEEKDATA", CURLOPT_SEEKDATA, CURLOT_CBPTR, 0}, - {"SEEKFUNCTION", CURLOPT_SEEKFUNCTION, CURLOT_FUNCTION, 0}, - {"SERVER_RESPONSE_TIMEOUT", CURLOPT_SERVER_RESPONSE_TIMEOUT, - CURLOT_LONG, 0}, - {"SERVER_RESPONSE_TIMEOUT_MS", CURLOPT_SERVER_RESPONSE_TIMEOUT_MS, - CURLOT_LONG, 0}, - {"SERVICE_NAME", CURLOPT_SERVICE_NAME, CURLOT_STRING, 0}, - {"SHARE", CURLOPT_SHARE, CURLOT_OBJECT, 0}, - {"SOCKOPTDATA", CURLOPT_SOCKOPTDATA, CURLOT_CBPTR, 0}, - {"SOCKOPTFUNCTION", CURLOPT_SOCKOPTFUNCTION, CURLOT_FUNCTION, 0}, - {"SOCKS5_AUTH", CURLOPT_SOCKS5_AUTH, CURLOT_LONG, 0}, - {"SOCKS5_GSSAPI_NEC", CURLOPT_SOCKS5_GSSAPI_NEC, CURLOT_LONG, 0}, - {"SOCKS5_GSSAPI_SERVICE", CURLOPT_SOCKS5_GSSAPI_SERVICE, CURLOT_STRING, 0}, - {"SSH_AUTH_TYPES", CURLOPT_SSH_AUTH_TYPES, CURLOT_VALUES, 0}, - {"SSH_COMPRESSION", CURLOPT_SSH_COMPRESSION, CURLOT_LONG, 0}, - {"SSH_HOSTKEYDATA", CURLOPT_SSH_HOSTKEYDATA, CURLOT_CBPTR, 0}, - {"SSH_HOSTKEYFUNCTION", CURLOPT_SSH_HOSTKEYFUNCTION, CURLOT_FUNCTION, 0}, - {"SSH_HOST_PUBLIC_KEY_MD5", CURLOPT_SSH_HOST_PUBLIC_KEY_MD5, - CURLOT_STRING, 0}, - {"SSH_HOST_PUBLIC_KEY_SHA256", CURLOPT_SSH_HOST_PUBLIC_KEY_SHA256, - CURLOT_STRING, 0}, - {"SSH_KEYDATA", CURLOPT_SSH_KEYDATA, CURLOT_CBPTR, 0}, - {"SSH_KEYFUNCTION", CURLOPT_SSH_KEYFUNCTION, CURLOT_FUNCTION, 0}, - {"SSH_KNOWNHOSTS", CURLOPT_SSH_KNOWNHOSTS, CURLOT_STRING, 0}, - {"SSH_PRIVATE_KEYFILE", CURLOPT_SSH_PRIVATE_KEYFILE, CURLOT_STRING, 0}, - {"SSH_PUBLIC_KEYFILE", CURLOPT_SSH_PUBLIC_KEYFILE, CURLOT_STRING, 0}, - {"SSLCERT", CURLOPT_SSLCERT, CURLOT_STRING, 0}, - {"SSLCERTPASSWD", CURLOPT_KEYPASSWD, CURLOT_STRING, CURLOT_FLAG_ALIAS}, - {"SSLCERTTYPE", CURLOPT_SSLCERTTYPE, CURLOT_STRING, 0}, - {"SSLCERT_BLOB", CURLOPT_SSLCERT_BLOB, CURLOT_BLOB, 0}, - {"SSLENGINE", CURLOPT_SSLENGINE, CURLOT_STRING, 0}, - {"SSLENGINE_DEFAULT", CURLOPT_SSLENGINE_DEFAULT, CURLOT_LONG, 0}, - {"SSLKEY", CURLOPT_SSLKEY, CURLOT_STRING, 0}, - {"SSLKEYPASSWD", CURLOPT_KEYPASSWD, CURLOT_STRING, CURLOT_FLAG_ALIAS}, - {"SSLKEYTYPE", CURLOPT_SSLKEYTYPE, CURLOT_STRING, 0}, - {"SSLKEY_BLOB", CURLOPT_SSLKEY_BLOB, CURLOT_BLOB, 0}, - {"SSLVERSION", CURLOPT_SSLVERSION, CURLOT_VALUES, 0}, - {"SSL_CIPHER_LIST", CURLOPT_SSL_CIPHER_LIST, CURLOT_STRING, 0}, - {"SSL_CTX_DATA", CURLOPT_SSL_CTX_DATA, CURLOT_CBPTR, 0}, - {"SSL_CTX_FUNCTION", CURLOPT_SSL_CTX_FUNCTION, CURLOT_FUNCTION, 0}, - {"SSL_EC_CURVES", CURLOPT_SSL_EC_CURVES, CURLOT_STRING, 0}, - {"SSL_ENABLE_ALPN", CURLOPT_SSL_ENABLE_ALPN, CURLOT_LONG, 0}, - {"SSL_ENABLE_NPN", CURLOPT_SSL_ENABLE_NPN, CURLOT_LONG, 0}, - {"SSL_FALSESTART", CURLOPT_SSL_FALSESTART, CURLOT_LONG, 0}, - {"SSL_OPTIONS", CURLOPT_SSL_OPTIONS, CURLOT_VALUES, 0}, - {"SSL_SESSIONID_CACHE", CURLOPT_SSL_SESSIONID_CACHE, CURLOT_LONG, 0}, - {"SSL_SIGNATURE_ALGORITHMS", CURLOPT_SSL_SIGNATURE_ALGORITHMS, - CURLOT_STRING, 0}, - {"SSL_VERIFYHOST", CURLOPT_SSL_VERIFYHOST, CURLOT_LONG, 0}, - {"SSL_VERIFYPEER", CURLOPT_SSL_VERIFYPEER, CURLOT_LONG, 0}, - {"SSL_VERIFYSTATUS", CURLOPT_SSL_VERIFYSTATUS, CURLOT_LONG, 0}, - {"STDERR", CURLOPT_STDERR, CURLOT_OBJECT, 0}, - {"STREAM_DEPENDS", CURLOPT_STREAM_DEPENDS, CURLOT_OBJECT, 0}, - {"STREAM_DEPENDS_E", CURLOPT_STREAM_DEPENDS_E, CURLOT_OBJECT, 0}, - {"STREAM_WEIGHT", CURLOPT_STREAM_WEIGHT, CURLOT_LONG, 0}, - {"SUPPRESS_CONNECT_HEADERS", CURLOPT_SUPPRESS_CONNECT_HEADERS, - CURLOT_LONG, 0}, - {"TCP_FASTOPEN", CURLOPT_TCP_FASTOPEN, CURLOT_LONG, 0}, - {"TCP_KEEPALIVE", CURLOPT_TCP_KEEPALIVE, CURLOT_LONG, 0}, - {"TCP_KEEPCNT", CURLOPT_TCP_KEEPCNT, CURLOT_LONG, 0}, - {"TCP_KEEPIDLE", CURLOPT_TCP_KEEPIDLE, CURLOT_LONG, 0}, - {"TCP_KEEPINTVL", CURLOPT_TCP_KEEPINTVL, CURLOT_LONG, 0}, - {"TCP_NODELAY", CURLOPT_TCP_NODELAY, CURLOT_LONG, 0}, - {"TELNETOPTIONS", CURLOPT_TELNETOPTIONS, CURLOT_SLIST, 0}, - {"TFTP_BLKSIZE", CURLOPT_TFTP_BLKSIZE, CURLOT_LONG, 0}, - {"TFTP_NO_OPTIONS", CURLOPT_TFTP_NO_OPTIONS, CURLOT_LONG, 0}, - {"TIMECONDITION", CURLOPT_TIMECONDITION, CURLOT_VALUES, 0}, - {"TIMEOUT", CURLOPT_TIMEOUT, CURLOT_LONG, 0}, - {"TIMEOUT_MS", CURLOPT_TIMEOUT_MS, CURLOT_LONG, 0}, - {"TIMEVALUE", CURLOPT_TIMEVALUE, CURLOT_LONG, 0}, - {"TIMEVALUE_LARGE", CURLOPT_TIMEVALUE_LARGE, CURLOT_OFF_T, 0}, - {"TLS13_CIPHERS", CURLOPT_TLS13_CIPHERS, CURLOT_STRING, 0}, - {"TLSAUTH_PASSWORD", CURLOPT_TLSAUTH_PASSWORD, CURLOT_STRING, 0}, - {"TLSAUTH_TYPE", CURLOPT_TLSAUTH_TYPE, CURLOT_STRING, 0}, - {"TLSAUTH_USERNAME", CURLOPT_TLSAUTH_USERNAME, CURLOT_STRING, 0}, - {"TRAILERDATA", CURLOPT_TRAILERDATA, CURLOT_CBPTR, 0}, - {"TRAILERFUNCTION", CURLOPT_TRAILERFUNCTION, CURLOT_FUNCTION, 0}, - {"TRANSFERTEXT", CURLOPT_TRANSFERTEXT, CURLOT_LONG, 0}, - {"TRANSFER_ENCODING", CURLOPT_TRANSFER_ENCODING, CURLOT_LONG, 0}, - {"UNIX_SOCKET_PATH", CURLOPT_UNIX_SOCKET_PATH, CURLOT_STRING, 0}, - {"UNRESTRICTED_AUTH", CURLOPT_UNRESTRICTED_AUTH, CURLOT_LONG, 0}, - {"UPKEEP_INTERVAL_MS", CURLOPT_UPKEEP_INTERVAL_MS, CURLOT_LONG, 0}, - {"UPLOAD", CURLOPT_UPLOAD, CURLOT_LONG, 0}, - {"UPLOAD_BUFFERSIZE", CURLOPT_UPLOAD_BUFFERSIZE, CURLOT_LONG, 0}, - {"UPLOAD_FLAGS", CURLOPT_UPLOAD_FLAGS, CURLOT_LONG, 0}, - {"URL", CURLOPT_URL, CURLOT_STRING, 0}, - {"USERAGENT", CURLOPT_USERAGENT, CURLOT_STRING, 0}, - {"USERNAME", CURLOPT_USERNAME, CURLOT_STRING, 0}, - {"USERPWD", CURLOPT_USERPWD, CURLOT_STRING, 0}, - {"USE_SSL", CURLOPT_USE_SSL, CURLOT_VALUES, 0}, - {"VERBOSE", CURLOPT_VERBOSE, CURLOT_LONG, 0}, - {"WILDCARDMATCH", CURLOPT_WILDCARDMATCH, CURLOT_LONG, 0}, - {"WRITEDATA", CURLOPT_WRITEDATA, CURLOT_CBPTR, 0}, - {"WRITEFUNCTION", CURLOPT_WRITEFUNCTION, CURLOT_FUNCTION, 0}, - {"WRITEHEADER", CURLOPT_HEADERDATA, CURLOT_CBPTR, CURLOT_FLAG_ALIAS}, - {"WS_OPTIONS", CURLOPT_WS_OPTIONS, CURLOT_LONG, 0}, - {"XFERINFODATA", CURLOPT_XFERINFODATA, CURLOT_CBPTR, 0}, - {"XFERINFOFUNCTION", CURLOPT_XFERINFOFUNCTION, CURLOT_FUNCTION, 0}, - {"XOAUTH2_BEARER", CURLOPT_XOAUTH2_BEARER, CURLOT_STRING, 0}, - {NULL, CURLOPT_LASTENTRY, CURLOT_LONG, 0} /* end of table */ + { "ABSTRACT_UNIX_SOCKET", CURLOPT_ABSTRACT_UNIX_SOCKET, CURLOT_STRING, 0 }, + { "ACCEPTTIMEOUT_MS", CURLOPT_ACCEPTTIMEOUT_MS, CURLOT_LONG, 0 }, + { "ACCEPT_ENCODING", CURLOPT_ACCEPT_ENCODING, CURLOT_STRING, 0 }, + { "ADDRESS_SCOPE", CURLOPT_ADDRESS_SCOPE, CURLOT_LONG, 0 }, + { "ALTSVC", CURLOPT_ALTSVC, CURLOT_STRING, 0 }, + { "ALTSVC_CTRL", CURLOPT_ALTSVC_CTRL, CURLOT_LONG, 0 }, + { "APPEND", CURLOPT_APPEND, CURLOT_LONG, 0 }, + { "AUTOREFERER", CURLOPT_AUTOREFERER, CURLOT_LONG, 0 }, + { "AWS_SIGV4", CURLOPT_AWS_SIGV4, CURLOT_STRING, 0 }, + { "BUFFERSIZE", CURLOPT_BUFFERSIZE, CURLOT_LONG, 0 }, + { "CAINFO", CURLOPT_CAINFO, CURLOT_STRING, 0 }, + { "CAINFO_BLOB", CURLOPT_CAINFO_BLOB, CURLOT_BLOB, 0 }, + { "CAPATH", CURLOPT_CAPATH, CURLOT_STRING, 0 }, + { "CA_CACHE_TIMEOUT", CURLOPT_CA_CACHE_TIMEOUT, CURLOT_LONG, 0 }, + { "CERTINFO", CURLOPT_CERTINFO, CURLOT_LONG, 0 }, + { "CHUNK_BGN_FUNCTION", CURLOPT_CHUNK_BGN_FUNCTION, CURLOT_FUNCTION, 0 }, + { "CHUNK_DATA", CURLOPT_CHUNK_DATA, CURLOT_CBPTR, 0 }, + { "CHUNK_END_FUNCTION", CURLOPT_CHUNK_END_FUNCTION, CURLOT_FUNCTION, 0 }, + { "CLOSESOCKETDATA", CURLOPT_CLOSESOCKETDATA, CURLOT_CBPTR, 0 }, + { "CLOSESOCKETFUNCTION", CURLOPT_CLOSESOCKETFUNCTION, CURLOT_FUNCTION, 0 }, + { "CONNECTTIMEOUT", CURLOPT_CONNECTTIMEOUT, CURLOT_LONG, 0 }, + { "CONNECTTIMEOUT_MS", CURLOPT_CONNECTTIMEOUT_MS, CURLOT_LONG, 0 }, + { "CONNECT_ONLY", CURLOPT_CONNECT_ONLY, CURLOT_LONG, 0 }, + { "CONNECT_TO", CURLOPT_CONNECT_TO, CURLOT_SLIST, 0 }, + { "CONV_FROM_NETWORK_FUNCTION", CURLOPT_CONV_FROM_NETWORK_FUNCTION, + CURLOT_FUNCTION, 0 }, + { "CONV_FROM_UTF8_FUNCTION", CURLOPT_CONV_FROM_UTF8_FUNCTION, + CURLOT_FUNCTION, 0 }, + { "CONV_TO_NETWORK_FUNCTION", CURLOPT_CONV_TO_NETWORK_FUNCTION, + CURLOT_FUNCTION, 0 }, + { "COOKIE", CURLOPT_COOKIE, CURLOT_STRING, 0 }, + { "COOKIEFILE", CURLOPT_COOKIEFILE, CURLOT_STRING, 0 }, + { "COOKIEJAR", CURLOPT_COOKIEJAR, CURLOT_STRING, 0 }, + { "COOKIELIST", CURLOPT_COOKIELIST, CURLOT_STRING, 0 }, + { "COOKIESESSION", CURLOPT_COOKIESESSION, CURLOT_LONG, 0 }, + { "COPYPOSTFIELDS", CURLOPT_COPYPOSTFIELDS, CURLOT_OBJECT, 0 }, + { "CRLF", CURLOPT_CRLF, CURLOT_LONG, 0 }, + { "CRLFILE", CURLOPT_CRLFILE, CURLOT_STRING, 0 }, + { "CURLU", CURLOPT_CURLU, CURLOT_OBJECT, 0 }, + { "CUSTOMREQUEST", CURLOPT_CUSTOMREQUEST, CURLOT_STRING, 0 }, + { "DEBUGDATA", CURLOPT_DEBUGDATA, CURLOT_CBPTR, 0 }, + { "DEBUGFUNCTION", CURLOPT_DEBUGFUNCTION, CURLOT_FUNCTION, 0 }, + { "DEFAULT_PROTOCOL", CURLOPT_DEFAULT_PROTOCOL, CURLOT_STRING, 0 }, + { "DIRLISTONLY", CURLOPT_DIRLISTONLY, CURLOT_LONG, 0 }, + { "DISALLOW_USERNAME_IN_URL", CURLOPT_DISALLOW_USERNAME_IN_URL, + CURLOT_LONG, 0 }, + { "DNS_CACHE_TIMEOUT", CURLOPT_DNS_CACHE_TIMEOUT, CURLOT_LONG, 0 }, + { "DNS_INTERFACE", CURLOPT_DNS_INTERFACE, CURLOT_STRING, 0 }, + { "DNS_LOCAL_IP4", CURLOPT_DNS_LOCAL_IP4, CURLOT_STRING, 0 }, + { "DNS_LOCAL_IP6", CURLOPT_DNS_LOCAL_IP6, CURLOT_STRING, 0 }, + { "DNS_SERVERS", CURLOPT_DNS_SERVERS, CURLOT_STRING, 0 }, + { "DNS_SHUFFLE_ADDRESSES", CURLOPT_DNS_SHUFFLE_ADDRESSES, CURLOT_LONG, 0 }, + { "DNS_USE_GLOBAL_CACHE", CURLOPT_DNS_USE_GLOBAL_CACHE, CURLOT_LONG, 0 }, + { "DOH_SSL_VERIFYHOST", CURLOPT_DOH_SSL_VERIFYHOST, CURLOT_LONG, 0 }, + { "DOH_SSL_VERIFYPEER", CURLOPT_DOH_SSL_VERIFYPEER, CURLOT_LONG, 0 }, + { "DOH_SSL_VERIFYSTATUS", CURLOPT_DOH_SSL_VERIFYSTATUS, CURLOT_LONG, 0 }, + { "DOH_URL", CURLOPT_DOH_URL, CURLOT_STRING, 0 }, + { "ECH", CURLOPT_ECH, CURLOT_STRING, 0 }, + { "EGDSOCKET", CURLOPT_EGDSOCKET, CURLOT_STRING, 0 }, + { "ENCODING", CURLOPT_ACCEPT_ENCODING, CURLOT_STRING, CURLOT_FLAG_ALIAS }, + { "ERRORBUFFER", CURLOPT_ERRORBUFFER, CURLOT_OBJECT, 0 }, + { "EXPECT_100_TIMEOUT_MS", CURLOPT_EXPECT_100_TIMEOUT_MS, CURLOT_LONG, 0 }, + { "FAILONERROR", CURLOPT_FAILONERROR, CURLOT_LONG, 0 }, + { "FILE", CURLOPT_WRITEDATA, CURLOT_CBPTR, CURLOT_FLAG_ALIAS }, + { "FILETIME", CURLOPT_FILETIME, CURLOT_LONG, 0 }, + { "FNMATCH_DATA", CURLOPT_FNMATCH_DATA, CURLOT_CBPTR, 0 }, + { "FNMATCH_FUNCTION", CURLOPT_FNMATCH_FUNCTION, CURLOT_FUNCTION, 0 }, + { "FOLLOWLOCATION", CURLOPT_FOLLOWLOCATION, CURLOT_LONG, 0 }, + { "FORBID_REUSE", CURLOPT_FORBID_REUSE, CURLOT_LONG, 0 }, + { "FRESH_CONNECT", CURLOPT_FRESH_CONNECT, CURLOT_LONG, 0 }, + { "FTPAPPEND", CURLOPT_APPEND, CURLOT_LONG, CURLOT_FLAG_ALIAS }, + { "FTPLISTONLY", CURLOPT_DIRLISTONLY, CURLOT_LONG, CURLOT_FLAG_ALIAS }, + { "FTPPORT", CURLOPT_FTPPORT, CURLOT_STRING, 0 }, + { "FTPSSLAUTH", CURLOPT_FTPSSLAUTH, CURLOT_VALUES, 0 }, + { "FTP_ACCOUNT", CURLOPT_FTP_ACCOUNT, CURLOT_STRING, 0 }, + { "FTP_ALTERNATIVE_TO_USER", CURLOPT_FTP_ALTERNATIVE_TO_USER, + CURLOT_STRING, 0 }, + { "FTP_CREATE_MISSING_DIRS", CURLOPT_FTP_CREATE_MISSING_DIRS, + CURLOT_LONG, 0 }, + { "FTP_FILEMETHOD", CURLOPT_FTP_FILEMETHOD, CURLOT_VALUES, 0 }, + { "FTP_RESPONSE_TIMEOUT", CURLOPT_SERVER_RESPONSE_TIMEOUT, + CURLOT_LONG, CURLOT_FLAG_ALIAS }, + { "FTP_SKIP_PASV_IP", CURLOPT_FTP_SKIP_PASV_IP, CURLOT_LONG, 0 }, + { "FTP_SSL", CURLOPT_USE_SSL, CURLOT_VALUES, CURLOT_FLAG_ALIAS }, + { "FTP_SSL_CCC", CURLOPT_FTP_SSL_CCC, CURLOT_LONG, 0 }, + { "FTP_USE_EPRT", CURLOPT_FTP_USE_EPRT, CURLOT_LONG, 0 }, + { "FTP_USE_EPSV", CURLOPT_FTP_USE_EPSV, CURLOT_LONG, 0 }, + { "FTP_USE_PRET", CURLOPT_FTP_USE_PRET, CURLOT_LONG, 0 }, + { "GSSAPI_DELEGATION", CURLOPT_GSSAPI_DELEGATION, CURLOT_VALUES, 0 }, + { "HAPPY_EYEBALLS_TIMEOUT_MS", CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS, + CURLOT_LONG, 0 }, + { "HAPROXYPROTOCOL", CURLOPT_HAPROXYPROTOCOL, CURLOT_LONG, 0 }, + { "HAPROXY_CLIENT_IP", CURLOPT_HAPROXY_CLIENT_IP, CURLOT_STRING, 0 }, + { "HEADER", CURLOPT_HEADER, CURLOT_LONG, 0 }, + { "HEADERDATA", CURLOPT_HEADERDATA, CURLOT_CBPTR, 0 }, + { "HEADERFUNCTION", CURLOPT_HEADERFUNCTION, CURLOT_FUNCTION, 0 }, + { "HEADEROPT", CURLOPT_HEADEROPT, CURLOT_VALUES, 0 }, + { "HSTS", CURLOPT_HSTS, CURLOT_STRING, 0 }, + { "HSTSREADDATA", CURLOPT_HSTSREADDATA, CURLOT_CBPTR, 0 }, + { "HSTSREADFUNCTION", CURLOPT_HSTSREADFUNCTION, CURLOT_FUNCTION, 0 }, + { "HSTSWRITEDATA", CURLOPT_HSTSWRITEDATA, CURLOT_CBPTR, 0 }, + { "HSTSWRITEFUNCTION", CURLOPT_HSTSWRITEFUNCTION, CURLOT_FUNCTION, 0 }, + { "HSTS_CTRL", CURLOPT_HSTS_CTRL, CURLOT_LONG, 0 }, + { "HTTP09_ALLOWED", CURLOPT_HTTP09_ALLOWED, CURLOT_LONG, 0 }, + { "HTTP200ALIASES", CURLOPT_HTTP200ALIASES, CURLOT_SLIST, 0 }, + { "HTTPAUTH", CURLOPT_HTTPAUTH, CURLOT_VALUES, 0 }, + { "HTTPGET", CURLOPT_HTTPGET, CURLOT_LONG, 0 }, + { "HTTPHEADER", CURLOPT_HTTPHEADER, CURLOT_SLIST, 0 }, + { "HTTPPOST", CURLOPT_HTTPPOST, CURLOT_OBJECT, 0 }, + { "HTTPPROXYTUNNEL", CURLOPT_HTTPPROXYTUNNEL, CURLOT_LONG, 0 }, + { "HTTP_CONTENT_DECODING", CURLOPT_HTTP_CONTENT_DECODING, CURLOT_LONG, 0 }, + { "HTTP_TRANSFER_DECODING", CURLOPT_HTTP_TRANSFER_DECODING, + CURLOT_LONG, 0 }, + { "HTTP_VERSION", CURLOPT_HTTP_VERSION, CURLOT_VALUES, 0 }, + { "IGNORE_CONTENT_LENGTH", CURLOPT_IGNORE_CONTENT_LENGTH, CURLOT_LONG, 0 }, + { "INFILE", CURLOPT_READDATA, CURLOT_CBPTR, CURLOT_FLAG_ALIAS }, + { "INFILESIZE", CURLOPT_INFILESIZE, CURLOT_LONG, 0 }, + { "INFILESIZE_LARGE", CURLOPT_INFILESIZE_LARGE, CURLOT_OFF_T, 0 }, + { "INTERFACE", CURLOPT_INTERFACE, CURLOT_STRING, 0 }, + { "INTERLEAVEDATA", CURLOPT_INTERLEAVEDATA, CURLOT_CBPTR, 0 }, + { "INTERLEAVEFUNCTION", CURLOPT_INTERLEAVEFUNCTION, CURLOT_FUNCTION, 0 }, + { "IOCTLDATA", CURLOPT_IOCTLDATA, CURLOT_CBPTR, 0 }, + { "IOCTLFUNCTION", CURLOPT_IOCTLFUNCTION, CURLOT_FUNCTION, 0 }, + { "IPRESOLVE", CURLOPT_IPRESOLVE, CURLOT_VALUES, 0 }, + { "ISSUERCERT", CURLOPT_ISSUERCERT, CURLOT_STRING, 0 }, + { "ISSUERCERT_BLOB", CURLOPT_ISSUERCERT_BLOB, CURLOT_BLOB, 0 }, + { "KEEP_SENDING_ON_ERROR", CURLOPT_KEEP_SENDING_ON_ERROR, CURLOT_LONG, 0 }, + { "KEYPASSWD", CURLOPT_KEYPASSWD, CURLOT_STRING, 0 }, + { "KRB4LEVEL", CURLOPT_KRBLEVEL, CURLOT_STRING, CURLOT_FLAG_ALIAS }, + { "KRBLEVEL", CURLOPT_KRBLEVEL, CURLOT_STRING, 0 }, + { "LOCALPORT", CURLOPT_LOCALPORT, CURLOT_LONG, 0 }, + { "LOCALPORTRANGE", CURLOPT_LOCALPORTRANGE, CURLOT_LONG, 0 }, + { "LOGIN_OPTIONS", CURLOPT_LOGIN_OPTIONS, CURLOT_STRING, 0 }, + { "LOW_SPEED_LIMIT", CURLOPT_LOW_SPEED_LIMIT, CURLOT_LONG, 0 }, + { "LOW_SPEED_TIME", CURLOPT_LOW_SPEED_TIME, CURLOT_LONG, 0 }, + { "MAIL_AUTH", CURLOPT_MAIL_AUTH, CURLOT_STRING, 0 }, + { "MAIL_FROM", CURLOPT_MAIL_FROM, CURLOT_STRING, 0 }, + { "MAIL_RCPT", CURLOPT_MAIL_RCPT, CURLOT_SLIST, 0 }, + { "MAIL_RCPT_ALLLOWFAILS", CURLOPT_MAIL_RCPT_ALLOWFAILS, + CURLOT_LONG, CURLOT_FLAG_ALIAS }, + { "MAIL_RCPT_ALLOWFAILS", CURLOPT_MAIL_RCPT_ALLOWFAILS, CURLOT_LONG, 0 }, + { "MAXAGE_CONN", CURLOPT_MAXAGE_CONN, CURLOT_LONG, 0 }, + { "MAXCONNECTS", CURLOPT_MAXCONNECTS, CURLOT_LONG, 0 }, + { "MAXFILESIZE", CURLOPT_MAXFILESIZE, CURLOT_LONG, 0 }, + { "MAXFILESIZE_LARGE", CURLOPT_MAXFILESIZE_LARGE, CURLOT_OFF_T, 0 }, + { "MAXLIFETIME_CONN", CURLOPT_MAXLIFETIME_CONN, CURLOT_LONG, 0 }, + { "MAXREDIRS", CURLOPT_MAXREDIRS, CURLOT_LONG, 0 }, + { "MAX_RECV_SPEED_LARGE", CURLOPT_MAX_RECV_SPEED_LARGE, CURLOT_OFF_T, 0 }, + { "MAX_SEND_SPEED_LARGE", CURLOPT_MAX_SEND_SPEED_LARGE, CURLOT_OFF_T, 0 }, + { "MIMEPOST", CURLOPT_MIMEPOST, CURLOT_OBJECT, 0 }, + { "MIME_OPTIONS", CURLOPT_MIME_OPTIONS, CURLOT_LONG, 0 }, + { "NETRC", CURLOPT_NETRC, CURLOT_VALUES, 0 }, + { "NETRC_FILE", CURLOPT_NETRC_FILE, CURLOT_STRING, 0 }, + { "NEW_DIRECTORY_PERMS", CURLOPT_NEW_DIRECTORY_PERMS, CURLOT_LONG, 0 }, + { "NEW_FILE_PERMS", CURLOPT_NEW_FILE_PERMS, CURLOT_LONG, 0 }, + { "NOBODY", CURLOPT_NOBODY, CURLOT_LONG, 0 }, + { "NOPROGRESS", CURLOPT_NOPROGRESS, CURLOT_LONG, 0 }, + { "NOPROXY", CURLOPT_NOPROXY, CURLOT_STRING, 0 }, + { "NOSIGNAL", CURLOPT_NOSIGNAL, CURLOT_LONG, 0 }, + { "OPENSOCKETDATA", CURLOPT_OPENSOCKETDATA, CURLOT_CBPTR, 0 }, + { "OPENSOCKETFUNCTION", CURLOPT_OPENSOCKETFUNCTION, CURLOT_FUNCTION, 0 }, + { "PASSWORD", CURLOPT_PASSWORD, CURLOT_STRING, 0 }, + { "PATH_AS_IS", CURLOPT_PATH_AS_IS, CURLOT_LONG, 0 }, + { "PINNEDPUBLICKEY", CURLOPT_PINNEDPUBLICKEY, CURLOT_STRING, 0 }, + { "PIPEWAIT", CURLOPT_PIPEWAIT, CURLOT_LONG, 0 }, + { "PORT", CURLOPT_PORT, CURLOT_LONG, 0 }, + { "POST", CURLOPT_POST, CURLOT_LONG, 0 }, + { "POST301", CURLOPT_POSTREDIR, CURLOT_VALUES, CURLOT_FLAG_ALIAS }, + { "POSTFIELDS", CURLOPT_POSTFIELDS, CURLOT_OBJECT, 0 }, + { "POSTFIELDSIZE", CURLOPT_POSTFIELDSIZE, CURLOT_LONG, 0 }, + { "POSTFIELDSIZE_LARGE", CURLOPT_POSTFIELDSIZE_LARGE, CURLOT_OFF_T, 0 }, + { "POSTQUOTE", CURLOPT_POSTQUOTE, CURLOT_SLIST, 0 }, + { "POSTREDIR", CURLOPT_POSTREDIR, CURLOT_VALUES, 0 }, + { "PREQUOTE", CURLOPT_PREQUOTE, CURLOT_SLIST, 0 }, + { "PREREQDATA", CURLOPT_PREREQDATA, CURLOT_CBPTR, 0 }, + { "PREREQFUNCTION", CURLOPT_PREREQFUNCTION, CURLOT_FUNCTION, 0 }, + { "PRE_PROXY", CURLOPT_PRE_PROXY, CURLOT_STRING, 0 }, + { "PRIVATE", CURLOPT_PRIVATE, CURLOT_OBJECT, 0 }, + { "PROGRESSDATA", CURLOPT_XFERINFODATA, CURLOT_CBPTR, CURLOT_FLAG_ALIAS }, + { "PROGRESSFUNCTION", CURLOPT_PROGRESSFUNCTION, CURLOT_FUNCTION, 0 }, + { "PROTOCOLS", CURLOPT_PROTOCOLS, CURLOT_LONG, 0 }, + { "PROTOCOLS_STR", CURLOPT_PROTOCOLS_STR, CURLOT_STRING, 0 }, + { "PROXY", CURLOPT_PROXY, CURLOT_STRING, 0 }, + { "PROXYAUTH", CURLOPT_PROXYAUTH, CURLOT_VALUES, 0 }, + { "PROXYHEADER", CURLOPT_PROXYHEADER, CURLOT_SLIST, 0 }, + { "PROXYPASSWORD", CURLOPT_PROXYPASSWORD, CURLOT_STRING, 0 }, + { "PROXYPORT", CURLOPT_PROXYPORT, CURLOT_LONG, 0 }, + { "PROXYTYPE", CURLOPT_PROXYTYPE, CURLOT_VALUES, 0 }, + { "PROXYUSERNAME", CURLOPT_PROXYUSERNAME, CURLOT_STRING, 0 }, + { "PROXYUSERPWD", CURLOPT_PROXYUSERPWD, CURLOT_STRING, 0 }, + { "PROXY_CAINFO", CURLOPT_PROXY_CAINFO, CURLOT_STRING, 0 }, + { "PROXY_CAINFO_BLOB", CURLOPT_PROXY_CAINFO_BLOB, CURLOT_BLOB, 0 }, + { "PROXY_CAPATH", CURLOPT_PROXY_CAPATH, CURLOT_STRING, 0 }, + { "PROXY_CRLFILE", CURLOPT_PROXY_CRLFILE, CURLOT_STRING, 0 }, + { "PROXY_ISSUERCERT", CURLOPT_PROXY_ISSUERCERT, CURLOT_STRING, 0 }, + { "PROXY_ISSUERCERT_BLOB", CURLOPT_PROXY_ISSUERCERT_BLOB, CURLOT_BLOB, 0 }, + { "PROXY_KEYPASSWD", CURLOPT_PROXY_KEYPASSWD, CURLOT_STRING, 0 }, + { "PROXY_PINNEDPUBLICKEY", CURLOPT_PROXY_PINNEDPUBLICKEY, + CURLOT_STRING, 0 }, + { "PROXY_SERVICE_NAME", CURLOPT_PROXY_SERVICE_NAME, CURLOT_STRING, 0 }, + { "PROXY_SSLCERT", CURLOPT_PROXY_SSLCERT, CURLOT_STRING, 0 }, + { "PROXY_SSLCERTTYPE", CURLOPT_PROXY_SSLCERTTYPE, CURLOT_STRING, 0 }, + { "PROXY_SSLCERT_BLOB", CURLOPT_PROXY_SSLCERT_BLOB, CURLOT_BLOB, 0 }, + { "PROXY_SSLKEY", CURLOPT_PROXY_SSLKEY, CURLOT_STRING, 0 }, + { "PROXY_SSLKEYTYPE", CURLOPT_PROXY_SSLKEYTYPE, CURLOT_STRING, 0 }, + { "PROXY_SSLKEY_BLOB", CURLOPT_PROXY_SSLKEY_BLOB, CURLOT_BLOB, 0 }, + { "PROXY_SSLVERSION", CURLOPT_PROXY_SSLVERSION, CURLOT_VALUES, 0 }, + { "PROXY_SSL_CIPHER_LIST", CURLOPT_PROXY_SSL_CIPHER_LIST, + CURLOT_STRING, 0 }, + { "PROXY_SSL_OPTIONS", CURLOPT_PROXY_SSL_OPTIONS, CURLOT_LONG, 0 }, + { "PROXY_SSL_VERIFYHOST", CURLOPT_PROXY_SSL_VERIFYHOST, CURLOT_LONG, 0 }, + { "PROXY_SSL_VERIFYPEER", CURLOPT_PROXY_SSL_VERIFYPEER, CURLOT_LONG, 0 }, + { "PROXY_TLS13_CIPHERS", CURLOPT_PROXY_TLS13_CIPHERS, CURLOT_STRING, 0 }, + { "PROXY_TLSAUTH_PASSWORD", CURLOPT_PROXY_TLSAUTH_PASSWORD, + CURLOT_STRING, 0 }, + { "PROXY_TLSAUTH_TYPE", CURLOPT_PROXY_TLSAUTH_TYPE, CURLOT_STRING, 0 }, + { "PROXY_TLSAUTH_USERNAME", CURLOPT_PROXY_TLSAUTH_USERNAME, + CURLOT_STRING, 0 }, + { "PROXY_TRANSFER_MODE", CURLOPT_PROXY_TRANSFER_MODE, CURLOT_LONG, 0 }, + { "PUT", CURLOPT_PUT, CURLOT_LONG, 0 }, + { "QUICK_EXIT", CURLOPT_QUICK_EXIT, CURLOT_LONG, 0 }, + { "QUOTE", CURLOPT_QUOTE, CURLOT_SLIST, 0 }, + { "RANDOM_FILE", CURLOPT_RANDOM_FILE, CURLOT_STRING, 0 }, + { "RANGE", CURLOPT_RANGE, CURLOT_STRING, 0 }, + { "READDATA", CURLOPT_READDATA, CURLOT_CBPTR, 0 }, + { "READFUNCTION", CURLOPT_READFUNCTION, CURLOT_FUNCTION, 0 }, + { "REDIR_PROTOCOLS", CURLOPT_REDIR_PROTOCOLS, CURLOT_LONG, 0 }, + { "REDIR_PROTOCOLS_STR", CURLOPT_REDIR_PROTOCOLS_STR, CURLOT_STRING, 0 }, + { "REFERER", CURLOPT_REFERER, CURLOT_STRING, 0 }, + { "REQUEST_TARGET", CURLOPT_REQUEST_TARGET, CURLOT_STRING, 0 }, + { "RESOLVE", CURLOPT_RESOLVE, CURLOT_SLIST, 0 }, + { "RESOLVER_START_DATA", CURLOPT_RESOLVER_START_DATA, CURLOT_CBPTR, 0 }, + { "RESOLVER_START_FUNCTION", CURLOPT_RESOLVER_START_FUNCTION, + CURLOT_FUNCTION, 0 }, + { "RESUME_FROM", CURLOPT_RESUME_FROM, CURLOT_LONG, 0 }, + { "RESUME_FROM_LARGE", CURLOPT_RESUME_FROM_LARGE, CURLOT_OFF_T, 0 }, + { "RTSPHEADER", CURLOPT_HTTPHEADER, CURLOT_SLIST, CURLOT_FLAG_ALIAS }, + { "RTSP_CLIENT_CSEQ", CURLOPT_RTSP_CLIENT_CSEQ, CURLOT_LONG, 0 }, + { "RTSP_REQUEST", CURLOPT_RTSP_REQUEST, CURLOT_VALUES, 0 }, + { "RTSP_SERVER_CSEQ", CURLOPT_RTSP_SERVER_CSEQ, CURLOT_LONG, 0 }, + { "RTSP_SESSION_ID", CURLOPT_RTSP_SESSION_ID, CURLOT_STRING, 0 }, + { "RTSP_STREAM_URI", CURLOPT_RTSP_STREAM_URI, CURLOT_STRING, 0 }, + { "RTSP_TRANSPORT", CURLOPT_RTSP_TRANSPORT, CURLOT_STRING, 0 }, + { "SASL_AUTHZID", CURLOPT_SASL_AUTHZID, CURLOT_STRING, 0 }, + { "SASL_IR", CURLOPT_SASL_IR, CURLOT_LONG, 0 }, + { "SEEKDATA", CURLOPT_SEEKDATA, CURLOT_CBPTR, 0 }, + { "SEEKFUNCTION", CURLOPT_SEEKFUNCTION, CURLOT_FUNCTION, 0 }, + { "SERVER_RESPONSE_TIMEOUT", CURLOPT_SERVER_RESPONSE_TIMEOUT, + CURLOT_LONG, 0 }, + { "SERVER_RESPONSE_TIMEOUT_MS", CURLOPT_SERVER_RESPONSE_TIMEOUT_MS, + CURLOT_LONG, 0 }, + { "SERVICE_NAME", CURLOPT_SERVICE_NAME, CURLOT_STRING, 0 }, + { "SHARE", CURLOPT_SHARE, CURLOT_OBJECT, 0 }, + { "SOCKOPTDATA", CURLOPT_SOCKOPTDATA, CURLOT_CBPTR, 0 }, + { "SOCKOPTFUNCTION", CURLOPT_SOCKOPTFUNCTION, CURLOT_FUNCTION, 0 }, + { "SOCKS5_AUTH", CURLOPT_SOCKS5_AUTH, CURLOT_LONG, 0 }, + { "SOCKS5_GSSAPI_NEC", CURLOPT_SOCKS5_GSSAPI_NEC, CURLOT_LONG, 0 }, + { "SOCKS5_GSSAPI_SERVICE", CURLOPT_SOCKS5_GSSAPI_SERVICE, + CURLOT_STRING, 0 }, + { "SSH_AUTH_TYPES", CURLOPT_SSH_AUTH_TYPES, CURLOT_VALUES, 0 }, + { "SSH_COMPRESSION", CURLOPT_SSH_COMPRESSION, CURLOT_LONG, 0 }, + { "SSH_HOSTKEYDATA", CURLOPT_SSH_HOSTKEYDATA, CURLOT_CBPTR, 0 }, + { "SSH_HOSTKEYFUNCTION", CURLOPT_SSH_HOSTKEYFUNCTION, CURLOT_FUNCTION, 0 }, + { "SSH_HOST_PUBLIC_KEY_MD5", CURLOPT_SSH_HOST_PUBLIC_KEY_MD5, + CURLOT_STRING, 0 }, + { "SSH_HOST_PUBLIC_KEY_SHA256", CURLOPT_SSH_HOST_PUBLIC_KEY_SHA256, + CURLOT_STRING, 0 }, + { "SSH_KEYDATA", CURLOPT_SSH_KEYDATA, CURLOT_CBPTR, 0 }, + { "SSH_KEYFUNCTION", CURLOPT_SSH_KEYFUNCTION, CURLOT_FUNCTION, 0 }, + { "SSH_KNOWNHOSTS", CURLOPT_SSH_KNOWNHOSTS, CURLOT_STRING, 0 }, + { "SSH_PRIVATE_KEYFILE", CURLOPT_SSH_PRIVATE_KEYFILE, CURLOT_STRING, 0 }, + { "SSH_PUBLIC_KEYFILE", CURLOPT_SSH_PUBLIC_KEYFILE, CURLOT_STRING, 0 }, + { "SSLCERT", CURLOPT_SSLCERT, CURLOT_STRING, 0 }, + { "SSLCERTPASSWD", CURLOPT_KEYPASSWD, CURLOT_STRING, CURLOT_FLAG_ALIAS }, + { "SSLCERTTYPE", CURLOPT_SSLCERTTYPE, CURLOT_STRING, 0 }, + { "SSLCERT_BLOB", CURLOPT_SSLCERT_BLOB, CURLOT_BLOB, 0 }, + { "SSLENGINE", CURLOPT_SSLENGINE, CURLOT_STRING, 0 }, + { "SSLENGINE_DEFAULT", CURLOPT_SSLENGINE_DEFAULT, CURLOT_LONG, 0 }, + { "SSLKEY", CURLOPT_SSLKEY, CURLOT_STRING, 0 }, + { "SSLKEYPASSWD", CURLOPT_KEYPASSWD, CURLOT_STRING, CURLOT_FLAG_ALIAS }, + { "SSLKEYTYPE", CURLOPT_SSLKEYTYPE, CURLOT_STRING, 0 }, + { "SSLKEY_BLOB", CURLOPT_SSLKEY_BLOB, CURLOT_BLOB, 0 }, + { "SSLVERSION", CURLOPT_SSLVERSION, CURLOT_VALUES, 0 }, + { "SSL_CIPHER_LIST", CURLOPT_SSL_CIPHER_LIST, CURLOT_STRING, 0 }, + { "SSL_CTX_DATA", CURLOPT_SSL_CTX_DATA, CURLOT_CBPTR, 0 }, + { "SSL_CTX_FUNCTION", CURLOPT_SSL_CTX_FUNCTION, CURLOT_FUNCTION, 0 }, + { "SSL_EC_CURVES", CURLOPT_SSL_EC_CURVES, CURLOT_STRING, 0 }, + { "SSL_ENABLE_ALPN", CURLOPT_SSL_ENABLE_ALPN, CURLOT_LONG, 0 }, + { "SSL_ENABLE_NPN", CURLOPT_SSL_ENABLE_NPN, CURLOT_LONG, 0 }, + { "SSL_FALSESTART", CURLOPT_SSL_FALSESTART, CURLOT_LONG, 0 }, + { "SSL_OPTIONS", CURLOPT_SSL_OPTIONS, CURLOT_VALUES, 0 }, + { "SSL_SESSIONID_CACHE", CURLOPT_SSL_SESSIONID_CACHE, CURLOT_LONG, 0 }, + { "SSL_SIGNATURE_ALGORITHMS", CURLOPT_SSL_SIGNATURE_ALGORITHMS, + CURLOT_STRING, 0 }, + { "SSL_VERIFYHOST", CURLOPT_SSL_VERIFYHOST, CURLOT_LONG, 0 }, + { "SSL_VERIFYPEER", CURLOPT_SSL_VERIFYPEER, CURLOT_LONG, 0 }, + { "SSL_VERIFYSTATUS", CURLOPT_SSL_VERIFYSTATUS, CURLOT_LONG, 0 }, + { "STDERR", CURLOPT_STDERR, CURLOT_OBJECT, 0 }, + { "STREAM_DEPENDS", CURLOPT_STREAM_DEPENDS, CURLOT_OBJECT, 0 }, + { "STREAM_DEPENDS_E", CURLOPT_STREAM_DEPENDS_E, CURLOT_OBJECT, 0 }, + { "STREAM_WEIGHT", CURLOPT_STREAM_WEIGHT, CURLOT_LONG, 0 }, + { "SUPPRESS_CONNECT_HEADERS", CURLOPT_SUPPRESS_CONNECT_HEADERS, + CURLOT_LONG, 0 }, + { "TCP_FASTOPEN", CURLOPT_TCP_FASTOPEN, CURLOT_LONG, 0 }, + { "TCP_KEEPALIVE", CURLOPT_TCP_KEEPALIVE, CURLOT_LONG, 0 }, + { "TCP_KEEPCNT", CURLOPT_TCP_KEEPCNT, CURLOT_LONG, 0 }, + { "TCP_KEEPIDLE", CURLOPT_TCP_KEEPIDLE, CURLOT_LONG, 0 }, + { "TCP_KEEPINTVL", CURLOPT_TCP_KEEPINTVL, CURLOT_LONG, 0 }, + { "TCP_NODELAY", CURLOPT_TCP_NODELAY, CURLOT_LONG, 0 }, + { "TELNETOPTIONS", CURLOPT_TELNETOPTIONS, CURLOT_SLIST, 0 }, + { "TFTP_BLKSIZE", CURLOPT_TFTP_BLKSIZE, CURLOT_LONG, 0 }, + { "TFTP_NO_OPTIONS", CURLOPT_TFTP_NO_OPTIONS, CURLOT_LONG, 0 }, + { "TIMECONDITION", CURLOPT_TIMECONDITION, CURLOT_VALUES, 0 }, + { "TIMEOUT", CURLOPT_TIMEOUT, CURLOT_LONG, 0 }, + { "TIMEOUT_MS", CURLOPT_TIMEOUT_MS, CURLOT_LONG, 0 }, + { "TIMEVALUE", CURLOPT_TIMEVALUE, CURLOT_LONG, 0 }, + { "TIMEVALUE_LARGE", CURLOPT_TIMEVALUE_LARGE, CURLOT_OFF_T, 0 }, + { "TLS13_CIPHERS", CURLOPT_TLS13_CIPHERS, CURLOT_STRING, 0 }, + { "TLSAUTH_PASSWORD", CURLOPT_TLSAUTH_PASSWORD, CURLOT_STRING, 0 }, + { "TLSAUTH_TYPE", CURLOPT_TLSAUTH_TYPE, CURLOT_STRING, 0 }, + { "TLSAUTH_USERNAME", CURLOPT_TLSAUTH_USERNAME, CURLOT_STRING, 0 }, + { "TRAILERDATA", CURLOPT_TRAILERDATA, CURLOT_CBPTR, 0 }, + { "TRAILERFUNCTION", CURLOPT_TRAILERFUNCTION, CURLOT_FUNCTION, 0 }, + { "TRANSFERTEXT", CURLOPT_TRANSFERTEXT, CURLOT_LONG, 0 }, + { "TRANSFER_ENCODING", CURLOPT_TRANSFER_ENCODING, CURLOT_LONG, 0 }, + { "UNIX_SOCKET_PATH", CURLOPT_UNIX_SOCKET_PATH, CURLOT_STRING, 0 }, + { "UNRESTRICTED_AUTH", CURLOPT_UNRESTRICTED_AUTH, CURLOT_LONG, 0 }, + { "UPKEEP_INTERVAL_MS", CURLOPT_UPKEEP_INTERVAL_MS, CURLOT_LONG, 0 }, + { "UPLOAD", CURLOPT_UPLOAD, CURLOT_LONG, 0 }, + { "UPLOAD_BUFFERSIZE", CURLOPT_UPLOAD_BUFFERSIZE, CURLOT_LONG, 0 }, + { "UPLOAD_FLAGS", CURLOPT_UPLOAD_FLAGS, CURLOT_LONG, 0 }, + { "URL", CURLOPT_URL, CURLOT_STRING, 0 }, + { "USERAGENT", CURLOPT_USERAGENT, CURLOT_STRING, 0 }, + { "USERNAME", CURLOPT_USERNAME, CURLOT_STRING, 0 }, + { "USERPWD", CURLOPT_USERPWD, CURLOT_STRING, 0 }, + { "USE_SSL", CURLOPT_USE_SSL, CURLOT_VALUES, 0 }, + { "VERBOSE", CURLOPT_VERBOSE, CURLOT_LONG, 0 }, + { "WILDCARDMATCH", CURLOPT_WILDCARDMATCH, CURLOT_LONG, 0 }, + { "WRITEDATA", CURLOPT_WRITEDATA, CURLOT_CBPTR, 0 }, + { "WRITEFUNCTION", CURLOPT_WRITEFUNCTION, CURLOT_FUNCTION, 0 }, + { "WRITEHEADER", CURLOPT_HEADERDATA, CURLOT_CBPTR, CURLOT_FLAG_ALIAS }, + { "WS_OPTIONS", CURLOPT_WS_OPTIONS, CURLOT_LONG, 0 }, + { "XFERINFODATA", CURLOPT_XFERINFODATA, CURLOT_CBPTR, 0 }, + { "XFERINFOFUNCTION", CURLOPT_XFERINFOFUNCTION, CURLOT_FUNCTION, 0 }, + { "XOAUTH2_BEARER", CURLOPT_XOAUTH2_BEARER, CURLOT_STRING, 0 }, + { NULL, CURLOPT_LASTENTRY, CURLOT_LONG, 0 } /* end of table */ }; #ifdef DEBUGBUILD diff --git a/vendor/hydra/vendor/curl/lib/easyoptions.h b/vendor/hydra/vendor/curl/lib/easyoptions.h index 44b6a828..d895653c 100644 --- a/vendor/hydra/vendor/curl/lib/easyoptions.h +++ b/vendor/hydra/vendor/curl/lib/easyoptions.h @@ -23,15 +23,13 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - /* should probably go into the public header */ -#include - /* generated table with all easy options */ extern const struct curl_easyoption Curl_easyopts[]; #ifdef DEBUGBUILD int Curl_easyopts_check(void); #endif -#endif + +#endif /* HEADER_CURL_EASYOPTIONS_H */ diff --git a/vendor/hydra/vendor/curl/lib/escape.c b/vendor/hydra/vendor/curl/lib/escape.c index 2064f4d0..afdf18c1 100644 --- a/vendor/hydra/vendor/curl/lib/escape.c +++ b/vendor/hydra/vendor/curl/lib/escape.c @@ -21,26 +21,17 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - /* Escape and unescape URL encoding in strings. The functions return a new - * allocated string or NULL if an error occurred. */ - + * allocated string or NULL if an error occurred. */ #include "curl_setup.h" -#include - struct Curl_easy; #include "urldata.h" -#include "curlx/warnless.h" #include "escape.h" #include "curlx/strparse.h" #include "curl_printf.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* for ABI-compatibility with previous versions */ char *curl_escape(const char *string, int inlength) { @@ -56,8 +47,7 @@ char *curl_unescape(const char *string, int length) /* Escapes for URL the given unescaped string of given length. * 'data' is ignored since 7.82.0. */ -char *curl_easy_escape(CURL *data, const char *string, - int inlength) +char *curl_easy_escape(CURL *data, const char *string, int inlength) { size_t length; struct dynbuf d; @@ -68,7 +58,10 @@ char *curl_easy_escape(CURL *data, const char *string, length = (inlength ? (size_t)inlength : strlen(string)); if(!length) - return strdup(""); + return curlx_strdup(""); + + if(length > SIZE_MAX / 16) + return NULL; curlx_dyn_init(&d, length * 3 + 1); @@ -83,7 +76,7 @@ char *curl_easy_escape(CURL *data, const char *string, } else { /* encode it */ - unsigned char out[3]={'%'}; + unsigned char out[3] = { '%' }; Curl_hexbyte(&out[1], in); if(curlx_dyn_addn(&d, out, 3)) return NULL; @@ -120,7 +113,7 @@ CURLcode Curl_urldecode(const char *string, size_t length, DEBUGASSERT(ctrl >= REJECT_NADA); /* crash on TRUE/FALSE */ alloc = (length ? length : strlen(string)); - ns = malloc(alloc + 1); + ns = curlx_malloc(alloc + 1); if(!ns) return CURLE_OUT_OF_MEMORY; @@ -133,8 +126,8 @@ CURLcode Curl_urldecode(const char *string, size_t length, if(('%' == in) && (alloc > 2) && ISXDIGIT(string[1]) && ISXDIGIT(string[2])) { /* this is two hexadecimal digits following a '%' */ - in = (unsigned char)((Curl_hexval(string[1]) << 4) | - Curl_hexval(string[2])); + in = (unsigned char)((curlx_hexval(string[1]) << 4) | + curlx_hexval(string[2])); string += 3; alloc -= 3; } @@ -167,8 +160,7 @@ CURLcode Curl_urldecode(const char *string, size_t length, * If olen == NULL, no output length is stored. * 'data' is ignored since 7.82.0. */ -char *curl_easy_unescape(CURL *data, const char *string, - int length, int *olen) +char *curl_easy_unescape(CURL *data, const char *string, int length, int *olen) { char *str = NULL; (void)data; @@ -181,7 +173,7 @@ char *curl_easy_unescape(CURL *data, const char *string, return NULL; if(olen) { - if(outputlen <= (size_t) INT_MAX) + if(outputlen <= (size_t)INT_MAX) *olen = curlx_uztosi(outputlen); else /* too large to return in an int, fail! */ @@ -196,7 +188,7 @@ char *curl_easy_unescape(CURL *data, const char *string, the library's memory system */ void curl_free(void *p) { - free(p); + curlx_free(p); } /* diff --git a/vendor/hydra/vendor/curl/lib/escape.h b/vendor/hydra/vendor/curl/lib/escape.h index a43fc38e..2ea06c44 100644 --- a/vendor/hydra/vendor/curl/lib/escape.h +++ b/vendor/hydra/vendor/curl/lib/escape.h @@ -26,8 +26,6 @@ /* Escape and unescape URL encoding in strings. The functions return a new * allocated string or NULL if an error occurred. */ -#include "curl_ctype.h" - enum urlreject { REJECT_NADA = 2, REJECT_CTRL, diff --git a/vendor/hydra/vendor/curl/lib/fake_addrinfo.c b/vendor/hydra/vendor/curl/lib/fake_addrinfo.c index 80edf786..bf5a4489 100644 --- a/vendor/hydra/vendor/curl/lib/fake_addrinfo.c +++ b/vendor/hydra/vendor/curl/lib/fake_addrinfo.c @@ -21,20 +21,14 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" + #include "fake_addrinfo.h" #ifdef USE_FAKE_GETADDRINFO -#include -#include #include -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - void r_freeaddrinfo(struct addrinfo *cahead) { struct addrinfo *canext; @@ -42,7 +36,7 @@ void r_freeaddrinfo(struct addrinfo *cahead) for(ca = cahead; ca; ca = canext) { canext = ca->ai_next; - free(ca); + curlx_free(ca); } } @@ -90,7 +84,7 @@ static struct addrinfo *mk_getaddrinfo(const struct ares_addrinfo *aihead) if((size_t)ai->ai_addrlen < ss_size) continue; - ca = malloc(sizeof(struct addrinfo) + ss_size + namelen); + ca = curlx_malloc(sizeof(struct addrinfo) + ss_size + namelen); if(!ca) { r_freeaddrinfo(cafirst); return NULL; @@ -180,13 +174,12 @@ int r_getaddrinfo(const char *node, curl_mfprintf(stderr, "ares_set_servers_ports_csv failed: %d", rc); /* Cleanup */ ares_destroy(channel); - return EAI_MEMORY; /* we can't run */ + return EAI_MEMORY; /* we cannot run */ } } } - ares_getaddrinfo(channel, node, service, &ahints, - async_addrinfo_cb, &ctx); + ares_getaddrinfo(channel, node, service, &ahints, async_addrinfo_cb, &ctx); /* Wait until no more requests are left to be processed */ ares_queue_wait_empty(channel, -1); diff --git a/vendor/hydra/vendor/curl/lib/fake_addrinfo.h b/vendor/hydra/vendor/curl/lib/fake_addrinfo.h index 13b0d71d..db701be4 100644 --- a/vendor/hydra/vendor/curl/lib/fake_addrinfo.h +++ b/vendor/hydra/vendor/curl/lib/fake_addrinfo.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifdef USE_ARES @@ -31,7 +30,7 @@ #endif #if defined(CURLDEBUG) && defined(USE_ARES) && defined(HAVE_GETADDRINFO) && \ - (ARES_VERSION >= 0x011a00) /* >= 1.26. 0 */ + (ARES_VERSION >= 0x011a00) /* >= 1.26.0 */ #define USE_FAKE_GETADDRINFO 1 #endif diff --git a/vendor/hydra/vendor/curl/lib/file.c b/vendor/hydra/vendor/curl/lib/file.c index f45a487c..982f254b 100644 --- a/vendor/hydra/vendor/curl/lib/file.c +++ b/vendor/hydra/vendor/curl/lib/file.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifndef CURL_DISABLE_FILE @@ -55,24 +54,18 @@ #endif #include "urldata.h" -#include #include "progress.h" #include "sendf.h" +#include "curl_trc.h" #include "escape.h" #include "file.h" -#include "speedcheck.h" #include "multiif.h" #include "transfer.h" #include "url.h" #include "parsedate.h" /* for the week day and month names */ #include "curlx/fopen.h" -#include "curlx/warnless.h" #include "curl_range.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #if defined(_WIN32) || defined(MSDOS) #define DOS_FILESYSTEM 1 #elif defined(__amigaos4__) @@ -132,7 +125,6 @@ const struct Curl_handler Curl_handler_file = { PROTOPT_NONETWORK | PROTOPT_NOURLQUERY /* flags */ }; - static void file_cleanup(struct FILEPROTO *file) { Curl_safefree(file->freepath); @@ -149,7 +141,7 @@ static void file_easy_dtor(void *key, size_t klen, void *entry) (void)key; (void)klen; file_cleanup(file); - free(file); + curlx_free(file); } static CURLcode file_setup_connection(struct Curl_easy *data, @@ -158,7 +150,7 @@ static CURLcode file_setup_connection(struct Curl_easy *data, struct FILEPROTO *filep; (void)conn; /* allocate the FILE specific struct */ - filep = calloc(1, sizeof(*filep)); + filep = curlx_calloc(1, sizeof(*filep)); if(!filep || Curl_meta_set(data, CURL_META_FILE_EASY, filep, file_easy_dtor)) return CURLE_OUT_OF_MEMORY; @@ -270,12 +262,12 @@ static CURLcode file_connect(struct Curl_easy *data, bool *done) file->path = real_path; #endif #endif - free(file->freepath); + curlx_free(file->freepath); file->freepath = real_path; /* free this when done */ file->fd = fd; if(!data->state.upload && (fd == -1)) { - failf(data, "Couldn't open file %s", data->state.up.path); + failf(data, "Could not open file %s", data->state.up.path); file_done(data, CURLE_FILE_COULDNT_READ_FILE, FALSE); return CURLE_FILE_COULDNT_READ_FILE; } @@ -321,7 +313,6 @@ static CURLcode file_upload(struct Curl_easy *data, CURLcode result = CURLE_OK; char *xfer_ulbuf; size_t xfer_ulblen; - curl_off_t bytecount = 0; struct_stat file_stat; const char *sendbuf; bool eos = FALSE; @@ -337,13 +328,16 @@ static CURLcode file_upload(struct Curl_easy *data, if(!dir[1]) return CURLE_FILE_COULDNT_READ_FILE; /* fix: better error code */ - mode = O_WRONLY|O_CREAT|CURL_O_BINARY; + mode = O_WRONLY | O_CREAT | CURL_O_BINARY; if(data->state.resume_from) mode |= O_APPEND; else mode |= O_TRUNC; -#if (defined(ANDROID) || defined(__ANDROID__)) && \ +#ifdef _WIN32 + fd = curlx_open(file->path, mode, + data->set.new_file_perms & (_S_IREAD | _S_IWRITE)); +#elif (defined(ANDROID) || defined(__ANDROID__)) && \ (defined(__i386__) || defined(__arm__)) fd = curlx_open(file->path, mode, (mode_t)data->set.new_file_perms); #else @@ -373,8 +367,8 @@ static CURLcode file_upload(struct Curl_easy *data, goto out; while(!result && !eos) { - size_t nread; - ssize_t nwrite; + size_t nread, nwritten; + ssize_t rv; size_t readcount; result = Curl_client_read(data, xfer_ulbuf, xfer_ulblen, &readcount, &eos); @@ -403,23 +397,17 @@ static CURLcode file_upload(struct Curl_easy *data, sendbuf = xfer_ulbuf; /* write the data to the target */ - nwrite = write(fd, sendbuf, nread); - if((size_t)nwrite != nread) { + rv = write(fd, sendbuf, nread); + if(!curlx_sztouz(rv, &nwritten) || (nwritten != nread)) { result = CURLE_SEND_ERROR; break; } + Curl_pgrs_upload_inc(data, nwritten); - bytecount += nread; - - Curl_pgrsSetUploadCounter(data, bytecount); - - if(Curl_pgrsUpdate(data)) - result = CURLE_ABORTED_BY_CALLBACK; - else - result = Curl_speedcheck(data, curlx_now()); + result = Curl_pgrsCheck(data); } - if(!result && Curl_pgrsUpdate(data)) - result = CURLE_ABORTED_BY_CALLBACK; + if(!result) + result = Curl_pgrsUpdate(data); out: close(fd); @@ -484,7 +472,7 @@ static CURLcode file_do(struct Curl_easy *data, bool *done) const struct tm *tm = &buffer; char header[80]; int headerlen; - static const char accept_ranges[]= { "Accept-ranges: bytes\r\n" }; + static const char accept_ranges[] = { "Accept-ranges: bytes\r\n" }; if(expected_size >= 0) { headerlen = curl_msnprintf(header, sizeof(header), @@ -500,7 +488,7 @@ static CURLcode file_do(struct Curl_easy *data, bool *done) } filetime = (time_t)statbuf.st_mtime; - result = Curl_gmtime(filetime, &buffer); + result = curlx_gmtime(filetime, &buffer); if(result) return result; @@ -508,7 +496,7 @@ static CURLcode file_do(struct Curl_easy *data, bool *done) headerlen = curl_msnprintf(header, sizeof(header), "Last-Modified: %s, %02d %s %4d %02d:%02d:%02d GMT\r\n", - Curl_wkday[tm->tm_wday ? tm->tm_wday-1 : 6], + Curl_wkday[tm->tm_wday ? tm->tm_wday - 1 : 6], tm->tm_mday, Curl_month[tm->tm_mon], tm->tm_year + 1900, @@ -572,12 +560,12 @@ static CURLcode file_do(struct Curl_easy *data, bool *done) if(data->state.resume_from) { if(!S_ISDIR(statbuf.st_mode)) { -#if defined(__AMIGA__) || defined(__MINGW32CE__) +#ifdef __AMIGA__ if(data->state.resume_from != - lseek(fd, (off_t)data->state.resume_from, SEEK_SET)) + lseek(fd, (off_t)data->state.resume_from, SEEK_SET)) #else if(data->state.resume_from != - lseek(fd, data->state.resume_from, SEEK_SET)) + lseek(fd, data->state.resume_from, SEEK_SET)) #endif return CURLE_BAD_DOWNLOAD_RESUME; } @@ -597,11 +585,11 @@ static CURLcode file_do(struct Curl_easy *data, bool *done) size_t bytestoread; if(size_known) { - bytestoread = (expected_size < (curl_off_t)(xfer_blen-1)) ? - curlx_sotouz(expected_size) : (xfer_blen-1); + bytestoread = (expected_size < (curl_off_t)(xfer_blen - 1)) ? + curlx_sotouz(expected_size) : (xfer_blen - 1); } else - bytestoread = xfer_blen-1; + bytestoread = xfer_blen - 1; nread = read(fd, xfer_buf, bytestoread); @@ -618,10 +606,7 @@ static CURLcode file_do(struct Curl_easy *data, bool *done) if(result) goto out; - if(Curl_pgrsUpdate(data)) - result = CURLE_ABORTED_BY_CALLBACK; - else - result = Curl_speedcheck(data, curlx_now()); + result = Curl_pgrsCheck(data); if(result) goto out; } @@ -655,8 +640,8 @@ static CURLcode file_do(struct Curl_easy *data, bool *done) #endif } - if(Curl_pgrsUpdate(data)) - result = CURLE_ABORTED_BY_CALLBACK; + if(!result) + result = Curl_pgrsUpdate(data); out: Curl_multi_xfer_buf_release(data, xfer_buf); diff --git a/vendor/hydra/vendor/curl/lib/file.h b/vendor/hydra/vendor/curl/lib/file.h index fea1eea5..cb3552d9 100644 --- a/vendor/hydra/vendor/curl/lib/file.h +++ b/vendor/hydra/vendor/curl/lib/file.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #ifndef CURL_DISABLE_FILE extern const struct Curl_handler Curl_handler_file; #endif diff --git a/vendor/hydra/vendor/curl/lib/fileinfo.c b/vendor/hydra/vendor/curl/lib/fileinfo.c index bddd3fe6..33e5acde 100644 --- a/vendor/hydra/vendor/curl/lib/fileinfo.c +++ b/vendor/hydra/vendor/curl/lib/fileinfo.c @@ -21,19 +21,15 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifndef CURL_DISABLE_FTP #include "fileinfo.h" -#include "curl_memory.h" -/* The last #include file should be: */ -#include "memdebug.h" struct fileinfo *Curl_fileinfo_alloc(void) { - return calloc(1, sizeof(struct fileinfo)); + return curlx_calloc(1, sizeof(struct fileinfo)); } void Curl_fileinfo_cleanup(struct fileinfo *finfo) @@ -42,7 +38,7 @@ void Curl_fileinfo_cleanup(struct fileinfo *finfo) return; curlx_dyn_free(&finfo->buf); - free(finfo); + curlx_free(finfo); } -#endif +#endif /* !CURL_DISABLE_FTP */ diff --git a/vendor/hydra/vendor/curl/lib/fileinfo.h b/vendor/hydra/vendor/curl/lib/fileinfo.h index 6746ee25..73796678 100644 --- a/vendor/hydra/vendor/curl/lib/fileinfo.h +++ b/vendor/hydra/vendor/curl/lib/fileinfo.h @@ -23,8 +23,8 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ +#include "curl_setup.h" -#include #include "llist.h" #include "curlx/dynbuf.h" diff --git a/vendor/hydra/vendor/curl/lib/formdata.c b/vendor/hydra/vendor/curl/lib/formdata.c index 74a73028..8c4dc483 100644 --- a/vendor/hydra/vendor/curl/lib/formdata.c +++ b/vendor/hydra/vendor/curl/lib/formdata.c @@ -21,37 +21,28 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include - struct Curl_easy; #include "formdata.h" + #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_FORM_API) #include "urldata.h" /* for struct Curl_easy */ #include "mime.h" -#include "vtls/vtls.h" -#include "sendf.h" #include "strdup.h" -#include "rand.h" +#include "bufref.h" #include "curlx/fopen.h" -#include "curlx/warnless.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - -#define HTTPPOST_PTRNAME CURL_HTTPPOST_PTRNAME -#define HTTPPOST_FILENAME CURL_HTTPPOST_FILENAME +#define HTTPPOST_PTRNAME CURL_HTTPPOST_PTRNAME +#define HTTPPOST_FILENAME CURL_HTTPPOST_FILENAME #define HTTPPOST_PTRCONTENTS CURL_HTTPPOST_PTRCONTENTS -#define HTTPPOST_READFILE CURL_HTTPPOST_READFILE -#define HTTPPOST_PTRBUFFER CURL_HTTPPOST_PTRBUFFER -#define HTTPPOST_CALLBACK CURL_HTTPPOST_CALLBACK -#define HTTPPOST_BUFFER CURL_HTTPPOST_BUFFER +#define HTTPPOST_READFILE CURL_HTTPPOST_READFILE +#define HTTPPOST_PTRBUFFER CURL_HTTPPOST_PTRBUFFER +#define HTTPPOST_CALLBACK CURL_HTTPPOST_CALLBACK +#define HTTPPOST_BUFFER CURL_HTTPPOST_BUFFER /*************************************************************************** * @@ -63,31 +54,30 @@ struct Curl_easy; * Returns newly allocated HttpPost on success and NULL if malloc failed. * ***************************************************************************/ -static struct curl_httppost * -AddHttpPost(struct FormInfo *src, - struct curl_httppost *parent_post, - struct curl_httppost **httppost, - struct curl_httppost **last_post) +static struct curl_httppost *AddHttpPost(struct FormInfo *src, + struct curl_httppost *parent_post, + struct curl_httppost **httppost, + struct curl_httppost **last_post) { struct curl_httppost *post; size_t namelength = src->namelength; - if(!namelength && src->name) - namelength = strlen(src->name); + if(!namelength && Curl_bufref_ptr(&src->name)) + namelength = strlen(Curl_bufref_ptr(&src->name)); if((src->bufferlength > LONG_MAX) || (namelength > LONG_MAX)) /* avoid overflow in typecasts below */ return NULL; - post = calloc(1, sizeof(struct curl_httppost)); + post = curlx_calloc(1, sizeof(struct curl_httppost)); if(post) { - post->name = src->name; + post->name = CURL_UNCONST(Curl_bufref_ptr(&src->name)); post->namelength = (long)namelength; - post->contents = src->value; + post->contents = CURL_UNCONST(Curl_bufref_ptr(&src->value)); post->contentlen = src->contentslength; post->buffer = src->buffer; post->bufferlength = (long)src->bufferlength; - post->contenttype = src->contenttype; + post->contenttype = CURL_UNCONST(Curl_bufref_ptr(&src->contenttype)); post->flags = src->flags | CURL_HTTPPOST_LARGE; post->contentheader = src->contentheader; - post->showfilename = src->showfilename; + post->showfilename = CURL_UNCONST(Curl_bufref_ptr(&src->showfilename)); post->userp = src->userp; } else @@ -112,60 +102,63 @@ AddHttpPost(struct FormInfo *src, return post; } +/* Allocate and initialize a new FormInfo structure. */ +static struct FormInfo *NewFormInfo(void) +{ + struct FormInfo *form_info = curlx_calloc(1, sizeof(struct FormInfo)); + + if(form_info) { + Curl_bufref_init(&form_info->name); + Curl_bufref_init(&form_info->value); + Curl_bufref_init(&form_info->contenttype); + Curl_bufref_init(&form_info->showfilename); + } + + return form_info; +} + +/* Replace the target field data by a dynamic copy of it. */ +static CURLcode FormInfoCopyField(struct bufref *field, size_t len) +{ + const char *value = Curl_bufref_ptr(field); + CURLcode result = CURLE_OK; + + if(value) { + if(!len) + len = strlen(value); + result = Curl_bufref_memdup0(field, value, len); + } + + return result; +} + /*************************************************************************** * * AddFormInfo() * - * Adds a FormInfo structure to the list presented by parent_form_info. - * - * Returns newly allocated FormInfo on success and NULL if malloc failed/ - * parent_form_info is NULL. + * Adds a FormInfo structure to the list presented by parent. * ***************************************************************************/ -static struct FormInfo *AddFormInfo(char *value, - char *contenttype, - struct FormInfo *parent_form_info) +static void AddFormInfo(struct FormInfo *form_info, struct FormInfo *parent) { - struct FormInfo *form_info; - form_info = calloc(1, sizeof(struct FormInfo)); - if(!form_info) - return NULL; - if(value) - form_info->value = value; - if(contenttype) - form_info->contenttype = contenttype; - form_info->flags = HTTPPOST_FILENAME; + form_info->flags |= HTTPPOST_FILENAME; - if(parent_form_info) { + if(parent) { /* now, point our 'more' to the original 'more' */ - form_info->more = parent_form_info->more; + form_info->more = parent->more; /* then move the original 'more' to point to ourselves */ - parent_form_info->more = form_info; + parent->more = form_info; } - - return form_info; } static void free_formlist(struct FormInfo *ptr) { for(; ptr != NULL; ptr = ptr->more) { - if(ptr->name_alloc) { - Curl_safefree(ptr->name); - ptr->name_alloc = FALSE; - } - if(ptr->value_alloc) { - Curl_safefree(ptr->value); - ptr->value_alloc = FALSE; - } - if(ptr->contenttype_alloc) { - Curl_safefree(ptr->contenttype); - ptr->contenttype_alloc = FALSE; - } - if(ptr->showfilename_alloc) { - Curl_safefree(ptr->showfilename); - ptr->showfilename_alloc = FALSE; - } + Curl_bufref_free(&ptr->name); + Curl_bufref_free(&ptr->value); + Curl_bufref_free(&ptr->contenttype); + Curl_bufref_free(&ptr->showfilename); } } @@ -231,82 +224,62 @@ static CURLFORMcode FormAddCheck(struct FormInfo *first_form, /* go through the list, check for completeness and if everything is * alright add the HttpPost item otherwise set retval accordingly */ - for(form = first_form; - form != NULL; - form = form->more) { - if(((!form->name || !form->value) && !post) || - ( (form->contentslength) && - (form->flags & HTTPPOST_FILENAME) ) || - ( (form->flags & HTTPPOST_FILENAME) && - (form->flags & HTTPPOST_PTRCONTENTS) ) || - - ( (!form->buffer) && - (form->flags & HTTPPOST_BUFFER) && - (form->flags & HTTPPOST_PTRBUFFER) ) || - - ( (form->flags & HTTPPOST_READFILE) && - (form->flags & HTTPPOST_PTRCONTENTS) ) + for(form = first_form; form != NULL; form = form->more) { + const char *name = Curl_bufref_ptr(&form->name); + + if(((!name || !Curl_bufref_ptr(&form->value)) && !post) || + (form->contentslength && + (form->flags & HTTPPOST_FILENAME)) || + ((form->flags & HTTPPOST_FILENAME) && + (form->flags & HTTPPOST_PTRCONTENTS)) || + + (!form->buffer && + (form->flags & HTTPPOST_BUFFER) && + (form->flags & HTTPPOST_PTRBUFFER)) || + + ((form->flags & HTTPPOST_READFILE) && + (form->flags & HTTPPOST_PTRCONTENTS)) ) { return CURL_FORMADD_INCOMPLETE; } if(((form->flags & HTTPPOST_FILENAME) || (form->flags & HTTPPOST_BUFFER)) && - !form->contenttype) { - char *f = (form->flags & HTTPPOST_BUFFER) ? - form->showfilename : form->value; - char const *type; - type = Curl_mime_contenttype(f); + !Curl_bufref_ptr(&form->contenttype)) { + const char *f = Curl_bufref_ptr((form->flags & HTTPPOST_BUFFER) ? + &form->showfilename : &form->value); + const char *type = Curl_mime_contenttype(f); if(!type) type = prevtype; if(!type) type = FILE_CONTENTTYPE_DEFAULT; /* our contenttype is missing */ - form->contenttype = strdup(type); - if(!form->contenttype) + if(Curl_bufref_memdup0(&form->contenttype, type, strlen(type))) return CURL_FORMADD_MEMORY; - - form->contenttype_alloc = TRUE; } - if(form->name && form->namelength) { - if(memchr(form->name, 0, form->namelength)) + if(name && form->namelength) { + if(memchr(name, 0, form->namelength)) return CURL_FORMADD_NULL; } - if(!(form->flags & HTTPPOST_PTRNAME) && form->name) { + if(!(form->flags & HTTPPOST_PTRNAME)) { /* Note that there is small risk that form->name is NULL here if the app passed in a bad combo, so we check for that. */ - - /* copy name (without strdup; possibly not null-terminated) */ - char *dupname = Curl_memdup0(form->name, form->namelength ? - form->namelength : strlen(form->name)); - if(!dupname) + if(FormInfoCopyField(&form->name, form->namelength)) return CURL_FORMADD_MEMORY; - - form->name = dupname; - form->name_alloc = TRUE; } if(!(form->flags & (HTTPPOST_FILENAME | HTTPPOST_READFILE | HTTPPOST_PTRCONTENTS | HTTPPOST_PTRBUFFER | - HTTPPOST_CALLBACK)) && form->value) { - /* copy value (without strdup; possibly contains null characters) */ - size_t clen = (size_t) form->contentslength; - if(!clen) - clen = strlen(form->value) + 1; - - form->value = Curl_memdup(form->value, clen); - - if(!form->value) + HTTPPOST_CALLBACK))) { + if(FormInfoCopyField(&form->value, (size_t)form->contentslength)) return CURL_FORMADD_MEMORY; - - form->value_alloc = TRUE; } post = AddHttpPost(form, post, httppost, last_post); if(!post) return CURL_FORMADD_MEMORY; - if(form->contenttype) - prevtype = form->contenttype; + if(Curl_bufref_ptr(&form->contenttype)) + prevtype = Curl_bufref_ptr(&form->contenttype); } return CURL_FORMADD_OK; @@ -320,15 +293,13 @@ static void free_chain(struct curl_httppost *c) struct curl_httppost *next = c->next; if(c->more) free_chain(c->more); - free(c); + curlx_free(c); c = next; } } -static -CURLFORMcode FormAdd(struct curl_httppost **httppost, - struct curl_httppost **last_post, - va_list params) +static CURLFORMcode FormAdd(struct curl_httppost **httppost, + struct curl_httppost **last_post, va_list params) { struct FormInfo *first_form, *curr, *form = NULL; CURLFORMcode retval = CURL_FORMADD_OK; @@ -338,15 +309,17 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost, struct curl_httppost *newchain = NULL; struct curl_httppost *lastnode = NULL; - /* This is a state variable, that if TRUE means that we are parsing an - array that we got passed to us. If FALSE we are parsing the input - va_list arguments. */ - bool array_state = FALSE; +#define form_ptr_arg(t) (forms ? (t)(void *)avalue : va_arg(params, t)) +#ifdef HAVE_STDINT_H +#define form_int_arg(t) (forms ? (t)(uintptr_t)avalue : va_arg(params, t)) +#else +#define form_int_arg(t) (forms ? (t)(void *)avalue : va_arg(params, t)) +#endif /* * We need to allocate the first struct to fill in. */ - first_form = calloc(1, sizeof(struct FormInfo)); + first_form = NewFormInfo(); if(!first_form) return CURL_FORMADD_MEMORY; @@ -358,7 +331,7 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost, while(retval == CURL_FORMADD_OK) { /* first see if we have more parts of the array param */ - if(array_state && forms) { + if(forms) { /* get the upcoming option from the given array */ option = forms->option; avalue = (char *)CURL_UNCONST(forms->value); @@ -366,7 +339,7 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost, forms++; /* advance this to next entry */ if(CURLFORM_END == option) { /* end of array state */ - array_state = FALSE; + forms = NULL; continue; } } @@ -381,14 +354,12 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost, switch(option) { case CURLFORM_ARRAY: - if(array_state) + if(forms) /* we do not support an array from within an array */ retval = CURL_FORMADD_ILLEGAL_ARRAY; else { forms = va_arg(params, struct curl_forms *); - if(forms) - array_state = TRUE; - else + if(!forms) retval = CURL_FORMADD_NULL; } break; @@ -397,17 +368,15 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost, * Set the Name property. */ case CURLFORM_PTRNAME: - curr->flags |= HTTPPOST_PTRNAME; /* fall through */ - + curr->flags |= HTTPPOST_PTRNAME; FALLTHROUGH(); case CURLFORM_COPYNAME: - if(curr->name) + if(Curl_bufref_ptr(&curr->name)) retval = CURL_FORMADD_OPTION_TWICE; else { - if(!array_state) - avalue = va_arg(params, char *); + avalue = form_ptr_arg(char *); if(avalue) - curr->name = avalue; /* store for the moment */ + Curl_bufref_set(&curr->name, avalue, 0, NULL); /* No copy yet. */ else retval = CURL_FORMADD_NULL; } @@ -416,8 +385,7 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost, if(curr->namelength) retval = CURL_FORMADD_OPTION_TWICE; else - curr->namelength = - array_state ? (size_t)avalue : (size_t)va_arg(params, long); + curr->namelength = (size_t)form_int_arg(long); break; /* @@ -427,44 +395,36 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost, curr->flags |= HTTPPOST_PTRCONTENTS; FALLTHROUGH(); case CURLFORM_COPYCONTENTS: - if(curr->value) + if(Curl_bufref_ptr(&curr->value)) retval = CURL_FORMADD_OPTION_TWICE; else { - if(!array_state) - avalue = va_arg(params, char *); + avalue = form_ptr_arg(char *); if(avalue) - curr->value = avalue; /* store for the moment */ + Curl_bufref_set(&curr->value, avalue, 0, NULL); /* No copy yet. */ else retval = CURL_FORMADD_NULL; } break; case CURLFORM_CONTENTSLENGTH: - curr->contentslength = - array_state ? (size_t)avalue : (size_t)va_arg(params, long); + curr->contentslength = (curl_off_t)(size_t)form_int_arg(long); break; case CURLFORM_CONTENTLEN: curr->flags |= CURL_HTTPPOST_LARGE; - curr->contentslength = - array_state ? (curl_off_t)(size_t)avalue : - va_arg(params, curl_off_t); + curr->contentslength = form_int_arg(curl_off_t); break; /* Get contents from a given filename */ case CURLFORM_FILECONTENT: - if(curr->flags & (HTTPPOST_PTRCONTENTS|HTTPPOST_READFILE)) + if(curr->flags & (HTTPPOST_PTRCONTENTS | HTTPPOST_READFILE)) retval = CURL_FORMADD_OPTION_TWICE; else { - if(!array_state) - avalue = va_arg(params, char *); + avalue = form_ptr_arg(char *); if(avalue) { - curr->value = strdup(avalue); - if(!curr->value) + if(Curl_bufref_memdup0(&curr->value, avalue, strlen(avalue))) retval = CURL_FORMADD_MEMORY; - else { + else curr->flags |= HTTPPOST_READFILE; - curr->value_alloc = TRUE; - } } else retval = CURL_FORMADD_NULL; @@ -473,26 +433,20 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost, /* We upload a file */ case CURLFORM_FILE: - if(!array_state) - avalue = va_arg(params, char *); - - if(curr->value) { + avalue = form_ptr_arg(char *); + if(Curl_bufref_ptr(&curr->value)) { if(curr->flags & HTTPPOST_FILENAME) { if(avalue) { - char *fname = strdup(avalue); - if(!fname) + form = NewFormInfo(); + if(!form || + Curl_bufref_memdup0(&form->value, avalue, strlen(avalue))) { + curlx_free(form); retval = CURL_FORMADD_MEMORY; + } else { - form = AddFormInfo(fname, NULL, curr); - if(!form) { - free(fname); - retval = CURL_FORMADD_MEMORY; - } - else { - form->value_alloc = TRUE; - curr = form; - form = NULL; - } + AddFormInfo(form, curr); + curr = form; + form = NULL; } } else @@ -503,13 +457,10 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost, } else { if(avalue) { - curr->value = strdup(avalue); - if(!curr->value) + if(Curl_bufref_memdup0(&curr->value, avalue, strlen(avalue))) retval = CURL_FORMADD_MEMORY; - else { + else curr->flags |= HTTPPOST_FILENAME; - curr->value_alloc = TRUE; - } } else retval = CURL_FORMADD_NULL; @@ -517,16 +468,15 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost, break; case CURLFORM_BUFFERPTR: - curr->flags |= HTTPPOST_PTRBUFFER|HTTPPOST_BUFFER; + curr->flags |= HTTPPOST_PTRBUFFER | HTTPPOST_BUFFER; if(curr->buffer) retval = CURL_FORMADD_OPTION_TWICE; else { - if(!array_state) - avalue = va_arg(params, char *); + avalue = form_ptr_arg(char *); if(avalue) { curr->buffer = avalue; /* store for the moment */ - curr->value = avalue; /* make it non-NULL to be accepted - as fine */ + /* Make value non-NULL to be accepted as fine */ + Curl_bufref_set(&curr->value, avalue, 0, NULL); } else retval = CURL_FORMADD_NULL; @@ -537,8 +487,7 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost, if(curr->bufferlength) retval = CURL_FORMADD_OPTION_TWICE; else - curr->bufferlength = - array_state ? (size_t)avalue : (size_t)va_arg(params, long); + curr->bufferlength = (size_t)form_int_arg(long); break; case CURLFORM_STREAM: @@ -546,14 +495,13 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost, if(curr->userp) retval = CURL_FORMADD_OPTION_TWICE; else { - if(!array_state) - avalue = va_arg(params, char *); + avalue = form_ptr_arg(char *); if(avalue) { curr->userp = avalue; - curr->value = avalue; /* this is not strictly true but we derive a - value from this later on and we need this - non-NULL to be accepted as a fine form - part */ + /* The following line is not strictly true but we derive a value + from this later on and we need this non-NULL to be accepted as + a fine form part */ + Curl_bufref_set(&curr->value, avalue, 0, NULL); } else retval = CURL_FORMADD_NULL; @@ -561,25 +509,20 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost, break; case CURLFORM_CONTENTTYPE: - if(!array_state) - avalue = va_arg(params, char *); - if(curr->contenttype) { + avalue = form_ptr_arg(char *); + if(Curl_bufref_ptr(&curr->contenttype)) { if(curr->flags & HTTPPOST_FILENAME) { if(avalue) { - char *type = strdup(avalue); - if(!type) + form = NewFormInfo(); + if(!form || Curl_bufref_memdup0(&form->contenttype, avalue, + strlen(avalue))) { + curlx_free(form); retval = CURL_FORMADD_MEMORY; + } else { - form = AddFormInfo(NULL, type, curr); - if(!form) { - free(type); - retval = CURL_FORMADD_MEMORY; - } - else { - form->contenttype_alloc = TRUE; - curr = form; - form = NULL; - } + AddFormInfo(form, curr); + curr = form; + form = NULL; } } else @@ -588,47 +531,33 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost, else retval = CURL_FORMADD_OPTION_TWICE; } - else { - if(avalue) { - curr->contenttype = strdup(avalue); - if(!curr->contenttype) - retval = CURL_FORMADD_MEMORY; - else - curr->contenttype_alloc = TRUE; - } - else - retval = CURL_FORMADD_NULL; + else if(avalue) { + if(Curl_bufref_memdup0(&curr->contenttype, avalue, strlen(avalue))) + retval = CURL_FORMADD_MEMORY; } + else + retval = CURL_FORMADD_NULL; break; - case CURLFORM_CONTENTHEADER: - { - /* this "cast increases required alignment of target type" but - we consider it OK anyway */ - struct curl_slist *list = array_state ? - (struct curl_slist *)(void *)avalue : - va_arg(params, struct curl_slist *); + case CURLFORM_CONTENTHEADER: { + /* this "cast increases required alignment of target type" but + we consider it OK anyway */ + struct curl_slist *list = form_ptr_arg(struct curl_slist *); - if(curr->contentheader) - retval = CURL_FORMADD_OPTION_TWICE; - else - curr->contentheader = list; + if(curr->contentheader) + retval = CURL_FORMADD_OPTION_TWICE; + else + curr->contentheader = list; - break; - } + break; + } case CURLFORM_FILENAME: case CURLFORM_BUFFER: - if(!array_state) - avalue = va_arg(params, char *); - if(curr->showfilename) + avalue = form_ptr_arg(char *); + if(Curl_bufref_ptr(&curr->showfilename)) retval = CURL_FORMADD_OPTION_TWICE; - else { - curr->showfilename = strdup(avalue); - if(!curr->showfilename) - retval = CURL_FORMADD_MEMORY; - else - curr->showfilename_alloc = TRUE; - } + else if(Curl_bufref_memdup0(&curr->showfilename, avalue, strlen(avalue))) + retval = CURL_FORMADD_MEMORY; break; default: @@ -650,7 +579,7 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost, now by the httppost linked list */ while(first_form) { struct FormInfo *ptr = first_form->more; - free(first_form); + curlx_free(first_form); first_form = ptr; } @@ -667,6 +596,8 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost, free_chain(newchain); return retval; +#undef form_ptr_arg +#undef form_int_arg } /* @@ -676,8 +607,7 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost, */ CURLFORMcode curl_formadd(struct curl_httppost **httppost, - struct curl_httppost **last_post, - ...) + struct curl_httppost **last_post, ...) { va_list arg; CURLFORMcode result; @@ -700,6 +630,10 @@ int curl_formget(struct curl_httppost *form, void *arg, CURLcode result; curl_mimepart toppart; + /* Validate callback is provided */ + if(!append) + return (int)CURLE_BAD_FUNCTION_ARGUMENT; + Curl_mime_initpart(&toppart); /* default form is empty */ result = Curl_getformdata(NULL, &toppart, form, NULL); if(!result) @@ -721,7 +655,7 @@ int curl_formget(struct curl_httppost *form, void *arg, } Curl_mime_cleanpart(&toppart); - return (int) result; + return (int)result; } /* @@ -743,19 +677,17 @@ void curl_formfree(struct curl_httppost *form) curl_formfree(form->more); if(!(form->flags & HTTPPOST_PTRNAME)) - free(form->name); /* free the name */ + curlx_free(form->name); /* free the name */ if(!(form->flags & - (HTTPPOST_PTRCONTENTS|HTTPPOST_BUFFER|HTTPPOST_CALLBACK)) - ) - free(form->contents); /* free the contents */ - free(form->contenttype); /* free the content type */ - free(form->showfilename); /* free the faked filename */ - free(form); /* free the struct */ + (HTTPPOST_PTRCONTENTS | HTTPPOST_BUFFER | HTTPPOST_CALLBACK))) + curlx_free(form->contents); /* free the contents */ + curlx_free(form->contenttype); /* free the content type */ + curlx_free(form->showfilename); /* free the faked filename */ + curlx_free(form); /* free the struct */ form = next; } while(form); /* continue */ } - /* Set mime part name, taking care of non null-terminated name string. */ static CURLcode setname(curl_mimepart *part, const char *name, size_t len) { @@ -768,7 +700,7 @@ static CURLcode setname(curl_mimepart *part, const char *name, size_t len) if(!zname) return CURLE_OUT_OF_MEMORY; res = curl_mime_name(part, zname); - free(zname); + curlx_free(zname); return res; } @@ -859,10 +791,10 @@ CURLcode Curl_getformdata(CURL *data, #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wcast-function-type-strict" #endif - result = curl_mime_data_cb(part, (curl_off_t) -1, - (curl_read_callback) fread, + result = curl_mime_data_cb(part, (curl_off_t)-1, + (curl_read_callback)fread, curlx_fseek, - NULL, (void *) stdin); + NULL, (void *)stdin); #if defined(__clang__) && __clang_major__ >= 16 #pragma clang diagnostic pop #endif @@ -897,7 +829,7 @@ CURLcode Curl_getformdata(CURL *data, /* Set fake filename. */ if(!result && post->showfilename) if(post->more || (post->flags & (HTTPPOST_FILENAME | HTTPPOST_BUFFER | - HTTPPOST_CALLBACK))) + HTTPPOST_CALLBACK))) result = curl_mime_filename(part, post->showfilename); } } @@ -911,8 +843,7 @@ CURLcode Curl_getformdata(CURL *data, #else /* if disabled */ CURLFORMcode curl_formadd(struct curl_httppost **httppost, - struct curl_httppost **last_post, - ...) + struct curl_httppost **last_post, ...) { (void)httppost; (void)last_post; @@ -934,4 +865,4 @@ void curl_formfree(struct curl_httppost *form) /* Nothing to do. */ } -#endif /* if disabled */ +#endif /* if disabled */ diff --git a/vendor/hydra/vendor/curl/lib/formdata.h b/vendor/hydra/vendor/curl/lib/formdata.h index 74f00bf4..ce592a8f 100644 --- a/vendor/hydra/vendor/curl/lib/formdata.h +++ b/vendor/hydra/vendor/curl/lib/formdata.h @@ -23,30 +23,27 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifndef CURL_DISABLE_FORM_API +#include "bufref.h" + /* used by FormAdd for temporary storage */ struct FormInfo { - char *name; - size_t namelength; - char *value; - curl_off_t contentslength; - char *contenttype; + struct bufref name; + struct bufref value; + struct bufref contenttype; + struct bufref showfilename; /* The filename to show. If not set, the actual + filename will be used */ char *buffer; /* pointer to existing buffer used for file upload */ - size_t bufferlength; - char *showfilename; /* The filename to show. If not set, the actual - filename will be used */ char *userp; /* pointer for the read callback */ - struct curl_slist *contentheader; struct FormInfo *more; + struct curl_slist *contentheader; + curl_off_t contentslength; + size_t namelength; + size_t bufferlength; unsigned char flags; - BIT(name_alloc); - BIT(value_alloc); - BIT(contenttype_alloc); - BIT(showfilename_alloc); }; CURLcode Curl_getformdata(CURL *data, @@ -55,5 +52,4 @@ CURLcode Curl_getformdata(CURL *data, curl_read_callback fread_func); #endif /* CURL_DISABLE_FORM_API */ - #endif /* HEADER_CURL_FORMDATA_H */ diff --git a/vendor/hydra/vendor/curl/lib/ftp.c b/vendor/hydra/vendor/curl/lib/ftp.c index 4858ae23..12b8d4a6 100644 --- a/vendor/hydra/vendor/curl/lib/ftp.c +++ b/vendor/hydra/vendor/curl/lib/ftp.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifndef CURL_DISABLE_FTP @@ -40,15 +39,14 @@ #include #endif -#include #include "urldata.h" #include "sendf.h" +#include "curl_trc.h" #include "if2ip.h" #include "hostip.h" #include "progress.h" #include "transfer.h" #include "escape.h" -#include "http.h" /* for HTTP proxy tunnel stuff */ #include "ftp.h" #include "fileinfo.h" #include "ftplistparser.h" @@ -65,18 +63,11 @@ #include "sockaddr.h" /* required for Curl_sockaddr_storage */ #include "multiif.h" #include "url.h" -#include "speedcheck.h" -#include "curlx/warnless.h" #include "http_proxy.h" -#include "socks.h" #include "strdup.h" #include "curlx/strerr.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifndef NI_MAXHOST #define NI_MAXHOST 1025 #endif @@ -86,18 +77,18 @@ /* macro to check for a three-digit ftp status code at the start of the given string */ -#define STATUSCODE(line) (ISDIGIT(line[0]) && ISDIGIT(line[1]) && \ - ISDIGIT(line[2])) +#define STATUSCODE(line) \ + (ISDIGIT(line[0]) && ISDIGIT(line[1]) && ISDIGIT(line[2])) /* macro to check for the last line in an FTP server response */ #define LASTLINE(line) (STATUSCODE(line) && (' ' == line[3])) #ifdef CURL_DISABLE_VERBOSE_STRINGS -#define ftp_pasv_verbose(a,b,c,d) Curl_nop_stmt -#define FTP_CSTATE(c) ((void)(c), "") +#define ftp_pasv_verbose(a, b, c, d) Curl_nop_stmt +#define FTP_CSTATE(c) ((void)(c), "") #else /* CURL_DISABLE_VERBOSE_STRINGS */ /* for tracing purposes */ -static const char * const ftp_state_names[]={ +static const char * const ftp_state_names[] = { "STOP", "WAIT220", "AUTH", @@ -136,7 +127,7 @@ static const char * const ftp_state_names[]={ "STOR", "QUIT" }; -#define FTP_CSTATE(ftpc) ((ftpc)? ftp_state_names[(ftpc)->state] : "???") +#define FTP_CSTATE(ftpc) ((ftpc) ? ftp_state_names[(ftpc)->state] : "???") #endif /* !CURL_DISABLE_VERBOSE_STRINGS */ @@ -168,12 +159,11 @@ static void ftp_state_low(struct Curl_easy *data, ftpc->state = newstate; } - /* Local API functions */ #ifndef DEBUGBUILD -#define ftp_state(x,y,z) ftp_state_low(x,y,z) +#define ftp_state(x, y, z) ftp_state_low(x, y, z) #else /* !DEBUGBUILD */ -#define ftp_state(x,y,z) ftp_state_low(x,y,z,__LINE__) +#define ftp_state(x, y, z) ftp_state_low(x, y, z, __LINE__) #endif /* DEBUGBUILD */ static CURLcode ftp_sendquote(struct Curl_easy *data, @@ -271,10 +261,10 @@ const struct Curl_handler Curl_handler_ftp = { CURLPROTO_FTP, /* family */ PROTOPT_DUAL | PROTOPT_CLOSEACTION | PROTOPT_NEEDSPWD | PROTOPT_NOURLQUERY | PROTOPT_PROXY_AS_HTTP | - PROTOPT_WILDCARD | PROTOPT_SSL_REUSE /* flags */ + PROTOPT_WILDCARD | PROTOPT_SSL_REUSE | + PROTOPT_CONN_REUSE /* flags */ }; - #ifdef USE_SSL /* * FTPS protocol handler. @@ -303,7 +293,8 @@ const struct Curl_handler Curl_handler_ftps = { CURLPROTO_FTPS, /* protocol */ CURLPROTO_FTP, /* family */ PROTOPT_SSL | PROTOPT_DUAL | PROTOPT_CLOSEACTION | - PROTOPT_NEEDSPWD | PROTOPT_NOURLQUERY | PROTOPT_WILDCARD /* flags */ + PROTOPT_NEEDSPWD | PROTOPT_NOURLQUERY | PROTOPT_WILDCARD | + PROTOPT_CONN_REUSE /* flags */ }; #endif @@ -316,18 +307,6 @@ static void close_secondarysocket(struct Curl_easy *data, Curl_conn_cf_discard_all(data, data->conn, SECONDARYSOCKET); } -/* - * NOTE: back in the old days, we added code in the FTP code that made NOBODY - * requests on files respond with headers passed to the client/stdout that - * looked like HTTP ones. - * - * This approach is not elegant, it causes confusion and is error-prone. It is - * subject for removal at the next (or at least a future) soname bump. Until - * then you can test the effects of the removal by undefining the following - * define named CURL_FTP_HTTPSTYLE_HEAD. - */ -#define CURL_FTP_HTTPSTYLE_HEAD 1 - static void freedirs(struct ftp_conn *ftpc) { Curl_safefree(ftpc->dirs); @@ -429,7 +408,7 @@ static const struct Curl_cwtype ftp_cw_lc = { #endif /* CURL_PREFER_LF_LINEENDS */ -static CURLcode getftpresponse(struct Curl_easy *data, ssize_t *nread, +static CURLcode getftpresponse(struct Curl_easy *data, size_t *nread, int *ftpcode); /*********************************************************************** @@ -443,7 +422,7 @@ static CURLcode ftp_check_ctrl_on_data_wait(struct Curl_easy *data, struct connectdata *conn = data->conn; curl_socket_t ctrl_sock = conn->sock[FIRSTSOCKET]; struct pingpong *pp = &ftpc->pp; - ssize_t nread; + size_t nread; int ftpcode; bool response = FALSE; @@ -462,8 +441,7 @@ static CURLcode ftp_check_ctrl_on_data_wait(struct Curl_easy *data, /* there is pending control data still in the buffer to read */ response = TRUE; else { - int socketstate = Curl_socket_check(ctrl_sock, CURL_SOCKET_BAD, - CURL_SOCKET_BAD, 0); + int socketstate = SOCKET_READABLE(ctrl_sock, 0); /* see if the connection request is already here */ switch(socketstate) { case -1: /* error */ @@ -505,7 +483,7 @@ static CURLcode ftp_check_ctrl_on_data_wait(struct Curl_easy *data, infof(data, "FTP code: %03d", ftpcode); - if(ftpcode/100 > 3) + if(ftpcode / 100 > 3) return CURLE_FTP_ACCEPT_FAILED; return CURLE_WEIRD_SERVER_REPLY; @@ -614,7 +592,7 @@ static CURLcode ftp_readresp(struct Curl_easy *data, * */ static CURLcode getftpresponse(struct Curl_easy *data, - ssize_t *nreadp, /* return number of bytes + size_t *nreadp, /* return number of bytes read */ int *ftpcodep) /* return the ftp-code */ { @@ -687,8 +665,7 @@ static CURLcode getftpresponse(struct Curl_easy *data, return CURLE_RECV_ERROR; } else if(ev == 0) { - if(Curl_pgrsUpdate(data)) - return CURLE_ABORTED_BY_CALLBACK; + result = Curl_pgrsUpdate(data); continue; /* just continue in our loop for the timeout duration */ } } @@ -778,8 +755,8 @@ static CURLcode ftp_domore_pollset(struct Curl_easy *data, /* if stopped and still in this state, then we are also waiting for a connect on the secondary connection */ DEBUGASSERT(data->conn->sock[SECONDARYSOCKET] != CURL_SOCKET_BAD || - (data->conn->cfilter[SECONDARYSOCKET] && - !Curl_conn_is_connected(data->conn, SECONDARYSOCKET))); + (data->conn->cfilter[SECONDARYSOCKET] && + !Curl_conn_is_connected(data->conn, SECONDARYSOCKET))); /* An unconnected SECONDARY will add its socket by itself * via its adjust_pollset() */ return Curl_pollset_add_in(data, ps, data->conn->sock[FIRSTSOCKET]); @@ -798,7 +775,7 @@ static const char *pathpiece(struct ftp_conn *ftpc, int num) { DEBUGASSERT(ftpc->dirs); DEBUGASSERT(ftpc->dirdepth > num); - return &ftpc->rawpath[ ftpc->dirs[num].start ]; + return &ftpc->rawpath[ftpc->dirs[num].start]; } /* This is called after the FTP_QUOTE state is passed. @@ -969,7 +946,7 @@ static CURLcode ftp_state_use_port(struct Curl_easy *data, if(addrlen) { const struct Curl_sockaddr_ex *remote_addr = - Curl_conn_get_remote_addr(data, FIRSTSOCKET); + Curl_conn_get_remote_addr(data, FIRSTSOCKET); DEBUGASSERT(remote_addr); if(!remote_addr) @@ -987,15 +964,15 @@ static CURLcode ftp_state_use_port(struct Curl_easy *data, conn->scope_id, #endif ipstr, hbuf, sizeof(hbuf))) { - case IF2IP_NOT_FOUND: - /* not an interface, use the given string as hostname instead */ - host = ipstr; - break; - case IF2IP_AF_NOT_SUPPORTED: - goto out; - case IF2IP_FOUND: - host = hbuf; /* use the hbuf for hostname */ - break; + case IF2IP_NOT_FOUND: + /* not an interface, use the given string as hostname instead */ + host = ipstr; + break; + case IF2IP_AF_NOT_SUPPORTED: + goto out; + case IF2IP_FOUND: + host = hbuf; /* use the hbuf for hostname */ + break; } } else @@ -1048,8 +1025,12 @@ static CURLcode ftp_state_use_port(struct Curl_easy *data, /* step 2, create a socket for the requested address */ error = 0; for(ai = res; ai; ai = ai->ai_next) { - if(Curl_socket_open(data, ai, NULL, - Curl_conn_get_transport(data, conn), &portsock)) { + result = Curl_socket_open(data, ai, NULL, + Curl_conn_get_transport(data, conn), &portsock); + if(result) { + if(result == CURLE_OUT_OF_MEMORY) + goto out; + result = CURLE_FTP_PORT_FAILED; error = SOCKERRNO; continue; } @@ -1076,7 +1057,7 @@ static CURLcode ftp_state_use_port(struct Curl_easy *data, sa6->sin6_port = htons(port); #endif /* Try binding the given address. */ - if(bind(portsock, sa, sslen) ) { + if(bind(portsock, sa, sslen)) { /* It failed. */ error = SOCKERRNO; if(possibly_non_local && (error == SOCKEADDRNOTAVAIL)) { @@ -1115,7 +1096,6 @@ static CURLcode ftp_state_use_port(struct Curl_easy *data, port++; } - /* get the name again after the bind() so that we can extract the port number it uses now */ sslen = sizeof(ss); @@ -1432,7 +1412,7 @@ static CURLcode ftp_state_list(struct Curl_easy *data, return CURLE_OUT_OF_MEMORY; result = Curl_pp_sendf(data, &ftpc->pp, "%s", cmd); - free(cmd); + curlx_free(cmd); if(!result) ftp_state(data, ftpc, FTP_LIST); @@ -1518,7 +1498,6 @@ static CURLcode ftp_state_mdtm(struct Curl_easy *data, return result; } - /* This is called after the TYPE and possible quote commands have been sent */ static CURLcode ftp_state_ul_setup(struct Curl_easy *data, struct ftp_conn *ftpc, @@ -1571,7 +1550,7 @@ static CURLcode ftp_state_ul_setup(struct Curl_easy *data, } /* seekerr == CURL_SEEKFUNC_CANTSEEK (cannot seek to offset) */ do { - char scratch[4*1024]; + char scratch[4 * 1024]; size_t readthisamountnow = (data->state.resume_from - passed > (curl_off_t)sizeof(scratch)) ? sizeof(scratch) : @@ -1769,9 +1748,7 @@ static CURLcode ftp_epsv_disable(struct Curl_easy *data, return result; } - -static CURLcode ftp_control_addr_dup(struct Curl_easy *data, - char **newhostp) +static CURLcode ftp_control_addr_dup(struct Curl_easy *data, char **newhostp) { struct connectdata *conn = data->conn; struct ip_quadruple ipquad; @@ -1783,12 +1760,12 @@ static CURLcode ftp_control_addr_dup(struct Curl_easy *data, not the ftp host. */ #ifndef CURL_DISABLE_PROXY if(conn->bits.tunnel_proxy || conn->bits.socksproxy) - *newhostp = strdup(conn->host.name); + *newhostp = curlx_strdup(conn->host.name); else #endif if(!Curl_conn_get_ip_info(data, conn, FIRSTSOCKET, &is_ipv6, &ipquad) && *ipquad.remote_ip) - *newhostp = strdup(ipquad.remote_ip); + *newhostp = curlx_strdup(ipquad.remote_ip); else { /* failed to get the remote_ip of the DATA connection */ failf(data, "unable to get peername of DATA connection"); @@ -1827,8 +1804,7 @@ static CURLcode ftp_state_pasv_resp(struct Curl_easy *data, struct pingpong *pp = &ftpc->pp; char *newhost = NULL; unsigned short newport = 0; - char *str = - curlx_dyn_ptr(&pp->recvbuf) + 4; /* start on the first letter */ + char *str = curlx_dyn_ptr(&pp->recvbuf) + 4; /* start on the first letter */ if((ftpc->count1 == 0) && (ftpcode == 229)) { @@ -1880,7 +1856,7 @@ static CURLcode ftp_state_pasv_resp(struct Curl_easy *data, } if(!*str) { - failf(data, "Couldn't interpret the 227-response"); + failf(data, "Could not interpret the 227-response"); return CURLE_FTP_WEIRD_227_FORMAT; } @@ -1889,8 +1865,7 @@ static CURLcode ftp_state_pasv_resp(struct Curl_easy *data, /* told to ignore the remotely given IP but instead use the host we used for the control connection */ infof(data, "Skip %u.%u.%u.%u for data connection, reuse %s instead", - ip[0], ip[1], ip[2], ip[3], - conn->host.name); + ip[0], ip[1], ip[2], ip[3], conn->host.name); result = ftp_control_addr_dup(data, &newhost); if(result) return result; @@ -1915,7 +1890,7 @@ static CURLcode ftp_state_pasv_resp(struct Curl_easy *data, #ifndef CURL_DISABLE_PROXY if(conn->bits.proxy) { /* This connection uses a proxy and we need to connect to the proxy again - * here. We do not want to rely on a former host lookup that might've + * here. We do not want to rely on a former host lookup that might have * expired now, instead we remake the lookup here and now! */ struct ip_quadruple ipquad; bool is_ipv6; @@ -1947,7 +1922,7 @@ static CURLcode ftp_state_pasv_resp(struct Curl_easy *data, /* postponed address resolution in case of tcp fastopen */ if(conn->bits.tcp_fastopen && !conn->bits.reuse && !newhost[0]) { - free(newhost); + curlx_free(newhost); result = ftp_control_addr_dup(data, &newhost); if(result) goto error; @@ -1968,17 +1943,17 @@ static CURLcode ftp_state_pasv_resp(struct Curl_easy *data, CURL_CF_SSL_ENABLE : CURL_CF_SSL_DISABLE); if(result) { - if(ftpc->count1 == 0 && ftpcode == 229) { - free(newhost); + if((result != CURLE_OUT_OF_MEMORY) && + (ftpc->count1 == 0) && (ftpcode == 229)) { + curlx_free(newhost); return ftp_epsv_disable(data, ftpc, conn); } goto error; } - /* - * When this is used from the multi interface, this might've returned with + * When this is used from the multi interface, this might have returned with * the 'connected' set to FALSE and thus we are now awaiting a non-blocking * connect to connect. */ @@ -1987,9 +1962,9 @@ static CURLcode ftp_state_pasv_resp(struct Curl_easy *data, /* this just dumps information about this second connection */ ftp_pasv_verbose(data, dns->addr, newhost, connectport); - free(conn->secondaryhostname); + curlx_free(conn->secondaryhostname); conn->secondary_port = newport; - conn->secondaryhostname = strdup(newhost); + conn->secondaryhostname = curlx_strdup(newhost); if(!conn->secondaryhostname) { result = CURLE_OUT_OF_MEMORY; goto error; @@ -1999,7 +1974,7 @@ static CURLcode ftp_state_pasv_resp(struct Curl_easy *data, ftp_state(data, ftpc, FTP_STOP); /* this phase is completed */ error: - free(newhost); + curlx_free(newhost); return result; } @@ -2042,7 +2017,7 @@ static CURLcode ftp_state_port_resp(struct Curl_easy *data, static int twodigit(const char *p) { - return (p[0]-'0') * 10 + (p[1]-'0'); + return (p[0] - '0') * 10 + (p[1] - '0'); } static bool ftp_213_date(const char *p, int *year, int *month, int *day, @@ -2097,28 +2072,26 @@ static CURLcode ftp_state_mdtm_resp(struct Curl_easy *data, CURLcode result = CURLE_OK; switch(ftpcode) { - case 213: - { - /* we got a time. Format should be: "YYYYMMDDHHMMSS[.sss]" where the - last .sss part is optional and means fractions of a second */ - int year, month, day, hour, minute, second; - struct pingpong *pp = &ftpc->pp; - char *resp = curlx_dyn_ptr(&pp->recvbuf) + 4; - bool showtime = FALSE; - if(ftp_213_date(resp, &year, &month, &day, &hour, &minute, &second)) { - /* we have a time, reformat it */ - char timebuf[24]; - curl_msnprintf(timebuf, sizeof(timebuf), - "%04d%02d%02d %02d:%02d:%02d GMT", - year, month, day, hour, minute, second); - /* now, convert this into a time() value: */ - if(!Curl_getdate_capped(timebuf, &data->info.filetime)) - showtime = TRUE; - } + case 213: { + /* we got a time. Format should be: "YYYYMMDDHHMMSS[.sss]" where the + last .sss part is optional and means fractions of a second */ + int year, month, day, hour, minute, second; + struct pingpong *pp = &ftpc->pp; + char *resp = curlx_dyn_ptr(&pp->recvbuf) + 4; + bool showtime = FALSE; + if(ftp_213_date(resp, &year, &month, &day, &hour, &minute, &second)) { + /* we have a time, reformat it */ + char timebuf[24]; + curl_msnprintf(timebuf, sizeof(timebuf), + "%04d%02d%02d %02d:%02d:%02d GMT", + year, month, day, hour, minute, second); + /* now, convert this into a time() value: */ + if(!Curl_getdate_capped(timebuf, &data->info.filetime)) + showtime = TRUE; + } -#ifdef CURL_FTP_HTTPSTYLE_HEAD - /* If we asked for a time of the file and we actually got one as well, - we "emulate" an HTTP-style header in our output. */ + /* If we asked for a time of the file and we actually got one as well, + we "emulate" an HTTP-style header in our output. */ #if defined(__GNUC__) && (defined(__DJGPP__) || defined(__AMIGA__)) #pragma GCC diagnostic push @@ -2126,39 +2099,38 @@ static CURLcode ftp_state_mdtm_resp(struct Curl_easy *data, warning: comparison of unsigned expression in '>= 0' is always true */ #pragma GCC diagnostic ignored "-Wtype-limits" #endif - if(data->req.no_body && ftpc->file && - data->set.get_filetime && showtime) { + if(data->req.no_body && ftpc->file && + data->set.get_filetime && showtime) { #if defined(__GNUC__) && (defined(__DJGPP__) || defined(__AMIGA__)) #pragma GCC diagnostic pop #endif - char headerbuf[128]; - int headerbuflen; - time_t filetime = data->info.filetime; - struct tm buffer; - const struct tm *tm = &buffer; + char headerbuf[128]; + int headerbuflen; + time_t filetime = data->info.filetime; + struct tm buffer; + const struct tm *tm = &buffer; - result = Curl_gmtime(filetime, &buffer); - if(result) - return result; + result = curlx_gmtime(filetime, &buffer); + if(result) + return result; - /* format: "Tue, 15 Nov 1994 12:45:26" */ - headerbuflen = - curl_msnprintf(headerbuf, sizeof(headerbuf), - "Last-Modified: %s, %02d %s %4d %02d:%02d:%02d " - "GMT\r\n", - Curl_wkday[tm->tm_wday ? tm->tm_wday-1 : 6], - tm->tm_mday, - Curl_month[tm->tm_mon], - tm->tm_year + 1900, - tm->tm_hour, - tm->tm_min, - tm->tm_sec); - result = client_write_header(data, headerbuf, headerbuflen); - if(result) - return result; - } /* end of a ridiculous amount of conditionals */ -#endif - } + /* format: "Tue, 15 Nov 1994 12:45:26" */ + headerbuflen = + curl_msnprintf(headerbuf, sizeof(headerbuf), + "Last-Modified: %s, %02d %s %4d %02d:%02d:%02d " + "GMT\r\n", + Curl_wkday[tm->tm_wday ? tm->tm_wday-1 : 6], + tm->tm_mday, + Curl_month[tm->tm_mon], + tm->tm_year + 1900, + tm->tm_hour, + tm->tm_min, + tm->tm_sec); + result = client_write_header(data, headerbuf, headerbuflen); + if(result) + return result; + } /* end of a ridiculous amount of conditionals */ + } break; default: infof(data, "unsupported MDTM reply format"); @@ -2214,11 +2186,11 @@ static CURLcode ftp_state_type_resp(struct Curl_easy *data, { CURLcode result = CURLE_OK; - if(ftpcode/100 != 2) { + if(ftpcode / 100 != 2) { /* "sasserftpd" and "(u)r(x)bot ftpd" both responds with 226 after a successful 'TYPE I'. While that is not as RFC959 says, it is still a positive response code and we allow that. */ - failf(data, "Couldn't set desired mode"); + failf(data, "Could not set desired mode"); return CURLE_FTP_COULDNT_SET_TYPE; } if(ftpcode != 200) @@ -2287,7 +2259,7 @@ static CURLcode ftp_state_retr(struct Curl_easy *data, return CURLE_BAD_DOWNLOAD_RESUME; } /* Now store the number of bytes we are expected to download */ - ftp->downloadsize = filesize-data->state.resume_from; + ftp->downloadsize = filesize - data->state.resume_from; } } @@ -2362,7 +2334,6 @@ static CURLcode ftp_state_size_resp(struct Curl_easy *data, } if(instate == FTP_SIZE) { -#ifdef CURL_FTP_HTTPSTYLE_HEAD if(filesize != -1) { char clbuf[128]; int clbuflen = curl_msnprintf(clbuf, sizeof(clbuf), @@ -2372,7 +2343,6 @@ static CURLcode ftp_state_size_resp(struct Curl_easy *data, if(result) return result; } -#endif Curl_pgrsSetDownloadSize(data, filesize); result = ftp_state_rest(data, ftpc, ftp); } @@ -2399,20 +2369,18 @@ static CURLcode ftp_state_rest_resp(struct Curl_easy *data, switch(instate) { case FTP_REST: default: -#ifdef CURL_FTP_HTTPSTYLE_HEAD if(ftpcode == 350) { - char buffer[24]= { "Accept-ranges: bytes\r\n" }; + char buffer[24] = { "Accept-ranges: bytes\r\n" }; result = client_write_header(data, buffer, strlen(buffer)); if(result) return result; } -#endif result = ftp_state_prepare_transfer(data, ftpc, ftp); break; case FTP_RETR_REST: if(ftpcode != 350) { - failf(data, "Couldn't use REST"); + failf(data, "Could not use REST"); result = CURLE_FTP_COULDNT_USE_REST; } else { @@ -2488,7 +2456,6 @@ static CURLcode ftp_state_get_resp(struct Curl_easy *data, data->req.size = -1; /* default unknown size */ - /* * It appears that there are FTP-servers that return size 0 for files when * SIZE is used on the file while being in BINARY mode. To work around @@ -2558,7 +2525,7 @@ static CURLcode ftp_state_get_resp(struct Curl_easy *data, } else { if((instate == FTP_LIST) && (ftpcode == 450)) { - /* simply no matching files in the dir listing */ + /* simply no matching files in the directory listing */ ftp->transfer = PPTRANSFER_NONE; /* do not download anything */ ftp_state(data, ftpc, FTP_STOP); /* this phase is over */ } @@ -2615,12 +2582,11 @@ static CURLcode ftp_state_user_resp(struct Curl_easy *data, if((ftpcode == 331) && (ftpc->state == FTP_USER)) { /* 331 Password required for ... (the server requires to send the user's password too) */ - result = Curl_pp_sendf(data, &ftpc->pp, "PASS %s", - data->conn->passwd); + result = Curl_pp_sendf(data, &ftpc->pp, "PASS %s", data->conn->passwd); if(!result) ftp_state(data, ftpc, FTP_PASS); } - else if(ftpcode/100 == 2) { + else if(ftpcode / 100 == 2) { /* 230 User ... logged in. (the user logged in with or without password) */ result = ftp_state_loggedin(data, ftpc); @@ -2646,9 +2612,8 @@ static CURLcode ftp_state_user_resp(struct Curl_easy *data, if(data->set.str[STRING_FTP_ALTERNATIVE_TO_USER] && !ftpc->ftp_trying_alternative) { /* Ok, USER failed. Let's try the supplied command. */ - result = - Curl_pp_sendf(data, &ftpc->pp, "%s", - data->set.str[STRING_FTP_ALTERNATIVE_TO_USER]); + result = Curl_pp_sendf(data, &ftpc->pp, "%s", + data->set.str[STRING_FTP_ALTERNATIVE_TO_USER]); if(!result) { ftpc->ftp_trying_alternative = TRUE; ftp_state(data, ftpc, FTP_USER); @@ -2744,29 +2709,24 @@ static CURLcode ftp_pwd_resp(struct Curl_easy *data, if(!ftpc->server_os && dir[0] != '/') { result = Curl_pp_sendf(data, &ftpc->pp, "%s", "SYST"); if(result) { - free(dir); + curlx_free(dir); return result; } - free(ftpc->entrypath); - ftpc->entrypath = dir; /* remember this */ - infof(data, "Entry path is '%s'", ftpc->entrypath); - /* also save it where getinfo can access it: */ - free(data->state.most_recent_ftp_entrypath); - data->state.most_recent_ftp_entrypath = strdup(ftpc->entrypath); - if(!data->state.most_recent_ftp_entrypath) - return CURLE_OUT_OF_MEMORY; - ftp_state(data, ftpc, FTP_SYST); - return result; } - free(ftpc->entrypath); + curlx_free(ftpc->entrypath); ftpc->entrypath = dir; /* remember this */ infof(data, "Entry path is '%s'", ftpc->entrypath); /* also save it where getinfo can access it: */ - free(data->state.most_recent_ftp_entrypath); - data->state.most_recent_ftp_entrypath = strdup(ftpc->entrypath); + curlx_free(data->state.most_recent_ftp_entrypath); + data->state.most_recent_ftp_entrypath = curlx_strdup(ftpc->entrypath); if(!data->state.most_recent_ftp_entrypath) return CURLE_OUT_OF_MEMORY; + + if(!ftpc->server_os && dir[0] != '/') { + ftp_state(data, ftpc, FTP_SYST); + return CURLE_OK; + } } else { /* could not get the path */ @@ -2819,8 +2779,7 @@ static CURLcode ftp_wait_resp(struct Curl_easy *data, (int)data->set.ftpsslauth); return CURLE_UNKNOWN_OPTION; /* we do not know what to do */ } - result = Curl_pp_sendf(data, &ftpc->pp, "AUTH %s", - ftpauth[ftpc->count1]); + result = Curl_pp_sendf(data, &ftpc->pp, "AUTH %s", ftpauth[ftpc->count1]); if(!result) ftp_state(data, ftpc, FTP_AUTH); } @@ -2920,10 +2879,9 @@ static CURLcode ftp_pp_statemachine(struct Curl_easy *data, break; case FTP_PROT: - if(ftpcode/100 == 2) + if(ftpcode / 100 == 2) /* We have enabled SSL for the data connection! */ - conn->bits.ftp_use_data_ssl = - (data->set.use_ssl != CURLUSESSL_CONTROL); + conn->bits.ftp_use_data_ssl = (data->set.use_ssl != CURLUSESSL_CONTROL); /* FTP servers typically responds with 500 if they decide to reject our 'P' request */ else if(data->set.use_ssl > CURLUSESSL_CONTROL) @@ -2987,18 +2945,18 @@ static CURLcode ftp_pp_statemachine(struct Curl_easy *data, /* Force OS400 name format 1. */ result = Curl_pp_sendf(data, &ftpc->pp, "%s", "SITE NAMEFMT 1"); if(result) { - free(os); + curlx_free(os); return result; } /* remember target server OS */ - free(ftpc->server_os); + curlx_free(ftpc->server_os); ftpc->server_os = os; ftp_state(data, ftpc, FTP_NAMEFMT); break; } /* Nothing special for the target server. */ /* remember target server OS */ - free(ftpc->server_os); + curlx_free(ftpc->server_os); ftpc->server_os = os; } else { @@ -3035,7 +2993,7 @@ static CURLcode ftp_pp_statemachine(struct Curl_easy *data, break; case FTP_CWD: - if(ftpcode/100 != 2) { + if(ftpcode / 100 != 2) { /* failure to CWD there */ if(data->set.ftp_create_missing_dirs && ftpc->cwdcount && !ftpc->count2) { @@ -3077,8 +3035,8 @@ static CURLcode ftp_pp_statemachine(struct Curl_easy *data, break; case FTP_MKD: - if((ftpcode/100 != 2) && !ftpc->count3--) { - /* failure to MKD the dir */ + if((ftpcode / 100 != 2) && !ftpc->count3--) { + /* failure to MKD the directory */ failf(data, "Failed to MKD dir: %03d", ftpcode); result = CURLE_REMOTE_ACCESS_DENIED; } @@ -3150,7 +3108,6 @@ static CURLcode ftp_pp_statemachine(struct Curl_easy *data, return result; } - /* called repeatedly until done from multi.c */ static CURLcode ftp_statemach(struct Curl_easy *data, struct ftp_conn *ftpc, @@ -3211,9 +3168,6 @@ static CURLcode ftp_connect(struct Curl_easy *data, if(!ftpc) return CURLE_FAILED_INIT; pp = &ftpc->pp; - /* We always support persistent connections on ftp */ - connkeep(conn, "FTP default"); - PINGPONG_SETUP(pp, ftp_pp_statemachine, ftp_endofresp); if(Curl_conn_is_ssl(conn, FIRSTSOCKET)) { @@ -3224,7 +3178,7 @@ static CURLcode ftp_connect(struct Curl_easy *data, conn->bits.ftp_use_control_ssl = TRUE; } - Curl_pp_init(pp); /* once per transfer */ + Curl_pp_init(pp, Curl_pgrs_now(data)); /* once per transfer */ /* When we connect, we start in the state where we await the 220 response */ @@ -3251,7 +3205,7 @@ static CURLcode ftp_done(struct Curl_easy *data, CURLcode status, struct FTP *ftp = Curl_meta_get(data, CURL_META_FTP_EASY); struct ftp_conn *ftpc = Curl_conn_meta_get(data->conn, CURL_META_FTP_CONN); struct pingpong *pp; - ssize_t nread; + size_t nread; int ftpcode; CURLcode result = CURLE_OK; @@ -3306,7 +3260,7 @@ static CURLcode ftp_done(struct Curl_easy *data, CURLcode status, * the error path) */ ftpc->ctl_valid = FALSE; /* mark control connection as bad */ connclose(conn, "FTP: out of memory!"); /* mark for connection closure */ - free(ftpc->prevpath); + curlx_free(ftpc->prevpath); ftpc->prevpath = NULL; /* no path remembering */ } else { /* remember working directory for connection reuse */ @@ -3317,7 +3271,7 @@ static CURLcode ftp_done(struct Curl_easy *data, CURLcode status, else { size_t pathLen = strlen(ftpc->rawpath); - free(ftpc->prevpath); + curlx_free(ftpc->prevpath); if(!ftpc->cwdfail) { if(data->set.ftp_filemethod == FTPFILE_NOCWD) @@ -3332,15 +3286,11 @@ static CURLcode ftp_done(struct Curl_easy *data, CURLcode status, } } if(ftpc->prevpath) - infof(data, "Remembering we are in dir \"%s\"", ftpc->prevpath); + infof(data, "Remembering we are in directory \"%s\"", ftpc->prevpath); } /* shut down the socket to inform the server we are done */ -#ifdef UNDER_CE - shutdown(conn->sock[SECONDARYSOCKET], 2); /* SD_BOTH */ -#endif - if(Curl_conn_is_setup(conn, SECONDARYSOCKET)) { if(!result && ftpc->dont_check && data->req.maxdownload > 0) { /* partial download completed */ @@ -3364,7 +3314,7 @@ static CURLcode ftp_done(struct Curl_easy *data, CURLcode status, * data has been transferred. This happens when doing through NATs etc that * abandon old silent connections. */ - pp->response = curlx_now(); /* timeout relative now */ + pp->response = *Curl_pgrs_now(data); /* timeout relative now */ result = getftpresponse(data, &nread, &ftpcode); if(!nread && (CURLE_OPERATION_TIMEDOUT == result)) { @@ -3456,10 +3406,9 @@ static CURLcode ftp_done(struct Curl_easy *data, CURLcode status, * * BLOCKING */ -static -CURLcode ftp_sendquote(struct Curl_easy *data, - struct ftp_conn *ftpc, - struct curl_slist *quote) +static CURLcode ftp_sendquote(struct Curl_easy *data, + struct ftp_conn *ftpc, + struct curl_slist *quote) { struct curl_slist *item; struct pingpong *pp = &ftpc->pp; @@ -3467,7 +3416,7 @@ CURLcode ftp_sendquote(struct Curl_easy *data, item = quote; while(item) { if(item->data) { - ssize_t nread; + size_t nread; char *cmd = item->data; bool acceptfail = FALSE; CURLcode result; @@ -3485,7 +3434,7 @@ CURLcode ftp_sendquote(struct Curl_easy *data, result = Curl_pp_sendf(data, &ftpc->pp, "%s", cmd); if(!result) { - pp->response = curlx_now(); /* timeout relative now */ + pp->response = *Curl_pgrs_now(data); /* timeout relative now */ result = getftpresponse(data, &nread, &ftpcode); } if(result) @@ -3606,6 +3555,8 @@ static CURLcode ftp_do_more(struct Curl_easy *data, int *completep) if(conn->cfilter[SECONDARYSOCKET]) { bool is_eptr = Curl_conn_is_tcp_listen(data, SECONDARYSOCKET); result = Curl_conn_connect(data, SECONDARYSOCKET, FALSE, &connected); + if(result == CURLE_OUT_OF_MEMORY) + return result; if(result || (!connected && !is_eptr && !Curl_conn_is_ip_connected(data, SECONDARYSOCKET))) { if(result && !is_eptr && (ftpc->count1 == 0)) { @@ -3735,7 +3686,6 @@ static CURLcode ftp_do_more(struct Curl_easy *data, int *completep) return result; } - /*********************************************************************** * * ftp_perform() @@ -3790,7 +3740,7 @@ static void wc_data_dtor(void *ptr) struct ftp_wc *ftpwc = ptr; if(ftpwc && ftpwc->parser) Curl_ftp_parselist_data_free(&ftpwc->parser); - free(ftpwc); + curlx_free(ftpwc); } static CURLcode init_wc_data(struct Curl_easy *data, @@ -3810,14 +3760,14 @@ static CURLcode init_wc_data(struct Curl_easy *data, wildcard->state = CURLWC_CLEAN; return ftp_parse_url_path(data, ftpc, ftp); } - wildcard->pattern = strdup(last_slash); + wildcard->pattern = curlx_strdup(last_slash); if(!wildcard->pattern) return CURLE_OUT_OF_MEMORY; last_slash[0] = '\0'; /* cut file from path */ } else { /* there is only 'wildcard pattern' or nothing */ if(path[0]) { - wildcard->pattern = strdup(path); + wildcard->pattern = curlx_strdup(path); if(!wildcard->pattern) return CURLE_OUT_OF_MEMORY; path[0] = '\0'; @@ -3832,7 +3782,7 @@ static CURLcode init_wc_data(struct Curl_easy *data, resources for wildcard transfer */ /* allocate ftp protocol specific wildcard data */ - ftpwc = calloc(1, sizeof(struct ftp_wc)); + ftpwc = curlx_calloc(1, sizeof(struct ftp_wc)); if(!ftpwc) { result = CURLE_OUT_OF_MEMORY; goto fail; @@ -3858,7 +3808,7 @@ static CURLcode init_wc_data(struct Curl_easy *data, goto fail; } - wildcard->path = strdup(ftp->path); + wildcard->path = curlx_strdup(ftp->path); if(!wildcard->path) { result = CURLE_OUT_OF_MEMORY; goto fail; @@ -3879,7 +3829,7 @@ static CURLcode init_wc_data(struct Curl_easy *data, fail: if(ftpwc) { Curl_ftp_parselist_data_free(&ftpwc->parser); - free(ftpwc); + curlx_free(ftpwc); } Curl_safefree(wildcard->pattern); wildcard->dtor = ZERO_NULL; @@ -3937,7 +3887,7 @@ static CURLcode wc_statemach(struct Curl_easy *data, return CURLE_OUT_OF_MEMORY; /* switch default ftp->path and tmp_path */ - free(ftp->pathalloc); + curlx_free(ftp->pathalloc); ftp->pathalloc = ftp->path = tmp_path; infof(data, "Wildcard - START of \"%s\"", finfo->filename); @@ -3950,8 +3900,7 @@ static CURLcode wc_statemach(struct Curl_easy *data, Curl_set_in_callback(data, FALSE); switch(userresponse) { case CURL_CHUNK_BGN_FUNC_SKIP: - infof(data, "Wildcard - \"%s\" skipped by user", - finfo->filename); + infof(data, "Wildcard - \"%s\" skipped by user", finfo->filename); wildcard->state = CURLWC_SKIP; continue; case CURL_CHUNK_BGN_FUNC_FAIL: @@ -4167,10 +4116,9 @@ static size_t numof_slashes(const char *str) * Parse the URL path into separate path components. * */ -static -CURLcode ftp_parse_url_path(struct Curl_easy *data, - struct ftp_conn *ftpc, - struct FTP *ftp) +static CURLcode ftp_parse_url_path(struct Curl_easy *data, + struct ftp_conn *ftpc, + struct FTP *ftp) { const char *slashPos = NULL; const char *fileName = NULL; @@ -4192,78 +4140,78 @@ CURLcode ftp_parse_url_path(struct Curl_easy *data, rawPath = ftpc->rawpath; switch(data->set.ftp_filemethod) { - case FTPFILE_NOCWD: /* fastest, but less standard-compliant */ + case FTPFILE_NOCWD: /* fastest, but less standard-compliant */ - if((pathLen > 0) && (rawPath[pathLen - 1] != '/')) - fileName = rawPath; /* this is a full file path */ - /* - else: ftpc->file is not used anywhere other than for operations on - a file. In other words, never for directory operations. - So we can safely leave filename as NULL here and use it as a - argument in dir/file decisions. - */ - break; + if((pathLen > 0) && (rawPath[pathLen - 1] != '/')) + fileName = rawPath; /* this is a full file path */ + /* + else: ftpc->file is not used anywhere other than for operations on + a file. In other words, never for directory operations. + So we can safely leave filename as NULL here and use it as a + argument in dir/file decisions. + */ + break; - case FTPFILE_SINGLECWD: - slashPos = strrchr(rawPath, '/'); - if(slashPos) { - /* get path before last slash, except for / */ - size_t dirlen = slashPos - rawPath; - if(dirlen == 0) - dirlen = 1; - - ftpc->dirs = calloc(1, sizeof(ftpc->dirs[0])); - if(!ftpc->dirs) - return CURLE_OUT_OF_MEMORY; - - ftpc->dirs[0].start = 0; - ftpc->dirs[0].len = (int)dirlen; - ftpc->dirdepth = 1; /* we consider it to be a single dir */ - fileName = slashPos + 1; /* rest is filename */ - } - else - fileName = rawPath; /* filename only (or empty) */ - break; + case FTPFILE_SINGLECWD: + slashPos = strrchr(rawPath, '/'); + if(slashPos) { + /* get path before last slash, except for / */ + size_t dirlen = slashPos - rawPath; + if(dirlen == 0) + dirlen = 1; - default: /* allow pretty much anything */ - case FTPFILE_MULTICWD: { - /* current position: begin of next path component */ - const char *curPos = rawPath; - - /* number of entries to allocate for the 'dirs' array */ - size_t dirAlloc = numof_slashes(rawPath); - - if(dirAlloc >= FTP_MAX_DIR_DEPTH) - /* suspiciously deep dir hierarchy */ - return CURLE_URL_MALFORMAT; - - if(dirAlloc) { - ftpc->dirs = calloc(dirAlloc, sizeof(ftpc->dirs[0])); - if(!ftpc->dirs) - return CURLE_OUT_OF_MEMORY; - - /* parse the URL path into separate path components */ - while(dirAlloc--) { - const char *spos = strchr(curPos, '/'); - size_t clen = spos - curPos; - - /* path starts with a slash: add that as a directory */ - if(!clen && (ftpc->dirdepth == 0)) - ++clen; - - /* we skip empty path components, like "x//y" since the FTP command - CWD requires a parameter and a non-existent parameter a) does not - work on many servers and b) has no effect on the others. */ - if(clen) { - ftpc->dirs[ftpc->dirdepth].start = (int)(curPos - rawPath); - ftpc->dirs[ftpc->dirdepth].len = (int)clen; - ftpc->dirdepth++; - } - curPos = spos + 1; + ftpc->dirs = curlx_calloc(1, sizeof(ftpc->dirs[0])); + if(!ftpc->dirs) + return CURLE_OUT_OF_MEMORY; + + ftpc->dirs[0].start = 0; + ftpc->dirs[0].len = (int)dirlen; + ftpc->dirdepth = 1; /* we consider it to be a single directory */ + fileName = slashPos + 1; /* rest is filename */ + } + else + fileName = rawPath; /* filename only (or empty) */ + break; + + default: /* allow pretty much anything */ + case FTPFILE_MULTICWD: { + /* current position: begin of next path component */ + const char *curPos = rawPath; + + /* number of entries to allocate for the 'dirs' array */ + size_t dirAlloc = numof_slashes(rawPath); + + if(dirAlloc >= FTP_MAX_DIR_DEPTH) + /* suspiciously deep directory hierarchy */ + return CURLE_URL_MALFORMAT; + + if(dirAlloc) { + ftpc->dirs = curlx_calloc(dirAlloc, sizeof(ftpc->dirs[0])); + if(!ftpc->dirs) + return CURLE_OUT_OF_MEMORY; + + /* parse the URL path into separate path components */ + while(dirAlloc--) { + const char *spos = strchr(curPos, '/'); + size_t clen = spos - curPos; + + /* path starts with a slash: add that as a directory */ + if(!clen && (ftpc->dirdepth == 0)) + ++clen; + + /* we skip empty path components, like "x//y" since the FTP command + CWD requires a parameter and a non-existent parameter a) does not + work on many servers and b) has no effect on the others. */ + if(clen) { + ftpc->dirs[ftpc->dirdepth].start = (int)(curPos - rawPath); + ftpc->dirs[ftpc->dirdepth].len = (int)clen; + ftpc->dirdepth++; } + curPos = spos + 1; } - fileName = curPos; /* the rest is the filename (or empty) */ } + fileName = curPos; /* the rest is the filename (or empty) */ + } break; } /* switch */ @@ -4364,20 +4312,16 @@ static CURLcode ftp_doing(struct Curl_easy *data, * ftp->ctl_valid starts out as FALSE, and gets set to TRUE if we reach the * ftp_done() function without finding any major problem. */ -static -CURLcode ftp_regular_transfer(struct Curl_easy *data, - struct ftp_conn *ftpc, - struct FTP *ftp, - bool *dophase_done) +static CURLcode ftp_regular_transfer(struct Curl_easy *data, + struct ftp_conn *ftpc, + struct FTP *ftp, + bool *dophase_done) { CURLcode result = CURLE_OK; bool connected = FALSE; data->req.size = -1; /* make sure this is unknown at this point */ - Curl_pgrsSetUploadCounter(data, 0); - Curl_pgrsSetDownloadCounter(data, 0); - Curl_pgrsSetUploadSize(data, -1); - Curl_pgrsSetDownloadSize(data, -1); + Curl_pgrsReset(data); ftpc->ctl_valid = TRUE; /* starts good */ @@ -4408,7 +4352,7 @@ static void ftp_easy_dtor(void *key, size_t klen, void *entry) (void)key; (void)klen; Curl_safefree(ftp->pathalloc); - free(ftp); + curlx_free(ftp); } static void ftp_conn_dtor(void *key, size_t klen, void *entry) @@ -4423,7 +4367,7 @@ static void ftp_conn_dtor(void *key, size_t klen, void *entry) Curl_safefree(ftpc->prevpath); Curl_safefree(ftpc->server_os); Curl_pp_disconnect(&ftpc->pp); - free(ftpc); + curlx_free(ftpc); } static void type_url_check(struct Curl_easy *data, struct FTP *ftp) @@ -4462,19 +4406,19 @@ static CURLcode ftp_setup_connection(struct Curl_easy *data, CURLcode result = CURLE_OK; struct ftp_conn *ftpc; - ftp = calloc(1, sizeof(*ftp)); + ftp = curlx_calloc(1, sizeof(*ftp)); if(!ftp || Curl_meta_set(data, CURL_META_FTP_EASY, ftp, ftp_easy_dtor)) return CURLE_OUT_OF_MEMORY; - ftpc = calloc(1, sizeof(*ftpc)); + ftpc = curlx_calloc(1, sizeof(*ftpc)); if(!ftpc || Curl_conn_meta_set(conn, CURL_META_FTP_CONN, ftpc, ftp_conn_dtor)) return CURLE_OUT_OF_MEMORY; /* clone connection related data that is FTP specific */ if(data->set.str[STRING_FTP_ACCOUNT]) { - ftpc->account = strdup(data->set.str[STRING_FTP_ACCOUNT]); + ftpc->account = curlx_strdup(data->set.str[STRING_FTP_ACCOUNT]); if(!ftpc->account) { Curl_conn_meta_remove(conn, CURL_META_FTP_CONN); return CURLE_OUT_OF_MEMORY; @@ -4482,7 +4426,7 @@ static CURLcode ftp_setup_connection(struct Curl_easy *data, } if(data->set.str[STRING_FTP_ALTERNATIVE_TO_USER]) { ftpc->alternative_to_user = - strdup(data->set.str[STRING_FTP_ALTERNATIVE_TO_USER]); + curlx_strdup(data->set.str[STRING_FTP_ALTERNATIVE_TO_USER]); if(!ftpc->alternative_to_user) { Curl_safefree(ftpc->account); Curl_conn_meta_remove(conn, CURL_META_FTP_CONN); diff --git a/vendor/hydra/vendor/curl/lib/ftp.h b/vendor/hydra/vendor/curl/lib/ftp.h index 8d5f9c20..0e32d398 100644 --- a/vendor/hydra/vendor/curl/lib/ftp.h +++ b/vendor/hydra/vendor/curl/lib/ftp.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #include "pingpong.h" @@ -61,11 +60,11 @@ enum { FTP_STOR_PREQUOTE, FTP_LIST_PREQUOTE, FTP_POSTQUOTE, - FTP_CWD, /* change dir */ - FTP_MKD, /* if the dir did not exist */ + FTP_CWD, /* change directory */ + FTP_MKD, /* if the directory did not exist */ FTP_MDTM, /* to figure out the datestamp */ FTP_TYPE, /* to set type when doing a head-like request */ - FTP_LIST_TYPE, /* set type when about to do a dir list */ + FTP_LIST_TYPE, /* set type when about to do a directory list */ FTP_RETR_LIST_TYPE, FTP_RETR_TYPE, /* set type when about to RETR a file */ FTP_STOR_TYPE, /* set type when about to STOR a file */ diff --git a/vendor/hydra/vendor/curl/lib/ftplistparser.c b/vendor/hydra/vendor/curl/lib/ftplistparser.c index de573d3c..f82895d5 100644 --- a/vendor/hydra/vendor/curl/lib/ftplistparser.c +++ b/vendor/hydra/vendor/curl/lib/ftplistparser.c @@ -21,6 +21,9 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ +#include "curl_setup.h" + +#ifndef CURL_DISABLE_FTP /** * Now implemented: @@ -37,12 +40,6 @@ * 01-29-97 11:32PM prog */ -#include "curl_setup.h" - -#ifndef CURL_DISABLE_FTP - -#include - #include "urldata.h" #include "fileinfo.h" #include "llist.h" @@ -52,10 +49,6 @@ #include "multiif.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - typedef enum { PL_UNIX_TOTALSIZE = 0, PL_UNIX_FILETYPE, @@ -185,12 +178,10 @@ static void fileinfo_dtor(void *user, void *element) Curl_fileinfo_cleanup(element); } -CURLcode Curl_wildcard_init(struct WildcardData *wc) +void Curl_wildcard_init(struct WildcardData *wc) { Curl_llist_init(&wc->filelist, fileinfo_dtor); wc->state = CURLWC_INIT; - - return CURLE_OK; } void Curl_wildcard_dtor(struct WildcardData **wcp) @@ -207,37 +198,34 @@ void Curl_wildcard_dtor(struct WildcardData **wcp) DEBUGASSERT(wc->ftpwc == NULL); Curl_llist_destroy(&wc->filelist, NULL); - free(wc->path); + curlx_free(wc->path); wc->path = NULL; - free(wc->pattern); + curlx_free(wc->pattern); wc->pattern = NULL; wc->state = CURLWC_INIT; - free(wc); + curlx_free(wc); *wcp = NULL; } struct ftp_parselist_data *Curl_ftp_parselist_data_alloc(void) { - return calloc(1, sizeof(struct ftp_parselist_data)); + return curlx_calloc(1, sizeof(struct ftp_parselist_data)); } - void Curl_ftp_parselist_data_free(struct ftp_parselist_data **parserp) { struct ftp_parselist_data *parser = *parserp; if(parser) Curl_fileinfo_cleanup(parser->file_data); - free(parser); + curlx_free(parser); *parserp = NULL; } - CURLcode Curl_ftp_parselist_geterror(struct ftp_parselist_data *pl_data) { return pl_data->error; } - #define FTP_LP_MALFORMATED_PERM 0x01000000 static unsigned int ftp_pl_get_permission(const char *str) @@ -290,7 +278,7 @@ static unsigned int ftp_pl_get_permission(const char *str) if(str[7] == 'w') permissions |= 1 << 1; else if(str[7] != '-') - permissions |= FTP_LP_MALFORMATED_PERM; + permissions |= FTP_LP_MALFORMATED_PERM; if(str[8] == 'x') permissions |= 1; else if(str[8] == 't') { @@ -436,7 +424,6 @@ static CURLcode parse_unix_totalsize(struct ftp_parselist_data *parser, } else return CURLE_FTP_BAD_FILE_LIST; - } break; } @@ -493,7 +480,7 @@ static CURLcode parse_unix_hlinks(struct ftp_parselist_data *parser, } break; case PL_UNIX_HLINKS_NUMBER: - parser->item_length ++; + parser->item_length++; if(c == ' ') { const char *p = &mem[parser->item_offset]; curl_off_t hlinks; @@ -629,7 +616,7 @@ static CURLcode parse_unix_time(struct ftp_parselist_data *parser, case PL_UNIX_TIME_PREPART1: if(c != ' ') { if(ISALNUM(c) && len) { - parser->item_offset = len -1; + parser->item_offset = len - 1; parser->item_length = 1; parser->state.UNIX.sub.time = PL_UNIX_TIME_PART1; } @@ -674,7 +661,7 @@ static CURLcode parse_unix_time(struct ftp_parselist_data *parser, case PL_UNIX_TIME_PART3: parser->item_length++; if(c == ' ') { - mem[parser->item_offset + parser->item_length -1] = 0; + mem[parser->item_offset + parser->item_length - 1] = 0; parser->offsets.time = parser->item_offset; if(finfo->filetype == CURLFILETYPE_SYMLINK) { parser->state.UNIX.main = PL_UNIX_SYMLINK; @@ -930,7 +917,7 @@ static CURLcode parse_winnt(struct Curl_easy *data, case PL_WINNT_TIME_TIME: if(c == ' ') { parser->offsets.time = parser->item_offset; - mem[parser->item_offset + parser->item_length -1] = 0; + mem[parser->item_offset + parser->item_length - 1] = 0; parser->state.NT.main = PL_WINNT_DIRORSIZE; parser->state.NT.sub.dirorsize = PL_WINNT_DIRORSIZE_PRESPACE; parser->item_length = 0; @@ -950,7 +937,7 @@ static CURLcode parse_winnt(struct Curl_easy *data, } break; case PL_WINNT_DIRORSIZE_CONTENT: - parser->item_length ++; + parser->item_length++; if(c == ' ') { mem[parser->item_offset + parser->item_length - 1] = 0; if(strcmp("", mem + parser->item_offset) == 0) { @@ -978,7 +965,7 @@ static CURLcode parse_winnt(struct Curl_easy *data, switch(parser->state.NT.sub.filename) { case PL_WINNT_FILENAME_PRESPACE: if(c != ' ' && len) { - parser->item_offset = len -1; + parser->item_offset = len - 1; parser->item_length = 1; parser->state.NT.sub.filename = PL_WINNT_FILENAME_CONTENT; } @@ -1026,7 +1013,7 @@ static CURLcode parse_winnt(struct Curl_easy *data, size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb, void *connptr) { - size_t bufflen = size*nmemb; + size_t bufflen = size * nmemb; struct Curl_easy *data = (struct Curl_easy *)connptr; struct ftp_wc *ftpwc = data->wildcard->ftpwc; struct ftp_parselist_data *parser = ftpwc->parser; @@ -1101,4 +1088,4 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb, return retsize; } -#endif /* CURL_DISABLE_FTP */ +#endif /* !CURL_DISABLE_FTP */ diff --git a/vendor/hydra/vendor/curl/lib/ftplistparser.h b/vendor/hydra/vendor/curl/lib/ftplistparser.h index 5ba1f6a9..afb90dee 100644 --- a/vendor/hydra/vendor/curl/lib/ftplistparser.h +++ b/vendor/hydra/vendor/curl/lib/ftplistparser.h @@ -65,13 +65,13 @@ struct WildcardData { unsigned char state; /* wildcard_states */ }; -CURLcode Curl_wildcard_init(struct WildcardData *wc); +void Curl_wildcard_init(struct WildcardData *wc); void Curl_wildcard_dtor(struct WildcardData **wcp); struct Curl_easy; -#else -/* FTP is disabled */ +#else /* CURL_DISABLE_FTP */ #define Curl_wildcard_dtor(x) -#endif /* CURL_DISABLE_FTP */ +#endif /* !CURL_DISABLE_FTP */ + #endif /* HEADER_CURL_FTPLISTPARSER_H */ diff --git a/vendor/hydra/vendor/curl/lib/functypes.h b/vendor/hydra/vendor/curl/lib/functypes.h index b4dccc0c..ba754f99 100644 --- a/vendor/hydra/vendor/curl/lib/functypes.h +++ b/vendor/hydra/vendor/curl/lib/functypes.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" /* defaults: @@ -68,7 +67,6 @@ #define SEND_TYPE_RETV int #endif - #ifndef RECV_TYPE_ARG1 #define RECV_TYPE_ARG1 int #endif diff --git a/vendor/hydra/vendor/curl/lib/getenv.c b/vendor/hydra/vendor/curl/lib/getenv.c index 3bfcf707..a957e6e8 100644 --- a/vendor/hydra/vendor/curl/lib/getenv.c +++ b/vendor/hydra/vendor/curl/lib/getenv.c @@ -21,17 +21,11 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include -#include "curl_memory.h" - -#include "memdebug.h" - -static char *GetEnv(const char *variable) +char *curl_getenv(const char *variable) { -#if defined(CURL_WINDOWS_UWP) || defined(UNDER_CE) || \ +#if defined(CURL_WINDOWS_UWP) || \ defined(__ORBIS__) || defined(__PROSPERO__) /* PlayStation 4 and 5 */ (void)variable; return NULL; @@ -45,9 +39,9 @@ static char *GetEnv(const char *variable) const DWORD max = 32768; /* max env var size from MSCRT source */ for(;;) { - tmp = realloc(buf, rc); + tmp = curlx_realloc(buf, rc); if(!tmp) { - free(buf); + curlx_free(buf); return NULL; } @@ -58,7 +52,7 @@ static char *GetEnv(const char *variable) Since getenv does not make that distinction we ignore it as well. */ rc = GetEnvironmentVariableA(variable, buf, bufsize); if(!rc || rc == bufsize || rc > max) { - free(buf); + curlx_free(buf); return NULL; } @@ -70,11 +64,6 @@ static char *GetEnv(const char *variable) } #else char *env = getenv(variable); - return (env && env[0]) ? strdup(env) : NULL; + return (env && env[0]) ? curlx_strdup(env) : NULL; #endif } - -char *curl_getenv(const char *v) -{ - return GetEnv(v); -} diff --git a/vendor/hydra/vendor/curl/lib/getinfo.c b/vendor/hydra/vendor/curl/lib/getinfo.c index e2a8231d..e094ffd1 100644 --- a/vendor/hydra/vendor/curl/lib/getinfo.c +++ b/vendor/hydra/vendor/curl/lib/getinfo.c @@ -21,23 +21,16 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include - #include "urldata.h" #include "getinfo.h" #include "cfilters.h" #include "vtls/vtls.h" #include "connect.h" /* Curl_getconnectinfo() */ -#include "progress.h" +#include "bufref.h" #include "curlx/strparse.h" -/* The last #include files should be: */ -#include "curl_memory.h" -#include "memdebug.h" - /* * Initialize statistical and informational data. * @@ -45,7 +38,7 @@ * beginning of a perform session. It must reset the session-info variables, * in particular all variables in struct PureInfo. */ -CURLcode Curl_initinfo(struct Curl_easy *data) +void Curl_initinfo(struct Curl_easy *data) { struct Progress *pro = &data->progress; struct PureInfo *info = &data->info; @@ -74,15 +67,13 @@ CURLcode Curl_initinfo(struct Curl_easy *data) info->httpauthpicked = 0; info->numconnects = 0; - free(info->contenttype); + curlx_free(info->contenttype); info->contenttype = NULL; - free(info->wouldredirect); + curlx_free(info->wouldredirect); info->wouldredirect = NULL; memset(&info->primary, 0, sizeof(info->primary)); - info->primary.remote_port = -1; - info->primary.local_port = -1; info->retry_after = 0; info->conn_scheme = 0; @@ -91,15 +82,16 @@ CURLcode Curl_initinfo(struct Curl_easy *data) #ifdef USE_SSL Curl_ssl_free_certinfo(data); #endif - return CURLE_OK; } static CURLcode getinfo_char(struct Curl_easy *data, CURLINFO info, const char **param_charp) { switch(info) { - case CURLINFO_EFFECTIVE_URL: - *param_charp = data->state.url ? data->state.url : ""; + case CURLINFO_EFFECTIVE_URL: { + const char *s = Curl_bufref_ptr(&data->state.url); + *param_charp = s ? s : ""; + } break; case CURLINFO_EFFECTIVE_METHOD: { const char *m = data->set.str[STRING_CUSTOMREQUEST]; @@ -135,12 +127,12 @@ static CURLcode getinfo_char(struct Curl_easy *data, CURLINFO info, *param_charp = data->info.contenttype; break; case CURLINFO_PRIVATE: - *param_charp = (char *) data->set.private_data; + *param_charp = (char *)data->set.private_data; break; case CURLINFO_FTP_ENTRY_PATH: /* Return the entrypath string from the most recent connection. This pointer was copied from the connectdata structure by FTP. - The actual string may be free()ed by subsequent libcurl calls so + The actual string may be freed by subsequent libcurl calls so it must be copied to a safer area before the next libcurl call. Callers must never free it themselves. */ *param_charp = data->state.most_recent_ftp_entrypath; @@ -152,7 +144,7 @@ static CURLcode getinfo_char(struct Curl_easy *data, CURLINFO info, break; case CURLINFO_REFERER: /* Return the referrer header for this request, or NULL if unset */ - *param_charp = data->state.referer; + *param_charp = Curl_bufref_ptr(&data->state.referer); break; case CURLINFO_PRIMARY_IP: /* Return the ip address of the most recent (primary) connection */ @@ -205,31 +197,31 @@ static CURLcode getinfo_long(struct Curl_easy *data, CURLINFO info, } lptr; #ifdef DEBUGBUILD - const char *timestr = getenv("CURL_TIME"); - if(timestr) { - curl_off_t val; - curlx_str_number(×tr, &val, TIME_T_MAX); - switch(info) { - case CURLINFO_LOCAL_PORT: + const char *envstr; + + /* use another variable for this to allow different values */ + switch(info) { + case CURLINFO_LOCAL_PORT: + envstr = getenv("CURL_TIME"); + if(envstr) { + curl_off_t val; + curlx_str_number(&envstr, &val, TIME_T_MAX); *param_longp = (long)val; return CURLE_OK; - default: - break; } - } - /* use another variable for this to allow different values */ - timestr = getenv("CURL_DEBUG_SIZE"); - if(timestr) { - curl_off_t val; - curlx_str_number(×tr, &val, LONG_MAX); - switch(info) { - case CURLINFO_HEADER_SIZE: - case CURLINFO_REQUEST_SIZE: + break; + case CURLINFO_HEADER_SIZE: + case CURLINFO_REQUEST_SIZE: + envstr = getenv("CURL_DEBUG_SIZE"); + if(envstr) { + curl_off_t val; + curlx_str_number(&envstr, &val, LONG_MAX); *param_longp = (long)val; return CURLE_OK; - default: - break; } + break; + default: + break; } #endif @@ -305,11 +297,17 @@ static CURLcode getinfo_long(struct Curl_easy *data, CURLINFO info, break; case CURLINFO_PRIMARY_PORT: /* Return the (remote) port of the most recent (primary) connection */ - *param_longp = data->info.primary.remote_port; + if(CUR_IP_QUAD_HAS_PORTS(&data->info.primary)) + *param_longp = data->info.primary.remote_port; + else + *param_longp = -1; break; case CURLINFO_LOCAL_PORT: /* Return the local port of the most recent (primary) connection */ - *param_longp = data->info.primary.local_port; + if(CUR_IP_QUAD_HAS_PORTS(&data->info.primary)) + *param_longp = data->info.primary.local_port; + else + *param_longp = -1; break; case CURLINFO_PROXY_ERROR: *param_longp = (long)data->info.pxcode; @@ -376,34 +374,35 @@ static CURLcode getinfo_long(struct Curl_easy *data, CURLINFO info, return CURLE_OK; } -#define DOUBLE_SECS(x) (double)(x)/1000000 +#define DOUBLE_SECS(x) (double)(x) / 1000000 static CURLcode getinfo_offt(struct Curl_easy *data, CURLINFO info, curl_off_t *param_offt) { #ifdef DEBUGBUILD - const char *timestr = getenv("CURL_TIME"); - if(timestr) { - curl_off_t val; - curlx_str_number(×tr, &val, CURL_OFF_T_MAX); - - switch(info) { - case CURLINFO_TOTAL_TIME_T: - case CURLINFO_NAMELOOKUP_TIME_T: - case CURLINFO_CONNECT_TIME_T: - case CURLINFO_APPCONNECT_TIME_T: - case CURLINFO_PRETRANSFER_TIME_T: - case CURLINFO_POSTTRANSFER_TIME_T: - case CURLINFO_QUEUE_TIME_T: - case CURLINFO_STARTTRANSFER_TIME_T: - case CURLINFO_REDIRECT_TIME_T: - case CURLINFO_SPEED_DOWNLOAD_T: - case CURLINFO_SPEED_UPLOAD_T: + const char *envstr; + switch(info) { + case CURLINFO_TOTAL_TIME_T: + case CURLINFO_NAMELOOKUP_TIME_T: + case CURLINFO_CONNECT_TIME_T: + case CURLINFO_APPCONNECT_TIME_T: + case CURLINFO_PRETRANSFER_TIME_T: + case CURLINFO_POSTTRANSFER_TIME_T: + case CURLINFO_QUEUE_TIME_T: + case CURLINFO_STARTTRANSFER_TIME_T: + case CURLINFO_REDIRECT_TIME_T: + case CURLINFO_SPEED_DOWNLOAD_T: + case CURLINFO_SPEED_UPLOAD_T: + envstr = getenv("CURL_TIME"); + if(envstr) { + curl_off_t val; + curlx_str_number(&envstr, &val, CURL_OFF_T_MAX); *param_offt = (curl_off_t)val; return CURLE_OK; - default: - break; } + break; + default: + break; } #endif switch(info) { @@ -481,26 +480,28 @@ static CURLcode getinfo_double(struct Curl_easy *data, CURLINFO info, double *param_doublep) { #ifdef DEBUGBUILD - const char *timestr = getenv("CURL_TIME"); - if(timestr) { - curl_off_t val; - curlx_str_number(×tr, &val, CURL_OFF_T_MAX); - - switch(info) { - case CURLINFO_TOTAL_TIME: - case CURLINFO_NAMELOOKUP_TIME: - case CURLINFO_CONNECT_TIME: - case CURLINFO_APPCONNECT_TIME: - case CURLINFO_PRETRANSFER_TIME: - case CURLINFO_STARTTRANSFER_TIME: - case CURLINFO_REDIRECT_TIME: - case CURLINFO_SPEED_DOWNLOAD: - case CURLINFO_SPEED_UPLOAD: + const char *envstr; + + switch(info) { + case CURLINFO_TOTAL_TIME: + case CURLINFO_NAMELOOKUP_TIME: + case CURLINFO_CONNECT_TIME: + case CURLINFO_APPCONNECT_TIME: + case CURLINFO_PRETRANSFER_TIME: + case CURLINFO_STARTTRANSFER_TIME: + case CURLINFO_REDIRECT_TIME: + case CURLINFO_SPEED_DOWNLOAD: + case CURLINFO_SPEED_UPLOAD: + envstr = getenv("CURL_TIME"); + if(envstr) { + curl_off_t val; + curlx_str_number(&envstr, &val, CURL_OFF_T_MAX); *param_doublep = (double)val; return CURLE_OK; - default: - break; } + break; + default: + break; } #endif switch(info) { @@ -575,20 +576,19 @@ static CURLcode getinfo_slist(struct Curl_easy *data, CURLINFO info, *param_slistp = ptr.to_slist; break; case CURLINFO_TLS_SESSION: - case CURLINFO_TLS_SSL_PTR: - { - struct curl_tlssessioninfo **tsip = (struct curl_tlssessioninfo **) - param_slistp; - struct curl_tlssessioninfo *tsi = &data->tsi; - - /* we are exposing a pointer to internal memory with unknown - * lifetime here. */ - *tsip = tsi; - if(!Curl_conn_get_ssl_info(data, data->conn, FIRSTSOCKET, tsi)) { - tsi->backend = Curl_ssl_backend(); - tsi->internals = NULL; - } + case CURLINFO_TLS_SSL_PTR: { + struct curl_tlssessioninfo **tsip = (struct curl_tlssessioninfo **) + param_slistp; + struct curl_tlssessioninfo *tsi = &data->tsi; + + /* we are exposing a pointer to internal memory with unknown + * lifetime here. */ + *tsip = tsi; + if(!Curl_conn_get_ssl_info(data, data->conn, FIRSTSOCKET, tsi)) { + tsi->backend = Curl_ssl_backend(); + tsi->internals = NULL; } + } break; default: return CURLE_UNKNOWN_OPTION; diff --git a/vendor/hydra/vendor/curl/lib/getinfo.h b/vendor/hydra/vendor/curl/lib/getinfo.h index 56bb440b..f5efe418 100644 --- a/vendor/hydra/vendor/curl/lib/getinfo.h +++ b/vendor/hydra/vendor/curl/lib/getinfo.h @@ -24,6 +24,6 @@ * ***************************************************************************/ CURLcode Curl_getinfo(struct Curl_easy *data, CURLINFO info, ...); -CURLcode Curl_initinfo(struct Curl_easy *data); +void Curl_initinfo(struct Curl_easy *data); #endif /* HEADER_CURL_GETINFO_H */ diff --git a/vendor/hydra/vendor/curl/lib/gopher.c b/vendor/hydra/vendor/curl/lib/gopher.c index 3a6c73e6..186530de 100644 --- a/vendor/hydra/vendor/curl/lib/gopher.c +++ b/vendor/hydra/vendor/curl/lib/gopher.c @@ -21,28 +21,20 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifndef CURL_DISABLE_GOPHER #include "urldata.h" -#include #include "transfer.h" #include "sendf.h" +#include "curl_trc.h" #include "cfilters.h" #include "connect.h" -#include "progress.h" #include "gopher.h" #include "select.h" -#include "vtls/vtls.h" #include "url.h" #include "escape.h" -#include "curlx/warnless.h" - -/* The last 2 #include files should be: */ -#include "curl_memory.h" -#include "memdebug.h" /* * Forward declarations. @@ -139,11 +131,10 @@ static CURLcode gopher_do(struct Curl_easy *data, bool *done) char *gopherpath; char *path = data->state.up.path; char *query = data->state.up.query; - char *sel = NULL; - char *sel_org = NULL; + const char *buf = NULL; + char *buf_alloc = NULL; + size_t nwritten, buf_len; timediff_t timeout_ms; - ssize_t k; - size_t amount, len; int what; *done = TRUE; /* unconditionally */ @@ -154,16 +145,16 @@ static CURLcode gopher_do(struct Curl_easy *data, bool *done) if(query) gopherpath = curl_maprintf("%s?%s", path, query); else - gopherpath = strdup(path); + gopherpath = curlx_strdup(path); if(!gopherpath) return CURLE_OUT_OF_MEMORY; /* Create selector. Degenerate cases: / and /1 => convert to "" */ if(strlen(gopherpath) <= 2) { - sel = (char *)CURL_UNCONST(""); - len = strlen(sel); - free(gopherpath); + buf = ""; + buf_len = 0; + curlx_free(gopherpath); } else { char *newp; @@ -173,36 +164,34 @@ static CURLcode gopher_do(struct Curl_easy *data, bool *done) newp += 2; /* ... and finally unescape */ - result = Curl_urldecode(newp, 0, &sel, &len, REJECT_ZERO); - free(gopherpath); + result = Curl_urldecode(newp, 0, &buf_alloc, &buf_len, REJECT_ZERO); + curlx_free(gopherpath); if(result) return result; - sel_org = sel; + buf = buf_alloc; } - k = curlx_uztosz(len); + for(; buf_len;) { - for(;;) { - /* Break out of the loop if the selector is empty because OpenSSL and/or - LibreSSL fail with errno 0 if this is the case. */ - if(strlen(sel) < 1) - break; - - result = Curl_xfer_send(data, sel, k, FALSE, &amount); + result = Curl_xfer_send(data, buf, buf_len, FALSE, &nwritten); if(!result) { /* Which may not have written it all! */ - result = Curl_client_write(data, CLIENTWRITE_HEADER, sel, amount); + result = Curl_client_write(data, CLIENTWRITE_HEADER, buf, nwritten); if(result) break; - k -= amount; - sel += amount; - if(k < 1) + if(nwritten > buf_len) { + DEBUGASSERT(0); + break; + } + buf_len -= nwritten; + buf += nwritten; + if(!buf_len) break; /* but it did write it all */ } else break; - timeout_ms = Curl_timeleft(data, NULL, FALSE); + timeout_ms = Curl_timeleft_ms(data, FALSE); if(timeout_ms < 0) { result = CURLE_OPERATION_TIMEDOUT; break; @@ -227,10 +216,10 @@ static CURLcode gopher_do(struct Curl_easy *data, bool *done) } } - free(sel_org); + curlx_free(buf_alloc); if(!result) - result = Curl_xfer_send(data, "\r\n", 2, FALSE, &amount); + result = Curl_xfer_send(data, "\r\n", 2, FALSE, &nwritten); if(result) { failf(data, "Failed sending Gopher request"); return result; diff --git a/vendor/hydra/vendor/curl/lib/gopher.h b/vendor/hydra/vendor/curl/lib/gopher.h index 9e3365b7..1e6a5d2d 100644 --- a/vendor/hydra/vendor/curl/lib/gopher.h +++ b/vendor/hydra/vendor/curl/lib/gopher.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #ifndef CURL_DISABLE_GOPHER extern const struct Curl_handler Curl_handler_gopher; #ifdef USE_SSL diff --git a/vendor/hydra/vendor/curl/lib/hash.c b/vendor/hydra/vendor/curl/lib/hash.c index 8312fbf0..0b6ecc48 100644 --- a/vendor/hydra/vendor/curl/lib/hash.c +++ b/vendor/hydra/vendor/curl/lib/hash.c @@ -21,17 +21,9 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include - #include "hash.h" -#include "llist.h" -#include "curl_memory.h" - -/* The last #include file should be: */ -#include "memdebug.h" /* random patterns for API verification */ #ifdef DEBUGBUILD @@ -39,10 +31,8 @@ #define ITERINIT 0x5FEDCBA9 #endif - #if 0 /* useful function for debugging hashes and their contents */ -void Curl_hash_print(struct Curl_hash *h, - void (*func)(void *)) +void Curl_hash_print(struct Curl_hash *h, void (*func)(void *)) { struct Curl_hash_iterator iter; struct Curl_hash_element *he; @@ -84,12 +74,11 @@ void Curl_hash_print(struct Curl_hash *h, * @unittest: 1602 * @unittest: 1603 */ -void -Curl_hash_init(struct Curl_hash *h, - size_t slots, - hash_function hfunc, - comp_function comparator, - Curl_hash_dtor dtor) +void Curl_hash_init(struct Curl_hash *h, + size_t slots, + hash_function hfunc, + comp_function comparator, + Curl_hash_dtor dtor) { DEBUGASSERT(h); DEBUGASSERT(slots); @@ -108,14 +97,15 @@ Curl_hash_init(struct Curl_hash *h, #endif } -static struct Curl_hash_element * -hash_elem_create(const void *key, size_t key_len, const void *p, - Curl_hash_elem_dtor dtor) +static struct Curl_hash_element *hash_elem_create(const void *key, + size_t key_len, + const void *p, + Curl_hash_elem_dtor dtor) { struct Curl_hash_element *he; /* allocate the struct plus memory after it to store the key */ - he = malloc(sizeof(struct Curl_hash_element) + key_len); + he = curlx_malloc(sizeof(struct Curl_hash_element) + key_len); if(he) { he->next = NULL; /* copy the key */ @@ -145,7 +135,7 @@ static void hash_elem_destroy(struct Curl_hash *h, struct Curl_hash_element *he) { hash_elem_clear_ptr(h, he); - free(he); + curlx_free(he); } static void hash_elem_unlink(struct Curl_hash *h, @@ -165,8 +155,8 @@ static void hash_elem_link(struct Curl_hash *h, ++h->size; } -#define CURL_HASH_SLOT(x,y,z) x->table[x->hash_func(y, z, x->slots)] -#define CURL_HASH_SLOT_ADDR(x,y,z) &CURL_HASH_SLOT(x,y,z) +#define CURL_HASH_SLOT(x, y, z) x->table[x->hash_func(y, z, x->slots)] +#define CURL_HASH_SLOT_ADDR(x, y, z) &CURL_HASH_SLOT(x, y, z) void *Curl_hash_add2(struct Curl_hash *h, void *key, size_t key_len, void *p, Curl_hash_elem_dtor dtor) @@ -177,7 +167,7 @@ void *Curl_hash_add2(struct Curl_hash *h, void *key, size_t key_len, void *p, DEBUGASSERT(h->slots); DEBUGASSERT(h->init == HASHINIT); if(!h->table) { - h->table = calloc(h->slots, sizeof(struct Curl_hash_element *)); + h->table = curlx_calloc(h->slots, sizeof(struct Curl_hash_element *)); if(!h->table) return NULL; /* OOM */ } @@ -209,8 +199,7 @@ void *Curl_hash_add2(struct Curl_hash *h, void *key, size_t key_len, void *p, * @unittest: 1602 * @unittest: 1603 */ -void * -Curl_hash_add(struct Curl_hash *h, void *key, size_t key_len, void *p) +void *Curl_hash_add(struct Curl_hash *h, void *key, size_t key_len, void *p) { return Curl_hash_add2(h, key, key_len, p, NULL); } @@ -246,8 +235,7 @@ int Curl_hash_delete(struct Curl_hash *h, void *key, size_t key_len) * * @unittest: 1603 */ -void * -Curl_hash_pick(struct Curl_hash *h, void *key, size_t key_len) +void *Curl_hash_pick(struct Curl_hash *h, void *key, size_t key_len) { DEBUGASSERT(h); DEBUGASSERT(h->init == HASHINIT); @@ -272,8 +260,7 @@ Curl_hash_pick(struct Curl_hash *h, void *key, size_t key_len) * @unittest: 1602 * @unittest: 1603 */ -void -Curl_hash_destroy(struct Curl_hash *h) +void Curl_hash_destroy(struct Curl_hash *h) { DEBUGASSERT(h->init == HASHINIT); if(h->table) { @@ -312,9 +299,8 @@ size_t Curl_hash_count(struct Curl_hash *h) } /* Cleans all entries that pass the comp function criteria. */ -void -Curl_hash_clean_with_criterium(struct Curl_hash *h, void *user, - int (*comp)(void *, void *)) +void Curl_hash_clean_with_criterium(struct Curl_hash *h, void *user, + int (*comp)(void *, void *)) { size_t i; @@ -339,7 +325,7 @@ Curl_hash_clean_with_criterium(struct Curl_hash *h, void *user, size_t Curl_hash_str(void *key, size_t key_length, size_t slots_num) { - const char *key_str = (const char *) key; + const char *key_str = (const char *)key; const char *end = key_str + key_length; size_t h = 5381; diff --git a/vendor/hydra/vendor/curl/lib/hash.h b/vendor/hydra/vendor/curl/lib/hash.h index fcd92db6..8bf47ccf 100644 --- a/vendor/hydra/vendor/curl/lib/hash.h +++ b/vendor/hydra/vendor/curl/lib/hash.h @@ -23,25 +23,20 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include - -#include "llist.h" - /* Hash function prototype */ -typedef size_t (*hash_function) (void *key, - size_t key_length, - size_t slots_num); +typedef size_t (*hash_function)(void *key, + size_t key_length, + size_t slots_num); /* Comparator function prototype. Compares two keys. */ -typedef size_t (*comp_function) (void *key1, - size_t key1_len, - void *key2, - size_t key2_len); +typedef size_t (*comp_function)(void *key1, + size_t key1_len, + void *key2, + size_t key2_len); typedef void (*Curl_hash_dtor)(void *); @@ -49,10 +44,10 @@ typedef void (*Curl_hash_elem_dtor)(void *key, size_t key_len, void *p); struct Curl_hash_element { struct Curl_hash_element *next; - void *ptr; + void *ptr; Curl_hash_elem_dtor dtor; size_t key_len; - char key[1]; /* allocated memory following the struct */ + char key[1]; /* allocated memory following the struct */ }; struct Curl_hash { @@ -63,7 +58,7 @@ struct Curl_hash { /* Comparator function to compare keys */ comp_function comp_func; /* General element construct, unless element itself carries one */ - Curl_hash_dtor dtor; + Curl_hash_dtor dtor; size_t slots; size_t size; #ifdef DEBUGBUILD @@ -105,7 +100,6 @@ void Curl_hash_start_iterate(struct Curl_hash *hash, struct Curl_hash_element * Curl_hash_next_element(struct Curl_hash_iterator *iter); -void Curl_hash_print(struct Curl_hash *h, - void (*func)(void *)); +void Curl_hash_print(struct Curl_hash *h, void (*func)(void *)); #endif /* HEADER_CURL_HASH_H */ diff --git a/vendor/hydra/vendor/curl/lib/headers.c b/vendor/hydra/vendor/curl/lib/headers.c index 5a572571..c1880453 100644 --- a/vendor/hydra/vendor/curl/lib/headers.c +++ b/vendor/hydra/vendor/curl/lib/headers.c @@ -21,18 +21,12 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #include "urldata.h" -#include "strdup.h" #include "sendf.h" +#include "curl_trc.h" #include "headers.h" -#include "curlx/strparse.h" - -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_HEADERS_API) @@ -51,7 +45,7 @@ static void copy_header_external(struct Curl_header_store *hs, h->index = index; /* this will randomly OR a reserved bit for the sole purpose of making it impossible for applications to do == comparisons, as that would otherwise - be very tempting and then lead to the reserved bits not being reserved + be tempting and then lead to the reserved bits not being reserved anymore. */ h->origin = (unsigned int)(hs->type | (1 << 27)); h->anchor = e; @@ -73,7 +67,7 @@ CURLHcode curl_easy_header(CURL *easy, struct Curl_header_store *hs = NULL; struct Curl_header_store *pick = NULL; if(!name || !hout || !data || - (type > (CURLH_HEADER|CURLH_TRAILER|CURLH_CONNECT|CURLH_1XX| + (type > (CURLH_HEADER | CURLH_TRAILER | CURLH_CONNECT | CURLH_1XX | CURLH_PSEUDO)) || !type || (request < -1)) return CURLHE_BAD_ARGUMENT; if(!Curl_llist_count(&data->state.httphdrs)) @@ -219,97 +213,42 @@ static CURLcode namevalue(char *header, size_t hlen, unsigned int type, return CURLE_OK; } -static CURLcode unfold_value(struct Curl_easy *data, const char *value, - size_t vlen) /* length of the incoming header */ -{ - struct Curl_header_store *hs; - struct Curl_header_store *newhs; - size_t olen; /* length of the old value */ - size_t oalloc; /* length of the old name + value + separator */ - size_t offset; - DEBUGASSERT(data->state.prevhead); - hs = data->state.prevhead; - olen = strlen(hs->value); - offset = hs->value - hs->buffer; - oalloc = olen + offset + 1; - - /* skip all trailing space letters */ - while(vlen && ISBLANK(value[vlen - 1])) - vlen--; - - /* save only one leading space */ - while((vlen > 1) && ISBLANK(value[0]) && ISBLANK(value[1])) { - vlen--; - value++; - } - - /* since this header block might move in the realloc below, it needs to - first be unlinked from the list and then re-added again after the - realloc */ - Curl_node_remove(&hs->node); - - /* new size = struct + new value length + old name+value length */ - newhs = Curl_saferealloc(hs, sizeof(*hs) + vlen + oalloc + 1); - if(!newhs) - return CURLE_OUT_OF_MEMORY; - /* ->name and ->value point into ->buffer (to keep the header allocation - in a single memory block), which now potentially have moved. Adjust - them. */ - newhs->name = newhs->buffer; - newhs->value = &newhs->buffer[offset]; - - /* put the data at the end of the previous data, not the newline */ - memcpy(&newhs->value[olen], value, vlen); - newhs->value[olen + vlen] = 0; /* null-terminate at newline */ - - /* insert this node into the list of headers */ - Curl_llist_append(&data->state.httphdrs, newhs, &newhs->node); - data->state.prevhead = newhs; - return CURLE_OK; -} - - /* * Curl_headers_push() gets passed a full HTTP header to store. It gets called - * immediately before the header callback. The header is CRLF terminated. + * immediately before the header callback. The header is CRLF, CR or LF + * terminated. */ CURLcode Curl_headers_push(struct Curl_easy *data, const char *header, + size_t hlen, /* length of header */ unsigned char type) { char *value = NULL; char *name = NULL; - char *end; - size_t hlen; /* length of the incoming header */ struct Curl_header_store *hs; CURLcode result = CURLE_OUT_OF_MEMORY; + const size_t ilen = hlen; if((header[0] == '\r') || (header[0] == '\n')) /* ignore the body separator */ return CURLE_OK; - end = strchr(header, '\r'); - if(!end) { - end = strchr(header, '\n'); - if(!end) - /* neither CR nor LF as terminator is not a valid header */ - return CURLE_WEIRD_SERVER_REPLY; - } - hlen = end - header; - - if((header[0] == ' ') || (header[0] == '\t')) { - if(data->state.prevhead) - /* line folding, append value to the previous header's value */ - return unfold_value(data, header, hlen); - else { - /* cannot unfold without a previous header. Instead of erroring, just - pass the leading blanks. */ - while(hlen && ISBLANK(*header)) { - header++; - hlen--; - } - if(!hlen) - return CURLE_WEIRD_SERVER_REPLY; + /* trim off newline characters */ + if(hlen && (header[hlen - 1] == '\n')) + hlen--; + if(hlen && (header[hlen - 1] == '\r')) + hlen--; + if(hlen == ilen) + /* neither CR nor LF as terminator is not a valid header */ + return CURLE_WEIRD_SERVER_REPLY; + + if(ISBLANK(header[0])) { + /* pass leading blanks */ + while(hlen && ISBLANK(*header)) { + header++; + hlen--; } + if(!hlen) + return CURLE_WEIRD_SERVER_REPLY; } if(Curl_llist_count(&data->state.httphdrs) >= MAX_HTTP_RESP_HEADER_COUNT) { failf(data, "Too many response headers, %d is max", @@ -317,7 +256,7 @@ CURLcode Curl_headers_push(struct Curl_easy *data, const char *header, return CURLE_TOO_LARGE; } - hs = calloc(1, sizeof(*hs) + hlen); + hs = curlx_calloc(1, sizeof(*hs) + hlen); if(!hs) return CURLE_OUT_OF_MEMORY; memcpy(hs->buffer, header, hlen); @@ -336,7 +275,7 @@ CURLcode Curl_headers_push(struct Curl_easy *data, const char *header, } else { failf(data, "Invalid response header"); - free(hs); + curlx_free(hs); } return result; } @@ -364,7 +303,7 @@ static CURLcode hds_cw_collect_write(struct Curl_easy *data, (type & CLIENTWRITE_1XX ? CURLH_1XX : (type & CLIENTWRITE_TRAILER ? CURLH_TRAILER : CURLH_HEADER))); - CURLcode result = Curl_headers_push(data, buf, htype); + CURLcode result = Curl_headers_push(data, buf, blen, htype); CURL_TRC_WRITE(data, "header_collect pushed(type=%x, len=%zu) -> %d", htype, blen, result); if(result) @@ -417,7 +356,7 @@ CURLcode Curl_headers_cleanup(struct Curl_easy *data) for(e = Curl_llist_head(&data->state.httphdrs); e; e = n) { struct Curl_header_store *hs = Curl_node_elem(e); n = Curl_node_next(e); - free(hs); + curlx_free(hs); } headers_reset(data); return CURLE_OK; diff --git a/vendor/hydra/vendor/curl/lib/headers.h b/vendor/hydra/vendor/curl/lib/headers.h index e11fe980..adb03af7 100644 --- a/vendor/hydra/vendor/curl/lib/headers.h +++ b/vendor/hydra/vendor/curl/lib/headers.h @@ -46,7 +46,7 @@ CURLcode Curl_headers_init(struct Curl_easy *data); * Curl_headers_push() gets passed a full header to store. */ CURLcode Curl_headers_push(struct Curl_easy *data, const char *header, - unsigned char type); + size_t hlen, unsigned char type); /* * Curl_headers_cleanup(). Free all stored headers and associated memory. @@ -54,9 +54,9 @@ CURLcode Curl_headers_push(struct Curl_easy *data, const char *header, CURLcode Curl_headers_cleanup(struct Curl_easy *data); #else -#define Curl_headers_init(x) CURLE_OK -#define Curl_headers_push(x,y,z) CURLE_OK -#define Curl_headers_cleanup(x) Curl_nop_stmt +#define Curl_headers_init(x) CURLE_OK +#define Curl_headers_push(x,y,z,a) CURLE_OK +#define Curl_headers_cleanup(x) Curl_nop_stmt #endif #endif /* HEADER_CURL_HEADER_H */ diff --git a/vendor/hydra/vendor/curl/lib/hmac.c b/vendor/hydra/vendor/curl/lib/hmac.c index 7842f060..90805883 100644 --- a/vendor/hydra/vendor/curl/lib/hmac.c +++ b/vendor/hydra/vendor/curl/lib/hmac.c @@ -23,21 +23,13 @@ * RFC2104 Keyed-Hashing for Message Authentication * ***************************************************************************/ - #include "curl_setup.h" #if (defined(USE_CURL_NTLM_CORE) && !defined(USE_WINDOWS_SSPI)) || \ !defined(CURL_DISABLE_AWS) || !defined(CURL_DISABLE_DIGEST_AUTH) || \ defined(USE_SSL) -#include - #include "curl_hmac.h" -#include "curl_memory.h" -#include "curlx/warnless.h" - -/* The last #include file should be: */ -#include "memdebug.h" /* * Generic HMAC algorithm. @@ -50,10 +42,9 @@ static const unsigned char hmac_ipad = 0x36; static const unsigned char hmac_opad = 0x5C; -struct HMAC_context * -Curl_HMAC_init(const struct HMAC_params *hashparams, - const unsigned char *key, - unsigned int keylen) +struct HMAC_context *Curl_HMAC_init(const struct HMAC_params *hashparams, + const unsigned char *key, + unsigned int keylen) { size_t i; struct HMAC_context *ctxt; @@ -62,21 +53,21 @@ Curl_HMAC_init(const struct HMAC_params *hashparams, /* Create HMAC context. */ i = sizeof(*ctxt) + 2 * hashparams->ctxtsize + hashparams->resultlen; - ctxt = malloc(i); + ctxt = curlx_malloc(i); if(!ctxt) return ctxt; ctxt->hash = hashparams; - ctxt->hashctxt1 = (void *) (ctxt + 1); - ctxt->hashctxt2 = (void *) ((char *) ctxt->hashctxt1 + hashparams->ctxtsize); + ctxt->hashctxt1 = (void *)(ctxt + 1); + ctxt->hashctxt2 = (void *)((char *)ctxt->hashctxt1 + hashparams->ctxtsize); /* If the key is too long, replace it by its hash digest. */ if(keylen > hashparams->maxkeylen) { if(hashparams->hinit(ctxt->hashctxt1)) goto fail; hashparams->hupdate(ctxt->hashctxt1, key, keylen); - hkey = (unsigned char *) ctxt->hashctxt2 + hashparams->ctxtsize; + hkey = (unsigned char *)ctxt->hashctxt2 + hashparams->ctxtsize; hashparams->hfinal(hkey, ctxt->hashctxt1); key = hkey; keylen = hashparams->resultlen; @@ -103,7 +94,7 @@ Curl_HMAC_init(const struct HMAC_params *hashparams, return ctxt; fail: - free(ctxt); + curlx_free(ctxt); return NULL; } @@ -116,7 +107,6 @@ int Curl_HMAC_update(struct HMAC_context *ctxt, return 0; } - int Curl_HMAC_final(struct HMAC_context *ctxt, unsigned char *output) { const struct HMAC_params *hashparams = ctxt->hash; @@ -125,12 +115,12 @@ int Curl_HMAC_final(struct HMAC_context *ctxt, unsigned char *output) storage. */ if(!output) - output = (unsigned char *) ctxt->hashctxt2 + ctxt->hash->ctxtsize; + output = (unsigned char *)ctxt->hashctxt2 + ctxt->hash->ctxtsize; hashparams->hfinal(output, ctxt->hashctxt1); hashparams->hupdate(ctxt->hashctxt2, output, hashparams->resultlen); hashparams->hfinal(output, ctxt->hashctxt2); - free(ctxt); + curlx_free(ctxt); return 0; } diff --git a/vendor/hydra/vendor/curl/lib/hostip.c b/vendor/hydra/vendor/curl/lib/hostip.c index 7e2551d8..a0e1d40c 100644 --- a/vendor/hydra/vendor/curl/lib/hostip.c +++ b/vendor/hydra/vendor/curl/lib/hostip.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifdef HAVE_NETINET_IN_H @@ -41,33 +40,28 @@ #include #endif -#include -#ifndef UNDER_CE +#include /* for sigjmp_buf, sigsetjmp() */ #include -#endif #include "urldata.h" -#include "sendf.h" +#include "curl_trc.h" #include "connect.h" #include "hostip.h" #include "hash.h" #include "rand.h" -#include "share.h" +#include "curl_share.h" #include "url.h" #include "curlx/inet_ntop.h" #include "curlx/inet_pton.h" #include "multiif.h" #include "doh.h" -#include "curlx/warnless.h" +#include "progress.h" #include "select.h" #include "strcase.h" #include "easy_lock.h" +#include "curlx/strcopy.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #if defined(CURLRES_SYNCH) && \ defined(HAVE_ALARM) && \ defined(SIGALRM) && \ @@ -124,7 +118,7 @@ static void dnscache_entry_free(struct Curl_dns_entry *dns); static void show_resolve_info(struct Curl_easy *data, struct Curl_dns_entry *dns); #else -#define show_resolve_info(x,y) Curl_nop_stmt +#define show_resolve_info(x, y) Curl_nop_stmt #endif /* @@ -164,10 +158,9 @@ void Curl_printable_address(const struct Curl_addrinfo *ai, char *buf, * Create a hostcache id string for the provided host + port, to be used by * the DNS caching. Without alloc. Return length of the id string. */ -static size_t -create_dnscache_id(const char *name, - size_t nlen, /* 0 or actual name length */ - int port, char *ptr, size_t buflen) +static size_t create_dnscache_id(const char *name, + size_t nlen, /* 0 or actual name length */ + int port, char *ptr, size_t buflen) { size_t len = nlen ? nlen : strlen(name); DEBUGASSERT(buflen >= MAX_HOSTCACHE_LEN); @@ -191,16 +184,14 @@ struct dnscache_prune_data { * Returning non-zero means remove the entry, return 0 to keep it in the * cache. */ -static int -dnscache_entry_is_stale(void *datap, void *hc) +static int dnscache_entry_is_stale(void *datap, void *hc) { - struct dnscache_prune_data *prune = - (struct dnscache_prune_data *) datap; - struct Curl_dns_entry *dns = (struct Curl_dns_entry *) hc; + struct dnscache_prune_data *prune = (struct dnscache_prune_data *)datap; + struct Curl_dns_entry *dns = (struct Curl_dns_entry *)hc; if(dns->timestamp.tv_sec || dns->timestamp.tv_usec) { /* get age in milliseconds */ - timediff_t age = curlx_timediff(prune->now, dns->timestamp); + timediff_t age = curlx_ptimediff_ms(&prune->now, &dns->timestamp); if(!dns->addr) age *= 2; /* negative entries age twice as fast */ if(age >= prune->max_age_ms) @@ -215,9 +206,9 @@ dnscache_entry_is_stale(void *datap, void *hc) * Prune the DNS cache. This assumes that a lock has already been taken. * Returns the 'age' of the oldest still kept entry - in milliseconds. */ -static timediff_t -dnscache_prune(struct Curl_hash *hostcache, timediff_t cache_timeout_ms, - struct curltime now) +static timediff_t dnscache_prune(struct Curl_hash *hostcache, + timediff_t cache_timeout_ms, + struct curltime now) { struct dnscache_prune_data user; @@ -226,7 +217,7 @@ dnscache_prune(struct Curl_hash *hostcache, timediff_t cache_timeout_ms, user.oldest_ms = 0; Curl_hash_clean_with_criterium(hostcache, - (void *) &user, + (void *)&user, dnscache_entry_is_stale); return user.oldest_ms; @@ -262,7 +253,6 @@ static void dnscache_unlock(struct Curl_easy *data, void Curl_dnscache_prune(struct Curl_easy *data) { struct Curl_dnscache *dnscache = dnscache_get(data); - struct curltime now; /* the timeout may be set -1 (forever) */ timediff_t timeout_ms = data->set.dns_cache_timeout_ms; @@ -272,11 +262,10 @@ void Curl_dnscache_prune(struct Curl_easy *data) dnscache_lock(data, dnscache); - now = curlx_now(); - do { /* Remove outdated and unused entries from the hostcache */ - timediff_t oldest_ms = dnscache_prune(&dnscache->entries, timeout_ms, now); + timediff_t oldest_ms = + dnscache_prune(&dnscache->entries, timeout_ms, *Curl_pgrs_now(data)); if(Curl_hash_count(&dnscache->entries) > MAX_DNS_CACHE_SIZE) /* prune the ones over half this age */ @@ -342,7 +331,7 @@ static struct Curl_dns_entry *fetch_addr(struct Curl_easy *data, /* See whether the returned entry is stale. Done before we release lock */ struct dnscache_prune_data user; - user.now = curlx_now(); + user.now = *Curl_pgrs_now(data); user.max_age_ms = data->set.dns_cache_timeout_ms; user.oldest_ms = 0; @@ -395,11 +384,10 @@ static struct Curl_dns_entry *fetch_addr(struct Curl_easy *data, * The returned data *MUST* be "released" with Curl_resolv_unlink() after * use, or we will leak memory! */ -struct Curl_dns_entry * -Curl_dnscache_get(struct Curl_easy *data, - const char *hostname, - int port, - int ip_version) +struct Curl_dns_entry *Curl_dnscache_get(struct Curl_easy *data, + const char *hostname, + int port, + int ip_version) { struct Curl_dnscache *dnscache = dnscache_get(data); struct Curl_dns_entry *dns = NULL; @@ -453,7 +441,7 @@ UNITTEST CURLcode Curl_shuffle_addr(struct Curl_easy *data, struct Curl_addrinfo **nodes; infof(data, "Shuffling %i addresses", num_addrs); - nodes = malloc(num_addrs*sizeof(*nodes)); + nodes = curlx_malloc(num_addrs * sizeof(*nodes)); if(nodes) { int i; unsigned int *rnd; @@ -462,10 +450,10 @@ UNITTEST CURLcode Curl_shuffle_addr(struct Curl_easy *data, /* build a plain array of Curl_addrinfo pointers */ nodes[0] = *addr; for(i = 1; i < num_addrs; i++) { - nodes[i] = nodes[i-1]->ai_next; + nodes[i] = nodes[i - 1]->ai_next; } - rnd = malloc(rnd_size); + rnd = curlx_malloc(rnd_size); if(rnd) { /* Fisher-Yates shuffle */ if(Curl_rand(data, (unsigned char *)rnd, rnd_size) == CURLE_OK) { @@ -478,17 +466,17 @@ UNITTEST CURLcode Curl_shuffle_addr(struct Curl_easy *data, /* relink list in the new order */ for(i = 1; i < num_addrs; i++) { - nodes[i-1]->ai_next = nodes[i]; + nodes[i - 1]->ai_next = nodes[i]; } - nodes[num_addrs-1]->ai_next = NULL; + nodes[num_addrs - 1]->ai_next = NULL; *addr = nodes[0]; } - free(rnd); + curlx_free(rnd); } else result = CURLE_OUT_OF_MEMORY; - free(nodes); + curlx_free(nodes); } else result = CURLE_OUT_OF_MEMORY; @@ -511,10 +499,8 @@ Curl_dnscache_mk_entry(struct Curl_easy *data, /* shuffle addresses if requested */ if(data->set.dns_shuffle_addresses) { CURLcode result = Curl_shuffle_addr(data, &addr); - if(result) { - Curl_freeaddrinfo(addr); + if(result) return NULL; - } } #else (void)data; @@ -523,11 +509,9 @@ Curl_dnscache_mk_entry(struct Curl_easy *data, hostlen = strlen(hostname); /* Create a new cache entry */ - dns = calloc(1, sizeof(struct Curl_dns_entry) + hostlen); - if(!dns) { - Curl_freeaddrinfo(addr); + dns = curlx_calloc(1, sizeof(struct Curl_dns_entry) + hostlen); + if(!dns) return NULL; - } dns->refcount = 1; /* the cache has the first reference */ dns->addr = addr; /* this is the address(es) */ @@ -536,7 +520,7 @@ Curl_dnscache_mk_entry(struct Curl_easy *data, dns->timestamp.tv_usec = 0; /* an entry that never goes stale */ } else { - dns->timestamp = curlx_now(); + dns->timestamp = *Curl_pgrs_now(data); } dns->hostport = port; if(hostlen) @@ -571,6 +555,7 @@ dnscache_add_addr(struct Curl_easy *data, dns2 = Curl_hash_add(&dnscache->entries, entry_id, entry_len + 1, (void *)dns); if(!dns2) { + dns->addr = NULL; dnscache_entry_free(dns); return NULL; } @@ -614,7 +599,7 @@ static struct Curl_addrinfo *get_localhost6(int port, const char *name) struct sockaddr_in6 sa6; unsigned char ipv6[16]; unsigned short port16 = (unsigned short)(port & 0xffff); - ca = calloc(1, sizeof(struct Curl_addrinfo) + ss_size + hostlen + 1); + ca = curlx_calloc(1, sizeof(struct Curl_addrinfo) + ss_size + hostlen + 1); if(!ca) return NULL; @@ -637,11 +622,11 @@ static struct Curl_addrinfo *get_localhost6(int port, const char *name) ca->ai_addr = (void *)((char *)ca + sizeof(struct Curl_addrinfo)); memcpy(ca->ai_addr, &sa6, ss_size); ca->ai_canonname = (char *)ca->ai_addr + ss_size; - strcpy(ca->ai_canonname, name); + curlx_strcopy(ca->ai_canonname, hostlen + 1, name, hostlen); return ca; } #else -#define get_localhost6(x,y) NULL +#define get_localhost6(x, y) NULL #endif /* return a static IPv4 127.0.0.1 for the given name */ @@ -663,7 +648,7 @@ static struct Curl_addrinfo *get_localhost(int port, const char *name) return NULL; memcpy(&sa.sin_addr, &ipv4, sizeof(ipv4)); - ca = calloc(1, sizeof(struct Curl_addrinfo) + ss_size + hostlen + 1); + ca = curlx_calloc(1, sizeof(struct Curl_addrinfo) + ss_size + hostlen + 1); if(!ca) return NULL; ca->ai_flags = 0; @@ -674,7 +659,7 @@ static struct Curl_addrinfo *get_localhost(int port, const char *name) ca->ai_addr = (void *)((char *)ca + sizeof(struct Curl_addrinfo)); memcpy(ca->ai_addr, &sa, ss_size); ca->ai_canonname = (char *)ca->ai_addr + ss_size; - strcpy(ca->ai_canonname, name); + curlx_strcopy(ca->ai_canonname, hostlen + 1, name, hostlen); ca6 = get_localhost6(port, name); if(!ca6) @@ -736,7 +721,6 @@ bool Curl_host_is_ipnum(const char *hostname) return FALSE; } - /* return TRUE if 'part' is a case insensitive tail of 'full' */ static bool tailmatch(const char *full, size_t flen, const char *part, size_t plen) @@ -746,40 +730,6 @@ static bool tailmatch(const char *full, size_t flen, return curl_strnequal(part, &full[flen - plen], plen); } -static struct Curl_addrinfo * -convert_ipaddr_direct(const char *hostname, int port, bool *is_ipaddr) -{ - struct in_addr in; - *is_ipaddr = FALSE; - /* First check if this is an IPv4 address string */ - if(curlx_inet_pton(AF_INET, hostname, &in) > 0) { - /* This is a dotted IP address 123.123.123.123-style */ - *is_ipaddr = TRUE; -#ifdef USE_RESOLVE_ON_IPS - (void)port; - return NULL; -#else - return Curl_ip2addr(AF_INET, &in, hostname, port); -#endif - } -#ifdef USE_IPV6 - else { - struct in6_addr in6; - /* check if this is an IPv6 address string */ - if(curlx_inet_pton(AF_INET6, hostname, &in6) > 0) { - /* This is an IPv6 address literal */ - *is_ipaddr = TRUE; -#ifdef USE_RESOLVE_ON_IPS - return NULL; -#else - return Curl_ip2addr(AF_INET6, &in6, hostname, port); -#endif - } - } -#endif /* USE_IPV6 */ - return NULL; -} - static bool can_resolve_ip_version(struct Curl_easy *data, int ip_version) { #ifdef CURLRES_IPV6 @@ -843,10 +793,9 @@ CURLcode Curl_resolv(struct Curl_easy *data, struct Curl_dnscache *dnscache = dnscache_get(data); struct Curl_dns_entry *dns = NULL; struct Curl_addrinfo *addr = NULL; - int respwait = 0; - bool is_ipaddr; + bool respwait = FALSE; size_t hostname_len; - bool keep_negative = TRUE; /* cache a negative result */ + CURLcode result = CURLE_COULDNT_RESOLVE_HOST; *entry = NULL; @@ -855,8 +804,11 @@ CURLcode Curl_resolv(struct Curl_easy *data, #else (void)allowDOH; #endif - if(!dnscache) + DEBUGASSERT(dnscache); + if(!dnscache) { + result = CURLE_BAD_FUNCTION_ARGUMENT; goto error; + } /* We should intentionally error and not resolve .onion TLDs */ hostname_len = strlen(hostname); @@ -876,6 +828,7 @@ CURLcode Curl_resolv(struct Curl_easy *data, dnscache_unlock(data, dnscache); if(dns) { infof(data, "Hostname %s was found in DNS cache", hostname); + result = CURLE_OK; goto out; } @@ -884,7 +837,8 @@ CURLcode Curl_resolv(struct Curl_easy *data, void *resolver = NULL; int st; #ifdef CURLRES_ASYNCH - if(Curl_async_get_impl(data, &resolver)) + result = Curl_async_get_impl(data, &resolver); + if(result) goto error; #endif Curl_set_in_callback(data, TRUE); @@ -892,56 +846,58 @@ CURLcode Curl_resolv(struct Curl_easy *data, data->set.resolver_start_client); Curl_set_in_callback(data, FALSE); if(st) { - keep_negative = FALSE; + result = CURLE_ABORTED_BY_CALLBACK; goto error; } } - /* shortcut literal IP addresses, if we are not told to resolve them. */ - addr = convert_ipaddr_direct(hostname, port, &is_ipaddr); - if(addr) - goto out; - + if(Curl_is_ipaddr(hostname)) { #ifndef USE_RESOLVE_ON_IPS - /* allowed to convert, hostname is IP address, then NULL means error */ - if(is_ipaddr) - goto error; + /* shortcut literal IP addresses, if we are not told to resolve them. */ + result = Curl_str2addr(hostname, port, &addr); + if(result) + goto error; + goto out; #endif + } - /* Really need a resolver for hostname. */ - if(ip_version == CURL_IPRESOLVE_V6 && !Curl_ipv6works(data)) - goto error; - - if(!is_ipaddr && - (curl_strequal(hostname, "localhost") || - curl_strequal(hostname, "localhost.") || - tailmatch(hostname, hostname_len, STRCONST(".localhost")) || - tailmatch(hostname, hostname_len, STRCONST(".localhost.")))) { + if(curl_strequal(hostname, "localhost") || + curl_strequal(hostname, "localhost.") || + tailmatch(hostname, hostname_len, STRCONST(".localhost")) || + tailmatch(hostname, hostname_len, STRCONST(".localhost."))) { addr = get_localhost(port, hostname); + result = addr ? CURLE_OK : CURLE_OUT_OF_MEMORY; } #ifndef CURL_DISABLE_DOH - else if(!is_ipaddr && allowDOH && data->set.doh) { - addr = Curl_doh(data, hostname, port, ip_version, &respwait); + else if(!Curl_is_ipaddr(hostname) && allowDOH && data->set.doh) { + result = Curl_doh(data, hostname, port, ip_version); + respwait = TRUE; } #endif else { /* Can we provide the requested IP specifics in resolving? */ - if(!can_resolve_ip_version(data, ip_version)) + if(!can_resolve_ip_version(data, ip_version)) { + result = CURLE_COULDNT_RESOLVE_HOST; goto error; + } #ifdef CURLRES_ASYNCH - addr = Curl_async_getaddrinfo(data, hostname, port, ip_version, &respwait); + result = Curl_async_getaddrinfo(data, hostname, port, ip_version); + respwait = TRUE; #else - respwait = 0; /* no async waiting here */ + respwait = FALSE; /* no async waiting here */ addr = Curl_sync_getaddrinfo(data, hostname, port, ip_version); + if(addr) + result = CURLE_OK; #endif } out: - /* We either have found a `dns` or looked up the `addr` - * or `respwait` is set for an async operation. - * Everything else is a failure to resolve. */ - if(dns) { + /* We either have found a `dns` or looked up the `addr` or `respwait` is set + * for an async operation. Everything else is a failure to resolve. */ + if(result) + ; + else if(dns) { if(!dns->addr) { infof(data, "Negative DNS entry"); dns->refcount--; @@ -954,8 +910,12 @@ CURLcode Curl_resolv(struct Curl_easy *data, /* we got a response, create a dns entry, add to cache, return */ dns = Curl_dnscache_mk_entry(data, addr, hostname, 0, port, FALSE); if(!dns || Curl_dnscache_add(data, dns)) { - /* this is OOM or similar, don't store such negative resolves */ - keep_negative = FALSE; + /* this is OOM or similar, do not store such negative resolves */ + Curl_freeaddrinfo(addr); + if(dns) + /* avoid a dangling pointer to addr in the dying dns entry */ + dns->addr = NULL; + result = CURLE_OUT_OF_MEMORY; goto error; } show_resolve_info(data, dns); @@ -967,14 +927,16 @@ CURLcode Curl_resolv(struct Curl_easy *data, *entry = dns; return dns ? CURLE_OK : CURLE_AGAIN; } + result = CURLE_COULDNT_RESOLVE_HOST; } error: if(dns) Curl_resolv_unlink(data, &dns); Curl_async_shutdown(data); - if(keep_negative) + if(result == CURLE_COULDNT_RESOLVE_HOST) store_negative_resolve(data, hostname, port); - return CURLE_COULDNT_RESOLVE_HOST; + DEBUGASSERT(result); + return result; } CURLcode Curl_resolv_blocking(struct Curl_easy *data, @@ -1011,8 +973,7 @@ CURLcode Curl_resolv_blocking(struct Curl_easy *data, * execution. This effectively causes the remainder of the application to run * within a signal handler which is nonportable and could lead to problems. */ -CURL_NORETURN static -void alarmfunc(int sig) +CURL_NORETURN static void alarmfunc(int sig) { (void)sig; siglongjmp(curl_jmpenv, 1); @@ -1049,7 +1010,7 @@ CURLcode Curl_resolv_timeout(struct Curl_easy *data, { #ifdef USE_ALARM_TIMEOUT #ifdef HAVE_SIGACTION - struct sigaction keep_sigact; /* store the old struct here */ + struct sigaction keep_sigact; /* store the old struct here */ volatile bool keep_copysig = FALSE; /* whether old sigact has been saved */ struct sigaction sigact; #else @@ -1089,8 +1050,8 @@ CURLcode Curl_resolv_timeout(struct Curl_easy *data, /* The alarm() function only provides integer second resolution, so if we want to wait less than one second we must bail out already now. */ failf(data, - "remaining timeout of %ld too small to resolve via SIGALRM method", - timeout); + "remaining timeout of %ld too small to resolve via SIGALRM method", + timeout); return CURLE_OPERATION_TIMEDOUT; } /* This allows us to time-out from the name resolver, as the timeout @@ -1132,7 +1093,7 @@ CURLcode Curl_resolv_timeout(struct Curl_easy *data, /* alarm() makes a signal get sent when the timeout fires off, and that will abort system calls */ - prev_alarm = alarm(curlx_sltoui(timeout/1000L)); + prev_alarm = alarm(curlx_sltoui(timeout / 1000L)); } #else /* !USE_ALARM_TIMEOUT */ @@ -1175,14 +1136,14 @@ CURLcode Curl_resolv_timeout(struct Curl_easy *data, the time we spent until now! */ if(prev_alarm) { /* there was an alarm() set before us, now put it back */ - timediff_t elapsed_secs = curlx_timediff(curlx_now(), - data->conn->created) / 1000; + timediff_t elapsed_secs = curlx_ptimediff_ms(Curl_pgrs_now(data), + &data->conn->created) / 1000; /* the alarm period is counted in even number of seconds */ unsigned long alarm_set = (unsigned long)(prev_alarm - elapsed_secs); if(!alarm_set || - ((alarm_set >= 0x80000000) && (prev_alarm < 0x80000000)) ) { + ((alarm_set >= 0x80000000) && (prev_alarm < 0x80000000))) { /* if the alarm time-left reached zero or turned "negative" (counted with unsigned values), we should fire off a SIGALRM here, but we will not, and zero would be to switch it off so we never set it to @@ -1205,10 +1166,10 @@ static void dnscache_entry_free(struct Curl_dns_entry *dns) #ifdef USE_HTTPSRR if(dns->hinfo) { Curl_httpsrr_cleanup(dns->hinfo); - free(dns->hinfo); + curlx_free(dns->hinfo); } #endif - free(dns); + curlx_free(dns); } /* @@ -1234,7 +1195,7 @@ void Curl_resolv_unlink(struct Curl_easy *data, struct Curl_dns_entry **pdns) static void dnscache_entry_dtor(void *entry) { - struct Curl_dns_entry *dns = (struct Curl_dns_entry *) entry; + struct Curl_dns_entry *dns = (struct Curl_dns_entry *)entry; DEBUGASSERT(dns && (dns->refcount > 0)); dns->refcount--; if(dns->refcount == 0) @@ -1338,6 +1299,7 @@ CURLcode Curl_loadhostpairs(struct Curl_easy *data) while(*host) { struct Curl_str target; struct Curl_addrinfo *ai; + CURLcode result; if(!curlx_str_single(&host, '[')) { if(curlx_str_until(&host, &target, MAX_IPADR_LEN, ']') || @@ -1368,8 +1330,8 @@ CURLcode Curl_loadhostpairs(struct Curl_easy *data) memcpy(address, curlx_str(&target), curlx_strlen(&target)); address[curlx_strlen(&target)] = '\0'; - ai = Curl_str2addr(address, (int)port); - if(!ai) { + result = Curl_str2addr(address, (int)port, &ai); + if(result) { infof(data, "Resolve address '%s' found illegal", address); goto err; } @@ -1391,8 +1353,7 @@ CURLcode Curl_loadhostpairs(struct Curl_easy *data) error = FALSE; err: if(error) { - failf(data, "Couldn't parse CURLOPT_RESOLVE entry '%s'", - hostp->data); + failf(data, "Could not parse CURLOPT_RESOLVE entry '%s'", hostp->data); Curl_freeaddrinfo(head); return CURLE_SETOPT_OPTION_SYNTAX; } @@ -1428,11 +1389,12 @@ CURLcode Curl_loadhostpairs(struct Curl_easy *data) /* put this new host in the cache */ dns = dnscache_add_addr(data, dnscache, head, curlx_str(&source), curlx_strlen(&source), (int)port, permanent); - if(dns) { + if(dns) /* release the returned reference; the cache itself will keep the * entry alive: */ dns->refcount--; - } + else + Curl_freeaddrinfo(head); dnscache_unlock(data, dnscache); diff --git a/vendor/hydra/vendor/curl/lib/hostip.h b/vendor/hydra/vendor/curl/lib/hostip.h index 3eb82cd1..712b8eaf 100644 --- a/vendor/hydra/vendor/curl/lib/hostip.h +++ b/vendor/hydra/vendor/curl/lib/hostip.h @@ -23,16 +23,14 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" + #include "hash.h" #include "curl_addrinfo.h" -#include "curlx/timeval.h" /* for timediff_t */ +#include "curlx/timeval.h" /* for curltime, timediff_t */ #include "asyn.h" #include "httpsrr.h" -#include - #ifdef USE_HTTPSRR # include #endif @@ -116,7 +114,6 @@ bool Curl_ipv6works(struct Curl_easy *data); #define Curl_ipv6works(x) FALSE #endif - /* unlink a dns entry, potentially shared with a cache */ void Curl_resolv_unlink(struct Curl_easy *data, struct Curl_dns_entry **pdns); @@ -132,7 +129,7 @@ void Curl_dnscache_prune(struct Curl_easy *data); /* clear the DNS cache */ void Curl_dnscache_clear(struct Curl_easy *data); -/* IPv4 threadsafe resolve function used for synch and asynch builds */ +/* IPv4 thread-safe resolve function used for synch and asynch builds */ struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, int port); CURLcode Curl_once_resolved(struct Curl_easy *data, @@ -175,10 +172,9 @@ Curl_dnscache_mk_entry(struct Curl_easy *data, * The returned data *MUST* be "released" with Curl_resolv_unlink() after * use, or we will leak memory! */ -struct Curl_dns_entry * -Curl_dnscache_get(struct Curl_easy *data, - const char *hostname, - int port, int ip_version); +struct Curl_dns_entry *Curl_dnscache_get(struct Curl_easy *data, + const char *hostname, int port, + int ip_version); /* * Curl_dnscache_addr() adds `entry` to the cache, increasing its @@ -196,7 +192,7 @@ CURLcode Curl_loadhostpairs(struct Curl_easy *data); CURLcode Curl_resolv_check(struct Curl_easy *data, struct Curl_dns_entry **dns); #else -#define Curl_resolv_check(x,y) CURLE_NOT_BUILT_IN +#define Curl_resolv_check(x, y) CURLE_NOT_BUILT_IN #endif CURLcode Curl_resolv_pollset(struct Curl_easy *data, struct easy_pollset *ps); diff --git a/vendor/hydra/vendor/curl/lib/hostip4.c b/vendor/hydra/vendor/curl/lib/hostip4.c index e1ed007a..422e0b22 100644 --- a/vendor/hydra/vendor/curl/lib/hostip4.c +++ b/vendor/hydra/vendor/curl/lib/hostip4.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" /*********************************************************************** @@ -44,16 +43,10 @@ #endif #include "urldata.h" -#include "sendf.h" +#include "curl_trc.h" #include "hostip.h" -#include "hash.h" -#include "share.h" #include "url.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef CURLRES_SYNCH @@ -97,10 +90,10 @@ struct Curl_addrinfo *Curl_sync_getaddrinfo(struct Curl_easy *data, #if defined(CURLRES_IPV4) && !defined(CURLRES_ARES) && !defined(CURLRES_AMIGA) /* - * Curl_ipv4_resolve_r() - ipv4 threadsafe resolver function. + * Curl_ipv4_resolve_r() - ipv4 thread-safe resolver function. * * This is used for both synchronous and asynchronous resolver builds, - * implying that only threadsafe code and function calls may be used. + * implying that only thread-safe code and function calls may be used. * */ struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, @@ -139,7 +132,7 @@ struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, */ int h_errnop; - buf = calloc(1, CURL_HOSTENT_SIZE); + buf = curlx_calloc(1, CURL_HOSTENT_SIZE); if(!buf) return NULL; /* major failure */ /* @@ -157,7 +150,7 @@ struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, &h_errnop); /* If the buffer is too small, it returns NULL and sets errno to - * ERANGE. The errno is thread safe if this is compiled with + * ERANGE. The errno is thread-safe if this is compiled with * -D_REENTRANT as then the 'errno' variable is a macro defined to get * used properly for threads. */ @@ -170,11 +163,11 @@ struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, /* Linux */ (void)gethostbyname_r(hostname, - (struct hostent *)buf, - (char *)buf + sizeof(struct hostent), - CURL_HOSTENT_SIZE - sizeof(struct hostent), - &h, /* DIFFERENCE */ - &h_errnop); + (struct hostent *)buf, + (char *)buf + sizeof(struct hostent), + CURL_HOSTENT_SIZE - sizeof(struct hostent), + &h, /* DIFFERENCE */ + &h_errnop); /* Redhat 8, using glibc 2.2.93 changed the behavior. Now all of a * sudden this function returns EAGAIN if the given buffer size is too * small. Previous versions are known to return ERANGE for the same @@ -253,8 +246,8 @@ struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, * Since we do not know how big buffer this particular lookup required, * we cannot realloc down the huge alloc without doing closer analysis of * the returned data. Thus, we always use CURL_HOSTENT_SIZE for every - * name lookup. Fixing this would require an extra malloc() and then - * calling Curl_addrinfo_copy() that subsequent realloc()s down the new + * name lookup. Fixing this would require an extra allocation and then + * calling Curl_addrinfo_copy() that subsequent reallocation down the new * memory area to the actually used amount. */ } @@ -262,12 +255,12 @@ struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, #endif /* HAVE_...BYNAME_R_5 || HAVE_...BYNAME_R_6 || HAVE_...BYNAME_R_3 */ { h = NULL; /* set return code to NULL */ - free(buf); + curlx_free(buf); } #else /* (HAVE_GETADDRINFO && HAVE_GETADDRINFO_THREADSAFE) || HAVE_GETHOSTBYNAME_R */ /* - * Here is code for platforms that do not have a thread safe + * Here is code for platforms that do not have a thread-safe * getaddrinfo() nor gethostbyname_r() function or for which * gethostbyname() is the preferred one. */ @@ -280,7 +273,7 @@ struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, ai = Curl_he2ai(h, port); if(buf) /* used a *_r() function */ - free(buf); + curlx_free(buf); } #endif diff --git a/vendor/hydra/vendor/curl/lib/hostip6.c b/vendor/hydra/vendor/curl/lib/hostip6.c index 9419b9e4..e4793d7a 100644 --- a/vendor/hydra/vendor/curl/lib/hostip6.c +++ b/vendor/hydra/vendor/curl/lib/hostip6.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" /*********************************************************************** @@ -45,18 +44,12 @@ #include "urldata.h" #include "cfilters.h" -#include "sendf.h" +#include "curl_trc.h" #include "hostip.h" -#include "hash.h" -#include "share.h" #include "url.h" #include "curlx/inet_pton.h" #include "connect.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef CURLRES_SYNCH #ifdef DEBUG_ADDRINFO diff --git a/vendor/hydra/vendor/curl/lib/hsts.c b/vendor/hydra/vendor/curl/lib/hsts.c index 4e41155f..de6c5731 100644 --- a/vendor/hydra/vendor/curl/lib/hsts.c +++ b/vendor/hydra/vendor/curl/lib/hsts.c @@ -28,27 +28,20 @@ #include "curl_setup.h" #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_HSTS) -#include #include "urldata.h" #include "llist.h" #include "hsts.h" #include "curl_fopen.h" #include "curl_get_line.h" -#include "sendf.h" #include "parsedate.h" -#include "rename.h" -#include "share.h" -#include "strdup.h" +#include "curl_share.h" #include "curlx/strparse.h" +#include "curlx/strcopy.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - -#define MAX_HSTS_LINE 4095 +#define MAX_HSTS_LINE 4095 #define MAX_HSTS_HOSTLEN 2048 #define MAX_HSTS_DATELEN 256 -#define UNLIMITED "unlimited" +#define UNLIMITED "unlimited" #if defined(DEBUGBUILD) || defined(UNITTESTS) /* to play well with debug builds, we can *set* a fixed time this will @@ -72,18 +65,14 @@ static time_t hsts_debugtime(void *unused) struct hsts *Curl_hsts_init(void) { - struct hsts *h = calloc(1, sizeof(struct hsts)); + struct hsts *h = curlx_calloc(1, sizeof(struct hsts)); if(h) { Curl_llist_init(&h->list, NULL); } return h; } -static void hsts_free(struct stsentry *e) -{ - free(CURL_UNCONST(e->host)); - free(e); -} +#define hsts_free(x) curlx_free(x) void Curl_hsts_cleanup(struct hsts **hp) { @@ -96,8 +85,8 @@ void Curl_hsts_cleanup(struct hsts **hp) n = Curl_node_next(e); hsts_free(sts); } - free(h->filename); - free(h); + curlx_free(h->filename); + curlx_free(h); *hp = NULL; } } @@ -115,18 +104,11 @@ static CURLcode hsts_create(struct hsts *h, /* strip off any trailing dot */ --hlen; if(hlen) { - char *duphost; - struct stsentry *sts = calloc(1, sizeof(struct stsentry)); + struct stsentry *sts = curlx_calloc(1, sizeof(struct stsentry) + hlen); if(!sts) return CURLE_OUT_OF_MEMORY; - - duphost = Curl_memdup0(hostname, hlen); - if(!duphost) { - free(sts); - return CURLE_OUT_OF_MEMORY; - } - - sts->host = duphost; + /* the null terminator is already there */ + memcpy(sts->host, hostname, hlen); sts->expires = expires; sts->includeSubDomains = subdomains; Curl_llist_append(&h->list, sts, &sts->node); @@ -252,7 +234,7 @@ struct stsentry *Curl_hsts(struct hsts *h, const char *hostname, if((hlen > MAX_HSTS_HOSTLEN) || !hlen) return NULL; - if(hostname[hlen-1] == '.') + if(hostname[hlen - 1] == '.') /* remove the trailing dot */ --hlen; @@ -269,7 +251,7 @@ struct stsentry *Curl_hsts(struct hsts *h, const char *hostname, ntail = strlen(sts->host); if((subdomain && sts->includeSubDomains) && (ntail < hlen)) { size_t offs = hlen - ntail; - if((hostname[offs-1] == '.') && + if((hostname[offs - 1] == '.') && curl_strnequal(&hostname[offs], sts->host, ntail) && (ntail > blen)) { /* save the tail match with the longest tail */ @@ -277,7 +259,7 @@ struct stsentry *Curl_hsts(struct hsts *h, const char *hostname, blen = ntail; } } - /* avoid curl_strequal because the host name is not null-terminated */ + /* avoid curl_strequal because the hostname is not null-terminated */ if((hlen == ntail) && curl_strnequal(hostname, sts->host, hlen)) return sts; } @@ -298,12 +280,12 @@ static CURLcode hsts_push(struct Curl_easy *data, struct tm stamp; CURLcode result; - e.name = (char *)CURL_UNCONST(sts->host); + e.name = (char *)sts->host; e.namelen = strlen(sts->host); e.includeSubDomains = sts->includeSubDomains; if(sts->expires != TIME_T_MAX) { - result = Curl_gmtime((time_t)sts->expires, &stamp); + result = curlx_gmtime((time_t)sts->expires, &stamp); if(result) return result; @@ -312,10 +294,9 @@ static CURLcode hsts_push(struct Curl_easy *data, stamp.tm_hour, stamp.tm_min, stamp.tm_sec); } else - strcpy(e.expire, UNLIMITED); + curlx_strcopy(e.expire, sizeof(e.expire), UNLIMITED, strlen(UNLIMITED)); - sc = data->set.hsts_write(data, &e, i, - data->set.hsts_write_userp); + sc = data->set.hsts_write(data, &e, i, data->set.hsts_write_userp); *stop = (sc != CURLSTS_OK); return sc == CURLSTS_FAIL ? CURLE_BAD_FUNCTION_ARGUMENT : CURLE_OK; } @@ -327,11 +308,11 @@ static CURLcode hsts_out(struct stsentry *sts, FILE *fp) { struct tm stamp; if(sts->expires != TIME_T_MAX) { - CURLcode result = Curl_gmtime((time_t)sts->expires, &stamp); + CURLcode result = curlx_gmtime((time_t)sts->expires, &stamp); if(result) return result; curl_mfprintf(fp, "%s%s \"%d%02d%02d %02d:%02d:%02d\"\n", - sts->includeSubDomains ? ".": "", sts->host, + sts->includeSubDomains ? "." : "", sts->host, stamp.tm_year + 1900, stamp.tm_mon + 1, stamp.tm_mday, stamp.tm_hour, stamp.tm_min, stamp.tm_sec); } @@ -341,7 +322,6 @@ static CURLcode hsts_out(struct stsentry *sts, FILE *fp) return CURLE_OK; } - /* * Curl_https_save() writes the HSTS cache to file and callback. */ @@ -379,13 +359,13 @@ CURLcode Curl_hsts_save(struct Curl_easy *data, struct hsts *h, break; } curlx_fclose(out); - if(!result && tempstore && Curl_rename(tempstore, file)) + if(!result && tempstore && curlx_rename(tempstore, file)) result = CURLE_WRITE_ERROR; if(result && tempstore) unlink(tempstore); } - free(tempstore); + curlx_free(tempstore); skipsave: if(data->set.hsts_write) { /* if there is a write callback */ @@ -473,7 +453,7 @@ static CURLcode hsts_pull(struct Curl_easy *data, struct hsts *h) char buffer[MAX_HSTS_HOSTLEN + 1]; struct curl_hstsentry e; e.name = buffer; - e.namelen = sizeof(buffer)-1; + e.namelen = sizeof(buffer) - 1; e.includeSubDomains = FALSE; /* default */ e.expire[0] = 0; e.name[0] = 0; /* just to make it clean */ @@ -518,8 +498,8 @@ static CURLcode hsts_load(struct hsts *h, const char *file) /* we need a private copy of the filename so that the hsts cache file name survives an easy handle reset */ - free(h->filename); - h->filename = strdup(file); + curlx_free(h->filename); + h->filename = curlx_strdup(file); if(!h->filename) return CURLE_OUT_OF_MEMORY; @@ -571,18 +551,22 @@ CURLcode Curl_hsts_loadcb(struct Curl_easy *data, struct hsts *h) return CURLE_OK; } -void Curl_hsts_loadfiles(struct Curl_easy *data) +CURLcode Curl_hsts_loadfiles(struct Curl_easy *data) { + CURLcode result = CURLE_OK; struct curl_slist *l = data->state.hstslist; if(l) { Curl_share_lock(data, CURL_LOCK_DATA_HSTS, CURL_LOCK_ACCESS_SINGLE); while(l) { - (void)Curl_hsts_loadfile(data, data->hsts, l->data); + result = Curl_hsts_loadfile(data, data->hsts, l->data); + if(result) + break; l = l->next; } Curl_share_unlock(data, CURL_LOCK_DATA_HSTS); } + return result; } #if defined(DEBUGBUILD) || defined(UNITTESTS) diff --git a/vendor/hydra/vendor/curl/lib/hsts.h b/vendor/hydra/vendor/curl/lib/hsts.h index 8ec9637c..e2c9922f 100644 --- a/vendor/hydra/vendor/curl/lib/hsts.h +++ b/vendor/hydra/vendor/curl/lib/hsts.h @@ -26,7 +26,6 @@ #include "curl_setup.h" #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_HSTS) -#include #include "llist.h" #if defined(DEBUGBUILD) || defined(UNITTESTS) @@ -35,9 +34,9 @@ extern time_t deltatime; struct stsentry { struct Curl_llist_node node; - const char *host; curl_off_t expires; /* the timestamp of this entry's expiry */ BIT(includeSubDomains); + char host[1]; }; /* The HSTS cache. Needs to be able to tailmatch hostnames. */ @@ -59,11 +58,11 @@ CURLcode Curl_hsts_loadfile(struct Curl_easy *data, struct hsts *h, const char *file); CURLcode Curl_hsts_loadcb(struct Curl_easy *data, struct hsts *h); -void Curl_hsts_loadfiles(struct Curl_easy *data); +CURLcode Curl_hsts_loadfiles(struct Curl_easy *data); #else #define Curl_hsts_cleanup(x) -#define Curl_hsts_loadcb(x,y) CURLE_OK -#define Curl_hsts_save(x,y,z) -#define Curl_hsts_loadfiles(x) +#define Curl_hsts_loadcb(x, y) CURLE_OK +#define Curl_hsts_save(x, y, z) +#define Curl_hsts_loadfiles(x) CURLE_OK #endif /* CURL_DISABLE_HTTP || CURL_DISABLE_HSTS */ #endif /* HEADER_CURL_HSTS_H */ diff --git a/vendor/hydra/vendor/curl/lib/http.c b/vendor/hydra/vendor/curl/lib/http.c index 529c3c90..a78e2f66 100644 --- a/vendor/hydra/vendor/curl/lib/http.c +++ b/vendor/hydra/vendor/curl/lib/http.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifndef CURL_DISABLE_HTTP @@ -48,16 +47,15 @@ #endif #include "urldata.h" -#include #include "transfer.h" #include "sendf.h" +#include "curl_trc.h" #include "formdata.h" #include "mime.h" #include "progress.h" #include "curlx/base64.h" #include "cookie.h" #include "vauth/vauth.h" -#include "vtls/vtls.h" #include "vquic/vquic.h" #include "http_digest.h" #include "http_ntlm.h" @@ -65,7 +63,7 @@ #include "http_aws_sigv4.h" #include "url.h" #include "urlapi-int.h" -#include "share.h" +#include "curl_share.h" #include "hostip.h" #include "dynhds.h" #include "http.h" @@ -76,21 +74,17 @@ #include "strcase.h" #include "content_encoding.h" #include "http_proxy.h" -#include "curlx/warnless.h" #include "http2.h" #include "cfilters.h" #include "connect.h" #include "strdup.h" #include "altsvc.h" #include "hsts.h" +#include "rtsp.h" #include "ws.h" -#include "curl_ctype.h" +#include "bufref.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* * Forward declarations. */ @@ -114,7 +108,8 @@ static CURLcode http_statusline(struct Curl_easy *data, struct connectdata *conn); static CURLcode http_target(struct Curl_easy *data, struct dynbuf *req); static CURLcode http_useragent(struct Curl_easy *data); - +static CURLcode http_write_header(struct Curl_easy *data, + const char *hd, size_t hdlen); /* * HTTP handler interface. @@ -125,13 +120,13 @@ const struct Curl_handler Curl_handler_http = { Curl_http, /* do_it */ Curl_http_done, /* done */ ZERO_NULL, /* do_more */ - Curl_http_connect, /* connect_it */ + ZERO_NULL, /* connect_it */ ZERO_NULL, /* connecting */ ZERO_NULL, /* doing */ ZERO_NULL, /* proto_pollset */ - Curl_http_do_pollset, /* doing_pollset */ + Curl_http_doing_pollset, /* doing_pollset */ ZERO_NULL, /* domore_pollset */ - ZERO_NULL, /* perform_pollset */ + Curl_http_perform_pollset, /* perform_pollset */ ZERO_NULL, /* disconnect */ Curl_http_write_resp, /* write_resp */ Curl_http_write_resp_hd, /* write_resp_hd */ @@ -142,7 +137,8 @@ const struct Curl_handler Curl_handler_http = { CURLPROTO_HTTP, /* protocol */ CURLPROTO_HTTP, /* family */ PROTOPT_CREDSPERREQUEST | /* flags */ - PROTOPT_USERPWDCTRL + PROTOPT_USERPWDCTRL | PROTOPT_CONN_REUSE + }; #ifdef USE_SSL @@ -155,13 +151,13 @@ const struct Curl_handler Curl_handler_https = { Curl_http, /* do_it */ Curl_http_done, /* done */ ZERO_NULL, /* do_more */ - Curl_http_connect, /* connect_it */ + ZERO_NULL, /* connect_it */ NULL, /* connecting */ ZERO_NULL, /* doing */ NULL, /* proto_pollset */ - Curl_http_do_pollset, /* doing_pollset */ + Curl_http_doing_pollset, /* doing_pollset */ ZERO_NULL, /* domore_pollset */ - ZERO_NULL, /* perform_pollset */ + Curl_http_perform_pollset, /* perform_pollset */ ZERO_NULL, /* disconnect */ Curl_http_write_resp, /* write_resp */ Curl_http_write_resp_hd, /* write_resp_hd */ @@ -172,7 +168,7 @@ const struct Curl_handler Curl_handler_https = { CURLPROTO_HTTPS, /* protocol */ CURLPROTO_HTTP, /* family */ PROTOPT_SSL | PROTOPT_CREDSPERREQUEST | PROTOPT_ALPN | /* flags */ - PROTOPT_USERPWDCTRL + PROTOPT_USERPWDCTRL | PROTOPT_CONN_REUSE }; #endif @@ -220,7 +216,6 @@ CURLcode Curl_http_setup_conn(struct Curl_easy *data, { /* allocate the HTTP-specific struct for the Curl_easy, only to survive during this request */ - connkeep(conn, "HTTP default"); if(data->state.http_neg.wanted == CURL_HTTP_V3x) { /* only HTTP/3, needs to work */ CURLcode result = Curl_conn_may_http3(data, conn, conn->transport_wanted); @@ -259,7 +254,7 @@ char *Curl_checkProxyheaders(struct Curl_easy *data, } #else /* disabled */ -#define Curl_checkProxyheaders(x,y,z,a) NULL +#define Curl_checkProxyheaders(x, y, z, a) NULL #endif static bool http_header_is_empty(const char *header) @@ -277,7 +272,7 @@ static bool http_header_is_empty(const char *header) /* * Strip off leading and trailing whitespace from the value in the given HTTP - * header line and return a strdup()ed copy in 'valp' - returns an empty + * header line and return a strdup-ed copy in 'valp' - returns an empty * string if the header value consists entirely of whitespace. * * If the header is provided as "name;", ending with a semicolon, it returns a @@ -305,7 +300,7 @@ static CURLcode copy_custom_value(const char *header, char **valp) /* * Strip off leading and trailing whitespace from the value in the given HTTP - * header line and return a strdup()ed copy in 'valp' - returns an empty + * header line and return a strdup-ed copy in 'valp' - returns an empty * string if the header value consists entirely of whitespace. * * This function MUST be used after the header has already been confirmed to @@ -367,7 +362,8 @@ static CURLcode http_output_basic(struct Curl_easy *data, bool proxy) if(!out) return CURLE_OUT_OF_MEMORY; - result = curlx_base64_encode(out, strlen(out), &authorization, &size); + result = curlx_base64_encode((uint8_t *)out, strlen(out), + &authorization, &size); if(result) goto fail; @@ -376,18 +372,18 @@ static CURLcode http_output_basic(struct Curl_easy *data, bool proxy) goto fail; } - free(*userp); + curlx_free(*userp); *userp = curl_maprintf("%sAuthorization: Basic %s\r\n", proxy ? "Proxy-" : "", authorization); - free(authorization); + curlx_free(authorization); if(!*userp) { result = CURLE_OUT_OF_MEMORY; goto fail; } fail: - free(out); + curlx_free(out); return result; } @@ -406,7 +402,7 @@ static CURLcode http_output_bearer(struct Curl_easy *data) CURLcode result = CURLE_OK; userp = &data->state.aptr.userpwd; - free(*userp); + curlx_free(*userp); *userp = curl_maprintf("Authorization: Bearer %s\r\n", data->set.str[STRING_BEARER]); @@ -504,7 +500,7 @@ static CURLcode http_perhapsrewind(struct Curl_easy *data, return CURLE_OK; if(abort_upload) { - /* We'd like to abort the upload - but should we? */ + /* We would like to abort the upload - but should we? */ #ifdef USE_NTLM if((data->state.authproxy.picked == CURLAUTH_NTLM) || (data->state.authhost.picked == CURLAUTH_NTLM)) { @@ -602,7 +598,6 @@ CURLcode Curl_http_auth_act(struct Curl_easy *data) data->state.authproblem = TRUE; else data->info.proxyauthpicked = data->state.authproxy.picked; - } #endif @@ -614,13 +609,14 @@ CURLcode Curl_http_auth_act(struct Curl_easy *data) /* In case this is GSS auth, the newurl field is already allocated so we must make sure to free it before allocating a new one. As figured out in bug #2284386 */ - free(data->req.newurl); - data->req.newurl = strdup(data->state.url); /* clone URL */ + curlx_free(data->req.newurl); + /* clone URL */ + data->req.newurl = Curl_bufref_dup(&data->state.url); if(!data->req.newurl) return CURLE_OUT_OF_MEMORY; } else if((data->req.httpcode < 300) && - (!data->state.authhost.done) && + !data->state.authhost.done && data->req.authneg) { /* no (known) authentication available, authentication is not "done" yet and @@ -628,7 +624,8 @@ CURLcode Curl_http_auth_act(struct Curl_easy *data) we did not try HEAD or GET */ if((data->state.httpreq != HTTPREQ_GET) && (data->state.httpreq != HTTPREQ_HEAD)) { - data->req.newurl = strdup(data->state.url); /* clone URL */ + /* clone URL */ + data->req.newurl = Curl_bufref_dup(&data->state.url); if(!data->req.newurl) return CURLE_OUT_OF_MEMORY; data->state.authhost.done = TRUE; @@ -648,13 +645,12 @@ CURLcode Curl_http_auth_act(struct Curl_easy *data) * Output the correct authentication header depending on the auth type * and whether or not it is to a proxy. */ -static CURLcode -output_auth_headers(struct Curl_easy *data, - struct connectdata *conn, - struct auth *authstatus, - const char *request, - const char *path, - bool proxy) +static CURLcode output_auth_headers(struct Curl_easy *data, + struct connectdata *conn, + struct auth *authstatus, + const char *request, + const char *path, + bool proxy) { const char *auth = NULL; CURLcode result = CURLE_OK; @@ -868,13 +864,12 @@ Curl_http_output_auth(struct Curl_easy *data, #else /* when disabled */ -CURLcode -Curl_http_output_auth(struct Curl_easy *data, - struct connectdata *conn, - const char *request, - Curl_HttpReq httpreq, - const char *path, - bool proxytunnel) +CURLcode Curl_http_output_auth(struct Curl_easy *data, + struct connectdata *conn, + const char *request, + Curl_HttpReq httpreq, + const char *path, + bool proxytunnel) { (void)data; (void)conn; @@ -915,8 +910,8 @@ static CURLcode auth_spnego(struct Curl_easy *data, curlnegotiate *negstate = proxy ? &conn->proxy_negotiate_state : &conn->http_negotiate_state; if(!result) { - free(data->req.newurl); - data->req.newurl = strdup(data->state.url); + curlx_free(data->req.newurl); + data->req.newurl = Curl_bufref_dup(&data->state.url); if(!data->req.newurl) return CURLE_OUT_OF_MEMORY; data->state.authproblem = FALSE; @@ -949,6 +944,8 @@ static CURLcode auth_ntlm(struct Curl_easy *data, if(!result) data->state.authproblem = FALSE; else { + if(result == CURLE_OUT_OF_MEMORY) + return result; infof(data, "NTLM authentication problem, ignoring."); data->state.authproblem = TRUE; } @@ -979,6 +976,8 @@ static CURLcode auth_digest(struct Curl_easy *data, * Digest */ result = Curl_input_digest(data, proxy, auth); if(result) { + if(result == CURLE_OUT_OF_MEMORY) + return result; infof(data, "Digest authentication problem, ignoring."); data->state.authproblem = TRUE; } @@ -1235,18 +1234,15 @@ CURLcode Curl_http_follow(struct Curl_easy *data, const char *newurl, /* We are asked to automatically set the previous URL as the referer when we get the next URL. We pick the ->url field, which may or may not be 100% correct */ - - if(data->state.referer_alloc) { - Curl_safefree(data->state.referer); - data->state.referer_alloc = FALSE; - } + Curl_bufref_free(&data->state.referer); /* Make a copy of the URL without credentials and fragment */ u = curl_url(); if(!u) return CURLE_OUT_OF_MEMORY; - uc = curl_url_set(u, CURLUPART_URL, data->state.url, 0); + uc = curl_url_set(u, CURLUPART_URL, + Curl_bufref_ptr(&data->state.url), 0); if(!uc) uc = curl_url_set(u, CURLUPART_FRAGMENT, NULL, 0); if(!uc) @@ -1261,8 +1257,7 @@ CURLcode Curl_http_follow(struct Curl_easy *data, const char *newurl, if(uc || !referer) return CURLE_OUT_OF_MEMORY; - data->state.referer = referer; - data->state.referer_alloc = TRUE; /* yes, free this later */ + Curl_bufref_set(&data->state.referer, referer, 0, curl_free); } } } @@ -1282,7 +1277,7 @@ CURLcode Curl_http_follow(struct Curl_easy *data, const char *newurl, CURLU_ALLOW_SPACE | (data->set.path_as_is ? CURLU_PATH_AS_IS : 0))); if(uc) { - if(type != FOLLOW_FAKE) { + if((uc == CURLUE_OUT_OF_MEMORY) || (type != FOLLOW_FAKE)) { failf(data, "The redirect target URL could not be parsed: %s", curl_url_strerror(uc)); return Curl_uc_to_curlcode(uc); @@ -1290,7 +1285,7 @@ CURLcode Curl_http_follow(struct Curl_easy *data, const char *newurl, /* the URL could not be parsed for some reason, but since this is FAKE mode, just duplicate the field as-is */ - follow_url = strdup(newurl); + follow_url = curlx_strdup(newurl); if(!follow_url) return CURLE_OUT_OF_MEMORY; } @@ -1302,7 +1297,6 @@ CURLcode Curl_http_follow(struct Curl_easy *data, const char *newurl, /* Clear auth if this redirects to a different port number or protocol, unless permitted */ if(!data->set.allow_auth_to_other_hosts && (type != FOLLOW_FAKE)) { - char *portnum; int port; bool clear = FALSE; @@ -1310,14 +1304,19 @@ CURLcode Curl_http_follow(struct Curl_easy *data, const char *newurl, /* a custom port is used */ port = (int)data->set.use_port; else { + curl_off_t value; + char *portnum; + const char *p; uc = curl_url_get(data->state.uh, CURLUPART_PORT, &portnum, CURLU_DEFAULT_PORT); if(uc) { - free(follow_url); + curlx_free(follow_url); return Curl_uc_to_curlcode(uc); } - port = atoi(portnum); - free(portnum); + p = portnum; + curlx_str_number(&p, &value, 0xffff); + port = (int)value; + curlx_free(portnum); } if(port != data->info.conn_remote_port) { infof(data, "Clear auth, redirects to port from %u to %u", @@ -1329,7 +1328,7 @@ CURLcode Curl_http_follow(struct Curl_easy *data, const char *newurl, const struct Curl_handler *p; uc = curl_url_get(data->state.uh, CURLUPART_SCHEME, &scheme, 0); if(uc) { - free(follow_url); + curlx_free(follow_url); return Curl_uc_to_curlcode(uc); } @@ -1339,7 +1338,7 @@ CURLcode Curl_http_follow(struct Curl_easy *data, const char *newurl, data->info.conn_scheme, scheme); clear = TRUE; } - free(scheme); + curlx_free(scheme); } if(clear) { Curl_safefree(data->state.aptr.user); @@ -1364,13 +1363,9 @@ CURLcode Curl_http_follow(struct Curl_easy *data, const char *newurl, if(disallowport) data->state.allow_port = FALSE; - if(data->state.url_alloc) - Curl_safefree(data->state.url); - - data->state.url = follow_url; - data->state.url_alloc = TRUE; + Curl_bufref_set(&data->state.url, follow_url, 0, curl_free); rewind_result = Curl_req_soft_reset(&data->req, data); - infof(data, "Issue another request to this URL: '%s'", data->state.url); + infof(data, "Issue another request to this URL: '%s'", follow_url); if((data->set.http_follow_mode == CURLFOLLOW_FIRSTONLY) && data->set.str[STRING_CUSTOMREQUEST] && !data->state.http_ignorecustom) { @@ -1393,7 +1388,7 @@ CURLcode Curl_http_follow(struct Curl_easy *data, const char *newurl, /* 300 - Multiple Choices */ /* 306 - Not used */ /* 307 - Temporary Redirect */ - default: /* for all above (and the unknown ones) */ + default: /* for all above (and the unknown ones) */ /* Some codes are explicitly mentioned since I have checked RFC2616 and * they seem to be OK to POST to. */ @@ -1415,10 +1410,10 @@ CURLcode Curl_http_follow(struct Curl_easy *data, const char *newurl, * This behavior is forbidden by RFC1945 and the obsolete RFC2616, and * can be overridden with CURLOPT_POSTREDIR. */ - if((data->state.httpreq == HTTPREQ_POST - || data->state.httpreq == HTTPREQ_POST_FORM - || data->state.httpreq == HTTPREQ_POST_MIME) - && !(data->set.keep_post & CURL_REDIR_POST_301)) { + if((data->state.httpreq == HTTPREQ_POST || + data->state.httpreq == HTTPREQ_POST_FORM || + data->state.httpreq == HTTPREQ_POST_MIME) && + !(data->set.keep_post & CURL_REDIR_POST_301)) { http_switch_to_get(data, 301); switch_to_get = TRUE; } @@ -1440,10 +1435,10 @@ CURLcode Curl_http_follow(struct Curl_easy *data, const char *newurl, * This behavior is forbidden by RFC1945 and the obsolete RFC2616, and * can be overridden with CURLOPT_POSTREDIR. */ - if((data->state.httpreq == HTTPREQ_POST - || data->state.httpreq == HTTPREQ_POST_FORM - || data->state.httpreq == HTTPREQ_POST_MIME) - && !(data->set.keep_post & CURL_REDIR_POST_302)) { + if((data->state.httpreq == HTTPREQ_POST || + data->state.httpreq == HTTPREQ_POST_FORM || + data->state.httpreq == HTTPREQ_POST_MIME) && + !(data->set.keep_post & CURL_REDIR_POST_302)) { http_switch_to_get(data, 302); switch_to_get = TRUE; } @@ -1497,12 +1492,11 @@ CURLcode Curl_http_follow(struct Curl_easy *data, const char *newurl, * Returns TRUE if 'headerline' contains the 'header' with given 'content'. * Pass headers WITH the colon. */ -bool -Curl_compareheader(const char *headerline, /* line to check */ - const char *header, /* header keyword _with_ colon */ - const size_t hlen, /* len of the keyword in bytes */ - const char *content, /* content string to find */ - const size_t clen) /* len of the content in bytes */ +bool Curl_compareheader(const char *headerline, /* line to check */ + const char *header, /* header keyword _with_ colon */ + const size_t hlen, /* len of the keyword in bytes */ + const char *content, /* content string to find */ + const size_t clen) /* len of the content in bytes */ { /* RFC2616, section 4.2 says: "Each header field consists of a name followed * by a colon (":") and the field value. Field names are case-insensitive. @@ -1538,31 +1532,33 @@ Curl_compareheader(const char *headerline, /* line to check */ return FALSE; /* no match */ } -/* - * Curl_http_connect() performs HTTP stuff to do at connect-time, called from - * the generic Curl_connect(). - */ -CURLcode Curl_http_connect(struct Curl_easy *data, bool *done) -{ - struct connectdata *conn = data->conn; - - /* We default to persistent connections. We set this already in this connect - function to make the reuse checks properly be able to check this bit. */ - connkeep(conn, "HTTP default"); - - return Curl_conn_connect(data, FIRSTSOCKET, FALSE, done); -} - /* this returns the socket to wait for in the DO and DOING state for the multi interface and then we are always _sending_ a request and thus we wait for the single socket to become writable only */ -CURLcode Curl_http_do_pollset(struct Curl_easy *data, - struct easy_pollset *ps) +CURLcode Curl_http_doing_pollset(struct Curl_easy *data, + struct easy_pollset *ps) { /* write mode */ return Curl_pollset_add_out(data, ps, data->conn->sock[FIRSTSOCKET]); } +CURLcode Curl_http_perform_pollset(struct Curl_easy *data, + struct easy_pollset *ps) +{ + struct connectdata *conn = data->conn; + CURLcode result = CURLE_OK; + + if(CURL_WANT_RECV(data)) { + result = Curl_pollset_add_in(data, ps, conn->sock[FIRSTSOCKET]); + } + + /* on a "Expect: 100-continue" timed wait, do not poll for outgoing */ + if(!result && Curl_req_want_send(data) && !http_exp100_is_waiting(data)) { + result = Curl_pollset_add_out(data, ps, conn->sock[FIRSTSOCKET]); + } + return result; +} + /* * Curl_http_done() gets called after a single HTTP request has been * performed. @@ -1578,6 +1574,10 @@ CURLcode Curl_http_done(struct Curl_easy *data, data->state.authhost.multipass = FALSE; data->state.authproxy.multipass = FALSE; + if(curlx_dyn_len(&data->state.headerb)) { + (void)http_write_header(data, curlx_dyn_ptr(&data->state.headerb), + curlx_dyn_len(&data->state.headerb)); + } curlx_dyn_reset(&data->state.headerb); if(status) @@ -1635,14 +1635,14 @@ static unsigned char http_request_version(struct Curl_easy *data) static const char *get_http_string(int httpversion) { switch(httpversion) { - case 30: - return "3"; - case 20: - return "2"; - case 11: - return "1.1"; - default: - return "1.0"; + case 30: + return "3"; + case 20: + return "2"; + case 11: + return "1.1"; + default: + return "1.0"; } } @@ -1712,7 +1712,7 @@ CURLcode Curl_add_custom_headers(struct Curl_easy *data, curlx_str_untilnl(&p, &val, MAX_HTTP_RESP_HEADER_SIZE); curlx_str_trimblanks(&val); if(!curlx_strlen(&val)) - /* no content, don't send this */ + /* no content, do not send this */ continue; } else @@ -1783,7 +1783,7 @@ CURLcode Curl_add_timecondition(struct Curl_easy *data, /* no condition was asked for */ return CURLE_OK; - result = Curl_gmtime(data->set.timevalue, &keeptime); + result = curlx_gmtime(data->set.timevalue, &keeptime); if(result) { failf(data, "Invalid TIMEVALUE"); return result; @@ -1825,7 +1825,7 @@ CURLcode Curl_add_timecondition(struct Curl_easy *data, curl_msnprintf(datestr, sizeof(datestr), "%s: %s, %02d %s %4d %02d:%02d:%02d GMT\r\n", condp, - Curl_wkday[tm->tm_wday ? tm->tm_wday-1 : 6], + Curl_wkday[tm->tm_wday ? tm->tm_wday - 1 : 6], tm->tm_mday, Curl_month[tm->tm_mon], tm->tm_year + 1900, @@ -1853,11 +1853,11 @@ void Curl_http_method(struct Curl_easy *data, Curl_HttpReq httpreq = (Curl_HttpReq)data->state.httpreq; const char *request; #ifndef CURL_DISABLE_WEBSOCKETS - if(data->conn->handler->protocol&(CURLPROTO_WS|CURLPROTO_WSS)) + if(data->conn->handler->protocol & (CURLPROTO_WS | CURLPROTO_WSS)) httpreq = HTTPREQ_GET; else #endif - if((data->conn->handler->protocol&(PROTO_FAMILY_HTTP|CURLPROTO_FTP)) && + if((data->conn->handler->protocol & (PROTO_FAMILY_HTTP | CURLPROTO_FTP)) && data->state.upload) httpreq = HTTPREQ_PUT; @@ -1901,13 +1901,12 @@ static CURLcode http_useragent(struct Curl_easy *data) with the user-agent string specified, we erase the previously made string here. */ if(Curl_checkheaders(data, STRCONST("User-Agent"))) { - free(data->state.aptr.uagent); + curlx_free(data->state.aptr.uagent); data->state.aptr.uagent = NULL; } return CURLE_OK; } - static CURLcode http_set_aptr_host(struct Curl_easy *data) { struct connectdata *conn = data->conn; @@ -1916,9 +1915,9 @@ static CURLcode http_set_aptr_host(struct Curl_easy *data) if(!data->state.this_is_a_follow) { /* Free to avoid leaking memory on multiple requests */ - free(data->state.first_host); + curlx_free(data->state.first_host); - data->state.first_host = strdup(conn->host.name); + data->state.first_host = curlx_strdup(conn->host.name); if(!data->state.first_host) return CURLE_OUT_OF_MEMORY; @@ -1942,7 +1941,7 @@ static CURLcode http_set_aptr_host(struct Curl_easy *data) return result; if(!*cookiehost) /* ignore empty data */ - free(cookiehost); + curlx_free(cookiehost); else { /* If the host begins with '[', we start searching for the port after the bracket has been closed */ @@ -1961,7 +1960,7 @@ static CURLcode http_set_aptr_host(struct Curl_easy *data) if(colon) *colon = 0; /* The host must not include an embedded port number */ } - free(aptr->cookiehost); + curlx_free(aptr->cookiehost); aptr->cookiehost = cookiehost; } #endif @@ -1977,10 +1976,10 @@ static CURLcode http_set_aptr_host(struct Curl_easy *data) [brackets] if the hostname is a plain IPv6-address. RFC2732-style. */ const char *host = conn->host.name; - if(((conn->given->protocol&(CURLPROTO_HTTPS|CURLPROTO_WSS)) && + if(((conn->given->protocol & (CURLPROTO_HTTPS | CURLPROTO_WSS)) && (conn->remote_port == PORT_HTTPS)) || - ((conn->given->protocol&(CURLPROTO_HTTP|CURLPROTO_WS)) && - (conn->remote_port == PORT_HTTP)) ) + ((conn->given->protocol & (CURLPROTO_HTTP | CURLPROTO_WS)) && + (conn->remote_port == PORT_HTTP))) /* if(HTTPS on port 443) OR (HTTP on port 80) then do not include the port number in the host string */ aptr->host = curl_maprintf("Host: %s%s%s\r\n", @@ -2070,7 +2069,7 @@ static CURLcode http_target(struct Curl_easy *data, /* target or URL */ result = curlx_dyn_add(r, data->set.str[STRING_TARGET] ? data->set.str[STRING_TARGET] : url); - free(url); + curlx_free(url); if(result) return result; @@ -2126,7 +2125,7 @@ static CURLcode set_post_reader(struct Curl_easy *data, Curl_HttpReq httpreq) /* Convert the form structure into a mime structure, then keep the conversion */ if(!data->state.formp) { - data->state.formp = calloc(1, sizeof(curl_mimepart)); + data->state.formp = curlx_calloc(1, sizeof(curl_mimepart)); if(!data->state.formp) return CURLE_OUT_OF_MEMORY; Curl_mime_cleanpart(data->state.formp); @@ -2218,9 +2217,11 @@ static CURLcode set_reader(struct Curl_easy *data, Curl_HttpReq httpreq) result = Curl_creader_set_null(data); } else if(data->set.postfields) { - if(postsize > 0) - result = Curl_creader_set_buf(data, data->set.postfields, - (size_t)postsize); + size_t plen = curlx_sotouz_range(postsize, 0, SIZE_MAX); + if(plen == SIZE_MAX) + return CURLE_OUT_OF_MEMORY; + else if(plen) + result = Curl_creader_set_buf(data, data->set.postfields, plen); else result = Curl_creader_set_null(data); } @@ -2398,7 +2399,7 @@ static CURLcode http_add_content_hds(struct Curl_easy *data, (data->req.authneg || !Curl_checkheaders(data, STRCONST("Content-Length")))) { /* we allow replacing this header if not during auth negotiation, - although it is not very wise to actually set your own */ + although it is not wise to actually set your own */ result = curlx_dyn_addf(r, "Content-Length: %" FMT_OFF_T "\r\n", req_clen); } @@ -2459,10 +2460,12 @@ static CURLcode http_cookies(struct Curl_easy *data, int count = 0; if(data->cookies && data->state.cookie_engine) { + bool okay; const char *host = data->state.aptr.cookiehost ? data->state.aptr.cookiehost : data->conn->host.name; Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE); - if(!Curl_cookie_getlist(data, data->conn, host, &list)) { + result = Curl_cookie_getlist(data, data->conn, &okay, host, &list); + if(!result && okay) { struct Curl_llist_node *n; size_t clen = 8; /* hold the size of the generated Cookie: header */ @@ -2512,7 +2515,7 @@ static CURLcode http_cookies(struct Curl_easy *data, return result; } #else -#define http_cookies(a,b) CURLE_OK +#define http_cookies(a, b) CURLE_OK #endif static CURLcode http_range(struct Curl_easy *data, @@ -2527,15 +2530,17 @@ static CURLcode http_range(struct Curl_easy *data, if(((httpreq == HTTPREQ_GET) || (httpreq == HTTPREQ_HEAD)) && !Curl_checkheaders(data, STRCONST("Range"))) { /* if a line like this was already allocated, free the previous one */ - free(data->state.aptr.rangeline); + curlx_free(data->state.aptr.rangeline); data->state.aptr.rangeline = curl_maprintf("Range: bytes=%s\r\n", data->state.range); + if(!data->state.aptr.rangeline) + return CURLE_OUT_OF_MEMORY; } else if((httpreq == HTTPREQ_POST || httpreq == HTTPREQ_PUT) && !Curl_checkheaders(data, STRCONST("Content-Range"))) { curl_off_t req_clen = Curl_creader_total_length(data); /* if a line like this was already allocated, free the previous one */ - free(data->state.aptr.rangeline); + curlx_free(data->state.aptr.rangeline); if(data->set.set_resume_from < 0) { /* Upload resume was asked for, but we do not know the size of the @@ -2557,7 +2562,7 @@ static CURLcode http_range(struct Curl_easy *data, data->state.aptr.rangeline = curl_maprintf("Content-Range: bytes %s%" FMT_OFF_T "/" "%" FMT_OFF_T "\r\n", - data->state.range, total_len-1, total_len); + data->state.range, total_len - 1, total_len); } else { /* Range was selected and then we just pass the incoming range and @@ -2701,7 +2706,7 @@ static CURLcode http_add_connection_hd(struct Curl_easy *data, return result; result = curlx_dyn_addf(req, "%s%s", sep, value); sep = ", "; - free(value); + curlx_free(value); break; /* leave, having added 1st one */ } } @@ -2851,8 +2856,10 @@ static CURLcode http_add_hd(struct Curl_easy *data, case H1_HD_REFERER: Curl_safefree(data->state.aptr.ref); - if(data->state.referer && !Curl_checkheaders(data, STRCONST("Referer"))) - result = curlx_dyn_addf(req, "Referer: %s\r\n", data->state.referer); + if(Curl_bufref_ptr(&data->state.referer) && + !Curl_checkheaders(data, STRCONST("Referer"))) + result = curlx_dyn_addf(req, "Referer: %s\r\n", + Curl_bufref_ptr(&data->state.referer)); break; #ifndef CURL_DISABLE_PROXY @@ -2887,7 +2894,7 @@ static CURLcode http_add_hd(struct Curl_easy *data, result = Curl_http2_request_upgrade(req, data); } #ifndef CURL_DISABLE_WEBSOCKETS - if(!result && conn->handler->protocol&(CURLPROTO_WS|CURLPROTO_WSS)) + if(!result && conn->handler->protocol & (CURLPROTO_WS | CURLPROTO_WSS)) result = Curl_ws_request(data, req); #endif break; @@ -2943,6 +2950,7 @@ CURLcode Curl_http(struct Curl_easy *data, bool *done) /* make sure the header buffer is reset - if there are leftovers from a previous transfer */ curlx_dyn_reset(&data->state.headerb); + data->state.maybe_folded = FALSE; if(!data->conn->bits.reuse) { result = http_check_new_conn(data); @@ -2978,7 +2986,7 @@ CURLcode Curl_http(struct Curl_easy *data, bool *done) } result = Curl_http_output_auth(data, data->conn, method, httpreq, (pq ? pq : data->state.up.path), FALSE); - free(pq); + curlx_free(pq); } if(result) goto out; @@ -3035,7 +3043,6 @@ typedef enum { STATUS_BAD /* not a status line */ } statusline; - /* Check a string for a prefix. Check no more than 'len' bytes */ static bool checkprefixmax(const char *prefix, const char *buffer, size_t len) { @@ -3048,9 +3055,8 @@ static bool checkprefixmax(const char *prefix, const char *buffer, size_t len) * * Returns TRUE if member of the list matches prefix of string */ -static statusline -checkhttpprefix(struct Curl_easy *data, - const char *s, size_t len) +static statusline checkhttpprefix(struct Curl_easy *data, + const char *s, size_t len) { struct curl_slist *head = data->set.http200aliases; statusline rc = STATUS_BAD; @@ -3071,9 +3077,8 @@ checkhttpprefix(struct Curl_easy *data, } #ifndef CURL_DISABLE_RTSP -static statusline -checkrtspprefix(struct Curl_easy *data, - const char *s, size_t len) +static statusline checkrtspprefix(struct Curl_easy *data, + const char *s, size_t len) { statusline result = STATUS_BAD; statusline onmatch = len >= 5 ? STATUS_DONE : STATUS_UNKNOWN; @@ -3085,9 +3090,9 @@ checkrtspprefix(struct Curl_easy *data, } #endif /* CURL_DISABLE_RTSP */ -static statusline -checkprotoprefix(struct Curl_easy *data, struct connectdata *conn, - const char *s, size_t len) +static statusline checkprotoprefix(struct Curl_easy *data, + struct connectdata *conn, + const char *s, size_t len) { #ifndef CURL_DISABLE_RTSP if(conn->handler->protocol & CURLPROTO_RTSP) @@ -3101,17 +3106,17 @@ checkprotoprefix(struct Curl_easy *data, struct connectdata *conn, /* HTTP header has field name `n` (a string constant) */ #define HD_IS(hd, hdlen, n) \ - (((hdlen) >= (sizeof(n)-1)) && curl_strnequal((n), (hd), (sizeof(n)-1))) + (((hdlen) >= (sizeof(n) - 1)) && curl_strnequal((n), (hd), (sizeof(n) - 1))) #define HD_VAL(hd, hdlen, n) \ - ((((hdlen) >= (sizeof(n)-1)) && \ - curl_strnequal((n), (hd), (sizeof(n)-1)))? (hd + (sizeof(n)-1)) : NULL) + ((((hdlen) >= (sizeof(n) - 1)) && \ + curl_strnequal((n), (hd), (sizeof(n) - 1)))? (hd + (sizeof(n) - 1)) : NULL) /* HTTP header has field name `n` (a string constant) and contains `v` * (a string constant) in its value(s) */ #define HD_IS_AND_SAYS(hd, hdlen, n, v) \ (HD_IS(hd, hdlen, n) && \ - ((hdlen) > ((sizeof(n)-1) + (sizeof(v)-1))) && \ + ((hdlen) > ((sizeof(n) - 1) + (sizeof(v) - 1))) && \ Curl_compareheader(hd, STRCONST(n), STRCONST(v))) /* @@ -3223,21 +3228,22 @@ static CURLcode http_header_c(struct Curl_easy *data, return CURLE_OUT_OF_MEMORY; if(!*contenttype) /* ignore empty data */ - free(contenttype); + curlx_free(contenttype); else { - free(data->info.contenttype); + curlx_free(data->info.contenttype); data->info.contenttype = contenttype; } return CURLE_OK; } - if(HD_IS_AND_SAYS(hd, hdlen, "Connection:", "close")) { + if((k->httpversion < 20) && + HD_IS_AND_SAYS(hd, hdlen, "Connection:", "close")) { /* * [RFC 2616, section 8.1.2.1] * "Connection: close" is HTTP/1.1 language and means that * the connection will close when this request has been * served. */ - streamclose(conn, "Connection: close used"); + connclose(conn, "Connection: close used"); return CURLE_OK; } if((k->httpversion == 10) && @@ -3310,14 +3316,14 @@ static CURLcode http_header_l(struct Curl_easy *data, if(!*location || (data->req.location && !strcmp(data->req.location, location))) { /* ignore empty header, or exact repeat of a previous one */ - free(location); + curlx_free(location); return CURLE_OK; } else { /* has value and is not an exact repeat */ if(data->req.location) { failf(data, "Multiple Location headers"); - free(location); + curlx_free(location); return CURLE_WEIRD_SERVER_REPLY; } data->req.location = location; @@ -3326,7 +3332,7 @@ static CURLcode http_header_l(struct Curl_easy *data, data->set.http_follow_mode) { CURLcode result; DEBUGASSERT(!data->req.newurl); - data->req.newurl = strdup(data->req.location); /* clone */ + data->req.newurl = curlx_strdup(data->req.location); /* clone */ if(!data->req.newurl) return CURLE_OUT_OF_MEMORY; @@ -3384,7 +3390,7 @@ static CURLcode http_header_p(struct Curl_easy *data, CURLcode result = auth ? CURLE_OK : CURLE_OUT_OF_MEMORY; if(!result) { result = Curl_http_input_auth(data, TRUE, auth); - free(auth); + curlx_free(auth); } return result; } @@ -3403,7 +3409,7 @@ static CURLcode http_header_p(struct Curl_easy *data, negdata->havenoauthpersist = TRUE; infof(data, "Negotiate: noauthpersist -> %d, header part: %s", negdata->noauthpersist, persistentauth); - free(persistentauth); + curlx_free(persistentauth); } } #endif @@ -3467,11 +3473,12 @@ static CURLcode http_header_s(struct Curl_easy *data, const char *host = data->state.aptr.cookiehost ? data->state.aptr.cookiehost : conn->host.name; const bool secure_context = Curl_secure_context(conn, host); + CURLcode result; Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE); - Curl_cookie_add(data, data->cookies, TRUE, FALSE, v, host, - data->state.up.path, secure_context); + result = Curl_cookie_add(data, data->cookies, TRUE, FALSE, v, host, + data->state.up.path, secure_context); Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE); - return CURLE_OK; + return result; } #endif #ifndef CURL_DISABLE_HSTS @@ -3489,8 +3496,11 @@ static CURLcode http_header_s(struct Curl_easy *data, if(v) { CURLcode check = Curl_hsts_parse(data->hsts, conn->host.name, v); - if(check) + if(check) { + if(check == CURLE_OUT_OF_MEMORY) + return check; infof(data, "Illegal STS header skipped"); + } #ifdef DEBUGBUILD else infof(data, "Parsed STS header fine (%zu entries)", @@ -3563,7 +3573,7 @@ static CURLcode http_header_w(struct Curl_easy *data, result = CURLE_OUT_OF_MEMORY; else { result = Curl_http_input_auth(data, FALSE, auth); - free(auth); + curlx_free(auth); } } return result; @@ -3640,15 +3650,15 @@ static CURLcode http_statusline(struct Curl_easy *data, #endif /* no major version switch mid-connection */ if(k->httpversion_sent && - (k->httpversion/10 != k->httpversion_sent/10)) { + (k->httpversion / 10 != k->httpversion_sent / 10)) { failf(data, "Version mismatch (from HTTP/%u to HTTP/%u)", - k->httpversion_sent/10, k->httpversion/10); + k->httpversion_sent / 10, k->httpversion / 10); return CURLE_WEIRD_SERVER_REPLY; } break; default: failf(data, "Unsupported HTTP version (%u.%d) in response", - k->httpversion/10, k->httpversion%10); + k->httpversion / 10, k->httpversion % 10); return CURLE_UNSUPPORTED_PROTOCOL; } @@ -3801,7 +3811,7 @@ static CURLcode http_write_header(struct Curl_easy *data, Curl_debug(data, CURLINFO_HEADER_IN, hd, hdlen); writetype = CLIENTWRITE_HEADER | - ((data->req.httpcode/100 == 1) ? CLIENTWRITE_1XX : 0); + ((data->req.httpcode / 100 == 1) ? CLIENTWRITE_1XX : 0); result = Curl_client_write(data, writetype, hd, hdlen); if(result) @@ -3987,8 +3997,7 @@ static CURLcode http_on_response(struct Curl_easy *data, /* Check if this response means the transfer errored. */ if(http_should_fail(data, data->req.httpcode)) { - failf(data, "The requested URL returned error: %d", - k->httpcode); + failf(data, "The requested URL returned error: %d", k->httpcode); result = CURLE_HTTP_RETURNED_ERROR; goto out; } @@ -4009,7 +4018,7 @@ static CURLcode http_on_response(struct Curl_easy *data, * * The check for close above is done simply because of something * else has already deemed the connection to get closed then - * something else should've considered the big picture and we + * something else should have considered the big picture and we * avoid this check. * */ @@ -4032,8 +4041,7 @@ static CURLcode http_on_response(struct Curl_easy *data, } else { infof(data, "Got HTTP failure 417 while sending data"); - streamclose(conn, - "Stop sending data before everything sent"); + streamclose(conn, "Stop sending data before everything sent"); result = http_perhapsrewind(data, conn); if(result) goto out; @@ -4041,7 +4049,7 @@ static CURLcode http_on_response(struct Curl_easy *data, data->state.disableexpect = TRUE; Curl_req_abort_sending(data); DEBUGASSERT(!data->req.newurl); - data->req.newurl = strdup(data->state.url); + data->req.newurl = Curl_bufref_dup(&data->state.url); if(!data->req.newurl) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -4071,7 +4079,6 @@ static CURLcode http_on_response(struct Curl_easy *data, infof(data, "Keep sending data to get tossed away"); k->keepon |= KEEP_SEND; } - } /* If we requested a "no body", this is a good time to get @@ -4081,7 +4088,7 @@ static CURLcode http_on_response(struct Curl_easy *data, k->download_done = TRUE; /* If max download size is *zero* (nothing) we already have - nothing and can safely return ok now! But for HTTP/2, we would + nothing and can safely return ok now! But for HTTP/2, we would like to call http2_handle_stream_close to properly close a stream. In order to do this, we keep reading until we close the stream. */ @@ -4118,6 +4125,7 @@ static CURLcode http_rw_hd(struct Curl_easy *data, CURLcode result = CURLE_OK; struct SingleRequest *k = &data->req; int writetype; + DEBUGASSERT(!hd[hdlen]); /* null terminated */ *pconsumed = 0; if((0x0a == *hd) || (0x0d == *hd)) { @@ -4178,7 +4186,7 @@ static CURLcode http_rw_hd(struct Curl_easy *data, k->httpcode = (p[0] - '0') * 100 + (p[1] - '0') * 10 + (p[2] - '0'); /* RFC 9112 requires a single space following the status code, - but the browsers don't so let's not insist */ + but the browsers do not so let's not insist */ fine_statusline = TRUE; } } @@ -4266,7 +4274,7 @@ static CURLcode http_rw_hd(struct Curl_easy *data, */ Curl_debug(data, CURLINFO_HEADER_IN, hd, hdlen); - if(k->httpcode/100 == 1) + if(k->httpcode / 100 == 1) writetype |= CLIENTWRITE_1XX; result = Curl_client_write(data, writetype, hd, hdlen); if(result) @@ -4279,6 +4287,26 @@ static CURLcode http_rw_hd(struct Curl_easy *data, return CURLE_OK; } +/* remove trailing CRLF then all trailing whitespace */ +void Curl_http_to_fold(struct dynbuf *bf) +{ + size_t len = curlx_dyn_len(bf); + char *hd = curlx_dyn_ptr(bf); + if(len && (hd[len - 1] == '\n')) + len--; + if(len && (hd[len - 1] == '\r')) + len--; + while(len && (ISBLANK(hd[len - 1]))) /* strip off trailing whitespace */ + len--; + curlx_dyn_setlen(bf, len); +} + +static void unfold_header(struct Curl_easy *data) +{ + Curl_http_to_fold(&data->state.headerb); + data->state.leading_unfold = TRUE; +} + /* * Read any HTTP header lines from the server and pass them to the client app. */ @@ -4292,10 +4320,49 @@ static CURLcode http_parse_headers(struct Curl_easy *data, char *end_ptr; bool leftover_body = FALSE; + /* we have bytes for the next header, make sure it is not a folded header + before passing it on */ + if(data->state.maybe_folded && blen) { + if(ISBLANK(buf[0])) { + /* folded, remove the trailing newlines and append the next header */ + unfold_header(data); + } + else { + /* the header data we hold is a complete header, pass it on */ + size_t ignore_this; + result = http_rw_hd(data, curlx_dyn_ptr(&data->state.headerb), + curlx_dyn_len(&data->state.headerb), + NULL, 0, &ignore_this); + curlx_dyn_reset(&data->state.headerb); + if(result) + return result; + } + data->state.maybe_folded = FALSE; + } + /* header line within buffer loop */ *pconsumed = 0; while(blen && k->header) { size_t consumed; + size_t hlen; + char *hd; + size_t unfold_len = 0; + + if(data->state.leading_unfold) { + /* immediately after an unfold, keep only a single whitespace */ + while(blen && ISBLANK(buf[0])) { + buf++; + blen--; + unfold_len++; + } + if(blen) { + /* insert a single space */ + result = curlx_dyn_addn(&data->state.headerb, " ", 1); + if(result) + return result; + data->state.leading_unfold = FALSE; /* done now */ + } + } end_ptr = memchr(buf, '\n', blen); if(!end_ptr) { @@ -4304,7 +4371,7 @@ static CURLcode http_parse_headers(struct Curl_easy *data, result = curlx_dyn_addn(&data->state.headerb, buf, blen); if(result) return result; - *pconsumed += blen; + *pconsumed += blen + unfold_len; if(!k->headerline) { /* check if this looks like a protocol header */ @@ -4333,24 +4400,26 @@ static CURLcode http_parse_headers(struct Curl_easy *data, goto out; /* read more and try again */ } - /* decrease the size of the remaining (supposed) header line */ + /* the size of the remaining header line */ consumed = (end_ptr - buf) + 1; + result = curlx_dyn_addn(&data->state.headerb, buf, consumed); if(result) return result; blen -= consumed; buf += consumed; - *pconsumed += consumed; + *pconsumed += consumed + unfold_len; /**** * We now have a FULL header line in 'headerb'. *****/ + hlen = curlx_dyn_len(&data->state.headerb); + hd = curlx_dyn_ptr(&data->state.headerb); + if(!k->headerline) { - /* the first read header */ - statusline st = checkprotoprefix(data, conn, - curlx_dyn_ptr(&data->state.headerb), - curlx_dyn_len(&data->state.headerb)); + /* the first read "header", the status line */ + statusline st = checkprotoprefix(data, conn, hd, hlen); if(st == STATUS_BAD) { streamclose(conn, "bad HTTP: No end-of-message indicator"); /* this is not the beginning of a protocol first header line. @@ -4368,10 +4437,25 @@ static CURLcode http_parse_headers(struct Curl_easy *data, goto out; } } + else { + if(hlen && !ISNEWLINE(hd[0])) { + /* this is NOT the header separator */ + + /* if we have bytes for the next header, check for folding */ + if(blen && ISBLANK(buf[0])) { + /* remove the trailing CRLF and append the next header */ + unfold_header(data); + continue; + } + else if(!blen) { + /* this might be a folded header so deal with it in next invoke */ + data->state.maybe_folded = TRUE; + break; + } + } + } - result = http_rw_hd(data, curlx_dyn_ptr(&data->state.headerb), - curlx_dyn_len(&data->state.headerb), - buf, blen, &consumed); + result = http_rw_hd(data, hd, hlen, buf, blen, &consumed); /* We are done with this line. We reset because response * processing might switch to HTTP/2 and that might call us * directly again. */ @@ -4402,6 +4486,7 @@ CURLcode Curl_http_write_resp_hd(struct Curl_easy *data, CURLcode result; size_t consumed; char tmp = 0; + DEBUGASSERT(!hd[hdlen]); /* null terminated */ result = http_rw_hd(data, hd, hdlen, &tmp, 0, &consumed); if(!result && is_eos) { @@ -4507,7 +4592,7 @@ CURLcode Curl_http_req_make(struct httpreq **preq, DEBUGASSERT(method && m_len); - req = calloc(1, sizeof(*req) + m_len); + req = curlx_calloc(1, sizeof(*req) + m_len); if(!req) goto out; #if defined(__GNUC__) && __GNUC__ >= 13 @@ -4549,12 +4634,12 @@ CURLcode Curl_http_req_make(struct httpreq **preq, static CURLcode req_assign_url_authority(struct httpreq *req, CURLU *url) { - char *user, *pass, *host, *port; + char *host, *port; struct dynbuf buf; CURLUcode uc; CURLcode result = CURLE_URL_MALFORMAT; - user = pass = host = port = NULL; + host = port = NULL; curlx_dyn_init(&buf, DYN_HTTP_REQUEST); uc = curl_url_get(url, CURLUPART_HOST, &host, 0); @@ -4569,28 +4654,7 @@ static CURLcode req_assign_url_authority(struct httpreq *req, CURLU *url) uc = curl_url_get(url, CURLUPART_PORT, &port, CURLU_NO_DEFAULT_PORT); if(uc && uc != CURLUE_NO_PORT) goto out; - uc = curl_url_get(url, CURLUPART_USER, &user, 0); - if(uc && uc != CURLUE_NO_USER) - goto out; - if(user) { - uc = curl_url_get(url, CURLUPART_PASSWORD, &pass, 0); - if(uc && uc != CURLUE_NO_PASSWORD) - goto out; - } - if(user) { - result = curlx_dyn_add(&buf, user); - if(result) - goto out; - if(pass) { - result = curlx_dyn_addf(&buf, ":%s", pass); - if(result) - goto out; - } - result = curlx_dyn_add(&buf, "@"); - if(result) - goto out; - } result = curlx_dyn_add(&buf, host); if(result) goto out; @@ -4599,17 +4663,12 @@ static CURLcode req_assign_url_authority(struct httpreq *req, CURLU *url) if(result) goto out; } - req->authority = strdup(curlx_dyn_ptr(&buf)); - if(!req->authority) - goto out; - result = CURLE_OK; - + req->authority = curlx_dyn_ptr(&buf); out: - free(user); - free(pass); - free(host); - free(port); - curlx_dyn_free(&buf); + curlx_free(host); + curlx_free(port); + if(result) + curlx_dyn_free(&buf); return result; } @@ -4623,41 +4682,32 @@ static CURLcode req_assign_url_path(struct httpreq *req, CURLU *url) path = query = NULL; curlx_dyn_init(&buf, DYN_HTTP_REQUEST); - uc = curl_url_get(url, CURLUPART_PATH, &path, CURLU_PATH_AS_IS); + uc = curl_url_get(url, CURLUPART_PATH, &path, 0); if(uc) goto out; uc = curl_url_get(url, CURLUPART_QUERY, &query, 0); if(uc && uc != CURLUE_NO_QUERY) goto out; - if(!path && !query) { - req->path = NULL; - } - else if(path && !query) { + if(!query) { req->path = path; path = NULL; } else { - if(path) { - result = curlx_dyn_add(&buf, path); - if(result) - goto out; - } - if(query) { + result = curlx_dyn_add(&buf, path); + if(!result) result = curlx_dyn_addf(&buf, "?%s", query); - if(result) - goto out; - } - req->path = strdup(curlx_dyn_ptr(&buf)); - if(!req->path) + if(result) goto out; + req->path = curlx_dyn_ptr(&buf); } result = CURLE_OK; out: - free(path); - free(query); - curlx_dyn_free(&buf); + curlx_free(path); + curlx_free(query); + if(result) + curlx_dyn_free(&buf); return result; } @@ -4671,7 +4721,7 @@ CURLcode Curl_http_req_make2(struct httpreq **preq, DEBUGASSERT(method && m_len); - req = calloc(1, sizeof(*req) + m_len); + req = curlx_calloc(1, sizeof(*req) + m_len); if(!req) goto out; memcpy(req->method, method, m_len); @@ -4680,7 +4730,7 @@ CURLcode Curl_http_req_make2(struct httpreq **preq, if(uc && uc != CURLUE_NO_SCHEME) goto out; if(!req->scheme && scheme_default) { - req->scheme = strdup(scheme_default); + req->scheme = curlx_strdup(scheme_default); if(!req->scheme) goto out; } @@ -4706,12 +4756,12 @@ CURLcode Curl_http_req_make2(struct httpreq **preq, void Curl_http_req_free(struct httpreq *req) { if(req) { - free(req->scheme); - free(req->authority); - free(req->path); + curlx_free(req->scheme); + curlx_free(req->authority); + curlx_free(req->path); Curl_dynhds_free(&req->headers); Curl_dynhds_free(&req->trailers); - free(req); + curlx_free(req); } } @@ -4794,8 +4844,7 @@ CURLcode Curl_http_req_to_h2(struct dynhds *h2_headers, infof(data, "set pseudo header %s to %s", HTTP_PSEUDO_SCHEME, scheme); } else { - scheme = Curl_conn_is_ssl(data->conn, FIRSTSOCKET) ? - "https" : "http"; + scheme = Curl_conn_is_ssl(data->conn, FIRSTSOCKET) ? "https" : "http"; } } @@ -4849,13 +4898,13 @@ CURLcode Curl_http_resp_make(struct http_resp **presp, struct http_resp *resp; CURLcode result = CURLE_OUT_OF_MEMORY; - resp = calloc(1, sizeof(*resp)); + resp = curlx_calloc(1, sizeof(*resp)); if(!resp) goto out; resp->status = status; if(description) { - resp->description = strdup(description); + resp->description = curlx_strdup(description); if(!resp->description) goto out; } @@ -4873,12 +4922,12 @@ CURLcode Curl_http_resp_make(struct http_resp **presp, void Curl_http_resp_free(struct http_resp *resp) { if(resp) { - free(resp->description); + curlx_free(resp->description); Curl_dynhds_free(&resp->headers); Curl_dynhds_free(&resp->trailers); if(resp->prev) Curl_http_resp_free(resp->prev); - free(resp); + curlx_free(resp); } } @@ -4896,8 +4945,6 @@ static void http_exp100_continue(struct Curl_easy *data, struct cr_exp100_ctx *ctx = reader->ctx; if(ctx->state > EXP100_SEND_DATA) { ctx->state = EXP100_SEND_DATA; - data->req.keepon |= KEEP_SEND; - data->req.keepon &= ~KEEP_SEND_TIMED; Curl_expire_done(data, EXPIRE_100_TIMEOUT); } } @@ -4925,10 +4972,8 @@ static CURLcode cr_exp100_read(struct Curl_easy *data, DEBUGF(infof(data, "cr_exp100_read, start AWAITING_CONTINUE, " "timeout %dms", data->set.expect_100_timeout)); ctx->state = EXP100_AWAITING_CONTINUE; - ctx->start = curlx_now(); + ctx->start = *Curl_pgrs_now(data); Curl_expire(data, data->set.expect_100_timeout, EXPIRE_100_TIMEOUT); - data->req.keepon &= ~KEEP_SEND; - data->req.keepon |= KEEP_SEND_TIMED; *nread = 0; *eos = FALSE; return CURLE_OK; @@ -4938,11 +4983,9 @@ static CURLcode cr_exp100_read(struct Curl_easy *data, *eos = FALSE; return CURLE_READ_ERROR; case EXP100_AWAITING_CONTINUE: - ms = curlx_timediff(curlx_now(), ctx->start); + ms = curlx_ptimediff_ms(Curl_pgrs_now(data), &ctx->start); if(ms < data->set.expect_100_timeout) { DEBUGF(infof(data, "cr_exp100_read, AWAITING_CONTINUE, not expired")); - data->req.keepon &= ~KEEP_SEND; - data->req.keepon |= KEEP_SEND_TIMED; *nread = 0; *eos = FALSE; return CURLE_OK; @@ -4962,7 +5005,6 @@ static void cr_exp100_done(struct Curl_easy *data, { struct cr_exp100_ctx *ctx = reader->ctx; ctx->state = premature ? EXP100_FAILED : EXP100_SEND_DATA; - data->req.keepon &= ~KEEP_SEND_TIMED; Curl_expire_done(data, EXPIRE_100_TIMEOUT); } @@ -4985,8 +5027,7 @@ static CURLcode http_exp100_add_reader(struct Curl_easy *data) struct Curl_creader *reader = NULL; CURLcode result; - result = Curl_creader_create(&reader, data, &cr_exp100, - CURL_CR_PROTOCOL); + result = Curl_creader_create(&reader, data, &cr_exp100, CURL_CR_PROTOCOL); if(!result) result = Curl_creader_add(data, reader); if(!result) { diff --git a/vendor/hydra/vendor/curl/lib/http.h b/vendor/hydra/vendor/curl/lib/http.h index 67ef17f5..89810b17 100644 --- a/vendor/hydra/vendor/curl/lib/http.h +++ b/vendor/hydra/vendor/curl/lib/http.h @@ -27,7 +27,6 @@ #include "bufq.h" #include "dynhds.h" -#include "ws.h" typedef enum { HTTPREQ_GET, @@ -38,7 +37,6 @@ typedef enum { HTTPREQ_HEAD } Curl_HttpReq; - /* When redirecting transfers. */ typedef enum { FOLLOW_NONE, /* not used within the function, just a placeholder to @@ -55,7 +53,6 @@ typedef enum { /* bitmask of CURL_HTTP_V* values */ typedef unsigned char http_majors; - #ifndef CURL_DISABLE_HTTP #ifdef USE_HTTP3 @@ -74,6 +71,7 @@ struct http_negotiation { unsigned char rcvd_min; /* minimum version seen in responses, 09, 10, 11 */ http_majors wanted; /* wanted major versions when talking to server */ http_majors allowed; /* allowed major versions when talking to server */ + http_majors preferred; /* preferred major version when talking to server */ BIT(h2_upgrade); /* Do HTTP Upgrade from 1.1 to 2 */ BIT(h2_prior_knowledge); /* Directly do HTTP/2 without ALPN/SSL */ BIT(accept_09); /* Accept an HTTP/0.9 response */ @@ -106,6 +104,8 @@ CURLcode Curl_add_custom_headers(struct Curl_easy *data, bool is_connect, CURLcode Curl_dynhds_add_custom(struct Curl_easy *data, bool is_connect, struct dynhds *hds); +void Curl_http_to_fold(struct dynbuf *bf); + void Curl_http_method(struct Curl_easy *data, const char **method, Curl_HttpReq *); @@ -114,9 +114,10 @@ CURLcode Curl_http_setup_conn(struct Curl_easy *data, struct connectdata *conn); CURLcode Curl_http(struct Curl_easy *data, bool *done); CURLcode Curl_http_done(struct Curl_easy *data, CURLcode, bool premature); -CURLcode Curl_http_connect(struct Curl_easy *data, bool *done); -CURLcode Curl_http_do_pollset(struct Curl_easy *data, - struct easy_pollset *ps); +CURLcode Curl_http_doing_pollset(struct Curl_easy *data, + struct easy_pollset *ps); +CURLcode Curl_http_perform_pollset(struct Curl_easy *data, + struct easy_pollset *ps); CURLcode Curl_http_write_resp(struct Curl_easy *data, const char *buf, size_t blen, bool is_eos); @@ -138,7 +139,7 @@ CURLcode Curl_http_follow(struct Curl_easy *data, const char *newurl, selected to use no auth at all. Ie, we actively select no auth, as opposed to not having one selected. The other CURLAUTH_* defines are present in the public curl/curl.h header. */ -#define CURLAUTH_PICKNONE (1<<30) /* do not use auth */ +#define CURLAUTH_PICKNONE (1 << 30) /* do not use auth */ /* MAX_INITIAL_POST_SIZE indicates the number of bytes that will make the POST data get included in the initial data chunk sent to the server. If the @@ -153,7 +154,7 @@ CURLcode Curl_http_follow(struct Curl_easy *data, const char *newurl, It must not be greater than 64K to work on VMS. */ #ifndef MAX_INITIAL_POST_SIZE -#define MAX_INITIAL_POST_SIZE (64*1024) +#define MAX_INITIAL_POST_SIZE (64 * 1024) #endif /* EXPECT_100_THRESHOLD is the request body size limit for when libcurl will @@ -162,13 +163,13 @@ CURLcode Curl_http_follow(struct Curl_easy *data, const char *newurl, * */ #ifndef EXPECT_100_THRESHOLD -#define EXPECT_100_THRESHOLD (1024*1024) +#define EXPECT_100_THRESHOLD (1024 * 1024) #endif /* MAX_HTTP_RESP_HEADER_SIZE is the maximum size of all response headers combined that libcurl allows for a single HTTP response, any HTTP version. This count includes CONNECT response headers. */ -#define MAX_HTTP_RESP_HEADER_SIZE (300*1024) +#define MAX_HTTP_RESP_HEADER_SIZE (300 * 1024) /* MAX_HTTP_RESP_HEADER_COUNT is the maximum number of response headers that libcurl allows for a single HTTP response, including CONNECT and @@ -213,7 +214,6 @@ Curl_http_output_auth(struct Curl_easy *data, /* Decode HTTP status code string. */ CURLcode Curl_http_decode_status(int *pstatus, const char *s, size_t len); - /** * All about a core HTTP request, excluding body and trailers */ @@ -241,11 +241,11 @@ CURLcode Curl_http_req_make2(struct httpreq **preq, void Curl_http_req_free(struct httpreq *req); -#define HTTP_PSEUDO_METHOD ":method" -#define HTTP_PSEUDO_SCHEME ":scheme" +#define HTTP_PSEUDO_METHOD ":method" +#define HTTP_PSEUDO_SCHEME ":scheme" #define HTTP_PSEUDO_AUTHORITY ":authority" -#define HTTP_PSEUDO_PATH ":path" -#define HTTP_PSEUDO_STATUS ":status" +#define HTTP_PSEUDO_PATH ":path" +#define HTTP_PSEUDO_STATUS ":status" /** * Create the list of HTTP/2 headers which represent the request, diff --git a/vendor/hydra/vendor/curl/lib/http1.c b/vendor/hydra/vendor/curl/lib/http1.c index 098dd7cd..9e584248 100644 --- a/vendor/hydra/vendor/curl/lib/http1.c +++ b/vendor/hydra/vendor/curl/lib/http1.c @@ -21,23 +21,17 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifndef CURL_DISABLE_HTTP #include "urldata.h" -#include #include "http.h" #include "http1.h" #include "urlapi-int.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - -#define H1_MAX_URL_LEN (8*1024) +#define H1_MAX_URL_LEN (8 * 1024) void Curl_h1_req_parse_init(struct h1_req_parser *parser, size_t max_line_len) { @@ -80,63 +74,66 @@ static CURLcode trim_line(struct h1_req_parser *parser, int options) return CURLE_OK; } -static ssize_t detect_line(struct h1_req_parser *parser, - const char *buf, const size_t buflen, - CURLcode *err) +static CURLcode detect_line(struct h1_req_parser *parser, + const uint8_t *buf, const size_t buflen, + size_t *pnread) { - const char *line_end; + const char *line_end; DEBUGASSERT(!parser->line); + *pnread = 0; line_end = memchr(buf, '\n', buflen); - if(!line_end) { - *err = CURLE_AGAIN; - return -1; - } - parser->line = buf; - parser->line_len = line_end - buf + 1; - *err = CURLE_OK; - return (ssize_t)parser->line_len; + if(!line_end) + return CURLE_AGAIN; + parser->line = (const char *)buf; + parser->line_len = line_end - parser->line + 1; + *pnread = parser->line_len; + return CURLE_OK; } -static ssize_t next_line(struct h1_req_parser *parser, - const char *buf, const size_t buflen, int options, - CURLcode *err) +static CURLcode next_line(struct h1_req_parser *parser, + const uint8_t *buf, const size_t buflen, int options, + size_t *pnread) { - ssize_t nread = 0; + CURLcode result; + *pnread = 0; if(parser->line) { parser->line = NULL; parser->line_len = 0; curlx_dyn_reset(&parser->scratch); } - nread = detect_line(parser, buf, buflen, err); - if(nread >= 0) { + result = detect_line(parser, buf, buflen, pnread); + if(!result) { if(curlx_dyn_len(&parser->scratch)) { /* append detected line to scratch to have the complete line */ - *err = curlx_dyn_addn(&parser->scratch, parser->line, parser->line_len); - if(*err) - return -1; + result = curlx_dyn_addn(&parser->scratch, parser->line, + parser->line_len); + if(result) + return result; parser->line = curlx_dyn_ptr(&parser->scratch); parser->line_len = curlx_dyn_len(&parser->scratch); } - *err = trim_line(parser, options); - if(*err) - return -1; + result = trim_line(parser, options); + if(result) + return result; } - else if(*err == CURLE_AGAIN) { + else if(result == CURLE_AGAIN) { /* no line end in `buf`, add it to our scratch */ - *err = curlx_dyn_addn(&parser->scratch, (const unsigned char *)buf, - buflen); - nread = (*err) ? -1 : (ssize_t)buflen; + result = curlx_dyn_addn(&parser->scratch, (const unsigned char *)buf, + buflen); + *pnread = buflen; } - return nread; + return result; } static CURLcode start_req(struct h1_req_parser *parser, - const char *scheme_default, int options) + const char *scheme_default, + const char *custom_method, + int options) { - const char *p, *m, *target, *hv, *scheme, *authority, *path; + const char *p, *m, *target, *hv, *scheme, *authority, *path; size_t m_len, target_len, hv_len, scheme_len, authority_len, path_len; size_t i; CURLU *url = NULL; @@ -144,9 +141,15 @@ static CURLcode start_req(struct h1_req_parser *parser, DEBUGASSERT(!parser->req); /* line must match: "METHOD TARGET HTTP_VERSION" */ - p = memchr(parser->line, ' ', parser->line_len); - if(!p || p == parser->line) - goto out; + if(custom_method && custom_method[0] && + !strncmp(custom_method, parser->line, strlen(custom_method))) { + p = parser->line + strlen(custom_method); + } + else { + p = memchr(parser->line, ' ', parser->line_len); + if(!p || p == parser->line) + goto out; + } m = parser->line; m_len = p - parser->line; @@ -222,8 +225,8 @@ static CURLcode start_req(struct h1_req_parser *parser, result = CURLE_OUT_OF_MEMORY; goto out; } - url_options = (CURLU_NON_SUPPORT_SCHEME| - CURLU_PATH_AS_IS| + url_options = (CURLU_NON_SUPPORT_SCHEME | + CURLU_PATH_AS_IS | CURLU_NO_DEFAULT_PORT); if(!(options & H1_PARSE_OPT_STRICT)) url_options |= CURLU_ALLOW_SPACE; @@ -256,28 +259,28 @@ static CURLcode start_req(struct h1_req_parser *parser, return result; } -ssize_t Curl_h1_req_parse_read(struct h1_req_parser *parser, - const char *buf, size_t buflen, - const char *scheme_default, int options, - CURLcode *err) +CURLcode Curl_h1_req_parse_read(struct h1_req_parser *parser, + const uint8_t *buf, size_t buflen, + const char *scheme_default, + const char *custom_method, + int options, size_t *pnread) { - ssize_t nread = 0, n; + CURLcode result = CURLE_OK; + size_t nread; - *err = CURLE_OK; + *pnread = 0; while(!parser->done) { - n = next_line(parser, buf, buflen, options, err); - if(n < 0) { - if(*err != CURLE_AGAIN) { - nread = -1; - } - *err = CURLE_OK; + result = next_line(parser, buf, buflen, options, &nread); + if(result) { + if(result == CURLE_AGAIN) + result = CURLE_OK; goto out; } /* Consume this line */ - nread += (size_t)n; - buf += (size_t)n; - buflen -= (size_t)n; + *pnread += nread; + buf += nread; + buflen -= nread; if(!parser->line) { /* consumed bytes, but line not complete */ @@ -285,17 +288,14 @@ ssize_t Curl_h1_req_parse_read(struct h1_req_parser *parser, goto out; } else if(!parser->req) { - *err = start_req(parser, scheme_default, options); - if(*err) { - nread = -1; + result = start_req(parser, scheme_default, custom_method, options); + if(result) goto out; - } } else if(parser->line_len == 0) { /* last, empty line, we are finished */ if(!parser->req) { - *err = CURLE_URL_MALFORMAT; - nread = -1; + result = CURLE_URL_MALFORMAT; goto out; } parser->done = TRUE; @@ -303,17 +303,15 @@ ssize_t Curl_h1_req_parse_read(struct h1_req_parser *parser, /* last chance adjustments */ } else { - *err = Curl_dynhds_h1_add_line(&parser->req->headers, - parser->line, parser->line_len); - if(*err) { - nread = -1; + result = Curl_dynhds_h1_add_line(&parser->req->headers, + parser->line, parser->line_len); + if(result) goto out; - } } } out: - return nread; + return result; } CURLcode Curl_h1_req_write_head(struct httpreq *req, int http_minor, diff --git a/vendor/hydra/vendor/curl/lib/http1.h b/vendor/hydra/vendor/curl/lib/http1.h index b38b32f5..124d32e3 100644 --- a/vendor/hydra/vendor/curl/lib/http1.h +++ b/vendor/hydra/vendor/curl/lib/http1.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifndef CURL_DISABLE_HTTP @@ -48,10 +47,11 @@ struct h1_req_parser { void Curl_h1_req_parse_init(struct h1_req_parser *parser, size_t max_line_len); void Curl_h1_req_parse_free(struct h1_req_parser *parser); -ssize_t Curl_h1_req_parse_read(struct h1_req_parser *parser, - const char *buf, size_t buflen, - const char *scheme_default, int options, - CURLcode *err); +CURLcode Curl_h1_req_parse_read(struct h1_req_parser *parser, + const uint8_t *buf, size_t buflen, + const char *scheme_default, + const char *custom_method, + int options, size_t *pnread); CURLcode Curl_h1_req_dprint(const struct httpreq *req, struct dynbuf *dbuf); diff --git a/vendor/hydra/vendor/curl/lib/http2.c b/vendor/hydra/vendor/curl/lib/http2.c index 36bfd610..a8b8d5c5 100644 --- a/vendor/hydra/vendor/curl/lib/http2.c +++ b/vendor/hydra/vendor/curl/lib/http2.c @@ -21,12 +21,12 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #if !defined(CURL_DISABLE_HTTP) && defined(USE_NGHTTP2) #include #include + #include "urldata.h" #include "bufq.h" #include "uint-hash.h" @@ -34,29 +34,26 @@ #include "http2.h" #include "http.h" #include "sendf.h" +#include "curl_trc.h" #include "select.h" #include "curlx/base64.h" #include "multiif.h" +#include "progress.h" #include "url.h" #include "urlapi-int.h" #include "cfilters.h" #include "connect.h" -#include "rand.h" -#include "curlx/strparse.h" #include "transfer.h" +#include "bufref.h" #include "curlx/dynbuf.h" #include "headers.h" -/* The last 3 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #if (NGHTTP2_VERSION_NUM < 0x010c00) #error too old nghttp2 version, upgrade! #endif #ifdef CURL_DISABLE_VERBOSE_STRINGS -#define nghttp2_session_callbacks_set_error_callback(x,y) +#define nghttp2_session_callbacks_set_error_callback(x, y) #endif #if (NGHTTP2_VERSION_NUM >= 0x010c00) @@ -94,36 +91,9 @@ * is blocked from sending us any data. See #10988 for an issue with this. */ #define HTTP2_HUGE_WINDOW_SIZE (100 * H2_STREAM_WINDOW_SIZE_MAX) -#define H2_SETTINGS_IV_LEN 3 +#define H2_SETTINGS_IV_LEN 3 #define H2_BINSETTINGS_LEN 80 -static size_t populate_settings(nghttp2_settings_entry *iv, - struct Curl_easy *data) -{ - iv[0].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS; - iv[0].value = Curl_multi_max_concurrent_streams(data->multi); - - iv[1].settings_id = NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE; - iv[1].value = H2_STREAM_WINDOW_SIZE_INITIAL; - - iv[2].settings_id = NGHTTP2_SETTINGS_ENABLE_PUSH; - iv[2].value = data->multi->push_cb != NULL; - - return 3; -} - -static ssize_t populate_binsettings(uint8_t *binsettings, - struct Curl_easy *data) -{ - nghttp2_settings_entry iv[H2_SETTINGS_IV_LEN]; - size_t ivlen; - - ivlen = populate_settings(iv, data); - /* this returns number of bytes it wrote or a negative number on error. */ - return nghttp2_pack_settings_payload(binsettings, H2_BINSETTINGS_LEN, - iv, ivlen); -} - struct cf_h2_ctx { nghttp2_session *h2; /* The easy handle used in the current filter call, cleared at return */ @@ -136,13 +106,11 @@ struct cf_h2_ctx { struct uint_hash streams; /* hash of `data->mid` to `h2_stream_ctx` */ size_t drain_total; /* sum of all stream's UrlState drain */ + uint32_t initial_win_size; /* current initial window size (settings) */ uint32_t max_concurrent_streams; uint32_t goaway_error; /* goaway error code from server */ int32_t remote_max_sid; /* max id processed by server */ int32_t local_max_sid; /* max id processed by us */ -#ifdef DEBUGBUILD - int32_t stream_win_max; /* max h2 stream window size */ -#endif BIT(initialized); BIT(via_h1_upgrade); BIT(conn_closed); @@ -154,8 +122,7 @@ struct cf_h2_ctx { /* How to access `call_data` from a cf_h2 filter */ #undef CF_CTX_CALL_DATA -#define CF_CTX_CALL_DATA(cf) \ - ((struct cf_h2_ctx *)(cf)->ctx)->call_data +#define CF_CTX_CALL_DATA(cf) ((struct cf_h2_ctx *)(cf)->ctx)->call_data static void h2_stream_hash_free(unsigned int id, void *stream); @@ -165,21 +132,9 @@ static void cf_h2_ctx_init(struct cf_h2_ctx *ctx, bool via_h1_upgrade) Curl_bufq_initp(&ctx->inbufq, &ctx->stream_bufcp, H2_NW_RECV_CHUNKS, 0); Curl_bufq_initp(&ctx->outbufq, &ctx->stream_bufcp, H2_NW_SEND_CHUNKS, 0); curlx_dyn_init(&ctx->scratch, CURL_MAX_HTTP_HEADER); - Curl_uint_hash_init(&ctx->streams, 63, h2_stream_hash_free); + Curl_uint32_hash_init(&ctx->streams, 63, h2_stream_hash_free); ctx->remote_max_sid = 2147483647; ctx->via_h1_upgrade = via_h1_upgrade; -#ifdef DEBUGBUILD - { - const char *p = getenv("CURL_H2_STREAM_WIN_MAX"); - - ctx->stream_win_max = H2_STREAM_WINDOW_SIZE_MAX; - if(p) { - curl_off_t l; - if(!curlx_str_number(&p, &l, INT_MAX)) - ctx->stream_win_max = (int32_t)l; - } - } -#endif ctx->initialized = TRUE; } @@ -190,10 +145,10 @@ static void cf_h2_ctx_free(struct cf_h2_ctx *ctx) Curl_bufq_free(&ctx->outbufq); Curl_bufcp_free(&ctx->stream_bufcp); curlx_dyn_free(&ctx->scratch); - Curl_uint_hash_destroy(&ctx->streams); + Curl_uint32_hash_destroy(&ctx->streams); memset(ctx, 0, sizeof(*ctx)); } - free(ctx); + curlx_free(ctx); } static void cf_h2_ctx_close(struct cf_h2_ctx *ctx) @@ -203,6 +158,60 @@ static void cf_h2_ctx_close(struct cf_h2_ctx *ctx) } } +static uint32_t cf_h2_initial_win_size(struct Curl_easy *data) +{ +#if NGHTTP2_HAS_SET_LOCAL_WINDOW_SIZE + /* If the transfer has a rate-limit lower than the default initial + * stream window size, use that. It needs to be at least 8k or servers + * may be unhappy. */ + if(data->progress.dl.rlimit.rate_per_step && + (data->progress.dl.rlimit.rate_per_step < H2_STREAM_WINDOW_SIZE_INITIAL)) + return CURLMAX((uint32_t)data->progress.dl.rlimit.rate_per_step, 8192); +#endif + return H2_STREAM_WINDOW_SIZE_INITIAL; +} + +static size_t populate_settings(nghttp2_settings_entry *iv, + struct Curl_easy *data, + struct cf_h2_ctx *ctx) +{ + iv[0].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS; + iv[0].value = Curl_multi_max_concurrent_streams(data->multi); + + iv[1].settings_id = NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE; + iv[1].value = cf_h2_initial_win_size(data); + if(ctx) + ctx->initial_win_size = iv[1].value; + iv[2].settings_id = NGHTTP2_SETTINGS_ENABLE_PUSH; + iv[2].value = data->multi->push_cb != NULL; + + return 3; +} + +static ssize_t populate_binsettings(uint8_t *binsettings, + struct Curl_easy *data) +{ + nghttp2_settings_entry iv[H2_SETTINGS_IV_LEN]; + size_t ivlen; + + ivlen = populate_settings(iv, data, NULL); + /* this returns number of bytes it wrote or a negative number on error. */ + return nghttp2_pack_settings_payload(binsettings, H2_BINSETTINGS_LEN, + iv, ivlen); +} + +static CURLcode cf_h2_update_settings(struct cf_h2_ctx *ctx, + uint32_t initial_win_size) +{ + nghttp2_settings_entry entry; + entry.settings_id = NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE; + entry.value = initial_win_size; + if(nghttp2_submit_settings(ctx->h2, NGHTTP2_FLAG_NONE, &entry, 1)) + return CURLE_SEND_ERROR; + ctx->initial_win_size = initial_win_size; + return CURLE_OK; +} + static CURLcode nw_out_flush(struct Curl_cfilter *cf, struct Curl_easy *data); @@ -238,16 +247,16 @@ struct h2_stream_ctx { BIT(write_paused); /* stream write is paused */ }; -#define H2_STREAM_CTX(ctx,data) \ +#define H2_STREAM_CTX(ctx, data) \ ((struct h2_stream_ctx *)( \ - data? Curl_uint_hash_get(&(ctx)->streams, (data)->mid) : NULL)) + data? Curl_uint32_hash_get(&(ctx)->streams, (data)->mid) : NULL)) static struct h2_stream_ctx *h2_stream_ctx_create(struct cf_h2_ctx *ctx) { struct h2_stream_ctx *stream; (void)ctx; - stream = calloc(1, sizeof(*stream)); + stream = curlx_calloc(1, sizeof(*stream)); if(!stream) return NULL; @@ -270,7 +279,7 @@ static void free_push_headers(struct h2_stream_ctx *stream) { size_t i; for(i = 0; i < stream->push_headers_used; i++) - free(stream->push_headers[i]); + curlx_free(stream->push_headers[i]); Curl_safefree(stream->push_headers); stream->push_headers_used = 0; } @@ -281,7 +290,7 @@ static void h2_stream_ctx_free(struct h2_stream_ctx *stream) Curl_h1_req_parse_free(&stream->h1); Curl_dynhds_free(&stream->resp_trailers); free_push_headers(stream); - free(stream); + curlx_free(stream); } static void h2_stream_hash_free(unsigned int id, void *stream) @@ -295,23 +304,17 @@ static void h2_stream_hash_free(unsigned int id, void *stream) static int32_t cf_h2_get_desired_local_win(struct Curl_cfilter *cf, struct Curl_easy *data) { + curl_off_t avail = Curl_rlimit_avail(&data->progress.dl.rlimit, + Curl_pgrs_now(data)); + (void)cf; - if(data->set.max_recv_speed && data->set.max_recv_speed < INT32_MAX) { - /* The transfer should only receive `max_recv_speed` bytes per second. - * We restrict the stream's local window size, so that the server cannot - * send us "too much" at a time. - * This gets less precise the higher the latency. */ - return (int32_t)data->set.max_recv_speed; - } -#ifdef DEBUGBUILD - else { - struct cf_h2_ctx *ctx = cf->ctx; - CURL_TRC_CF(data, cf, "stream_win_max=%d", ctx->stream_win_max); - return ctx->stream_win_max; + if(avail < CURL_OFF_T_MAX) { /* limit in place */ + if(avail <= 0) + return 0; + else if(avail < INT32_MAX) + return (int32_t)avail; } -#else return H2_STREAM_WINDOW_SIZE_MAX; -#endif } static CURLcode cf_h2_update_local_win(struct Curl_cfilter *cf, @@ -375,7 +378,6 @@ static CURLcode cf_h2_update_local_win(struct Curl_cfilter *cf, } #endif /* !NGHTTP2_HAS_SET_LOCAL_WINDOW_SIZE */ - static CURLcode http2_data_setup(struct Curl_cfilter *cf, struct Curl_easy *data, struct h2_stream_ctx **pstream) @@ -395,7 +397,7 @@ static CURLcode http2_data_setup(struct Curl_cfilter *cf, if(!stream) return CURLE_OUT_OF_MEMORY; - if(!Curl_uint_hash_set(&ctx->streams, data->mid, stream)) { + if(!Curl_uint32_hash_set(&ctx->streams, data->mid, stream)) { h2_stream_ctx_free(stream); return CURLE_OUT_OF_MEMORY; } @@ -435,7 +437,7 @@ static void http2_data_done(struct Curl_cfilter *cf, struct Curl_easy *data) } } - Curl_uint_hash_remove(&ctx->streams, data->mid); + Curl_uint32_hash_remove(&ctx->streams, data->mid); } static int h2_client_new(struct Curl_cfilter *cf, @@ -443,8 +445,8 @@ static int h2_client_new(struct Curl_cfilter *cf, { struct cf_h2_ctx *ctx = cf->ctx; nghttp2_option *o; - nghttp2_mem mem = {NULL, Curl_nghttp2_malloc, Curl_nghttp2_free, - Curl_nghttp2_calloc, Curl_nghttp2_realloc}; + nghttp2_mem mem = { NULL, Curl_nghttp2_malloc, Curl_nghttp2_free, + Curl_nghttp2_calloc, Curl_nghttp2_realloc }; int rc = nghttp2_option_new(&o); if(rc) @@ -505,7 +507,7 @@ static CURLcode cf_h2_ctx_open(struct Curl_cfilter *cf, rc = nghttp2_session_callbacks_new(&cbs); if(rc) { - failf(data, "Couldn't initialize nghttp2 callbacks"); + failf(data, "Could not initialize nghttp2 callbacks"); goto out; } @@ -529,7 +531,7 @@ static CURLcode cf_h2_ctx_open(struct Curl_cfilter *cf, /* The nghttp2 session is not yet setup, do it */ rc = h2_client_new(cf, cbs); if(rc) { - failf(data, "Couldn't initialize nghttp2"); + failf(data, "Could not initialize nghttp2"); goto out; } ctx->max_concurrent_streams = DEFAULT_MAX_CONCURRENT_STREAMS; @@ -539,10 +541,12 @@ static CURLcode cf_h2_ctx_open(struct Curl_cfilter *cf, * in the H1 request and we upgrade from there. This stream * is opened implicitly as #1. */ uint8_t binsettings[H2_BINSETTINGS_LEN]; - ssize_t binlen; /* length of the binsettings data */ + ssize_t rclen; + size_t binlen; /* length of the binsettings data */ + + rclen = populate_binsettings(binsettings, data); - binlen = populate_binsettings(binsettings, data); - if(binlen <= 0) { + if(!curlx_sztouz(rclen, &binlen) || !binlen) { failf(data, "nghttp2 unexpectedly failed on pack_settings_payload"); result = CURLE_FAILED_INIT; goto out; @@ -554,7 +558,7 @@ static CURLcode cf_h2_ctx_open(struct Curl_cfilter *cf, DEBUGASSERT(stream); stream->id = 1; /* queue SETTINGS frame (again) */ - rc = nghttp2_session_upgrade2(ctx->h2, binsettings, (size_t)binlen, + rc = nghttp2_session_upgrade2(ctx->h2, binsettings, binlen, data->state.httpreq == HTTPREQ_HEAD, NULL); if(rc) { @@ -577,7 +581,7 @@ static CURLcode cf_h2_ctx_open(struct Curl_cfilter *cf, nghttp2_settings_entry iv[H2_SETTINGS_IV_LEN]; size_t ivlen; - ivlen = populate_settings(iv, data); + ivlen = populate_settings(iv, data, ctx); rc = nghttp2_submit_settings(ctx->h2, NGHTTP2_FLAG_NONE, iv, ivlen); if(rc) { @@ -627,16 +631,16 @@ static CURLcode h2_process_pending_input(struct Curl_cfilter *cf, { struct cf_h2_ctx *ctx = cf->ctx; const unsigned char *buf; - size_t blen; + size_t blen, nread; ssize_t rv; while(Curl_bufq_peek(&ctx->inbufq, &buf, &blen)) { rv = nghttp2_session_mem_recv(ctx->h2, (const uint8_t *)buf, blen); - if(rv < 0) { + if(!curlx_sztouz(rv, &nread)) { failf(data, "nghttp2 recv error %zd: %s", rv, nghttp2_strerror((int)rv)); return CURLE_HTTP2; } - Curl_bufq_skip(&ctx->inbufq, (size_t)rv); + Curl_bufq_skip(&ctx->inbufq, nread); if(Curl_bufq_is_empty(&ctx->inbufq)) { break; } @@ -713,7 +717,7 @@ static CURLcode http2_send_ping(struct Curl_cfilter *cf, if(rc) { failf(data, "nghttp2_submit_ping() failed: %s(%d)", nghttp2_strerror(rc), rc); - return CURLE_HTTP2; + return CURLE_HTTP2; } rc = nghttp2_session_send(ctx->h2); @@ -796,11 +800,10 @@ static ssize_t send_callback(nghttp2_session *h2, ctx->nw_out_blocked = 1; return NGHTTP2_ERR_WOULDBLOCK; } - return (nwritten > SSIZE_MAX) ? + return (nwritten > SSIZE_MAX) ? NGHTTP2_ERR_CALLBACK_FAILURE : (ssize_t)nwritten; } - /* We pass a pointer to this struct in the push callback, but the contents of the struct are hidden from the user. */ struct curl_pushheaders { @@ -918,10 +921,7 @@ static int set_transfer_url(struct Curl_easy *data, if(rc) return rc; - if(data->state.url_alloc) - free(data->state.url); - data->state.url_alloc = TRUE; - data->state.url = url; + Curl_bufref_set(&data->state.url, url, 0, curl_free); return 0; } @@ -945,7 +945,7 @@ static int push_promise(struct Curl_cfilter *cf, struct h2_stream_ctx *stream; struct h2_stream_ctx *newstream; struct curl_pushheaders heads; - CURLMcode rc; + CURLMcode mresult; CURLcode result; /* clone the parent */ struct Curl_easy *newhandle = h2_duphandle(cf, data); @@ -969,7 +969,7 @@ static int push_promise(struct Curl_cfilter *cf, rv = set_transfer_url(newhandle, &heads); if(rv) { - CURL_TRC_CF(data, cf, "[%d] PUSH_PROMISE, failed to set url -> %d", + CURL_TRC_CF(data, cf, "[%d] PUSH_PROMISE, failed to set URL -> %d", frame->promised_stream_id, rv); discard_newhandle(cf, newhandle); rv = CURL_PUSH_DENY; @@ -997,8 +997,8 @@ static int push_promise(struct Curl_cfilter *cf, /* approved, add to the multi handle for processing. This * assigns newhandle->mid. For the new `mid` we assign the * h2_stream instance and remember the stream_id already known. */ - rc = Curl_multi_add_perform(data->multi, newhandle, cf->conn); - if(rc) { + mresult = Curl_multi_add_perform(data->multi, newhandle, cf->conn); + if(mresult) { infof(data, "failed to add handle to multi"); discard_newhandle(cf, newhandle); rv = CURL_PUSH_DENY; @@ -1211,72 +1211,72 @@ static CURLcode on_stream_frame(struct Curl_cfilter *cf, static int fr_print(const nghttp2_frame *frame, char *buffer, size_t blen) { switch(frame->hd.type) { - case NGHTTP2_DATA: { - return curl_msnprintf(buffer, blen, - "FRAME[DATA, len=%d, eos=%d, padlen=%d]", - (int)frame->hd.length, - !!(frame->hd.flags & NGHTTP2_FLAG_END_STREAM), - (int)frame->data.padlen); - } - case NGHTTP2_HEADERS: { - return curl_msnprintf(buffer, blen, - "FRAME[HEADERS, len=%d, hend=%d, eos=%d]", - (int)frame->hd.length, - !!(frame->hd.flags & NGHTTP2_FLAG_END_HEADERS), - !!(frame->hd.flags & NGHTTP2_FLAG_END_STREAM)); - } - case NGHTTP2_PRIORITY: { - return curl_msnprintf(buffer, blen, - "FRAME[PRIORITY, len=%d, flags=%d]", - (int)frame->hd.length, frame->hd.flags); - } - case NGHTTP2_RST_STREAM: { - return curl_msnprintf(buffer, blen, - "FRAME[RST_STREAM, len=%d, flags=%d, error=%u]", - (int)frame->hd.length, frame->hd.flags, - frame->rst_stream.error_code); - } - case NGHTTP2_SETTINGS: { - if(frame->hd.flags & NGHTTP2_FLAG_ACK) { - return curl_msnprintf(buffer, blen, "FRAME[SETTINGS, ack=1]"); - } - return curl_msnprintf(buffer, blen, - "FRAME[SETTINGS, len=%d]", (int)frame->hd.length); - } - case NGHTTP2_PUSH_PROMISE: { - return curl_msnprintf(buffer, blen, - "FRAME[PUSH_PROMISE, len=%d, hend=%d]", - (int)frame->hd.length, - !!(frame->hd.flags & NGHTTP2_FLAG_END_HEADERS)); - } - case NGHTTP2_PING: { - return curl_msnprintf(buffer, blen, - "FRAME[PING, len=%d, ack=%d]", - (int)frame->hd.length, - frame->hd.flags&NGHTTP2_FLAG_ACK); - } - case NGHTTP2_GOAWAY: { - char scratch[128]; - size_t s_len = CURL_ARRAYSIZE(scratch); - size_t len = (frame->goaway.opaque_data_len < s_len) ? - frame->goaway.opaque_data_len : s_len-1; - if(len) - memcpy(scratch, frame->goaway.opaque_data, len); - scratch[len] = '\0'; - return curl_msnprintf(buffer, blen, - "FRAME[GOAWAY, error=%d, reason='%s', " - "last_stream=%d]", frame->goaway.error_code, - scratch, frame->goaway.last_stream_id); - } - case NGHTTP2_WINDOW_UPDATE: { - return curl_msnprintf(buffer, blen, - "FRAME[WINDOW_UPDATE, incr=%d]", - frame->window_update.window_size_increment); - } - default: - return curl_msnprintf(buffer, blen, "FRAME[%d, len=%d, flags=%d]", - frame->hd.type, (int)frame->hd.length, - frame->hd.flags); + case NGHTTP2_DATA: { + return curl_msnprintf(buffer, blen, + "FRAME[DATA, len=%d, eos=%d, padlen=%d]", + (int)frame->hd.length, + !!(frame->hd.flags & NGHTTP2_FLAG_END_STREAM), + (int)frame->data.padlen); + } + case NGHTTP2_HEADERS: { + return curl_msnprintf(buffer, blen, + "FRAME[HEADERS, len=%d, hend=%d, eos=%d]", + (int)frame->hd.length, + !!(frame->hd.flags & NGHTTP2_FLAG_END_HEADERS), + !!(frame->hd.flags & NGHTTP2_FLAG_END_STREAM)); + } + case NGHTTP2_PRIORITY: { + return curl_msnprintf(buffer, blen, + "FRAME[PRIORITY, len=%d, flags=%d]", + (int)frame->hd.length, frame->hd.flags); + } + case NGHTTP2_RST_STREAM: { + return curl_msnprintf(buffer, blen, + "FRAME[RST_STREAM, len=%d, flags=%d, error=%u]", + (int)frame->hd.length, frame->hd.flags, + frame->rst_stream.error_code); + } + case NGHTTP2_SETTINGS: { + if(frame->hd.flags & NGHTTP2_FLAG_ACK) { + return curl_msnprintf(buffer, blen, "FRAME[SETTINGS, ack=1]"); + } + return curl_msnprintf(buffer, blen, + "FRAME[SETTINGS, len=%d]", (int)frame->hd.length); + } + case NGHTTP2_PUSH_PROMISE: { + return curl_msnprintf(buffer, blen, + "FRAME[PUSH_PROMISE, len=%d, hend=%d]", + (int)frame->hd.length, + !!(frame->hd.flags & NGHTTP2_FLAG_END_HEADERS)); + } + case NGHTTP2_PING: { + return curl_msnprintf(buffer, blen, + "FRAME[PING, len=%d, ack=%d]", + (int)frame->hd.length, + frame->hd.flags & NGHTTP2_FLAG_ACK); + } + case NGHTTP2_GOAWAY: { + char scratch[128]; + size_t s_len = CURL_ARRAYSIZE(scratch); + size_t len = (frame->goaway.opaque_data_len < s_len) ? + frame->goaway.opaque_data_len : s_len - 1; + if(len) + memcpy(scratch, frame->goaway.opaque_data, len); + scratch[len] = '\0'; + return curl_msnprintf(buffer, blen, + "FRAME[GOAWAY, error=%d, reason='%s', " + "last_stream=%d]", frame->goaway.error_code, + scratch, frame->goaway.last_stream_id); + } + case NGHTTP2_WINDOW_UPDATE: { + return curl_msnprintf(buffer, blen, + "FRAME[WINDOW_UPDATE, incr=%d]", + frame->window_update.window_size_increment); + } + default: + return curl_msnprintf(buffer, blen, "FRAME[%d, len=%d, flags=%d]", + frame->hd.type, (int)frame->hd.length, + frame->hd.flags); } } @@ -1292,7 +1292,7 @@ static int on_frame_send(nghttp2_session *session, const nghttp2_frame *frame, if(data && Curl_trc_cf_is_verbose(cf, data)) { char buffer[256]; int len; - len = fr_print(frame, buffer, sizeof(buffer)-1); + len = fr_print(frame, buffer, sizeof(buffer) - 1); buffer[len] = 0; CURL_TRC_CF(data, cf, "[%d] -> %s", frame->hd.stream_id, buffer); } @@ -1320,9 +1320,9 @@ static int on_frame_recv(nghttp2_session *session, const nghttp2_frame *frame, if(Curl_trc_cf_is_verbose(cf, data)) { char buffer[256]; int len; - len = fr_print(frame, buffer, sizeof(buffer)-1); + len = fr_print(frame, buffer, sizeof(buffer) - 1); buffer[len] = 0; - CURL_TRC_CF(data, cf, "[%d] <- %s",frame->hd.stream_id, buffer); + CURL_TRC_CF(data, cf, "[%d] <- %s", frame->hd.stream_id, buffer); } #endif /* !CURL_DISABLE_VERBOSE_STRINGS */ @@ -1334,9 +1334,9 @@ static int on_frame_recv(nghttp2_session *session, const nghttp2_frame *frame, if(!(frame->hd.flags & NGHTTP2_FLAG_ACK)) { uint32_t max_conn = ctx->max_concurrent_streams; ctx->max_concurrent_streams = nghttp2_session_get_remote_settings( - session, NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS); + session, NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS); ctx->enable_push = nghttp2_session_get_remote_settings( - session, NGHTTP2_SETTINGS_ENABLE_PUSH) != 0; + session, NGHTTP2_SETTINGS_ENABLE_PUSH) != 0; CURL_TRC_CF(data, cf, "[0] MAX_CONCURRENT_STREAMS: %d", ctx->max_concurrent_streams); CURL_TRC_CF(data, cf, "[0] ENABLE_PUSH: %s", @@ -1363,7 +1363,7 @@ static int on_frame_recv(nghttp2_session *session, const nghttp2_frame *frame, ctx->remote_max_sid = frame->goaway.last_stream_id; if(data) { infof(data, "received GOAWAY, error=%u, last_stream=%u", - ctx->goaway_error, ctx->remote_max_sid); + ctx->goaway_error, ctx->remote_max_sid); Curl_multi_connchanged(data->multi); } break; @@ -1397,7 +1397,7 @@ static int cf_h2_on_invalid_frame_recv(nghttp2_session *session, #ifndef CURL_DISABLE_VERBOSE_STRINGS char buffer[256]; int len; - len = fr_print(frame, buffer, sizeof(buffer)-1); + len = fr_print(frame, buffer, sizeof(buffer) - 1); buffer[len] = 0; failf(data, "[HTTP2] [%d] received invalid frame: %s, error %d: %s", stream_id, buffer, ngerr, nghttp2_strerror(ngerr)); @@ -1434,8 +1434,7 @@ static int on_data_chunk_recv(nghttp2_session *session, uint8_t flags, /* Receiving a Stream ID not in the hash should not happen - unless we have aborted a transfer artificially and there were more data in the pipeline. Silently ignore. */ - CURL_TRC_CF(CF_DATA_CURRENT(cf), cf, "[%d] Data for unknown", - stream_id); + CURL_TRC_CF(CF_DATA_CURRENT(cf), cf, "[%d] Data for unknown", stream_id); /* consumed explicitly as no one will read it */ nghttp2_session_consume(session, stream_id, len); return 0; @@ -1588,7 +1587,7 @@ static int on_header(nghttp2_session *session, const nghttp2_frame *frame, if(frame->hd.type == NGHTTP2_PUSH_PROMISE) { char *h; - if((namelen == (sizeof(HTTP_PSEUDO_AUTHORITY)-1)) && + if((namelen == (sizeof(HTTP_PSEUDO_AUTHORITY) - 1)) && !strncmp(HTTP_PSEUDO_AUTHORITY, (const char *)name, namelen)) { /* pseudo headers are lower case */ int rc = 0; @@ -1609,15 +1608,15 @@ static int on_header(nghttp2_session *session, const nghttp2_frame *frame, stream_id, NGHTTP2_PROTOCOL_ERROR); rc = NGHTTP2_ERR_CALLBACK_FAILURE; } - free(check); + curlx_free(check); if(rc) return rc; } if(!stream->push_headers) { stream->push_headers_alloc = 10; - stream->push_headers = malloc(stream->push_headers_alloc * - sizeof(char *)); + stream->push_headers = curlx_malloc(stream->push_headers_alloc * + sizeof(char *)); if(!stream->push_headers) return NGHTTP2_ERR_CALLBACK_FAILURE; stream->push_headers_used = 0; @@ -1632,8 +1631,8 @@ static int on_header(nghttp2_session *session, const nghttp2_frame *frame, return NGHTTP2_ERR_CALLBACK_FAILURE; } stream->push_headers_alloc *= 2; - headp = realloc(stream->push_headers, - stream->push_headers_alloc * sizeof(char *)); + headp = curlx_realloc(stream->push_headers, + stream->push_headers_alloc * sizeof(char *)); if(!headp) { free_push_headers(stream); return NGHTTP2_ERR_CALLBACK_FAILURE; @@ -1665,15 +1664,16 @@ static int on_header(nghttp2_session *session, const nghttp2_frame *frame, memcmp(HTTP_PSEUDO_STATUS, name, namelen) == 0) { /* nghttp2 guarantees :status is received first and only once. */ char buffer[32]; + size_t hlen; result = Curl_http_decode_status(&stream->status_code, (const char *)value, valuelen); if(result) { cf_h2_header_error(cf, data_s, stream, result); return NGHTTP2_ERR_CALLBACK_FAILURE; } - curl_msnprintf(buffer, sizeof(buffer), HTTP_PSEUDO_STATUS ":%u\r", - stream->status_code); - result = Curl_headers_push(data_s, buffer, CURLH_PSEUDO); + hlen = curl_msnprintf(buffer, sizeof(buffer), HTTP_PSEUDO_STATUS ":%u\r", + stream->status_code); + result = Curl_headers_push(data_s, buffer, hlen, CURLH_PSEUDO); if(result) { cf_h2_header_error(cf, data_s, stream, result); return NGHTTP2_ERR_CALLBACK_FAILURE; @@ -1804,17 +1804,17 @@ CURLcode Curl_http2_request_upgrade(struct dynbuf *req, size_t blen; struct SingleRequest *k = &data->req; uint8_t binsettings[H2_BINSETTINGS_LEN]; - ssize_t binlen; /* length of the binsettings data */ + ssize_t rc; + size_t binlen; /* length of the binsettings data */ - binlen = populate_binsettings(binsettings, data); - if(binlen <= 0) { + rc = populate_binsettings(binsettings, data); + if(!curlx_sztouz(rc, &binlen) || !binlen) { failf(data, "nghttp2 unexpectedly failed on pack_settings_payload"); curlx_dyn_free(req); return CURLE_FAILED_INIT; } - result = curlx_base64url_encode((const char *)binsettings, (size_t)binlen, - &base64, &blen); + result = curlx_base64url_encode(binsettings, binlen, &base64, &blen); if(result) { curlx_dyn_free(req); return result; @@ -1826,7 +1826,7 @@ CURLcode Curl_http2_request_upgrade(struct dynbuf *req, "Upgrade: %s\r\n" "HTTP2-Settings: %s\r\n", NGHTTP2_CLEARTEXT_PROTO_VERSION_ID, base64); - free(base64); + curlx_free(base64); k->upgr101 = UPGR101_H2; data->conn->bits.upgrade_in_progress = TRUE; @@ -1894,7 +1894,8 @@ static CURLcode http2_handle_stream_close(struct Curl_cfilter *cf, break; Curl_debug(data, CURLINFO_HEADER_IN, curlx_dyn_ptr(&dbuf), curlx_dyn_len(&dbuf)); - result = Curl_client_write(data, CLIENTWRITE_HEADER|CLIENTWRITE_TRAILER, + result = Curl_client_write(data, + CLIENTWRITE_HEADER | CLIENTWRITE_TRAILER, curlx_dyn_ptr(&dbuf), curlx_dyn_len(&dbuf)); if(result) break; @@ -1961,7 +1962,7 @@ static CURLcode h2_progress_egress(struct Curl_cfilter *cf, if(stream && stream->id > 0 && ((sweight_wanted(data) != sweight_in_effect(data)) || (data->set.priority.exclusive != data->state.priority.exclusive) || - (data->set.priority.parent != data->state.priority.parent)) ) { + (data->set.priority.parent != data->state.priority.parent))) { /* send new weight and/or dependency */ nghttp2_priority_spec pri_spec; @@ -2003,6 +2004,9 @@ static CURLcode stream_recv(struct Curl_cfilter *cf, struct Curl_easy *data, (void)len; *pnread = 0; + if(!stream->xfer_result) + stream->xfer_result = cf_h2_update_local_win(cf, data, stream); + if(stream->xfer_result) { CURL_TRC_CF(data, cf, "[%d] xfer write failed", stream->id); result = stream->xfer_result; @@ -2034,11 +2038,11 @@ static CURLcode h2_progress_ingress(struct Curl_cfilter *cf, size_t nread; if(should_close_session(ctx)) { - CURL_TRC_CF(data, cf, "progress ingress, session is closed"); + CURL_TRC_CF(data, cf, "[0] ingress: session is closed"); return CURLE_HTTP2; } - /* Process network input buffer fist */ + /* Process network input buffer first */ if(!Curl_bufq_is_empty(&ctx->inbufq)) { CURL_TRC_CF(data, cf, "Process %zu bytes in connection buffer", Curl_bufq_len(&ctx->inbufq)); @@ -2091,15 +2095,16 @@ static CURLcode h2_progress_ingress(struct Curl_cfilter *cf, result = h2_process_pending_input(cf, data); if(result) return result; - CURL_TRC_CF(data, cf, "[0] progress ingress: inbufg=%zu", + CURL_TRC_CF(data, cf, "[0] ingress: nw-in buffered %zu", Curl_bufq_len(&ctx->inbufq)); } if(ctx->conn_closed && Curl_bufq_is_empty(&ctx->inbufq)) { - connclose(cf->conn, "GOAWAY received"); + connclose(cf->conn, ctx->rcvd_goaway ? "server closed with GOAWAY" : + "server closed abruptly"); } - CURL_TRC_CF(data, cf, "[0] progress ingress: done"); + CURL_TRC_CF(data, cf, "[0] ingress: done"); return CURLE_OK; } @@ -2173,15 +2178,16 @@ static CURLcode cf_h2_recv(struct Curl_cfilter *cf, struct Curl_easy *data, return result; } -static ssize_t cf_h2_body_send(struct Curl_cfilter *cf, - struct Curl_easy *data, - struct h2_stream_ctx *stream, - const void *buf, size_t blen, bool eos, - CURLcode *err) +static CURLcode cf_h2_body_send(struct Curl_cfilter *cf, + struct Curl_easy *data, + struct h2_stream_ctx *stream, + const void *buf, size_t blen, bool eos, + size_t *pnwritten) { struct cf_h2_ctx *ctx = cf->ctx; - size_t nwritten; + CURLcode result; + *pnwritten = 0; if(stream->closed) { if(stream->resp_hds_complete) { /* Server decided to close the stream after having sent us a final @@ -2193,36 +2199,34 @@ static ssize_t cf_h2_body_send(struct Curl_cfilter *cf, "on closed stream with response", stream->id); if(eos) stream->body_eos = TRUE; - *err = CURLE_OK; - return (ssize_t)blen; + *pnwritten = blen; + return CURLE_OK; } /* Server closed before we got a response, this is an error */ infof(data, "stream %u closed", stream->id); - *err = CURLE_SEND_ERROR; - return -1; + return CURLE_SEND_ERROR; } - *err = Curl_bufq_write(&stream->sendbuf, buf, blen, &nwritten); - if(*err) - return -1; + result = Curl_bufq_write(&stream->sendbuf, buf, blen, pnwritten); + if(result) + return result; - if(eos && (blen == nwritten)) + if(eos && (blen == *pnwritten)) stream->body_eos = TRUE; if(eos || !Curl_bufq_is_empty(&stream->sendbuf)) { /* resume the potentially suspended stream */ int rv = nghttp2_session_resume_data(ctx->h2, stream->id); - if(nghttp2_is_fatal(rv)) { - *err = CURLE_SEND_ERROR; - return -1; - } + if(nghttp2_is_fatal(rv)) + return CURLE_SEND_ERROR; } - return (ssize_t)nwritten; + + return CURLE_OK; } static CURLcode h2_submit(struct h2_stream_ctx **pstream, struct Curl_cfilter *cf, struct Curl_easy *data, - const void *buf, size_t len, + const uint8_t *buf, size_t len, bool eos, size_t *pnwritten) { struct cf_h2_ctx *ctx = cf->ctx; @@ -2234,8 +2238,9 @@ static CURLcode h2_submit(struct h2_stream_ctx **pstream, nghttp2_data_provider data_prd; int32_t stream_id; nghttp2_priority_spec pri_spec; - ssize_t nwritten; + size_t nwritten; CURLcode result = CURLE_OK; + uint32_t initial_win_size; *pnwritten = 0; Curl_dynhds_init(&h2_headers, 0, DYN_HTTP_REQUEST); @@ -2244,10 +2249,13 @@ static CURLcode h2_submit(struct h2_stream_ctx **pstream, if(result) goto out; - nwritten = Curl_h1_req_parse_read(&stream->h1, buf, len, NULL, 0, &result); - if(nwritten < 0) + result = Curl_h1_req_parse_read(&stream->h1, buf, len, NULL, + !data->state.http_ignorecustom ? + data->set.str[STRING_CUSTOMREQUEST] : NULL, + 0, &nwritten); + if(result) goto out; - *pnwritten = (size_t)nwritten; + *pnwritten = nwritten; if(!stream->h1.done) { /* need more data */ goto out; @@ -2270,6 +2278,15 @@ static CURLcode h2_submit(struct h2_stream_ctx **pstream, if(!nghttp2_session_check_request_allowed(ctx->h2)) CURL_TRC_CF(data, cf, "send request NOT allowed (via nghttp2)"); + /* Check the initial windows size of the transfer (rate-limits?) and + * send an updated settings on changes from previous value. */ + initial_win_size = cf_h2_initial_win_size(data); + if(initial_win_size != ctx->initial_win_size) { + result = cf_h2_update_settings(ctx, initial_win_size); + if(result) + goto out; + } + switch(data->state.httpreq) { case HTTPREQ_POST: case HTTPREQ_POST_FORM: @@ -2298,7 +2315,7 @@ static CURLcode h2_submit(struct h2_stream_ctx **pstream, size_t acc = 0, i; infof(data, "[HTTP/2] [%d] OPENED stream for %s", - stream_id, data->state.url); + stream_id, Curl_bufref_ptr(&data->state.url)); for(i = 0; i < nheader; ++i) { acc += nva[i].namelen + nva[i].valuelen; @@ -2321,8 +2338,9 @@ static CURLcode h2_submit(struct h2_stream_ctx **pstream, bodylen = len - *pnwritten; if(bodylen || eos) { - ssize_t n = cf_h2_body_send(cf, data, stream, body, bodylen, eos, &result); - if(n >= 0) + size_t n; + result = cf_h2_body_send(cf, data, stream, body, bodylen, eos, &n); + if(!result) *pnwritten += n; else if(result == CURLE_AGAIN) result = CURLE_OK; @@ -2341,13 +2359,12 @@ static CURLcode h2_submit(struct h2_stream_ctx **pstream, } static CURLcode cf_h2_send(struct Curl_cfilter *cf, struct Curl_easy *data, - const void *buf, size_t len, bool eos, + const uint8_t *buf, size_t len, bool eos, size_t *pnwritten) { struct cf_h2_ctx *ctx = cf->ctx; struct h2_stream_ctx *stream = H2_STREAM_CTX(ctx, data); struct cf_call_data save; - ssize_t nwritten; CURLcode result = CURLE_OK, r2; CF_DATA_SAVE(save, cf, data); @@ -2364,21 +2381,19 @@ static CURLcode cf_h2_send(struct Curl_cfilter *cf, struct Curl_easy *data, * being able to flush stream->sendbuf. Make a 0-length write * to trigger flushing again. * If this works, we report to have written `len` bytes. */ + size_t n; DEBUGASSERT(eos); - nwritten = cf_h2_body_send(cf, data, stream, buf, 0, eos, &result); - CURL_TRC_CF(data, cf, "[%d] cf_body_send last CHUNK -> %zd, %d, eos=%d", - stream->id, nwritten, result, eos); - if(nwritten < 0) { + result = cf_h2_body_send(cf, data, stream, buf, 0, eos, &n); + CURL_TRC_CF(data, cf, "[%d] cf_body_send last CHUNK -> %d, %zu, eos=%d", + stream->id, result, n, eos); + if(result) goto out; - } *pnwritten = len; } else { - nwritten = cf_h2_body_send(cf, data, stream, buf, len, eos, &result); - CURL_TRC_CF(data, cf, "[%d] cf_body_send(len=%zu) -> %zd, %d, eos=%d", - stream->id, len, nwritten, result, eos); - if(nwritten >= 0) - *pnwritten = (size_t)nwritten; + result = cf_h2_body_send(cf, data, stream, buf, len, eos, pnwritten); + CURL_TRC_CF(data, cf, "[%d] cf_body_send(len=%zu) -> %d, %zu, eos=%d", + stream->id, len, result, *pnwritten, eos); } /* Call the nghttp2 send loop and flush to write ALL buffered data, @@ -2558,7 +2573,7 @@ static CURLcode cf_h2_connect(struct Curl_cfilter *cf, } /* Send out our SETTINGS and ACKs and such. If that blocks, we - * have it buffered and can count this filter as being connected */ + * have it buffered and can count this filter as being connected */ result = h2_progress_egress(cf, data); if(result && (result != CURLE_AGAIN)) goto out; @@ -2772,7 +2787,7 @@ static CURLcode cf_h2_query(struct Curl_cfilter *cf, CF_DATA_SAVE(save, cf, data); if(!ctx->h2 || !nghttp2_session_check_request_allowed(ctx->h2)) { /* the limit is what we have in use right now */ - effective_max = CONN_ATTACHED(cf->conn); + effective_max = cf->conn->attached_xfers; } else { effective_max = ctx->max_concurrent_streams; @@ -2834,7 +2849,7 @@ static CURLcode http2_cfilter_add(struct Curl_cfilter **pcf, CURLcode result = CURLE_OUT_OF_MEMORY; DEBUGASSERT(data->conn); - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) goto out; cf_h2_ctx_init(ctx, via_h1_upgrade); @@ -2862,7 +2877,7 @@ static CURLcode http2_cfilter_insert_after(struct Curl_cfilter *cf, CURLcode result = CURLE_OUT_OF_MEMORY; (void)data; - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) goto out; cf_h2_ctx_init(ctx, via_h1_upgrade); @@ -2945,7 +2960,7 @@ CURLcode Curl_http2_upgrade(struct Curl_easy *data, struct cf_h2_ctx *ctx; CURLcode result; - DEBUGASSERT(Curl_conn_http_version(data, conn) < 20); + DEBUGASSERT(Curl_conn_http_version(data, conn) < 20); result = http2_cfilter_add(&cf, data, conn, sockindex, TRUE); if(result) @@ -3028,7 +3043,6 @@ void *Curl_nghttp2_realloc(void *ptr, size_t size, void *user_data) #else /* CURL_DISABLE_HTTP || !USE_NGHTTP2 */ /* Satisfy external references even if http2 is not compiled in. */ -#include char *curl_pushheader_bynum(struct curl_pushheaders *h, size_t num) { diff --git a/vendor/hydra/vendor/curl/lib/http2.h b/vendor/hydra/vendor/curl/lib/http2.h index 93cc2d44..950b2f7b 100644 --- a/vendor/hydra/vendor/curl/lib/http2.h +++ b/vendor/hydra/vendor/curl/lib/http2.h @@ -23,11 +23,9 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifdef USE_NGHTTP2 -#include "http.h" /* value for MAX_CONCURRENT_STREAMS we use until we get an updated setting from the peer */ @@ -65,10 +63,10 @@ extern struct Curl_cftype Curl_cft_nghttp2; #define Curl_http2_may_switch(a) FALSE -#define Curl_http2_request_upgrade(x,y) CURLE_UNSUPPORTED_PROTOCOL -#define Curl_http2_switch(a) CURLE_UNSUPPORTED_PROTOCOL -#define Curl_http2_upgrade(a,b,c,d,e) CURLE_UNSUPPORTED_PROTOCOL -#define Curl_h2_http_1_1_error(x) 0 +#define Curl_http2_request_upgrade(x, y) CURLE_UNSUPPORTED_PROTOCOL +#define Curl_http2_switch(a) CURLE_UNSUPPORTED_PROTOCOL +#define Curl_http2_upgrade(a, b, c, d, e) CURLE_UNSUPPORTED_PROTOCOL +#define Curl_h2_http_1_1_error(x) 0 #endif #endif /* HEADER_CURL_HTTP2_H */ diff --git a/vendor/hydra/vendor/curl/lib/http_aws_sigv4.c b/vendor/hydra/vendor/curl/lib/http_aws_sigv4.c index bb88a0f8..598d8cbe 100644 --- a/vendor/hydra/vendor/curl/lib/http_aws_sigv4.c +++ b/vendor/hydra/vendor/curl/lib/http_aws_sigv4.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_AWS) @@ -32,19 +31,13 @@ #include "http_aws_sigv4.h" #include "curl_sha256.h" #include "transfer.h" -#include "parsedate.h" -#include "sendf.h" +#include "curl_trc.h" #include "escape.h" #include "curlx/strparse.h" +#include "slist.h" #include -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - -#include "slist.h" - #define HMAC_SHA256(k, kl, d, dl, o) \ do { \ result = Curl_hmacit(&Curl_HMAC_SHA256, \ @@ -137,7 +130,7 @@ static void trim_headers(struct curl_slist *head) } /* maximum length for the aws sivg4 parts */ -#define MAX_SIGV4_LEN 64 +#define MAX_SIGV4_LEN 64 #define DATE_HDR_KEY_LEN (MAX_SIGV4_LEN + sizeof("X--Date")) /* string been x-PROVIDER-date:TIMESTAMP, I need +1 for ':' */ @@ -210,12 +203,12 @@ static CURLcode merge_duplicate_headers(struct curl_slist *head) if(result) return result; - free(curr->data); + curlx_free(curr->data); curr->data = curlx_dyn_ptr(&buf); curr->next = next->next; - free(next->data); - free(next); + curlx_free(next->data); + curlx_free(next); } else { curr = curr->next; @@ -269,12 +262,11 @@ static CURLcode make_headers(struct Curl_easy *data, if(fullhost) head = Curl_slist_append_nodup(NULL, fullhost); if(!head) { - free(fullhost); + curlx_free(fullhost); goto fail; } } - if(*content_sha256_header) { tmp_head = curl_slist_append(head, content_sha256_header); if(!tmp_head) @@ -308,13 +300,13 @@ static CURLcode make_headers(struct Curl_easy *data, ; if(!*ptr && ptr != sep + 1) /* a value of whitespace only */ continue; - dupdata = strdup(l->data); + dupdata = curlx_strdup(l->data); if(!dupdata) goto fail; dupdata[sep - l->data] = ':'; tmp_head = Curl_slist_append_nodup(head, dupdata); if(!tmp_head) { - free(dupdata); + curlx_free(dupdata); goto fail; } head = tmp_head; @@ -405,14 +397,14 @@ static CURLcode make_headers(struct Curl_easy *data, #define CONTENT_SHA256_KEY_LEN (MAX_SIGV4_LEN + sizeof("X--Content-Sha256")) /* add 2 for ": " between header name and value */ -#define CONTENT_SHA256_HDR_LEN (CONTENT_SHA256_KEY_LEN + 2 + \ - SHA256_HEX_LENGTH) +#define CONTENT_SHA256_HDR_LEN (CONTENT_SHA256_KEY_LEN + 2 + SHA256_HEX_LENGTH) /* try to parse a payload hash from the content-sha256 header */ static const char *parse_content_sha_hdr(struct Curl_easy *data, const char *provider1, size_t plen, - size_t *value_len) { + size_t *value_len) +{ char key[CONTENT_SHA256_KEY_LEN]; size_t key_len; const char *value; @@ -433,7 +425,7 @@ static const char *parse_content_sha_hdr(struct Curl_easy *data, curlx_str_passblanks(&value); len = strlen(value); - while(len > 0 && ISBLANK(value[len-1])) + while(len > 0 && ISBLANK(value[len - 1])) --len; *value_len = len; @@ -453,7 +445,7 @@ static CURLcode calc_payload_hash(struct Curl_easy *data, else post_data_len = (size_t)data->set.postfieldsize; } - result = Curl_sha256it(sha_hash, (const unsigned char *) post_data, + result = Curl_sha256it(sha_hash, (const unsigned char *)post_data, post_data_len); if(!result) sha256_to_hex(sha_hex, sha_hash); @@ -534,7 +526,6 @@ static int compare_func(const void *a, const void *b) compare = strcmp(curlx_dyn_ptr(&aa->value), curlx_dyn_ptr(&bb->value)); return compare; - } UNITTEST CURLcode canon_path(const char *q, size_t len, @@ -576,14 +567,13 @@ UNITTEST CURLcode canon_query(const char *query, struct dynbuf *dq) if(!query) return result; - result = split_to_dyn_array(query, &query_array[0], - &num_query_components); + result = split_to_dyn_array(query, &query_array[0], &num_query_components); if(result) { goto fail; } /* Create list of pairs, each pair containing an encoded query - * component */ + * component */ for(index = 0; index < num_query_components; index++) { const char *in_key; @@ -603,8 +593,8 @@ UNITTEST CURLcode canon_query(const char *query, struct dynbuf *dq) in_key_len = offset - in_key; } - curlx_dyn_init(&encoded_query_array[index].key, query_part_len*3 + 1); - curlx_dyn_init(&encoded_query_array[index].value, query_part_len*3 + 1); + curlx_dyn_init(&encoded_query_array[index].key, query_part_len * 3 + 1); + curlx_dyn_init(&encoded_query_array[index].value, query_part_len * 3 + 1); counted_query_components++; /* Decode/encode the key */ @@ -676,8 +666,8 @@ CURLcode Curl_output_aws_sigv4(struct Curl_easy *data) const char *line; struct Curl_str provider0; struct Curl_str provider1; - struct Curl_str region = { NULL, 0}; - struct Curl_str service = { NULL, 0}; + struct Curl_str region = { NULL, 0 }; + struct Curl_str service = { NULL, 0 }; const char *hostname = conn->host.name; time_t clock; struct tm tm; @@ -701,8 +691,8 @@ CURLcode Curl_output_aws_sigv4(struct Curl_easy *data) char *str_to_sign = NULL; const char *user = data->state.aptr.user ? data->state.aptr.user : ""; char *secret = NULL; - unsigned char sign0[CURL_SHA256_DIGEST_LENGTH] = {0}; - unsigned char sign1[CURL_SHA256_DIGEST_LENGTH] = {0}; + unsigned char sign0[CURL_SHA256_DIGEST_LENGTH] = { 0 }; + unsigned char sign1[CURL_SHA256_DIGEST_LENGTH] = { 0 }; char *auth_headers = NULL; if(data->set.path_as_is) { @@ -786,7 +776,7 @@ CURLcode Curl_output_aws_sigv4(struct Curl_easy *data) /* AWS S3 requires a x-amz-content-sha256 header, and supports special * values like UNSIGNED-PAYLOAD */ bool sign_as_s3 = curlx_str_casecompare(&provider0, "aws") && - curlx_str_casecompare(&service, "s3"); + curlx_str_casecompare(&service, "s3"); if(sign_as_s3) result = calc_s3_payload_hash(data, httpreq, curlx_str(&provider1), @@ -813,7 +803,7 @@ CURLcode Curl_output_aws_sigv4(struct Curl_easy *data) #else clock = time(NULL); #endif - result = Curl_gmtime(clock, &tm); + result = curlx_gmtime(clock, &tm); if(result) { goto fail; } @@ -868,7 +858,7 @@ CURLcode Curl_output_aws_sigv4(struct Curl_easy *data) goto fail; infof(data, "aws_sigv4: Canonical request (enclosed in []) - [%s]", - canonical_request); + canonical_request); request_type = curl_maprintf("%.*s4_request", (int)curlx_strlen(&provider0), @@ -889,7 +879,7 @@ CURLcode Curl_output_aws_sigv4(struct Curl_easy *data) if(!credential_scope) goto fail; - if(Curl_sha256it(sha_hash, (unsigned char *) canonical_request, + if(Curl_sha256it(sha_hash, (unsigned char *)canonical_request, strlen(canonical_request))) goto fail; @@ -916,7 +906,7 @@ CURLcode Curl_output_aws_sigv4(struct Curl_easy *data) curlx_strlen(&provider0)); infof(data, "aws_sigv4: String to sign (enclosed in []) - [%s]", - str_to_sign); + str_to_sign); secret = curl_maprintf("%.*s4%s", (int)curlx_strlen(&provider0), curlx_str(&provider0), data->state.aptr.passwd ? @@ -964,7 +954,7 @@ CURLcode Curl_output_aws_sigv4(struct Curl_easy *data) Curl_strntoupper(&auth_headers[sizeof("Authorization: ") - 1], curlx_str(&provider0), curlx_strlen(&provider0)); - free(data->state.aptr.userpwd); + curlx_free(data->state.aptr.userpwd); data->state.aptr.userpwd = auth_headers; data->state.authhost.done = TRUE; result = CURLE_OK; @@ -974,18 +964,18 @@ CURLcode Curl_output_aws_sigv4(struct Curl_easy *data) curlx_dyn_free(&canonical_path); curlx_dyn_free(&canonical_headers); curlx_dyn_free(&signed_headers); - free(canonical_request); - free(request_type); - free(credential_scope); - free(str_to_sign); - free(secret); - free(date_header); + curlx_free(canonical_request); + curlx_free(request_type); + curlx_free(credential_scope); + curlx_free(str_to_sign); + curlx_free(secret); + curlx_free(date_header); return result; } /* -* Frees all allocated strings in a dynbuf pair array, and the dynbuf itself -*/ + * Frees all allocated strings in a dynbuf pair array, and the dynbuf itself + */ static void pair_array_free(struct pair *pair_array, size_t num_elements) { @@ -995,12 +985,11 @@ static void pair_array_free(struct pair *pair_array, size_t num_elements) curlx_dyn_free(&pair_array[index].key); curlx_dyn_free(&pair_array[index].value); } - } /* -* Frees all allocated strings in a split dynbuf, and the dynbuf itself -*/ + * Frees all allocated strings in a split dynbuf, and the dynbuf itself + */ static void dyn_array_free(struct dynbuf *db, size_t num_elements) { @@ -1011,10 +1000,10 @@ static void dyn_array_free(struct dynbuf *db, size_t num_elements) } /* -* Splits source string by SPLIT_BY, and creates an array of dynbuf in db. -* db is initialized by this function. -* Caller is responsible for freeing the array elements with dyn_array_free -*/ + * Splits source string by SPLIT_BY, and creates an array of dynbuf in db. + * db is initialized by this function. + * Caller is responsible for freeing the array elements with dyn_array_free + */ #define SPLIT_BY '&' @@ -1036,8 +1025,7 @@ static CURLcode split_to_dyn_array(const char *source, if(source[pos] == SPLIT_BY) { if(segment_length) { curlx_dyn_init(&db[index], segment_length + 1); - result = curlx_dyn_addn(&db[index], &source[start], - segment_length); + result = curlx_dyn_addn(&db[index], &source[start], segment_length); if(result) goto fail; @@ -1068,7 +1056,6 @@ static CURLcode split_to_dyn_array(const char *source, return result; } - static bool is_reserved_char(const char c) { return (ISALNUM(c) || ISURLPUNTCS(c)); @@ -1095,7 +1082,6 @@ static CURLcode uri_encode_path(struct Curl_str *original_path, return CURLE_OK; } - static CURLcode encode_query_component(char *component, size_t len, struct dynbuf *db) { @@ -1120,8 +1106,8 @@ static CURLcode encode_query_component(char *component, size_t len, } /* -* Populates a dynbuf containing url_encode(url_decode(in)) -*/ + * Populates a dynbuf containing url_encode(url_decode(in)) + */ static CURLcode http_aws_decode_encode(const char *in, size_t in_len, struct dynbuf *out) @@ -1141,10 +1127,10 @@ static CURLcode http_aws_decode_encode(const char *in, size_t in_len, static bool should_urlencode(struct Curl_str *service_name) { /* - * These services require unmodified (not additionally url encoded) URL + * These services require unmodified (not additionally URL-encoded) URL * paths. * should_urlencode == true is equivalent to should_urlencode_uri_path - * from the AWS SDK. Urls are already normalized by the curl url parser + * from the AWS SDK. Urls are already normalized by the curl URL parser */ if(curlx_str_cmp(service_name, "s3") || diff --git a/vendor/hydra/vendor/curl/lib/http_aws_sigv4.h b/vendor/hydra/vendor/curl/lib/http_aws_sigv4.h index 9747c948..25009c68 100644 --- a/vendor/hydra/vendor/curl/lib/http_aws_sigv4.h +++ b/vendor/hydra/vendor/curl/lib/http_aws_sigv4.h @@ -24,17 +24,16 @@ * ***************************************************************************/ #include "curl_setup.h" + #include "curlx/dynbuf.h" #include "urldata.h" -#include "curlx/strparse.h" /* this is for creating aws_sigv4 header output */ CURLcode Curl_output_aws_sigv4(struct Curl_easy *data); #ifdef UNITTESTS UNITTEST CURLcode canon_path(const char *q, size_t len, - struct dynbuf *new_path, - bool normalize); + struct dynbuf *new_path, bool normalize); UNITTEST CURLcode canon_query(const char *query, struct dynbuf *dq); #endif diff --git a/vendor/hydra/vendor/curl/lib/http_chunks.c b/vendor/hydra/vendor/curl/lib/http_chunks.c index 005d34e7..f78a89e5 100644 --- a/vendor/hydra/vendor/curl/lib/http_chunks.c +++ b/vendor/hydra/vendor/curl/lib/http_chunks.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifndef CURL_DISABLE_HTTP @@ -30,15 +29,8 @@ #include "curl_trc.h" #include "sendf.h" /* for the client write stuff */ #include "curlx/dynbuf.h" -#include "content_encoding.h" -#include "http.h" #include "multiif.h" #include "curlx/strparse.h" -#include "curlx/warnless.h" - -/* The last #include files should be: */ -#include "curl_memory.h" -#include "memdebug.h" /* * Chunk format (simplified): @@ -361,7 +353,6 @@ static CURLcode httpchunk_readwrite(struct Curl_easy *data, case CHUNK_FAILED: return CURLE_RECV_ERROR; } - } return CURLE_OK; } @@ -532,8 +523,7 @@ static CURLcode add_last_chunk(struct Curl_easy *data, continue; } - result = Curl_bufq_cwrite(&ctx->chunkbuf, tr->data, - strlen(tr->data), &n); + result = Curl_bufq_cwrite(&ctx->chunkbuf, tr->data, strlen(tr->data), &n); if(!result) result = Curl_bufq_cwrite(&ctx->chunkbuf, STRCONST("\r\n"), &n); if(result) diff --git a/vendor/hydra/vendor/curl/lib/http_chunks.h b/vendor/hydra/vendor/curl/lib/http_chunks.h index b84e479f..d8e5982e 100644 --- a/vendor/hydra/vendor/curl/lib/http_chunks.h +++ b/vendor/hydra/vendor/curl/lib/http_chunks.h @@ -23,6 +23,7 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ +#include "curl_setup.h" #ifndef CURL_DISABLE_HTTP diff --git a/vendor/hydra/vendor/curl/lib/http_digest.c b/vendor/hydra/vendor/curl/lib/http_digest.c index 097c81fd..ccc67f5e 100644 --- a/vendor/hydra/vendor/curl/lib/http_digest.c +++ b/vendor/hydra/vendor/curl/lib/http_digest.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_DIGEST_AUTH) @@ -32,10 +31,6 @@ #include "http_digest.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* Test example headers: WWW-Authenticate: Digest realm="testrealm", nonce="1053604598" @@ -152,20 +147,20 @@ CURLcode Curl_output_digest(struct Curl_easy *data, } } if(!tmp) - path = (unsigned char *)strdup((const char *) uripath); + path = (unsigned char *)curlx_strdup((const char *)uripath); if(!path) return CURLE_OUT_OF_MEMORY; result = Curl_auth_create_digest_http_message(data, userp, passwdp, request, path, digest, &response, &len); - free(path); + curlx_free(path); if(result) return result; *allocuserpwd = curl_maprintf("%sAuthorization: Digest %s\r\n", proxy ? "Proxy-" : "", response); - free(response); + curlx_free(response); if(!*allocuserpwd) return CURLE_OUT_OF_MEMORY; diff --git a/vendor/hydra/vendor/curl/lib/http_negotiate.c b/vendor/hydra/vendor/curl/lib/http_negotiate.c index 136cb076..be1063d9 100644 --- a/vendor/hydra/vendor/curl/lib/http_negotiate.c +++ b/vendor/hydra/vendor/curl/lib/http_negotiate.c @@ -21,23 +21,18 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #if !defined(CURL_DISABLE_HTTP) && defined(USE_SPNEGO) #include "urldata.h" #include "cfilters.h" -#include "sendf.h" +#include "curl_trc.h" #include "http_negotiate.h" #include "vauth/vauth.h" #include "vtls/vtls.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - static void http_auth_nego_reset(struct connectdata *conn, struct negotiatedata *neg_ctx, @@ -51,7 +46,6 @@ static void http_auth_nego_reset(struct connectdata *conn, Curl_auth_cleanup_spnego(neg_ctx); } - CURLcode Curl_input_negotiate(struct Curl_easy *data, struct connectdata *conn, bool proxy, const char *header) { @@ -124,12 +118,12 @@ CURLcode Curl_input_negotiate(struct Curl_easy *data, struct connectdata *conn, neg_ctx->sslContext = conn->sslContext; #endif /* Check if the connection is using SSL and get the channel binding data */ -#ifdef CURL_GSSAPI_HAS_CHANNEL_BINDING +#ifdef GSS_C_CHANNEL_BOUND_FLAG #ifdef USE_SSL curlx_dyn_init(&neg_ctx->channel_binding_data, SSL_CB_MAX_SIZE + 1); if(Curl_conn_is_ssl(conn, FIRSTSOCKET)) { - result = Curl_ssl_get_channel_binding( - data, FIRSTSOCKET, &neg_ctx->channel_binding_data); + result = Curl_ssl_get_channel_binding(data, FIRSTSOCKET, + &neg_ctx->channel_binding_data); if(result) { http_auth_nego_reset(conn, neg_ctx, proxy); return result; @@ -138,13 +132,13 @@ CURLcode Curl_input_negotiate(struct Curl_easy *data, struct connectdata *conn, #else curlx_dyn_init(&neg_ctx->channel_binding_data, 1); #endif /* USE_SSL */ -#endif /* CURL_GSSAPI_HAS_CHANNEL_BINDING */ +#endif /* GSS_C_CHANNEL_BOUND_FLAG */ /* Initialize the security context and decode our challenge */ result = Curl_auth_decode_spnego_message(data, userp, passwdp, service, host, header, neg_ctx); -#ifdef CURL_GSSAPI_HAS_CHANNEL_BINDING +#ifdef GSS_C_CHANNEL_BOUND_FLAG curlx_dyn_free(&neg_ctx->channel_binding_data); #endif @@ -223,16 +217,16 @@ CURLcode Curl_output_negotiate(struct Curl_easy *data, if(proxy) { #ifndef CURL_DISABLE_PROXY - free(data->state.aptr.proxyuserpwd); + curlx_free(data->state.aptr.proxyuserpwd); data->state.aptr.proxyuserpwd = userp; #endif } else { - free(data->state.aptr.userpwd); + curlx_free(data->state.aptr.userpwd); data->state.aptr.userpwd = userp; } - free(base64); + curlx_free(base64); if(!userp) { return CURLE_OUT_OF_MEMORY; diff --git a/vendor/hydra/vendor/curl/lib/http_negotiate.h b/vendor/hydra/vendor/curl/lib/http_negotiate.h index ad7c43d8..6c285f15 100644 --- a/vendor/hydra/vendor/curl/lib/http_negotiate.h +++ b/vendor/hydra/vendor/curl/lib/http_negotiate.h @@ -23,6 +23,7 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ +#include "curl_setup.h" #if !defined(CURL_DISABLE_HTTP) && defined(USE_SPNEGO) diff --git a/vendor/hydra/vendor/curl/lib/http_ntlm.c b/vendor/hydra/vendor/curl/lib/http_ntlm.c index fa375b49..c4dbdf9c 100644 --- a/vendor/hydra/vendor/curl/lib/http_ntlm.c +++ b/vendor/hydra/vendor/curl/lib/http_ntlm.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #if !defined(CURL_DISABLE_HTTP) && defined(USE_NTLM) @@ -34,7 +33,7 @@ */ #include "urldata.h" -#include "sendf.h" +#include "curl_trc.h" #include "strcase.h" #include "http_ntlm.h" #include "curl_ntlm_core.h" @@ -49,10 +48,6 @@ #include "curl_sspi.h" #endif -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - CURLcode Curl_input_ntlm(struct Curl_easy *data, bool proxy, /* if proxy or not */ const char *header) /* rest of the www-authenticate: @@ -68,7 +63,7 @@ CURLcode Curl_input_ntlm(struct Curl_easy *data, if(checkprefix("NTLM", header)) { struct ntlmdata *ntlm = Curl_auth_ntlm_get(conn, proxy); if(!ntlm) - return CURLE_FAILED_INIT; + return CURLE_OUT_OF_MEMORY; header += strlen("NTLM"); curlx_str_passblanks(&header); @@ -148,7 +143,7 @@ CURLcode Curl_output_ntlm(struct Curl_easy *data, bool proxy) userp = data->state.aptr.proxyuser; passwdp = data->state.aptr.proxypasswd; service = data->set.str[STRING_PROXY_SERVICE_NAME] ? - data->set.str[STRING_PROXY_SERVICE_NAME] : "HTTP"; + data->set.str[STRING_PROXY_SERVICE_NAME] : "HTTP"; hostname = conn->http_proxy.host.name; state = &conn->proxy_ntlm_state; authp = &data->state.authproxy; @@ -161,7 +156,7 @@ CURLcode Curl_output_ntlm(struct Curl_easy *data, bool proxy) userp = data->state.aptr.user; passwdp = data->state.aptr.passwd; service = data->set.str[STRING_SERVICE_NAME] ? - data->set.str[STRING_SERVICE_NAME] : "HTTP"; + data->set.str[STRING_SERVICE_NAME] : "HTTP"; hostname = conn->host.name; state = &conn->http_ntlm_state; authp = &data->state.authhost; @@ -180,7 +175,7 @@ CURLcode Curl_output_ntlm(struct Curl_easy *data, bool proxy) #ifdef USE_WINDOWS_SSPI if(!Curl_pSecFn) { - /* not thread safe and leaks - use curl_global_init() to avoid */ + /* not thread-safe and leaks - use curl_global_init() to avoid */ CURLcode err = Curl_sspi_global_init(); if(!Curl_pSecFn) return err; @@ -205,14 +200,13 @@ CURLcode Curl_output_ntlm(struct Curl_easy *data, bool proxy) hostname, ntlm, &ntlmmsg); if(!result) { DEBUGASSERT(Curl_bufref_len(&ntlmmsg) != 0); - result = curlx_base64_encode((const char *) Curl_bufref_ptr(&ntlmmsg), - Curl_bufref_len(&ntlmmsg), &base64, &len); + result = curlx_base64_encode(Curl_bufref_uptr(&ntlmmsg), + Curl_bufref_len(&ntlmmsg), &base64, &len); if(!result) { - free(*allocuserpwd); + curlx_free(*allocuserpwd); *allocuserpwd = curl_maprintf("%sAuthorization: NTLM %s\r\n", - proxy ? "Proxy-" : "", - base64); - free(base64); + proxy ? "Proxy-" : "", base64); + curlx_free(base64); if(!*allocuserpwd) result = CURLE_OUT_OF_MEMORY; } @@ -224,14 +218,13 @@ CURLcode Curl_output_ntlm(struct Curl_easy *data, bool proxy) result = Curl_auth_create_ntlm_type3_message(data, userp, passwdp, ntlm, &ntlmmsg); if(!result && Curl_bufref_len(&ntlmmsg)) { - result = curlx_base64_encode((const char *) Curl_bufref_ptr(&ntlmmsg), + result = curlx_base64_encode(Curl_bufref_uptr(&ntlmmsg), Curl_bufref_len(&ntlmmsg), &base64, &len); if(!result) { - free(*allocuserpwd); + curlx_free(*allocuserpwd); *allocuserpwd = curl_maprintf("%sAuthorization: NTLM %s\r\n", - proxy ? "Proxy-" : "", - base64); - free(base64); + proxy ? "Proxy-" : "", base64); + curlx_free(base64); if(!*allocuserpwd) result = CURLE_OUT_OF_MEMORY; else { diff --git a/vendor/hydra/vendor/curl/lib/http_ntlm.h b/vendor/hydra/vendor/curl/lib/http_ntlm.h index b38ff82d..ff5218d8 100644 --- a/vendor/hydra/vendor/curl/lib/http_ntlm.h +++ b/vendor/hydra/vendor/curl/lib/http_ntlm.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #if !defined(CURL_DISABLE_HTTP) && defined(USE_NTLM) diff --git a/vendor/hydra/vendor/curl/lib/http_proxy.c b/vendor/hydra/vendor/curl/lib/http_proxy.c index f6e546b9..c5b2f3e8 100644 --- a/vendor/hydra/vendor/curl/lib/http_proxy.c +++ b/vendor/hydra/vendor/curl/lib/http_proxy.c @@ -21,33 +21,23 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #include "http_proxy.h" #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_PROXY) -#include -#include "sendf.h" +#include "curl_trc.h" #include "http.h" #include "url.h" -#include "select.h" -#include "progress.h" #include "cfilters.h" #include "cf-h1-proxy.h" #include "cf-h2-proxy.h" #include "connect.h" -#include "vtls/vtls.h" #include "transfer.h" -#include "multiif.h" #include "vauth/vauth.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - static CURLcode dynhds_add_custom(struct Curl_easy *data, bool is_connect, int httpversion, struct dynhds *hds) @@ -135,25 +125,31 @@ static CURLcode dynhds_add_custom(struct Curl_easy *data, if(data->state.aptr.host && /* a Host: header was sent already, do not pass on any custom Host: header as that will produce *two* in the same request! */ - curlx_str_casecompare(&name, "Host")); + curlx_str_casecompare(&name, "Host")) + ; else if(data->state.httpreq == HTTPREQ_POST_FORM && /* this header (extended by formdata.c) is sent later */ - curlx_str_casecompare(&name, "Content-Type")); + curlx_str_casecompare(&name, "Content-Type")) + ; else if(data->state.httpreq == HTTPREQ_POST_MIME && /* this header is sent later */ - curlx_str_casecompare(&name, "Content-Type")); + curlx_str_casecompare(&name, "Content-Type")) + ; else if(data->req.authneg && /* while doing auth neg, do not allow the custom length since we will force length zero then */ - curlx_str_casecompare(&name, "Content-Length")); + curlx_str_casecompare(&name, "Content-Length")) + ; else if((httpversion >= 20) && - curlx_str_casecompare(&name, "Transfer-Encoding")); + curlx_str_casecompare(&name, "Transfer-Encoding")) + ; /* HTTP/2 and HTTP/3 do not support chunked requests */ else if((curlx_str_casecompare(&name, "Authorization") || curlx_str_casecompare(&name, "Cookie")) && /* be careful of sending this potentially sensitive header to other hosts */ - !Curl_auth_allowed_to_host(data)); + !Curl_auth_allowed_to_host(data)) + ; else { CURLcode result = Curl_dynhds_add(hds, curlx_str(&name), curlx_strlen(&name), @@ -167,9 +163,9 @@ static CURLcode dynhds_add_custom(struct Curl_easy *data, return CURLE_OK; } -CURLcode Curl_http_proxy_get_destination(struct Curl_cfilter *cf, - const char **phostname, - int *pport, bool *pipv6_ip) +void Curl_http_proxy_get_destination(struct Curl_cfilter *cf, + const char **phostname, + int *pport, bool *pipv6_ip) { DEBUGASSERT(cf); DEBUGASSERT(cf->conn); @@ -192,8 +188,6 @@ CURLcode Curl_http_proxy_get_destination(struct Curl_cfilter *cf, *pipv6_ip = (strchr(*phostname, ':') != NULL); else *pipv6_ip = cf->conn->bits.ipv6_ip; - - return CURLE_OK; } struct cf_proxy_ctx { @@ -214,18 +208,16 @@ CURLcode Curl_http_proxy_create_CONNECT(struct httpreq **preq, CURLcode result; struct httpreq *req = NULL; - result = Curl_http_proxy_get_destination(cf, &hostname, &port, &ipv6_ip); - if(result) - goto out; + Curl_http_proxy_get_destination(cf, &hostname, &port, &ipv6_ip); authority = curl_maprintf("%s%s%s:%d", ipv6_ip ? "[" : "", hostname, - ipv6_ip ?"]" : "", port); + ipv6_ip ? "]" : "", port); if(!authority) { result = CURLE_OUT_OF_MEMORY; goto out; } - result = Curl_http_req_make(&req, "CONNECT", sizeof("CONNECT")-1, + result = Curl_http_req_make(&req, "CONNECT", sizeof("CONNECT") - 1, NULL, 0, authority, strlen(authority), NULL, 0); if(result) @@ -261,7 +253,7 @@ CURLcode Curl_http_proxy_create_CONNECT(struct httpreq **preq, } if(http_version_major == 1 && - !Curl_checkProxyheaders(data, cf->conn, STRCONST("Proxy-Connection"))) { + !Curl_checkProxyheaders(data, cf->conn, STRCONST("Proxy-Connection"))) { result = Curl_dynhds_cadd(&req->headers, "Proxy-Connection", "Keep-Alive"); if(result) goto out; @@ -274,7 +266,7 @@ CURLcode Curl_http_proxy_create_CONNECT(struct httpreq **preq, Curl_http_req_free(req); req = NULL; } - free(authority); + curlx_free(authority); *preq = req; return result; } @@ -390,7 +382,7 @@ static void http_proxy_cf_destroy(struct Curl_cfilter *cf, (void)data; CURL_TRC_CF(data, cf, "destroy"); - free(ctx); + curlx_free(ctx); } static void http_proxy_cf_close(struct Curl_cfilter *cf, @@ -402,10 +394,9 @@ static void http_proxy_cf_close(struct Curl_cfilter *cf, cf->next->cft->do_close(cf->next, data); } - struct Curl_cftype Curl_cft_http_proxy = { "HTTP-PROXY", - CF_TYPE_IP_CONNECT|CF_TYPE_PROXY, + CF_TYPE_IP_CONNECT | CF_TYPE_PROXY, 0, http_proxy_cf_destroy, http_proxy_cf_connect, @@ -429,7 +420,7 @@ CURLcode Curl_cf_http_proxy_insert_after(struct Curl_cfilter *cf_at, CURLcode result; (void)data; - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -441,8 +432,8 @@ CURLcode Curl_cf_http_proxy_insert_after(struct Curl_cfilter *cf_at, Curl_conn_cf_insert_after(cf_at, cf); out: - free(ctx); + curlx_free(ctx); return result; } -#endif /* ! CURL_DISABLE_HTTP && !CURL_DISABLE_PROXY */ +#endif /* !CURL_DISABLE_HTTP && !CURL_DISABLE_PROXY */ diff --git a/vendor/hydra/vendor/curl/lib/http_proxy.h b/vendor/hydra/vendor/curl/lib/http_proxy.h index e6ab2bac..c27787b3 100644 --- a/vendor/hydra/vendor/curl/lib/http_proxy.h +++ b/vendor/hydra/vendor/curl/lib/http_proxy.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #if !defined(CURL_DISABLE_PROXY) && !defined(CURL_DISABLE_HTTP) @@ -36,9 +35,9 @@ enum Curl_proxy_use { HEADER_CONNECT /* sending CONNECT to a proxy */ }; -CURLcode Curl_http_proxy_get_destination(struct Curl_cfilter *cf, - const char **phostname, - int *pport, bool *pipv6_ip); +void Curl_http_proxy_get_destination(struct Curl_cfilter *cf, + const char **phostname, + int *pport, bool *pipv6_ip); CURLcode Curl_http_proxy_create_CONNECT(struct httpreq **preq, struct Curl_cfilter *cf, @@ -46,7 +45,7 @@ CURLcode Curl_http_proxy_create_CONNECT(struct httpreq **preq, int http_version_major); /* Default proxy timeout in milliseconds */ -#define PROXY_TIMEOUT (3600*1000) +#define PROXY_TIMEOUT (3600 * 1000) CURLcode Curl_cf_http_proxy_query(struct Curl_cfilter *cf, struct Curl_easy *data, diff --git a/vendor/hydra/vendor/curl/lib/httpsrr.c b/vendor/hydra/vendor/curl/lib/httpsrr.c index f0d7ea14..d642a4c9 100644 --- a/vendor/hydra/vendor/curl/lib/httpsrr.c +++ b/vendor/hydra/vendor/curl/lib/httpsrr.c @@ -21,23 +21,17 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifdef USE_HTTPSRR #include "urldata.h" -#include "curl_addrinfo.h" #include "httpsrr.h" #include "connect.h" -#include "sendf.h" +#include "curl_trc.h" #include "strdup.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - -static CURLcode httpsrr_decode_alpn(const char *cp, size_t len, +static CURLcode httpsrr_decode_alpn(const uint8_t *cp, size_t len, unsigned char *alpns) { /* @@ -49,7 +43,7 @@ static CURLcode httpsrr_decode_alpn(const char *cp, size_t len, int idnum = 0; while(len > 0) { - size_t tlen = (size_t) *cp++; + size_t tlen = *cp++; enum alpnid id; len--; if(tlen > len) @@ -84,7 +78,7 @@ CURLcode Curl_httpsrr_set(struct Curl_easy *data, CURL_TRC_DNS(data, "HTTPS RR MANDATORY left to implement"); break; case HTTPS_RR_CODE_ALPN: /* str_list */ - result = httpsrr_decode_alpn((const char *)val, vlen, hi->alpns); + result = httpsrr_decode_alpn(val, vlen, hi->alpns); CURL_TRC_DNS(data, "HTTPS RR ALPN: %u %u %u %u", hi->alpns[0], hi->alpns[1], hi->alpns[2], hi->alpns[3]); break; @@ -97,7 +91,7 @@ CURLcode Curl_httpsrr_set(struct Curl_easy *data, case HTTPS_RR_CODE_IPV4: /* addr4 list */ if(!vlen || (vlen & 3)) /* the size must be 4-byte aligned */ return CURLE_BAD_FUNCTION_ARGUMENT; - free(hi->ipv4hints); + curlx_free(hi->ipv4hints); hi->ipv4hints = Curl_memdup(val, vlen); if(!hi->ipv4hints) return CURLE_OUT_OF_MEMORY; @@ -107,7 +101,7 @@ CURLcode Curl_httpsrr_set(struct Curl_easy *data, case HTTPS_RR_CODE_ECH: if(!vlen) return CURLE_BAD_FUNCTION_ARGUMENT; - free(hi->echconfiglist); + curlx_free(hi->echconfiglist); hi->echconfiglist = Curl_memdup(val, vlen); if(!hi->echconfiglist) return CURLE_OUT_OF_MEMORY; @@ -117,7 +111,7 @@ CURLcode Curl_httpsrr_set(struct Curl_easy *data, case HTTPS_RR_CODE_IPV6: /* addr6 list */ if(!vlen || (vlen & 15)) /* the size must be 16-byte aligned */ return CURLE_BAD_FUNCTION_ARGUMENT; - free(hi->ipv6hints); + curlx_free(hi->ipv6hints); hi->ipv6hints = Curl_memdup(val, vlen); if(!hi->ipv6hints) return CURLE_OUT_OF_MEMORY; @@ -155,7 +149,6 @@ void Curl_httpsrr_cleanup(struct Curl_https_rrinfo *rrinfo) Curl_safefree(rrinfo->rrname); } - #ifdef USE_ARES static CURLcode httpsrr_opt(struct Curl_easy *data, @@ -167,7 +160,7 @@ static CURLcode httpsrr_opt(struct Curl_easy *data, unsigned short code; size_t len = 0; - code = ares_dns_rr_get_opt(rr, key, idx, &val, &len); + code = ares_dns_rr_get_opt(rr, key, idx, &val, &len); return Curl_httpsrr_set(data, hinfo, code, val, len); } @@ -189,8 +182,8 @@ CURLcode Curl_httpsrr_from_ares(struct Curl_easy *data, is in ServiceMode */ target = ares_dns_rr_get_str(rr, ARES_RR_HTTPS_TARGET); if(target && target[0]) { - free(hinfo->target); - hinfo->target = strdup(target); + curlx_free(hinfo->target); + hinfo->target = curlx_strdup(target); if(!hinfo->target) { result = CURLE_OUT_OF_MEMORY; goto out; diff --git a/vendor/hydra/vendor/curl/lib/httpsrr.h b/vendor/hydra/vendor/curl/lib/httpsrr.h index 9b7831f7..8fe7c0c8 100644 --- a/vendor/hydra/vendor/curl/lib/httpsrr.h +++ b/vendor/hydra/vendor/curl/lib/httpsrr.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifdef USE_ARES @@ -33,7 +32,7 @@ #ifdef USE_HTTPSRR #define CURL_MAXLEN_host_name 253 -#define MAX_HTTPSRR_ALPNS 4 +#define MAX_HTTPSRR_ALPNS 4 struct Curl_easy; diff --git a/vendor/hydra/vendor/curl/lib/idn.c b/vendor/hydra/vendor/curl/lib/idn.c index 7e324db6..f055882e 100644 --- a/vendor/hydra/vendor/curl/lib/idn.c +++ b/vendor/hydra/vendor/curl/lib/idn.c @@ -21,17 +21,13 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - - /* - * IDN conversions - */ - +/* + * IDN conversions + */ #include "curl_setup.h" + #include "urldata.h" #include "idn.h" -#include "sendf.h" -#include "curlx/multibyte.h" -#include "curlx/warnless.h" #ifdef USE_LIBIDN2 #include @@ -43,11 +39,7 @@ #define IDN2_LOOKUP(name, host, flags) \ idn2_lookup_ul((const char *)name, (char **)host, flags) #endif -#endif /* USE_LIBIDN2 */ - -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" +#endif /* USE_LIBIDN2 */ /* for macOS and iOS targets */ #ifdef USE_APPLE_IDN @@ -92,23 +84,23 @@ static CURLcode mac_idn_to_ascii(const char *in, char **out) { size_t inlen = strlen(in); if(inlen < MAX_HOST_LENGTH) { - char iconv_buffer[MAX_HOST_LENGTH] = {0}; + char iconv_buffer[MAX_HOST_LENGTH] = { 0 }; char *iconv_outptr = iconv_buffer; size_t iconv_outlen = sizeof(iconv_buffer); CURLcode iconv_result = iconv_to_utf8(in, inlen, &iconv_outptr, &iconv_outlen); if(!iconv_result) { UErrorCode err = U_ZERO_ERROR; - UIDNA* idna = uidna_openUTS46( - UIDNA_CHECK_BIDI|UIDNA_NONTRANSITIONAL_TO_ASCII, &err); + UIDNA *idna = uidna_openUTS46( + UIDNA_CHECK_BIDI | UIDNA_NONTRANSITIONAL_TO_ASCII, &err); if(!U_FAILURE(err)) { UIDNAInfo info = UIDNA_INFO_INITIALIZER; - char buffer[MAX_HOST_LENGTH] = {0}; + char buffer[MAX_HOST_LENGTH] = { 0 }; (void)uidna_nameToASCII_UTF8(idna, iconv_buffer, (int)iconv_outlen, buffer, sizeof(buffer) - 1, &info, &err); uidna_close(idna); if(!U_FAILURE(err) && !info.errors) { - *out = strdup(buffer); + *out = curlx_strdup(buffer); if(*out) return CURLE_OK; else @@ -127,16 +119,16 @@ static CURLcode mac_ascii_to_idn(const char *in, char **out) size_t inlen = strlen(in); if(inlen < MAX_HOST_LENGTH) { UErrorCode err = U_ZERO_ERROR; - UIDNA* idna = uidna_openUTS46( - UIDNA_CHECK_BIDI|UIDNA_NONTRANSITIONAL_TO_UNICODE, &err); + UIDNA *idna = uidna_openUTS46( + UIDNA_CHECK_BIDI | UIDNA_NONTRANSITIONAL_TO_UNICODE, &err); if(!U_FAILURE(err)) { UIDNAInfo info = UIDNA_INFO_INITIALIZER; - char buffer[MAX_HOST_LENGTH] = {0}; + char buffer[MAX_HOST_LENGTH] = { 0 }; (void)uidna_nameToUnicodeUTF8(idna, in, -1, buffer, sizeof(buffer) - 1, &info, &err); uidna_close(idna); if(!U_FAILURE(err)) { - *out = strdup(buffer); + *out = curlx_strdup(buffer); if(*out) return CURLE_OK; else @@ -167,24 +159,39 @@ WINBASEAPI int WINAPI IdnToUnicode(DWORD dwFlags, #define IDN_MAX_LENGTH 255 +static char *idn_curlx_convert_wchar_to_UTF8(const wchar_t *str_w, int chars) +{ + char *str_utf8 = NULL; + int bytes = WideCharToMultiByte(CP_UTF8, 0, str_w, chars, NULL, 0, + NULL, NULL); + if(bytes > 0) { + str_utf8 = curlx_malloc(bytes); + if(str_utf8) { + if(WideCharToMultiByte(CP_UTF8, 0, str_w, chars, str_utf8, bytes, + NULL, NULL) == 0) { + curlx_free(str_utf8); + return NULL; + } + } + } + return str_utf8; +} + static CURLcode win32_idn_to_ascii(const char *in, char **out) { - wchar_t *in_w = curlx_convert_UTF8_to_wchar(in); + wchar_t in_w[IDN_MAX_LENGTH]; + int in_w_len; *out = NULL; - if(in_w) { + /* Returned in_w_len includes the null-terminator, which then gets + preserved across the calls that follow, ending up terminating + the buffer returned to the caller. */ + in_w_len = MultiByteToWideChar(CP_UTF8, 0, in, -1, in_w, IDN_MAX_LENGTH); + if(in_w_len) { wchar_t punycode[IDN_MAX_LENGTH]; - int chars = IdnToAscii(0, in_w, (int)(wcslen(in_w) + 1), punycode, - IDN_MAX_LENGTH); - curlx_unicodefree(in_w); - if(chars) { - char *mstr = curlx_convert_wchar_to_UTF8(punycode); - if(mstr) { - *out = strdup(mstr); - curlx_unicodefree(mstr); - if(!*out) - return CURLE_OUT_OF_MEMORY; - } - else + int chars = IdnToAscii(0, in_w, in_w_len, punycode, IDN_MAX_LENGTH); + if(chars > 0) { + *out = idn_curlx_convert_wchar_to_UTF8(punycode, chars); + if(!*out) return CURLE_OUT_OF_MEMORY; } else @@ -196,31 +203,29 @@ static CURLcode win32_idn_to_ascii(const char *in, char **out) return CURLE_OK; } -static CURLcode win32_ascii_to_idn(const char *in, char **output) +static CURLcode win32_ascii_to_idn(const char *in, char **out) { - char *out = NULL; - - wchar_t *in_w = curlx_convert_UTF8_to_wchar(in); - if(in_w) { + wchar_t in_w[IDN_MAX_LENGTH]; + int in_w_len; + *out = NULL; + /* Returned in_w_len includes the null-terminator, which then gets + preserved across the calls that follow, ending up terminating + the buffer returned to the caller. */ + in_w_len = MultiByteToWideChar(CP_UTF8, 0, in, -1, in_w, IDN_MAX_LENGTH); + if(in_w_len) { WCHAR idn[IDN_MAX_LENGTH]; /* stores a UTF-16 string */ - int chars = IdnToUnicode(0, in_w, (int)(wcslen(in_w) + 1), idn, - IDN_MAX_LENGTH); - if(chars) { - /* 'chars' is "the number of characters retrieved" */ - char *mstr = curlx_convert_wchar_to_UTF8(idn); - if(mstr) { - out = strdup(mstr); - curlx_unicodefree(mstr); - if(!out) - return CURLE_OUT_OF_MEMORY; - } + int chars = IdnToUnicode(0, in_w, in_w_len, idn, IDN_MAX_LENGTH); + if(chars > 0) { /* 'chars' is "the number of characters retrieved" */ + *out = idn_curlx_convert_wchar_to_UTF8(idn, chars); + if(!*out) + return CURLE_OUT_OF_MEMORY; } else return CURLE_URL_MALFORMAT; } else return CURLE_URL_MALFORMAT; - *output = out; + return CURLE_OK; } @@ -314,7 +319,7 @@ CURLcode Curl_idn_decode(const char *input, char **output) CURLcode result = idn_decode(input, &d); #ifdef USE_LIBIDN2 if(!result) { - char *c = strdup(d); + char *c = curlx_strdup(d); idn2_free(d); if(c) d = c; @@ -325,7 +330,7 @@ CURLcode Curl_idn_decode(const char *input, char **output) if(!result) { if(!d[0]) { /* ended up zero length, not acceptable */ result = CURLE_URL_MALFORMAT; - free(d); + curlx_free(d); } else *output = d; @@ -339,7 +344,7 @@ CURLcode Curl_idn_encode(const char *puny, char **output) CURLcode result = idn_encode(puny, &d); #ifdef USE_LIBIDN2 if(!result) { - char *c = strdup(d); + char *c = curlx_strdup(d); idn2_free(d); if(c) d = c; diff --git a/vendor/hydra/vendor/curl/lib/idn.h b/vendor/hydra/vendor/curl/lib/idn.h index 2bdce892..42613af5 100644 --- a/vendor/hydra/vendor/curl/lib/idn.h +++ b/vendor/hydra/vendor/curl/lib/idn.h @@ -23,17 +23,17 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - bool Curl_is_ASCII_name(const char *hostname); CURLcode Curl_idnconvert_hostname(struct hostname *host); + #if defined(USE_LIBIDN2) || defined(USE_WIN32_IDN) || defined(USE_APPLE_IDN) #define USE_IDN void Curl_free_idnconverted_hostname(struct hostname *host); CURLcode Curl_idn_decode(const char *input, char **output); CURLcode Curl_idn_encode(const char *input, char **output); - #else #define Curl_free_idnconverted_hostname(x) #define Curl_idn_decode(x) NULL #endif + #endif /* HEADER_CURL_IDN_H */ diff --git a/vendor/hydra/vendor/curl/lib/if2ip.c b/vendor/hydra/vendor/curl/lib/if2ip.c index 79b05991..d940c871 100644 --- a/vendor/hydra/vendor/curl/lib/if2ip.c +++ b/vendor/hydra/vendor/curl/lib/if2ip.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifdef HAVE_NETINET_IN_H @@ -55,10 +54,6 @@ #include "curlx/inet_ntop.h" #include "if2ip.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* ------------------------------------------------------------------ */ #ifdef USE_IPV6 @@ -66,10 +61,10 @@ unsigned int Curl_ipv6_scope(const struct sockaddr *sa) { if(sa->sa_family == AF_INET6) { - const struct sockaddr_in6 * sa6 = - (const struct sockaddr_in6 *)(const void *) sa; + const struct sockaddr_in6 *sa6 = + (const struct sockaddr_in6 *)(const void *)sa; const unsigned char *b = sa6->sin6_addr.s6_addr; - unsigned short w = (unsigned short) ((b[0] << 8) | b[1]); + unsigned short w = (unsigned short)((b[0] << 8) | b[1]); if((b[0] & 0xFE) == 0xFC) /* Handle ULAs */ return IPV6_SCOPE_UNIQUELOCAL; @@ -107,8 +102,7 @@ if2ip_result_t Curl_if2ip(int af, struct ifaddrs *iface, *head; if2ip_result_t res = IF2IP_NOT_FOUND; -#if defined(USE_IPV6) && \ - !defined(HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID) +#if defined(USE_IPV6) && !defined(HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID) (void)local_scope_id; #endif @@ -142,7 +136,7 @@ if2ip_result_t Curl_if2ip(int af, #ifdef HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID /* Include the scope of this interface as part of the address */ scopeid = ((struct sockaddr_in6 *)(void *)iface->ifa_addr) - ->sin6_scope_id; + ->sin6_scope_id; /* If given, scope id should match. */ if(local_scope_id && scopeid != local_scope_id) { @@ -252,15 +246,15 @@ if2ip_result_t Curl_if2ip(int af, const char *interf, char *buf, size_t buf_size) { - (void)af; + (void)af; #ifdef USE_IPV6 - (void)remote_scope; - (void)local_scope_id; + (void)remote_scope; + (void)local_scope_id; #endif - (void)interf; - (void)buf; - (void)buf_size; - return IF2IP_NOT_FOUND; + (void)interf; + (void)buf; + (void)buf_size; + return IF2IP_NOT_FOUND; } #endif diff --git a/vendor/hydra/vendor/curl/lib/if2ip.h b/vendor/hydra/vendor/curl/lib/if2ip.h index b33e41ae..12fdaabd 100644 --- a/vendor/hydra/vendor/curl/lib/if2ip.h +++ b/vendor/hydra/vendor/curl/lib/if2ip.h @@ -56,33 +56,33 @@ if2ip_result_t Curl_if2ip(int af, /* Nedelcho Stanev's work-around for SFU 3.0 */ struct ifreq { -#define IFNAMSIZ 16 +#define IFNAMSIZ 16 #define IFHWADDRLEN 6 union { char ifrn_name[IFNAMSIZ]; /* if name, e.g. "en0" */ } ifr_ifrn; - union { - struct sockaddr ifru_addr; - struct sockaddr ifru_broadaddr; - struct sockaddr ifru_netmask; - struct sockaddr ifru_hwaddr; - short ifru_flags; - int ifru_metric; - int ifru_mtu; - } ifr_ifru; + union { + struct sockaddr ifru_addr; + struct sockaddr ifru_broadaddr; + struct sockaddr ifru_netmask; + struct sockaddr ifru_hwaddr; + short ifru_flags; + int ifru_metric; + int ifru_mtu; + } ifr_ifru; }; /* This define exists to avoid an extra #ifdef INTERIX in the C code. */ -#define ifr_name ifr_ifrn.ifrn_name /* interface name */ -#define ifr_addr ifr_ifru.ifru_addr /* address */ +#define ifr_name ifr_ifrn.ifrn_name /* interface name */ +#define ifr_addr ifr_ifru.ifru_addr /* address */ #define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */ -#define ifr_netmask ifr_ifru.ifru_netmask /* interface net mask */ -#define ifr_flags ifr_ifru.ifru_flags /* flags */ -#define ifr_hwaddr ifr_ifru.ifru_hwaddr /* MAC address */ -#define ifr_metric ifr_ifru.ifru_metric /* metric */ -#define ifr_mtu ifr_ifru.ifru_mtu /* mtu */ +#define ifr_netmask ifr_ifru.ifru_netmask /* interface net mask */ +#define ifr_flags ifr_ifru.ifru_flags /* flags */ +#define ifr_hwaddr ifr_ifru.ifru_hwaddr /* MAC address */ +#define ifr_metric ifr_ifru.ifru_metric /* metric */ +#define ifr_mtu ifr_ifru.ifru_mtu /* mtu */ #define SIOCGIFADDR _IOW('s', 102, struct ifreq) /* Get if addr */ diff --git a/vendor/hydra/vendor/curl/lib/imap.c b/vendor/hydra/vendor/curl/lib/imap.c index d23076a4..0af18780 100644 --- a/vendor/hydra/vendor/curl/lib/imap.c +++ b/vendor/hydra/vendor/curl/lib/imap.c @@ -34,9 +34,7 @@ * Draft LOGIN SASL Mechanism * ***************************************************************************/ - #include "curl_setup.h" -#include "curlx/dynbuf.h" #ifndef CURL_DISABLE_IMAP @@ -54,15 +52,15 @@ #include #endif -#include +#include "curlx/dynbuf.h" #include "urldata.h" #include "sendf.h" +#include "curl_trc.h" #include "hostip.h" #include "progress.h" #include "transfer.h" #include "escape.h" -#include "http.h" /* for HTTP proxy tunnel stuff */ -#include "socks.h" +#include "pingpong.h" #include "imap.h" #include "mime.h" #include "curlx/strparse.h" @@ -71,17 +69,10 @@ #include "cfilters.h" #include "connect.h" #include "select.h" -#include "multiif.h" #include "url.h" #include "bufref.h" #include "curl_sasl.h" -#include "curlx/warnless.h" -#include "curl_ctype.h" - -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - +#include "curlx/strcopy.h" /* meta key for storing protocol meta at easy handle */ #define CURL_META_IMAP_EASY "meta:proto:imap:easy" @@ -146,7 +137,6 @@ struct IMAP { BIT(uidvalidity_set); }; - /* Local API functions */ static CURLcode imap_regular_transfer(struct Curl_easy *data, struct IMAP *imap, @@ -210,9 +200,9 @@ const struct Curl_handler Curl_handler_imap = { PORT_IMAP, /* defport */ CURLPROTO_IMAP, /* protocol */ CURLPROTO_IMAP, /* family */ - PROTOPT_CLOSEACTION| /* flags */ - PROTOPT_URLOPTIONS| - PROTOPT_SSL_REUSE + PROTOPT_CLOSEACTION | /* flags */ + PROTOPT_URLOPTIONS | PROTOPT_SSL_REUSE | + PROTOPT_CONN_REUSE }; #ifdef USE_SSL @@ -243,7 +233,7 @@ const struct Curl_handler Curl_handler_imaps = { CURLPROTO_IMAPS, /* protocol */ CURLPROTO_IMAP, /* family */ PROTOPT_CLOSEACTION | PROTOPT_SSL | /* flags */ - PROTOPT_URLOPTIONS + PROTOPT_URLOPTIONS | PROTOPT_CONN_REUSE }; #endif @@ -351,46 +341,46 @@ static bool imap_endofresp(struct Curl_easy *data, struct connectdata *conn, /* Do we have an untagged command response? */ if(len >= 2 && !memcmp("* ", line, 2)) { switch(imapc->state) { - /* States which are interested in untagged responses */ - case IMAP_CAPABILITY: - if(!imap_matchresp(line, len, "CAPABILITY")) - return FALSE; - break; - - case IMAP_LIST: - if((!imap->custom && !imap_matchresp(line, len, "LIST")) || - (imap->custom && !imap_matchresp(line, len, imap->custom) && - (!curl_strequal(imap->custom, "STORE") || - !imap_matchresp(line, len, "FETCH")) && - !curl_strequal(imap->custom, "SELECT") && - !curl_strequal(imap->custom, "EXAMINE") && - !curl_strequal(imap->custom, "SEARCH") && - !curl_strequal(imap->custom, "EXPUNGE") && - !curl_strequal(imap->custom, "LSUB") && - !curl_strequal(imap->custom, "UID") && - !curl_strequal(imap->custom, "GETQUOTAROOT") && - !curl_strequal(imap->custom, "NOOP"))) - return FALSE; - break; + /* States which are interested in untagged responses */ + case IMAP_CAPABILITY: + if(!imap_matchresp(line, len, "CAPABILITY")) + return FALSE; + break; - case IMAP_SELECT: - /* SELECT is special in that its untagged responses do not have a - common prefix so accept anything! */ - break; + case IMAP_LIST: + if((!imap->custom && !imap_matchresp(line, len, "LIST")) || + (imap->custom && !imap_matchresp(line, len, imap->custom) && + (!curl_strequal(imap->custom, "STORE") || + !imap_matchresp(line, len, "FETCH")) && + !curl_strequal(imap->custom, "SELECT") && + !curl_strequal(imap->custom, "EXAMINE") && + !curl_strequal(imap->custom, "SEARCH") && + !curl_strequal(imap->custom, "EXPUNGE") && + !curl_strequal(imap->custom, "LSUB") && + !curl_strequal(imap->custom, "UID") && + !curl_strequal(imap->custom, "GETQUOTAROOT") && + !curl_strequal(imap->custom, "NOOP"))) + return FALSE; + break; - case IMAP_FETCH: - if(!imap_matchresp(line, len, "FETCH")) - return FALSE; - break; + case IMAP_SELECT: + /* SELECT is special in that its untagged responses do not have a + common prefix so accept anything! */ + break; - case IMAP_SEARCH: - if(!imap_matchresp(line, len, "SEARCH")) - return FALSE; - break; + case IMAP_FETCH: + if(!imap_matchresp(line, len, "FETCH")) + return FALSE; + break; - /* Ignore other untagged responses */ - default: + case IMAP_SEARCH: + if(!imap_matchresp(line, len, "SEARCH")) return FALSE; + break; + + /* Ignore other untagged responses */ + default: + return FALSE; } *resp = '*'; @@ -404,16 +394,16 @@ static bool imap_endofresp(struct Curl_easy *data, struct connectdata *conn, if(!imap->custom && ((len == 3 && line[0] == '+') || (len >= 2 && !memcmp("+ ", line, 2)))) { switch(imapc->state) { - /* States which are interested in continuation responses */ - case IMAP_AUTHENTICATE: - case IMAP_APPEND: - *resp = '+'; - break; + /* States which are interested in continuation responses */ + case IMAP_AUTHENTICATE: + case IMAP_APPEND: + *resp = '+'; + break; - default: - failf(data, "Unexpected continuation response"); - *resp = -1; - break; + default: + failf(data, "Unexpected continuation response"); + *resp = -1; + break; } return TRUE; @@ -475,7 +465,7 @@ static void imap_state(struct Curl_easy *data, { #if defined(DEBUGBUILD) && !defined(CURL_DISABLE_VERBOSE_STRINGS) /* for debug purposes */ - static const char * const names[]={ + static const char * const names[] = { "STOP", "SERVERGREET", "CAPABILITY", @@ -574,8 +564,8 @@ static CURLcode imap_perform_upgrade_tls(struct Curl_easy *data, result, ssldone)); if(!result && ssldone) { imapc->ssldone = ssldone; - /* perform CAPA now, changes imapc->state out of IMAP_UPGRADETLS */ - result = imap_perform_capability(data, imapc); + /* perform CAPA now, changes imapc->state out of IMAP_UPGRADETLS */ + result = imap_perform_capability(data, imapc); } out: return result; @@ -617,8 +607,8 @@ static CURLcode imap_perform_login(struct Curl_easy *data, result = imap_sendf(data, imapc, "LOGIN %s %s", user ? user : "", passwd ? passwd : ""); - free(user); - free(passwd); + curlx_free(user); + curlx_free(passwd); if(!result) imap_state(data, imapc, IMAP_LOGIN); @@ -640,7 +630,7 @@ static CURLcode imap_perform_authenticate(struct Curl_easy *data, struct imap_conn *imapc = Curl_conn_meta_get(data->conn, CURL_META_IMAP_CONN); CURLcode result = CURLE_OK; - const char *ir = (const char *) Curl_bufref_ptr(initresp); + const char *ir = Curl_bufref_ptr(initresp); if(!imapc) return CURLE_FAILED_INIT; @@ -672,8 +662,7 @@ static CURLcode imap_continue_authenticate(struct Curl_easy *data, (void)mech; if(!imapc) return CURLE_FAILED_INIT; - return Curl_pp_sendf(data, &imapc->pp, - "%s", (const char *) Curl_bufref_ptr(resp)); + return Curl_pp_sendf(data, &imapc->pp, "%s", Curl_bufref_ptr(resp)); } /*********************************************************************** @@ -751,14 +740,14 @@ static CURLcode imap_perform_list(struct Curl_easy *data, else { /* Make sure the mailbox is in the correct atom format if necessary */ char *mailbox = imap->mailbox ? imap_atom(imap->mailbox, TRUE) - : strdup(""); + : curlx_strdup(""); if(!mailbox) return CURLE_OUT_OF_MEMORY; /* Send the LIST command */ result = imap_sendf(data, imapc, "LIST \"%s\" *", mailbox); - free(mailbox); + curlx_free(mailbox); } if(!result) @@ -797,7 +786,7 @@ static CURLcode imap_perform_select(struct Curl_easy *data, /* Send the SELECT command */ result = imap_sendf(data, imapc, "SELECT %s", mailbox); - free(mailbox); + curlx_free(mailbox); if(!result) imap_state(data, imapc, IMAP_SELECT); @@ -947,7 +936,7 @@ static CURLcode imap_perform_append(struct Curl_easy *data, cleanup: curlx_dyn_free(&flags); - free(mailbox); + curlx_free(mailbox); if(!result) imap_state(data, imapc, IMAP_APPEND); @@ -1052,8 +1041,8 @@ static CURLcode imap_state_capability_resp(struct Curl_easy *data, /* Extract the word */ for(wordlen = 0; line[wordlen] && line[wordlen] != ' ' && - line[wordlen] != '\t' && line[wordlen] != '\r' && - line[wordlen] != '\n';) + line[wordlen] != '\t' && line[wordlen] != '\r' && + line[wordlen] != '\n';) wordlen++; /* Does the server support the STARTTLS capability? */ @@ -1218,8 +1207,6 @@ static CURLcode imap_state_listsearch_resp(struct Curl_easy *data, /* This is a literal response, setup to receive the body data */ infof(data, "Found %" FMT_OFF_T " bytes to download", size); - /* Progress size includes both header line and literal body */ - Curl_pgrsSetDownloadSize(data, size + len); /* First write the header line */ result = Curl_client_write(data, CLIENTWRITE_BODY, line, len); @@ -1272,6 +1259,9 @@ static CURLcode imap_state_listsearch_resp(struct Curl_easy *data, else size += len; + /* Progress size includes both header line and literal body */ + Curl_pgrsSetDownloadSize(data, size); + if(data->req.bytecount == size) /* All data already transferred (header + literal body) */ Curl_xfer_setup_nop(data); @@ -1312,20 +1302,19 @@ static CURLcode imap_state_select_resp(struct Curl_easy *data, imapstate instate) { CURLcode result = CURLE_OK; - const char *line = curlx_dyn_ptr(&imapc->pp.recvbuf); - (void)instate; if(imapcode == '*') { /* See if this is an UIDVALIDITY response */ - if(checkprefix("OK [UIDVALIDITY ", line + 2)) { + const char *line = curlx_dyn_ptr(&imapc->pp.recvbuf); + size_t len = curlx_dyn_len(&imapc->pp.recvbuf); + if((len >= 18) && checkprefix("OK [UIDVALIDITY ", &line[2])) { curl_off_t value; const char *p = &line[2] + strlen("OK [UIDVALIDITY "); if(!curlx_str_number(&p, &value, UINT_MAX)) { imapc->mb_uidvalidity = (unsigned int)value; imapc->mb_uidvalidity_set = TRUE; } - } } else if(imapcode == IMAP_RESP_OK) { @@ -1338,7 +1327,7 @@ static CURLcode imap_state_select_resp(struct Curl_easy *data, else { /* Note the currently opened mailbox on this connection */ DEBUGASSERT(!imapc->mailbox); - imapc->mailbox = strdup(imap->mailbox); + imapc->mailbox = curlx_strdup(imap->mailbox); if(!imapc->mailbox) return CURLE_OUT_OF_MEMORY; @@ -1680,9 +1669,6 @@ static CURLcode imap_connect(struct Curl_easy *data, bool *done) if(!imapc) return CURLE_FAILED_INIT; - /* We always support persistent connections in IMAP */ - connkeep(data->conn, "IMAP default"); - /* Parse the URL options */ result = imap_parse_url_options(data->conn, imapc); if(result) @@ -1692,7 +1678,7 @@ static CURLcode imap_connect(struct Curl_easy *data, bool *done) imap_state(data, imapc, IMAP_SERVERGREET); /* Start off with an response id of '*' */ - strcpy(imapc->resptag, "*"); + curlx_strcopy(imapc->resptag, sizeof(imapc->resptag), "*", 1); result = imap_multi_statemach(data, done); @@ -1803,7 +1789,7 @@ static CURLcode imap_perform(struct Curl_easy *data, bool *connected, /* SEARCH the current mailbox */ result = imap_perform_search(data, imapc, imap); else if(imap->mailbox && !selected && - (imap->custom || imap->uid || imap->mindex || imap->query)) + (imap->custom || imap->uid || imap->mindex || imap->query)) /* SELECT the mailbox */ result = imap_perform_select(data, imapc, imap); else @@ -1938,10 +1924,7 @@ static CURLcode imap_regular_transfer(struct Curl_easy *data, data->req.size = -1; /* Set the progress data */ - Curl_pgrsSetUploadCounter(data, 0); - Curl_pgrsSetDownloadCounter(data, 0); - Curl_pgrsSetUploadSize(data, -1); - Curl_pgrsSetDownloadSize(data, -1); + Curl_pgrsReset(data); /* Carry out the perform */ result = imap_perform(data, &connected, dophase_done); @@ -1973,7 +1956,7 @@ static void imap_easy_dtor(void *key, size_t klen, void *entry) (void)key; (void)klen; imap_easy_reset(imap); - free(imap); + curlx_free(imap); } static void imap_conn_dtor(void *key, size_t klen, void *entry) @@ -1984,7 +1967,7 @@ static void imap_conn_dtor(void *key, size_t klen, void *entry) Curl_pp_disconnect(&imapc->pp); curlx_dyn_free(&imapc->dyn); Curl_safefree(imapc->mailbox); - free(imapc); + curlx_free(imapc); } static CURLcode imap_setup_connection(struct Curl_easy *data, @@ -1994,7 +1977,7 @@ static CURLcode imap_setup_connection(struct Curl_easy *data, struct pingpong *pp; struct IMAP *imap; - imapc = calloc(1, sizeof(*imapc)); + imapc = curlx_calloc(1, sizeof(*imapc)); if(!imapc) return CURLE_OUT_OF_MEMORY; @@ -2006,12 +1989,12 @@ static CURLcode imap_setup_connection(struct Curl_easy *data, Curl_sasl_init(&imapc->sasl, data, &saslimap); curlx_dyn_init(&imapc->dyn, DYN_IMAP_CMD); - Curl_pp_init(pp); + Curl_pp_init(pp, Curl_pgrs_now(data)); if(Curl_conn_meta_set(conn, CURL_META_IMAP_CONN, imapc, imap_conn_dtor)) return CURLE_OUT_OF_MEMORY; - imap = calloc(1, sizeof(struct IMAP)); + imap = curlx_calloc(1, sizeof(struct IMAP)); if(!imap || Curl_meta_set(data, CURL_META_IMAP_EASY, imap, imap_easy_dtor)) return CURLE_OUT_OF_MEMORY; @@ -2084,7 +2067,7 @@ static char *imap_atom(const char *str, bool escape_only) nclean = strcspn(str, "() {%*]\\\""); if(len == nclean) /* nothing to escape, return a strdup */ - return strdup(str); + return curlx_strdup(str); curlx_dyn_init(&line, 2000); @@ -2121,21 +2104,33 @@ static bool imap_is_bchar(char ch) return TRUE; switch(ch) { - /* bchar */ - case ':': case '@': case '/': - /* bchar -> achar */ - case '&': case '=': - /* bchar -> achar -> uchar -> unreserved (without alphanumeric) */ - case '-': case '.': case '_': case '~': - /* bchar -> achar -> uchar -> sub-delims-sh */ - case '!': case '$': case '\'': case '(': case ')': case '*': - case '+': case ',': - /* bchar -> achar -> uchar -> pct-encoded */ - case '%': /* HEXDIG chars are already included above */ - return TRUE; + /* bchar */ + case ':': + case '@': + case '/': + /* bchar -> achar */ + case '&': + case '=': + /* bchar -> achar -> uchar -> unreserved (without alphanumeric) */ + case '-': + case '.': + case '_': + case '~': + /* bchar -> achar -> uchar -> sub-delims-sh */ + case '!': + case '$': + case '\'': + case '(': + case ')': + case '*': + case '+': + case ',': + /* bchar -> achar -> uchar -> pct-encoded */ + case '%': /* HEXDIG chars are already included above */ + return TRUE; - default: - return FALSE; + default: + return FALSE; } } @@ -2264,7 +2259,7 @@ static CURLcode imap_parse_url_path(struct Curl_easy *data, result = Curl_urldecode(begin, ptr - begin, &value, &valuelen, REJECT_CTRL); if(result) { - free(name); + curlx_free(name); return result; } @@ -2285,7 +2280,7 @@ static CURLcode imap_parse_url_path(struct Curl_easy *data, imap->uidvalidity = (unsigned int)num; imap->uidvalidity_set = TRUE; } - free(value); + curlx_free(value); } else if(curl_strequal(name, "UID") && !imap->uid) { imap->uid = value; @@ -2300,23 +2295,25 @@ static CURLcode imap_parse_url_path(struct Curl_easy *data, imap->partial = value; } else { - free(name); - free(value); + curlx_free(name); + curlx_free(value); return CURLE_URL_MALFORMAT; } } else /* blank? */ - free(value); - free(name); + curlx_free(value); + curlx_free(name); } /* Does the URL contain a query parameter? Only valid when we have a mailbox and no UID as per RFC-5092 */ if(imap->mailbox && !imap->uid && !imap->mindex) { /* Get the query parameter, URL decoded */ - (void)curl_url_get(data->state.uh, CURLUPART_QUERY, &imap->query, - CURLU_URLDECODE); + CURLUcode uc = curl_url_get(data->state.uh, CURLUPART_QUERY, &imap->query, + CURLU_URLDECODE); + if(uc == CURLUE_OUT_OF_MEMORY) + return CURLE_OUT_OF_MEMORY; } /* Any extra stuff at the end of the URL is an error */ @@ -2350,7 +2347,7 @@ static CURLcode imap_parse_custom_request(struct Curl_easy *data, params++; if(*params) { - imap->custom_params = strdup(params); + imap->custom_params = curlx_strdup(params); imap->custom[params - imap->custom] = '\0'; if(!imap->custom_params) diff --git a/vendor/hydra/vendor/curl/lib/imap.h b/vendor/hydra/vendor/curl/lib/imap.h index f802ed5c..26306a6a 100644 --- a/vendor/hydra/vendor/curl/lib/imap.h +++ b/vendor/hydra/vendor/curl/lib/imap.h @@ -23,11 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - -#include "pingpong.h" -#include "curl_sasl.h" - - extern const struct Curl_handler Curl_handler_imap; extern const struct Curl_handler Curl_handler_imaps; @@ -37,6 +32,6 @@ extern const struct Curl_handler Curl_handler_imaps; /* Authentication type values */ #define IMAP_TYPE_NONE 0 -#define IMAP_TYPE_ANY (IMAP_TYPE_CLEARTEXT|IMAP_TYPE_SASL) +#define IMAP_TYPE_ANY (IMAP_TYPE_CLEARTEXT | IMAP_TYPE_SASL) #endif /* HEADER_CURL_IMAP_H */ diff --git a/vendor/hydra/vendor/curl/lib/ldap.c b/vendor/hydra/vendor/curl/lib/ldap.c index f0bc2f2a..95a982f3 100644 --- a/vendor/hydra/vendor/curl/lib/ldap.c +++ b/vendor/hydra/vendor/curl/lib/ldap.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #if !defined(CURL_DISABLE_LDAP) && !defined(USE_OPENLDAP) @@ -64,46 +63,38 @@ # pragma warning(pop) # endif # include -# ifndef LDAP_VENDOR_NAME -# error Your Platform SDK is NOT sufficient for LDAP support! \ - Update your Platform SDK, or disable LDAP support! -# else -# include -# endif +# include #else # define LDAP_DEPRECATED 1 /* Be sure ldap_init() is defined. */ # ifdef HAVE_LBER_H # include # endif # include -# if (defined(HAVE_LDAP_SSL) && defined(HAVE_LDAP_SSL_H)) +# if defined(HAVE_LDAP_SSL) && defined(HAVE_LDAP_SSL_H) # include # endif /* HAVE_LDAP_SSL && HAVE_LDAP_SSL_H */ #endif #include "urldata.h" -#include #include "cfilters.h" #include "sendf.h" +#include "curl_trc.h" #include "escape.h" #include "progress.h" #include "transfer.h" #include "curlx/strparse.h" +#include "bufref.h" #include "curl_ldap.h" #include "curlx/multibyte.h" #include "curlx/base64.h" #include "connect.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef USE_WIN32_LDAP -#define FREE_ON_WINLDAP(x) curlx_unicodefree(x) -#define curl_ldap_num_t ULONG +#define FREE_ON_WINLDAP(x) curlx_free(x) +#define curl_ldap_num_t ULONG #else #define FREE_ON_WINLDAP(x) -#define curl_ldap_num_t int +#define curl_ldap_num_t int #endif #ifndef HAVE_LDAP_URL_PARSE @@ -146,14 +137,15 @@ static void ldap_free_urldesc_low(LDAPURLDesc *ludp); #endif /* !HAVE_LDAP_URL_PARSE */ #ifdef DEBUG_LDAP - #define LDAP_TRACE(x) do { \ - ldap_trace_low("%u: ", __LINE__); \ - ldap_trace_low x; \ - } while(0) +#define LDAP_TRACE(x) \ + do { \ + ldap_trace_low("%u: ", __LINE__); \ + ldap_trace_low x; \ + } while(0) - static void ldap_trace_low(const char *fmt, ...) CURL_PRINTF(1, 2); +static void ldap_trace_low(const char *fmt, ...) CURL_PRINTF(1, 2); #else - #define LDAP_TRACE(x) Curl_nop_stmt +#define LDAP_TRACE(x) Curl_nop_stmt #endif #if defined(USE_WIN32_LDAP) && defined(ldap_err2string) @@ -176,7 +168,6 @@ static CURLcode ldap_do(struct Curl_easy *data, bool *done); /* * LDAP protocol handler. */ - const struct Curl_handler Curl_handler_ldap = { "ldap", /* scheme */ ZERO_NULL, /* setup_connection */ @@ -206,7 +197,6 @@ const struct Curl_handler Curl_handler_ldap = { /* * LDAPS protocol handler. */ - const struct Curl_handler Curl_handler_ldaps = { "ldaps", /* scheme */ ZERO_NULL, /* setup_connection */ @@ -300,8 +290,8 @@ static ULONG ldap_win_bind(struct Curl_easy *data, LDAP *server, rc = ldap_simple_bind_s(server, inuser, inpass); - curlx_unicodefree(inuser); - curlx_unicodefree(inpass); + curlx_free(inuser); + curlx_free(inpass); } #ifdef USE_WINDOWS_SSPI else { @@ -343,10 +333,10 @@ static CURLcode ldap_do(struct Curl_easy *data, bool *done) *done = TRUE; /* unconditionally */ infof(data, "LDAP local: LDAP Vendor = %s ; LDAP Version = %d", LDAP_VENDOR_NAME, LDAP_VENDOR_VERSION); - infof(data, "LDAP local: %s", data->state.url); + infof(data, "LDAP local: %s", Curl_bufref_ptr(&data->state.url)); #ifdef HAVE_LDAP_URL_PARSE - rc = ldap_url_parse(data->state.url, &ludp); + rc = ldap_url_parse(Curl_bufref_ptr(&data->state.url), &ludp); #else rc = ldap_url_parse_low(data, conn, &ludp); #endif @@ -382,16 +372,29 @@ static CURLcode ldap_do(struct Curl_easy *data, bool *done) passwd = conn->passwd; } +#ifdef USE_WIN32_LDAP + if(ldap_ssl) + server = ldap_sslinit(host, (curl_ldap_num_t)ipquad.remote_port, 1); + else +#else + server = ldap_init(host, (curl_ldap_num_t)ipquad.remote_port); +#endif + if(!server) { + failf(data, "LDAP: cannot setup connect to %s:%u", + conn->host.dispname, ipquad.remote_port); + result = CURLE_COULDNT_CONNECT; + goto quit; + } + #ifdef LDAP_OPT_NETWORK_TIMEOUT - ldap_set_option(NULL, LDAP_OPT_NETWORK_TIMEOUT, &ldap_timeout); + ldap_set_option(server, LDAP_OPT_NETWORK_TIMEOUT, &ldap_timeout); #endif - ldap_set_option(NULL, LDAP_OPT_PROTOCOL_VERSION, &ldap_proto); + ldap_set_option(server, LDAP_OPT_PROTOCOL_VERSION, &ldap_proto); if(ldap_ssl) { #ifdef HAVE_LDAP_SSL #ifdef USE_WIN32_LDAP /* Win32 LDAP SDK does not support insecure mode without CA! */ - server = ldap_sslinit(host, (curl_ldap_num_t)ipquad.remote_port, 1); ldap_set_option(server, LDAP_OPT_SSL, LDAP_OPT_ON); #else /* !USE_WIN32_LDAP */ int ldap_option; @@ -411,7 +414,7 @@ static CURLcode ldap_do(struct Curl_easy *data, bool *done) goto quit; } infof(data, "LDAP local: using PEM CA cert: %s", ldap_ca); - rc = ldap_set_option(NULL, LDAP_OPT_X_TLS_CACERTFILE, ldap_ca); + rc = ldap_set_option(server, LDAP_OPT_X_TLS_CACERTFILE, ldap_ca); if(rc != LDAP_SUCCESS) { failf(data, "LDAP local: ERROR setting PEM CA cert: %s", ldap_err2string(rc)); @@ -423,20 +426,13 @@ static CURLcode ldap_do(struct Curl_easy *data, bool *done) else ldap_option = LDAP_OPT_X_TLS_NEVER; - rc = ldap_set_option(NULL, LDAP_OPT_X_TLS_REQUIRE_CERT, &ldap_option); + rc = ldap_set_option(server, LDAP_OPT_X_TLS_REQUIRE_CERT, &ldap_option); if(rc != LDAP_SUCCESS) { failf(data, "LDAP local: ERROR setting cert verify mode: %s", ldap_err2string(rc)); result = CURLE_SSL_CERTPROBLEM; goto quit; } - server = ldap_init(host, ipquad.remote_port); - if(!server) { - failf(data, "LDAP local: Cannot connect to %s:%u", - conn->host.dispname, ipquad.remote_port); - result = CURLE_COULDNT_CONNECT; - goto quit; - } ldap_option = LDAP_OPT_X_TLS_HARD; rc = ldap_set_option(server, LDAP_OPT_X_TLS, &ldap_option); if(rc != LDAP_SUCCESS) { @@ -445,16 +441,6 @@ static CURLcode ldap_do(struct Curl_easy *data, bool *done) result = CURLE_SSL_CERTPROBLEM; goto quit; } -#if 0 - rc = ldap_start_tls_s(server, NULL, NULL); - if(rc != LDAP_SUCCESS) { - failf(data, "LDAP local: ERROR starting SSL/TLS mode: %s", - ldap_err2string(rc)); - result = CURLE_SSL_CERTPROBLEM; - goto quit; - } -#endif - #else /* !LDAP_OPT_X_TLS */ (void)ldap_option; (void)ldap_ca; @@ -473,15 +459,7 @@ static CURLcode ldap_do(struct Curl_easy *data, bool *done) result = CURLE_NOT_BUILT_IN; goto quit; } - else { - server = ldap_init(host, (curl_ldap_num_t)ipquad.remote_port); - if(!server) { - failf(data, "LDAP local: Cannot connect to %s:%u", - conn->host.dispname, ipquad.remote_port); - result = CURLE_COULDNT_CONNECT; - goto quit; - } - } + #ifdef USE_WIN32_LDAP ldap_set_option(server, LDAP_OPT_PROTOCOL_VERSION, &ldap_proto); rc = ldap_win_bind(data, server, user, passwd); @@ -509,7 +487,7 @@ static CURLcode ldap_do(struct Curl_easy *data, bool *done) goto quit; } - Curl_pgrsSetDownloadCounter(data, 0); + Curl_pgrsReset(data); rc = ldap_search_s(server, ludp->lud_dn, (curl_ldap_num_t)ludp->lud_scope, ludp->lud_filter, ludp->lud_attrs, 0, &ldapmsg); @@ -623,10 +601,11 @@ static CURLcode ldap_do(struct Curl_easy *data, bool *done) } if((attr_len > 7) && - curl_strequal(";binary", attr + (attr_len - 7)) ) { + curl_strequal(";binary", attr + (attr_len - 7))) { /* Binary attribute, encode to base64. */ if(vals[i]->bv_len) { - result = curlx_base64_encode(vals[i]->bv_val, vals[i]->bv_len, + result = curlx_base64_encode((uint8_t *)vals[i]->bv_val, + vals[i]->bv_len, &val_b64, &val_b64_sz); if(result) { ldap_value_free_len(vals); @@ -641,7 +620,7 @@ static CURLcode ldap_do(struct Curl_easy *data, bool *done) if(val_b64_sz > 0) { result = Curl_client_write(data, CLIENTWRITE_BODY, val_b64, val_b64_sz); - free(val_b64); + curlx_free(val_b64); if(result) { ldap_value_free_len(vals); FREE_ON_WINLDAP(attr); @@ -808,15 +787,15 @@ static curl_ldap_num_t ldap_url_parse2_low(struct Curl_easy *data, ludp->lud_host = conn->host.name; /* Duplicate the path */ - p = path = strdup(data->state.up.path + 1); + p = path = curlx_strdup(data->state.up.path + 1); if(!path) return LDAP_NO_MEMORY; /* Duplicate the query if present */ if(data->state.up.query) { - q = query = strdup(data->state.up.query); + q = query = curlx_strdup(data->state.up.query); if(!query) { - free(path); + curlx_free(path); return LDAP_NO_MEMORY; } } @@ -842,7 +821,7 @@ static curl_ldap_num_t ldap_url_parse2_low(struct Curl_easy *data, ludp->lud_dn = curlx_convert_UTF8_to_tchar(unescaped); /* Free the unescaped string as we are done with it */ - free(unescaped); + curlx_free(unescaped); if(!ludp->lud_dn) { rc = LDAP_NO_MEMORY; @@ -869,9 +848,9 @@ static curl_ldap_num_t ldap_url_parse2_low(struct Curl_easy *data, /* Allocate our array (+1 for the NULL entry) */ #ifdef USE_WIN32_LDAP - ludp->lud_attrs = calloc(count + 1, sizeof(TCHAR *)); + ludp->lud_attrs = curlx_calloc(count + 1, sizeof(TCHAR *)); #else - ludp->lud_attrs = calloc(count + 1, sizeof(char *)); + ludp->lud_attrs = curlx_calloc(count + 1, sizeof(char *)); #endif if(!ludp->lud_attrs) { rc = LDAP_NO_MEMORY; @@ -889,8 +868,7 @@ static curl_ldap_num_t ldap_url_parse2_low(struct Curl_easy *data, LDAP_TRACE(("attr[%zu] '%.*s'\n", i, (int)out.len, out.str)); /* Unescape the attribute */ - result = Curl_urldecode(out.str, out.len, &unescaped, NULL, - REJECT_ZERO); + result = Curl_urldecode(out.str, out.len, &unescaped, NULL, REJECT_ZERO); if(result) { rc = LDAP_NO_MEMORY; goto quit; @@ -901,7 +879,7 @@ static curl_ldap_num_t ldap_url_parse2_low(struct Curl_easy *data, ludp->lud_attrs[i] = curlx_convert_UTF8_to_tchar(unescaped); /* Free the unescaped string as we are done with it */ - free(unescaped); + curlx_free(unescaped); if(!ludp->lud_attrs[i]) { rc = LDAP_NO_MEMORY; @@ -965,7 +943,7 @@ static curl_ldap_num_t ldap_url_parse2_low(struct Curl_easy *data, ludp->lud_filter = curlx_convert_UTF8_to_tchar(unescaped); /* Free the unescaped string as we are done with it */ - free(unescaped); + curlx_free(unescaped); if(!ludp->lud_filter) { rc = LDAP_NO_MEMORY; @@ -985,8 +963,8 @@ static curl_ldap_num_t ldap_url_parse2_low(struct Curl_easy *data, } quit: - free(path); - free(query); + curlx_free(path); + curlx_free(query); return rc; } @@ -995,7 +973,7 @@ static curl_ldap_num_t ldap_url_parse_low(struct Curl_easy *data, const struct connectdata *conn, LDAPURLDesc **ludpp) { - LDAPURLDesc *ludp = calloc(1, sizeof(*ludp)); + LDAPURLDesc *ludp = curlx_calloc(1, sizeof(*ludp)); curl_ldap_num_t rc; *ludpp = NULL; @@ -1016,30 +994,61 @@ static void ldap_free_urldesc_low(LDAPURLDesc *ludp) if(!ludp) return; -#ifdef USE_WIN32_LDAP - curlx_unicodefree(ludp->lud_dn); - curlx_unicodefree(ludp->lud_filter); -#else - free(ludp->lud_dn); - free(ludp->lud_filter); -#endif + curlx_free(ludp->lud_dn); + curlx_free(ludp->lud_filter); if(ludp->lud_attrs) { size_t i; for(i = 0; i < ludp->lud_attrs_dups; i++) { -#ifdef USE_WIN32_LDAP - curlx_unicodefree(ludp->lud_attrs[i]); -#else - free(ludp->lud_attrs[i]); -#endif + curlx_free(ludp->lud_attrs[i]); } - free(ludp->lud_attrs); + curlx_free(ludp->lud_attrs); } - free(ludp); + curlx_free(ludp); } #endif /* !HAVE_LDAP_URL_PARSE */ +void Curl_ldap_version(char *buf, size_t bufsz) +{ +#ifdef USE_WIN32_LDAP + curl_msnprintf(buf, bufsz, "WinLDAP"); +#else +#ifdef LDAP_OPT_X_TLS_PASSPHRASE + static const char *flavor = "/Apple"; +#else + static const char *flavor = ""; +#endif + LDAPAPIInfo api; + api.ldapai_info_version = LDAP_API_INFO_VERSION; + + /* Comparing against 0, as different platforms + disagree on the success define name */ + if(ldap_get_option(NULL, LDAP_OPT_API_INFO, &api) == 0) { + unsigned int patch = (unsigned int)(api.ldapai_vendor_version % 100); + unsigned int major = (unsigned int)(api.ldapai_vendor_version / 10000); + unsigned int minor = + (((unsigned int)api.ldapai_vendor_version - major * 10000) + - patch) / 100; + +#ifdef __OS400__ + curl_msnprintf(buf, bufsz, "IBMLDAP/%u.%u.%u", + major, minor, patch); + + ldap_value_free(api.ldapai_extensions); +#else + curl_msnprintf(buf, bufsz, "%s/%u.%u.%u%s", + api.ldapai_vendor_name, major, minor, patch, flavor); + + ldap_memfree(api.ldapai_vendor_name); + ber_memvfree((void **)api.ldapai_extensions); +#endif + } + else + curl_msnprintf(buf, bufsz, "LDAP/1"); +#endif +} + #if defined(__GNUC__) && defined(__APPLE__) #pragma GCC diagnostic pop #endif diff --git a/vendor/hydra/vendor/curl/lib/llist.c b/vendor/hydra/vendor/curl/lib/llist.c index c9a7d4a8..0e3084b5 100644 --- a/vendor/hydra/vendor/curl/lib/llist.c +++ b/vendor/hydra/vendor/curl/lib/llist.c @@ -21,16 +21,9 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include - #include "llist.h" -#include "curl_memory.h" - -/* this must be the last include file */ -#include "memdebug.h" #ifdef DEBUGBUILD #define LLISTINIT 0x100cc001 /* random pattern */ @@ -49,8 +42,7 @@ static struct Curl_llist_node *verifynode(struct Curl_llist_node *n) /* * @unittest: 1300 */ -void -Curl_llist_init(struct Curl_llist *l, Curl_llist_dtor dtor) +void Curl_llist_init(struct Curl_llist *l, Curl_llist_dtor dtor) { l->_size = 0; l->_dtor = dtor; @@ -72,11 +64,10 @@ Curl_llist_init(struct Curl_llist *l, Curl_llist_dtor dtor) * * @unittest: 1300 */ -void -Curl_llist_insert_next(struct Curl_llist *list, - struct Curl_llist_node *e, /* may be NULL */ - const void *p, - struct Curl_llist_node *ne) +void Curl_llist_insert_next(struct Curl_llist *list, + struct Curl_llist_node *e, /* may be NULL */ + const void *p, + struct Curl_llist_node *ne) { DEBUGASSERT(list); DEBUGASSERT(list->_init == LLISTINIT); @@ -123,9 +114,8 @@ Curl_llist_insert_next(struct Curl_llist *list, * * @unittest: 1300 */ -void -Curl_llist_append(struct Curl_llist *list, const void *p, - struct Curl_llist_node *ne) +void Curl_llist_append(struct Curl_llist *list, const void *p, + struct Curl_llist_node *ne) { DEBUGASSERT(list); DEBUGASSERT(list->_init == LLISTINIT); @@ -181,9 +171,8 @@ void *Curl_node_take_elem(struct Curl_llist_node *e) /* * @unittest: 1300 */ -UNITTEST void Curl_node_uremove(struct Curl_llist_node *, void *); -UNITTEST void -Curl_node_uremove(struct Curl_llist_node *e, void *user) +UNITTEST void Curl_node_uremove(struct Curl_llist_node *e, void *user); +UNITTEST void Curl_node_uremove(struct Curl_llist_node *e, void *user) { struct Curl_llist *list; void *ptr; @@ -204,8 +193,7 @@ void Curl_node_remove(struct Curl_llist_node *e) Curl_node_uremove(e, NULL); } -void -Curl_llist_destroy(struct Curl_llist *list, void *user) +void Curl_llist_destroy(struct Curl_llist *list, void *user) { if(list) { DEBUGASSERT(list->_init == LLISTINIT); diff --git a/vendor/hydra/vendor/curl/lib/llist.h b/vendor/hydra/vendor/curl/lib/llist.h index 0a2bc9a6..1d73db17 100644 --- a/vendor/hydra/vendor/curl/lib/llist.h +++ b/vendor/hydra/vendor/curl/lib/llist.h @@ -23,9 +23,7 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include typedef void (*Curl_llist_dtor)(void *user, void *elem); @@ -55,8 +53,8 @@ struct Curl_llist_node { void Curl_llist_init(struct Curl_llist *, Curl_llist_dtor); void Curl_llist_insert_next(struct Curl_llist *, struct Curl_llist_node *, const void *, struct Curl_llist_node *node); -void Curl_llist_append(struct Curl_llist *, - const void *, struct Curl_llist_node *node); +void Curl_llist_append(struct Curl_llist *, const void *, + struct Curl_llist_node *node); void Curl_node_remove(struct Curl_llist_node *); void Curl_llist_destroy(struct Curl_llist *, void *); diff --git a/vendor/hydra/vendor/curl/lib/macos.c b/vendor/hydra/vendor/curl/lib/macos.c index daf2ab94..334dbc7d 100644 --- a/vendor/hydra/vendor/curl/lib/macos.c +++ b/vendor/hydra/vendor/curl/lib/macos.c @@ -21,13 +21,10 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifdef CURL_MACOS_CALL_COPYPROXIES -#include - #include "macos.h" #include diff --git a/vendor/hydra/vendor/curl/lib/macos.h b/vendor/hydra/vendor/curl/lib/macos.h index 637860e8..0a72a302 100644 --- a/vendor/hydra/vendor/curl/lib/macos.h +++ b/vendor/hydra/vendor/curl/lib/macos.h @@ -23,17 +23,12 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifdef CURL_MACOS_CALL_COPYPROXIES - CURLcode Curl_macos_init(void); - #else - #define Curl_macos_init() CURLE_OK - #endif #endif /* HEADER_CURL_MACOS_H */ diff --git a/vendor/hydra/vendor/curl/lib/md4.c b/vendor/hydra/vendor/curl/lib/md4.c index d86a2462..e7ecf58e 100644 --- a/vendor/hydra/vendor/curl/lib/md4.c +++ b/vendor/hydra/vendor/curl/lib/md4.c @@ -21,15 +21,11 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifdef USE_CURL_NTLM_CORE -#include - #include "curl_md4.h" -#include "curlx/warnless.h" #ifdef USE_OPENSSL #include @@ -71,18 +67,13 @@ #include #endif -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - - #if defined(USE_WOLFSSL) && !defined(WOLFSSL_NO_MD4) #ifdef OPENSSL_COEXIST - #define MD4_CTX WOLFSSL_MD4_CTX - #define MD4_Init wolfSSL_MD4_Init + #define MD4_CTX WOLFSSL_MD4_CTX + #define MD4_Init wolfSSL_MD4_Init #define MD4_Update wolfSSL_MD4_Update - #define MD4_Final wolfSSL_MD4_Final + #define MD4_Final wolfSSL_MD4_Final #endif #elif defined(USE_OPENSSL) && !defined(OPENSSL_NO_MD4) @@ -133,12 +124,7 @@ static int MD4_Init(MD4_CTX *ctx) static void MD4_Update(MD4_CTX *ctx, const void *data, unsigned long size) { -#ifdef __MINGW32CE__ - CryptHashData(ctx->hHash, (BYTE *)CURL_UNCONST(data), - (unsigned int) size, 0); -#else - CryptHashData(ctx->hHash, (const BYTE *)data, (unsigned int) size, 0); -#endif + CryptHashData(ctx->hHash, (const BYTE *)data, (unsigned int)size, 0); } static void MD4_Final(unsigned char *result, MD4_CTX *ctx) @@ -233,8 +219,8 @@ static void MD4_Final(unsigned char *result, MD4_CTX *ctx); * The MD4 transformation for all three rounds. */ #define MD4_STEP(f, a, b, c, d, x, s) \ - (a) += f((b), (c), (d)) + (x); \ - (a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s)))); + (a) += f((b), (c), (d)) + (x); \ + (a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s)))); /* * SET reads 4 input bytes in little-endian byte order and stores them @@ -245,19 +231,15 @@ static void MD4_Final(unsigned char *result, MD4_CTX *ctx); * does not work. */ #if defined(__i386__) || defined(__x86_64__) || defined(__vax__) -#define MD4_SET(n) \ - (*(const MD4_u32plus *)(const void *)&ptr[(n) * 4]) -#define MD4_GET(n) \ - MD4_SET(n) +#define MD4_SET(n) (*(const MD4_u32plus *)(const void *)&ptr[(n) * 4]) +#define MD4_GET(n) MD4_SET(n) #else -#define MD4_SET(n) \ - (ctx->block[(n)] = \ - (MD4_u32plus)ptr[(n) * 4] | \ - ((MD4_u32plus)ptr[(n) * 4 + 1] << 8) | \ - ((MD4_u32plus)ptr[(n) * 4 + 2] << 16) | \ - ((MD4_u32plus)ptr[(n) * 4 + 3] << 24)) -#define MD4_GET(n) \ - (ctx->block[(n)]) +#define MD4_SET(n) (ctx->block[(n)] = \ + (MD4_u32plus)ptr[(n) * 4] | \ + ((MD4_u32plus)ptr[(n) * 4 + 1] << 8) | \ + ((MD4_u32plus)ptr[(n) * 4 + 2] << 16) | \ + ((MD4_u32plus)ptr[(n) * 4 + 3] << 24)) +#define MD4_GET(n) (ctx->block[(n)]) #endif /* @@ -422,32 +404,32 @@ static void MD4_Final(unsigned char *result, MD4_CTX *ctx) memset(&ctx->buffer[used], 0, available - 8); ctx->lo <<= 3; - ctx->buffer[56] = curlx_ultouc((ctx->lo)&0xff); - ctx->buffer[57] = curlx_ultouc((ctx->lo >> 8)&0xff); - ctx->buffer[58] = curlx_ultouc((ctx->lo >> 16)&0xff); - ctx->buffer[59] = curlx_ultouc((ctx->lo >> 24)&0xff); - ctx->buffer[60] = curlx_ultouc((ctx->hi)&0xff); - ctx->buffer[61] = curlx_ultouc((ctx->hi >> 8)&0xff); - ctx->buffer[62] = curlx_ultouc((ctx->hi >> 16)&0xff); + ctx->buffer[56] = curlx_ultouc((ctx->lo) & 0xff); + ctx->buffer[57] = curlx_ultouc((ctx->lo >> 8) & 0xff); + ctx->buffer[58] = curlx_ultouc((ctx->lo >> 16) & 0xff); + ctx->buffer[59] = curlx_ultouc((ctx->lo >> 24) & 0xff); + ctx->buffer[60] = curlx_ultouc((ctx->hi) & 0xff); + ctx->buffer[61] = curlx_ultouc((ctx->hi >> 8) & 0xff); + ctx->buffer[62] = curlx_ultouc((ctx->hi >> 16) & 0xff); ctx->buffer[63] = curlx_ultouc(ctx->hi >> 24); my_md4_body(ctx, ctx->buffer, 64); - result[0] = curlx_ultouc((ctx->a)&0xff); - result[1] = curlx_ultouc((ctx->a >> 8)&0xff); - result[2] = curlx_ultouc((ctx->a >> 16)&0xff); + result[0] = curlx_ultouc((ctx->a) & 0xff); + result[1] = curlx_ultouc((ctx->a >> 8) & 0xff); + result[2] = curlx_ultouc((ctx->a >> 16) & 0xff); result[3] = curlx_ultouc(ctx->a >> 24); - result[4] = curlx_ultouc((ctx->b)&0xff); - result[5] = curlx_ultouc((ctx->b >> 8)&0xff); - result[6] = curlx_ultouc((ctx->b >> 16)&0xff); + result[4] = curlx_ultouc((ctx->b) & 0xff); + result[5] = curlx_ultouc((ctx->b >> 8) & 0xff); + result[6] = curlx_ultouc((ctx->b >> 16) & 0xff); result[7] = curlx_ultouc(ctx->b >> 24); - result[8] = curlx_ultouc((ctx->c)&0xff); - result[9] = curlx_ultouc((ctx->c >> 8)&0xff); - result[10] = curlx_ultouc((ctx->c >> 16)&0xff); + result[8] = curlx_ultouc((ctx->c) & 0xff); + result[9] = curlx_ultouc((ctx->c >> 8) & 0xff); + result[10] = curlx_ultouc((ctx->c >> 16) & 0xff); result[11] = curlx_ultouc(ctx->c >> 24); - result[12] = curlx_ultouc((ctx->d)&0xff); - result[13] = curlx_ultouc((ctx->d >> 8)&0xff); - result[14] = curlx_ultouc((ctx->d >> 16)&0xff); + result[12] = curlx_ultouc((ctx->d) & 0xff); + result[13] = curlx_ultouc((ctx->d >> 8) & 0xff); + result[14] = curlx_ultouc((ctx->d >> 16) & 0xff); result[15] = curlx_ultouc(ctx->d >> 24); memset(ctx, 0, sizeof(*ctx)); diff --git a/vendor/hydra/vendor/curl/lib/md5.c b/vendor/hydra/vendor/curl/lib/md5.c index d99554a4..3e068cc5 100644 --- a/vendor/hydra/vendor/curl/lib/md5.c +++ b/vendor/hydra/vendor/curl/lib/md5.c @@ -21,18 +21,13 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #if (defined(USE_CURL_NTLM_CORE) && !defined(USE_WINDOWS_SSPI)) || \ !defined(CURL_DISABLE_DIGEST_AUTH) -#include -#include - #include "curl_md5.h" #include "curl_hmac.h" -#include "curlx/warnless.h" #ifdef USE_OPENSSL #include @@ -81,10 +76,6 @@ #include #endif -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef USE_GNUTLS typedef struct md5_ctx my_md5_ctx; @@ -240,11 +231,7 @@ static void my_md5_update(void *in, unsigned int inputLen) { my_md5_ctx *ctx = in; -#ifdef __MINGW32CE__ - CryptHashData(ctx->hHash, (BYTE *)CURL_UNCONST(input), inputLen, 0); -#else CryptHashData(ctx->hHash, (const BYTE *)input, inputLen, 0); -#endif } static void my_md5_final(unsigned char *digest, void *in) @@ -322,9 +309,9 @@ static void my_md5_final(unsigned char *result, void *ctx); * The MD5 transformation for all four rounds. */ #define MD5_STEP(f, a, b, c, d, x, t, s) \ - (a) += f((b), (c), (d)) + (x) + (t); \ - (a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s)))); \ - (a) += (b); + (a) += f((b), (c), (d)) + (x) + (t); \ + (a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s)))); \ + (a) += (b); /* * SET reads 4 input bytes in little-endian byte order and stores them @@ -335,19 +322,15 @@ static void my_md5_final(unsigned char *result, void *ctx); * does not work. */ #if defined(__i386__) || defined(__x86_64__) || defined(__vax__) -#define MD5_SET(n) \ - (*(const MD5_u32plus *)(const void *)&ptr[(n) * 4]) -#define MD5_GET(n) \ - MD5_SET(n) +#define MD5_SET(n) (*(const MD5_u32plus *)(const void *)&ptr[(n) * 4]) +#define MD5_GET(n) MD5_SET(n) #else -#define MD5_SET(n) \ - (ctx->block[(n)] = \ - (MD5_u32plus)ptr[(n) * 4] | \ - ((MD5_u32plus)ptr[(n) * 4 + 1] << 8) | \ - ((MD5_u32plus)ptr[(n) * 4 + 2] << 16) | \ - ((MD5_u32plus)ptr[(n) * 4 + 3] << 24)) -#define MD5_GET(n) \ - (ctx->block[(n)]) +#define MD5_SET(n) (ctx->block[(n)] = \ + (MD5_u32plus)ptr[(n) * 4] | \ + ((MD5_u32plus)ptr[(n) * 4 + 1] << 8) | \ + ((MD5_u32plus)ptr[(n) * 4 + 2] << 16) | \ + ((MD5_u32plus)ptr[(n) * 4 + 3] << 24)) +#define MD5_GET(n) (ctx->block[(n)]) #endif /* @@ -535,32 +518,32 @@ static void my_md5_final(unsigned char *result, void *in) memset(&ctx->buffer[used], 0, available - 8); ctx->lo <<= 3; - ctx->buffer[56] = curlx_ultouc((ctx->lo)&0xff); - ctx->buffer[57] = curlx_ultouc((ctx->lo >> 8)&0xff); - ctx->buffer[58] = curlx_ultouc((ctx->lo >> 16)&0xff); + ctx->buffer[56] = curlx_ultouc((ctx->lo) & 0xff); + ctx->buffer[57] = curlx_ultouc((ctx->lo >> 8) & 0xff); + ctx->buffer[58] = curlx_ultouc((ctx->lo >> 16) & 0xff); ctx->buffer[59] = curlx_ultouc(ctx->lo >> 24); - ctx->buffer[60] = curlx_ultouc((ctx->hi)&0xff); - ctx->buffer[61] = curlx_ultouc((ctx->hi >> 8)&0xff); - ctx->buffer[62] = curlx_ultouc((ctx->hi >> 16)&0xff); + ctx->buffer[60] = curlx_ultouc((ctx->hi) & 0xff); + ctx->buffer[61] = curlx_ultouc((ctx->hi >> 8) & 0xff); + ctx->buffer[62] = curlx_ultouc((ctx->hi >> 16) & 0xff); ctx->buffer[63] = curlx_ultouc(ctx->hi >> 24); my_md5_body(ctx, ctx->buffer, 64); - result[0] = curlx_ultouc((ctx->a)&0xff); - result[1] = curlx_ultouc((ctx->a >> 8)&0xff); - result[2] = curlx_ultouc((ctx->a >> 16)&0xff); + result[0] = curlx_ultouc((ctx->a) & 0xff); + result[1] = curlx_ultouc((ctx->a >> 8) & 0xff); + result[2] = curlx_ultouc((ctx->a >> 16) & 0xff); result[3] = curlx_ultouc(ctx->a >> 24); - result[4] = curlx_ultouc((ctx->b)&0xff); - result[5] = curlx_ultouc((ctx->b >> 8)&0xff); - result[6] = curlx_ultouc((ctx->b >> 16)&0xff); + result[4] = curlx_ultouc((ctx->b) & 0xff); + result[5] = curlx_ultouc((ctx->b >> 8) & 0xff); + result[6] = curlx_ultouc((ctx->b >> 16) & 0xff); result[7] = curlx_ultouc(ctx->b >> 24); - result[8] = curlx_ultouc((ctx->c)&0xff); - result[9] = curlx_ultouc((ctx->c >> 8)&0xff); - result[10] = curlx_ultouc((ctx->c >> 16)&0xff); + result[8] = curlx_ultouc((ctx->c) & 0xff); + result[9] = curlx_ultouc((ctx->c >> 8) & 0xff); + result[10] = curlx_ultouc((ctx->c >> 16) & 0xff); result[11] = curlx_ultouc(ctx->c >> 24); - result[12] = curlx_ultouc((ctx->d)&0xff); - result[13] = curlx_ultouc((ctx->d >> 8)&0xff); - result[14] = curlx_ultouc((ctx->d >> 16)&0xff); + result[12] = curlx_ultouc((ctx->d) & 0xff); + result[13] = curlx_ultouc((ctx->d >> 8) & 0xff); + result[14] = curlx_ultouc((ctx->d >> 16) & 0xff); result[15] = curlx_ultouc(ctx->d >> 24); memset(ctx, 0, sizeof(*ctx)); @@ -608,23 +591,23 @@ struct MD5_context *Curl_MD5_init(const struct MD5_params *md5params) struct MD5_context *ctxt; /* Create MD5 context */ - ctxt = malloc(sizeof(*ctxt)); + ctxt = curlx_malloc(sizeof(*ctxt)); if(!ctxt) return ctxt; - ctxt->md5_hashctx = malloc(md5params->md5_ctxtsize); + ctxt->md5_hashctx = curlx_malloc(md5params->md5_ctxtsize); if(!ctxt->md5_hashctx) { - free(ctxt); + curlx_free(ctxt); return NULL; } ctxt->md5_hash = md5params; if((*md5params->md5_init_func)(ctxt->md5_hashctx)) { - free(ctxt->md5_hashctx); - free(ctxt); + curlx_free(ctxt->md5_hashctx); + curlx_free(ctxt); return NULL; } @@ -644,8 +627,8 @@ CURLcode Curl_MD5_final(struct MD5_context *context, unsigned char *result) { (*context->md5_hash->md5_final_func)(result, context->md5_hashctx); - free(context->md5_hashctx); - free(context); + curlx_free(context->md5_hashctx); + curlx_free(context); return CURLE_OK; } diff --git a/vendor/hydra/vendor/curl/lib/memdebug.c b/vendor/hydra/vendor/curl/lib/memdebug.c index 7ded52c1..a99972fd 100644 --- a/vendor/hydra/vendor/curl/lib/memdebug.c +++ b/vendor/hydra/vendor/curl/lib/memdebug.c @@ -21,19 +21,19 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifdef CURLDEBUG -#include +#include /* for offsetof() */ #include "urldata.h" -#include "curlx/fopen.h" /* for CURLX_FOPEN_LOW() */ +#include "curl_threads.h" +#include "curlx/fopen.h" /* for CURLX_FOPEN_LOW(), CURLX_FREOPEN_LOW() */ -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" +#ifdef USE_BACKTRACE +#include "backtrace.h" +#endif struct memdebug { size_t size; @@ -51,13 +51,47 @@ struct memdebug { * For advanced analysis, record a log file and write perl scripts to analyze * them! * - * Do not use these with multithreaded test programs! + * Do not use these with multi-threaded test programs! */ FILE *curl_dbg_logfile = NULL; static bool registered_cleanup = FALSE; /* atexit registered cleanup */ static bool memlimit = FALSE; /* enable memory limit */ static long memsize = 0; /* set number of mallocs allowed */ +#ifdef USE_BACKTRACE +static struct backtrace_state *btstate; +#endif + +static char membuf[10000]; +static size_t memwidx = 0; /* write index */ + +#if defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32) +static bool dbg_mutex_init = 0; +static curl_mutex_t dbg_mutex; +#endif + +static bool curl_dbg_lock(void) +{ +#if defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32) + if(dbg_mutex_init) { + Curl_mutex_acquire(&dbg_mutex); + return TRUE; + } +#endif + return FALSE; +} + +static void curl_dbg_unlock(bool was_locked) +{ +#if defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32) + if(was_locked) + Curl_mutex_release(&dbg_mutex); +#else + (void)was_locked; +#endif +} + +static void curl_dbg_log_locked(const char *format, ...) CURL_PRINTF(1, 2); /* LeakSantizier (LSAN) calls _exit() instead of exit() when a leak is detected on exit so the logfile must be closed explicitly or data could be lost. @@ -68,26 +102,69 @@ static void curl_dbg_cleanup(void) if(curl_dbg_logfile && curl_dbg_logfile != stderr && curl_dbg_logfile != stdout) { + if(memwidx) + fwrite(membuf, 1, memwidx, curl_dbg_logfile); /* !checksrc! disable BANNEDFUNC 1 */ fclose(curl_dbg_logfile); } curl_dbg_logfile = NULL; +#if defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32) + if(dbg_mutex_init) { + Curl_mutex_destroy(&dbg_mutex); + dbg_mutex_init = FALSE; + } +#endif +} +#ifdef USE_BACKTRACE +static void error_bt_callback(void *data, const char *message, + int error_number) +{ + (void)data; + if(error_number == -1) + curl_dbg_log("compile with -g\n\n"); + else + curl_dbg_log("Backtrace error %d: %s\n", error_number, message); } +static int full_callback(void *data, uintptr_t pc, const char *pathname, + int line_number, const char *function) +{ + (void)data; + (void)pc; + if(pathname || function || line_number) + curl_dbg_log("BT %s:%d -- %s\n", pathname, line_number, function); + return 0; +} + +static void dump_bt(void) +{ + backtrace_full(btstate, 0, full_callback, error_bt_callback, NULL); +} +#else +#define dump_bt() /* nothing to do */ +#endif + /* this sets the log filename */ void curl_dbg_memdebug(const char *logname) { if(!curl_dbg_logfile) { if(logname && *logname) curl_dbg_logfile = CURLX_FOPEN_LOW(logname, FOPEN_WRITETEXT); - else - curl_dbg_logfile = stderr; #ifdef MEMDEBUG_LOG_SYNC /* Flush the log file after every line so the log is not lost in a crash */ if(curl_dbg_logfile) setbuf(curl_dbg_logfile, (char *)NULL); #endif } +#if defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32) + if(!dbg_mutex_init) { + dbg_mutex_init = TRUE; + Curl_mutex_init(&dbg_mutex); + } +#endif +#ifdef USE_BACKTRACE + btstate = backtrace_create_state(NULL, 0, error_bt_callback, NULL); +#endif if(!registered_cleanup) registered_cleanup = !atexit(curl_dbg_cleanup); } @@ -110,14 +187,14 @@ static bool countcheck(const char *func, int line, const char *source) if(memlimit && source) { if(!memsize) { /* log to file */ - curl_dbg_log("LIMIT %s:%d %s reached memlimit\n", - source, line, func); + curl_dbg_log("LIMIT %s:%d %s reached memlimit\n", source, line, func); /* log to stderr also */ curl_mfprintf(stderr, "LIMIT %s:%d %s reached memlimit\n", source, line, func); + dump_bt(); fflush(curl_dbg_logfile); /* because it might crash now */ /* !checksrc! disable ERRNOVAR 1 */ - CURL_SETERRNO(ENOMEM); + errno = ENOMEM; return TRUE; /* RETURN ERROR! */ } else @@ -240,6 +317,7 @@ void *curl_dbg_realloc(void *ptr, size_t wantedsize, int line, const char *source) { struct memdebug *mem = NULL; + bool was_locked; size_t size = sizeof(struct memdebug) + wantedsize; @@ -248,6 +326,10 @@ void *curl_dbg_realloc(void *ptr, size_t wantedsize, if(countcheck("realloc", line, source)) return NULL; + /* need to realloc under lock, as we get out-of-order log + * entries otherwise, since another thread might alloc the + * memory released by realloc() before otherwise would log it. */ + was_locked = curl_dbg_lock(); #ifdef __INTEL_COMPILER # pragma warning(push) # pragma warning(disable:1684) @@ -263,10 +345,11 @@ void *curl_dbg_realloc(void *ptr, size_t wantedsize, mem = (Curl_crealloc)(mem, size); if(source) - curl_dbg_log("MEM %s:%d realloc(%p, %zu) = %p\n", - source, line, (void *)ptr, wantedsize, - mem ? (void *)mem->mem : (void *)0); + curl_dbg_log_locked("MEM %s:%d realloc(%p, %zu) = %p\n", + source, line, (void *)ptr, wantedsize, + mem ? (void *)mem->mem : (void *)0); + curl_dbg_unlock(was_locked); if(mem) { mem->size = wantedsize; return mem->mem; @@ -280,6 +363,9 @@ void curl_dbg_free(void *ptr, int line, const char *source) if(ptr) { struct memdebug *mem; + if(source) + curl_dbg_log("MEM %s:%d free(%p)\n", source, line, (void *)ptr); + #ifdef __INTEL_COMPILER # pragma warning(push) # pragma warning(disable:1684) @@ -295,9 +381,6 @@ void curl_dbg_free(void *ptr, int line, const char *source) /* free for real */ (Curl_cfree)(mem); } - - if(source && ptr) - curl_dbg_log("MEM %s:%d free(%p)\n", source, line, (void *)ptr); } curl_socket_t curl_dbg_socket(int domain, int type, int protocol, @@ -318,37 +401,6 @@ curl_socket_t curl_dbg_socket(int domain, int type, int protocol, return sockfd; } -SEND_TYPE_RETV curl_dbg_send(SEND_TYPE_ARG1 sockfd, - SEND_QUAL_ARG2 SEND_TYPE_ARG2 buf, - SEND_TYPE_ARG3 len, SEND_TYPE_ARG4 flags, - int line, const char *source) -{ - SEND_TYPE_RETV rc; - if(countcheck("send", line, source)) - return -1; - /* !checksrc! disable BANNEDFUNC 1 */ - rc = send(sockfd, buf, len, flags); - if(source) - curl_dbg_log("SEND %s:%d send(%lu) = %ld\n", - source, line, (unsigned long)len, (long)rc); - return rc; -} - -RECV_TYPE_RETV curl_dbg_recv(RECV_TYPE_ARG1 sockfd, RECV_TYPE_ARG2 buf, - RECV_TYPE_ARG3 len, RECV_TYPE_ARG4 flags, - int line, const char *source) -{ - RECV_TYPE_RETV rc; - if(countcheck("recv", line, source)) - return -1; - /* !checksrc! disable BANNEDFUNC 1 */ - rc = recv(sockfd, buf, len, flags); - if(source) - curl_dbg_log("RECV %s:%d recv(%lu) = %ld\n", - source, line, (unsigned long)len, (long)rc); - return rc; -} - #ifdef HAVE_SOCKETPAIR int curl_dbg_socketpair(int domain, int type, int protocol, curl_socket_t socket_vector[2], @@ -412,9 +464,8 @@ void curl_dbg_mark_sclose(curl_socket_t sockfd, int line, const char *source) /* this is our own defined way to close sockets on *ALL* platforms */ int curl_dbg_sclose(curl_socket_t sockfd, int line, const char *source) { - int res = CURL_SCLOSE(sockfd); curl_dbg_mark_sclose(sockfd, line, source); - return res; + return CURL_SCLOSE(sockfd); } ALLOC_FUNC @@ -424,7 +475,19 @@ FILE *curl_dbg_fopen(const char *file, const char *mode, FILE *res = CURLX_FOPEN_LOW(file, mode); if(source) curl_dbg_log("FILE %s:%d fopen(\"%s\",\"%s\") = %p\n", - source, line, file, mode, (void *)res); + source, line, file, mode, (void *)res); + + return res; +} + +ALLOC_FUNC +FILE *curl_dbg_freopen(const char *file, const char *mode, FILE *fh, + int line, const char *source) +{ + FILE *res = CURLX_FREOPEN_LOW(file, mode, fh); + if(source) + curl_dbg_log("FILE %s:%d freopen(\"%s\",\"%s\",%p) = %p\n", + source, line, file, mode, (void *)fh, (void *)res); return res; } @@ -448,8 +511,7 @@ int curl_dbg_fclose(FILE *file, int line, const char *source) DEBUGASSERT(file != NULL); if(source) - curl_dbg_log("FILE %s:%d fclose(%p)\n", - source, line, (void *)file); + curl_dbg_log("FILE %s:%d fclose(%p)\n", source, line, (void *)file); /* !checksrc! disable BANNEDFUNC 1 */ res = fclose(file); @@ -457,25 +519,59 @@ int curl_dbg_fclose(FILE *file, int line, const char *source) return res; } -/* this does the writing to the memory tracking log file */ -void curl_dbg_log(const char *format, ...) +static void curl_dbg_vlog(const char * const fmt, + va_list ap) CURL_PRINTF(1, 0); + +static void curl_dbg_vlog(const char * const fmt, va_list ap) { char buf[1024]; - int nchars; + size_t nchars = curl_mvsnprintf(buf, sizeof(buf), fmt, ap); + + if(nchars > (int)sizeof(buf) - 1) + nchars = (int)sizeof(buf) - 1; + + if(nchars > 0) { + if(sizeof(membuf) - nchars < memwidx) { + /* flush */ + fwrite(membuf, 1, memwidx, curl_dbg_logfile); + fflush(curl_dbg_logfile); + memwidx = 0; + } + if(memwidx) { + /* the previous line ends with a newline */ + DEBUGASSERT(membuf[memwidx - 1] == '\n'); + } + memcpy(&membuf[memwidx], buf, nchars); + memwidx += nchars; + } +} + +static void curl_dbg_log_locked(const char *format, ...) +{ va_list ap; if(!curl_dbg_logfile) return; va_start(ap, format); - nchars = curl_mvsnprintf(buf, sizeof(buf), format, ap); + curl_dbg_vlog(format, ap); va_end(ap); +} - if(nchars > (int)sizeof(buf) - 1) - nchars = (int)sizeof(buf) - 1; +/* this does the writing to the memory tracking log file */ +void curl_dbg_log(const char *format, ...) +{ + bool was_locked; + va_list ap; - if(nchars > 0) - (fwrite)(buf, 1, (size_t)nchars, curl_dbg_logfile); + if(!curl_dbg_logfile) + return; + + was_locked = curl_dbg_lock(); + va_start(ap, format); + curl_dbg_vlog(format, ap); + va_end(ap); + curl_dbg_unlock(was_locked); } #endif /* CURLDEBUG */ diff --git a/vendor/hydra/vendor/curl/lib/memdebug.h b/vendor/hydra/vendor/curl/lib/memdebug.h deleted file mode 100644 index c2b7fad9..00000000 --- a/vendor/hydra/vendor/curl/lib/memdebug.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef HEADER_CURL_MEMDEBUG_H -#define HEADER_CURL_MEMDEBUG_H -/*************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ - * \___|\___/|_| \_\_____| - * - * Copyright (C) Daniel Stenberg, , et al. - * - * This software is licensed as described in the file COPYING, which - * you should have received as part of this distribution. The terms - * are also available at https://curl.se/docs/copyright.html. - * - * You may opt to use, copy, modify, merge, publish, distribute and/or sell - * copies of the Software, and permit persons to whom the Software is - * furnished to do so, under the terms of the COPYING file. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - * SPDX-License-Identifier: curl - * - ***************************************************************************/ - -/* - * CAUTION: this header is designed to work when included by the app-side - * as well as the library. Do not mix with library internals! - */ - -#ifdef CURLDEBUG - -/* Set this symbol on the command-line, recompile all lib-sources */ -#undef strdup -#define strdup(ptr) curl_dbg_strdup(ptr, __LINE__, __FILE__) -#undef malloc -#define malloc(size) curl_dbg_malloc(size, __LINE__, __FILE__) -#undef calloc -#define calloc(nbelem,size) curl_dbg_calloc(nbelem, size, __LINE__, __FILE__) -#undef realloc -#define realloc(ptr,size) curl_dbg_realloc(ptr, size, __LINE__, __FILE__) -#undef free -#define free(ptr) curl_dbg_free(ptr, __LINE__, __FILE__) - -#ifdef _WIN32 -#undef Curl_tcsdup -#ifdef UNICODE -#define Curl_tcsdup(ptr) curl_dbg_wcsdup(ptr, __LINE__, __FILE__) -#else -#define Curl_tcsdup(ptr) curl_dbg_strdup(ptr, __LINE__, __FILE__) -#endif -#endif /* _WIN32 */ - -#endif /* CURLDEBUG */ -#endif /* HEADER_CURL_MEMDEBUG_H */ diff --git a/vendor/hydra/vendor/curl/lib/mime.c b/vendor/hydra/vendor/curl/lib/mime.c index 0a56b07b..37b50de3 100644 --- a/vendor/hydra/vendor/curl/lib/mime.c +++ b/vendor/hydra/vendor/curl/lib/mime.c @@ -21,19 +21,17 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include - struct Curl_easy; #include "mime.h" -#include "curlx/warnless.h" #include "urldata.h" #include "sendf.h" +#include "curl_trc.h" #include "transfer.h" #include "strdup.h" +#include "curlx/strcopy.h" #include "curlx/fopen.h" #include "curlx/base64.h" @@ -50,18 +48,14 @@ struct Curl_easy; #include "slist.h" #include "curlx/dynbuf.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef _WIN32 # ifndef R_OK # define R_OK 4 # endif #endif -#define READ_ERROR ((size_t) -1) -#define STOP_FILLING ((size_t) -2) +#define READ_ERROR ((size_t)-1) +#define STOP_FILLING ((size_t)-2) static size_t mime_subparts_read(char *buffer, size_t size, size_t nitems, void *instream, bool *hasread); @@ -81,12 +75,12 @@ static curl_off_t encoder_qp_size(curl_mimepart *part); static curl_off_t mime_size(curl_mimepart *part); static const struct mime_encoder encoders[] = { - {"binary", encoder_nop_read, encoder_nop_size}, - {"8bit", encoder_nop_read, encoder_nop_size}, - {"7bit", encoder_7bit_read, encoder_nop_size}, - {"base64", encoder_base64_read, encoder_base64_size}, - {"quoted-printable", encoder_qp_read, encoder_qp_size}, - {ZERO_NULL, ZERO_NULL, ZERO_NULL} + { "binary", encoder_nop_read, encoder_nop_size }, + { "8bit", encoder_nop_read, encoder_nop_size }, + { "7bit", encoder_7bit_read, encoder_nop_size }, + { "base64", encoder_base64_read, encoder_base64_size }, + { "quoted-printable", encoder_qp_read, encoder_qp_size }, + { ZERO_NULL, ZERO_NULL, ZERO_NULL } }; /* Quoted-printable character class table. @@ -124,15 +118,13 @@ static const unsigned char qp_class[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* F0 - FF */ }; - /* Binary --> hexadecimal ASCII table. */ static const char aschex[] = "\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x41\x42\x43\x44\x45\x46"; - #ifndef __VMS #define filesize(name, stat_data) (stat_data.st_size) -#define fopen_read curlx_fopen +#define fopen_read curlx_fopen #else @@ -147,13 +139,12 @@ static const char aschex[] = * and CD/DVD images should be either a STREAM_LF format or a fixed format. * */ -curl_off_t VmsRealFileSize(const char *name, - const struct_stat *stat_buf) +curl_off_t VmsRealFileSize(const char *name, const struct_stat *stat_buf) { char buffer[8192]; curl_off_t count; int ret_stat; - FILE * file; + FILE *file; file = curlx_fopen(name, FOPEN_READTEXT); /* VMS */ if(!file) @@ -177,8 +168,7 @@ curl_off_t VmsRealFileSize(const char *name, * if not to call a routine to get the correct size. * */ -static curl_off_t VmsSpecialSize(const char *name, - const struct_stat *stat_buf) +static curl_off_t VmsSpecialSize(const char *name, const struct_stat *stat_buf) { switch(stat_buf->st_fab_rfm) { case FAB$C_VAR: @@ -200,7 +190,7 @@ static curl_off_t VmsSpecialSize(const char *name, * record format of the file. * */ -static FILE * vmsfopenread(const char *file, const char *mode) +static FILE *vmsfopenread(const char *file, const char *mode) { struct_stat statbuf; int result; @@ -221,7 +211,6 @@ static FILE * vmsfopenread(const char *file, const char *mode) #define fopen_read vmsfopenread #endif - #ifndef HAVE_BASENAME /* (Quote from The Open Group Base Specifications Issue 6 IEEE Std 1003.1, 2004 @@ -268,10 +257,9 @@ static char *Curl_basename(char *path) return path; } -#define basename(x) Curl_basename((x)) +#define basename(x) Curl_basename(x) #endif - /* Set readback state. */ static void mimesetstate(struct mime_state *state, enum mimestate tok, void *ptr) @@ -281,7 +269,6 @@ static void mimesetstate(struct mime_state *state, state->offset = 0; } - /* Escape header string into allocated memory. */ static char *escape_string(struct Curl_easy *data, const char *src, enum mimestrategy strategy) @@ -357,13 +344,13 @@ static char *strippath(const char *fullfile) { char *filename; char *base; - filename = strdup(fullfile); /* duplicate since basename() may ruin the - buffer it works on */ + filename = curlx_strdup(fullfile); /* duplicate since basename() may ruin + the buffer it works on */ if(!filename) return NULL; - base = strdup(basename(filename)); + base = curlx_strdup(basename(filename)); - free(filename); /* free temporary buffer */ + curlx_free(filename); /* free temporary buffer */ return base; /* returns an allocated string or NULL ! */ } @@ -376,7 +363,6 @@ static void cleanup_encoder_state(struct mime_encoder_state *p) p->bufend = 0; } - /* Dummy encoder. This is used for 8bit and binary content encodings. */ static size_t encoder_nop_read(char *buffer, size_t size, bool ateof, struct curl_mimepart *part) @@ -404,7 +390,6 @@ static curl_off_t encoder_nop_size(curl_mimepart *part) return part->datasize; } - /* 7bit encoder: the encoder is just a data validity check. */ static size_t encoder_7bit_read(char *buffer, size_t size, bool ateof, curl_mimepart *part) @@ -430,7 +415,6 @@ static size_t encoder_7bit_read(char *buffer, size_t size, bool ateof, return cursize; } - /* Base64 content encoder. */ static size_t encoder_base64_read(char *buffer, size_t size, bool ateof, curl_mimepart *part) @@ -469,10 +453,10 @@ static size_t encoder_base64_read(char *buffer, size_t size, bool ateof, i = st->buf[st->bufbeg++] & 0xFF; i = (i << 8) | (st->buf[st->bufbeg++] & 0xFF); i = (i << 8) | (st->buf[st->bufbeg++] & 0xFF); - *ptr++ = Curl_base64encdec[(i >> 18) & 0x3F]; - *ptr++ = Curl_base64encdec[(i >> 12) & 0x3F]; - *ptr++ = Curl_base64encdec[(i >> 6) & 0x3F]; - *ptr++ = Curl_base64encdec[i & 0x3F]; + *ptr++ = curlx_base64encdec[(i >> 18) & 0x3F]; + *ptr++ = curlx_base64encdec[(i >> 12) & 0x3F]; + *ptr++ = curlx_base64encdec[(i >> 6) & 0x3F]; + *ptr++ = curlx_base64encdec[i & 0x3F]; cursize += 4; st->pos += 4; size -= 4; @@ -496,10 +480,10 @@ static size_t encoder_base64_read(char *buffer, size_t size, bool ateof, i = (st->buf[st->bufbeg + 1] & 0xFF) << 8; i |= (st->buf[st->bufbeg] & 0xFF) << 16; - ptr[0] = Curl_base64encdec[(i >> 18) & 0x3F]; - ptr[1] = Curl_base64encdec[(i >> 12) & 0x3F]; + ptr[0] = curlx_base64encdec[(i >> 18) & 0x3F]; + ptr[1] = curlx_base64encdec[(i >> 12) & 0x3F]; if(++st->bufbeg != st->bufend) { - ptr[2] = Curl_base64encdec[(i >> 6) & 0x3F]; + ptr[2] = curlx_base64encdec[(i >> 6) & 0x3F]; st->bufbeg++; } cursize += 4; @@ -525,7 +509,6 @@ static curl_off_t encoder_base64_size(curl_mimepart *part) return size + 2 * ((size - 1) / MAX_ENCODED_LINE_LENGTH); } - /* Quoted-printable lookahead. * * Check if a CRLF or end of data is in input buffer at current position + n. @@ -562,7 +545,7 @@ static size_t encoder_qp_read(char *buffer, size_t size, bool ateof, size_t len = 1; size_t consumed = 1; int i = st->buf[st->bufbeg]; - buf[0] = (char) i; + buf[0] = (char)i; buf[1] = aschex[(i >> 4) & 0xF]; buf[2] = aschex[i & 0xF]; @@ -619,7 +602,7 @@ static size_t encoder_qp_read(char *buffer, size_t size, bool ateof, } } if(softlinebreak) { - strcpy(buf, "\x3D\x0D\x0A"); /* "=\r\n" */ + curlx_strcopy(buf, sizeof(buf), "\x3D\x0D\x0A", 3); /* "=\r\n" */ len = 3; consumed = 0; } @@ -653,13 +636,12 @@ static curl_off_t encoder_qp_size(curl_mimepart *part) return part->datasize ? -1 : 0; } - /* In-memory data callbacks. */ /* Argument is a pointer to the mime part. */ static size_t mime_mem_read(char *buffer, size_t size, size_t nitems, void *instream) { - curl_mimepart *part = (curl_mimepart *) instream; + curl_mimepart *part = (curl_mimepart *)instream; size_t sz = curlx_sotouz(part->datasize - part->state.offset); (void)size; /* Always 1 */ @@ -677,7 +659,7 @@ static size_t mime_mem_read(char *buffer, size_t size, size_t nitems, static int mime_mem_seek(void *instream, curl_off_t offset, int whence) { - curl_mimepart *part = (curl_mimepart *) instream; + curl_mimepart *part = (curl_mimepart *)instream; switch(whence) { case SEEK_CUR: @@ -697,10 +679,9 @@ static int mime_mem_seek(void *instream, curl_off_t offset, int whence) static void mime_mem_free(void *ptr) { - Curl_safefree(((curl_mimepart *) ptr)->data); + Curl_safefree(((curl_mimepart *)ptr)->data); } - /* Named file callbacks. */ /* Argument is a pointer to the mime part. */ static bool mime_open_file(curl_mimepart *part) @@ -716,7 +697,7 @@ static bool mime_open_file(curl_mimepart *part) static size_t mime_file_read(char *buffer, size_t size, size_t nitems, void *instream) { - curl_mimepart *part = (curl_mimepart *) instream; + curl_mimepart *part = (curl_mimepart *)instream; if(!nitems) return STOP_FILLING; @@ -729,7 +710,7 @@ static size_t mime_file_read(char *buffer, size_t size, size_t nitems, static int mime_file_seek(void *instream, curl_off_t offset, int whence) { - curl_mimepart *part = (curl_mimepart *) instream; + curl_mimepart *part = (curl_mimepart *)instream; if(whence == SEEK_SET && !offset && !part->fp) return CURL_SEEKFUNC_OK; /* Not open: implicitly already at BOF. */ @@ -743,7 +724,7 @@ static int mime_file_seek(void *instream, curl_off_t offset, int whence) static void mime_file_free(void *ptr) { - curl_mimepart *part = (curl_mimepart *) ptr; + curl_mimepart *part = (curl_mimepart *)ptr; if(part->fp) { curlx_fclose(part->fp); @@ -752,7 +733,6 @@ static void mime_file_free(void *ptr) Curl_safefree(part->data); } - /* Subparts callbacks. */ /* Argument is a pointer to the mime structure. */ @@ -802,7 +782,7 @@ static size_t read_part_content(curl_mimepart *part, } /* If we can determine we are at end of part data, spare a read. */ - if(part->datasize != (curl_off_t) -1 && + if(part->datasize != (curl_off_t)-1 && part->state.offset >= part->datasize) { /* sz is already zero. */ } @@ -813,8 +793,8 @@ static size_t read_part_content(curl_mimepart *part, * Cannot be processed as other kinds since read function requires * an additional parameter and is highly recursive. */ - sz = mime_subparts_read(buffer, 1, bufsize, part->arg, hasread); - break; + sz = mime_subparts_read(buffer, 1, bufsize, part->arg, hasread); + break; case MIMEKIND_FILE: if(part->fp && feof(part->fp)) break; /* At EOF. */ @@ -920,7 +900,7 @@ static size_t readback_part(curl_mimepart *part, while(bufsize) { size_t sz = 0; - struct curl_slist *hdr = (struct curl_slist *) part->state.ptr; + struct curl_slist *hdr = (struct curl_slist *)part->state.ptr; switch(part->state.state) { case MIMESTATE_BEGIN: mimesetstate(&part->state, @@ -998,7 +978,7 @@ static size_t readback_part(curl_mimepart *part, static size_t mime_subparts_read(char *buffer, size_t size, size_t nitems, void *instream, bool *hasread) { - curl_mime *mime = (curl_mime *) instream; + curl_mime *mime = (curl_mime *)instream; size_t cursize = 0; (void)size; /* Always 1 */ @@ -1074,7 +1054,7 @@ static int mime_part_rewind(curl_mimepart *part) if(part->state.state > targetstate) { res = CURL_SEEKFUNC_CANTSEEK; if(part->seekfunc) { - res = part->seekfunc(part->arg, (curl_off_t) 0, SEEK_SET); + res = part->seekfunc(part->arg, (curl_off_t)0, SEEK_SET); switch(res) { case CURL_SEEKFUNC_OK: case CURL_SEEKFUNC_FAIL: @@ -1099,7 +1079,7 @@ static int mime_part_rewind(curl_mimepart *part) static int mime_subparts_seek(void *instream, curl_off_t offset, int whence) { - curl_mime *mime = (curl_mime *) instream; + curl_mime *mime = (curl_mime *)instream; curl_mimepart *part; int result = CURL_SEEKFUNC_OK; @@ -1130,10 +1110,10 @@ static void cleanup_part_content(curl_mimepart *part) part->readfunc = NULL; part->seekfunc = NULL; part->freefunc = NULL; - part->arg = (void *) part; /* Defaults to part itself. */ + part->arg = (void *)part; /* Defaults to part itself. */ part->data = NULL; part->fp = NULL; - part->datasize = (curl_off_t) 0; /* No size yet. */ + part->datasize = (curl_off_t)0; /* No size yet. */ cleanup_encoder_state(&part->encstate); part->kind = MIMEKIND_NONE; part->flags &= ~(unsigned int)MIME_FAST_READ; @@ -1143,7 +1123,7 @@ static void cleanup_part_content(curl_mimepart *part) static void mime_subparts_free(void *ptr) { - curl_mime *mime = (curl_mime *) ptr; + curl_mime *mime = (curl_mime *)ptr; if(mime && mime->parent) { mime->parent->freefunc = NULL; /* Be sure we will not be called again. */ @@ -1155,7 +1135,7 @@ static void mime_subparts_free(void *ptr) /* Do not free subparts: unbind them. This is used for the top level only. */ static void mime_subparts_unbind(void *ptr) { - curl_mime *mime = (curl_mime *) ptr; + curl_mime *mime = (curl_mime *)ptr; if(mime && mime->parent) { mime->parent->freefunc = NULL; /* Be sure we will not be called again. */ @@ -1164,7 +1144,6 @@ static void mime_subparts_unbind(void *ptr) } } - void Curl_mime_cleanpart(curl_mimepart *part) { if(part) { @@ -1190,9 +1169,9 @@ void curl_mime_free(curl_mime *mime) part = mime->firstpart; mime->firstpart = part->nextpart; Curl_mime_cleanpart(part); - free(part); + curlx_free(part); } - free(mime); + curlx_free(mime); } } @@ -1211,7 +1190,7 @@ CURLcode Curl_mime_duppart(struct Curl_easy *data, case MIMEKIND_NONE: break; case MIMEKIND_DATA: - res = curl_mime_data(dst, src->data, (size_t) src->datasize); + res = curl_mime_data(dst, src->data, (size_t)src->datasize); break; case MIMEKIND_FILE: res = curl_mime_filedata(dst, src->data); @@ -1230,7 +1209,7 @@ CURLcode Curl_mime_duppart(struct Curl_easy *data, res = mime ? curl_mime_subparts(dst, mime) : CURLE_OUT_OF_MEMORY; /* Duplicate subparts. */ - for(s = ((curl_mime *) src->arg)->firstpart; !res && s; s = s->nextpart) { + for(s = ((curl_mime *)src->arg)->firstpart; !res && s; s = s->nextpart) { d = curl_mime_addpart(mime); res = d ? Curl_mime_duppart(data, d, s) : CURLE_OUT_OF_MEMORY; } @@ -1282,7 +1261,7 @@ curl_mime *curl_mime_init(void *easy) { curl_mime *mime; - mime = (curl_mime *) malloc(sizeof(*mime)); + mime = (curl_mime *)curlx_malloc(sizeof(*mime)); if(mime) { mime->parent = NULL; @@ -1291,10 +1270,10 @@ curl_mime *curl_mime_init(void *easy) memset(mime->boundary, '-', MIME_BOUNDARY_DASHES); if(Curl_rand_alnum(easy, - (unsigned char *) &mime->boundary[MIME_BOUNDARY_DASHES], + (unsigned char *)&mime->boundary[MIME_BOUNDARY_DASHES], MIME_RAND_BOUNDARY_CHARS + 1)) { /* failed to get random separator, bail out */ - free(mime); + curlx_free(mime); return NULL; } mimesetstate(&mime->state, MIMESTATE_BEGIN, NULL); @@ -1306,7 +1285,7 @@ curl_mime *curl_mime_init(void *easy) /* Initialize a mime part. */ void Curl_mime_initpart(curl_mimepart *part) { - memset((char *) part, 0, sizeof(*part)); + memset((char *)part, 0, sizeof(*part)); part->lastreadstatus = 1; /* Successful read status. */ mimesetstate(&part->state, MIMESTATE_BEGIN, NULL); } @@ -1319,7 +1298,7 @@ curl_mimepart *curl_mime_addpart(curl_mime *mime) if(!mime) return NULL; - part = (curl_mimepart *) malloc(sizeof(*part)); + part = (curl_mimepart *)curlx_malloc(sizeof(*part)); if(part) { Curl_mime_initpart(part); @@ -1345,7 +1324,7 @@ CURLcode curl_mime_name(curl_mimepart *part, const char *name) Curl_safefree(part->name); if(name) { - part->name = strdup(name); + part->name = curlx_strdup(name); if(!part->name) return CURLE_OUT_OF_MEMORY; } @@ -1362,7 +1341,7 @@ CURLcode curl_mime_filename(curl_mimepart *part, const char *filename) Curl_safefree(part->filename); if(filename) { - part->filename = strdup(filename); + part->filename = curlx_strdup(filename); if(!part->filename) return CURLE_OUT_OF_MEMORY; } @@ -1371,8 +1350,7 @@ CURLcode curl_mime_filename(curl_mimepart *part, const char *filename) } /* Set mime part content from memory data. */ -CURLcode curl_mime_data(curl_mimepart *part, - const char *ptr, size_t datasize) +CURLcode curl_mime_data(curl_mimepart *part, const char *ptr, size_t datasize) { if(!part) return CURLE_BAD_FUNCTION_ARGUMENT; @@ -1415,7 +1393,7 @@ CURLcode curl_mime_filedata(curl_mimepart *part, const char *filename) if(curlx_stat(filename, &sbuf)) result = CURLE_READ_ERROR; else { - part->data = strdup(filename); + part->data = curlx_strdup(filename); if(!part->data) result = CURLE_OUT_OF_MEMORY; else { @@ -1438,7 +1416,7 @@ CURLcode curl_mime_filedata(curl_mimepart *part, const char *filename) result = CURLE_OUT_OF_MEMORY; else { result = curl_mime_filename(part, base); - free(base); + curlx_free(base); } } } @@ -1455,7 +1433,7 @@ CURLcode curl_mime_type(curl_mimepart *part, const char *mimetype) Curl_safefree(part->mimetype); if(mimetype) { - part->mimetype = strdup(mimetype); + part->mimetype = curlx_strdup(mimetype); if(!part->mimetype) return CURLE_OUT_OF_MEMORY; } @@ -1562,7 +1540,7 @@ CURLcode Curl_mime_set_subparts(curl_mimepart *part, they might not be positioned at start. Rewind them now, as a future check while rewinding the parent may cause this content to be skipped. */ - if(mime_subparts_seek(subparts, (curl_off_t) 0, SEEK_SET) != + if(mime_subparts_seek(subparts, (curl_off_t)0, SEEK_SET) != CURL_SEEKFUNC_OK) return CURLE_SEND_FAIL_REWIND; @@ -1584,12 +1562,11 @@ CURLcode curl_mime_subparts(curl_mimepart *part, curl_mime *subparts) return Curl_mime_set_subparts(part, subparts, TRUE); } - /* Readback from top mime. */ /* Argument is the dummy top part. */ size_t Curl_mime_read(char *buffer, size_t size, size_t nitems, void *instream) { - curl_mimepart *part = (curl_mimepart *) instream; + curl_mimepart *part = (curl_mimepart *)instream; size_t ret; bool hasread; @@ -1672,8 +1649,7 @@ static curl_off_t mime_size(curl_mimepart *part) if(size >= 0 && !(part->flags & MIME_BODY_ONLY)) { /* Compute total part size. */ size += slist_size(part->curlheaders, 2, NULL, 0); - size += slist_size(part->userheaders, 2, - STRCONST("Content-Type")); + size += slist_size(part->userheaders, 2, STRCONST("Content-Type")); size += 2; /* CRLF after headers. */ } return size; @@ -1696,7 +1672,7 @@ CURLcode Curl_mime_add_header(struct curl_slist **slp, const char *fmt, ...) if(hdr) *slp = hdr; else - free(s); + curlx_free(s); } return hdr ? CURLE_OK : CURLE_OUT_OF_MEMORY; @@ -1722,16 +1698,16 @@ const char *Curl_mime_contenttype(const char *filename) const char *type; }; static const struct ContentType ctts[] = { - {".gif", "image/gif"}, - {".jpg", "image/jpeg"}, - {".jpeg", "image/jpeg"}, - {".png", "image/png"}, - {".svg", "image/svg+xml"}, - {".txt", "text/plain"}, - {".htm", "text/html"}, - {".html", "text/html"}, - {".pdf", "application/pdf"}, - {".xml", "application/xml"} + { ".gif", "image/gif" }, + { ".jpg", "image/jpeg" }, + { ".jpeg", "image/jpeg" }, + { ".png", "image/png" }, + { ".svg", "image/svg+xml" }, + { ".txt", "text/plain" }, + { ".htm", "text/html" }, + { ".html", "text/html" }, + { ".pdf", "application/pdf" }, + { ".xml", "application/xml" } }; if(filename) { @@ -1812,7 +1788,7 @@ CURLcode Curl_mime_prepare_headers(struct Curl_easy *data, } if(part->kind == MIMEKIND_MULTIPART) { - mime = (curl_mime *) part->arg; + mime = (curl_mime *)part->arg; if(mime) boundary = mime->boundary; } @@ -1825,10 +1801,10 @@ CURLcode Curl_mime_prepare_headers(struct Curl_easy *data, if(!search_header(part->userheaders, STRCONST("Content-Disposition"))) { if(!disposition) if(part->filename || part->name || - (contenttype && !curl_strnequal(contenttype, "multipart/", 10))) - disposition = DISPOSITION_DEFAULT; + (contenttype && !curl_strnequal(contenttype, "multipart/", 10))) + disposition = DISPOSITION_DEFAULT; if(disposition && curl_strequal(disposition, "attachment") && - !part->name && !part->filename) + !part->name && !part->filename) disposition = NULL; if(disposition) { char *name = NULL; @@ -1858,8 +1834,8 @@ CURLcode Curl_mime_prepare_headers(struct Curl_easy *data, Curl_safefree(filename); if(ret) return ret; - } } + } /* Issue Content-Type header. */ if(contenttype) { @@ -1874,7 +1850,7 @@ CURLcode Curl_mime_prepare_headers(struct Curl_easy *data, if(part->encoder) cte = part->encoder->name; else if(contenttype && strategy == MIMESTRATEGY_MAIL && - part->kind != MIMEKIND_MULTIPART) + part->kind != MIMEKIND_MULTIPART) cte = "8bit"; if(cte) { ret = Curl_mime_add_header(&part->curlheaders, @@ -1913,7 +1889,7 @@ static void mime_unpause(curl_mimepart *part) if(part->lastreadstatus == CURL_READFUNC_PAUSE) part->lastreadstatus = 1; /* Successful read status. */ if(part->kind == MIMEKIND_MULTIPART) { - curl_mime *mime = (curl_mime *) part->arg; + curl_mime *mime = (curl_mime *)part->arg; if(mime) { curl_mimepart *subpart; @@ -1966,7 +1942,6 @@ static CURLcode cr_mime_read(struct Curl_easy *data, size_t nread; char tmp[256]; - /* Once we have errored, we will return the same error forever */ if(ctx->errored) { CURL_TRC_READ(data, "cr_mime_read(len=%zu) is errored -> %d, eos=0", @@ -2118,7 +2093,7 @@ static CURLcode cr_mime_resume_from(struct Curl_easy *data, curl_off_t passed = 0; do { - char scratch[4*1024]; + char scratch[4 * 1024]; size_t readthisamountnow = (offset - passed > (curl_off_t)sizeof(scratch)) ? sizeof(scratch) : @@ -2267,8 +2242,7 @@ CURLcode curl_mime_encoder(curl_mimepart *part, const char *encoding) return CURLE_NOT_BUILT_IN; } -CURLcode curl_mime_data(curl_mimepart *part, - const char *data, size_t datasize) +CURLcode curl_mime_data(curl_mimepart *part, const char *data, size_t datasize) { (void)part; (void)data; @@ -2283,8 +2257,7 @@ CURLcode curl_mime_filedata(curl_mimepart *part, const char *filename) return CURLE_NOT_BUILT_IN; } -CURLcode curl_mime_data_cb(curl_mimepart *part, - curl_off_t datasize, +CURLcode curl_mime_data_cb(curl_mimepart *part, curl_off_t datasize, curl_read_callback readfunc, curl_seek_callback seekfunc, curl_free_callback freefunc, diff --git a/vendor/hydra/vendor/curl/lib/mime.h b/vendor/hydra/vendor/curl/lib/mime.h index 5073a38f..81080b44 100644 --- a/vendor/hydra/vendor/curl/lib/mime.h +++ b/vendor/hydra/vendor/curl/lib/mime.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #define MIME_BOUNDARY_DASHES 24 /* leading boundary dashes */ @@ -165,12 +164,11 @@ CURLcode Curl_creader_set_mime(struct Curl_easy *data, curl_mimepart *part); /* if disabled */ #define Curl_mime_initpart(x) #define Curl_mime_cleanpart(x) -#define Curl_mime_duppart(x,y,z) CURLE_OK /* Nothing to duplicate. Succeed */ -#define Curl_mime_set_subparts(a,b,c) CURLE_NOT_BUILT_IN -#define Curl_mime_prepare_headers(a,b,c,d,e) CURLE_NOT_BUILT_IN -#define Curl_mime_read NULL -#define Curl_creader_set_mime(x,y) ((void)x, CURLE_NOT_BUILT_IN) +#define Curl_mime_duppart(x, y, z) CURLE_OK /* Nothing to duplicate. Succeed */ +#define Curl_mime_set_subparts(a, b, c) CURLE_NOT_BUILT_IN +#define Curl_mime_prepare_headers(a, b, c, d, e) CURLE_NOT_BUILT_IN +#define Curl_mime_read NULL +#define Curl_creader_set_mime(x, y) ((void)x, CURLE_NOT_BUILT_IN) #endif - #endif /* HEADER_CURL_MIME_H */ diff --git a/vendor/hydra/vendor/curl/lib/mprintf.c b/vendor/hydra/vendor/curl/lib/mprintf.c index 176f8a3e..50ede212 100644 --- a/vendor/hydra/vendor/curl/lib/mprintf.c +++ b/vendor/hydra/vendor/curl/lib/mprintf.c @@ -20,17 +20,13 @@ * * SPDX-License-Identifier: curl * - */ - + ***************************************************************************/ #include "curl_setup.h" + #include "curlx/dynbuf.h" #include "curl_printf.h" #include "curlx/strparse.h" -#include "curl_memory.h" -/* The last #include file should be: */ -#include "memdebug.h" - #ifdef HAVE_LONGLONG # define LONG_LONG_TYPE long long # define HAVE_LONG_LONG_TYPE @@ -175,8 +171,8 @@ static int dollarstring(const char *p, const char **end) return (int)num - 1; } -#define is_arg_used(x,y) ((x)[(y)/8] & (1 << ((y)&7))) -#define mark_arg_used(x,y) ((x)[y/8] |= (unsigned char)(1 << ((y)&7))) +#define is_arg_used(x, y) ((x)[(y) / 8] & (1 << ((y) & 7))) +#define mark_arg_used(x, y) ((x)[y / 8] |= (unsigned char)(1 << ((y) & 7))) /* * Parse the format string. @@ -210,7 +206,7 @@ static int parsefmt(const char *format, int max_param = -1; int i; int ocount = 0; - unsigned char usedinput[MAX_PARAMETERS/8]; + unsigned char usedinput[MAX_PARAMETERS / 8]; size_t outlen = 0; struct outsegment *optr; int use_dollar = DOLLAR_UNKNOWN; @@ -368,8 +364,15 @@ static int parsefmt(const char *format, if(!(flags & FLAGS_LEFT)) flags |= FLAGS_PAD_NIL; FALLTHROUGH(); - case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': { + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': { curl_off_t num; flags |= FLAGS_WIDTH; fmt--; @@ -435,7 +438,7 @@ static int parsefmt(const char *format, type = FORMAT_LONGU; else type = FORMAT_INTU; - flags |= FLAGS_OCTAL|FLAGS_UNSIGNED; + flags |= FLAGS_OCTAL | FLAGS_UNSIGNED; break; case 'x': if(flags & FLAGS_LONGLONG) @@ -444,7 +447,7 @@ static int parsefmt(const char *format, type = FORMAT_LONGU; else type = FORMAT_INTU; - flags |= FLAGS_HEX|FLAGS_UNSIGNED; + flags |= FLAGS_HEX | FLAGS_UNSIGNED; break; case 'X': if(flags & FLAGS_LONGLONG) @@ -453,7 +456,7 @@ static int parsefmt(const char *format, type = FORMAT_LONGU; else type = FORMAT_INTU; - flags |= FLAGS_HEX|FLAGS_UPPER|FLAGS_UNSIGNED; + flags |= FLAGS_HEX | FLAGS_UPPER | FLAGS_UNSIGNED; break; case 'c': type = FORMAT_INT; @@ -468,7 +471,7 @@ static int parsefmt(const char *format, break; case 'E': type = FORMAT_DOUBLE; - flags |= FLAGS_FLOATE|FLAGS_UPPER; + flags |= FLAGS_FLOATE | FLAGS_UPPER; break; case 'g': type = FORMAT_DOUBLE; @@ -476,7 +479,7 @@ static int parsefmt(const char *format, break; case 'G': type = FORMAT_DOUBLE; - flags |= FLAGS_FLOATG|FLAGS_UPPER; + flags |= FLAGS_FLOATG | FLAGS_UPPER; break; default: /* invalid instruction, disregard and continue */ @@ -631,9 +634,9 @@ static bool out_double(void *userp, double dnum, char *work, int *donep) { - char formatbuf[32]="%"; + char formatbuf[32] = "%"; char *fptr = &formatbuf[1]; - size_t left = sizeof(formatbuf)-strlen(formatbuf); + size_t left = sizeof(formatbuf) - strlen(formatbuf); int flags = p->flags; int width = p->width; int prec = p->prec; @@ -749,7 +752,7 @@ static bool out_number(void *userp, if(!(flags & FLAGS_LEFT)) while(--width > 0) OUTCHAR(' '); - OUTCHAR((char) num); + OUTCHAR((char)num); if(flags & FLAGS_LEFT) while(--width > 0) OUTCHAR(' '); @@ -872,7 +875,7 @@ static bool out_string(void *userp, if(!str) { /* Write null string if there is space. */ - if(prec == -1 || prec >= (int) sizeof(nilstr) - 1) { + if(prec == -1 || prec >= (int)sizeof(nilstr) - 1) { str = nilstr; len = sizeof(nilstr) - 1; /* Disable quotes around (nil) */ @@ -920,10 +923,10 @@ static bool out_pointer(void *userp, { /* Generic pointer. */ if(ptr) { - size_t num = (size_t) ptr; + size_t num = (size_t)ptr; /* If the pointer is not NULL, write it as a %#x spec. */ - p->flags |= FLAGS_HEX|FLAGS_ALT; + p->flags |= FLAGS_HEX | FLAGS_ALT; if(out_number(userp, stream, p, num, 0, work, donep)) return TRUE; } @@ -962,13 +965,12 @@ static bool out_pointer(void *userp, * All output is sent to the 'stream()' callback, one byte at a time. */ -static int formatf( - void *userp, /* untouched by format(), just sent to the stream() function in - the second argument */ - /* function pointer called for each output character */ - int (*stream)(unsigned char, void *), - const char *format, /* %-formatted string */ - va_list ap_save) /* list of parameters */ +static int formatf(void *userp, /* untouched by format(), just sent to the + stream() function in the second argument */ + /* function pointer called for each output character */ + int (*stream)(unsigned char, void *), + const char *format, /* %-formatted string */ + va_list ap_save) /* list of parameters */ { int done = 0; /* number of characters written */ int i; @@ -1069,15 +1071,15 @@ static int formatf( /* Answer the count of characters written. */ #ifdef HAVE_LONG_LONG_TYPE if(p.flags & FLAGS_LONGLONG) - *(LONG_LONG_TYPE *) iptr->val.ptr = (LONG_LONG_TYPE)done; + *(LONG_LONG_TYPE *)iptr->val.ptr = (LONG_LONG_TYPE)done; else #endif if(p.flags & FLAGS_LONG) - *(long *) iptr->val.ptr = (long)done; + *(long *)iptr->val.ptr = (long)done; else if(!(p.flags & FLAGS_SHORT)) - *(int *) iptr->val.ptr = (int)done; + *(int *)iptr->val.ptr = (int)done; else - *(short *) iptr->val.ptr = (short)done; + *(short *)iptr->val.ptr = (short)done; break; default: @@ -1142,7 +1144,7 @@ static int alloc_addbyter(unsigned char outc, void *f) CURLcode result = curlx_dyn_addn(infop->b, &outc, 1); if(result) { infop->merr = result == CURLE_TOO_LARGE ? MERR_TOO_LARGE : MERR_MEM; - return 1 ; /* fail */ + return 1; /* fail */ } return 0; } @@ -1177,7 +1179,7 @@ char *curl_mvaprintf(const char *format, va_list ap_save) } if(curlx_dyn_len(info.b)) return curlx_dyn_ptr(info.b); - return strdup(""); + return curlx_strdup(""); } char *curl_maprintf(const char *format, ...) diff --git a/vendor/hydra/vendor/curl/lib/mqtt.c b/vendor/hydra/vendor/curl/lib/mqtt.c index 0bf956c0..2ba1ca73 100644 --- a/vendor/hydra/vendor/curl/lib/mqtt.c +++ b/vendor/hydra/vendor/curl/lib/mqtt.c @@ -22,28 +22,21 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifndef CURL_DISABLE_MQTT #include "urldata.h" -#include #include "transfer.h" #include "sendf.h" +#include "curl_trc.h" #include "progress.h" #include "mqtt.h" #include "select.h" #include "url.h" #include "escape.h" -#include "curlx/warnless.h" -#include "multiif.h" #include "rand.h" -/* The last 2 #includes file should be: */ -#include "curl_memory.h" -#include "memdebug.h" - /* first byte is command. second byte is for flags. */ #define MQTT_MSG_CONNECT 0x10 @@ -55,8 +48,8 @@ /* #define MQTT_MSG_PINGREQ 0xC0 */ #define MQTT_MSG_PINGRESP 0xD0 -#define MQTT_CONNACK_LEN 2 -#define MQTT_SUBACK_LEN 3 +#define MQTT_CONNACK_LEN 2 +#define MQTT_SUBACK_LEN 3 #define MQTT_CLIENTID_LEN 12 /* "curl0123abcd" */ /* meta key for storing protocol meta at easy handle */ @@ -96,7 +89,6 @@ struct MQTT { BIT(pingsent); /* 1 while we wait for ping response */ }; - /* * Forward declarations. */ @@ -146,14 +138,14 @@ static void mqtt_easy_dtor(void *key, size_t klen, void *entry) (void)klen; curlx_dyn_free(&mq->sendbuf); curlx_dyn_free(&mq->recvbuf); - free(mq); + curlx_free(mq); } static void mqtt_conn_dtor(void *key, size_t klen, void *entry) { (void)key; (void)klen; - free(entry); + curlx_free(entry); } static CURLcode mqtt_setup_conn(struct Curl_easy *data, @@ -163,12 +155,12 @@ static CURLcode mqtt_setup_conn(struct Curl_easy *data, struct mqtt_conn *mqtt; struct MQTT *mq; - mqtt = calloc(1, sizeof(*mqtt)); + mqtt = curlx_calloc(1, sizeof(*mqtt)); if(!mqtt || Curl_conn_meta_set(conn, CURL_META_MQTT_CONN, mqtt, mqtt_conn_dtor)) return CURLE_OUT_OF_MEMORY; - mq = calloc(1, sizeof(struct MQTT)); + mq = curlx_calloc(1, sizeof(struct MQTT)); if(!mq) return CURLE_OUT_OF_MEMORY; curlx_dyn_init(&mq->recvbuf, DYN_MQTT_RECV); @@ -191,8 +183,8 @@ static CURLcode mqtt_send(struct Curl_easy *data, result = Curl_xfer_send(data, buf, len, FALSE, &n); if(result) return result; - mq->lastTime = curlx_now(); - Curl_debug(data, CURLINFO_HEADER_OUT, buf, (size_t)n); + mq->lastTime = *Curl_pgrs_now(data); + Curl_debug(data, CURLINFO_HEADER_OUT, buf, n); if(len != n) { size_t nsend = len - n; if(curlx_dyn_len(&mq->sendbuf)) { @@ -319,7 +311,7 @@ static CURLcode mqtt_connect(struct Curl_easy *data) int rc = 0; /* remain length */ int remain_pos = 0; - char remain[4] = {0}; + char remain[4] = { 0 }; size_t packetlen = 0; size_t start_user = 0; size_t start_pwd = 0; @@ -328,12 +320,10 @@ static CURLcode mqtt_connect(struct Curl_easy *data) char *packet = NULL; /* extracting username from request */ - const char *username = data->state.aptr.user ? - data->state.aptr.user : ""; + const char *username = data->state.aptr.user ? data->state.aptr.user : ""; const size_t ulen = strlen(username); /* extracting password from request */ - const char *passwd = data->state.aptr.passwd ? - data->state.aptr.passwd : ""; + const char *passwd = data->state.aptr.passwd ? data->state.aptr.passwd : ""; const size_t plen = strlen(passwd); const size_t payloadlen = ulen + plen + MQTT_CLIENTID_LEN + 2 + /* The plus 2s below are for the MSB and LSB describing the length of the @@ -350,7 +340,7 @@ static CURLcode mqtt_connect(struct Curl_easy *data) /* allocating packet */ if(packetlen > 0xFFFFFFF) return CURLE_WEIRD_SERVER_REPLY; - packet = calloc(1, packetlen); + packet = curlx_calloc(1, packetlen); if(!packet) return CURLE_OUT_OF_MEMORY; @@ -400,7 +390,7 @@ static CURLcode mqtt_connect(struct Curl_easy *data) end: if(packet) - free(packet); + curlx_free(packet); Curl_safefree(data->state.aptr.user); Curl_safefree(data->state.aptr.passwd); return result; @@ -524,7 +514,7 @@ static CURLcode mqtt_subscribe(struct Curl_easy *data) n = mqtt_encode_len((char *)encodedsize, packetlen); packetlen += n + 1; /* add one for the control packet type byte */ - packet = malloc(packetlen); + packet = curlx_malloc(packetlen); if(!packet) { result = CURLE_OUT_OF_MEMORY; goto fail; @@ -535,15 +525,15 @@ static CURLcode mqtt_subscribe(struct Curl_easy *data) packet[1 + n] = (mqtt->packetid >> 8) & 0xff; packet[2 + n] = mqtt->packetid & 0xff; packet[3 + n] = (topiclen >> 8) & 0xff; - packet[4 + n ] = topiclen & 0xff; + packet[4 + n] = topiclen & 0xff; memcpy(&packet[5 + n], topic, topiclen); packet[5 + n + topiclen] = 0; /* QoS zero */ result = mqtt_send(data, (const char *)packet, packetlen); fail: - free(topic); - free(packet); + curlx_free(topic); + curlx_free(packet); return result; } @@ -582,6 +572,8 @@ static CURLcode mqtt_verify_suback(struct Curl_easy *data) return result; } +#define MAX_MQTT_MESSAGE_SIZE 0xFFFFFFF + static CURLcode mqtt_publish(struct Curl_easy *data) { CURLcode result; @@ -600,10 +592,11 @@ static CURLcode mqtt_publish(struct Curl_easy *data) DEBUGF(infof(data, "mqtt_publish without payload, return bad arg")); return CURLE_BAD_FUNCTION_ARGUMENT; } - if(postfieldsize < 0) + if(!curlx_sotouz_fits(postfieldsize, &payloadlen)) { + if(postfieldsize > 0) /* off_t does not fit into size_t */ + return CURLE_BAD_FUNCTION_ARGUMENT; payloadlen = strlen(payload); - else - payloadlen = (size_t)postfieldsize; + } result = mqtt_get_topic(data, &topic, &topiclen); if(result) @@ -611,9 +604,13 @@ static CURLcode mqtt_publish(struct Curl_easy *data) remaininglength = payloadlen + 2 + topiclen; encodelen = mqtt_encode_len(encodedbytes, remaininglength); + if(MAX_MQTT_MESSAGE_SIZE - remaininglength - 1 < encodelen) { + result = CURLE_TOO_LARGE; + goto fail; + } /* add the control byte and the encoded remaining length */ - pkt = malloc(remaininglength + 1 + encodelen); + pkt = curlx_malloc(remaininglength + 1 + encodelen); if(!pkt) { result = CURLE_OUT_OF_MEMORY; goto fail; @@ -632,13 +629,13 @@ static CURLcode mqtt_publish(struct Curl_easy *data) result = mqtt_send(data, (const char *)pkt, i); fail: - free(pkt); - free(topic); + curlx_free(pkt); + curlx_free(topic); return result; } -static size_t mqtt_decode_len(unsigned char *buf, - size_t buflen, size_t *lenbytes) +/* return 0 on success, non-zero on error */ +static int mqtt_decode_len(size_t *lenp, unsigned char *buf, size_t buflen) { size_t len = 0; size_t mult = 1; @@ -646,19 +643,19 @@ static size_t mqtt_decode_len(unsigned char *buf, unsigned char encoded = 128; for(i = 0; (i < buflen) && (encoded & 128); i++) { + if(i == 4) + return 1; /* bad size */ encoded = buf[i]; len += (encoded & 127) * mult; mult *= 128; } - if(lenbytes) - *lenbytes = i; - - return len; + *lenp = len; + return 0; } #ifdef DEBUGBUILD -static const char *statenames[]={ +static const char *statenames[] = { "MQTT_FIRST", "MQTT_REMAINING_LENGTH", "MQTT_CONNACK", @@ -692,7 +689,6 @@ static void mqstate(struct Curl_easy *data, mqtt->nextstate = nextstate; } - static CURLcode mqtt_read_publish(struct Curl_easy *data, bool *done) { CURLcode result = CURLE_OK; @@ -753,7 +749,7 @@ static CURLcode mqtt_read_publish(struct Curl_easy *data, bool *done) FALLTHROUGH(); case MQTT_PUB_REMAIN: { /* read rest of packet, but no more. Cap to buffer size */ - char buffer[4*1024]; + char buffer[4 * 1024]; size_t rest = mq->npacket; if(rest > sizeof(buffer)) rest = sizeof(buffer); @@ -771,7 +767,7 @@ static CURLcode mqtt_read_publish(struct Curl_easy *data, bool *done) } /* we received something */ - mq->lastTime = curlx_now(); + mq->lastTime = *Curl_pgrs_now(data); /* if QoS is set, message contains packet id */ result = Curl_client_write(data, CLIENTWRITE_BODY, buffer, nread); @@ -801,7 +797,7 @@ static CURLcode mqtt_do(struct Curl_easy *data, bool *done) if(!mq) return CURLE_FAILED_INIT; - mq->lastTime = curlx_now(); + mq->lastTime = *Curl_pgrs_now(data); mq->pingsent = FALSE; result = mqtt_connect(data); @@ -840,8 +836,8 @@ static CURLcode mqtt_ping(struct Curl_easy *data) if(mqtt->state == MQTT_FIRST && !mq->pingsent && data->set.upkeep_interval_ms > 0) { - struct curltime t = curlx_now(); - timediff_t diff = curlx_timediff(t, mq->lastTime); + struct curltime t = *Curl_pgrs_now(data); + timediff_t diff = curlx_ptimediff_ms(&t, &mq->lastTime); if(diff > data->set.upkeep_interval_ms) { /* 0xC0 is PINGREQ, and 0x00 is remaining length */ @@ -883,7 +879,7 @@ static CURLcode mqtt_doing(struct Curl_easy *data, bool *done) if(result) return result; - infof(data, "mqtt_doing: state [%d]", (int) mqtt->state); + infof(data, "mqtt_doing: state [%d]", (int)mqtt->state); switch(mqtt->state) { case MQTT_FIRST: /* Read the initial byte only */ @@ -899,7 +895,7 @@ static CURLcode mqtt_doing(struct Curl_easy *data, bool *done) Curl_debug(data, CURLINFO_HEADER_IN, (const char *)&mq->firstbyte, 1); /* we received something */ - mq->lastTime = curlx_now(); + mq->lastTime = *Curl_pgrs_now(data); /* remember the first byte */ mq->npacket = 0; @@ -919,7 +915,10 @@ static CURLcode mqtt_doing(struct Curl_easy *data, bool *done) result = CURLE_WEIRD_SERVER_REPLY; if(result) break; - mq->remaining_length = mqtt_decode_len(mq->pkt_hd, mq->npacket, NULL); + if(mqtt_decode_len(&mq->remaining_length, mq->pkt_hd, mq->npacket)) { + result = CURLE_WEIRD_SERVER_REPLY; + break; + } mq->npacket = 0; if(mq->remaining_length) { mqstate(data, mqtt->nextstate, MQTT_NOSTATE); diff --git a/vendor/hydra/vendor/curl/lib/mqtt.h b/vendor/hydra/vendor/curl/lib/mqtt.h index 8fb8a33c..3e45815b 100644 --- a/vendor/hydra/vendor/curl/lib/mqtt.h +++ b/vendor/hydra/vendor/curl/lib/mqtt.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #ifndef CURL_DISABLE_MQTT extern const struct Curl_handler Curl_handler_mqtt; #endif diff --git a/vendor/hydra/vendor/curl/lib/multi.c b/vendor/hydra/vendor/curl/lib/multi.c index c27e8bda..7cfd053c 100644 --- a/vendor/hydra/vendor/curl/lib/multi.c +++ b/vendor/hydra/vendor/curl/lib/multi.c @@ -21,29 +21,23 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include - #include "urldata.h" #include "transfer.h" #include "url.h" #include "cfilters.h" #include "connect.h" #include "progress.h" -#include "easyif.h" -#include "share.h" +#include "curl_share.h" #include "psl.h" #include "multiif.h" #include "multi_ev.h" #include "sendf.h" -#include "curlx/timeval.h" +#include "curl_trc.h" #include "http.h" #include "select.h" -#include "curlx/warnless.h" #include "curlx/wait.h" -#include "speedcheck.h" #include "conncache.h" #include "multihandle.h" #include "sigpipe.h" @@ -52,15 +46,10 @@ #include "http_proxy.h" #include "http2.h" #include "socketpair.h" -#include "socks.h" -#include "urlapi-int.h" - -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" +#include "bufref.h" /* initial multi->xfers table size for a full multi */ -#define CURL_XFER_TABLE_SIZE 512 +#define CURL_XFER_TABLE_SIZE 512 /* CURL_SOCKET_HASH_TABLE_SIZE should be a prime number. Increasing it from 97 @@ -85,6 +74,7 @@ #define CURL_MULTI_HANDLE 0x000bab1e + #ifdef DEBUGBUILD /* On a debug build, we want to fail hard on multi handles that * are not NULL, but no longer have the MAGIC touch. This gives @@ -99,18 +89,24 @@ static void move_pending_to_connect(struct Curl_multi *multi, struct Curl_easy *data); -static CURLMcode add_next_timeout(struct curltime now, +static CURLMcode add_next_timeout(const struct curltime *pnow, struct Curl_multi *multi, struct Curl_easy *d); -static CURLMcode multi_timeout(struct Curl_multi *multi, - struct curltime *expire_time, - long *timeout_ms); +static void multi_timeout(struct Curl_multi *multi, + struct curltime *expire_time, + long *timeout_ms); static void process_pending_handles(struct Curl_multi *multi); static void multi_xfer_bufs_free(struct Curl_multi *multi); #ifdef DEBUGBUILD static void multi_xfer_tbl_dump(struct Curl_multi *multi); #endif +static const struct curltime *multi_now(struct Curl_multi *multi) +{ + curlx_pnow(&multi->now); + return &multi->now; +} + /* function pointer called once when switching TO a state */ typedef void (*init_multistate_func)(struct Curl_easy *data); @@ -146,7 +142,6 @@ static void mstate(struct Curl_easy *data, CURLMstate state Curl_init_CONNECT, /* CONNECT */ NULL, /* RESOLVING */ NULL, /* CONNECTING */ - NULL, /* TUNNELING */ NULL, /* PROTOCONNECT */ NULL, /* PROTOCONNECTING */ NULL, /* DO */ @@ -170,6 +165,7 @@ static void mstate(struct Curl_easy *data, CURLMstate state CURL_TRC_M(data, "-> [%s]", CURL_MSTATE_NAME(state)); #endif + /* really switching state */ data->mstate = state; switch(state) { case MSTATE_DONE: @@ -181,11 +177,11 @@ static void mstate(struct Curl_easy *data, CURLMstate state if(oldstate < MSTATE_DONE) CURLM_NTFY(data, CURLMNOTIFY_EASY_DONE); /* changing to COMPLETED means it is in process and needs to go */ - DEBUGASSERT(Curl_uint_bset_contains(&data->multi->process, data->mid)); - Curl_uint_bset_remove(&data->multi->process, data->mid); - Curl_uint_bset_remove(&data->multi->pending, data->mid); /* to be sure */ + DEBUGASSERT(Curl_uint32_bset_contains(&data->multi->process, data->mid)); + Curl_uint32_bset_remove(&data->multi->process, data->mid); + Curl_uint32_bset_remove(&data->multi->pending, data->mid); /* to be sure */ - if(Curl_uint_bset_empty(&data->multi->process)) { + if(Curl_uint32_bset_empty(&data->multi->process)) { /* free the transfer buffer when we have no more active transfers */ multi_xfer_bufs_free(data->multi); } @@ -200,12 +196,11 @@ static void mstate(struct Curl_easy *data, CURLMstate state } #ifndef DEBUGBUILD -#define multistate(x,y) mstate(x,y) +#define multistate(x, y) mstate(x, y) #else -#define multistate(x,y) mstate(x,y, __LINE__) +#define multistate(x, y) mstate(x, y, __LINE__) #endif - /* multi->proto_hash destructor. Should never be called as elements * MUST be added with their own destructor */ static void ph_freeentry(void *p) @@ -230,13 +225,13 @@ static void multi_addmsg(struct Curl_multi *multi, struct Curl_message *msg) Curl_llist_append(&multi->msglist, msg, &msg->list); } -struct Curl_multi *Curl_multi_handle(unsigned int xfer_table_size, +struct Curl_multi *Curl_multi_handle(uint32_t xfer_table_size, size_t ev_hashsize, /* event hash */ size_t chashsize, /* connection hash */ size_t dnssize, /* dns hash */ size_t sesssize) /* TLS session cache */ { - struct Curl_multi *multi = calloc(1, sizeof(struct Curl_multi)); + struct Curl_multi *multi = curlx_calloc(1, sizeof(struct Curl_multi)); if(!multi) return NULL; @@ -246,11 +241,11 @@ struct Curl_multi *Curl_multi_handle(unsigned int xfer_table_size, Curl_dnscache_init(&multi->dnscache, dnssize); Curl_mntfy_init(multi); Curl_multi_ev_init(multi, ev_hashsize); - Curl_uint_tbl_init(&multi->xfers, NULL); - Curl_uint_bset_init(&multi->process); - Curl_uint_bset_init(&multi->dirty); - Curl_uint_bset_init(&multi->pending); - Curl_uint_bset_init(&multi->msgsent); + Curl_uint32_tbl_init(&multi->xfers, NULL); + Curl_uint32_bset_init(&multi->process); + Curl_uint32_bset_init(&multi->dirty); + Curl_uint32_bset_init(&multi->pending); + Curl_uint32_bset_init(&multi->msgsent); Curl_hash_init(&multi->proto_hash, 23, Curl_hash_str, curlx_str_key_compare, ph_freeentry); Curl_llist_init(&multi->msglist, NULL); @@ -260,11 +255,11 @@ struct Curl_multi *Curl_multi_handle(unsigned int xfer_table_size, multi->last_timeout_ms = -1; if(Curl_mntfy_resize(multi) || - Curl_uint_bset_resize(&multi->process, xfer_table_size) || - Curl_uint_bset_resize(&multi->pending, xfer_table_size) || - Curl_uint_bset_resize(&multi->dirty, xfer_table_size) || - Curl_uint_bset_resize(&multi->msgsent, xfer_table_size) || - Curl_uint_tbl_resize(&multi->xfers, xfer_table_size)) + Curl_uint32_bset_resize(&multi->process, xfer_table_size) || + Curl_uint32_bset_resize(&multi->pending, xfer_table_size) || + Curl_uint32_bset_resize(&multi->dirty, xfer_table_size) || + Curl_uint32_bset_resize(&multi->msgsent, xfer_table_size) || + Curl_uint32_tbl_resize(&multi->xfers, xfer_table_size)) goto error; multi->admin = curl_easy_init(); @@ -274,11 +269,13 @@ struct Curl_multi *Curl_multi_handle(unsigned int xfer_table_size, multi->admin->multi = multi; multi->admin->state.internal = TRUE; Curl_llist_init(&multi->admin->state.timeoutlist, NULL); + #ifdef DEBUGBUILD if(getenv("CURL_DEBUG")) multi->admin->set.verbose = TRUE; #endif - Curl_uint_tbl_add(&multi->xfers, multi->admin, &multi->admin->mid); + Curl_uint32_tbl_add(&multi->xfers, multi->admin, &multi->admin->mid); + Curl_uint32_bset_add(&multi->process, multi->admin->mid); if(Curl_cshutdn_init(&multi->cshutdn, multi)) goto error; @@ -321,13 +318,13 @@ struct Curl_multi *Curl_multi_handle(unsigned int xfer_table_size, } Curl_mntfy_cleanup(multi); - Curl_uint_bset_destroy(&multi->process); - Curl_uint_bset_destroy(&multi->dirty); - Curl_uint_bset_destroy(&multi->pending); - Curl_uint_bset_destroy(&multi->msgsent); - Curl_uint_tbl_destroy(&multi->xfers); + Curl_uint32_bset_destroy(&multi->process); + Curl_uint32_bset_destroy(&multi->dirty); + Curl_uint32_bset_destroy(&multi->pending); + Curl_uint32_bset_destroy(&multi->msgsent); + Curl_uint32_tbl_destroy(&multi->xfers); - free(multi); + curlx_free(multi); return NULL; } @@ -346,24 +343,23 @@ static void multi_warn_debug(struct Curl_multi *multi, struct Curl_easy *data) if(!multi->warned) { infof(data, "!!! WARNING !!!"); infof(data, "This is a debug build of libcurl, " - "do not use in production."); + "do not use in production."); multi->warned = TRUE; } } #else -#define multi_warn_debug(x,y) Curl_nop_stmt +#define multi_warn_debug(x, y) Curl_nop_stmt #endif - static CURLMcode multi_xfers_add(struct Curl_multi *multi, struct Curl_easy *data) { - unsigned int capacity = Curl_uint_tbl_capacity(&multi->xfers); - unsigned int new_size = 0; + uint32_t capacity = Curl_uint32_tbl_capacity(&multi->xfers); + uint32_t new_size = 0; /* Prepare to make this into a CURLMOPT_MAX_TRANSFERS, because some * applications may want to prevent a run-away of their memory use. */ /* UINT_MAX is our "invalid" id, do not let the table grow up to that. */ - const unsigned int max_capacity = UINT_MAX - 1; + const uint32_t max_capacity = UINT_MAX - 1; if(capacity < max_capacity) { /* We want `multi->xfers` to have "sufficient" free rows, so that we do @@ -371,9 +367,9 @@ static CURLMcode multi_xfers_add(struct Curl_multi *multi, * Since uint_tbl and uint_bset are quite memory efficient, * regard less than 25% free as insufficient. * (for low capacities, e.g. multi_easy, 4 or less). */ - unsigned int used = Curl_uint_tbl_count(&multi->xfers); - unsigned int unused = capacity - used; - unsigned int min_unused = CURLMAX(capacity >> 2, 4); + uint32_t used = Curl_uint32_tbl_count(&multi->xfers); + uint32_t unused = capacity - used; + uint32_t min_unused = CURLMAX(capacity >> 2, 4); if(unused <= min_unused) { /* Make sure the uint arithmetic here works on the corner * cases where we are close to max_capacity or UINT_MAX */ @@ -383,8 +379,8 @@ static CURLMcode multi_xfers_add(struct Curl_multi *multi, new_size = max_capacity; /* can not be larger than this */ } else { - /* make it a 64 multiple, since our bitsets frow by that and - * small (easy_multi) grows to at least 64 on first resize. */ + /* make it a 64 multiple, since our bitsets frow by that and + * small (easy_multi) grows to at least 64 on first resize. */ new_size = (((used + min_unused) + 63) / 64) * 64; } } @@ -396,30 +392,30 @@ static CURLMcode multi_xfers_add(struct Curl_multi *multi, * to work properly when larger than the table, but not * the other way around. */ CURL_TRC_M(data, "increasing xfer table size to %u", new_size); - if(Curl_uint_bset_resize(&multi->process, new_size) || - Curl_uint_bset_resize(&multi->dirty, new_size) || - Curl_uint_bset_resize(&multi->pending, new_size) || - Curl_uint_bset_resize(&multi->msgsent, new_size) || - Curl_uint_tbl_resize(&multi->xfers, new_size)) + if(Curl_uint32_bset_resize(&multi->process, new_size) || + Curl_uint32_bset_resize(&multi->dirty, new_size) || + Curl_uint32_bset_resize(&multi->pending, new_size) || + Curl_uint32_bset_resize(&multi->msgsent, new_size) || + Curl_uint32_tbl_resize(&multi->xfers, new_size)) return CURLM_OUT_OF_MEMORY; } /* Insert the easy into the table now */ - if(!Curl_uint_tbl_add(&multi->xfers, data, &data->mid)) { + if(!Curl_uint32_tbl_add(&multi->xfers, data, &data->mid)) { /* MUST only happen when table is full */ - DEBUGASSERT(Curl_uint_tbl_capacity(&multi->xfers) <= - Curl_uint_tbl_count(&multi->xfers)); + DEBUGASSERT(Curl_uint32_tbl_capacity(&multi->xfers) <= + Curl_uint32_tbl_count(&multi->xfers)); return CURLM_OUT_OF_MEMORY; } return CURLM_OK; } - CURLMcode curl_multi_add_handle(CURLM *m, CURL *d) { - CURLMcode rc; + CURLMcode mresult; struct Curl_multi *multi = m; struct Curl_easy *data = d; + /* First, make some basic checks that the CURLM handle is a good handle */ if(!GOOD_MULTI_HANDLE(multi)) return CURLM_BAD_HANDLE; @@ -441,14 +437,14 @@ CURLMcode curl_multi_add_handle(CURLM *m, CURL *d) handles are still alive - but if there are none alive anymore, it is fine to start over and unmark the "deadness" of this handle. This means only the admin handle MUST be present. */ - if((Curl_uint_tbl_count(&multi->xfers) != 1) || - !Curl_uint_tbl_contains(&multi->xfers, 0)) + if((Curl_uint32_tbl_count(&multi->xfers) != 1) || + !Curl_uint32_tbl_contains(&multi->xfers, 0)) return CURLM_ABORTED_BY_CALLBACK; multi->dead = FALSE; - Curl_uint_bset_clear(&multi->process); - Curl_uint_bset_clear(&multi->dirty); - Curl_uint_bset_clear(&multi->pending); - Curl_uint_bset_clear(&multi->msgsent); + Curl_uint32_bset_clear(&multi->process); + Curl_uint32_bset_clear(&multi->dirty); + Curl_uint32_bset_clear(&multi->pending); + Curl_uint32_bset_clear(&multi->msgsent); } if(data->multi_easy) { @@ -492,7 +488,7 @@ CURLMcode curl_multi_add_handle(CURLM *m, CURL *d) #endif /* add the easy handle to the process set */ - Curl_uint_bset_add(&multi->process, data->mid); + Curl_uint32_bset_add(&multi->process, data->mid); ++multi->xfers_alive; ++multi->xfers_total_ever; @@ -501,14 +497,15 @@ CURLMcode curl_multi_add_handle(CURLM *m, CURL *d) /* Make sure the new handle will run */ Curl_multi_mark_dirty(data); + /* Necessary in event based processing, where dirty handles trigger * a timeout callback invocation. */ - rc = Curl_update_timer(multi); - if(rc) { + mresult = Curl_update_timer(multi); + if(mresult) { data->multi = NULL; /* not anymore */ - Curl_uint_tbl_remove(&multi->xfers, data->mid); - data->mid = UINT_MAX; - return rc; + Curl_uint32_tbl_remove(&multi->xfers, data->mid); + data->mid = UINT32_MAX; + return mresult; } /* The admin handle only ever has default timeouts set. To improve the @@ -522,7 +519,7 @@ CURLMcode curl_multi_add_handle(CURLM *m, CURL *d) CURL_TRC_M(data, "added to multi, mid=%u, running=%u, total=%u", data->mid, Curl_multi_xfers_running(multi), - Curl_uint_tbl_count(&multi->xfers)); + Curl_uint32_tbl_count(&multi->xfers)); return CURLM_OK; } @@ -546,6 +543,47 @@ struct multi_done_ctx { BIT(premature); }; +static bool multi_conn_should_close(struct connectdata *conn, + struct Curl_easy *data, + bool premature) +{ + /* if conn->bits.close is TRUE, it means that the connection should be + closed in spite of everything else. */ + if(conn->bits.close) + return TRUE; + + /* if data->set.reuse_forbid is TRUE, it means the libcurl client has + forced us to close this connection. This is ignored for requests taking + place in a NTLM/NEGOTIATE authentication handshake. */ + if(data->set.reuse_forbid +#ifdef USE_NTLM + && !(conn->http_ntlm_state == NTLMSTATE_TYPE2 || + conn->proxy_ntlm_state == NTLMSTATE_TYPE2) +#endif +#ifdef USE_SPNEGO + && !(conn->http_negotiate_state == GSS_AUTHRECV || + conn->proxy_negotiate_state == GSS_AUTHRECV) +#endif + ) + return TRUE; + + /* Unless this connection is for a "connect-only" transfer, it + * needs to be closed if the protocol handler does not support reuse. */ + if(!data->set.connect_only && conn->handler && + !(conn->handler->flags & PROTOPT_CONN_REUSE)) + return TRUE; + + /* if premature is TRUE, it means this connection was said to be DONE before + the entire request operation is complete and thus we cannot know in what + state it is for reusing, so we are forced to close it. In a perfect world + we can add code that keep track of if we really must close it here or not, + but currently we have no such detail knowledge. */ + if(premature && !Curl_conn_is_multiplex(conn, FIRSTSOCKET)) + return TRUE; + + return FALSE; +} + static void multi_done_locked(struct connectdata *conn, struct Curl_easy *data, void *userdata) @@ -570,12 +608,11 @@ static void multi_done_locked(struct connectdata *conn, Curl_detach_connection(data); - CURL_TRC_M(data, "multi_done_locked, in use=%u", - Curl_uint_spbset_count(&conn->xfers_attached)); + CURL_TRC_M(data, "multi_done_locked, in use=%u", conn->attached_xfers); if(CONN_INUSE(conn)) { /* Stop if still used. */ CURL_TRC_M(data, "Connection still in use %u, no more multi_done now!", - Curl_uint_spbset_count(&conn->xfers_attached)); + conn->attached_xfers); return; } @@ -586,32 +623,7 @@ static void multi_done_locked(struct connectdata *conn, Curl_resolv_unlink(data, &data->state.dns[1]); Curl_dnscache_prune(data); - /* if data->set.reuse_forbid is TRUE, it means the libcurl client has - forced us to close this connection. This is ignored for requests taking - place in a NTLM/NEGOTIATE authentication handshake - - if conn->bits.close is TRUE, it means that the connection should be - closed in spite of all our efforts to be nice, due to protocol - restrictions in our or the server's end - - if premature is TRUE, it means this connection was said to be DONE before - the entire request operation is complete and thus we cannot know in what - state it is for reusing, so we are forced to close it. In a perfect world - we can add code that keep track of if we really must close it here or not, - but currently we have no such detail knowledge. - */ - - if((data->set.reuse_forbid -#ifdef USE_NTLM - && !(conn->http_ntlm_state == NTLMSTATE_TYPE2 || - conn->proxy_ntlm_state == NTLMSTATE_TYPE2) -#endif -#ifdef USE_SPNEGO - && !(conn->http_negotiate_state == GSS_AUTHRECV || - conn->proxy_negotiate_state == GSS_AUTHRECV) -#endif - ) || conn->bits.close - || (mdctx->premature && !Curl_conn_is_multiplex(conn, FIRSTSOCKET))) { + if(multi_conn_should_close(conn, data, mdctx->premature)) { #ifndef CURL_DISABLE_VERBOSE_STRINGS CURL_TRC_M(data, "multi_done, terminating conn #%" FMT_OFF_T " to %s:%d, " "forbid=%d, close=%d, premature=%d, conn_multiplex=%d", @@ -737,9 +749,9 @@ CURLMcode curl_multi_remove_handle(CURLM *m, CURL *d) struct Curl_easy *data = d; bool premature; struct Curl_llist_node *e; - CURLMcode rc; + CURLMcode mresult; bool removed_timer = FALSE; - unsigned int mid; + uint32_t mid; /* First, make some basic checks that the CURLM handle is a good handle */ if(!GOOD_MULTI_HANDLE(multi)) @@ -757,11 +769,11 @@ CURLMcode curl_multi_remove_handle(CURLM *m, CURL *d) if(data->multi != multi) return CURLM_BAD_EASY_HANDLE; - if(data->mid == UINT_MAX) { + if(data->mid == UINT32_MAX) { DEBUGASSERT(0); return CURLM_INTERNAL_ERROR; } - if(Curl_uint_tbl_get(&multi->xfers, data->mid) != data) { + if(Curl_uint32_tbl_get(&multi->xfers, data->mid) != data) { DEBUGASSERT(0); return CURLM_INTERNAL_ERROR; } @@ -796,7 +808,7 @@ CURLMcode curl_multi_remove_handle(CURLM *m, CURL *d) removed_timer = Curl_expire_clear(data); /* If in `msgsent`, it was deducted from `multi->xfers_alive` already. */ - if(!Curl_uint_bset_contains(&multi->msgsent, data->mid)) + if(!Curl_uint32_bset_contains(&multi->msgsent, data->mid)) --multi->xfers_alive; Curl_wildcard_dtor(&data->wildcard); @@ -829,7 +841,7 @@ CURLMcode curl_multi_remove_handle(CURLM *m, CURL *d) if(data->state.lastconnect_id != -1) { /* Mark any connect-only connection for closure */ Curl_cpool_do_by_id(data, data->state.lastconnect_id, - close_connect_only, NULL); + close_connect_only, NULL); } #ifdef USE_LIBPSL @@ -852,29 +864,29 @@ CURLMcode curl_multi_remove_handle(CURLM *m, CURL *d) /* clear the association to this multi handle */ mid = data->mid; - DEBUGASSERT(Curl_uint_tbl_contains(&multi->xfers, mid)); - Curl_uint_tbl_remove(&multi->xfers, mid); - Curl_uint_bset_remove(&multi->process, mid); - Curl_uint_bset_remove(&multi->dirty, mid); - Curl_uint_bset_remove(&multi->pending, mid); - Curl_uint_bset_remove(&multi->msgsent, mid); + DEBUGASSERT(Curl_uint32_tbl_contains(&multi->xfers, mid)); + Curl_uint32_tbl_remove(&multi->xfers, mid); + Curl_uint32_bset_remove(&multi->process, mid); + Curl_uint32_bset_remove(&multi->dirty, mid); + Curl_uint32_bset_remove(&multi->pending, mid); + Curl_uint32_bset_remove(&multi->msgsent, mid); data->multi = NULL; - data->mid = UINT_MAX; - data->master_mid = UINT_MAX; + data->mid = UINT32_MAX; + data->master_mid = UINT32_MAX; /* NOTE NOTE NOTE We do not touch the easy handle here! */ process_pending_handles(multi); if(removed_timer) { - rc = Curl_update_timer(multi); - if(rc) - return rc; + mresult = Curl_update_timer(multi); + if(mresult) + return mresult; } CURL_TRC_M(data, "removed from multi, mid=%u, running=%u, total=%u", mid, Curl_multi_xfers_running(multi), - Curl_uint_tbl_count(&multi->xfers)); + Curl_uint32_tbl_count(&multi->xfers)); return CURLM_OK; } @@ -894,9 +906,13 @@ void Curl_detach_connection(struct Curl_easy *data) { struct connectdata *conn = data->conn; if(conn) { - Curl_uint_spbset_remove(&conn->xfers_attached, data->mid); - if(Curl_uint_spbset_empty(&conn->xfers_attached)) - conn->attached_multi = NULL; + /* this should never happen, prevent underflow */ + DEBUGASSERT(conn->attached_xfers); + if(conn->attached_xfers) { + conn->attached_xfers--; + if(!conn->attached_xfers) + conn->attached_multi = NULL; + } } data->conn = NULL; } @@ -912,8 +928,9 @@ void Curl_attach_connection(struct Curl_easy *data, DEBUGASSERT(data); DEBUGASSERT(!data->conn); DEBUGASSERT(conn); + DEBUGASSERT(conn->attached_xfers < UINT32_MAX); data->conn = conn; - Curl_uint_spbset_add(&conn->xfers_attached, data->mid); + conn->attached_xfers++; /* all attached transfers must be from the same multi */ if(!conn->attached_multi) conn->attached_multi = data->multi; @@ -923,102 +940,167 @@ void Curl_attach_connection(struct Curl_easy *data, conn->handler->attach(data, conn); } +/* adjust pollset for rate limits/pauses */ +static CURLcode multi_adjust_pollset(struct Curl_easy *data, + struct easy_pollset *ps) +{ + CURLcode result = CURLE_OK; + + if(ps->n) { + const struct curltime *pnow = Curl_pgrs_now(data); + bool send_blocked, recv_blocked; + + recv_blocked = (Curl_rlimit_avail(&data->progress.dl.rlimit, pnow) <= 0); + send_blocked = (Curl_rlimit_avail(&data->progress.ul.rlimit, pnow) <= 0); + if(send_blocked || recv_blocked) { + int i; + for(i = 0; i <= SECONDARYSOCKET; ++i) { + curl_socket_t sock = data->conn->sock[i]; + if(sock == CURL_SOCKET_BAD) + continue; + if(recv_blocked && Curl_pollset_want_recv(data, ps, sock)) { + result = Curl_pollset_remove_in(data, ps, sock); + if(result) + break; + } + if(send_blocked && Curl_pollset_want_send(data, ps, sock)) { + result = Curl_pollset_remove_out(data, ps, sock); + if(result) + break; + } + } + } + + /* Not blocked and wanting to receive. If there is data pending + * in the connection filters, make transfer run again. */ + if(!recv_blocked && + ((Curl_pollset_want_recv(data, ps, data->conn->sock[FIRSTSOCKET]) && + Curl_conn_data_pending(data, FIRSTSOCKET)) || + (Curl_pollset_want_recv(data, ps, data->conn->sock[SECONDARYSOCKET]) && + Curl_conn_data_pending(data, SECONDARYSOCKET)))) { + CURL_TRC_M(data, "pollset[] has POLLIN, but there is still " + "buffered input -> mark as dirty"); + Curl_multi_mark_dirty(data); + } + } + return result; +} + static CURLcode mstate_connecting_pollset(struct Curl_easy *data, struct easy_pollset *ps) { - if(data->conn) { - curl_socket_t sockfd = Curl_conn_get_first_socket(data); - if(sockfd != CURL_SOCKET_BAD) { - /* Default is to wait to something from the server */ - return Curl_pollset_change(data, ps, sockfd, CURL_POLL_IN, 0); - } + struct connectdata *conn = data->conn; + curl_socket_t sockfd; + CURLcode result = CURLE_OK; + + if(Curl_xfer_recv_is_paused(data)) + return CURLE_OK; + /* If a socket is set, receiving is default. If the socket + * has not been determined yet (eyeballing), always ask the + * connection filters for what to monitor. */ + sockfd = Curl_conn_get_first_socket(data); + if(sockfd != CURL_SOCKET_BAD) { + result = Curl_pollset_change(data, ps, sockfd, CURL_POLL_IN, 0); + if(!result) + result = multi_adjust_pollset(data, ps); } - return CURLE_OK; + if(!result) + result = Curl_conn_adjust_pollset(data, conn, ps); + return result; } static CURLcode mstate_protocol_pollset(struct Curl_easy *data, struct easy_pollset *ps) { struct connectdata *conn = data->conn; - if(conn) { - curl_socket_t sockfd; - if(conn->handler->proto_pollset) - return conn->handler->proto_pollset(data, ps); - sockfd = conn->sock[FIRSTSOCKET]; + CURLcode result = CURLE_OK; + + if(conn->handler->proto_pollset) + result = conn->handler->proto_pollset(data, ps); + else { + curl_socket_t sockfd = conn->sock[FIRSTSOCKET]; if(sockfd != CURL_SOCKET_BAD) { /* Default is to wait to something from the server */ - return Curl_pollset_change(data, ps, sockfd, CURL_POLL_IN, 0); + result = Curl_pollset_change(data, ps, sockfd, CURL_POLL_IN, 0); } } - return CURLE_OK; + if(!result) + result = multi_adjust_pollset(data, ps); + if(!result) + result = Curl_conn_adjust_pollset(data, conn, ps); + return result; } static CURLcode mstate_do_pollset(struct Curl_easy *data, struct easy_pollset *ps) { struct connectdata *conn = data->conn; - if(conn) { - if(conn->handler->doing_pollset) - return conn->handler->doing_pollset(data, ps); - else if(CONN_SOCK_IDX_VALID(conn->send_idx)) { - /* Default is that we want to send something to the server */ - return Curl_pollset_add_out( - data, ps, conn->sock[conn->send_idx]); - } + CURLcode result = CURLE_OK; + + if(conn->handler->doing_pollset) + result = conn->handler->doing_pollset(data, ps); + else if(CONN_SOCK_IDX_VALID(conn->send_idx)) { + /* Default is that we want to send something to the server */ + result = Curl_pollset_add_out(data, ps, conn->sock[conn->send_idx]); } - return CURLE_OK; + if(!result) + result = multi_adjust_pollset(data, ps); + if(!result) + result = Curl_conn_adjust_pollset(data, conn, ps); + return result; } static CURLcode mstate_domore_pollset(struct Curl_easy *data, struct easy_pollset *ps) { struct connectdata *conn = data->conn; - if(conn) { - if(conn->handler->domore_pollset) - return conn->handler->domore_pollset(data, ps); - else if(CONN_SOCK_IDX_VALID(conn->send_idx)) { - /* Default is that we want to send something to the server */ - return Curl_pollset_add_out( - data, ps, conn->sock[conn->send_idx]); - } + CURLcode result = CURLE_OK; + + if(conn->handler->domore_pollset) + result = conn->handler->domore_pollset(data, ps); + else if(CONN_SOCK_IDX_VALID(conn->send_idx)) { + /* Default is that we want to send something to the server */ + result = Curl_pollset_add_out(data, ps, conn->sock[conn->send_idx]); } - return CURLE_OK; + if(!result) + result = multi_adjust_pollset(data, ps); + if(!result) + result = Curl_conn_adjust_pollset(data, conn, ps); + return result; } static CURLcode mstate_perform_pollset(struct Curl_easy *data, struct easy_pollset *ps) { struct connectdata *conn = data->conn; - if(!conn) - return CURLE_OK; - else if(conn->handler->perform_pollset) - return conn->handler->perform_pollset(data, ps); + CURLcode result = CURLE_OK; + + if(conn->handler->perform_pollset) + result = conn->handler->perform_pollset(data, ps); else { /* Default is to obey the data->req.keepon flags for send/recv */ - CURLcode result = CURLE_OK; - if(CURL_WANT_RECV(data) && CONN_SOCK_IDX_VALID(conn->recv_idx)) { - result = Curl_pollset_add_in( - data, ps, conn->sock[conn->recv_idx]); + if(Curl_req_want_recv(data) && CONN_SOCK_IDX_VALID(conn->recv_idx)) { + result = Curl_pollset_add_in(data, ps, conn->sock[conn->recv_idx]); } - if(!result && Curl_req_want_send(data) && CONN_SOCK_IDX_VALID(conn->send_idx)) { - result = Curl_pollset_add_out( - data, ps, conn->sock[conn->send_idx]); + result = Curl_pollset_add_out(data, ps, conn->sock[conn->send_idx]); } - return result; } + if(!result) + result = multi_adjust_pollset(data, ps); + if(!result) + result = Curl_conn_adjust_pollset(data, conn, ps); + return result; } /* Initializes `poll_set` with the current socket poll actions needed * for transfer `data`. */ CURLMcode Curl_multi_pollset(struct Curl_easy *data, - struct easy_pollset *ps, - const char *caller) + struct easy_pollset *ps) { CURLMcode mresult = CURLM_OK; CURLcode result = CURLE_OK; - bool expect_sockets = TRUE; /* If the transfer has no connection, this is fine. Happens when called via curl_multi_remove_handle() => Curl_multi_ev_assess() => @@ -1033,70 +1115,48 @@ CURLMcode Curl_multi_pollset(struct Curl_easy *data, case MSTATE_SETUP: case MSTATE_CONNECT: /* nothing to poll for yet */ - expect_sockets = FALSE; break; case MSTATE_RESOLVING: result = Curl_resolv_pollset(data, ps); - /* connection filters are not involved in this phase. It's ok if we get no - * sockets to wait for. Resolving can wake up from other sources. */ - expect_sockets = FALSE; break; case MSTATE_CONNECTING: - case MSTATE_TUNNELING: - if(!Curl_xfer_recv_is_paused(data)) { - result = mstate_connecting_pollset(data, ps); - if(!result) - result = Curl_conn_adjust_pollset(data, data->conn, ps); - } - else - expect_sockets = FALSE; + result = mstate_connecting_pollset(data, ps); break; case MSTATE_PROTOCONNECT: case MSTATE_PROTOCONNECTING: result = mstate_protocol_pollset(data, ps); - if(!result) - result = Curl_conn_adjust_pollset(data, data->conn, ps); break; case MSTATE_DO: case MSTATE_DOING: result = mstate_do_pollset(data, ps); - if(!result) - result = Curl_conn_adjust_pollset(data, data->conn, ps); break; case MSTATE_DOING_MORE: result = mstate_domore_pollset(data, ps); - if(!result) - result = Curl_conn_adjust_pollset(data, data->conn, ps); break; case MSTATE_DID: /* same as PERFORMING in regard to polling */ case MSTATE_PERFORMING: result = mstate_perform_pollset(data, ps); - if(!result) - result = Curl_conn_adjust_pollset(data, data->conn, ps); break; case MSTATE_RATELIMITING: /* we need to let time pass, ignore socket(s) */ - expect_sockets = FALSE; break; case MSTATE_DONE: case MSTATE_COMPLETED: case MSTATE_MSGSENT: /* nothing more to poll for */ - expect_sockets = FALSE; break; default: failf(data, "multi_getsock: unexpected multi state %d", data->mstate); DEBUGASSERT(0); - expect_sockets = FALSE; break; } @@ -1110,68 +1170,42 @@ CURLMcode Curl_multi_pollset(struct Curl_easy *data, goto out; } - /* Unblocked and waiting to receive with buffered input. - * Make transfer run again at next opportunity. */ - if(!Curl_xfer_is_blocked(data) && !Curl_xfer_is_too_fast(data) && - ((Curl_pollset_want_read(data, ps, data->conn->sock[FIRSTSOCKET]) && - Curl_conn_data_pending(data, FIRSTSOCKET)) || - (Curl_pollset_want_read(data, ps, data->conn->sock[SECONDARYSOCKET]) && - Curl_conn_data_pending(data, SECONDARYSOCKET)))) { - CURL_TRC_M(data, "%s pollset[] has POLLIN, but there is still " - "buffered input to consume -> mark as dirty", caller); - Curl_multi_mark_dirty(data); - } - #ifndef CURL_DISABLE_VERBOSE_STRINGS if(CURL_TRC_M_is_verbose(data)) { size_t timeout_count = Curl_llist_count(&data->state.timeoutlist); switch(ps->n) { - case 0: - CURL_TRC_M(data, "%s pollset[], timeouts=%zu, paused %d/%d (r/w)", - caller, timeout_count, - Curl_xfer_send_is_paused(data), - Curl_xfer_recv_is_paused(data)); - break; - case 1: - CURL_TRC_M(data, "%s pollset[fd=%" FMT_SOCKET_T " %s%s], timeouts=%zu", - caller, ps->sockets[0], - (ps->actions[0] & CURL_POLL_IN) ? "IN" : "", - (ps->actions[0] & CURL_POLL_OUT) ? "OUT" : "", - timeout_count); - break; - case 2: - CURL_TRC_M(data, "%s pollset[fd=%" FMT_SOCKET_T " %s%s, " - "fd=%" FMT_SOCKET_T " %s%s], timeouts=%zu", - caller, ps->sockets[0], - (ps->actions[0] & CURL_POLL_IN) ? "IN" : "", - (ps->actions[0] & CURL_POLL_OUT) ? "OUT" : "", - ps->sockets[1], - (ps->actions[1] & CURL_POLL_IN) ? "IN" : "", - (ps->actions[1] & CURL_POLL_OUT) ? "OUT" : "", - timeout_count); - break; - default: - CURL_TRC_M(data, "%s pollset[fds=%u], timeouts=%zu", - caller, ps->n, timeout_count); - break; + case 0: + CURL_TRC_M(data, "pollset[], timeouts=%zu, paused %d/%d (r/w)", + timeout_count, + Curl_xfer_send_is_paused(data), + Curl_xfer_recv_is_paused(data)); + break; + case 1: + CURL_TRC_M(data, "pollset[fd=%" FMT_SOCKET_T " %s%s], timeouts=%zu", + ps->sockets[0], + (ps->actions[0] & CURL_POLL_IN) ? "IN" : "", + (ps->actions[0] & CURL_POLL_OUT) ? "OUT" : "", + timeout_count); + break; + case 2: + CURL_TRC_M(data, "pollset[fd=%" FMT_SOCKET_T " %s%s, " + "fd=%" FMT_SOCKET_T " %s%s], timeouts=%zu", + ps->sockets[0], + (ps->actions[0] & CURL_POLL_IN) ? "IN" : "", + (ps->actions[0] & CURL_POLL_OUT) ? "OUT" : "", + ps->sockets[1], + (ps->actions[1] & CURL_POLL_IN) ? "IN" : "", + (ps->actions[1] & CURL_POLL_OUT) ? "OUT" : "", + timeout_count); + break; + default: + CURL_TRC_M(data, "pollset[fds=%u], timeouts=%zu", ps->n, timeout_count); + break; } CURL_TRC_EASY_TIMERS(data); } #endif - if(expect_sockets && !ps->n && data->multi && - !Curl_uint_bset_contains(&data->multi->dirty, data->mid) && - !Curl_llist_count(&data->state.timeoutlist) && - !Curl_cwriter_is_paused(data) && !Curl_creader_is_paused(data) && - Curl_conn_is_ip_connected(data, FIRSTSOCKET)) { - /* We expected sockets for POLL monitoring, but none are set. - * We are not dirty (and run anyway). - * We are not waiting on any timer. - * None of the READ/WRITE directions are paused. - * We are connected to the server on IP level, at least. */ - infof(data, "WARNING: no socket in pollset or timer, transfer may stall!"); - DEBUGASSERT(0); - } out: return mresult; } @@ -1186,7 +1220,8 @@ CURLMcode curl_multi_fdset(CURLM *m, int this_max_fd = -1; struct Curl_multi *multi = m; struct easy_pollset ps; - unsigned int i, mid; + unsigned int i; + uint32_t mid; (void)exc_fd_set; if(!GOOD_MULTI_HANDLE(multi)) @@ -1196,7 +1231,7 @@ CURLMcode curl_multi_fdset(CURLM *m, return CURLM_RECURSIVE_API_CALL; Curl_pollset_init(&ps); - if(Curl_uint_bset_first(&multi->process, &mid)) { + if(Curl_uint32_bset_first(&multi->process, &mid)) { do { struct Curl_easy *data = Curl_multi_get_easy(multi, mid); @@ -1205,7 +1240,7 @@ CURLMcode curl_multi_fdset(CURLM *m, continue; } - Curl_multi_pollset(data, &ps, "curl_multi_fdset"); + Curl_multi_pollset(data, &ps); for(i = 0; i < ps.n; i++) { if(!FDSET_SOCK(ps.sockets[i])) /* pretend it does not exist */ @@ -1224,8 +1259,7 @@ CURLMcode curl_multi_fdset(CURLM *m, if((int)ps.sockets[i] > this_max_fd) this_max_fd = (int)ps.sockets[i]; } - } - while(Curl_uint_bset_next(&multi->process, mid, &mid)); + } while(Curl_uint32_bset_next(&multi->process, mid, &mid)); } Curl_cshutdn_setfds(&multi->cshutdn, multi->admin, @@ -1243,10 +1277,11 @@ CURLMcode curl_multi_waitfds(CURLM *m, unsigned int *fd_count) { struct Curl_waitfds cwfds; - CURLMcode result = CURLM_OK; + CURLMcode mresult = CURLM_OK; struct Curl_multi *multi = m; struct easy_pollset ps; - unsigned int need = 0, mid; + unsigned int need = 0; + uint32_t mid; if(!ufds && (size || !fd_count)) return CURLM_BAD_FUNCTION_ARGUMENT; @@ -1259,31 +1294,29 @@ CURLMcode curl_multi_waitfds(CURLM *m, Curl_pollset_init(&ps); Curl_waitfds_init(&cwfds, ufds, size); - if(Curl_uint_bset_first(&multi->process, &mid)) { + if(Curl_uint32_bset_first(&multi->process, &mid)) { do { struct Curl_easy *data = Curl_multi_get_easy(multi, mid); if(!data) { DEBUGASSERT(0); - Curl_uint_bset_remove(&multi->process, mid); - Curl_uint_bset_remove(&multi->dirty, mid); + Curl_uint32_bset_remove(&multi->process, mid); + Curl_uint32_bset_remove(&multi->dirty, mid); continue; } - Curl_multi_pollset(data, &ps, "curl_multi_waitfds"); + Curl_multi_pollset(data, &ps); need += Curl_waitfds_add_ps(&cwfds, &ps); - } - while(Curl_uint_bset_next(&multi->process, mid, &mid)); + } while(Curl_uint32_bset_next(&multi->process, mid, &mid)); } need += Curl_cshutdn_add_waitfds(&multi->cshutdn, multi->admin, &cwfds); - if(need != cwfds.n && ufds) { - result = CURLM_OUT_OF_MEMORY; - } + if(need != cwfds.n && ufds) + mresult = CURLM_OUT_OF_MEMORY; if(fd_count) *fd_count = need; Curl_pollset_cleanup(&ps); - return result; + return mresult; } #ifdef USE_WINSOCK @@ -1298,7 +1331,7 @@ static void reset_socket_fdwrite(curl_socket_t s) int t; int l = (int)sizeof(t); if(!getsockopt(s, SOL_SOCKET, SO_TYPE, (char *)&t, &l) && t == SOCK_STREAM) - CURL_SEND(s, NULL, 0, 0); + send(s, NULL, 0, 0); } #endif @@ -1321,8 +1354,8 @@ static CURLMcode multi_wait(struct Curl_multi *multi, struct curl_pollfds cpfds; unsigned int curl_nfds = 0; /* how many pfds are for curl transfers */ struct Curl_easy *data = NULL; - CURLMcode result = CURLM_OK; - unsigned int mid; + CURLMcode mresult = CURLM_OK; + uint32_t mid; #ifdef USE_WINSOCK WSANETWORKEVENTS wsa_events; @@ -1345,26 +1378,25 @@ static CURLMcode multi_wait(struct Curl_multi *multi, Curl_pollfds_init(&cpfds, a_few_on_stack, NUM_POLLS_ON_STACK); /* Add the curl handles to our pollfds first */ - if(Curl_uint_bset_first(&multi->process, &mid)) { + if(Curl_uint32_bset_first(&multi->process, &mid)) { do { data = Curl_multi_get_easy(multi, mid); if(!data) { DEBUGASSERT(0); - Curl_uint_bset_remove(&multi->process, mid); - Curl_uint_bset_remove(&multi->dirty, mid); + Curl_uint32_bset_remove(&multi->process, mid); + Curl_uint32_bset_remove(&multi->dirty, mid); continue; } - Curl_multi_pollset(data, &ps, "multi_wait"); + Curl_multi_pollset(data, &ps); if(Curl_pollfds_add_ps(&cpfds, &ps)) { - result = CURLM_OUT_OF_MEMORY; + mresult = CURLM_OUT_OF_MEMORY; goto out; } - } - while(Curl_uint_bset_next(&multi->process, mid, &mid)); + } while(Curl_uint32_bset_next(&multi->process, mid, &mid)); } if(Curl_cshutdn_add_pollfds(&multi->cshutdn, multi->admin, &cpfds)) { - result = CURLM_OUT_OF_MEMORY; + mresult = CURLM_OUT_OF_MEMORY; goto out; } @@ -1379,7 +1411,7 @@ static CURLMcode multi_wait(struct Curl_multi *multi, if(extra_fds[i].events & CURL_WAIT_POLLOUT) events |= POLLOUT; if(Curl_pollfds_add_sock(&cpfds, extra_fds[i].fd, events)) { - result = CURLM_OUT_OF_MEMORY; + mresult = CURLM_OUT_OF_MEMORY; goto out; } } @@ -1389,16 +1421,16 @@ static CURLMcode multi_wait(struct Curl_multi *multi, for(i = 0; i < cpfds.n; i++) { long mask = 0; if(cpfds.pfds[i].events & POLLIN) - mask |= FD_READ|FD_ACCEPT|FD_CLOSE; + mask |= FD_READ | FD_ACCEPT | FD_CLOSE; if(cpfds.pfds[i].events & POLLPRI) mask |= FD_OOB; if(cpfds.pfds[i].events & POLLOUT) { - mask |= FD_WRITE|FD_CONNECT|FD_CLOSE; + mask |= FD_WRITE | FD_CONNECT | FD_CLOSE; reset_socket_fdwrite(cpfds.pfds[i].fd); } if(mask) { if(WSAEventSelect(cpfds.pfds[i].fd, multi->wsa_event, mask) != 0) { - result = CURLM_OUT_OF_MEMORY; + mresult = CURLM_OUT_OF_MEMORY; goto out; } } @@ -1409,7 +1441,7 @@ static CURLMcode multi_wait(struct Curl_multi *multi, #ifndef USE_WINSOCK if(use_wakeup && multi->wakeup_pair[0] != CURL_SOCKET_BAD) { if(Curl_pollfds_add_sock(&cpfds, multi->wakeup_pair[0], POLLIN)) { - result = CURLM_OUT_OF_MEMORY; + mresult = CURLM_OUT_OF_MEMORY; goto out; } } @@ -1420,7 +1452,7 @@ static CURLMcode multi_wait(struct Curl_multi *multi, * poll. Collecting the sockets may install new timers by protocols * and connection filters. * Use the shorter one of the internal and the caller requested timeout. */ - (void)multi_timeout(multi, &expire_time, &timeout_internal); + multi_timeout(multi, &expire_time, &timeout_internal); if((timeout_internal >= 0) && (timeout_internal < (long)timeout_ms)) timeout_ms = (int)timeout_internal; @@ -1442,7 +1474,7 @@ static CURLMcode multi_wait(struct Curl_multi *multi, pollrc = Curl_poll(cpfds.pfds, cpfds.n, timeout_ms); /* wait... */ #endif if(pollrc < 0) { - result = CURLM_UNRECOVERABLE_POLL; + mresult = CURLM_UNRECOVERABLE_POLL; goto out; } @@ -1468,9 +1500,9 @@ static CURLMcode multi_wait(struct Curl_multi *multi, curl_socket_t s = extra_fds[i].fd; wsa_events.lNetworkEvents = 0; if(WSAEnumNetworkEvents(s, NULL, &wsa_events) == 0) { - if(wsa_events.lNetworkEvents & (FD_READ|FD_ACCEPT|FD_CLOSE)) + if(wsa_events.lNetworkEvents & (FD_READ | FD_ACCEPT | FD_CLOSE)) mask |= CURL_WAIT_POLLIN; - if(wsa_events.lNetworkEvents & (FD_WRITE|FD_CONNECT|FD_CLOSE)) + if(wsa_events.lNetworkEvents & (FD_WRITE | FD_CONNECT | FD_CLOSE)) mask |= CURL_WAIT_POLLOUT; if(wsa_events.lNetworkEvents & FD_OOB) mask |= CURL_WAIT_POLLPRI; @@ -1541,7 +1573,8 @@ static CURLMcode multi_wait(struct Curl_multi *multi, long sleep_ms = 0; /* Avoid busy-looping when there is nothing particular to wait for */ - if(!curl_multi_timeout(multi, &sleep_ms) && sleep_ms) { + multi_timeout(multi, &expire_time, &sleep_ms); + if(sleep_ms) { if(sleep_ms > timeout_ms) sleep_ms = timeout_ms; /* when there are no easy handles in the multi, this holds a -1 @@ -1555,7 +1588,7 @@ static CURLMcode multi_wait(struct Curl_multi *multi, out: Curl_pollset_cleanup(&ps); Curl_pollfds_cleanup(&cpfds); - return result; + return mresult; } CURLMcode curl_multi_wait(CURLM *multi, @@ -1574,8 +1607,7 @@ CURLMcode curl_multi_poll(CURLM *multi, int timeout_ms, int *ret) { - return multi_wait(multi, extra_fds, extra_nfds, timeout_ms, ret, TRUE, - TRUE); + return multi_wait(multi, extra_fds, extra_nfds, timeout_ms, ret, TRUE, TRUE); } CURLMcode curl_multi_wakeup(CURLM *m) @@ -1668,13 +1700,13 @@ CURLMcode Curl_multi_add_perform(struct Curl_multi *multi, struct Curl_easy *data, struct connectdata *conn) { - CURLMcode rc; + CURLMcode mresult; if(multi->in_callback) return CURLM_RECURSIVE_API_CALL; - rc = curl_multi_add_handle(multi, data); - if(!rc) { + mresult = curl_multi_add_handle(multi, data); + if(!mresult) { struct SingleRequest *k = &data->req; CURLcode result; @@ -1691,7 +1723,7 @@ CURLMcode Curl_multi_add_perform(struct Curl_multi *multi, Curl_attach_connection(data, conn); k->keepon |= KEEP_RECV; /* setup to receive! */ } - return rc; + return mresult; } static CURLcode multi_do(struct Curl_easy *data, bool *done) @@ -1734,12 +1766,13 @@ static CURLcode multi_do_more(struct Curl_easy *data, int *complete) * Check whether a timeout occurred, and handle it if it did */ static bool multi_handle_timeout(struct Curl_easy *data, - struct curltime *now, bool *stream_error, CURLcode *result) { bool connect_timeout = data->mstate < MSTATE_DO; - timediff_t timeout_ms = Curl_timeleft(data, now, connect_timeout); + timediff_t timeout_ms; + + timeout_ms = Curl_timeleft_ms(data, connect_timeout); if(timeout_ms < 0) { /* Handle timed out */ struct curltime since; @@ -1749,22 +1782,26 @@ static bool multi_handle_timeout(struct Curl_easy *data, since = data->progress.t_startop; if(data->mstate == MSTATE_RESOLVING) failf(data, "Resolving timed out after %" FMT_TIMEDIFF_T - " milliseconds", curlx_timediff(*now, since)); + " milliseconds", + curlx_ptimediff_ms(Curl_pgrs_now(data), &since)); else if(data->mstate == MSTATE_CONNECTING) failf(data, "Connection timed out after %" FMT_TIMEDIFF_T - " milliseconds", curlx_timediff(*now, since)); + " milliseconds", + curlx_ptimediff_ms(Curl_pgrs_now(data), &since)); else { struct SingleRequest *k = &data->req; if(k->size != -1) { failf(data, "Operation timed out after %" FMT_TIMEDIFF_T " milliseconds with %" FMT_OFF_T " out of %" FMT_OFF_T " bytes received", - curlx_timediff(*now, since), k->bytecount, k->size); + curlx_ptimediff_ms(Curl_pgrs_now(data), &since), + k->bytecount, k->size); } else { failf(data, "Operation timed out after %" FMT_TIMEDIFF_T " milliseconds with %" FMT_OFF_T " bytes received", - curlx_timediff(*now, since), k->bytecount); + curlx_ptimediff_ms(Curl_pgrs_now(data), &since), + k->bytecount); } } *result = CURLE_OPERATION_TIMEDOUT; @@ -1828,47 +1865,31 @@ static CURLcode protocol_doing(struct Curl_easy *data, bool *done) * proceed with some action. * */ -static CURLcode protocol_connect(struct Curl_easy *data, - bool *protocol_done) +static CURLcode protocol_connect(struct Curl_easy *data, bool *protocol_done) { - CURLcode result = CURLE_OK; struct connectdata *conn = data->conn; + CURLcode result = CURLE_OK; + DEBUGASSERT(conn); DEBUGASSERT(protocol_done); + DEBUGASSERT(Curl_conn_is_connected(conn, FIRSTSOCKET)); *protocol_done = FALSE; - - if(Curl_conn_is_connected(conn, FIRSTSOCKET) - && conn->bits.protoconnstart) { - /* We already are connected, get back. This may happen when the connect - worked fine in the first call, like when we connect to a local server - or proxy. Note that we do not know if the protocol is actually done. - - Unless this protocol does not have any protocol-connect callback, as - then we know we are done. */ - if(!conn->handler->connecting) - *protocol_done = TRUE; - - return CURLE_OK; - } - if(!conn->bits.protoconnstart) { if(conn->handler->connect_it) { - /* is there a protocol-specific connect() procedure? */ - /* Call the protocol-specific connect function */ result = conn->handler->connect_it(data, protocol_done); + if(result) + return result; } - else - *protocol_done = TRUE; - - /* it has started, possibly even completed but that knowledge is not stored - in this bit! */ - if(!result) - conn->bits.protoconnstart = TRUE; + conn->bits.protoconnstart = TRUE; } - return result; /* pass back status */ + /* Unless this protocol does not have any protocol-connect callback, as + then we know we are done. */ + if(!conn->handler->connecting) + *protocol_done = TRUE; + return CURLE_OK; } static void set_in_callback(struct Curl_multi *multi, bool value) @@ -1906,56 +1927,48 @@ static CURLcode multi_follow(struct Curl_easy *data, return CURLE_TOO_MANY_REDIRECTS; } -static CURLcode mspeed_check(struct Curl_easy *data, - struct curltime *nowp) +static CURLcode mspeed_check(struct Curl_easy *data) { + const struct curltime *pnow = Curl_pgrs_now(data); timediff_t recv_wait_ms = 0; timediff_t send_wait_ms = 0; - /* check if over send speed */ - if(data->set.max_send_speed) - send_wait_ms = Curl_pgrsLimitWaitTime(&data->progress.ul, - data->set.max_send_speed, - *nowp); - - /* check if over recv speed */ - if(data->set.max_recv_speed) - recv_wait_ms = Curl_pgrsLimitWaitTime(&data->progress.dl, - data->set.max_recv_speed, - *nowp); + /* check if our send/recv limits require idle waits */ + send_wait_ms = Curl_rlimit_wait_ms(&data->progress.ul.rlimit, pnow); + recv_wait_ms = Curl_rlimit_wait_ms(&data->progress.dl.rlimit, pnow); if(send_wait_ms || recv_wait_ms) { if(data->mstate != MSTATE_RATELIMITING) { - Curl_ratelimit(data, *nowp); multistate(data, MSTATE_RATELIMITING); } Curl_expire(data, CURLMAX(send_wait_ms, recv_wait_ms), EXPIRE_TOOFAST); Curl_multi_clear_dirty(data); + CURL_TRC_M(data, "[RLIMIT] waiting %" FMT_TIMEDIFF_T "ms", + CURLMAX(send_wait_ms, recv_wait_ms)); return CURLE_AGAIN; } else if(data->mstate != MSTATE_PERFORMING) { + CURL_TRC_M(data, "[RLIMIT] wait over, continue"); multistate(data, MSTATE_PERFORMING); - Curl_ratelimit(data, *nowp); } return CURLE_OK; } static CURLMcode state_performing(struct Curl_easy *data, - struct curltime *nowp, bool *stream_errorp, CURLcode *resultp) { char *newurl = NULL; bool retry = FALSE; - CURLMcode rc = CURLM_OK; + CURLMcode mresult = CURLM_OK; CURLcode result = *resultp = CURLE_OK; *stream_errorp = FALSE; - if(mspeed_check(data, nowp) == CURLE_AGAIN) + if(mspeed_check(data) == CURLE_AGAIN) return CURLM_OK; /* read/write data if it is ready to do so */ - result = Curl_sendrecv(data, nowp); + result = Curl_sendrecv(data); if(data->req.done || (result == CURLE_RECV_ERROR)) { /* If CURLE_RECV_ERROR happens early enough, we assume it was a race @@ -1989,7 +2002,7 @@ static CURLMcode state_performing(struct Curl_easy *data, data->state.errorbuf = FALSE; if(!newurl) /* typically for HTTP_1_1_REQUIRED error on first flight */ - newurl = strdup(data->state.url); + newurl = Curl_bufref_dup(&data->state.url); if(!newurl) { result = CURLE_OUT_OF_MEMORY; } @@ -2035,7 +2048,7 @@ static CURLMcode state_performing(struct Curl_easy *data, if(!retry) { /* if the URL is a follow-location and not just a retried request then figure out the URL here */ - free(newurl); + curlx_free(newurl); newurl = data->req.newurl; data->req.newurl = NULL; follow = FOLLOW_REDIR; @@ -2047,7 +2060,7 @@ static CURLMcode state_performing(struct Curl_easy *data, result = multi_follow(data, handler, newurl, follow); if(!result) { multistate(data, MSTATE_SETUP); - rc = CURLM_CALL_MULTI_PERFORM; + mresult = CURLM_CALL_MULTI_PERFORM; } } else { @@ -2056,7 +2069,7 @@ static CURLMcode state_performing(struct Curl_easy *data, /* but first check to see if we got a location info even though we are not following redirects */ if(data->req.location) { - free(newurl); + curlx_free(newurl); newurl = data->req.location; data->req.location = NULL; result = multi_follow(data, handler, newurl, FOLLOW_FAKE); @@ -2068,23 +2081,23 @@ static CURLMcode state_performing(struct Curl_easy *data, if(!result) { multistate(data, MSTATE_DONE); - rc = CURLM_CALL_MULTI_PERFORM; + mresult = CURLM_CALL_MULTI_PERFORM; } } } else { /* not errored, not done */ - mspeed_check(data, nowp); + mspeed_check(data); } - free(newurl); + curlx_free(newurl); *resultp = result; - return rc; + return mresult; } static CURLMcode state_do(struct Curl_easy *data, bool *stream_errorp, CURLcode *resultp) { - CURLMcode rc = CURLM_OK; + CURLMcode mresult = CURLM_OK; CURLcode result = CURLE_OK; if(data->set.fprereq) { int prereq_rc; @@ -2109,10 +2122,8 @@ static CURLMcode state_do(struct Curl_easy *data, } if(data->set.connect_only && !data->set.connect_only_ws) { - /* keep connection open for application to use the socket */ - connkeep(data->conn, "CONNECT_ONLY"); multistate(data, MSTATE_DONE); - rc = CURLM_CALL_MULTI_PERFORM; + mresult = CURLM_CALL_MULTI_PERFORM; } else { bool dophase_done = FALSE; @@ -2132,9 +2143,8 @@ static CURLMcode state_do(struct Curl_easy *data, multi_done(data, CURLE_OK, FALSE); /* if there is no connection left, skip the DONE state */ - multistate(data, data->conn ? - MSTATE_DONE : MSTATE_COMPLETED); - rc = CURLM_CALL_MULTI_PERFORM; + multistate(data, data->conn ? MSTATE_DONE : MSTATE_COMPLETED); + mresult = CURLM_CALL_MULTI_PERFORM; goto end; } } @@ -2142,7 +2152,7 @@ static CURLMcode state_do(struct Curl_easy *data, /* DO was not completed in one function call, we must continue DOING... */ multistate(data, MSTATE_DOING); - rc = CURLM_CALL_MULTI_PERFORM; + mresult = CURLM_CALL_MULTI_PERFORM; } /* after DO, go DO_DONE... or DO_MORE */ @@ -2150,12 +2160,12 @@ static CURLMcode state_do(struct Curl_easy *data, /* we are supposed to do more, but we need to sit down, relax and wait a little while first */ multistate(data, MSTATE_DOING_MORE); - rc = CURLM_CALL_MULTI_PERFORM; + mresult = CURLM_CALL_MULTI_PERFORM; } else { /* we are done with the DO, now DID */ multistate(data, MSTATE_DID); - rc = CURLM_CALL_MULTI_PERFORM; + mresult = CURLM_CALL_MULTI_PERFORM; } } else if((CURLE_SEND_ERROR == result) && @@ -2188,7 +2198,7 @@ static CURLMcode state_do(struct Curl_easy *data, drc = multi_follow(data, handler, newurl, follow); if(!drc) { multistate(data, MSTATE_SETUP); - rc = CURLM_CALL_MULTI_PERFORM; + mresult = CURLM_CALL_MULTI_PERFORM; result = CURLE_OK; } else { @@ -2205,7 +2215,7 @@ static CURLMcode state_do(struct Curl_easy *data, /* Have error handler disconnect conn if we cannot retry */ *stream_errorp = TRUE; } - free(newurl); + curlx_free(newurl); } else { /* failure detected */ @@ -2217,21 +2227,17 @@ static CURLMcode state_do(struct Curl_easy *data, } end: *resultp = result; - return rc; + return mresult; } static CURLMcode state_ratelimiting(struct Curl_easy *data, - struct curltime *nowp, CURLcode *resultp) { CURLcode result = CURLE_OK; - CURLMcode rc = CURLM_OK; + CURLMcode mresult = CURLM_OK; DEBUGASSERT(data->conn); /* if both rates are within spec, resume transfer */ - if(Curl_pgrsUpdate(data)) - result = CURLE_ABORTED_BY_CALLBACK; - else - result = Curl_speedcheck(data, *nowp); + result = Curl_pgrsCheck(data); if(result) { if(!(data->conn->handler->flags & PROTOPT_DUAL) && @@ -2242,11 +2248,11 @@ static CURLMcode state_ratelimiting(struct Curl_easy *data, multi_done(data, result, TRUE); } else { - if(!mspeed_check(data, nowp)) - rc = CURLM_CALL_MULTI_PERFORM; + if(!mspeed_check(data)) + mresult = CURLM_CALL_MULTI_PERFORM; } *resultp = result; - return rc; + return mresult; } static CURLMcode state_resolving(struct Curl_multi *multi, @@ -2256,7 +2262,7 @@ static CURLMcode state_resolving(struct Curl_multi *multi, { struct Curl_dns_entry *dns = NULL; CURLcode result; - CURLMcode rc = CURLM_OK; + CURLMcode mresult = CURLM_OK; result = Curl_resolv_check(data, &dns); CURL_TRC_DNS(data, "Curl_resolv_check() -> %d, %s", @@ -2266,9 +2272,9 @@ static CURLMcode state_resolving(struct Curl_multi *multi, socket(s) will again be used further down. If the name has not yet been resolved, it is likely that new sockets have been opened in an attempt to contact another resolver. */ - rc = Curl_multi_ev_assess_xfer(multi, data); - if(rc) - return rc; + mresult = Curl_multi_ev_assess_xfer(multi, data); + if(mresult) + return mresult; if(dns) { bool connected; @@ -2282,7 +2288,7 @@ static CURLMcode state_resolving(struct Curl_multi *multi, data->conn = NULL; /* no more connection */ else { /* call again please so that we get the next socket setup */ - rc = CURLM_CALL_MULTI_PERFORM; + mresult = CURLM_CALL_MULTI_PERFORM; if(connected) multistate(data, MSTATE_PROTOCONNECT); else { @@ -2296,36 +2302,34 @@ static CURLMcode state_resolving(struct Curl_multi *multi, *stream_errorp = TRUE; *resultp = result; - return rc; + return mresult; } static CURLMcode state_connect(struct Curl_multi *multi, struct Curl_easy *data, - struct curltime *nowp, CURLcode *resultp) { /* Connect. We want to get a connection identifier filled in. This state can be entered from SETUP and from PENDING. */ bool connected; bool async; - CURLMcode rc = CURLM_OK; + CURLMcode mresult = CURLM_OK; CURLcode result = Curl_connect(data, &async, &connected); if(CURLE_NO_CONNECTION_AVAILABLE == result) { /* There was no connection available. We will go to the pending state and wait for an available connection. */ multistate(data, MSTATE_PENDING); /* move from process to pending set */ - Curl_uint_bset_remove(&multi->process, data->mid); - Curl_uint_bset_remove(&multi->dirty, data->mid); - Curl_uint_bset_add(&multi->pending, data->mid); + Curl_uint32_bset_remove(&multi->process, data->mid); + Curl_uint32_bset_remove(&multi->dirty, data->mid); + Curl_uint32_bset_add(&multi->pending, data->mid); *resultp = CURLE_OK; - return rc; + return mresult; } else process_pending_handles(data->multi); if(!result) { - *nowp = Curl_pgrsTime(data, TIMER_POSTQUEUE); if(async) /* We are now waiting for an asynchronous name lookup */ multistate(data, MSTATE_RESOLVING); @@ -2333,7 +2337,7 @@ static CURLMcode state_connect(struct Curl_multi *multi, /* after the connect has been sent off, go WAITCONNECT unless the protocol connect is already done and we can go directly to WAITDO or DO! */ - rc = CURLM_CALL_MULTI_PERFORM; + mresult = CURLM_CALL_MULTI_PERFORM; if(connected) { if(!data->conn->bits.reuse && @@ -2349,18 +2353,17 @@ static CURLMcode state_connect(struct Curl_multi *multi, } } *resultp = result; - return rc; + return mresult; } static CURLMcode multi_runsingle(struct Curl_multi *multi, - struct curltime *nowp, struct Curl_easy *data) { struct Curl_message *msg = NULL; bool connected; bool protocol_connected = FALSE; bool dophase_done = FALSE; - CURLMcode rc; + CURLMcode mresult; CURLcode result = CURLE_OK; int control; @@ -2380,13 +2383,18 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi, /* transfer runs now, clear the dirty bit. This may be set * again during processing, triggering a re-run later. */ - Curl_uint_bset_remove(&multi->dirty, data->mid); + Curl_uint32_bset_remove(&multi->dirty, data->mid); + + if(data == multi->admin) { + Curl_cshutdn_perform(&multi->cshutdn, multi->admin, CURL_SOCKET_TIMEOUT); + return CURLM_OK; + } do { /* A "stream" here is a logical stream if the protocol can handle that (HTTP/2), or the full connection for older protocols */ bool stream_error = FALSE; - rc = CURLM_OK; + mresult = CURLM_OK; if(multi_ischanged(multi, TRUE)) { CURL_TRC_M(data, "multi changed, check CONNECT_PEND queue"); @@ -2404,7 +2412,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi, /* Wait for the connect state as only then is the start time stored, but we must not check already completed handles */ if((data->mstate >= MSTATE_CONNECT) && (data->mstate < MSTATE_COMPLETED) && - multi_handle_timeout(data, nowp, &stream_error, &result)) + multi_handle_timeout(data, &stream_error, &result)) /* Skip the statemachine and go directly to error handling section. */ goto statemachine_end; @@ -2424,7 +2432,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi, case MSTATE_SETUP: /* Transitional state. Setup things for a new transfer. The handle can come back to this state on a redirect. */ - *nowp = Curl_pgrsTime(data, TIMER_STARTSINGLE); + Curl_pgrsTime(data, TIMER_STARTSINGLE); if(data->set.timeout) Curl_expire(data, data->set.timeout, EXPIRE_TIMEOUT); if(data->set.connecttimeout) @@ -2437,29 +2445,14 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi, FALLTHROUGH(); case MSTATE_CONNECT: - rc = state_connect(multi, data, nowp, &result); + mresult = state_connect(multi, data, &result); break; case MSTATE_RESOLVING: /* awaiting an asynch name resolve to complete */ - rc = state_resolving(multi, data, &stream_error, &result); + mresult = state_resolving(multi, data, &stream_error, &result); break; -#ifndef CURL_DISABLE_HTTP - case MSTATE_TUNNELING: - /* this is HTTP-specific, but sending CONNECT to a proxy is HTTP... */ - DEBUGASSERT(data->conn); - result = Curl_http_connect(data, &protocol_connected); - if(!result) { - rc = CURLM_CALL_MULTI_PERFORM; - /* initiate protocol connect phase */ - multistate(data, MSTATE_PROTOCONNECT); - } - else - stream_error = TRUE; - break; -#endif - case MSTATE_CONNECTING: /* awaiting a completion of an asynch TCP connect */ DEBUGASSERT(data->conn); @@ -2471,7 +2464,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi, /* new connection, can multiplex, wake pending handles */ process_pending_handles(data->multi); } - rc = CURLM_CALL_MULTI_PERFORM; + mresult = CURLM_CALL_MULTI_PERFORM; multistate(data, MSTATE_PROTOCONNECT); } else if(result) { @@ -2491,7 +2484,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi, * restart this on a reused connection. */ multistate(data, MSTATE_DO); - rc = CURLM_CALL_MULTI_PERFORM; + mresult = CURLM_CALL_MULTI_PERFORM; break; } if(!result) @@ -2499,12 +2492,12 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi, if(!result && !protocol_connected) { /* switch to waiting state */ multistate(data, MSTATE_PROTOCONNECTING); - rc = CURLM_CALL_MULTI_PERFORM; + mresult = CURLM_CALL_MULTI_PERFORM; } else if(!result) { /* protocol connect has completed, go WAITDO or DO */ multistate(data, MSTATE_DO); - rc = CURLM_CALL_MULTI_PERFORM; + mresult = CURLM_CALL_MULTI_PERFORM; } else { /* failure detected */ @@ -2520,7 +2513,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi, if(!result && protocol_connected) { /* after the connect has completed, go WAITDO or DO */ multistate(data, MSTATE_DO); - rc = CURLM_CALL_MULTI_PERFORM; + mresult = CURLM_CALL_MULTI_PERFORM; } else if(result) { /* failure detected */ @@ -2531,7 +2524,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi, break; case MSTATE_DO: - rc = state_do(data, &stream_error, &result); + mresult = state_do(data, &stream_error, &result); break; case MSTATE_DOING: @@ -2543,7 +2536,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi, /* after DO, go DO_DONE or DO_MORE */ multistate(data, data->conn->bits.do_more ? MSTATE_DOING_MORE : MSTATE_DID); - rc = CURLM_CALL_MULTI_PERFORM; + mresult = CURLM_CALL_MULTI_PERFORM; } /* dophase_done */ } else { @@ -2565,9 +2558,8 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi, if(control) { /* if positive, advance to DO_DONE if negative, go back to DOING */ - multistate(data, control == 1 ? - MSTATE_DID : MSTATE_DOING); - rc = CURLM_CALL_MULTI_PERFORM; + multistate(data, control == 1 ? MSTATE_DID : MSTATE_DOING); + mresult = CURLM_CALL_MULTI_PERFORM; } /* else stay in DO_MORE */ @@ -2584,7 +2576,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi, DEBUGASSERT(data->conn); if(data->conn->bits.multiplex) /* Check if we can move pending requests to send pipe */ - process_pending_handles(multi); /* multiplexed */ + process_pending_handles(multi); /* multiplexed */ /* Only perform the transfer if there is a good socket to work with. Having both BAD is a signal to skip immediately to DONE */ @@ -2600,20 +2592,20 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi, #endif multistate(data, MSTATE_DONE); } - rc = CURLM_CALL_MULTI_PERFORM; + mresult = CURLM_CALL_MULTI_PERFORM; break; case MSTATE_RATELIMITING: /* limit-rate exceeded in either direction */ - rc = state_ratelimiting(data, nowp, &result); + mresult = state_ratelimiting(data, &result); break; case MSTATE_PERFORMING: - rc = state_performing(data, nowp, &stream_error, &result); + mresult = state_performing(data, &stream_error, &result); break; case MSTATE_DONE: /* this state is highly transient, so run another loop after this */ - rc = CURLM_CALL_MULTI_PERFORM; + mresult = CURLM_CALL_MULTI_PERFORM; if(data->conn) { CURLcode res; @@ -2655,7 +2647,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi, if(data->mstate >= MSTATE_CONNECT && data->mstate < MSTATE_DO && - rc != CURLM_CALL_MULTI_PERFORM && + mresult != CURLM_CALL_MULTI_PERFORM && !multi_ischanged(multi, FALSE)) { /* We now handle stream timeouts if and only if this will be the last * loop iteration. We only check this on the last iteration to ensure @@ -2663,7 +2655,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi, * (i.e. CURLM_CALL_MULTI_PERFORM == TRUE) then we should do that before * declaring the connection timed out as we may almost have a completed * connection. */ - multi_handle_timeout(data, nowp, &stream_error, &result); + multi_handle_timeout(data, &stream_error, &result); } statemachine_end: @@ -2701,24 +2693,26 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi, } multistate(data, MSTATE_COMPLETED); - rc = CURLM_CALL_MULTI_PERFORM; + mresult = CURLM_CALL_MULTI_PERFORM; } /* if there is still a connection to use, call the progress function */ - else if(data->conn && Curl_pgrsUpdate(data)) { - /* aborted due to progress callback return code must close the - connection */ - result = CURLE_ABORTED_BY_CALLBACK; - streamclose(data->conn, "Aborted by callback"); - - /* if not yet in DONE state, go there, otherwise COMPLETED */ - multistate(data, (data->mstate < MSTATE_DONE) ? - MSTATE_DONE : MSTATE_COMPLETED); - rc = CURLM_CALL_MULTI_PERFORM; + else if(data->conn) { + result = Curl_pgrsUpdate(data); + if(result) { + /* aborted due to progress callback return code must close the + connection */ + streamclose(data->conn, "Aborted by callback"); + + /* if not yet in DONE state, go there, otherwise COMPLETED */ + multistate(data, (data->mstate < MSTATE_DONE) ? + MSTATE_DONE : MSTATE_COMPLETED); + mresult = CURLM_CALL_MULTI_PERFORM; + } } } if(MSTATE_COMPLETED == data->mstate) { - if(data->master_mid != UINT_MAX) { + if(data->master_mid != UINT32_MAX) { /* A sub transfer, not for msgsent to application */ struct Curl_easy *mdata; @@ -2749,32 +2743,28 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi, multistate(data, MSTATE_MSGSENT); /* remove from the other sets, add to msgsent */ - Curl_uint_bset_remove(&multi->process, data->mid); - Curl_uint_bset_remove(&multi->dirty, data->mid); - Curl_uint_bset_remove(&multi->pending, data->mid); - Curl_uint_bset_add(&multi->msgsent, data->mid); + Curl_uint32_bset_remove(&multi->process, data->mid); + Curl_uint32_bset_remove(&multi->dirty, data->mid); + Curl_uint32_bset_remove(&multi->pending, data->mid); + Curl_uint32_bset_add(&multi->msgsent, data->mid); --multi->xfers_alive; return CURLM_OK; } - } while((rc == CURLM_CALL_MULTI_PERFORM) || multi_ischanged(multi, FALSE)); + } while((mresult == CURLM_CALL_MULTI_PERFORM) || + multi_ischanged(multi, FALSE)); data->result = result; - return rc; + return mresult; } - -CURLMcode curl_multi_perform(CURLM *m, int *running_handles) +static CURLMcode multi_perform(struct Curl_multi *multi, + int *running_handles) { CURLMcode returncode = CURLM_OK; - struct Curl_tree *t = NULL; - struct curltime now = curlx_now(); - struct Curl_multi *multi = m; - unsigned int mid; + struct curltime start = *multi_now(multi); + uint32_t mid; SIGPIPE_VARIABLE(pipe_st); - if(!GOOD_MULTI_HANDLE(multi)) - return CURLM_BAD_HANDLE; - if(multi->in_callback) return CURLM_RECURSIVE_API_CALL; @@ -2782,37 +2772,30 @@ CURLMcode curl_multi_perform(CURLM *m, int *running_handles) return CURLM_RECURSIVE_API_CALL; sigpipe_init(&pipe_st); - if(Curl_uint_bset_first(&multi->process, &mid)) { + if(Curl_uint32_bset_first(&multi->process, &mid)) { CURL_TRC_M(multi->admin, "multi_perform(running=%u)", Curl_multi_xfers_running(multi)); do { struct Curl_easy *data = Curl_multi_get_easy(multi, mid); - CURLMcode result; + CURLMcode mresult; if(!data) { DEBUGASSERT(0); - Curl_uint_bset_remove(&multi->process, mid); - Curl_uint_bset_remove(&multi->dirty, mid); + Curl_uint32_bset_remove(&multi->process, mid); + Curl_uint32_bset_remove(&multi->dirty, mid); continue; } - if(data != multi->admin) { - /* admin handle is processed below */ - sigpipe_apply(data, &pipe_st); - result = multi_runsingle(multi, &now, data); - if(result) - returncode = result; - } - } - while(Curl_uint_bset_next(&multi->process, mid, &mid)); + sigpipe_apply(data, &pipe_st); + mresult = multi_runsingle(multi, data); + if(mresult) + returncode = mresult; + } while(Curl_uint32_bset_next(&multi->process, mid, &mid)); } - - sigpipe_apply(multi->admin, &pipe_st); - Curl_cshutdn_perform(&multi->cshutdn, multi->admin, CURL_SOCKET_TIMEOUT); sigpipe_restore(&pipe_st); - if(multi_ischanged(m, TRUE)) - process_pending_handles(m); + if(multi_ischanged(multi, TRUE)) + process_pending_handles(multi); - if(!returncode) + if(!returncode && CURL_MNTFY_HAS_ENTRIES(multi)) returncode = Curl_mntfy_dispatch_all(multi); /* @@ -2825,22 +2808,25 @@ CURLMcode curl_multi_perform(CURLM *m, int *running_handles) * then and then we risk this loop to remove timers that actually have not * been handled! */ - do { - multi->timetree = Curl_splaygetbest(now, multi->timetree, &t); - if(t) { - /* the removed may have another timeout in queue */ - struct Curl_easy *data = Curl_splayget(t); - (void)add_next_timeout(now, multi, data); - if(data->mstate == MSTATE_PENDING) { - bool stream_unused; - CURLcode result_unused; - if(multi_handle_timeout(data, &now, &stream_unused, &result_unused)) { - infof(data, "PENDING handle timeout"); - move_pending_to_connect(multi, data); + if(multi->timetree) { + struct Curl_tree *t = NULL; + do { + multi->timetree = Curl_splaygetbest(&start, multi->timetree, &t); + if(t) { + /* the removed may have another timeout in queue */ + struct Curl_easy *data = Curl_splayget(t); + (void)add_next_timeout(&start, multi, data); + if(data->mstate == MSTATE_PENDING) { + bool stream_unused; + CURLcode result_unused; + if(multi_handle_timeout(data, &stream_unused, &result_unused)) { + infof(data, "PENDING handle timeout"); + move_pending_to_connect(multi, data); + } } } - } - } while(t); + } while(t); + } if(running_handles) { unsigned int running = Curl_multi_xfers_running(multi); @@ -2853,12 +2839,22 @@ CURLMcode curl_multi_perform(CURLM *m, int *running_handles) return returncode; } +CURLMcode curl_multi_perform(CURLM *m, int *running_handles) +{ + struct Curl_multi *multi = m; + + if(!GOOD_MULTI_HANDLE(multi)) + return CURLM_BAD_HANDLE; + + return multi_perform(multi, running_handles); +} + CURLMcode curl_multi_cleanup(CURLM *m) { struct Curl_multi *multi = m; if(GOOD_MULTI_HANDLE(multi)) { void *entry; - unsigned int mid; + uint32_t mid; if(multi->in_callback) return CURLM_RECURSIVE_API_CALL; if(multi->in_ntfy_callback) @@ -2866,7 +2862,7 @@ CURLMcode curl_multi_cleanup(CURLM *m) /* First remove all remaining easy handles, * close internal ones. admin handle is special */ - if(Curl_uint_tbl_first(&multi->xfers, &mid, &entry)) { + if(Curl_uint32_tbl_first(&multi->xfers, &mid, &entry)) { do { struct Curl_easy *data = entry; if(!GOOD_EASY_HANDLE(data)) @@ -2888,8 +2884,8 @@ CURLMcode curl_multi_cleanup(CURLM *m) (void)multi_done(data, CURLE_OK, TRUE); data->multi = NULL; /* clear the association */ - Curl_uint_tbl_remove(&multi->xfers, mid); - data->mid = UINT_MAX; + Curl_uint32_tbl_remove(&multi->xfers, mid); + data->mid = UINT32_MAX; #ifdef USE_LIBPSL if(data->psl == &multi->psl) @@ -2897,8 +2893,7 @@ CURLMcode curl_multi_cleanup(CURLM *m) #endif if(data->state.internal) Curl_close(&data); - } - while(Curl_uint_tbl_next(&multi->xfers, mid, &mid, &entry)); + } while(Curl_uint32_tbl_next(&multi->xfers, mid, &mid, &entry)); } Curl_cpool_destroy(&multi->cpool); @@ -2906,7 +2901,7 @@ CURLMcode curl_multi_cleanup(CURLM *m) if(multi->admin) { CURL_TRC_M(multi->admin, "multi_cleanup, closing admin handle, done"); multi->admin->multi = NULL; - Curl_uint_tbl_remove(&multi->xfers, multi->admin->mid); + Curl_uint32_tbl_remove(&multi->xfers, multi->admin->mid); Curl_close(&multi->admin); } @@ -2934,17 +2929,17 @@ CURLMcode curl_multi_cleanup(CURLM *m) multi_xfer_bufs_free(multi); Curl_mntfy_cleanup(multi); #ifdef DEBUGBUILD - if(Curl_uint_tbl_count(&multi->xfers)) { + if(Curl_uint32_tbl_count(&multi->xfers)) { multi_xfer_tbl_dump(multi); DEBUGASSERT(0); } #endif - Curl_uint_bset_destroy(&multi->process); - Curl_uint_bset_destroy(&multi->dirty); - Curl_uint_bset_destroy(&multi->pending); - Curl_uint_bset_destroy(&multi->msgsent); - Curl_uint_tbl_destroy(&multi->xfers); - free(multi); + Curl_uint32_bset_destroy(&multi->process); + Curl_uint32_bset_destroy(&multi->dirty); + Curl_uint32_bset_destroy(&multi->pending); + Curl_uint32_bset_destroy(&multi->msgsent); + Curl_uint32_tbl_destroy(&multi->xfers); + curlx_free(multi); return CURLM_OK; } @@ -2989,7 +2984,6 @@ CURLMsg *curl_multi_info_read(CURLM *m, int *msgs_in_queue) return NULL; } - void Curl_multi_will_close(struct Curl_easy *data, curl_socket_t s) { if(data) { @@ -3013,7 +3007,7 @@ void Curl_multi_will_close(struct Curl_easy *data, curl_socket_t s) * The splay tree only has each sessionhandle as a single node and the nearest * timeout is used to sort it on. */ -static CURLMcode add_next_timeout(struct curltime now, +static CURLMcode add_next_timeout(const struct curltime *pnow, struct Curl_multi *multi, struct Curl_easy *d) { @@ -3027,7 +3021,7 @@ static CURLMcode add_next_timeout(struct curltime now, for(e = Curl_llist_head(list); e;) { struct Curl_llist_node *n = Curl_node_next(e); struct time_node *node = Curl_node_elem(e); - timediff_t diff = curlx_timediff_us(node->time, now); + timediff_t diff = curlx_ptimediff_us(&node->time, pnow); if(diff <= 0) /* remove outdated entry */ Curl_node_remove(e); @@ -3050,7 +3044,7 @@ static CURLMcode add_next_timeout(struct curltime now, /* Insert this node again into the splay. Keep the timer in the list in case we need to recompute future timers. */ - multi->timetree = Curl_splayinsert(*tv, multi->timetree, + multi->timetree = Curl_splayinsert(tv, multi->timetree, &d->state.timenode); } return CURLM_OK; @@ -3058,13 +3052,12 @@ static CURLMcode add_next_timeout(struct curltime now, struct multi_run_ctx { struct Curl_multi *multi; - struct curltime now; size_t run_xfers; SIGPIPE_MEMBER(pipe_st); - bool run_cpool; }; -static void multi_mark_expired_as_dirty(struct multi_run_ctx *mrc) +static void multi_mark_expired_as_dirty(struct multi_run_ctx *mrc, + const struct curltime *ts) { struct Curl_multi *multi = mrc->multi; struct Curl_easy *data = NULL; @@ -3078,7 +3071,7 @@ static void multi_mark_expired_as_dirty(struct multi_run_ctx *mrc) while(1) { /* Check if there is one (more) expired timer to deal with! This function extracts a matching node if there is one */ - multi->timetree = Curl_splaygetbest(mrc->now, multi->timetree, &t); + multi->timetree = Curl_splaygetbest(ts, multi->timetree, &t); if(!t) return; @@ -3094,7 +3087,7 @@ static void multi_mark_expired_as_dirty(struct multi_run_ctx *mrc) } } #endif - (void)add_next_timeout(mrc->now, multi, data); + (void)add_next_timeout(ts, multi, data); Curl_multi_mark_dirty(data); } } @@ -3102,48 +3095,42 @@ static void multi_mark_expired_as_dirty(struct multi_run_ctx *mrc) static CURLMcode multi_run_dirty(struct multi_run_ctx *mrc) { struct Curl_multi *multi = mrc->multi; - CURLMcode result = CURLM_OK; - unsigned int mid; + CURLMcode mresult = CURLM_OK; + uint32_t mid; - if(Curl_uint_bset_first(&multi->dirty, &mid)) { + if(Curl_uint32_bset_first(&multi->dirty, &mid)) { do { struct Curl_easy *data = Curl_multi_get_easy(multi, mid); if(data) { CURL_TRC_M(data, "multi_run_dirty"); - if(data == multi->admin) { - Curl_uint_bset_remove(&multi->dirty, mid); - mrc->run_cpool = TRUE; - continue; - } - else if(!Curl_uint_bset_contains(&multi->process, mid)) { + if(!Curl_uint32_bset_contains(&multi->process, mid)) { /* We are no longer processing this transfer */ - Curl_uint_bset_remove(&multi->dirty, mid); + Curl_uint32_bset_remove(&multi->dirty, mid); continue; } mrc->run_xfers++; sigpipe_apply(data, &mrc->pipe_st); /* runsingle() clears the dirty mid */ - result = multi_runsingle(multi, &mrc->now, data); + mresult = multi_runsingle(multi, data); - if(CURLM_OK >= result) { + if(CURLM_OK >= mresult) { /* reassess event handling of data */ - result = Curl_multi_ev_assess_xfer(multi, data); - if(result) + mresult = Curl_multi_ev_assess_xfer(multi, data); + if(mresult) goto out; } } else { CURL_TRC_M(multi->admin, "multi_run_dirty, %u no longer found", mid); - Curl_uint_bset_remove(&multi->dirty, mid); + Curl_uint32_bset_remove(&multi->dirty, mid); } - } - while(Curl_uint_bset_next(&multi->dirty, mid, &mid)); + } while(Curl_uint32_bset_next(&multi->dirty, mid, &mid)); } out: - return result; + return mresult; } static CURLMcode multi_socket(struct Curl_multi *multi, @@ -3152,30 +3139,28 @@ static CURLMcode multi_socket(struct Curl_multi *multi, int ev_bitmask, int *running_handles) { - CURLMcode result = CURLM_OK; + CURLMcode mresult = CURLM_OK; struct multi_run_ctx mrc; (void)ev_bitmask; memset(&mrc, 0, sizeof(mrc)); mrc.multi = multi; - mrc.now = curlx_now(); sigpipe_init(&mrc.pipe_st); if(checkall) { /* *perform() deals with running_handles on its own */ - result = curl_multi_perform(multi, running_handles); + mresult = multi_perform(multi, running_handles); - if(result != CURLM_BAD_HANDLE) { + if(mresult != CURLM_BAD_HANDLE) { /* Reassess event status of all active transfers */ - result = Curl_multi_ev_assess_xfer_bset(multi, &multi->process); + mresult = Curl_multi_ev_assess_xfer_bset(multi, &multi->process); } - mrc.run_cpool = TRUE; goto out; } if(s != CURL_SOCKET_TIMEOUT) { /* Mark all transfers of that socket as dirty */ - Curl_multi_ev_dirty_xfers(multi, s, &mrc.run_cpool); + Curl_multi_ev_dirty_xfers(multi, s); } else { /* Asked to run due to time-out. Clear the 'last_expire_ts' variable to @@ -3184,12 +3169,11 @@ static CURLMcode multi_socket(struct Curl_multi *multi, handles the case when the application asks libcurl to run the timeout prematurely. */ memset(&multi->last_expire_ts, 0, sizeof(multi->last_expire_ts)); - mrc.run_cpool = TRUE; } - multi_mark_expired_as_dirty(&mrc); - result = multi_run_dirty(&mrc); - if(result) + multi_mark_expired_as_dirty(&mrc, multi_now(multi)); + mresult = multi_run_dirty(&mrc); + if(mresult) goto out; if(mrc.run_xfers) { @@ -3198,39 +3182,33 @@ static CURLMcode multi_socket(struct Curl_multi *multi, * to set a 0 timeout and call us again, we run them here. * Do that only once or it might be unfair to transfers on other * sockets. */ - mrc.now = curlx_now(); - multi_mark_expired_as_dirty(&mrc); - result = multi_run_dirty(&mrc); + multi_mark_expired_as_dirty(&mrc, &multi->now); + mresult = multi_run_dirty(&mrc); } out: - if(mrc.run_cpool) { - sigpipe_apply(multi->admin, &mrc.pipe_st); - Curl_cshutdn_perform(&multi->cshutdn, multi->admin, s); - } sigpipe_restore(&mrc.pipe_st); if(multi_ischanged(multi, TRUE)) process_pending_handles(multi); - if(!result) - result = Curl_mntfy_dispatch_all(multi); + if(!mresult && CURL_MNTFY_HAS_ENTRIES(multi)) + mresult = Curl_mntfy_dispatch_all(multi); if(running_handles) { unsigned int running = Curl_multi_xfers_running(multi); *running_handles = (running < INT_MAX) ? (int)running : INT_MAX; } - if(CURLM_OK >= result) - result = Curl_update_timer(multi); - return result; + if(CURLM_OK >= mresult) + mresult = Curl_update_timer(multi); + return mresult; } #undef curl_multi_setopt -CURLMcode curl_multi_setopt(CURLM *m, - CURLMoption option, ...) +CURLMcode curl_multi_setopt(CURLM *m, CURLMoption option, ...) { - CURLMcode res = CURLM_OK; + CURLMcode mresult = CURLM_OK; va_list param; unsigned long uarg; struct Curl_multi *multi = m; @@ -3271,10 +3249,12 @@ CURLMcode curl_multi_setopt(CURLM *m, multi->maxconnects = (unsigned int)uarg; break; case CURLMOPT_MAX_HOST_CONNECTIONS: - multi->max_host_connections = va_arg(param, long); + if(!curlx_sltouz(va_arg(param, long), &multi->max_host_connections)) + mresult = CURLM_BAD_FUNCTION_ARGUMENT; break; case CURLMOPT_MAX_TOTAL_CONNECTIONS: - multi->max_total_connections = va_arg(param, long); + if(!curlx_sltouz(va_arg(param, long), &multi->max_total_connections)) + mresult = CURLM_BAD_FUNCTION_ARGUMENT; break; /* options formerly used for pipelining */ case CURLMOPT_MAX_PIPELINE_LENGTH: @@ -3287,14 +3267,13 @@ CURLMcode curl_multi_setopt(CURLM *m, break; case CURLMOPT_PIPELINING_SERVER_BL: break; - case CURLMOPT_MAX_CONCURRENT_STREAMS: - { - long streams = va_arg(param, long); - if((streams < 1) || (streams > INT_MAX)) - streams = 100; - multi->max_concurrent_streams = (unsigned int)streams; - } + case CURLMOPT_MAX_CONCURRENT_STREAMS: { + long streams = va_arg(param, long); + if((streams < 1) || (streams > INT_MAX)) + streams = 100; + multi->max_concurrent_streams = (unsigned int)streams; break; + } case CURLMOPT_NETWORK_CHANGED: { long val = va_arg(param, long); if(val & CURLMNWC_CLEAR_DNS) { @@ -3312,11 +3291,11 @@ CURLMcode curl_multi_setopt(CURLM *m, multi->ntfy.ntfy_cb_data = va_arg(param, void *); break; default: - res = CURLM_UNKNOWN_OPTION; + mresult = CURLM_UNKNOWN_OPTION; break; } va_end(param); - return res; + return mresult; } /* we define curl_multi_socket() in the public multi.h header */ @@ -3353,54 +3332,50 @@ CURLMcode curl_multi_socket_all(CURLM *m, int *running_handles) return multi_socket(multi, TRUE, CURL_SOCKET_BAD, 0, running_handles); } - static bool multi_has_dirties(struct Curl_multi *multi) { - unsigned int mid; - if(Curl_uint_bset_first(&multi->dirty, &mid)) { + uint32_t mid; + if(Curl_uint32_bset_first(&multi->dirty, &mid)) { do { struct Curl_easy *data = Curl_multi_get_easy(multi, mid); if(data) { - if(Curl_uint_bset_contains(&multi->process, mid)) + if(Curl_uint32_bset_contains(&multi->process, mid)) return TRUE; /* We are no longer processing this transfer */ - Curl_uint_bset_remove(&multi->dirty, mid); + Curl_uint32_bset_remove(&multi->dirty, mid); } else { CURL_TRC_M(multi->admin, "dirty transfer %u no longer found", mid); - Curl_uint_bset_remove(&multi->dirty, mid); + Curl_uint32_bset_remove(&multi->dirty, mid); } - } - while(Curl_uint_bset_next(&multi->dirty, mid, &mid)); + } while(Curl_uint32_bset_next(&multi->dirty, mid, &mid)); } return FALSE; } -static CURLMcode multi_timeout(struct Curl_multi *multi, - struct curltime *expire_time, - long *timeout_ms) +static void multi_timeout(struct Curl_multi *multi, + struct curltime *expire_time, + long *timeout_ms) { - static const struct curltime tv_zero = {0, 0}; + static const struct curltime tv_zero = { 0, 0 }; #ifndef CURL_DISABLE_VERBOSE_STRINGS struct Curl_easy *data = NULL; #endif if(multi->dead) { *timeout_ms = 0; - return CURLM_OK; + return; } if(multi_has_dirties(multi)) { - *expire_time = curlx_now(); + *expire_time = *multi_now(multi); *timeout_ms = 0; - return CURLM_OK; + return; } else if(multi->timetree) { - /* we have a tree of expire times */ - struct curltime now = curlx_now(); - + const struct curltime *pnow = multi_now(multi); /* splay the lowest to the bottom */ - multi->timetree = Curl_splay(tv_zero, multi->timetree); + multi->timetree = Curl_splay(&tv_zero, multi->timetree); /* this will not return NULL from a non-empty tree, but some compilers * are not convinced of that. Analyzers are hard. */ *expire_time = multi->timetree ? multi->timetree->key : tv_zero; @@ -3408,15 +3383,16 @@ static CURLMcode multi_timeout(struct Curl_multi *multi, /* 'multi->timetree' will be non-NULL here but the compilers sometimes yell at us if we assume so */ if(multi->timetree && - curlx_timediff_us(multi->timetree->key, now) > 0) { + curlx_ptimediff_us(&multi->timetree->key, pnow) > 0) { /* some time left before expiration */ - timediff_t diff = curlx_timediff_ceil(multi->timetree->key, now); + timediff_t diff_ms = + curlx_timediff_ceil_ms(multi->timetree->key, *pnow); #ifndef CURL_DISABLE_VERBOSE_STRINGS data = Curl_splayget(multi->timetree); #endif /* this should be safe even on 32-bit archs, as we do not use that overly long timeouts */ - *timeout_ms = (long)diff; + *timeout_ms = (long)diff_ms; } else { #ifndef CURL_DISABLE_VERBOSE_STRINGS @@ -3435,8 +3411,7 @@ static CURLMcode multi_timeout(struct Curl_multi *multi, #ifndef CURL_DISABLE_VERBOSE_STRINGS if(data && CURL_TRC_TIMER_is_verbose(data)) { - struct Curl_llist_node *e = - Curl_llist_head(&data->state.timeoutlist); + struct Curl_llist_node *e = Curl_llist_head(&data->state.timeoutlist); if(e) { struct time_node *n = Curl_node_elem(e); CURL_TRC_TIMER(data, n->eid, "gives multi timeout in %ldms", @@ -3444,8 +3419,6 @@ static CURLMcode multi_timeout(struct Curl_multi *multi, } } #endif - - return CURLM_OK; } CURLMcode curl_multi_timeout(CURLM *m, @@ -3461,7 +3434,8 @@ CURLMcode curl_multi_timeout(CURLM *m, if(multi->in_callback) return CURLM_RECURSIVE_API_CALL; - return multi_timeout(multi, &expire_time, timeout_ms); + multi_timeout(multi, &expire_time, timeout_ms); + return CURLM_OK; } /* @@ -3477,9 +3451,7 @@ CURLMcode Curl_update_timer(struct Curl_multi *multi) if(!multi->timer_cb || multi->dead) return CURLM_OK; - if(multi_timeout(multi, &expire_ts, &timeout_ms)) { - return CURLM_OK; - } + multi_timeout(multi, &expire_ts, &timeout_ms); if(timeout_ms < 0 && multi->last_timeout_ms < 0) { /* nothing to do */ @@ -3491,11 +3463,10 @@ CURLMcode Curl_update_timer(struct Curl_multi *multi) set_value = TRUE; } else if(multi->last_timeout_ms < 0) { - CURL_TRC_M(multi->admin, "[TIMER] set %ldms, none before", - timeout_ms); + CURL_TRC_M(multi->admin, "[TIMER] set %ldms, none before", timeout_ms); set_value = TRUE; } - else if(curlx_timediff_us(multi->last_expire_ts, expire_ts)) { + else if(curlx_ptimediff_us(&multi->last_expire_ts, &expire_ts)) { /* We had a timeout before and have one now, the absolute timestamp * differs. The relative timeout_ms may be the same, but the starting * point differs. Let the application restart its timer. */ @@ -3528,8 +3499,7 @@ CURLMcode Curl_update_timer(struct Curl_multi *multi) * * Remove a given timestamp from the list of timeouts. */ -static void -multi_deltimeout(struct Curl_easy *data, expire_id eid) +static void multi_deltimeout(struct Curl_easy *data, expire_id eid) { struct Curl_llist_node *e; struct Curl_llist *timeoutlist = &data->state.timeoutlist; @@ -3550,11 +3520,9 @@ multi_deltimeout(struct Curl_easy *data, expire_id eid) * of list is always the timeout nearest in time. * */ -static CURLMcode -multi_addtimeout(struct Curl_easy *data, - struct curltime *stamp, - expire_id eid, - const struct curltime *nowp) +static CURLMcode multi_addtimeout(struct Curl_easy *data, + struct curltime *stamp, + expire_id eid) { struct Curl_llist_node *e; struct time_node *node; @@ -3562,7 +3530,6 @@ multi_addtimeout(struct Curl_easy *data, size_t n; struct Curl_llist *timeoutlist = &data->state.timeoutlist; - (void)nowp; node = &data->state.expires[eid]; /* copy the timestamp and id */ @@ -3574,24 +3541,22 @@ multi_addtimeout(struct Curl_easy *data, /* find the correct spot in the list */ for(e = Curl_llist_head(timeoutlist); e; e = Curl_node_next(e)) { struct time_node *check = Curl_node_elem(e); - timediff_t diff = curlx_timediff(check->time, node->time); + timediff_t diff = curlx_ptimediff_ms(&check->time, &node->time); if(diff > 0) break; prev = e; } - } /* else this is the first timeout on the list */ Curl_llist_insert_next(timeoutlist, prev, node, &node->list); CURL_TRC_TIMER(data, eid, "set for %" FMT_TIMEDIFF_T "ns", - curlx_timediff_us(node->time, *nowp)); + curlx_ptimediff_us(&node->time, Curl_pgrs_now(data))); return CURLM_OK; } void Curl_expire_ex(struct Curl_easy *data, - const struct curltime *nowp, timediff_t milli, expire_id id) { struct Curl_multi *multi = data->multi; @@ -3605,9 +3570,9 @@ void Curl_expire_ex(struct Curl_easy *data, DEBUGASSERT(id < EXPIRE_LAST); - set = *nowp; - set.tv_sec += (time_t)(milli/1000); /* might be a 64 to 32 bits conversion */ - set.tv_usec += (int)(milli%1000)*1000; + set = *Curl_pgrs_now(data); + set.tv_sec += (time_t)(milli / 1000); /* may be a 64 to 32-bit conversion */ + set.tv_usec += (int)(milli % 1000) * 1000; if(set.tv_usec >= 1000000) { set.tv_sec++; @@ -3619,13 +3584,13 @@ void Curl_expire_ex(struct Curl_easy *data, /* Add it to the timer list. It must stay in the list until it has expired in case we need to recompute the minimum timer later. */ - multi_addtimeout(data, &set, id, nowp); + multi_addtimeout(data, &set, id); if(curr_expire->tv_sec || curr_expire->tv_usec) { /* This means that the struct is added as a node in the splay tree. Compare if the new time is earlier, and only remove-old/add-new if it is. */ - timediff_t diff = curlx_timediff(set, *curr_expire); + timediff_t diff = curlx_ptimediff_ms(&set, curr_expire); int rc; if(diff > 0) { @@ -3646,7 +3611,7 @@ void Curl_expire_ex(struct Curl_easy *data, value since it is our local minimum. */ *curr_expire = set; Curl_splayset(&data->state.timenode, data); - multi->timetree = Curl_splayinsert(*curr_expire, multi->timetree, + multi->timetree = Curl_splayinsert(curr_expire, multi->timetree, &data->state.timenode); } @@ -3663,8 +3628,7 @@ void Curl_expire_ex(struct Curl_easy *data, */ void Curl_expire(struct Curl_easy *data, timediff_t milli, expire_id id) { - struct curltime now = curlx_now(); - Curl_expire_ex(data, &now, milli, id); + Curl_expire_ex(data, milli, id); } /* @@ -3734,8 +3698,8 @@ static void move_pending_to_connect(struct Curl_multi *multi, DEBUGASSERT(data->mstate == MSTATE_PENDING); /* Remove this node from the pending set, add into process set */ - Curl_uint_bset_remove(&multi->pending, data->mid); - Curl_uint_bset_add(&multi->process, data->mid); + Curl_uint32_bset_remove(&multi->pending, data->mid); + Curl_uint32_bset_add(&multi->process, data->mid); multistate(data, MSTATE_CONNECT); Curl_multi_mark_dirty(data); /* make it run */ @@ -3757,8 +3721,8 @@ static void move_pending_to_connect(struct Curl_multi *multi, */ static void process_pending_handles(struct Curl_multi *multi) { - unsigned int mid; - if(Curl_uint_bset_first(&multi->pending, &mid)) { + uint32_t mid; + if(Curl_uint32_bset_first(&multi->pending, &mid)) { do { struct Curl_easy *data = Curl_multi_get_easy(multi, mid); if(data) { @@ -3766,10 +3730,9 @@ static void process_pending_handles(struct Curl_multi *multi) break; } /* transfer no longer known, should not happen */ - Curl_uint_bset_remove(&multi->pending, mid); + Curl_uint32_bset_remove(&multi->pending, mid); DEBUGASSERT(0); - } - while(Curl_uint_bset_next(&multi->pending, mid, &mid)); + } while(Curl_uint32_bset_next(&multi->pending, mid, &mid)); } } @@ -3794,19 +3757,19 @@ CURL **curl_multi_get_handles(CURLM *m) { struct Curl_multi *multi = m; void *entry; - unsigned int count = Curl_uint_tbl_count(&multi->xfers); - CURL **a = malloc(sizeof(struct Curl_easy *) * (count + 1)); + unsigned int count = Curl_uint32_tbl_count(&multi->xfers); + CURL **a = curlx_malloc(sizeof(struct Curl_easy *) * (count + 1)); if(a) { - unsigned int i = 0, mid; + unsigned int i = 0; + uint32_t mid; - if(Curl_uint_tbl_first(&multi->xfers, &mid, &entry)) { + if(Curl_uint32_tbl_first(&multi->xfers, &mid, &entry)) { do { struct Curl_easy *data = entry; DEBUGASSERT(i < count); if(!data->state.internal) a[i++] = data; - } - while(Curl_uint_tbl_next(&multi->xfers, mid, &mid, &entry)); + } while(Curl_uint32_tbl_next(&multi->xfers, mid, &mid, &entry)); } a[i] = NULL; /* last entry is a NULL */ } @@ -3818,6 +3781,7 @@ CURLMcode curl_multi_get_offt(CURLM *m, curl_off_t *pvalue) { struct Curl_multi *multi = m; + uint32_t n; if(!GOOD_MULTI_HANDLE(multi)) return CURLM_BAD_HANDLE; @@ -3825,21 +3789,23 @@ CURLMcode curl_multi_get_offt(CURLM *m, return CURLM_BAD_FUNCTION_ARGUMENT; switch(info) { - case CURLMINFO_XFERS_CURRENT: { - unsigned int n = Curl_uint_tbl_count(&multi->xfers); + case CURLMINFO_XFERS_CURRENT: + n = Curl_uint32_tbl_count(&multi->xfers); if(n && multi->admin) --n; *pvalue = (curl_off_t)n; return CURLM_OK; - } case CURLMINFO_XFERS_RUNNING: - *pvalue = (curl_off_t)Curl_uint_bset_count(&multi->process); + n = Curl_uint32_bset_count(&multi->process); + if(n && Curl_uint32_bset_contains(&multi->process, multi->admin->mid)) + --n; + *pvalue = (curl_off_t)n; return CURLM_OK; case CURLMINFO_XFERS_PENDING: - *pvalue = (curl_off_t)Curl_uint_bset_count(&multi->pending); + *pvalue = (curl_off_t)Curl_uint32_bset_count(&multi->pending); return CURLM_OK; case CURLMINFO_XFERS_DONE: - *pvalue = (curl_off_t)Curl_uint_bset_count(&multi->msgsent); + *pvalue = (curl_off_t)Curl_uint32_bset_count(&multi->msgsent); return CURLM_OK; case CURLMINFO_XFERS_ADDED: *pvalue = multi->xfers_total_ever; @@ -3873,16 +3839,16 @@ CURLcode Curl_multi_xfer_buf_borrow(struct Curl_easy *data, if(data->multi->xfer_buf && data->set.buffer_size > data->multi->xfer_buf_len) { /* not large enough, get a new one */ - free(data->multi->xfer_buf); + curlx_free(data->multi->xfer_buf); data->multi->xfer_buf = NULL; data->multi->xfer_buf_len = 0; } if(!data->multi->xfer_buf) { - data->multi->xfer_buf = malloc((size_t)data->set.buffer_size); + data->multi->xfer_buf = curlx_malloc(curlx_uitouz(data->set.buffer_size)); if(!data->multi->xfer_buf) { - failf(data, "could not allocate xfer_buf of %zu bytes", - (size_t)data->set.buffer_size); + failf(data, "could not allocate xfer_buf of %u bytes", + data->set.buffer_size); return CURLE_OUT_OF_MEMORY; } data->multi->xfer_buf_len = data->set.buffer_size; @@ -3926,16 +3892,17 @@ CURLcode Curl_multi_xfer_ulbuf_borrow(struct Curl_easy *data, if(data->multi->xfer_ulbuf && data->set.upload_buffer_size > data->multi->xfer_ulbuf_len) { /* not large enough, get a new one */ - free(data->multi->xfer_ulbuf); + curlx_free(data->multi->xfer_ulbuf); data->multi->xfer_ulbuf = NULL; data->multi->xfer_ulbuf_len = 0; } if(!data->multi->xfer_ulbuf) { - data->multi->xfer_ulbuf = malloc((size_t)data->set.upload_buffer_size); + data->multi->xfer_ulbuf = + curlx_malloc(curlx_uitouz(data->set.upload_buffer_size)); if(!data->multi->xfer_ulbuf) { - failf(data, "could not allocate xfer_ulbuf of %zu bytes", - (size_t)data->set.upload_buffer_size); + failf(data, "could not allocate xfer_ulbuf of %u bytes", + data->set.upload_buffer_size); return CURLE_OUT_OF_MEMORY; } data->multi->xfer_ulbuf_len = data->set.upload_buffer_size; @@ -3973,13 +3940,13 @@ CURLcode Curl_multi_xfer_sockbuf_borrow(struct Curl_easy *data, if(data->multi->xfer_sockbuf && blen > data->multi->xfer_sockbuf_len) { /* not large enough, get a new one */ - free(data->multi->xfer_sockbuf); + curlx_free(data->multi->xfer_sockbuf); data->multi->xfer_sockbuf = NULL; data->multi->xfer_sockbuf_len = 0; } if(!data->multi->xfer_sockbuf) { - data->multi->xfer_sockbuf = malloc(blen); + data->multi->xfer_sockbuf = curlx_malloc(blen); if(!data->multi->xfer_sockbuf) { failf(data, "could not allocate xfer_sockbuf of %zu bytes", blen); return CURLE_OUT_OF_MEMORY; @@ -4016,14 +3983,14 @@ static void multi_xfer_bufs_free(struct Curl_multi *multi) } struct Curl_easy *Curl_multi_get_easy(struct Curl_multi *multi, - unsigned int mid) + uint32_t mid) { - struct Curl_easy *data = mid ? Curl_uint_tbl_get(&multi->xfers, mid) : NULL; + struct Curl_easy *data = Curl_uint32_tbl_get(&multi->xfers, mid); if(data && GOOD_EASY_HANDLE(data)) return data; CURL_TRC_M(multi->admin, "invalid easy handle in xfer table for mid=%u", mid); - Curl_uint_tbl_remove(&multi->xfers, mid); + Curl_uint32_tbl_remove(&multi->xfers, mid); return NULL; } @@ -4034,14 +4001,14 @@ unsigned int Curl_multi_xfers_running(struct Curl_multi *multi) void Curl_multi_mark_dirty(struct Curl_easy *data) { - if(data->multi && data->mid != UINT_MAX) - Curl_uint_bset_add(&data->multi->dirty, data->mid); + if(data->multi && data->mid != UINT32_MAX) + Curl_uint32_bset_add(&data->multi->dirty, data->mid); } void Curl_multi_clear_dirty(struct Curl_easy *data) { - if(data->multi && data->mid != UINT_MAX) - Curl_uint_bset_remove(&data->multi->dirty, data->mid); + if(data->multi && data->mid != UINT32_MAX) + Curl_uint32_bset_remove(&data->multi->dirty, data->mid); } CURLMcode curl_multi_notify_enable(CURLM *m, unsigned int notification) @@ -4063,7 +4030,7 @@ CURLMcode curl_multi_notify_disable(CURLM *m, unsigned int notification) } #ifdef DEBUGBUILD -static void multi_xfer_dump(struct Curl_multi *multi, unsigned int mid, +static void multi_xfer_dump(struct Curl_multi *multi, uint32_t mid, void *entry) { struct Curl_easy *data = entry; @@ -4077,20 +4044,20 @@ static void multi_xfer_dump(struct Curl_multi *multi, unsigned int mid, ", url=%s\n", mid, (data->magic == CURLEASY_MAGIC_NUMBER) ? "GOOD" : "BAD!", - (void *)data, data->id, data->state.url); + (void *)data, data->id, Curl_bufref_ptr(&data->state.url)); } } static void multi_xfer_tbl_dump(struct Curl_multi *multi) { - unsigned int mid; + uint32_t mid; void *entry; curl_mfprintf(stderr, "=== multi xfer table (count=%u, capacity=%u\n", - Curl_uint_tbl_count(&multi->xfers), - Curl_uint_tbl_capacity(&multi->xfers)); - if(Curl_uint_tbl_first(&multi->xfers, &mid, &entry)) { + Curl_uint32_tbl_count(&multi->xfers), + Curl_uint32_tbl_capacity(&multi->xfers)); + if(Curl_uint32_tbl_first(&multi->xfers, &mid, &entry)) { multi_xfer_dump(multi, mid, entry); - while(Curl_uint_tbl_next(&multi->xfers, mid, &mid, &entry)) + while(Curl_uint32_tbl_next(&multi->xfers, mid, &mid, &entry)) multi_xfer_dump(multi, mid, entry); } curl_mfprintf(stderr, "===\n"); diff --git a/vendor/hydra/vendor/curl/lib/multi_ev.c b/vendor/hydra/vendor/curl/lib/multi_ev.c index ff755caa..0c89721f 100644 --- a/vendor/hydra/vendor/curl/lib/multi_ev.c +++ b/vendor/hydra/vendor/curl/lib/multi_ev.c @@ -21,29 +21,18 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include - #include "urldata.h" #include "url.h" #include "cfilters.h" #include "curl_trc.h" #include "multiif.h" -#include "curlx/timeval.h" #include "multi_ev.h" #include "select.h" #include "uint-bset.h" #include "uint-spbset.h" -#include "uint-table.h" -#include "curlx/warnless.h" #include "multihandle.h" -#include "socks.h" - -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" static void mev_in_callback(struct Curl_multi *multi, bool value) @@ -55,7 +44,7 @@ static void mev_in_callback(struct Curl_multi *multi, bool value) * what to supervise (CURL_POLL_IN/CURL_POLL_OUT/CURL_POLL_REMOVE) */ struct mev_sh_entry { - struct uint_spbset xfers; /* bitset of transfers `mid`s on this socket */ + struct uint32_spbset xfers; /* bitset of transfers `mid`s on this socket */ struct connectdata *conn; /* connection using this socket or NULL */ void *user_data; /* libcurl app data via curl_multi_assign() */ unsigned int action; /* CURL_POLL_IN/CURL_POLL_OUT we last told the @@ -68,7 +57,7 @@ struct mev_sh_entry { static size_t mev_sh_entry_hash(void *key, size_t key_length, size_t slots_num) { - curl_socket_t fd = *((curl_socket_t *) key); + curl_socket_t fd = *((curl_socket_t *)key); (void)key_length; return (fd % (curl_socket_t)slots_num); } @@ -76,21 +65,22 @@ static size_t mev_sh_entry_hash(void *key, size_t key_length, size_t slots_num) static size_t mev_sh_entry_compare(void *k1, size_t k1_len, void *k2, size_t k2_len) { - (void)k1_len; (void)k2_len; - return (*((curl_socket_t *) k1)) == (*((curl_socket_t *) k2)); + (void)k1_len; + (void)k2_len; + return (*((curl_socket_t *)k1)) == (*((curl_socket_t *)k2)); } /* sockhash entry destructor callback */ static void mev_sh_entry_dtor(void *freethis) { struct mev_sh_entry *entry = (struct mev_sh_entry *)freethis; - Curl_uint_spbset_destroy(&entry->xfers); - free(entry); + Curl_uint32_spbset_destroy(&entry->xfers); + curlx_free(entry); } /* look up a given socket in the socket hash, skip invalid sockets */ -static struct mev_sh_entry * -mev_sh_entry_get(struct Curl_hash *sh, curl_socket_t s) +static struct mev_sh_entry *mev_sh_entry_get(struct Curl_hash *sh, + curl_socket_t s) { if(s != CURL_SOCKET_BAD) { /* only look for proper sockets */ @@ -100,8 +90,8 @@ mev_sh_entry_get(struct Curl_hash *sh, curl_socket_t s) } /* make sure this socket is present in the hash for this handle */ -static struct mev_sh_entry * -mev_sh_entry_add(struct Curl_hash *sh, curl_socket_t s) +static struct mev_sh_entry *mev_sh_entry_add(struct Curl_hash *sh, + curl_socket_t s) { struct mev_sh_entry *there = mev_sh_entry_get(sh, s); struct mev_sh_entry *check; @@ -112,11 +102,11 @@ mev_sh_entry_add(struct Curl_hash *sh, curl_socket_t s) } /* not present, add it */ - check = calloc(1, sizeof(struct mev_sh_entry)); + check = curlx_calloc(1, sizeof(struct mev_sh_entry)); if(!check) return NULL; /* major failure */ - Curl_uint_spbset_init(&check->xfers); + Curl_uint32_spbset_init(&check->xfers); /* make/add new hash entry */ if(!Curl_hash_add(sh, (char *)&s, sizeof(curl_socket_t), check)) { @@ -135,13 +125,13 @@ static void mev_sh_entry_kill(struct Curl_multi *multi, curl_socket_t s) static size_t mev_sh_entry_user_count(struct mev_sh_entry *e) { - return Curl_uint_spbset_count(&e->xfers) + (e->conn ? 1 : 0); + return Curl_uint32_spbset_count(&e->xfers) + (e->conn ? 1 : 0); } static bool mev_sh_entry_xfer_known(struct mev_sh_entry *e, struct Curl_easy *data) { - return Curl_uint_spbset_contains(&e->xfers, data->mid); + return Curl_uint32_spbset_contains(&e->xfers, data->mid); } static bool mev_sh_entry_conn_known(struct mev_sh_entry *e, @@ -155,7 +145,7 @@ static bool mev_sh_entry_xfer_add(struct mev_sh_entry *e, { /* detect weird values */ DEBUGASSERT(mev_sh_entry_user_count(e) < 100000); - return Curl_uint_spbset_add(&e->xfers, data->mid); + return Curl_uint32_spbset_add(&e->xfers, data->mid); } static bool mev_sh_entry_conn_add(struct mev_sh_entry *e, @@ -170,13 +160,12 @@ static bool mev_sh_entry_conn_add(struct mev_sh_entry *e, return TRUE; } - static bool mev_sh_entry_xfer_remove(struct mev_sh_entry *e, struct Curl_easy *data) { - bool present = Curl_uint_spbset_contains(&e->xfers, data->mid); + bool present = Curl_uint32_spbset_contains(&e->xfers, data->mid); if(present) - Curl_uint_spbset_remove(&e->xfers, data->mid); + Curl_uint32_spbset_remove(&e->xfers, data->mid); return present; } @@ -206,8 +195,7 @@ static CURLMcode mev_forget_socket(struct Curl_multi *multi, /* We managed this socket before, tell the socket callback to forget it. */ if(entry->announced && multi->socket_cb) { - CURL_TRC_M(data, "ev %s, call(fd=%" FMT_SOCKET_T ", ev=REMOVE)", - cause, s); + CURL_TRC_M(data, "ev %s, call(fd=%" FMT_SOCKET_T ", ev=REMOVE)", cause, s); mev_in_callback(multi, TRUE); rc = multi->socket_cb(data, s, CURL_POLL_REMOVE, multi->socket_userp, entry->user_data); @@ -340,7 +328,7 @@ static CURLMcode mev_pollset_diff(struct Curl_multi *multi, /* What was the previous action the transfer had regarding this socket? * If the transfer is new to the socket, disregard the information * in `last_poll`, because the socket might have been destroyed and - * reopened. We'd have cleared the sh_entry for that, but the socket + * reopened. We would have cleared the sh_entry for that, but the socket * might still be mentioned in the hashed pollsets. */ last_action = 0; if(first_time) { @@ -356,7 +344,7 @@ static CURLMcode mev_pollset_diff(struct Curl_multi *multi, ", total=%u/%d (xfer/conn)", s, conn ? "connection" : "transfer", conn ? conn->connection_id : data->mid, - Curl_uint_spbset_count(&entry->xfers), + Curl_uint32_spbset_count(&entry->xfers), entry->conn ? 1 : 0); } else { @@ -424,7 +412,7 @@ static CURLMcode mev_pollset_diff(struct Curl_multi *multi, return mresult; CURL_TRC_M(data, "ev entry fd=%" FMT_SOCKET_T ", removed transfer, " "total=%u/%d (xfer/conn)", s, - Curl_uint_spbset_count(&entry->xfers), + Curl_uint32_spbset_count(&entry->xfers), entry->conn ? 1 : 0); } else { @@ -446,12 +434,11 @@ static void mev_pollset_dtor(void *key, size_t klen, void *entry) (void)klen; if(ps) { Curl_pollset_cleanup(ps); - free(ps); + curlx_free(ps); } } -static struct easy_pollset* -mev_add_new_conn_pollset(struct connectdata *conn) +static struct easy_pollset *mev_add_new_conn_pollset(struct connectdata *conn) { struct easy_pollset *ps; @@ -463,8 +450,7 @@ mev_add_new_conn_pollset(struct connectdata *conn) return ps; } -static struct easy_pollset* -mev_add_new_xfer_pollset(struct Curl_easy *data) +static struct easy_pollset *mev_add_new_xfer_pollset(struct Curl_easy *data) { struct easy_pollset *ps; @@ -476,9 +462,8 @@ mev_add_new_xfer_pollset(struct Curl_easy *data) return ps; } -static struct easy_pollset * -mev_get_last_pollset(struct Curl_easy *data, - struct connectdata *conn) +static struct easy_pollset *mev_get_last_pollset(struct Curl_easy *data, + struct connectdata *conn) { if(data) { if(conn) @@ -493,7 +478,7 @@ static CURLMcode mev_assess(struct Curl_multi *multi, struct connectdata *conn) { struct easy_pollset ps, *last_ps; - CURLMcode res = CURLM_OK; + CURLMcode mresult = CURLM_OK; if(!multi || !multi->socket_cb) return CURLM_OK; @@ -502,13 +487,13 @@ static CURLMcode mev_assess(struct Curl_multi *multi, if(conn) { CURLcode r = Curl_conn_adjust_pollset(data, conn, &ps); if(r) { - res = (r == CURLE_OUT_OF_MEMORY) ? - CURLM_OUT_OF_MEMORY : CURLM_INTERNAL_ERROR; + mresult = (r == CURLE_OUT_OF_MEMORY) ? + CURLM_OUT_OF_MEMORY : CURLM_INTERNAL_ERROR; goto out; } } else - Curl_multi_pollset(data, &ps, "ev assess"); + Curl_multi_pollset(data, &ps); last_ps = mev_get_last_pollset(data, conn); if(!last_ps && ps.n) { @@ -517,18 +502,18 @@ static CURLMcode mev_assess(struct Curl_multi *multi, else last_ps = mev_add_new_xfer_pollset(data); if(!last_ps) { - res = CURLM_OUT_OF_MEMORY; + mresult = CURLM_OUT_OF_MEMORY; goto out; } } if(last_ps) - res = mev_pollset_diff(multi, data, conn, &ps, last_ps); + mresult = mev_pollset_diff(multi, data, conn, &ps, last_ps); else DEBUGASSERT(!ps.n); out: Curl_pollset_cleanup(&ps); - return res; + return mresult; } CURLMcode Curl_multi_ev_assess_xfer(struct Curl_multi *multi, @@ -545,23 +530,22 @@ CURLMcode Curl_multi_ev_assess_conn(struct Curl_multi *multi, } CURLMcode Curl_multi_ev_assess_xfer_bset(struct Curl_multi *multi, - struct uint_bset *set) + struct uint32_bset *set) { - unsigned int mid; - CURLMcode result = CURLM_OK; + uint32_t mid; + CURLMcode mresult = CURLM_OK; - if(multi && multi->socket_cb && Curl_uint_bset_first(set, &mid)) { + if(multi && multi->socket_cb && Curl_uint32_bset_first(set, &mid)) { do { struct Curl_easy *data = Curl_multi_get_easy(multi, mid); - if(data) - result = Curl_multi_ev_assess_xfer(multi, data); - } - while(!result && Curl_uint_bset_next(set, mid, &mid)); + if(data) { + mresult = Curl_multi_ev_assess_xfer(multi, data); + } + } while(!mresult && Curl_uint32_bset_next(set, mid, &mid)); } - return result; + return mresult; } - CURLMcode Curl_multi_ev_assign(struct Curl_multi *multi, curl_socket_t s, void *user_data) @@ -574,8 +558,7 @@ CURLMcode Curl_multi_ev_assign(struct Curl_multi *multi, } void Curl_multi_ev_dirty_xfers(struct Curl_multi *multi, - curl_socket_t s, - bool *run_cpool) + curl_socket_t s) { struct mev_sh_entry *entry; @@ -589,9 +572,9 @@ void Curl_multi_ev_dirty_xfers(struct Curl_multi *multi, and just move on. */ if(entry) { struct Curl_easy *data; - unsigned int mid; + uint32_t mid; - if(Curl_uint_spbset_first(&entry->xfers, &mid)) { + if(Curl_uint32_spbset_first(&entry->xfers, &mid)) { do { data = Curl_multi_get_easy(multi, mid); if(data) { @@ -599,14 +582,13 @@ void Curl_multi_ev_dirty_xfers(struct Curl_multi *multi, } else { CURL_TRC_M(multi->admin, "socket transfer %u no longer found", mid); - Curl_uint_spbset_remove(&entry->xfers, mid); + Curl_uint32_spbset_remove(&entry->xfers, mid); } - } - while(Curl_uint_spbset_next(&entry->xfers, mid, &mid)); + } while(Curl_uint32_spbset_next(&entry->xfers, mid, &mid)); } if(entry->conn) - *run_cpool = TRUE; + Curl_multi_mark_dirty(multi->admin); } } diff --git a/vendor/hydra/vendor/curl/lib/multi_ev.h b/vendor/hydra/vendor/curl/lib/multi_ev.h index 20c1aeac..ddbb9331 100644 --- a/vendor/hydra/vendor/curl/lib/multi_ev.h +++ b/vendor/hydra/vendor/curl/lib/multi_ev.h @@ -23,13 +23,12 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "hash.h" struct Curl_easy; struct Curl_multi; struct easy_pollset; -struct uint_bset; +struct uint32_bset; /* meta key for event pollset at easy handle or connection */ #define CURL_META_MEV_POLLSET "meta:mev:ps" @@ -55,7 +54,7 @@ CURLMcode Curl_multi_ev_assess_xfer(struct Curl_multi *multi, struct Curl_easy *data); /* Assess all easy handles on the list */ CURLMcode Curl_multi_ev_assess_xfer_bset(struct Curl_multi *multi, - struct uint_bset *set); + struct uint32_bset *set); /* Assess the connection by getting its current pollset */ CURLMcode Curl_multi_ev_assess_conn(struct Curl_multi *multi, struct Curl_easy *data, @@ -63,8 +62,7 @@ CURLMcode Curl_multi_ev_assess_conn(struct Curl_multi *multi, /* Mark all transfers tied to the given socket as dirty */ void Curl_multi_ev_dirty_xfers(struct Curl_multi *multi, - curl_socket_t s, - bool *run_cpool); + curl_socket_t s); /* Socket will be closed, forget anything we know about it. */ void Curl_multi_ev_socket_done(struct Curl_multi *multi, diff --git a/vendor/hydra/vendor/curl/lib/multi_ntfy.c b/vendor/hydra/vendor/curl/lib/multi_ntfy.c index fe7cc050..4921fc55 100644 --- a/vendor/hydra/vendor/curl/lib/multi_ntfy.c +++ b/vendor/hydra/vendor/curl/lib/multi_ntfy.c @@ -21,29 +21,21 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include - #include "urldata.h" #include "curl_trc.h" #include "multihandle.h" #include "multiif.h" #include "multi_ntfy.h" -/* The last 3 #include files should be in this order */ -#include "curl_printf.h" -#include "curl_memory.h" -#include "memdebug.h" - struct mntfy_entry { - unsigned int mid; - unsigned int type; + uint32_t mid; + uint32_t type; }; -#define CURL_MNTFY_CHUNK_SIZE 128 +#define CURL_MNTFY_CHUNK_SIZE 128 struct mntfy_chunk { struct mntfy_chunk *next; @@ -54,12 +46,12 @@ struct mntfy_chunk { static struct mntfy_chunk *mnfty_chunk_create(void) { - return calloc(1, sizeof(struct mntfy_chunk)); + return curlx_calloc(1, sizeof(struct mntfy_chunk)); } static void mnfty_chunk_destroy(struct mntfy_chunk *chunk) { - free(chunk); + curlx_free(chunk); } static void mnfty_chunk_reset(struct mntfy_chunk *chunk) @@ -69,7 +61,7 @@ static void mnfty_chunk_reset(struct mntfy_chunk *chunk) static bool mntfy_chunk_append(struct mntfy_chunk *chunk, struct Curl_easy *data, - unsigned int type) + uint32_t type) { struct mntfy_entry *e; @@ -116,7 +108,7 @@ static void mntfy_chunk_dispatch_all(struct Curl_multi *multi, e = &chunk->entries[chunk->r_offset]; data = e->mid ? Curl_multi_get_easy(multi, e->mid) : multi->admin; /* only when notification has not been disabled in the meantime */ - if(data && Curl_uint_bset_contains(&multi->ntfy.enabled, e->type)) { + if(data && Curl_uint32_bset_contains(&multi->ntfy.enabled, e->type)) { /* this may cause new notifications to be added! */ CURL_TRC_M(multi->admin, "[NTFY] dispatch %d to xfer %u", e->type, e->mid); @@ -132,12 +124,12 @@ static void mntfy_chunk_dispatch_all(struct Curl_multi *multi, void Curl_mntfy_init(struct Curl_multi *multi) { memset(&multi->ntfy, 0, sizeof(multi->ntfy)); - Curl_uint_bset_init(&multi->ntfy.enabled); + Curl_uint32_bset_init(&multi->ntfy.enabled); } CURLMcode Curl_mntfy_resize(struct Curl_multi *multi) { - if(Curl_uint_bset_resize(&multi->ntfy.enabled, CURLMNOTIFY_EASY_DONE + 1)) + if(Curl_uint32_bset_resize(&multi->ntfy.enabled, CURLMNOTIFY_EASY_DONE + 1)) return CURLM_OUT_OF_MEMORY; return CURLM_OK; } @@ -150,14 +142,14 @@ void Curl_mntfy_cleanup(struct Curl_multi *multi) mnfty_chunk_destroy(chunk); } multi->ntfy.tail = NULL; - Curl_uint_bset_destroy(&multi->ntfy.enabled); + Curl_uint32_bset_destroy(&multi->ntfy.enabled); } CURLMcode Curl_mntfy_enable(struct Curl_multi *multi, unsigned int type) { if(type > CURLMNOTIFY_EASY_DONE) return CURLM_UNKNOWN_OPTION; - Curl_uint_bset_add(&multi->ntfy.enabled, type); + Curl_uint32_bset_add(&multi->ntfy.enabled, type); return CURLM_OK; } @@ -165,7 +157,7 @@ CURLMcode Curl_mntfy_disable(struct Curl_multi *multi, unsigned int type) { if(type > CURLMNOTIFY_EASY_DONE) return CURLM_UNKNOWN_OPTION; - Curl_uint_bset_remove(&multi->ntfy.enabled, type); + Curl_uint32_bset_remove(&multi->ntfy.enabled, (uint32_t)type); return CURLM_OK; } @@ -173,14 +165,15 @@ void Curl_mntfy_add(struct Curl_easy *data, unsigned int type) { struct Curl_multi *multi = data ? data->multi : NULL; if(multi && multi->ntfy.ntfy_cb && !multi->ntfy.failure && - Curl_uint_bset_contains(&multi->ntfy.enabled, type)) { + Curl_uint32_bset_contains(&multi->ntfy.enabled, (uint32_t)type)) { /* append to list of outstanding notifications */ struct mntfy_chunk *tail = mntfy_non_full_tail(&multi->ntfy); - CURL_TRC_M(data, "[NTFY] add %d for xfer %u", type, data->mid); + CURL_TRC_M(data, "[NTFY] add %d for xfer %u", type, data->mid); if(tail) - mntfy_chunk_append(tail, data, type); + mntfy_chunk_append(tail, data, (uint32_t)type); else multi->ntfy.failure = CURLM_OUT_OF_MEMORY; + multi->ntfy.has_entries = TRUE; } } @@ -204,9 +197,11 @@ CURLMcode Curl_mntfy_dispatch_all(struct Curl_multi *multi) multi->in_ntfy_callback = FALSE; if(multi->ntfy.failure) { - CURLMcode result = multi->ntfy.failure; + CURLMcode mresult = multi->ntfy.failure; multi->ntfy.failure = CURLM_OK; /* reset, once delivered */ - return result; + return mresult; } + else + multi->ntfy.has_entries = FALSE; return CURLM_OK; } diff --git a/vendor/hydra/vendor/curl/lib/multi_ntfy.h b/vendor/hydra/vendor/curl/lib/multi_ntfy.h index d920b329..05df2d66 100644 --- a/vendor/hydra/vendor/curl/lib/multi_ntfy.h +++ b/vendor/hydra/vendor/curl/lib/multi_ntfy.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "uint-bset.h" struct Curl_easy; @@ -32,10 +31,11 @@ struct Curl_multi; struct curl_multi_ntfy { curl_notify_callback ntfy_cb; void *ntfy_cb_data; - struct uint_bset enabled; - CURLMcode failure; + struct uint32_bset enabled; struct mntfy_chunk *head; struct mntfy_chunk *tail; + CURLMcode failure; + BIT(has_entries); }; void Curl_mntfy_init(struct Curl_multi *multi); @@ -47,11 +47,14 @@ CURLMcode Curl_mntfy_disable(struct Curl_multi *multi, unsigned int type); void Curl_mntfy_add(struct Curl_easy *data, unsigned int type); -#define CURLM_NTFY(d,t) \ - do { if((d) && (d)->multi && (d)->multi->ntfy.ntfy_cb) \ - Curl_mntfy_add((d), (t)); } while(0) +#define CURLM_NTFY(d, t) \ + do { \ + if((d) && (d)->multi && (d)->multi->ntfy.ntfy_cb) \ + Curl_mntfy_add((d), (t)); \ + } while(0) -CURLMcode Curl_mntfy_dispatch_all(struct Curl_multi *multi); +#define CURL_MNTFY_HAS_ENTRIES(m) ((m)->ntfy.has_entries) +CURLMcode Curl_mntfy_dispatch_all(struct Curl_multi *multi); #endif /* HEADER_CURL_MULTI_NTFY_H */ diff --git a/vendor/hydra/vendor/curl/lib/multihandle.h b/vendor/hydra/vendor/curl/lib/multihandle.h index 69f977bb..f66853f5 100644 --- a/vendor/hydra/vendor/curl/lib/multihandle.h +++ b/vendor/hydra/vendor/curl/lib/multihandle.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "llist.h" #include "hash.h" #include "conncache.h" @@ -51,26 +50,23 @@ struct Curl_message { */ typedef enum { MSTATE_INIT, /* 0 - start in this state */ - MSTATE_PENDING, /* 1 - no connections, waiting for one */ - MSTATE_SETUP, /* 2 - start a new transfer */ - MSTATE_CONNECT, /* 3 - resolve/connect has been sent off */ - MSTATE_RESOLVING, /* 4 - awaiting the resolve to finalize */ - MSTATE_CONNECTING, /* 5 - awaiting the TCP connect to finalize */ - MSTATE_TUNNELING, /* 6 - awaiting HTTPS proxy SSL initialization to - complete and/or proxy CONNECT to finalize */ - MSTATE_PROTOCONNECT, /* 7 - initiate protocol connect procedure */ - MSTATE_PROTOCONNECTING, /* 8 - completing the protocol-specific connect - phase */ - MSTATE_DO, /* 9 - start send off the request (part 1) */ - MSTATE_DOING, /* 10 - sending off the request (part 1) */ - MSTATE_DOING_MORE, /* 11 - send off the request (part 2) */ - MSTATE_DID, /* 12 - done sending off request */ - MSTATE_PERFORMING, /* 13 - transfer data */ - MSTATE_RATELIMITING, /* 14 - wait because limit-rate exceeded */ - MSTATE_DONE, /* 15 - post data transfer operation */ - MSTATE_COMPLETED, /* 16 - operation complete */ - MSTATE_MSGSENT, /* 17 - the operation complete message is sent */ - MSTATE_LAST /* 18 - not a true state, never use this */ + MSTATE_PENDING, /* no connections, waiting for one */ + MSTATE_SETUP, /* start a new transfer */ + MSTATE_CONNECT, /* resolve/connect has been sent off */ + MSTATE_RESOLVING, /* awaiting the resolve to finalize */ + MSTATE_CONNECTING, /* awaiting the TCP connect to finalize */ + MSTATE_PROTOCONNECT, /* initiate protocol connect procedure */ + MSTATE_PROTOCONNECTING, /* completing the protocol-specific connect phase */ + MSTATE_DO, /* start send off the request (part 1) */ + MSTATE_DOING, /* sending off the request (part 1) */ + MSTATE_DOING_MORE, /* send off the request (part 2) */ + MSTATE_DID, /* done sending off request */ + MSTATE_PERFORMING, /* transfer data */ + MSTATE_RATELIMITING, /* wait because limit-rate exceeded */ + MSTATE_DONE, /* post data transfer operation */ + MSTATE_COMPLETED, /* operation complete */ + MSTATE_MSGSENT, /* the operation complete message is sent */ + MSTATE_LAST /* not a true state, never use this */ } CURLMstate; #define CURLPIPE_ANY (CURLPIPE_MULTIPLEX) @@ -91,12 +87,12 @@ struct Curl_multi { unsigned int xfers_alive; /* amount of added transfers that have not yet reached COMPLETE state */ curl_off_t xfers_total_ever; /* total of added transfers, ever. */ - struct uint_tbl xfers; /* transfers added to this multi */ + struct uint32_tbl xfers; /* transfers added to this multi */ /* Each transfer's mid may be present in at most one of these */ - struct uint_bset process; /* transfer being processed */ - struct uint_bset dirty; /* transfer to be run NOW, e.g. ASAP. */ - struct uint_bset pending; /* transfers in waiting (conn limit etc.) */ - struct uint_bset msgsent; /* transfers done with message for application */ + struct uint32_bset process; /* transfer being processed */ + struct uint32_bset dirty; /* transfer to be run NOW, e.g. ASAP. */ + struct uint32_bset pending; /* transfers in waiting (conn limit etc.) */ + struct uint32_bset msgsent; /* transfers done with message for application */ struct Curl_llist msglist; /* a list of messages from completed transfers */ @@ -119,6 +115,8 @@ struct Curl_multi { struct PslCache psl; #endif + /* current time for transfers running in this multi handle */ + struct curltime now; /* timetree points to the splay-tree of time nodes to figure out expire times of all currently set timers */ struct Curl_tree *timetree; @@ -149,11 +147,10 @@ struct Curl_multi { struct cshutdn cshutdn; /* connection shutdown handling */ struct cpool cpool; /* connection pool (bundles) */ - long max_host_connections; /* if >0, a fixed limit of the maximum number - of connections per host */ - - long max_total_connections; /* if >0, a fixed limit of the maximum number - of connections in total */ + size_t max_host_connections; /* if >0, a fixed limit of the maximum number + of connections per host */ + size_t max_total_connections; /* if >0, a fixed limit of the maximum number + of connections in total */ /* timer callback and user data pointer for the *socket() API */ curl_multi_timer_callback timer_cb; @@ -174,6 +171,9 @@ struct Curl_multi { unsigned int maxconnects; /* if >0, a fixed limit of the maximum number of entries we are allowed to grow the connection cache to */ +#ifdef DEBUGBUILD + unsigned int now_access_count; +#endif #define IPV6_UNKNOWN 0 #define IPV6_DEAD 1 #define IPV6_WORKS 2 diff --git a/vendor/hydra/vendor/curl/lib/multiif.h b/vendor/hydra/vendor/curl/lib/multiif.h index 1423d5a0..15fc0703 100644 --- a/vendor/hydra/vendor/curl/lib/multiif.h +++ b/vendor/hydra/vendor/curl/lib/multiif.h @@ -23,14 +23,12 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - /* * Prototypes for library-wide functions provided by multi.c */ void Curl_expire(struct Curl_easy *data, timediff_t milli, expire_id); void Curl_expire_ex(struct Curl_easy *data, - const struct curltime *nowp, timediff_t milli, expire_id id); bool Curl_expire_clear(struct Curl_easy *data); void Curl_expire_done(struct Curl_easy *data, expire_id id); @@ -47,7 +45,7 @@ void Curl_multi_connchanged(struct Curl_multi *multi); /* Internal version of curl_multi_init() accepts size parameters for the socket, connection and dns hashes */ -struct Curl_multi *Curl_multi_handle(unsigned int xfer_table_size, +struct Curl_multi *Curl_multi_handle(uint32_t xfer_table_size, size_t hashsize, size_t chashsize, size_t dnssize, @@ -68,13 +66,11 @@ CURLMcode Curl_multi_add_perform(struct Curl_multi *multi, struct Curl_easy *data, struct connectdata *conn); - /* Return the value of the CURLMOPT_MAX_CONCURRENT_STREAMS option */ unsigned int Curl_multi_max_concurrent_streams(struct Curl_multi *multi); CURLMcode Curl_multi_pollset(struct Curl_easy *data, - struct easy_pollset *ps, - const char *caller); + struct easy_pollset *ps); /** * Borrow the transfer buffer from the multi, suitable @@ -154,7 +150,7 @@ void Curl_multi_xfer_sockbuf_release(struct Curl_easy *data, char *buf); * Returns NULL if not found. */ struct Curl_easy *Curl_multi_get_easy(struct Curl_multi *multi, - unsigned int mid); + uint32_t mid); /* Get the # of transfers current in process/pending. */ unsigned int Curl_multi_xfers_running(struct Curl_multi *multi); @@ -165,4 +161,6 @@ void Curl_multi_mark_dirty(struct Curl_easy *data); /* Clear transfer from the dirty set. */ void Curl_multi_clear_dirty(struct Curl_easy *data); +void Curl_multi_set_now(struct Curl_multi *multi); + #endif /* HEADER_CURL_MULTIIF_H */ diff --git a/vendor/hydra/vendor/curl/lib/netrc.c b/vendor/hydra/vendor/curl/lib/netrc.c index 9c5c6c7f..0678733d 100644 --- a/vendor/hydra/vendor/curl/lib/netrc.c +++ b/vendor/hydra/vendor/curl/lib/netrc.c @@ -21,8 +21,8 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" + #ifndef CURL_DISABLE_NETRC #ifdef HAVE_PWD_H @@ -35,17 +35,12 @@ #endif #endif -#include #include "netrc.h" #include "strcase.h" #include "curl_get_line.h" #include "curlx/fopen.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* Get user and password from .netrc when given a machine name */ enum host_lookup_state { @@ -64,8 +59,8 @@ enum found_state { #define FOUND_LOGIN 1 #define FOUND_PASSWORD 2 -#define MAX_NETRC_LINE 16384 -#define MAX_NETRC_FILE (128*1024) +#define MAX_NETRC_LINE 16384 +#define MAX_NETRC_FILE (128 * 1024) #define MAX_NETRC_TOKEN 4096 /* convert a dynbuf call CURLcode error to a NETRCcode error */ @@ -277,8 +272,8 @@ static NETRCcode parsenetrc(struct store_netrc *store, our_login = !Curl_timestrcmp(login, tok); else { our_login = TRUE; - free(login); - login = strdup(tok); + curlx_free(login); + login = curlx_strdup(tok); if(!login) { retcode = NETRC_OUT_OF_MEMORY; /* allocation failed */ goto out; @@ -288,8 +283,8 @@ static NETRCcode parsenetrc(struct store_netrc *store, keyword = NONE; } else if(keyword == PASSWORD) { - free(password); - password = strdup(tok); + curlx_free(password); + password = curlx_strdup(tok); if(!password) { retcode = NETRC_OUT_OF_MEMORY; /* allocation failed */ goto out; @@ -322,7 +317,7 @@ static NETRCcode parsenetrc(struct store_netrc *store, if(!specific_login) Curl_safefree(login); } - if((found == (FOUND_PASSWORD|FOUND_LOGIN)) && our_login) { + if((found == (FOUND_PASSWORD | FOUND_LOGIN)) && our_login) { done = TRUE; break; } @@ -346,7 +341,7 @@ static NETRCcode parsenetrc(struct store_netrc *store, if(!retcode) { if(!password && our_login) { /* success without a password, set a blank one */ - password = strdup(""); + password = curlx_strdup(""); if(!password) retcode = NETRC_OUT_OF_MEMORY; /* out of memory */ } @@ -364,8 +359,8 @@ static NETRCcode parsenetrc(struct store_netrc *store, curlx_dyn_free(filebuf); store->loaded = FALSE; if(!specific_login) - free(login); - free(password); + curlx_free(login); + curlx_free(password); } return retcode; @@ -416,8 +411,8 @@ NETRCcode Curl_parsenetrc(struct store_netrc *store, const char *host, } else { struct passwd pw, *pw_res; - if(!getpwuid_r(geteuid(), &pw, pwbuf, sizeof(pwbuf), &pw_res) - && pw_res) { + if(!getpwuid_r(geteuid(), &pw, pwbuf, sizeof(pwbuf), &pw_res) && + pw_res) { home = pw.pw_dir; } #elif defined(HAVE_GETPWUID) && defined(HAVE_GETEUID) @@ -444,25 +439,25 @@ NETRCcode Curl_parsenetrc(struct store_netrc *store, const char *host, filealloc = curl_maprintf("%s%s.netrc", home, DIR_CHAR); if(!filealloc) { - free(homea); + curlx_free(homea); return NETRC_OUT_OF_MEMORY; } } retcode = parsenetrc(store, host, loginp, passwordp, filealloc); - free(filealloc); + curlx_free(filealloc); #ifdef _WIN32 if(retcode == NETRC_FILE_MISSING) { /* fallback to the old-style "_netrc" file */ filealloc = curl_maprintf("%s%s_netrc", home, DIR_CHAR); if(!filealloc) { - free(homea); + curlx_free(homea); return NETRC_OUT_OF_MEMORY; } retcode = parsenetrc(store, host, loginp, passwordp, filealloc); - free(filealloc); + curlx_free(filealloc); } #endif - free(homea); + curlx_free(homea); } else retcode = parsenetrc(store, host, loginp, passwordp, netrcfile); diff --git a/vendor/hydra/vendor/curl/lib/netrc.h b/vendor/hydra/vendor/curl/lib/netrc.h index 0d6d081b..99ddc625 100644 --- a/vendor/hydra/vendor/curl/lib/netrc.h +++ b/vendor/hydra/vendor/curl/lib/netrc.h @@ -23,9 +23,10 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" + #ifndef CURL_DISABLE_NETRC + #include "curlx/dynbuf.h" struct store_netrc { @@ -50,14 +51,14 @@ void Curl_netrc_cleanup(struct store_netrc *s); NETRCcode Curl_parsenetrc(struct store_netrc *s, const char *host, char **loginp, char **passwordp, const char *filename); - /* Assume: (*passwordp)[0]=0, host[0] != 0. - * If (*loginp)[0] = 0, search for login and password within a machine - * section in the netrc. - * If (*loginp)[0] != 0, search for password within machine and login. - */ +/* Assume: (*passwordp)[0]=0, host[0] != 0. + * If (*loginp)[0] = 0, search for login and password within a machine + * section in the netrc. + * If (*loginp)[0] != 0, search for password within machine and login. + */ #else /* disabled */ -#define Curl_parsenetrc(a,b,c,d,e,f) 1 +#define Curl_parsenetrc(a, b, c, d, e, f) 1 #define Curl_netrc_init(x) #define Curl_netrc_cleanup(x) #endif diff --git a/vendor/hydra/vendor/curl/lib/noproxy.c b/vendor/hydra/vendor/curl/lib/noproxy.c index 20a33599..541765b6 100644 --- a/vendor/hydra/vendor/curl/lib/noproxy.c +++ b/vendor/hydra/vendor/curl/lib/noproxy.c @@ -21,12 +21,10 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifndef CURL_DISABLE_PROXY -#include /* for curl_strnequal() */ #include "curlx/inet_pton.h" #include "noproxy.h" #include "curlx/strparse.h" @@ -117,14 +115,74 @@ enum nametype { TYPE_IPV6 }; +static bool match_host(const char *token, size_t tokenlen, + const char *name, size_t namelen) +{ + bool match = FALSE; + + /* ignore trailing dots in the token to check */ + if(token[tokenlen - 1] == '.') + tokenlen--; + + if(tokenlen && (*token == '.')) { + /* ignore leading token dot as well */ + token++; + tokenlen--; + } + /* A: example.com matches 'example.com' + B: www.example.com matches 'example.com' + C: nonexample.com DOES NOT match 'example.com' + */ + if(tokenlen == namelen) + /* case A, exact match */ + match = curl_strnequal(token, name, namelen); + else if(tokenlen < namelen) { + /* case B, tailmatch domain */ + match = (name[namelen - tokenlen - 1] == '.') && + curl_strnequal(token, name + (namelen - tokenlen), tokenlen); + } + /* case C passes through, not a match */ + return match; +} + +static bool match_ip(int type, const char *token, size_t tokenlen, + const char *name) +{ + const char *check = token; + char *slash; + unsigned int bits = 0; + char checkip[128]; + if(tokenlen >= sizeof(checkip)) + /* this cannot match */ + return FALSE; + /* copy the check name to a temp buffer */ + memcpy(checkip, check, tokenlen); + checkip[tokenlen] = 0; + check = checkip; + + slash = strchr(check, '/'); + /* if the slash is part of this token, use it */ + if(slash) { + curl_off_t value; + const char *p = &slash[1]; + if(curlx_str_number(&p, &value, 128) || *p) + return FALSE; + /* a too large value is rejected in the cidr function below */ + bits = (unsigned int)value; + *slash = 0; /* null-terminate there */ + } + if(type == TYPE_IPV6) + return Curl_cidr6_match(name, check, bits); + else + return Curl_cidr4_match(name, check, bits); +} + /**************************************************************** -* Checks if the host is in the noproxy list. returns TRUE if it matches and -* therefore the proxy should NOT be used. -****************************************************************/ + * Checks if the host is in the noproxy list. returns TRUE if it matches and + * therefore the proxy should NOT be used. + ****************************************************************/ bool Curl_check_noproxy(const char *name, const char *no_proxy) { - char hostip[128]; - /* * If we do not have a hostname at all, like for example with a FILE * transfer, we have nothing to interrogate the noproxy list with. @@ -140,43 +198,30 @@ bool Curl_check_noproxy(const char *name, const char *no_proxy) if(no_proxy && no_proxy[0]) { const char *p = no_proxy; size_t namelen; + char address[16]; enum nametype type = TYPE_HOST; if(!strcmp("*", no_proxy)) return TRUE; /* NO_PROXY was specified and it was not just an asterisk */ - if(name[0] == '[') { - char *endptr; - /* IPv6 numerical address */ - endptr = strchr(name, ']'); - if(!endptr) - return FALSE; - name++; - namelen = endptr - name; - if(namelen >= sizeof(hostip)) - return FALSE; - memcpy(hostip, name, namelen); - hostip[namelen] = 0; - name = hostip; + /* Check if name is an IP address; if not, assume it being a hostname. */ + namelen = strlen(name); + if(curlx_inet_pton(AF_INET, name, &address) == 1) + type = TYPE_IPV4; +#ifdef USE_IPV6 + else if(curlx_inet_pton(AF_INET6, name, &address) == 1) type = TYPE_IPV6; - } +#endif else { - unsigned int address; - namelen = strlen(name); - if(curlx_inet_pton(AF_INET, name, &address) == 1) - type = TYPE_IPV4; - else { - /* ignore trailing dots in the hostname */ - if(name[namelen - 1] == '.') - namelen--; - } + /* ignore trailing dots in the hostname */ + if(name[namelen - 1] == '.') + namelen--; } while(*p) { const char *token; size_t tokenlen = 0; - bool match = FALSE; /* pass blanks */ curlx_str_passblanks(&p); @@ -189,64 +234,16 @@ bool Curl_check_noproxy(const char *name, const char *no_proxy) } if(tokenlen) { - switch(type) { - case TYPE_HOST: - /* ignore trailing dots in the token to check */ - if(token[tokenlen - 1] == '.') - tokenlen--; - - if(tokenlen && (*token == '.')) { - /* ignore leading token dot as well */ - token++; - tokenlen--; - } - /* A: example.com matches 'example.com' - B: www.example.com matches 'example.com' - C: nonexample.com DOES NOT match 'example.com' - */ - if(tokenlen == namelen) - /* case A, exact match */ - match = curl_strnequal(token, name, namelen); - else if(tokenlen < namelen) { - /* case B, tailmatch domain */ - match = (name[namelen - tokenlen - 1] == '.') && - curl_strnequal(token, name + (namelen - tokenlen), - tokenlen); - } - /* case C passes through, not a match */ - break; - case TYPE_IPV4: - case TYPE_IPV6: { - const char *check = token; - char *slash; - unsigned int bits = 0; - char checkip[128]; - if(tokenlen >= sizeof(checkip)) - /* this cannot match */ - break; - /* copy the check name to a temp buffer */ - memcpy(checkip, check, tokenlen); - checkip[tokenlen] = 0; - check = checkip; + bool match = FALSE; + if(type == TYPE_HOST) + match = match_host(token, tokenlen, name, namelen); + else + match = match_ip(type, token, tokenlen, name); - slash = strchr(check, '/'); - /* if the slash is part of this token, use it */ - if(slash) { - /* if the bits variable gets a crazy value here, that is fine as - the value will then be rejected in the cidr function */ - bits = (unsigned int)atoi(slash + 1); - *slash = 0; /* null-terminate there */ - } - if(type == TYPE_IPV6) - match = Curl_cidr6_match(name, check, bits); - else - match = Curl_cidr4_match(name, check, bits); - break; - } - } if(match) return TRUE; - } /* if(tokenlen) */ + } + /* pass blanks after pattern */ curlx_str_passblanks(&p); /* if not a comma, this ends the loop */ diff --git a/vendor/hydra/vendor/curl/lib/openldap.c b/vendor/hydra/vendor/curl/lib/openldap.c index f06587f0..f826a4d0 100644 --- a/vendor/hydra/vendor/curl/lib/openldap.c +++ b/vendor/hydra/vendor/curl/lib/openldap.c @@ -22,7 +22,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #if !defined(CURL_DISABLE_LDAP) && defined(USE_OPENLDAP) @@ -42,8 +41,8 @@ #include "urldata.h" #include "url.h" -#include #include "sendf.h" +#include "curl_trc.h" #include "vtls/vtls.h" #include "transfer.h" #include "curl_ldap.h" @@ -52,10 +51,7 @@ #include "connect.h" #include "curl_sasl.h" #include "strcase.h" - -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" +#include "bufref.h" /* * Uncommenting this will enable the built-in debug logging of the openldap @@ -116,7 +112,6 @@ static Curl_recv oldap_recv; /* * LDAP protocol handler. */ - const struct Curl_handler Curl_handler_ldap = { "ldap", /* scheme */ oldap_setup_connection, /* setup_connection */ @@ -139,14 +134,14 @@ const struct Curl_handler Curl_handler_ldap = { PORT_LDAP, /* defport */ CURLPROTO_LDAP, /* protocol */ CURLPROTO_LDAP, /* family */ - PROTOPT_SSL_REUSE /* flags */ + PROTOPT_SSL_REUSE | /* flags */ + PROTOPT_CONN_REUSE }; #ifdef USE_SSL /* * LDAPS protocol handler. */ - const struct Curl_handler Curl_handler_ldaps = { "ldaps", /* scheme */ oldap_setup_connection, /* setup_connection */ @@ -169,7 +164,8 @@ const struct Curl_handler Curl_handler_ldaps = { PORT_LDAPS, /* defport */ CURLPROTO_LDAPS, /* protocol */ CURLPROTO_LDAP, /* family */ - PROTOPT_SSL /* flags */ + PROTOPT_SSL | /* flags */ + PROTOPT_CONN_REUSE }; #endif @@ -276,14 +272,14 @@ static CURLcode oldap_url_parse(struct Curl_easy *data, LDAPURLDesc **ludp) *ludp = NULL; if(!data->state.up.user && !data->state.up.password && !data->state.up.options) - rc = ldap_url_parse(data->state.url, ludp); + rc = ldap_url_parse(Curl_bufref_ptr(&data->state.url), ludp); if(rc != LDAP_URL_SUCCESS) { const char *msg = "url parsing problem"; result = rc == LDAP_URL_ERR_MEM ? CURLE_OUT_OF_MEMORY : CURLE_URL_MALFORMAT; rc -= LDAP_URL_SUCCESS; - if((size_t) rc < CURL_ARRAYSIZE(url_errs)) + if((size_t)rc < CURL_ARRAYSIZE(url_errs)) msg = url_errs[rc]; failf(data, "LDAP local: %s", msg); } @@ -509,8 +505,7 @@ static ber_slen_t ldapsb_tls_write(Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len); static int ldapsb_tls_close(Sockbuf_IO_Desc *sbiod); -static Sockbuf_IO ldapsb_tls = -{ +static Sockbuf_IO ldapsb_tls = { ldapsb_tls_setup, ldapsb_tls_remove, ldapsb_tls_ctrl, @@ -575,7 +570,7 @@ static void oldap_easy_dtor(void *key, size_t klen, void *entry) struct ldapreqinfo *lr = entry; (void)key; (void)klen; - free(lr); + curlx_free(lr); } static void oldap_conn_dtor(void *key, size_t klen, void *entry) @@ -587,7 +582,7 @@ static void oldap_conn_dtor(void *key, size_t klen, void *entry) ldap_unbind_ext(li->ld, NULL, NULL); li->ld = NULL; } - free(li); + curlx_free(li); } static CURLcode oldap_connect(struct Curl_easy *data, bool *done) @@ -604,7 +599,7 @@ static CURLcode oldap_connect(struct Curl_easy *data, bool *done) (void)done; - li = calloc(1, sizeof(struct ldapconninfo)); + li = curlx_calloc(1, sizeof(struct ldapconninfo)); if(!li) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -660,7 +655,7 @@ static CURLcode oldap_connect(struct Curl_easy *data, bool *done) ldap_set_option(li->ld, LDAP_OPT_REFERRALS, LDAP_OPT_OFF); { - ber_len_t max = 256*1024; + ber_len_t max = 256 * 1024; Sockbuf *sb; if((ldap_get_option(li->ld, LDAP_OPT_SOCKBUF, &sb) != LDAP_OPT_SUCCESS) || /* Set the maximum allowed size of an incoming message, which to @@ -695,7 +690,7 @@ static CURLcode oldap_connect(struct Curl_easy *data, bool *done) result = oldap_perform_bind(data, OLDAP_BIND); out: - free(hosturl); + curlx_free(hosturl); return result; } @@ -732,7 +727,7 @@ static CURLcode oldap_state_mechs_resp(struct Curl_easy *data, if(bvals) { for(i = 0; bvals[i].bv_val; i++) { size_t llen; - unsigned short mech = Curl_sasl_decode_mech((char *) bvals[i].bv_val, + unsigned short mech = Curl_sasl_decode_mech((char *)bvals[i].bv_val, bvals[i].bv_len, &llen); if(bvals[i].bv_len == llen) li->sasl.authmechs |= mech; @@ -831,7 +826,7 @@ static CURLcode oldap_connecting(struct Curl_easy *data, bool *done) struct connectdata *conn = data->conn; struct ldapconninfo *li = Curl_conn_meta_get(conn, CURL_META_LDAP_CONN); LDAPMessage *msg = NULL; - struct timeval tv = {0, 0}; + struct timeval tv = { 0, 0 }; int code = LDAP_SUCCESS; int rc; @@ -992,9 +987,8 @@ static CURLcode oldap_do(struct Curl_easy *data, bool *done) if(!li) return CURLE_FAILED_INIT; - connkeep(conn, "OpenLDAP do"); - infof(data, "LDAP local: %s", data->state.url); + infof(data, "LDAP local: %s", Curl_bufref_ptr(&data->state.url)); result = oldap_url_parse(data, &lud); if(result) @@ -1022,7 +1016,7 @@ static CURLcode oldap_do(struct Curl_easy *data, bool *done) goto out; } - lr = calloc(1, sizeof(struct ldapreqinfo)); + lr = curlx_calloc(1, sizeof(struct ldapreqinfo)); if(!lr || Curl_meta_set(data, CURL_META_LDAP_EASY, lr, oldap_easy_dtor)) { ldap_abandon_ext(li->ld, msgid, NULL, NULL); @@ -1094,7 +1088,7 @@ static CURLcode oldap_recv(struct Curl_easy *data, int sockindex, char *buf, int rc; LDAPMessage *msg = NULL; BerElement *ber = NULL; - struct timeval tv = {0, 0}; + struct timeval tv = { 0, 0 }; struct berval bv, *bvals; CURLcode result = CURLE_AGAIN; int code; @@ -1212,12 +1206,13 @@ static CURLcode oldap_recv(struct Curl_easy *data, int sockindex, char *buf, /* Binary value, encode to base64. */ if(bvals[i].bv_len) - result = curlx_base64_encode(bvals[i].bv_val, bvals[i].bv_len, + result = curlx_base64_encode((uint8_t *)bvals[i].bv_val, + bvals[i].bv_len, &val_b64, &val_b64_sz); if(!result) result = client_write(data, STRCONST(": "), val_b64, val_b64_sz, STRCONST("\n")); - free(val_b64); + curlx_free(val_b64); } else result = client_write(data, STRCONST(" "), @@ -1235,7 +1230,6 @@ static CURLcode oldap_recv(struct Curl_easy *data, int sockindex, char *buf, break; } - if(!result) result = client_write(data, STRCONST("\n"), NULL, 0, NULL, 0); if(!result) @@ -1249,30 +1243,26 @@ static CURLcode oldap_recv(struct Curl_easy *data, int sockindex, char *buf, } #ifdef USE_SSL -static int -ldapsb_tls_setup(Sockbuf_IO_Desc *sbiod, void *arg) +static int ldapsb_tls_setup(Sockbuf_IO_Desc *sbiod, void *arg) { sbiod->sbiod_pvt = arg; return 0; } -static int -ldapsb_tls_remove(Sockbuf_IO_Desc *sbiod) +static int ldapsb_tls_remove(Sockbuf_IO_Desc *sbiod) { sbiod->sbiod_pvt = NULL; return 0; } /* We do not need to do anything because libcurl does it already */ -static int -ldapsb_tls_close(Sockbuf_IO_Desc *sbiod) +static int ldapsb_tls_close(Sockbuf_IO_Desc *sbiod) { (void)sbiod; return 0; } -static int -ldapsb_tls_ctrl(Sockbuf_IO_Desc *sbiod, int opt, void *arg) +static int ldapsb_tls_ctrl(Sockbuf_IO_Desc *sbiod, int opt, void *arg) { (void)arg; if(opt == LBER_SB_OPT_DATA_READY) { @@ -1282,8 +1272,8 @@ ldapsb_tls_ctrl(Sockbuf_IO_Desc *sbiod, int opt, void *arg) return 0; } -static ber_slen_t -ldapsb_tls_read(Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len) +static ber_slen_t ldapsb_tls_read(Sockbuf_IO_Desc *sbiod, void *buf, + ber_len_t len) { struct Curl_easy *data = sbiod->sbiod_pvt; ber_slen_t ret = 0; @@ -1307,8 +1297,8 @@ ldapsb_tls_read(Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len) } return ret; } -static ber_slen_t -ldapsb_tls_write(Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len) +static ber_slen_t ldapsb_tls_write(Sockbuf_IO_Desc *sbiod, void *buf, + ber_len_t len) { struct Curl_easy *data = sbiod->sbiod_pvt; ber_slen_t ret = 0; @@ -1334,4 +1324,24 @@ ldapsb_tls_write(Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len) } #endif /* USE_SSL */ +void Curl_ldap_version(char *buf, size_t bufsz) +{ + LDAPAPIInfo api; + api.ldapai_info_version = LDAP_API_INFO_VERSION; + + if(ldap_get_option(NULL, LDAP_OPT_API_INFO, &api) == LDAP_OPT_SUCCESS) { + unsigned int patch = (unsigned int)(api.ldapai_vendor_version % 100); + unsigned int major = (unsigned int)(api.ldapai_vendor_version / 10000); + unsigned int minor = + (((unsigned int)api.ldapai_vendor_version - major * 10000) + - patch) / 100; + curl_msnprintf(buf, bufsz, "%s/%u.%u.%u", + api.ldapai_vendor_name, major, minor, patch); + ldap_memfree(api.ldapai_vendor_name); + ber_memvfree((void **)api.ldapai_extensions); + } + else + curl_msnprintf(buf, bufsz, "OpenLDAP"); +} + #endif /* !CURL_DISABLE_LDAP && USE_OPENLDAP */ diff --git a/vendor/hydra/vendor/curl/lib/parsedate.c b/vendor/hydra/vendor/curl/lib/parsedate.c index b9429db7..9b4c4838 100644 --- a/vendor/hydra/vendor/curl/lib/parsedate.c +++ b/vendor/hydra/vendor/curl/lib/parsedate.c @@ -21,6 +21,11 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ +#include "curl_setup.h" + +#include "parsedate.h" +#include "curlx/strparse.h" + /* A brief summary of the date string formats this parser groks: @@ -75,15 +80,6 @@ */ -#include "curl_setup.h" - -#include - -#include -#include "curlx/warnless.h" -#include "parsedate.h" -#include "curlx/strparse.h" - /* * parsedate() * @@ -107,17 +103,19 @@ static int parsedate(const char *date, time_t *output); #if !defined(CURL_DISABLE_PARSEDATE) || !defined(CURL_DISABLE_FTP) || \ !defined(CURL_DISABLE_FILE) || defined(USE_GNUTLS) /* These names are also used by FTP and FILE code */ -const char * const Curl_wkday[] = -{"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}; -const char * const Curl_month[]= -{ "Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; +const char * const Curl_wkday[] = { + "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" +}; +const char * const Curl_month[] = { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" +}; #endif #ifndef CURL_DISABLE_PARSEDATE -static const char * const weekday[] = -{ "Monday", "Tuesday", "Wednesday", "Thursday", - "Friday", "Saturday", "Sunday" }; +static const char * const weekday[] = { + "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" +}; struct tzinfo { char name[5]; @@ -127,83 +125,83 @@ struct tzinfo { /* Here's a bunch of frequently used time zone names. These were supported by the old getdate parser. */ #define tDAYZONE -60 /* offset for daylight savings time */ -static const struct tzinfo tz[]= { - {"GMT", 0}, /* Greenwich Mean */ - {"UT", 0}, /* Universal Time */ - {"UTC", 0}, /* Universal (Coordinated) */ - {"WET", 0}, /* Western European */ - {"BST", 0 tDAYZONE}, /* British Summer */ - {"WAT", 60}, /* West Africa */ - {"AST", 240}, /* Atlantic Standard */ - {"ADT", 240 tDAYZONE}, /* Atlantic Daylight */ - {"EST", 300}, /* Eastern Standard */ - {"EDT", 300 tDAYZONE}, /* Eastern Daylight */ - {"CST", 360}, /* Central Standard */ - {"CDT", 360 tDAYZONE}, /* Central Daylight */ - {"MST", 420}, /* Mountain Standard */ - {"MDT", 420 tDAYZONE}, /* Mountain Daylight */ - {"PST", 480}, /* Pacific Standard */ - {"PDT", 480 tDAYZONE}, /* Pacific Daylight */ - {"YST", 540}, /* Yukon Standard */ - {"YDT", 540 tDAYZONE}, /* Yukon Daylight */ - {"HST", 600}, /* Hawaii Standard */ - {"HDT", 600 tDAYZONE}, /* Hawaii Daylight */ - {"CAT", 600}, /* Central Alaska */ - {"AHST", 600}, /* Alaska-Hawaii Standard */ - {"NT", 660}, /* Nome */ /* spellchecker:disable-line */ - {"IDLW", 720}, /* International Date Line West */ - {"CET", -60}, /* Central European */ - {"MET", -60}, /* Middle European */ - {"MEWT", -60}, /* Middle European Winter */ - {"MEST", -60 tDAYZONE}, /* Middle European Summer */ - {"CEST", -60 tDAYZONE}, /* Central European Summer */ - {"MESZ", -60 tDAYZONE}, /* Middle European Summer */ - {"FWT", -60}, /* French Winter */ - {"FST", -60 tDAYZONE}, /* French Summer */ - {"EET", -120}, /* Eastern Europe, USSR Zone 1 */ - {"WAST", -420}, /* spellchecker:disable-line */ - /* West Australian Standard */ - {"WADT", -420 tDAYZONE}, /* West Australian Daylight */ - {"CCT", -480}, /* China Coast, USSR Zone 7 */ - {"JST", -540}, /* Japan Standard, USSR Zone 8 */ - {"EAST", -600}, /* Eastern Australian Standard */ - {"EADT", -600 tDAYZONE}, /* Eastern Australian Daylight */ - {"GST", -600}, /* Guam Standard, USSR Zone 9 */ - {"NZT", -720}, /* New Zealand */ - {"NZST", -720}, /* New Zealand Standard */ - {"NZDT", -720 tDAYZONE}, /* New Zealand Daylight */ - {"IDLE", -720}, /* International Date Line East */ +static const struct tzinfo tz[] = { + { "GMT", 0 }, /* Greenwich Mean */ + { "UT", 0 }, /* Universal Time */ + { "UTC", 0 }, /* Universal (Coordinated) */ + { "WET", 0 }, /* Western European */ + { "BST", 0 tDAYZONE }, /* British Summer */ + { "WAT", 60 }, /* West Africa */ + { "AST", 240 }, /* Atlantic Standard */ + { "ADT", 240 tDAYZONE }, /* Atlantic Daylight */ + { "EST", 300 }, /* Eastern Standard */ + { "EDT", 300 tDAYZONE }, /* Eastern Daylight */ + { "CST", 360 }, /* Central Standard */ + { "CDT", 360 tDAYZONE }, /* Central Daylight */ + { "MST", 420 }, /* Mountain Standard */ + { "MDT", 420 tDAYZONE }, /* Mountain Daylight */ + { "PST", 480 }, /* Pacific Standard */ + { "PDT", 480 tDAYZONE }, /* Pacific Daylight */ + { "YST", 540 }, /* Yukon Standard */ + { "YDT", 540 tDAYZONE }, /* Yukon Daylight */ + { "HST", 600 }, /* Hawaii Standard */ + { "HDT", 600 tDAYZONE }, /* Hawaii Daylight */ + { "CAT", 600 }, /* Central Alaska */ + { "AHST", 600 }, /* Alaska-Hawaii Standard */ + { "NT", 660 }, /* Nome */ /* spellchecker:disable-line */ + { "IDLW", 720 }, /* International Date Line West */ + { "CET", -60 }, /* Central European */ + { "MET", -60 }, /* Middle European */ + { "MEWT", -60 }, /* Middle European Winter */ + { "MEST", -60 tDAYZONE }, /* Middle European Summer */ + { "CEST", -60 tDAYZONE }, /* Central European Summer */ + { "MESZ", -60 tDAYZONE }, /* Middle European Summer */ + { "FWT", -60 }, /* French Winter */ + { "FST", -60 tDAYZONE }, /* French Summer */ + { "EET", -120 }, /* Eastern Europe, USSR Zone 1 */ + { "WAST", -420 }, /* spellchecker:disable-line */ + /* West Australian Standard */ + { "WADT", -420 tDAYZONE }, /* West Australian Daylight */ + { "CCT", -480 }, /* China Coast, USSR Zone 7 */ + { "JST", -540 }, /* Japan Standard, USSR Zone 8 */ + { "EAST", -600 }, /* Eastern Australian Standard */ + { "EADT", -600 tDAYZONE }, /* Eastern Australian Daylight */ + { "GST", -600 }, /* Guam Standard, USSR Zone 9 */ + { "NZT", -720 }, /* New Zealand */ + { "NZST", -720 }, /* New Zealand Standard */ + { "NZDT", -720 tDAYZONE }, /* New Zealand Daylight */ + { "IDLE", -720 }, /* International Date Line East */ /* Next up: Military timezone names. RFC822 allowed these, but (as noted in RFC 1123) had their signs wrong. Here we use the correct signs to match actual military usage. */ - {"A", 1 * 60}, /* Alpha */ - {"B", 2 * 60}, /* Bravo */ - {"C", 3 * 60}, /* Charlie */ - {"D", 4 * 60}, /* Delta */ - {"E", 5 * 60}, /* Echo */ - {"F", 6 * 60}, /* Foxtrot */ - {"G", 7 * 60}, /* Golf */ - {"H", 8 * 60}, /* Hotel */ - {"I", 9 * 60}, /* India */ + { "A", 1 * 60 }, /* Alpha */ + { "B", 2 * 60 }, /* Bravo */ + { "C", 3 * 60 }, /* Charlie */ + { "D", 4 * 60 }, /* Delta */ + { "E", 5 * 60 }, /* Echo */ + { "F", 6 * 60 }, /* Foxtrot */ + { "G", 7 * 60 }, /* Golf */ + { "H", 8 * 60 }, /* Hotel */ + { "I", 9 * 60 }, /* India */ /* "J", Juliet is not used as a timezone, to indicate the observer's local time */ - {"K", 10 * 60}, /* Kilo */ - {"L", 11 * 60}, /* Lima */ - {"M", 12 * 60}, /* Mike */ - {"N", -1 * 60}, /* November */ - {"O", -2 * 60}, /* Oscar */ - {"P", -3 * 60}, /* Papa */ - {"Q", -4 * 60}, /* Quebec */ - {"R", -5 * 60}, /* Romeo */ - {"S", -6 * 60}, /* Sierra */ - {"T", -7 * 60}, /* Tango */ - {"U", -8 * 60}, /* Uniform */ - {"V", -9 * 60}, /* Victor */ - {"W", -10 * 60}, /* Whiskey */ - {"X", -11 * 60}, /* X-ray */ - {"Y", -12 * 60}, /* Yankee */ - {"Z", 0}, /* Zulu, zero meridian, a.k.a. UTC */ + { "K", 10 * 60 }, /* Kilo */ + { "L", 11 * 60 }, /* Lima */ + { "M", 12 * 60 }, /* Mike */ + { "N", -1 * 60 }, /* November */ + { "O", -2 * 60 }, /* Oscar */ + { "P", -3 * 60 }, /* Papa */ + { "Q", -4 * 60 }, /* Quebec */ + { "R", -5 * 60 }, /* Romeo */ + { "S", -6 * 60 }, /* Sierra */ + { "T", -7 * 60 }, /* Tango */ + { "U", -8 * 60 }, /* Uniform */ + { "V", -9 * 60 }, /* Victor */ + { "W", -10 * 60 }, /* Whiskey */ + { "X", -11 * 60 }, /* X-ray */ + { "Y", -12 * 60 }, /* Yankee */ + { "Z", 0 }, /* Zulu, zero meridian, a.k.a. UTC */ }; /* returns: @@ -260,7 +258,7 @@ static int checktz(const char *check, size_t len) size_t ilen = strlen(what->name); if((ilen == len) && curl_strnequal(check, what->name, len)) - return what->offset*60; + return what->offset * 60; what++; } return -1; @@ -286,12 +284,13 @@ enum assume { static time_t time2epoch(int sec, int min, int hour, int mday, int mon, int year) { - static const int month_days_cumulative [12] = - { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; + static const int month_days_cumulative[12] = { + 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 + }; int leap_days = year - (mon <= 1); leap_days = ((leap_days / 4) - (leap_days / 100) + (leap_days / 400) - (1969 / 4) + (1969 / 100) - (1969 / 400)); - return ((((time_t) (year - 1970) * 365 + return ((((time_t)(year - 1970) * 365 + leap_days + month_days_cumulative[mon] + mday - 1) * 24 + hour) * 60 + min) * 60 + sec; } @@ -304,13 +303,12 @@ static int oneortwodigit(const char *date, const char **endp) int num = date[0] - '0'; if(ISDIGIT(date[1])) { *endp = &date[2]; - return num*10 + (date[1] - '0'); + return num * 10 + (date[1] - '0'); } *endp = &date[1]; return num; } - /* HH:MM:SS or HH:MM and accept single-digits too */ static bool match_time(const char *date, int *h, int *m, int *s, char **endp) @@ -362,7 +360,7 @@ static int parsedate(const char *date, time_t *output) time_t t = 0; int wdaynum = -1; /* day of the week number, 0-6 (mon-sun) */ int monnum = -1; /* month of the year number, 0-11 */ - int mdaynum = -1; /* day of month, 1 - 31 */ + int mdaynum = -1; /* day of month, 1 - 31 */ int hournum = -1; int minnum = -1; int secnum = -1; @@ -444,11 +442,11 @@ static int parsedate(const char *date, time_t *output) anyone has a more authoritative source for the exact maximum time zone offsets, please speak up! */ found = TRUE; - tzoff = (val/100 * 60 + val%100)*60; + tzoff = (val / 100 * 60 + val % 100) * 60; /* the + and - prefix indicates the local time compared to GMT, this we need their reversed math to get what we want */ - tzoff = date[-1]=='+' ? -tzoff : tzoff; + tzoff = date[-1] == '+' ? -tzoff : tzoff; } else if((num_digits == 8) && @@ -457,9 +455,9 @@ static int parsedate(const char *date, time_t *output) (mdaynum == -1)) { /* 8 digits, no year, month or day yet. This is YYYYMMDD */ found = TRUE; - yearnum = val/10000; - monnum = (val%10000)/100-1; /* month is 0 - 11 */ - mdaynum = val%100; + yearnum = val / 10000; + monnum = (val % 10000) / 100 - 1; /* month is 0 - 11 */ + mdaynum = val % 100; } if(!found && (dignext == DATE_MDAY) && (mdaynum == -1)) { @@ -596,27 +594,3 @@ int Curl_getdate_capped(const char *p, time_t *tp) int rc = parsedate(p, tp); return (rc == PARSEDATE_FAIL); } - -/* - * Curl_gmtime() is a gmtime() replacement for portability. Do not use the - * gmtime_r() or gmtime() functions anywhere else but here. - * - */ - -CURLcode Curl_gmtime(time_t intime, struct tm *store) -{ - const struct tm *tm; -#ifdef HAVE_GMTIME_R - /* thread-safe version */ - tm = (struct tm *)gmtime_r(&intime, store); -#else - /* !checksrc! disable BANNEDFUNC 1 */ - tm = gmtime(&intime); - if(tm) - *store = *tm; /* copy the pointed struct to the local copy */ -#endif - - if(!tm) - return CURLE_BAD_FUNCTION_ARGUMENT; - return CURLE_OK; -} diff --git a/vendor/hydra/vendor/curl/lib/parsedate.h b/vendor/hydra/vendor/curl/lib/parsedate.h index e5efb53f..a6ee43a5 100644 --- a/vendor/hydra/vendor/curl/lib/parsedate.h +++ b/vendor/hydra/vendor/curl/lib/parsedate.h @@ -23,12 +23,9 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - extern const char * const Curl_wkday[7]; extern const char * const Curl_month[12]; -CURLcode Curl_gmtime(time_t intime, struct tm *store); - /* Curl_getdate_capped() differs from curl_getdate() in that this returns TIME_T_MAX in case the parsed time value was too big, instead of an error. */ diff --git a/vendor/hydra/vendor/curl/lib/pingpong.c b/vendor/hydra/vendor/curl/lib/pingpong.c index 470199a6..5af53052 100644 --- a/vendor/hydra/vendor/curl/lib/pingpong.c +++ b/vendor/hydra/vendor/curl/lib/pingpong.c @@ -24,23 +24,16 @@ * IMAP, POP3, SMTP and whatever more that likes them. * ***************************************************************************/ - #include "curl_setup.h" #include "urldata.h" #include "cfilters.h" #include "connect.h" #include "sendf.h" +#include "curl_trc.h" #include "select.h" #include "progress.h" -#include "speedcheck.h" #include "pingpong.h" -#include "multiif.h" -#include "vtls/vtls.h" - -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" #ifdef USE_PINGPONG @@ -52,7 +45,6 @@ timediff_t Curl_pp_state_timeout(struct Curl_easy *data, timediff_t timeout_ms; /* in milliseconds */ timediff_t response_time = data->set.server_response_timeout ? data->set.server_response_timeout : RESP_TIMEOUT; - struct curltime now = curlx_now(); /* if CURLOPT_SERVER_RESPONSE_TIMEOUT is set, use that to determine remaining time, or use pp->response because SERVER_RESPONSE_TIMEOUT is @@ -61,17 +53,18 @@ timediff_t Curl_pp_state_timeout(struct Curl_easy *data, /* Without a requested timeout, we only wait 'response_time' seconds for the full response to arrive before we bail out */ - timeout_ms = response_time - curlx_timediff(now, pp->response); + timeout_ms = response_time - + curlx_ptimediff_ms(Curl_pgrs_now(data), &pp->response); if(data->set.timeout && !disconnecting) { /* if timeout is requested, find out how much overall remains */ - timediff_t timeout2_ms = Curl_timeleft(data, &now, FALSE); + timediff_t timeout2_ms = Curl_timeleft_ms(data, FALSE); /* pick the lowest number */ timeout_ms = CURLMIN(timeout_ms, timeout2_ms); } if(disconnecting) { - timediff_t total_left_ms = Curl_timeleft(data, NULL, FALSE); + timediff_t total_left_ms = Curl_timeleft_ms(data, FALSE); timeout_ms = CURLMIN(timeout_ms, CURLMAX(total_left_ms, 0)); } @@ -122,11 +115,7 @@ CURLcode Curl_pp_statemach(struct Curl_easy *data, if(block) { /* if we did not wait, we do not have to spend time on this now */ - if(Curl_pgrsUpdate(data)) - result = CURLE_ABORTED_BY_CALLBACK; - else - result = Curl_speedcheck(data, curlx_now()); - + result = Curl_pgrsCheck(data); if(result) return result; } @@ -144,11 +133,11 @@ CURLcode Curl_pp_statemach(struct Curl_easy *data, } /* initialize stuff to prepare for reading a fresh new response */ -void Curl_pp_init(struct pingpong *pp) +void Curl_pp_init(struct pingpong *pp, const struct curltime *pnow) { DEBUGASSERT(!pp->initialised); pp->nread_resp = 0; - pp->response = curlx_now(); /* start response time-out now! */ + pp->response = *pnow; /* start response time-out */ pp->pending_resp = TRUE; curlx_dyn_init(&pp->sendbuf, DYN_PINGPPONG_CMD); curlx_dyn_init(&pp->recvbuf, DYN_PINGPPONG_CMD); @@ -217,13 +206,12 @@ CURLcode Curl_pp_vsendf(struct Curl_easy *data, else { pp->sendthis = NULL; pp->sendleft = pp->sendsize = 0; - pp->response = curlx_now(); + pp->response = *Curl_pgrs_now(data); } return CURLE_OK; } - /*********************************************************************** * * Curl_pp_sendf() @@ -284,7 +272,7 @@ CURLcode Curl_pp_readresp(struct Curl_easy *data, size_t full = curlx_dyn_len(&pp->recvbuf); /* trim off the "final" leading part */ - curlx_dyn_tail(&pp->recvbuf, full - pp->nfinal); + curlx_dyn_tail(&pp->recvbuf, full - pp->nfinal); pp->nfinal = 0; /* now gone */ } @@ -409,7 +397,7 @@ CURLcode Curl_pp_flushsend(struct Curl_easy *data, else { pp->sendthis = NULL; pp->sendleft = pp->sendsize = 0; - pp->response = curlx_now(); + pp->response = *Curl_pgrs_now(data); } return CURLE_OK; } diff --git a/vendor/hydra/vendor/curl/lib/pingpong.h b/vendor/hydra/vendor/curl/lib/pingpong.h index bd723b1c..a7292e60 100644 --- a/vendor/hydra/vendor/curl/lib/pingpong.h +++ b/vendor/hydra/vendor/curl/lib/pingpong.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #if !defined(CURL_DISABLE_IMAP) || !defined(CURL_DISABLE_FTP) || \ @@ -71,10 +70,10 @@ struct pingpong { read */ }; -#define PINGPONG_SETUP(pp,s,e) \ - do { \ - (pp)->statemachine = s; \ - (pp)->endofresp = e; \ +#define PINGPONG_SETUP(pp, s, e) \ + do { \ + (pp)->statemachine = s; \ + (pp)->endofresp = e; \ } while(0) /* @@ -87,14 +86,13 @@ CURLcode Curl_pp_statemach(struct Curl_easy *data, struct pingpong *pp, bool block, bool disconnecting); /* initialize stuff to prepare for reading a fresh new response */ -void Curl_pp_init(struct pingpong *pp); +void Curl_pp_init(struct pingpong *pp, const struct curltime *pnow); /* Returns timeout in ms. 0 or negative number means the timeout has already triggered */ timediff_t Curl_pp_state_timeout(struct Curl_easy *data, struct pingpong *pp, bool disconnecting); - /*********************************************************************** * * Curl_pp_sendf() @@ -148,7 +146,6 @@ CURLcode Curl_pp_pollset(struct Curl_easy *data, struct pingpong *pp, struct easy_pollset *ps); - /*********************************************************************** * * Curl_pp_moredata() diff --git a/vendor/hydra/vendor/curl/lib/pop3.c b/vendor/hydra/vendor/curl/lib/pop3.c index affd6427..8e2c8aa3 100644 --- a/vendor/hydra/vendor/curl/lib/pop3.c +++ b/vendor/hydra/vendor/curl/lib/pop3.c @@ -36,7 +36,6 @@ * Draft LOGIN SASL Mechanism * ***************************************************************************/ - #include "curl_setup.h" #ifndef CURL_DISABLE_POP3 @@ -55,44 +54,36 @@ #include #endif -#include #include "urldata.h" #include "sendf.h" +#include "curl_trc.h" #include "hostip.h" #include "progress.h" #include "transfer.h" #include "escape.h" -#include "http.h" /* for HTTP proxy tunnel stuff */ -#include "socks.h" #include "pingpong.h" #include "pop3.h" #include "vtls/vtls.h" #include "cfilters.h" #include "connect.h" #include "select.h" -#include "multiif.h" #include "url.h" #include "bufref.h" #include "curl_sasl.h" #include "curl_md5.h" -#include "curlx/warnless.h" #include "strdup.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* Authentication type flags */ #define POP3_TYPE_CLEARTEXT (1 << 0) #define POP3_TYPE_APOP (1 << 1) #define POP3_TYPE_SASL (1 << 2) /* Authentication type values */ -#define POP3_TYPE_NONE 0 -#define POP3_TYPE_ANY (POP3_TYPE_CLEARTEXT|POP3_TYPE_APOP|POP3_TYPE_SASL) +#define POP3_TYPE_NONE 0 +#define POP3_TYPE_ANY (POP3_TYPE_CLEARTEXT | POP3_TYPE_APOP | POP3_TYPE_SASL) /* This is the 5-bytes End-Of-Body marker for POP3 */ -#define POP3_EOB "\x0d\x0a\x2e\x0d\x0a" +#define POP3_EOB "\x0d\x0a\x2e\x0d\x0a" #define POP3_EOB_LEN 5 /* meta key for storing protocol meta at easy handle */ @@ -200,7 +191,7 @@ const struct Curl_handler Curl_handler_pop3 = { CURLPROTO_POP3, /* protocol */ CURLPROTO_POP3, /* family */ PROTOPT_CLOSEACTION | PROTOPT_NOURLQUERY | /* flags */ - PROTOPT_URLOPTIONS | PROTOPT_SSL_REUSE + PROTOPT_URLOPTIONS | PROTOPT_SSL_REUSE | PROTOPT_CONN_REUSE }; #ifdef USE_SSL @@ -230,8 +221,8 @@ const struct Curl_handler Curl_handler_pop3s = { PORT_POP3S, /* defport */ CURLPROTO_POP3S, /* protocol */ CURLPROTO_POP3, /* family */ - PROTOPT_CLOSEACTION | PROTOPT_SSL - | PROTOPT_NOURLQUERY | PROTOPT_URLOPTIONS /* flags */ + PROTOPT_CLOSEACTION | PROTOPT_SSL | /* flags */ + PROTOPT_NOURLQUERY | PROTOPT_URLOPTIONS | PROTOPT_CONN_REUSE }; #endif @@ -514,7 +505,7 @@ static CURLcode pop3_perform_upgrade_tls(struct Curl_easy *data, result, ssldone)); if(!result && ssldone) { pop3c->ssldone = ssldone; - /* perform CAPA now, changes pop3c->state out of POP3_UPGRADETLS */ + /* perform CAPA now, changes pop3c->state out of POP3_UPGRADETLS */ result = pop3_perform_capa(data, conn); } out: @@ -591,10 +582,10 @@ static CURLcode pop3_perform_apop(struct Curl_easy *data, if(!ctxt) return CURLE_OUT_OF_MEMORY; - Curl_MD5_update(ctxt, (const unsigned char *) pop3c->apoptimestamp, + Curl_MD5_update(ctxt, (const unsigned char *)pop3c->apoptimestamp, curlx_uztoui(strlen(pop3c->apoptimestamp))); - Curl_MD5_update(ctxt, (const unsigned char *) conn->passwd, + Curl_MD5_update(ctxt, (const unsigned char *)conn->passwd, curlx_uztoui(strlen(conn->passwd))); /* Finalise the digest */ @@ -627,7 +618,7 @@ static CURLcode pop3_perform_auth(struct Curl_easy *data, struct pop3_conn *pop3c = Curl_conn_meta_get(data->conn, CURL_META_POP3_CONN); CURLcode result = CURLE_OK; - const char *ir = (const char *) Curl_bufref_ptr(initresp); + const char *ir = Curl_bufref_ptr(initresp); if(!pop3c) return CURLE_FAILED_INIT; @@ -661,8 +652,7 @@ static CURLcode pop3_continue_auth(struct Curl_easy *data, if(!pop3c) return CURLE_FAILED_INIT; - return Curl_pp_sendf(data, &pop3c->pp, - "%s", (const char *) Curl_bufref_ptr(resp)); + return Curl_pp_sendf(data, &pop3c->pp, "%s", Curl_bufref_ptr(resp)); } /*********************************************************************** @@ -1295,9 +1285,6 @@ static CURLcode pop3_connect(struct Curl_easy *data, bool *done) if(!pop3c) return CURLE_FAILED_INIT; - /* We always support persistent connections in POP3 */ - connkeep(conn, "POP3 default"); - PINGPONG_SETUP(pp, pop3_statemachine, pop3_endofresp); /* Set the default preferred authentication type and mechanism */ @@ -1305,7 +1292,7 @@ static CURLcode pop3_connect(struct Curl_easy *data, bool *done) Curl_sasl_init(&pop3c->sasl, data, &saslpop3); /* Initialise the pingpong layer */ - Curl_pp_init(pp); + Curl_pp_init(pp, Curl_pgrs_now(data)); /* Parse the URL options */ result = pop3_parse_url_options(conn); @@ -1503,10 +1490,7 @@ static CURLcode pop3_regular_transfer(struct Curl_easy *data, data->req.size = -1; /* Set the progress data */ - Curl_pgrsSetUploadCounter(data, 0); - Curl_pgrsSetDownloadCounter(data, 0); - Curl_pgrsSetUploadSize(data, -1); - Curl_pgrsSetDownloadSize(data, -1); + Curl_pgrsReset(data); /* Carry out the perform */ result = pop3_perform(data, &connected, dophase_done); @@ -1527,7 +1511,7 @@ static void pop3_easy_dtor(void *key, size_t klen, void *entry) /* Cleanup our per-request based variables */ Curl_safefree(pop3->id); Curl_safefree(pop3->custom); - free(pop3); + curlx_free(pop3); } static void pop3_conn_dtor(void *key, size_t klen, void *entry) @@ -1538,19 +1522,19 @@ static void pop3_conn_dtor(void *key, size_t klen, void *entry) DEBUGASSERT(pop3c); Curl_pp_disconnect(&pop3c->pp); Curl_safefree(pop3c->apoptimestamp); - free(pop3c); + curlx_free(pop3c); } static CURLcode pop3_setup_connection(struct Curl_easy *data, struct connectdata *conn) { struct pop3_conn *pop3c; - struct POP3 *pop3 = calloc(1, sizeof(*pop3)); + struct POP3 *pop3 = curlx_calloc(1, sizeof(*pop3)); if(!pop3 || Curl_meta_set(data, CURL_META_POP3_EASY, pop3, pop3_easy_dtor)) return CURLE_OUT_OF_MEMORY; - pop3c = calloc(1, sizeof(*pop3c)); + pop3c = curlx_calloc(1, sizeof(*pop3c)); if(!pop3c || Curl_conn_meta_set(conn, CURL_META_POP3_CONN, pop3c, pop3_conn_dtor)) return CURLE_OUT_OF_MEMORY; @@ -1742,9 +1726,8 @@ static CURLcode pop3_write(struct Curl_easy *data, const char *str, /* Did we have a partial match which has subsequently failed? */ if(prev && prev >= pop3c->eob) { - /* Strip can only be non-zero for the very first mismatch after CRLF - and then both prev and strip are equal and nothing will be output - below */ + /* Strip can only be non-zero for the first mismatch after CRLF and + then both prev and strip are equal and nothing will be output below */ while(prev && pop3c->strip) { prev--; pop3c->strip--; diff --git a/vendor/hydra/vendor/curl/lib/pop3.h b/vendor/hydra/vendor/curl/lib/pop3.h index 485e7c2c..ed00dd15 100644 --- a/vendor/hydra/vendor/curl/lib/pop3.h +++ b/vendor/hydra/vendor/curl/lib/pop3.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - extern const struct Curl_handler Curl_handler_pop3; extern const struct Curl_handler Curl_handler_pop3s; diff --git a/vendor/hydra/vendor/curl/lib/progress.c b/vendor/hydra/vendor/curl/lib/progress.c index 7b473ef3..9cbd2674 100644 --- a/vendor/hydra/vendor/curl/lib/progress.c +++ b/vendor/hydra/vendor/curl/lib/progress.c @@ -21,83 +21,166 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #include "urldata.h" -#include "sendf.h" +#include "curl_trc.h" #include "multiif.h" #include "progress.h" -#include "curlx/timeval.h" +#include "transfer.h" +#include "curlx/strcopy.h" /* check rate limits within this many recent milliseconds, at minimum. */ #define MIN_RATE_LIMIT_PERIOD 3000 #ifndef CURL_DISABLE_PROGRESS_METER -/* Provide a string that is 2 + 1 + 2 + 1 + 2 = 8 letters long (plus the zero - byte) */ -static void time2str(char *r, curl_off_t seconds) +/* Provide a string that is 7 letters long (plus the zero byte). + + Unit test 1636. +*/ +UNITTEST void time2str(char *r, size_t rsize, curl_off_t seconds); +UNITTEST void time2str(char *r, size_t rsize, curl_off_t seconds) { curl_off_t h; if(seconds <= 0) { - strcpy(r, "--:--:--"); + curlx_strcopy(r, rsize, " ", 7); return; } h = seconds / 3600; if(h <= 99) { curl_off_t m = (seconds - (h * 3600)) / 60; - curl_off_t s = (seconds - (h * 3600)) - (m * 60); - curl_msnprintf(r, 9, "%2" FMT_OFF_T ":%02" FMT_OFF_T ":%02" FMT_OFF_T, - h, m, s); + if(h <= 9) { + curl_off_t s = (seconds - (h * 3600)) - (m * 60); + if(h) + curl_msnprintf(r, rsize, "%" FMT_OFF_T ":%02" FMT_OFF_T ":" + "%02" FMT_OFF_T, h, m, s); + else + curl_msnprintf(r, rsize, " %02" FMT_OFF_T ":%02" FMT_OFF_T, m, s); + } + else + curl_msnprintf(r, rsize, "%" FMT_OFF_T "h %02" FMT_OFF_T "m", h, m); } else { - /* this equals to more than 99 hours, switch to a more suitable output - format to fit within the limits. */ curl_off_t d = seconds / 86400; h = (seconds - (d * 86400)) / 3600; - if(d <= 999) - curl_msnprintf(r, 9, "%3" FMT_OFF_T "d %02" FMT_OFF_T "h", d, h); - else - curl_msnprintf(r, 9, "%7" FMT_OFF_T "d", d); + if(d <= 99) + curl_msnprintf(r, rsize, "%2" FMT_OFF_T "d %02" FMT_OFF_T "h", d, h); + else if(d <= 999) + curl_msnprintf(r, rsize, "%6" FMT_OFF_T "d", d); + else { /* more than 999 days */ + curl_off_t m = d / 30; + if(m <= 999) + curl_msnprintf(r, rsize, "%6" FMT_OFF_T "m", m); + else { /* more than 999 months */ + curl_off_t y = d / 365; + if(y <= 99999) + curl_msnprintf(r, rsize, "%6" FMT_OFF_T "y", y); + else + curlx_strcopy(r, rsize, ">99999y", 7); + } + } } } /* The point of this function would be to return a string of the input data, but never longer than 6 columns (+ one zero byte). - Add suffix k, M, G when suitable... */ -static char *max6data(curl_off_t bytes, char *max6) -{ - /* a signed 64-bit value is 8192 petabytes maximum */ - const char unit[] = { 'k', 'M', 'G', 'T', 'P', 0 }; - int k = 0; - if(bytes < 1000000) { - curl_msnprintf(max6, 7, "%5" CURL_FORMAT_CURL_OFF_T, bytes); - return max6; - } + Add suffix k, M, G when suitable... - do { - curl_off_t nbytes = bytes / 1024; - if(nbytes < 1000) { + Unit test 1636 +*/ +UNITTEST char *max6out(curl_off_t bytes, char *max6, size_t mlen); +UNITTEST char *max6out(curl_off_t bytes, char *max6, size_t mlen) +{ + /* a signed 64-bit value is 8192 petabytes maximum, shown as + 8.0E (exabytes)*/ + if(bytes < 100000) + curl_msnprintf(max6, mlen, "%6" CURL_FORMAT_CURL_OFF_T, bytes); + else { + const char unit[] = { 'k', 'M', 'G', 'T', 'P', 'E', 0 }; + int k = 0; + curl_off_t nbytes; + curl_off_t rest; + do { + nbytes = bytes / 1024; + if(nbytes < 1000) + break; + bytes = nbytes; + k++; + DEBUGASSERT(unit[k]); + } while(unit[k]); + rest = bytes % 1024; + if(nbytes <= 99) + /* xx.yyU */ + curl_msnprintf(max6, mlen, "%2" CURL_FORMAT_CURL_OFF_T + ".%02" CURL_FORMAT_CURL_OFF_T "%c", nbytes, + rest * 100 / 1024, unit[k]); + else /* xxx.yU */ - curl_msnprintf(max6, 7, "%3" CURL_FORMAT_CURL_OFF_T + curl_msnprintf(max6, mlen, "%3" CURL_FORMAT_CURL_OFF_T ".%" CURL_FORMAT_CURL_OFF_T "%c", nbytes, - (bytes%1024) / (1024/10), unit[k]); - break; - } - else if(nbytes < 100000) { - /* xxxxxU */ - curl_msnprintf(max6, 7, "%5" CURL_FORMAT_CURL_OFF_T "%c", - nbytes, unit[k]); - break; - } - bytes = nbytes; - k++; - DEBUGASSERT(unit[k]); - } while(unit[k]); + rest * 10 / 1024, unit[k]); + } return max6; } #endif +static void pgrs_speedinit(struct Curl_easy *data) +{ + memset(&data->state.keeps_speed, 0, sizeof(struct curltime)); +} + +/* + * @unittest: 1606 + */ +UNITTEST CURLcode pgrs_speedcheck(struct Curl_easy *data, + const struct curltime *pnow) +{ + if(!data->set.low_speed_time || !data->set.low_speed_limit || + Curl_xfer_recv_is_paused(data) || Curl_xfer_send_is_paused(data)) + /* A paused transfer is not qualified for speed checks */ + return CURLE_OK; + + if(data->progress.current_speed >= 0) { + if(data->progress.current_speed < data->set.low_speed_limit) { + if(!data->state.keeps_speed.tv_sec) + /* under the limit at this moment */ + data->state.keeps_speed = *pnow; + else { + /* how long has it been under the limit */ + timediff_t howlong = + curlx_ptimediff_ms(pnow, &data->state.keeps_speed); + + if(howlong >= data->set.low_speed_time * 1000) { + /* too long */ + failf(data, + "Operation too slow. " + "Less than %ld bytes/sec transferred the last %ld seconds", + data->set.low_speed_limit, + data->set.low_speed_time); + return CURLE_OPERATION_TIMEDOUT; + } + } + } + else + /* faster right now */ + data->state.keeps_speed.tv_sec = 0; + } + + /* since low speed limit is enabled, set the expire timer to make this + connection's speed get checked again in a second */ + Curl_expire(data, 1000, EXPIRE_SPEEDCHECK); + + return CURLE_OK; +} + +const struct curltime *Curl_pgrs_now(struct Curl_easy *data) +{ + struct curltime *pnow = data->multi ? + &data->multi->now : &data->progress.now; + curlx_pnow(pnow); + return pnow; +} + /* New proposed interface, 9th of February 2000: @@ -125,10 +208,19 @@ int Curl_pgrsDone(struct Curl_easy *data) * hidden */ curl_mfprintf(data->set.err, "\n"); - data->progress.speeder_c = 0; /* reset the progress meter display */ return 0; } +void Curl_pgrsReset(struct Curl_easy *data) +{ + Curl_pgrsSetUploadCounter(data, 0); + data->progress.dl.cur_size = 0; + Curl_pgrsSetUploadSize(data, -1); + Curl_pgrsSetDownloadSize(data, -1); + data->progress.speeder_c = 0; /* reset speed records */ + pgrs_speedinit(data); +} + /* reset the known transfer sizes */ void Curl_pgrsResetTransferSizes(struct Curl_easy *data) { @@ -136,6 +228,22 @@ void Curl_pgrsResetTransferSizes(struct Curl_easy *data) Curl_pgrsSetUploadSize(data, -1); } +void Curl_pgrsRecvPause(struct Curl_easy *data, bool enable) +{ + if(!enable) { + data->progress.speeder_c = 0; /* reset speed records */ + pgrs_speedinit(data); /* reset low speed measurements */ + } +} + +void Curl_pgrsSendPause(struct Curl_easy *data, bool enable) +{ + if(!enable) { + data->progress.speeder_c = 0; /* reset speed records */ + pgrs_speedinit(data); /* reset low speed measurements */ + } +} + /* * * Curl_pgrsTimeWas(). Store the timestamp time at the given label. @@ -164,7 +272,7 @@ void Curl_pgrsTimeWas(struct Curl_easy *data, timerid timer, case TIMER_POSTQUEUE: /* Queue time is accumulative from all involved redirects */ data->progress.t_postqueue += - curlx_timediff_us(timestamp, data->progress.t_startqueue); + curlx_ptimediff_us(×tamp, &data->progress.t_startqueue); break; case TIMER_STARTACCEPT: data->progress.t_acceptdata = timestamp; @@ -200,13 +308,14 @@ void Curl_pgrsTimeWas(struct Curl_easy *data, timerid timer, delta = &data->progress.t_posttransfer; break; case TIMER_REDIRECT: - data->progress.t_redirect = curlx_timediff_us(timestamp, - data->progress.start); + data->progress.t_redirect = curlx_ptimediff_us(×tamp, + &data->progress.start); data->progress.t_startqueue = timestamp; break; } if(delta) { - timediff_t us = curlx_timediff_us(timestamp, data->progress.t_startsingle); + timediff_t us = curlx_ptimediff_us(×tamp, + &data->progress.t_startsingle); if(us < 1) us = 1; /* make sure at least one microsecond passed */ *delta += us; @@ -220,116 +329,38 @@ void Curl_pgrsTimeWas(struct Curl_easy *data, timerid timer, * * @unittest: 1399 */ -struct curltime Curl_pgrsTime(struct Curl_easy *data, timerid timer) +void Curl_pgrsTime(struct Curl_easy *data, timerid timer) { - struct curltime now = curlx_now(); - - Curl_pgrsTimeWas(data, timer, now); - return now; + Curl_pgrsTimeWas(data, timer, *Curl_pgrs_now(data)); } void Curl_pgrsStartNow(struct Curl_easy *data) { struct Progress *p = &data->progress; + p->speeder_c = 0; /* reset the progress meter display */ - p->start = curlx_now(); + p->start = *Curl_pgrs_now(data); p->is_t_startransfer_set = FALSE; - p->ul.limit.start = p->start; - p->dl.limit.start = p->start; - p->ul.limit.start_size = 0; - p->dl.limit.start_size = 0; p->dl.cur_size = 0; p->ul.cur_size = 0; /* the sizes are unknown at start */ p->dl_size_known = FALSE; p->ul_size_known = FALSE; - Curl_ratelimit(data, p->start); } -/* - * This is used to handle speed limits, calculating how many milliseconds to - * wait until we are back under the speed limit, if needed. - * - * The way it works is by having a "starting point" (time & amount of data - * transferred by then) used in the speed computation, to be used instead of - * the start of the transfer. This starting point is regularly moved as - * transfer goes on, to keep getting accurate values (instead of average over - * the entire transfer). - * - * This function takes the current amount of data transferred, the amount at - * the starting point, the limit (in bytes/s), the time of the starting point - * and the current time. - * - * Returns 0 if no waiting is needed or when no waiting is needed but the - * starting point should be reset (to current); or the number of milliseconds - * to wait to get back under the speed limit. - */ -timediff_t Curl_pgrsLimitWaitTime(struct pgrs_dir *d, - curl_off_t bytes_per_sec, - struct curltime now) +void Curl_pgrs_download_inc(struct Curl_easy *data, size_t delta) { - curl_off_t bytes = d->cur_size - d->limit.start_size; - timediff_t should_ms; - timediff_t took_ms; - - /* no limit or we did not get to any bytes yet */ - if(!bytes_per_sec || !bytes) - return 0; - - /* The time it took us to have `bytes` */ - took_ms = curlx_timediff_ceil(now, d->limit.start); - - /* The time it *should* have taken us to have `bytes` - * when obeying the bytes_per_sec speed_limit. */ - if(bytes < CURL_OFF_T_MAX/1000) { - /* (1000 * bytes / (bytes / sec)) = 1000 * sec = ms */ - should_ms = (timediff_t) (1000 * bytes / bytes_per_sec); - } - else { - /* very large `bytes`, first calc the seconds it should have taken. - * if that is small enough, convert to milliseconds. */ - should_ms = (timediff_t) (bytes / bytes_per_sec); - if(should_ms < TIMEDIFF_T_MAX/1000) - should_ms *= 1000; - else - should_ms = TIMEDIFF_T_MAX; - } - - if(took_ms < should_ms) { - /* when gotten to `bytes` too fast, wait the difference */ - return should_ms - took_ms; + if(delta) { + data->progress.dl.cur_size += delta; + Curl_rlimit_drain(&data->progress.dl.rlimit, delta, Curl_pgrs_now(data)); } - return 0; } -/* - * Set the number of downloaded bytes so far. - */ -CURLcode Curl_pgrsSetDownloadCounter(struct Curl_easy *data, curl_off_t size) +void Curl_pgrs_upload_inc(struct Curl_easy *data, size_t delta) { - data->progress.dl.cur_size = size; - return CURLE_OK; -} - -/* - * Update the timestamp and sizestamp to use for rate limit calculations. - */ -void Curl_ratelimit(struct Curl_easy *data, struct curltime now) -{ - /* do not set a new stamp unless the time since last update is long enough */ - if(data->set.max_recv_speed) { - if(curlx_timediff(now, data->progress.dl.limit.start) >= - MIN_RATE_LIMIT_PERIOD) { - data->progress.dl.limit.start = now; - data->progress.dl.limit.start_size = data->progress.dl.cur_size; - } - } - if(data->set.max_send_speed) { - if(curlx_timediff(now, data->progress.ul.limit.start) >= - MIN_RATE_LIMIT_PERIOD) { - data->progress.ul.limit.start = now; - data->progress.ul.limit.start_size = data->progress.ul.cur_size; - } + if(delta) { + data->progress.ul.cur_size += delta; + Curl_rlimit_drain(&data->progress.ul.rlimit, delta, Curl_pgrs_now(data)); } } @@ -367,7 +398,7 @@ void Curl_pgrsSetUploadSize(struct Curl_easy *data, curl_off_t size) void Curl_pgrsEarlyData(struct Curl_easy *data, curl_off_t sent) { - data->progress.earlydata_sent = sent; + data->progress.earlydata_sent = sent; } /* returns the average speed in bytes / second */ @@ -376,7 +407,7 @@ static curl_off_t trspeed(curl_off_t size, /* number of bytes */ { if(us < 1) return size * 1000000; - else if(size < CURL_OFF_T_MAX/1000000) + else if(size < CURL_OFF_T_MAX / 1000000) return (size * 1000000) / us; else if(us >= 1000000) return size / (us / 1000000); @@ -385,75 +416,83 @@ static curl_off_t trspeed(curl_off_t size, /* number of bytes */ } /* returns TRUE if it is time to show the progress meter */ -static bool progress_calc(struct Curl_easy *data, struct curltime now) +static bool progress_calc(struct Curl_easy *data, + const struct curltime *pnow) { - bool timetoshow = FALSE; struct Progress * const p = &data->progress; + int i_next, i_oldest, i_latest; + timediff_t duration_ms; + curl_off_t amount; /* The time spent so far (from the start) in microseconds */ - p->timespent = curlx_timediff_us(now, p->start); + p->timespent = curlx_ptimediff_us(pnow, &p->start); p->dl.speed = trspeed(p->dl.cur_size, p->timespent); p->ul.speed = trspeed(p->ul.cur_size, p->timespent); - /* Calculations done at most once a second, unless end is reached */ - if(p->lastshow != now.tv_sec) { - int countindex; /* amount of seconds stored in the speeder array */ - int nowindex = p->speeder_c% CURR_TIME; - p->lastshow = now.tv_sec; - timetoshow = TRUE; - - /* Let's do the "current speed" thing, with the dl + ul speeds - combined. Store the speed at entry 'nowindex'. */ - p->speeder[ nowindex ] = p->dl.cur_size + p->ul.cur_size; - - /* remember the exact time for this moment */ - p->speeder_time [ nowindex ] = now; - - /* advance our speeder_c counter, which is increased every time we get - here and we expect it to never wrap as 2^32 is a lot of seconds! */ + if(!p->speeder_c) { /* no previous record exists */ + p->speed_amount[0] = p->dl.cur_size + p->ul.cur_size; + p->speed_time[0] = *pnow; p->speeder_c++; - - /* figure out how many index entries of data we have stored in our speeder - array. With N_ENTRIES filled in, we have about N_ENTRIES-1 seconds of - transfer. Imagine, after one second we have filled in two entries, - after two seconds we have filled in three entries etc. */ - countindex = ((p->speeder_c >= CURR_TIME) ? CURR_TIME : p->speeder_c) - 1; - - /* first of all, we do not do this if there is no counted seconds yet */ - if(countindex) { - int checkindex; - timediff_t span_ms; - curl_off_t amount; - - /* Get the index position to compare with the 'nowindex' position. - Get the oldest entry possible. While we have less than CURR_TIME - entries, the first entry will remain the oldest. */ - checkindex = (p->speeder_c >= CURR_TIME) ? p->speeder_c%CURR_TIME : 0; - - /* Figure out the exact time for the time span */ - span_ms = curlx_timediff(now, p->speeder_time[checkindex]); - if(span_ms == 0) - span_ms = 1; /* at least one millisecond MUST have passed */ - - /* Calculate the average speed the last 'span_ms' milliseconds */ - amount = p->speeder[nowindex]- p->speeder[checkindex]; - - if(amount > (0xffffffff/1000)) - /* the 'amount' value is bigger than would fit in 32 bits if - multiplied with 1000, so we use the double math for this */ - p->current_speed = (curl_off_t) - ((double)amount/((double)span_ms/1000.0)); - else - /* the 'amount' value is small enough to fit within 32 bits even - when multiplied with 1000 */ - p->current_speed = amount * 1000/span_ms; + /* use the overall average at the start */ + p->current_speed = p->ul.speed + p->dl.speed; + p->lastshow = pnow->tv_sec; + return TRUE; + } + /* We have at least one record now. Where to put the next and + * where is the latest one? */ + i_next = p->speeder_c % CURL_SPEED_RECORDS; + i_latest = (i_next > 0) ? (i_next - 1) : (CURL_SPEED_RECORDS - 1); + + /* Make a new record only when some time has passed. + * Too frequent calls otherwise ruin the history. */ + if(curlx_ptimediff_ms(pnow, &p->speed_time[i_latest]) >= 1000) { + p->speeder_c++; + i_latest = i_next; + p->speed_amount[i_latest] = p->dl.cur_size + p->ul.cur_size; + p->speed_time[i_latest] = *pnow; + } + else if(data->req.done) { + /* When a transfer is done, and we did not have a current speed + * already, update the last record. Otherwise, stay at the speed + * we have. The last chunk of data, when rate limiting, would increase + * reported speed since it no longer measures a full second. */ + if(!p->current_speed) { + p->speed_amount[i_latest] = p->dl.cur_size + p->ul.cur_size; + p->speed_time[i_latest] = *pnow; } - else - /* the first second we use the average */ - p->current_speed = p->ul.speed + p->dl.speed; + } + else { + /* transfer ongoing, wait for more time to pass. */ + return FALSE; + } - } /* Calculations end */ - return timetoshow; + i_oldest = (p->speeder_c < CURL_SPEED_RECORDS) ? 0 : + ((i_latest + 1) % CURL_SPEED_RECORDS); + + /* How much we transferred between oldest and current records */ + amount = p->speed_amount[i_latest] - p->speed_amount[i_oldest]; + /* How long this took */ + duration_ms = curlx_ptimediff_ms(&p->speed_time[i_latest], + &p->speed_time[i_oldest]); + if(duration_ms <= 0) + duration_ms = 1; + + if(amount > (CURL_OFF_T_MAX / 1000)) { + /* the 'amount' value is bigger than would fit in 64 bits if + multiplied with 1000, so we use the double math for this */ + p->current_speed = + (curl_off_t)(((double)amount * 1000.0) / (double)duration_ms); + } + else { + /* the 'amount' value is small enough to fit within 32 bits even + when multiplied with 1000 */ + p->current_speed = amount * 1000 / duration_ms; + } + + if((p->lastshow == pnow->tv_sec) && !data->req.done) + return FALSE; + p->lastshow = pnow->tv_sec; + return TRUE; } #ifndef CURL_DISABLE_PROGRESS_METER @@ -468,7 +507,7 @@ static curl_off_t pgrs_est_percent(curl_off_t total, curl_off_t cur) if(total > 10000) return cur / (total / 100); else if(total > 0) - return (cur*100) / total; + return (cur * 100) / total; return 0; } @@ -494,10 +533,10 @@ static void progress_meter(struct Curl_easy *data) curl_off_t total_cur_size; curl_off_t total_expected_size; curl_off_t dl_size; - char time_left[10]; - char time_total[10]; - char time_spent[10]; - curl_off_t cur_secs = (curl_off_t)p->timespent/1000000; /* seconds */ + char time_left[8]; + char time_total[8]; + char time_spent[8]; + curl_off_t cur_secs = (curl_off_t)p->timespent / 1000000; /* seconds */ if(!p->headers_out) { if(data->state.resume_from) { @@ -506,10 +545,10 @@ static void progress_meter(struct Curl_easy *data) data->state.resume_from); } curl_mfprintf(data->set.err, - " %% Total %% Received %% Xferd Average Speed " - "Time Time Time Current\n" - " Dload Upload " - "Total Spent Left Speed\n"); + " %% Total %% Received %% Xferd Average Speed " + "Time Time Time Current\n" + " Dload Upload " + "Total Spent Left Speed\n"); p->headers_out = TRUE; /* headers are shown */ } @@ -520,16 +559,15 @@ static void progress_meter(struct Curl_easy *data) /* Since both happen at the same time, total expected duration is max. */ total_estm.secs = CURLMAX(ul_estm.secs, dl_estm.secs); /* create the three time strings */ - time2str(time_left, total_estm.secs > 0 ? (total_estm.secs - cur_secs) : 0); - time2str(time_total, total_estm.secs); - time2str(time_spent, cur_secs); + time2str(time_left, sizeof(time_left), + total_estm.secs > 0 ? (total_estm.secs - cur_secs) : 0); + time2str(time_total, sizeof(time_total), total_estm.secs); + time2str(time_spent, sizeof(time_spent), cur_secs); /* Get the total amount of data expected to get transferred */ - total_expected_size = - p->ul_size_known ? p->ul.total_size : p->ul.cur_size; + total_expected_size = p->ul_size_known ? p->ul.total_size : p->ul.cur_size; - dl_size = - p->dl_size_known ? p->dl.total_size : p->dl.cur_size; + dl_size = p->dl_size_known ? p->dl.total_size : p->dl.cur_size; /* integer overflow check */ if((CURL_OFF_T_MAX - total_expected_size) < dl_size) @@ -547,19 +585,25 @@ static void progress_meter(struct Curl_easy *data) "\r" "%3" FMT_OFF_T " %s " "%3" FMT_OFF_T " %s " - "%3" FMT_OFF_T " %s %s %s %s %s %s %s", - total_estm.percent, /* 3 letters */ /* total % */ - max6data(total_expected_size, max6[2]), /* total size */ - dl_estm.percent, /* 3 letters */ /* rcvd % */ - max6data(p->dl.cur_size, max6[0]), /* rcvd size */ - ul_estm.percent, /* 3 letters */ /* xfer % */ - max6data(p->ul.cur_size, max6[1]), /* xfer size */ - max6data(p->dl.speed, max6[3]), /* avrg dl speed */ - max6data(p->ul.speed, max6[4]), /* avrg ul speed */ - time_total, /* 8 letters */ /* total time */ - time_spent, /* 8 letters */ /* time spent */ - time_left, /* 8 letters */ /* time left */ - max6data(p->current_speed, max6[5]) + "%3" FMT_OFF_T " %s %s %s %s %s %s %s", + total_estm.percent, /* 3 letters */ /* total % */ + max6out(total_expected_size, max6[2], + sizeof(max6[2])), /* total size */ + dl_estm.percent, /* 3 letters */ /* rcvd % */ + max6out(p->dl.cur_size, max6[0], + sizeof(max6[0])), /* rcvd size */ + ul_estm.percent, /* 3 letters */ /* xfer % */ + max6out(p->ul.cur_size, max6[1], + sizeof(max6[1])), /* xfer size */ + max6out(p->dl.speed, max6[3], + sizeof(max6[3])), /* avrg dl speed */ + max6out(p->ul.speed, max6[4], + sizeof(max6[4])), /* avrg ul speed */ + time_total, /* 7 letters */ /* total time */ + time_spent, /* 7 letters */ /* time spent */ + time_left, /* 7 letters */ /* time left */ + max6out(p->current_speed, max6[5], + sizeof(max6[5])) /* current speed */ ); /* we flush the output stream to make it appear as soon as possible */ @@ -570,12 +614,11 @@ static void progress_meter(struct Curl_easy *data) #define progress_meter(x) Curl_nop_stmt #endif - /* * Curl_pgrsUpdate() returns 0 for success or the value returned by the * progress callback! */ -static int pgrsupdate(struct Curl_easy *data, bool showprogress) +static CURLcode pgrsupdate(struct Curl_easy *data, bool showprogress) { if(!data->progress.hide) { if(data->set.fxferinfo) { @@ -589,9 +632,11 @@ static int pgrsupdate(struct Curl_easy *data, bool showprogress) data->progress.ul.cur_size); Curl_set_in_callback(data, FALSE); if(result != CURL_PROGRESSFUNC_CONTINUE) { - if(result) + if(result) { failf(data, "Callback aborted"); - return result; + return CURLE_ABORTED_BY_CALLBACK; + } + return CURLE_OK; } } else if(data->set.fprogress) { @@ -605,9 +650,11 @@ static int pgrsupdate(struct Curl_easy *data, bool showprogress) (double)data->progress.ul.cur_size); Curl_set_in_callback(data, FALSE); if(result != CURL_PROGRESSFUNC_CONTINUE) { - if(result) + if(result) { failf(data, "Callback aborted"); - return result; + return CURLE_ABORTED_BY_CALLBACK; + } + return CURLE_OK; } } @@ -615,21 +662,35 @@ static int pgrsupdate(struct Curl_easy *data, bool showprogress) progress_meter(data); } - return 0; + return CURLE_OK; } -int Curl_pgrsUpdate(struct Curl_easy *data) +static CURLcode pgrs_update(struct Curl_easy *data, + const struct curltime *pnow) { - struct curltime now = curlx_now(); /* what time is it */ - bool showprogress = progress_calc(data, now); + bool showprogress = progress_calc(data, pnow); return pgrsupdate(data, showprogress); } +CURLcode Curl_pgrsUpdate(struct Curl_easy *data) +{ + return pgrs_update(data, Curl_pgrs_now(data)); +} + +CURLcode Curl_pgrsCheck(struct Curl_easy *data) +{ + CURLcode result; + + result = pgrs_update(data, Curl_pgrs_now(data)); + if(!result && !data->req.done) + result = pgrs_speedcheck(data, Curl_pgrs_now(data)); + return result; +} + /* * Update all progress, do not do progress meter/callbacks. */ void Curl_pgrsUpdate_nometer(struct Curl_easy *data) { - struct curltime now = curlx_now(); /* what time is it */ - (void)progress_calc(data, now); + (void)progress_calc(data, Curl_pgrs_now(data)); } diff --git a/vendor/hydra/vendor/curl/lib/progress.h b/vendor/hydra/vendor/curl/lib/progress.h index bbe135cd..9cb0924d 100644 --- a/vendor/hydra/vendor/curl/lib/progress.h +++ b/vendor/hydra/vendor/curl/lib/progress.h @@ -23,9 +23,9 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curlx/timeval.h" +struct Curl_easy; typedef enum { TIMER_NONE, @@ -43,24 +43,35 @@ typedef enum { TIMER_LAST /* must be last */ } timerid; +/* Get the current timestamp of the transfer */ +const struct curltime *Curl_pgrs_now(struct Curl_easy *data); + int Curl_pgrsDone(struct Curl_easy *data); void Curl_pgrsStartNow(struct Curl_easy *data); void Curl_pgrsSetDownloadSize(struct Curl_easy *data, curl_off_t size); void Curl_pgrsSetUploadSize(struct Curl_easy *data, curl_off_t size); -/* It is fine to not check the return code if 'size' is set to 0 */ -CURLcode Curl_pgrsSetDownloadCounter(struct Curl_easy *data, curl_off_t size); - +void Curl_pgrs_download_inc(struct Curl_easy *data, size_t delta); +void Curl_pgrs_upload_inc(struct Curl_easy *data, size_t delta); void Curl_pgrsSetUploadCounter(struct Curl_easy *data, curl_off_t size); -void Curl_ratelimit(struct Curl_easy *data, struct curltime now); -int Curl_pgrsUpdate(struct Curl_easy *data); + +/* perform progress update, invoking callbacks at intervals */ +CURLcode Curl_pgrsUpdate(struct Curl_easy *data); +/* perform progress update, no callbacks invoked */ void Curl_pgrsUpdate_nometer(struct Curl_easy *data); +/* perform progress update with callbacks and speed checks */ +CURLcode Curl_pgrsCheck(struct Curl_easy *data); +/* Inform progress/speedcheck about receive/send pausing */ +void Curl_pgrsRecvPause(struct Curl_easy *data, bool enable); +void Curl_pgrsSendPause(struct Curl_easy *data, bool enable); + +/* Reset sizes and counters for up- and download. */ +void Curl_pgrsReset(struct Curl_easy *data); +/* Reset sizes for up- and download. */ void Curl_pgrsResetTransferSizes(struct Curl_easy *data); -struct curltime Curl_pgrsTime(struct Curl_easy *data, timerid timer); -timediff_t Curl_pgrsLimitWaitTime(struct pgrs_dir *d, - curl_off_t speed_limit, - struct curltime now); + +void Curl_pgrsTime(struct Curl_easy *data, timerid timer); /** * Update progress timer with the elapsed time from its start to `timestamp`. * This allows updating timers later and is used by happy eyeballing, where @@ -71,4 +82,9 @@ void Curl_pgrsTimeWas(struct Curl_easy *data, timerid timer, void Curl_pgrsEarlyData(struct Curl_easy *data, curl_off_t sent); +#ifdef UNITTESTS +UNITTEST CURLcode pgrs_speedcheck(struct Curl_easy *data, + const struct curltime *pnow); +#endif + #endif /* HEADER_CURL_PROGRESS_H */ diff --git a/vendor/hydra/vendor/curl/lib/psl.c b/vendor/hydra/vendor/curl/lib/psl.c index 832d6d21..e2488aea 100644 --- a/vendor/hydra/vendor/curl/lib/psl.c +++ b/vendor/hydra/vendor/curl/lib/psl.c @@ -21,19 +21,13 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include - #ifdef USE_LIBPSL #include "psl.h" -#include "share.h" - -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" +#include "progress.h" +#include "curl_share.h" void Curl_psl_destroy(struct PslCache *pslcache) { @@ -45,25 +39,18 @@ void Curl_psl_destroy(struct PslCache *pslcache) } } -static time_t now_seconds(void) -{ - struct curltime now = curlx_now(); - - return now.tv_sec; -} - const psl_ctx_t *Curl_psl_use(struct Curl_easy *easy) { struct PslCache *pslcache = easy->psl; const psl_ctx_t *psl; - time_t now; + time_t now_sec; if(!pslcache) return NULL; Curl_share_lock(easy, CURL_LOCK_DATA_PSL, CURL_LOCK_ACCESS_SHARED); - now = now_seconds(); - if(!pslcache->psl || pslcache->expires <= now) { + now_sec = Curl_pgrs_now(easy)->tv_sec; + if(!pslcache->psl || pslcache->expires <= now_sec) { /* Let a chance to other threads to do the job: avoids deadlock. */ Curl_share_unlock(easy, CURL_LOCK_DATA_PSL); @@ -71,8 +58,10 @@ const psl_ctx_t *Curl_psl_use(struct Curl_easy *easy) Curl_share_lock(easy, CURL_LOCK_DATA_PSL, CURL_LOCK_ACCESS_SINGLE); /* Recheck in case another thread did the job. */ - now = now_seconds(); - if(!pslcache->psl || pslcache->expires <= now) { + if(pslcache->expires <= now_sec) { + now_sec = Curl_pgrs_now(easy)->tv_sec; + } + if(!pslcache->psl || pslcache->expires <= now_sec) { bool dynamic = FALSE; time_t expires = TIME_T_MAX; @@ -80,7 +69,8 @@ const psl_ctx_t *Curl_psl_use(struct Curl_easy *easy) psl = psl_latest(NULL); dynamic = psl != NULL; /* Take care of possible time computation overflow. */ - expires = now < TIME_T_MAX - PSL_TTL ? now + PSL_TTL : TIME_T_MAX; + expires = (now_sec < TIME_T_MAX - PSL_TTL) ? + (now_sec + PSL_TTL) : TIME_T_MAX; /* Only get the built-in PSL if we do not already have the "latest". */ if(!psl && !pslcache->dynamic) @@ -95,7 +85,7 @@ const psl_ctx_t *Curl_psl_use(struct Curl_easy *easy) pslcache->expires = expires; } } - Curl_share_unlock(easy, CURL_LOCK_DATA_PSL); /* Release exclusive lock. */ + Curl_share_unlock(easy, CURL_LOCK_DATA_PSL); /* Release exclusive lock. */ Curl_share_lock(easy, CURL_LOCK_DATA_PSL, CURL_LOCK_ACCESS_SHARED); } psl = pslcache->psl; diff --git a/vendor/hydra/vendor/curl/lib/psl.h b/vendor/hydra/vendor/curl/lib/psl.h index dc11469a..97871f96 100644 --- a/vendor/hydra/vendor/curl/lib/psl.h +++ b/vendor/hydra/vendor/curl/lib/psl.h @@ -23,8 +23,8 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #ifdef USE_LIBPSL + #include struct Curl_easy; diff --git a/vendor/hydra/vendor/curl/lib/rand.c b/vendor/hydra/vendor/curl/lib/rand.c index cbfcbf27..a0b168c0 100644 --- a/vendor/hydra/vendor/curl/lib/rand.c +++ b/vendor/hydra/vendor/curl/lib/rand.c @@ -21,27 +21,18 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include - #ifdef HAVE_ARPA_INET_H #include #endif -#include #include "urldata.h" #include "vtls/vtls.h" -#include "sendf.h" -#include "curlx/timeval.h" +#include "curl_trc.h" #include "rand.h" #include "escape.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef _WIN32 #if defined(_WIN32_WINNT) && _WIN32_WINNT >= _WIN32_WINNT_VISTA && \ @@ -50,10 +41,6 @@ # include # ifdef _MSC_VER # pragma comment(lib, "bcrypt.lib") -# endif - /* Offered by mingw-w64 v3+. MS SDK v7.0A+. */ -# ifndef BCRYPT_USE_SYSTEM_PREFERRED_RNG -# define BCRYPT_USE_SYSTEM_PREFERRED_RNG 0x00000002 # endif # ifndef STATUS_SUCCESS # define STATUS_SUCCESS ((NTSTATUS)0x00000000L) @@ -127,7 +114,8 @@ static CURLcode weak_random(struct Curl_easy *data, static bool seeded = FALSE; unsigned int rnd; if(!seeded) { - struct curltime now = curlx_now(); + struct curltime now; + curlx_pnow(&now); randseed += (unsigned int)now.tv_usec + (unsigned int)now.tv_sec; randseed = randseed * 1103515245 + 12345; randseed = randseed * 1103515245 + 12345; @@ -235,8 +223,7 @@ CURLcode Curl_rand_bytes(struct Curl_easy *data, * size. */ -CURLcode Curl_rand_hex(struct Curl_easy *data, unsigned char *rnd, - size_t num) +CURLcode Curl_rand_hex(struct Curl_easy *data, unsigned char *rnd, size_t num) { CURLcode result = CURLE_BAD_FUNCTION_ARGUMENT; unsigned char buffer[128]; @@ -248,7 +235,7 @@ CURLcode Curl_rand_hex(struct Curl_easy *data, unsigned char *rnd, memset(buffer, 0, sizeof(buffer)); #endif - if((num/2 >= sizeof(buffer)) || !(num&1)) { + if((num / 2 >= sizeof(buffer)) || !(num & 1)) { /* make sure it fits in the local buffer and that it is an odd number! */ DEBUGF(infof(data, "invalid buffer size with Curl_rand_hex")); return CURLE_BAD_FUNCTION_ARGUMENT; @@ -256,11 +243,11 @@ CURLcode Curl_rand_hex(struct Curl_easy *data, unsigned char *rnd, num--; /* save one for null-termination */ - result = Curl_rand(data, buffer, num/2); + result = Curl_rand(data, buffer, num / 2); if(result) return result; - Curl_hexencode(buffer, num/2, rnd, num + 1); + Curl_hexencode(buffer, num / 2, rnd, num + 1); return result; } diff --git a/vendor/hydra/vendor/curl/lib/rand.h b/vendor/hydra/vendor/curl/lib/rand.h index 2ba60e72..03c69a0d 100644 --- a/vendor/hydra/vendor/curl/lib/rand.h +++ b/vendor/hydra/vendor/curl/lib/rand.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - CURLcode Curl_rand_bytes(struct Curl_easy *data, #ifdef DEBUGBUILD bool allow_env_override, @@ -31,9 +30,9 @@ CURLcode Curl_rand_bytes(struct Curl_easy *data, unsigned char *rnd, size_t num); #ifdef DEBUGBUILD -#define Curl_rand(a,b,c) Curl_rand_bytes((a), TRUE, (b), (c)) +#define Curl_rand(a, b, c) Curl_rand_bytes((a), TRUE, (b), (c)) #else -#define Curl_rand(a,b,c) Curl_rand_bytes((a), (b), (c)) +#define Curl_rand(a, b, c) Curl_rand_bytes((a), (b), (c)) #endif /* @@ -41,8 +40,7 @@ CURLcode Curl_rand_bytes(struct Curl_easy *data, * hexadecimal digits PLUS a null-terminating byte. It must be an odd number * size. */ -CURLcode Curl_rand_hex(struct Curl_easy *data, unsigned char *rnd, - size_t num); +CURLcode Curl_rand_hex(struct Curl_easy *data, unsigned char *rnd, size_t num); /* * Curl_rand_alnum() fills the 'rnd' buffer with a given 'num' size with random diff --git a/vendor/hydra/vendor/curl/lib/ratelimit.c b/vendor/hydra/vendor/curl/lib/ratelimit.c new file mode 100644 index 00000000..c7ba6461 --- /dev/null +++ b/vendor/hydra/vendor/curl/lib/ratelimit.c @@ -0,0 +1,196 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + * SPDX-License-Identifier: curl + * + ***************************************************************************/ +#include "curl_setup.h" + +#include "ratelimit.h" + +#define CURL_US_PER_SEC 1000000 +#define CURL_RLIMIT_MIN_CHUNK (16 * 1024) +#define CURL_RLIMIT_MAX_STEPS 2 /* 500ms interval */ + +void Curl_rlimit_init(struct Curl_rlimit *r, + curl_off_t rate_per_s, + curl_off_t burst_per_s, + const struct curltime *pts) +{ + curl_off_t rate_steps; + + DEBUGASSERT(rate_per_s >= 0); + DEBUGASSERT(burst_per_s >= rate_per_s || !burst_per_s); + DEBUGASSERT(pts); + r->step_us = CURL_US_PER_SEC; + r->rate_per_step = rate_per_s; + r->burst_per_step = burst_per_s; + /* On rates that are multiples of CURL_RLIMIT_MIN_CHUNK, we reduce + * the interval `step_us` from 1 second to smaller steps with at + * most CURL_RLIMIT_MAX_STEPS. + * Smaller means more CPU, but also more precision. */ + rate_steps = rate_per_s / CURL_RLIMIT_MIN_CHUNK; + rate_steps = CURLMIN(rate_steps, CURL_RLIMIT_MAX_STEPS); + if(rate_steps >= 2) { + r->step_us /= rate_steps; + r->rate_per_step /= rate_steps; + r->burst_per_step /= rate_steps; + } + r->tokens = r->rate_per_step; + r->spare_us = 0; + r->ts = *pts; + r->blocked = FALSE; +} + +void Curl_rlimit_start(struct Curl_rlimit *r, const struct curltime *pts) +{ + r->tokens = r->rate_per_step; + r->spare_us = 0; + r->ts = *pts; +} + +bool Curl_rlimit_active(struct Curl_rlimit *r) +{ + return (r->rate_per_step > 0) || r->blocked; +} + +bool Curl_rlimit_is_blocked(struct Curl_rlimit *r) +{ + return r->blocked; +} + +static void ratelimit_update(struct Curl_rlimit *r, + const struct curltime *pts) +{ + timediff_t elapsed_us, elapsed_steps; + curl_off_t token_gain; + + DEBUGASSERT(r->rate_per_step); + if((r->ts.tv_sec == pts->tv_sec) && (r->ts.tv_usec == pts->tv_usec)) + return; + + elapsed_us = curlx_ptimediff_us(pts, &r->ts); + if(elapsed_us < 0) { /* not going back in time */ + DEBUGASSERT(0); + return; + } + + elapsed_us += r->spare_us; + if(elapsed_us < r->step_us) + return; + + /* we do the update */ + r->ts = *pts; + elapsed_steps = elapsed_us / r->step_us; + r->spare_us = elapsed_us % r->step_us; + + /* How many tokens did we gain since the last update? */ + if(r->rate_per_step > (CURL_OFF_T_MAX / elapsed_steps)) + token_gain = CURL_OFF_T_MAX; + else { + token_gain = r->rate_per_step * elapsed_steps; + } + + /* Limit the token again by the burst rate per second (if set), so we + * do not suddenly have a huge number of tokens after inactivity. */ + r->tokens += token_gain; + if(r->burst_per_step && (r->tokens > r->burst_per_step)) { + r->tokens = r->burst_per_step; + } +} + +curl_off_t Curl_rlimit_avail(struct Curl_rlimit *r, + const struct curltime *pts) +{ + if(r->blocked) + return 0; + else if(r->rate_per_step) { + ratelimit_update(r, pts); + return r->tokens; + } + else + return CURL_OFF_T_MAX; +} + +void Curl_rlimit_drain(struct Curl_rlimit *r, + size_t tokens, + const struct curltime *pts) +{ + if(r->blocked || !r->rate_per_step) + return; + + ratelimit_update(r, pts); +#if SIZEOF_CURL_OFF_T <= SIZEOF_SIZE_T + if(tokens > CURL_OFF_T_MAX) { + r->tokens = CURL_OFF_T_MIN; + return; + } + else +#endif + { + curl_off_t val = (curl_off_t)tokens; + if((CURL_OFF_T_MIN + val) < r->tokens) + r->tokens -= val; + else + r->tokens = CURL_OFF_T_MIN; + } +} + +timediff_t Curl_rlimit_wait_ms(struct Curl_rlimit *r, + const struct curltime *pts) +{ + timediff_t wait_us, elapsed_us; + + if(r->blocked || !r->rate_per_step) + return 0; + ratelimit_update(r, pts); + if(r->tokens > 0) + return 0; + + /* How much time will it take tokens to become positive again? + * Deduct `spare_us` and check against already elapsed time */ + wait_us = (1 + (-r->tokens / r->rate_per_step)) * r->step_us; + wait_us -= r->spare_us; + + elapsed_us = curlx_ptimediff_us(pts, &r->ts); + if(elapsed_us >= wait_us) + return 0; + wait_us -= elapsed_us; + return (wait_us + 999) / 1000; /* in milliseconds */ +} + +void Curl_rlimit_block(struct Curl_rlimit *r, + bool activate, + const struct curltime *pts) +{ + if(!activate == !r->blocked) + return; + + r->ts = *pts; + r->blocked = activate; + if(!r->blocked) { + /* Start rate limiting fresh. The amount of time this was blocked + * does not generate extra tokens. */ + Curl_rlimit_start(r, pts); + } + else { + r->tokens = 0; + } +} diff --git a/vendor/hydra/vendor/curl/lib/ratelimit.h b/vendor/hydra/vendor/curl/lib/ratelimit.h new file mode 100644 index 00000000..07f11b8f --- /dev/null +++ b/vendor/hydra/vendor/curl/lib/ratelimit.h @@ -0,0 +1,93 @@ +#ifndef HEADER_Curl_rlimit_H +#define HEADER_Curl_rlimit_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + * SPDX-License-Identifier: curl + * + ***************************************************************************/ +#include "curlx/timeval.h" + +struct Curl_easy; + +/* This is a rate limiter that provides "tokens" to be consumed + * per second with a "burst" rate limitation. Example: + * A rate limit of 1 megabyte per second with a burst rate of 1.5MB. + * - initially 1 million tokens are available. + * - these are drained in the first second. + * - checking available tokens before the 2nd second will return 0. + * - at/after the 2nd second, 1 million tokens are available again. + * - nothing happens for a second, the 1 million tokens would grow + * to 2 million, however the burst limit caps those at 1.5 million. + * Thus: + * - setting "burst" to CURL_OFF_T_MAX would average tokens over the + * complete lifetime. E.g. for a download, at the *end* of it, the + * average rate from start to finish would be the rate limit. + * - setting "burst" to the same value as "rate" would make a + * download always try to stay *at/below* the rate and slow times will + * not generate extra tokens. + * A rate limit can be blocked, causing the available tokens to become + * always 0 until unblocked. After unblocking, the rate limiting starts + * again with no history of the past. + * Finally, a rate limiter with rate 0 will always have CURL_OFF_T_MAX + * tokens available, unless blocked. + */ + +struct Curl_rlimit { + curl_off_t rate_per_step; /* rate tokens are generated per step us */ + curl_off_t burst_per_step; /* burst rate of tokens per step us */ + timediff_t step_us; /* microseconds between token increases */ + curl_off_t tokens; /* tokens available in the next second */ + timediff_t spare_us; /* microseconds unaffecting tokens */ + struct curltime ts; /* time of the last update */ + BIT(blocked); /* blocking sets available tokens to 0 */ +}; + +void Curl_rlimit_init(struct Curl_rlimit *r, + curl_off_t rate_per_s, + curl_off_t burst_per_s, + const struct curltime *pts); + +/* Start ratelimiting with the given timestamp. Resets available tokens. */ +void Curl_rlimit_start(struct Curl_rlimit *r, const struct curltime *pts); + +/* How many milliseconds to wait until token are available again. */ +timediff_t Curl_rlimit_wait_ms(struct Curl_rlimit *r, + const struct curltime *pts); + +/* Return if rate limiting of tokens is active */ +bool Curl_rlimit_active(struct Curl_rlimit *r); +bool Curl_rlimit_is_blocked(struct Curl_rlimit *r); + +/* Return how many tokens are available to spend, may be negative */ +curl_off_t Curl_rlimit_avail(struct Curl_rlimit *r, + const struct curltime *pts); + +/* Drain tokens from the ratelimit, return how many are now available. */ +void Curl_rlimit_drain(struct Curl_rlimit *r, + size_t tokens, + const struct curltime *pts); + +/* Block/unblock ratelimiting. A blocked ratelimit has 0 tokens available. */ +void Curl_rlimit_block(struct Curl_rlimit *r, + bool activate, + const struct curltime *pts); + +#endif /* HEADER_Curl_rlimit_H */ diff --git a/vendor/hydra/vendor/curl/lib/rename.c b/vendor/hydra/vendor/curl/lib/rename.c deleted file mode 100644 index 4c66ce4e..00000000 --- a/vendor/hydra/vendor/curl/lib/rename.c +++ /dev/null @@ -1,72 +0,0 @@ -/*************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ - * \___|\___/|_| \_\_____| - * - * Copyright (C) Daniel Stenberg, , et al. - * - * This software is licensed as described in the file COPYING, which - * you should have received as part of this distribution. The terms - * are also available at https://curl.se/docs/copyright.html. - * - * You may opt to use, copy, modify, merge, publish, distribute and/or sell - * copies of the Software, and permit persons to whom the Software is - * furnished to do so, under the terms of the COPYING file. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - * SPDX-License-Identifier: curl - * - ***************************************************************************/ - -#include "rename.h" - -#include "curl_setup.h" - -#if (!defined(CURL_DISABLE_HTTP) || !defined(CURL_DISABLE_COOKIES)) || \ - !defined(CURL_DISABLE_ALTSVC) - -#include "curlx/multibyte.h" -#include "curlx/timeval.h" - -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - -/* return 0 on success, 1 on error */ -int Curl_rename(const char *oldpath, const char *newpath) -{ -#if defined(_WIN32) && !defined(UNDER_CE) - /* rename() on Windows does not overwrite, so we cannot use it here. - MoveFileEx() will overwrite and is usually atomic, however it fails - when there are open handles to the file. */ - const int max_wait_ms = 1000; - struct curltime start = curlx_now(); - TCHAR *tchar_oldpath = curlx_convert_UTF8_to_tchar(oldpath); - TCHAR *tchar_newpath = curlx_convert_UTF8_to_tchar(newpath); - for(;;) { - timediff_t diff; - if(MoveFileEx(tchar_oldpath, tchar_newpath, MOVEFILE_REPLACE_EXISTING)) { - curlx_unicodefree(tchar_oldpath); - curlx_unicodefree(tchar_newpath); - break; - } - diff = curlx_timediff(curlx_now(), start); - if(diff < 0 || diff > max_wait_ms) { - curlx_unicodefree(tchar_oldpath); - curlx_unicodefree(tchar_newpath); - return 1; - } - Sleep(1); - } -#else - if(rename(oldpath, newpath)) - return 1; -#endif - return 0; -} - -#endif diff --git a/vendor/hydra/vendor/curl/lib/request.c b/vendor/hydra/vendor/curl/lib/request.c index 1fa56832..ad7f628f 100644 --- a/vendor/hydra/vendor/curl/lib/request.c +++ b/vendor/hydra/vendor/curl/lib/request.c @@ -21,25 +21,20 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #include "urldata.h" #include "cfilters.h" #include "curlx/dynbuf.h" #include "doh.h" -#include "multiif.h" #include "progress.h" #include "request.h" #include "sendf.h" +#include "curl_trc.h" #include "transfer.h" #include "url.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - void Curl_req_init(struct SingleRequest *req) { memset(req, 0, sizeof(*req)); @@ -64,7 +59,7 @@ CURLcode Curl_req_soft_reset(struct SingleRequest *req, req->header = FALSE; req->headerline = 0; req->headerbytecount = 0; - req->allheadercount = 0; + req->allheadercount = 0; req->deductheadercount = 0; req->httpversion_sent = 0; req->httpversion = 0; @@ -94,7 +89,7 @@ CURLcode Curl_req_soft_reset(struct SingleRequest *req, CURLcode Curl_req_start(struct SingleRequest *req, struct Curl_easy *data) { - req->start = curlx_now(); + req->start = *Curl_pgrs_now(data); return Curl_req_soft_reset(req, data); } @@ -115,7 +110,7 @@ CURLcode Curl_req_done(struct SingleRequest *req, void Curl_req_hard_reset(struct SingleRequest *req, struct Curl_easy *data) { - struct curltime t0 = {0, 0}; + struct curltime t0 = { 0, 0 }; Curl_safefree(req->newurl); Curl_client_reset(data); @@ -132,7 +127,7 @@ void Curl_req_hard_reset(struct SingleRequest *req, struct Curl_easy *data) req->writebytecount = 0; req->start = t0; req->headerbytecount = 0; - req->allheadercount = 0; + req->allheadercount = 0; req->deductheadercount = 0; req->headerline = 0; req->offset = 0; @@ -223,7 +218,7 @@ static CURLcode xfer_send(struct Curl_easy *data, size_t body_len = *pnwritten - hds_len; Curl_debug(data, CURLINFO_DATA_OUT, buf + hds_len, body_len); data->req.writebytecount += body_len; - Curl_pgrsSetUploadCounter(data, data->req.writebytecount); + Curl_pgrs_upload_inc(data, body_len); } } } @@ -258,7 +253,7 @@ static CURLcode req_set_upload_done(struct Curl_easy *data) { DEBUGASSERT(!data->req.upload_done); data->req.upload_done = TRUE; - data->req.keepon &= ~(KEEP_SEND|KEEP_SEND_TIMED); /* we are done sending */ + data->req.keepon &= ~KEEP_SEND; /* we are done sending */ Curl_pgrsTime(data, TIMER_POSTRANSFER); Curl_creader_done(data, data->req.upload_aborted); @@ -393,6 +388,11 @@ CURLcode Curl_req_send(struct Curl_easy *data, struct dynbuf *req, return result; buf += nwritten; blen -= nwritten; + if(!blen) { + result = req_set_upload_done(data); + if(result) + return result; + } } if(blen) { @@ -415,14 +415,23 @@ bool Curl_req_sendbuf_empty(struct Curl_easy *data) bool Curl_req_want_send(struct Curl_easy *data) { - /* Not done and - * - KEEP_SEND and not PAUSEd. - * - or request has buffered data to send - * - or transfer connection has pending data to send */ + /* Not done and upload not blocked and either one of + * - KEEP_SEND + * - request has buffered data to send + * - connection has pending data to send */ return !data->req.done && - (((data->req.keepon & KEEP_SENDBITS) == KEEP_SEND) || - !Curl_req_sendbuf_empty(data) || - Curl_xfer_needs_flush(data)); + !Curl_rlimit_is_blocked(&data->progress.ul.rlimit) && + ((data->req.keepon & KEEP_SEND) || + !Curl_req_sendbuf_empty(data) || + Curl_xfer_needs_flush(data)); +} + +bool Curl_req_want_recv(struct Curl_easy *data) +{ + /* Not done and download not blocked and KEEP_RECV */ + return !data->req.done && + !Curl_rlimit_is_blocked(&data->progress.dl.rlimit) && + (data->req.keepon & KEEP_RECV); } bool Curl_req_done_sending(struct Curl_easy *data) @@ -458,8 +467,7 @@ CURLcode Curl_req_abort_sending(struct Curl_easy *data) if(!data->req.upload_done) { Curl_bufq_reset(&data->req.sendbuf); data->req.upload_aborted = TRUE; - /* no longer KEEP_SEND and KEEP_SEND_PAUSE */ - data->req.keepon &= ~KEEP_SENDBITS; + data->req.keepon &= ~KEEP_SEND; return req_set_upload_done(data); } return CURLE_OK; @@ -470,6 +478,9 @@ CURLcode Curl_req_stop_send_recv(struct Curl_easy *data) /* stop receiving and ALL sending as well, including PAUSE and HOLD. * We might still be paused on receive client writes though, so * keep those bits around. */ - data->req.keepon &= ~(KEEP_RECV|KEEP_SENDBITS); - return Curl_req_abort_sending(data); + CURLcode result = CURLE_OK; + if(data->req.keepon & KEEP_SEND) + result = Curl_req_abort_sending(data); + data->req.keepon &= ~(KEEP_RECV | KEEP_SEND); + return result; } diff --git a/vendor/hydra/vendor/curl/lib/request.h b/vendor/hydra/vendor/curl/lib/request.h index e12d5efd..389ae4d8 100644 --- a/vendor/hydra/vendor/curl/lib/request.h +++ b/vendor/hydra/vendor/curl/lib/request.h @@ -23,9 +23,7 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - /* This file is for lib internal stuff */ - #include "curl_setup.h" #include "bufq.h" @@ -48,7 +46,6 @@ enum upgrade101 { UPGR101_RECEIVED /* 101 response received */ }; - /* * Request specific data in the easy handle (Curl_easy). Previously, * these members were on the connectdata struct but since a conn struct may @@ -130,6 +127,7 @@ struct SingleRequest { BIT(sendbuf_init); /* sendbuf is initialized */ BIT(shutdown); /* request end will shutdown connection */ BIT(shutdown_err_ignore); /* errors in shutdown will not fail request */ + BIT(reader_started); /* client reads have started */ }; /** @@ -195,11 +193,13 @@ bool Curl_req_done_sending(struct Curl_easy *data); */ CURLcode Curl_req_send_more(struct Curl_easy *data); -/** - * TRUE iff the request wants to send, e.g. has buffered bytes. - */ +/* TRUE if the request wants to send, e.g. is not done sending + * and is not blocked. */ bool Curl_req_want_send(struct Curl_easy *data); +/* TRUE if the request wants to receive and is not blocked. */ +bool Curl_req_want_recv(struct Curl_easy *data); + /** * TRUE iff the request has no buffered bytes yet to send. */ diff --git a/vendor/hydra/vendor/curl/lib/rtsp.c b/vendor/hydra/vendor/curl/lib/rtsp.c index 95215b8d..93bcbeb4 100644 --- a/vendor/hydra/vendor/curl/lib/rtsp.c +++ b/vendor/hydra/vendor/curl/lib/rtsp.c @@ -21,15 +21,14 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifndef CURL_DISABLE_RTSP #include "urldata.h" -#include #include "transfer.h" #include "sendf.h" +#include "curl_trc.h" #include "multiif.h" #include "http.h" #include "url.h" @@ -40,13 +39,9 @@ #include "connect.h" #include "cfilters.h" #include "strdup.h" +#include "bufref.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - - /* meta key for storing protocol meta at easy handle */ #define CURL_META_RTSP_EASY "meta:proto:rtsp:easy" /* meta key for storing protocol meta at connection */ @@ -75,7 +70,6 @@ struct RTSP { long CSeq_recv; /* CSeq received */ }; - #define RTP_PKT_LENGTH(p) ((((unsigned int)((unsigned char)((p)[2]))) << 8) | \ ((unsigned int)((unsigned char)((p)[3])))) @@ -121,11 +115,10 @@ static CURLcode rtsp_do_pollset(struct Curl_easy *data, return Curl_pollset_add_out(data, ps, data->conn->sock[FIRSTSOCKET]); } -static -CURLcode rtp_client_write(struct Curl_easy *data, const char *ptr, size_t len); -static -CURLcode rtsp_parse_transport(struct Curl_easy *data, const char *transport); - +static CURLcode rtp_client_write(struct Curl_easy *data, const char *ptr, + size_t len); +static CURLcode rtsp_parse_transport(struct Curl_easy *data, + const char *transport); /* * RTSP handler interface. @@ -142,7 +135,7 @@ const struct Curl_handler Curl_handler_rtsp = { ZERO_NULL, /* proto_pollset */ rtsp_do_pollset, /* doing_pollset */ ZERO_NULL, /* domore_pollset */ - ZERO_NULL, /* perform_pollset */ + Curl_http_perform_pollset, /* perform_pollset */ ZERO_NULL, /* disconnect */ rtsp_rtp_write_resp, /* write_resp */ rtsp_rtp_write_resp_hd, /* write_resp_hd */ @@ -152,7 +145,7 @@ const struct Curl_handler Curl_handler_rtsp = { PORT_RTSP, /* defport */ CURLPROTO_RTSP, /* protocol */ CURLPROTO_RTSP, /* family */ - PROTOPT_NONE /* flags */ + PROTOPT_CONN_REUSE /* flags */ }; #define MAX_RTP_BUFFERSIZE 1000000 /* arbitrary */ @@ -162,7 +155,7 @@ static void rtsp_easy_dtor(void *key, size_t klen, void *entry) struct RTSP *rtsp = entry; (void)key; (void)klen; - free(rtsp); + curlx_free(rtsp); } static void rtsp_conn_dtor(void *key, size_t klen, void *entry) @@ -171,7 +164,7 @@ static void rtsp_conn_dtor(void *key, size_t klen, void *entry) (void)key; (void)klen; curlx_dyn_free(&rtspc->buf); - free(rtspc); + curlx_free(rtspc); } static CURLcode rtsp_setup_connection(struct Curl_easy *data, @@ -180,14 +173,14 @@ static CURLcode rtsp_setup_connection(struct Curl_easy *data, struct rtsp_conn *rtspc; struct RTSP *rtsp; - rtspc = calloc(1, sizeof(*rtspc)); + rtspc = curlx_calloc(1, sizeof(*rtspc)); if(!rtspc) return CURLE_OUT_OF_MEMORY; curlx_dyn_init(&rtspc->buf, MAX_RTP_BUFFERSIZE); if(Curl_conn_meta_set(conn, CURL_META_RTSP_CONN, rtspc, rtsp_conn_dtor)) return CURLE_OUT_OF_MEMORY; - rtsp = calloc(1, sizeof(struct RTSP)); + rtsp = curlx_calloc(1, sizeof(struct RTSP)); if(!rtsp || Curl_meta_set(data, CURL_META_RTSP_EASY, rtsp, rtsp_easy_dtor)) return CURLE_OUT_OF_MEMORY; @@ -195,7 +188,6 @@ static CURLcode rtsp_setup_connection(struct Curl_easy *data, return CURLE_OK; } - /* * Function to check on various aspects of a connection. */ @@ -215,18 +207,14 @@ static unsigned int rtsp_conncheck(struct Curl_easy *data, return ret_val; } - static CURLcode rtsp_connect(struct Curl_easy *data, bool *done) { struct rtsp_conn *rtspc = Curl_conn_meta_get(data->conn, CURL_META_RTSP_CONN); - CURLcode httpStatus; if(!rtspc) return CURLE_FAILED_INIT; - httpStatus = Curl_http_connect(data, done); - /* Initialize the CSeq if not already done */ if(data->state.rtsp_next_client_CSeq == 0) data->state.rtsp_next_client_CSeq = 1; @@ -234,8 +222,8 @@ static CURLcode rtsp_connect(struct Curl_easy *data, bool *done) data->state.rtsp_next_server_CSeq = 1; rtspc->rtp_channel = -1; - - return httpStatus; + *done = TRUE; + return CURLE_OK; } static CURLcode rtsp_done(struct Curl_easy *data, @@ -278,7 +266,6 @@ static CURLcode rtsp_done(struct Curl_easy *data, return httpStatus; } - static CURLcode rtsp_setup_body(struct Curl_easy *data, Curl_RtspReq rtspreq, struct dynbuf *reqp) @@ -328,9 +315,8 @@ static CURLcode rtsp_setup_body(struct Curl_easy *data, if(rtspreq == RTSPREQ_SET_PARAMETER || rtspreq == RTSPREQ_GET_PARAMETER) { if(!Curl_checkheaders(data, STRCONST("Content-Type"))) { - result = curlx_dyn_addn(reqp, - STRCONST("Content-Type: " - "text/parameters\r\n")); + result = curlx_dyn_addn(reqp, STRCONST("Content-Type: " + "text/parameters\r\n")); if(result) return result; } @@ -338,9 +324,8 @@ static CURLcode rtsp_setup_body(struct Curl_easy *data, if(rtspreq == RTSPREQ_ANNOUNCE) { if(!Curl_checkheaders(data, STRCONST("Content-Type"))) { - result = curlx_dyn_addn(reqp, - STRCONST("Content-Type: " - "application/sdp\r\n")); + result = curlx_dyn_addn(reqp, STRCONST("Content-Type: " + "application/sdp\r\n")); if(result) return result; } @@ -392,7 +377,7 @@ static CURLcode rtsp_do(struct Curl_easy *data, bool *done) to this origin */ if(!data->state.first_host) { - data->state.first_host = strdup(conn->host.name); + data->state.first_host = curlx_strdup(conn->host.name); if(!data->state.first_host) return CURLE_OUT_OF_MEMORY; @@ -481,7 +466,7 @@ static CURLcode rtsp_do(struct Curl_easy *data, bool *done) if(rtspreq == RTSPREQ_SETUP && !p_transport) { /* New Transport: setting? */ if(data->set.str[STRING_RTSP_TRANSPORT]) { - free(data->state.aptr.rtsp_transport); + curlx_free(data->state.aptr.rtsp_transport); data->state.aptr.rtsp_transport = curl_maprintf("Transport: %s\r\n", data->set.str[STRING_RTSP_TRANSPORT]); @@ -507,7 +492,7 @@ static CURLcode rtsp_do(struct Curl_easy *data, bool *done) /* Accept-Encoding header */ if(!Curl_checkheaders(data, STRCONST("Accept-Encoding")) && data->set.str[STRING_ENCODING]) { - free(data->state.aptr.accept_encoding); + curlx_free(data->state.aptr.accept_encoding); data->state.aptr.accept_encoding = curl_maprintf("Accept-Encoding: %s\r\n", data->set.str[STRING_ENCODING]); @@ -546,9 +531,10 @@ static CURLcode rtsp_do(struct Curl_easy *data, bool *done) /* Referrer */ Curl_safefree(data->state.aptr.ref); - if(data->state.referer && !Curl_checkheaders(data, STRCONST("Referer"))) - data->state.aptr.ref = curl_maprintf("Referer: %s\r\n", - data->state.referer); + if(Curl_bufref_ptr(&data->state.referer) && + !Curl_checkheaders(data, STRCONST("Referer"))) + data->state.aptr.ref = + curl_maprintf("Referer: %s\r\n", Curl_bufref_ptr(&data->state.referer)); p_referrer = data->state.aptr.ref; @@ -563,7 +549,7 @@ static CURLcode rtsp_do(struct Curl_easy *data, bool *done) /* Check to see if there is a range set in the custom headers */ if(!Curl_checkheaders(data, STRCONST("Range")) && data->state.range) { - free(data->state.aptr.rangeline); + curlx_free(data->state.aptr.rangeline); data->state.aptr.rangeline = curl_maprintf("Range: %s\r\n", data->state.range); p_range = data->state.aptr.rangeline; @@ -668,8 +654,7 @@ static CURLcode rtsp_do(struct Curl_easy *data, bool *done) /* if a request-body has been sent off, we make sure this progress is noted properly */ Curl_pgrsSetUploadCounter(data, data->req.writebytecount); - if(Curl_pgrsUpdate(data)) - result = CURLE_ABORTED_BY_CALLBACK; + result = Curl_pgrsUpdate(data); } out: curlx_dyn_free(&req_buffer); @@ -936,7 +921,7 @@ static CURLcode rtsp_rtp_write_resp(struct Curl_easy *data, blen, rtspc->in_header, data->req.done, rtspc->state, data->req.size)); if(!result && (is_eos || blen)) { - result = Curl_client_write(data, CLIENTWRITE_BODY| + result = Curl_client_write(data, CLIENTWRITE_BODY | (is_eos ? CLIENTWRITE_EOS : 0), buf, blen); } @@ -959,8 +944,8 @@ static CURLcode rtsp_rtp_write_resp_hd(struct Curl_easy *data, return rtsp_rtp_write_resp(data, buf, blen, is_eos); } -static -CURLcode rtp_client_write(struct Curl_easy *data, const char *ptr, size_t len) +static CURLcode rtp_client_write(struct Curl_easy *data, const char *ptr, + size_t len) { size_t wrote; curl_write_callback writeit; @@ -1071,10 +1056,10 @@ CURLcode Curl_rtsp_parseheader(struct Curl_easy *data, const char *header) return CURLE_OK; } -static -CURLcode rtsp_parse_transport(struct Curl_easy *data, const char *transport) +static CURLcode rtsp_parse_transport(struct Curl_easy *data, + const char *transport) { - /* If we receive multiple Transport response-headers, the linterleaved + /* If we receive multiple Transport response-headers, the interleaved channels of each response header is recorded and used together for subsequent data validity checks.*/ /* e.g.: ' RTP/AVP/TCP;unicast;interleaved=5-6' */ @@ -1114,5 +1099,4 @@ CURLcode rtsp_parse_transport(struct Curl_easy *data, const char *transport) return CURLE_OK; } - #endif /* CURL_DISABLE_RTSP */ diff --git a/vendor/hydra/vendor/curl/lib/rtsp.h b/vendor/hydra/vendor/curl/lib/rtsp.h index 59f20a9f..70ca00f6 100644 --- a/vendor/hydra/vendor/curl/lib/rtsp.h +++ b/vendor/hydra/vendor/curl/lib/rtsp.h @@ -23,17 +23,11 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #ifndef CURL_DISABLE_RTSP - extern const struct Curl_handler Curl_handler_rtsp; - CURLcode Curl_rtsp_parseheader(struct Curl_easy *data, const char *header); - #else -/* disabled */ -#define Curl_rtsp_parseheader(x,y) CURLE_NOT_BUILT_IN - -#endif /* CURL_DISABLE_RTSP */ +#define Curl_rtsp_parseheader(x, y) CURLE_NOT_BUILT_IN +#endif #endif /* HEADER_CURL_RTSP_H */ diff --git a/vendor/hydra/vendor/curl/lib/select.c b/vendor/hydra/vendor/curl/lib/select.c index 7818082e..cae5085f 100644 --- a/vendor/hydra/vendor/curl/lib/select.c +++ b/vendor/hydra/vendor/curl/lib/select.c @@ -21,34 +21,24 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #if !defined(HAVE_SELECT) && !defined(HAVE_POLL) #error "We cannot compile without select() or poll() support." #endif -#include - #ifdef HAVE_SYS_SELECT_H #include #elif defined(HAVE_UNISTD_H) #include #endif -#include - #include "urldata.h" #include "connect.h" #include "select.h" #include "curl_trc.h" #include "curlx/timediff.h" #include "curlx/wait.h" -#include "curlx/warnless.h" - -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" #ifndef HAVE_POLL /* @@ -150,19 +140,19 @@ int Curl_socket_check(curl_socket_t readfd0, /* two sockets to read from */ num = 0; if(readfd0 != CURL_SOCKET_BAD) { pfd[num].fd = readfd0; - pfd[num].events = POLLRDNORM|POLLIN|POLLRDBAND|POLLPRI; + pfd[num].events = POLLRDNORM | POLLIN | POLLRDBAND | POLLPRI; pfd[num].revents = 0; num++; } if(readfd1 != CURL_SOCKET_BAD) { pfd[num].fd = readfd1; - pfd[num].events = POLLRDNORM|POLLIN|POLLRDBAND|POLLPRI; + pfd[num].events = POLLRDNORM | POLLIN | POLLRDBAND | POLLPRI; pfd[num].revents = 0; num++; } if(writefd != CURL_SOCKET_BAD) { pfd[num].fd = writefd; - pfd[num].events = POLLWRNORM|POLLOUT|POLLPRI; + pfd[num].events = POLLWRNORM | POLLOUT | POLLPRI; pfd[num].revents = 0; num++; } @@ -174,23 +164,23 @@ int Curl_socket_check(curl_socket_t readfd0, /* two sockets to read from */ r = 0; num = 0; if(readfd0 != CURL_SOCKET_BAD) { - if(pfd[num].revents & (POLLRDNORM|POLLIN|POLLERR|POLLHUP)) + if(pfd[num].revents & (POLLRDNORM | POLLIN | POLLERR | POLLHUP)) r |= CURL_CSELECT_IN; - if(pfd[num].revents & (POLLPRI|POLLNVAL)) + if(pfd[num].revents & (POLLPRI | POLLNVAL)) r |= CURL_CSELECT_ERR; num++; } if(readfd1 != CURL_SOCKET_BAD) { - if(pfd[num].revents & (POLLRDNORM|POLLIN|POLLERR|POLLHUP)) + if(pfd[num].revents & (POLLRDNORM | POLLIN | POLLERR | POLLHUP)) r |= CURL_CSELECT_IN2; - if(pfd[num].revents & (POLLPRI|POLLNVAL)) + if(pfd[num].revents & (POLLPRI | POLLNVAL)) r |= CURL_CSELECT_ERR; num++; } if(writefd != CURL_SOCKET_BAD) { - if(pfd[num].revents & (POLLWRNORM|POLLOUT)) + if(pfd[num].revents & (POLLWRNORM | POLLOUT)) r |= CURL_CSELECT_OUT; - if(pfd[num].revents & (POLLERR|POLLHUP|POLLPRI|POLLNVAL)) + if(pfd[num].revents & (POLLERR | POLLHUP | POLLPRI | POLLNVAL)) r |= CURL_CSELECT_ERR; } @@ -269,10 +259,10 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, timediff_t timeout_ms) if(ufds[i].revents & POLLHUP) ufds[i].revents |= POLLIN; if(ufds[i].revents & POLLERR) - ufds[i].revents |= POLLIN|POLLOUT; + ufds[i].revents |= POLLIN | POLLOUT; } -#else /* HAVE_POLL */ +#else /* !HAVE_POLL */ FD_ZERO(&fds_read); FD_ZERO(&fds_write); @@ -284,15 +274,15 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, timediff_t timeout_ms) if(ufds[i].fd == CURL_SOCKET_BAD) continue; VERIFY_SOCK(ufds[i].fd); - if(ufds[i].events & (POLLIN|POLLOUT|POLLPRI| - POLLRDNORM|POLLWRNORM|POLLRDBAND)) { + if(ufds[i].events & (POLLIN |POLLOUT |POLLPRI | + POLLRDNORM | POLLWRNORM | POLLRDBAND)) { if(ufds[i].fd > maxfd) maxfd = ufds[i].fd; - if(ufds[i].events & (POLLRDNORM|POLLIN)) + if(ufds[i].events & (POLLRDNORM | POLLIN)) FD_SET(ufds[i].fd, &fds_read); - if(ufds[i].events & (POLLWRNORM|POLLOUT)) + if(ufds[i].events & (POLLWRNORM | POLLOUT)) FD_SET(ufds[i].fd, &fds_write); - if(ufds[i].events & (POLLRDBAND|POLLPRI)) + if(ufds[i].events & (POLLRDBAND | POLLPRI)) FD_SET(ufds[i].fd, &fds_err); } } @@ -338,7 +328,7 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, timediff_t timeout_ms) r++; } -#endif /* HAVE_POLL */ +#endif /* HAVE_POLL */ return r; } @@ -364,7 +354,7 @@ void Curl_pollfds_cleanup(struct curl_pollfds *cpfds) { DEBUGASSERT(cpfds); if(cpfds->allocated_pfds) { - free(cpfds->pfds); + curlx_free(cpfds->pfds); } memset(cpfds, 0, sizeof(*cpfds)); } @@ -374,13 +364,13 @@ static CURLcode cpfds_increase(struct curl_pollfds *cpfds, unsigned int inc) struct pollfd *new_fds; unsigned int new_count = cpfds->count + inc; - new_fds = calloc(new_count, sizeof(struct pollfd)); + new_fds = curlx_calloc(new_count, sizeof(struct pollfd)); if(!new_fds) return CURLE_OUT_OF_MEMORY; memcpy(new_fds, cpfds->pfds, cpfds->count * sizeof(struct pollfd)); if(cpfds->allocated_pfds) - free(cpfds->pfds); + curlx_free(cpfds->pfds); cpfds->pfds = new_fds; cpfds->count = new_count; cpfds->allocated_pfds = TRUE; @@ -521,7 +511,7 @@ void Curl_pollset_init(struct easy_pollset *ps) struct easy_pollset *Curl_pollset_create(void) { - struct easy_pollset *ps = calloc(1, sizeof(*ps)); + struct easy_pollset *ps = curlx_calloc(1, sizeof(*ps)); if(ps) Curl_pollset_init(ps); return ps; @@ -533,11 +523,11 @@ void Curl_pollset_cleanup(struct easy_pollset *ps) DEBUGASSERT(ps->init == CURL_EASY_POLLSET_MAGIC); #endif if(ps->sockets != ps->def_sockets) { - free(ps->sockets); + curlx_free(ps->sockets); ps->sockets = ps->def_sockets; } if(ps->actions != ps->def_actions) { - free(ps->actions); + curlx_free(ps->actions); ps->actions = ps->def_actions; } ps->count = CURL_ARRAYSIZE(ps->def_sockets); @@ -583,9 +573,9 @@ CURLcode Curl_pollset_change(struct Curl_easy *data, if(!VALID_SOCK(sock)) return CURLE_BAD_FUNCTION_ARGUMENT; - DEBUGASSERT(add_flags <= (CURL_POLL_IN|CURL_POLL_OUT)); - DEBUGASSERT(remove_flags <= (CURL_POLL_IN|CURL_POLL_OUT)); - DEBUGASSERT((add_flags&remove_flags) == 0); /* no overlap */ + DEBUGASSERT(add_flags <= (CURL_POLL_IN | CURL_POLL_OUT)); + DEBUGASSERT(remove_flags <= (CURL_POLL_IN | CURL_POLL_OUT)); + DEBUGASSERT((add_flags & remove_flags) == 0); /* no overlap */ for(i = 0; i < ps->n; ++i) { if(ps->sockets[i] == sock) { ps->actions[i] &= (unsigned char)(~remove_flags); @@ -614,21 +604,21 @@ CURLcode Curl_pollset_change(struct Curl_easy *data, ps->count, new_count); if(new_count <= ps->count) return CURLE_OUT_OF_MEMORY; - nsockets = calloc(new_count, sizeof(nsockets[0])); + nsockets = curlx_calloc(new_count, sizeof(nsockets[0])); if(!nsockets) return CURLE_OUT_OF_MEMORY; - nactions = calloc(new_count, sizeof(nactions[0])); + nactions = curlx_calloc(new_count, sizeof(nactions[0])); if(!nactions) { - free(nsockets); + curlx_free(nsockets); return CURLE_OUT_OF_MEMORY; } memcpy(nsockets, ps->sockets, ps->count * sizeof(ps->sockets[0])); memcpy(nactions, ps->actions, ps->count * sizeof(ps->actions[0])); if(ps->sockets != ps->def_sockets) - free(ps->sockets); + curlx_free(ps->sockets); ps->sockets = nsockets; if(ps->actions != ps->def_actions) - free(ps->actions); + curlx_free(ps->actions); ps->actions = nactions; ps->count = new_count; } @@ -668,7 +658,7 @@ int Curl_pollset_poll(struct Curl_easy *data, if(!ps->n) return curlx_wait_ms(timeout_ms); - pfds = calloc(ps->n, sizeof(*pfds)); + pfds = curlx_calloc(ps->n, sizeof(*pfds)); if(!pfds) return -1; @@ -689,7 +679,7 @@ int Curl_pollset_poll(struct Curl_easy *data, } result = Curl_poll(pfds, npfds, timeout_ms); - free(pfds); + curlx_free(pfds); return result; } @@ -711,7 +701,7 @@ void Curl_pollset_check(struct Curl_easy *data, *pwant_read = *pwant_write = FALSE; } -bool Curl_pollset_want_read(struct Curl_easy *data, +bool Curl_pollset_want_recv(struct Curl_easy *data, struct easy_pollset *ps, curl_socket_t sock) { @@ -723,3 +713,16 @@ bool Curl_pollset_want_read(struct Curl_easy *data, } return FALSE; } + +bool Curl_pollset_want_send(struct Curl_easy *data, + struct easy_pollset *ps, + curl_socket_t sock) +{ + unsigned int i; + (void)data; + for(i = 0; i < ps->n; ++i) { + if((ps->sockets[i] == sock) && (ps->actions[i] & CURL_POLL_OUT)) + return TRUE; + } + return FALSE; +} diff --git a/vendor/hydra/vendor/curl/lib/select.h b/vendor/hydra/vendor/curl/lib/select.h index c1f975e9..268ae7ce 100644 --- a/vendor/hydra/vendor/curl/lib/select.h +++ b/vendor/hydra/vendor/curl/lib/select.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifdef HAVE_POLL_H @@ -47,11 +46,10 @@ #define POLLHUP 0x10 #define POLLNVAL 0x20 -struct pollfd -{ - curl_socket_t fd; - short events; - short revents; +struct pollfd { + curl_socket_t fd; + short events; + short revents; }; #endif @@ -76,9 +74,9 @@ struct pollfd int Curl_socket_check(curl_socket_t readfd, curl_socket_t readfd2, curl_socket_t writefd, timediff_t timeout_ms); -#define SOCKET_READABLE(x,z) \ +#define SOCKET_READABLE(x, z) \ Curl_socket_check(x, CURL_SOCKET_BAD, CURL_SOCKET_BAD, z) -#define SOCKET_WRITABLE(x,z) \ +#define SOCKET_WRITABLE(x, z) \ Curl_socket_check(CURL_SOCKET_BAD, CURL_SOCKET_BAD, x, z) int Curl_poll(struct pollfd ufds[], unsigned int nfds, timediff_t timeout_ms); @@ -90,32 +88,33 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, timediff_t timeout_ms); #ifdef USE_WINSOCK #define VALID_SOCK(s) ((s) < INVALID_SOCKET) #define FDSET_SOCK(x) 1 -#define VERIFY_SOCK(x) do { \ - if(!VALID_SOCK(x)) { \ - SET_SOCKERRNO(SOCKEINVAL); \ - return -1; \ - } \ -} while(0) +#define VERIFY_SOCK(x) \ + do { \ + if(!VALID_SOCK(x)) { \ + SET_SOCKERRNO(SOCKEINVAL); \ + return -1; \ + } \ + } while(0) #else #define VALID_SOCK(s) ((s) >= 0) /* If the socket is small enough to get set or read from an fdset */ #define FDSET_SOCK(s) ((s) < FD_SETSIZE) -#define VERIFY_SOCK(x) do { \ - if(!VALID_SOCK(x) || !FDSET_SOCK(x)) { \ - SET_SOCKERRNO(SOCKEINVAL); \ - return -1; \ - } \ +#define VERIFY_SOCK(x) \ + do { \ + if(!VALID_SOCK(x) || !FDSET_SOCK(x)) { \ + SET_SOCKERRNO(SOCKEINVAL); \ + return -1; \ + } \ } while(0) #endif - /* Keep the sockets to poll for an easy handle. * `actions` are bitmaps of CURL_POLL_IN and CURL_POLL_OUT. * Starts with small capacity, grows on demand. */ -#define EZ_POLLSET_DEF_COUNT 2 +#define EZ_POLLSET_DEF_COUNT 2 struct easy_pollset { curl_socket_t *sockets; @@ -133,7 +132,6 @@ struct easy_pollset { #define CURL_EASY_POLLSET_MAGIC 0x7a657370 #endif - /* allocate and initialise */ struct easy_pollset *Curl_pollset_create(void); @@ -162,18 +160,22 @@ CURLcode Curl_pollset_set(struct Curl_easy *data, bool do_in, bool do_out) WARN_UNUSED_RESULT; #define Curl_pollset_add_in(data, ps, sock) \ - Curl_pollset_change((data), (ps), (sock), CURL_POLL_IN, 0) + Curl_pollset_change((data), (ps), (sock), CURL_POLL_IN, 0) +#define Curl_pollset_remove_in(data, ps, sock) \ + Curl_pollset_change((data), (ps), (sock), 0, CURL_POLL_IN) #define Curl_pollset_add_out(data, ps, sock) \ - Curl_pollset_change((data), (ps), (sock), CURL_POLL_OUT, 0) + Curl_pollset_change((data), (ps), (sock), CURL_POLL_OUT, 0) +#define Curl_pollset_remove_out(data, ps, sock) \ + Curl_pollset_change((data), (ps), (sock), 0, CURL_POLL_OUT) #define Curl_pollset_add_inout(data, ps, sock) \ - Curl_pollset_change((data), (ps), (sock), \ - CURL_POLL_IN|CURL_POLL_OUT, 0) + Curl_pollset_change((data), (ps), (sock), \ + CURL_POLL_IN | CURL_POLL_OUT, 0) #define Curl_pollset_set_in_only(data, ps, sock) \ - Curl_pollset_change((data), (ps), (sock), \ - CURL_POLL_IN, CURL_POLL_OUT) + Curl_pollset_change((data), (ps), (sock), \ + CURL_POLL_IN, CURL_POLL_OUT) #define Curl_pollset_set_out_only(data, ps, sock) \ - Curl_pollset_change((data), (ps), (sock), \ - CURL_POLL_OUT, CURL_POLL_IN) + Curl_pollset_change((data), (ps), (sock), \ + CURL_POLL_OUT, CURL_POLL_IN) /* return < = on error, 0 on timeout or how many sockets are ready */ int Curl_pollset_poll(struct Curl_easy *data, @@ -188,10 +190,12 @@ void Curl_pollset_check(struct Curl_easy *data, struct easy_pollset *ps, curl_socket_t sock, bool *pwant_read, bool *pwant_write); -/** - * Return TRUE if the pollset contains socket with CURL_POLL_IN. - */ -bool Curl_pollset_want_read(struct Curl_easy *data, +/* TRUE if the pollset contains socket with CURL_POLL_IN. */ +bool Curl_pollset_want_recv(struct Curl_easy *data, + struct easy_pollset *ps, + curl_socket_t sock); +/* TRUE if the pollset contains socket with CURL_POLL_OUT. */ +bool Curl_pollset_want_send(struct Curl_easy *data, struct easy_pollset *ps, curl_socket_t sock); diff --git a/vendor/hydra/vendor/curl/lib/sendf.c b/vendor/hydra/vendor/curl/lib/sendf.c index f2c29956..2d66ed58 100644 --- a/vendor/hydra/vendor/curl/lib/sendf.c +++ b/vendor/hydra/vendor/curl/lib/sendf.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifdef HAVE_NETINET_IN_H @@ -34,30 +33,17 @@ #include #endif -#include - #include "urldata.h" #include "sendf.h" +#include "curl_trc.h" #include "transfer.h" #include "cfilters.h" #include "connect.h" -#include "content_encoding.h" #include "cw-out.h" #include "cw-pause.h" -#include "vtls/vtls.h" -#include "vssh/ssh.h" -#include "easyif.h" #include "multiif.h" #include "strerror.h" -#include "select.h" -#include "http2.h" #include "progress.h" -#include "curlx/warnless.h" -#include "ws.h" - -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" static CURLcode do_init_writer_stack(struct Curl_easy *data); @@ -73,13 +59,14 @@ CURLcode Curl_client_write(struct Curl_easy *data, CURLcode result; /* it is one of those, at least */ - DEBUGASSERT(type & (CLIENTWRITE_BODY|CLIENTWRITE_HEADER|CLIENTWRITE_INFO)); + DEBUGASSERT(type & + (CLIENTWRITE_BODY | CLIENTWRITE_HEADER | CLIENTWRITE_INFO)); /* BODY is only BODY (with optional EOS) */ DEBUGASSERT(!(type & CLIENTWRITE_BODY) || - ((type & ~(CLIENTWRITE_BODY|CLIENTWRITE_EOS)) == 0)); + ((type & ~(CLIENTWRITE_BODY | CLIENTWRITE_EOS)) == 0)); /* INFO is only INFO (with optional EOS) */ DEBUGASSERT(!(type & CLIENTWRITE_INFO) || - ((type & ~(CLIENTWRITE_INFO|CLIENTWRITE_EOS)) == 0)); + ((type & ~(CLIENTWRITE_INFO | CLIENTWRITE_EOS)) == 0)); if(!data->req.writer_stack) { result = do_init_writer_stack(data); @@ -100,7 +87,7 @@ static void cl_reset_writer(struct Curl_easy *data) while(writer) { data->req.writer_stack = writer->next; writer->cwt->do_close(data, writer); - free(writer); + curlx_free(writer); writer = data->req.writer_stack; } } @@ -108,10 +95,11 @@ static void cl_reset_writer(struct Curl_easy *data) static void cl_reset_reader(struct Curl_easy *data) { struct Curl_creader *reader = data->req.reader_stack; + data->req.reader_started = FALSE; while(reader) { data->req.reader_stack = reader->next; reader->crt->do_close(data, reader); - free(reader); + curlx_free(reader); reader = data->req.reader_stack; } } @@ -209,20 +197,7 @@ static size_t get_max_body_write_len(struct Curl_easy *data, curl_off_t limit) { if(limit != -1) { /* How much more are we allowed to write? */ - curl_off_t remain_diff; - remain_diff = limit - data->req.bytecount; - if(remain_diff < 0) { - /* already written too much! */ - return 0; - } -#if SIZEOF_CURL_OFF_T > SIZEOF_SIZE_T - else if(remain_diff > SSIZE_MAX) { - return SIZE_MAX; - } -#endif - else { - return (size_t)remain_diff; - } + return curlx_sotouz_range(limit - data->req.bytecount, 0, SIZE_MAX); } return SIZE_MAX; } @@ -242,8 +217,10 @@ static CURLcode cw_download_write(struct Curl_easy *data, size_t nwrite, excess_len = 0; bool is_connect = !!(type & CLIENTWRITE_CONNECT); - if(!is_connect && !ctx->started_response) { + if(!ctx->started_response && + !(type & (CLIENTWRITE_INFO | CLIENTWRITE_CONNECT))) { Curl_pgrsTime(data, TIMER_STARTTRANSFER); + Curl_rlimit_start(&data->progress.dl.rlimit, Curl_pgrs_now(data)); ctx->started_response = TRUE; } @@ -314,11 +291,12 @@ static CURLcode cw_download_write(struct Curl_easy *data, if(result) return result; } + /* Update stats, write and report progress */ - data->req.bytecount += nwrite; - result = Curl_pgrsSetDownloadCounter(data, data->req.bytecount); - if(result) - return result; + if(nwrite) { + data->req.bytecount += nwrite; + Curl_pgrs_download_inc(data, nwrite); + } if(excess_len) { if(!data->req.ignorebody) { @@ -384,7 +362,7 @@ CURLcode Curl_cwriter_create(struct Curl_cwriter **pwriter, void *p; DEBUGASSERT(cwt->cwriter_size >= sizeof(struct Curl_cwriter)); - p = calloc(1, cwt->cwriter_size); + p = curlx_calloc(1, cwt->cwriter_size); if(!p) goto out; @@ -397,7 +375,7 @@ CURLcode Curl_cwriter_create(struct Curl_cwriter **pwriter, out: *pwriter = result ? NULL : writer; if(result) - free(writer); + curlx_free(writer); return result; } @@ -406,7 +384,7 @@ void Curl_cwriter_free(struct Curl_easy *data, { if(writer) { writer->cwt->do_close(data, writer); - free(writer); + curlx_free(writer); } } @@ -680,11 +658,7 @@ static CURLcode cr_in_read(struct Curl_easy *data, } /* respect length limitations */ if(ctx->total_len >= 0) { - curl_off_t remain = ctx->total_len - ctx->read_len; - if(remain <= 0) - blen = 0; - else if(remain < (curl_off_t)blen) - blen = (size_t)remain; + blen = curlx_sotouz_range(ctx->total_len - ctx->read_len, 0, blen); } nread = 0; if(ctx->read_cb && blen) { @@ -802,7 +776,7 @@ static CURLcode cr_in_resume_from(struct Curl_easy *data, } /* when seekerr == CURL_SEEKFUNC_CANTSEEK (cannot seek to offset) */ do { - char scratch[4*1024]; + char scratch[4 * 1024]; size_t readthisamountnow = (offset - passed > (curl_off_t)sizeof(scratch)) ? sizeof(scratch) : @@ -952,7 +926,7 @@ CURLcode Curl_creader_create(struct Curl_creader **preader, void *p; DEBUGASSERT(crt->creader_size >= sizeof(struct Curl_creader)); - p = calloc(1, crt->creader_size); + p = curlx_calloc(1, crt->creader_size); if(!p) goto out; @@ -965,7 +939,7 @@ CURLcode Curl_creader_create(struct Curl_creader **preader, out: *preader = result ? NULL : reader; if(result) - free(reader); + curlx_free(reader); return result; } @@ -973,7 +947,7 @@ void Curl_creader_free(struct Curl_easy *data, struct Curl_creader *reader) { if(reader) { reader->crt->do_close(data, reader); - free(reader); + curlx_free(reader); } } @@ -1107,8 +1081,7 @@ static CURLcode cr_lc_add(struct Curl_easy *data) struct Curl_creader *reader = NULL; CURLcode result; - result = Curl_creader_create(&reader, data, &cr_lc, - CURL_CR_CONTENT_ENCODE); + result = Curl_creader_create(&reader, data, &cr_lc, CURL_CR_CONTENT_ENCODE); if(!result) result = Curl_creader_add(data, reader); @@ -1210,6 +1183,7 @@ CURLcode Curl_client_read(struct Curl_easy *data, char *buf, size_t blen, DEBUGASSERT(blen); DEBUGASSERT(nread); DEBUGASSERT(eos); + *nread = 0; if(!data->req.reader_stack) { result = Curl_creader_set_fread(data, data->state.infilesize); @@ -1217,9 +1191,26 @@ CURLcode Curl_client_read(struct Curl_easy *data, char *buf, size_t blen, return result; DEBUGASSERT(data->req.reader_stack); } + if(!data->req.reader_started) { + Curl_rlimit_start(&data->progress.ul.rlimit, Curl_pgrs_now(data)); + data->req.reader_started = TRUE; + } + if(Curl_rlimit_active(&data->progress.ul.rlimit)) { + curl_off_t ul_avail = Curl_rlimit_avail(&data->progress.ul.rlimit, + Curl_pgrs_now(data)); + if(ul_avail <= 0) { + result = CURLE_OK; + *eos = FALSE; + goto out; + } + if(ul_avail < (curl_off_t)blen) + blen = (size_t)ul_avail; + } result = Curl_creader_read(data, data->req.reader_stack, buf, blen, nread, eos); + +out: CURL_TRC_READ(data, "client_read(len=%zu) -> %d, nread=%zu, eos=%d", blen, result, *nread, *eos); return result; @@ -1365,9 +1356,9 @@ static CURLcode cr_buf_resume_from(struct Curl_easy *data, /* already started reading? */ if(ctx->index) return CURLE_READ_ERROR; - if(offset <= 0) + boffset = curlx_sotouz_range(offset, 0, SIZE_MAX); + if(!boffset) return CURLE_OK; - boffset = (size_t)offset; if(boffset > ctx->blen) return CURLE_READ_ERROR; @@ -1479,5 +1470,4 @@ struct Curl_creader *Curl_creader_get_by_type(struct Curl_easy *data, return r; } return NULL; - } diff --git a/vendor/hydra/vendor/curl/lib/sendf.h b/vendor/hydra/vendor/curl/lib/sendf.h index 68674439..1521ccb0 100644 --- a/vendor/hydra/vendor/curl/lib/sendf.h +++ b/vendor/hydra/vendor/curl/lib/sendf.h @@ -23,11 +23,8 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include "curl_trc.h" - /** * Type of data that is being written to the client (application) * - data written can be either BODY or META data @@ -42,15 +39,20 @@ * BODY, INFO and HEADER should not be mixed, as this would lead to * confusion on how to interpret/format/convert the data. */ -#define CLIENTWRITE_BODY (1<<0) /* non-meta information, BODY */ -#define CLIENTWRITE_INFO (1<<1) /* meta information, not a HEADER */ -#define CLIENTWRITE_HEADER (1<<2) /* meta information, HEADER */ -#define CLIENTWRITE_STATUS (1<<3) /* a special status HEADER */ -#define CLIENTWRITE_CONNECT (1<<4) /* a CONNECT related HEADER */ -#define CLIENTWRITE_1XX (1<<5) /* a 1xx response related HEADER */ -#define CLIENTWRITE_TRAILER (1<<6) /* a trailer HEADER */ -#define CLIENTWRITE_EOS (1<<7) /* End Of transfer download Stream */ -#define CLIENTWRITE_0LEN (1<<8) /* write even 0-length buffers */ +#define CLIENTWRITE_BODY (1 << 0) /* non-meta information, BODY */ +#define CLIENTWRITE_INFO (1 << 1) /* meta information, not a HEADER */ +#define CLIENTWRITE_HEADER (1 << 2) /* meta information, HEADER */ +#define CLIENTWRITE_STATUS (1 << 3) /* a special status HEADER */ +#define CLIENTWRITE_CONNECT (1 << 4) /* a CONNECT related HEADER */ +#define CLIENTWRITE_1XX (1 << 5) /* a 1xx response related HEADER */ +#define CLIENTWRITE_TRAILER (1 << 6) /* a trailer HEADER */ +#define CLIENTWRITE_EOS (1 << 7) /* End Of transfer download Stream */ +#define CLIENTWRITE_0LEN (1 << 8) /* write even 0-length buffers */ + +/* Forward declarations */ +struct Curl_creader; +struct Curl_cwriter; +struct Curl_easy; /** * Write `len` bytes at `prt` to the client. `type` indicates what @@ -202,7 +204,6 @@ CURLcode Curl_cwriter_def_write(struct Curl_easy *data, void Curl_cwriter_def_close(struct Curl_easy *data, struct Curl_cwriter *writer); - typedef enum { CURL_CRCNTRL_REWIND, CURL_CRCNTRL_UNPAUSE, @@ -403,7 +404,6 @@ void Curl_creader_done(struct Curl_easy *data, int premature); struct Curl_creader *Curl_creader_get_by_type(struct Curl_easy *data, const struct Curl_crtype *crt); - /** * Set the client reader to provide 0 bytes, immediate EOS. */ diff --git a/vendor/hydra/vendor/curl/lib/setopt.c b/vendor/hydra/vendor/curl/lib/setopt.c index 3c3adb06..0c1da5bc 100644 --- a/vendor/hydra/vendor/curl/lib/setopt.c +++ b/vendor/hydra/vendor/curl/lib/setopt.c @@ -21,11 +21,8 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include - #ifdef HAVE_NETINET_IN_H #include #endif @@ -41,30 +38,24 @@ #include "progress.h" #include "content_encoding.h" #include "strcase.h" -#include "share.h" +#include "curl_share.h" #include "vtls/vtls.h" -#include "curlx/warnless.h" -#include "sendf.h" +#include "curl_trc.h" #include "hostip.h" -#include "http2.h" #include "setopt.h" -#include "multiif.h" #include "altsvc.h" #include "hsts.h" #include "tftp.h" #include "strdup.h" #include "escape.h" - -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" +#include "bufref.h" static CURLcode setopt_set_timeout_sec(timediff_t *ptimeout_ms, long secs) { if(secs < 0) return CURLE_BAD_FUNCTION_ARGUMENT; -#if LONG_MAX > (TIMEDIFF_T_MAX/1000) - if(secs > (TIMEDIFF_T_MAX/1000)) { +#if LONG_MAX > (TIMEDIFF_T_MAX / 1000) + if(secs > (TIMEDIFF_T_MAX / 1000)) { *ptimeout_ms = TIMEDIFF_T_MAX; return CURLE_OK; } @@ -98,7 +89,7 @@ CURLcode Curl_setstropt(char **charp, const char *s) if(strlen(s) > CURL_MAX_INPUT_LENGTH) return CURLE_BAD_FUNCTION_ARGUMENT; - *charp = strdup(s); + *charp = curlx_strdup(s); if(!*charp) return CURLE_OUT_OF_MEMORY; } @@ -119,8 +110,8 @@ CURLcode Curl_setblobopt(struct curl_blob **blobp, if(blob->len > CURL_MAX_INPUT_LENGTH) return CURLE_BAD_FUNCTION_ARGUMENT; nblob = (struct curl_blob *) - malloc(sizeof(struct curl_blob) + - ((blob->flags & CURL_BLOB_COPY) ? blob->len : 0)); + curlx_malloc(sizeof(struct curl_blob) + + ((blob->flags & CURL_BLOB_COPY) ? blob->len : 0)); if(!nblob) return CURLE_OUT_OF_MEMORY; *nblob = *blob; @@ -158,10 +149,10 @@ static CURLcode setstropt_userpwd(char *option, char **userp, char **passwdp) return result; } - free(*userp); + curlx_free(*userp); *userp = user; - free(*passwdp); + curlx_free(*passwdp); *passwdp = passwd; return CURLE_OK; @@ -185,19 +176,19 @@ static CURLcode setstropt_interface(char *option, char **devp, if(result) return result; } - free(*devp); + curlx_free(*devp); *devp = dev; - free(*ifacep); + curlx_free(*ifacep); *ifacep = iface; - free(*hostp); + curlx_free(*hostp); *hostp = host; return CURLE_OK; } -#define C_SSLVERSION_VALUE(x) (x & 0xffff) +#define C_SSLVERSION_VALUE(x) (x & 0xffff) #define C_SSLVERSION_MAX_VALUE(x) ((unsigned long)x & 0xffff0000) static CURLcode protocol2num(const char *str, curl_prot_t *val) @@ -212,7 +203,7 @@ static CURLcode protocol2num(const char *str, curl_prot_t *val) return CURLE_BAD_FUNCTION_ARGUMENT; if(curl_strequal(str, "all")) { - *val = ~(curl_prot_t) 0; + *val = ~(curl_prot_t)0; return CURLE_OK; } @@ -221,7 +212,7 @@ static CURLcode protocol2num(const char *str, curl_prot_t *val) size_t tlen; str = strchr(str, ','); - tlen = str ? (size_t) (str - token) : strlen(token); + tlen = str ? (size_t)(str - token) : strlen(token); if(tlen) { const struct Curl_handler *h = Curl_getn_scheme_handler(token, tlen); @@ -260,7 +251,7 @@ static CURLcode httpauth(struct Curl_easy *data, bool proxy, /* switch off bits we cannot support */ #ifndef USE_NTLM - auth &= ~CURLAUTH_NTLM; /* no NTLM support */ + auth &= ~CURLAUTH_NTLM; /* no NTLM support */ #endif #ifndef USE_SPNEGO auth &= ~CURLAUTH_NEGOTIATE; /* no Negotiate (SPNEGO) auth without GSS-API @@ -322,7 +313,7 @@ static CURLcode setopt_HTTP_VERSION(struct Curl_easy *data, long arg) data->set.httpwant = (unsigned char)arg; return CURLE_OK; } -#endif /* ! CURL_DISABLE_HTTP */ +#endif /* !CURL_DISABLE_HTTP */ #ifdef USE_SSL CURLcode Curl_setopt_SSLVERSION(struct Curl_easy *data, CURLoption option, @@ -359,7 +350,7 @@ CURLcode Curl_setopt_SSLVERSION(struct Curl_easy *data, CURLoption option, } return CURLE_OK; } -#endif /* ! USE_SSL */ +#endif /* !USE_SSL */ #ifndef CURL_DISABLE_RTSP static CURLcode setopt_RTSP_REQUEST(struct Curl_easy *data, long arg) @@ -420,7 +411,7 @@ static CURLcode setopt_RTSP_REQUEST(struct Curl_easy *data, long arg) data->set.rtspreq = rtspreq; return CURLE_OK; } -#endif /* ! CURL_DISABLE_RTSP */ +#endif /* !CURL_DISABLE_RTSP */ #ifdef USE_SSL static void set_ssl_options(struct ssl_config_data *ssl, @@ -528,7 +519,7 @@ static CURLcode setopt_bool(struct Curl_easy *data, CURLoption option, case CURLOPT_HTTP09_ALLOWED: s->http09_allowed = enabled; break; -#if !defined(CURL_DISABLE_COOKIES) +#ifndef CURL_DISABLE_COOKIES case CURLOPT_COOKIESESSION: /* * Set this option to TRUE to start a new "cookie session". It will @@ -591,7 +582,7 @@ static CURLcode setopt_bool(struct Curl_easy *data, CURLoption option, else s->method = HTTPREQ_GET; break; -#endif /* ! CURL_DISABLE_HTTP */ +#endif /* !CURL_DISABLE_HTTP */ #ifndef CURL_DISABLE_PROXY case CURLOPT_HTTPPROXYTUNNEL: /* @@ -629,7 +620,7 @@ static CURLcode setopt_bool(struct Curl_easy *data, CURLoption option, */ s->proxy_transfer_mode = enabled; break; -#endif /* ! CURL_DISABLE_PROXY */ +#endif /* !CURL_DISABLE_PROXY */ #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI) case CURLOPT_SOCKS5_GSSAPI_NEC: /* @@ -692,7 +683,7 @@ static CURLcode setopt_bool(struct Curl_easy *data, CURLoption option, */ s->tftp_no_options = enabled; break; -#endif /* ! CURL_DISABLE_TFTP */ +#endif /* !CURL_DISABLE_TFTP */ case CURLOPT_TRANSFERTEXT: /* * This option was previously named 'FTPASCII'. Renamed to work with @@ -735,7 +726,7 @@ static CURLcode setopt_bool(struct Curl_easy *data, CURLoption option, s->doh_verifystatus = enabled; ok = 2; break; -#endif /* ! CURL_DISABLE_DOH */ +#endif /* !CURL_DISABLE_DOH */ case CURLOPT_SSL_VERIFYHOST: /* * Enable verification of the hostname in the peer certificate @@ -791,15 +782,14 @@ static CURLcode setopt_bool(struct Curl_easy *data, CURLoption option, case CURLOPT_SSL_SESSIONID_CACHE: s->ssl.primary.cache_session = enabled; #ifndef CURL_DISABLE_PROXY - s->proxy_ssl.primary.cache_session = - s->ssl.primary.cache_session; + s->proxy_ssl.primary.cache_session = s->ssl.primary.cache_session; #endif break; #ifdef USE_SSH case CURLOPT_SSH_COMPRESSION: s->ssh_compression = enabled; break; -#endif /* ! USE_SSH */ +#endif /* !USE_SSH */ #ifndef CURL_DISABLE_SMTP case CURLOPT_MAIL_RCPT_ALLOWFAILS: /* allow RCPT TO command to fail for some recipients */ @@ -814,7 +804,7 @@ static CURLcode setopt_bool(struct Curl_easy *data, CURLoption option, s->tcp_keepalive = enabled; break; case CURLOPT_TCP_FASTOPEN: -#if defined(CONNECT_DATA_IDEMPOTENT) || defined(MSG_FASTOPEN) || \ +#if defined(CONNECT_DATA_IDEMPOTENT) || defined(MSG_FASTOPEN) || \ defined(TCP_FASTOPEN_CONNECT) s->tcp_fastopen = enabled; break; @@ -992,7 +982,7 @@ static CURLcode setopt_long(struct Curl_easy *data, CURLoption option, s->expect_100_timeout = (unsigned short)arg; break; -#endif /* ! CURL_DISABLE_HTTP */ +#endif /* !CURL_DISABLE_HTTP */ #ifndef CURL_DISABLE_MIME case CURLOPT_MIME_OPTIONS: @@ -1001,9 +991,9 @@ static CURLcode setopt_long(struct Curl_easy *data, CURLoption option, #endif #ifndef CURL_DISABLE_PROXY case CURLOPT_PROXYPORT: - if((arg < 0) || (arg > 65535)) + if((arg < 0) || (arg > UINT16_MAX)) return CURLE_BAD_FUNCTION_ARGUMENT; - s->proxyport = (unsigned short)arg; + s->proxyport = (uint16_t)arg; break; case CURLOPT_PROXYAUTH: @@ -1020,7 +1010,7 @@ static CURLcode setopt_long(struct Curl_easy *data, CURLoption option, return CURLE_NOT_BUILT_IN; s->socks5auth = (unsigned char)uarg; break; -#endif /* ! CURL_DISABLE_PROXY */ +#endif /* !CURL_DISABLE_PROXY */ #ifndef CURL_DISABLE_FTP case CURLOPT_FTP_FILEMETHOD: @@ -1041,14 +1031,14 @@ static CURLcode setopt_long(struct Curl_easy *data, CURLoption option, break; case CURLOPT_ACCEPTTIMEOUT_MS: return setopt_set_timeout_ms(&s->accepttimeout, arg); -#endif /* ! CURL_DISABLE_FTP */ +#endif /* !CURL_DISABLE_FTP */ #if !defined(CURL_DISABLE_FTP) || defined(USE_SSH) case CURLOPT_FTP_CREATE_MISSING_DIRS: if((arg < CURLFTP_CREATE_DIR_NONE) || (arg > CURLFTP_CREATE_DIR_RETRY)) return CURLE_BAD_FUNCTION_ARGUMENT; s->ftp_create_missing_dirs = (unsigned char)arg; break; -#endif /* ! CURL_DISABLE_FTP || USE_SSH */ +#endif /* !CURL_DISABLE_FTP || USE_SSH */ case CURLOPT_INFILESIZE: if(arg < -1) return CURLE_BAD_FUNCTION_ARGUMENT; @@ -1103,7 +1093,7 @@ static CURLcode setopt_long(struct Curl_easy *data, CURLoption option, #ifdef HAVE_GSSAPI case CURLOPT_GSSAPI_DELEGATION: s->gssapi_delegation = (unsigned char)uarg & - (CURLGSSAPI_DELEGATION_POLICY_FLAG|CURLGSSAPI_DELEGATION_FLAG); + (CURLGSSAPI_DELEGATION_POLICY_FLAG | CURLGSSAPI_DELEGATION_FLAG); break; #endif @@ -1149,7 +1139,7 @@ static CURLcode setopt_long(struct Curl_easy *data, CURLoption option, case CURLOPT_IPRESOLVE: if((arg < CURL_IPRESOLVE_WHATEVER) || (arg > CURL_IPRESOLVE_V6)) return CURLE_BAD_FUNCTION_ARGUMENT; - s->ipver = (unsigned char) arg; + s->ipver = (unsigned char)arg; break; case CURLOPT_CONNECT_ONLY: @@ -1159,7 +1149,6 @@ static CURLcode setopt_long(struct Curl_easy *data, CURLoption option, s->connect_only_ws = (arg == 2); break; - #ifdef USE_SSH case CURLOPT_SSH_AUTH_TYPES: s->ssh_auth_types = (int)arg; @@ -1208,7 +1197,7 @@ static CURLcode setopt_long(struct Curl_easy *data, CURLoption option, data->state.rtsp_next_server_CSeq = arg; break; -#endif /* ! CURL_DISABLE_RTSP */ +#endif /* !CURL_DISABLE_RTSP */ case CURLOPT_TCP_KEEPIDLE: result = value_range(&arg, 0, 0, INT_MAX); @@ -1264,7 +1253,7 @@ static CURLcode setopt_long(struct Curl_easy *data, CURLoption option, else Curl_hsts_cleanup(&data->hsts); break; -#endif /* ! CURL_DISABLE_HSTS */ +#endif /* !CURL_DISABLE_HSTS */ #ifndef CURL_DISABLE_ALTSVC case CURLOPT_ALTSVC_CTRL: if(!arg) { @@ -1277,7 +1266,7 @@ static CURLcode setopt_long(struct Curl_easy *data, CURLoption option, return CURLE_OUT_OF_MEMORY; } return Curl_altsvc_ctrl(data->asi, arg); -#endif /* ! CURL_DISABLE_ALTSVC */ +#endif /* !CURL_DISABLE_ALTSVC */ #ifndef CURL_DISABLE_WEBSOCKETS case CURLOPT_WS_OPTIONS: s->ws_raw_mode = (bool)(arg & CURLWS_RAW_MODE); @@ -1416,10 +1405,10 @@ static CURLcode setopt_pointers(struct Curl_easy *data, CURLoption option, Curl_safefree(data->state.formp); data->state.mimepost = NULL; break; -#endif /* ! CURL_DISABLE_FORM_API */ -#endif /* ! CURL_DISABLE_HTTP */ -#if !defined(CURL_DISABLE_HTTP) || !defined(CURL_DISABLE_SMTP) || \ - !defined(CURL_DISABLE_IMAP) +#endif /* !CURL_DISABLE_FORM_API */ +#endif /* !CURL_DISABLE_HTTP */ +#if !defined(CURL_DISABLE_HTTP) || !defined(CURL_DISABLE_SMTP) || \ + !defined(CURL_DISABLE_IMAP) # ifndef CURL_DISABLE_MIME case CURLOPT_MIMEPOST: /* @@ -1438,8 +1427,8 @@ static CURLcode setopt_pointers(struct Curl_easy *data, CURLoption option, #endif } break; -#endif /* ! CURL_DISABLE_MIME */ -#endif /* ! disabled HTTP, SMTP or IMAP */ +#endif /* !CURL_DISABLE_MIME */ +#endif /* !CURL_DISABLE_HTTP || !CURL_DISABLE_SMTP || !CURL_DISABLE_IMAP */ case CURLOPT_STDERR: /* * Set to a FILE * that should receive all error writes. This @@ -1449,8 +1438,7 @@ static CURLcode setopt_pointers(struct Curl_easy *data, CURLoption option, if(!s->err) s->err = stderr; break; - case CURLOPT_SHARE: - { + case CURLOPT_SHARE: { struct Curl_share *set = va_arg(param, struct Curl_share *); /* disconnect from old share, if any */ @@ -1497,7 +1485,7 @@ static CURLcode setopt_pointers(struct Curl_easy *data, CURLoption option, /* enable cookies since we now use a share that uses cookies! */ data->cookies = data->share->cookies; } -#endif /* CURL_DISABLE_HTTP */ +#endif /* CURL_DISABLE_HTTP */ #ifndef CURL_DISABLE_HSTS if(data->share->hsts) { /* first free the private one if any */ @@ -1514,8 +1502,8 @@ static CURLcode setopt_pointers(struct Curl_easy *data, CURLoption option, } /* check for host cache not needed, * it will be done by curl_easy_perform */ + break; } - break; #ifdef USE_HTTP2 case CURLOPT_STREAM_DEPENDS: @@ -1535,9 +1523,9 @@ static CURLcode setopt_pointers(struct Curl_easy *data, CURLoption option, } #ifndef CURL_DISABLE_COOKIES -static CURLcode cookielist(struct Curl_easy *data, - const char *ptr) +static CURLcode cookielist(struct Curl_easy *data, const char *ptr) { + CURLcode result = CURLE_OK; if(!ptr) return CURLE_OK; @@ -1559,14 +1547,15 @@ static CURLcode cookielist(struct Curl_easy *data, } else if(curl_strequal(ptr, "RELOAD")) { /* reload cookies from file */ - Curl_cookie_loadfiles(data); + return Curl_cookie_loadfiles(data); } else { if(!data->cookies) { /* if cookie engine was not running, activate it */ - data->cookies = Curl_cookie_init(data, NULL, NULL, TRUE); + data->cookies = Curl_cookie_init(); if(!data->cookies) return CURLE_OUT_OF_MEMORY; + data->state.cookie_engine = TRUE; } /* general protection against mistakes and abuse */ @@ -1576,19 +1565,18 @@ static CURLcode cookielist(struct Curl_easy *data, Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE); if(checkprefix("Set-Cookie:", ptr)) /* HTTP Header format line */ - Curl_cookie_add(data, data->cookies, TRUE, FALSE, ptr + 11, NULL, - NULL, TRUE); + result = Curl_cookie_add(data, data->cookies, TRUE, FALSE, ptr + 11, + NULL, NULL, TRUE); else /* Netscape format line */ - Curl_cookie_add(data, data->cookies, FALSE, FALSE, ptr, NULL, - NULL, TRUE); + result = Curl_cookie_add(data, data->cookies, FALSE, FALSE, ptr, NULL, + NULL, TRUE); Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE); } - return CURLE_OK; + return result; } -static CURLcode cookiefile(struct Curl_easy *data, - const char *ptr) +static CURLcode cookiefile(struct Curl_easy *data, const char *ptr) { /* * Set cookie file to read and parse. Can be used multiple times. @@ -1642,8 +1630,7 @@ static CURLcode setopt_cptr(struct Curl_easy *data, CURLoption option, case CURLOPT_PROXY_SSL_CIPHER_LIST: if(Curl_ssl_supports(data, SSLSUPP_CIPHER_LIST)) { /* set a list of cipher we want to use in the SSL connection for proxy */ - return Curl_setstropt(&s->str[STRING_SSL_CIPHER_LIST_PROXY], - ptr); + return Curl_setstropt(&s->str[STRING_SSL_CIPHER_LIST_PROXY], ptr); } else return CURLE_NOT_BUILT_IN; @@ -1659,8 +1646,7 @@ static CURLcode setopt_cptr(struct Curl_easy *data, CURLoption option, case CURLOPT_PROXY_TLS13_CIPHERS: if(Curl_ssl_supports(data, SSLSUPP_TLS13_CIPHERSUITES)) /* set preferred list of TLS 1.3 cipher suites for proxy */ - return Curl_setstropt(&s->str[STRING_SSL_CIPHER13_LIST_PROXY], - ptr); + return Curl_setstropt(&s->str[STRING_SSL_CIPHER13_LIST_PROXY], ptr); else return CURLE_NOT_BUILT_IN; #endif @@ -1683,31 +1669,29 @@ static CURLcode setopt_cptr(struct Curl_easy *data, CURLoption option, /* * A string with POST data. Makes curl HTTP POST. Even if it is NULL. * If needed, CURLOPT_POSTFIELDSIZE must have been set prior to - * CURLOPT_COPYPOSTFIELDS and not altered later. + * CURLOPT_COPYPOSTFIELDS and not altered later. */ if(!ptr || s->postfieldsize == -1) result = Curl_setstropt(&s->str[STRING_COPYPOSTFIELDS], ptr); else { + size_t pflen; + if(s->postfieldsize < 0) return CURLE_BAD_FUNCTION_ARGUMENT; -#if SIZEOF_CURL_OFF_T > SIZEOF_SIZE_T - /* - * Check that requested length does not overflow the size_t type. - */ - else if(s->postfieldsize > SIZE_MAX) + pflen = curlx_sotouz_range(s->postfieldsize, 0, SIZE_MAX); + if(pflen == SIZE_MAX) return CURLE_OUT_OF_MEMORY; -#endif else { /* Allocate even when size == 0. This satisfies the need of possible later address compare to detect the COPYPOSTFIELDS mode, and to mark that postfields is used rather than read function or form data. */ - char *p = Curl_memdup0(ptr, (size_t)s->postfieldsize); + char *p = Curl_memdup0(ptr, pflen); if(!p) return CURLE_OUT_OF_MEMORY; else { - free(s->str[STRING_COPYPOSTFIELDS]); + curlx_free(s->str[STRING_COPYPOSTFIELDS]); s->str[STRING_COPYPOSTFIELDS] = p; } } @@ -1726,7 +1710,7 @@ static CURLcode setopt_cptr(struct Curl_easy *data, CURLoption option, Curl_safefree(s->str[STRING_COPYPOSTFIELDS]); s->method = HTTPREQ_POST; break; -#endif /* ! CURL_DISABLE_HTTP || ! CURL_DISABLE_MQTT */ +#endif /* !CURL_DISABLE_HTTP || !CURL_DISABLE_MQTT */ #ifndef CURL_DISABLE_HTTP case CURLOPT_ACCEPT_ENCODING: @@ -1740,9 +1724,14 @@ static CURLcode setopt_cptr(struct Curl_easy *data, CURLoption option, * */ if(ptr && !*ptr) { - char all[256]; - Curl_all_content_encodings(all, sizeof(all)); - return Curl_setstropt(&s->str[STRING_ENCODING], all); + ptr = Curl_get_content_encodings(); + if(ptr) { + curlx_free(s->str[STRING_ENCODING]); + s->str[STRING_ENCODING] = ptr; + } + else + result = CURLE_OUT_OF_MEMORY; + return result; } return Curl_setstropt(&s->str[STRING_ENCODING], ptr); @@ -1764,12 +1753,8 @@ static CURLcode setopt_cptr(struct Curl_easy *data, CURLoption option, /* * String to set in the HTTP Referer: field. */ - if(data->state.referer_alloc) { - Curl_safefree(data->state.referer); - data->state.referer_alloc = FALSE; - } result = Curl_setstropt(&s->str[STRING_SET_REFERER], ptr); - data->state.referer = s->str[STRING_SET_REFERER]; + Curl_bufref_set(&data->state.referer, s->str[STRING_SET_REFERER], 0, NULL); break; case CURLOPT_USERAGENT: @@ -1798,11 +1783,12 @@ static CURLcode setopt_cptr(struct Curl_easy *data, CURLoption option, * Activate the cookie parser. This may or may not already * have been made. */ - struct CookieInfo *newcookies = - Curl_cookie_init(data, NULL, data->cookies, s->cookiesession); - if(!newcookies) + if(!data->cookies) + data->cookies = Curl_cookie_init(); + if(!data->cookies) result = CURLE_OUT_OF_MEMORY; - data->cookies = newcookies; + else + data->state.cookie_engine = TRUE; } break; @@ -1810,7 +1796,7 @@ static CURLcode setopt_cptr(struct Curl_easy *data, CURLoption option, return cookielist(data, ptr); #endif /* !CURL_DISABLE_COOKIES */ -#endif /* ! CURL_DISABLE_HTTP */ +#endif /* !CURL_DISABLE_HTTP */ case CURLOPT_CUSTOMREQUEST: /* @@ -1845,7 +1831,7 @@ static CURLcode setopt_cptr(struct Curl_easy *data, CURLoption option, * to use the socks proxy. */ return Curl_setstropt(&s->str[STRING_PRE_PROXY], ptr); -#endif /* CURL_DISABLE_PROXY */ +#endif /* CURL_DISABLE_PROXY */ #ifndef CURL_DISABLE_PROXY case CURLOPT_SOCKS5_GSSAPI_SERVICE: @@ -1981,12 +1967,8 @@ static CURLcode setopt_cptr(struct Curl_easy *data, CURLoption option, /* * The URL to fetch. */ - if(data->state.url_alloc) { - Curl_safefree(data->state.url); - data->state.url_alloc = FALSE; - } result = Curl_setstropt(&s->str[STRING_SET_URL], ptr); - data->state.url = s->str[STRING_SET_URL]; + Curl_bufref_set(&data->state.url, s->str[STRING_SET_URL], 0, NULL); break; case CURLOPT_USERPWD: @@ -2040,10 +2022,10 @@ static CURLcode setopt_cptr(struct Curl_easy *data, CURLoption option, result = Curl_urldecode(p, 0, &s->str[STRING_PROXYPASSWORD], NULL, REJECT_ZERO); } - free(u); - free(p); - } + curlx_free(u); + curlx_free(p); break; + } case CURLOPT_PROXYUSERNAME: /* * authentication username to use in the operation @@ -2061,7 +2043,7 @@ static CURLcode setopt_cptr(struct Curl_easy *data, CURLoption option, * proxy exception list */ return Curl_setstropt(&s->str[STRING_NOPROXY], ptr); -#endif /* ! CURL_DISABLE_PROXY */ +#endif /* !CURL_DISABLE_PROXY */ case CURLOPT_RANGE: /* @@ -2073,12 +2055,7 @@ static CURLcode setopt_cptr(struct Curl_easy *data, CURLoption option, /* * pass CURLU to set URL */ - if(data->state.url_alloc) { - Curl_safefree(data->state.url); - data->state.url_alloc = FALSE; - } - else - data->state.url = NULL; + Curl_bufref_free(&data->state.url); Curl_safefree(s->str[STRING_SET_URL]); s->uh = (CURLU *)ptr; break; @@ -2170,8 +2147,9 @@ static CURLcode setopt_cptr(struct Curl_easy *data, CURLoption option, * Set the client IP to send through HAProxy PROXY protocol */ result = Curl_setstropt(&s->str[STRING_HAPROXY_CLIENT_IP], ptr); - /* enable the HAProxy protocol */ - s->haproxyprotocol = TRUE; + + /* enable the HAProxy protocol if an IP is provided */ + s->haproxyprotocol = !!s->str[STRING_HAPROXY_CLIENT_IP]; break; #endif @@ -2204,8 +2182,7 @@ static CURLcode setopt_cptr(struct Curl_easy *data, CURLoption option, */ #ifdef USE_SSL if(Curl_ssl_supports(data, SSLSUPP_PINNEDPUBKEY)) - return Curl_setstropt(&s->str[STRING_SSL_PINNEDPUBLICKEY_PROXY], - ptr); + return Curl_setstropt(&s->str[STRING_SSL_PINNEDPUBLICKEY_PROXY], ptr); #endif return CURLE_NOT_BUILT_IN; #endif @@ -2307,8 +2284,7 @@ static CURLcode setopt_cptr(struct Curl_easy *data, CURLoption option, * Specify colon-delimited list of signature scheme names. */ if(Curl_ssl_supports(data, SSLSUPP_SIGNATURE_ALGORITHMS)) - return Curl_setstropt(&s->str[STRING_SSL_SIGNATURE_ALGORITHMS], - ptr); + return Curl_setstropt(&s->str[STRING_SSL_SIGNATURE_ALGORITHMS], ptr); return CURLE_NOT_BUILT_IN; #endif #ifdef USE_SSH @@ -2350,8 +2326,7 @@ static CURLcode setopt_cptr(struct Curl_easy *data, CURLoption option, * Option to allow for the SHA256 of the host public key to be checked * for validation purposes. */ - return Curl_setstropt(&s->str[STRING_SSH_HOST_PUBLIC_KEY_SHA256], - ptr); + return Curl_setstropt(&s->str[STRING_SSH_HOST_PUBLIC_KEY_SHA256], ptr); case CURLOPT_SSH_HOSTKEYDATA: /* @@ -2362,17 +2337,27 @@ static CURLcode setopt_cptr(struct Curl_easy *data, CURLoption option, #endif /* USE_LIBSSH2 */ #endif /* USE_SSH */ case CURLOPT_PROTOCOLS_STR: - if(ptr) - return protocol2num(ptr, &s->allowed_protocols); - /* make a NULL argument reset to default */ - s->allowed_protocols = (curl_prot_t) CURLPROTO_ALL; + if(ptr) { + curl_prot_t protos; + result = protocol2num(ptr, &protos); + if(!result) + s->allowed_protocols = protos; + } + else + /* make a NULL argument reset to default */ + s->allowed_protocols = (curl_prot_t)CURLPROTO_ALL; break; case CURLOPT_REDIR_PROTOCOLS_STR: - if(ptr) - return protocol2num(ptr, &s->redir_protocols); - /* make a NULL argument reset to default */ - s->redir_protocols = (curl_prot_t) CURLPROTO_REDIR; + if(ptr) { + curl_prot_t protos; + result = protocol2num(ptr, &protos); + if(!result) + s->redir_protocols = protos; + } + else + /* make a NULL argument reset to default */ + s->redir_protocols = (curl_prot_t)CURLPROTO_REDIR; break; case CURLOPT_DEFAULT_PROTOCOL: @@ -2416,7 +2401,7 @@ static CURLcode setopt_cptr(struct Curl_easy *data, CURLoption option, case CURLOPT_INTERLEAVEDATA: s->rtp_out = ptr; break; -#endif /* ! CURL_DISABLE_RTSP */ +#endif /* !CURL_DISABLE_RTSP */ #ifndef CURL_DISABLE_FTP case CURLOPT_CHUNK_DATA: s->wildcardptr = ptr; @@ -2534,7 +2519,7 @@ static CURLcode setopt_cptr(struct Curl_easy *data, CURLoption option, } break; } -#endif /* ! CURL_DISABLE_HSTS */ +#endif /* !CURL_DISABLE_HSTS */ #ifndef CURL_DISABLE_ALTSVC case CURLOPT_ALTSVC: if(!data->asi) { @@ -2546,9 +2531,9 @@ static CURLcode setopt_cptr(struct Curl_easy *data, CURLoption option, if(result) return result; if(ptr) - (void)Curl_altsvc_load(data->asi, ptr); + return Curl_altsvc_load(data->asi, ptr); break; -#endif /* ! CURL_DISABLE_ALTSVC */ +#endif /* !CURL_DISABLE_ALTSVC */ #ifdef USE_ECH case CURLOPT_ECH: { size_t plen = 0; @@ -2564,17 +2549,13 @@ static CURLcode setopt_cptr(struct Curl_easy *data, CURLoption option, } /* set tls_ech flag value, preserving CLA_CFG bit */ if(!strcmp(ptr, "false")) - s->tls_ech = CURLECH_DISABLE | - (s->tls_ech & CURLECH_CLA_CFG); + s->tls_ech = (s->tls_ech & CURLECH_CLA_CFG) | CURLECH_DISABLE; else if(!strcmp(ptr, "grease")) - s->tls_ech = CURLECH_GREASE | - (s->tls_ech & CURLECH_CLA_CFG); + s->tls_ech = (s->tls_ech & CURLECH_CLA_CFG) | CURLECH_GREASE; else if(!strcmp(ptr, "true")) - s->tls_ech = CURLECH_ENABLE | - (s->tls_ech & CURLECH_CLA_CFG); + s->tls_ech = (s->tls_ech & CURLECH_CLA_CFG) | CURLECH_ENABLE; else if(!strcmp(ptr, "hard")) - s->tls_ech = CURLECH_HARD | - (s->tls_ech & CURLECH_CLA_CFG); + s->tls_ech = (s->tls_ech & CURLECH_CLA_CFG) | CURLECH_HARD; else if(plen > 5 && !strncmp(ptr, "ecl:", 4)) { result = Curl_setstropt(&s->str[STRING_ECH_CONFIG], ptr + 4); if(result) @@ -2831,6 +2812,8 @@ static CURLcode setopt_offt(struct Curl_easy *data, CURLoption option, if(offt < 0) return CURLE_BAD_FUNCTION_ARGUMENT; s->max_send_speed = offt; + Curl_rlimit_init(&data->progress.ul.rlimit, offt, offt, + Curl_pgrs_now(data)); break; case CURLOPT_MAX_RECV_SPEED_LARGE: /* @@ -2840,6 +2823,8 @@ static CURLcode setopt_offt(struct Curl_easy *data, CURLoption option, if(offt < 0) return CURLE_BAD_FUNCTION_ARGUMENT; s->max_recv_speed = offt; + Curl_rlimit_init(&data->progress.dl.rlimit, offt, offt, + Curl_pgrs_now(data)); break; case CURLOPT_RESUME_FROM_LARGE: /* @@ -2899,8 +2884,7 @@ static CURLcode setopt_blob(struct Curl_easy *data, CURLoption option, /* * Blob that holds Issuer certificate to check certificates issuer */ - return Curl_setblobopt(&s->blobs[BLOB_SSL_ISSUERCERT_PROXY], - blob); + return Curl_setblobopt(&s->blobs[BLOB_SSL_ISSUERCERT_PROXY], blob); #endif case CURLOPT_SSLKEY_BLOB: /* diff --git a/vendor/hydra/vendor/curl/lib/setopt.h b/vendor/hydra/vendor/curl/lib/setopt.h index c323dd74..0dd60c78 100644 --- a/vendor/hydra/vendor/curl/lib/setopt.h +++ b/vendor/hydra/vendor/curl/lib/setopt.h @@ -28,7 +28,7 @@ CURLcode Curl_setopt_SSLVERSION(struct Curl_easy *data, CURLoption option, long arg); #else -#define Curl_setopt_SSLVERSION(a,b,c) CURLE_NOT_BUILT_IN +#define Curl_setopt_SSLVERSION(a, b, c) CURLE_NOT_BUILT_IN #endif CURLcode Curl_setstropt(char **charp, const char *s) WARN_UNUSED_RESULT; diff --git a/vendor/hydra/vendor/curl/lib/setup-os400.h b/vendor/hydra/vendor/curl/lib/setup-os400.h index ef7baca6..4cb0d89c 100644 --- a/vendor/hydra/vendor/curl/lib/setup-os400.h +++ b/vendor/hydra/vendor/curl/lib/setup-os400.h @@ -24,7 +24,6 @@ * ***************************************************************************/ - /* OS/400 netdb.h does not define NI_MAXHOST. */ #define NI_MAXHOST 1025 @@ -37,15 +36,13 @@ typedef unsigned long u_int32_t; /* OS/400 has no idea of a tty! */ #define isatty(fd) 0 - /* Workaround bug in IBM QADRT runtime library: * function puts() does not output the implicit trailing newline. */ #include /* Be sure it is loaded. */ #undef puts -#define puts(s) (fputs((s), stdout) == EOF? EOF: putchar('\n')) - +#define puts(s) (fputs((s), stdout) == EOF ? EOF : putchar('\n')) /* System API wrapper prototypes & definitions to support ASCII parameters. */ @@ -79,7 +76,6 @@ extern OM_uint32 Curl_gss_import_name_a(OM_uint32 * minor_status, gss_name_t * out_name); #define gss_import_name Curl_gss_import_name_a - extern OM_uint32 Curl_gss_display_status_a(OM_uint32 * minor_status, OM_uint32 status_value, int status_type, gss_OID mech_type, @@ -87,7 +83,6 @@ extern OM_uint32 Curl_gss_display_status_a(OM_uint32 * minor_status, gss_buffer_t status_string); #define gss_display_status Curl_gss_display_status_a - extern OM_uint32 Curl_gss_init_sec_context_a(OM_uint32 * minor_status, gss_cred_id_t cred_handle, gss_ctx_id_t * context_handle, @@ -104,13 +99,11 @@ extern OM_uint32 Curl_gss_init_sec_context_a(OM_uint32 * minor_status, OM_uint32 * time_rec); #define gss_init_sec_context Curl_gss_init_sec_context_a - -extern OM_uint32 Curl_gss_delete_sec_context_a(OM_uint32 * minor_status, - gss_ctx_id_t * context_handle, +extern OM_uint32 Curl_gss_delete_sec_context_a(OM_uint32 *minor_status, + gss_ctx_id_t *context_handle, gss_buffer_t output_token); #define gss_delete_sec_context Curl_gss_delete_sec_context_a - /* LDAP wrappers. */ #define BerValue struct berval diff --git a/vendor/hydra/vendor/curl/lib/setup-vms.h b/vendor/hydra/vendor/curl/lib/setup-vms.h index e3777ded..dd460223 100644 --- a/vendor/hydra/vendor/curl/lib/setup-vms.h +++ b/vendor/hydra/vendor/curl/lib/setup-vms.h @@ -38,9 +38,9 @@ /* Hide the stuff we are overriding */ #define getenv decc_getenv #ifdef __DECC -# if __INITIAL_POINTER_SIZE != 64 -# define getpwuid decc_getpwuid -# endif +# if __INITIAL_POINTER_SIZE != 64 +# define getpwuid decc_getpwuid +# endif #endif #include char *decc$getenv(const char *__name); @@ -51,34 +51,34 @@ char *decc$getenv(const char *__name); #undef getenv #undef getpwuid -#define getenv vms_getenv +#define getenv vms_getenv #define getpwuid vms_getpwuid /* VAX needs these in upper case when compiling exact case */ #define sys$assign SYS$ASSIGN #define sys$dassgn SYS$DASSGN -#define sys$qiow SYS$QIOW +#define sys$qiow SYS$QIOW #ifdef __DECC -# if __INITIAL_POINTER_SIZE -# pragma __pointer_size __save -# endif +# if __INITIAL_POINTER_SIZE +# pragma __pointer_size __save +# endif #endif #if __USE_LONG_GID_T -# define decc_getpwuid DECC$__LONG_GID_GETPWUID +# define decc_getpwuid DECC$__LONG_GID_GETPWUID #else -# if __INITIAL_POINTER_SIZE -# define decc_getpwuid decc$__32_getpwuid -# else -# define decc_getpwuid decc$getpwuid -# endif +# if __INITIAL_POINTER_SIZE +# define decc_getpwuid decc$__32_getpwuid +# else +# define decc_getpwuid decc$getpwuid +# endif #endif - struct passwd *decc_getpwuid(uid_t uid); +struct passwd *decc_getpwuid(uid_t uid); #ifdef __DECC -# if __INITIAL_POINTER_SIZE == 32 +# if __INITIAL_POINTER_SIZE == 32 /* Translate the path, but only if the path is a VMS file specification */ /* The translation is usually only needed for older versions of VMS */ static char *vms_translate_path(const char *path) @@ -100,18 +100,18 @@ static char *vms_translate_path(const char *path) return (char *)path; } } -# else - /* VMS translate path is actually not needed on the current 64-bit */ - /* VMS platforms, so instead of figuring out the pointer settings */ - /* Change it to a noop */ -# define vms_translate_path(__path) __path -# endif +# else + /* VMS translate path is actually not needed on the current 64-bit */ + /* VMS platforms, so instead of figuring out the pointer settings */ + /* Change it to a noop */ +# define vms_translate_path(__path) __path +# endif #endif #ifdef __DECC -# if __INITIAL_POINTER_SIZE -# pragma __pointer_size __restore -# endif +# if __INITIAL_POINTER_SIZE +# pragma __pointer_size __restore +# endif #endif static char *vms_getenv(const char *envvar) @@ -137,7 +137,6 @@ static char *vms_getenv(const char *envvar) return result; } - static struct passwd vms_passwd_cache; static struct passwd *vms_getpwuid(uid_t uid) @@ -146,11 +145,11 @@ static struct passwd *vms_getpwuid(uid_t uid) /* Hack needed to support 64-bit builds, decc_getpwnam is 32-bit only */ #ifdef __DECC -# if __INITIAL_POINTER_SIZE +# if __INITIAL_POINTER_SIZE __char_ptr32 unix_path; -# else +# else char *unix_path; -# endif +# endif #else char *unix_path; #endif @@ -191,181 +190,178 @@ static struct passwd *vms_getpwuid(uid_t uid) /* Bug - VMS OpenSSL and Kerberos universal symbols are in uppercase only */ /* VMS libraries should have universal symbols in exact and uppercase */ -#define ASN1_INTEGER_get ASN1_INTEGER_GET -#define ASN1_STRING_data ASN1_STRING_DATA -#define ASN1_STRING_length ASN1_STRING_LENGTH -#define ASN1_STRING_print ASN1_STRING_PRINT -#define ASN1_STRING_to_UTF8 ASN1_STRING_TO_UTF8 -#define ASN1_STRING_type ASN1_STRING_TYPE -#define BIO_ctrl BIO_CTRL -#define BIO_free BIO_FREE -#define BIO_new BIO_NEW -#define BIO_s_mem BIO_S_MEM -#define BN_bn2bin BN_BN2BIN -#define BN_num_bits BN_NUM_BITS +#define ASN1_INTEGER_get ASN1_INTEGER_GET +#define ASN1_STRING_data ASN1_STRING_DATA +#define ASN1_STRING_length ASN1_STRING_LENGTH +#define ASN1_STRING_print ASN1_STRING_PRINT +#define ASN1_STRING_to_UTF8 ASN1_STRING_TO_UTF8 +#define ASN1_STRING_type ASN1_STRING_TYPE +#define BIO_ctrl BIO_CTRL +#define BIO_free BIO_FREE +#define BIO_new BIO_NEW +#define BIO_s_mem BIO_S_MEM +#define BN_bn2bin BN_BN2BIN +#define BN_num_bits BN_NUM_BITS #define CRYPTO_cleanup_all_ex_data CRYPTO_CLEANUP_ALL_EX_DATA -#define CRYPTO_free CRYPTO_FREE -#define CRYPTO_malloc CRYPTO_MALLOC -#define CONF_modules_load_file CONF_MODULES_LOAD_FILE +#define CRYPTO_free CRYPTO_FREE +#define CRYPTO_malloc CRYPTO_MALLOC +#define CONF_modules_load_file CONF_MODULES_LOAD_FILE #ifdef __VAX # ifdef VMS_OLD_SSL /* Ancient OpenSSL on VAX/VMS missing this constant */ # define CONF_MFLAGS_IGNORE_MISSING_FILE 0x10 # undef CONF_modules_load_file - static int CONF_modules_load_file(const char *filename, - const char *appname, - unsigned long flags) { - return 1; - } +static int CONF_modules_load_file(const char *filename, + const char *appname, + unsigned long flags) { + return 1; +} # endif #endif -#define DES_ecb_encrypt DES_ECB_ENCRYPT -#define DES_set_key DES_SET_KEY -#define DES_set_odd_parity DES_SET_ODD_PARITY -#define ENGINE_ctrl ENGINE_CTRL -#define ENGINE_ctrl_cmd ENGINE_CTRL_CMD -#define ENGINE_finish ENGINE_FINISH -#define ENGINE_free ENGINE_FREE -#define ENGINE_get_first ENGINE_GET_FIRST -#define ENGINE_get_id ENGINE_GET_ID -#define ENGINE_get_next ENGINE_GET_NEXT -#define ENGINE_init ENGINE_INIT +#define DES_ecb_encrypt DES_ECB_ENCRYPT +#define DES_set_key DES_SET_KEY +#define DES_set_odd_parity DES_SET_ODD_PARITY +#define ENGINE_ctrl ENGINE_CTRL +#define ENGINE_ctrl_cmd ENGINE_CTRL_CMD +#define ENGINE_finish ENGINE_FINISH +#define ENGINE_free ENGINE_FREE +#define ENGINE_get_first ENGINE_GET_FIRST +#define ENGINE_get_id ENGINE_GET_ID +#define ENGINE_get_next ENGINE_GET_NEXT +#define ENGINE_init ENGINE_INIT #define ENGINE_load_builtin_engines ENGINE_LOAD_BUILTIN_ENGINES -#define ENGINE_load_private_key ENGINE_LOAD_PRIVATE_KEY -#define ENGINE_set_default ENGINE_SET_DEFAULT -#define ERR_clear_error ERR_CLEAR_ERROR -#define ERR_error_string ERR_ERROR_STRING -#define ERR_error_string_n ERR_ERROR_STRING_N -#define ERR_free_strings ERR_FREE_STRINGS -#define ERR_get_error ERR_GET_ERROR -#define ERR_peek_error ERR_PEEK_ERROR -#define ERR_remove_state ERR_REMOVE_STATE -#define EVP_PKEY_copy_parameters EVP_PKEY_COPY_PARAMETERS -#define EVP_PKEY_free EVP_PKEY_FREE -#define EVP_cleanup EVP_CLEANUP -#define GENERAL_NAMES_free GENERAL_NAMES_FREE -#define i2d_X509_PUBKEY I2D_X509_PUBKEY -#define MD4_Final MD4_FINAL -#define MD4_Init MD4_INIT -#define MD4_Update MD4_UPDATE -#define MD5_Final MD5_FINAL -#define MD5_Init MD5_INIT -#define MD5_Update MD5_UPDATE +#define ENGINE_load_private_key ENGINE_LOAD_PRIVATE_KEY +#define ENGINE_set_default ENGINE_SET_DEFAULT +#define ERR_clear_error ERR_CLEAR_ERROR +#define ERR_error_string ERR_ERROR_STRING +#define ERR_error_string_n ERR_ERROR_STRING_N +#define ERR_free_strings ERR_FREE_STRINGS +#define ERR_get_error ERR_GET_ERROR +#define ERR_peek_error ERR_PEEK_ERROR +#define ERR_remove_state ERR_REMOVE_STATE +#define EVP_PKEY_copy_parameters EVP_PKEY_COPY_PARAMETERS +#define EVP_PKEY_free EVP_PKEY_FREE +#define EVP_cleanup EVP_CLEANUP +#define GENERAL_NAMES_free GENERAL_NAMES_FREE +#define i2d_X509_PUBKEY I2D_X509_PUBKEY +#define MD4_Final MD4_FINAL +#define MD4_Init MD4_INIT +#define MD4_Update MD4_UPDATE +#define MD5_Final MD5_FINAL +#define MD5_Init MD5_INIT +#define MD5_Update MD5_UPDATE #define OPENSSL_add_all_algo_noconf OPENSSL_ADD_ALL_ALGO_NOCONF #ifndef __VAX #define OPENSSL_load_builtin_modules OPENSSL_LOAD_BUILTIN_MODULES #endif -#define PEM_read_X509 PEM_READ_X509 -#define PEM_write_bio_X509 PEM_WRITE_BIO_X509 -#define PKCS12_free PKCS12_FREE -#define PKCS12_parse PKCS12_PARSE -#define RAND_add RAND_ADD -#define RAND_bytes RAND_BYTES -#define RAND_file_name RAND_FILE_NAME -#define RAND_load_file RAND_LOAD_FILE -#define RAND_status RAND_STATUS -#define SSL_CIPHER_get_name SSL_CIPHER_GET_NAME -#define SSL_CTX_add_client_CA SSL_CTX_ADD_CLIENT_CA -#define SSL_CTX_callback_ctrl SSL_CTX_CALLBACK_CTRL -#define SSL_CTX_check_private_key SSL_CTX_CHECK_PRIVATE_KEY -#define SSL_CTX_ctrl SSL_CTX_CTRL -#define SSL_CTX_free SSL_CTX_FREE -#define SSL_CTX_get_cert_store SSL_CTX_GET_CERT_STORE -#define SSL_CTX_load_verify_locations SSL_CTX_LOAD_VERIFY_LOCATIONS -#define SSL_CTX_new SSL_CTX_NEW -#define SSL_CTX_set_cipher_list SSL_CTX_SET_CIPHER_LIST -#define SSL_CTX_set_def_passwd_cb_ud SSL_CTX_SET_DEF_PASSWD_CB_UD -#define SSL_CTX_set_default_passwd_cb SSL_CTX_SET_DEFAULT_PASSWD_CB -#define SSL_CTX_set_msg_callback SSL_CTX_SET_MSG_CALLBACK -#define SSL_CTX_set_verify SSL_CTX_SET_VERIFY -#define SSL_CTX_use_PrivateKey SSL_CTX_USE_PRIVATEKEY -#define SSL_CTX_use_PrivateKey_file SSL_CTX_USE_PRIVATEKEY_FILE -#define SSL_CTX_use_cert_chain_file SSL_CTX_USE_CERT_CHAIN_FILE -#define SSL_CTX_use_certificate SSL_CTX_USE_CERTIFICATE -#define SSL_CTX_use_certificate_file SSL_CTX_USE_CERTIFICATE_FILE -#define SSL_SESSION_free SSL_SESSION_FREE -#define SSL_connect SSL_CONNECT -#define SSL_free SSL_FREE -#define SSL_get1_session SSL_GET1_SESSION -#define SSL_get_certificate SSL_GET_CERTIFICATE -#define SSL_get_current_cipher SSL_GET_CURRENT_CIPHER -#define SSL_get_error SSL_GET_ERROR -#define SSL_get_peer_cert_chain SSL_GET_PEER_CERT_CHAIN -#define SSL_get_peer_certificate SSL_GET_PEER_CERTIFICATE -#define SSL_get_privatekey SSL_GET_PRIVATEKEY -#define SSL_get_session SSL_GET_SESSION -#define SSL_get_shutdown SSL_GET_SHUTDOWN -#define SSL_get_verify_result SSL_GET_VERIFY_RESULT -#define SSL_library_init SSL_LIBRARY_INIT -#define SSL_load_error_strings SSL_LOAD_ERROR_STRINGS -#define SSL_new SSL_NEW -#define SSL_peek SSL_PEEK -#define SSL_pending SSL_PENDING -#define SSL_read SSL_READ -#define SSL_set_connect_state SSL_SET_CONNECT_STATE -#define SSL_set_fd SSL_SET_FD -#define SSL_set_session SSL_SET_SESSION -#define SSL_shutdown SSL_SHUTDOWN -#define SSL_version SSL_VERSION -#define SSL_write SSL_WRITE -#define SSLeay SSLEAY -#define SSLv23_client_method SSLV23_CLIENT_METHOD -#define SSLv3_client_method SSLV3_CLIENT_METHOD -#define TLSv1_client_method TLSV1_CLIENT_METHOD -#define UI_create_method UI_CREATE_METHOD -#define UI_destroy_method UI_DESTROY_METHOD -#define UI_get0_user_data UI_GET0_USER_DATA -#define UI_get_input_flags UI_GET_INPUT_FLAGS -#define UI_get_string_type UI_GET_STRING_TYPE -#define UI_create_method UI_CREATE_METHOD -#define UI_destroy_method UI_DESTROY_METHOD -#define UI_method_get_closer UI_METHOD_GET_CLOSER -#define UI_method_get_opener UI_METHOD_GET_OPENER -#define UI_method_get_reader UI_METHOD_GET_READER -#define UI_method_get_writer UI_METHOD_GET_WRITER -#define UI_method_set_closer UI_METHOD_SET_CLOSER -#define UI_method_set_opener UI_METHOD_SET_OPENER -#define UI_method_set_reader UI_METHOD_SET_READER -#define UI_method_set_writer UI_METHOD_SET_WRITER -#define UI_OpenSSL UI_OPENSSL -#define UI_set_result UI_SET_RESULT -#define X509V3_EXT_print X509V3_EXT_PRINT -#define X509_EXTENSION_get_critical X509_EXTENSION_GET_CRITICAL -#define X509_EXTENSION_get_data X509_EXTENSION_GET_DATA -#define X509_EXTENSION_get_object X509_EXTENSION_GET_OBJECT -#define X509_LOOKUP_file X509_LOOKUP_FILE -#define X509_NAME_ENTRY_get_data X509_NAME_ENTRY_GET_DATA -#define X509_NAME_get_entry X509_NAME_GET_ENTRY -#define X509_NAME_get_index_by_NID X509_NAME_GET_INDEX_BY_NID -#define X509_NAME_print_ex X509_NAME_PRINT_EX +#define PEM_read_X509 PEM_READ_X509 +#define PEM_write_bio_X509 PEM_WRITE_BIO_X509 +#define PKCS12_free PKCS12_FREE +#define PKCS12_parse PKCS12_PARSE +#define RAND_add RAND_ADD +#define RAND_bytes RAND_BYTES +#define RAND_file_name RAND_FILE_NAME +#define RAND_load_file RAND_LOAD_FILE +#define RAND_status RAND_STATUS +#define SSL_CIPHER_get_name SSL_CIPHER_GET_NAME +#define SSL_CTX_add_client_CA SSL_CTX_ADD_CLIENT_CA +#define SSL_CTX_callback_ctrl SSL_CTX_CALLBACK_CTRL +#define SSL_CTX_check_private_key SSL_CTX_CHECK_PRIVATE_KEY +#define SSL_CTX_ctrl SSL_CTX_CTRL +#define SSL_CTX_free SSL_CTX_FREE +#define SSL_CTX_get_cert_store SSL_CTX_GET_CERT_STORE +#define SSL_CTX_load_verify_locations SSL_CTX_LOAD_VERIFY_LOCATIONS +#define SSL_CTX_new SSL_CTX_NEW +#define SSL_CTX_set_cipher_list SSL_CTX_SET_CIPHER_LIST +#define SSL_CTX_set_def_passwd_cb_ud SSL_CTX_SET_DEF_PASSWD_CB_UD +#define SSL_CTX_set_default_passwd_cb SSL_CTX_SET_DEFAULT_PASSWD_CB +#define SSL_CTX_set_msg_callback SSL_CTX_SET_MSG_CALLBACK +#define SSL_CTX_set_verify SSL_CTX_SET_VERIFY +#define SSL_CTX_use_PrivateKey SSL_CTX_USE_PRIVATEKEY +#define SSL_CTX_use_PrivateKey_file SSL_CTX_USE_PRIVATEKEY_FILE +#define SSL_CTX_use_cert_chain_file SSL_CTX_USE_CERT_CHAIN_FILE +#define SSL_CTX_use_certificate SSL_CTX_USE_CERTIFICATE +#define SSL_CTX_use_certificate_file SSL_CTX_USE_CERTIFICATE_FILE +#define SSL_SESSION_free SSL_SESSION_FREE +#define SSL_connect SSL_CONNECT +#define SSL_free SSL_FREE +#define SSL_get1_session SSL_GET1_SESSION +#define SSL_get_certificate SSL_GET_CERTIFICATE +#define SSL_get_current_cipher SSL_GET_CURRENT_CIPHER +#define SSL_get_error SSL_GET_ERROR +#define SSL_get_peer_cert_chain SSL_GET_PEER_CERT_CHAIN +#define SSL_get_peer_certificate SSL_GET_PEER_CERTIFICATE +#define SSL_get_privatekey SSL_GET_PRIVATEKEY +#define SSL_get_session SSL_GET_SESSION +#define SSL_get_shutdown SSL_GET_SHUTDOWN +#define SSL_get_verify_result SSL_GET_VERIFY_RESULT +#define SSL_library_init SSL_LIBRARY_INIT +#define SSL_load_error_strings SSL_LOAD_ERROR_STRINGS +#define SSL_new SSL_NEW +#define SSL_peek SSL_PEEK +#define SSL_pending SSL_PENDING +#define SSL_read SSL_READ +#define SSL_set_connect_state SSL_SET_CONNECT_STATE +#define SSL_set_fd SSL_SET_FD +#define SSL_set_session SSL_SET_SESSION +#define SSL_shutdown SSL_SHUTDOWN +#define SSL_version SSL_VERSION +#define SSL_write SSL_WRITE +#define SSLeay SSLEAY +#define SSLv23_client_method SSLV23_CLIENT_METHOD +#define SSLv3_client_method SSLV3_CLIENT_METHOD +#define TLSv1_client_method TLSV1_CLIENT_METHOD +#define UI_create_method UI_CREATE_METHOD +#define UI_destroy_method UI_DESTROY_METHOD +#define UI_get0_user_data UI_GET0_USER_DATA +#define UI_get_input_flags UI_GET_INPUT_FLAGS +#define UI_get_string_type UI_GET_STRING_TYPE +#define UI_create_method UI_CREATE_METHOD +#define UI_destroy_method UI_DESTROY_METHOD +#define UI_method_get_closer UI_METHOD_GET_CLOSER +#define UI_method_get_opener UI_METHOD_GET_OPENER +#define UI_method_get_reader UI_METHOD_GET_READER +#define UI_method_get_writer UI_METHOD_GET_WRITER +#define UI_method_set_closer UI_METHOD_SET_CLOSER +#define UI_method_set_opener UI_METHOD_SET_OPENER +#define UI_method_set_reader UI_METHOD_SET_READER +#define UI_method_set_writer UI_METHOD_SET_WRITER +#define UI_OpenSSL UI_OPENSSL +#define UI_set_result UI_SET_RESULT +#define X509V3_EXT_print X509V3_EXT_PRINT +#define X509_EXTENSION_get_critical X509_EXTENSION_GET_CRITICAL +#define X509_EXTENSION_get_data X509_EXTENSION_GET_DATA +#define X509_EXTENSION_get_object X509_EXTENSION_GET_OBJECT +#define X509_LOOKUP_file X509_LOOKUP_FILE +#define X509_NAME_ENTRY_get_data X509_NAME_ENTRY_GET_DATA +#define X509_NAME_get_entry X509_NAME_GET_ENTRY +#define X509_NAME_get_index_by_NID X509_NAME_GET_INDEX_BY_NID +#define X509_NAME_print_ex X509_NAME_PRINT_EX #define X509_STORE_CTX_get_current_cert X509_STORE_CTX_GET_CURRENT_CERT -#define X509_STORE_add_lookup X509_STORE_ADD_LOOKUP -#define X509_STORE_set_flags X509_STORE_SET_FLAGS -#define X509_check_issued X509_CHECK_ISSUED -#define X509_free X509_FREE -#define X509_get_ext_d2i X509_GET_EXT_D2I -#define X509_get_issuer_name X509_GET_ISSUER_NAME -#define X509_get_pubkey X509_GET_PUBKEY -#define X509_get_serialNumber X509_GET_SERIALNUMBER -#define X509_get_subject_name X509_GET_SUBJECT_NAME -#define X509_load_crl_file X509_LOAD_CRL_FILE -#define X509_verify_cert_error_string X509_VERIFY_CERT_ERROR_STRING -#define d2i_PKCS12_fp D2I_PKCS12_FP -#define i2t_ASN1_OBJECT I2T_ASN1_OBJECT -#define sk_num SK_NUM -#define sk_pop SK_POP -#define sk_pop_free SK_POP_FREE -#define sk_value SK_VALUE -#ifdef __VAX -#define OPENSSL_NO_SHA256 -#endif -#define SHA256_Final SHA256_FINAL -#define SHA256_Init SHA256_INIT +#define X509_STORE_add_lookup X509_STORE_ADD_LOOKUP +#define X509_STORE_set_flags X509_STORE_SET_FLAGS +#define X509_check_issued X509_CHECK_ISSUED +#define X509_free X509_FREE +#define X509_get_ext_d2i X509_GET_EXT_D2I +#define X509_get_issuer_name X509_GET_ISSUER_NAME +#define X509_get_pubkey X509_GET_PUBKEY +#define X509_get_serialNumber X509_GET_SERIALNUMBER +#define X509_get_subject_name X509_GET_SUBJECT_NAME +#define X509_load_crl_file X509_LOAD_CRL_FILE +#define X509_verify_cert_error_string X509_VERIFY_CERT_ERROR_STRING +#define d2i_PKCS12_fp D2I_PKCS12_FP +#define i2t_ASN1_OBJECT I2T_ASN1_OBJECT +#define sk_num SK_NUM +#define sk_pop SK_POP +#define sk_pop_free SK_POP_FREE +#define sk_value SK_VALUE +#define SHA256_Final SHA256_FINAL +#define SHA256_Init SHA256_INIT #define SHA256_Update SHA256_UPDATE #define USE_UPPERCASE_GSSAPI 1 -#define gss_seal GSS_SEAL -#define gss_unseal GSS_UNSEAL +#define gss_seal GSS_SEAL +#define gss_unseal GSS_UNSEAL #define USE_UPPERCASE_KRBAPI 1 @@ -379,11 +375,11 @@ static struct passwd *vms_getpwuid(uid_t uid) /* VAX symbols are always in uppercase */ #ifdef __VAX -#define inflate INFLATE -#define inflateEnd INFLATEEND +#define inflate INFLATE +#define inflateEnd INFLATEEND #define inflateInit2_ INFLATEINIT2_ -#define inflateInit_ INFLATEINIT_ -#define zlibVersion ZLIBVERSION +#define inflateInit_ INFLATEINIT_ +#define zlibVersion ZLIBVERSION #endif /* Older VAX OpenSSL port defines these as Macros */ @@ -391,11 +387,11 @@ static struct passwd *vms_getpwuid(uid_t uid) /* that way a newer port will also work if some one has one */ #ifdef __VAX -# include -# ifndef OpenSSL_add_all_algorithms -# define OpenSSL_add_all_algorithms OPENSSL_ADD_ALL_ALGORITHMS - void OPENSSL_ADD_ALL_ALGORITHMS(void); -# endif +# include +# ifndef OpenSSL_add_all_algorithms +# define OpenSSL_add_all_algorithms OPENSSL_ADD_ALL_ALGORITHMS + void OPENSSL_ADD_ALL_ALGORITHMS(void); +# endif #endif #endif /* HEADER_CURL_SETUP_VMS_H */ diff --git a/vendor/hydra/vendor/curl/lib/sha256.c b/vendor/hydra/vendor/curl/lib/sha256.c index f7bb5456..7c3cad33 100644 --- a/vendor/hydra/vendor/curl/lib/sha256.c +++ b/vendor/hydra/vendor/curl/lib/sha256.c @@ -22,15 +22,12 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #if !defined(CURL_DISABLE_AWS) || !defined(CURL_DISABLE_DIGEST_AUTH) || \ defined(USE_LIBSSH2) || defined(USE_SSL) -#include "curlx/warnless.h" #include "curl_sha256.h" -#include "curl_hmac.h" #ifdef USE_MBEDTLS #include @@ -59,10 +56,6 @@ #include #endif -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* Please keep the SSL backend-specific #if branches in this order: * * 1. USE_OPENSSL @@ -197,7 +190,7 @@ static CURLcode my_sha256_init(void *in) { my_sha256_ctx *ctx = (my_sha256_ctx *)in; if(!CryptAcquireContext(&ctx->hCryptProv, NULL, NULL, PROV_RSA_AES, - CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) + CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) return CURLE_OUT_OF_MEMORY; if(!CryptCreateHash(ctx->hCryptProv, CALG_SHA_256, 0, 0, &ctx->hHash)) { @@ -214,11 +207,7 @@ static void my_sha256_update(void *in, unsigned int length) { my_sha256_ctx *ctx = (my_sha256_ctx *)in; -#ifdef __MINGW32CE__ - CryptHashData(ctx->hHash, (BYTE *)CURL_UNCONST(data), length, 0); -#else CryptHashData(ctx->hHash, (const BYTE *)data, length, 0); -#endif } static void my_sha256_final(unsigned char *digest, void *in) @@ -244,42 +233,43 @@ static void my_sha256_final(unsigned char *digest, void *in) /* This is based on the SHA256 implementation in LibTomCrypt that was released * into public domain. */ -#define WPA_GET_BE32(a) ((((unsigned long)(a)[0]) << 24) | \ - (((unsigned long)(a)[1]) << 16) | \ - (((unsigned long)(a)[2]) << 8) | \ - ((unsigned long)(a)[3])) -#define WPA_PUT_BE32(a, val) \ -do { \ - (a)[0] = (unsigned char)((((unsigned long) (val)) >> 24) & 0xff); \ - (a)[1] = (unsigned char)((((unsigned long) (val)) >> 16) & 0xff); \ - (a)[2] = (unsigned char)((((unsigned long) (val)) >> 8) & 0xff); \ - (a)[3] = (unsigned char)(((unsigned long) (val)) & 0xff); \ -} while(0) +#define WPA_GET_BE32(a) \ + ((((unsigned long)(a)[0]) << 24) | \ + (((unsigned long)(a)[1]) << 16) | \ + (((unsigned long)(a)[2]) << 8) | \ + ((unsigned long)(a)[3])) +#define WPA_PUT_BE32(a, val) \ + do { \ + (a)[0] = (unsigned char)((((unsigned long)(val)) >> 24) & 0xff); \ + (a)[1] = (unsigned char)((((unsigned long)(val)) >> 16) & 0xff); \ + (a)[2] = (unsigned char)((((unsigned long)(val)) >> 8) & 0xff); \ + (a)[3] = (unsigned char) (((unsigned long)(val)) & 0xff); \ + } while(0) #ifdef HAVE_LONGLONG -#define WPA_PUT_BE64(a, val) \ -do { \ - (a)[0] = (unsigned char)(((unsigned long long)(val)) >> 56); \ - (a)[1] = (unsigned char)(((unsigned long long)(val)) >> 48); \ - (a)[2] = (unsigned char)(((unsigned long long)(val)) >> 40); \ - (a)[3] = (unsigned char)(((unsigned long long)(val)) >> 32); \ - (a)[4] = (unsigned char)(((unsigned long long)(val)) >> 24); \ - (a)[5] = (unsigned char)(((unsigned long long)(val)) >> 16); \ - (a)[6] = (unsigned char)(((unsigned long long)(val)) >> 8); \ - (a)[7] = (unsigned char)(((unsigned long long)(val)) & 0xff); \ -} while(0) +#define WPA_PUT_BE64(a, val) \ + do { \ + (a)[0] = (unsigned char)(((unsigned long long)(val)) >> 56); \ + (a)[1] = (unsigned char)(((unsigned long long)(val)) >> 48); \ + (a)[2] = (unsigned char)(((unsigned long long)(val)) >> 40); \ + (a)[3] = (unsigned char)(((unsigned long long)(val)) >> 32); \ + (a)[4] = (unsigned char)(((unsigned long long)(val)) >> 24); \ + (a)[5] = (unsigned char)(((unsigned long long)(val)) >> 16); \ + (a)[6] = (unsigned char)(((unsigned long long)(val)) >> 8); \ + (a)[7] = (unsigned char)(((unsigned long long)(val)) & 0xff); \ + } while(0) #else -#define WPA_PUT_BE64(a, val) \ -do { \ - (a)[0] = (unsigned char)(((unsigned __int64)(val)) >> 56); \ - (a)[1] = (unsigned char)(((unsigned __int64)(val)) >> 48); \ - (a)[2] = (unsigned char)(((unsigned __int64)(val)) >> 40); \ - (a)[3] = (unsigned char)(((unsigned __int64)(val)) >> 32); \ - (a)[4] = (unsigned char)(((unsigned __int64)(val)) >> 24); \ - (a)[5] = (unsigned char)(((unsigned __int64)(val)) >> 16); \ - (a)[6] = (unsigned char)(((unsigned __int64)(val)) >> 8); \ - (a)[7] = (unsigned char)(((unsigned __int64)(val)) & 0xff); \ -} while(0) +#define WPA_PUT_BE64(a, val) \ + do { \ + (a)[0] = (unsigned char)(((unsigned __int64)(val)) >> 56); \ + (a)[1] = (unsigned char)(((unsigned __int64)(val)) >> 48); \ + (a)[2] = (unsigned char)(((unsigned __int64)(val)) >> 40); \ + (a)[3] = (unsigned char)(((unsigned __int64)(val)) >> 32); \ + (a)[4] = (unsigned char)(((unsigned __int64)(val)) >> 24); \ + (a)[5] = (unsigned char)(((unsigned __int64)(val)) >> 16); \ + (a)[6] = (unsigned char)(((unsigned __int64)(val)) >> 8); \ + (a)[7] = (unsigned char)(((unsigned __int64)(val)) & 0xff); \ + } while(0) #endif struct sha256_state { @@ -312,20 +302,21 @@ static const unsigned long K[64] = { /* Various logical functions */ #define RORc(x, y) \ -(((((unsigned long)(x) & 0xFFFFFFFFUL) >> (unsigned long)((y) & 31)) | \ - ((unsigned long)(x) << (unsigned long)(32 - ((y) & 31)))) & 0xFFFFFFFFUL) -#define Sha256_Ch(x,y,z) (z ^ (x & (y ^ z))) -#define Sha256_Maj(x,y,z) (((x | y) & z) | (x & y)) -#define Sha256_S(x, n) RORc((x), (n)) -#define Sha256_R(x, n) (((x)&0xFFFFFFFFUL)>>(n)) + (((((unsigned long)(x) & 0xFFFFFFFFUL) >> (unsigned long)((y) & 31)) | \ + ((unsigned long)(x) << (unsigned long)(32 - ((y) & 31)))) & 0xFFFFFFFFUL) + +#define Sha256_Ch(x, y, z) (z ^ (x & (y ^ z))) +#define Sha256_Maj(x, y, z) (((x | y) & z) | (x & y)) +#define Sha256_S(x, n) RORc((x), (n)) +#define Sha256_R(x, n) (((x) & 0xFFFFFFFFUL) >> (n)) + #define Sigma0(x) (Sha256_S(x, 2) ^ Sha256_S(x, 13) ^ Sha256_S(x, 22)) #define Sigma1(x) (Sha256_S(x, 6) ^ Sha256_S(x, 11) ^ Sha256_S(x, 25)) #define Gamma0(x) (Sha256_S(x, 7) ^ Sha256_S(x, 18) ^ Sha256_R(x, 3)) #define Gamma1(x) (Sha256_S(x, 17) ^ Sha256_S(x, 19) ^ Sha256_R(x, 10)) /* Compress 512-bits */ -static int sha256_compress(struct sha256_state *md, - const unsigned char *buf) +static int sha256_compress(struct sha256_state *md, const unsigned char *buf) { unsigned long S[8], W[64]; int i; @@ -339,12 +330,11 @@ static int sha256_compress(struct sha256_state *md, W[i] = WPA_GET_BE32(buf + (4 * i)); /* fill W[16..63] */ for(i = 16; i < 64; i++) { - W[i] = Gamma1(W[i - 2]) + W[i - 7] + Gamma0(W[i - 15]) + - W[i - 16]; + W[i] = Gamma1(W[i - 2]) + W[i - 7] + Gamma0(W[i - 15]) + W[i - 16]; } /* Compress */ -#define RND(a,b,c,d,e,f,g,h,i) \ +#define RND(a, b, c, d, e, f, g, h, i) \ do { \ unsigned long t0 = h + Sigma1(e) + Sha256_Ch(e, f, g) + K[i] + W[i]; \ unsigned long t1 = Sigma0(a) + Sha256_Maj(a, b, c); \ @@ -355,8 +345,15 @@ static int sha256_compress(struct sha256_state *md, for(i = 0; i < 64; ++i) { unsigned long t; RND(S[0], S[1], S[2], S[3], S[4], S[5], S[6], S[7], i); - t = S[7]; S[7] = S[6]; S[6] = S[5]; S[5] = S[4]; - S[4] = S[3]; S[3] = S[2]; S[2] = S[1]; S[1] = S[0]; S[0] = t; + t = S[7]; + S[7] = S[6]; + S[6] = S[5]; + S[5] = S[4]; + S[4] = S[3]; + S[3] = S[2]; + S[2] = S[1]; + S[1] = S[0]; + S[0] = t; } /* Feedback */ @@ -500,7 +497,6 @@ CURLcode Curl_sha256it(unsigned char *output, const unsigned char *input, return result; } - const struct HMAC_params Curl_HMAC_SHA256 = { my_sha256_init, /* Hash initialization function. */ my_sha256_update, /* Hash update function. */ diff --git a/vendor/hydra/vendor/curl/lib/sigpipe.h b/vendor/hydra/vendor/curl/lib/sigpipe.h index 1be3a111..5d2c78a2 100644 --- a/vendor/hydra/vendor/curl/lib/sigpipe.h +++ b/vendor/hydra/vendor/curl/lib/sigpipe.h @@ -25,7 +25,7 @@ ***************************************************************************/ #include "curl_setup.h" -#if defined(HAVE_SIGACTION) && \ +#if defined(HAVE_SIGACTION) && \ (defined(USE_OPENSSL) || defined(USE_MBEDTLS) || defined(USE_WOLFSSL)) #include @@ -88,12 +88,12 @@ static void sigpipe_apply(struct Curl_easy *data, #else /* for systems without sigaction */ -#define sigpipe_ignore(x,y) Curl_nop_stmt -#define sigpipe_apply(x,y) Curl_nop_stmt -#define sigpipe_init(x) Curl_nop_stmt -#define sigpipe_restore(x) Curl_nop_stmt +#define sigpipe_ignore(x, y) Curl_nop_stmt +#define sigpipe_apply(x, y) Curl_nop_stmt +#define sigpipe_init(x) Curl_nop_stmt +#define sigpipe_restore(x) Curl_nop_stmt #define SIGPIPE_VARIABLE(x) -#define SIGPIPE_MEMBER(x) bool x +#define SIGPIPE_MEMBER(x) bool x #endif #endif /* HEADER_CURL_SIGPIPE_H */ diff --git a/vendor/hydra/vendor/curl/lib/slist.c b/vendor/hydra/vendor/curl/lib/slist.c index 366b2476..9bfd08ae 100644 --- a/vendor/hydra/vendor/curl/lib/slist.c +++ b/vendor/hydra/vendor/curl/lib/slist.c @@ -21,21 +21,14 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include - #include "slist.h" -/* The last #include files should be: */ -#include "curl_memory.h" -#include "memdebug.h" - /* returns last node in linked list */ static struct curl_slist *slist_get_last(struct curl_slist *list) { - struct curl_slist *item; + struct curl_slist *item; /* if caller passed us a NULL, return now */ if(!list) @@ -58,19 +51,20 @@ static struct curl_slist *slist_get_last(struct curl_slist *list) * If an error occurs, NULL is returned and the string argument is NOT * released. */ -struct curl_slist *Curl_slist_append_nodup(struct curl_slist *list, char *data) +struct curl_slist *Curl_slist_append_nodup(struct curl_slist *list, + const char *data) { - struct curl_slist *last; - struct curl_slist *new_item; + struct curl_slist *last; + struct curl_slist *new_item; DEBUGASSERT(data); - new_item = malloc(sizeof(struct curl_slist)); + new_item = curlx_malloc(sizeof(struct curl_slist)); if(!new_item) return NULL; new_item->next = NULL; - new_item->data = data; + new_item->data = CURL_UNCONST(data); /* if this is the first item, then new_item *is* the list */ if(!list) @@ -88,17 +82,16 @@ struct curl_slist *Curl_slist_append_nodup(struct curl_slist *list, char *data) * bothersome, then simply create a separate _init function and call it * appropriately from within the program. */ -struct curl_slist *curl_slist_append(struct curl_slist *list, - const char *data) +struct curl_slist *curl_slist_append(struct curl_slist *list, const char *data) { - char *dupdata = strdup(data); + char *dupdata = curlx_strdup(data); if(!dupdata) return NULL; list = Curl_slist_append_nodup(list, dupdata); if(!list) - free(dupdata); + curlx_free(dupdata); return list; } @@ -130,8 +123,8 @@ struct curl_slist *Curl_slist_duplicate(struct curl_slist *inlist) /* be nice and clean up resources */ void curl_slist_free_all(struct curl_slist *list) { - struct curl_slist *next; - struct curl_slist *item; + struct curl_slist *next; + struct curl_slist *item; if(!list) return; @@ -140,7 +133,7 @@ void curl_slist_free_all(struct curl_slist *list) do { next = item->next; Curl_safefree(item->data); - free(item); + curlx_free(item); item = next; } while(next); } diff --git a/vendor/hydra/vendor/curl/lib/slist.h b/vendor/hydra/vendor/curl/lib/slist.h index 9561fd02..47a30824 100644 --- a/vendor/hydra/vendor/curl/lib/slist.h +++ b/vendor/hydra/vendor/curl/lib/slist.h @@ -36,6 +36,6 @@ struct curl_slist *Curl_slist_duplicate(struct curl_slist *inlist); * it to the list. */ struct curl_slist *Curl_slist_append_nodup(struct curl_slist *list, - char *data); + const char *data); #endif /* HEADER_CURL_SLIST_H */ diff --git a/vendor/hydra/vendor/curl/lib/smb.c b/vendor/hydra/vendor/curl/lib/smb.c index 2aa8e966..003a38f1 100644 --- a/vendor/hydra/vendor/curl/lib/smb.c +++ b/vendor/hydra/vendor/curl/lib/smb.c @@ -22,7 +22,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #if !defined(CURL_DISABLE_SMB) && defined(USE_CURL_NTLM_CORE) @@ -31,21 +30,16 @@ #include "urldata.h" #include "url.h" #include "sendf.h" -#include "multiif.h" +#include "curl_trc.h" #include "cfilters.h" #include "connect.h" #include "progress.h" #include "transfer.h" #include "select.h" -#include "vtls/vtls.h" #include "curl_ntlm_core.h" #include "escape.h" #include "curl_endian.h" - -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - +#include "curlx/strcopy.h" /* meta key for storing protocol meta at easy handle */ #define CURL_META_SMB_EASY "meta:proto:smb:easy" @@ -329,7 +323,7 @@ const struct Curl_handler Curl_handler_smb = { PORT_SMB, /* defport */ CURLPROTO_SMB, /* protocol */ CURLPROTO_SMB, /* family */ - PROTOPT_NONE /* flags */ + PROTOPT_CONN_REUSE /* flags */ }; #ifdef USE_SSL @@ -358,7 +352,7 @@ const struct Curl_handler Curl_handler_smbs = { PORT_SMBS, /* defport */ CURLPROTO_SMBS, /* protocol */ CURLPROTO_SMB, /* family */ - PROTOPT_SSL /* flags */ + PROTOPT_SSL | PROTOPT_CONN_REUSE /* flags */ }; #endif @@ -372,7 +366,7 @@ const struct Curl_handler Curl_handler_smbs = { defined(__OS400__) static unsigned short smb_swap16(unsigned short x) { - return (unsigned short) ((x << 8) | ((x >> 8) & 0xff)); + return (unsigned short)((x << 8) | ((x >> 8) & 0xff)); } static unsigned int smb_swap32(unsigned int x) @@ -383,8 +377,8 @@ static unsigned int smb_swap32(unsigned int x) static curl_off_t smb_swap64(curl_off_t x) { - return ((curl_off_t) smb_swap32((unsigned int) x) << 32) | - smb_swap32((unsigned int) (x >> 32)); + return ((curl_off_t)smb_swap32((unsigned int)x) << 32) | + smb_swap32((unsigned int)(x >> 32)); } #else @@ -451,7 +445,7 @@ static void smb_easy_dtor(void *key, size_t klen, void *entry) /* `req->path` points to somewhere in `struct smb_conn` which is * kept at the connection meta. If the connection is destroyed first, * req->path points to free'd memory. */ - free(req); + curlx_free(req); } static void smb_conn_dtor(void *key, size_t klen, void *entry) @@ -463,7 +457,7 @@ static void smb_conn_dtor(void *key, size_t klen, void *entry) Curl_safefree(smbc->domain); Curl_safefree(smbc->recv_buf); Curl_safefree(smbc->send_buf); - free(smbc); + curlx_free(smbc); } /* this should setup things in the connection, not in the easy @@ -475,13 +469,13 @@ static CURLcode smb_setup_connection(struct Curl_easy *data, struct smb_request *req; /* Initialize the connection state */ - smbc = calloc(1, sizeof(*smbc)); + smbc = curlx_calloc(1, sizeof(*smbc)); if(!smbc || Curl_conn_meta_set(conn, CURL_META_SMB_CONN, smbc, smb_conn_dtor)) return CURLE_OUT_OF_MEMORY; /* Initialize the request state */ - req = calloc(1, sizeof(*req)); + req = curlx_calloc(1, sizeof(*req)); if(!req || Curl_meta_set(data, CURL_META_SMB_EASY, req, smb_easy_dtor)) return CURLE_OUT_OF_MEMORY; @@ -506,16 +500,13 @@ static CURLcode smb_connect(struct Curl_easy *data, bool *done) /* Initialize the connection state */ smbc->state = SMB_CONNECTING; - smbc->recv_buf = malloc(MAX_MESSAGE_SIZE); + smbc->recv_buf = curlx_malloc(MAX_MESSAGE_SIZE); if(!smbc->recv_buf) return CURLE_OUT_OF_MEMORY; - smbc->send_buf = malloc(MAX_MESSAGE_SIZE); + smbc->send_buf = curlx_malloc(MAX_MESSAGE_SIZE); if(!smbc->send_buf) return CURLE_OUT_OF_MEMORY; - /* Multiple requests are allowed with this connection */ - connkeep(conn, "SMB default"); - /* Parse the username, domain, and password */ slash = strchr(conn->user, '/'); if(!slash) @@ -523,14 +514,14 @@ static CURLcode smb_connect(struct Curl_easy *data, bool *done) if(slash) { smbc->user = slash + 1; - smbc->domain = strdup(conn->user); + smbc->domain = curlx_strdup(conn->user); if(!smbc->domain) return CURLE_OUT_OF_MEMORY; smbc->domain[slash - conn->user] = 0; } else { smbc->user = conn->user; - smbc->domain = strdup(conn->host.name); + smbc->domain = curlx_strdup(conn->host.name); if(!smbc->domain) return CURLE_OUT_OF_MEMORY; } @@ -580,7 +571,7 @@ static CURLcode smb_recv_message(struct Curl_easy *data, if(nbt_size >= msg_size + 1) { /* Add the word count */ - msg_size += 1 + ((unsigned char) buf[msg_size]) * sizeof(unsigned short); + msg_size += 1 + ((unsigned char)buf[msg_size]) * sizeof(unsigned short); if(nbt_size >= msg_size + sizeof(unsigned short)) { /* Add the byte count */ msg_size += sizeof(unsigned short) + @@ -608,8 +599,8 @@ static void smb_format_message(struct smb_conn *smbc, const unsigned int pid = 0xbad71d; /* made up */ memset(h, 0, sizeof(*h)); - h->nbt_length = htons((unsigned short) (sizeof(*h) - sizeof(unsigned int) + - len)); + h->nbt_length = htons((unsigned short)(sizeof(*h) - sizeof(unsigned int) + + len)); memcpy((char *)h->magic, "\xffSMB", 4); h->command = cmd; h->flags = SMB_FLAGS_CANONICAL_PATHNAMES | SMB_FLAGS_CASELESS_PATHNAMES; @@ -617,7 +608,7 @@ static void smb_format_message(struct smb_conn *smbc, h->uid = smb_swap16(smbc->uid); h->tid = smb_swap16(req->tid); h->pid_high = smb_swap16((unsigned short)(pid >> 16)); - h->pid = smb_swap16((unsigned short) pid); + h->pid = smb_swap16((unsigned short)pid); } static CURLcode smb_send(struct Curl_easy *data, struct smb_conn *smbc, @@ -668,12 +659,12 @@ static CURLcode smb_send_message(struct Curl_easy *data, unsigned char cmd, const void *msg, size_t msg_len) { - smb_format_message(smbc, req, (struct smb_header *)smbc->send_buf, - cmd, msg_len); - if((sizeof(struct smb_header) + msg_len) > MAX_MESSAGE_SIZE) { + if((MAX_MESSAGE_SIZE - sizeof(struct smb_header)) < msg_len) { DEBUGASSERT(0); return CURLE_SEND_ERROR; } + smb_format_message(smbc, req, (struct smb_header *)smbc->send_buf, + cmd, msg_len); memcpy(smbc->send_buf + sizeof(struct smb_header), msg, msg_len); return smb_send(data, smbc, sizeof(struct smb_header) + msg_len, 0); @@ -797,8 +788,8 @@ static CURLcode smb_send_open(struct Curl_easy *data, msg.access = smb_swap32(SMB_GENERIC_READ); msg.create_disposition = smb_swap32(SMB_FILE_OPEN); } - msg.byte_count = smb_swap16((unsigned short) byte_count); - strcpy(msg.bytes, req->path); + msg.byte_count = smb_swap16((unsigned short)byte_count); + curlx_strcopy(msg.bytes, sizeof(msg.bytes), req->path, byte_count - 1); return smb_send_message(data, smbc, req, SMB_COM_NT_CREATE_ANDX, &msg, sizeof(msg) - sizeof(msg.bytes) + byte_count); @@ -838,8 +829,8 @@ static CURLcode smb_send_read(struct Curl_easy *data, msg.word_count = SMB_WC_READ_ANDX; msg.andx.command = SMB_COM_NO_ANDX_COMMAND; msg.fid = smb_swap16(req->fid); - msg.offset = smb_swap32((unsigned int) offset); - msg.offset_high = smb_swap32((unsigned int) (offset >> 32)); + msg.offset = smb_swap32((unsigned int)offset); + msg.offset_high = smb_swap32((unsigned int)(offset >> 32)); msg.min_bytes = smb_swap16(MAX_PAYLOAD_SIZE); msg.max_bytes = smb_swap16(MAX_PAYLOAD_SIZE); @@ -863,16 +854,16 @@ static CURLcode smb_send_write(struct Curl_easy *data, msg->word_count = SMB_WC_WRITE_ANDX; msg->andx.command = SMB_COM_NO_ANDX_COMMAND; msg->fid = smb_swap16(req->fid); - msg->offset = smb_swap32((unsigned int) offset); - msg->offset_high = smb_swap32((unsigned int) (offset >> 32)); - msg->data_length = smb_swap16((unsigned short) upload_size); + msg->offset = smb_swap32((unsigned int)offset); + msg->offset_high = smb_swap32((unsigned int)(offset >> 32)); + msg->data_length = smb_swap16((unsigned short)upload_size); msg->data_offset = smb_swap16(sizeof(*msg) - sizeof(unsigned int)); - msg->byte_count = smb_swap16((unsigned short) (upload_size + 1)); + msg->byte_count = smb_swap16((unsigned short)(upload_size + 1)); smb_format_message(smbc, req, &msg->h, SMB_COM_WRITE_ANDX, - sizeof(*msg) - sizeof(msg->h) + (size_t) upload_size); + sizeof(*msg) - sizeof(msg->h) + (size_t)upload_size); - return smb_send(data, smbc, sizeof(*msg), (size_t) upload_size); + return smb_send(data, smbc, sizeof(*msg), (size_t)upload_size); } static CURLcode smb_send_and_recv(struct Curl_easy *data, @@ -1021,7 +1012,7 @@ static void get_posix_time(time_t *out, curl_off_t timestamp) *out = TIME_T_MIN; else #endif - *out = (time_t) timestamp; + *out = (time_t)timestamp; } else *out = 0; @@ -1091,7 +1082,7 @@ static CURLcode smb_request_state(struct Curl_easy *data, bool *done) next_state = SMB_TREE_DISCONNECT; break; } - smb_m = (const struct smb_nt_create_response*) msg; + smb_m = (const struct smb_nt_create_response *)msg; req->fid = smb_swap16(smb_m->fid); data->req.offset = 0; if(data->state.upload) { @@ -1120,9 +1111,9 @@ static CURLcode smb_request_state(struct Curl_easy *data, bool *done) next_state = SMB_CLOSE; break; } - len = Curl_read16_le(((const unsigned char *) msg) + + len = Curl_read16_le((const unsigned char *)msg + sizeof(struct smb_header) + 11); - off = Curl_read16_le(((const unsigned char *) msg) + + off = Curl_read16_le((const unsigned char *)msg + sizeof(struct smb_header) + 13); if(len > 0) { if(off + sizeof(unsigned int) + len > smbc->got) { @@ -1149,11 +1140,11 @@ static CURLcode smb_request_state(struct Curl_easy *data, bool *done) next_state = SMB_CLOSE; break; } - len = Curl_read16_le(((const unsigned char *) msg) + + len = Curl_read16_le((const unsigned char *)msg + sizeof(struct smb_header) + 5); data->req.bytecount += len; data->req.offset += len; - Curl_pgrsSetUploadCounter(data, data->req.bytecount); + Curl_pgrs_upload_inc(data, len); if(data->req.bytecount >= data->req.size) next_state = SMB_CLOSE; else @@ -1249,8 +1240,9 @@ static CURLcode smb_parse_url_path(struct Curl_easy *data, return result; /* Parse the path for the share */ - smbc->share = strdup((*path == '/' || *path == '\\') ? path + 1 : path); - free(path); + smbc->share = curlx_strdup((*path == '/' || *path == '\\') + ? path + 1 : path); + curlx_free(path); if(!smbc->share) return CURLE_OUT_OF_MEMORY; diff --git a/vendor/hydra/vendor/curl/lib/smb.h b/vendor/hydra/vendor/curl/lib/smb.h index aa0be881..474f8d6a 100644 --- a/vendor/hydra/vendor/curl/lib/smb.h +++ b/vendor/hydra/vendor/curl/lib/smb.h @@ -24,7 +24,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #if !defined(CURL_DISABLE_SMB) && defined(USE_CURL_NTLM_CORE) && \ (SIZEOF_CURL_OFF_T > 4) diff --git a/vendor/hydra/vendor/curl/lib/smtp.c b/vendor/hydra/vendor/curl/lib/smtp.c index 3d4f3636..471c8231 100644 --- a/vendor/hydra/vendor/curl/lib/smtp.c +++ b/vendor/hydra/vendor/curl/lib/smtp.c @@ -38,7 +38,6 @@ * Draft LOGIN SASL Mechanism * ***************************************************************************/ - #include "curl_setup.h" #ifndef CURL_DISABLE_SMTP @@ -57,34 +56,27 @@ #include #endif -#include #include "urldata.h" #include "sendf.h" +#include "curl_trc.h" #include "hostip.h" #include "progress.h" #include "transfer.h" #include "escape.h" -#include "http.h" /* for HTTP proxy tunnel stuff */ +#include "pingpong.h" #include "mime.h" -#include "socks.h" #include "smtp.h" #include "vtls/vtls.h" #include "cfilters.h" #include "connect.h" #include "select.h" -#include "multiif.h" #include "url.h" #include "curl_gethostname.h" #include "bufref.h" #include "curl_sasl.h" -#include "curlx/warnless.h" #include "idn.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* meta key for storing protocol meta at easy handle */ #define CURL_META_SMTP_EASY "meta:proto:smtp:easy" /* meta key for storing protocol meta at connection */ @@ -205,7 +197,7 @@ const struct Curl_handler Curl_handler_smtp = { CURLPROTO_SMTP, /* protocol */ CURLPROTO_SMTP, /* family */ PROTOPT_CLOSEACTION | PROTOPT_NOURLQUERY | /* flags */ - PROTOPT_URLOPTIONS | PROTOPT_SSL_REUSE + PROTOPT_URLOPTIONS | PROTOPT_SSL_REUSE | PROTOPT_CONN_REUSE }; #ifdef USE_SSL @@ -235,8 +227,8 @@ const struct Curl_handler Curl_handler_smtps = { PORT_SMTPS, /* defport */ CURLPROTO_SMTPS, /* protocol */ CURLPROTO_SMTP, /* family */ - PROTOPT_CLOSEACTION | PROTOPT_SSL - | PROTOPT_NOURLQUERY | PROTOPT_URLOPTIONS /* flags */ + PROTOPT_CLOSEACTION | PROTOPT_SSL | /* flags */ + PROTOPT_NOURLQUERY | PROTOPT_URLOPTIONS | PROTOPT_CONN_REUSE }; #endif @@ -287,10 +279,10 @@ static bool smtp_endofresp(struct Curl_easy *data, struct connectdata *conn, const char *p = tmpline; result = TRUE; memcpy(tmpline, line, (len == 5 ? 5 : 3)); - tmpline[len == 5 ? 5 : 3 ] = 0; + tmpline[len == 5 ? 5 : 3] = 0; if(curlx_str_number(&p, &code, len == 5 ? 99999 : 999)) return FALSE; - *resp = (int) code; + *resp = (int)code; /* Make sure real server never sends internal value */ if(*resp == 1) @@ -510,7 +502,7 @@ static CURLcode smtp_perform_auth(struct Curl_easy *data, CURLcode result = CURLE_OK; struct smtp_conn *smtpc = Curl_conn_meta_get(data->conn, CURL_META_SMTP_CONN); - const char *ir = (const char *) Curl_bufref_ptr(initresp); + const char *ir = Curl_bufref_ptr(initresp); if(!smtpc) return CURLE_FAILED_INIT; @@ -543,8 +535,7 @@ static CURLcode smtp_continue_auth(struct Curl_easy *data, (void)mech; if(!smtpc) return CURLE_FAILED_INIT; - return Curl_pp_sendf(data, &smtpc->pp, - "%s", (const char *) Curl_bufref_ptr(resp)); + return Curl_pp_sendf(data, &smtpc->pp, "%s", Curl_bufref_ptr(resp)); } /*********************************************************************** @@ -644,7 +635,7 @@ static CURLcode smtp_perform_command(struct Curl_easy *data, utf8 ? " SMTPUTF8" : ""); Curl_free_idnconverted_hostname(&host); - free(address); + curlx_free(address); } else { /* Establish whether we should report that we support SMTPUTF8 for EXPN @@ -720,11 +711,11 @@ static CURLcode smtp_perform_mail(struct Curl_easy *data, worry about that and reply with a 501 error */ from = curl_maprintf("<%s>%s", address, suffix); - free(address); + curlx_free(address); } else /* Null reverse-path, RFC-5321, sect. 3.6.3 */ - from = strdup("<>"); + from = curlx_strdup("<>"); if(!from) { result = CURLE_OUT_OF_MEMORY; @@ -761,11 +752,11 @@ static CURLcode smtp_perform_mail(struct Curl_easy *data, /* An invalid mailbox was provided but we will simply let the server worry about it */ auth = curl_maprintf("<%s>%s", address, suffix); - free(address); + curlx_free(address); } else /* Empty AUTH, RFC-2554, sect. 5 */ - auth = strdup("<>"); + auth = curlx_strdup("<>"); if(!auth) { result = CURLE_OUT_OF_MEMORY; @@ -846,9 +837,9 @@ static CURLcode smtp_perform_mail(struct Curl_easy *data, : ""); /* included in our envelope */ out: - free(from); - free(auth); - free(size); + curlx_free(from); + curlx_free(auth); + curlx_free(size); if(!result) smtp_state(data, smtpc, SMTP_MAIL); @@ -890,7 +881,7 @@ static CURLcode smtp_perform_rcpt_to(struct Curl_easy *data, address, suffix); Curl_free_idnconverted_hostname(&host); - free(address); + curlx_free(address); if(!result) smtp_state(data, smtpc, SMTP_RCPT); @@ -925,7 +916,7 @@ static CURLcode smtp_state_servergreet_resp(struct Curl_easy *data, CURLcode result = CURLE_OK; (void)instate; - if(smtpcode/100 != 2) { + if(smtpcode / 100 != 2) { failf(data, "Got unexpected smtp-server response: %d", smtpcode); result = CURLE_WEIRD_SERVER_REPLY; } @@ -974,9 +965,9 @@ static CURLcode smtp_state_ehlo_resp(struct Curl_easy *data, (void)instate; - if(smtpcode/100 != 2 && smtpcode != 1) { - if(data->set.use_ssl <= CURLUSESSL_TRY - || Curl_conn_is_ssl(data->conn, FIRSTSOCKET)) + if(smtpcode / 100 != 2 && smtpcode != 1) { + if(data->set.use_ssl <= CURLUSESSL_TRY || + Curl_conn_is_ssl(data->conn, FIRSTSOCKET)) result = smtp_perform_helo(data, smtpc); else { failf(data, "Remote access denied: %d", smtpcode); @@ -1075,7 +1066,7 @@ static CURLcode smtp_state_helo_resp(struct Curl_easy *data, CURLcode result = CURLE_OK; (void)instate; - if(smtpcode/100 != 2) { + if(smtpcode / 100 != 2) { failf(data, "Remote access denied: %d", smtpcode); result = CURLE_REMOTE_ACCESS_DENIED; } @@ -1127,8 +1118,8 @@ static CURLcode smtp_state_command_resp(struct Curl_easy *data, (void)instate; - if((smtp->rcpt && smtpcode/100 != 2 && smtpcode != 553 && smtpcode != 1) || - (!smtp->rcpt && smtpcode/100 != 2 && smtpcode != 1)) { + if((smtp->rcpt && smtpcode / 100 != 2 && smtpcode != 553 && smtpcode != 1) || + (!smtp->rcpt && smtpcode / 100 != 2 && smtpcode != 1)) { failf(data, "Command failed: %d", smtpcode); result = CURLE_WEIRD_SERVER_REPLY; } @@ -1167,7 +1158,7 @@ static CURLcode smtp_state_mail_resp(struct Curl_easy *data, CURLcode result = CURLE_OK; (void)instate; - if(smtpcode/100 != 2) { + if(smtpcode / 100 != 2) { failf(data, "MAIL failed: %d", smtpcode); result = CURLE_SEND_ERROR; } @@ -1191,7 +1182,7 @@ static CURLcode smtp_state_rcpt_resp(struct Curl_easy *data, (void)instate; - is_smtp_err = (smtpcode/100 != 2); + is_smtp_err = (smtpcode / 100 != 2); /* If there is multiple RCPT TO to be issued, it is possible to ignore errors and proceed with only the valid addresses. */ @@ -1440,16 +1431,13 @@ static CURLcode smtp_connect(struct Curl_easy *data, bool *done) if(!smtpc) return CURLE_FAILED_INIT; - /* We always support persistent connections in SMTP */ - connkeep(data->conn, "SMTP default"); - PINGPONG_SETUP(&smtpc->pp, smtp_pp_statemachine, smtp_endofresp); /* Initialize the SASL storage */ Curl_sasl_init(&smtpc->sasl, data, &saslsmtp); /* Initialise the pingpong layer */ - Curl_pp_init(&smtpc->pp); + Curl_pp_init(&smtpc->pp, Curl_pgrs_now(data)); /* Parse the URL options */ result = smtp_parse_url_options(data->conn, smtpc); @@ -1697,10 +1685,7 @@ static CURLcode smtp_regular_transfer(struct Curl_easy *data, data->req.size = -1; /* Set the progress data */ - Curl_pgrsSetUploadCounter(data, 0); - Curl_pgrsSetDownloadCounter(data, 0); - Curl_pgrsSetUploadSize(data, -1); - Curl_pgrsSetDownloadSize(data, -1); + Curl_pgrsReset(data); /* Carry out the perform */ result = smtp_perform(data, smtpc, smtp, &connected, dophase_done); @@ -1714,13 +1699,12 @@ static CURLcode smtp_regular_transfer(struct Curl_easy *data, return result; } - static void smtp_easy_dtor(void *key, size_t klen, void *entry) { struct SMTP *smtp = entry; (void)key; (void)klen; - free(smtp); + curlx_free(smtp); } static void smtp_conn_dtor(void *key, size_t klen, void *entry) @@ -1730,7 +1714,7 @@ static void smtp_conn_dtor(void *key, size_t klen, void *entry) (void)klen; Curl_pp_disconnect(&smtpc->pp); Curl_safefree(smtpc->domain); - free(smtpc); + curlx_free(smtpc); } static CURLcode smtp_setup_connection(struct Curl_easy *data, @@ -1740,14 +1724,14 @@ static CURLcode smtp_setup_connection(struct Curl_easy *data, struct SMTP *smtp; CURLcode result = CURLE_OK; - smtpc = calloc(1, sizeof(*smtpc)); + smtpc = curlx_calloc(1, sizeof(*smtpc)); if(!smtpc || Curl_conn_meta_set(conn, CURL_META_SMTP_CONN, smtpc, smtp_conn_dtor)) { - result = CURLE_OUT_OF_MEMORY; - goto out; + result = CURLE_OUT_OF_MEMORY; + goto out; } - smtp = calloc(1, sizeof(*smtp)); + smtp = curlx_calloc(1, sizeof(*smtp)); if(!smtp || Curl_meta_set(data, CURL_META_SMTP_EASY, smtp, smtp_easy_dtor)) result = CURLE_OUT_OF_MEMORY; @@ -1881,7 +1865,7 @@ static CURLcode smtp_parse_address(const char *fqma, char **address, /* Duplicate the fully qualified email address so we can manipulate it, ensuring it does not contain the delimiters if specified */ - char *dup = strdup(fqma[0] == '<' ? fqma + 1 : fqma); + char *dup = curlx_strdup(fqma[0] == '<' ? fqma + 1 : fqma); if(!dup) return CURLE_OUT_OF_MEMORY; @@ -1951,7 +1935,7 @@ static void cr_eob_close(struct Curl_easy *data, struct Curl_creader *reader) } /* this is the 5-bytes End-Of-Body marker for SMTP */ -#define SMTP_EOB "\r\n.\r\n" +#define SMTP_EOB "\r\n.\r\n" #define SMTP_EOB_FIND_LEN 3 /* client reader doing SMTP End-Of-Body escaping. */ @@ -2024,16 +2008,16 @@ static CURLcode cr_eob_read(struct Curl_easy *data, const char *eob = SMTP_EOB; CURL_TRC_SMTP(data, "auto-ending mail body with '\\r\\n.\\r\\n'"); switch(ctx->n_eob) { - case 2: - /* seen a CRLF at the end, just add the remainder */ - eob = &SMTP_EOB[2]; - break; - case 3: - /* ended with '\r\n.', we should escape the last '.' */ - eob = "." SMTP_EOB; - break; - default: - break; + case 2: + /* seen a CRLF at the end, just add the remainder */ + eob = &SMTP_EOB[2]; + break; + case 3: + /* ended with '\r\n.', we should escape the last '.' */ + eob = "." SMTP_EOB; + break; + default: + break; } result = Curl_bufq_cwrite(&ctx->buf, eob, strlen(eob), &n); if(result) @@ -2086,8 +2070,7 @@ static CURLcode cr_eob_add(struct Curl_easy *data) struct Curl_creader *reader = NULL; CURLcode result; - result = Curl_creader_create(&reader, data, &cr_eob, - CURL_CR_CONTENT_ENCODE); + result = Curl_creader_create(&reader, data, &cr_eob, CURL_CR_CONTENT_ENCODE); if(!result) result = Curl_creader_add(data, reader); diff --git a/vendor/hydra/vendor/curl/lib/smtp.h b/vendor/hydra/vendor/curl/lib/smtp.h index ed9824b1..7e3cf774 100644 --- a/vendor/hydra/vendor/curl/lib/smtp.h +++ b/vendor/hydra/vendor/curl/lib/smtp.h @@ -23,10 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - -#include "pingpong.h" -#include "curl_sasl.h" - extern const struct Curl_handler Curl_handler_smtp; extern const struct Curl_handler Curl_handler_smtps; diff --git a/vendor/hydra/vendor/curl/lib/sockaddr.h b/vendor/hydra/vendor/curl/lib/sockaddr.h index 2e2d375e..2b033350 100644 --- a/vendor/hydra/vendor/curl/lib/sockaddr.h +++ b/vendor/hydra/vendor/curl/lib/sockaddr.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" struct Curl_sockaddr_storage { diff --git a/vendor/hydra/vendor/curl/lib/socketpair.c b/vendor/hydra/vendor/curl/lib/socketpair.c index 45e908bb..bdbe9562 100644 --- a/vendor/hydra/vendor/curl/lib/socketpair.c +++ b/vendor/hydra/vendor/curl/lib/socketpair.c @@ -21,11 +21,12 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" + #include "socketpair.h" #include "urldata.h" #include "rand.h" +#include "curlx/nonblock.h" #ifdef USE_EVENTFD @@ -107,37 +108,23 @@ int Curl_socketpair(int domain, int type, int protocol, } #endif /* USE_SOCKETPAIR */ #else /* !HAVE_SOCKETPAIR */ -#ifdef _WIN32 -/* - * This is a socketpair() implementation for Windows. - */ -#include -#ifdef HAVE_IO_H -#include -#endif -#else + #ifdef HAVE_NETDB_H #include #endif #ifdef HAVE_NETINET_IN_H -#include /* IPPROTO_TCP */ +#include /* for IPPROTO_TCP */ #endif #ifdef HAVE_ARPA_INET_H #include #endif + #ifndef INADDR_LOOPBACK #define INADDR_LOOPBACK 0x7f000001 -#endif /* !INADDR_LOOPBACK */ -#endif /* !_WIN32 */ +#endif -#include "curlx/nonblock.h" /* for curlx_nonblock */ -#include "curlx/timeval.h" /* needed before select.h */ #include "select.h" /* for Curl_poll */ -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - int Curl_socketpair(int domain, int type, int protocol, curl_socket_t socks[2], bool nonblocking) { @@ -228,18 +215,18 @@ int Curl_socketpair(int domain, int type, int protocol, if(nread == -1) { int sockerr = SOCKERRNO; /* Do not block forever */ - if(curlx_timediff(curlx_now(), start) > (60 * 1000)) + if(curlx_timediff_ms(curlx_now(), start) > (60 * 1000)) goto error; if( #ifdef USE_WINSOCK - /* This is how Windows does it */ - (SOCKEWOULDBLOCK == sockerr) + /* This is how Windows does it */ + (SOCKEWOULDBLOCK == sockerr) #else - /* errno may be EWOULDBLOCK or on some systems EAGAIN when it - returned due to its inability to send off data without - blocking. We therefore treat both error codes the same here */ - (SOCKEWOULDBLOCK == sockerr) || (EAGAIN == sockerr) || - (SOCKEINTR == sockerr) || (SOCKEINPROGRESS == sockerr) + /* errno may be EWOULDBLOCK or on some systems EAGAIN when it + returned due to its inability to send off data without + blocking. We therefore treat both error codes the same here */ + (SOCKEWOULDBLOCK == sockerr) || (EAGAIN == sockerr) || + (SOCKEINTR == sockerr) || (SOCKEINPROGRESS == sockerr) #endif ) { continue; diff --git a/vendor/hydra/vendor/curl/lib/socketpair.h b/vendor/hydra/vendor/curl/lib/socketpair.h index e601f5f7..36685e71 100644 --- a/vendor/hydra/vendor/curl/lib/socketpair.h +++ b/vendor/hydra/vendor/curl/lib/socketpair.h @@ -23,27 +23,24 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifdef USE_EVENTFD -#define wakeup_write write -#define wakeup_read read -#define wakeup_close close -#define wakeup_create(p,nb) Curl_eventfd(p,nb) +#define wakeup_write write +#define wakeup_read read +#define wakeup_close close +#define wakeup_create(p, nb) Curl_eventfd(p, nb) -#include int Curl_eventfd(curl_socket_t socks[2], bool nonblocking); #elif defined(HAVE_PIPE) -#define wakeup_write write -#define wakeup_read read -#define wakeup_close close -#define wakeup_create(p,nb) Curl_pipe(p,nb) +#define wakeup_write write +#define wakeup_read read +#define wakeup_close close +#define wakeup_create(p, nb) Curl_pipe(p, nb) -#include int Curl_pipe(curl_socket_t socks[2], bool nonblocking); #else /* !USE_EVENTFD && !HAVE_PIPE */ @@ -67,14 +64,12 @@ int Curl_pipe(curl_socket_t socks[2], bool nonblocking); #endif #define USE_SOCKETPAIR -#define wakeup_create(p,nb) \ +#define wakeup_create(p, nb) \ Curl_socketpair(SOCKETPAIR_FAMILY, SOCKETPAIR_TYPE, 0, p, nb) #endif /* USE_EVENTFD */ #ifndef CURL_DISABLE_SOCKETPAIR -#include - int Curl_socketpair(int domain, int type, int protocol, curl_socket_t socks[2], bool nonblocking); #endif diff --git a/vendor/hydra/vendor/curl/lib/socks.c b/vendor/hydra/vendor/curl/lib/socks.c index 9936aaf5..e49e8c82 100644 --- a/vendor/hydra/vendor/curl/lib/socks.c +++ b/vendor/hydra/vendor/curl/lib/socks.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifndef CURL_DISABLE_PROXY @@ -35,20 +34,14 @@ #include "urldata.h" #include "bufq.h" -#include "sendf.h" +#include "curl_trc.h" #include "select.h" #include "cfilters.h" #include "connect.h" -#include "curlx/timeval.h" #include "socks.h" -#include "multiif.h" /* for getsock macros */ #include "curlx/inet_pton.h" #include "url.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #if defined(DEBUGBUILD) && !defined(CURL_DISABLE_VERBOSE_STRINGS) #define DEBUG_AND_VERBOSE #endif @@ -137,7 +130,7 @@ CURLcode Curl_blockread_all(struct Curl_cfilter *cf, *pnread = 0; for(;;) { - timediff_t timeout_ms = Curl_timeleft(data, NULL, TRUE); + timediff_t timeout_ms = Curl_timeleft_ms(data, TRUE); if(timeout_ms < 0) { /* we already got the timeout */ return CURLE_OPERATION_TIMEDOUT; @@ -168,9 +161,9 @@ CURLcode Curl_blockread_all(struct Curl_cfilter *cf, #if defined(DEBUGBUILD) && !defined(CURL_DISABLE_VERBOSE_STRINGS) #define DEBUG_AND_VERBOSE -#define sxstate(x,c,d,y) socksstate(x,c,d,y, __LINE__) +#define sxstate(x, c, d, y) socksstate(x, c, d, y, __LINE__) #else -#define sxstate(x,c,d,y) socksstate(x,c,d,y) +#define sxstate(x, c, d, y) socksstate(x, c, d, y) #endif /* always use this function to change state, to make debugging easier */ @@ -210,9 +203,9 @@ static CURLproxycode socks_failed(struct socks_state *sx, } static CURLproxycode socks_flush(struct socks_state *sx, - struct Curl_cfilter *cf, - struct Curl_easy *data, - bool *done) + struct Curl_cfilter *cf, + struct Curl_easy *data, + bool *done) { CURLcode result; size_t nwritten; @@ -308,7 +301,7 @@ static CURLproxycode socks4_req_add_user(struct socks_state *sx, return CURLPX_SEND_REQUEST; } else { - /* empty user name */ + /* empty username */ unsigned char b = 0; result = Curl_bufq_write(&sx->iobuf, &b, 1, &nwritten); if(result || (nwritten != 1)) @@ -336,8 +329,7 @@ static CURLproxycode socks4_resolving(struct socks_state *sx, result = Curl_resolv(data, sx->hostname, sx->remote_port, cf->conn->ip_version, TRUE, &dns); if(result == CURLE_AGAIN) { - CURL_TRC_CF(data, cf, "SOCKS4 non-blocking resolve of %s", - sx->hostname); + CURL_TRC_CF(data, cf, "SOCKS4 non-blocking resolve of %s", sx->hostname); return CURLPX_OK; } else if(result) @@ -351,8 +343,7 @@ static CURLproxycode socks4_resolving(struct socks_state *sx, } if(result || !dns) { - failf(data, "Failed to resolve \"%s\" for SOCKS4 connect.", - sx->hostname); + failf(data, "Failed to resolve \"%s\" for SOCKS4 connect.", sx->hostname); return CURLPX_RESOLVE_HOST; } @@ -469,16 +460,16 @@ static CURLproxycode socks4_check_resp(struct socks_state *sx, } /* -* This function logs in to a SOCKS4 proxy and sends the specifics to the final -* destination server. -* -* Reference : -* https://www.openssh.com/txt/socks4.protocol -* -* Note : -* Set protocol4a=true for "SOCKS 4A (Simple Extension to SOCKS 4 Protocol)" -* Nonsupport "Identification Protocol (RFC1413)" -*/ + * This function logs in to a SOCKS4 proxy and sends the specifics to the final + * destination server. + * + * Reference : + * https://www.openssh.com/txt/socks4.protocol + * + * Note : + * Set protocol4a=true for "SOCKS 4A (Simple Extension to SOCKS 4 Protocol)" + * Nonsupport "Identification Protocol (RFC1413)" + */ static CURLproxycode socks4_connect(struct Curl_cfilter *cf, struct socks_state *sx, struct Curl_easy *data) @@ -528,7 +519,7 @@ static CURLproxycode socks4_connect(struct Curl_cfilter *cf, /* socks4a, not resolving locally, sends the hostname. * add an invalid address + user + hostname */ unsigned char buf[4] = { 0, 0, 0, 1 }; - size_t hlen = strlen(sx->hostname) + 1; /* including NUL */ + size_t hlen = strlen(sx->hostname) + 1; /* including NUL */ if(hlen > 255) { failf(data, "SOCKS4: too long hostname"); @@ -737,7 +728,7 @@ static CURLproxycode socks5_auth_init(struct Curl_cfilter *cf, if(result || (nwritten != ulen)) return CURLPX_SEND_REQUEST; } - buf[0] = (unsigned char) plen; + buf[0] = (unsigned char)plen; result = Curl_bufq_write(&sx->iobuf, buf, 1, &nwritten); if(result || (nwritten != 1)) return CURLPX_SEND_REQUEST; @@ -817,7 +808,7 @@ static CURLproxycode socks5_req1_init(struct socks_state *sx, const size_t hostname_len = strlen(sx->hostname); desttype = 3; destination = (const unsigned char *)sx->hostname; - destlen = (unsigned char) hostname_len; /* one byte length */ + destlen = (unsigned char)hostname_len; /* one byte length */ } req[3] = desttype; @@ -864,8 +855,7 @@ static CURLproxycode socks5_resolving(struct socks_state *sx, result = Curl_resolv(data, sx->hostname, sx->remote_port, cf->conn->ip_version, TRUE, &dns); if(result == CURLE_AGAIN) { - CURL_TRC_CF(data, cf, "SOCKS5 non-blocking resolve of %s", - sx->hostname); + CURL_TRC_CF(data, cf, "SOCKS5 non-blocking resolve of %s", sx->hostname); return CURLPX_OK; } else if(result) @@ -879,8 +869,7 @@ static CURLproxycode socks5_resolving(struct socks_state *sx, } if(result || !dns) { - failf(data, "Failed to resolve \"%s\" for SOCKS5 connect.", - sx->hostname); + failf(data, "Failed to resolve \"%s\" for SOCKS5 connect.", sx->hostname); presult = CURLPX_RESOLVE_HOST; goto out; } @@ -897,8 +886,7 @@ static CURLproxycode socks5_resolving(struct socks_state *sx, } #endif if(!hp) { - failf(data, "Failed to resolve \"%s\" for SOCKS5 connect.", - sx->hostname); + failf(data, "Failed to resolve \"%s\" for SOCKS5 connect.", sx->hostname); presult = CURLPX_RESOLVE_HOST; goto out; } @@ -1215,7 +1203,7 @@ static void socks_proxy_cf_free(struct Curl_cfilter *cf) struct socks_state *sxstate = cf->ctx; if(sxstate) { Curl_bufq_free(&sxstate->iobuf); - free(sxstate); + curlx_free(sxstate); cf->ctx = NULL; } } @@ -1247,7 +1235,7 @@ static CURLcode socks_proxy_cf_connect(struct Curl_cfilter *cf, return result; if(!sx) { - cf->ctx = sx = calloc(1, sizeof(*sx)); + cf->ctx = sx = curlx_calloc(1, sizeof(*sx)); if(!sx) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -1398,7 +1386,7 @@ static CURLcode socks_cf_query(struct Curl_cfilter *cf, struct Curl_cftype Curl_cft_socks_proxy = { "SOCKS", - CF_TYPE_IP_CONNECT|CF_TYPE_PROXY, + CF_TYPE_IP_CONNECT | CF_TYPE_PROXY, 0, socks_proxy_cf_destroy, socks_proxy_cf_connect, diff --git a/vendor/hydra/vendor/curl/lib/socks.h b/vendor/hydra/vendor/curl/lib/socks.h index f76bddc5..520fb75d 100644 --- a/vendor/hydra/vendor/curl/lib/socks.h +++ b/vendor/hydra/vendor/curl/lib/socks.h @@ -23,14 +23,9 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#ifdef CURL_DISABLE_PROXY -#define Curl_SOCKS4(a,b,c,d,e) CURLE_NOT_BUILT_IN -#define Curl_SOCKS5(a,b,c,d,e,f) CURLE_NOT_BUILT_IN -#define Curl_SOCKS_getsock(x,y,z) 0 -#else +#ifndef CURL_DISABLE_PROXY /* * Helper read-from-socket functions. Does the same as Curl_read() but it * blocks until all bytes amount of buffersize will be read. No more, no less. @@ -56,6 +51,6 @@ CURLcode Curl_cf_socks_proxy_insert_after(struct Curl_cfilter *cf_at, extern struct Curl_cftype Curl_cft_socks_proxy; -#endif /* CURL_DISABLE_PROXY */ +#endif /* !CURL_DISABLE_PROXY */ -#endif /* HEADER_CURL_SOCKS_H */ +#endif /* HEADER_CURL_SOCKS_H */ diff --git a/vendor/hydra/vendor/curl/lib/socks_gssapi.c b/vendor/hydra/vendor/curl/lib/socks_gssapi.c index 929132f5..2da11713 100644 --- a/vendor/hydra/vendor/curl/lib/socks_gssapi.c +++ b/vendor/hydra/vendor/curl/lib/socks_gssapi.c @@ -22,25 +22,19 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #if defined(HAVE_GSSAPI) && !defined(CURL_DISABLE_PROXY) #include "curl_gssapi.h" #include "urldata.h" -#include "sendf.h" +#include "curl_trc.h" #include "cfilters.h" #include "connect.h" -#include "curlx/timeval.h" +#include "curlx/nonblock.h" #include "socks.h" -#include "curlx/warnless.h" #include "strdup.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #if defined(__GNUC__) && defined(__APPLE__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" @@ -71,8 +65,7 @@ static int check_gss_err(struct Curl_easy *data, GSS_C_NULL_OID, &msg_ctx, &status_string); if(maj_stat == GSS_S_COMPLETE) { - if(curlx_dyn_addn(&dbuf, status_string.value, - status_string.length)) + if(curlx_dyn_addn(&dbuf, status_string.value, status_string.length)) return 1; /* error */ gss_release_buffer(&min_stat, &status_string); break; @@ -89,8 +82,7 @@ static int check_gss_err(struct Curl_easy *data, GSS_C_NULL_OID, &msg_ctx, &status_string); if(maj_stat == GSS_S_COMPLETE) { - if(curlx_dyn_addn(&dbuf, status_string.value, - status_string.length)) + if(curlx_dyn_addn(&dbuf, status_string.value, status_string.length)) return 1; /* error */ gss_release_buffer(&min_stat, &status_string); break; @@ -132,7 +124,6 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, const size_t serviceptr_length = strlen(serviceptr); gss_ctx_id_t gss_context = GSS_C_NO_CONTEXT; - /* GSS-API request looks like * +----+------+-----+----------------+ * |VER | MTYP | LEN | TOKEN | @@ -149,11 +140,11 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, return CURLE_OUT_OF_MEMORY; gss_major_status = gss_import_name(&gss_minor_status, &service, - (gss_OID) GSS_C_NULL_OID, &server); + (gss_OID)GSS_C_NULL_OID, &server); } else { - service.value = malloc(serviceptr_length + - strlen(conn->socks_proxy.host.name) + 2); + service.value = curlx_malloc(serviceptr_length + + strlen(conn->socks_proxy.host.name) + 2); if(!service.value) return CURLE_OUT_OF_MEMORY; service.length = serviceptr_length + @@ -212,8 +203,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, us_length = htons((unsigned short)gss_send_token.length); memcpy(socksreq + 2, &us_length, sizeof(short)); - code = Curl_conn_cf_send(cf->next, data, (char *)socksreq, 4, - FALSE, &nwritten); + code = Curl_conn_cf_send(cf->next, data, socksreq, 4, FALSE, &nwritten); if(code || (nwritten != 4)) { failf(data, "Failed to send GSS-API authentication request."); gss_release_name(&gss_status, &server); @@ -223,7 +213,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, } code = Curl_conn_cf_send(cf->next, data, - (char *)gss_send_token.value, + gss_send_token.value, gss_send_token.length, FALSE, &nwritten); if(code || (gss_send_token.length != nwritten)) { failf(data, "Failed to send GSS-API authentication token."); @@ -232,7 +222,6 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, Curl_gss_delete_sec_context(&gss_status, &gss_context, NULL); return CURLE_COULDNT_CONNECT; } - } gss_release_buffer(&gss_status, &gss_send_token); @@ -278,7 +267,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, us_length = ntohs(us_length); gss_recv_token.length = us_length; - gss_recv_token.value = malloc(gss_recv_token.length); + gss_recv_token.value = curlx_malloc(gss_recv_token.length); if(!gss_recv_token.value) { failf(data, "Could not allocate memory for GSS-API authentication " @@ -410,8 +399,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, memcpy(socksreq + 2, &us_length, sizeof(short)); } - code = Curl_conn_cf_send(cf->next, data, (char *)socksreq, 4, FALSE, - &nwritten); + code = Curl_conn_cf_send(cf->next, data, socksreq, 4, FALSE, &nwritten); if(code || (nwritten != 4)) { failf(data, "Failed to send GSS-API encryption request."); gss_release_buffer(&gss_status, &gss_w_token); @@ -421,8 +409,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, if(data->set.socks5_gssapi_nec) { memcpy(socksreq, &gss_enc, 1); - code = Curl_conn_cf_send(cf->next, data, (char *)socksreq, 1, FALSE, - &nwritten); + code = Curl_conn_cf_send(cf->next, data, socksreq, 1, FALSE, &nwritten); if(code || (nwritten != 1)) { failf(data, "Failed to send GSS-API encryption type."); Curl_gss_delete_sec_context(&gss_status, &gss_context, NULL); @@ -430,7 +417,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, } } else { - code = Curl_conn_cf_send(cf->next, data, (char *)gss_w_token.value, + code = Curl_conn_cf_send(cf->next, data, gss_w_token.value, gss_w_token.length, FALSE, &nwritten); if(code || (gss_w_token.length != nwritten)) { failf(data, "Failed to send GSS-API encryption type."); @@ -467,7 +454,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, us_length = ntohs(us_length); gss_recv_token.length = us_length; - gss_recv_token.value = malloc(gss_recv_token.length); + gss_recv_token.value = curlx_malloc(gss_recv_token.length); if(!gss_recv_token.value) { Curl_gss_delete_sec_context(&gss_status, &gss_context, NULL); return CURLE_OUT_OF_MEMORY; diff --git a/vendor/hydra/vendor/curl/lib/socks_sspi.c b/vendor/hydra/vendor/curl/lib/socks_sspi.c index a7aa81b7..0f3cfceb 100644 --- a/vendor/hydra/vendor/curl/lib/socks_sspi.c +++ b/vendor/hydra/vendor/curl/lib/socks_sspi.c @@ -22,25 +22,19 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #if defined(USE_WINDOWS_SSPI) && !defined(CURL_DISABLE_PROXY) #include "urldata.h" -#include "sendf.h" +#include "curl_trc.h" #include "cfilters.h" #include "connect.h" #include "strerror.h" -#include "curlx/timeval.h" +#include "curlx/nonblock.h" #include "socks.h" #include "curl_sspi.h" #include "curlx/multibyte.h" -#include "curlx/warnless.h" - -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" /* * Helper sspi error functions. @@ -87,8 +81,8 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, unsigned long qop; unsigned char socksreq[4]; /* room for GSS-API exchange header only */ const char *service = data->set.str[STRING_PROXY_SERVICE_NAME] ? - data->set.str[STRING_PROXY_SERVICE_NAME] : "rcmd"; - char *etbuf; + data->set.str[STRING_PROXY_SERVICE_NAME] : "rcmd"; + uint8_t *etbuf; size_t etbuf_size; /* GSS-API request looks like @@ -101,7 +95,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, /* prepare service name */ if(strchr(service, '/')) - service_name = strdup(service); + service_name = curlx_strdup(service); else service_name = curl_maprintf("%s/%s", service, conn->socks_proxy.host.name); @@ -156,7 +150,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, (void)curlx_nonblock(sock, FALSE); /* As long as we need to keep sending some context info, and there is no */ - /* errors, keep sending it... */ + /* errors, keep sending it... */ for(;;) { TCHAR *sname; @@ -179,7 +173,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, &output_desc, &sspi_ret_flags, NULL); - curlx_unicodefree(sname); + curlx_free(sname); Curl_safefree(sspi_recv_token.pvBuffer); sspi_recv_token.cbBuffer = 0; @@ -191,8 +185,8 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, } if(sspi_send_token.cbBuffer) { - socksreq[0] = 1; /* GSS-API subnegotiation version */ - socksreq[1] = 1; /* authentication message type */ + socksreq[0] = 1; /* GSS-API subnegotiation version */ + socksreq[1] = 1; /* authentication message type */ if(sspi_send_token.cbBuffer > 0xffff) { /* needs to fit in an unsigned 16 bit field */ result = CURLE_COULDNT_CONNECT; @@ -201,8 +195,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, us_length = htons((unsigned short)sspi_send_token.cbBuffer); memcpy(socksreq + 2, &us_length, sizeof(short)); - code = Curl_conn_cf_send(cf->next, data, (char *)socksreq, 4, FALSE, - &written); + code = Curl_conn_cf_send(cf->next, data, socksreq, 4, FALSE, &written); if(code || (written != 4)) { failf(data, "Failed to send SSPI authentication request."); result = CURLE_COULDNT_CONNECT; @@ -210,7 +203,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, } code = Curl_conn_cf_send(cf->next, data, - (char *)sspi_send_token.pvBuffer, + sspi_send_token.pvBuffer, sspi_send_token.cbBuffer, FALSE, &written); if(code || (sspi_send_token.cbBuffer != written)) { failf(data, "Failed to send SSPI authentication token."); @@ -268,7 +261,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, us_length = ntohs(us_length); sspi_recv_token.cbBuffer = us_length; - sspi_recv_token.pvBuffer = malloc(us_length); + sspi_recv_token.pvBuffer = curlx_malloc(us_length); if(!sspi_recv_token.pvBuffer) { result = CURLE_OUT_OF_MEMORY; @@ -303,15 +296,15 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, char *user_utf8 = curlx_convert_tchar_to_UTF8(names.sUserName); infof(data, "SOCKS5 server authenticated user %s with GSS-API.", (user_utf8 ? user_utf8 : "(unknown)")); - curlx_unicodefree(user_utf8); + curlx_free(user_utf8); #endif Curl_pSecFn->FreeContextBuffer(names.sUserName); names.sUserName = NULL; } /* Do encryption */ - socksreq[0] = 1; /* GSS-API subnegotiation version */ - socksreq[1] = 2; /* encryption message type */ + socksreq[0] = 1; /* GSS-API subnegotiation version */ + socksreq[1] = 2; /* encryption message type */ gss_enc = 0; /* no data protection */ /* do confidentiality protection if supported */ @@ -323,7 +316,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, infof(data, "SOCKS5 server supports GSS-API %s data protection.", (gss_enc == 0) ? "no" : - ((gss_enc == 1) ? "integrity":"confidentiality") ); + ((gss_enc == 1) ? "integrity" : "confidentiality") ); /* * Sending the encryption type in clear seems wrong. It should be @@ -372,7 +365,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, sspi_w_token[0].cbBuffer = sspi_sizes.cbSecurityTrailer; sspi_w_token[0].BufferType = SECBUFFER_TOKEN; - sspi_w_token[0].pvBuffer = malloc(sspi_sizes.cbSecurityTrailer); + sspi_w_token[0].pvBuffer = curlx_malloc(sspi_sizes.cbSecurityTrailer); if(!sspi_w_token[0].pvBuffer) { result = CURLE_OUT_OF_MEMORY; @@ -380,7 +373,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, } sspi_w_token[1].cbBuffer = 1; - sspi_w_token[1].pvBuffer = malloc(1); + sspi_w_token[1].pvBuffer = curlx_malloc(1); if(!sspi_w_token[1].pvBuffer) { result = CURLE_OUT_OF_MEMORY; goto error; @@ -389,7 +382,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, memcpy(sspi_w_token[1].pvBuffer, &gss_enc, 1); sspi_w_token[2].BufferType = SECBUFFER_PADDING; sspi_w_token[2].cbBuffer = sspi_sizes.cbBlockSize; - sspi_w_token[2].pvBuffer = malloc(sspi_sizes.cbBlockSize); + sspi_w_token[2].pvBuffer = curlx_malloc(sspi_sizes.cbBlockSize); if(!sspi_w_token[2].pvBuffer) { result = CURLE_OUT_OF_MEMORY; goto error; @@ -404,13 +397,13 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, } etbuf_size = sspi_w_token[0].cbBuffer + sspi_w_token[1].cbBuffer + - sspi_w_token[2].cbBuffer; + sspi_w_token[2].cbBuffer; if(etbuf_size > 0xffff) { /* needs to fit in an unsigned 16 bit field */ result = CURLE_COULDNT_CONNECT; goto error; } - etbuf = malloc(etbuf_size); + etbuf = curlx_malloc(etbuf_size); if(!etbuf) { result = CURLE_OUT_OF_MEMORY; goto error; @@ -433,8 +426,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, memcpy(socksreq + 2, &us_length, sizeof(short)); } - code = Curl_conn_cf_send(cf->next, data, (char *)socksreq, 4, FALSE, - &written); + code = Curl_conn_cf_send(cf->next, data, socksreq, 4, FALSE, &written); if(code || (written != 4)) { failf(data, "Failed to send SSPI encryption request."); result = CURLE_COULDNT_CONNECT; @@ -443,8 +435,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, if(data->set.socks5_gssapi_nec) { memcpy(socksreq, &gss_enc, 1); - code = Curl_conn_cf_send(cf->next, data, (char *)socksreq, 1, FALSE, - &written); + code = Curl_conn_cf_send(cf->next, data, socksreq, 1, FALSE, &written); if(code || (written != 1)) { failf(data, "Failed to send SSPI encryption type."); result = CURLE_COULDNT_CONNECT; @@ -489,7 +480,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, us_length = ntohs(us_length); sspi_w_token[0].cbBuffer = us_length; - sspi_w_token[0].pvBuffer = malloc(us_length); + sspi_w_token[0].pvBuffer = curlx_malloc(us_length); if(!sspi_w_token[0].pvBuffer) { result = CURLE_OUT_OF_MEMORY; goto error; @@ -505,7 +496,6 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, goto error; } - if(!data->set.socks5_gssapi_nec) { wrap_desc.cBuffers = 2; sspi_w_token[0].BufferType = SECBUFFER_STREAM; @@ -518,7 +508,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, /* since sspi_w_token[1].pvBuffer is allocated by the SSPI in this case, it must be freed in this block using FreeContextBuffer() instead of - potentially in error cleanup using free(). */ + potentially in error cleanup using curlx_free(). */ if(check_sspi_err(data, status, "DecryptMessage")) { failf(data, "Failed to query security context attributes."); @@ -581,21 +571,18 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, return CURLE_OK; error: (void)curlx_nonblock(sock, TRUE); - free(service_name); + curlx_free(service_name); Curl_pSecFn->DeleteSecurityContext(&sspi_context); Curl_pSecFn->FreeCredentialsHandle(&cred_handle); - free(sspi_recv_token.pvBuffer); + curlx_free(sspi_recv_token.pvBuffer); if(sspi_send_token.pvBuffer) Curl_pSecFn->FreeContextBuffer(sspi_send_token.pvBuffer); if(names.sUserName) Curl_pSecFn->FreeContextBuffer(names.sUserName); - if(sspi_w_token[0].pvBuffer) - Curl_pSecFn->FreeContextBuffer(sspi_w_token[0].pvBuffer); - if(sspi_w_token[1].pvBuffer) - Curl_pSecFn->FreeContextBuffer(sspi_w_token[1].pvBuffer); - if(sspi_w_token[2].pvBuffer) - Curl_pSecFn->FreeContextBuffer(sspi_w_token[2].pvBuffer); - free(etbuf); + curlx_free(sspi_w_token[0].pvBuffer); + curlx_free(sspi_w_token[1].pvBuffer); + curlx_free(sspi_w_token[2].pvBuffer); + curlx_free(etbuf); return result; } #endif diff --git a/vendor/hydra/vendor/curl/lib/speedcheck.c b/vendor/hydra/vendor/curl/lib/speedcheck.c deleted file mode 100644 index b063e5d4..00000000 --- a/vendor/hydra/vendor/curl/lib/speedcheck.c +++ /dev/null @@ -1,80 +0,0 @@ -/*************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ - * \___|\___/|_| \_\_____| - * - * Copyright (C) Daniel Stenberg, , et al. - * - * This software is licensed as described in the file COPYING, which - * you should have received as part of this distribution. The terms - * are also available at https://curl.se/docs/copyright.html. - * - * You may opt to use, copy, modify, merge, publish, distribute and/or sell - * copies of the Software, and permit persons to whom the Software is - * furnished to do so, under the terms of the COPYING file. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - * SPDX-License-Identifier: curl - * - ***************************************************************************/ - -#include "curl_setup.h" - -#include -#include "urldata.h" -#include "sendf.h" -#include "transfer.h" -#include "multiif.h" -#include "speedcheck.h" - -void Curl_speedinit(struct Curl_easy *data) -{ - memset(&data->state.keeps_speed, 0, sizeof(struct curltime)); -} - -/* - * @unittest: 1606 - */ -CURLcode Curl_speedcheck(struct Curl_easy *data, - struct curltime now) -{ - if(Curl_xfer_recv_is_paused(data)) - /* A paused transfer is not qualified for speed checks */ - return CURLE_OK; - - if((data->progress.current_speed >= 0) && data->set.low_speed_time) { - if(data->progress.current_speed < data->set.low_speed_limit) { - if(!data->state.keeps_speed.tv_sec) - /* under the limit at this very moment */ - data->state.keeps_speed = now; - else { - /* how long has it been under the limit */ - timediff_t howlong = curlx_timediff(now, data->state.keeps_speed); - - if(howlong >= data->set.low_speed_time * 1000) { - /* too long */ - failf(data, - "Operation too slow. " - "Less than %ld bytes/sec transferred the last %ld seconds", - data->set.low_speed_limit, - data->set.low_speed_time); - return CURLE_OPERATION_TIMEDOUT; - } - } - } - else - /* faster right now */ - data->state.keeps_speed.tv_sec = 0; - } - - if(data->set.low_speed_limit) - /* if low speed limit is enabled, set the expire timer to make this - connection's speed get checked again in a second */ - Curl_expire(data, 1000, EXPIRE_SPEEDCHECK); - - return CURLE_OK; -} diff --git a/vendor/hydra/vendor/curl/lib/speedcheck.h b/vendor/hydra/vendor/curl/lib/speedcheck.h deleted file mode 100644 index f54365ca..00000000 --- a/vendor/hydra/vendor/curl/lib/speedcheck.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef HEADER_CURL_SPEEDCHECK_H -#define HEADER_CURL_SPEEDCHECK_H -/*************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ - * \___|\___/|_| \_\_____| - * - * Copyright (C) Daniel Stenberg, , et al. - * - * This software is licensed as described in the file COPYING, which - * you should have received as part of this distribution. The terms - * are also available at https://curl.se/docs/copyright.html. - * - * You may opt to use, copy, modify, merge, publish, distribute and/or sell - * copies of the Software, and permit persons to whom the Software is - * furnished to do so, under the terms of the COPYING file. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - * SPDX-License-Identifier: curl - * - ***************************************************************************/ - -#include "curl_setup.h" - -#include "curlx/timeval.h" -struct Curl_easy; -void Curl_speedinit(struct Curl_easy *data); -CURLcode Curl_speedcheck(struct Curl_easy *data, - struct curltime now); - -#endif /* HEADER_CURL_SPEEDCHECK_H */ diff --git a/vendor/hydra/vendor/curl/lib/splay.c b/vendor/hydra/vendor/curl/lib/splay.c index 3ca8678b..5e4cd54d 100644 --- a/vendor/hydra/vendor/curl/lib/splay.c +++ b/vendor/hydra/vendor/curl/lib/splay.c @@ -21,10 +21,8 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include "curlx/timeval.h" #include "splay.h" /* @@ -34,13 +32,13 @@ * zero : when i is equal to j * positive when : when i is larger than j */ -#define compare(i,j) curlx_timediff_us(i,j) +#define splay_compare(i, j) curlx_ptimediff_us(i, j) /* * Splay using the key i (which may or may not be in the tree.) The starting * root is t. */ -struct Curl_tree *Curl_splay(struct curltime i, +struct Curl_tree *Curl_splay(const struct curltime *pkey, struct Curl_tree *t) { struct Curl_tree N, *l, *r, *y; @@ -51,11 +49,11 @@ struct Curl_tree *Curl_splay(struct curltime i, l = r = &N; for(;;) { - timediff_t comp = compare(i, t->key); + timediff_t comp = splay_compare(pkey, &t->key); if(comp < 0) { if(!t->smaller) break; - if(compare(i, t->smaller->key) < 0) { + if(splay_compare(pkey, &t->smaller->key) < 0) { y = t->smaller; /* rotate smaller */ t->smaller = y->larger; y->larger = t; @@ -70,7 +68,7 @@ struct Curl_tree *Curl_splay(struct curltime i, else if(comp > 0) { if(!t->larger) break; - if(compare(i, t->larger->key) > 0) { + if(splay_compare(pkey, &t->larger->key) > 0) { y = t->larger; /* rotate larger */ t->larger = y->smaller; y->smaller = t; @@ -103,16 +101,16 @@ static const struct curltime SPLAY_SUBNODE = { * * @unittest: 1309 */ -struct Curl_tree *Curl_splayinsert(struct curltime i, +struct Curl_tree *Curl_splayinsert(const struct curltime *pkey, struct Curl_tree *t, struct Curl_tree *node) { DEBUGASSERT(node); if(t) { - t = Curl_splay(i, t); + t = Curl_splay(pkey, t); DEBUGASSERT(t); - if(compare(i, t->key) == 0) { + if(splay_compare(pkey, &t->key) == 0) { /* There already exists a node in the tree with the same key. Build a doubly-linked circular list of nodes. We add the new 'node' struct to the end of this list. */ @@ -130,18 +128,17 @@ struct Curl_tree *Curl_splayinsert(struct curltime i, if(!t) { node->smaller = node->larger = NULL; } - else if(compare(i, t->key) < 0) { + else if(splay_compare(pkey, &t->key) < 0) { node->smaller = t->smaller; node->larger = t; t->smaller = NULL; - } else { node->larger = t->larger; node->smaller = t; t->larger = NULL; } - node->key = i; + node->key = *pkey; /* no identical nodes (yet), we are the only one in the list of nodes */ node->samen = node; @@ -152,11 +149,11 @@ struct Curl_tree *Curl_splayinsert(struct curltime i, /* Finds and deletes the best-fit node from the tree. Return a pointer to the resulting tree. best-fit means the smallest node if it is not larger than the key */ -struct Curl_tree *Curl_splaygetbest(struct curltime i, +struct Curl_tree *Curl_splaygetbest(const struct curltime *pkey, struct Curl_tree *t, struct Curl_tree **removed) { - static const struct curltime tv_zero = {0, 0}; + static const struct curltime tv_zero = { 0, 0 }; struct Curl_tree *x; if(!t) { @@ -165,9 +162,9 @@ struct Curl_tree *Curl_splaygetbest(struct curltime i, } /* find smallest */ - t = Curl_splay(tv_zero, t); + t = Curl_splay(&tv_zero, t); DEBUGASSERT(t); - if(compare(i, t->key) < 0) { + if(splay_compare(pkey, &t->key) < 0) { /* even the smallest is too big */ *removed = NULL; return t; @@ -197,7 +194,6 @@ struct Curl_tree *Curl_splaygetbest(struct curltime i, return x; } - /* Deletes the node we point out from the tree if it is there. Stores a * pointer to the new resulting tree in 'newroot'. * @@ -220,7 +216,7 @@ int Curl_splayremove(struct Curl_tree *t, DEBUGASSERT(removenode); - if(compare(SPLAY_SUBNODE, removenode->key) == 0) { + if(splay_compare(&SPLAY_SUBNODE, &removenode->key) == 0) { /* It is a subnode within a 'same' linked list and thus we can unlink it easily. */ DEBUGASSERT(removenode->samen != removenode); @@ -238,7 +234,7 @@ int Curl_splayremove(struct Curl_tree *t, return 0; } - t = Curl_splay(removenode->key, t); + t = Curl_splay(&removenode->key, t); DEBUGASSERT(t); /* First make sure that we got the same root node as the one we want @@ -270,7 +266,7 @@ int Curl_splayremove(struct Curl_tree *t, if(!t->smaller) x = t->larger; else { - x = Curl_splay(removenode->key, t->smaller); + x = Curl_splay(&removenode->key, t->smaller); DEBUGASSERT(x); x->larger = t->larger; } diff --git a/vendor/hydra/vendor/curl/lib/splay.h b/vendor/hydra/vendor/curl/lib/splay.h index ccc3781e..9ed96f63 100644 --- a/vendor/hydra/vendor/curl/lib/splay.h +++ b/vendor/hydra/vendor/curl/lib/splay.h @@ -24,6 +24,7 @@ * ***************************************************************************/ #include "curl_setup.h" + #include "curlx/timeval.h" /* only use function calls to access this struct */ @@ -36,14 +37,14 @@ struct Curl_tree { void *ptr; /* data the splay code does not care about */ }; -struct Curl_tree *Curl_splay(struct curltime i, +struct Curl_tree *Curl_splay(const struct curltime *pkey, struct Curl_tree *t); -struct Curl_tree *Curl_splayinsert(struct curltime key, +struct Curl_tree *Curl_splayinsert(const struct curltime *pkey, struct Curl_tree *t, struct Curl_tree *newnode); -struct Curl_tree *Curl_splaygetbest(struct curltime key, +struct Curl_tree *Curl_splaygetbest(const struct curltime *pkey, struct Curl_tree *t, struct Curl_tree **removed); diff --git a/vendor/hydra/vendor/curl/lib/strcase.c b/vendor/hydra/vendor/curl/lib/strcase.c index ee5b9072..34ccae35 100644 --- a/vendor/hydra/vendor/curl/lib/strcase.c +++ b/vendor/hydra/vendor/curl/lib/strcase.c @@ -21,65 +21,66 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include - #include "strcase.h" /* Mapping table to go from lowercase to uppercase for plain ASCII.*/ static const unsigned char touppermap[256] = { -0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, -22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, -41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, -60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, -79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 65, -66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, -85, 86, 87, 88, 89, 90, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, -134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, -150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, -166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, -182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, -198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, -214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, -230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, -246, 247, 248, 249, 250, 251, 252, 253, 254, 255 + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, + 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, + 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, + 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, + 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, + 90, 91, 92, 93, 94, 95, 96, 65, 66, 67, 68, 69, 70, 71, 72, + 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, + 88, 89, 90, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, + 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, + 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, + 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, + 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, + 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, + 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, + 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, + 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, + 255 }; /* Mapping table to go from uppercase to lowercase for plain ASCII.*/ static const unsigned char tolowermap[256] = { -0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, -22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, -42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -62, 63, 64, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, -111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 91, 92, 93, 94, 95, -96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, -112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, -128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, -144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, -160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, -176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, -192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, -208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, -224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, -240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255 + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, + 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, + 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, + 60, 61, 62, 63, 64, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, + 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, + 122, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, + 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, + 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, + 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, + 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, + 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, + 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, + 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, + 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, + 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, + 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, + 255 }; - /* Portable, consistent toupper. Do not use toupper() because its behavior is altered by the current locale. */ char Curl_raw_toupper(char in) { - return (char)touppermap[(unsigned char) in]; + return (char)touppermap[(unsigned char)in]; } - /* Portable, consistent tolower. Do not use tolower() because its behavior is altered by the current locale. */ char Curl_raw_tolower(char in) { - return (char)tolowermap[(unsigned char) in]; + return (char)tolowermap[(unsigned char)in]; } /* Copy an upper case version of the string from src to dest. The @@ -133,7 +134,7 @@ int Curl_timestrcmp(const char *a, const char *b) if(a && b) { while(1) { - match |= a[i]^b[i]; + match |= a[i] ^ b[i]; if(!a[i] || !b[i]) break; i++; diff --git a/vendor/hydra/vendor/curl/lib/strcase.h b/vendor/hydra/vendor/curl/lib/strcase.h index 915c9969..3a7f1267 100644 --- a/vendor/hydra/vendor/curl/lib/strcase.h +++ b/vendor/hydra/vendor/curl/lib/strcase.h @@ -23,15 +23,14 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - -#include +#include "curl_setup.h" char Curl_raw_toupper(char in); char Curl_raw_tolower(char in); /* checkprefix() is a shorter version of the above, used when the first argument is the string literal */ -#define checkprefix(a,b) curl_strnequal(b, STRCONST(a)) +#define checkprefix(a, b) curl_strnequal(b, STRCONST(a)) void Curl_strntoupper(char *dest, const char *src, size_t n); void Curl_strntolower(char *dest, const char *src, size_t n); diff --git a/vendor/hydra/vendor/curl/lib/strdup.c b/vendor/hydra/vendor/curl/lib/strdup.c index 3339e909..f666571e 100644 --- a/vendor/hydra/vendor/curl/lib/strdup.c +++ b/vendor/hydra/vendor/curl/lib/strdup.c @@ -21,20 +21,13 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include - #ifdef _WIN32 #include #endif #include "strdup.h" -#include "curl_memory.h" - -/* The last #include file should be: */ -#include "memdebug.h" #ifndef HAVE_STRDUP char *Curl_strdup(const char *str) @@ -47,7 +40,7 @@ char *Curl_strdup(const char *str) len = strlen(str) + 1; - newstr = malloc(len); + newstr = curlx_malloc(len); if(!newstr) return (char *)NULL; @@ -90,7 +83,7 @@ wchar_t *Curl_wcsdup(const wchar_t *src) ***************************************************************************/ void *Curl_memdup(const void *src, size_t length) { - void *buffer = malloc(length); + void *buffer = curlx_malloc(length); if(!buffer) return NULL; /* fail */ @@ -111,7 +104,7 @@ void *Curl_memdup(const void *src, size_t length) ***************************************************************************/ void *Curl_memdup0(const char *src, size_t length) { - char *buf = (length < SIZE_MAX) ? malloc(length + 1) : NULL; + char *buf = (length < SIZE_MAX) ? curlx_malloc(length + 1) : NULL; if(!buf) return NULL; if(length) { @@ -126,7 +119,7 @@ void *Curl_memdup0(const char *src, size_t length) * * Curl_saferealloc(ptr, size) * - * Does a normal realloc(), but will free the data pointer if the realloc + * Does a normal curlx_realloc(), but will free the data pointer if the realloc * fails. If 'size' is non-zero, it will free the data and return a failure. * * This convenience function is provided and used to help us avoid a common @@ -138,9 +131,9 @@ void *Curl_memdup0(const char *src, size_t length) ***************************************************************************/ void *Curl_saferealloc(void *ptr, size_t size) { - void *datap = realloc(ptr, size); + void *datap = curlx_realloc(ptr, size); if(size && !datap) /* only free 'ptr' if size was non-zero */ - free(ptr); + curlx_free(ptr); return datap; } diff --git a/vendor/hydra/vendor/curl/lib/strdup.h b/vendor/hydra/vendor/curl/lib/strdup.h index 238a2611..cd01ffbd 100644 --- a/vendor/hydra/vendor/curl/lib/strdup.h +++ b/vendor/hydra/vendor/curl/lib/strdup.h @@ -29,10 +29,9 @@ char *Curl_strdup(const char *str); #endif #ifdef _WIN32 -wchar_t* Curl_wcsdup(const wchar_t* src); +wchar_t *Curl_wcsdup(const wchar_t *src); #endif void *Curl_memdup(const void *src, size_t buffer_length); void *Curl_saferealloc(void *ptr, size_t size); void *Curl_memdup0(const char *src, size_t length); - #endif /* HEADER_CURL_STRDUP_H */ diff --git a/vendor/hydra/vendor/curl/lib/strequal.c b/vendor/hydra/vendor/curl/lib/strequal.c index 17dd34b7..98cecdc2 100644 --- a/vendor/hydra/vendor/curl/lib/strequal.c +++ b/vendor/hydra/vendor/curl/lib/strequal.c @@ -21,10 +21,8 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include #include "strcase.h" /* diff --git a/vendor/hydra/vendor/curl/lib/strerror.c b/vendor/hydra/vendor/curl/lib/strerror.c index 5b82d7f9..b281b188 100644 --- a/vendor/hydra/vendor/curl/lib/strerror.c +++ b/vendor/hydra/vendor/curl/lib/strerror.c @@ -21,25 +21,17 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include -#include - #ifdef USE_WINDOWS_SSPI #include "curl_sspi.h" #endif #include "curlx/winapi.h" #include "strerror.h" +#include "curlx/strcopy.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - -const char * -curl_easy_strerror(CURLcode error) +const char *curl_easy_strerror(CURLcode error) { #ifndef CURL_DISABLE_VERBOSE_STRINGS switch(error) { @@ -57,7 +49,7 @@ curl_easy_strerror(CURLcode error) case CURLE_NOT_BUILT_IN: return "A requested feature, protocol or option was not found built-in in" - " this libcurl due to a build-time decision."; + " this libcurl due to a build-time decision."; case CURLE_COULDNT_RESOLVE_PROXY: return "Could not resolve proxy name"; @@ -331,8 +323,7 @@ curl_easy_strerror(CURLcode error) #endif } -const char * -curl_multi_strerror(CURLMcode error) +const char *curl_multi_strerror(CURLMcode error) { #ifndef CURL_DISABLE_VERBOSE_STRINGS switch(error) { @@ -391,8 +382,7 @@ curl_multi_strerror(CURLMcode error) #endif } -const char * -curl_share_strerror(CURLSHcode error) +const char *curl_share_strerror(CURLSHcode error) { #ifndef CURL_DISABLE_VERBOSE_STRINGS switch(error) { @@ -427,8 +417,7 @@ curl_share_strerror(CURLSHcode error) #endif } -const char * -curl_url_strerror(CURLUcode error) +const char *curl_url_strerror(CURLUcode error) { #ifndef CURL_DISABLE_VERBOSE_STRINGS switch(error) { @@ -562,96 +551,96 @@ const char *Curl_sspi_strerror(SECURITY_STATUS err, char *buf, size_t buflen) #ifndef CURL_DISABLE_VERBOSE_STRINGS switch(err) { - case SEC_E_OK: - txt = "No error"; - break; + case SEC_E_OK: + txt = "No error"; + break; #define SEC2TXT(sec) case sec: txt = #sec; break - SEC2TXT(CRYPT_E_REVOKED); - SEC2TXT(CRYPT_E_NO_REVOCATION_DLL); - SEC2TXT(CRYPT_E_NO_REVOCATION_CHECK); - SEC2TXT(CRYPT_E_REVOCATION_OFFLINE); - SEC2TXT(CRYPT_E_NOT_IN_REVOCATION_DATABASE); - SEC2TXT(SEC_E_ALGORITHM_MISMATCH); - SEC2TXT(SEC_E_BAD_BINDINGS); - SEC2TXT(SEC_E_BAD_PKGID); - SEC2TXT(SEC_E_BUFFER_TOO_SMALL); - SEC2TXT(SEC_E_CANNOT_INSTALL); - SEC2TXT(SEC_E_CANNOT_PACK); - SEC2TXT(SEC_E_CERT_EXPIRED); - SEC2TXT(SEC_E_CERT_UNKNOWN); - SEC2TXT(SEC_E_CERT_WRONG_USAGE); - SEC2TXT(SEC_E_CONTEXT_EXPIRED); - SEC2TXT(SEC_E_CROSSREALM_DELEGATION_FAILURE); - SEC2TXT(SEC_E_CRYPTO_SYSTEM_INVALID); - SEC2TXT(SEC_E_DECRYPT_FAILURE); - SEC2TXT(SEC_E_DELEGATION_POLICY); - SEC2TXT(SEC_E_DELEGATION_REQUIRED); - SEC2TXT(SEC_E_DOWNGRADE_DETECTED); - SEC2TXT(SEC_E_ENCRYPT_FAILURE); - SEC2TXT(SEC_E_ILLEGAL_MESSAGE); - SEC2TXT(SEC_E_INCOMPLETE_CREDENTIALS); - SEC2TXT(SEC_E_INCOMPLETE_MESSAGE); - SEC2TXT(SEC_E_INSUFFICIENT_MEMORY); - SEC2TXT(SEC_E_INTERNAL_ERROR); - SEC2TXT(SEC_E_INVALID_HANDLE); - SEC2TXT(SEC_E_INVALID_PARAMETER); - SEC2TXT(SEC_E_INVALID_TOKEN); - SEC2TXT(SEC_E_ISSUING_CA_UNTRUSTED); - SEC2TXT(SEC_E_ISSUING_CA_UNTRUSTED_KDC); - SEC2TXT(SEC_E_KDC_CERT_EXPIRED); - SEC2TXT(SEC_E_KDC_CERT_REVOKED); - SEC2TXT(SEC_E_KDC_INVALID_REQUEST); - SEC2TXT(SEC_E_KDC_UNABLE_TO_REFER); - SEC2TXT(SEC_E_KDC_UNKNOWN_ETYPE); - SEC2TXT(SEC_E_LOGON_DENIED); - SEC2TXT(SEC_E_MAX_REFERRALS_EXCEEDED); - SEC2TXT(SEC_E_MESSAGE_ALTERED); - SEC2TXT(SEC_E_MULTIPLE_ACCOUNTS); - SEC2TXT(SEC_E_MUST_BE_KDC); - SEC2TXT(SEC_E_NOT_OWNER); - SEC2TXT(SEC_E_NO_AUTHENTICATING_AUTHORITY); - SEC2TXT(SEC_E_NO_CREDENTIALS); - SEC2TXT(SEC_E_NO_IMPERSONATION); - SEC2TXT(SEC_E_NO_IP_ADDRESSES); - SEC2TXT(SEC_E_NO_KERB_KEY); - SEC2TXT(SEC_E_NO_PA_DATA); - SEC2TXT(SEC_E_NO_S4U_PROT_SUPPORT); - SEC2TXT(SEC_E_NO_TGT_REPLY); - SEC2TXT(SEC_E_OUT_OF_SEQUENCE); - SEC2TXT(SEC_E_PKINIT_CLIENT_FAILURE); - SEC2TXT(SEC_E_PKINIT_NAME_MISMATCH); - SEC2TXT(SEC_E_POLICY_NLTM_ONLY); - SEC2TXT(SEC_E_QOP_NOT_SUPPORTED); - SEC2TXT(SEC_E_REVOCATION_OFFLINE_C); - SEC2TXT(SEC_E_REVOCATION_OFFLINE_KDC); - SEC2TXT(SEC_E_SECPKG_NOT_FOUND); - SEC2TXT(SEC_E_SECURITY_QOS_FAILED); - SEC2TXT(SEC_E_SHUTDOWN_IN_PROGRESS); - SEC2TXT(SEC_E_SMARTCARD_CERT_EXPIRED); - SEC2TXT(SEC_E_SMARTCARD_CERT_REVOKED); - SEC2TXT(SEC_E_SMARTCARD_LOGON_REQUIRED); - SEC2TXT(SEC_E_STRONG_CRYPTO_NOT_SUPPORTED); - SEC2TXT(SEC_E_TARGET_UNKNOWN); - SEC2TXT(SEC_E_TIME_SKEW); - SEC2TXT(SEC_E_TOO_MANY_PRINCIPALS); - SEC2TXT(SEC_E_UNFINISHED_CONTEXT_DELETED); - SEC2TXT(SEC_E_UNKNOWN_CREDENTIALS); - SEC2TXT(SEC_E_UNSUPPORTED_FUNCTION); - SEC2TXT(SEC_E_UNSUPPORTED_PREAUTH); - SEC2TXT(SEC_E_UNTRUSTED_ROOT); - SEC2TXT(SEC_E_WRONG_CREDENTIAL_HANDLE); - SEC2TXT(SEC_E_WRONG_PRINCIPAL); - SEC2TXT(SEC_I_COMPLETE_AND_CONTINUE); - SEC2TXT(SEC_I_COMPLETE_NEEDED); - SEC2TXT(SEC_I_CONTEXT_EXPIRED); - SEC2TXT(SEC_I_CONTINUE_NEEDED); - SEC2TXT(SEC_I_INCOMPLETE_CREDENTIALS); - SEC2TXT(SEC_I_LOCAL_LOGON); - SEC2TXT(SEC_I_NO_LSA_CONTEXT); - SEC2TXT(SEC_I_RENEGOTIATE); - SEC2TXT(SEC_I_SIGNATURE_NEEDED); - default: - txt = "Unknown error"; + SEC2TXT(CRYPT_E_REVOKED); + SEC2TXT(CRYPT_E_NO_REVOCATION_DLL); + SEC2TXT(CRYPT_E_NO_REVOCATION_CHECK); + SEC2TXT(CRYPT_E_REVOCATION_OFFLINE); + SEC2TXT(CRYPT_E_NOT_IN_REVOCATION_DATABASE); + SEC2TXT(SEC_E_ALGORITHM_MISMATCH); + SEC2TXT(SEC_E_BAD_BINDINGS); + SEC2TXT(SEC_E_BAD_PKGID); + SEC2TXT(SEC_E_BUFFER_TOO_SMALL); + SEC2TXT(SEC_E_CANNOT_INSTALL); + SEC2TXT(SEC_E_CANNOT_PACK); + SEC2TXT(SEC_E_CERT_EXPIRED); + SEC2TXT(SEC_E_CERT_UNKNOWN); + SEC2TXT(SEC_E_CERT_WRONG_USAGE); + SEC2TXT(SEC_E_CONTEXT_EXPIRED); + SEC2TXT(SEC_E_CROSSREALM_DELEGATION_FAILURE); + SEC2TXT(SEC_E_CRYPTO_SYSTEM_INVALID); + SEC2TXT(SEC_E_DECRYPT_FAILURE); + SEC2TXT(SEC_E_DELEGATION_POLICY); + SEC2TXT(SEC_E_DELEGATION_REQUIRED); + SEC2TXT(SEC_E_DOWNGRADE_DETECTED); + SEC2TXT(SEC_E_ENCRYPT_FAILURE); + SEC2TXT(SEC_E_ILLEGAL_MESSAGE); + SEC2TXT(SEC_E_INCOMPLETE_CREDENTIALS); + SEC2TXT(SEC_E_INCOMPLETE_MESSAGE); + SEC2TXT(SEC_E_INSUFFICIENT_MEMORY); + SEC2TXT(SEC_E_INTERNAL_ERROR); + SEC2TXT(SEC_E_INVALID_HANDLE); + SEC2TXT(SEC_E_INVALID_PARAMETER); + SEC2TXT(SEC_E_INVALID_TOKEN); + SEC2TXT(SEC_E_ISSUING_CA_UNTRUSTED); + SEC2TXT(SEC_E_ISSUING_CA_UNTRUSTED_KDC); + SEC2TXT(SEC_E_KDC_CERT_EXPIRED); + SEC2TXT(SEC_E_KDC_CERT_REVOKED); + SEC2TXT(SEC_E_KDC_INVALID_REQUEST); + SEC2TXT(SEC_E_KDC_UNABLE_TO_REFER); + SEC2TXT(SEC_E_KDC_UNKNOWN_ETYPE); + SEC2TXT(SEC_E_LOGON_DENIED); + SEC2TXT(SEC_E_MAX_REFERRALS_EXCEEDED); + SEC2TXT(SEC_E_MESSAGE_ALTERED); + SEC2TXT(SEC_E_MULTIPLE_ACCOUNTS); + SEC2TXT(SEC_E_MUST_BE_KDC); + SEC2TXT(SEC_E_NOT_OWNER); + SEC2TXT(SEC_E_NO_AUTHENTICATING_AUTHORITY); + SEC2TXT(SEC_E_NO_CREDENTIALS); + SEC2TXT(SEC_E_NO_IMPERSONATION); + SEC2TXT(SEC_E_NO_IP_ADDRESSES); + SEC2TXT(SEC_E_NO_KERB_KEY); + SEC2TXT(SEC_E_NO_PA_DATA); + SEC2TXT(SEC_E_NO_S4U_PROT_SUPPORT); + SEC2TXT(SEC_E_NO_TGT_REPLY); + SEC2TXT(SEC_E_OUT_OF_SEQUENCE); + SEC2TXT(SEC_E_PKINIT_CLIENT_FAILURE); + SEC2TXT(SEC_E_PKINIT_NAME_MISMATCH); + SEC2TXT(SEC_E_POLICY_NLTM_ONLY); + SEC2TXT(SEC_E_QOP_NOT_SUPPORTED); + SEC2TXT(SEC_E_REVOCATION_OFFLINE_C); + SEC2TXT(SEC_E_REVOCATION_OFFLINE_KDC); + SEC2TXT(SEC_E_SECPKG_NOT_FOUND); + SEC2TXT(SEC_E_SECURITY_QOS_FAILED); + SEC2TXT(SEC_E_SHUTDOWN_IN_PROGRESS); + SEC2TXT(SEC_E_SMARTCARD_CERT_EXPIRED); + SEC2TXT(SEC_E_SMARTCARD_CERT_REVOKED); + SEC2TXT(SEC_E_SMARTCARD_LOGON_REQUIRED); + SEC2TXT(SEC_E_STRONG_CRYPTO_NOT_SUPPORTED); + SEC2TXT(SEC_E_TARGET_UNKNOWN); + SEC2TXT(SEC_E_TIME_SKEW); + SEC2TXT(SEC_E_TOO_MANY_PRINCIPALS); + SEC2TXT(SEC_E_UNFINISHED_CONTEXT_DELETED); + SEC2TXT(SEC_E_UNKNOWN_CREDENTIALS); + SEC2TXT(SEC_E_UNSUPPORTED_FUNCTION); + SEC2TXT(SEC_E_UNSUPPORTED_PREAUTH); + SEC2TXT(SEC_E_UNTRUSTED_ROOT); + SEC2TXT(SEC_E_WRONG_CREDENTIAL_HANDLE); + SEC2TXT(SEC_E_WRONG_PRINCIPAL); + SEC2TXT(SEC_I_COMPLETE_AND_CONTINUE); + SEC2TXT(SEC_I_COMPLETE_NEEDED); + SEC2TXT(SEC_I_CONTEXT_EXPIRED); + SEC2TXT(SEC_I_CONTINUE_NEEDED); + SEC2TXT(SEC_I_INCOMPLETE_CREDENTIALS); + SEC2TXT(SEC_I_LOCAL_LOGON); + SEC2TXT(SEC_I_NO_LSA_CONTEXT); + SEC2TXT(SEC_I_RENEGOTIATE); + SEC2TXT(SEC_I_SIGNATURE_NEEDED); + default: + txt = "Unknown error"; } if(err == SEC_E_ILLEGAL_MESSAGE) { @@ -674,12 +663,11 @@ const char *Curl_sspi_strerror(SECURITY_STATUS err, char *buf, size_t buflen) txt = "No error"; else txt = "Error"; - if(buflen > strlen(txt)) - strcpy(buf, txt); + curlx_strcopy(buf, buflen, txt, strlen(txt)); #endif if(errno != old_errno) - CURL_SETERRNO(old_errno); + errno = old_errno; #ifdef _WIN32 if(old_win_err != GetLastError()) diff --git a/vendor/hydra/vendor/curl/lib/strerror.h b/vendor/hydra/vendor/curl/lib/strerror.h index c52503ed..4b9779ff 100644 --- a/vendor/hydra/vendor/curl/lib/strerror.h +++ b/vendor/hydra/vendor/curl/lib/strerror.h @@ -23,6 +23,7 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ +#include "curl_setup.h" #ifdef USE_WINDOWS_SSPI const char *Curl_sspi_strerror(SECURITY_STATUS err, char *buf, size_t buflen); diff --git a/vendor/hydra/vendor/curl/lib/system_win32.c b/vendor/hydra/vendor/curl/lib/system_win32.c index cd01fd2e..0e03e7cd 100644 --- a/vendor/hydra/vendor/curl/lib/system_win32.c +++ b/vendor/hydra/vendor/curl/lib/system_win32.c @@ -21,20 +21,13 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifdef _WIN32 -#include #include "system_win32.h" #include "curlx/version_win32.h" #include "curl_sspi.h" -#include "curlx/warnless.h" - -/* The last #include files should be: */ -#include "curl_memory.h" -#include "memdebug.h" #ifndef HAVE_IF_NAMETOINDEX /* Handle of iphlpapp.dll */ @@ -74,7 +67,7 @@ CURLcode Curl_win32_init(long flags) /* highest supported version. */ if(LOBYTE(wsaData.wVersion) != LOBYTE(wVersionRequested) || - HIBYTE(wsaData.wVersion) != HIBYTE(wVersionRequested) ) { + HIBYTE(wsaData.wVersion) != HIBYTE(wVersionRequested)) { /* Tell the user that we could not find a usable */ /* winsock.dll. */ @@ -99,15 +92,9 @@ CURLcode Curl_win32_init(long flags) s_hIpHlpApiDll = curl_load_library(TEXT("iphlpapi.dll")); if(s_hIpHlpApiDll) { /* Get the address of the if_nametoindex function */ -#ifdef UNDER_CE - #define CURL_TEXT(n) TEXT(n) -#else - #define CURL_TEXT(n) (n) -#endif IF_NAMETOINDEX_FN pIfNameToIndex = CURLX_FUNCTION_CAST(IF_NAMETOINDEX_FN, - GetProcAddress(s_hIpHlpApiDll, - CURL_TEXT("if_nametoindex"))); + GetProcAddress(s_hIpHlpApiDll, "if_nametoindex")); if(pIfNameToIndex) Curl_if_nametoindex = pIfNameToIndex; @@ -164,13 +151,9 @@ typedef HMODULE (APIENTRY *LOADLIBRARYEX_FN)(LPCTSTR, HANDLE, DWORD); /* See function definitions in winbase.h */ #ifdef UNICODE -# ifdef UNDER_CE -# define LOADLIBARYEX L"LoadLibraryExW" -# else -# define LOADLIBARYEX "LoadLibraryExW" -# endif +# define LOADLIBARYEX "LoadLibraryExW" #else -# define LOADLIBARYEX "LoadLibraryExA" +# define LOADLIBARYEX "LoadLibraryExA" #endif /* @@ -189,7 +172,7 @@ typedef HMODULE (APIENTRY *LOADLIBRARYEX_FN)(LPCTSTR, HANDLE, DWORD); */ static HMODULE curl_load_library(LPCTSTR filename) { -#if !defined(CURL_WINDOWS_UWP) && !defined(UNDER_CE) +#ifndef CURL_WINDOWS_UWP HMODULE hModule = NULL; LOADLIBRARYEX_FN pLoadLibraryEx = NULL; @@ -228,7 +211,8 @@ static HMODULE curl_load_library(LPCTSTR filename) /* Allocate space for the full DLL path (Room for the null-terminator is included in systemdirlen) */ size_t filenamelen = _tcslen(filename); - TCHAR *path = malloc(sizeof(TCHAR) * (systemdirlen + 1 + filenamelen)); + TCHAR *path = curlx_malloc(sizeof(TCHAR) * + (systemdirlen + 1 + filenamelen)); if(path && GetSystemDirectory(path, systemdirlen)) { /* Calculate the full DLL path */ _tcscpy(path + _tcslen(path), TEXT("\\")); @@ -240,7 +224,7 @@ static HMODULE curl_load_library(LPCTSTR filename) pLoadLibraryEx(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH) : LoadLibrary(path); } - free(path); + curlx_free(path); } } return hModule; diff --git a/vendor/hydra/vendor/curl/lib/system_win32.h b/vendor/hydra/vendor/curl/lib/system_win32.h index 6bf89d3d..c7df2a5c 100644 --- a/vendor/hydra/vendor/curl/lib/system_win32.h +++ b/vendor/hydra/vendor/curl/lib/system_win32.h @@ -23,13 +23,10 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifdef _WIN32 -#include - extern LARGE_INTEGER Curl_freq; extern bool Curl_isVistaOrGreater; @@ -43,8 +40,8 @@ typedef unsigned int(WINAPI *IF_NAMETOINDEX_FN)(const char *); /* This is used instead of if_nametoindex if available on Windows */ extern IF_NAMETOINDEX_FN Curl_if_nametoindex; #endif -#else /* _WIN32 */ +#else /* !_WIN32 */ #define Curl_win32_init(x) CURLE_OK -#endif /* !_WIN32 */ +#endif /* _WIN32 */ #endif /* HEADER_CURL_SYSTEM_WIN32_H */ diff --git a/vendor/hydra/vendor/curl/lib/telnet.c b/vendor/hydra/vendor/curl/lib/telnet.c index 5c25bc2e..cca97cfc 100644 --- a/vendor/hydra/vendor/curl/lib/telnet.c +++ b/vendor/hydra/vendor/curl/lib/telnet.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifndef CURL_DISABLE_TELNET @@ -48,45 +47,39 @@ #include "urldata.h" #include "url.h" -#include #include "transfer.h" #include "sendf.h" +#include "curl_trc.h" #include "telnet.h" #include "connect.h" #include "progress.h" -#include "system_win32.h" #include "arpa_telnet.h" #include "select.h" -#include "curlx/warnless.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #define SUBBUFSIZE 512 -#define CURL_SB_CLEAR(x) x->subpointer = x->subbuffer -#define CURL_SB_TERM(x) \ - do { \ - x->subend = x->subpointer; \ - CURL_SB_CLEAR(x); \ +#define CURL_SB_CLEAR(x) x->subpointer = x->subbuffer +#define CURL_SB_TERM(x) \ + do { \ + x->subend = x->subpointer; \ + CURL_SB_CLEAR(x); \ } while(0) -#define CURL_SB_ACCUM(x,c) \ - do { \ - if(x->subpointer < (x->subbuffer + sizeof(x->subbuffer))) \ - *x->subpointer++ = (c); \ +#define CURL_SB_ACCUM(x, c) \ + do { \ + if(x->subpointer < (x->subbuffer + sizeof(x->subbuffer))) \ + *x->subpointer++ = (c); \ } while(0) -#define CURL_SB_GET(x) ((*x->subpointer++)&0xff) -#define CURL_SB_LEN(x) (x->subend - x->subpointer) +#define CURL_SB_GET(x) ((*x->subpointer++) & 0xff) +#define CURL_SB_LEN(x) (x->subend - x->subpointer) /* For posterity: #define CURL_SB_PEEK(x) ((*x->subpointer)&0xff) #define CURL_SB_EOF(x) (x->subpointer >= x->subend) */ #ifdef CURL_DISABLE_VERBOSE_STRINGS -#define printoption(a,b,c,d) Curl_nop_stmt +#define printoption(a, b, c, d) Curl_nop_stmt #endif /* For negotiation compliant to RFC 1143 */ @@ -98,15 +91,13 @@ #define CURL_EMPTY 0 #define CURL_OPPOSITE 1 - /* meta key for storing protocol meta at easy handle */ #define CURL_META_TELNET_EASY "meta:proto:telnet:easy" /* * Telnet receiver states for fsm */ -typedef enum -{ +typedef enum { CURL_TS_DATA = 0, CURL_TS_IAC, CURL_TS_WILL, @@ -141,12 +132,12 @@ struct TELNET { unsigned char *subpointer, *subend; /* buffer for sub-options */ }; - -static -CURLcode telrcv(struct Curl_easy *data, - struct TELNET *tn, - const unsigned char *inbuf, /* Data received from socket */ - ssize_t count); /* Number of bytes received */ +static CURLcode telrcv(struct Curl_easy *data, + struct TELNET *tn, + const unsigned char *inbuf, /* Data received from + socket */ + ssize_t count); /* Number of bytes + received */ #ifndef CURL_DISABLE_VERBOSE_STRINGS static void printoption(struct Curl_easy *data, @@ -203,7 +194,6 @@ const struct Curl_handler Curl_handler_telnet = { PROTOPT_NONE | PROTOPT_NOURLQUERY /* flags */ }; - static void telnet_easy_dtor(void *key, size_t klen, void *entry) { struct TELNET *tn = entry; @@ -211,15 +201,14 @@ static void telnet_easy_dtor(void *key, size_t klen, void *entry) (void)klen; curl_slist_free_all(tn->telnet_vars); curlx_dyn_free(&tn->out); - free(tn); + curlx_free(tn); } -static -CURLcode init_telnet(struct Curl_easy *data) +static CURLcode init_telnet(struct Curl_easy *data) { struct TELNET *tn; - tn = calloc(1, sizeof(struct TELNET)); + tn = curlx_calloc(1, sizeof(struct TELNET)); if(!tn) return CURLE_OUT_OF_MEMORY; @@ -332,15 +321,14 @@ static void send_negotiation(struct Curl_easy *data, int cmd, int option) bytes_written = swrite(conn->sock[FIRSTSOCKET], buf, 3); if(bytes_written < 0) { int err = SOCKERRNO; - failf(data,"Sending data failed (%d)",err); + failf(data, "Sending data failed (%d)", err); } printoption(data, "SENT", cmd, option); } -static -void set_remote_option(struct Curl_easy *data, struct TELNET *tn, - int option, int newstate) +static void set_remote_option(struct Curl_easy *data, struct TELNET *tn, + int option, int newstate) { if(newstate == CURL_YES) { switch(tn->him[option]) { @@ -412,8 +400,7 @@ void set_remote_option(struct Curl_easy *data, struct TELNET *tn, } } -static -void rec_will(struct Curl_easy *data, struct TELNET *tn, int option) +static void rec_will(struct Curl_easy *data, struct TELNET *tn, int option) { switch(tn->him[option]) { case CURL_NO: @@ -459,8 +446,7 @@ void rec_will(struct Curl_easy *data, struct TELNET *tn, int option) } } -static -void rec_wont(struct Curl_easy *data, struct TELNET *tn, int option) +static void rec_wont(struct Curl_easy *data, struct TELNET *tn, int option) { switch(tn->him[option]) { case CURL_NO: @@ -500,9 +486,8 @@ void rec_wont(struct Curl_easy *data, struct TELNET *tn, int option) } } -static void -set_local_option(struct Curl_easy *data, struct TELNET *tn, - int option, int newstate) +static void set_local_option(struct Curl_easy *data, struct TELNET *tn, + int option, int newstate) { if(newstate == CURL_YES) { switch(tn->us[option]) { @@ -574,8 +559,7 @@ set_local_option(struct Curl_easy *data, struct TELNET *tn, } } -static -void rec_do(struct Curl_easy *data, struct TELNET *tn, int option) +static void rec_do(struct Curl_easy *data, struct TELNET *tn, int option) { switch(tn->us[option]) { case CURL_NO: @@ -633,8 +617,7 @@ void rec_do(struct Curl_easy *data, struct TELNET *tn, int option) } } -static -void rec_dont(struct Curl_easy *data, struct TELNET *tn, int option) +static void rec_dont(struct Curl_easy *data, struct TELNET *tn, int option) { switch(tn->us[option]) { case CURL_NO: @@ -674,7 +657,6 @@ void rec_dont(struct Curl_easy *data, struct TELNET *tn, int option) } } - static void printsub(struct Curl_easy *data, int direction, /* '<' or '>' */ unsigned char *pointer, /* where suboption data is */ @@ -687,8 +669,8 @@ static void printsub(struct Curl_easy *data, if(length >= 3) { int j; - i = pointer[length-2]; - j = pointer[length-1]; + i = pointer[length - 2]; + j = pointer[length - 1]; if(i != CURL_IAC || j != CURL_SE) { infof(data, "(terminated by "); @@ -895,8 +877,10 @@ static CURLcode check_telnet_options(struct Curl_easy *data, case 6: /* To take care or not of the 8th bit in data exchange */ if(curl_strnequal(option, "BINARY", 6)) { - int binary_option = atoi(arg); - if(binary_option != 1) { + const char *p = arg; + curl_off_t binary_option; + if(!curlx_str_number(&p, &binary_option, 1) && + (binary_option != 1)) { tn->us_preferred[CURL_TELOPT_BINARY] = CURL_NO; tn->him_preferred[CURL_TELOPT_BINARY] = CURL_NO; } @@ -952,77 +936,77 @@ static CURLcode suboption(struct Curl_easy *data, struct TELNET *tn) printsub(data, '<', (unsigned char *)tn->subbuffer, CURL_SB_LEN(tn) + 2); switch(CURL_SB_GET(tn)) { - case CURL_TELOPT_TTYPE: - if(bad_option(tn->subopt_ttype)) - return CURLE_BAD_FUNCTION_ARGUMENT; - if(strlen(tn->subopt_ttype) > 1000) { - failf(data, "Tool long telnet TTYPE"); - return CURLE_SEND_ERROR; - } - len = curl_msnprintf((char *)temp, sizeof(temp), "%c%c%c%c%s%c%c", - CURL_IAC, CURL_SB, CURL_TELOPT_TTYPE, - CURL_TELQUAL_IS, tn->subopt_ttype, CURL_IAC, - CURL_SE); - bytes_written = swrite(conn->sock[FIRSTSOCKET], temp, len); + case CURL_TELOPT_TTYPE: + if(bad_option(tn->subopt_ttype)) + return CURLE_BAD_FUNCTION_ARGUMENT; + if(strlen(tn->subopt_ttype) > 1000) { + failf(data, "Tool long telnet TTYPE"); + return CURLE_SEND_ERROR; + } + len = curl_msnprintf((char *)temp, sizeof(temp), "%c%c%c%c%s%c%c", + CURL_IAC, CURL_SB, CURL_TELOPT_TTYPE, + CURL_TELQUAL_IS, tn->subopt_ttype, CURL_IAC, + CURL_SE); + bytes_written = swrite(conn->sock[FIRSTSOCKET], temp, len); - if(bytes_written < 0) { - err = SOCKERRNO; - failf(data, "Sending data failed (%d)", err); - return CURLE_SEND_ERROR; - } - printsub(data, '>', &temp[2], len-2); - break; - case CURL_TELOPT_XDISPLOC: - if(bad_option(tn->subopt_xdisploc)) + if(bytes_written < 0) { + err = SOCKERRNO; + failf(data, "Sending data failed (%d)", err); + return CURLE_SEND_ERROR; + } + printsub(data, '>', &temp[2], len-2); + break; + case CURL_TELOPT_XDISPLOC: + if(bad_option(tn->subopt_xdisploc)) + return CURLE_BAD_FUNCTION_ARGUMENT; + if(strlen(tn->subopt_xdisploc) > 1000) { + failf(data, "Tool long telnet XDISPLOC"); + return CURLE_SEND_ERROR; + } + len = curl_msnprintf((char *)temp, sizeof(temp), "%c%c%c%c%s%c%c", + CURL_IAC, CURL_SB, CURL_TELOPT_XDISPLOC, + CURL_TELQUAL_IS, tn->subopt_xdisploc, CURL_IAC, + CURL_SE); + bytes_written = swrite(conn->sock[FIRSTSOCKET], temp, len); + if(bytes_written < 0) { + err = SOCKERRNO; + failf(data, "Sending data failed (%d)", err); + return CURLE_SEND_ERROR; + } + printsub(data, '>', &temp[2], len - 2); + break; + case CURL_TELOPT_NEW_ENVIRON: + len = curl_msnprintf((char *)temp, sizeof(temp), "%c%c%c%c", + CURL_IAC, CURL_SB, CURL_TELOPT_NEW_ENVIRON, + CURL_TELQUAL_IS); + for(v = tn->telnet_vars; v; v = v->next) { + size_t tmplen = (strlen(v->data) + 1); + if(bad_option(v->data)) return CURLE_BAD_FUNCTION_ARGUMENT; - if(strlen(tn->subopt_xdisploc) > 1000) { - failf(data, "Tool long telnet XDISPLOC"); - return CURLE_SEND_ERROR; - } - len = curl_msnprintf((char *)temp, sizeof(temp), "%c%c%c%c%s%c%c", - CURL_IAC, CURL_SB, CURL_TELOPT_XDISPLOC, - CURL_TELQUAL_IS, tn->subopt_xdisploc, CURL_IAC, - CURL_SE); - bytes_written = swrite(conn->sock[FIRSTSOCKET], temp, len); - if(bytes_written < 0) { - err = SOCKERRNO; - failf(data,"Sending data failed (%d)",err); - return CURLE_SEND_ERROR; - } - printsub(data, '>', &temp[2], len-2); - break; - case CURL_TELOPT_NEW_ENVIRON: - len = curl_msnprintf((char *)temp, sizeof(temp), "%c%c%c%c", - CURL_IAC, CURL_SB, CURL_TELOPT_NEW_ENVIRON, - CURL_TELQUAL_IS); - for(v = tn->telnet_vars; v; v = v->next) { - size_t tmplen = (strlen(v->data) + 1); - if(bad_option(v->data)) - return CURLE_BAD_FUNCTION_ARGUMENT; - /* Add the variable if it fits */ - if(len + tmplen < (int)sizeof(temp)-6) { - char *s = strchr(v->data, ','); - if(!s) - len += curl_msnprintf((char *)&temp[len], sizeof(temp) - len, - "%c%s", CURL_NEW_ENV_VAR, v->data); - else { - size_t vlen = s - v->data; - len += curl_msnprintf((char *)&temp[len], sizeof(temp) - len, - "%c%.*s%c%s", CURL_NEW_ENV_VAR, - (int)vlen, v->data, CURL_NEW_ENV_VALUE, ++s); - } + /* Add the variable if it fits */ + if(len + tmplen < (int)sizeof(temp) - 6) { + char *s = strchr(v->data, ','); + if(!s) + len += curl_msnprintf((char *)&temp[len], sizeof(temp) - len, + "%c%s", CURL_NEW_ENV_VAR, v->data); + else { + size_t vlen = s - v->data; + len += curl_msnprintf((char *)&temp[len], sizeof(temp) - len, + "%c%.*s%c%s", CURL_NEW_ENV_VAR, + (int)vlen, v->data, CURL_NEW_ENV_VALUE, ++s); } } - curl_msnprintf((char *)&temp[len], sizeof(temp) - len, - "%c%c", CURL_IAC, CURL_SE); - len += 2; - bytes_written = swrite(conn->sock[FIRSTSOCKET], temp, len); - if(bytes_written < 0) { - err = SOCKERRNO; - failf(data,"Sending data failed (%d)",err); - } - printsub(data, '>', &temp[2], len-2); - break; + } + curl_msnprintf((char *)&temp[len], sizeof(temp) - len, + "%c%c", CURL_IAC, CURL_SE); + len += 2; + bytes_written = swrite(conn->sock[FIRSTSOCKET], temp, len); + if(bytes_written < 0) { + err = SOCKERRNO; + failf(data, "Sending data failed (%d)", err); + } + printsub(data, '>', &temp[2], len - 2); + break; } return CURLE_OK; } @@ -1065,7 +1049,7 @@ static void sendsuboption(struct Curl_easy *data, /* data suboption is now ready */ printsub(data, '>', (unsigned char *)tn->subbuffer + 2, - CURL_SB_LEN(tn)-2); + CURL_SB_LEN(tn) - 2); /* we send the header of the suboption... */ bytes_written = swrite(conn->sock[FIRSTSOCKET], tn->subbuffer, 3); @@ -1086,11 +1070,12 @@ static void sendsuboption(struct Curl_easy *data, } } -static -CURLcode telrcv(struct Curl_easy *data, - struct TELNET *tn, - const unsigned char *inbuf, /* Data received from socket */ - ssize_t count) /* Number of bytes received */ +static CURLcode telrcv(struct Curl_easy *data, + struct TELNET *tn, + const unsigned char *inbuf, /* Data received from + socket */ + ssize_t count) /* Number of bytes + received */ { unsigned char c; CURLcode result; @@ -1108,9 +1093,9 @@ CURLcode telrcv(struct Curl_easy *data, } \ startwrite = -1 -#define writebyte() \ - if(startwrite < 0) \ - startwrite = in +#define writebyte() \ + if(startwrite < 0) \ + startwrite = in #define bufferflush() startskipping() @@ -1139,7 +1124,6 @@ CURLcode telrcv(struct Curl_easy *data, break; case CURL_TS_IAC: -process_iac: DEBUGASSERT(startwrite < 0); switch(c) { case CURL_WILL: @@ -1172,79 +1156,67 @@ CURLcode telrcv(struct Curl_easy *data, } break; - case CURL_TS_WILL: - printoption(data, "RCVD", CURL_WILL, c); - tn->please_negotiate = 1; - rec_will(data, tn, c); - tn->telrcv_state = CURL_TS_DATA; - break; + case CURL_TS_WILL: + printoption(data, "RCVD", CURL_WILL, c); + tn->please_negotiate = 1; + rec_will(data, tn, c); + tn->telrcv_state = CURL_TS_DATA; + break; - case CURL_TS_WONT: - printoption(data, "RCVD", CURL_WONT, c); - tn->please_negotiate = 1; - rec_wont(data, tn, c); - tn->telrcv_state = CURL_TS_DATA; - break; + case CURL_TS_WONT: + printoption(data, "RCVD", CURL_WONT, c); + tn->please_negotiate = 1; + rec_wont(data, tn, c); + tn->telrcv_state = CURL_TS_DATA; + break; - case CURL_TS_DO: - printoption(data, "RCVD", CURL_DO, c); - tn->please_negotiate = 1; - rec_do(data, tn, c); - tn->telrcv_state = CURL_TS_DATA; - break; + case CURL_TS_DO: + printoption(data, "RCVD", CURL_DO, c); + tn->please_negotiate = 1; + rec_do(data, tn, c); + tn->telrcv_state = CURL_TS_DATA; + break; - case CURL_TS_DONT: - printoption(data, "RCVD", CURL_DONT, c); - tn->please_negotiate = 1; - rec_dont(data, tn, c); - tn->telrcv_state = CURL_TS_DATA; - break; + case CURL_TS_DONT: + printoption(data, "RCVD", CURL_DONT, c); + tn->please_negotiate = 1; + rec_dont(data, tn, c); + tn->telrcv_state = CURL_TS_DATA; + break; - case CURL_TS_SB: - if(c == CURL_IAC) - tn->telrcv_state = CURL_TS_SE; - else - CURL_SB_ACCUM(tn, c); - break; + case CURL_TS_SB: + if(c == CURL_IAC) + tn->telrcv_state = CURL_TS_SE; + else + CURL_SB_ACCUM(tn, c); + break; - case CURL_TS_SE: - if(c != CURL_SE) { - if(c != CURL_IAC) { - /* - * This is an error. We only expect to get "IAC IAC" or "IAC SE". - * Several things may have happened. An IAC was not doubled, the - * IAC SE was left off, or another option got inserted into the - * suboption are all possibilities. If we assume that the IAC was - * not doubled, and really the IAC SE was left off, we could get - * into an infinite loop here. So, instead, we terminate the - * suboption, and process the partial suboption if we can. - */ - CURL_SB_ACCUM(tn, CURL_IAC); - CURL_SB_ACCUM(tn, c); - tn->subpointer -= 2; - CURL_SB_TERM(tn); - - printoption(data, "In SUBOPTION processing, RCVD", CURL_IAC, c); - result = suboption(data, tn); /* handle sub-option */ - if(result) - return result; - tn->telrcv_state = CURL_TS_IAC; - goto process_iac; - } - CURL_SB_ACCUM(tn, c); - tn->telrcv_state = CURL_TS_SB; - } - else { - CURL_SB_ACCUM(tn, CURL_IAC); - CURL_SB_ACCUM(tn, CURL_SE); - tn->subpointer -= 2; - CURL_SB_TERM(tn); - result = suboption(data, tn); /* handle sub-option */ - if(result) - return result; - tn->telrcv_state = CURL_TS_DATA; + case CURL_TS_SE: + if(c != CURL_SE) { + if(c != CURL_IAC) { + /* + * This is an error. We only expect to get "IAC IAC" or "IAC SE". + * Several things may have happened. An IAC was not doubled, the IAC + * SE was left off, or another option got inserted into the + * suboption are all possibilities. + */ + failf(data, "telnet: suboption error"); + return CURLE_RECV_ERROR; } - break; + CURL_SB_ACCUM(tn, c); + tn->telrcv_state = CURL_TS_SB; + } + else { + CURL_SB_ACCUM(tn, CURL_IAC); + CURL_SB_ACCUM(tn, CURL_SE); + tn->subpointer -= 2; + CURL_SB_TERM(tn); + result = suboption(data, tn); /* handle sub-option */ + if(result) + return result; + tn->telrcv_state = CURL_TS_DATA; + } + break; } ++in; } @@ -1293,16 +1265,16 @@ static CURLcode send_telnet_data(struct Curl_easy *data, pfd[0].fd = conn->sock[FIRSTSOCKET]; pfd[0].events = POLLOUT; switch(Curl_poll(pfd, 1, -1)) { - case -1: /* error, abort writing */ - case 0: /* timeout (will never happen) */ - result = CURLE_SEND_ERROR; - break; - default: /* write! */ - bytes_written = 0; - result = Curl_xfer_send(data, outbuf + total_written, - outlen - total_written, FALSE, &bytes_written); - total_written += bytes_written; - break; + case -1: /* error, abort writing */ + case 0: /* timeout (will never happen) */ + result = CURLE_SEND_ERROR; + break; + default: /* write! */ + bytes_written = 0; + result = Curl_xfer_send(data, outbuf + total_written, + outlen - total_written, FALSE, &bytes_written); + total_written += bytes_written; + break; } } @@ -1328,21 +1300,18 @@ static CURLcode telnet_do(struct Curl_easy *data, bool *done) WSANETWORKEVENTS events; HANDLE stdin_handle; HANDLE objs[2]; - DWORD obj_count; - DWORD wait_timeout; + DWORD obj_count; + DWORD wait_timeout; DWORD readfile_read; int err; #else timediff_t interval_ms; struct pollfd pfd[2]; int poll_cnt; - curl_off_t total_dl = 0; - curl_off_t total_ul = 0; ssize_t snread; #endif - struct curltime now; bool keepon = TRUE; - char buffer[4*1024]; + char buffer[4 * 1024]; struct TELNET *tn; *done = TRUE; /* unconditionally */ @@ -1373,7 +1342,8 @@ static CURLcode telnet_do(struct Curl_easy *data, bool *done) } /* Tell Winsock what events we want to listen to */ - if(WSAEventSelect(sockfd, event_handle, FD_READ|FD_CLOSE) == SOCKET_ERROR) { + if(WSAEventSelect(sockfd, event_handle, FD_READ | FD_CLOSE) == + SOCKET_ERROR) { WSACloseEvent(event_handle); return CURLE_RECV_ERROR; } @@ -1387,8 +1357,7 @@ static CURLcode telnet_do(struct Curl_easy *data, bool *done) /* If stdin_handle is a pipe, use PeekNamedPipe() method to check it, else use the old WaitForMultipleObjects() way */ - if(GetFileType(stdin_handle) == FILE_TYPE_PIPE || - data->set.is_fread_set) { + if(GetFileType(stdin_handle) == FILE_TYPE_PIPE || data->set.is_fread_set) { /* Do not wait for stdin_handle, just wait for event_handle */ obj_count = 1; /* Check stdin_handle per 100 milliseconds */ @@ -1406,8 +1375,7 @@ static CURLcode telnet_do(struct Curl_easy *data, bool *done) FALSE, wait_timeout); switch(waitret) { - case WAIT_TIMEOUT: - { + case WAIT_TIMEOUT: { for(;;) { if(data->set.is_fread_set) { size_t n; @@ -1440,8 +1408,7 @@ static CURLcode telnet_do(struct Curl_easy *data, bool *done) if(!readfile_read) break; - if(!ReadFile(stdin_handle, buffer, buf_size, - &readfile_read, NULL)) { + if(!ReadFile(stdin_handle, buffer, buf_size, &readfile_read, NULL)) { keepon = FALSE; result = CURLE_READ_ERROR; break; @@ -1457,10 +1424,8 @@ static CURLcode telnet_do(struct Curl_easy *data, bool *done) } break; - case WAIT_OBJECT_0 + 1: - { - if(!ReadFile(stdin_handle, buffer, buf_size, - &readfile_read, NULL)) { + case WAIT_OBJECT_0 + 1: { + if(!ReadFile(stdin_handle, buffer, buf_size, &readfile_read, NULL)) { keepon = FALSE; result = CURLE_READ_ERROR; break; @@ -1474,8 +1439,7 @@ static CURLcode telnet_do(struct Curl_easy *data, bool *done) } break; - case WAIT_OBJECT_0: - { + case WAIT_OBJECT_0: { events.lNetworkEvents = 0; if(WSAEnumNetworkEvents(sockfd, event_handle, &events) == SOCKET_ERROR) { err = SOCKERRNO; @@ -1505,7 +1469,7 @@ static CURLcode telnet_do(struct Curl_easy *data, bool *done) break; } - result = telrcv(data, tn, (unsigned char *) buffer, nread); + result = telrcv(data, tn, (unsigned char *)buffer, nread); if(result) { keepon = FALSE; break; @@ -1522,14 +1486,13 @@ static CURLcode telnet_do(struct Curl_easy *data, bool *done) if(events.lNetworkEvents & FD_CLOSE) { keepon = FALSE; } + break; } - break; - - } + } /* switch */ if(data->set.timeout) { - now = curlx_now(); - if(curlx_timediff(now, conn->created) >= data->set.timeout) { + if(curlx_ptimediff_ms(Curl_pgrs_now(data), &conn->created) >= + data->set.timeout) { failf(data, "Time-out"); result = CURLE_OPERATION_TIMEDOUT; keepon = FALSE; @@ -1598,10 +1561,8 @@ static CURLcode telnet_do(struct Curl_easy *data, bool *done) break; } - total_dl += nread; - result = Curl_pgrsSetDownloadCounter(data, total_dl); - if(!result) - result = telrcv(data, tn, (unsigned char *)buffer, nread); + Curl_pgrs_download_inc(data, nread); + result = telrcv(data, tn, (unsigned char *)buffer, nread); if(result) { keepon = FALSE; break; @@ -1625,7 +1586,7 @@ static CURLcode telnet_do(struct Curl_easy *data, bool *done) else { /* read from user-supplied method */ snread = (int)data->state.fread_func(buffer, 1, sizeof(buffer), - data->state.in); + data->state.in); if(snread == CURL_READFUNC_ABORT) { keepon = FALSE; break; @@ -1640,8 +1601,7 @@ static CURLcode telnet_do(struct Curl_easy *data, bool *done) keepon = FALSE; break; } - total_ul += snread; - Curl_pgrsSetUploadCounter(data, total_ul); + Curl_pgrs_upload_inc(data, (size_t)snread); } else if(snread < 0) keepon = FALSE; @@ -1650,17 +1610,18 @@ static CURLcode telnet_do(struct Curl_easy *data, bool *done) } /* poll switch statement */ if(data->set.timeout) { - now = curlx_now(); - if(curlx_timediff(now, conn->created) >= data->set.timeout) { + if(curlx_ptimediff_ms(Curl_pgrs_now(data), &conn->created) >= + data->set.timeout) { failf(data, "Time-out"); result = CURLE_OPERATION_TIMEDOUT; keepon = FALSE; } } - if(Curl_pgrsUpdate(data)) { - result = CURLE_ABORTED_BY_CALLBACK; - break; + if(!result) { + result = Curl_pgrsUpdate(data); + if(result) + keepon = FALSE; } } #endif diff --git a/vendor/hydra/vendor/curl/lib/tftp.c b/vendor/hydra/vendor/curl/lib/tftp.c index d9d978c2..69571bbd 100644 --- a/vendor/hydra/vendor/curl/lib/tftp.c +++ b/vendor/hydra/vendor/curl/lib/tftp.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifndef CURL_DISABLE_TFTP @@ -47,31 +46,26 @@ #endif #include "urldata.h" -#include #include "cfilters.h" #include "cf-socket.h" #include "transfer.h" #include "sendf.h" +#include "curl_trc.h" #include "tftp.h" #include "progress.h" #include "connect.h" #include "sockaddr.h" /* required for Curl_sockaddr_storage */ -#include "multiif.h" #include "url.h" #include "strcase.h" -#include "speedcheck.h" #include "select.h" #include "escape.h" #include "curlx/strerr.h" #include "curlx/strparse.h" - -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" +#include "curlx/strcopy.h" /* RFC2348 allows the block size to be negotiated */ #define TFTP_BLKSIZE_DEFAULT 512 -#define TFTP_OPTION_BLKSIZE "blksize" +#define TFTP_OPTION_BLKSIZE "blksize" /* from RFC2349: */ #define TFTP_OPTION_TSIZE "tsize" @@ -148,7 +142,6 @@ struct tftp_conn { BIT(remote_pinned); }; - /* Forward declarations */ static CURLcode tftp_rx(struct tftp_conn *state, tftp_event_t event); static CURLcode tftp_tx(struct tftp_conn *state, tftp_event_t event); @@ -164,11 +157,9 @@ static CURLcode tftp_pollset(struct Curl_easy *data, struct easy_pollset *ps); static CURLcode tftp_translate_code(tftp_error_t error); - /* * TFTP protocol handler. */ - const struct Curl_handler Curl_handler_tftp = { "tftp", /* scheme */ tftp_setup_connection, /* setup_connection */ @@ -211,7 +202,7 @@ static CURLcode tftp_set_timeouts(struct tftp_conn *state) bool start = (state->state == TFTP_STATE_START); /* Compute drop-dead time */ - timeout_ms = Curl_timeleft(state->data, NULL, start); + timeout_ms = Curl_timeleft_ms(state->data, start); if(timeout_ms < 0) { /* time-out, bail out, go home */ @@ -226,7 +217,7 @@ static CURLcode tftp_set_timeouts(struct tftp_conn *state) timeout = 15; /* Average reposting an ACK after 5 seconds */ - state->retry_max = (int)timeout/5; + state->retry_max = (int)timeout / 5; /* But bound the total number */ if(state->retry_max < 3) @@ -236,12 +227,12 @@ static CURLcode tftp_set_timeouts(struct tftp_conn *state) state->retry_max = 50; /* Compute the re-ACK interval to suit the timeout */ - state->retry_time = (int)(timeout/state->retry_max); + state->retry_time = (int)(timeout / state->retry_max); if(state->retry_time < 1) state->retry_time = 1; infof(state->data, - "set timeouts for state %d; Total % " FMT_OFF_T ", retry %d maxtry %d", + "set timeouts for state %d; Total %" FMT_OFF_T ", retry %d maxtry %d", (int)state->state, timeout_ms, state->retry_time, state->retry_max); /* init RX time */ @@ -264,7 +255,6 @@ static void setpacketevent(struct tftp_packet *packet, unsigned short num) packet->data[1] = (unsigned char)(num & 0xff); } - static void setpacketblock(struct tftp_packet *packet, unsigned short num) { packet->data[2] = (unsigned char)(num >> 8); @@ -284,7 +274,7 @@ static unsigned short getrpacketblock(const struct tftp_packet *packet) static size_t tftp_strnlen(const char *string, size_t maxlen) { const char *end = memchr(string, '\0', maxlen); - return end ? (size_t) (end - string) : maxlen; + return end ? (size_t)(end - string) : maxlen; } static const char *tftp_option_get(const char *buf, size_t len, @@ -299,7 +289,7 @@ static const char *tftp_option_get(const char *buf, size_t len, return NULL; *option = buf; - loc += tftp_strnlen(buf + loc, len-loc); + loc += tftp_strnlen(buf + loc, len - loc); loc++; /* NULL term */ if(loc > len) @@ -379,12 +369,17 @@ static CURLcode tftp_parse_option_ack(struct tftp_conn *state, } static CURLcode tftp_option_add(struct tftp_conn *state, size_t *csize, - char *buf, const char *option) + size_t index, const char *option) { - if(( strlen(option) + *csize + 1) > (size_t)state->blksize) + char *buf = (char *)&state->spacket.data[index]; + size_t oplen = strlen(option); + size_t blen; + if((state->blksize <= index) || + (oplen + 1) > (size_t)(state->blksize - index)) return CURLE_TFTP_ILLEGAL; - strcpy(buf, option); - *csize += strlen(option) + 1; + blen = state->blksize - index; + curlx_strcopy(buf, blen, option, oplen); + *csize += oplen + 1; return CURLE_OK; } @@ -471,14 +466,15 @@ static CURLcode tftp_send_first(struct tftp_conn *state, if(strlen(filename) > (state->blksize - strlen(mode) - 4)) { failf(data, "TFTP filename too long"); - free(filename); + curlx_free(filename); return CURLE_TFTP_ILLEGAL; /* too long filename field */ } curl_msnprintf((char *)state->spacket.data + 2, state->blksize, - "%s%c%s%c", filename, '\0', mode, '\0'); + "%s%c%s%c", filename, '\0', mode, '\0'); sbytes = 4 + strlen(filename) + strlen(mode); + curlx_free(filename); /* optional addition of TFTP options */ if(!data->set.tftp_no_options) { @@ -488,36 +484,26 @@ static CURLcode tftp_send_first(struct tftp_conn *state, data->state.upload && (data->state.infilesize != -1) ? data->state.infilesize : 0); - result = tftp_option_add(state, &sbytes, - (char *)state->spacket.data + sbytes, - TFTP_OPTION_TSIZE); + result = tftp_option_add(state, &sbytes, sbytes, TFTP_OPTION_TSIZE); if(result == CURLE_OK) - result = tftp_option_add(state, &sbytes, - (char *)state->spacket.data + sbytes, buf); + result = tftp_option_add(state, &sbytes, sbytes, buf); /* add blksize option */ curl_msnprintf(buf, sizeof(buf), "%d", state->requested_blksize); if(result == CURLE_OK) - result = tftp_option_add(state, &sbytes, - (char *)state->spacket.data + sbytes, - TFTP_OPTION_BLKSIZE); + result = tftp_option_add(state, &sbytes, sbytes, TFTP_OPTION_BLKSIZE); if(result == CURLE_OK) - result = tftp_option_add(state, &sbytes, - (char *)state->spacket.data + sbytes, buf); + result = tftp_option_add(state, &sbytes, sbytes, buf); /* add timeout option */ curl_msnprintf(buf, sizeof(buf), "%d", state->retry_time); if(result == CURLE_OK) - result = tftp_option_add(state, &sbytes, - (char *)state->spacket.data + sbytes, - TFTP_OPTION_INTERVAL); + result = tftp_option_add(state, &sbytes, sbytes, TFTP_OPTION_INTERVAL); if(result == CURLE_OK) - result = tftp_option_add(state, &sbytes, - (char *)state->spacket.data + sbytes, buf); + result = tftp_option_add(state, &sbytes, sbytes, buf); if(result != CURLE_OK) { failf(data, "TFTP buffer too small for options"); - free(filename); return CURLE_TFTP_ILLEGAL; } } @@ -537,7 +523,6 @@ static CURLcode tftp_send_first(struct tftp_conn *state, (SEND_TYPE_ARG3)sbytes, 0, CURL_SENDTO_ARG5(&remote_addr->curl_sa_addr), (curl_socklen_t)remote_addr->addrlen); - free(filename); if(senddata != (ssize_t)sbytes) { char buffer[STRERROR_LEN]; failf(data, "%s", curlx_strerror(SOCKERRNO, buffer, sizeof(buffer))); @@ -576,7 +561,7 @@ static CURLcode tftp_send_first(struct tftp_conn *state, /* the next blocknum is x + 1 but it needs to wrap at an unsigned 16bit boundary */ -#define NEXT_BLOCKNUM(x) (((x) + 1)&0xffff) +#define NEXT_BLOCKNUM(x) (((x) + 1) & 0xffff) /********************************************************** * @@ -790,7 +775,7 @@ static CURLcode tftp_tx(struct tftp_conn *state, tftp_event_t event) bufptr += cb; } while(state->sbytes < state->blksize && cb); - sbytes = sendto(state->sockfd, (void *) state->spacket.data, + sbytes = sendto(state->sockfd, (void *)state->spacket.data, 4 + (SEND_TYPE_ARG3)state->sbytes, SEND_4TH_ARG, (struct sockaddr *)&state->remote_addr, state->remote_addrlen); @@ -801,7 +786,7 @@ static CURLcode tftp_tx(struct tftp_conn *state, tftp_event_t event) } /* Update the progress meter */ k->writebytecount += state->sbytes; - Curl_pgrsSetUploadCounter(data, k->writebytecount); + Curl_pgrs_upload_inc(data, state->sbytes); break; case TFTP_EVENT_TIMEOUT: @@ -948,7 +933,7 @@ static void tftp_conn_dtor(void *key, size_t klen, void *entry) (void)klen; Curl_safefree(state->rpacket.data); Curl_safefree(state->spacket.data); - free(state); + curlx_free(state); } /********************************************************** @@ -969,7 +954,7 @@ static CURLcode tftp_connect(struct Curl_easy *data, bool *done) blksize = TFTP_BLKSIZE_DEFAULT; - state = calloc(1, sizeof(*state)); + state = curlx_calloc(1, sizeof(*state)); if(!state || Curl_conn_meta_set(conn, CURL_META_TFTP_CONN, state, tftp_conn_dtor)) return CURLE_OUT_OF_MEMORY; @@ -985,14 +970,14 @@ static CURLcode tftp_connect(struct Curl_easy *data, bool *done) need_blksize = TFTP_BLKSIZE_DEFAULT; if(!state->rpacket.data) { - state->rpacket.data = calloc(1, need_blksize + 2 + 2); + state->rpacket.data = curlx_calloc(1, need_blksize + 2 + 2); if(!state->rpacket.data) return CURLE_OUT_OF_MEMORY; } if(!state->spacket.data) { - state->spacket.data = calloc(1, need_blksize + 2 + 2); + state->spacket.data = curlx_calloc(1, need_blksize + 2 + 2); if(!state->spacket.data) return CURLE_OUT_OF_MEMORY; @@ -1142,15 +1127,14 @@ static CURLcode tftp_receive_packet(struct Curl_easy *data, (NEXT_BLOCKNUM(state->block) == getrpacketblock(&state->rpacket))) { result = Curl_client_write(data, CLIENTWRITE_BODY, (char *)state->rpacket.data + 4, - state->rbytes-4); + state->rbytes - 4); if(result) { tftp_state_machine(state, TFTP_EVENT_ERROR); return result; } } break; - case TFTP_EVENT_ERROR: - { + case TFTP_EVENT_ERROR: { unsigned short error = getrpacketblock(&state->rpacket); char *str = (char *)state->rpacket.data + 4; size_t strn = state->rbytes - 4; @@ -1176,9 +1160,10 @@ static CURLcode tftp_receive_packet(struct Curl_easy *data, } /* Update the progress meter */ - if(Curl_pgrsUpdate(data)) { + result = Curl_pgrsUpdate(data); + if(result) { tftp_state_machine(state, TFTP_EVENT_ERROR); - return CURLE_ABORTED_BY_CALLBACK; + return result; } } return result; @@ -1200,8 +1185,8 @@ static timediff_t tftp_state_timeout(struct tftp_conn *state, if(event) *event = TFTP_EVENT_NONE; - timeout_ms = Curl_timeleft(state->data, NULL, - (state->state == TFTP_STATE_START)); + timeout_ms = Curl_timeleft_ms(state->data, + (state->state == TFTP_STATE_START)); if(timeout_ms < 0) { state->error = TFTP_ERR_TIMEOUT; state->state = TFTP_STATE_FIN; @@ -1298,10 +1283,7 @@ static CURLcode tftp_doing(struct Curl_easy *data, bool *dophase_done) /* The multi code does not have this logic for the DOING state so we provide it for TFTP since it may do the entire transfer in this state. */ - if(Curl_pgrsUpdate(data)) - result = CURLE_ABORTED_BY_CALLBACK; - else - result = Curl_speedcheck(data, curlx_now()); + result = Curl_pgrsCheck(data); } return result; } @@ -1336,7 +1318,6 @@ static CURLcode tftp_perform(struct Curl_easy *data, bool *dophase_done) return result; } - /********************************************************** * * tftp_do diff --git a/vendor/hydra/vendor/curl/lib/transfer.c b/vendor/hydra/vendor/curl/lib/transfer.c index 0269a4c2..fed6a178 100644 --- a/vendor/hydra/vendor/curl/lib/transfer.c +++ b/vendor/hydra/vendor/curl/lib/transfer.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifdef HAVE_NETINET_IN_H @@ -39,9 +38,7 @@ #ifdef HAVE_SYS_IOCTL_H #include #endif -#ifndef UNDER_CE #include -#endif #ifdef HAVE_SYS_PARAM_H #include @@ -58,37 +55,27 @@ #endif #include "urldata.h" -#include -#include "netrc.h" -#include "content_encoding.h" #include "hostip.h" #include "cfilters.h" #include "cw-out.h" #include "transfer.h" #include "sendf.h" -#include "speedcheck.h" +#include "curl_trc.h" #include "progress.h" #include "http.h" #include "url.h" #include "getinfo.h" -#include "vtls/vtls.h" -#include "vquic/vquic.h" -#include "select.h" #include "multiif.h" #include "connect.h" -#include "http2.h" #include "mime.h" #include "hsts.h" #include "setopt.h" #include "headers.h" - -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" +#include "bufref.h" #if !defined(CURL_DISABLE_HTTP) || !defined(CURL_DISABLE_SMTP) || \ - !defined(CURL_DISABLE_IMAP) + !defined(CURL_DISABLE_IMAP) /* * checkheaders() checks the linked list of custom headers for a * particular header (prefix). Provide the prefix without colon! @@ -101,11 +88,11 @@ char *Curl_checkheaders(const struct Curl_easy *data, { struct curl_slist *head; DEBUGASSERT(thislen); - DEBUGASSERT(thisheader[thislen-1] != ':'); + DEBUGASSERT(thisheader[thislen - 1] != ':'); for(head = data->set.headers; head; head = head->next) { if(curl_strnequal(head->data, thisheader, thislen) && - Curl_headersep(head->data[thislen]) ) + Curl_headersep(head->data[thislen])) return head->data; } @@ -117,13 +104,13 @@ static int data_pending(struct Curl_easy *data, bool rcvd_eagain) { struct connectdata *conn = data->conn; - if(conn->handler->protocol&PROTO_FAMILY_FTP) + if(conn->handler->protocol & PROTO_FAMILY_FTP) return Curl_conn_data_pending(data, SECONDARYSOCKET); /* in the case of libssh2, we can never be really sure that we have emptied its internal buffers so we MUST always try until we get EAGAIN back */ return (!rcvd_eagain && - conn->handler->protocol&(CURLPROTO_SCP|CURLPROTO_SFTP)) || + conn->handler->protocol & (CURLPROTO_SCP | CURLPROTO_SFTP)) || Curl_conn_data_pending(data, FIRSTSOCKET); } @@ -186,56 +173,46 @@ CURLcode Curl_xfer_send_shutdown(struct Curl_easy *data, bool *done) * @param buf buffer to keep response data received * @param blen length of `buf` * @param eos_reliable if EOS detection in underlying connection is reliable - * @param err error code in case of -1 return * @return number of bytes read or -1 for error */ -static ssize_t xfer_recv_resp(struct Curl_easy *data, - char *buf, size_t blen, - bool eos_reliable, - CURLcode *err) +static CURLcode xfer_recv_resp(struct Curl_easy *data, + char *buf, size_t blen, + bool eos_reliable, + size_t *pnread) { - size_t nread; + CURLcode result; DEBUGASSERT(blen > 0); + *pnread = 0; /* If we are reading BODY data and the connection does NOT handle EOF * and we know the size of the BODY data, limit the read amount */ if(!eos_reliable && !data->req.header && data->req.size != -1) { - curl_off_t totalleft = data->req.size - data->req.bytecount; - if(totalleft <= 0) - blen = 0; - else if(totalleft < (curl_off_t)blen) - blen = (size_t)totalleft; + blen = curlx_sotouz_range(data->req.size - data->req.bytecount, 0, blen); } else if(xfer_recv_shutdown_started(data)) { /* we already received everything. Do not try more. */ blen = 0; } - if(!blen) { - /* want nothing more */ - *err = CURLE_OK; - nread = 0; - } - else { - *err = Curl_xfer_recv(data, buf, blen, &nread); + if(blen) { + result = Curl_xfer_recv(data, buf, blen, pnread); + if(result) + return result; } - if(*err) - return -1; - if(nread == 0) { + if(*pnread == 0) { if(data->req.shutdown) { bool done; - *err = xfer_recv_shutdown(data, &done); - if(*err) - return -1; + result = xfer_recv_shutdown(data, &done); + if(result) + return result; if(!done) { - *err = CURLE_AGAIN; - return -1; + return CURLE_AGAIN; } } DEBUGF(infof(data, "sendrecv_dl: we are done")); } - return (ssize_t)nread; + return CURLE_OK; } /* @@ -251,10 +228,9 @@ static CURLcode sendrecv_dl(struct Curl_easy *data, char *buf, *xfer_buf; size_t blen, xfer_blen; int maxloops = 10; - curl_off_t total_received = 0; bool is_multiplex = FALSE; bool rcvd_eagain = FALSE; - bool is_eos = FALSE; + bool is_eos = FALSE, rate_limited = FALSE; result = Curl_multi_xfer_buf_borrow(data, &xfer_buf, &xfer_blen); if(result) @@ -264,7 +240,6 @@ static CURLcode sendrecv_dl(struct Curl_easy *data, read or we get a CURLE_AGAIN */ do { size_t bytestoread; - ssize_t nread; if(!is_multiplex) { /* Multiplexed connection have inherent handling of EOF and we do not @@ -276,21 +251,27 @@ static CURLcode sendrecv_dl(struct Curl_easy *data, buf = xfer_buf; bytestoread = xfer_blen; - if(bytestoread && data->set.max_recv_speed > 0) { - /* In case of speed limit on receiving: if this loop already got - * a quarter of the quota, break out. We want to stutter a bit - * to keep in the limit, but too small receives will just cost - * cpu unnecessarily. */ - if(total_received && (total_received >= (data->set.max_recv_speed / 4))) + if(bytestoread && Curl_rlimit_active(&data->progress.dl.rlimit)) { + curl_off_t dl_avail = Curl_rlimit_avail(&data->progress.dl.rlimit, + Curl_pgrs_now(data)); + /* DEBUGF(infof(data, "dl_rlimit, available=%" FMT_OFF_T, dl_avail)); + */ + /* In case of rate limited downloads: if this loop already got + * data and less than 16k is left in the limit, break out. + * We want to stutter a bit to keep in the limit, but too small + * receives will just cost cpu unnecessarily. */ + if(dl_avail <= 0) { + rate_limited = TRUE; break; - if(data->set.max_recv_speed < (curl_off_t)bytestoread) - bytestoread = (size_t)data->set.max_recv_speed; + } + if(dl_avail < (curl_off_t)bytestoread) + bytestoread = (size_t)dl_avail; } rcvd_eagain = FALSE; - nread = xfer_recv_resp(data, buf, bytestoread, is_multiplex, &result); - if(nread < 0) { - if(CURLE_AGAIN != result) + result = xfer_recv_resp(data, buf, bytestoread, is_multiplex, &blen); + if(result) { + if(result != CURLE_AGAIN) goto out; /* real error */ rcvd_eagain = TRUE; result = CURLE_OK; @@ -298,7 +279,7 @@ static CURLcode sendrecv_dl(struct Curl_easy *data, !data->req.resp_trailer) { DEBUGF(infof(data, "EAGAIN, download done, no trailer announced, " "not waiting for EOS")); - nread = 0; + blen = 0; /* continue as if we received the EOS */ } else @@ -306,28 +287,15 @@ static CURLcode sendrecv_dl(struct Curl_easy *data, } /* We only get a 0-length receive at the end of the response */ - blen = (size_t)nread; is_eos = (blen == 0); - if(!blen && (conn->recv[FIRSTSOCKET] == Curl_cf_recv)) { - /* if we receive 0 or less here and the protocol handler did not - replace the connection's `recv` callback, either the data transfer - is done or the server closed the connection and - we bail out from this! - With a `recv` replacement, we assume the protocol handler knows - what it is doing and a 0-length receive is fine. For example, - SFTP downloads of an empty file would show this. See #19165. */ - if(is_multiplex) - DEBUGF(infof(data, "nread == 0, stream closed, bailing")); - else - DEBUGF(infof(data, "nread <= 0, server closed connection, bailing")); + if(!blen) { result = Curl_req_stop_send_recv(data); if(result) goto out; if(k->eos_written) /* already did write this to client, leave */ break; } - total_received += blen; result = Curl_xfer_write_resp(data, buf, blen, is_eos); if(result || data->req.done) @@ -339,13 +307,13 @@ static CURLcode sendrecv_dl(struct Curl_easy *data, if((!is_multiplex && data->req.download_done) || is_eos) { data->req.keepon &= ~KEEP_RECV; } - /* if we are PAUSEd or stopped receiving, leave the loop */ - if((k->keepon & KEEP_RECV_PAUSE) || !(k->keepon & KEEP_RECV)) + /* if we stopped receiving, leave the loop */ + if(!(k->keepon & KEEP_RECV)) break; } while(maxloops--); - if(!is_eos && !Curl_xfer_is_blocked(data) && + if(!is_eos && !rate_limited && CURL_WANT_RECV(data) && (!rcvd_eagain || data_pending(data, rcvd_eagain))) { /* Did not read until EAGAIN/EOS or there is still data pending * in buffers. Mark as read-again via simulated SELECT results. */ @@ -353,7 +321,7 @@ static CURLcode sendrecv_dl(struct Curl_easy *data, CURL_TRC_M(data, "sendrecv_dl() no EAGAIN/pending data, mark as dirty"); } - if(((k->keepon & (KEEP_RECV|KEEP_SEND)) == KEEP_SEND) && + if(((k->keepon & (KEEP_RECV | KEEP_SEND)) == KEEP_SEND) && (conn->bits.close || is_multiplex)) { /* When we have read the entire thing and the close bit is set, the server may now close the connection. If there is now any kind of sending going @@ -388,12 +356,11 @@ static CURLcode sendrecv_ul(struct Curl_easy *data) * Curl_sendrecv() is the low-level function to be called when data is to * be read and written to/from the connection. */ -CURLcode Curl_sendrecv(struct Curl_easy *data, struct curltime *nowp) +CURLcode Curl_sendrecv(struct Curl_easy *data) { struct SingleRequest *k = &data->req; CURLcode result = CURLE_OK; - DEBUGASSERT(nowp); if(Curl_xfer_is_blocked(data)) { result = CURLE_OK; goto out; @@ -408,32 +375,31 @@ CURLcode Curl_sendrecv(struct Curl_easy *data, struct curltime *nowp) } /* If we still have writing to do, we check if we have a writable socket. */ - if(Curl_req_want_send(data) || (data->req.keepon & KEEP_SEND_TIMED)) { + if(Curl_req_want_send(data)) { result = sendrecv_ul(data); if(result) goto out; } - if(Curl_pgrsUpdate(data)) - result = CURLE_ABORTED_BY_CALLBACK; - else - result = Curl_speedcheck(data, *nowp); + result = Curl_pgrsCheck(data); if(result) goto out; if(k->keepon) { - if(0 > Curl_timeleft(data, nowp, FALSE)) { + if(Curl_timeleft_ms(data, FALSE) < 0) { if(k->size != -1) { failf(data, "Operation timed out after %" FMT_TIMEDIFF_T " milliseconds with %" FMT_OFF_T " out of %" FMT_OFF_T " bytes received", - curlx_timediff(*nowp, data->progress.t_startsingle), + curlx_ptimediff_ms(Curl_pgrs_now(data), + &data->progress.t_startsingle), k->bytecount, k->size); } else { failf(data, "Operation timed out after %" FMT_TIMEDIFF_T " milliseconds with %" FMT_OFF_T " bytes received", - curlx_timediff(*nowp, data->progress.t_startsingle), + curlx_ptimediff_ms(Curl_pgrs_now(data), + &data->progress.t_startsingle), k->bytecount); } result = CURLE_OPERATION_TIMEDOUT; @@ -452,16 +418,14 @@ CURLcode Curl_sendrecv(struct Curl_easy *data, struct curltime *nowp) result = CURLE_PARTIAL_FILE; goto out; } - if(Curl_pgrsUpdate(data)) { - result = CURLE_ABORTED_BY_CALLBACK; - goto out; - } } /* If there is nothing more to send/recv, the request is done */ - if((k->keepon & (KEEP_RECVBITS|KEEP_SENDBITS)) == 0) + if((k->keepon & (KEEP_RECV | KEEP_SEND)) == 0) data->req.done = TRUE; + result = Curl_pgrsUpdate(data); + out: if(result) DEBUGF(infof(data, "Curl_sendrecv() -> %d", result)); @@ -504,7 +468,7 @@ CURLcode Curl_pretransfer(struct Curl_easy *data) is allowed to be changed by the user between transfers */ if(data->set.uh) { CURLUcode uc; - free(data->set.str[STRING_SET_URL]); + curlx_free(data->set.str[STRING_SET_URL]); uc = curl_url_get(data->set.uh, CURLUPART_URL, &data->set.str[STRING_SET_URL], 0); if(uc) { @@ -513,13 +477,7 @@ CURLcode Curl_pretransfer(struct Curl_easy *data) } } - /* since the URL may have been redirected in a previous use of this handle */ - if(data->state.url_alloc) { - Curl_safefree(data->state.url); - data->state.url_alloc = FALSE; - } - - data->state.url = data->set.str[STRING_SET_URL]; + Curl_bufref_set(&data->state.url, data->set.str[STRING_SET_URL], 0, NULL); if(data->set.postfields && data->set.set_resume_from) { /* we cannot */ @@ -558,14 +516,17 @@ CURLcode Curl_pretransfer(struct Curl_easy *data) data->state.infilesize = 0; /* If there is a list of cookie files to read, do it now! */ - Curl_cookie_loadfiles(data); + result = Curl_cookie_loadfiles(data); + if(!result) + Curl_cookie_run(data); /* activate */ /* If there is a list of host pairs to deal with */ - if(data->state.resolve) + if(!result && data->state.resolve) result = Curl_loadhostpairs(data); - /* If there is a list of hsts files to read */ - Curl_hsts_loadfiles(data); + if(!result) + /* If there is a list of hsts files to read */ + result = Curl_hsts_loadfiles(data); if(!result) { /* Allow data->set.use_port to set which port to use. This needs to be @@ -596,7 +557,7 @@ CURLcode Curl_pretransfer(struct Curl_easy *data) if(data->state.wildcardmatch) { struct WildcardData *wc; if(!data->wildcard) { - data->wildcard = calloc(1, sizeof(struct WildcardData)); + data->wildcard = curlx_calloc(1, sizeof(struct WildcardData)); if(!data->wildcard) return CURLE_OUT_OF_MEMORY; } @@ -606,9 +567,7 @@ CURLcode Curl_pretransfer(struct Curl_easy *data) wc->dtor(wc->ftpwc); Curl_safefree(wc->pattern); Curl_safefree(wc->path); - result = Curl_wildcard_init(wc); /* init wildcard structures */ - if(result) - return CURLE_OUT_OF_MEMORY; + Curl_wildcard_init(wc); /* init wildcard structures */ } } #endif @@ -620,8 +579,8 @@ CURLcode Curl_pretransfer(struct Curl_easy *data) * basically anything through an HTTP proxy we cannot limit this based on * protocol. */ - if(data->set.str[STRING_USERAGENT]) { - free(data->state.aptr.uagent); + if(!result && data->set.str[STRING_USERAGENT]) { + curlx_free(data->state.aptr.uagent); data->state.aptr.uagent = curl_maprintf("User-Agent: %s\r\n", data->set.str[STRING_USERAGENT]); if(!data->state.aptr.uagent) @@ -653,7 +612,7 @@ CURLcode Curl_pretransfer(struct Curl_easy *data) /* Returns CURLE_OK *and* sets '*url' if a request retry is wanted. - NOTE: that the *url is malloc()ed. */ + NOTE: that the *url is curlx_malloc()ed. */ CURLcode Curl_retry_request(struct Curl_easy *data, char **url) { struct connectdata *conn = data->conn; @@ -664,7 +623,7 @@ CURLcode Curl_retry_request(struct Curl_easy *data, char **url) protocol is HTTP as when uploading over HTTP we will still get a response */ if(data->state.upload && - !(conn->handler->protocol&(PROTO_FAMILY_HTTP|CURLPROTO_RTSP))) + !(conn->handler->protocol & (PROTO_FAMILY_HTTP | CURLPROTO_RTSP))) return CURLE_OK; if(conn->bits.reuse && @@ -684,7 +643,7 @@ CURLcode Curl_retry_request(struct Curl_easy *data, char **url) it again. Bad luck. Retry the same request on a fresh connect! */ retry = TRUE; else if(data->state.refused_stream && - (data->req.bytecount + data->req.headerbytecount == 0) ) { + (data->req.bytecount + data->req.headerbytecount == 0)) { /* This was sent on a refused stream, safe to rerun. A refused stream error can typically only happen on HTTP/2 level if the stream is safe to issue again, but the nghttp2 API can deliver the message to other @@ -704,7 +663,7 @@ CURLcode Curl_retry_request(struct Curl_easy *data, char **url) } infof(data, "Connection died, retrying a fresh connect (retry count: %d)", data->state.retrycount); - *url = strdup(data->state.url); + *url = Curl_bufref_dup(&data->state.url); if(!*url) return CURLE_OUT_OF_MEMORY; @@ -844,6 +803,7 @@ CURLcode Curl_xfer_write_resp_hd(struct Curl_easy *data, const char *hd0, size_t hdlen, bool is_eos) { if(data->conn->handler->write_resp_hd) { + DEBUGASSERT(!hd0[hdlen]); /* null terminated */ /* protocol handlers offering this function take full responsibility * for writing all received download data to the client. */ return data->conn->handler->write_resp_hd(data, hd0, hdlen, is_eos); @@ -899,8 +859,8 @@ CURLcode Curl_xfer_recv(struct Curl_easy *data, DEBUGASSERT(data->conn); DEBUGASSERT(data->set.buffer_size > 0); - if((size_t)data->set.buffer_size < blen) - blen = (size_t)data->set.buffer_size; + if(curlx_uitouz(data->set.buffer_size) < blen) + blen = curlx_uitouz(data->set.buffer_size); return Curl_conn_recv(data, data->conn->recv_idx, buf, blen, pnrcvd); } @@ -924,51 +884,31 @@ bool Curl_xfer_is_blocked(struct Curl_easy *data) bool Curl_xfer_send_is_paused(struct Curl_easy *data) { - return (data->req.keepon & KEEP_SEND_PAUSE); + return Curl_rlimit_is_blocked(&data->progress.ul.rlimit); } bool Curl_xfer_recv_is_paused(struct Curl_easy *data) { - return (data->req.keepon & KEEP_RECV_PAUSE); + return Curl_rlimit_is_blocked(&data->progress.dl.rlimit); } CURLcode Curl_xfer_pause_send(struct Curl_easy *data, bool enable) { CURLcode result = CURLE_OK; - if(enable) { - data->req.keepon |= KEEP_SEND_PAUSE; - } - else { - data->req.keepon &= ~KEEP_SEND_PAUSE; - if(Curl_creader_is_paused(data)) - result = Curl_creader_unpause(data); - } + Curl_rlimit_block(&data->progress.ul.rlimit, enable, Curl_pgrs_now(data)); + if(!enable && Curl_creader_is_paused(data)) + result = Curl_creader_unpause(data); + Curl_pgrsSendPause(data, enable); return result; } CURLcode Curl_xfer_pause_recv(struct Curl_easy *data, bool enable) { CURLcode result = CURLE_OK; - if(enable) { - data->req.keepon |= KEEP_RECV_PAUSE; - } - else { - data->req.keepon &= ~KEEP_RECV_PAUSE; - if(Curl_cwriter_is_paused(data)) - result = Curl_cwriter_unpause(data); - } + Curl_rlimit_block(&data->progress.dl.rlimit, enable, Curl_pgrs_now(data)); + if(!enable && Curl_cwriter_is_paused(data)) + result = Curl_cwriter_unpause(data); Curl_conn_ev_data_pause(data, enable); + Curl_pgrsRecvPause(data, enable); return result; } - -bool Curl_xfer_is_too_fast(struct Curl_easy *data) -{ - struct Curl_llist_node *e = Curl_llist_head(&data->state.timeoutlist); - while(e) { - struct time_node *n = Curl_node_elem(e); - e = Curl_node_next(e); - if(n->eid == EXPIRE_TOOFAST) - return TRUE; - } - return FALSE; -} diff --git a/vendor/hydra/vendor/curl/lib/transfer.h b/vendor/hydra/vendor/curl/lib/transfer.h index 6145efb4..05a5f891 100644 --- a/vendor/hydra/vendor/curl/lib/transfer.h +++ b/vendor/hydra/vendor/curl/lib/transfer.h @@ -23,8 +23,8 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ +#define Curl_headersep(x) ((((x) == ':') || ((x) == ';'))) -#define Curl_headersep(x) ((((x)==':') || ((x)==';'))) char *Curl_checkheaders(const struct Curl_easy *data, const char *thisheader, const size_t thislen); @@ -33,7 +33,7 @@ void Curl_init_CONNECT(struct Curl_easy *data); CURLcode Curl_pretransfer(struct Curl_easy *data); -CURLcode Curl_sendrecv(struct Curl_easy *data, struct curltime *nowp); +CURLcode Curl_sendrecv(struct Curl_easy *data); CURLcode Curl_retry_request(struct Curl_easy *data, char **url); bool Curl_meets_timecondition(struct Curl_easy *data, time_t timeofdoc); @@ -143,7 +143,4 @@ bool Curl_xfer_recv_is_paused(struct Curl_easy *data); CURLcode Curl_xfer_pause_send(struct Curl_easy *data, bool enable); CURLcode Curl_xfer_pause_recv(struct Curl_easy *data, bool enable); -/* Query if transfer has expire timeout TOOFAST set. */ -bool Curl_xfer_is_too_fast(struct Curl_easy *data); - #endif /* HEADER_CURL_TRANSFER_H */ diff --git a/vendor/hydra/vendor/curl/lib/uint-bset.c b/vendor/hydra/vendor/curl/lib/uint-bset.c index 7b822344..5efdbea2 100644 --- a/vendor/hydra/vendor/curl/lib/uint-bset.c +++ b/vendor/hydra/vendor/curl/lib/uint-bset.c @@ -21,42 +21,37 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include "uint-bset.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" +#include "uint-bset.h" #ifdef DEBUGBUILD -#define CURL_UINT_BSET_MAGIC 0x62757473 +#define CURL_UINT32_BSET_MAGIC 0x62757473 #endif -void Curl_uint_bset_init(struct uint_bset *bset) +void Curl_uint32_bset_init(struct uint32_bset *bset) { memset(bset, 0, sizeof(*bset)); #ifdef DEBUGBUILD - bset->init = CURL_UINT_BSET_MAGIC; + bset->init = CURL_UINT32_BSET_MAGIC; #endif } - -CURLcode Curl_uint_bset_resize(struct uint_bset *bset, unsigned int nmax) +CURLcode Curl_uint32_bset_resize(struct uint32_bset *bset, uint32_t nmax) { - unsigned int nslots = (nmax < (UINT_MAX-63)) ? - ((nmax + 63) / 64) : (UINT_MAX / 64); + uint32_t nslots = (nmax < (UINT32_MAX - 63)) ? + ((nmax + 63) / 64) : (UINT32_MAX / 64); - DEBUGASSERT(bset->init == CURL_UINT_BSET_MAGIC); + DEBUGASSERT(bset->init == CURL_UINT32_BSET_MAGIC); if(nslots != bset->nslots) { - curl_uint64_t *slots = calloc(nslots, sizeof(curl_uint64_t)); + uint64_t *slots = curlx_calloc(nslots, sizeof(uint64_t)); if(!slots) return CURLE_OUT_OF_MEMORY; if(bset->slots) { memcpy(slots, bset->slots, - (CURLMIN(nslots, bset->nslots) * sizeof(curl_uint64_t))); - free(bset->slots); + (CURLMIN(nslots, bset->nslots) * sizeof(uint64_t))); + curlx_free(bset->slots); } bset->slots = slots; bset->nslots = nslots; @@ -65,25 +60,24 @@ CURLcode Curl_uint_bset_resize(struct uint_bset *bset, unsigned int nmax) return CURLE_OK; } - -void Curl_uint_bset_destroy(struct uint_bset *bset) +void Curl_uint32_bset_destroy(struct uint32_bset *bset) { - DEBUGASSERT(bset->init == CURL_UINT_BSET_MAGIC); - free(bset->slots); + DEBUGASSERT(bset->init == CURL_UINT32_BSET_MAGIC); + curlx_free(bset->slots); memset(bset, 0, sizeof(*bset)); } #ifdef UNITTESTS -UNITTEST unsigned int Curl_uint_bset_capacity(struct uint_bset *bset) +UNITTEST uint32_t Curl_uint32_bset_capacity(struct uint32_bset *bset) { return bset->nslots * 64; } #endif -unsigned int Curl_uint_bset_count(struct uint_bset *bset) +uint32_t Curl_uint32_bset_count(struct uint32_bset *bset) { - unsigned int i; - unsigned int n = 0; + uint32_t i; + uint32_t n = 0; for(i = 0; i < bset->nslots; ++i) { if(bset->slots[i]) n += CURL_POPCOUNT64(bset->slots[i]); @@ -91,9 +85,9 @@ unsigned int Curl_uint_bset_count(struct uint_bset *bset) return n; } -bool Curl_uint_bset_empty(struct uint_bset *bset) +bool Curl_uint32_bset_empty(struct uint32_bset *bset) { - unsigned int i; + uint32_t i; for(i = bset->first_slot_used; i < bset->nslots; ++i) { if(bset->slots[i]) return FALSE; @@ -101,48 +95,43 @@ bool Curl_uint_bset_empty(struct uint_bset *bset) return TRUE; } - -void Curl_uint_bset_clear(struct uint_bset *bset) +void Curl_uint32_bset_clear(struct uint32_bset *bset) { if(bset->nslots) { - memset(bset->slots, 0, bset->nslots * sizeof(curl_uint64_t)); - bset->first_slot_used = UINT_MAX; + memset(bset->slots, 0, bset->nslots * sizeof(uint64_t)); + bset->first_slot_used = UINT32_MAX; } } - -bool Curl_uint_bset_add(struct uint_bset *bset, unsigned int i) +bool Curl_uint32_bset_add(struct uint32_bset *bset, uint32_t i) { - unsigned int islot = i / 64; + uint32_t islot = i / 64; if(islot >= bset->nslots) return FALSE; - bset->slots[islot] |= ((curl_uint64_t)1 << (i % 64)); + bset->slots[islot] |= ((uint64_t)1 << (i % 64)); if(islot < bset->first_slot_used) bset->first_slot_used = islot; return TRUE; } - -void Curl_uint_bset_remove(struct uint_bset *bset, unsigned int i) +void Curl_uint32_bset_remove(struct uint32_bset *bset, uint32_t i) { size_t islot = i / 64; if(islot < bset->nslots) - bset->slots[islot] &= ~((curl_uint64_t)1 << (i % 64)); + bset->slots[islot] &= ~((uint64_t)1 << (i % 64)); } - -bool Curl_uint_bset_contains(struct uint_bset *bset, unsigned int i) +bool Curl_uint32_bset_contains(struct uint32_bset *bset, uint32_t i) { - unsigned int islot = i / 64; + uint32_t islot = i / 64; if(islot >= bset->nslots) return FALSE; - return (bset->slots[islot] & ((curl_uint64_t)1 << (i % 64))) != 0; + return (bset->slots[islot] & ((uint64_t)1 << (i % 64))) != 0; } - -bool Curl_uint_bset_first(struct uint_bset *bset, unsigned int *pfirst) +bool Curl_uint32_bset_first(struct uint32_bset *bset, uint32_t *pfirst) { - unsigned int i; + uint32_t i; for(i = bset->first_slot_used; i < bset->nslots; ++i) { if(bset->slots[i]) { *pfirst = (i * 64) + CURL_CTZ64(bset->slots[i]); @@ -150,15 +139,15 @@ bool Curl_uint_bset_first(struct uint_bset *bset, unsigned int *pfirst) return TRUE; } } - bset->first_slot_used = *pfirst = UINT_MAX; + bset->first_slot_used = *pfirst = UINT32_MAX; return FALSE; } -bool Curl_uint_bset_next(struct uint_bset *bset, unsigned int last, - unsigned int *pnext) +bool Curl_uint32_bset_next(struct uint32_bset *bset, uint32_t last, + uint32_t *pnext) { - unsigned int islot; - curl_uint64_t x; + uint32_t islot; + uint64_t x; ++last; /* look for number one higher than last */ islot = last / 64; /* the slot this would be in */ @@ -178,42 +167,41 @@ bool Curl_uint_bset_next(struct uint_bset *bset, unsigned int last, } } } - *pnext = UINT_MAX; /* a value we cannot store */ + *pnext = UINT32_MAX; /* a value we cannot store */ return FALSE; } #ifdef CURL_POPCOUNT64_IMPLEMENT -unsigned int Curl_popcount64(curl_uint64_t x) +uint32_t Curl_popcount64(uint64_t x) { /* Compute the "Hamming Distance" between 'x' and 0, * which is the number of set bits in 'x'. * See: https://en.wikipedia.org/wiki/Hamming_weight */ - const curl_uint64_t m1 = 0x5555555555555555LL; /* 0101+ */ - const curl_uint64_t m2 = 0x3333333333333333LL; /* 00110011+ */ - const curl_uint64_t m4 = 0x0f0f0f0f0f0f0f0fLL; /* 00001111+ */ + const uint64_t m1 = 0x5555555555555555LL; /* 0101+ */ + const uint64_t m2 = 0x3333333333333333LL; /* 00110011+ */ + const uint64_t m4 = 0x0f0f0f0f0f0f0f0fLL; /* 00001111+ */ /* 1 + 256^1 + 256^2 + 256^3 + ... + 256^7 */ - const curl_uint64_t h01 = 0x0101010101010101LL; + const uint64_t h01 = 0x0101010101010101LL; x -= (x >> 1) & m1; /* replace every 2 bits with bits present */ x = (x & m2) + ((x >> 2) & m2); /* replace every nibble with bits present */ x = (x + (x >> 4)) & m4; /* replace every byte with bits present */ - /* top 8 bits of x + (x<<8) + (x<<16) + (x<<24) + ... which makes the + /* top 8 bits of x + (x << 8) + (x << 16) + (x << 24) + ... which makes the * top byte the sum of all individual 8 bytes, throw away the rest */ - return (unsigned int)((x * h01) >> 56); + return (uint32_t)((x * h01) >> 56); } #endif /* CURL_POPCOUNT64_IMPLEMENT */ - #ifdef CURL_CTZ64_IMPLEMENT -unsigned int Curl_ctz64(curl_uint64_t x) +uint32_t Curl_ctz64(uint64_t x) { - /* count trailing zeros in a curl_uint64_t. + /* count trailing zeros in a uint64_t. * divide and conquer to find the number of lower 0 bits */ - const curl_uint64_t ml32 = 0xFFFFFFFF; /* lower 32 bits */ - const curl_uint64_t ml16 = 0x0000FFFF; /* lower 16 bits */ - const curl_uint64_t ml8 = 0x000000FF; /* lower 8 bits */ - const curl_uint64_t ml4 = 0x0000000F; /* lower 4 bits */ - const curl_uint64_t ml2 = 0x00000003; /* lower 2 bits */ - unsigned int n; + const uint64_t ml32 = 0xFFFFFFFF; /* lower 32 bits */ + const uint64_t ml16 = 0x0000FFFF; /* lower 16 bits */ + const uint64_t ml8 = 0x000000FF; /* lower 8 bits */ + const uint64_t ml4 = 0x0000000F; /* lower 4 bits */ + const uint64_t ml2 = 0x00000003; /* lower 2 bits */ + uint32_t n; if(!x) return 64; @@ -238,6 +226,6 @@ unsigned int Curl_ctz64(curl_uint64_t x) n = n + 2; x = x >> 2; } - return n - (unsigned int)(x & 1); + return n - (uint32_t)(x & 1); } #endif /* CURL_CTZ64_IMPLEMENT */ diff --git a/vendor/hydra/vendor/curl/lib/uint-bset.h b/vendor/hydra/vendor/curl/lib/uint-bset.h index cc405cc6..7455c427 100644 --- a/vendor/hydra/vendor/curl/lib/uint-bset.h +++ b/vendor/hydra/vendor/curl/lib/uint-bset.h @@ -25,8 +25,6 @@ ***************************************************************************/ #include "curl_setup.h" -#include - /* A bitset for unsigned int values. * It can hold the numbers from 0 - (nmax - 1), * rounded to the next 64 multiple. @@ -39,51 +37,51 @@ * the price of slightly slower operations. */ -struct uint_bset { - curl_uint64_t *slots; - unsigned int nslots; - unsigned int first_slot_used; +struct uint32_bset { + uint64_t *slots; + uint32_t nslots; + uint32_t first_slot_used; #ifdef DEBUGBUILD int init; #endif }; /* Initialize the bitset with capacity 0. */ -void Curl_uint_bset_init(struct uint_bset *bset); +void Curl_uint32_bset_init(struct uint32_bset *bset); /* Resize the bitset capacity to hold numbers from 0 to `nmax`, * which rounds up `nmax` to the next multiple of 64. */ -CURLcode Curl_uint_bset_resize(struct uint_bset *bset, unsigned int nmax); +CURLcode Curl_uint32_bset_resize(struct uint32_bset *bset, uint32_t nmax); /* Destroy the bitset, freeing all resources. */ -void Curl_uint_bset_destroy(struct uint_bset *bset); +void Curl_uint32_bset_destroy(struct uint32_bset *bset); /* Get the bitset capacity, e.g. can hold numbers from 0 to capacity - 1. */ -unsigned int Curl_uint_bset_capacity(struct uint_bset *bset); +uint32_t Curl_uint32_bset_capacity(struct uint32_bset *bset); /* Get the cardinality of the bitset, e.g. numbers present in the set. */ -unsigned int Curl_uint_bset_count(struct uint_bset *bset); +uint32_t Curl_uint32_bset_count(struct uint32_bset *bset); /* TRUE of bitset is empty */ -bool Curl_uint_bset_empty(struct uint_bset *bset); +bool Curl_uint32_bset_empty(struct uint32_bset *bset); /* Clear the bitset, making it empty. */ -void Curl_uint_bset_clear(struct uint_bset *bset); +void Curl_uint32_bset_clear(struct uint32_bset *bset); /* Add the number `i` to the bitset. Return FALSE if the number is * outside the set's capacity. * Numbers can be added more than once, without making a difference. */ -bool Curl_uint_bset_add(struct uint_bset *bset, unsigned int i); +bool Curl_uint32_bset_add(struct uint32_bset *bset, uint32_t i); /* Remove the number `i` from the bitset. */ -void Curl_uint_bset_remove(struct uint_bset *bset, unsigned int i); +void Curl_uint32_bset_remove(struct uint32_bset *bset, uint32_t i); /* Return TRUE if the bitset contains number `i`. */ -bool Curl_uint_bset_contains(struct uint_bset *bset, unsigned int i); +bool Curl_uint32_bset_contains(struct uint32_bset *bset, uint32_t i); /* Get the first number in the bitset, e.g. the smallest. * Returns FALSE when the bitset is empty. */ -bool Curl_uint_bset_first(struct uint_bset *bset, unsigned int *pfirst); +bool Curl_uint32_bset_first(struct uint32_bset *bset, uint32_t *pfirst); /* Get the next number in the bitset, following `last` in natural order. * Put another way, this is the smallest number greater than `last` in @@ -96,20 +94,19 @@ bool Curl_uint_bset_first(struct uint_bset *bset, unsigned int *pfirst); * - added numbers lower than 'last' will not show up. * - removed numbers lower or equal to 'last' will not show up. * - removed numbers higher than 'last' will not be visited. */ -bool Curl_uint_bset_next(struct uint_bset *bset, unsigned int last, - unsigned int *pnext); - +bool Curl_uint32_bset_next(struct uint32_bset *bset, uint32_t last, + uint32_t *pnext); #ifndef CURL_POPCOUNT64 -#define CURL_POPCOUNT64(x) Curl_popcount64(x) +#define CURL_POPCOUNT64(x) Curl_popcount64(x) #define CURL_POPCOUNT64_IMPLEMENT -unsigned int Curl_popcount64(curl_uint64_t x); +uint32_t Curl_popcount64(uint64_t x); #endif /* !CURL_POPCOUNT64 */ #ifndef CURL_CTZ64 #define CURL_CTZ64(x) Curl_ctz64(x) #define CURL_CTZ64_IMPLEMENT -unsigned int Curl_ctz64(curl_uint64_t x); +uint32_t Curl_ctz64(uint64_t x); #endif /* !CURL_CTZ64 */ #endif /* HEADER_CURL_UINT_BSET_H */ diff --git a/vendor/hydra/vendor/curl/lib/uint-hash.c b/vendor/hydra/vendor/curl/lib/uint-hash.c index 6c665078..e23d249d 100644 --- a/vendor/hydra/vendor/curl/lib/uint-hash.c +++ b/vendor/hydra/vendor/curl/lib/uint-hash.c @@ -21,37 +21,29 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include - #include "uint-hash.h" -#include "curl_memory.h" - -/* The last #include file should be: */ -#include "memdebug.h" /* random patterns for API verification */ #ifdef DEBUGBUILD -#define CURL_UINTHASHINIT 0x7117e779 +#define CURL_UINT32_HASHINIT 0x7117e779 #endif -static unsigned int uint_hash_hash(unsigned int id, unsigned int slots) +static uint32_t uint32_hash_hash(uint32_t id, uint32_t slots) { return (id % slots); } - struct uint_hash_entry { struct uint_hash_entry *next; - void *value; - unsigned int id; + void *value; + uint32_t id; }; -void Curl_uint_hash_init(struct uint_hash *h, - unsigned int slots, - Curl_uint_hash_dtor *dtor) +void Curl_uint32_hash_init(struct uint_hash *h, + uint32_t slots, + Curl_uint32_hash_dtor *dtor) { DEBUGASSERT(h); DEBUGASSERT(slots); @@ -61,16 +53,16 @@ void Curl_uint_hash_init(struct uint_hash *h, h->size = 0; h->slots = slots; #ifdef DEBUGBUILD - h->init = CURL_UINTHASHINIT; + h->init = CURL_UINT32_HASHINIT; #endif } -static struct uint_hash_entry *uint_hash_mk_entry(unsigned int id, void *value) +static struct uint_hash_entry *uint32_hash_mk_entry(uint32_t id, void *value) { struct uint_hash_entry *e; /* allocate the struct for the hash entry */ - e = malloc(sizeof(*e)); + e = curlx_malloc(sizeof(*e)); if(e) { e->id = id; e->next = NULL; @@ -79,8 +71,8 @@ static struct uint_hash_entry *uint_hash_mk_entry(unsigned int id, void *value) return e; } -static void uint_hash_entry_clear(struct uint_hash *h, - struct uint_hash_entry *e) +static void uint32_hash_entry_clear(struct uint_hash *h, + struct uint_hash_entry *e) { DEBUGASSERT(h); DEBUGASSERT(e); @@ -91,78 +83,78 @@ static void uint_hash_entry_clear(struct uint_hash *h, } } -static void uint_hash_entry_destroy(struct uint_hash *h, - struct uint_hash_entry *e) +static void uint32_hash_entry_destroy(struct uint_hash *h, + struct uint_hash_entry *e) { - uint_hash_entry_clear(h, e); - free(e); + uint32_hash_entry_clear(h, e); + curlx_free(e); } -static void uint_hash_entry_unlink(struct uint_hash *h, - struct uint_hash_entry **he_anchor, - struct uint_hash_entry *he) +static void uint32_hash_entry_unlink(struct uint_hash *h, + struct uint_hash_entry **he_anchor, + struct uint_hash_entry *he) { *he_anchor = he->next; --h->size; } -static void uint_hash_elem_link(struct uint_hash *h, - struct uint_hash_entry **he_anchor, - struct uint_hash_entry *he) +static void uint32_hash_elem_link(struct uint_hash *h, + struct uint_hash_entry **he_anchor, + struct uint_hash_entry *he) { he->next = *he_anchor; *he_anchor = he; ++h->size; } -#define CURL_UINT_HASH_SLOT(h,id) h->table[uint_hash_hash(id, h->slots)] -#define CURL_UINT_HASH_SLOT_ADDR(h,id) &CURL_UINT_HASH_SLOT(h,id) +#define CURL_UINT32_HASH_SLOT(h, id) h->table[uint32_hash_hash(id, h->slots)] +#define CURL_UINT32_HASH_SLOT_ADDR(h, id) &CURL_UINT32_HASH_SLOT(h, id) -bool Curl_uint_hash_set(struct uint_hash *h, unsigned int id, void *value) +bool Curl_uint32_hash_set(struct uint_hash *h, uint32_t id, void *value) { struct uint_hash_entry *he, **slot; DEBUGASSERT(h); DEBUGASSERT(h->slots); - DEBUGASSERT(h->init == CURL_UINTHASHINIT); + DEBUGASSERT(h->init == CURL_UINT32_HASHINIT); if(!h->table) { - h->table = calloc(h->slots, sizeof(*he)); + h->table = curlx_calloc(h->slots, sizeof(*he)); if(!h->table) return FALSE; /* OOM */ } - slot = CURL_UINT_HASH_SLOT_ADDR(h, id); + slot = CURL_UINT32_HASH_SLOT_ADDR(h, id); for(he = *slot; he; he = he->next) { if(he->id == id) { /* existing key entry, overwrite by clearing old pointer */ - uint_hash_entry_clear(h, he); + uint32_hash_entry_clear(h, he); he->value = value; return TRUE; } } - he = uint_hash_mk_entry(id, value); + he = uint32_hash_mk_entry(id, value); if(!he) return FALSE; /* OOM */ - uint_hash_elem_link(h, slot, he); + uint32_hash_elem_link(h, slot, he); return TRUE; } -bool Curl_uint_hash_remove(struct uint_hash *h, unsigned int id) +bool Curl_uint32_hash_remove(struct uint_hash *h, uint32_t id) { DEBUGASSERT(h); DEBUGASSERT(h->slots); - DEBUGASSERT(h->init == CURL_UINTHASHINIT); + DEBUGASSERT(h->init == CURL_UINT32_HASHINIT); if(h->table) { struct uint_hash_entry *he, **he_anchor; - he_anchor = CURL_UINT_HASH_SLOT_ADDR(h, id); + he_anchor = CURL_UINT32_HASH_SLOT_ADDR(h, id); while(*he_anchor) { he = *he_anchor; if(id == he->id) { - uint_hash_entry_unlink(h, he_anchor, he); - uint_hash_entry_destroy(h, he); + uint32_hash_entry_unlink(h, he_anchor, he); + uint32_hash_entry_destroy(h, he); return TRUE; } he_anchor = &he->next; @@ -171,14 +163,14 @@ bool Curl_uint_hash_remove(struct uint_hash *h, unsigned int id) return FALSE; } -void *Curl_uint_hash_get(struct uint_hash *h, unsigned int id) +void *Curl_uint32_hash_get(struct uint_hash *h, uint32_t id) { DEBUGASSERT(h); - DEBUGASSERT(h->init == CURL_UINTHASHINIT); + DEBUGASSERT(h->init == CURL_UINT32_HASHINIT); if(h->table) { struct uint_hash_entry *he; DEBUGASSERT(h->slots); - he = CURL_UINT_HASH_SLOT(h, id); + he = CURL_UINT32_HASH_SLOT(h, id); while(he) { if(id == he->id) { return he->value; @@ -194,28 +186,28 @@ static void uint_hash_clear(struct uint_hash *h) if(h && h->table) { struct uint_hash_entry *he, **he_anchor; size_t i; - DEBUGASSERT(h->init == CURL_UINTHASHINIT); + DEBUGASSERT(h->init == CURL_UINT32_HASHINIT); for(i = 0; i < h->slots; ++i) { he_anchor = &h->table[i]; while(*he_anchor) { he = *he_anchor; - uint_hash_entry_unlink(h, he_anchor, he); - uint_hash_entry_destroy(h, he); + uint32_hash_entry_unlink(h, he_anchor, he); + uint32_hash_entry_destroy(h, he); } } } } #ifdef UNITTESTS -UNITTEST void Curl_uint_hash_clear(struct uint_hash *h) +UNITTEST void Curl_uint32_hash_clear(struct uint_hash *h) { uint_hash_clear(h); } #endif -void Curl_uint_hash_destroy(struct uint_hash *h) +void Curl_uint32_hash_destroy(struct uint_hash *h) { - DEBUGASSERT(h->init == CURL_UINTHASHINIT); + DEBUGASSERT(h->init == CURL_UINT32_HASHINIT); if(h->table) { uint_hash_clear(h); Curl_safefree(h->table); @@ -224,20 +216,20 @@ void Curl_uint_hash_destroy(struct uint_hash *h) h->slots = 0; } -unsigned int Curl_uint_hash_count(struct uint_hash *h) +uint32_t Curl_uint32_hash_count(struct uint_hash *h) { - DEBUGASSERT(h->init == CURL_UINTHASHINIT); + DEBUGASSERT(h->init == CURL_UINT32_HASHINIT); return h->size; } -void Curl_uint_hash_visit(struct uint_hash *h, - Curl_uint_hash_visit_cb *cb, - void *user_data) +void Curl_uint32_hash_visit(struct uint_hash *h, + Curl_uint32_hash_visit_cb *cb, + void *user_data) { if(h && h->table && cb) { struct uint_hash_entry *he; size_t i; - DEBUGASSERT(h->init == CURL_UINTHASHINIT); + DEBUGASSERT(h->init == CURL_UINT32_HASHINIT); for(i = 0; i < h->slots; ++i) { for(he = h->table[i]; he; he = he->next) { if(!cb(he->id, he->value, user_data)) diff --git a/vendor/hydra/vendor/curl/lib/uint-hash.h b/vendor/hydra/vendor/curl/lib/uint-hash.h index 1b52dba4..56d71043 100644 --- a/vendor/hydra/vendor/curl/lib/uint-hash.h +++ b/vendor/hydra/vendor/curl/lib/uint-hash.h @@ -23,46 +23,39 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include - -#include "llist.h" - -/* A version with unsigned int as key */ -typedef void Curl_uint_hash_dtor(unsigned int id, void *value); +/* A version with uint32_t as key */ +typedef void Curl_uint32_hash_dtor(uint32_t id, void *value); struct uint_hash_entry; -/* Hash for `unsigned int` as key */ +/* Hash for `uint32_t` as key */ struct uint_hash { struct uint_hash_entry **table; - Curl_uint_hash_dtor *dtor; - unsigned int slots; - unsigned int size; + Curl_uint32_hash_dtor *dtor; + uint32_t slots; + uint32_t size; #ifdef DEBUGBUILD int init; #endif }; +void Curl_uint32_hash_init(struct uint_hash *h, + uint32_t slots, + Curl_uint32_hash_dtor *dtor); +void Curl_uint32_hash_destroy(struct uint_hash *h); +void Curl_uint32_hash_clear(struct uint_hash *h); -void Curl_uint_hash_init(struct uint_hash *h, - unsigned int slots, - Curl_uint_hash_dtor *dtor); -void Curl_uint_hash_destroy(struct uint_hash *h); -void Curl_uint_hash_clear(struct uint_hash *h); - -bool Curl_uint_hash_set(struct uint_hash *h, unsigned int id, void *value); -bool Curl_uint_hash_remove(struct uint_hash *h, unsigned int id); -void *Curl_uint_hash_get(struct uint_hash *h, unsigned int id); -unsigned int Curl_uint_hash_count(struct uint_hash *h); - +bool Curl_uint32_hash_set(struct uint_hash *h, uint32_t id, void *value); +bool Curl_uint32_hash_remove(struct uint_hash *h, uint32_t id); +void *Curl_uint32_hash_get(struct uint_hash *h, uint32_t id); +uint32_t Curl_uint32_hash_count(struct uint_hash *h); -typedef bool Curl_uint_hash_visit_cb(unsigned int id, void *value, - void *user_data); +typedef bool Curl_uint32_hash_visit_cb(uint32_t id, void *value, + void *user_data); -void Curl_uint_hash_visit(struct uint_hash *h, - Curl_uint_hash_visit_cb *cb, - void *user_data); +void Curl_uint32_hash_visit(struct uint_hash *h, + Curl_uint32_hash_visit_cb *cb, + void *user_data); #endif /* HEADER_CURL_UINT_HASH_H */ diff --git a/vendor/hydra/vendor/curl/lib/uint-spbset.c b/vendor/hydra/vendor/curl/lib/uint-spbset.c index 2e8e2a13..58dcbdac 100644 --- a/vendor/hydra/vendor/curl/lib/uint-spbset.c +++ b/vendor/hydra/vendor/curl/lib/uint-spbset.c @@ -21,43 +21,39 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" + #include "uint-bset.h" #include "uint-spbset.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef DEBUGBUILD -#define CURL_UINT_SPBSET_MAGIC 0x70737362 +#define CURL_UINT32_SPBSET_MAGIC 0x70737362 #endif /* Clear the bitset, making it empty. */ -UNITTEST void Curl_uint_spbset_clear(struct uint_spbset *bset); +UNITTEST void Curl_uint32_spbset_clear(struct uint32_spbset *bset); -void Curl_uint_spbset_init(struct uint_spbset *bset) +void Curl_uint32_spbset_init(struct uint32_spbset *bset) { memset(bset, 0, sizeof(*bset)); #ifdef DEBUGBUILD - bset->init = CURL_UINT_SPBSET_MAGIC; + bset->init = CURL_UINT32_SPBSET_MAGIC; #endif } -void Curl_uint_spbset_destroy(struct uint_spbset *bset) +void Curl_uint32_spbset_destroy(struct uint32_spbset *bset) { - DEBUGASSERT(bset->init == CURL_UINT_SPBSET_MAGIC); - Curl_uint_spbset_clear(bset); + DEBUGASSERT(bset->init == CURL_UINT32_SPBSET_MAGIC); + Curl_uint32_spbset_clear(bset); } -unsigned int Curl_uint_spbset_count(struct uint_spbset *bset) +uint32_t Curl_uint32_spbset_count(struct uint32_spbset *bset) { - struct uint_spbset_chunk *chunk; - unsigned int i, n = 0; + struct uint32_spbset_chunk *chunk; + uint32_t i, n = 0; for(chunk = &bset->head; chunk; chunk = chunk->next) { - for(i = 0; i < CURL_UINT_SPBSET_CH_SLOTS; ++i) { + for(i = 0; i < CURL_UINT32_SPBSET_CH_SLOTS; ++i) { if(chunk->slots[i]) n += CURL_POPCOUNT64(chunk->slots[i]); } @@ -65,37 +61,22 @@ unsigned int Curl_uint_spbset_count(struct uint_spbset *bset) return n; } -bool Curl_uint_spbset_empty(struct uint_spbset *bset) -{ - struct uint_spbset_chunk *chunk; - unsigned int i; - - for(chunk = &bset->head; chunk; chunk = chunk->next) { - for(i = 0; i < CURL_UINT_SPBSET_CH_SLOTS; ++i) { - if(chunk->slots[i]) - return FALSE; - } - } - return TRUE; -} - -UNITTEST void Curl_uint_spbset_clear(struct uint_spbset *bset) +UNITTEST void Curl_uint32_spbset_clear(struct uint32_spbset *bset) { - struct uint_spbset_chunk *next, *chunk; + struct uint32_spbset_chunk *next, *chunk; for(chunk = bset->head.next; chunk; chunk = next) { next = chunk->next; - free(chunk); + curlx_free(chunk); } memset(&bset->head, 0, sizeof(bset->head)); } - -static struct uint_spbset_chunk * -uint_spbset_get_chunk(struct uint_spbset *bset, unsigned int i, bool grow) +static struct uint32_spbset_chunk * +uint32_spbset_get_chunk(struct uint32_spbset *bset, uint32_t i, bool grow) { - struct uint_spbset_chunk *chunk, **panchor = NULL; - unsigned int i_offset = (i & ~CURL_UINT_SPBSET_CH_MASK); + struct uint32_spbset_chunk *chunk, **panchor = NULL; + uint32_t i_offset = (i & ~CURL_UINT32_SPBSET_CH_MASK); if(!bset) return NULL; @@ -116,7 +97,7 @@ uint_spbset_get_chunk(struct uint_spbset *bset, unsigned int i, bool grow) return NULL; /* need a new one */ - chunk = calloc(1, sizeof(*chunk)); + chunk = curlx_calloc(1, sizeof(*chunk)); if(!chunk) return NULL; @@ -133,62 +114,59 @@ uint_spbset_get_chunk(struct uint_spbset *bset, unsigned int i, bool grow) return chunk; } - -bool Curl_uint_spbset_add(struct uint_spbset *bset, unsigned int i) +bool Curl_uint32_spbset_add(struct uint32_spbset *bset, uint32_t i) { - struct uint_spbset_chunk *chunk; - unsigned int i_chunk; + struct uint32_spbset_chunk *chunk; + uint32_t i_chunk; - chunk = uint_spbset_get_chunk(bset, i, TRUE); + chunk = uint32_spbset_get_chunk(bset, i, TRUE); if(!chunk) return FALSE; DEBUGASSERT(i >= chunk->offset); i_chunk = (i - chunk->offset); - DEBUGASSERT((i_chunk / 64) < CURL_UINT_SPBSET_CH_SLOTS); - chunk->slots[(i_chunk / 64)] |= ((curl_uint64_t)1 << (i_chunk % 64)); + DEBUGASSERT((i_chunk / 64) < CURL_UINT32_SPBSET_CH_SLOTS); + chunk->slots[(i_chunk / 64)] |= ((uint64_t)1 << (i_chunk % 64)); return TRUE; } - -void Curl_uint_spbset_remove(struct uint_spbset *bset, unsigned int i) +void Curl_uint32_spbset_remove(struct uint32_spbset *bset, uint32_t i) { - struct uint_spbset_chunk *chunk; - unsigned int i_chunk; + struct uint32_spbset_chunk *chunk; + uint32_t i_chunk; - chunk = uint_spbset_get_chunk(bset, i, FALSE); + chunk = uint32_spbset_get_chunk(bset, i, FALSE); if(chunk) { DEBUGASSERT(i >= chunk->offset); i_chunk = (i - chunk->offset); - DEBUGASSERT((i_chunk / 64) < CURL_UINT_SPBSET_CH_SLOTS); - chunk->slots[(i_chunk / 64)] &= ~((curl_uint64_t)1 << (i_chunk % 64)); + DEBUGASSERT((i_chunk / 64) < CURL_UINT32_SPBSET_CH_SLOTS); + chunk->slots[(i_chunk / 64)] &= ~((uint64_t)1 << (i_chunk % 64)); } } - -bool Curl_uint_spbset_contains(struct uint_spbset *bset, unsigned int i) +bool Curl_uint32_spbset_contains(struct uint32_spbset *bset, uint32_t i) { - struct uint_spbset_chunk *chunk; - unsigned int i_chunk; + struct uint32_spbset_chunk *chunk; + uint32_t i_chunk; - chunk = uint_spbset_get_chunk(bset, i, FALSE); + chunk = uint32_spbset_get_chunk(bset, i, FALSE); if(chunk) { DEBUGASSERT(i >= chunk->offset); i_chunk = (i - chunk->offset); - DEBUGASSERT((i_chunk / 64) < CURL_UINT_SPBSET_CH_SLOTS); + DEBUGASSERT((i_chunk / 64) < CURL_UINT32_SPBSET_CH_SLOTS); return (chunk->slots[i_chunk / 64] & - ((curl_uint64_t)1 << (i_chunk % 64))) != 0; + ((uint64_t)1 << (i_chunk % 64))) != 0; } return FALSE; } -bool Curl_uint_spbset_first(struct uint_spbset *bset, unsigned int *pfirst) +bool Curl_uint32_spbset_first(struct uint32_spbset *bset, uint32_t *pfirst) { - struct uint_spbset_chunk *chunk; - unsigned int i; + struct uint32_spbset_chunk *chunk; + uint32_t i; for(chunk = &bset->head; chunk; chunk = chunk->next) { - for(i = 0; i < CURL_UINT_SPBSET_CH_SLOTS; ++i) { + for(i = 0; i < CURL_UINT32_SPBSET_CH_SLOTS; ++i) { if(chunk->slots[i]) { *pfirst = chunk->offset + ((i * 64) + CURL_CTZ64(chunk->slots[i])); return TRUE; @@ -199,30 +177,28 @@ bool Curl_uint_spbset_first(struct uint_spbset *bset, unsigned int *pfirst) return FALSE; } - -static bool uint_spbset_chunk_first(struct uint_spbset_chunk *chunk, - unsigned int *pfirst) +static bool uint32_spbset_chunk_first(struct uint32_spbset_chunk *chunk, + uint32_t *pfirst) { - unsigned int i; - for(i = 0; i < CURL_UINT_SPBSET_CH_SLOTS; ++i) { + uint32_t i; + for(i = 0; i < CURL_UINT32_SPBSET_CH_SLOTS; ++i) { if(chunk->slots[i]) { *pfirst = chunk->offset + ((i * 64) + CURL_CTZ64(chunk->slots[i])); return TRUE; } } - *pfirst = UINT_MAX; /* a value we cannot store */ + *pfirst = UINT32_MAX; /* a value we cannot store */ return FALSE; } - -static bool uint_spbset_chunk_next(struct uint_spbset_chunk *chunk, - unsigned int last, - unsigned int *pnext) +static bool uint32_spbset_chunk_next(struct uint32_spbset_chunk *chunk, + uint32_t last, + uint32_t *pnext) { if(chunk->offset <= last) { - curl_uint64_t x; - unsigned int i = ((last - chunk->offset) / 64); - if(i < CURL_UINT_SPBSET_CH_SLOTS) { + uint64_t x; + uint32_t i = ((last - chunk->offset) / 64); + if(i < CURL_UINT32_SPBSET_CH_SLOTS) { x = (chunk->slots[i] >> (last % 64)); if(x) { /* more bits set, next is `last` + trailing0s of the shifted slot */ @@ -230,7 +206,7 @@ static bool uint_spbset_chunk_next(struct uint_spbset_chunk *chunk, return TRUE; } /* no more bits set in the last slot, scan forward */ - for(i = i + 1; i < CURL_UINT_SPBSET_CH_SLOTS; ++i) { + for(i = i + 1; i < CURL_UINT32_SPBSET_CH_SLOTS; ++i) { if(chunk->slots[i]) { *pnext = chunk->offset + ((i * 64) + CURL_CTZ64(chunk->slots[i])); return TRUE; @@ -238,18 +214,18 @@ static bool uint_spbset_chunk_next(struct uint_spbset_chunk *chunk, } } } - *pnext = UINT_MAX; + *pnext = UINT32_MAX; return FALSE; } -bool Curl_uint_spbset_next(struct uint_spbset *bset, unsigned int last, - unsigned int *pnext) +bool Curl_uint32_spbset_next(struct uint32_spbset *bset, uint32_t last, + uint32_t *pnext) { - struct uint_spbset_chunk *chunk; - unsigned int last_offset; + struct uint32_spbset_chunk *chunk; + uint32_t last_offset; ++last; /* look for the next higher number */ - last_offset = (last & ~CURL_UINT_SPBSET_CH_MASK); + last_offset = (last & ~CURL_UINT32_SPBSET_CH_MASK); for(chunk = &bset->head; chunk; chunk = chunk->next) { if(chunk->offset >= last_offset) { @@ -259,17 +235,17 @@ bool Curl_uint_spbset_next(struct uint_spbset *bset, unsigned int last, if(chunk && (chunk->offset == last_offset)) { /* is there a number higher than last in this chunk? */ - if(uint_spbset_chunk_next(chunk, last, pnext)) + if(uint32_spbset_chunk_next(chunk, last, pnext)) return TRUE; /* not in this chunk */ chunk = chunk->next; } /* look for the first in the "higher" chunks, if there are any. */ while(chunk) { - if(uint_spbset_chunk_first(chunk, pnext)) + if(uint32_spbset_chunk_first(chunk, pnext)) return TRUE; chunk = chunk->next; } - *pnext = UINT_MAX; + *pnext = UINT32_MAX; return FALSE; } diff --git a/vendor/hydra/vendor/curl/lib/uint-spbset.h b/vendor/hydra/vendor/curl/lib/uint-spbset.h index bd234790..4b105c02 100644 --- a/vendor/hydra/vendor/curl/lib/uint-spbset.h +++ b/vendor/hydra/vendor/curl/lib/uint-spbset.h @@ -25,10 +25,8 @@ ***************************************************************************/ #include "curl_setup.h" -#include - -/* A "sparse" bitset for unsigned int values. - * It can hold any unsigned int value. +/* A "sparse" bitset for uint32_t values. + * It can hold any uint32_t value. * * Optimized for the case where only a small set of numbers need * to be kept, especially when "close" together. Then storage space @@ -36,48 +34,45 @@ */ /* 4 slots = 256 bits, keep this a 2^n value. */ -#define CURL_UINT_SPBSET_CH_SLOTS 4 -#define CURL_UINT_SPBSET_CH_MASK ((CURL_UINT_SPBSET_CH_SLOTS * 64) - 1) +#define CURL_UINT32_SPBSET_CH_SLOTS 4 +#define CURL_UINT32_SPBSET_CH_MASK ((CURL_UINT32_SPBSET_CH_SLOTS * 64) - 1) /* store the uint value from offset to - * (offset + (CURL_UINT_SPBSET_CHUNK_SLOTS * 64) - 1 */ -struct uint_spbset_chunk { - struct uint_spbset_chunk *next; - curl_uint64_t slots[CURL_UINT_SPBSET_CH_SLOTS]; - unsigned int offset; + * (offset + (CURL_UINT32_SPBSET_CHUNK_SLOTS * 64) - 1 */ +struct uint32_spbset_chunk { + struct uint32_spbset_chunk *next; + uint64_t slots[CURL_UINT32_SPBSET_CH_SLOTS]; + uint32_t offset; }; -struct uint_spbset { - struct uint_spbset_chunk head; +struct uint32_spbset { + struct uint32_spbset_chunk head; #ifdef DEBUGBUILD int init; #endif }; -void Curl_uint_spbset_init(struct uint_spbset *bset); +void Curl_uint32_spbset_init(struct uint32_spbset *bset); -void Curl_uint_spbset_destroy(struct uint_spbset *bset); +void Curl_uint32_spbset_destroy(struct uint32_spbset *bset); /* Get the cardinality of the bitset, e.g. numbers present in the set. */ -unsigned int Curl_uint_spbset_count(struct uint_spbset *bset); - -/* TRUE of bitset is empty */ -bool Curl_uint_spbset_empty(struct uint_spbset *bset); +uint32_t Curl_uint32_spbset_count(struct uint32_spbset *bset); /* Add the number `i` to the bitset. * Numbers can be added more than once, without making a difference. * Returns FALSE if allocations failed. */ -bool Curl_uint_spbset_add(struct uint_spbset *bset, unsigned int i); +bool Curl_uint32_spbset_add(struct uint32_spbset *bset, uint32_t i); /* Remove the number `i` from the bitset. */ -void Curl_uint_spbset_remove(struct uint_spbset *bset, unsigned int i); +void Curl_uint32_spbset_remove(struct uint32_spbset *bset, uint32_t i); /* Return TRUE if the bitset contains number `i`. */ -bool Curl_uint_spbset_contains(struct uint_spbset *bset, unsigned int i); +bool Curl_uint32_spbset_contains(struct uint32_spbset *bset, uint32_t i); /* Get the first number in the bitset, e.g. the smallest. * Returns FALSE when the bitset is empty. */ -bool Curl_uint_spbset_first(struct uint_spbset *bset, unsigned int *pfirst); +bool Curl_uint32_spbset_first(struct uint32_spbset *bset, uint32_t *pfirst); /* Get the next number in the bitset, following `last` in natural order. * Put another way, this is the smallest number greater than `last` in @@ -90,7 +85,7 @@ bool Curl_uint_spbset_first(struct uint_spbset *bset, unsigned int *pfirst); * - added numbers lower than 'last' will not show up. * - removed numbers lower or equal to 'last' will not show up. * - removed numbers higher than 'last' will not be visited. */ -bool Curl_uint_spbset_next(struct uint_spbset *bset, unsigned int last, - unsigned int *pnext); +bool Curl_uint32_spbset_next(struct uint32_spbset *bset, uint32_t last, + uint32_t *pnext); #endif /* HEADER_CURL_UINT_SPBSET_H */ diff --git a/vendor/hydra/vendor/curl/lib/uint-table.c b/vendor/hydra/vendor/curl/lib/uint-table.c index 5077363a..b9c19901 100644 --- a/vendor/hydra/vendor/curl/lib/uint-table.c +++ b/vendor/hydra/vendor/curl/lib/uint-table.c @@ -21,38 +21,33 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" -#include "uint-table.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" +#include "uint-table.h" #ifdef DEBUGBUILD -#define CURL_UINT_TBL_MAGIC 0x62757473 +#define CURL_UINT32_TBL_MAGIC 0x62757473 #endif /* Clear the table, making it empty. */ -UNITTEST void Curl_uint_tbl_clear(struct uint_tbl *tbl); +UNITTEST void Curl_uint32_tbl_clear(struct uint32_tbl *tbl); -void Curl_uint_tbl_init(struct uint_tbl *tbl, - Curl_uint_tbl_entry_dtor *entry_dtor) +void Curl_uint32_tbl_init(struct uint32_tbl *tbl, + Curl_uint32_tbl_entry_dtor *entry_dtor) { memset(tbl, 0, sizeof(*tbl)); tbl->entry_dtor = entry_dtor; - tbl->last_key_added = UINT_MAX; + tbl->last_key_added = UINT32_MAX; #ifdef DEBUGBUILD - tbl->init = CURL_UINT_TBL_MAGIC; + tbl->init = CURL_UINT32_TBL_MAGIC; #endif } - -static void uint_tbl_clear_rows(struct uint_tbl *tbl, - unsigned int from, - unsigned int upto_excluding) +static void uint32_tbl_clear_rows(struct uint32_tbl *tbl, + uint32_t from, + uint32_t upto_excluding) { - unsigned int i, end; + uint32_t i, end; end = CURLMIN(upto_excluding, tbl->nrows); for(i = from; i < end; ++i) { @@ -65,22 +60,21 @@ static void uint_tbl_clear_rows(struct uint_tbl *tbl, } } - -CURLcode Curl_uint_tbl_resize(struct uint_tbl *tbl, unsigned int nrows) +CURLcode Curl_uint32_tbl_resize(struct uint32_tbl *tbl, uint32_t nrows) { /* we use `tbl->nrows + 1` during iteration, want that to work */ - DEBUGASSERT(tbl->init == CURL_UINT_TBL_MAGIC); + DEBUGASSERT(tbl->init == CURL_UINT32_TBL_MAGIC); if(!nrows) return CURLE_BAD_FUNCTION_ARGUMENT; if(nrows != tbl->nrows) { - void **rows = calloc(nrows, sizeof(void *)); + void **rows = curlx_calloc(nrows, sizeof(void *)); if(!rows) return CURLE_OUT_OF_MEMORY; if(tbl->rows) { memcpy(rows, tbl->rows, (CURLMIN(nrows, tbl->nrows) * sizeof(void *))); if(nrows < tbl->nrows) - uint_tbl_clear_rows(tbl, nrows, tbl->nrows); - free(tbl->rows); + uint32_tbl_clear_rows(tbl, nrows, tbl->nrows); + curlx_free(tbl->rows); } tbl->rows = rows; tbl->nrows = nrows; @@ -88,50 +82,45 @@ CURLcode Curl_uint_tbl_resize(struct uint_tbl *tbl, unsigned int nrows) return CURLE_OK; } - -void Curl_uint_tbl_destroy(struct uint_tbl *tbl) +void Curl_uint32_tbl_destroy(struct uint32_tbl *tbl) { - DEBUGASSERT(tbl->init == CURL_UINT_TBL_MAGIC); - Curl_uint_tbl_clear(tbl); - free(tbl->rows); + DEBUGASSERT(tbl->init == CURL_UINT32_TBL_MAGIC); + Curl_uint32_tbl_clear(tbl); + curlx_free(tbl->rows); memset(tbl, 0, sizeof(*tbl)); } -UNITTEST void Curl_uint_tbl_clear(struct uint_tbl *tbl) +UNITTEST void Curl_uint32_tbl_clear(struct uint32_tbl *tbl) { - DEBUGASSERT(tbl->init == CURL_UINT_TBL_MAGIC); - uint_tbl_clear_rows(tbl, 0, tbl->nrows); + DEBUGASSERT(tbl->init == CURL_UINT32_TBL_MAGIC); + uint32_tbl_clear_rows(tbl, 0, tbl->nrows); DEBUGASSERT(!tbl->nentries); - tbl->last_key_added = UINT_MAX; + tbl->last_key_added = UINT32_MAX; } - -unsigned int Curl_uint_tbl_capacity(struct uint_tbl *tbl) +uint32_t Curl_uint32_tbl_capacity(struct uint32_tbl *tbl) { return tbl->nrows; } - -unsigned int Curl_uint_tbl_count(struct uint_tbl *tbl) +uint32_t Curl_uint32_tbl_count(struct uint32_tbl *tbl) { return tbl->nentries; } - -void *Curl_uint_tbl_get(struct uint_tbl *tbl, unsigned int key) +void *Curl_uint32_tbl_get(struct uint32_tbl *tbl, uint32_t key) { return (key < tbl->nrows) ? tbl->rows[key] : NULL; } - -bool Curl_uint_tbl_add(struct uint_tbl *tbl, void *entry, unsigned int *pkey) +bool Curl_uint32_tbl_add(struct uint32_tbl *tbl, void *entry, uint32_t *pkey) { - unsigned int key, start_pos; + uint32_t key, start_pos; - DEBUGASSERT(tbl->init == CURL_UINT_TBL_MAGIC); + DEBUGASSERT(tbl->init == CURL_UINT32_TBL_MAGIC); if(!entry || !pkey) return FALSE; - *pkey = UINT_MAX; + *pkey = UINT32_MAX; if(tbl->nentries == tbl->nrows) /* full */ return FALSE; @@ -160,21 +149,18 @@ bool Curl_uint_tbl_add(struct uint_tbl *tbl, void *entry, unsigned int *pkey) return FALSE; } - -void Curl_uint_tbl_remove(struct uint_tbl *tbl, unsigned int key) +void Curl_uint32_tbl_remove(struct uint32_tbl *tbl, uint32_t key) { - uint_tbl_clear_rows(tbl, key, key + 1); + uint32_tbl_clear_rows(tbl, key, key + 1); } - -bool Curl_uint_tbl_contains(struct uint_tbl *tbl, unsigned int key) +bool Curl_uint32_tbl_contains(struct uint32_tbl *tbl, uint32_t key) { return (key < tbl->nrows) ? !!tbl->rows[key] : FALSE; } - -static bool uint_tbl_next_at(struct uint_tbl *tbl, unsigned int key, - unsigned int *pkey, void **pentry) +static bool uint32_tbl_next_at(struct uint32_tbl *tbl, uint32_t key, + uint32_t *pkey, void **pentry) { for(; key < tbl->nrows; ++key) { if(tbl->rows[key]) { @@ -183,33 +169,32 @@ static bool uint_tbl_next_at(struct uint_tbl *tbl, unsigned int key, return TRUE; } } - *pkey = UINT_MAX; /* always invalid */ + *pkey = UINT32_MAX; /* always invalid */ *pentry = NULL; return FALSE; } -bool Curl_uint_tbl_first(struct uint_tbl *tbl, - unsigned int *pkey, void **pentry) +bool Curl_uint32_tbl_first(struct uint32_tbl *tbl, + uint32_t *pkey, void **pentry) { if(!pkey || !pentry) return FALSE; - if(tbl->nentries && uint_tbl_next_at(tbl, 0, pkey, pentry)) + if(tbl->nentries && uint32_tbl_next_at(tbl, 0, pkey, pentry)) return TRUE; DEBUGASSERT(!tbl->nentries); - *pkey = UINT_MAX; /* always invalid */ + *pkey = UINT32_MAX; /* always invalid */ *pentry = NULL; return FALSE; } - -bool Curl_uint_tbl_next(struct uint_tbl *tbl, unsigned int last_key, - unsigned int *pkey, void **pentry) +bool Curl_uint32_tbl_next(struct uint32_tbl *tbl, uint32_t last_key, + uint32_t *pkey, void **pentry) { if(!pkey || !pentry) return FALSE; - if(uint_tbl_next_at(tbl, last_key + 1, pkey, pentry)) + if(uint32_tbl_next_at(tbl, last_key + 1, pkey, pentry)) return TRUE; - *pkey = UINT_MAX; /* always invalid */ + *pkey = UINT32_MAX; /* always invalid */ *pentry = NULL; return FALSE; } diff --git a/vendor/hydra/vendor/curl/lib/uint-table.h b/vendor/hydra/vendor/curl/lib/uint-table.h index c74ec7ad..3fc7e34e 100644 --- a/vendor/hydra/vendor/curl/lib/uint-table.h +++ b/vendor/hydra/vendor/curl/lib/uint-table.h @@ -25,17 +25,15 @@ ***************************************************************************/ #include "curl_setup.h" -#include - /* Destructor for a single table entry */ -typedef void Curl_uint_tbl_entry_dtor(unsigned int key, void *entry); +typedef void Curl_uint32_tbl_entry_dtor(uint32_t key, void *entry); -struct uint_tbl { +struct uint32_tbl { void **rows; /* array of void* holding entries */ - Curl_uint_tbl_entry_dtor *entry_dtor; - unsigned int nrows; /* length of `rows` array */ - unsigned int nentries; /* entries in table */ - unsigned int last_key_added; /* UINT_MAX or last key added */ + Curl_uint32_tbl_entry_dtor *entry_dtor; + uint32_t nrows; /* length of `rows` array */ + uint32_t nentries; /* entries in table */ + uint32_t last_key_added; /* UINT_MAX or last key added */ #ifdef DEBUGBUILD int init; #endif @@ -44,42 +42,42 @@ struct uint_tbl { /* Initialize the table with 0 capacity. * The optional `entry_dtor` is called when a table entry is removed, * Passing NULL means no action is taken on removal. */ -void Curl_uint_tbl_init(struct uint_tbl *tbl, - Curl_uint_tbl_entry_dtor *entry_dtor); +void Curl_uint32_tbl_init(struct uint32_tbl *tbl, + Curl_uint32_tbl_entry_dtor *entry_dtor); /* Resize the table to change capacity `nmax`. When `nmax` is reduced, * all present entries with key equal or larger to `nmax` are removed. */ -CURLcode Curl_uint_tbl_resize(struct uint_tbl *tbl, unsigned int nmax); +CURLcode Curl_uint32_tbl_resize(struct uint32_tbl *tbl, uint32_t nmax); /* Destroy the table, freeing all entries. */ -void Curl_uint_tbl_destroy(struct uint_tbl *tbl); +void Curl_uint32_tbl_destroy(struct uint32_tbl *tbl); /* Get the table capacity. */ -unsigned int Curl_uint_tbl_capacity(struct uint_tbl *tbl); +uint32_t Curl_uint32_tbl_capacity(struct uint32_tbl *tbl); /* Get the number of entries in the table. */ -unsigned int Curl_uint_tbl_count(struct uint_tbl *tbl); +uint32_t Curl_uint32_tbl_count(struct uint32_tbl *tbl); /* Get the entry for key or NULL if not present */ -void *Curl_uint_tbl_get(struct uint_tbl *tbl, unsigned int key); +void *Curl_uint32_tbl_get(struct uint32_tbl *tbl, uint32_t key); /* Add a new entry to the table and assign it a free key. * Returns FALSE if the table is full. * * Keys are assigned in a round-robin manner. * No matter the capacity, UINT_MAX is never assigned. */ -bool Curl_uint_tbl_add(struct uint_tbl *tbl, void *entry, unsigned int *pkey); +bool Curl_uint32_tbl_add(struct uint32_tbl *tbl, void *entry, uint32_t *pkey); /* Remove the entry with `key`. */ -void Curl_uint_tbl_remove(struct uint_tbl *tbl, unsigned int key); +void Curl_uint32_tbl_remove(struct uint32_tbl *tbl, uint32_t key); /* Return TRUE if the table contains an tryn with that keys. */ -bool Curl_uint_tbl_contains(struct uint_tbl *tbl, unsigned int key); +bool Curl_uint32_tbl_contains(struct uint32_tbl *tbl, uint32_t key); /* Get the first entry in the table (with the smallest `key`). * Returns FALSE if the table is empty. */ -bool Curl_uint_tbl_first(struct uint_tbl *tbl, - unsigned int *pkey, void **pentry); +bool Curl_uint32_tbl_first(struct uint32_tbl *tbl, + uint32_t *pkey, void **pentry); /* Get the next key in the table, following `last_key` in natural order. * Put another way, this is the smallest key greater than `last_key` in @@ -92,7 +90,7 @@ bool Curl_uint_tbl_first(struct uint_tbl *tbl, * - added keys lower than 'last_key' will not show up. * - removed keys lower or equal to 'last_key' will not show up. * - removed keys higher than 'last_key' will not be visited. */ -bool Curl_uint_tbl_next(struct uint_tbl *tbl, unsigned int last_key, - unsigned int *pkey, void **pentry); +bool Curl_uint32_tbl_next(struct uint32_tbl *tbl, uint32_t last_key, + uint32_t *pkey, void **pentry); #endif /* HEADER_CURL_UINT_TABLE_H */ diff --git a/vendor/hydra/vendor/curl/lib/url.c b/vendor/hydra/vendor/curl/lib/url.c index f0fe7d3d..130be195 100644 --- a/vendor/hydra/vendor/curl/lib/url.c +++ b/vendor/hydra/vendor/curl/lib/url.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifdef HAVE_NETINET_IN_H @@ -66,30 +65,22 @@ #include #endif -#include - #include "doh.h" #include "urldata.h" -#include "netrc.h" #include "formdata.h" #include "mime.h" +#include "bufref.h" #include "vtls/vtls.h" #include "hostip.h" #include "transfer.h" -#include "sendf.h" +#include "curl_trc.h" #include "progress.h" #include "cookie.h" #include "strcase.h" #include "escape.h" -#include "share.h" -#include "content_encoding.h" +#include "curl_share.h" #include "http_digest.h" -#include "http_negotiate.h" -#include "select.h" #include "multiif.h" -#include "easyif.h" -#include "speedcheck.h" -#include "curlx/warnless.h" #include "getinfo.h" #include "pop3.h" #include "urlapi-int.h" @@ -98,6 +89,16 @@ #include "noproxy.h" #include "cfilters.h" #include "idn.h" +#include "http_proxy.h" +#include "conncache.h" +#include "multihandle.h" +#include "strdup.h" +#include "setopt.h" +#include "altsvc.h" +#include "curlx/dynbuf.h" +#include "headers.h" +#include "curlx/strerr.h" +#include "curlx/strparse.h" /* And now for the protocols */ #include "ftp.h" @@ -105,31 +106,18 @@ #include "telnet.h" #include "tftp.h" #include "http.h" -#include "http2.h" #include "file.h" #include "curl_ldap.h" #include "vssh/ssh.h" #include "imap.h" #include "url.h" #include "connect.h" -#include "http_ntlm.h" #include "curl_rtmp.h" #include "gopher.h" #include "mqtt.h" -#include "http_proxy.h" -#include "conncache.h" -#include "multihandle.h" -#include "strdup.h" -#include "setopt.h" -#include "altsvc.h" -#include "curlx/dynbuf.h" -#include "headers.h" -#include "curlx/strerr.h" -#include "curlx/strparse.h" - -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" +#include "rtsp.h" +#include "smtp.h" +#include "ws.h" #ifdef USE_NGHTTP2 static void data_priority_cleanup(struct Curl_easy *data); @@ -153,16 +141,16 @@ static void data_priority_cleanup(struct Curl_easy *data); #define MAX_URL_LEN 0xffff /* -* get_protocol_family() -* -* This is used to return the protocol family for a given protocol. -* -* Parameters: -* -* 'h' [in] - struct Curl_handler pointer. -* -* Returns the family as a single bit protocol identifier. -*/ + * get_protocol_family() + * + * This is used to return the protocol family for a given protocol. + * + * Parameters: + * + * 'h' [in] - struct Curl_handler pointer. + * + * Returns the family as a single bit protocol identifier. + */ static curl_prot_t get_protocol_family(const struct Curl_handler *h) { DEBUGASSERT(h); @@ -184,16 +172,8 @@ void Curl_freeset(struct Curl_easy *data) Curl_safefree(data->set.blobs[j]); } - if(data->state.referer_alloc) { - Curl_safefree(data->state.referer); - data->state.referer_alloc = FALSE; - } - data->state.referer = NULL; - if(data->state.url_alloc) { - Curl_safefree(data->state.url); - data->state.url_alloc = FALSE; - } - data->state.url = NULL; + Curl_bufref_free(&data->state.referer); + Curl_bufref_free(&data->state.url); Curl_mime_cleanpart(&data->set.mimepost); @@ -258,7 +238,7 @@ CURLcode Curl_close(struct Curl_easy **datap) Curl_expire_clear(data); /* shut off any timers left */ if(data->state.rangestringalloc) - free(data->state.range); + curlx_free(data->state.range); /* release any resolve information this transfer kept */ Curl_async_destroy(data); @@ -279,11 +259,7 @@ CURLcode Curl_close(struct Curl_easy **datap) Curl_safefree(data->state.first_host); Curl_ssl_free_certinfo(data); - if(data->state.referer_alloc) { - Curl_safefree(data->state.referer); - data->state.referer_alloc = FALSE; - } - data->state.referer = NULL; + Curl_bufref_free(&data->state.referer); up_free(data); curlx_dyn_free(&data->state.headerb); @@ -347,7 +323,7 @@ CURLcode Curl_close(struct Curl_easy **datap) Curl_freeset(data); Curl_headers_cleanup(data); Curl_netrc_cleanup(&data->state.netrc); - free(data); + curlx_free(data); return CURLE_OK; } @@ -465,8 +441,7 @@ void Curl_init_userdefined(struct Curl_easy *data) set->conn_max_idle_ms = 118 * 1000; set->conn_max_age_ms = 24 * 3600 * 1000; set->http09_allowed = FALSE; - set->httpwant = CURL_HTTP_VERSION_NONE - ; + set->httpwant = CURL_HTTP_VERSION_NONE; #if defined(USE_HTTP2) || defined(USE_HTTP3) memset(&set->priority, 0, sizeof(set->priority)); #endif @@ -501,7 +476,7 @@ CURLcode Curl_open(struct Curl_easy **curl) struct Curl_easy *data; /* simple start-up: alloc the struct, init it with zeroes and return */ - data = calloc(1, sizeof(struct Curl_easy)); + data = curlx_calloc(1, sizeof(struct Curl_easy)); if(!data) { /* this is a serious error */ DEBUGF(curl_mfprintf(stderr, "Error: calloc of Curl_easy failed\n")); @@ -514,14 +489,16 @@ CURLcode Curl_open(struct Curl_easy **curl) data->state.recent_conn_id = -1; /* and not assigned an id yet */ data->id = -1; - data->mid = UINT_MAX; - data->master_mid = UINT_MAX; + data->mid = UINT32_MAX; + data->master_mid = UINT32_MAX; data->progress.hide = TRUE; data->state.current_speed = -1; /* init to negative == impossible */ Curl_hash_init(&data->meta_hash, 23, Curl_hash_str, curlx_str_key_compare, easy_meta_freeentry); curlx_dyn_init(&data->state.headerb, CURL_MAX_HTTP_HEADER); + Curl_bufref_init(&data->state.url); + Curl_bufref_init(&data->state.referer); Curl_req_init(&data->req); Curl_initinfo(data); #ifndef CURL_DISABLE_HTTP @@ -576,10 +553,9 @@ void Curl_conn_free(struct Curl_easy *data, struct connectdata *conn) Curl_safefree(conn->unix_domain_socket); #endif Curl_safefree(conn->destination); - Curl_uint_spbset_destroy(&conn->xfers_attached); Curl_hash_destroy(&conn->meta_hash); - free(conn); /* free all the connection oriented data */ + curlx_free(conn); /* free all the connection oriented data */ } /* @@ -597,7 +573,7 @@ static bool xfer_may_multiplex(const struct Curl_easy *data, (!conn->bits.protoconnstart || !conn->bits.close)) { if(Curl_multiplex_wanted(data->multi) && - (data->state.http_neg.allowed & (CURL_HTTP_V2x|CURL_HTTP_V3x))) + (data->state.http_neg.allowed & (CURL_HTTP_V2x | CURL_HTTP_V3x))) /* allows HTTP/2 or newer */ return TRUE; } @@ -609,9 +585,8 @@ static bool xfer_may_multiplex(const struct Curl_easy *data, } #ifndef CURL_DISABLE_PROXY -static bool -proxy_info_matches(const struct proxy_info *data, - const struct proxy_info *needle) +static bool proxy_info_matches(const struct proxy_info *data, + const struct proxy_info *needle) { if((data->proxytype == needle->proxytype) && (data->port == needle->port) && @@ -621,9 +596,8 @@ proxy_info_matches(const struct proxy_info *data, return FALSE; } -static bool -socks_proxy_info_matches(const struct proxy_info *data, - const struct proxy_info *needle) +static bool socks_proxy_info_matches(const struct proxy_info *data, + const struct proxy_info *needle) { if(!proxy_info_matches(data, needle)) return FALSE; @@ -641,8 +615,8 @@ socks_proxy_info_matches(const struct proxy_info *data, } #else /* disabled, will not get called */ -#define proxy_info_matches(x,y) FALSE -#define socks_proxy_info_matches(x,y) FALSE +#define proxy_info_matches(x, y) FALSE +#define socks_proxy_info_matches(x, y) FALSE #endif /* A connection has to have been idle for less than 'conn_max_idle_ms' @@ -655,7 +629,7 @@ static bool conn_maxage(struct Curl_easy *data, timediff_t age_ms; if(data->set.conn_max_idle_ms) { - age_ms = curlx_timediff(now, conn->lastused); + age_ms = curlx_ptimediff_ms(&now, &conn->lastused); if(age_ms > data->set.conn_max_idle_ms) { infof(data, "Too old connection (%" FMT_TIMEDIFF_T " ms idle, max idle is %" FMT_TIMEDIFF_T " ms), disconnect it", @@ -665,7 +639,7 @@ static bool conn_maxage(struct Curl_easy *data, } if(data->set.conn_max_age_ms) { - age_ms = curlx_timediff(now, conn->created); + age_ms = curlx_ptimediff_ms(&now, &conn->created); if(age_ms > data->set.conn_max_age_ms) { infof(data, "Too old connection (created %" FMT_TIMEDIFF_T @@ -682,21 +656,15 @@ static bool conn_maxage(struct Curl_easy *data, * Return TRUE iff the given connection is considered dead. */ bool Curl_conn_seems_dead(struct connectdata *conn, - struct Curl_easy *data, - struct curltime *pnow) + struct Curl_easy *data) { DEBUGASSERT(!data->conn); if(!CONN_INUSE(conn)) { /* The check for a dead socket makes sense only if the connection is not in use */ bool dead; - struct curltime now; - if(!pnow) { - now = curlx_now(); - pnow = &now; - } - if(conn_maxage(data, conn, *pnow)) { + if(conn_maxage(data, conn, *Curl_pgrs_now(data))) { /* avoid check if already too old */ dead = TRUE; } @@ -713,7 +681,6 @@ bool Curl_conn_seems_dead(struct connectdata *conn, dead = (state & CONNRESULT_DEAD); /* detach the connection again */ Curl_detach_connection(data); - } else { bool input_pending = FALSE; @@ -746,11 +713,11 @@ bool Curl_conn_seems_dead(struct connectdata *conn, } CURLcode Curl_conn_upkeep(struct Curl_easy *data, - struct connectdata *conn, - struct curltime *now) + struct connectdata *conn) { CURLcode result = CURLE_OK; - if(curlx_timediff(*now, conn->keepalive) <= data->set.upkeep_interval_ms) + if(curlx_ptimediff_ms(Curl_pgrs_now(data), &conn->keepalive) <= + data->set.upkeep_interval_ms) return result; /* briefly attach for action */ @@ -768,7 +735,7 @@ CURLcode Curl_conn_upkeep(struct Curl_easy *data, } Curl_detach_connection(data); - conn->keepalive = *now; + conn->keepalive = *Curl_pgrs_now(data); return result; } @@ -808,8 +775,8 @@ static bool url_match_connect_config(struct connectdata *conn, return FALSE; /* ip_version must match */ - if(m->data->set.ipver != CURL_IPRESOLVE_WHATEVER - && m->data->set.ipver != conn->ip_version) + if(m->data->set.ipver != CURL_IPRESOLVE_WHATEVER && + m->data->set.ipver != conn->ip_version) return FALSE; if(m->needle->localdev || m->needle->localport) { @@ -911,16 +878,16 @@ static bool url_match_multiplex_limits(struct connectdata *conn, if(CONN_INUSE(conn) && m->may_multiplex) { DEBUGASSERT(conn->bits.multiplex); /* If multiplexed, make sure we do not go over concurrency limit */ - if(CONN_ATTACHED(conn) >= + if(conn->attached_xfers >= Curl_multi_max_concurrent_streams(m->data->multi)) { infof(m->data, "client side MAX_CONCURRENT_STREAMS reached" - ", skip (%u)", CONN_ATTACHED(conn)); + ", skip (%u)", conn->attached_xfers); return FALSE; } - if(CONN_ATTACHED(conn) >= - Curl_conn_get_max_concurrent(m->data, conn, FIRSTSOCKET)) { + if(conn->attached_xfers >= + Curl_conn_get_max_concurrent(m->data, conn, FIRSTSOCKET)) { infof(m->data, "MAX_CONCURRENT_STREAMS reached, skip (%u)", - CONN_ATTACHED(conn)); + conn->attached_xfers); return FALSE; } /* When not multiplexed, we have a match here! */ @@ -956,8 +923,7 @@ static bool url_match_proxy_use(struct connectdata *conn, return FALSE; if(m->needle->bits.socksproxy && - !socks_proxy_info_matches(&m->needle->socks_proxy, - &conn->socks_proxy)) + !socks_proxy_info_matches(&m->needle->socks_proxy, &conn->socks_proxy)) return FALSE; if(m->needle->bits.httpproxy) { @@ -974,9 +940,9 @@ static bool url_match_proxy_use(struct connectdata *conn, /* match SSL config to proxy */ if(!Curl_ssl_conn_config_match(m->data, conn, TRUE)) { DEBUGF(infof(m->data, - "Connection #%" FMT_OFF_T - " has different SSL proxy parameters, cannot reuse", - conn->connection_id)); + "Connection #%" FMT_OFF_T + " has different SSL proxy parameters, cannot reuse", + conn->connection_id)); return FALSE; } /* the SSL config to the server, which may apply here is checked @@ -986,7 +952,7 @@ static bool url_match_proxy_use(struct connectdata *conn, return TRUE; } #else -#define url_match_proxy_use(c,m) ((void)c, (void)m, TRUE) +#define url_match_proxy_use(c, m) ((void)c, (void)m, TRUE) #endif #ifndef CURL_DISABLE_HTTP @@ -994,7 +960,7 @@ static bool url_match_http_multiplex(struct connectdata *conn, struct url_conn_match *m) { if(m->may_multiplex && - (m->data->state.http_neg.allowed & (CURL_HTTP_V2x|CURL_HTTP_V3x)) && + (m->data->state.http_neg.allowed & (CURL_HTTP_V2x | CURL_HTTP_V3x)) && (m->needle->handler->protocol & CURLPROTO_HTTP) && !conn->httpversion_seen) { if(m->data->set.pipewait) { @@ -1042,8 +1008,8 @@ static bool url_match_http_version(struct connectdata *conn, return TRUE; } #else -#define url_match_http_multiplex(c,m) ((void)c, (void)m, TRUE) -#define url_match_http_version(c,m) ((void)c, (void)m, TRUE) +#define url_match_http_multiplex(c, m) ((void)c, (void)m, TRUE) +#define url_match_http_version(c, m) ((void)c, (void)m, TRUE) #endif static bool url_match_proto_config(struct connectdata *conn, @@ -1096,7 +1062,7 @@ static bool url_match_destination(struct connectdata *conn, { /* Additional match requirements if talking TLS OR * not talking to an HTTP proxy OR using a tunnel through a proxy */ - if((m->needle->handler->flags&PROTOPT_SSL) + if((m->needle->handler->flags & PROTOPT_SSL) #ifndef CURL_DISABLE_PROXY || !m->needle->bits.httpproxy || m->needle->bits.tunnel_proxy #endif @@ -1121,7 +1087,7 @@ static bool url_match_destination(struct connectdata *conn, if((m->needle->bits.conn_to_host && !curl_strequal( m->needle->conn_to_host.name, conn->conn_to_host.name)) || (m->needle->bits.conn_to_port && - m->needle->conn_to_port != conn->conn_to_port)) + m->needle->conn_to_port != conn->conn_to_port)) return FALSE; /* hostname and port must match */ @@ -1212,7 +1178,7 @@ static bool url_match_auth_ntlm(struct connectdata *conn, return TRUE; } #else -#define url_match_auth_ntlm(c,m) ((void)c, (void)m, TRUE) +#define url_match_auth_ntlm(c, m) ((void)c, (void)m, TRUE) #endif static bool url_match_conn(struct connectdata *conn, void *userdata) @@ -1261,7 +1227,7 @@ static bool url_match_conn(struct connectdata *conn, void *userdata) if(!url_match_multiplex_limits(conn, m)) return FALSE; - if(!CONN_INUSE(conn) && Curl_conn_seems_dead(conn, m->data, NULL)) { + if(!CONN_INUSE(conn) && Curl_conn_seems_dead(conn, m->data)) { /* remove and disconnect. */ Curl_conn_terminate(m->data, conn, FALSE); return FALSE; @@ -1283,7 +1249,7 @@ static bool url_match_result(bool result, void *userdata) return TRUE; } else if(match->seen_single_use_conn && !match->seen_multiplex_conn) { - /* We've seen a single-use, existing connection to the destination and + /* We have seen a single-use, existing connection to the destination and * no multiplexed one. It seems safe to assume that the server does * not support multiplexing. */ match->wait_pipe = FALSE; @@ -1308,12 +1274,11 @@ static bool url_match_result(bool result, void *userdata) * * The force_reuse flag is set if the connection must be used. */ -static bool -ConnectionExists(struct Curl_easy *data, - struct connectdata *needle, - struct connectdata **usethis, - bool *force_reuse, - bool *waitpipe) +static bool ConnectionExists(struct Curl_easy *data, + struct connectdata *needle, + struct connectdata **usethis, + bool *force_reuse, + bool *waitpipe) { struct url_conn_match match; bool result; @@ -1352,7 +1317,7 @@ ConnectionExists(struct Curl_easy *data, */ static struct connectdata *allocate_conn(struct Curl_easy *data) { - struct connectdata *conn = calloc(1, sizeof(struct connectdata)); + struct connectdata *conn = curlx_calloc(1, sizeof(struct connectdata)); if(!conn) return NULL; @@ -1363,15 +1328,11 @@ static struct connectdata *allocate_conn(struct Curl_easy *data) conn->recv_idx = 0; /* default for receiving transfer data */ conn->send_idx = 0; /* default for sending transfer data */ conn->connection_id = -1; /* no ID */ + conn->attached_xfers = 0; conn->remote_port = -1; /* unknown at this point */ - /* Default protocol-independent behavior does not support persistent - connections, so we set this to force-close. Protocols that support - this need to set this to FALSE in their "curl_do" functions. */ - connclose(conn, "Default to force-close"); - /* Store creation time to help future close decision making */ - conn->created = curlx_now(); + conn->created = *Curl_pgrs_now(data); /* Store current time to give a baseline to keepalive connection times. */ conn->keepalive = conn->created; @@ -1407,12 +1368,9 @@ static struct connectdata *allocate_conn(struct Curl_easy *data) conn->connect_only = data->set.connect_only; conn->transport_wanted = TRNSPRT_TCP; /* most of them are TCP streams */ - /* Initialize the attached xfers bitset */ - Curl_uint_spbset_init(&conn->xfers_attached); - /* Store the local bind parameters that will be used for this connection */ if(data->set.str[STRING_DEVICE]) { - conn->localdev = strdup(data->set.str[STRING_DEVICE]); + conn->localdev = curlx_strdup(data->set.str[STRING_DEVICE]); if(!conn->localdev) goto error; } @@ -1429,11 +1387,12 @@ static struct connectdata *allocate_conn(struct Curl_easy *data) #ifdef HAVE_GSSAPI conn->gssapi_delegation = data->set.gssapi_delegation; #endif + DEBUGF(infof(data, "alloc connection, bits.close=%d", conn->bits.close)); return conn; error: - free(conn->localdev); - free(conn); + curlx_free(conn->localdev); + curlx_free(conn); return NULL; } @@ -1568,7 +1527,7 @@ const struct Curl_handler *Curl_getn_scheme_handler(const char *scheme, #else NULL, #endif -#if defined(USE_SSH) +#ifdef USE_SSH &Curl_handler_scp, #else NULL, @@ -1685,12 +1644,11 @@ static CURLcode findprotocol(struct Curl_easy *data, create_conn() function when the connectdata struct is allocated. */ failf(data, "Protocol \"%s\" %s%s", protostr, p ? "disabled" : "not supported", - data->state.this_is_a_follow ? " (in redirect)":""); + data->state.this_is_a_follow ? " (in redirect)" : ""); return CURLE_UNSUPPORTED_PROTOCOL; } - CURLcode Curl_uc_to_curlcode(CURLUcode uc) { switch(uc) { @@ -1752,11 +1710,11 @@ static void zonefrom_url(CURLU *uh, struct Curl_easy *data, } #endif /* HAVE_IF_NAMETOINDEX || _WIN32 */ - free(zoneid); + curlx_free(zoneid); } } #else -#define zonefrom_url(a,b,c) Curl_nop_stmt +#define zonefrom_url(a, b, c) Curl_nop_stmt #endif /* @@ -1785,22 +1743,19 @@ static CURLcode parseurlandfillconn(struct Curl_easy *data, return CURLE_OUT_OF_MEMORY; if(data->set.str[STRING_DEFAULT_PROTOCOL] && - !Curl_is_absolute_url(data->state.url, NULL, 0, TRUE)) { + !Curl_is_absolute_url(Curl_bufref_ptr(&data->state.url), NULL, 0, TRUE)) { char *url = curl_maprintf("%s://%s", data->set.str[STRING_DEFAULT_PROTOCOL], - data->state.url); + Curl_bufref_ptr(&data->state.url)); if(!url) return CURLE_OUT_OF_MEMORY; - if(data->state.url_alloc) - free(data->state.url); - data->state.url = url; - data->state.url_alloc = TRUE; + Curl_bufref_set(&data->state.url, url, 0, curl_free); } if(!use_set_uh) { char *newurl; - uc = curl_url_set(uh, CURLUPART_URL, data->state.url, (unsigned int) - (CURLU_GUESS_SCHEME | + uc = curl_url_set(uh, CURLUPART_URL, Curl_bufref_ptr(&data->state.url), + (unsigned int)(CURLU_GUESS_SCHEME | CURLU_NON_SUPPORT_SCHEME | (data->set.disallow_username_in_url ? CURLU_DISALLOW_USER : 0) | @@ -1814,10 +1769,7 @@ static CURLcode parseurlandfillconn(struct Curl_easy *data, uc = curl_url_get(uh, CURLUPART_URL, &newurl, 0); if(uc) return Curl_uc_to_curlcode(uc); - if(data->state.url_alloc) - free(data->state.url); - data->state.url = newurl; - data->state.url_alloc = TRUE; + Curl_bufref_set(&data->state.url, newurl, 0, curl_free); } uc = curl_url_get(uh, CURLUPART_SCHEME, &data->state.up.scheme, 0); @@ -1849,7 +1801,7 @@ static CURLcode parseurlandfillconn(struct Curl_easy *data, } /* make sure the connect struct gets its own copy of the hostname */ - conn->host.rawalloc = strdup(hostname ? hostname : ""); + conn->host.rawalloc = curlx_strdup(hostname ? hostname : ""); if(!conn->host.rawalloc) return CURLE_OUT_OF_MEMORY; conn->host.name = conn->host.rawalloc; @@ -1871,21 +1823,18 @@ static CURLcode parseurlandfillconn(struct Curl_easy *data, uc = curl_url_set(uh, CURLUPART_SCHEME, "https", 0); if(uc) return Curl_uc_to_curlcode(uc); - if(data->state.url_alloc) - Curl_safefree(data->state.url); + Curl_bufref_free(&data->state.url); /* after update, get the updated version */ uc = curl_url_get(uh, CURLUPART_URL, &url, 0); if(uc) return Curl_uc_to_curlcode(uc); uc = curl_url_get(uh, CURLUPART_SCHEME, &data->state.up.scheme, 0); if(uc) { - free(url); + curlx_free(url); return Curl_uc_to_curlcode(uc); } - data->state.url = url; - data->state.url_alloc = TRUE; - infof(data, "Switched from HTTP to HTTPS due to HSTS => %s", - data->state.url); + Curl_bufref_set(&data->state.url, url, 0, curl_free); + infof(data, "Switched from HTTP to HTTPS due to HSTS => %s", url); } } #endif @@ -1942,22 +1891,22 @@ static CURLcode parseurlandfillconn(struct Curl_easy *data, uc = curl_url_get(uh, CURLUPART_OPTIONS, &data->state.up.options, CURLU_URLDECODE); if(!uc) { - conn->options = strdup(data->state.up.options); + conn->options = curlx_strdup(data->state.up.options); if(!conn->options) return CURLE_OUT_OF_MEMORY; } else if(uc != CURLUE_NO_OPTIONS) return Curl_uc_to_curlcode(uc); - uc = curl_url_get(uh, CURLUPART_PATH, &data->state.up.path, - CURLU_URLENCODE); + uc = curl_url_get(uh, CURLUPART_PATH, &data->state.up.path, CURLU_URLENCODE); if(uc) return Curl_uc_to_curlcode(uc); uc = curl_url_get(uh, CURLUPART_PORT, &data->state.up.port, CURLU_DEFAULT_PORT); if(uc) { - if(!curl_strequal("file", data->state.up.scheme)) + if((uc == CURLUE_OUT_OF_MEMORY) || + !curl_strequal("file", data->state.up.scheme)) return CURLE_OUT_OF_MEMORY; } else { @@ -1974,7 +1923,9 @@ static CURLcode parseurlandfillconn(struct Curl_easy *data, conn->remote_port = (unsigned short)port; } - (void)curl_url_get(uh, CURLUPART_QUERY, &data->state.up.query, 0); + uc = curl_url_get(uh, CURLUPART_QUERY, &data->state.up.query, 0); + if(uc && (uc != CURLUE_NO_QUERY)) + return CURLE_OUT_OF_MEMORY; #ifdef USE_IPV6 if(data->set.scope_id) @@ -1985,7 +1936,6 @@ static CURLcode parseurlandfillconn(struct Curl_easy *data, return CURLE_OK; } - /* * If we are doing a resumed transfer, we need to setup our stuff * properly. @@ -1996,12 +1946,12 @@ static CURLcode setup_range(struct Curl_easy *data) s->resume_from = data->set.set_resume_from; if(s->resume_from || data->set.str[STRING_SET_RANGE]) { if(s->rangestringalloc) - free(s->range); + curlx_free(s->range); if(s->resume_from) s->range = curl_maprintf("%" FMT_OFF_T "-", s->resume_from); else - s->range = strdup(data->set.str[STRING_SET_RANGE]); + s->range = curlx_strdup(data->set.str[STRING_SET_RANGE]); if(!s->range) return CURLE_OUT_OF_MEMORY; @@ -2017,7 +1967,6 @@ static CURLcode setup_range(struct Curl_easy *data) return CURLE_OK; } - /* * setup_connection_internals() - * @@ -2034,11 +1983,13 @@ static CURLcode setup_connection_internals(struct Curl_easy *data, int port; CURLcode result; + DEBUGF(infof(data, "setup connection, bits.close=%d", conn->bits.close)); if(conn->handler->setup_connection) { result = conn->handler->setup_connection(data, conn); if(result) return result; } + DEBUGF(infof(data, "setup connection, bits.close=%d", conn->bits.close)); /* Now create the destination name */ #ifndef CURL_DISABLE_PROXY @@ -2071,15 +2022,14 @@ static CURLcode setup_connection_internals(struct Curl_easy *data, return CURLE_OK; } - #ifndef CURL_DISABLE_PROXY #ifndef CURL_DISABLE_HTTP /**************************************************************** -* Detect what (if any) proxy to use. Remember that this selects a host -* name and is not limited to HTTP proxies only. -* The returned pointer must be freed by the caller (unless NULL) -****************************************************************/ + * Detect what (if any) proxy to use. Remember that this selects a host + * name and is not limited to HTTP proxies only. + * The returned pointer must be freed by the caller (unless NULL) + ****************************************************************/ static char *detect_proxy(struct Curl_easy *data, struct connectdata *conn) { @@ -2172,7 +2122,6 @@ static CURLcode parse_proxy(struct Curl_easy *data, long proxytype) { char *portptr = NULL; - int port = -1; char *proxyuser = NULL; char *proxypasswd = NULL; char *host = NULL; @@ -2187,7 +2136,6 @@ static CURLcode parse_proxy(struct Curl_easy *data, bool is_unix_proxy = FALSE; #endif - if(!uhp) { result = CURLE_OUT_OF_MEMORY; goto error; @@ -2196,7 +2144,7 @@ static CURLcode parse_proxy(struct Curl_easy *data, /* When parsing the proxy, allowing non-supported schemes since we have these made up ones for proxies. Guess scheme for URLs without it. */ uc = curl_url_set(uhp, CURLUPART_URL, proxy, - CURLU_NON_SUPPORT_SCHEME|CURLU_GUESS_SCHEME); + CURLU_NON_SUPPORT_SCHEME | CURLU_GUESS_SCHEME); if(!uc) { /* parsed okay as a URL */ uc = curl_url_get(uhp, CURLUPART_SCHEME, &scheme, 0); @@ -2257,14 +2205,18 @@ static CURLcode parse_proxy(struct Curl_easy *data, /* Is there a username and password given in this proxy url? */ uc = curl_url_get(uhp, CURLUPART_USER, &proxyuser, CURLU_URLDECODE); - if(uc && (uc != CURLUE_NO_USER)) + if(uc && (uc != CURLUE_NO_USER)) { + result = Curl_uc_to_curlcode(uc); goto error; + } uc = curl_url_get(uhp, CURLUPART_PASSWORD, &proxypasswd, CURLU_URLDECODE); - if(uc && (uc != CURLUE_NO_PASSWORD)) + if(uc && (uc != CURLUE_NO_PASSWORD)) { + result = Curl_uc_to_curlcode(uc); goto error; + } if(proxyuser || proxypasswd) { - free(proxyinfo->user); + curlx_free(proxyinfo->user); proxyinfo->user = proxyuser; result = Curl_setstropt(&data->state.aptr.proxyuser, proxyuser); proxyuser = NULL; @@ -2272,7 +2224,7 @@ static CURLcode parse_proxy(struct Curl_easy *data, goto error; Curl_safefree(proxyinfo->passwd); if(!proxypasswd) { - proxypasswd = strdup(""); + proxypasswd = curlx_strdup(""); if(!proxypasswd) { result = CURLE_OUT_OF_MEMORY; goto error; @@ -2286,29 +2238,32 @@ static CURLcode parse_proxy(struct Curl_easy *data, conn->bits.proxy_user_passwd = TRUE; /* enable it */ } - (void)curl_url_get(uhp, CURLUPART_PORT, &portptr, 0); + uc = curl_url_get(uhp, CURLUPART_PORT, &portptr, 0); + if(uc == CURLUE_OUT_OF_MEMORY) { + result = CURLE_OUT_OF_MEMORY; + goto error; + } if(portptr) { curl_off_t num; const char *p = portptr; - if(!curlx_str_number(&p, &num, 0xffff)) - port = (int)num; - free(portptr); + if(!curlx_str_number(&p, &num, UINT16_MAX)) + proxyinfo->port = (uint16_t)num; + /* Should we not error out when the port number is invalid? */ + curlx_free(portptr); } else { if(data->set.proxyport) /* None given in the proxy string, then get the default one if it is given */ - port = (int)data->set.proxyport; + proxyinfo->port = data->set.proxyport; else { if(IS_HTTPS_PROXY(proxytype)) - port = CURL_DEFAULT_HTTPS_PROXY_PORT; + proxyinfo->port = CURL_DEFAULT_HTTPS_PROXY_PORT; else - port = CURL_DEFAULT_PROXY_PORT; + proxyinfo->port = CURL_DEFAULT_PROXY_PORT; } } - if(port >= 0) - proxyinfo->port = port; /* now, clone the proxy hostname */ uc = curl_url_get(uhp, CURLUPART_HOST, &host, CURLU_URLDECODE); @@ -2326,13 +2281,13 @@ static CURLcode parse_proxy(struct Curl_easy *data, /* path will be "/", if no path was found */ if(strcmp("/", path)) { is_unix_proxy = TRUE; - free(host); - host = curl_maprintf(UNIX_SOCKET_PREFIX"%s", path); + curlx_free(host); + host = curl_maprintf(UNIX_SOCKET_PREFIX "%s", path); if(!host) { result = CURLE_OUT_OF_MEMORY; goto error; } - free(proxyinfo->host.rawalloc); + curlx_free(proxyinfo->host.rawalloc); proxyinfo->host.rawalloc = host; proxyinfo->host.name = host; host = NULL; @@ -2341,12 +2296,12 @@ static CURLcode parse_proxy(struct Curl_easy *data, if(!is_unix_proxy) { #endif - free(proxyinfo->host.rawalloc); + curlx_free(proxyinfo->host.rawalloc); proxyinfo->host.rawalloc = host; if(host[0] == '[') { /* this is a numerical IPv6, strip off the brackets */ size_t len = strlen(host); - host[len-1] = 0; /* clear the trailing bracket */ + host[len - 1] = 0; /* clear the trailing bracket */ host++; zonefrom_url(uhp, data, conn); } @@ -2357,12 +2312,12 @@ static CURLcode parse_proxy(struct Curl_easy *data, #endif error: - free(proxyuser); - free(proxypasswd); - free(host); - free(scheme); + curlx_free(proxyuser); + curlx_free(proxypasswd); + curlx_free(host); + curlx_free(scheme); #ifdef USE_UNIX_SOCKETS - free(path); + curlx_free(path); #endif curl_url_cleanup(uhp); return result; @@ -2380,9 +2335,9 @@ static CURLcode parse_proxy_auth(struct Curl_easy *data, data->state.aptr.proxypasswd : ""; CURLcode result = CURLE_OUT_OF_MEMORY; - conn->http_proxy.user = strdup(proxyuser); + conn->http_proxy.user = curlx_strdup(proxyuser); if(conn->http_proxy.user) { - conn->http_proxy.passwd = strdup(proxypasswd); + conn->http_proxy.passwd = curlx_strdup(proxypasswd); if(conn->http_proxy.passwd) result = CURLE_OK; else @@ -2414,7 +2369,7 @@ static CURLcode create_conn_helper_init_proxy(struct Curl_easy *data, * Detect what (if any) proxy to use *************************************************************/ if(data->set.str[STRING_PROXY]) { - proxy = strdup(data->set.str[STRING_PROXY]); + proxy = curlx_strdup(data->set.str[STRING_PROXY]); /* if global proxy is set, this is it */ if(!proxy) { failf(data, "memory shortage"); @@ -2424,7 +2379,7 @@ static CURLcode create_conn_helper_init_proxy(struct Curl_easy *data, } if(data->set.str[STRING_PRE_PROXY]) { - socksproxy = strdup(data->set.str[STRING_PRE_PROXY]); + socksproxy = curlx_strdup(data->set.str[STRING_PRE_PROXY]); /* if global socks proxy is set, this is it */ if(!socksproxy) { failf(data, "memory shortage"); @@ -2460,20 +2415,21 @@ static CURLcode create_conn_helper_init_proxy(struct Curl_easy *data, #ifdef USE_UNIX_SOCKETS /* For the time being do not mix proxy and Unix domain sockets. See #1274 */ if(proxy && conn->unix_domain_socket) { - free(proxy); + curlx_free(proxy); proxy = NULL; } #endif if(proxy && (!*proxy || (conn->handler->flags & PROTOPT_NONETWORK))) { - free(proxy); /* Do not bother with an empty proxy string or if the - protocol does not work with network */ + curlx_free(proxy); /* Do not bother with an empty proxy string + or if the protocol does not work with network */ proxy = NULL; } if(socksproxy && (!*socksproxy || (conn->handler->flags & PROTOPT_NONETWORK))) { - free(socksproxy); /* Do not bother with an empty socks proxy string or if - the protocol does not work with network */ + curlx_free(socksproxy); /* Do not bother with an empty socks proxy string + or if the protocol does not work with + network */ socksproxy = NULL; } @@ -2528,7 +2484,7 @@ static CURLcode create_conn_helper_init_proxy(struct Curl_easy *data, if(!conn->socks_proxy.user) { conn->socks_proxy.user = conn->http_proxy.user; conn->http_proxy.user = NULL; - free(conn->socks_proxy.passwd); + curlx_free(conn->socks_proxy.passwd); conn->socks_proxy.passwd = conn->http_proxy.passwd; conn->http_proxy.passwd = NULL; } @@ -2558,8 +2514,8 @@ static CURLcode create_conn_helper_init_proxy(struct Curl_easy *data, out: - free(socksproxy); - free(proxy); + curlx_free(socksproxy); + curlx_free(proxy); return result; } #endif /* CURL_DISABLE_PROXY */ @@ -2653,8 +2609,8 @@ CURLcode Curl_parse_login_details(const char *login, const size_t len, *passwdp = pbuf; return CURLE_OK; error: - free(ubuf); - free(pbuf); + curlx_free(ubuf); + curlx_free(pbuf); return CURLE_OUT_OF_MEMORY; } @@ -2712,8 +2668,8 @@ static CURLcode override_login(struct Curl_easy *data, char **optionsp = &conn->options; if(data->set.str[STRING_OPTIONS]) { - free(*optionsp); - *optionsp = strdup(data->set.str[STRING_OPTIONS]); + curlx_free(*optionsp); + *optionsp = curlx_strdup(data->set.str[STRING_OPTIONS]); if(!*optionsp) return CURLE_OUT_OF_MEMORY; } @@ -2739,9 +2695,11 @@ static CURLcode override_login(struct Curl_easy *data, NETRCcode ret = Curl_parsenetrc(&data->state.netrc, conn->host.name, userp, passwdp, data->set.str[STRING_NETRC_FILE]); - if(ret && ((ret == NETRC_NO_MATCH) || - (data->set.use_netrc == CURL_NETRC_OPTIONAL))) { - infof(data, "Couldn't find host %s in the %s file; using defaults", + if(ret == NETRC_OUT_OF_MEMORY) + return CURLE_OUT_OF_MEMORY; + else if(ret && ((ret == NETRC_NO_MATCH) || + (data->set.use_netrc == CURL_NETRC_OPTIONAL))) { + infof(data, "Could not find host %s in the %s file; using defaults", conn->host.name, (data->set.str[STRING_NETRC_FILE] ? data->set.str[STRING_NETRC_FILE] : ".netrc")); @@ -2752,8 +2710,8 @@ static CURLcode override_login(struct Curl_easy *data, return CURLE_READ_ERROR; } else { - if(!(conn->handler->flags&PROTOPT_USERPWDCTRL)) { - /* if the protocol can't handle control codes in credentials, make + if(!(conn->handler->flags & PROTOPT_USERPWDCTRL)) { + /* if the protocol cannot handle control codes in credentials, make sure there are none */ if(str_has_ctrl(*userp) || str_has_ctrl(*passwdp)) { failf(data, "control code detected in .netrc credentials"); @@ -2767,14 +2725,14 @@ static CURLcode override_login(struct Curl_easy *data, } } if(url_provided) { - free(conn->user); - conn->user = strdup(*userp); + curlx_free(conn->user); + conn->user = curlx_strdup(*userp); if(!conn->user) return CURLE_OUT_OF_MEMORY; } /* no user was set but a password, set a blank user */ if(!*userp && *passwdp) { - *userp = strdup(""); + *userp = curlx_strdup(""); if(!*userp) return CURLE_OUT_OF_MEMORY; } @@ -2798,7 +2756,7 @@ static CURLcode override_login(struct Curl_easy *data, if(uc) return Curl_uc_to_curlcode(uc); if(!*userp) { - *userp = strdup(data->state.aptr.user); + *userp = curlx_strdup(data->state.aptr.user); if(!*userp) return CURLE_OUT_OF_MEMORY; } @@ -2815,7 +2773,7 @@ static CURLcode override_login(struct Curl_easy *data, if(uc) return Curl_uc_to_curlcode(uc); if(!*passwdp) { - *passwdp = strdup(data->state.aptr.passwd); + *passwdp = curlx_strdup(data->state.aptr.passwd); if(!*passwdp) return CURLE_OUT_OF_MEMORY; } @@ -2843,14 +2801,14 @@ static CURLcode set_login(struct Curl_easy *data, } /* Store the default user */ if(!conn->user) { - conn->user = strdup(setuser); + conn->user = curlx_strdup(setuser); if(!conn->user) return CURLE_OUT_OF_MEMORY; } /* Store the default password */ if(!conn->passwd) { - conn->passwd = strdup(setpasswd); + conn->passwd = curlx_strdup(setpasswd); if(!conn->passwd) result = CURLE_OUT_OF_MEMORY; } @@ -2885,7 +2843,7 @@ static CURLcode parse_connect_to_host_port(struct Curl_easy *data, if(!host || !*host) return CURLE_OK; - host_dup = strdup(host); + host_dup = curlx_strdup(host); if(!host_dup) return CURLE_OUT_OF_MEMORY; @@ -2947,7 +2905,7 @@ static CURLcode parse_connect_to_host_port(struct Curl_easy *data, /* now, clone the cleaned hostname */ DEBUGASSERT(hostptr); - *hostname_result = strdup(hostptr); + *hostname_result = curlx_strdup(hostptr); if(!*hostname_result) { result = CURLE_OUT_OF_MEMORY; goto error; @@ -2956,7 +2914,7 @@ static CURLcode parse_connect_to_host_port(struct Curl_easy *data, *port_result = port; error: - free(host_dup); + curlx_free(host_dup); return result; } @@ -2995,7 +2953,7 @@ static CURLcode parse_connect_to_string(struct Curl_easy *data, hostname_to_match_len = strlen(hostname_to_match); host_match = curl_strnequal(ptr, hostname_to_match, hostname_to_match_len); - free(hostname_to_match); + curlx_free(hostname_to_match); ptr += hostname_to_match_len; host_match = host_match && *ptr == ':'; @@ -3090,6 +3048,7 @@ static CURLcode parse_connect_to_slist(struct Curl_easy *data, struct altsvc *as = NULL; int allowed_alpns = ALPN_none; struct http_negotiation *neg = &data->state.http_neg; + bool same_dest = FALSE; DEBUGF(infof(data, "Alt-svc check wanted=%x, allowed=%x", neg->wanted, neg->allowed)); @@ -3113,7 +3072,7 @@ static CURLcode parse_connect_to_slist(struct Curl_easy *data, hit = Curl_altsvc_lookup(data->asi, ALPN_h3, host, conn->remote_port, /* from */ &as /* to */, - allowed_alpns); + allowed_alpns, &same_dest); } #endif #ifdef USE_HTTP2 @@ -3123,7 +3082,7 @@ static CURLcode parse_connect_to_slist(struct Curl_easy *data, hit = Curl_altsvc_lookup(data->asi, ALPN_h2, host, conn->remote_port, /* from */ &as /* to */, - allowed_alpns); + allowed_alpns, &same_dest); } #endif if(!hit && (neg->wanted & CURL_HTTP_V1x) && @@ -3132,11 +3091,30 @@ static CURLcode parse_connect_to_slist(struct Curl_easy *data, hit = Curl_altsvc_lookup(data->asi, ALPN_h1, host, conn->remote_port, /* from */ &as /* to */, - allowed_alpns); + allowed_alpns, &same_dest); } - if(hit) { - char *hostd = strdup((char *)as->dst.host); + if(hit && same_dest) { + /* same destination, but more HTTPS version options */ + switch(as->dst.alpnid) { + case ALPN_h1: + neg->wanted |= CURL_HTTP_V1x; + neg->preferred = CURL_HTTP_V1x; + break; + case ALPN_h2: + neg->wanted |= CURL_HTTP_V2x; + neg->preferred = CURL_HTTP_V2x; + break; + case ALPN_h3: + neg->wanted |= CURL_HTTP_V3x; + neg->preferred = CURL_HTTP_V3x; + break; + default: /* should not be possible */ + break; + } + } + else if(hit) { + char *hostd = curlx_strdup((char *)as->dst.host); if(!hostd) return CURLE_OUT_OF_MEMORY; conn->conn_to_host.rawalloc = hostd; @@ -3188,7 +3166,7 @@ static CURLcode resolve_unix(struct Curl_easy *data, /* Unix domain sockets are local. The host gets ignored, just use the * specified domain socket address. Do not cache "DNS entries". There is * no DNS involved and we already have the file system path available. */ - hostaddr = calloc(1, sizeof(struct Curl_dns_entry)); + hostaddr = curlx_calloc(1, sizeof(struct Curl_dns_entry)); if(!hostaddr) return CURLE_OUT_OF_MEMORY; @@ -3198,7 +3176,7 @@ static CURLcode resolve_unix(struct Curl_easy *data, if(longpath) /* Long paths are not supported for now */ failf(data, "Unix socket path too long: '%s'", unix_path); - free(hostaddr); + curlx_free(hostaddr); return longpath ? CURLE_COULDNT_RESOLVE_HOST : CURLE_OUT_OF_MEMORY; } @@ -3218,7 +3196,7 @@ static CURLcode resolve_server(struct Curl_easy *data, { struct hostname *ehost; int eport; - timediff_t timeout_ms = Curl_timeleft(data, NULL, TRUE); + timediff_t timeout_ms = Curl_timeleft_ms(data, TRUE); const char *peertype = "host"; CURLcode result; @@ -3230,7 +3208,7 @@ static CURLcode resolve_server(struct Curl_easy *data, #ifndef CURL_DISABLE_PROXY if(!unix_path && CONN_IS_PROXIED(conn) && conn->socks_proxy.host.name && - !strncmp(UNIX_SOCKET_PREFIX"/", + !strncmp(UNIX_SOCKET_PREFIX "/", conn->socks_proxy.host.name, sizeof(UNIX_SOCKET_PREFIX))) unix_path = conn->socks_proxy.host.name + sizeof(UNIX_SOCKET_PREFIX) - 1; #endif @@ -3261,7 +3239,7 @@ static CURLcode resolve_server(struct Curl_easy *data, } /* Resolve target host right on */ - conn->hostname_resolve = strdup(ehost->name); + conn->hostname_resolve = curlx_strdup(ehost->name); if(!conn->hostname_resolve) return CURLE_OUT_OF_MEMORY; @@ -3276,7 +3254,8 @@ static CURLcode resolve_server(struct Curl_easy *data, else if(result == CURLE_OPERATION_TIMEDOUT) { failf(data, "Failed to resolve %s '%s' with timeout after %" FMT_TIMEDIFF_T " ms", peertype, ehost->dispname, - curlx_timediff(curlx_now(), data->progress.t_startsingle)); + curlx_ptimediff_ms(Curl_pgrs_now(data), + &data->progress.t_startsingle)); return CURLE_OPERATION_TIMEDOUT; } else if(result) { @@ -3308,8 +3287,8 @@ static void reuse_conn(struct Curl_easy *data, * be new for this request even when we reuse an existing connection */ if(temp->user) { /* use the new username and password though */ - free(existing->user); - free(existing->passwd); + curlx_free(existing->user); + curlx_free(existing->passwd); existing->user = temp->user; existing->passwd = temp->passwd; temp->user = NULL; @@ -3320,10 +3299,10 @@ static void reuse_conn(struct Curl_easy *data, existing->bits.proxy_user_passwd = temp->bits.proxy_user_passwd; if(existing->bits.proxy_user_passwd) { /* use the new proxy username and proxy password though */ - free(existing->http_proxy.user); - free(existing->socks_proxy.user); - free(existing->http_proxy.passwd); - free(existing->socks_proxy.passwd); + curlx_free(existing->http_proxy.user); + curlx_free(existing->socks_proxy.user); + curlx_free(existing->http_proxy.passwd); + curlx_free(existing->socks_proxy.passwd); existing->http_proxy.user = temp->http_proxy.user; existing->socks_proxy.user = temp->socks_proxy.user; existing->http_proxy.passwd = temp->http_proxy.passwd; @@ -3354,7 +3333,7 @@ static void reuse_conn(struct Curl_easy *data, existing->conn_to_port = temp->conn_to_port; existing->remote_port = temp->remote_port; - free(existing->hostname_resolve); + curlx_free(existing->hostname_resolve); existing->hostname_resolve = temp->hostname_resolve; temp->hostname_resolve = NULL; @@ -3406,7 +3385,7 @@ static CURLcode create_conn(struct Curl_easy *data, /************************************************************* * Check input data *************************************************************/ - if(!data->state.url) { + if(!Curl_bufref_ptr(&data->state.url)) { result = CURLE_URL_MALFORMAT; goto out; } @@ -3436,7 +3415,7 @@ static CURLcode create_conn(struct Curl_easy *data, goto out; if(data->set.str[STRING_SASL_AUTHZID]) { - conn->sasl_authzid = strdup(data->set.str[STRING_SASL_AUTHZID]); + conn->sasl_authzid = curlx_strdup(data->set.str[STRING_SASL_AUTHZID]); if(!conn->sasl_authzid) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -3444,7 +3423,7 @@ static CURLcode create_conn(struct Curl_easy *data, } if(data->set.str[STRING_BEARER]) { - conn->oauth_bearer = strdup(data->set.str[STRING_BEARER]); + conn->oauth_bearer = curlx_strdup(data->set.str[STRING_BEARER]); if(!conn->oauth_bearer) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -3453,7 +3432,8 @@ static CURLcode create_conn(struct Curl_easy *data, #ifdef USE_UNIX_SOCKETS if(data->set.str[STRING_UNIX_SOCKET_PATH]) { - conn->unix_domain_socket = strdup(data->set.str[STRING_UNIX_SOCKET_PATH]); + conn->unix_domain_socket = + curlx_strdup(data->set.str[STRING_UNIX_SOCKET_PATH]); if(!conn->unix_domain_socket) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -3473,7 +3453,7 @@ static CURLcode create_conn(struct Curl_easy *data, * If the protocol is using SSL and HTTP proxy is used, we set * the tunnel_proxy bit. *************************************************************/ - if((conn->given->flags&PROTOPT_SSL) && conn->bits.httpproxy) + if((conn->given->flags & PROTOPT_SSL) && conn->bits.httpproxy) conn->bits.tunnel_proxy = TRUE; #endif @@ -3546,7 +3526,7 @@ static CURLcode create_conn(struct Curl_easy *data, * we set the tunnel_proxy bit. *************************************************************/ if((conn->bits.conn_to_host || conn->bits.conn_to_port) && - conn->bits.httpproxy) + conn->bits.httpproxy) conn->bits.tunnel_proxy = TRUE; #endif @@ -3660,6 +3640,7 @@ static CURLcode create_conn(struct Curl_easy *data, /* We have decided that we want a new connection. However, we may not be able to do that if we have reached the limit of how many connections we are allowed to open. */ + DEBUGF(infof(data, "new connection, bits.close=%d", conn->bits.close)); if(conn->handler->flags & PROTOPT_ALPN) { /* The protocol wants it, so set the bits if enabled in the easy handle @@ -3681,11 +3662,11 @@ static CURLcode create_conn(struct Curl_easy *data, connections_available = FALSE; break; case CPOOL_LIMIT_TOTAL: - if(data->master_mid != UINT_MAX) + if(data->master_mid != UINT32_MAX) CURL_TRC_M(data, "Allowing sub-requests (like DoH) to override " "max connection limit"); else { - infof(data, "No connections available, total of %ld reached.", + infof(data, "No connections available, total of %zu reached.", data->multi->max_total_connections); connections_available = FALSE; } @@ -3830,8 +3811,9 @@ CURLcode Curl_connect(struct Curl_easy *data, if(!result) { DEBUGASSERT(conn); + Curl_pgrsTime(data, TIMER_POSTQUEUE); if(reused) { - if(CONN_ATTACHED(conn) > 1) + if(conn->attached_xfers > 1) /* multiplexed */ *protocol_done = TRUE; } @@ -3879,7 +3861,6 @@ CURLcode Curl_connect(struct Curl_easy *data, CURLcode Curl_init_do(struct Curl_easy *data, struct connectdata *conn) { - /* if this is a pushed stream, we need this: */ CURLcode result; if(conn) { @@ -3899,9 +3880,7 @@ CURLcode Curl_init_do(struct Curl_easy *data, struct connectdata *conn) result = Curl_req_start(&data->req, data); if(!result) { - Curl_speedinit(data); - Curl_pgrsSetUploadCounter(data, 0); - Curl_pgrsSetDownloadCounter(data, 0); + Curl_pgrsReset(data); } return result; } @@ -3925,7 +3904,7 @@ static void priority_remove_child(struct Curl_easy *parent, DEBUGASSERT(pnode); if(pnode) { *pnext = pnode->next; - free(pnode); + curlx_free(pnode); } child->set.priority.parent = 0; @@ -3944,7 +3923,7 @@ CURLcode Curl_data_priority_add_child(struct Curl_easy *parent, struct Curl_data_prio_node **tail; struct Curl_data_prio_node *pnode; - pnode = calloc(1, sizeof(*pnode)); + pnode = curlx_calloc(1, sizeof(*pnode)); if(!pnode) return CURLE_OUT_OF_MEMORY; pnode->data = child; @@ -4005,7 +3984,6 @@ void Curl_data_priority_clear_state(struct Curl_easy *data) #endif /* USE_HTTP2 || USE_HTTP3 */ - CURLcode Curl_conn_meta_set(struct connectdata *conn, const char *key, void *meta_data, Curl_meta_dtor *meta_dtor) { diff --git a/vendor/hydra/vendor/curl/lib/url.h b/vendor/hydra/vendor/curl/lib/url.h index 82d869c5..3a8d57c3 100644 --- a/vendor/hydra/vendor/curl/lib/url.h +++ b/vendor/hydra/vendor/curl/lib/url.h @@ -84,15 +84,13 @@ const struct Curl_handler *Curl_getn_scheme_handler(const char *scheme, * @param nowp NULL or pointer to time being checked against. */ bool Curl_conn_seems_dead(struct connectdata *conn, - struct Curl_easy *data, - struct curltime *nowp); + struct Curl_easy *data); /** * Perform upkeep operations on the connection. */ CURLcode Curl_conn_upkeep(struct Curl_easy *data, - struct connectdata *conn, - struct curltime *now); + struct connectdata *conn); /** * Always eval all arguments, return the first result != CURLE_OK. diff --git a/vendor/hydra/vendor/curl/lib/urlapi.c b/vendor/hydra/vendor/curl/lib/urlapi.c index 0a6ae5ba..e974783d 100644 --- a/vendor/hydra/vendor/curl/lib/urlapi.c +++ b/vendor/hydra/vendor/curl/lib/urlapi.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #include "urldata.h" @@ -29,7 +28,6 @@ #include "strcase.h" #include "url.h" #include "escape.h" -#include "curl_ctype.h" #include "curlx/inet_pton.h" #include "curlx/inet_ntop.h" #include "strdup.h" @@ -37,24 +35,20 @@ #include "curlx/strparse.h" #include "curl_memrchr.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef _WIN32 - /* MS-DOS/Windows style drive prefix, eg c: in c:foo */ -#define STARTS_WITH_DRIVE_PREFIX(str) \ - ((('a' <= str[0] && str[0] <= 'z') || \ +/* MS-DOS/Windows style drive prefix, eg c: in c:foo */ +#define STARTS_WITH_DRIVE_PREFIX(str) \ + ((('a' <= str[0] && str[0] <= 'z') || \ ('A' <= str[0] && str[0] <= 'Z')) && \ (str[1] == ':')) #endif - /* MS-DOS/Windows style drive prefix, optionally with - * a '|' instead of ':', followed by a slash or NUL */ -#define STARTS_WITH_URL_DRIVE_PREFIX(str) \ - ((('a' <= (str)[0] && (str)[0] <= 'z') || \ - ('A' <= (str)[0] && (str)[0] <= 'Z')) && \ - ((str)[1] == ':' || (str)[1] == '|') && \ +/* MS-DOS/Windows style drive prefix, optionally with + * a '|' instead of ':', followed by a slash or NUL */ +#define STARTS_WITH_URL_DRIVE_PREFIX(str) \ + ((('a' <= (str)[0] && (str)[0] <= 'z') || \ + ('A' <= (str)[0] && (str)[0] <= 'Z')) && \ + ((str)[1] == ':' || (str)[1] == '|') && \ ((str)[2] == '/' || (str)[2] == '\\' || (str)[2] == 0)) /* scheme is not URL encoded, the longest libcurl supported ones are... */ @@ -94,16 +88,16 @@ static CURLUcode parseurl_and_replace(const char *url, CURLU *u, static void free_urlhandle(struct Curl_URL *u) { - free(u->scheme); - free(u->user); - free(u->password); - free(u->options); - free(u->host); - free(u->zoneid); - free(u->port); - free(u->path); - free(u->query); - free(u->fragment); + curlx_free(u->scheme); + curlx_free(u->user); + curlx_free(u->password); + curlx_free(u->options); + curlx_free(u->host); + curlx_free(u->zoneid); + curlx_free(u->port); + curlx_free(u->path); + curlx_free(u->query); + curlx_free(u->fragment); } /* @@ -143,12 +137,12 @@ static CURLUcode urlencode_str(struct dynbuf *o, const char *url, /* we must add this with whitespace-replacing */ bool left = !query; const unsigned char *iptr; - const unsigned char *host_sep = (const unsigned char *) url; + const unsigned char *host_sep = (const unsigned char *)url; CURLcode result = CURLE_OK; if(!relative) { size_t n; - host_sep = (const unsigned char *) find_host_sep(url); + host_sep = (const unsigned char *)find_host_sep(url); /* output the first piece as-is */ n = (const char *)host_sep - url; @@ -164,7 +158,7 @@ static CURLUcode urlencode_str(struct dynbuf *o, const char *url, result = curlx_dyn_addn(o, "+", 1); } else if((*iptr < ' ') || (*iptr >= 0x7f)) { - unsigned char out[3]={'%'}; + unsigned char out[3] = { '%' }; Curl_hexbyte(&out[1], *iptr); result = curlx_dyn_addn(o, out, 3); } @@ -203,7 +197,7 @@ size_t Curl_is_absolute_url(const char *url, char *buf, size_t buflen, if(ISALPHA(url[0])) for(i = 1; i < MAX_SCHEME_LEN; ++i) { char s = url[i]; - if(s && (ISALNUM(s) || (s == '+') || (s == '-') || (s == '.') )) { + if(s && (ISALNUM(s) || (s == '+') || (s == '-') || (s == '.'))) { /* RFC 3986 3.1 explains: scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) */ @@ -374,7 +368,9 @@ static CURLUcode parse_hostname_login(struct Curl_URL *u, (h && (h->flags & PROTOPT_URLOPTIONS)) ? &optionsp : NULL); if(ccode) { - result = CURLUE_BAD_LOGIN; + /* the only possible error from Curl_parse_login_details is out of + memory: */ + result = CURLUE_OUT_OF_MEMORY; goto out; } @@ -384,17 +380,17 @@ static CURLUcode parse_hostname_login(struct Curl_URL *u, result = CURLUE_USER_NOT_ALLOWED; goto out; } - free(u->user); + curlx_free(u->user); u->user = userp; } if(passwdp) { - free(u->password); + curlx_free(u->password); u->password = passwdp; } if(optionsp) { - free(u->options); + curlx_free(u->options); u->options = optionsp; } @@ -404,9 +400,9 @@ static CURLUcode parse_hostname_login(struct Curl_URL *u, out: - free(userp); - free(passwdp); - free(optionsp); + curlx_free(userp); + curlx_free(passwdp); + curlx_free(optionsp); u->user = NULL; u->password = NULL; u->options = NULL; @@ -457,9 +453,9 @@ UNITTEST CURLUcode Curl_parse_port(struct Curl_URL *u, struct dynbuf *host, if(curlx_str_number(&portptr, &port, 0xffff) || *portptr) return CURLUE_BAD_PORT_NUMBER; - u->portnum = (unsigned short) port; + u->portnum = (unsigned short)port; /* generate a new port number string to get rid of leading zeroes etc */ - free(u->port); + curlx_free(u->port); u->port = curl_maprintf("%" CURL_FORMAT_CURL_OFF_T, port); if(!u->port) return CURLUE_OUT_OF_MEMORY; @@ -497,7 +493,7 @@ static CURLUcode ipv6_parse(struct Curl_URL *u, char *hostname, if(!i || (']' != *h)) return CURLUE_BAD_IPV6; zoneid[i] = 0; - u->zoneid = strdup(zoneid); + u->zoneid = curlx_strdup(zoneid); if(!u->zoneid) return CURLUE_OUT_OF_MEMORY; hostname[len] = ']'; /* insert end bracket */ @@ -514,7 +510,7 @@ static CURLUcode ipv6_parse(struct Curl_URL *u, char *hostname, hostname[hlen] = 0; /* end the address there */ if(curlx_inet_pton(AF_INET6, hostname, dest) != 1) return CURLUE_BAD_IPV6; - if(curlx_inet_ntop(AF_INET6, dest, hostname, hlen)) { + if(curlx_inet_ntop(AF_INET6, dest, hostname, hlen + 1)) { hlen = strlen(hostname); /* might be shorter now */ hostname[hlen + 1] = 0; } @@ -567,7 +563,7 @@ static int ipv4_normalize(struct dynbuf *host) bool done = FALSE; int n = 0; const char *c = curlx_dyn_ptr(host); - unsigned int parts[4] = {0, 0, 0, 0}; + unsigned int parts[4] = { 0, 0, 0, 0 }; CURLcode result = CURLE_OK; if(*c == '[') @@ -675,7 +671,7 @@ static CURLUcode urldecode_host(struct dynbuf *host) return CURLUE_BAD_HOSTNAME; curlx_dyn_reset(host); result = curlx_dyn_addn(host, decoded, dlen); - free(decoded); + curlx_free(decoded); if(result) return cc2cu(result); } @@ -750,7 +746,7 @@ CURLUcode Curl_url_set_authority(CURLU *u, const char *authority) if(result) curlx_dyn_free(&host); else { - free(u->host); + curlx_free(u->host); u->host = curlx_dyn_ptr(&host); } return result; @@ -894,7 +890,7 @@ UNITTEST int dedotdotify(const char *input, size_t clen, char **outp) if(curlx_dyn_len(&out)) *outp = curlx_dyn_ptr(&out); else { - *outp = strdup(""); + *outp = curlx_strdup(""); if(!*outp) return 1; } @@ -924,7 +920,7 @@ static CURLUcode parseurl(const char *url, CURLU *u, unsigned int flags) goto fail; schemelen = Curl_is_absolute_url(url, schemebuf, sizeof(schemebuf), - flags & (CURLU_GUESS_SCHEME| + flags & (CURLU_GUESS_SCHEME | CURLU_DEFAULT_SCHEME)); /* handle the file: scheme */ @@ -940,7 +936,7 @@ static CURLUcode parseurl(const char *url, CURLU *u, unsigned int flags) path = &url[5]; pathlen = urllen - 5; - u->scheme = strdup("file"); + u->scheme = curlx_strdup("file"); if(!u->scheme) { result = CURLUE_OUT_OF_MEMORY; goto fail; @@ -1040,7 +1036,6 @@ static CURLUcode parseurl(const char *url, CURLU *u, unsigned int flags) pathlen--; } #endif - } else { /* clear path */ @@ -1073,7 +1068,7 @@ static CURLUcode parseurl(const char *url, CURLU *u, unsigned int flags) else { /* no scheme! */ - if(!(flags & (CURLU_DEFAULT_SCHEME|CURLU_GUESS_SCHEME))) { + if(!(flags & (CURLU_DEFAULT_SCHEME | CURLU_GUESS_SCHEME))) { result = CURLUE_BAD_SCHEME; goto fail; } @@ -1087,7 +1082,7 @@ static CURLUcode parseurl(const char *url, CURLU *u, unsigned int flags) } if(schemep) { - u->scheme = strdup(schemep); + u->scheme = curlx_strdup(schemep); if(!u->scheme) { result = CURLUE_OUT_OF_MEMORY; goto fail; @@ -1124,7 +1119,7 @@ static CURLUcode parseurl(const char *url, CURLU *u, unsigned int flags) else schemep = "http"; - u->scheme = strdup(schemep); + u->scheme = curlx_strdup(schemep); if(!u->scheme) { result = CURLUE_OUT_OF_MEMORY; goto fail; @@ -1197,7 +1192,7 @@ static CURLUcode parseurl(const char *url, CURLU *u, unsigned int flags) } else { /* single byte query */ - u->query = strdup(""); + u->query = curlx_strdup(""); if(!u->query) { result = CURLUE_OUT_OF_MEMORY; goto fail; @@ -1241,7 +1236,7 @@ static CURLUcode parseurl(const char *url, CURLU *u, unsigned int flags) goto fail; } if(dedot) { - free(u->path); + curlx_free(u->path); u->path = dedot; } } @@ -1277,21 +1272,21 @@ static CURLUcode parseurl_and_replace(const char *url, CURLU *u, */ CURLU *curl_url(void) { - return calloc(1, sizeof(struct Curl_URL)); + return curlx_calloc(1, sizeof(struct Curl_URL)); } void curl_url_cleanup(CURLU *u) { if(u) { free_urlhandle(u); - free(u); + curlx_free(u); } } #define DUP(dest, src, name) \ do { \ if(src->name) { \ - dest->name = strdup(src->name); \ + dest->name = curlx_strdup(src->name); \ if(!dest->name) \ goto fail; \ } \ @@ -1299,7 +1294,7 @@ void curl_url_cleanup(CURLU *u) CURLU *curl_url_dup(const CURLU *in) { - struct Curl_URL *u = calloc(1, sizeof(struct Curl_URL)); + struct Curl_URL *u = curlx_calloc(1, sizeof(struct Curl_URL)); if(u) { DUP(u, in, scheme); DUP(u, in, user); @@ -1322,8 +1317,8 @@ CURLU *curl_url_dup(const CURLU *in) } #ifndef USE_IDN -#define host_decode(x,y) CURLUE_LACKS_IDN -#define host_encode(x,y) CURLUE_LACKS_IDN +#define host_decode(x, y) CURLUE_LACKS_IDN +#define host_encode(x, y) CURLUE_LACKS_IDN #else static CURLUcode host_decode(const char *host, char **allochost) { @@ -1345,20 +1340,22 @@ static CURLUcode host_encode(const char *host, char **allochost) #endif static CURLUcode urlget_format(const CURLU *u, CURLUPart what, - const char *ptr, char **part, + const char *ptr, char **partp, bool plusdecode, unsigned int flags) { + CURLUcode uc = CURLUE_OK; size_t partlen = strlen(ptr); bool urldecode = (flags & CURLU_URLDECODE) ? 1 : 0; bool urlencode = (flags & CURLU_URLENCODE) ? 1 : 0; bool punycode = (flags & CURLU_PUNYCODE) && (what == CURLUPART_HOST); bool depunyfy = (flags & CURLU_PUNY2IDN) && (what == CURLUPART_HOST); - *part = Curl_memdup0(ptr, partlen); - if(!*part) + char *part = Curl_memdup0(ptr, partlen); + *partp = NULL; + if(!part) return CURLUE_OUT_OF_MEMORY; if(plusdecode) { /* convert + to space */ - char *plus = *part; + char *plus = part; size_t i = 0; for(i = 0; i < partlen; ++plus, i++) { if(*plus == '+') @@ -1370,46 +1367,43 @@ static CURLUcode urlget_format(const CURLU *u, CURLUPart what, size_t dlen; /* this unconditional rejection of control bytes is documented API behavior */ - CURLcode res = Curl_urldecode(*part, 0, &decoded, &dlen, REJECT_CTRL); - free(*part); - if(res) { - *part = NULL; + CURLcode res = Curl_urldecode(part, partlen, &decoded, &dlen, REJECT_CTRL); + curlx_free(part); + if(res) return CURLUE_URLDECODE; - } - *part = decoded; + part = decoded; partlen = dlen; } if(urlencode) { struct dynbuf enc; - CURLUcode uc; curlx_dyn_init(&enc, CURL_MAX_INPUT_LENGTH); - uc = urlencode_str(&enc, *part, partlen, TRUE, what == CURLUPART_QUERY); + uc = urlencode_str(&enc, part, partlen, TRUE, what == CURLUPART_QUERY); + curlx_free(part); if(uc) return uc; - free(*part); - *part = curlx_dyn_ptr(&enc); + part = curlx_dyn_ptr(&enc); } else if(punycode) { if(!Curl_is_ASCII_name(u->host)) { - char *allochost = NULL; - CURLUcode ret = host_decode(*part, &allochost); - if(ret) - return ret; - free(*part); - *part = allochost; + char *punyversion = NULL; + uc = host_decode(part, &punyversion); + curlx_free(part); + if(uc) + return uc; + part = punyversion; } } else if(depunyfy) { if(Curl_is_ASCII_name(u->host)) { - char *allochost = NULL; - CURLUcode ret = host_encode(*part, &allochost); - if(ret) - return ret; - free(*part); - *part = allochost; + char *unpunified = NULL; + uc = host_encode(part, &unpunified); + curlx_free(part); + if(uc) + return uc; + part = unpunified; } } - + *partp = part; return CURLUE_OK; } @@ -1521,7 +1515,7 @@ static CURLUcode urlget_url(const CURLU *u, char **part, unsigned int flags) u->query ? u->query : "", show_fragment ? "#": "", u->fragment ? u->fragment : ""); - free(allochost); + curlx_free(allochost); } if(!url) return CURLUE_OUT_OF_MEMORY; @@ -1667,7 +1661,7 @@ static CURLUcode set_url_port(CURLU *u, const char *provided_port) tmp = curl_maprintf("%" CURL_FORMAT_CURL_OFF_T, port); if(!tmp) return CURLUE_OUT_OF_MEMORY; - free(u->port); + curlx_free(u->port); u->port = tmp; u->portnum = (unsigned short)port; return CURLUE_OK; @@ -1688,26 +1682,35 @@ static CURLUcode set_url(CURLU *u, const char *url, size_t part_size, if(!part_size) { /* a blank URL is not a valid URL unless we already have a complete one and this is a redirect */ - if(!curl_url_get(u, CURLUPART_URL, &oldurl, flags)) { + uc = curl_url_get(u, CURLUPART_URL, &oldurl, flags); + if(!uc) { /* success, meaning the "" is a fine relative URL, but nothing changes */ - free(oldurl); + curlx_free(oldurl); return CURLUE_OK; } + if(uc == CURLUE_OUT_OF_MEMORY) + return uc; return CURLUE_MALFORMED_INPUT; } - /* if the new thing is absolute or the old one is not (we could not get an - * absolute URL in 'oldurl'), then replace the existing with the new. */ + /* if the new URL is absolute replace the existing with the new. */ if(Curl_is_absolute_url(url, NULL, 0, - flags & (CURLU_GUESS_SCHEME|CURLU_DEFAULT_SCHEME)) - || curl_url_get(u, CURLUPART_URL, &oldurl, flags)) { + flags & (CURLU_GUESS_SCHEME | CURLU_DEFAULT_SCHEME))) return parseurl_and_replace(url, u, flags); - } + + /* if the old URL is incomplete (we cannot get an absolute URL in + 'oldurl'), replace the existing with the new */ + uc = curl_url_get(u, CURLUPART_URL, &oldurl, flags); + if(uc == CURLUE_OUT_OF_MEMORY) + return uc; + else if(uc) + return parseurl_and_replace(url, u, flags); + DEBUGASSERT(oldurl); /* it is set here */ /* apply the relative part to create a new URL */ uc = redirect_url(oldurl, url, u, flags); - free(oldurl); + curlx_free(oldurl); return uc; } @@ -1761,11 +1764,24 @@ static CURLUcode urlset_clear(CURLU *u, CURLUPart what) static bool allowed_in_path(unsigned char x) { switch(x) { - case '!': case '$': case '&': case '\'': - case '(': case ')': case '{': case '}': - case '[': case ']': case '*': case '+': - case ',': case ';': case '=': case ':': - case '@': case '/': + case '!': + case '$': + case '&': + case '\'': + case '(': + case ')': + case '{': + case '}': + case '[': + case ']': + case '*': + case '+': + case ',': + case ';': + case '=': + case ':': + case '@': + case '/': return TRUE; } return FALSE; @@ -1874,7 +1890,7 @@ CURLUcode curl_url_set(CURLU *u, CURLUPart what, return cc2cu(result); } else { - unsigned char out[3]={'%'}; + unsigned char out[3] = { '%' }; Curl_hexbyte(&out[1], *i); result = curlx_dyn_addn(&enc, out, 3); if(result) @@ -1907,7 +1923,7 @@ CURLUcode curl_url_set(CURLU *u, CURLUPart what, none is present at the end of the existing query already */ size_t querylen = u->query ? strlen(u->query) : 0; - bool addamperand = querylen && (u->query[querylen -1] != '&'); + bool addamperand = querylen && (u->query[querylen - 1] != '&'); if(querylen) { struct dynbuf qbuf; curlx_dyn_init(&qbuf, CURL_MAX_INPUT_LENGTH); @@ -1922,7 +1938,7 @@ CURLUcode curl_url_set(CURLU *u, CURLUPart what, if(curlx_dyn_add(&qbuf, newp)) goto nomem; curlx_dyn_free(&enc); - free(*storep); + curlx_free(*storep); *storep = curlx_dyn_ptr(&qbuf); return CURLUE_OK; nomem: @@ -1941,7 +1957,7 @@ CURLUcode curl_url_set(CURLU *u, CURLUPart what, if(!n) bad = TRUE; /* empty hostname is not okay */ else if(!urlencode) { - /* if the host name part was not URL encoded here, it was set ready + /* if the hostname part was not URL encoded here, it was set ready URL encoded so we need to decode it to check */ size_t dlen; char *decoded = NULL; @@ -1949,7 +1965,7 @@ CURLUcode curl_url_set(CURLU *u, CURLUPart what, Curl_urldecode(newp, n, &decoded, &dlen, REJECT_CTRL); if(result || hostname_check(u, decoded, dlen)) bad = TRUE; - free(decoded); + curlx_free(decoded); } else if(hostname_check(u, (char *)CURL_UNCONST(newp), n)) bad = TRUE; @@ -1960,7 +1976,7 @@ CURLUcode curl_url_set(CURLU *u, CURLUPart what, } } - free(*storep); + curlx_free(*storep); *storep = (char *)CURL_UNCONST(newp); } return CURLUE_OK; diff --git a/vendor/hydra/vendor/curl/lib/urldata.h b/vendor/hydra/vendor/curl/lib/urldata.h index f79ccca0..aba1693c 100644 --- a/vendor/hydra/vendor/curl/lib/urldata.h +++ b/vendor/hydra/vendor/curl/lib/urldata.h @@ -23,45 +23,43 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - /* This file is for lib internal stuff */ - #include "curl_setup.h" -#define PORT_FTP 21 -#define PORT_FTPS 990 +#define PORT_FTP 21 +#define PORT_FTPS 990 #define PORT_TELNET 23 -#define PORT_HTTP 80 -#define PORT_HTTPS 443 -#define PORT_DICT 2628 -#define PORT_LDAP 389 -#define PORT_LDAPS 636 -#define PORT_TFTP 69 -#define PORT_SSH 22 -#define PORT_IMAP 143 -#define PORT_IMAPS 993 -#define PORT_POP3 110 -#define PORT_POP3S 995 -#define PORT_SMB 445 -#define PORT_SMBS 445 -#define PORT_SMTP 25 -#define PORT_SMTPS 465 /* sometimes called SSMTP */ -#define PORT_RTSP 554 -#define PORT_RTMP 1935 -#define PORT_RTMPT PORT_HTTP -#define PORT_RTMPS PORT_HTTPS +#define PORT_HTTP 80 +#define PORT_HTTPS 443 +#define PORT_DICT 2628 +#define PORT_LDAP 389 +#define PORT_LDAPS 636 +#define PORT_TFTP 69 +#define PORT_SSH 22 +#define PORT_IMAP 143 +#define PORT_IMAPS 993 +#define PORT_POP3 110 +#define PORT_POP3S 995 +#define PORT_SMB 445 +#define PORT_SMBS 445 +#define PORT_SMTP 25 +#define PORT_SMTPS 465 /* sometimes called SSMTP */ +#define PORT_RTSP 554 +#define PORT_RTMP 1935 +#define PORT_RTMPT PORT_HTTP +#define PORT_RTMPS PORT_HTTPS #define PORT_GOPHER 70 -#define PORT_MQTT 1883 +#define PORT_MQTT 1883 struct curl_trc_featt; #ifdef USE_ECH /* CURLECH_ bits for the tls_ech option */ -# define CURLECH_DISABLE (1<<0) -# define CURLECH_GREASE (1<<1) -# define CURLECH_ENABLE (1<<2) -# define CURLECH_HARD (1<<3) -# define CURLECH_CLA_CFG (1<<4) +# define CURLECH_DISABLE (1 << 0) +# define CURLECH_GREASE (1 << 1) +# define CURLECH_ENABLE (1 << 2) +# define CURLECH_HARD (1 << 3) +# define CURLECH_CLA_CFG (1 << 4) #endif #ifndef CURL_DISABLE_WEBSOCKETS @@ -70,8 +68,8 @@ struct curl_trc_featt; * platforms that have a >= 64-bit type and then we use such a type for the * protocol fields in the protocol handler. */ -#define CURLPROTO_WS (1L<<30) -#define CURLPROTO_WSS ((curl_prot_t)1<<31) +#define CURLPROTO_WS (1L << 30) +#define CURLPROTO_WSS ((curl_prot_t)1 << 31) #else #define CURLPROTO_WS 0L #define CURLPROTO_WSS 0L @@ -107,15 +105,15 @@ typedef unsigned int curl_prot_t; /* Convenience defines for checking protocols or their SSL based version. Each protocol handler should only ever have a single CURLPROTO_ in its protocol field. */ -#define PROTO_FAMILY_HTTP (CURLPROTO_HTTP|CURLPROTO_HTTPS|CURLPROTO_WS| \ +#define PROTO_FAMILY_HTTP (CURLPROTO_HTTP | CURLPROTO_HTTPS | CURLPROTO_WS | \ CURLPROTO_WSS) -#define PROTO_FAMILY_FTP (CURLPROTO_FTP|CURLPROTO_FTPS) -#define PROTO_FAMILY_POP3 (CURLPROTO_POP3|CURLPROTO_POP3S) -#define PROTO_FAMILY_SMB (CURLPROTO_SMB|CURLPROTO_SMBS) -#define PROTO_FAMILY_SMTP (CURLPROTO_SMTP|CURLPROTO_SMTPS) -#define PROTO_FAMILY_SSH (CURLPROTO_SCP|CURLPROTO_SFTP) +#define PROTO_FAMILY_FTP (CURLPROTO_FTP | CURLPROTO_FTPS) +#define PROTO_FAMILY_POP3 (CURLPROTO_POP3 | CURLPROTO_POP3S) +#define PROTO_FAMILY_SMB (CURLPROTO_SMB | CURLPROTO_SMBS) +#define PROTO_FAMILY_SMTP (CURLPROTO_SMTP | CURLPROTO_SMTPS) +#define PROTO_FAMILY_SSH (CURLPROTO_SCP | CURLPROTO_SFTP) -#if !defined(CURL_DISABLE_FTP) || defined(USE_SSH) || \ +#if !defined(CURL_DISABLE_FTP) || defined(USE_SSH) || \ !defined(CURL_DISABLE_POP3) /* these protocols support CURLOPT_DIRLISTONLY */ #define CURL_LIST_ONLY_PROTOCOL 1 @@ -127,13 +125,12 @@ typedef unsigned int curl_prot_t; #define MAX_IPADR_LEN sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255") /* Default FTP/IMAP etc response timeout in milliseconds */ -#define RESP_TIMEOUT (60*1000) +#define RESP_TIMEOUT (60 * 1000) /* Max string input length is a precaution against abuse and to detect junk input easier and better. */ #define CURL_MAX_INPUT_LENGTH 8000000 - #include "cookie.h" #include "psl.h" #include "formdata.h" @@ -147,21 +144,21 @@ typedef unsigned int curl_prot_t; #include "curlx/timeval.h" -#include - #include "http_chunks.h" /* for the structs and enum stuff */ #include "hostip.h" #include "hash.h" #include "splay.h" #include "curlx/dynbuf.h" +#include "bufref.h" #include "dynhds.h" #include "request.h" +#include "ratelimit.h" #include "netrc.h" /* On error return, the value of `pnwritten` has no meaning */ typedef CURLcode (Curl_send)(struct Curl_easy *data, /* transfer */ int sockindex, /* socketindex */ - const void *buf, /* data to write */ + const uint8_t *buf, /* data to write */ size_t len, /* amount to send */ bool eos, /* last chunk */ size_t *pnwritten); /* how much sent */ @@ -174,13 +171,8 @@ typedef CURLcode (Curl_recv)(struct Curl_easy *data, /* transfer */ size_t *pnread); /* how much received */ #include "mime.h" -#include "imap.h" -#include "smtp.h" #include "ftp.h" -#include "file.h" -#include "vssh/ssh.h" #include "http.h" -#include "rtsp.h" #include "smb.h" #include "mqtt.h" #include "ftplistparser.h" @@ -190,8 +182,11 @@ typedef CURLcode (Curl_recv)(struct Curl_easy *data, /* transfer */ #ifdef HAVE_GSSAPI # ifdef HAVE_GSSGNU # include -# else +# elif defined(HAVE_GSSAPI_H) +# include +# else /* MIT Kerberos */ # include +# include /* for GSS_C_CHANNEL_BOUND_FLAG, in 1.19+ */ # endif #endif @@ -213,8 +208,8 @@ typedef CURLcode (Curl_recv)(struct Curl_easy *data, /* transfer */ larger buffers can help further, but this is deemed a fair memory/speed compromise. */ #define UPLOADBUFFER_DEFAULT 65536 -#define UPLOADBUFFER_MAX (2*1024*1024) -#define UPLOADBUFFER_MIN CURL_MAX_WRITE_SIZE +#define UPLOADBUFFER_MAX (2 * 1024 * 1024) +#define UPLOADBUFFER_MIN CURL_MAX_WRITE_SIZE #define CURLEASY_MAGIC_NUMBER 0xc0dedbadU #ifdef DEBUGBUILD @@ -222,7 +217,7 @@ typedef CURLcode (Curl_recv)(struct Curl_easy *data, /* transfer */ * are not NULL, but no longer have the MAGIC touch. This gives * us early warning on things only discovered by valgrind otherwise. */ #define GOOD_EASY_HANDLE(x) \ - (((x) && ((x)->magic == CURLEASY_MAGIC_NUMBER))? TRUE: \ + (((x) && ((x)->magic == CURLEASY_MAGIC_NUMBER)) ? TRUE : \ (DEBUGASSERT(!(x)), FALSE)) #else #define GOOD_EASY_HANDLE(x) \ @@ -234,7 +229,7 @@ struct ssl_backend_data; struct Curl_ssl_scache_entry; struct ssl_primary_config { - char *CApath; /* certificate dir (does not work on Windows) */ + char *CApath; /* certificate directory (does not work on Windows) */ char *CAfile; /* certificate to verify peer against */ char *issuercert; /* optional issuer certificate filename */ char *clientcert; @@ -265,19 +260,19 @@ struct ssl_config_data { long certverifyresult; /* result from the certificate verification */ curl_ssl_ctx_callback fsslctx; /* function to initialize ssl ctx */ void *fsslctxp; /* parameter for call back */ - char *cert_type; /* format for certificate (default: PEM)*/ + char *cert_type; /* format for certificate (default: PEM) */ char *key; /* private key filename */ struct curl_blob *key_blob; char *key_type; /* format for private key (default: PEM) */ char *key_passwd; /* plain text private key password */ BIT(certinfo); /* gather lots of certificate info */ - BIT(earlydata); /* use tls1.3 early data */ + BIT(earlydata); /* use TLS 1.3 early data */ BIT(enable_beast); /* allow this flaw for interoperability's sake */ BIT(no_revoke); /* disable SSL certificate revocation checks */ BIT(no_partialchain); /* do not accept partial certificate chains */ BIT(revoke_best_effort); /* ignore SSL revocation offline/missing revocation list errors */ - BIT(native_ca_store); /* use the native ca store of operating system */ + BIT(native_ca_store); /* use the native CA store of operating system */ BIT(auto_client_cert); /* automatically locate and use a client certificate for authentication (Schannel) */ BIT(custom_cafile); /* application has set custom CA file */ @@ -420,32 +415,13 @@ struct hostname { */ #define KEEP_NONE 0 -#define KEEP_RECV (1<<0) /* there is or may be data to read */ -#define KEEP_SEND (1<<1) /* there is or may be data to write */ -#define KEEP_RECV_HOLD (1<<2) /* when set, no reading should be done but there - might still be data to read */ -#define KEEP_SEND_HOLD (1<<3) /* when set, no writing should be done but there - might still be data to write */ -#define KEEP_RECV_PAUSE (1<<4) /* reading is paused */ -#define KEEP_SEND_PAUSE (1<<5) /* writing is paused */ - -/* KEEP_SEND_TIMED is set when the transfer should attempt sending - * at timer (or other) events. A transfer waiting on a timer will - * remove KEEP_SEND to suppress POLLOUTs of the connection. - * Adding KEEP_SEND_TIMED will then attempt to send whenever the transfer - * enters the "readwrite" loop, e.g. when a timer fires. - * This is used in HTTP for 'Expect: 100-continue' waiting. */ -#define KEEP_SEND_TIMED (1<<6) - -#define KEEP_RECVBITS (KEEP_RECV | KEEP_RECV_HOLD | KEEP_RECV_PAUSE) -#define KEEP_SENDBITS (KEEP_SEND | KEEP_SEND_HOLD | KEEP_SEND_PAUSE) - -/* transfer wants to send is not PAUSE or HOLD */ -#define CURL_WANT_SEND(data) \ - (((data)->req.keepon & KEEP_SENDBITS) == KEEP_SEND) -/* transfer receive is not on PAUSE or HOLD */ -#define CURL_WANT_RECV(data) \ - (((data)->req.keepon & KEEP_RECVBITS) == KEEP_RECV) +#define KEEP_RECV (1 << 0) /* there is or may be data to read */ +#define KEEP_SEND (1 << 1) /* there is or may be data to write */ + +/* transfer wants to send */ +#define CURL_WANT_SEND(data) ((data)->req.keepon & KEEP_SEND) +/* transfer wants to receive */ +#define CURL_WANT_RECV(data) ((data)->req.keepon & KEEP_RECV) #define FIRSTSOCKET 0 #define SECONDARYSOCKET 1 @@ -542,7 +518,7 @@ struct Curl_handler { CURLcode (*follow)(struct Curl_easy *data, const char *newurl, followtype type); - int defport; /* Default port. */ + uint16_t defport; /* Default port. */ curl_prot_t protocol; /* See CURLPROTO_* - this needs to be the single specific protocol bit */ curl_prot_t family; /* single bit for protocol family; basically the @@ -552,63 +528,73 @@ struct Curl_handler { }; #define PROTOPT_NONE 0 /* nothing extra */ -#define PROTOPT_SSL (1<<0) /* uses SSL */ -#define PROTOPT_DUAL (1<<1) /* this protocol uses two connections */ -#define PROTOPT_CLOSEACTION (1<<2) /* need action before socket close */ +#define PROTOPT_SSL (1 << 0) /* uses SSL */ +#define PROTOPT_DUAL (1 << 1) /* this protocol uses two connections */ +#define PROTOPT_CLOSEACTION (1 << 2) /* need action before socket close */ /* some protocols will have to call the underlying functions without regard to what exact state the socket signals. IE even if the socket says "readable", the send function might need to be called while uploading, or vice versa. */ -#define PROTOPT_DIRLOCK (1<<3) -#define PROTOPT_NONETWORK (1<<4) /* protocol does not use the network! */ -#define PROTOPT_NEEDSPWD (1<<5) /* needs a password, and if none is set it +#define PROTOPT_DIRLOCK (1 << 3) +#define PROTOPT_NONETWORK (1 << 4) /* protocol does not use the network! */ +#define PROTOPT_NEEDSPWD (1 << 5) /* needs a password, and if none is set it gets a default */ -#define PROTOPT_NOURLQUERY (1<<6) /* protocol cannot handle - URL query strings (?foo=bar) ! */ -#define PROTOPT_CREDSPERREQUEST (1<<7) /* requires login credentials per - request instead of per connection */ -#define PROTOPT_ALPN (1<<8) /* set ALPN for this */ -/* (1<<9) was PROTOPT_STREAM, now free */ -#define PROTOPT_URLOPTIONS (1<<10) /* allow options part in the userinfo field - of the URL */ -#define PROTOPT_PROXY_AS_HTTP (1<<11) /* allow this non-HTTP scheme over a - HTTP proxy as HTTP proxies may know - this protocol and act as a gateway */ -#define PROTOPT_WILDCARD (1<<12) /* protocol supports wildcard matching */ -#define PROTOPT_USERPWDCTRL (1<<13) /* Allow "control bytes" (< 32 ASCII) in - username and password */ -#define PROTOPT_NOTCPPROXY (1<<14) /* this protocol cannot proxy over TCP */ -#define PROTOPT_SSL_REUSE (1<<15) /* this protocol may reuse an existing - SSL connection in the same family - without having PROTOPT_SSL. */ +#define PROTOPT_NOURLQUERY (1 << 6) /* protocol cannot handle + URL query strings (?foo=bar) ! */ +#define PROTOPT_CREDSPERREQUEST (1 << 7) /* requires login credentials per + request instead of per + connection */ +#define PROTOPT_ALPN (1 << 8) /* set ALPN for this */ +/* (1 << 9) was PROTOPT_STREAM, now free */ +#define PROTOPT_URLOPTIONS (1 << 10) /* allow options part in the userinfo + field of the URL */ +#define PROTOPT_PROXY_AS_HTTP (1 << 11) /* allow this non-HTTP scheme over a + HTTP proxy as HTTP proxies may know + this protocol and act as + a gateway */ +#define PROTOPT_WILDCARD (1 << 12) /* protocol supports wildcard matching */ +#define PROTOPT_USERPWDCTRL (1 << 13) /* Allow "control bytes" (< 32 ASCII) in + username and password */ +#define PROTOPT_NOTCPPROXY (1 << 14) /* this protocol cannot proxy over TCP */ +#define PROTOPT_SSL_REUSE (1 << 15) /* this protocol may reuse an existing + SSL connection in the same family + without having PROTOPT_SSL. */ +#define PROTOPT_CONN_REUSE (1 << 16) /* this protocol can reuse connections */ #define CONNCHECK_NONE 0 /* No checks */ -#define CONNCHECK_ISDEAD (1<<0) /* Check if the connection is dead. */ -#define CONNCHECK_KEEPALIVE (1<<1) /* Perform any keepalive function. */ +#define CONNCHECK_ISDEAD (1 << 0) /* Check if the connection is dead. */ +#define CONNCHECK_KEEPALIVE (1 << 1) /* Perform any keepalive function. */ #define CONNRESULT_NONE 0 /* No extra information. */ -#define CONNRESULT_DEAD (1<<0) /* The connection is dead. */ +#define CONNRESULT_DEAD (1 << 0) /* The connection is dead. */ + +#define TRNSPRT_NONE 0 +#define TRNSPRT_TCP 3 +#define TRNSPRT_UDP 4 +#define TRNSPRT_QUIC 5 +#define TRNSPRT_UNIX 6 struct ip_quadruple { char remote_ip[MAX_IPADR_LEN]; char local_ip[MAX_IPADR_LEN]; - int remote_port; - int local_port; + uint16_t remote_port; + uint16_t local_port; + uint8_t transport; }; +#define CUR_IP_QUAD_HAS_PORTS(x) \ + (((x)->transport == TRNSPRT_TCP) || \ + ((x)->transport == TRNSPRT_UDP) || \ + ((x)->transport == TRNSPRT_QUIC)) + struct proxy_info { struct hostname host; - int port; + uint16_t port; unsigned char proxytype; /* what kind of proxy that is in use */ char *user; /* proxy username string, allocated */ char *passwd; /* proxy password string, allocated */ }; -#define TRNSPRT_TCP 3 -#define TRNSPRT_UDP 4 -#define TRNSPRT_QUIC 5 -#define TRNSPRT_UNIX 6 - /* * The connectdata struct contains all fields and variables that should be * unique for an entire connection. @@ -624,8 +610,7 @@ struct connectdata { handle is still used by one or more easy handles and can only used by any other easy handle without careful consideration (== only for multiplexing) and it cannot be used by another multi handle! */ -#define CONN_INUSE(c) (!Curl_uint_spbset_empty(&(c)->xfers_attached)) -#define CONN_ATTACHED(c) Curl_uint_spbset_count(&(c)->xfers_attached) +#define CONN_INUSE(c) (!!(c)->attached_xfers) /**** Fields set when inited and not modified again */ curl_off_t connection_id; /* Contains a unique number to make it easier to @@ -685,7 +670,6 @@ struct connectdata { was used on this connection. */ struct curltime keepalive; - struct uint_spbset xfers_attached; /* mids of attached transfers */ /* A connection cache from a SHARE might be used in several multi handles. * We MUST not reuse connections that are running in another multi, * for concurrency reasons. That multi might run in another thread. @@ -720,7 +704,6 @@ struct connectdata { wrong connections. */ char *localdev; unsigned short localportrange; - int waitfor; /* current READ/WRITE bits to wait for */ #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI) int socks5_gssapi_enctype; #endif @@ -728,6 +711,9 @@ struct connectdata { int remote_port; /* the remote port, not the proxy port! */ int conn_to_port; /* the remote port to connect to. valid only if bits.conn_to_port is set */ + + uint32_t attached_xfers; /* # of attached easy handles */ + #ifdef USE_IPV6 unsigned int scope_id; /* Scope id for IPv6 */ #endif @@ -748,14 +734,14 @@ struct connectdata { #ifndef CURL_DISABLE_PROXY #define CURL_CONN_HOST_DISPNAME(c) \ - ((c)->bits.socksproxy ? (c)->socks_proxy.host.dispname : \ - (c)->bits.httpproxy ? (c)->http_proxy.host.dispname : \ - (c)->bits.conn_to_host ? (c)->conn_to_host.dispname : \ - (c)->host.dispname) + ((c)->bits.socksproxy ? (c)->socks_proxy.host.dispname : \ + (c)->bits.httpproxy ? (c)->http_proxy.host.dispname : \ + (c)->bits.conn_to_host ? (c)->conn_to_host.dispname : \ + (c)->host.dispname) #else #define CURL_CONN_HOST_DISPNAME(c) \ - (c)->bits.conn_to_host ? (c)->conn_to_host.dispname : \ - (c)->host.dispname + (c)->bits.conn_to_host ? (c)->conn_to_host.dispname : \ + (c)->host.dispname #endif /* The end of connectdata. */ @@ -801,19 +787,15 @@ struct PureInfo { BIT(used_proxy); /* the transfer used a proxy */ }; -struct pgrs_measure { - struct curltime start; /* when measure started */ - curl_off_t start_size; /* the 'cur_size' the measure started at */ -}; - struct pgrs_dir { curl_off_t total_size; /* total expected bytes */ curl_off_t cur_size; /* transferred bytes so far */ curl_off_t speed; /* bytes per second transferred */ - struct pgrs_measure limit; + struct Curl_rlimit rlimit; /* speed limiting / pausing */ }; struct Progress { + struct curltime now; /* current time of processing */ time_t lastshow; /* time() of the last displayed progress meter or NULL to force redraw at next call */ struct pgrs_dir ul; @@ -839,10 +821,10 @@ struct Progress { struct curltime t_startqueue; struct curltime t_acceptdata; -#define CURR_TIME (5 + 1) /* 6 entries for 5 seconds */ +#define CURL_SPEED_RECORDS (5 + 1) /* 6 entries for 5 seconds */ - curl_off_t speeder[ CURR_TIME ]; - struct curltime speeder_time[ CURR_TIME ]; + curl_off_t speed_amount[CURL_SPEED_RECORDS]; + struct curltime speed_time[CURL_SPEED_RECORDS]; unsigned char speeder_c; BIT(hide); BIT(ul_size_known); @@ -853,19 +835,19 @@ struct Progress { }; typedef enum { - RTSPREQ_NONE, /* first in list */ - RTSPREQ_OPTIONS, - RTSPREQ_DESCRIBE, - RTSPREQ_ANNOUNCE, - RTSPREQ_SETUP, - RTSPREQ_PLAY, - RTSPREQ_PAUSE, - RTSPREQ_TEARDOWN, - RTSPREQ_GET_PARAMETER, - RTSPREQ_SET_PARAMETER, - RTSPREQ_RECORD, - RTSPREQ_RECEIVE, - RTSPREQ_LAST /* last in list */ + RTSPREQ_NONE, /* first in list */ + RTSPREQ_OPTIONS, + RTSPREQ_DESCRIBE, + RTSPREQ_ANNOUNCE, + RTSPREQ_SETUP, + RTSPREQ_PLAY, + RTSPREQ_PAUSE, + RTSPREQ_TEARDOWN, + RTSPREQ_GET_PARAMETER, + RTSPREQ_SET_PARAMETER, + RTSPREQ_RECORD, + RTSPREQ_RECEIVE, + RTSPREQ_LAST /* last in list */ } Curl_RtspReq; struct auth { @@ -925,7 +907,6 @@ typedef enum { EXPIRE_LAST /* not an actual timer, used as a marker only */ } expire_id; - typedef enum { TRAILERS_NONE, TRAILERS_INITIALIZED, @@ -933,7 +914,6 @@ typedef enum { TRAILERS_DONE } trailers_state; - /* * One instance for each timeout an easy handle can set. */ @@ -1040,8 +1020,8 @@ struct UrlState { void *in; /* CURLOPT_READDATA */ CURLU *uh; /* URL handle for the current parsed URL */ struct urlpieces up; - char *url; /* work URL, copied from UserDefined */ - char *referer; /* referer string */ + struct bufref url; /* work URL, initially copied from UserDefined */ + struct bufref referer; /* referer string */ struct curl_slist *resolve; /* set to point to the set.resolve list when this should be dealt with in pretransfer */ #ifndef CURL_DISABLE_HTTP @@ -1137,8 +1117,6 @@ struct UrlState { #ifdef CURL_LIST_ONLY_PROTOCOL BIT(list_only); /* list directory contents */ #endif - BIT(url_alloc); /* URL string is malloc()'ed */ - BIT(referer_alloc); /* referer string is malloc()ed */ BIT(wildcard_resolve); /* Set to true if any resolve change is a wildcard */ BIT(upload); /* upload request */ BIT(internal); /* internal: true if this easy handle was created for @@ -1149,6 +1127,8 @@ struct UrlState { BIT(http_hd_te); /* Added HTTP header TE: */ BIT(http_hd_upgrade); /* Added HTTP header Upgrade: */ BIT(http_hd_h2_settings); /* Added HTTP header H2Settings: */ + BIT(maybe_folded); + BIT(leading_unfold); /* unfold started, this is the leading bytes */ #endif }; @@ -1174,8 +1154,8 @@ enum dupstring { STRING_SSL_PINNEDPUBLICKEY, /* public key file to verify peer against */ STRING_SSL_CIPHER_LIST, /* list of ciphers to use */ STRING_SSL_CIPHER13_LIST, /* list of TLS 1.3 ciphers to use */ - STRING_SSL_CRLFILE, /* crl file to check certificate */ - STRING_SSL_ISSUERCERT, /* issuer cert file to check certificate */ + STRING_SSL_CRLFILE, /* CRL file to check certificate */ + STRING_SSL_ISSUERCERT, /* issuer cert file to check certificate */ STRING_SERVICE_NAME, /* Service name */ #ifndef CURL_DISABLE_PROXY STRING_CERT_PROXY, /* client certificate filename */ @@ -1188,7 +1168,7 @@ enum dupstring { STRING_SSL_PINNEDPUBLICKEY_PROXY, /* public key file to verify proxy */ STRING_SSL_CIPHER_LIST_PROXY, /* list of ciphers to use */ STRING_SSL_CIPHER13_LIST_PROXY, /* list of TLS 1.3 ciphers to use */ - STRING_SSL_CRLFILE_PROXY, /* crl file to check certificate */ + STRING_SSL_CRLFILE_PROXY, /* CRL file to check certificate */ STRING_SSL_ISSUERCERT_PROXY, /* issuer cert file to check certificate */ STRING_PROXY_SERVICE_NAME, /* Proxy service name */ #endif @@ -1310,7 +1290,6 @@ enum dupblob { BLOB_LAST }; - struct UserDefined { FILE *err; /* the stderr user data goes here */ void *debugdata; /* the data that will be passed to fdebug */ @@ -1382,7 +1361,7 @@ struct UserDefined { #ifndef CURL_DISABLE_PROXY struct ssl_config_data proxy_ssl; /* user defined SSL stuff for proxy */ struct curl_slist *proxyheaders; /* linked list of extra CONNECT headers */ - unsigned short proxyport; /* If non-zero, use this port number by + uint16_t proxyport; /* If non-zero, use this port number by default. If the proxy string features a ":[port]" that one will override this. */ unsigned char proxytype; /* what kind of proxy */ @@ -1650,8 +1629,8 @@ struct Curl_easy { /* once an easy handle is added to a multi, either explicitly by the * libcurl application or implicitly during `curl_easy_perform()`, * a unique identifier inside this one multi instance. */ - unsigned int mid; - unsigned int master_mid; /* if set, this transfer belongs to a master */ + uint32_t mid; + uint32_t master_mid; /* if set, this transfer belongs to a master */ multi_sub_xfer_done_cb *sub_xfer_done; struct connectdata *conn; diff --git a/vendor/hydra/vendor/curl/lib/vauth/cleartext.c b/vendor/hydra/vendor/curl/lib/vauth/cleartext.c index 884ebce0..fc8a6ebd 100644 --- a/vendor/hydra/vendor/curl/lib/vauth/cleartext.c +++ b/vendor/hydra/vendor/curl/lib/vauth/cleartext.c @@ -24,23 +24,13 @@ * Draft LOGIN SASL Mechanism * ***************************************************************************/ - #include "../curl_setup.h" -#if !defined(CURL_DISABLE_IMAP) || !defined(CURL_DISABLE_SMTP) || \ - !defined(CURL_DISABLE_POP3) || \ +#if !defined(CURL_DISABLE_IMAP) || !defined(CURL_DISABLE_SMTP) || \ + !defined(CURL_DISABLE_POP3) || \ (!defined(CURL_DISABLE_LDAP) && defined(USE_OPENLDAP)) -#include -#include "../urldata.h" - #include "vauth.h" -#include "../curlx/warnless.h" -#include "../sendf.h" - -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" /* * Curl_auth_create_plain_message() @@ -114,8 +104,7 @@ void Curl_auth_create_login_message(const char *valuep, struct bufref *out) * * Returns void. */ -void Curl_auth_create_external_message(const char *user, - struct bufref *out) +void Curl_auth_create_external_message(const char *user, struct bufref *out) { /* This is the same formatting as the login message */ Curl_auth_create_login_message(user, out); diff --git a/vendor/hydra/vendor/curl/lib/vauth/cram.c b/vendor/hydra/vendor/curl/lib/vauth/cram.c index 2754ddc4..f5399738 100644 --- a/vendor/hydra/vendor/curl/lib/vauth/cram.c +++ b/vendor/hydra/vendor/curl/lib/vauth/cram.c @@ -23,22 +23,13 @@ * RFC2195 CRAM-MD5 authentication * ***************************************************************************/ - #include "../curl_setup.h" #ifndef CURL_DISABLE_DIGEST_AUTH -#include -#include "../urldata.h" - #include "vauth.h" #include "../curl_hmac.h" #include "../curl_md5.h" -#include "../curlx/warnless.h" - -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" /* @@ -67,14 +58,14 @@ CURLcode Curl_auth_create_cram_md5_message(const struct bufref *chlg, /* Compute the digest using the password as the key */ ctxt = Curl_HMAC_init(&Curl_HMAC_MD5, - (const unsigned char *) passwdp, + (const unsigned char *)passwdp, curlx_uztoui(strlen(passwdp))); if(!ctxt) return CURLE_OUT_OF_MEMORY; /* Update the digest with the given challenge */ if(Curl_bufref_len(chlg)) - Curl_HMAC_update(ctxt, Curl_bufref_ptr(chlg), + Curl_HMAC_update(ctxt, Curl_bufref_uptr(chlg), curlx_uztoui(Curl_bufref_len(chlg))); /* Finalise the digest */ diff --git a/vendor/hydra/vendor/curl/lib/vauth/digest.c b/vendor/hydra/vendor/curl/lib/vauth/digest.c index 0a0b3580..a1fd2486 100644 --- a/vendor/hydra/vendor/curl/lib/vauth/digest.c +++ b/vendor/hydra/vendor/curl/lib/vauth/digest.c @@ -24,30 +24,19 @@ * RFC7616 DIGEST-SHA256, DIGEST-SHA512-256 authentication * ***************************************************************************/ - #include "../curl_setup.h" #ifndef CURL_DISABLE_DIGEST_AUTH -#include - #include "vauth.h" #include "digest.h" -#include "../urldata.h" #include "../curlx/base64.h" -#include "../curl_hmac.h" #include "../curl_md5.h" #include "../curl_sha256.h" #include "../curl_sha512_256.h" -#include "../vtls/vtls.h" -#include "../curlx/warnless.h" #include "../curlx/strparse.h" #include "../rand.h" -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - #ifndef USE_WINDOWS_SSPI #define SESSION_ALGO 1 /* for algos with this bit set */ @@ -142,20 +131,20 @@ bool Curl_auth_digest_get_pair(const char *str, char *value, char *content, #ifndef USE_WINDOWS_SSPI /* Convert MD5 chunk to RFC2617 (section 3.1.3) -suitable ASCII string */ static void auth_digest_md5_to_ascii(unsigned char *source, /* 16 bytes */ - unsigned char *dest) /* 33 bytes */ + unsigned char *dest) /* 33 bytes */ { int i; for(i = 0; i < 16; i++) - curl_msnprintf((char *) &dest[i * 2], 3, "%02x", source[i]); + curl_msnprintf((char *)&dest[i * 2], 3, "%02x", source[i]); } /* Convert sha256 or SHA-512/256 chunk to RFC7616 -suitable ASCII string */ static void auth_digest_sha256_to_ascii(unsigned char *source, /* 32 bytes */ - unsigned char *dest) /* 65 bytes */ + unsigned char *dest) /* 65 bytes */ { int i; for(i = 0; i < 32; i++) - curl_msnprintf((char *) &dest[i * 2], 3, "%02x", source[i]); + curl_msnprintf((char *)&dest[i * 2], 3, "%02x", source[i]); } /* Perform quoted-string escaping as described in RFC2616 and its errata */ @@ -174,7 +163,7 @@ static char *auth_digest_string_quoted(const char *source) ++s; } - dest = malloc(n); + dest = curlx_malloc(n); if(dest) { char *d = dest; s = source; @@ -203,6 +192,9 @@ static bool auth_digest_get_key_value(const char *chlg, const char *key, do { struct Curl_str data; struct Curl_str name; + + curlx_str_passblanks(&chlg); + if(!curlx_str_until(&chlg, &name, 64, '=') && !curlx_str_single(&chlg, '=')) { /* this is the key, get the value, possibly quoted */ @@ -215,11 +207,22 @@ static bool auth_digest_get_key_value(const char *chlg, const char *key, if(curlx_str_cmp(&name, key)) { /* if this is our key, return the value */ - if(curlx_strlen(&data) >= buflen) - /* doesn't fit */ + size_t len = curlx_strlen(&data); + const char *src = curlx_str(&data); + size_t i; + size_t outlen = 0; + + if(len >= buflen) + /* does not fit */ return FALSE; - memcpy(buf, curlx_str(&data), curlx_strlen(&data)); - buf[curlx_strlen(&data)] = 0; + + for(i = 0; i < len; i++) { + if(src[i] == '\\' && i + 1 < len) { + i++; /* skip backslash */ + } + buf[outlen++] = src[i]; + } + buf[outlen] = 0; return TRUE; } if(curlx_str_single(&chlg, ',')) @@ -232,7 +235,7 @@ static bool auth_digest_get_key_value(const char *chlg, const char *key, return FALSE; } -static CURLcode auth_digest_get_qop_values(const char *options, int *value) +static void auth_digest_get_qop_values(const char *options, int *value) { struct Curl_str out; /* Initialise the output */ @@ -248,8 +251,6 @@ static CURLcode auth_digest_get_qop_values(const char *options, int *value) if(curlx_str_single(&options, ',')) break; } - - return CURLE_OK; } /* @@ -278,7 +279,7 @@ static CURLcode auth_decode_digest_md5_message(const struct bufref *chlgref, char *alg, size_t alen, char *qop, size_t qlen) { - const char *chlg = (const char *) Curl_bufref_ptr(chlgref); + const char *chlg = Curl_bufref_ptr(chlgref); /* Ensure we have a valid challenge message */ if(!Curl_bufref_len(chlgref)) @@ -377,9 +378,7 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data, return CURLE_BAD_CONTENT_ENCODING; /* Get the qop-values from the qop-options */ - result = auth_digest_get_qop_values(qop_options, &qop_values); - if(result) - return result; + auth_digest_get_qop_values(qop_options, &qop_values); /* We only support auth quality-of-protection */ if(!(qop_values & DIGEST_QOP_VALUE_AUTH)) @@ -395,13 +394,13 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data, if(!ctxt) return CURLE_OUT_OF_MEMORY; - Curl_MD5_update(ctxt, (const unsigned char *) userp, + Curl_MD5_update(ctxt, (const unsigned char *)userp, curlx_uztoui(strlen(userp))); - Curl_MD5_update(ctxt, (const unsigned char *) ":", 1); - Curl_MD5_update(ctxt, (const unsigned char *) realm, + Curl_MD5_update(ctxt, (const unsigned char *)":", 1); + Curl_MD5_update(ctxt, (const unsigned char *)realm, curlx_uztoui(strlen(realm))); - Curl_MD5_update(ctxt, (const unsigned char *) ":", 1); - Curl_MD5_update(ctxt, (const unsigned char *) passwdp, + Curl_MD5_update(ctxt, (const unsigned char *)":", 1); + Curl_MD5_update(ctxt, (const unsigned char *)passwdp, curlx_uztoui(strlen(passwdp))); Curl_MD5_final(ctxt, digest); @@ -409,12 +408,12 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data, if(!ctxt) return CURLE_OUT_OF_MEMORY; - Curl_MD5_update(ctxt, (const unsigned char *) digest, MD5_DIGEST_LEN); - Curl_MD5_update(ctxt, (const unsigned char *) ":", 1); - Curl_MD5_update(ctxt, (const unsigned char *) nonce, + Curl_MD5_update(ctxt, (const unsigned char *)digest, MD5_DIGEST_LEN); + Curl_MD5_update(ctxt, (const unsigned char *)":", 1); + Curl_MD5_update(ctxt, (const unsigned char *)nonce, curlx_uztoui(strlen(nonce))); - Curl_MD5_update(ctxt, (const unsigned char *) ":", 1); - Curl_MD5_update(ctxt, (const unsigned char *) cnonce, + Curl_MD5_update(ctxt, (const unsigned char *)":", 1); + Curl_MD5_update(ctxt, (const unsigned char *)cnonce, curlx_uztoui(strlen(cnonce))); Curl_MD5_final(ctxt, digest); @@ -430,15 +429,15 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data, /* Calculate H(A2) */ ctxt = Curl_MD5_init(&Curl_DIGEST_MD5); if(!ctxt) { - free(spn); + curlx_free(spn); return CURLE_OUT_OF_MEMORY; } - Curl_MD5_update(ctxt, (const unsigned char *) method, + Curl_MD5_update(ctxt, (const unsigned char *)method, curlx_uztoui(strlen(method))); - Curl_MD5_update(ctxt, (const unsigned char *) ":", 1); - Curl_MD5_update(ctxt, (const unsigned char *) spn, + Curl_MD5_update(ctxt, (const unsigned char *)":", 1); + Curl_MD5_update(ctxt, (const unsigned char *)spn, curlx_uztoui(strlen(spn))); Curl_MD5_final(ctxt, digest); @@ -448,28 +447,28 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data, /* Now calculate the response hash */ ctxt = Curl_MD5_init(&Curl_DIGEST_MD5); if(!ctxt) { - free(spn); + curlx_free(spn); return CURLE_OUT_OF_MEMORY; } - Curl_MD5_update(ctxt, (const unsigned char *) HA1_hex, 2 * MD5_DIGEST_LEN); - Curl_MD5_update(ctxt, (const unsigned char *) ":", 1); - Curl_MD5_update(ctxt, (const unsigned char *) nonce, + Curl_MD5_update(ctxt, (const unsigned char *)HA1_hex, 2 * MD5_DIGEST_LEN); + Curl_MD5_update(ctxt, (const unsigned char *)":", 1); + Curl_MD5_update(ctxt, (const unsigned char *)nonce, curlx_uztoui(strlen(nonce))); - Curl_MD5_update(ctxt, (const unsigned char *) ":", 1); + Curl_MD5_update(ctxt, (const unsigned char *)":", 1); - Curl_MD5_update(ctxt, (const unsigned char *) nonceCount, + Curl_MD5_update(ctxt, (const unsigned char *)nonceCount, curlx_uztoui(strlen(nonceCount))); - Curl_MD5_update(ctxt, (const unsigned char *) ":", 1); - Curl_MD5_update(ctxt, (const unsigned char *) cnonce, + Curl_MD5_update(ctxt, (const unsigned char *)":", 1); + Curl_MD5_update(ctxt, (const unsigned char *)cnonce, curlx_uztoui(strlen(cnonce))); - Curl_MD5_update(ctxt, (const unsigned char *) ":", 1); - Curl_MD5_update(ctxt, (const unsigned char *) qop, + Curl_MD5_update(ctxt, (const unsigned char *)":", 1); + Curl_MD5_update(ctxt, (const unsigned char *)qop, curlx_uztoui(strlen(qop))); - Curl_MD5_update(ctxt, (const unsigned char *) ":", 1); + Curl_MD5_update(ctxt, (const unsigned char *)":", 1); - Curl_MD5_update(ctxt, (const unsigned char *) HA2_hex, 2 * MD5_DIGEST_LEN); + Curl_MD5_update(ctxt, (const unsigned char *)HA2_hex, 2 * MD5_DIGEST_LEN); Curl_MD5_final(ctxt, digest); for(i = 0; i < MD5_DIGEST_LEN; i++) @@ -481,7 +480,7 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data, "response=%s,qop=%s", userp, realm, nonce, cnonce, nonceCount, spn, resp_hash_hex, qop); - free(spn); + curlx_free(spn); if(!response) return CURLE_OUT_OF_MEMORY; @@ -526,8 +525,8 @@ CURLcode Curl_auth_decode_digest_http_message(const char *chlg, /* Extract a value=content pair */ if(Curl_auth_digest_get_pair(chlg, value, content, &chlg)) { if(curl_strequal(value, "nonce")) { - free(digest->nonce); - digest->nonce = strdup(content); + curlx_free(digest->nonce); + digest->nonce = curlx_strdup(content); if(!digest->nonce) return CURLE_OUT_OF_MEMORY; } @@ -538,14 +537,14 @@ CURLcode Curl_auth_decode_digest_http_message(const char *chlg, } } else if(curl_strequal(value, "realm")) { - free(digest->realm); - digest->realm = strdup(content); + curlx_free(digest->realm); + digest->realm = curlx_strdup(content); if(!digest->realm) return CURLE_OUT_OF_MEMORY; } else if(curl_strequal(value, "opaque")) { - free(digest->opaque); - digest->opaque = strdup(content); + curlx_free(digest->opaque); + digest->opaque = curlx_strdup(content); if(!digest->opaque) return CURLE_OUT_OF_MEMORY; } @@ -561,7 +560,7 @@ CURLcode Curl_auth_decode_digest_http_message(const char *chlg, if(curlx_str_casecompare(&out, DIGEST_QOP_VALUE_STRING_AUTH)) foundAuth = TRUE; else if(curlx_str_casecompare(&out, - DIGEST_QOP_VALUE_STRING_AUTH_INT)) + DIGEST_QOP_VALUE_STRING_AUTH_INT)) foundAuthInt = TRUE; if(curlx_str_single(&token, ',')) break; @@ -571,21 +570,21 @@ CURLcode Curl_auth_decode_digest_http_message(const char *chlg, /* Select only auth or auth-int. Otherwise, ignore */ if(foundAuth) { - free(digest->qop); - digest->qop = strdup(DIGEST_QOP_VALUE_STRING_AUTH); + curlx_free(digest->qop); + digest->qop = curlx_strdup(DIGEST_QOP_VALUE_STRING_AUTH); if(!digest->qop) return CURLE_OUT_OF_MEMORY; } else if(foundAuthInt) { - free(digest->qop); - digest->qop = strdup(DIGEST_QOP_VALUE_STRING_AUTH_INT); + curlx_free(digest->qop); + digest->qop = curlx_strdup(DIGEST_QOP_VALUE_STRING_AUTH_INT); if(!digest->qop) return CURLE_OUT_OF_MEMORY; } } else if(curl_strequal(value, "algorithm")) { - free(digest->algorithm); - digest->algorithm = strdup(content); + curlx_free(digest->algorithm); + digest->algorithm = curlx_strdup(content); if(!digest->algorithm) return CURLE_OUT_OF_MEMORY; @@ -600,16 +599,16 @@ CURLcode Curl_auth_decode_digest_http_message(const char *chlg, else if(curl_strequal(content, "SHA-512-256")) { #ifdef CURL_HAVE_SHA512_256 digest->algo = ALGO_SHA512_256; -#else /* ! CURL_HAVE_SHA512_256 */ +#else /* !CURL_HAVE_SHA512_256 */ return CURLE_NOT_BUILT_IN; -#endif /* ! CURL_HAVE_SHA512_256 */ +#endif /* CURL_HAVE_SHA512_256 */ } else if(curl_strequal(content, "SHA-512-256-SESS")) { #ifdef CURL_HAVE_SHA512_256 digest->algo = ALGO_SHA512_256SESS; -#else /* ! CURL_HAVE_SHA512_256 */ +#else /* !CURL_HAVE_SHA512_256 */ return CURLE_NOT_BUILT_IN; -#endif /* ! CURL_HAVE_SHA512_256 */ +#endif /* CURL_HAVE_SHA512_256 */ } else return CURLE_BAD_CONTENT_ENCODING; @@ -714,7 +713,7 @@ static CURLcode auth_create_digest_http_message( if(result) return result; - result = curlx_base64_encode(cnoncebuf, sizeof(cnoncebuf), + result = curlx_base64_encode((uint8_t *)cnoncebuf, sizeof(cnoncebuf), &cnonce, &cnonce_sz); if(result) return result; @@ -728,8 +727,8 @@ static CURLcode auth_create_digest_http_message( if(!hashthis) return CURLE_OUT_OF_MEMORY; - result = hash(hashbuf, (unsigned char *) hashthis, strlen(hashthis)); - free(hashthis); + result = hash(hashbuf, (unsigned char *)hashthis, strlen(hashthis)); + curlx_free(hashthis); if(result) return result; convert_to_ascii(hashbuf, (unsigned char *)userh); @@ -751,8 +750,8 @@ static CURLcode auth_create_digest_http_message( if(!hashthis) return CURLE_OUT_OF_MEMORY; - result = hash(hashbuf, (unsigned char *) hashthis, strlen(hashthis)); - free(hashthis); + result = hash(hashbuf, (unsigned char *)hashthis, strlen(hashthis)); + curlx_free(hashthis); if(result) return result; convert_to_ascii(hashbuf, ha1); @@ -763,8 +762,8 @@ static CURLcode auth_create_digest_http_message( if(!tmp) return CURLE_OUT_OF_MEMORY; - result = hash(hashbuf, (unsigned char *) tmp, strlen(tmp)); - free(tmp); + result = hash(hashbuf, (unsigned char *)tmp, strlen(tmp)); + curlx_free(tmp); if(result) return result; convert_to_ascii(hashbuf, ha1); @@ -794,21 +793,21 @@ static CURLcode auth_create_digest_http_message( result = hash(hashbuf, (const unsigned char *)"", 0); if(result) { - free(hashthis); + curlx_free(hashthis); return result; } convert_to_ascii(hashbuf, (unsigned char *)hashed); hashthis2 = curl_maprintf("%s:%s", hashthis, hashed); - free(hashthis); + curlx_free(hashthis); hashthis = hashthis2; } if(!hashthis) return CURLE_OUT_OF_MEMORY; - result = hash(hashbuf, (unsigned char *) hashthis, strlen(hashthis)); - free(hashthis); + result = hash(hashbuf, (unsigned char *)hashthis, strlen(hashthis)); + curlx_free(hashthis); if(result) return result; convert_to_ascii(hashbuf, ha2); @@ -824,8 +823,8 @@ static CURLcode auth_create_digest_http_message( if(!hashthis) return CURLE_OUT_OF_MEMORY; - result = hash(hashbuf, (unsigned char *) hashthis, strlen(hashthis)); - free(hashthis); + result = hash(hashbuf, (unsigned char *)hashthis, strlen(hashthis)); + curlx_free(hashthis); if(result) return result; convert_to_ascii(hashbuf, request_digest); @@ -849,18 +848,18 @@ static CURLcode auth_create_digest_http_message( if(digest->realm) realm_quoted = auth_digest_string_quoted(digest->realm); else { - realm_quoted = malloc(1); + realm_quoted = curlx_malloc(1); if(realm_quoted) realm_quoted[0] = 0; } if(!realm_quoted) { - free(userp_quoted); + curlx_free(userp_quoted); return CURLE_OUT_OF_MEMORY; } nonce_quoted = auth_digest_string_quoted(digest->nonce); if(!nonce_quoted) { - free(realm_quoted); - free(userp_quoted); + curlx_free(realm_quoted); + curlx_free(userp_quoted); return CURLE_OUT_OF_MEMORY; } @@ -897,9 +896,9 @@ static CURLcode auth_create_digest_http_message( uripath, request_digest); } - free(nonce_quoted); - free(realm_quoted); - free(userp_quoted); + curlx_free(nonce_quoted); + curlx_free(realm_quoted); + curlx_free(userp_quoted); if(!response) return CURLE_OUT_OF_MEMORY; @@ -909,12 +908,12 @@ static CURLcode auth_create_digest_http_message( /* Append the opaque */ opaque_quoted = auth_digest_string_quoted(digest->opaque); if(!opaque_quoted) { - free(response); + curlx_free(response); return CURLE_OUT_OF_MEMORY; } tmp = curl_maprintf("%s, opaque=\"%s\"", response, opaque_quoted); - free(response); - free(opaque_quoted); + curlx_free(response); + curlx_free(opaque_quoted); if(!tmp) return CURLE_OUT_OF_MEMORY; @@ -924,7 +923,7 @@ static CURLcode auth_create_digest_http_message( if(digest->algorithm) { /* Append the algorithm */ tmp = curl_maprintf("%s, algorithm=%s", response, digest->algorithm); - free(response); + curlx_free(response); if(!tmp) return CURLE_OUT_OF_MEMORY; @@ -934,7 +933,7 @@ static CURLcode auth_create_digest_http_message( if(digest->userhash) { /* Append the userhash */ tmp = curl_maprintf("%s, userhash=true", response); - free(response); + curlx_free(response); if(!tmp) return CURLE_OUT_OF_MEMORY; @@ -1023,9 +1022,9 @@ void Curl_auth_digest_cleanup(struct digestdata *digest) digest->nc = 0; digest->algo = ALGO_MD5; /* default algorithm */ - digest->stale = FALSE; /* default means normal, not stale */ + digest->stale = FALSE; /* default means normal, not stale */ digest->userhash = FALSE; } -#endif /* !USE_WINDOWS_SSPI */ +#endif /* !USE_WINDOWS_SSPI */ -#endif /* !CURL_DISABLE_DIGEST_AUTH */ +#endif /* !CURL_DISABLE_DIGEST_AUTH */ diff --git a/vendor/hydra/vendor/curl/lib/vauth/digest.h b/vendor/hydra/vendor/curl/lib/vauth/digest.h index 99ce1f91..902ffab1 100644 --- a/vendor/hydra/vendor/curl/lib/vauth/digest.h +++ b/vendor/hydra/vendor/curl/lib/vauth/digest.h @@ -23,8 +23,7 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - -#include +#include "../curl_setup.h" #ifndef CURL_DISABLE_DIGEST_AUTH diff --git a/vendor/hydra/vendor/curl/lib/vauth/digest_sspi.c b/vendor/hydra/vendor/curl/lib/vauth/digest_sspi.c index 9441ee26..615b4bc8 100644 --- a/vendor/hydra/vendor/curl/lib/vauth/digest_sspi.c +++ b/vendor/hydra/vendor/curl/lib/vauth/digest_sspi.c @@ -24,36 +24,27 @@ * RFC2831 DIGEST-MD5 authentication * ***************************************************************************/ - #include "../curl_setup.h" #if defined(USE_WINDOWS_SSPI) && !defined(CURL_DISABLE_DIGEST_AUTH) -#include - #include "vauth.h" #include "digest.h" -#include "../urldata.h" -#include "../curlx/warnless.h" #include "../curlx/multibyte.h" -#include "../sendf.h" +#include "../curl_trc.h" #include "../strdup.h" #include "../strcase.h" #include "../strerror.h" -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* -* Curl_auth_is_digest_supported() -* -* This is used to evaluate if DIGEST is supported. -* -* Parameters: None -* -* Returns TRUE if DIGEST is supported by Windows SSPI. -*/ + * Curl_auth_is_digest_supported() + * + * This is used to evaluate if DIGEST is supported. + * + * Parameters: None + * + * Returns TRUE if DIGEST is supported by Windows SSPI. + */ bool Curl_auth_is_digest_supported(void) { PSecPkgInfo SecurityPackage; @@ -135,14 +126,14 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data, Curl_pSecFn->FreeContextBuffer(SecurityPackage); /* Allocate our response buffer */ - output_token = malloc(token_max); + output_token = curlx_malloc(token_max); if(!output_token) return CURLE_OUT_OF_MEMORY; /* Generate our SPN */ spn = Curl_auth_build_spn(service, data->conn->host.name, NULL); if(!spn) { - free(output_token); + curlx_free(output_token); return CURLE_OUT_OF_MEMORY; } @@ -150,8 +141,8 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data, /* Populate our identity structure */ result = Curl_create_sspi_identity(userp, passwdp, &identity); if(result) { - free(spn); - free(output_token); + curlx_free(spn); + curlx_free(output_token); return result; } @@ -171,8 +162,8 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data, if(status != SEC_E_OK) { Curl_sspi_free_identity(p_identity); - free(spn); - free(output_token); + curlx_free(spn); + curlx_free(output_token); return CURLE_LOGIN_DENIED; } @@ -208,8 +199,8 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data, Curl_pSecFn->FreeCredentialsHandle(&credentials); Curl_sspi_free_identity(p_identity); - free(spn); - free(output_token); + curlx_free(spn); + curlx_free(output_token); if(status == SEC_E_INSUFFICIENT_MEMORY) return CURLE_OUT_OF_MEMORY; @@ -233,7 +224,7 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data, Curl_sspi_free_identity(p_identity); /* Free the SPN */ - free(spn); + curlx_free(spn); return result; } @@ -276,18 +267,18 @@ CURLcode Curl_override_sspi_http_realm(const char *chlg, if(!domain.tchar_ptr) return CURLE_OUT_OF_MEMORY; - dup_domain.tchar_ptr = Curl_tcsdup(domain.tchar_ptr); + dup_domain.tchar_ptr = curlx_tcsdup(domain.tchar_ptr); if(!dup_domain.tchar_ptr) { - curlx_unicodefree(domain.tchar_ptr); + curlx_free(domain.tchar_ptr); return CURLE_OUT_OF_MEMORY; } - free(identity->Domain); + curlx_free(identity->Domain); identity->Domain = dup_domain.tbyte_ptr; identity->DomainLength = curlx_uztoul(_tcslen(dup_domain.tchar_ptr)); dup_domain.tchar_ptr = NULL; - curlx_unicodefree(domain.tchar_ptr); + curlx_free(domain.tchar_ptr); } else { /* Unknown specifier, ignore it! */ @@ -429,7 +420,7 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data, /* Allocate the output buffer according to the max token size as indicated by the security package */ - output_token = malloc(token_max); + output_token = curlx_malloc(token_max); if(!output_token) { return CURLE_OUT_OF_MEMORY; } @@ -457,10 +448,10 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data, chlg_buf[0].cbBuffer = 0; chlg_buf[1].BufferType = SECBUFFER_PKG_PARAMS; chlg_buf[1].pvBuffer = CURL_UNCONST(request); - chlg_buf[1].cbBuffer = curlx_uztoul(strlen((const char *) request)); + chlg_buf[1].cbBuffer = curlx_uztoul(strlen((const char *)request)); chlg_buf[2].BufferType = SECBUFFER_PKG_PARAMS; chlg_buf[2].pvBuffer = CURL_UNCONST(uripath); - chlg_buf[2].cbBuffer = curlx_uztoul(strlen((const char *) uripath)); + chlg_buf[2].cbBuffer = curlx_uztoul(strlen((const char *)uripath)); chlg_buf[3].BufferType = SECBUFFER_PKG_PARAMS; chlg_buf[3].pvBuffer = NULL; chlg_buf[3].cbBuffer = 0; @@ -495,14 +486,15 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data, if(userp && *userp) { /* Populate our identity structure */ if(Curl_create_sspi_identity(userp, passwdp, &identity)) { - free(output_token); + curlx_free(output_token); return CURLE_OUT_OF_MEMORY; } /* Populate our identity domain */ - if(Curl_override_sspi_http_realm((const char *) digest->input_token, + if(Curl_override_sspi_http_realm((const char *)digest->input_token, &identity)) { - free(output_token); + Curl_sspi_free_identity(&identity); + curlx_free(output_token); return CURLE_OUT_OF_MEMORY; } @@ -514,20 +506,20 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data, p_identity = NULL; if(userp) { - digest->user = strdup(userp); + digest->user = curlx_strdup(userp); if(!digest->user) { - free(output_token); + curlx_free(output_token); Curl_sspi_free_identity(p_identity); return CURLE_OUT_OF_MEMORY; } } if(passwdp) { - digest->passwd = strdup(passwdp); + digest->passwd = curlx_strdup(passwdp); if(!digest->passwd) { - free(output_token); + curlx_free(output_token); Curl_sspi_free_identity(p_identity); Curl_safefree(digest->user); return CURLE_OUT_OF_MEMORY; @@ -542,7 +534,7 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data, &credentials, NULL); if(status != SEC_E_OK) { Curl_sspi_free_identity(p_identity); - free(output_token); + curlx_free(output_token); return CURLE_LOGIN_DENIED; } @@ -556,7 +548,7 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data, chlg_buf[0].cbBuffer = curlx_uztoul(digest->input_token_len); chlg_buf[1].BufferType = SECBUFFER_PKG_PARAMS; chlg_buf[1].pvBuffer = CURL_UNCONST(request); - chlg_buf[1].cbBuffer = curlx_uztoul(strlen((const char *) request)); + chlg_buf[1].cbBuffer = curlx_uztoul(strlen((const char *)request)); chlg_buf[2].BufferType = SECBUFFER_PKG_PARAMS; chlg_buf[2].pvBuffer = NULL; chlg_buf[2].cbBuffer = 0; @@ -569,22 +561,23 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data, resp_buf.pvBuffer = output_token; resp_buf.cbBuffer = curlx_uztoul(token_max); - spn = curlx_convert_UTF8_to_tchar((const char *) uripath); + spn = curlx_convert_UTF8_to_tchar((const char *)uripath); if(!spn) { Curl_pSecFn->FreeCredentialsHandle(&credentials); Curl_sspi_free_identity(p_identity); - free(output_token); + curlx_free(output_token); return CURLE_OUT_OF_MEMORY; } /* Allocate our new context handle */ - digest->http_context = calloc(1, sizeof(CtxtHandle)); + digest->http_context = curlx_calloc(1, sizeof(CtxtHandle)); if(!digest->http_context) { - curlx_unicodefree(spn); + Curl_pSecFn->FreeCredentialsHandle(&credentials); + curlx_free(spn); Curl_sspi_free_identity(p_identity); - free(output_token); + curlx_free(output_token); return CURLE_OUT_OF_MEMORY; } @@ -595,7 +588,7 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data, &chlg_desc, 0, digest->http_context, &resp_desc, &attrs, NULL); - curlx_unicodefree(spn); + curlx_free(spn); if(status == SEC_I_COMPLETE_NEEDED || status == SEC_I_COMPLETE_AND_CONTINUE) @@ -608,7 +601,7 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data, Curl_pSecFn->FreeCredentialsHandle(&credentials); Curl_sspi_free_identity(p_identity); - free(output_token); + curlx_free(output_token); Curl_safefree(digest->http_context); @@ -630,7 +623,7 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data, } resp = Curl_memdup0((const char *)output_token, output_token_len); - free(output_token); + curlx_free(output_token); if(!resp) { return CURLE_OUT_OF_MEMORY; } diff --git a/vendor/hydra/vendor/curl/lib/vauth/gsasl.c b/vendor/hydra/vendor/curl/lib/vauth/gsasl.c index 119c392c..b95d6e3f 100644 --- a/vendor/hydra/vendor/curl/lib/vauth/gsasl.c +++ b/vendor/hydra/vendor/curl/lib/vauth/gsasl.c @@ -23,23 +23,15 @@ * RFC5802 SCRAM-SHA-1 authentication * ***************************************************************************/ - #include "../curl_setup.h" #ifdef USE_GSASL -#include - #include "vauth.h" -#include "../urldata.h" -#include "../sendf.h" +#include "../curl_trc.h" #include -/* The last 2 #include files should be in this order */ -#include "../curl_memory.h" -#include "../memdebug.h" - bool Curl_auth_gsasl_is_supported(struct Curl_easy *data, const char *mech, struct gsasldata *gsasl) @@ -103,8 +95,7 @@ CURLcode Curl_auth_gsasl_token(struct Curl_easy *data, char *response; size_t outlen; - res = gsasl_step(gsasl->client, - (const char *) Curl_bufref_ptr(chlg), Curl_bufref_len(chlg), + res = gsasl_step(gsasl->client, Curl_bufref_ptr(chlg), Curl_bufref_len(chlg), &response, &outlen); if(res != GSASL_OK && res != GSASL_NEEDS_MORE) { failf(data, "GSASL step: %s", gsasl_strerror(res)); diff --git a/vendor/hydra/vendor/curl/lib/vauth/krb5_gssapi.c b/vendor/hydra/vendor/curl/lib/vauth/krb5_gssapi.c index a414d0a3..6a9f1828 100644 --- a/vendor/hydra/vendor/curl/lib/vauth/krb5_gssapi.c +++ b/vendor/hydra/vendor/curl/lib/vauth/krb5_gssapi.c @@ -24,22 +24,14 @@ * RFC4752 The Kerberos V5 ("GSSAPI") SASL Mechanism * ***************************************************************************/ - #include "../curl_setup.h" #if defined(HAVE_GSSAPI) && defined(USE_KERBEROS5) -#include - #include "vauth.h" #include "../curl_sasl.h" -#include "../urldata.h" #include "../curl_gssapi.h" -#include "../sendf.h" - -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" +#include "../curl_trc.h" #if defined(__GNUC__) && defined(__APPLE__) #pragma GCC diagnostic push @@ -120,12 +112,12 @@ CURLcode Curl_auth_create_gssapi_user_message(struct Curl_easy *data, Curl_gss_log_error(data, "gss_import_name() failed: ", major_status, minor_status); - free(spn); + curlx_free(spn); return CURLE_AUTH_ERROR; } - free(spn); + curlx_free(spn); } if(chlg) { @@ -159,11 +151,11 @@ CURLcode Curl_auth_create_gssapi_user_message(struct Curl_easy *data, } if(output_token.value && output_token.length) { - result = Curl_bufref_memdup(out, output_token.value, output_token.length); + result = Curl_bufref_memdup0(out, output_token.value, output_token.length); gss_release_buffer(&unused_status, &output_token); } else - Curl_bufref_set(out, mutual_auth ? "": NULL, 0, NULL); + Curl_bufref_set(out, mutual_auth ? "" : NULL, 0, NULL); return result; } @@ -258,7 +250,7 @@ CURLcode Curl_auth_create_gssapi_security_message(struct Curl_easy *data, messagelen = 4; if(authzid) messagelen += strlen(authzid); - message = malloc(messagelen); + message = curlx_malloc(messagelen); if(!message) return CURLE_OUT_OF_MEMORY; @@ -285,17 +277,17 @@ CURLcode Curl_auth_create_gssapi_security_message(struct Curl_easy *data, if(GSS_ERROR(major_status)) { Curl_gss_log_error(data, "gss_wrap() failed: ", major_status, minor_status); - free(message); + curlx_free(message); return CURLE_AUTH_ERROR; } /* Return the response. */ - result = Curl_bufref_memdup(out, output_token.value, output_token.length); + result = Curl_bufref_memdup0(out, output_token.value, output_token.length); /* Free the output buffer */ gss_release_buffer(&unused_status, &output_token); /* Free the message buffer */ - free(message); + curlx_free(message); return result; } diff --git a/vendor/hydra/vendor/curl/lib/vauth/krb5_sspi.c b/vendor/hydra/vendor/curl/lib/vauth/krb5_sspi.c index c1953e11..8bf2091a 100644 --- a/vendor/hydra/vendor/curl/lib/vauth/krb5_sspi.c +++ b/vendor/hydra/vendor/curl/lib/vauth/krb5_sspi.c @@ -23,22 +23,12 @@ * RFC4752 The Kerberos V5 ("GSSAPI") SASL Mechanism * ***************************************************************************/ - #include "../curl_setup.h" #if defined(USE_WINDOWS_SSPI) && defined(USE_KERBEROS5) -#include - #include "vauth.h" -#include "../urldata.h" -#include "../curlx/warnless.h" -#include "../curlx/multibyte.h" -#include "../sendf.h" - -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" +#include "../curl_trc.h" /* * Curl_auth_is_gssapi_supported() @@ -131,7 +121,7 @@ CURLcode Curl_auth_create_gssapi_user_message(struct Curl_easy *data, Curl_pSecFn->FreeContextBuffer(SecurityPackage); /* Allocate our response buffer */ - krb5->output_token = malloc(krb5->token_max); + krb5->output_token = curlx_malloc(krb5->token_max); if(!krb5->output_token) return CURLE_OUT_OF_MEMORY; } @@ -152,7 +142,7 @@ CURLcode Curl_auth_create_gssapi_user_message(struct Curl_easy *data, krb5->p_identity = NULL; /* Allocate our credentials handle */ - krb5->credentials = calloc(1, sizeof(CredHandle)); + krb5->credentials = curlx_calloc(1, sizeof(CredHandle)); if(!krb5->credentials) return CURLE_OUT_OF_MEMORY; @@ -166,7 +156,7 @@ CURLcode Curl_auth_create_gssapi_user_message(struct Curl_easy *data, return CURLE_LOGIN_DENIED; /* Allocate our new context handle */ - krb5->context = calloc(1, sizeof(CtxtHandle)); + krb5->context = curlx_calloc(1, sizeof(CtxtHandle)); if(!krb5->context) return CURLE_OUT_OF_MEMORY; } @@ -218,7 +208,7 @@ CURLcode Curl_auth_create_gssapi_user_message(struct Curl_easy *data, } if(resp_buf.cbBuffer) { - result = Curl_bufref_memdup(out, resp_buf.pvBuffer, resp_buf.cbBuffer); + result = Curl_bufref_memdup0(out, resp_buf.pvBuffer, resp_buf.cbBuffer); } else if(mutual_auth) Curl_bufref_set(out, "", 0, NULL); @@ -250,6 +240,7 @@ CURLcode Curl_auth_create_gssapi_security_message(struct Curl_easy *data, struct kerberos5data *krb5, struct bufref *out) { + CURLcode result = CURLE_OK; size_t offset = 0; size_t messagelen = 0; size_t appdatalen = 0; @@ -281,8 +272,7 @@ CURLcode Curl_auth_create_gssapi_security_message(struct Curl_easy *data, /* Get our response size information */ status = Curl_pSecFn->QueryContextAttributes(krb5->context, - SECPKG_ATTR_SIZES, - &sizes); + SECPKG_ATTR_SIZES, &sizes); if(status == SEC_E_INSUFFICIENT_MEMORY) return CURLE_OUT_OF_MEMORY; @@ -339,7 +329,7 @@ CURLcode Curl_auth_create_gssapi_security_message(struct Curl_easy *data, } /* Allocate the trailer */ - trailer = malloc(sizes.cbSecurityTrailer); + trailer = curlx_malloc(sizes.cbSecurityTrailer); if(!trailer) return CURLE_OUT_OF_MEMORY; @@ -347,11 +337,10 @@ CURLcode Curl_auth_create_gssapi_security_message(struct Curl_easy *data, messagelen = 4; if(authzid) messagelen += strlen(authzid); - message = malloc(messagelen); + message = curlx_malloc(messagelen); if(!message) { - free(trailer); - - return CURLE_OUT_OF_MEMORY; + result = CURLE_OUT_OF_MEMORY; + goto out; } /* Populate the message with the security layer and client supported receive @@ -367,12 +356,10 @@ CURLcode Curl_auth_create_gssapi_security_message(struct Curl_easy *data, memcpy(message + 4, authzid, messagelen - 4); /* Allocate the padding */ - padding = malloc(sizes.cbBlockSize); + padding = curlx_malloc(sizes.cbBlockSize); if(!padding) { - free(message); - free(trailer); - - return CURLE_OUT_OF_MEMORY; + result = CURLE_OUT_OF_MEMORY; + goto out; } /* Setup the "authentication data" security buffer */ @@ -393,26 +380,20 @@ CURLcode Curl_auth_create_gssapi_security_message(struct Curl_easy *data, status = Curl_pSecFn->EncryptMessage(krb5->context, KERB_WRAP_NO_ENCRYPT, &wrap_desc, 0); if(status != SEC_E_OK) { - free(padding); - free(message); - free(trailer); - if(status == SEC_E_INSUFFICIENT_MEMORY) - return CURLE_OUT_OF_MEMORY; - - return CURLE_AUTH_ERROR; + result = CURLE_OUT_OF_MEMORY; + else + result = CURLE_AUTH_ERROR; + goto out; } /* Allocate the encryption (wrap) buffer */ appdatalen = wrap_buf[0].cbBuffer + wrap_buf[1].cbBuffer + wrap_buf[2].cbBuffer; - appdata = malloc(appdatalen); + appdata = curlx_malloc(appdatalen); if(!appdata) { - free(padding); - free(message); - free(trailer); - - return CURLE_OUT_OF_MEMORY; + result = CURLE_OUT_OF_MEMORY; + goto out; } /* Populate the encryption buffer */ @@ -422,10 +403,14 @@ CURLcode Curl_auth_create_gssapi_security_message(struct Curl_easy *data, offset += wrap_buf[1].cbBuffer; memcpy(appdata + offset, wrap_buf[2].pvBuffer, wrap_buf[2].cbBuffer); +out: /* Free all of our local buffers */ - free(padding); - free(message); - free(trailer); + curlx_free(padding); + curlx_free(message); + curlx_free(trailer); + + if(result) + return result; /* Return the response. */ Curl_bufref_set(out, appdata, appdatalen, curl_free); @@ -447,14 +432,14 @@ void Curl_auth_cleanup_gssapi(struct kerberos5data *krb5) /* Free our security context */ if(krb5->context) { Curl_pSecFn->DeleteSecurityContext(krb5->context); - free(krb5->context); + curlx_free(krb5->context); krb5->context = NULL; } /* Free our credentials handle */ if(krb5->credentials) { Curl_pSecFn->FreeCredentialsHandle(krb5->credentials); - free(krb5->credentials); + curlx_free(krb5->credentials); krb5->credentials = NULL; } diff --git a/vendor/hydra/vendor/curl/lib/vauth/ntlm.c b/vendor/hydra/vendor/curl/lib/vauth/ntlm.c index 1e9b629d..54755733 100644 --- a/vendor/hydra/vendor/curl/lib/vauth/ntlm.c +++ b/vendor/hydra/vendor/curl/lib/vauth/ntlm.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "../curl_setup.h" #if defined(USE_NTLM) && !defined(USE_WINDOWS_SSPI) @@ -35,110 +34,99 @@ #define DEBUG_ME 0 -#include "../urldata.h" -#include "../sendf.h" +#include "vauth.h" +#include "../curl_trc.h" #include "../curl_ntlm_core.h" -#include "../curl_gethostname.h" -#include "../curlx/multibyte.h" -#include "../curlx/warnless.h" #include "../rand.h" -#include "../vtls/vtls.h" #include "../strdup.h" - -#include "vauth.h" #include "../curl_endian.h" -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - - /* NTLM buffer fixed size, large enough for long user + host + domain */ #define NTLM_BUFSIZE 1024 /* Flag bits definitions based on https://davenport.sourceforge.net/ntlm.html */ -#define NTLMFLAG_NEGOTIATE_UNICODE (1<<0) +#define NTLMFLAG_NEGOTIATE_UNICODE (1 << 0) /* Indicates that Unicode strings are supported for use in security buffer data. */ -#define NTLMFLAG_NEGOTIATE_OEM (1<<1) +#define NTLMFLAG_NEGOTIATE_OEM (1 << 1) /* Indicates that OEM strings are supported for use in security buffer data. */ -#define NTLMFLAG_REQUEST_TARGET (1<<2) +#define NTLMFLAG_REQUEST_TARGET (1 << 2) /* Requests that the server's authentication realm be included in the Type 2 message. */ -/* unknown (1<<3) */ -#define NTLMFLAG_NEGOTIATE_SIGN (1<<4) +/* unknown (1 << 3) */ +#define NTLMFLAG_NEGOTIATE_SIGN (1 << 4) /* Specifies that authenticated communication between the client and server should carry a digital signature (message integrity). */ -#define NTLMFLAG_NEGOTIATE_SEAL (1<<5) +#define NTLMFLAG_NEGOTIATE_SEAL (1 << 5) /* Specifies that authenticated communication between the client and server should be encrypted (message confidentiality). */ -#define NTLMFLAG_NEGOTIATE_DATAGRAM_STYLE (1<<6) +#define NTLMFLAG_NEGOTIATE_DATAGRAM_STYLE (1 << 6) /* Indicates that datagram authentication is being used. */ -#define NTLMFLAG_NEGOTIATE_LM_KEY (1<<7) +#define NTLMFLAG_NEGOTIATE_LM_KEY (1 << 7) /* Indicates that the LAN Manager session key should be used for signing and sealing authenticated communications. */ -#define NTLMFLAG_NEGOTIATE_NTLM_KEY (1<<9) +#define NTLMFLAG_NEGOTIATE_NTLM_KEY (1 << 9) /* Indicates that NTLM authentication is being used. */ -/* unknown (1<<10) */ +/* unknown (1 << 10) */ -#define NTLMFLAG_NEGOTIATE_ANONYMOUS (1<<11) +#define NTLMFLAG_NEGOTIATE_ANONYMOUS (1 << 11) /* Sent by the client in the Type 3 message to indicate that an anonymous context has been established. This also affects the response fields. */ -#define NTLMFLAG_NEGOTIATE_DOMAIN_SUPPLIED (1<<12) +#define NTLMFLAG_NEGOTIATE_DOMAIN_SUPPLIED (1 << 12) /* Sent by the client in the Type 1 message to indicate that a desired authentication realm is included in the message. */ -#define NTLMFLAG_NEGOTIATE_WORKSTATION_SUPPLIED (1<<13) +#define NTLMFLAG_NEGOTIATE_WORKSTATION_SUPPLIED (1 << 13) /* Sent by the client in the Type 1 message to indicate that the client workstation's name is included in the message. */ -#define NTLMFLAG_NEGOTIATE_LOCAL_CALL (1<<14) +#define NTLMFLAG_NEGOTIATE_LOCAL_CALL (1 << 14) /* Sent by the server to indicate that the server and client are on the same machine. Implies that the client may use a pre-established local security context rather than responding to the challenge. */ -#define NTLMFLAG_NEGOTIATE_ALWAYS_SIGN (1<<15) +#define NTLMFLAG_NEGOTIATE_ALWAYS_SIGN (1 << 15) /* Indicates that authenticated communication between the client and server should be signed with a "dummy" signature. */ -#define NTLMFLAG_TARGET_TYPE_DOMAIN (1<<16) +#define NTLMFLAG_TARGET_TYPE_DOMAIN (1 << 16) /* Sent by the server in the Type 2 message to indicate that the target authentication realm is a domain. */ -#define NTLMFLAG_TARGET_TYPE_SERVER (1<<17) +#define NTLMFLAG_TARGET_TYPE_SERVER (1 << 17) /* Sent by the server in the Type 2 message to indicate that the target authentication realm is a server. */ -#define NTLMFLAG_TARGET_TYPE_SHARE (1<<18) +#define NTLMFLAG_TARGET_TYPE_SHARE (1 << 18) /* Sent by the server in the Type 2 message to indicate that the target authentication realm is a share. Presumably, this is for share-level authentication. Usage is unclear. */ -#define NTLMFLAG_NEGOTIATE_NTLM2_KEY (1<<19) +#define NTLMFLAG_NEGOTIATE_NTLM2_KEY (1 << 19) /* Indicates that the NTLM2 signing and sealing scheme should be used for protecting authenticated communications. */ -#define NTLMFLAG_REQUEST_INIT_RESPONSE (1<<20) +#define NTLMFLAG_REQUEST_INIT_RESPONSE (1 << 20) /* unknown purpose */ -#define NTLMFLAG_REQUEST_ACCEPT_RESPONSE (1<<21) +#define NTLMFLAG_REQUEST_ACCEPT_RESPONSE (1 << 21) /* unknown purpose */ -#define NTLMFLAG_REQUEST_NONNT_SESSION_KEY (1<<22) +#define NTLMFLAG_REQUEST_NONNT_SESSION_KEY (1 << 22) /* unknown purpose */ -#define NTLMFLAG_NEGOTIATE_TARGET_INFO (1<<23) +#define NTLMFLAG_NEGOTIATE_TARGET_INFO (1 << 23) /* Sent by the server in the Type 2 message to indicate that it is including a Target Information block in the message. */ @@ -148,21 +136,21 @@ /* unknown (1<27) */ /* unknown (1<28) */ -#define NTLMFLAG_NEGOTIATE_128 (1<<29) +#define NTLMFLAG_NEGOTIATE_128 (1 << 29) /* Indicates that 128-bit encryption is supported. */ -#define NTLMFLAG_NEGOTIATE_KEY_EXCHANGE (1<<30) +#define NTLMFLAG_NEGOTIATE_KEY_EXCHANGE (1 << 30) /* Indicates that the client will provide an encrypted master key in the "Session Key" field of the Type 3 message. */ -#define NTLMFLAG_NEGOTIATE_56 (1<<31) +#define NTLMFLAG_NEGOTIATE_56 (1 << 31) /* Indicates that 56-bit encryption is supported. */ /* "NTLMSSP" signature is always in ASCII regardless of the platform */ #define NTLMSSP_SIGNATURE "\x4e\x54\x4c\x4d\x53\x53\x50" #if DEBUG_ME -# define DEBUG_OUT(x) x +#define DEBUG_OUT(x) x static void ntlm_print_flags(FILE *handle, unsigned long flags) { if(flags & NTLMFLAG_NEGOTIATE_UNICODE) @@ -240,7 +228,7 @@ static void ntlm_print_hex(FILE *handle, const char *buf, size_t len) curl_mfprintf(stderr, "%02.2x", (unsigned int)*p++); } #else -# define DEBUG_OUT(x) Curl_nop_stmt +#define DEBUG_OUT(x) Curl_nop_stmt #endif /* @@ -263,7 +251,7 @@ static CURLcode ntlm_decode_type2_target(struct Curl_easy *data, { unsigned short target_info_len = 0; unsigned int target_info_offset = 0; - const unsigned char *type2 = Curl_bufref_ptr(type2ref); + const unsigned char *type2 = Curl_bufref_uptr(type2ref); size_t type2len = Curl_bufref_len(type2ref); #ifdef CURL_DISABLE_VERBOSE_STRINGS @@ -282,7 +270,7 @@ static CURLcode ntlm_decode_type2_target(struct Curl_easy *data, return CURLE_BAD_CONTENT_ENCODING; } - free(ntlm->target_info); /* replace any previous data */ + curlx_free(ntlm->target_info); /* replace any previous data */ ntlm->target_info = Curl_memdup(&type2[target_info_offset], target_info_len); if(!ntlm->target_info) @@ -363,7 +351,7 @@ CURLcode Curl_auth_decode_ntlm_type2_message(struct Curl_easy *data, */ CURLcode result = CURLE_OK; - const unsigned char *type2 = Curl_bufref_ptr(type2ref); + const unsigned char *type2 = Curl_bufref_uptr(type2ref); size_t type2len = Curl_bufref_len(type2ref); #ifdef CURL_DISABLE_VERBOSE_STRINGS @@ -839,10 +827,10 @@ CURLcode Curl_auth_create_ntlm_type3_message(struct Curl_easy *data, size += hostlen; /* Return the binary blob. */ - result = Curl_bufref_memdup(out, ntlmbuf, size); + result = Curl_bufref_memdup0(out, ntlmbuf, size); error: - free(ntlmv2resp); /* Free the dynamic buffer allocated for NTLMv2 */ + curlx_free(ntlmv2resp); /* Free the dynamic buffer allocated for NTLMv2 */ Curl_auth_cleanup_ntlm(ntlm); diff --git a/vendor/hydra/vendor/curl/lib/vauth/ntlm_sspi.c b/vendor/hydra/vendor/curl/lib/vauth/ntlm_sspi.c index 07161718..3197dd0a 100644 --- a/vendor/hydra/vendor/curl/lib/vauth/ntlm_sspi.c +++ b/vendor/hydra/vendor/curl/lib/vauth/ntlm_sspi.c @@ -21,25 +21,15 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "../curl_setup.h" #if defined(USE_WINDOWS_SSPI) && defined(USE_NTLM) -#include - #include "vauth.h" -#include "../urldata.h" #include "../curl_ntlm_core.h" -#include "../curlx/warnless.h" -#include "../curlx/multibyte.h" -#include "../sendf.h" +#include "../curl_trc.h" #include "../strdup.h" -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* * Curl_auth_is_ntlm_supported() * @@ -117,7 +107,7 @@ CURLcode Curl_auth_create_ntlm_type1_message(struct Curl_easy *data, Curl_pSecFn->FreeContextBuffer(SecurityPackage); /* Allocate our output buffer */ - ntlm->output_token = malloc(ntlm->token_max); + ntlm->output_token = curlx_malloc(ntlm->token_max); if(!ntlm->output_token) return CURLE_OUT_OF_MEMORY; @@ -137,7 +127,7 @@ CURLcode Curl_auth_create_ntlm_type1_message(struct Curl_easy *data, ntlm->p_identity = NULL; /* Allocate our credentials handle */ - ntlm->credentials = calloc(1, sizeof(CredHandle)); + ntlm->credentials = curlx_calloc(1, sizeof(CredHandle)); if(!ntlm->credentials) return CURLE_OUT_OF_MEMORY; @@ -151,7 +141,7 @@ CURLcode Curl_auth_create_ntlm_type1_message(struct Curl_easy *data, return CURLE_LOGIN_DENIED; /* Allocate our new context handle */ - ntlm->context = calloc(1, sizeof(CtxtHandle)); + ntlm->context = curlx_calloc(1, sizeof(CtxtHandle)); if(!ntlm->context) return CURLE_OUT_OF_MEMORY; @@ -215,7 +205,7 @@ CURLcode Curl_auth_decode_ntlm_type2_message(struct Curl_easy *data, } /* Store the challenge for later use */ - ntlm->input_token = Curl_memdup0((const char *)Curl_bufref_ptr(type2), + ntlm->input_token = Curl_memdup0(Curl_bufref_ptr(type2), Curl_bufref_len(type2)); if(!ntlm->input_token) return CURLE_OUT_OF_MEMORY; @@ -225,7 +215,6 @@ CURLcode Curl_auth_decode_ntlm_type2_message(struct Curl_easy *data, } /* -* Curl_auth_create_ntlm_type3_message() * Curl_auth_create_ntlm_type3_message() * * This is used to generate an already encoded NTLM type-3 message ready for @@ -271,12 +260,12 @@ CURLcode Curl_auth_create_ntlm_type3_message(struct Curl_easy *data, #ifdef SECPKG_ATTR_ENDPOINT_BINDINGS /* ssl context comes from schannel. - * When extended protection is used in IIS server, - * we have to pass a second SecBuffer to the SecBufferDesc - * otherwise IIS will not pass the authentication (401 response). - * Minimum supported version is Windows 7. - * https://learn.microsoft.com/security-updates/SecurityAdvisories/2009/973811 - */ + * When extended protection is used in IIS server, + * we have to pass a second SecBuffer to the SecBufferDesc + * otherwise IIS will not pass the authentication (401 response). + * Minimum supported version is Windows 7. + * https://learn.microsoft.com/security-updates/SecurityAdvisories/2009/973811 + */ if(ntlm->sslContext) { SEC_CHANNEL_BINDINGS channelBindings; SecPkgContext_Bindings pkgBindings; @@ -323,7 +312,7 @@ CURLcode Curl_auth_create_ntlm_type3_message(struct Curl_easy *data, } /* Return the response. */ - result = Curl_bufref_memdup(out, ntlm->output_token, type_3_buf.cbBuffer); + result = Curl_bufref_memdup0(out, ntlm->output_token, type_3_buf.cbBuffer); Curl_auth_cleanup_ntlm(ntlm); return result; } @@ -343,14 +332,14 @@ void Curl_auth_cleanup_ntlm(struct ntlmdata *ntlm) /* Free our security context */ if(ntlm->context) { Curl_pSecFn->DeleteSecurityContext(ntlm->context); - free(ntlm->context); + curlx_free(ntlm->context); ntlm->context = NULL; } /* Free our credentials handle */ if(ntlm->credentials) { Curl_pSecFn->FreeCredentialsHandle(ntlm->credentials); - free(ntlm->credentials); + curlx_free(ntlm->credentials); ntlm->credentials = NULL; } diff --git a/vendor/hydra/vendor/curl/lib/vauth/oauth2.c b/vendor/hydra/vendor/curl/lib/vauth/oauth2.c index cf7addf5..a7a06133 100644 --- a/vendor/hydra/vendor/curl/lib/vauth/oauth2.c +++ b/vendor/hydra/vendor/curl/lib/vauth/oauth2.c @@ -23,22 +23,13 @@ * RFC6749 OAuth 2.0 Authorization Framework * ***************************************************************************/ - #include "../curl_setup.h" #if !defined(CURL_DISABLE_IMAP) || !defined(CURL_DISABLE_SMTP) || \ - !defined(CURL_DISABLE_POP3) || \ + !defined(CURL_DISABLE_POP3) || \ (!defined(CURL_DISABLE_LDAP) && defined(USE_OPENLDAP)) -#include -#include "../urldata.h" - #include "vauth.h" -#include "../curlx/warnless.h" - -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" /* * Curl_auth_create_oauth_bearer_message() diff --git a/vendor/hydra/vendor/curl/lib/vauth/spnego_gssapi.c b/vendor/hydra/vendor/curl/lib/vauth/spnego_gssapi.c index 4e9125ba..b1ec37cb 100644 --- a/vendor/hydra/vendor/curl/lib/vauth/spnego_gssapi.c +++ b/vendor/hydra/vendor/curl/lib/vauth/spnego_gssapi.c @@ -23,24 +23,14 @@ * RFC4178 Simple and Protected GSS-API Negotiation Mechanism * ***************************************************************************/ - #include "../curl_setup.h" #if defined(HAVE_GSSAPI) && defined(USE_SPNEGO) -#include - #include "vauth.h" -#include "../urldata.h" #include "../curlx/base64.h" #include "../curl_gssapi.h" -#include "../curlx/warnless.h" -#include "../curlx/multibyte.h" -#include "../sendf.h" - -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" +#include "../curl_trc.h" #if defined(__GNUC__) && defined(__APPLE__) #pragma GCC diagnostic push @@ -96,7 +86,7 @@ CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data, gss_buffer_desc input_token = GSS_C_EMPTY_BUFFER; gss_buffer_desc output_token = GSS_C_EMPTY_BUFFER; gss_channel_bindings_t chan_bindings = GSS_C_NO_CHANNEL_BINDINGS; -#ifdef CURL_GSSAPI_HAS_CHANNEL_BINDING +#ifdef GSS_C_CHANNEL_BOUND_FLAG struct gss_channel_bindings_struct chan; #endif @@ -131,12 +121,12 @@ CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data, Curl_gss_log_error(data, "gss_import_name() failed: ", major_status, minor_status); - free(spn); + curlx_free(spn); return CURLE_AUTH_ERROR; } - free(spn); + curlx_free(spn); } if(chlg64 && *chlg64) { @@ -159,7 +149,7 @@ CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data, } /* Set channel binding data if available */ -#ifdef CURL_GSSAPI_HAS_CHANNEL_BINDING +#ifdef GSS_C_CHANNEL_BOUND_FLAG if(curlx_dyn_len(&nego->channel_binding_data)) { memset(&chan, 0, sizeof(struct gss_channel_bindings_struct)); chan.application_data.length = curlx_dyn_len(&nego->channel_binding_data); diff --git a/vendor/hydra/vendor/curl/lib/vauth/spnego_sspi.c b/vendor/hydra/vendor/curl/lib/vauth/spnego_sspi.c index 935468f3..42117631 100644 --- a/vendor/hydra/vendor/curl/lib/vauth/spnego_sspi.c +++ b/vendor/hydra/vendor/curl/lib/vauth/spnego_sspi.c @@ -23,25 +23,15 @@ * RFC4178 Simple and Protected GSS-API Negotiation Mechanism * ***************************************************************************/ - #include "../curl_setup.h" #if defined(USE_WINDOWS_SSPI) && defined(USE_SPNEGO) -#include - #include "vauth.h" -#include "../urldata.h" #include "../curlx/base64.h" -#include "../curlx/warnless.h" -#include "../curlx/multibyte.h" -#include "../sendf.h" +#include "../curl_trc.h" #include "../strerror.h" -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* * Curl_auth_is_spnego_supported() * @@ -66,7 +56,6 @@ bool Curl_auth_is_spnego_supported(void) Curl_pSecFn->FreeContextBuffer(SecurityPackage); } - return status == SEC_E_OK; } @@ -141,10 +130,10 @@ CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data, Curl_pSecFn->FreeContextBuffer(SecurityPackage); /* Allocate our output buffer */ - nego->output_token = malloc(nego->token_max); + nego->output_token = curlx_malloc(nego->token_max); if(!nego->output_token) return CURLE_OUT_OF_MEMORY; - } + } if(!nego->credentials) { /* Do we have credentials to use or are we using single sign-on? */ @@ -162,7 +151,7 @@ CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data, nego->p_identity = NULL; /* Allocate our credentials handle */ - nego->credentials = calloc(1, sizeof(CredHandle)); + nego->credentials = curlx_calloc(1, sizeof(CredHandle)); if(!nego->credentials) return CURLE_OUT_OF_MEMORY; @@ -176,7 +165,7 @@ CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data, return CURLE_AUTH_ERROR; /* Allocate our new context handle */ - nego->context = calloc(1, sizeof(CtxtHandle)); + nego->context = curlx_calloc(1, sizeof(CtxtHandle)); if(!nego->context) return CURLE_OUT_OF_MEMORY; } @@ -205,12 +194,12 @@ CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data, #ifdef SECPKG_ATTR_ENDPOINT_BINDINGS /* ssl context comes from Schannel. - * When extended protection is used in IIS server, - * we have to pass a second SecBuffer to the SecBufferDesc - * otherwise IIS will not pass the authentication (401 response). - * Minimum supported version is Windows 7. - * https://learn.microsoft.com/security-updates/SecurityAdvisories/2009/973811 - */ + * When extended protection is used in IIS server, + * we have to pass a second SecBuffer to the SecBufferDesc + * otherwise IIS will not pass the authentication (401 response). + * Minimum supported version is Windows 7. + * https://learn.microsoft.com/security-updates/SecurityAdvisories/2009/973811 + */ if(nego->sslContext) { SEC_CHANNEL_BINDINGS channelBindings; SecPkgContext_Bindings pkgBindings; @@ -249,7 +238,7 @@ CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data, &resp_desc, &attrs, NULL); /* Free the decoded challenge as it is not required anymore */ - free(chlg); + curlx_free(chlg); if(GSS_ERROR(nego->status)) { char buffer[STRERROR_LEN]; @@ -302,11 +291,11 @@ CURLcode Curl_auth_create_spnego_message(struct negotiatedata *nego, char **outptr, size_t *outlen) { /* Base64 encode the already generated response */ - CURLcode result = curlx_base64_encode((const char *)nego->output_token, + CURLcode result = curlx_base64_encode(nego->output_token, nego->output_token_length, outptr, outlen); if(!result && (!*outptr || !*outlen)) { - free(*outptr); + curlx_free(*outptr); result = CURLE_REMOTE_ACCESS_DENIED; } @@ -328,14 +317,14 @@ void Curl_auth_cleanup_spnego(struct negotiatedata *nego) /* Free our security context */ if(nego->context) { Curl_pSecFn->DeleteSecurityContext(nego->context); - free(nego->context); + curlx_free(nego->context); nego->context = NULL; } /* Free our credentials handle */ if(nego->credentials) { Curl_pSecFn->FreeCredentialsHandle(nego->credentials); - free(nego->credentials); + curlx_free(nego->credentials); nego->credentials = NULL; } diff --git a/vendor/hydra/vendor/curl/lib/vauth/vauth.c b/vendor/hydra/vendor/curl/lib/vauth/vauth.c index 6ee687dc..a74c2a1a 100644 --- a/vendor/hydra/vendor/curl/lib/vauth/vauth.c +++ b/vendor/hydra/vendor/curl/lib/vauth/vauth.c @@ -21,21 +21,12 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "../curl_setup.h" -#include - #include "vauth.h" -#include "../strdup.h" -#include "../urldata.h" #include "../curlx/multibyte.h" #include "../url.h" -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* * Curl_auth_build_spn() * @@ -76,7 +67,6 @@ TCHAR *Curl_auth_build_spn(const char *service, const char *host, { char *utf8_spn = NULL; TCHAR *tchar_spn = NULL; - TCHAR *dupe_tchar_spn = NULL; (void)realm; @@ -92,16 +82,11 @@ TCHAR *Curl_auth_build_spn(const char *service, const char *host, if(!utf8_spn) return NULL; - /* Allocate and return a TCHAR based SPN. Since curlx_convert_UTF8_to_tchar - must be freed by curlx_unicodefree we will dupe the result so that the - pointer this function returns can be normally free'd. */ + /* Allocate and return a TCHAR based SPN. */ tchar_spn = curlx_convert_UTF8_to_tchar(utf8_spn); - free(utf8_spn); - if(!tchar_spn) - return NULL; - dupe_tchar_spn = Curl_tcsdup(tchar_spn); - curlx_unicodefree(tchar_spn); - return dupe_tchar_spn; + curlx_free(utf8_spn); + + return tchar_spn; } #endif /* USE_WINDOWS_SSPI */ @@ -147,7 +132,7 @@ bool Curl_auth_user_contains_domain(const char *user) } /* - * Curl_auth_ollowed_to_host() tells if authentication, cookies or other + * Curl_auth_allowed_to_host() tells if authentication, cookies or other * "sensitive data" can (still) be sent to this host. */ bool Curl_auth_allowed_to_host(struct Curl_easy *data) @@ -170,18 +155,16 @@ static void ntlm_conn_dtor(void *key, size_t klen, void *entry) (void)klen; DEBUGASSERT(ntlm); Curl_auth_cleanup_ntlm(ntlm); - free(ntlm); + curlx_free(ntlm); } struct ntlmdata *Curl_auth_ntlm_get(struct connectdata *conn, bool proxy) { - const char *key = proxy ? CURL_META_NTLM_PROXY_CONN : - CURL_META_NTLM_CONN; + const char *key = proxy ? CURL_META_NTLM_PROXY_CONN : CURL_META_NTLM_CONN; struct ntlmdata *ntlm = Curl_conn_meta_get(conn, key); if(!ntlm) { - ntlm = calloc(1, sizeof(*ntlm)); - if(!ntlm || - Curl_conn_meta_set(conn, key, ntlm, ntlm_conn_dtor)) + ntlm = curlx_calloc(1, sizeof(*ntlm)); + if(!ntlm || Curl_conn_meta_set(conn, key, ntlm, ntlm_conn_dtor)) return NULL; } return ntlm; @@ -189,8 +172,8 @@ struct ntlmdata *Curl_auth_ntlm_get(struct connectdata *conn, bool proxy) void Curl_auth_ntlm_remove(struct connectdata *conn, bool proxy) { - Curl_conn_meta_remove(conn, proxy ? - CURL_META_NTLM_PROXY_CONN : CURL_META_NTLM_CONN); + Curl_conn_meta_remove(conn, proxy ? CURL_META_NTLM_PROXY_CONN + : CURL_META_NTLM_CONN); } #endif /* USE_NTLM */ @@ -204,14 +187,14 @@ static void krb5_conn_dtor(void *key, size_t klen, void *entry) (void)klen; DEBUGASSERT(krb5); Curl_auth_cleanup_gssapi(krb5); - free(krb5); + curlx_free(krb5); } struct kerberos5data *Curl_auth_krb5_get(struct connectdata *conn) { struct kerberos5data *krb5 = Curl_conn_meta_get(conn, CURL_META_KRB5_CONN); if(!krb5) { - krb5 = calloc(1, sizeof(*krb5)); + krb5 = curlx_calloc(1, sizeof(*krb5)); if(!krb5 || Curl_conn_meta_set(conn, CURL_META_KRB5_CONN, krb5, krb5_conn_dtor)) return NULL; @@ -230,14 +213,14 @@ static void gsasl_conn_dtor(void *key, size_t klen, void *entry) (void)klen; DEBUGASSERT(gsasl); Curl_auth_gsasl_cleanup(gsasl); - free(gsasl); + curlx_free(gsasl); } struct gsasldata *Curl_auth_gsasl_get(struct connectdata *conn) { struct gsasldata *gsasl = Curl_conn_meta_get(conn, CURL_META_GSASL_CONN); if(!gsasl) { - gsasl = calloc(1, sizeof(*gsasl)); + gsasl = curlx_calloc(1, sizeof(*gsasl)); if(!gsasl || Curl_conn_meta_set(conn, CURL_META_GSASL_CONN, gsasl, gsasl_conn_dtor)) return NULL; @@ -256,18 +239,16 @@ static void nego_conn_dtor(void *key, size_t klen, void *entry) (void)klen; DEBUGASSERT(nego); Curl_auth_cleanup_spnego(nego); - free(nego); + curlx_free(nego); } struct negotiatedata *Curl_auth_nego_get(struct connectdata *conn, bool proxy) { - const char *key = proxy ? CURL_META_NEGO_PROXY_CONN : - CURL_META_NEGO_CONN; + const char *key = proxy ? CURL_META_NEGO_PROXY_CONN : CURL_META_NEGO_CONN; struct negotiatedata *nego = Curl_conn_meta_get(conn, key); if(!nego) { - nego = calloc(1, sizeof(*nego)); - if(!nego || - Curl_conn_meta_set(conn, key, nego, nego_conn_dtor)) + nego = curlx_calloc(1, sizeof(*nego)); + if(!nego || Curl_conn_meta_set(conn, key, nego, nego_conn_dtor)) return NULL; } return nego; diff --git a/vendor/hydra/vendor/curl/lib/vauth/vauth.h b/vendor/hydra/vendor/curl/lib/vauth/vauth.h index 2ba8e471..312bd8da 100644 --- a/vendor/hydra/vendor/curl/lib/vauth/vauth.h +++ b/vendor/hydra/vendor/curl/lib/vauth/vauth.h @@ -23,11 +23,11 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - -#include +#include "../curl_setup.h" #include "../bufref.h" #include "../curlx/dynbuf.h" +#include "../urldata.h" struct Curl_easy; struct connectdata; @@ -233,14 +233,6 @@ CURLcode Curl_auth_create_xoauth_bearer_message(const char *user, #ifdef USE_KERBEROS5 -#ifdef HAVE_GSSAPI -# ifdef HAVE_GSSGNU -# include -# else -# include -# endif -#endif - /* meta key for storing KRB5 meta at connection */ #define CURL_META_KRB5_CONN "meta:auth:krb5:conn" @@ -306,7 +298,7 @@ struct negotiatedata { gss_ctx_id_t context; gss_name_t spn; gss_buffer_desc output_token; -#ifdef CURL_GSSAPI_HAS_CHANNEL_BINDING +#ifdef GSS_C_CHANNEL_BOUND_FLAG struct dynbuf channel_binding_data; #endif #else diff --git a/vendor/hydra/vendor/curl/lib/version.c b/vendor/hydra/vendor/curl/lib/version.c index 4c7e5712..697d9ea9 100644 --- a/vendor/hydra/vendor/curl/lib/version.c +++ b/vendor/hydra/vendor/curl/lib/version.c @@ -21,14 +21,12 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "curl_setup.h" #ifdef USE_NGHTTP2 #include #endif -#include #include "urldata.h" #include "vtls/vtls.h" #include "http2.h" @@ -77,16 +75,8 @@ #include #endif -#ifdef HAVE_GSSAPI -# ifdef HAVE_GSSGNU -# include -# else -# include -# endif -#endif - -#ifdef USE_OPENLDAP -#include +#ifndef CURL_DISABLE_LDAP +#include "curl_ldap.h" #endif #ifdef HAVE_BROTLI @@ -111,28 +101,6 @@ static void zstd_version(char *buf, size_t bufsz) } #endif -#ifdef USE_OPENLDAP -static void oldap_version(char *buf, size_t bufsz) -{ - LDAPAPIInfo api; - api.ldapai_info_version = LDAP_API_INFO_VERSION; - - if(ldap_get_option(NULL, LDAP_OPT_API_INFO, &api) == LDAP_OPT_SUCCESS) { - unsigned int patch = (unsigned int)(api.ldapai_vendor_version % 100); - unsigned int major = (unsigned int)(api.ldapai_vendor_version / 10000); - unsigned int minor = - (((unsigned int)api.ldapai_vendor_version - major * 10000) - - patch) / 100; - curl_msnprintf(buf, bufsz, "%s/%u.%u.%u", - api.ldapai_vendor_name, major, minor, patch); - ldap_memfree(api.ldapai_vendor_name); - ber_memvfree((void **)api.ldapai_extensions); - } - else - curl_msnprintf(buf, bufsz, "OpenLDAP"); -} -#endif - #ifdef USE_LIBPSL static void psl_version(char *buf, size_t bufsz) { @@ -219,7 +187,7 @@ char *curl_version(void) #ifdef HAVE_GSSAPI char gss_buf[40]; #endif -#ifdef USE_OPENLDAP +#ifndef CURL_DISABLE_LDAP char ldap_buf[30]; #endif int i = 0; @@ -297,8 +265,8 @@ char *curl_version(void) #endif src[i++] = gss_buf; #endif /* HAVE_GSSAPI */ -#ifdef USE_OPENLDAP - oldap_version(ldap_buf, sizeof(ldap_buf)); +#ifndef CURL_DISABLE_LDAP + Curl_ldap_version(ldap_buf, sizeof(ldap_buf)); src[i++] = ldap_buf; #endif @@ -365,8 +333,8 @@ static const char * const supported_protocols[] = { #ifndef CURL_DISABLE_LDAP "ldap", #if !defined(CURL_DISABLE_LDAPS) && \ - ((defined(USE_OPENLDAP) && defined(USE_SSL)) || \ - (!defined(USE_OPENLDAP) && defined(HAVE_LDAP_SSL))) + ((defined(USE_OPENLDAP) && defined(USE_SSL)) || \ + (!defined(USE_OPENLDAP) && defined(HAVE_LDAP_SSL))) "ldaps", #endif #endif @@ -468,7 +436,7 @@ static int ech_present(curl_version_info_data *info) * Use FEATURE() macro to define an entry: this allows documentation check. */ -#define FEATURE(name, present, bitmask) {(name), (present), (bitmask)} +#define FEATURE(name, present, bitmask) { (name), (present), (bitmask) } struct feat { const char *name; @@ -530,8 +498,7 @@ static const struct feat features_table[] = { #ifdef USE_KERBEROS5 FEATURE("Kerberos", NULL, CURL_VERSION_KERBEROS5), #endif -#if (SIZEOF_CURL_OFF_T > 4) && \ - ( (SIZEOF_OFF_T > 4) || defined(USE_WIN32_LARGE_FILES) ) +#if (SIZEOF_CURL_OFF_T > 4) && ((SIZEOF_OFF_T > 4) || defined(_WIN32)) FEATURE("Largefile", NULL, CURL_VERSION_LARGEFILE), #endif #ifdef HAVE_LIBZ @@ -582,9 +549,7 @@ static const struct feat features_table[] = { {NULL, NULL, 0} }; -static const char *feature_names[sizeof(features_table) / - sizeof(features_table[0])] = {NULL}; - +static const char *feature_names[CURL_ARRAYSIZE(features_table)] = { NULL }; static curl_version_info_data version_info = { CURLVERSION_NOW, diff --git a/vendor/hydra/vendor/curl/lib/vquic/curl_ngtcp2.c b/vendor/hydra/vendor/curl/lib/vquic/curl_ngtcp2.c index f72f6630..97ef98b9 100644 --- a/vendor/hydra/vendor/curl/lib/vquic/curl_ngtcp2.c +++ b/vendor/hydra/vendor/curl/lib/vquic/curl_ngtcp2.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "../curl_setup.h" #if !defined(CURL_DISABLE_HTTP) && defined(USE_NGTCP2) && defined(USE_NGHTTP3) @@ -49,7 +48,7 @@ #include "../urldata.h" #include "../url.h" #include "../uint-hash.h" -#include "../sendf.h" +#include "../curl_trc.h" #include "../rand.h" #include "../multiif.h" #include "../cfilters.h" @@ -59,8 +58,8 @@ #include "../curlx/dynbuf.h" #include "../http1.h" #include "../select.h" -#include "../curlx/inet_pton.h" #include "../transfer.h" +#include "../bufref.h" #include "vquic.h" #include "vquic_int.h" #include "vquic-tls.h" @@ -69,22 +68,18 @@ #include "../vtls/vtls_scache.h" #include "curl_ngtcp2.h" -#include "../curlx/warnless.h" - -/* The last 2 #include files should be in this order */ -#include "../curl_memory.h" -#include "../memdebug.h" +#define QUIC_MAX_STREAMS (256 * 1024) +#define QUIC_HANDSHAKE_TIMEOUT (10 * NGTCP2_SECONDS) -#define QUIC_MAX_STREAMS (256*1024) -#define QUIC_HANDSHAKE_TIMEOUT (10*NGTCP2_SECONDS) +/* We announce a small window size in transport param to the server, + * and grow that immediately to max when no rate limit is in place. + * We need to start small as we are not able to decrease it. */ +#define H3_STREAM_WINDOW_SIZE_INITIAL (32 * 1024) +#define H3_STREAM_WINDOW_SIZE_MAX (10 * 1024 * 1024) +#define H3_CONN_WINDOW_SIZE_MAX (100 * H3_STREAM_WINDOW_SIZE_MAX) -/* A stream window is the maximum amount we need to buffer for - * each active transfer. We use HTTP/3 flow control and only ACK - * when we take things out of the buffer. - * Chunk size is large enough to take a full DATA frame */ -#define H3_STREAM_WINDOW_SIZE (128 * 1024) -#define H3_STREAM_CHUNK_SIZE (16 * 1024) +#define H3_STREAM_CHUNK_SIZE (64 * 1024) #if H3_STREAM_CHUNK_SIZE < NGTCP2_MAX_UDP_PAYLOAD_SIZE #error H3_STREAM_CHUNK_SIZE smaller than NGTCP2_MAX_UDP_PAYLOAD_SIZE #endif @@ -94,13 +89,11 @@ * The benefit of the pool is that stream buffer to not keep * spares. Memory consumption goes down when streams run empty, * have a large upload done, etc. */ -#define H3_STREAM_POOL_SPARES \ - (H3_STREAM_WINDOW_SIZE / H3_STREAM_CHUNK_SIZE ) / 2 -/* Receive and Send max number of chunks just follows from the - * chunk size and window size */ +#define H3_STREAM_POOL_SPARES 2 +/* The max amount of un-acked upload data we keep around per stream */ +#define H3_STREAM_SEND_BUFFER_MAX (10 * 1024 * 1024) #define H3_STREAM_SEND_CHUNKS \ - (H3_STREAM_WINDOW_SIZE / H3_STREAM_CHUNK_SIZE) - + (H3_STREAM_SEND_BUFFER_MAX / H3_STREAM_CHUNK_SIZE) /* * Store ngtcp2 version info in this buffer. @@ -137,7 +130,6 @@ struct cf_ngtcp2_ctx { struct bufc_pool stream_bufcp; /* chunk pool for streams */ struct dynbuf scratch; /* temp buffer for header construction */ struct uint_hash streams; /* hash `data->mid` to `h3_stream_ctx` */ - size_t max_stream_window; /* max flow window for one stream */ uint64_t used_bidi_streams; /* bidi streams we have opened */ uint64_t max_bidi_streams; /* max bidi streams we can open */ size_t earlydata_max; /* max amount of early data supported by @@ -155,8 +147,7 @@ struct cf_ngtcp2_ctx { /* How to access `call_data` from a cf_ngtcp2 filter */ #undef CF_CTX_CALL_DATA -#define CF_CTX_CALL_DATA(cf) \ - ((struct cf_ngtcp2_ctx *)(cf)->ctx)->call_data +#define CF_CTX_CALL_DATA(cf) ((struct cf_ngtcp2_ctx *)(cf)->ctx)->call_data static void h3_stream_hash_free(unsigned int id, void *stream); @@ -165,11 +156,10 @@ static void cf_ngtcp2_ctx_init(struct cf_ngtcp2_ctx *ctx) DEBUGASSERT(!ctx->initialized); ctx->qlogfd = -1; ctx->version = NGTCP2_PROTO_VER_MAX; - ctx->max_stream_window = H3_STREAM_WINDOW_SIZE; Curl_bufcp_init(&ctx->stream_bufcp, H3_STREAM_CHUNK_SIZE, H3_STREAM_POOL_SPARES); curlx_dyn_init(&ctx->scratch, CURL_MAX_HTTP_HEADER); - Curl_uint_hash_init(&ctx->streams, 63, h3_stream_hash_free); + Curl_uint32_hash_init(&ctx->streams, 63, h3_stream_hash_free); ctx->initialized = TRUE; } @@ -180,10 +170,10 @@ static void cf_ngtcp2_ctx_free(struct cf_ngtcp2_ctx *ctx) vquic_ctx_free(&ctx->q); Curl_bufcp_free(&ctx->stream_bufcp); curlx_dyn_free(&ctx->scratch); - Curl_uint_hash_destroy(&ctx->streams); + Curl_uint32_hash_destroy(&ctx->streams); Curl_ssl_peer_cleanup(&ctx->peer); } - free(ctx); + curlx_free(ctx); } static void cf_ngtcp2_setup_keep_alive(struct Curl_cfilter *cf, @@ -192,14 +182,14 @@ static void cf_ngtcp2_setup_keep_alive(struct Curl_cfilter *cf, struct cf_ngtcp2_ctx *ctx = cf->ctx; const ngtcp2_transport_params *rp; /* Peer should have sent us its transport parameters. If it - * announces a positive `max_idle_timeout` it will close the - * connection when it does not hear from us for that time. - * - * Some servers use this as a keep-alive timer at a rather low - * value. We are doing HTTP/3 here and waiting for the response - * to a request may take a considerable amount of time. We need - * to prevent the peer's QUIC stack from closing in this case. - */ + * announces a positive `max_idle_timeout` it will close the + * connection when it does not hear from us for that time. + * + * Some servers use this as a keep-alive timer at a rather low + * value. We are doing HTTP/3 here and waiting for the response + * to a request may take a considerable amount of time. We need + * to prevent the peer's QUIC stack from closing in this case. + */ if(!ctx->qconn) return; @@ -208,7 +198,7 @@ static void cf_ngtcp2_setup_keep_alive(struct Curl_cfilter *cf, ngtcp2_conn_set_keep_alive_timeout(ctx->qconn, UINT64_MAX); CURL_TRC_CF(data, cf, "no peer idle timeout, unset keep-alive"); } - else if(!Curl_uint_hash_count(&ctx->streams)) { + else if(!Curl_uint32_hash_count(&ctx->streams)) { ngtcp2_conn_set_keep_alive_timeout(ctx->qconn, UINT64_MAX); CURL_TRC_CF(data, cf, "no active streams, unset keep-alive"); } @@ -216,14 +206,13 @@ static void cf_ngtcp2_setup_keep_alive(struct Curl_cfilter *cf, ngtcp2_duration keep_ns; keep_ns = (rp->max_idle_timeout > 1) ? (rp->max_idle_timeout / 2) : 1; ngtcp2_conn_set_keep_alive_timeout(ctx->qconn, keep_ns); - CURL_TRC_CF(data, cf, "peer idle timeout is %" FMT_PRIu64 "ms, " - "set keep-alive to %" FMT_PRIu64 " ms.", - (curl_uint64_t)(rp->max_idle_timeout / NGTCP2_MILLISECONDS), - (curl_uint64_t)(keep_ns / NGTCP2_MILLISECONDS)); + CURL_TRC_CF(data, cf, "peer idle timeout is %" PRIu64 "ms, " + "set keep-alive to %" PRIu64 " ms.", + (rp->max_idle_timeout / NGTCP2_MILLISECONDS), + (keep_ns / NGTCP2_MILLISECONDS)); } } - struct pkt_io_ctx; static CURLcode cf_progress_ingress(struct Curl_cfilter *cf, struct Curl_easy *data, @@ -236,26 +225,28 @@ static CURLcode cf_progress_egress(struct Curl_cfilter *cf, * All about the H3 internals of a stream */ struct h3_stream_ctx { - curl_int64_t id; /* HTTP/3 protocol identifier */ - struct bufq sendbuf; /* h3 request body */ - struct h1_req_parser h1; /* h1 request parsing */ + int64_t id; /* HTTP/3 protocol identifier */ + struct bufq sendbuf; /* h3 request body */ + struct h1_req_parser h1; /* h1 request parsing */ size_t sendbuf_len_in_flight; /* sendbuf amount "in flight" */ - curl_uint64_t error3; /* HTTP/3 stream error code */ - curl_off_t upload_left; /* number of request bytes left to upload */ - int status_code; /* HTTP status code */ - CURLcode xfer_result; /* result from xfer_resp_write(_hd) */ - BIT(resp_hds_complete); /* we have a complete, final response */ - BIT(closed); /* TRUE on stream close */ - BIT(reset); /* TRUE on stream reset */ - BIT(send_closed); /* stream is local closed */ - BIT(quic_flow_blocked); /* stream is blocked by QUIC flow control */ + uint64_t error3; /* HTTP/3 stream error code */ + curl_off_t upload_left; /* number of request bytes left to upload */ + uint64_t download_unacked; /* bytes not acknowledged yet */ + uint64_t window_size_max; /* max flow control window set for stream */ + int status_code; /* HTTP status code */ + CURLcode xfer_result; /* result from xfer_resp_write(_hd) */ + BIT(resp_hds_complete); /* we have a complete, final response */ + BIT(closed); /* TRUE on stream close */ + BIT(reset); /* TRUE on stream reset */ + BIT(send_closed); /* stream is local closed */ + BIT(quic_flow_blocked); /* stream is blocked by QUIC flow control */ }; static void h3_stream_ctx_free(struct h3_stream_ctx *stream) { Curl_bufq_free(&stream->sendbuf); Curl_h1_req_parse_free(&stream->h1); - free(stream); + curlx_free(stream); } static void h3_stream_hash_free(unsigned int id, void *stream) @@ -277,7 +268,7 @@ static CURLcode h3_data_setup(struct Curl_cfilter *cf, if(stream) return CURLE_OK; - stream = calloc(1, sizeof(*stream)); + stream = curlx_calloc(1, sizeof(*stream)); if(!stream) return CURLE_OUT_OF_MEMORY; @@ -286,14 +277,15 @@ static CURLcode h3_data_setup(struct Curl_cfilter *cf, Curl_bufq_initp(&stream->sendbuf, &ctx->stream_bufcp, H3_STREAM_SEND_CHUNKS, BUFQ_OPT_NONE); stream->sendbuf_len_in_flight = 0; + stream->window_size_max = H3_STREAM_WINDOW_SIZE_INITIAL; Curl_h1_req_parse_init(&stream->h1, H1_PARSE_DEFAULT_MAX_LINE_LEN); - if(!Curl_uint_hash_set(&ctx->streams, data->mid, stream)) { + if(!Curl_uint32_hash_set(&ctx->streams, data->mid, stream)) { h3_stream_ctx_free(stream); return CURLE_OUT_OF_MEMORY; } - if(Curl_uint_hash_count(&ctx->streams) == 1) + if(Curl_uint32_hash_count(&ctx->streams) == 1) cf_ngtcp2_setup_keep_alive(cf, data); return CURLE_OK; @@ -301,12 +293,12 @@ static CURLcode h3_data_setup(struct Curl_cfilter *cf, #if NGTCP2_VERSION_NUM < 0x011100 struct cf_ngtcp2_sfind_ctx { - curl_int64_t stream_id; + int64_t stream_id; struct h3_stream_ctx *stream; - unsigned int mid; + uint32_t mid; }; -static bool cf_ngtcp2_sfind(unsigned int mid, void *value, void *user_data) +static bool cf_ngtcp2_sfind(uint32_t mid, void *value, void *user_data) { struct cf_ngtcp2_sfind_ctx *fctx = user_data; struct h3_stream_ctx *stream = value; @@ -319,18 +311,18 @@ static bool cf_ngtcp2_sfind(unsigned int mid, void *value, void *user_data) return TRUE; /* continue */ } -static struct h3_stream_ctx * -cf_ngtcp2_get_stream(struct cf_ngtcp2_ctx *ctx, curl_int64_t stream_id) +static struct h3_stream_ctx *cf_ngtcp2_get_stream(struct cf_ngtcp2_ctx *ctx, + int64_t stream_id) { struct cf_ngtcp2_sfind_ctx fctx; fctx.stream_id = stream_id; fctx.stream = NULL; - Curl_uint_hash_visit(&ctx->streams, cf_ngtcp2_sfind, &fctx); + Curl_uint32_hash_visit(&ctx->streams, cf_ngtcp2_sfind, &fctx); return fctx.stream; } #else static struct h3_stream_ctx *cf_ngtcp2_get_stream(struct cf_ngtcp2_ctx *ctx, - curl_int64_t stream_id) + int64_t stream_id) { struct Curl_easy *data = ngtcp2_conn_get_stream_user_data(ctx->qconn, stream_id); @@ -360,7 +352,7 @@ static void cf_ngtcp2_stream_close(struct Curl_cfilter *cf, NGHTTP3_H3_REQUEST_CANCELLED); result = cf_progress_egress(cf, data, NULL); if(result) - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] cancel stream -> %d", + CURL_TRC_CF(data, cf, "[%" PRId64 "] cancel stream -> %d", stream->id, result); } } @@ -371,11 +363,10 @@ static void h3_data_done(struct Curl_cfilter *cf, struct Curl_easy *data) struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); (void)cf; if(stream) { - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] easy handle is done", - stream->id); + CURL_TRC_CF(data, cf, "[%" PRId64 "] easy handle is done", stream->id); cf_ngtcp2_stream_close(cf, data, stream); - Curl_uint_hash_remove(&ctx->streams, data->mid); - if(!Curl_uint_hash_count(&ctx->streams)) + Curl_uint32_hash_remove(&ctx->streams, data->mid); + if(!Curl_uint32_hash_count(&ctx->streams)) cf_ngtcp2_setup_keep_alive(cf, data); } } @@ -391,24 +382,31 @@ struct pkt_io_ctx { ngtcp2_path_storage ps; }; -static void pktx_update_time(struct pkt_io_ctx *pktx, +static void pktx_update_time(struct Curl_easy *data, + struct pkt_io_ctx *pktx, struct Curl_cfilter *cf) { struct cf_ngtcp2_ctx *ctx = cf->ctx; + const struct curltime *pnow = Curl_pgrs_now(data); - vquic_ctx_update_time(&ctx->q); - pktx->ts = (ngtcp2_tstamp)ctx->q.last_op.tv_sec * NGTCP2_SECONDS + - (ngtcp2_tstamp)ctx->q.last_op.tv_usec * NGTCP2_MICROSECONDS; + vquic_ctx_update_time(&ctx->q, pnow); + pktx->ts = (ngtcp2_tstamp)pnow->tv_sec * NGTCP2_SECONDS + + (ngtcp2_tstamp)pnow->tv_usec * NGTCP2_MICROSECONDS; } static void pktx_init(struct pkt_io_ctx *pktx, struct Curl_cfilter *cf, struct Curl_easy *data) { + struct cf_ngtcp2_ctx *ctx = cf->ctx; + const struct curltime *pnow = Curl_pgrs_now(data); + pktx->cf = cf; pktx->data = data; ngtcp2_path_storage_zero(&pktx->ps); - pktx_update_time(pktx, cf); + vquic_ctx_set_time(&ctx->q, pnow); + pktx->ts = (ngtcp2_tstamp)pnow->tv_sec * NGTCP2_SECONDS + + (ngtcp2_tstamp)pnow->tv_usec * NGTCP2_MICROSECONDS; } static int cb_h3_acked_req_body(nghttp3_conn *conn, int64_t stream_id, @@ -471,18 +469,18 @@ static void quic_settings(struct cf_ngtcp2_ctx *ctx, s->initial_ts = pktx->ts; s->handshake_timeout = (data->set.connecttimeout > 0) ? data->set.connecttimeout * NGTCP2_MILLISECONDS : QUIC_HANDSHAKE_TIMEOUT; - s->max_window = 100 * ctx->max_stream_window; - s->max_stream_window = 10 * ctx->max_stream_window; + s->max_window = H3_CONN_WINDOW_SIZE_MAX; + s->max_stream_window = 0; /* disable ngtcp2 auto-tuning of window */ s->no_pmtud = FALSE; #ifdef NGTCP2_SETTINGS_V3 /* try ten times the ngtcp2 defaults here for problems with Caddy */ s->glitch_ratelim_burst = 1000 * 10; s->glitch_ratelim_rate = 33 * 10; #endif - t->initial_max_data = 10 * ctx->max_stream_window; - t->initial_max_stream_data_bidi_local = ctx->max_stream_window; - t->initial_max_stream_data_bidi_remote = ctx->max_stream_window; - t->initial_max_stream_data_uni = ctx->max_stream_window; + t->initial_max_data = s->max_window; + t->initial_max_stream_data_bidi_local = H3_STREAM_WINDOW_SIZE_INITIAL; + t->initial_max_stream_data_bidi_remote = H3_STREAM_WINDOW_SIZE_INITIAL; + t->initial_max_stream_data_uni = t->initial_max_data; t->initial_max_streams_bidi = QUIC_MAX_STREAMS; t->initial_max_streams_uni = QUIC_MAX_STREAMS; t->max_idle_timeout = 0; /* no idle timeout from our side */ @@ -507,7 +505,7 @@ static int cf_ngtcp2_handshake_completed(ngtcp2_conn *tconn, void *user_data) if(!ctx || !data) return NGHTTP3_ERR_CALLBACK_FAILURE; - ctx->handshake_at = curlx_now(); + ctx->handshake_at = *Curl_pgrs_now(data); ctx->tls_handshake_complete = TRUE; Curl_vquic_report_handshake(&ctx->tls, cf, data); @@ -517,13 +515,12 @@ static int cf_ngtcp2_handshake_completed(ngtcp2_conn *tconn, void *user_data) if(Curl_trc_is_verbose(data)) { const ngtcp2_transport_params *rp; rp = ngtcp2_conn_get_remote_transport_params(ctx->qconn); - CURL_TRC_CF(data, cf, "handshake complete after %dms, remote transport[" - "max_udp_payload=%" FMT_PRIu64 - ", initial_max_data=%" FMT_PRIu64 + CURL_TRC_CF(data, cf, "handshake complete after %" FMT_TIMEDIFF_T + "ms, remote transport[max_udp_payload=%" PRIu64 + ", initial_max_data=%" PRIu64 "]", - (int)curlx_timediff(ctx->handshake_at, ctx->started_at), - (curl_uint64_t)rp->max_udp_payload_size, - (curl_uint64_t)rp->initial_max_data); + curlx_ptimediff_ms(&ctx->handshake_at, &ctx->started_at), + rp->max_udp_payload_size, rp->initial_max_data); } #endif @@ -607,13 +604,12 @@ static void cf_ngtcp2_h3_err_set(struct Curl_cfilter *cf, } static int cb_recv_stream_data(ngtcp2_conn *tconn, uint32_t flags, - int64_t sid, uint64_t offset, + int64_t stream_id, uint64_t offset, const uint8_t *buf, size_t buflen, void *user_data, void *stream_user_data) { struct Curl_cfilter *cf = user_data; struct cf_ngtcp2_ctx *ctx = cf->ctx; - curl_int64_t stream_id = (curl_int64_t)sid; nghttp3_ssize nconsumed; int fin = (flags & NGTCP2_STREAM_DATA_FLAG_FIN) ? 1 : 0; struct Curl_easy *data = stream_user_data; @@ -625,12 +621,12 @@ static int cb_recv_stream_data(ngtcp2_conn *tconn, uint32_t flags, if(!data) data = CF_DATA_CURRENT(cf); if(data) - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] read_stream(len=%zu) -> %zd", + CURL_TRC_CF(data, cf, "[%" PRId64 "] read_stream(len=%zu) -> %zd", stream_id, buflen, nconsumed); if(nconsumed < 0) { struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); if(data && stream) { - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] error on known stream, " + CURL_TRC_CF(data, cf, "[%" PRId64 "] error on known stream, " "reset=%d, closed=%d", stream_id, stream->reset, stream->closed); } @@ -646,10 +642,9 @@ static int cb_recv_stream_data(ngtcp2_conn *tconn, uint32_t flags, return 0; } -static int -cb_acked_stream_data_offset(ngtcp2_conn *tconn, int64_t stream_id, - uint64_t offset, uint64_t datalen, void *user_data, - void *stream_user_data) +static int cb_acked_stream_data_offset(ngtcp2_conn *tconn, int64_t stream_id, + uint64_t offset, uint64_t datalen, + void *user_data, void *stream_user_data) { struct Curl_cfilter *cf = user_data; struct cf_ngtcp2_ctx *ctx = cf->ctx; @@ -669,13 +664,12 @@ cb_acked_stream_data_offset(ngtcp2_conn *tconn, int64_t stream_id, } static int cb_stream_close(ngtcp2_conn *tconn, uint32_t flags, - int64_t sid, uint64_t app_error_code, + int64_t stream_id, uint64_t app_error_code, void *user_data, void *stream_user_data) { struct Curl_cfilter *cf = user_data; struct cf_ngtcp2_ctx *ctx = cf->ctx; struct Curl_easy *data = stream_user_data; - curl_int64_t stream_id = (curl_int64_t)sid; int rv; (void)tconn; @@ -690,9 +684,8 @@ static int cb_stream_close(ngtcp2_conn *tconn, uint32_t flags, } rv = nghttp3_conn_close_stream(ctx->h3conn, stream_id, app_error_code); - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] quic close(app_error=%" - FMT_PRIu64 ") -> %d", stream_id, (curl_uint64_t)app_error_code, - rv); + CURL_TRC_CF(data, cf, "[%" PRId64 "] quic close(app_error=%" + PRIu64 ") -> %d", stream_id, app_error_code, rv); if(rv && rv != NGHTTP3_ERR_STREAM_NOT_FOUND) { cf_ngtcp2_h3_err_set(cf, data, rv); return NGTCP2_ERR_CALLBACK_FAILURE; @@ -701,13 +694,12 @@ static int cb_stream_close(ngtcp2_conn *tconn, uint32_t flags, return 0; } -static int cb_stream_reset(ngtcp2_conn *tconn, int64_t sid, +static int cb_stream_reset(ngtcp2_conn *tconn, int64_t stream_id, uint64_t final_size, uint64_t app_error_code, void *user_data, void *stream_user_data) { struct Curl_cfilter *cf = user_data; struct cf_ngtcp2_ctx *ctx = cf->ctx; - curl_int64_t stream_id = (curl_int64_t)sid; struct Curl_easy *data = stream_user_data; int rv; (void)tconn; @@ -716,7 +708,7 @@ static int cb_stream_reset(ngtcp2_conn *tconn, int64_t sid, (void)data; rv = nghttp3_conn_shutdown_stream_read(ctx->h3conn, stream_id); - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] reset -> %d", stream_id, rv); + CURL_TRC_CF(data, cf, "[%" PRId64 "] reset -> %d", stream_id, rv); if(rv && rv != NGHTTP3_ERR_STREAM_NOT_FOUND) { return NGTCP2_ERR_CALLBACK_FAILURE; } @@ -754,9 +746,8 @@ static int cb_extend_max_local_streams_bidi(ngtcp2_conn *tconn, (void)tconn; ctx->max_bidi_streams = max_streams; if(data) - CURL_TRC_CF(data, cf, "max bidi streams now %" FMT_PRIu64 - ", used %" FMT_PRIu64, (curl_uint64_t)ctx->max_bidi_streams, - (curl_uint64_t)ctx->used_bidi_streams); + CURL_TRC_CF(data, cf, "max bidi streams now %" PRIu64 ", used %" PRIu64, + ctx->max_bidi_streams, ctx->used_bidi_streams); return 0; } @@ -778,8 +769,7 @@ static int cb_extend_max_stream_data(ngtcp2_conn *tconn, int64_t stream_id, } stream = H3_STREAM_CTX(ctx, s_data); if(stream && stream->quic_flow_blocked) { - CURL_TRC_CF(s_data, cf, "[%" FMT_PRId64 "] unblock quic flow", - (curl_int64_t)stream_id); + CURL_TRC_CF(s_data, cf, "[%" PRId64 "] unblock quic flow", stream_id); stream->quic_flow_blocked = FALSE; Curl_multi_mark_dirty(s_data); } @@ -841,8 +831,8 @@ static int cb_recv_rx_key(ngtcp2_conn *tconn, ngtcp2_encryption_level level, } #if defined(_MSC_VER) && defined(_DLL) -# pragma warning(push) -# pragma warning(disable:4232) /* MSVC extension, dllimport identity */ +#pragma warning(push) +#pragma warning(disable:4232) /* MSVC extension, dllimport identity */ #endif static ngtcp2_callbacks ng_callbacks = { @@ -886,13 +876,13 @@ static ngtcp2_callbacks ng_callbacks = { cb_recv_rx_key, NULL, /* recv_tx_key */ NULL, /* early_data_rejected */ -#ifdef NGTCP2_CALLBACKS_V2 +#ifdef NGTCP2_CALLBACKS_V2 /* ngtcp2 v1.14.0+ */ NULL, /* begin_path_validation */ #endif }; #if defined(_MSC_VER) && defined(_DLL) -# pragma warning(pop) +#pragma warning(pop) #endif /** @@ -915,7 +905,7 @@ static CURLcode check_and_set_expiry(struct Curl_cfilter *cf, pktx = &local_pktx; } else { - pktx_update_time(pktx, cf); + pktx_update_time(data, pktx, cf); } expiry = ngtcp2_conn_get_expiry(ctx->qconn); @@ -973,7 +963,7 @@ static CURLcode cf_ngtcp2_adjust_pollset(struct Curl_cfilter *cf, CF_DATA_SAVE(save, cf, data); c_exhaust = want_send && (!ngtcp2_conn_get_cwnd_left(ctx->qconn) || - !ngtcp2_conn_get_max_data_left(ctx->qconn)); + !ngtcp2_conn_get_max_data_left(ctx->qconn)); s_exhaust = want_send && stream && stream->id >= 0 && stream->quic_flow_blocked; want_recv = (want_recv || c_exhaust || s_exhaust); @@ -986,14 +976,13 @@ static CURLcode cf_ngtcp2_adjust_pollset(struct Curl_cfilter *cf, return result; } -static int cb_h3_stream_close(nghttp3_conn *conn, int64_t sid, +static int cb_h3_stream_close(nghttp3_conn *conn, int64_t stream_id, uint64_t app_error_code, void *user_data, void *stream_user_data) { struct Curl_cfilter *cf = user_data; struct cf_ngtcp2_ctx *ctx = cf->ctx; struct Curl_easy *data = stream_user_data; - curl_int64_t stream_id = (curl_int64_t)sid; struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); (void)conn; (void)stream_id; @@ -1003,15 +992,15 @@ static int cb_h3_stream_close(nghttp3_conn *conn, int64_t sid, return 0; stream->closed = TRUE; - stream->error3 = (curl_uint64_t)app_error_code; + stream->error3 = app_error_code; if(stream->error3 != NGHTTP3_H3_NO_ERROR) { stream->reset = TRUE; stream->send_closed = TRUE; - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] RESET: error %" FMT_PRIu64, + CURL_TRC_CF(data, cf, "[%" PRId64 "] RESET: error %" PRIu64, stream->id, stream->error3); } else { - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] CLOSED", stream->id); + CURL_TRC_CF(data, cf, "[%" PRId64 "] CLOSED", stream->id); } Curl_multi_mark_dirty(data); return 0; @@ -1031,7 +1020,7 @@ static void h3_xfer_write_resp_hd(struct Curl_cfilter *cf, if(!stream->xfer_result) { stream->xfer_result = Curl_xfer_write_resp_hd(data, buf, blen, eos); if(stream->xfer_result) - CURL_TRC_CF(data, cf, "[%"FMT_PRId64"] error %d writing %zu " + CURL_TRC_CF(data, cf, "[%" PRId64 "] error %d writing %zu " "bytes of headers", stream->id, stream->xfer_result, blen); } } @@ -1051,12 +1040,65 @@ static void h3_xfer_write_resp(struct Curl_cfilter *cf, stream->xfer_result = Curl_xfer_write_resp(data, buf, blen, eos); /* If the transfer write is errored, we do not want any more data */ if(stream->xfer_result) { - CURL_TRC_CF(data, cf, "[%"FMT_PRId64"] error %d writing %zu bytes " - "of data", stream->id, stream->xfer_result, blen); + CURL_TRC_CF(data, cf, "[%" PRId64 "] error %d writing %zu bytes of data", + stream->id, stream->xfer_result, blen); + } + } +} + +static void cf_ngtcp2_stream_update_window(struct Curl_cfilter *cf, + struct Curl_easy *data, + struct h3_stream_ctx *stream) +{ + /* stream receive max window size for flow control. We can only + * grow it from the initial window size */ + uint64_t swin_max = data->progress.dl.rlimit.rate_per_step ? + data->progress.dl.rlimit.rate_per_step : H3_STREAM_WINDOW_SIZE_MAX; + if(swin_max > stream->window_size_max) { + struct cf_ngtcp2_ctx *ctx = cf->ctx; + int rc = ngtcp2_conn_extend_max_stream_offset(ctx->qconn, stream->id, + swin_max - stream->window_size_max); + if(rc) { + CURL_TRC_CF(data, cf, "[%" PRId64 "] extend_max_stream_offset to %" + PRIu64 " -> %s (%d)", + stream->id, swin_max, ngtcp2_strerror(rc), rc); + DEBUGASSERT(0); } + stream->window_size_max = swin_max; } } +static void cf_ngtcp2_ack_stream(struct Curl_cfilter *cf, + struct Curl_easy *data, + struct h3_stream_ctx *stream) +{ + struct cf_ngtcp2_ctx *ctx = cf->ctx; + curl_off_t avail; + uint64_t ack_len = 0; + + /* How many byte to ack on the stream? */ + + /* how much does rate limiting allow us to acknowledge? */ + avail = Curl_rlimit_avail(&data->progress.dl.rlimit, + Curl_pgrs_now(data)); + if(avail == CURL_OFF_T_MAX) { /* no rate limit, ack all */ + ack_len = stream->download_unacked; + } + else if(avail > 0) { + ack_len = CURLMIN(stream->download_unacked, (uint64_t)avail); + } + + if(ack_len) { + CURL_TRC_CF(data, cf, "[%" PRId64 "] ACK %" PRIu64 + "/%" PRIu64 " bytes of DATA", stream->id, + ack_len, stream->download_unacked); + ngtcp2_conn_extend_max_stream_offset(ctx->qconn, stream->id, ack_len); + stream->download_unacked -= ack_len; + } + + cf_ngtcp2_stream_update_window(cf, data, stream); +} + static int cb_h3_recv_data(nghttp3_conn *conn, int64_t stream3_id, const uint8_t *buf, size_t blen, void *user_data, void *stream_user_data) @@ -1073,13 +1115,15 @@ static int cb_h3_recv_data(nghttp3_conn *conn, int64_t stream3_id, return NGHTTP3_ERR_CALLBACK_FAILURE; h3_xfer_write_resp(cf, data, stream, (const char *)buf, blen, FALSE); - if(blen) { - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] ACK %zu bytes of DATA", - stream->id, blen); - ngtcp2_conn_extend_max_stream_offset(ctx->qconn, stream->id, blen); - ngtcp2_conn_extend_max_offset(ctx->qconn, blen); - } - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] DATA len=%zu", stream->id, blen); + CURL_TRC_CF(data, cf, "[%" PRId64 "] DATA len=%zu", stream->id, blen); + + ngtcp2_conn_extend_max_offset(ctx->qconn, blen); + if(UINT64_MAX - blen < stream->download_unacked) + stream->download_unacked = UINT64_MAX; /* unlikely */ + else + stream->download_unacked += blen; + + cf_ngtcp2_ack_stream(cf, data, stream); return 0; } @@ -1099,13 +1143,12 @@ static int cb_h3_deferred_consume(nghttp3_conn *conn, int64_t stream3_id, return 0; } -static int cb_h3_end_headers(nghttp3_conn *conn, int64_t sid, +static int cb_h3_end_headers(nghttp3_conn *conn, int64_t stream_id, int fin, void *user_data, void *stream_user_data) { struct Curl_cfilter *cf = user_data; struct cf_ngtcp2_ctx *ctx = cf->ctx; struct Curl_easy *data = stream_user_data; - curl_int64_t stream_id = (curl_int64_t)sid; struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); (void)conn; (void)stream_id; @@ -1117,7 +1160,7 @@ static int cb_h3_end_headers(nghttp3_conn *conn, int64_t sid, /* add a CRLF only if we have received some headers */ h3_xfer_write_resp_hd(cf, data, stream, STRCONST("\r\n"), stream->closed); - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] end_headers, status=%d", + CURL_TRC_CF(data, cf, "[%" PRId64 "] end_headers, status=%d", stream_id, stream->status_code); if(stream->status_code / 100 != 1) { stream->resp_hds_complete = TRUE; @@ -1126,14 +1169,13 @@ static int cb_h3_end_headers(nghttp3_conn *conn, int64_t sid, return 0; } -static int cb_h3_recv_header(nghttp3_conn *conn, int64_t sid, +static int cb_h3_recv_header(nghttp3_conn *conn, int64_t stream_id, int32_t token, nghttp3_rcbuf *name, nghttp3_rcbuf *value, uint8_t flags, void *user_data, void *stream_user_data) { struct Curl_cfilter *cf = user_data; struct cf_ngtcp2_ctx *ctx = cf->ctx; - curl_int64_t stream_id = (curl_int64_t)sid; nghttp3_vec h3name = nghttp3_rcbuf_get_buf(name); nghttp3_vec h3val = nghttp3_rcbuf_get_buf(value); struct Curl_easy *data = stream_user_data; @@ -1165,7 +1207,7 @@ static int cb_h3_recv_header(nghttp3_conn *conn, int64_t sid, if(!result) h3_xfer_write_resp_hd(cf, data, stream, curlx_dyn_ptr(&ctx->scratch), curlx_dyn_len(&ctx->scratch), FALSE); - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] status: %s", + CURL_TRC_CF(data, cf, "[%" PRId64 "] status: %s", stream_id, curlx_dyn_ptr(&ctx->scratch)); if(result) { return NGHTTP3_ERR_CALLBACK_FAILURE; @@ -1173,7 +1215,7 @@ static int cb_h3_recv_header(nghttp3_conn *conn, int64_t sid, } else { /* store as an HTTP1-style header */ - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] header: %.*s: %.*s", + CURL_TRC_CF(data, cf, "[%" PRId64 "] header: %.*s: %.*s", stream_id, (int)h3name.len, h3name.base, (int)h3val.len, h3val.base); curlx_dyn_reset(&ctx->scratch); @@ -1212,12 +1254,12 @@ static int cb_h3_stop_sending(nghttp3_conn *conn, int64_t stream_id, return 0; } -static int cb_h3_reset_stream(nghttp3_conn *conn, int64_t sid, +static int cb_h3_reset_stream(nghttp3_conn *conn, int64_t stream_id, uint64_t app_error_code, void *user_data, - void *stream_user_data) { + void *stream_user_data) +{ struct Curl_cfilter *cf = user_data; struct cf_ngtcp2_ctx *ctx = cf->ctx; - curl_int64_t stream_id = (curl_int64_t)sid; struct Curl_easy *data = stream_user_data; int rv; (void)conn; @@ -1225,7 +1267,7 @@ static int cb_h3_reset_stream(nghttp3_conn *conn, int64_t sid, rv = ngtcp2_conn_shutdown_stream_write(ctx->qconn, 0, stream_id, app_error_code); - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] reset -> %d", stream_id, rv); + CURL_TRC_CF(data, cf, "[%" PRId64 "] reset -> %d", stream_id, rv); if(rv && rv != NGTCP2_ERR_STREAM_NOT_FOUND) { return NGHTTP3_ERR_CALLBACK_FAILURE; } @@ -1248,12 +1290,15 @@ static nghttp3_callbacks ngh3_callbacks = { NULL, /* end_stream */ cb_h3_reset_stream, NULL, /* shutdown */ - NULL, /* recv_settings */ -#ifdef NGHTTP3_CALLBACKS_V2 + NULL, /* recv_settings (deprecated) */ +#ifdef NGHTTP3_CALLBACKS_V2 /* nghttp3 v1.11.0+ */ NULL, /* recv_origin */ NULL, /* end_origin */ NULL, /* rand */ #endif +#ifdef NGHTTP3_CALLBACKS_V3 /* nghttp3 v1.14.0+ */ + NULL, /* recv_settings2 */ +#endif }; static CURLcode init_ngh3_conn(struct Curl_cfilter *cf, @@ -1319,32 +1364,25 @@ static CURLcode init_ngh3_conn(struct Curl_cfilter *cf, return CURLE_OK; } -static ssize_t recv_closed_stream(struct Curl_cfilter *cf, - struct Curl_easy *data, - struct h3_stream_ctx *stream, - CURLcode *err) +static CURLcode recv_closed_stream(struct Curl_cfilter *cf, + struct Curl_easy *data, + struct h3_stream_ctx *stream, + size_t *pnread) { - ssize_t nread = -1; - (void)cf; + *pnread = 0; if(stream->reset) { - failf(data, "HTTP/3 stream %" FMT_PRId64 " reset by server", stream->id); - *err = data->req.bytecount ? CURLE_PARTIAL_FILE : CURLE_HTTP3; - goto out; + failf(data, "HTTP/3 stream %" PRId64 " reset by server", stream->id); + return data->req.bytecount ? CURLE_PARTIAL_FILE : CURLE_HTTP3; } else if(!stream->resp_hds_complete) { failf(data, - "HTTP/3 stream %" FMT_PRId64 " was closed cleanly, but before " + "HTTP/3 stream %" PRId64 " was closed cleanly, but before " "getting all response header fields, treated as error", stream->id); - *err = CURLE_HTTP3; - goto out; + return CURLE_HTTP3; } - *err = CURLE_OK; - nread = 0; - -out: - return nread; + return CURLE_OK; } /* incoming data frames on the h3 stream */ @@ -1380,21 +1418,21 @@ static CURLcode cf_ngtcp2_recv(struct Curl_cfilter *cf, struct Curl_easy *data, goto out; } + cf_ngtcp2_ack_stream(cf, data, stream); + if(cf_progress_ingress(cf, data, &pktx)) { result = CURLE_RECV_ERROR; goto out; } if(stream->xfer_result) { - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] xfer write failed", stream->id); + CURL_TRC_CF(data, cf, "[%" PRId64 "] xfer write failed", stream->id); cf_ngtcp2_stream_close(cf, data, stream); result = stream->xfer_result; goto out; } else if(stream->closed) { - ssize_t nread = recv_closed_stream(cf, data, stream, &result); - if(nread > 0) - *pnread = (size_t)nread; + result = recv_closed_stream(cf, data, stream, pnread); goto out; } result = CURLE_AGAIN; @@ -1403,7 +1441,7 @@ static CURLcode cf_ngtcp2_recv(struct Curl_cfilter *cf, struct Curl_easy *data, result = Curl_1st_err(result, cf_progress_egress(cf, data, &pktx)); result = Curl_1st_err(result, check_and_set_expiry(cf, data, &pktx)); denied: - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] cf_recv(blen=%zu) -> %d, %zu", + CURL_TRC_CF(data, cf, "[%" PRId64 "] cf_recv(blen=%zu) -> %d, %zu", stream ? stream->id : -1, blen, result, *pnread); CF_DATA_RESTORE(cf, save); return result; @@ -1442,11 +1480,10 @@ static int cb_h3_acked_req_body(nghttp3_conn *conn, int64_t stream_id, return 0; } -static nghttp3_ssize -cb_h3_read_req_body(nghttp3_conn *conn, int64_t stream_id, - nghttp3_vec *vec, size_t veccnt, - uint32_t *pflags, void *user_data, - void *stream_user_data) +static nghttp3_ssize cb_h3_read_req_body(nghttp3_conn *conn, int64_t stream_id, + nghttp3_vec *vec, size_t veccnt, + uint32_t *pflags, void *user_data, + void *stream_user_data) { struct Curl_cfilter *cf = user_data; struct cf_ngtcp2_ctx *ctx = cf->ctx; @@ -1494,12 +1531,11 @@ cb_h3_read_req_body(nghttp3_conn *conn, int64_t stream_id, } else if(!nwritten) { /* Not EOF, and nothing to give, we signal WOULDBLOCK. */ - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] read req body -> AGAIN", - stream->id); + CURL_TRC_CF(data, cf, "[%" PRId64 "] read req body -> AGAIN", stream->id); return NGHTTP3_ERR_WOULDBLOCK; } - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] read req body -> " + CURL_TRC_CF(data, cf, "[%" PRId64 "] read req body -> " "%d vecs%s with %zu (buffered=%zu, left=%" FMT_OFF_T ")", stream->id, (int)nvecs, *pflags == NGHTTP3_DATA_FLAG_EOF ? " EOF" : "", @@ -1510,7 +1546,7 @@ cb_h3_read_req_body(nghttp3_conn *conn, int64_t stream_id, static CURLcode h3_stream_open(struct Curl_cfilter *cf, struct Curl_easy *data, - const void *buf, size_t len, + const uint8_t *buf, size_t len, size_t *pnwritten) { struct cf_ngtcp2_ctx *ctx = cf->ctx; @@ -1521,7 +1557,6 @@ static CURLcode h3_stream_open(struct Curl_cfilter *cf, nghttp3_nv *nva = NULL; int rc = 0; unsigned int i; - ssize_t nwritten = -1; nghttp3_data_reader reader; nghttp3_data_reader *preader = NULL; CURLcode result; @@ -1539,10 +1574,12 @@ static CURLcode h3_stream_open(struct Curl_cfilter *cf, goto out; } - nwritten = Curl_h1_req_parse_read(&stream->h1, buf, len, NULL, 0, &result); - if(nwritten < 0) + result = Curl_h1_req_parse_read(&stream->h1, buf, len, NULL, + !data->state.http_ignorecustom ? + data->set.str[STRING_CUSTOMREQUEST] : NULL, + 0, pnwritten); + if(result) goto out; - *pnwritten = (size_t)nwritten; if(!stream->h1.done) { /* need more data */ @@ -1558,7 +1595,7 @@ static CURLcode h3_stream_open(struct Curl_cfilter *cf, Curl_h1_req_parse_free(&stream->h1); nheader = Curl_dynhds_count(&h2_headers); - nva = malloc(sizeof(nghttp3_nv) * nheader); + nva = curlx_malloc(sizeof(nghttp3_nv) * nheader); if(!nva) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -1579,7 +1616,7 @@ static CURLcode h3_stream_open(struct Curl_cfilter *cf, result = CURLE_SEND_ERROR; goto out; } - stream->id = (curl_int64_t)sid; + stream->id = sid; ++ctx->used_bidi_streams; switch(data->state.httpreq) { @@ -1611,11 +1648,11 @@ static CURLcode h3_stream_open(struct Curl_cfilter *cf, if(rc) { switch(rc) { case NGHTTP3_ERR_CONN_CLOSING: - CURL_TRC_CF(data, cf, "h3sid[%" FMT_PRId64 "] failed to send, " + CURL_TRC_CF(data, cf, "h3sid[%" PRId64 "] failed to send, " "connection is closing", stream->id); break; default: - CURL_TRC_CF(data, cf, "h3sid[%" FMT_PRId64 "] failed to send -> " + CURL_TRC_CF(data, cf, "h3sid[%" PRId64 "] failed to send -> " "%d (%s)", stream->id, rc, nghttp3_strerror(rc)); break; } @@ -1624,24 +1661,26 @@ static CURLcode h3_stream_open(struct Curl_cfilter *cf, goto out; } + cf_ngtcp2_stream_update_window(cf, data, stream); + if(Curl_trc_is_verbose(data)) { - infof(data, "[HTTP/3] [%" FMT_PRId64 "] OPENED stream for %s", - stream->id, data->state.url); + infof(data, "[HTTP/3] [%" PRId64 "] OPENED stream for %s", + stream->id, Curl_bufref_ptr(&data->state.url)); for(i = 0; i < nheader; ++i) { - infof(data, "[HTTP/3] [%" FMT_PRId64 "] [%.*s: %.*s]", stream->id, + infof(data, "[HTTP/3] [%" PRId64 "] [%.*s: %.*s]", stream->id, (int)nva[i].namelen, nva[i].name, (int)nva[i].valuelen, nva[i].value); } } out: - free(nva); + curlx_free(nva); Curl_dynhds_free(&h2_headers); return result; } static CURLcode cf_ngtcp2_send(struct Curl_cfilter *cf, struct Curl_easy *data, - const void *buf, size_t len, bool eos, + const uint8_t *buf, size_t len, bool eos, size_t *pnwritten) { struct cf_ngtcp2_ctx *ctx = cf->ctx; @@ -1682,7 +1721,7 @@ static CURLcode cf_ngtcp2_send(struct Curl_cfilter *cf, struct Curl_easy *data, stream = H3_STREAM_CTX(ctx, data); } else if(stream->xfer_result) { - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] xfer write failed", stream->id); + CURL_TRC_CF(data, cf, "[%" PRId64 "] xfer write failed", stream->id); cf_ngtcp2_stream_close(cf, data, stream); result = stream->xfer_result; goto out; @@ -1694,13 +1733,13 @@ static CURLcode cf_ngtcp2_send(struct Curl_cfilter *cf, struct Curl_easy *data, * body. This happens on 30x or 40x responses. * We silently discard the data sent, since this is not a transport * error situation. */ - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] discarding data" + CURL_TRC_CF(data, cf, "[%" PRId64 "] discarding data" "on closed stream with response", stream->id); result = CURLE_OK; *pnwritten = len; goto out; } - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] send_body(len=%zu) " + CURL_TRC_CF(data, cf, "[%" PRId64 "] send_body(len=%zu) " "-> stream closed", stream->id, len); result = CURLE_HTTP3; goto out; @@ -1712,7 +1751,7 @@ static CURLcode cf_ngtcp2_send(struct Curl_cfilter *cf, struct Curl_easy *data, } else { result = Curl_bufq_write(&stream->sendbuf, buf, len, pnwritten); - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] cf_send, add to " + CURL_TRC_CF(data, cf, "[%" PRId64 "] cf_send, add to " "sendbuf(len=%zu) -> %d, %zu", stream->id, len, result, *pnwritten); if(result) @@ -1729,25 +1768,36 @@ static CURLcode cf_ngtcp2_send(struct Curl_cfilter *cf, struct Curl_easy *data, out: result = Curl_1st_err(result, check_and_set_expiry(cf, data, &pktx)); denied: - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] cf_send(len=%zu) -> %d, %zu", + CURL_TRC_CF(data, cf, "[%" PRId64 "] cf_send(len=%zu) -> %d, %zu", stream ? stream->id : -1, len, result, *pnwritten); CF_DATA_RESTORE(cf, save); return result; } +struct cf_ngtcp2_recv_ctx { + struct pkt_io_ctx *pktx; + size_t pkt_count; +}; + static CURLcode cf_ngtcp2_recv_pkts(const unsigned char *buf, size_t buflen, size_t gso_size, struct sockaddr_storage *remote_addr, socklen_t remote_addrlen, int ecn, void *userp) { - struct pkt_io_ctx *pktx = userp; + struct cf_ngtcp2_recv_ctx *rctx = userp; + struct pkt_io_ctx *pktx = rctx->pktx; struct cf_ngtcp2_ctx *ctx = pktx->cf->ctx; ngtcp2_pkt_info pi; ngtcp2_path path; size_t offset, pktlen; int rv; + if(!rctx->pkt_count) { + pktx_update_time(pktx->data, pktx, pktx->cf); + ngtcp2_path_storage_zero(&pktx->ps); + } + if(ecn) CURL_TRC_CF(pktx->data, pktx->cf, "vquic_recv(len=%zu, gso=%zu, ecn=%x)", buflen, gso_size, ecn); @@ -1758,6 +1808,7 @@ static CURLcode cf_ngtcp2_recv_pkts(const unsigned char *buf, size_t buflen, pi.ecn = (uint8_t)ecn; for(offset = 0; offset < buflen; offset += gso_size) { + rctx->pkt_count++; pktlen = ((offset + gso_size) <= buflen) ? gso_size : (buflen - offset); rv = ngtcp2_conn_read_pkt(ctx->qconn, &path, &pi, buf + offset, pktlen, pktx->ts); @@ -1782,23 +1833,22 @@ static CURLcode cf_progress_ingress(struct Curl_cfilter *cf, { struct cf_ngtcp2_ctx *ctx = cf->ctx; struct pkt_io_ctx local_pktx; + struct cf_ngtcp2_recv_ctx rctx; CURLcode result = CURLE_OK; if(!pktx) { pktx_init(&local_pktx, cf, data); pktx = &local_pktx; } - else { - pktx_update_time(pktx, cf); - ngtcp2_path_storage_zero(&pktx->ps); - } result = Curl_vquic_tls_before_recv(&ctx->tls, cf, data); if(result) return result; + rctx.pktx = pktx; + rctx.pkt_count = 0; return vquic_recv_packets(cf, data, &ctx->q, 1000, - cf_ngtcp2_recv_pkts, pktx); + cf_ngtcp2_recv_pkts, &rctx); } /** @@ -1860,8 +1910,8 @@ static CURLcode read_pkt_to_send(void *userp, struct h3_stream_ctx *stream; DEBUGASSERT(ndatalen == -1); nghttp3_conn_block_stream(ctx->h3conn, stream_id); - CURL_TRC_CF(x->data, x->cf, "[%" FMT_PRId64 "] block quic flow", - (curl_int64_t)stream_id); + CURL_TRC_CF(x->data, x->cf, "[%" PRId64 "] block quic flow", + stream_id); stream = cf_ngtcp2_get_stream(ctx, stream_id); if(stream) /* it might be not one of our h3 streams? */ stream->quic_flow_blocked = TRUE; @@ -1924,7 +1974,7 @@ static CURLcode cf_progress_egress(struct Curl_cfilter *cf, pktx = &local_pktx; } else { - pktx_update_time(pktx, cf); + pktx_update_time(data, pktx, cf); ngtcp2_path_storage_zero(&pktx->ps); } @@ -1950,7 +2000,7 @@ static CURLcode cf_progress_egress(struct Curl_cfilter *cf, */ max_payload_size = ngtcp2_conn_get_max_tx_udp_payload_size(ctx->qconn); path_max_payload_size = - ngtcp2_conn_get_path_max_tx_udp_payload_size(ctx->qconn); + ngtcp2_conn_get_path_max_tx_udp_payload_size(ctx->qconn); send_quantum = ngtcp2_conn_get_send_quantum(ctx->qconn); CURL_TRC_CF(data, cf, "egress, collect and send packets, quantum=%zu", send_quantum); @@ -1966,7 +2016,7 @@ static CURLcode cf_progress_egress(struct Curl_cfilter *cf, size_t buflen = Curl_bufq_len(&ctx->q.sendbuf); if((buflen >= send_quantum) || ((buflen + gsolen) >= ctx->q.sendbuf.chunk_size)) - break; + break; DEBUGASSERT(nread > 0); ++pktcnt; if(pktcnt == 1) { @@ -2011,7 +2061,7 @@ static CURLcode cf_progress_egress(struct Curl_cfilter *cf, } return curlcode; } - pktx_update_time(pktx, cf); + pktx_update_time(data, pktx, cf); ngtcp2_conn_update_pkt_tx_time(ctx->qconn, pktx->ts); } return CURLE_OK; @@ -2145,8 +2195,8 @@ static CURLcode cf_ngtcp2_shutdown(struct Curl_cfilter *cf, (uint8_t *)buffer, sizeof(buffer), &ctx->last_error, pktx.ts); CURL_TRC_CF(data, cf, "start shutdown(err_type=%d, err_code=%" - FMT_PRIu64 ") -> %d", ctx->last_error.type, - (curl_uint64_t)ctx->last_error.error_code, (int)nwritten); + PRIu64 ") -> %d", ctx->last_error.type, + ctx->last_error.error_code, (int)nwritten); /* there are cases listed in ngtcp2 documentation where this call * may fail. Since we are doing a connection shutdown as graceful * as we can, such an error is ignored here. */ @@ -2262,7 +2312,6 @@ static int quic_ossl_new_session_cb(SSL *ssl, SSL_SESSION *ssl_sessionid) #endif Curl_ossl_add_session(cf, data, ctx->peer.scache_key, ssl_sessionid, SSL_version(ssl), "h3", quic_tp, quic_tp_len); - return 1; } return 0; } @@ -2273,16 +2322,26 @@ static int quic_ossl_new_session_cb(SSL *ssl, SSL_SESSION *ssl_sessionid) static const char *gtls_hs_msg_name(int mtype) { switch(mtype) { - case 1: return "ClientHello"; - case 2: return "ServerHello"; - case 4: return "SessionTicket"; - case 8: return "EncryptedExtensions"; - case 11: return "Certificate"; - case 13: return "CertificateRequest"; - case 15: return "CertificateVerify"; - case 20: return "Finished"; - case 24: return "KeyUpdate"; - case 254: return "MessageHash"; + case 1: + return "ClientHello"; + case 2: + return "ServerHello"; + case 4: + return "SessionTicket"; + case 8: + return "EncryptedExtensions"; + case 11: + return "Certificate"; + case 13: + return "CertificateRequest"; + case 15: + return "CertificateVerify"; + case 20: + return "Finished"; + case 24: + return "KeyUpdate"; + case 254: + return "MessageHash"; } return "Unknown"; } @@ -2448,7 +2507,7 @@ static CURLcode cf_ngtcp2_on_session_reuse(struct Curl_cfilter *cf, #endif /* WOLFSSL_EARLY_DATA */ #endif #if defined(USE_GNUTLS) || defined(USE_WOLFSSL) || \ - (defined(USE_OPENSSL) && defined(HAVE_OPENSSL_EARLYDATA)) + (defined(USE_OPENSSL) && defined(HAVE_OPENSSL_EARLYDATA)) if((!ctx->earlydata_max)) { CURL_TRC_CF(data, cf, "SSL session does not allow earlydata"); } @@ -2498,7 +2557,7 @@ static CURLcode cf_connect_start(struct Curl_cfilter *cf, CURLcode result; const struct Curl_sockaddr_ex *sockaddr = NULL; int qfd; - static const struct alpn_spec ALPN_SPEC_H3 = {{ "h3", "h3-29" }, 2}; + static const struct alpn_spec ALPN_SPEC_H3 = { { "h3", "h3-29" }, 2 }; DEBUGASSERT(ctx->initialized); ctx->dcid.datalen = NGTCP2_MAX_CIDLEN; @@ -2515,7 +2574,7 @@ static CURLcode cf_connect_start(struct Curl_cfilter *cf, ctx->qlogfd = qfd; /* -1 if failure above */ quic_settings(ctx, data, pktx); - result = vquic_ctx_init(&ctx->q); + result = vquic_ctx_init(data, &ctx->q); if(result) return result; @@ -2584,7 +2643,6 @@ static CURLcode cf_ngtcp2_connect(struct Curl_cfilter *cf, struct cf_ngtcp2_ctx *ctx = cf->ctx; CURLcode result = CURLE_OK; struct cf_call_data save; - struct curltime now; struct pkt_io_ctx pktx; if(cf->connected) { @@ -2600,13 +2658,12 @@ static CURLcode cf_ngtcp2_connect(struct Curl_cfilter *cf, } *done = FALSE; - now = curlx_now(); pktx_init(&pktx, cf, data); CF_DATA_SAVE(save, cf, data); if(!ctx->qconn) { - ctx->started_at = now; + ctx->started_at = *Curl_pgrs_now(data); result = cf_connect_start(cf, data, &pktx); if(result) goto out; @@ -2633,20 +2690,19 @@ static CURLcode cf_ngtcp2_connect(struct Curl_cfilter *cf, CURL_TRC_CF(data, cf, "peer verified"); cf->connected = TRUE; *done = TRUE; - connkeep(cf->conn, "HTTP/3 default"); } } out: - if(result == CURLE_RECV_ERROR && ctx->qconn && + if(ctx->qconn && + ((result == CURLE_RECV_ERROR) || (result == CURLE_SEND_ERROR)) && ngtcp2_conn_in_draining_period(ctx->qconn)) { const ngtcp2_ccerr *cerr = ngtcp2_conn_get_ccerr(ctx->qconn); result = CURLE_COULDNT_CONNECT; if(cerr) { - CURL_TRC_CF(data, cf, "connect error, type=%d, code=%" - FMT_PRIu64, - cerr->type, (curl_uint64_t)cerr->error_code); + CURL_TRC_CF(data, cf, "connect error, type=%d, code=%" PRIu64, + cerr->type, cerr->error_code); switch(cerr->type) { case NGTCP2_CCERR_TYPE_VERSION_NEGOTIATION: CURL_TRC_CF(data, cf, "error in version negotiation"); @@ -2660,7 +2716,7 @@ static CURLcode cf_ngtcp2_connect(struct Curl_cfilter *cf, CURL_TRC_CF(data, cf, "connection refused by server"); /* When a QUIC server instance is shutting down, it may send us a * CONNECTION_CLOSE with this code right away. We want - * to keep on trying in this case. */ + * to keep on trying in this case. */ result = CURLE_WEIRD_SERVER_REPLY; } } @@ -2705,7 +2761,7 @@ static CURLcode cf_ngtcp2_query(struct Curl_cfilter *cf, } else if(ctx->max_bidi_streams) { uint64_t avail_bidi_streams = 0; - uint64_t max_streams = CONN_ATTACHED(cf->conn); + uint64_t max_streams = cf->conn->attached_xfers; if(ctx->max_bidi_streams > ctx->used_bidi_streams) avail_bidi_streams = ctx->max_bidi_streams - ctx->used_bidi_streams; max_streams += avail_bidi_streams; @@ -2715,13 +2771,14 @@ static CURLcode cf_ngtcp2_query(struct Curl_cfilter *cf, *pres1 = (int)Curl_multi_max_concurrent_streams(data->multi); CURL_TRC_CF(data, cf, "query conn[%" FMT_OFF_T "]: " "MAX_CONCURRENT -> %d (%u in use)", - cf->conn->connection_id, *pres1, CONN_ATTACHED(cf->conn)); + cf->conn->connection_id, *pres1, cf->conn->attached_xfers); CF_DATA_RESTORE(cf, save); return CURLE_OK; } case CF_QUERY_CONNECT_REPLY_MS: if(ctx->q.got_first_byte) { - timediff_t ms = curlx_timediff(ctx->q.first_byte_at, ctx->started_at); + timediff_t ms = curlx_ptimediff_ms(&ctx->q.first_byte_at, + &ctx->started_at); *pres1 = (ms < INT_MAX) ? (int)ms : INT_MAX; } else @@ -2782,7 +2839,8 @@ static bool cf_ngtcp2_conn_is_alive(struct Curl_cfilter *cf, * it will close the connection when it expires. */ rp = ngtcp2_conn_get_remote_transport_params(ctx->qconn); if(rp && rp->max_idle_timeout) { - timediff_t idletime_ms = curlx_timediff(curlx_now(), ctx->q.last_io); + timediff_t idletime_ms = + curlx_ptimediff_ms(Curl_pgrs_now(data), &ctx->q.last_io); if(idletime_ms > 0) { uint64_t max_idle_ms = (uint64_t)(rp->max_idle_timeout / NGTCP2_MILLISECONDS); @@ -2839,7 +2897,7 @@ CURLcode Curl_cf_ngtcp2_create(struct Curl_cfilter **pcf, CURLcode result; (void)data; - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -2868,20 +2926,4 @@ CURLcode Curl_cf_ngtcp2_create(struct Curl_cfilter **pcf, return result; } -bool Curl_conn_is_ngtcp2(const struct Curl_easy *data, - const struct connectdata *conn, - int sockindex) -{ - struct Curl_cfilter *cf = conn ? conn->cfilter[sockindex] : NULL; - - (void)data; - for(; cf; cf = cf->next) { - if(cf->cft == &Curl_cft_http3) - return TRUE; - if(cf->cft->flags & CF_TYPE_IP_CONNECT) - return FALSE; - } - return FALSE; -} - #endif diff --git a/vendor/hydra/vendor/curl/lib/vquic/curl_ngtcp2.h b/vendor/hydra/vendor/curl/lib/vquic/curl_ngtcp2.h index 86753a3a..1e9868e0 100644 --- a/vendor/hydra/vendor/curl/lib/vquic/curl_ngtcp2.h +++ b/vendor/hydra/vendor/curl/lib/vquic/curl_ngtcp2.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "../curl_setup.h" #if !defined(CURL_DISABLE_HTTP) && defined(USE_NGTCP2) && defined(USE_NGHTTP3) @@ -55,10 +54,6 @@ CURLcode Curl_cf_ngtcp2_create(struct Curl_cfilter **pcf, struct Curl_easy *data, struct connectdata *conn, const struct Curl_addrinfo *ai); - -bool Curl_conn_is_ngtcp2(const struct Curl_easy *data, - const struct connectdata *conn, - int sockindex); #endif #endif /* HEADER_CURL_VQUIC_CURL_NGTCP2_H */ diff --git a/vendor/hydra/vendor/curl/lib/vquic/curl_osslq.c b/vendor/hydra/vendor/curl/lib/vquic/curl_osslq.c index e30cfc64..46487978 100644 --- a/vendor/hydra/vendor/curl/lib/vquic/curl_osslq.c +++ b/vendor/hydra/vendor/curl/lib/vquic/curl_osslq.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "../curl_setup.h" #if !defined(CURL_DISABLE_HTTP) && defined(USE_OPENSSL_QUIC) && \ @@ -33,9 +32,7 @@ #include #include "../urldata.h" -#include "../hash.h" -#include "../sendf.h" -#include "../rand.h" +#include "../curl_trc.h" #include "../multiif.h" #include "../cfilters.h" #include "../cf-socket.h" @@ -44,7 +41,6 @@ #include "../curlx/dynbuf.h" #include "../http1.h" #include "../select.h" -#include "../curlx/inet_pton.h" #include "../uint-hash.h" #include "vquic.h" #include "vquic_int.h" @@ -54,12 +50,9 @@ #include "../vtls/openssl.h" #include "curl_osslq.h" #include "../url.h" -#include "../curlx/warnless.h" +#include "../bufref.h" #include "../curlx/strerr.h" - -/* The last 2 #include files should be in this order */ -#include "../curl_memory.h" -#include "../memdebug.h" +#include "../curlx/strcopy.h" /* A stream window is the maximum amount we need to buffer for * each active transfer. We use HTTP/3 flow control and only ACK @@ -73,13 +66,13 @@ * spares. Memory consumption goes down when streams run empty, * have a large upload done, etc. */ #define H3_STREAM_POOL_SPARES \ - (H3_STREAM_WINDOW_SIZE / H3_STREAM_CHUNK_SIZE ) / 2 + (H3_STREAM_WINDOW_SIZE / H3_STREAM_CHUNK_SIZE) / 2 /* Receive and Send max number of chunks just follows from the * chunk size and window size */ #define H3_STREAM_RECV_CHUNKS \ - (H3_STREAM_WINDOW_SIZE / H3_STREAM_CHUNK_SIZE) + (H3_STREAM_WINDOW_SIZE / H3_STREAM_CHUNK_SIZE) #define H3_STREAM_SEND_CHUNKS \ - (H3_STREAM_WINDOW_SIZE / H3_STREAM_CHUNK_SIZE) + (H3_STREAM_WINDOW_SIZE / H3_STREAM_CHUNK_SIZE) #if defined(OPENSSL_IS_BORINGSSL) || defined(OPENSSL_IS_AWSLC) typedef uint32_t sslerr_t; @@ -90,8 +83,7 @@ typedef unsigned long sslerr_t; /* How to access `call_data` from a cf_osslq filter */ #undef CF_CTX_CALL_DATA -#define CF_CTX_CALL_DATA(cf) \ - ((struct cf_osslq_ctx *)(cf)->ctx)->call_data +#define CF_CTX_CALL_DATA(cf) ((struct cf_osslq_ctx *)(cf)->ctx)->call_data static CURLcode cf_progress_ingress(struct Curl_cfilter *cf, struct Curl_easy *data); @@ -149,7 +141,7 @@ static char *osslq_strerror(unsigned long error, char *buf, size_t size) if(!*buf) { const char *msg = error ? "Unknown error" : "No error"; if(strlen(msg) < size) - strcpy(buf, msg); + curlx_strcopy(buf, size, msg, strlen(msg)); } return buf; @@ -207,7 +199,7 @@ static CURLcode make_bio_addr(BIO_ADDR **pbio_addr, /* QUIC stream (not necessarily H3) */ struct cf_osslq_stream { - curl_int64_t id; + int64_t id; SSL *ssl; struct bufq recvbuf; /* QUIC war data recv buffer */ BIT(recvd_eos); @@ -228,7 +220,7 @@ static CURLcode cf_osslq_stream_open(struct cf_osslq_stream *s, if(!s->ssl) { return CURLE_FAILED_INIT; } - s->id = (curl_int64_t)SSL_get_stream_id(s->ssl); + s->id = SSL_get_stream_id(s->ssl); SSL_set_app_data(s->ssl, user_data); return CURLE_OK; } @@ -305,7 +297,7 @@ static void cf_osslq_ctx_init(struct cf_osslq_ctx *ctx) DEBUGASSERT(!ctx->initialized); Curl_bufcp_init(&ctx->stream_bufcp, H3_STREAM_CHUNK_SIZE, H3_STREAM_POOL_SPARES); - Curl_uint_hash_init(&ctx->streams, 63, h3_stream_hash_free); + Curl_uint32_hash_init(&ctx->streams, 63, h3_stream_hash_free); ctx->poll_items = NULL; ctx->curl_items = NULL; ctx->items_max = 0; @@ -316,12 +308,12 @@ static void cf_osslq_ctx_free(struct cf_osslq_ctx *ctx) { if(ctx && ctx->initialized) { Curl_bufcp_free(&ctx->stream_bufcp); - Curl_uint_hash_destroy(&ctx->streams); + Curl_uint32_hash_destroy(&ctx->streams); Curl_ssl_peer_cleanup(&ctx->peer); - free(ctx->poll_items); - free(ctx->curl_items); + curlx_free(ctx->poll_items); + curlx_free(ctx->curl_items); } - free(ctx); + curlx_free(ctx); } static void cf_osslq_ctx_close(struct cf_osslq_ctx *ctx) @@ -450,36 +442,36 @@ static CURLcode cf_osslq_h3conn_add_stream(struct cf_osslq_h3conn *h3, struct Curl_easy *data) { struct cf_osslq_ctx *ctx = cf->ctx; - curl_int64_t stream_id = (curl_int64_t)SSL_get_stream_id(stream_ssl); + int64_t stream_id = (int64_t)SSL_get_stream_id(stream_ssl); int stype = SSL_get_stream_type(stream_ssl); /* This could be a GREASE stream, e.g. HTTP/3 rfc9114 ch 6.2.3 * reserved stream type that is supposed to be discarded silently. * BUT OpenSSL does not offer this information to us. So, we silently * ignore all such streams we do not expect. */ switch(stype) { - case SSL_STREAM_TYPE_READ: { - struct cf_osslq_stream *nstream; - if(h3->remote_ctrl_n >= CURL_ARRAYSIZE(h3->remote_ctrl)) { - /* rejected, we are full */ - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] reject remote uni stream", - stream_id); - SSL_free(stream_ssl); - return CURLE_OK; - } - nstream = &h3->remote_ctrl[h3->remote_ctrl_n++]; - nstream->id = stream_id; - nstream->ssl = stream_ssl; - Curl_bufq_initp(&nstream->recvbuf, &ctx->stream_bufcp, 1, BUFQ_OPT_NONE); - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] accepted remote uni stream", + case SSL_STREAM_TYPE_READ: { + struct cf_osslq_stream *nstream; + if(h3->remote_ctrl_n >= CURL_ARRAYSIZE(h3->remote_ctrl)) { + /* rejected, we are full */ + CURL_TRC_CF(data, cf, "[%" PRId64 "] reject remote uni stream", stream_id); - return CURLE_OK; - } - default: - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] reject remote %s" - " stream, type=%x", stream_id, - (stype == SSL_STREAM_TYPE_BIDI) ? "bidi" : "write", stype); SSL_free(stream_ssl); return CURLE_OK; + } + nstream = &h3->remote_ctrl[h3->remote_ctrl_n++]; + nstream->id = stream_id; + nstream->ssl = stream_ssl; + Curl_bufq_initp(&nstream->recvbuf, &ctx->stream_bufcp, 1, BUFQ_OPT_NONE); + CURL_TRC_CF(data, cf, "[%" PRId64 "] accepted remote uni stream", + stream_id); + return CURLE_OK; + } + default: + CURL_TRC_CF(data, cf, "[%" PRId64 "] reject remote %s" + " stream, type=%x", stream_id, + (stype == SSL_STREAM_TYPE_BIDI) ? "bidi" : "write", stype); + SSL_free(stream_ssl); + return CURLE_OK; } } @@ -509,8 +501,7 @@ static CURLcode cf_osslq_ssl_err(struct Curl_cfilter *cf, lerr = SSL_get_verify_result(ctx->tls.ossl.ssl); if(lerr != X509_V_OK) { ssl_config->certverifyresult = lerr; - curl_msnprintf(ebuf, sizeof(ebuf), - "SSL certificate problem: %s", + curl_msnprintf(ebuf, sizeof(ebuf), "SSL certificate problem: %s", X509_verify_cert_error_string(lerr)); } else @@ -544,7 +535,7 @@ static CURLcode cf_osslq_ssl_err(struct Curl_cfilter *cf, * the SO_ERROR is also lost. */ if(CURLE_SSL_CONNECT_ERROR == result && errdetail == 0) { - char extramsg[80]=""; + char extramsg[80] = ""; int sockerr = SOCKERRNO; struct ip_quadruple ip; @@ -574,20 +565,21 @@ static CURLcode cf_osslq_verify_peer(struct Curl_cfilter *cf, */ struct h3_stream_ctx { struct cf_osslq_stream s; - struct bufq sendbuf; /* h3 request body */ - struct bufq recvbuf; /* h3 response body */ - struct h1_req_parser h1; /* h1 request parsing */ + struct bufq sendbuf; /* h3 request body */ + struct bufq recvbuf; /* h3 response body */ + struct h1_req_parser h1; /* h1 request parsing */ size_t sendbuf_len_in_flight; /* sendbuf amount "in flight" */ - size_t recv_buf_nonflow; /* buffered bytes, not counting for flow control */ - curl_uint64_t error3; /* HTTP/3 stream error code */ - curl_off_t upload_left; /* number of request bytes left to upload */ - curl_off_t download_recvd; /* number of response DATA bytes received */ - int status_code; /* HTTP status code */ - BIT(resp_hds_complete); /* we have a complete, final response */ - BIT(closed); /* TRUE on stream close */ - BIT(reset); /* TRUE on stream reset */ - BIT(send_closed); /* stream is local closed */ - BIT(quic_flow_blocked); /* stream is blocked by QUIC flow control */ + size_t recv_buf_nonflow; /* buffered bytes, + not counting for flow control */ + uint64_t error3; /* HTTP/3 stream error code */ + curl_off_t upload_left; /* number of request bytes left to upload */ + curl_off_t download_recvd; /* number of response DATA bytes received */ + int status_code; /* HTTP status code */ + BIT(resp_hds_complete); /* we have a complete, final response */ + BIT(closed); /* TRUE on stream close */ + BIT(reset); /* TRUE on stream reset */ + BIT(send_closed); /* stream is local closed */ + BIT(quic_flow_blocked); /* stream is blocked by QUIC flow control */ }; static void h3_stream_ctx_free(struct h3_stream_ctx *stream) @@ -596,7 +588,7 @@ static void h3_stream_ctx_free(struct h3_stream_ctx *stream) Curl_bufq_free(&stream->sendbuf); Curl_bufq_free(&stream->recvbuf); Curl_h1_req_parse_free(&stream->h1); - free(stream); + curlx_free(stream); } static void h3_stream_hash_free(unsigned int id, void *stream) @@ -618,7 +610,7 @@ static CURLcode h3_data_setup(struct Curl_cfilter *cf, if(stream) return CURLE_OK; - stream = calloc(1, sizeof(*stream)); + stream = curlx_calloc(1, sizeof(*stream)); if(!stream) return CURLE_OUT_OF_MEMORY; @@ -634,7 +626,7 @@ static CURLcode h3_data_setup(struct Curl_cfilter *cf, stream->recv_buf_nonflow = 0; Curl_h1_req_parse_init(&stream->h1, H1_PARSE_DEFAULT_MAX_LINE_LEN); - if(!Curl_uint_hash_set(&ctx->streams, data->mid, stream)) { + if(!Curl_uint32_hash_set(&ctx->streams, data->mid, stream)) { h3_stream_ctx_free(stream); return CURLE_OUT_OF_MEMORY; } @@ -649,8 +641,7 @@ static void h3_data_done(struct Curl_cfilter *cf, struct Curl_easy *data) (void)cf; if(stream) { - CURL_TRC_CF(data, cf, "[%"FMT_PRId64"] easy handle is done", - stream->s.id); + CURL_TRC_CF(data, cf, "[%" PRIu64 "] easy handle is done", stream->s.id); if(ctx->h3.conn && (stream->s.id >= 0) && !stream->closed) { nghttp3_conn_shutdown_stream_read(ctx->h3.conn, stream->s.id); nghttp3_conn_close_stream(ctx->h3.conn, stream->s.id, @@ -659,16 +650,16 @@ static void h3_data_done(struct Curl_cfilter *cf, struct Curl_easy *data) stream->closed = TRUE; } - Curl_uint_hash_remove(&ctx->streams, data->mid); + Curl_uint32_hash_remove(&ctx->streams, data->mid); } } struct cf_ossq_find_ctx { - curl_int64_t stream_id; + int64_t stream_id; struct h3_stream_ctx *stream; }; -static bool cf_osslq_find_stream(unsigned int mid, void *val, void *user_data) +static bool cf_osslq_find_stream(uint32_t mid, void *val, void *user_data) { struct h3_stream_ctx *stream = val; struct cf_ossq_find_ctx *fctx = user_data; @@ -704,7 +695,7 @@ static struct cf_osslq_stream *cf_osslq_get_qstream(struct Curl_cfilter *cf, struct cf_ossq_find_ctx fctx; fctx.stream_id = stream_id; fctx.stream = NULL; - Curl_uint_hash_visit(&ctx->streams, cf_osslq_find_stream, &fctx); + Curl_uint32_hash_visit(&ctx->streams, cf_osslq_find_stream, &fctx); if(fctx.stream) return &fctx.stream->s; } @@ -743,11 +734,11 @@ static int cb_h3_stream_close(nghttp3_conn *conn, int64_t stream_id, if(stream->error3 != NGHTTP3_H3_NO_ERROR) { stream->reset = TRUE; stream->send_closed = TRUE; - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] RESET: error %" FMT_PRIu64, + CURL_TRC_CF(data, cf, "[%" PRId64 "] RESET: error %" PRIu64, stream->s.id, stream->error3); } else { - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] CLOSED", stream->s.id); + CURL_TRC_CF(data, cf, "[%" PRId64 "] CLOSED", stream->s.id); } Curl_multi_mark_dirty(data); return 0; @@ -777,11 +768,11 @@ static CURLcode write_resp_raw(struct Curl_cfilter *cf, return result; if(!flow) - stream->recv_buf_nonflow += (size_t)nwritten; + stream->recv_buf_nonflow += nwritten; if(nwritten < memlen) { /* This MUST not happen. Our recbuf is dimensioned to hold the - * full max_stream_window and then some for this very reason. */ + * full max_stream_window and then some for this reason. */ DEBUGASSERT(0); return CURLE_RECV_ERROR; } @@ -806,12 +797,12 @@ static int cb_h3_recv_data(nghttp3_conn *conn, int64_t stream3_id, result = write_resp_raw(cf, data, buf, buflen, TRUE); if(result) { - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] DATA len=%zu, ERROR %d", + CURL_TRC_CF(data, cf, "[%" PRId64 "] DATA len=%zu, ERROR %d", stream->s.id, buflen, result); return NGHTTP3_ERR_CALLBACK_FAILURE; } stream->download_recvd += (curl_off_t)buflen; - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] DATA len=%zu, total=%" FMT_OFF_T, + CURL_TRC_CF(data, cf, "[%" PRId64 "] DATA len=%zu, total=%" FMT_OFF_T, stream->s.id, buflen, stream->download_recvd); Curl_multi_mark_dirty(data); return 0; @@ -829,18 +820,17 @@ static int cb_h3_deferred_consume(nghttp3_conn *conn, int64_t stream_id, (void)conn; (void)stream_id; if(stream) - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] deferred consume %zu bytes", + CURL_TRC_CF(data, cf, "[%" PRId64 "] deferred consume %zu bytes", stream->s.id, consumed); return 0; } -static int cb_h3_recv_header(nghttp3_conn *conn, int64_t sid, +static int cb_h3_recv_header(nghttp3_conn *conn, int64_t stream_id, int32_t token, nghttp3_rcbuf *name, nghttp3_rcbuf *value, uint8_t flags, void *user_data, void *stream_user_data) { struct Curl_cfilter *cf = user_data; - curl_int64_t stream_id = sid; struct cf_osslq_ctx *ctx = cf->ctx; nghttp3_vec h3name = nghttp3_rcbuf_get_buf(name); nghttp3_vec h3val = nghttp3_rcbuf_get_buf(value); @@ -867,7 +857,7 @@ static int cb_h3_recv_header(nghttp3_conn *conn, int64_t sid, return -1; ncopy = curl_msnprintf(line, sizeof(line), "HTTP/3 %03d \r\n", stream->status_code); - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] status: %s", stream_id, line); + CURL_TRC_CF(data, cf, "[%" PRId64 "] status: %s", stream_id, line); result = write_resp_raw(cf, data, line, ncopy, FALSE); if(result) { return -1; @@ -875,7 +865,7 @@ static int cb_h3_recv_header(nghttp3_conn *conn, int64_t sid, } else { /* store as an HTTP1-style header */ - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] header: %.*s: %.*s", + CURL_TRC_CF(data, cf, "[%" PRId64 "] header: %.*s: %.*s", stream_id, (int)h3name.len, h3name.base, (int)h3val.len, h3val.base); result = write_resp_raw(cf, data, h3name.base, h3name.len, FALSE); @@ -898,13 +888,12 @@ static int cb_h3_recv_header(nghttp3_conn *conn, int64_t sid, return 0; } -static int cb_h3_end_headers(nghttp3_conn *conn, int64_t sid, +static int cb_h3_end_headers(nghttp3_conn *conn, int64_t stream_id, int fin, void *user_data, void *stream_user_data) { struct Curl_cfilter *cf = user_data; struct cf_osslq_ctx *ctx = cf->ctx; struct Curl_easy *data = stream_user_data; - curl_int64_t stream_id = sid; struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); CURLcode result = CURLE_OK; (void)conn; @@ -920,7 +909,7 @@ static int cb_h3_end_headers(nghttp3_conn *conn, int64_t sid, return -1; } - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] end_headers, status=%d", + CURL_TRC_CF(data, cf, "[%" PRId64 "] end_headers, status=%d", stream_id, stream->status_code); if(stream->status_code / 100 != 1) { stream->resp_hds_complete = TRUE; @@ -929,14 +918,13 @@ static int cb_h3_end_headers(nghttp3_conn *conn, int64_t sid, return 0; } -static int cb_h3_stop_sending(nghttp3_conn *conn, int64_t sid, +static int cb_h3_stop_sending(nghttp3_conn *conn, int64_t stream_id, uint64_t app_error_code, void *user_data, void *stream_user_data) { struct Curl_cfilter *cf = user_data; struct cf_osslq_ctx *ctx = cf->ctx; struct Curl_easy *data = stream_user_data; - curl_int64_t stream_id = sid; struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); (void)conn; (void)app_error_code; @@ -944,27 +932,27 @@ static int cb_h3_stop_sending(nghttp3_conn *conn, int64_t sid, if(!stream || !stream->s.ssl) return 0; - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] stop_sending", stream_id); + CURL_TRC_CF(data, cf, "[%" PRId64 "] stop_sending", stream_id); cf_osslq_stream_close(&stream->s); return 0; } -static int cb_h3_reset_stream(nghttp3_conn *conn, int64_t sid, +static int cb_h3_reset_stream(nghttp3_conn *conn, int64_t stream_id, uint64_t app_error_code, void *user_data, - void *stream_user_data) { + void *stream_user_data) +{ struct Curl_cfilter *cf = user_data; struct cf_osslq_ctx *ctx = cf->ctx; struct Curl_easy *data = stream_user_data; - curl_int64_t stream_id = sid; struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); int rv; (void)conn; if(stream && stream->s.ssl) { - SSL_STREAM_RESET_ARGS args = {0}; + SSL_STREAM_RESET_ARGS args = { 0 }; args.quic_error_code = app_error_code; rv = !SSL_stream_reset(stream->s.ssl, &args, sizeof(args)); - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] reset -> %d", stream_id, rv); + CURL_TRC_CF(data, cf, "[%" PRId64 "] reset -> %d", stream_id, rv); if(!rv) { return NGHTTP3_ERR_CALLBACK_FAILURE; } @@ -972,11 +960,10 @@ static int cb_h3_reset_stream(nghttp3_conn *conn, int64_t sid, return 0; } -static nghttp3_ssize -cb_h3_read_req_body(nghttp3_conn *conn, int64_t stream_id, - nghttp3_vec *vec, size_t veccnt, - uint32_t *pflags, void *user_data, - void *stream_user_data) +static nghttp3_ssize cb_h3_read_req_body(nghttp3_conn *conn, int64_t stream_id, + nghttp3_vec *vec, size_t veccnt, + uint32_t *pflags, void *user_data, + void *stream_user_data) { struct Curl_cfilter *cf = user_data; struct cf_osslq_ctx *ctx = cf->ctx; @@ -1024,12 +1011,12 @@ cb_h3_read_req_body(nghttp3_conn *conn, int64_t stream_id, } else if(!nwritten) { /* Not EOF, and nothing to give, we signal WOULDBLOCK. */ - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] read req body -> AGAIN", + CURL_TRC_CF(data, cf, "[%" PRId64 "] read req body -> AGAIN", stream->s.id); return NGHTTP3_ERR_WOULDBLOCK; } - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] read req body -> " + CURL_TRC_CF(data, cf, "[%" PRId64 "] read req body -> " "%d vecs%s with %zu (buffered=%zu, left=%" FMT_OFF_T ")", stream->s.id, (int)nvecs, *pflags == NGHTTP3_DATA_FLAG_EOF ? " EOF" : "", @@ -1086,12 +1073,15 @@ static nghttp3_callbacks ngh3_callbacks = { NULL, /* end_stream */ cb_h3_reset_stream, NULL, /* shutdown */ - NULL, /* recv_settings */ -#ifdef NGHTTP3_CALLBACKS_V2 + NULL, /* recv_settings (deprecated) */ +#ifdef NGHTTP3_CALLBACKS_V2 /* nghttp3 v1.11.0+ */ NULL, /* recv_origin */ NULL, /* end_origin */ NULL, /* rand */ #endif +#ifdef NGHTTP3_CALLBACKS_V3 /* nghttp3 v1.14.0+ */ + NULL, /* recv_settings2 */ +#endif }; static CURLcode cf_osslq_h3conn_init(struct cf_osslq_ctx *ctx, SSL *conn, @@ -1113,21 +1103,21 @@ static CURLcode cf_osslq_h3conn_init(struct cf_osslq_ctx *ctx, SSL *conn, } result = cf_osslq_stream_open(&h3->s_ctrl, conn, - SSL_STREAM_FLAG_ADVANCE|SSL_STREAM_FLAG_UNI, + SSL_STREAM_FLAG_ADVANCE | SSL_STREAM_FLAG_UNI, &ctx->stream_bufcp, NULL); if(result) { result = CURLE_QUIC_CONNECT_ERROR; goto out; } result = cf_osslq_stream_open(&h3->s_qpack_enc, conn, - SSL_STREAM_FLAG_ADVANCE|SSL_STREAM_FLAG_UNI, + SSL_STREAM_FLAG_ADVANCE | SSL_STREAM_FLAG_UNI, &ctx->stream_bufcp, NULL); if(result) { result = CURLE_QUIC_CONNECT_ERROR; goto out; } result = cf_osslq_stream_open(&h3->s_qpack_dec, conn, - SSL_STREAM_FLAG_ADVANCE|SSL_STREAM_FLAG_UNI, + SSL_STREAM_FLAG_ADVANCE | SSL_STREAM_FLAG_UNI, &ctx->stream_bufcp, NULL); if(result) { result = CURLE_QUIC_CONNECT_ERROR; @@ -1170,7 +1160,7 @@ static CURLcode cf_osslq_ctx_start(struct Curl_cfilter *cf, if(result) goto out; - result = vquic_ctx_init(&ctx->q); + result = vquic_ctx_init(data, &ctx->q); if(result) goto out; @@ -1228,7 +1218,8 @@ static CURLcode cf_osslq_ctx_start(struct Curl_cfilter *cf, SSL_INCOMING_STREAM_POLICY_ACCEPT, 0); /* from our side, there is no idle timeout */ SSL_set_value_uint(ctx->tls.ossl.ssl, - SSL_VALUE_CLASS_FEATURE_REQUEST, SSL_VALUE_QUIC_IDLE_TIMEOUT, 0); + SSL_VALUE_CLASS_FEATURE_REQUEST, + SSL_VALUE_QUIC_IDLE_TIMEOUT, 0); /* setup the H3 things on top of the QUIC connection */ result = cf_osslq_h3conn_init(ctx, ctx->tls.ossl.ssl, cf); @@ -1261,7 +1252,7 @@ static CURLcode h3_quic_recv(void *reader_ctx, return CURLE_AGAIN; } else if(detail == SSL_ERROR_ZERO_RETURN) { - CURL_TRC_CF(x->data, x->cf, "[%" FMT_PRId64 "] h3_quic_recv -> EOS", + CURL_TRC_CF(x->data, x->cf, "[%" PRId64 "] h3_quic_recv -> EOS", x->s->id); x->s->recvd_eos = TRUE; return CURLE_OK; @@ -1274,9 +1265,9 @@ static CURLcode h3_quic_recv(void *reader_ctx, return CURLE_RECV_ERROR; } else { - CURL_TRC_CF(x->data, x->cf, "[%" FMT_PRId64 "] h3_quic_recv -> RESET, " - "rv=%d, app_err=%" FMT_PRIu64, - x->s->id, rv, (curl_uint64_t)app_error_code); + CURL_TRC_CF(x->data, x->cf, "[%" PRId64 "] h3_quic_recv -> RESET, " + "rv=%d, app_err=%" PRIu64, + x->s->id, rv, app_error_code); if(app_error_code != NGHTTP3_H3_NO_ERROR) x->s->reset = TRUE; } @@ -1331,7 +1322,7 @@ static CURLcode cf_osslq_stream_recv(struct cf_osslq_stream *s, while(Curl_bufq_peek(&s->recvbuf, &buf, &blen)) { nread = nghttp3_conn_read_stream(ctx->h3.conn, s->id, buf, blen, 0); - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] forward %zu bytes " + CURL_TRC_CF(data, cf, "[%" PRId64 "] forward %zu bytes " "to nghttp3 -> %zd", s->id, blen, nread); if(nread < 0) { failf(data, "nghttp3_conn_read_stream(len=%zu) error: %s", @@ -1371,7 +1362,7 @@ static CURLcode cf_osslq_stream_recv(struct cf_osslq_stream *s, rv = nghttp3_conn_close_stream(ctx->h3.conn, s->id, NGHTTP3_H3_NO_ERROR); s->closed = TRUE; - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] close nghttp3 stream -> %d", + CURL_TRC_CF(data, cf, "[%" PRId64 "] close nghttp3 stream -> %d", s->id, rv); if(rv < 0 && rv != NGHTTP3_ERR_STREAM_NOT_FOUND) { failf(data, "nghttp3_conn_close_stream returned error: %s", @@ -1384,7 +1375,7 @@ static CURLcode cf_osslq_stream_recv(struct cf_osslq_stream *s, } out: if(result) - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] cf_osslq_stream_recv -> %d", + CURL_TRC_CF(data, cf, "[%" PRId64 "] cf_osslq_stream_recv -> %d", s->id, result); return result; } @@ -1395,7 +1386,7 @@ struct cf_ossq_recv_ctx { CURLcode result; }; -static bool cf_osslq_iter_recv(unsigned int mid, void *val, void *user_data) +static bool cf_osslq_iter_recv(uint32_t mid, void *val, void *user_data) { struct h3_stream_ctx *stream = val; struct cf_ossq_recv_ctx *rctx = user_data; @@ -1458,7 +1449,7 @@ static CURLcode cf_progress_ingress(struct Curl_cfilter *cf, rctx.cf = cf; rctx.multi = data->multi; rctx.result = CURLE_OK; - Curl_uint_hash_visit(&ctx->streams, cf_osslq_iter_recv, &rctx); + Curl_uint32_hash_visit(&ctx->streams, cf_osslq_iter_recv, &rctx); result = rctx.result; } @@ -1473,7 +1464,7 @@ struct cf_ossq_fill_ctx { size_t n; }; -static bool cf_osslq_collect_block_send(unsigned int mid, void *val, +static bool cf_osslq_collect_block_send(uint32_t mid, void *val, void *user_data) { struct h3_stream_ctx *stream = val; @@ -1511,21 +1502,22 @@ static CURLcode cf_osslq_check_and_unblock(struct Curl_cfilter *cf, if(ctx->h3.conn) { struct cf_ossq_fill_ctx fill_ctx; - if(ctx->items_max < Curl_uint_hash_count(&ctx->streams)) { - size_t nmax = Curl_uint_hash_count(&ctx->streams); + if(ctx->items_max < Curl_uint32_hash_count(&ctx->streams)) { + size_t nmax = Curl_uint32_hash_count(&ctx->streams); ctx->items_max = 0; - tmpptr = realloc(ctx->poll_items, nmax * sizeof(SSL_POLL_ITEM)); + tmpptr = curlx_realloc(ctx->poll_items, nmax * sizeof(SSL_POLL_ITEM)); if(!tmpptr) { - free(ctx->poll_items); + curlx_free(ctx->poll_items); ctx->poll_items = NULL; res = CURLE_OUT_OF_MEMORY; goto out; } ctx->poll_items = tmpptr; - tmpptr = realloc(ctx->curl_items, nmax * sizeof(struct Curl_easy *)); + tmpptr = curlx_realloc(ctx->curl_items, + nmax * sizeof(struct Curl_easy *)); if(!tmpptr) { - free(ctx->curl_items); + curlx_free(ctx->curl_items); ctx->curl_items = NULL; res = CURLE_OUT_OF_MEMORY; goto out; @@ -1537,8 +1529,8 @@ static CURLcode cf_osslq_check_and_unblock(struct Curl_cfilter *cf, fill_ctx.ctx = ctx; fill_ctx.multi = data->multi; fill_ctx.n = 0; - Curl_uint_hash_visit(&ctx->streams, cf_osslq_collect_block_send, - &fill_ctx); + Curl_uint32_hash_visit(&ctx->streams, cf_osslq_collect_block_send, + &fill_ctx); poll_count = fill_ctx.n; if(poll_count) { CURL_TRC_CF(data, cf, "polling %zu blocked streams", poll_count); @@ -1547,7 +1539,7 @@ static CURLcode cf_osslq_check_and_unblock(struct Curl_cfilter *cf, res = CURLE_UNRECOVERABLE_POLL; if(!SSL_poll(ctx->poll_items, poll_count, sizeof(SSL_POLL_ITEM), &timeout, 0, &result_count)) - goto out; + goto out; res = CURLE_OK; @@ -1608,7 +1600,7 @@ static CURLcode h3_send_streams(struct Curl_cfilter *cf, s = cf_osslq_get_qstream(cf, data, stream_id); if(!s) { failf(data, "nghttp3_conn_writev_stream gave unknown stream %" - FMT_PRId64, (curl_int64_t)stream_id); + PRId64, stream_id); result = CURLE_SEND_ERROR; goto out; } @@ -1623,13 +1615,13 @@ static CURLcode h3_send_streams(struct Curl_cfilter *cf, uint64_t flags = (eos && ((i + 1) == n)) ? SSL_WRITE_FLAG_CONCLUDE : 0; written = vec[i].len; ok = !s->ssl || SSL_write_ex2(s->ssl, vec[i].base, vec[i].len, flags, - &written); + &written); if(ok && flags & SSL_WRITE_FLAG_CONCLUDE) eos_written = TRUE; if(ok) { /* As OpenSSL buffers the data, we count this as acknowledged * from nghttp3's point of view */ - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] send %zu bytes to QUIC ok", + CURL_TRC_CF(data, cf, "[%" PRId64 "] send %zu bytes to QUIC ok", s->id, vec[i].len); acked_len += vec[i].len; } @@ -1639,14 +1631,14 @@ static CURLcode h3_send_streams(struct Curl_cfilter *cf, case SSL_ERROR_WANT_WRITE: case SSL_ERROR_WANT_READ: /* QUIC blocked us from writing more */ - CURL_TRC_CF(data, cf, "[%"FMT_PRId64 "] send %zu bytes to " + CURL_TRC_CF(data, cf, "[%" PRId64 "] send %zu bytes to " "QUIC blocked", s->id, vec[i].len); written = 0; nghttp3_conn_block_stream(ctx->h3.conn, s->id); s->send_blocked = blocked = TRUE; break; default: - failf(data, "[%"FMT_PRId64 "] send %zu bytes to QUIC, SSL error %d", + failf(data, "[%" PRId64 "] send %zu bytes to QUIC, SSL error %d", s->id, vec[i].len, detail); result = cf_osslq_ssl_err(cf, data, detail, CURLE_HTTP3); goto out; @@ -1657,7 +1649,7 @@ static CURLcode h3_send_streams(struct Curl_cfilter *cf, if(acked_len > 0 || (eos && !s->send_blocked)) { /* Since QUIC buffers the data written internally, we can tell * nghttp3 that it can move forward on it */ - ctx->q.last_io = curlx_now(); + ctx->q.last_io = *Curl_pgrs_now(data); rv = nghttp3_conn_add_write_offset(ctx->h3.conn, s->id, acked_len); if(rv && rv != NGHTTP3_ERR_STREAM_NOT_FOUND) { failf(data, "nghttp3_conn_add_write_offset returned error: %s", @@ -1672,13 +1664,13 @@ static CURLcode h3_send_streams(struct Curl_cfilter *cf, result = CURLE_SEND_ERROR; goto out; } - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] forwarded %zu/%zu h3 bytes " + CURL_TRC_CF(data, cf, "[%" PRId64 "] forwarded %zu/%zu h3 bytes " "to QUIC, eos=%d", s->id, acked_len, total_len, eos); } if(eos && !s->send_blocked && !eos_written) { /* wrote everything and H3 indicates end of stream */ - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] closing QUIC stream", s->id); + CURL_TRC_CF(data, cf, "[%" PRId64 "] closing QUIC stream", s->id); SSL_stream_conclude(s->ssl, 0); } } @@ -1755,7 +1747,6 @@ static CURLcode cf_osslq_connect(struct Curl_cfilter *cf, struct cf_osslq_ctx *ctx = cf->ctx; CURLcode result = CURLE_OK; struct cf_call_data save; - struct curltime now; int err; if(cf->connected) { @@ -1771,11 +1762,10 @@ static CURLcode cf_osslq_connect(struct Curl_cfilter *cf, } *done = FALSE; - now = curlx_now(); CF_DATA_SAVE(save, cf, data); if(!ctx->tls.ossl.ssl) { - ctx->started_at = now; + ctx->started_at = *Curl_pgrs_now(data); result = cf_osslq_ctx_start(cf, data); if(result) goto out; @@ -1785,7 +1775,7 @@ static CURLcode cf_osslq_connect(struct Curl_cfilter *cf, int readable = SOCKET_READABLE(ctx->q.sockfd, 0); if(readable > 0 && (readable & CURL_CSELECT_IN)) { ctx->got_first_byte = TRUE; - ctx->first_byte_at = curlx_now(); + ctx->first_byte_at = *Curl_pgrs_now(data); } } @@ -1802,33 +1792,39 @@ static CURLcode cf_osslq_connect(struct Curl_cfilter *cf, if(err == 1) { /* connected */ - ctx->handshake_at = now; - ctx->q.last_io = now; - CURL_TRC_CF(data, cf, "handshake complete after %dms", - (int)curlx_timediff(now, ctx->started_at)); + if(!ctx->got_first_byte) { + /* if not recorded yet, take the timestamp before we called + * SSL_do_handshake() as the time we received the first packet. */ + ctx->got_first_byte = TRUE; + ctx->first_byte_at = *Curl_pgrs_now(data); + } + /* Record the handshake complete with a new time stamp. */ + ctx->handshake_at = *Curl_pgrs_now(data); + ctx->q.last_io = *Curl_pgrs_now(data); + CURL_TRC_CF(data, cf, "handshake complete after %" FMT_TIMEDIFF_T "ms", + curlx_ptimediff_ms(Curl_pgrs_now(data), &ctx->started_at)); result = cf_osslq_verify_peer(cf, data); if(!result) { CURL_TRC_CF(data, cf, "peer verified"); cf->connected = TRUE; *done = TRUE; - connkeep(cf->conn, "HTTP/3 default"); } } else { int detail = SSL_get_error(ctx->tls.ossl.ssl, err); switch(detail) { case SSL_ERROR_WANT_READ: - ctx->q.last_io = now; + ctx->q.last_io = *Curl_pgrs_now(data); CURL_TRC_CF(data, cf, "QUIC SSL_connect() -> WANT_RECV"); goto out; case SSL_ERROR_WANT_WRITE: - ctx->q.last_io = now; + ctx->q.last_io = *Curl_pgrs_now(data); CURL_TRC_CF(data, cf, "QUIC SSL_connect() -> WANT_SEND"); result = CURLE_OK; goto out; #ifdef SSL_ERROR_WANT_ASYNC case SSL_ERROR_WANT_ASYNC: - ctx->q.last_io = now; + ctx->q.last_io = *Curl_pgrs_now(data); CURL_TRC_CF(data, cf, "QUIC SSL_connect() -> WANT_ASYNC"); result = CURLE_OK; goto out; @@ -1871,10 +1867,10 @@ static CURLcode cf_osslq_connect(struct Curl_cfilter *cf, return result; } -static ssize_t h3_stream_open(struct Curl_cfilter *cf, - struct Curl_easy *data, - const void *buf, size_t len, - CURLcode *err) +static CURLcode h3_stream_open(struct Curl_cfilter *cf, + struct Curl_easy *data, + const uint8_t *buf, size_t len, + size_t *pnwritten) { struct cf_osslq_ctx *ctx = cf->ctx; struct h3_stream_ctx *stream = NULL; @@ -1883,24 +1879,27 @@ static ssize_t h3_stream_open(struct Curl_cfilter *cf, nghttp3_nv *nva = NULL; int rc = 0; unsigned int i; - ssize_t nwritten = -1; nghttp3_data_reader reader; nghttp3_data_reader *preader = NULL; + CURLcode result; Curl_dynhds_init(&h2_headers, 0, DYN_HTTP_REQUEST); - *err = h3_data_setup(cf, data); - if(*err) + result = h3_data_setup(cf, data); + if(result) goto out; stream = H3_STREAM_CTX(ctx, data); DEBUGASSERT(stream); if(!stream) { - *err = CURLE_FAILED_INIT; + result = CURLE_FAILED_INIT; goto out; } - nwritten = Curl_h1_req_parse_read(&stream->h1, buf, len, NULL, 0, err); - if(nwritten < 0) + result = Curl_h1_req_parse_read(&stream->h1, buf, len, NULL, + !data->state.http_ignorecustom ? + data->set.str[STRING_CUSTOMREQUEST] : NULL, + 0, pnwritten); + if(result) goto out; if(!stream->h1.done) { /* need more data */ @@ -1908,19 +1907,16 @@ static ssize_t h3_stream_open(struct Curl_cfilter *cf, } DEBUGASSERT(stream->h1.req); - *err = Curl_http_req_to_h2(&h2_headers, stream->h1.req, data); - if(*err) { - nwritten = -1; + result = Curl_http_req_to_h2(&h2_headers, stream->h1.req, data); + if(result) goto out; - } /* no longer needed */ Curl_h1_req_parse_free(&stream->h1); nheader = Curl_dynhds_count(&h2_headers); - nva = malloc(sizeof(nghttp3_nv) * nheader); + nva = curlx_malloc(sizeof(nghttp3_nv) * nheader); if(!nva) { - *err = CURLE_OUT_OF_MEMORY; - nwritten = -1; + result = CURLE_OUT_OF_MEMORY; goto out; } @@ -1934,11 +1930,11 @@ static ssize_t h3_stream_open(struct Curl_cfilter *cf, } DEBUGASSERT(stream->s.id == -1); - *err = cf_osslq_stream_open(&stream->s, ctx->tls.ossl.ssl, 0, - &ctx->stream_bufcp, data); - if(*err) { + result = cf_osslq_stream_open(&stream->s, ctx->tls.ossl.ssl, 0, + &ctx->stream_bufcp, data); + if(result) { failf(data, "cannot get bidi streams"); - *err = CURLE_SEND_ERROR; + result = CURLE_SEND_ERROR; goto out; } @@ -1971,24 +1967,23 @@ static ssize_t h3_stream_open(struct Curl_cfilter *cf, if(rc) { switch(rc) { case NGHTTP3_ERR_CONN_CLOSING: - CURL_TRC_CF(data, cf, "h3sid[%"FMT_PRId64"] failed to send, " + CURL_TRC_CF(data, cf, "h3sid[%" PRId64 "] failed to send, " "connection is closing", stream->s.id); break; default: - CURL_TRC_CF(data, cf, "h3sid[%"FMT_PRId64 "] failed to send -> %d (%s)", + CURL_TRC_CF(data, cf, "h3sid[%" PRId64 "] failed to send -> %d (%s)", stream->s.id, rc, nghttp3_strerror(rc)); break; } - *err = CURLE_SEND_ERROR; - nwritten = -1; + result = CURLE_SEND_ERROR; goto out; } if(Curl_trc_is_verbose(data)) { - infof(data, "[HTTP/3] [%" FMT_PRId64 "] OPENED stream for %s", - stream->s.id, data->state.url); + infof(data, "[HTTP/3] [%" PRId64 "] OPENED stream for %s", + stream->s.id, Curl_bufref_ptr(&data->state.url)); for(i = 0; i < nheader; ++i) { - infof(data, "[HTTP/3] [%" FMT_PRId64 "] [%.*s: %.*s]", + infof(data, "[HTTP/3] [%" PRId64 "] [%.*s: %.*s]", stream->s.id, (int)nva[i].namelen, nva[i].name, (int)nva[i].valuelen, nva[i].value); @@ -1996,19 +1991,18 @@ static ssize_t h3_stream_open(struct Curl_cfilter *cf, } out: - free(nva); + curlx_free(nva); Curl_dynhds_free(&h2_headers); - return nwritten; + return result; } static CURLcode cf_osslq_send(struct Curl_cfilter *cf, struct Curl_easy *data, - const void *buf, size_t len, bool eos, + const uint8_t *buf, size_t len, bool eos, size_t *pnwritten) { struct cf_osslq_ctx *ctx = cf->ctx; - struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); + struct h3_stream_ctx *stream = NULL; struct cf_call_data save; - ssize_t nwritten; CURLcode result = CURLE_OK; (void)eos; /* use to end stream */ @@ -2026,14 +2020,14 @@ static CURLcode cf_osslq_send(struct Curl_cfilter *cf, struct Curl_easy *data, if(result) goto out; + stream = H3_STREAM_CTX(ctx, data); if(!stream || stream->s.id < 0) { - nwritten = h3_stream_open(cf, data, buf, len, &result); - if(nwritten < 0) { + result = h3_stream_open(cf, data, buf, len, pnwritten); + if(result) { CURL_TRC_CF(data, cf, "failed to open stream -> %d", result); goto out; } stream = H3_STREAM_CTX(ctx, data); - *pnwritten = (size_t)nwritten; } else if(stream->closed) { if(stream->resp_hds_complete) { @@ -2042,20 +2036,20 @@ static CURLcode cf_osslq_send(struct Curl_cfilter *cf, struct Curl_easy *data, * body. This happens on 30x or 40x responses. * We silently discard the data sent, since this is not a transport * error situation. */ - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] discarding data" + CURL_TRC_CF(data, cf, "[%" PRId64 "] discarding data" "on closed stream with response", stream->s.id); result = CURLE_OK; *pnwritten = len; goto out; } - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] send_body(len=%zu) " + CURL_TRC_CF(data, cf, "[%" PRId64 "] send_body(len=%zu) " "-> stream closed", stream->s.id, len); result = CURLE_HTTP3; goto out; } else { result = Curl_bufq_write(&stream->sendbuf, buf, len, pnwritten); - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] cf_send, add to " + CURL_TRC_CF(data, cf, "[%" PRId64 "] cf_send, add to " "sendbuf(len=%zu) -> %d, %zu", stream->s.id, len, result, *pnwritten); if(result) @@ -2068,7 +2062,7 @@ static CURLcode cf_osslq_send(struct Curl_cfilter *cf, struct Curl_easy *data, out: result = Curl_1st_err(result, check_and_set_expiry(cf, data)); - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] cf_send(len=%zu) -> %d, %zu", + CURL_TRC_CF(data, cf, "[%" PRId64 "] cf_send(len=%zu) -> %d, %zu", stream ? stream->s.id : -1, len, result, *pnwritten); CF_DATA_RESTORE(cf, save); return result; @@ -2083,13 +2077,13 @@ static CURLcode recv_closed_stream(struct Curl_cfilter *cf, *pnread = 0; if(stream->reset) { failf(data, - "HTTP/3 stream %" FMT_PRId64 " reset by server", + "HTTP/3 stream %" PRId64 " reset by server", stream->s.id); return data->req.bytecount ? CURLE_PARTIAL_FILE : CURLE_HTTP3; } else if(!stream->resp_hds_complete) { failf(data, - "HTTP/3 stream %" FMT_PRId64 + "HTTP/3 stream %" PRId64 " was closed cleanly, but before getting" " all response header fields, treated as error", stream->s.id); @@ -2102,18 +2096,17 @@ static CURLcode cf_osslq_recv(struct Curl_cfilter *cf, struct Curl_easy *data, char *buf, size_t len, size_t *pnread) { struct cf_osslq_ctx *ctx = cf->ctx; - struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); + struct h3_stream_ctx *stream; struct cf_call_data save; CURLcode result = CURLE_OK; - (void)ctx; CF_DATA_SAVE(save, cf, data); DEBUGASSERT(cf->connected); - DEBUGASSERT(ctx); DEBUGASSERT(ctx->tls.ossl.ssl); DEBUGASSERT(ctx->h3.conn); *pnread = 0; + stream = H3_STREAM_CTX(ctx, data); if(!stream) { result = CURLE_RECV_ERROR; goto out; @@ -2122,8 +2115,8 @@ static CURLcode cf_osslq_recv(struct Curl_cfilter *cf, struct Curl_easy *data, if(!Curl_bufq_is_empty(&stream->recvbuf)) { result = Curl_bufq_cread(&stream->recvbuf, buf, len, pnread); if(result) { - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] read recvbuf(len=%zu) " - "-> %d, %zu", stream->s.id, len, result, *pnread); + CURL_TRC_CF(data, cf, "[%" PRId64 "] read recvbuf(len=%zu) -> %d, %zu", + stream->s.id, len, result, *pnread); goto out; } } @@ -2136,8 +2129,8 @@ static CURLcode cf_osslq_recv(struct Curl_cfilter *cf, struct Curl_easy *data, if(!*pnread && !Curl_bufq_is_empty(&stream->recvbuf)) { result = Curl_bufq_cread(&stream->recvbuf, buf, len, pnread); if(result) { - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] read recvbuf(len=%zu) " - "-> %d, %zu", stream->s.id, len, result, *pnread); + CURL_TRC_CF(data, cf, "[%" PRId64 "] read recvbuf(len=%zu) -> %d, %zu", + stream->s.id, len, result, *pnread); goto out; } } @@ -2157,7 +2150,7 @@ static CURLcode cf_osslq_recv(struct Curl_cfilter *cf, struct Curl_easy *data, result = Curl_1st_err(result, cf_progress_egress(cf, data)); result = Curl_1st_err(result, check_and_set_expiry(cf, data)); - CURL_TRC_CF(data, cf, "[%" FMT_PRId64 "] cf_recv(len=%zu) -> %d, %zu", + CURL_TRC_CF(data, cf, "[%" PRId64 "] cf_recv(len=%zu) -> %d, %zu", stream ? stream->s.id : -1, len, result, *pnread); CF_DATA_RESTORE(cf, save); return result; @@ -2244,9 +2237,8 @@ static bool cf_osslq_conn_is_alive(struct Curl_cfilter *cf, "assume connection is dead."); goto out; } - CURL_TRC_CF(data, cf, "negotiated idle timeout: %" FMT_PRIu64 "ms", - (curl_uint64_t)idle_ms); - idletime = curlx_timediff(curlx_now(), ctx->q.last_io); + CURL_TRC_CF(data, cf, "negotiated idle timeout: %" PRIu64 "ms", idle_ms); + idletime = curlx_ptimediff_ms(Curl_pgrs_now(data), &ctx->q.last_io); if(idle_ms && idletime > 0 && (uint64_t)idletime > idle_ms) goto out; } @@ -2326,7 +2318,7 @@ static CURLcode cf_osslq_query(struct Curl_cfilter *cf, return CURLE_HTTP3; } /* we report avail + in_use */ - v += CONN_ATTACHED(cf->conn); + v += cf->conn->attached_xfers; *pres1 = (v > INT_MAX) ? INT_MAX : (int)v; #else *pres1 = 100; @@ -2336,7 +2328,8 @@ static CURLcode cf_osslq_query(struct Curl_cfilter *cf, } case CF_QUERY_CONNECT_REPLY_MS: if(ctx->got_first_byte) { - timediff_t ms = curlx_timediff(ctx->first_byte_at, ctx->started_at); + timediff_t ms = curlx_ptimediff_ms(&ctx->first_byte_at, + &ctx->started_at); *pres1 = (ms < INT_MAX) ? (int)ms : INT_MAX; } else @@ -2407,7 +2400,7 @@ CURLcode Curl_cf_osslq_create(struct Curl_cfilter **pcf, CURLcode result; (void)data; - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { result = CURLE_OUT_OF_MEMORY; goto out; diff --git a/vendor/hydra/vendor/curl/lib/vquic/curl_osslq.h b/vendor/hydra/vendor/curl/lib/vquic/curl_osslq.h index 9f5025f8..7aa93d67 100644 --- a/vendor/hydra/vendor/curl/lib/vquic/curl_osslq.h +++ b/vendor/hydra/vendor/curl/lib/vquic/curl_osslq.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "../curl_setup.h" #if !defined(CURL_DISABLE_HTTP) && defined(USE_OPENSSL_QUIC) && \ diff --git a/vendor/hydra/vendor/curl/lib/vquic/curl_quiche.c b/vendor/hydra/vendor/curl/lib/vquic/curl_quiche.c index a2ab24ba..e4140e77 100644 --- a/vendor/hydra/vendor/curl/lib/vquic/curl_quiche.c +++ b/vendor/hydra/vendor/curl/lib/vquic/curl_quiche.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "../curl_setup.h" #if !defined(CURL_DISABLE_HTTP) && defined(USE_QUICHE) @@ -33,7 +32,7 @@ #include "../urldata.h" #include "../cfilters.h" #include "../cf-socket.h" -#include "../sendf.h" +#include "../curl_trc.h" #include "../rand.h" #include "../multiif.h" #include "../connect.h" @@ -46,15 +45,11 @@ #include "curl_quiche.h" #include "../transfer.h" #include "../url.h" -#include "../curlx/inet_pton.h" +#include "../bufref.h" #include "../vtls/openssl.h" #include "../vtls/keylog.h" #include "../vtls/vtls.h" -/* The last 2 #include files should be in this order */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* HTTP/3 error values defined in RFC 9114, ch. 8.1 */ #define CURL_H3_NO_ERROR (0x0100) @@ -67,11 +62,11 @@ * stream buffer to not keep spares. Memory consumption goes down when streams * run empty, have a large upload done, etc. */ #define H3_STREAM_POOL_SPARES \ - (H3_STREAM_WINDOW_SIZE / H3_STREAM_CHUNK_SIZE ) / 2 + (H3_STREAM_WINDOW_SIZE / H3_STREAM_CHUNK_SIZE) / 2 /* Receive and Send max number of chunks just follows from the * chunk size and window size */ #define H3_STREAM_RECV_CHUNKS \ - (H3_STREAM_WINDOW_SIZE / H3_STREAM_CHUNK_SIZE) + (H3_STREAM_WINDOW_SIZE / H3_STREAM_CHUNK_SIZE) /* * Store quiche version info in this buffer. @@ -92,8 +87,9 @@ struct cf_quiche_ctx { uint8_t scid[QUICHE_MAX_CONN_ID_LEN]; struct curltime started_at; /* time the current attempt started */ struct curltime handshake_at; /* time connect handshake finished */ - struct bufc_pool stream_bufcp; /* chunk pool for streams */ struct uint_hash streams; /* hash `data->mid` to `stream_ctx` */ + struct dynbuf h1hdr; /* temp buffer for header construction */ + struct bufq writebuf; /* temp buffer for writing bodies */ curl_off_t data_recvd; BIT(initialized); BIT(goaway); /* got GOAWAY from server */ @@ -122,9 +118,10 @@ static void cf_quiche_ctx_init(struct cf_quiche_ctx *ctx) debug_log_init = 1; } #endif - Curl_bufcp_init(&ctx->stream_bufcp, H3_STREAM_CHUNK_SIZE, - H3_STREAM_POOL_SPARES); - Curl_uint_hash_init(&ctx->streams, 63, h3_stream_hash_free); + curlx_dyn_init(&ctx->h1hdr, CURL_MAX_HTTP_HEADER); + Curl_uint32_hash_init(&ctx->streams, 63, h3_stream_hash_free); + Curl_bufq_init2(&ctx->writebuf, H3_STREAM_CHUNK_SIZE, H3_STREAM_RECV_CHUNKS, + BUFQ_OPT_SOFT_LIMIT); ctx->data_recvd = 0; ctx->initialized = TRUE; } @@ -137,10 +134,11 @@ static void cf_quiche_ctx_free(struct cf_quiche_ctx *ctx) Curl_vquic_tls_cleanup(&ctx->tls); Curl_ssl_peer_cleanup(&ctx->peer); vquic_ctx_free(&ctx->q); - Curl_bufcp_free(&ctx->stream_bufcp); - Curl_uint_hash_destroy(&ctx->streams); + Curl_uint32_hash_destroy(&ctx->streams); + curlx_dyn_free(&ctx->h1hdr); + Curl_bufq_free(&ctx->writebuf); } - free(ctx); + curlx_free(ctx); } static void cf_quiche_ctx_close(struct cf_quiche_ctx *ctx) @@ -170,24 +168,24 @@ static CURLcode cf_flush_egress(struct Curl_cfilter *cf, * All about the H3 internals of a stream */ struct h3_stream_ctx { - curl_uint64_t id; /* HTTP/3 protocol stream identifier */ - struct bufq recvbuf; /* h3 response */ + uint64_t id; /* HTTP/3 protocol stream identifier */ struct h1_req_parser h1; /* h1 request parsing */ - curl_uint64_t error3; /* HTTP/3 stream error code */ - BIT(opened); /* TRUE after stream has been opened */ - BIT(closed); /* TRUE on stream close */ - BIT(reset); /* TRUE on stream reset */ - BIT(send_closed); /* stream is locally closed */ + uint64_t error3; /* HTTP/3 stream error code */ + int status_code; /* HTTP status code */ + CURLcode xfer_result; /* result from cf_quiche_write_(hd/body) */ + BIT(opened); /* TRUE after stream has been opened */ + BIT(closed); /* TRUE on stream close */ + BIT(reset); /* TRUE on stream reset */ + BIT(send_closed); /* stream is locally closed */ BIT(resp_hds_complete); /* final response has been received */ - BIT(resp_got_header); /* TRUE when h3 stream has recvd some HEADER */ - BIT(quic_flow_blocked); /* stream is blocked by QUIC flow control */ + BIT(resp_got_header); /* TRUE when h3 stream has recvd some HEADER */ + BIT(quic_flow_blocked); /* stream is blocked by QUIC flow control */ }; static void h3_stream_ctx_free(struct h3_stream_ctx *stream) { - Curl_bufq_free(&stream->recvbuf); Curl_h1_req_parse_free(&stream->h1); - free(stream); + curlx_free(stream); } static void h3_stream_hash_free(unsigned int id, void *stream) @@ -209,7 +207,7 @@ struct cf_quiche_visit_ctx { void *user_data; }; -static bool cf_quiche_stream_do(unsigned int mid, void *val, void *user_data) +static bool cf_quiche_stream_do(uint32_t mid, void *val, void *user_data) { struct cf_quiche_visit_ctx *vctx = user_data; struct h3_stream_ctx *stream = val; @@ -230,7 +228,7 @@ static void cf_quiche_for_all_streams(struct Curl_cfilter *cf, vctx.multi = multi; vctx.cb = do_cb; vctx.user_data = user_data; - Curl_uint_hash_visit(&ctx->streams, cf_quiche_stream_do, &vctx); + Curl_uint32_hash_visit(&ctx->streams, cf_quiche_stream_do, &vctx); } static bool cf_quiche_do_resume(struct Curl_cfilter *cf, @@ -242,7 +240,7 @@ static bool cf_quiche_do_resume(struct Curl_cfilter *cf, if(stream->quic_flow_blocked) { stream->quic_flow_blocked = FALSE; Curl_multi_mark_dirty(sdata); - CURL_TRC_CF(sdata, cf, "[%"FMT_PRIu64"] unblock", stream->id); + CURL_TRC_CF(sdata, cf, "[%" PRIu64 "] unblock", stream->id); } return TRUE; } @@ -255,6 +253,7 @@ static bool cf_quiche_do_expire(struct Curl_cfilter *cf, (void)stream; (void)user_data; CURL_TRC_CF(sdata, cf, "conn closed, mark as dirty"); + stream->xfer_result = CURLE_SEND_ERROR; Curl_multi_mark_dirty(sdata); return TRUE; } @@ -268,16 +267,14 @@ static CURLcode h3_data_setup(struct Curl_cfilter *cf, if(stream) return CURLE_OK; - stream = calloc(1, sizeof(*stream)); + stream = curlx_calloc(1, sizeof(*stream)); if(!stream) return CURLE_OUT_OF_MEMORY; stream->id = -1; - Curl_bufq_initp(&stream->recvbuf, &ctx->stream_bufcp, - H3_STREAM_RECV_CHUNKS, BUFQ_OPT_SOFT_LIMIT); Curl_h1_req_parse_init(&stream->h1, H1_PARSE_DEFAULT_MAX_LINE_LEN); - if(!Curl_uint_hash_set(&ctx->streams, data->mid, stream)) { + if(!Curl_uint32_hash_set(&ctx->streams, data->mid, stream)) { h3_stream_ctx_free(stream); return CURLE_OUT_OF_MEMORY; } @@ -285,29 +282,39 @@ static CURLcode h3_data_setup(struct Curl_cfilter *cf, return CURLE_OK; } +static void cf_quiche_stream_close(struct Curl_cfilter *cf, + struct Curl_easy *data, + struct h3_stream_ctx *stream) +{ + struct cf_quiche_ctx *ctx = cf->ctx; + CURLcode result; + + if(ctx->qconn && !stream->closed) { + quiche_conn_stream_shutdown(ctx->qconn, stream->id, + QUICHE_SHUTDOWN_READ, CURL_H3_NO_ERROR); + if(!stream->send_closed) { + quiche_conn_stream_shutdown(ctx->qconn, stream->id, + QUICHE_SHUTDOWN_WRITE, CURL_H3_NO_ERROR); + stream->send_closed = TRUE; + } + stream->closed = TRUE; + result = cf_flush_egress(cf, data); + if(result) + CURL_TRC_CF(data, cf, "[%" PRIu64 "] stream close, flush egress -> %d", + stream->id, result); + } +} + static void h3_data_done(struct Curl_cfilter *cf, struct Curl_easy *data) { struct cf_quiche_ctx *ctx = cf->ctx; struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); - CURLcode result; (void)cf; if(stream) { - CURL_TRC_CF(data, cf, "[%"FMT_PRIu64"] easy handle is done", stream->id); - if(ctx->qconn && !stream->closed) { - quiche_conn_stream_shutdown(ctx->qconn, stream->id, - QUICHE_SHUTDOWN_READ, CURL_H3_NO_ERROR); - if(!stream->send_closed) { - quiche_conn_stream_shutdown(ctx->qconn, stream->id, - QUICHE_SHUTDOWN_WRITE, CURL_H3_NO_ERROR); - stream->send_closed = TRUE; - } - stream->closed = TRUE; - result = cf_flush_egress(cf, data); - if(result) - CURL_TRC_CF(data, cf, "data_done, flush egress -> %d", result); - } - Curl_uint_hash_remove(&ctx->streams, data->mid); + CURL_TRC_CF(data, cf, "[%" PRIu64 "] easy handle is done", stream->id); + cf_quiche_stream_close(cf, data, stream); + Curl_uint32_hash_remove(&ctx->streams, data->mid); } } @@ -319,79 +326,106 @@ static void cf_quiche_expire_conn_closed(struct Curl_cfilter *cf, cf_quiche_for_all_streams(cf, data->multi, cf_quiche_do_expire, NULL); } -/* - * write_resp_raw() copies response data in raw format to the `data`'s - * receive buffer. If not enough space is available, it appends to the - * `data`'s overflow buffer. - */ -static CURLcode write_resp_raw(struct Curl_cfilter *cf, +static void cf_quiche_write_hd(struct Curl_cfilter *cf, struct Curl_easy *data, - const void *mem, size_t memlen) + struct h3_stream_ctx *stream, + const char *buf, size_t blen, bool eos) { - struct cf_quiche_ctx *ctx = cf->ctx; - struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); - CURLcode result = CURLE_OK; - size_t nwritten; - - (void)cf; - if(!stream) - return CURLE_RECV_ERROR; - result = Curl_bufq_write(&stream->recvbuf, mem, memlen, &nwritten); - if(result) - return result; - - if(nwritten < memlen) { - /* This MUST not happen. Our recbuf is dimensioned to hold the - * full max_stream_window and then some for this very reason. */ - DEBUGASSERT(0); - return CURLE_RECV_ERROR; + /* This function returns no error intentionally, but records + * the result at the stream, skipping further writes once the + * `result` of the transfer is known. + * The stream is subsequently cancelled "higher up" in the filter's + * send/recv callbacks. Closing the stream here leads to SEND/RECV + * errors in other places that then overwrite the transfer's result. */ + if(!stream->xfer_result) { + stream->xfer_result = Curl_xfer_write_resp_hd(data, buf, blen, eos); + if(stream->xfer_result) + CURL_TRC_CF(data, cf, "[%" PRId64 "] error %d writing %zu " + "bytes of headers", stream->id, stream->xfer_result, blen); } - return result; } struct cb_ctx { struct Curl_cfilter *cf; struct Curl_easy *data; + struct h3_stream_ctx *stream; }; +static bool is_valid_h3_header(const uint8_t *hdr, size_t hlen) +{ + while(hlen--) { + switch(*hdr++) { + case '\n': + case '\r': + case '\0': + return FALSE; + } + } + return TRUE; +} + static int cb_each_header(uint8_t *name, size_t name_len, uint8_t *value, size_t value_len, void *argp) { struct cb_ctx *x = argp; - struct cf_quiche_ctx *ctx = x->cf->ctx; - struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, x->data); - CURLcode result; + struct Curl_cfilter *cf = x->cf; + struct Curl_easy *data = x->data; + struct h3_stream_ctx *stream = x->stream; + struct cf_quiche_ctx *ctx = cf->ctx; + CURLcode result = CURLE_OK; - if(!stream) - return CURLE_OK; + if(!stream || stream->xfer_result) + return 1; /* abort iteration */ - if((name_len == 7) && !strncmp(HTTP_PSEUDO_STATUS, (char *)name, 7)) { - CURL_TRC_CF(x->data, x->cf, "[%" FMT_PRIu64 "] status: %.*s", - stream->id, (int)value_len, value); - result = write_resp_raw(x->cf, x->data, "HTTP/3 ", sizeof("HTTP/3 ") - 1); + if((name_len == 7) && !strncmp(HTTP_PSEUDO_STATUS, (char *)name, 7) && + is_valid_h3_header(value, value_len)) { + curlx_dyn_reset(&ctx->h1hdr); + result = Curl_http_decode_status(&stream->status_code, + (const char *)value, value_len); if(!result) - result = write_resp_raw(x->cf, x->data, value, value_len); + result = curlx_dyn_addn(&ctx->h1hdr, STRCONST("HTTP/3 ")); if(!result) - result = write_resp_raw(x->cf, x->data, " \r\n", 3); - } - else { - CURL_TRC_CF(x->data, x->cf, "[%" FMT_PRIu64 "] header: %.*s: %.*s", - stream->id, (int)name_len, name, - (int)value_len, value); - result = write_resp_raw(x->cf, x->data, name, name_len); - if(!result) - result = write_resp_raw(x->cf, x->data, ": ", 2); + result = curlx_dyn_addn(&ctx->h1hdr, (const char *)value, value_len); if(!result) - result = write_resp_raw(x->cf, x->data, value, value_len); + result = curlx_dyn_addn(&ctx->h1hdr, STRCONST(" \r\n")); if(!result) - result = write_resp_raw(x->cf, x->data, "\r\n", 2); + cf_quiche_write_hd(cf, data, stream, curlx_dyn_ptr(&ctx->h1hdr), + curlx_dyn_len(&ctx->h1hdr), FALSE); + CURL_TRC_CF(data, cf, "[%" PRId64 "] status: %s", + stream->id, curlx_dyn_ptr(&ctx->h1hdr)); } + else { + if(is_valid_h3_header(value, value_len) && + is_valid_h3_header(name, name_len)) { + /* store as an HTTP1-style header */ + CURL_TRC_CF(data, cf, "[%" PRId64 "] header: %.*s: %.*s", + stream->id, (int)name_len, name, + (int)value_len, value); + curlx_dyn_reset(&ctx->h1hdr); + result = curlx_dyn_addn(&ctx->h1hdr, (const char *)name, name_len); + if(!result) + result = curlx_dyn_addn(&ctx->h1hdr, STRCONST(": ")); + if(!result) + result = curlx_dyn_addn(&ctx->h1hdr, (const char *)value, value_len); + if(!result) + result = curlx_dyn_addn(&ctx->h1hdr, STRCONST("\r\n")); + if(!result) + cf_quiche_write_hd(cf, data, stream, curlx_dyn_ptr(&ctx->h1hdr), + curlx_dyn_len(&ctx->h1hdr), FALSE); + } + else + CURL_TRC_CF(x->data, x->cf, "[%" PRIu64 "] ignore %zu bytes bad header", + stream->id, value_len + name_len); + } + if(result) { - CURL_TRC_CF(x->data, x->cf, "[%"FMT_PRIu64"] on header error %d", + CURL_TRC_CF(x->data, x->cf, "[%" PRIu64 "] on header error %d", stream->id, result); + if(!stream->xfer_result) + stream->xfer_result = result; } - return result; + return stream->xfer_result ? 1 : 0; } static CURLcode stream_resp_read(void *reader_ctx, @@ -408,160 +442,143 @@ static CURLcode stream_resp_read(void *reader_ctx, return CURLE_RECV_ERROR; nread = quiche_h3_recv_body(ctx->h3c, ctx->qconn, stream->id, buf, len); - if(nread >= 0) { - *pnread = (size_t)nread; - return CURLE_OK; - } - else + if(!curlx_sztouz(nread, pnread)) return CURLE_AGAIN; + return CURLE_OK; } -static CURLcode cf_recv_body(struct Curl_cfilter *cf, - struct Curl_easy *data) +static void cf_quiche_flush_body(struct Curl_cfilter *cf, + struct Curl_easy *data, + struct h3_stream_ctx *stream) +{ + struct cf_quiche_ctx *ctx = cf->ctx; + const uint8_t *buf; + size_t blen; + + while(stream && !stream->xfer_result) { + if(Curl_bufq_peek(&ctx->writebuf, &buf, &blen)) { + stream->xfer_result = Curl_xfer_write_resp( + data, (const char *)buf, blen, FALSE); + Curl_bufq_skip(&ctx->writebuf, blen); + if(stream->xfer_result) { + CURL_TRC_CF(data, cf, "[%" PRId64 "] error %d writing %zu bytes" + " of data", stream->id, stream->xfer_result, blen); + } + } + else + break; + } + Curl_bufq_reset(&ctx->writebuf); +} + +static void cf_quiche_recv_body(struct Curl_cfilter *cf, + struct Curl_easy *data, + struct h3_stream_ctx *stream) { struct cf_quiche_ctx *ctx = cf->ctx; - struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); size_t nread; struct cb_ctx cb_ctx; CURLcode result = CURLE_OK; if(!stream) - return CURLE_RECV_ERROR; - - if(!stream->resp_hds_complete) { - result = write_resp_raw(cf, data, "\r\n", 2); - if(result) - return result; - stream->resp_hds_complete = TRUE; - } + return; + /* Even when the transfer has already errored, we need to receive + * the data from quiche, as quiche will otherwise get stuck and + * raise events to receive over and over again. */ cb_ctx.cf = cf; cb_ctx.data = data; - result = Curl_bufq_slurp(&stream->recvbuf, - stream_resp_read, &cb_ctx, &nread); - - if(result && result != CURLE_AGAIN) { - CURL_TRC_CF(data, cf, "[%"FMT_PRIu64"] recv_body error %zu", - stream->id, nread); - failf(data, "Error %d in HTTP/3 response body for stream[%"FMT_PRIu64"]", - result, stream->id); - stream->closed = TRUE; - stream->reset = TRUE; - stream->send_closed = TRUE; - streamclose(cf->conn, "Reset of stream"); - return result; - } - return CURLE_OK; -} - -#ifdef DEBUGBUILD -static const char *cf_ev_name(quiche_h3_event *ev) -{ - switch(quiche_h3_event_type(ev)) { - case QUICHE_H3_EVENT_HEADERS: - return "HEADERS"; - case QUICHE_H3_EVENT_DATA: - return "DATA"; - case QUICHE_H3_EVENT_RESET: - return "RESET"; - case QUICHE_H3_EVENT_FINISHED: - return "FINISHED"; - case QUICHE_H3_EVENT_GOAWAY: - return "GOAWAY"; - default: - return "Unknown"; + cb_ctx.stream = stream; + Curl_bufq_reset(&ctx->writebuf); + while(!result) { + result = Curl_bufq_slurp(&ctx->writebuf, + stream_resp_read, &cb_ctx, &nread); + if(!result) + cf_quiche_flush_body(cf, data, stream); + else if(result == CURLE_AGAIN) + break; + else if(result) { + CURL_TRC_CF(data, cf, "[%" PRIu64 "] recv_body error %d", + stream->id, result); + failf(data, "[%" PRIu64 "] Error %d in HTTP/3 response body for stream", + stream->id, result); + stream->closed = TRUE; + stream->reset = TRUE; + stream->send_closed = TRUE; + if(!stream->xfer_result) + stream->xfer_result = result; + } } + cf_quiche_flush_body(cf, data, stream); } -#else -#define cf_ev_name(x) "" -#endif -static CURLcode h3_process_event(struct Curl_cfilter *cf, +static void cf_quiche_process_ev(struct Curl_cfilter *cf, struct Curl_easy *data, struct h3_stream_ctx *stream, quiche_h3_event *ev) { - struct cb_ctx cb_ctx; - CURLcode result = CURLE_OK; - int rc; - if(!stream) - return CURLE_OK; + return; + switch(quiche_h3_event_type(ev)) { - case QUICHE_H3_EVENT_HEADERS: + case QUICHE_H3_EVENT_HEADERS: { + struct cb_ctx cb_ctx; stream->resp_got_header = TRUE; cb_ctx.cf = cf; cb_ctx.data = data; - rc = quiche_h3_event_for_each_header(ev, cb_each_header, &cb_ctx); - if(rc) { - failf(data, "Error %d in HTTP/3 response header for stream[%" - FMT_PRIu64"]", rc, stream->id); - return CURLE_RECV_ERROR; - } - CURL_TRC_CF(data, cf, "[%"FMT_PRIu64"] <- [HEADERS]", stream->id); + cb_ctx.stream = stream; + quiche_h3_event_for_each_header(ev, cb_each_header, &cb_ctx); + CURL_TRC_CF(data, cf, "[%" PRIu64 "] <- [HEADERS]", stream->id); + Curl_multi_mark_dirty(data); break; - + } case QUICHE_H3_EVENT_DATA: - if(!stream->closed) { - result = cf_recv_body(cf, data); + if(!stream->resp_hds_complete) { + stream->resp_hds_complete = TRUE; + cf_quiche_write_hd(cf, data, stream, "\r\n", 2, FALSE); } + cf_quiche_recv_body(cf, data, stream); + CURL_TRC_CF(data, cf, "[%" PRIu64 "] <- [DATA]", stream->id); + Curl_multi_mark_dirty(data); break; case QUICHE_H3_EVENT_RESET: - CURL_TRC_CF(data, cf, "[%"FMT_PRIu64"] RESET", stream->id); + CURL_TRC_CF(data, cf, "[%" PRIu64 "] RESET", stream->id); stream->closed = TRUE; stream->reset = TRUE; stream->send_closed = TRUE; - streamclose(cf->conn, "Reset of stream"); + Curl_multi_mark_dirty(data); break; case QUICHE_H3_EVENT_FINISHED: - CURL_TRC_CF(data, cf, "[%"FMT_PRIu64"] CLOSED", stream->id); + CURL_TRC_CF(data, cf, "[%" PRIu64 "] CLOSED", stream->id); if(!stream->resp_hds_complete) { - result = write_resp_raw(cf, data, "\r\n", 2); - if(result) - return result; stream->resp_hds_complete = TRUE; + cf_quiche_write_hd(cf, data, stream, "\r\n", 2, TRUE); } stream->closed = TRUE; - streamclose(cf->conn, "End of stream"); + Curl_multi_mark_dirty(data); break; case QUICHE_H3_EVENT_GOAWAY: - CURL_TRC_CF(data, cf, "[%"FMT_PRIu64"] <- [GOAWAY]", stream->id); + CURL_TRC_CF(data, cf, "[%" PRIu64 "] <- [GOAWAY]", stream->id); break; default: - CURL_TRC_CF(data, cf, "[%"FMT_PRIu64"] recv, unhandled event %d", + CURL_TRC_CF(data, cf, "[%" PRIu64 "] recv, unhandled event %d", stream->id, quiche_h3_event_type(ev)); break; } - return result; -} - -static CURLcode cf_quiche_ev_process(struct Curl_cfilter *cf, - struct Curl_easy *data, - struct h3_stream_ctx *stream, - quiche_h3_event *ev) -{ - CURLcode result = h3_process_event(cf, data, stream, ev); - Curl_multi_mark_dirty(data); - if(result) - CURL_TRC_CF(data, cf, "error processing event %s " - "for [%"FMT_PRIu64"] -> %d", cf_ev_name(ev), - stream->id, result); - return result; } struct cf_quich_disp_ctx { - curl_uint64_t stream_id; + uint64_t stream_id; struct Curl_cfilter *cf; struct Curl_multi *multi; quiche_h3_event *ev; - CURLcode result; }; -static bool cf_quiche_disp_event(unsigned int mid, void *val, void *user_data) +static bool cf_quiche_disp_event(uint32_t mid, void *val, void *user_data) { struct cf_quich_disp_ctx *dctx = user_data; struct h3_stream_ctx *stream = val; @@ -569,7 +586,7 @@ static bool cf_quiche_disp_event(unsigned int mid, void *val, void *user_data) if(stream->id == dctx->stream_id) { struct Curl_easy *sdata = Curl_multi_get_easy(dctx->multi, mid); if(sdata) - dctx->result = cf_quiche_ev_process(dctx->cf, sdata, stream, dctx->ev); + cf_quiche_process_ev(dctx->cf, sdata, stream, dctx->ev); return FALSE; /* stop iterating */ } return TRUE; @@ -584,33 +601,32 @@ static CURLcode cf_poll_events(struct Curl_cfilter *cf, /* Take in the events and distribute them to the transfers. */ while(ctx->h3c) { - curl_int64_t stream3_id = quiche_h3_conn_poll(ctx->h3c, ctx->qconn, &ev); - if(stream3_id == QUICHE_H3_ERR_DONE) { + int64_t rv = quiche_h3_conn_poll(ctx->h3c, ctx->qconn, &ev); + if(rv == QUICHE_H3_ERR_DONE) { break; } - else if(stream3_id < 0) { - CURL_TRC_CF(data, cf, "error poll: %"FMT_PRId64, stream3_id); + else if(rv < 0) { + CURL_TRC_CF(data, cf, "error poll: %" PRId64, rv); return CURLE_HTTP3; } else { - struct cf_quich_disp_ctx dctx; - dctx.stream_id = (curl_uint64_t)stream3_id; - dctx.cf = cf; - dctx.multi = data->multi; - dctx.ev = ev; - dctx.result = CURLE_OK; stream = H3_STREAM_CTX(ctx, data); - if(stream && stream->id == dctx.stream_id) { + if(stream && stream->id == (uint64_t)rv) { /* event for calling transfer */ - CURLcode result = cf_quiche_ev_process(cf, data, stream, ev); + cf_quiche_process_ev(cf, data, stream, ev); quiche_h3_event_free(ev); - if(result) - return result; + if(stream->xfer_result) + return stream->xfer_result; } else { /* another transfer, do not return errors, as they are not for * the calling transfer */ - Curl_uint_hash_visit(&ctx->streams, cf_quiche_disp_event, &dctx); + struct cf_quich_disp_ctx dctx; + dctx.stream_id = (uint64_t)rv; + dctx.cf = cf; + dctx.multi = data->multi; + dctx.ev = ev; + Curl_uint32_hash_visit(&ctx->streams, cf_quiche_disp_event, &dctx); quiche_h3_event_free(ev); } } @@ -633,8 +649,8 @@ static CURLcode cf_quiche_recv_pkts(const unsigned char *buf, size_t buflen, struct recv_ctx *r = userp; struct cf_quiche_ctx *ctx = r->cf->ctx; quiche_recv_info recv_info; - size_t pktlen, offset; - ssize_t nread; + size_t pktlen, offset, nread; + ssize_t rv; (void)ecn; @@ -645,11 +661,11 @@ static CURLcode cf_quiche_recv_pkts(const unsigned char *buf, size_t buflen, for(offset = 0; offset < buflen; offset += gso_size) { pktlen = ((offset + gso_size) <= buflen) ? gso_size : (buflen - offset); - nread = quiche_conn_recv(ctx->qconn, - (unsigned char *)CURL_UNCONST(buf + offset), - pktlen, &recv_info); - if(nread < 0) { - if(QUICHE_ERR_DONE == nread) { + rv = quiche_conn_recv(ctx->qconn, + (unsigned char *)CURL_UNCONST(buf + offset), + pktlen, &recv_info); + if(!curlx_sztouz(rv, &nread)) { + if(QUICHE_ERR_DONE == rv) { if(quiche_conn_is_draining(ctx->qconn)) { CURL_TRC_CF(r->data, r->cf, "ingress, connection is draining"); return CURLE_RECV_ERROR; @@ -661,7 +677,7 @@ static CURLcode cf_quiche_recv_pkts(const unsigned char *buf, size_t buflen, CURL_TRC_CF(r->data, r->cf, "ingress, quiche is DONE"); return CURLE_OK; } - else if(QUICHE_ERR_TLS_FAIL == nread) { + else if(QUICHE_ERR_TLS_FAIL == rv) { long verify_ok = SSL_get_verify_result(ctx->tls.ossl.ssl); if(verify_ok != X509_V_OK) { failf(r->data, "SSL certificate problem: %s", @@ -672,12 +688,12 @@ static CURLcode cf_quiche_recv_pkts(const unsigned char *buf, size_t buflen, return CURLE_RECV_ERROR; } else { - failf(r->data, "quiche reports error %zd on receive", nread); + failf(r->data, "quiche reports error %zd on receive", rv); return CURLE_RECV_ERROR; } } - else if((size_t)nread < pktlen) { - CURL_TRC_CF(r->data, r->cf, "ingress, quiche only read %zd/%zu bytes", + else if(nread < pktlen) { + CURL_TRC_CF(r->data, r->cf, "ingress, quiche only read %zu/%zu bytes", nread, pktlen); } ++r->pkts; @@ -728,18 +744,17 @@ static CURLcode read_pkt_to_send(void *userp, { struct read_ctx *x = userp; struct cf_quiche_ctx *ctx = x->cf->ctx; - ssize_t n; + ssize_t rv; *pnread = 0; - n = quiche_conn_send(ctx->qconn, buf, buflen, &x->send_info); - if(n == QUICHE_ERR_DONE) + rv = quiche_conn_send(ctx->qconn, buf, buflen, &x->send_info); + if(rv == QUICHE_ERR_DONE) return CURLE_AGAIN; - if(n < 0) { - failf(x->data, "quiche_conn_send returned %zd", n); + if(!curlx_sztouz(rv, pnread)) { + failf(x->data, "quiche_conn_send returned %zd", rv); return CURLE_SEND_ERROR; } - *pnread = (size_t)n; return CURLE_OK; } @@ -753,8 +768,8 @@ static CURLcode cf_flush_egress(struct Curl_cfilter *cf, struct cf_quiche_ctx *ctx = cf->ctx; size_t nread; CURLcode result; - curl_int64_t expiry_ns; - curl_int64_t timeout_ns; + int64_t expiry_ns; + int64_t timeout_ns; struct read_ctx readx; size_t pkt_count, gsolen; @@ -824,7 +839,7 @@ static CURLcode cf_flush_egress(struct Curl_cfilter *cf, timeout_ns = quiche_conn_timeout_as_nanos(ctx->qconn); if(timeout_ns % 1000000) timeout_ns += 1000000; - /* expire resolution is milliseconds */ + /* expire resolution is milliseconds */ Curl_expire(data, (timeout_ns / 1000000), EXPIRE_QUIC); return result; } @@ -840,15 +855,13 @@ static CURLcode recv_closed_stream(struct Curl_cfilter *cf, DEBUGASSERT(stream); *pnread = 0; if(stream->reset) { - failf(data, - "HTTP/3 stream %" FMT_PRIu64 " reset by server", stream->id); + failf(data, "HTTP/3 stream %" PRIu64 " reset by server", stream->id); result = data->req.bytecount ? CURLE_PARTIAL_FILE : CURLE_HTTP3; - CURL_TRC_CF(data, cf, "[%" FMT_PRIu64 "] cf_recv, was reset -> %d", + CURL_TRC_CF(data, cf, "[%" PRIu64 "] cf_recv, was reset -> %d", stream->id, result); } else if(!stream->resp_got_header) { - failf(data, - "HTTP/3 stream %" FMT_PRIu64 " was closed cleanly, but before " + failf(data, "HTTP/3 stream %" PRIu64 " was closed cleanly, but before " "getting all response header fields, treated as error", stream->id); result = CURLE_HTTP3; @@ -857,128 +870,107 @@ static CURLcode recv_closed_stream(struct Curl_cfilter *cf, } static CURLcode cf_quiche_recv(struct Curl_cfilter *cf, struct Curl_easy *data, - char *buf, size_t len, size_t *pnread) + char *buf, size_t blen, size_t *pnread) { struct cf_quiche_ctx *ctx = cf->ctx; struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); CURLcode result = CURLE_OK; *pnread = 0; - vquic_ctx_update_time(&ctx->q); + (void)buf; + (void)blen; + vquic_ctx_update_time(&ctx->q, Curl_pgrs_now(data)); if(!stream) return CURLE_RECV_ERROR; - - if(!Curl_bufq_is_empty(&stream->recvbuf)) { - result = Curl_bufq_cread(&stream->recvbuf, buf, len, pnread); - CURL_TRC_CF(data, cf, "[%" FMT_PRIu64 "] read recvbuf(len=%zu) " - "-> %d, %zu", stream->id, len, result, *pnread); - if(result) - goto out; - } - result = cf_process_ingress(cf, data); if(result) { CURL_TRC_CF(data, cf, "cf_recv, error on ingress"); goto out; } - /* recvbuf had nothing before, maybe after progressing ingress? */ - if(!*pnread && !Curl_bufq_is_empty(&stream->recvbuf)) { - result = Curl_bufq_cread(&stream->recvbuf, buf, len, pnread); - CURL_TRC_CF(data, cf, "[%" FMT_PRIu64 "] read recvbuf(len=%zu) " - "-> %d, %zu", stream->id, len, result, *pnread); - if(result) - goto out; - } - - if(*pnread) { - if(stream->closed) - Curl_multi_mark_dirty(data); + if(stream->xfer_result) { + cf_quiche_stream_close(cf, data, stream); + result = stream->xfer_result; + goto out; } - else { - if(stream->closed) - result = recv_closed_stream(cf, data, pnread); - else if(quiche_conn_is_draining(ctx->qconn)) { - failf(data, "QUIC connection is draining"); - result = CURLE_HTTP3; - } - else - result = CURLE_AGAIN; + else if(stream->closed) + result = recv_closed_stream(cf, data, pnread); + else if(quiche_conn_is_draining(ctx->qconn)) { + failf(data, "QUIC connection is draining"); + result = CURLE_HTTP3; } + else + result = CURLE_AGAIN; out: result = Curl_1st_err(result, cf_flush_egress(cf, data)); if(*pnread > 0) ctx->data_recvd += *pnread; - CURL_TRC_CF(data, cf, "[%"FMT_PRIu64"] cf_recv(total=%" - FMT_OFF_T ") -> %d, %zu", - stream->id, ctx->data_recvd, result, *pnread); + CURL_TRC_CF(data, cf, "[%" PRIu64 "] cf_recv(len=%zu) -> %d, %zu, total=%" + FMT_OFF_T, stream->id, blen, result, *pnread, ctx->data_recvd); return result; } static CURLcode cf_quiche_send_body(struct Curl_cfilter *cf, struct Curl_easy *data, struct h3_stream_ctx *stream, - const void *buf, size_t len, bool eos, + const uint8_t *buf, size_t len, bool eos, size_t *pnwritten) { struct cf_quiche_ctx *ctx = cf->ctx; - ssize_t nwritten; + ssize_t rv; *pnwritten = 0; - nwritten = quiche_h3_send_body(ctx->h3c, ctx->qconn, stream->id, - (uint8_t *)CURL_UNCONST(buf), len, eos); - if(nwritten == QUICHE_H3_ERR_DONE || (nwritten == 0 && len > 0)) { + rv = quiche_h3_send_body(ctx->h3c, ctx->qconn, stream->id, + (uint8_t *)CURL_UNCONST(buf), len, eos); + if(rv == QUICHE_H3_ERR_DONE || (rv == 0 && len > 0)) { /* Blocked on flow control and should HOLD sending. But when do we open * again? */ if(!quiche_conn_stream_writable(ctx->qconn, stream->id, len)) { - CURL_TRC_CF(data, cf, "[%" FMT_PRIu64 "] send_body(len=%zu) " + CURL_TRC_CF(data, cf, "[%" PRIu64 "] send_body(len=%zu) " "-> window exhausted", stream->id, len); stream->quic_flow_blocked = TRUE; } return CURLE_AGAIN; } - else if(nwritten == QUICHE_H3_TRANSPORT_ERR_INVALID_STREAM_STATE) { - CURL_TRC_CF(data, cf, "[%" FMT_PRIu64 "] send_body(len=%zu) " + else if(rv == QUICHE_H3_TRANSPORT_ERR_INVALID_STREAM_STATE) { + CURL_TRC_CF(data, cf, "[%" PRIu64 "] send_body(len=%zu) " "-> invalid stream state", stream->id, len); return CURLE_HTTP3; } - else if(nwritten == QUICHE_H3_TRANSPORT_ERR_FINAL_SIZE) { - CURL_TRC_CF(data, cf, "[%" FMT_PRIu64 "] send_body(len=%zu) " - "-> exceeds size", stream->id, len); + else if(rv == QUICHE_H3_TRANSPORT_ERR_FINAL_SIZE) { + CURL_TRC_CF(data, cf, "[%" PRIu64 "] send_body(len=%zu) -> exceeds size", + stream->id, len); return CURLE_SEND_ERROR; } - else if(nwritten < 0) { - CURL_TRC_CF(data, cf, "[%" FMT_PRIu64 "] send_body(len=%zu) " - "-> quiche err %zd", stream->id, len, nwritten); + else if(!curlx_sztouz(rv, pnwritten)) { + CURL_TRC_CF(data, cf, "[%" PRIu64 "] send_body(len=%zu) -> quiche err %zd", + stream->id, len, rv); return CURLE_SEND_ERROR; } else { - if(eos && (len == (size_t)nwritten)) + if(eos && (len == *pnwritten)) stream->send_closed = TRUE; - CURL_TRC_CF(data, cf, "[%" FMT_PRIu64 "] send body(len=%zu, " - "eos=%d) -> %zd", - stream->id, len, stream->send_closed, nwritten); - *pnwritten = (size_t)nwritten; + CURL_TRC_CF(data, cf, "[%" PRIu64 "] send body(len=%zu, eos=%d) -> %zu", + stream->id, len, stream->send_closed, *pnwritten); return CURLE_OK; } } static CURLcode h3_open_stream(struct Curl_cfilter *cf, struct Curl_easy *data, - const char *buf, size_t blen, bool eos, + const uint8_t *buf, size_t blen, bool eos, size_t *pnwritten) { struct cf_quiche_ctx *ctx = cf->ctx; struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); size_t nheader, i; - curl_int64_t stream3_id; + int64_t rv; struct dynhds h2_headers; quiche_h3_header *nva = NULL; CURLcode result = CURLE_OK; - ssize_t nwritten; *pnwritten = 0; if(!stream) { @@ -992,8 +984,12 @@ static CURLcode h3_open_stream(struct Curl_cfilter *cf, Curl_dynhds_init(&h2_headers, 0, DYN_HTTP_REQUEST); DEBUGASSERT(stream); - nwritten = Curl_h1_req_parse_read(&stream->h1, buf, blen, NULL, 0, &result); - if(nwritten < 0) + + result = Curl_h1_req_parse_read(&stream->h1, buf, blen, NULL, + !data->state.http_ignorecustom ? + data->set.str[STRING_CUSTOMREQUEST] : NULL, + 0, pnwritten); + if(result) goto out; if(!stream->h1.done) { /* need more data */ @@ -1009,7 +1005,7 @@ static CURLcode h3_open_stream(struct Curl_cfilter *cf, Curl_h1_req_parse_free(&stream->h1); nheader = Curl_dynhds_count(&h2_headers); - nva = malloc(sizeof(quiche_h3_header) * nheader); + nva = curlx_malloc(sizeof(quiche_h3_header) * nheader); if(!nva) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -1023,70 +1019,69 @@ static CURLcode h3_open_stream(struct Curl_cfilter *cf, nva[i].value_len = e->valuelen; } - *pnwritten = (size_t)nwritten; buf += *pnwritten; blen -= *pnwritten; if(eos && !blen) stream->send_closed = TRUE; - stream3_id = quiche_h3_send_request(ctx->h3c, ctx->qconn, nva, nheader, - stream->send_closed); - CURL_TRC_CF(data, cf, "quiche_send_request() -> %" FMT_PRIu64, stream3_id); - if(stream3_id < 0) { - if(QUICHE_H3_ERR_STREAM_BLOCKED == stream3_id) { + rv = quiche_h3_send_request(ctx->h3c, ctx->qconn, nva, nheader, + stream->send_closed); + CURL_TRC_CF(data, cf, "quiche_send_request() -> %" PRId64, rv); + if(rv < 0) { + if(QUICHE_H3_ERR_STREAM_BLOCKED == rv) { /* quiche seems to report this error if the connection window is * exhausted. Which happens frequently and intermittent. */ - CURL_TRC_CF(data, cf, "[%"FMT_PRIu64"] blocked", stream->id); + CURL_TRC_CF(data, cf, "[%" PRIu64 "] blocked", stream->id); stream->quic_flow_blocked = TRUE; result = CURLE_AGAIN; goto out; } else { - CURL_TRC_CF(data, cf, "send_request(%s) -> %" FMT_PRIu64, - data->state.url, stream3_id); + CURL_TRC_CF(data, cf, "send_request(%s) -> %" PRIu64, + Curl_bufref_ptr(&data->state.url), rv); } result = CURLE_SEND_ERROR; goto out; } DEBUGASSERT(!stream->opened); - stream->id = stream3_id; + stream->id = (uint64_t)rv; stream->opened = TRUE; stream->closed = FALSE; stream->reset = FALSE; if(Curl_trc_is_verbose(data)) { - infof(data, "[HTTP/3] [%" FMT_PRIu64 "] OPENED stream for %s", - stream->id, data->state.url); + infof(data, "[HTTP/3] [%" PRIu64 "] OPENED stream for %s", + stream->id, Curl_bufref_ptr(&data->state.url)); for(i = 0; i < nheader; ++i) { - infof(data, "[HTTP/3] [%" FMT_PRIu64 "] [%.*s: %.*s]", stream->id, + infof(data, "[HTTP/3] [%" PRIu64 "] [%.*s: %.*s]", stream->id, (int)nva[i].name_len, nva[i].name, (int)nva[i].value_len, nva[i].value); } } if(blen) { /* after the headers, there was request BODY data */ - size_t bwritten; + size_t nwritten; CURLcode r2 = CURLE_OK; - r2 = cf_quiche_send_body(cf, data, stream, buf, blen, eos, &bwritten); + r2 = cf_quiche_send_body(cf, data, stream, buf, blen, eos, &nwritten); if(r2 && (CURLE_AGAIN != r2)) { /* real error, fail */ result = r2; } - else if(bwritten > 0) { - *pnwritten += (size_t)bwritten; + else if(nwritten > 0) { + *pnwritten += nwritten; } } out: - free(nva); + curlx_free(nva); Curl_dynhds_free(&h2_headers); return result; } static CURLcode cf_quiche_send(struct Curl_cfilter *cf, struct Curl_easy *data, - const void *buf, size_t len, bool eos, + const uint8_t *buf, size_t len, bool eos, size_t *pnwritten) { struct cf_quiche_ctx *ctx = cf->ctx; @@ -1094,7 +1089,7 @@ static CURLcode cf_quiche_send(struct Curl_cfilter *cf, struct Curl_easy *data, CURLcode result; *pnwritten = 0; - vquic_ctx_update_time(&ctx->q); + vquic_ctx_update_time(&ctx->q, Curl_pgrs_now(data)); result = cf_process_ingress(cf, data); if(result) @@ -1106,6 +1101,10 @@ static CURLcode cf_quiche_send(struct Curl_cfilter *cf, struct Curl_easy *data, goto out; stream = H3_STREAM_CTX(ctx, data); } + else if(stream->xfer_result) { + cf_quiche_stream_close(cf, data, stream); + result = stream->xfer_result; + } else if(stream->closed) { if(stream->resp_hds_complete) { /* sending request body on a stream that has been closed by the @@ -1116,13 +1115,13 @@ static CURLcode cf_quiche_send(struct Curl_cfilter *cf, struct Curl_easy *data, * sending the 30x response. * This is sort of a race: had the transfer loop called recv first, * it would see the response and stop/discard sending on its own- */ - CURL_TRC_CF(data, cf, "[%" FMT_PRIu64 "] discarding data" + CURL_TRC_CF(data, cf, "[%" PRIu64 "] discarding data" "on closed stream with response", stream->id); result = CURLE_OK; *pnwritten = len; goto out; } - CURL_TRC_CF(data, cf, "[%" FMT_PRIu64 "] send_body(len=%zu) " + CURL_TRC_CF(data, cf, "[%" PRIu64 "] send_body(len=%zu) " "-> stream closed", stream->id, len); result = CURLE_HTTP3; goto out; @@ -1134,8 +1133,8 @@ static CURLcode cf_quiche_send(struct Curl_cfilter *cf, struct Curl_easy *data, out: result = Curl_1st_err(result, cf_flush_egress(cf, data)); - CURL_TRC_CF(data, cf, "[%" FMT_PRIu64 "] cf_send(len=%zu) -> %d, %zu", - stream ? stream->id : (curl_uint64_t)~0, len, + CURL_TRC_CF(data, cf, "[%" PRIu64 "] cf_send(len=%zu) -> %d, %zu", + stream ? stream->id : (uint64_t)~0, len, result, *pnwritten); return result; } @@ -1147,7 +1146,7 @@ static bool stream_is_writeable(struct Curl_cfilter *cf, struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); return stream && (quiche_conn_stream_writable( - ctx->qconn, (curl_uint64_t)stream->id, 1) > 0); + ctx->qconn, stream->id, 1) > 0); } static CURLcode cf_quiche_adjust_pollset(struct Curl_cfilter *cf, @@ -1179,19 +1178,6 @@ static CURLcode cf_quiche_adjust_pollset(struct Curl_cfilter *cf, return result; } -/* - * Called from transfer.c:data_pending to know if we should keep looping - * to receive more data from the connection. - */ -static bool cf_quiche_data_pending(struct Curl_cfilter *cf, - const struct Curl_easy *data) -{ - struct cf_quiche_ctx *ctx = cf->ctx; - const struct h3_stream_ctx *stream = H3_STREAM_CTX(ctx, data); - (void)cf; - return stream && !Curl_bufq_is_empty(&stream->recvbuf); -} - static CURLcode h3_data_pause(struct Curl_cfilter *cf, struct Curl_easy *data, bool pause) @@ -1232,7 +1218,7 @@ static CURLcode cf_quiche_cntrl(struct Curl_cfilter *cf, stream->send_closed = TRUE; body[0] = 'X'; result = cf_quiche_send(cf, data, body, 0, TRUE, &sent); - CURL_TRC_CF(data, cf, "[%"FMT_PRIu64"] DONE_SEND -> %d, %zu", + CURL_TRC_CF(data, cf, "[%" PRIu64 "] DONE_SEND -> %d, %zu", stream->id, result, sent); } break; @@ -1256,12 +1242,12 @@ static CURLcode cf_quiche_ctx_open(struct Curl_cfilter *cf, int rv; CURLcode result; const struct Curl_sockaddr_ex *sockaddr; - static const struct alpn_spec ALPN_SPEC_H3 = {{ "h3" }, 1}; + static const struct alpn_spec ALPN_SPEC_H3 = { { "h3" }, 1 }; DEBUGASSERT(ctx->q.sockfd != CURL_SOCKET_BAD); DEBUGASSERT(ctx->initialized); - result = vquic_ctx_init(&ctx->q); + result = vquic_ctx_init(data, &ctx->q); if(result) return result; @@ -1327,8 +1313,7 @@ static CURLcode cf_quiche_ctx_open(struct Curl_cfilter *cf, int qfd; (void)Curl_qlogdir(data, ctx->scid, sizeof(ctx->scid), &qfd); if(qfd != -1) - quiche_conn_set_qlog_fd(ctx->qconn, qfd, - "qlog title", "curl qlog"); + quiche_conn_set_qlog_fd(ctx->qconn, qfd, "qlog title", "curl qlog"); } #endif @@ -1381,7 +1366,7 @@ static CURLcode cf_quiche_connect(struct Curl_cfilter *cf, } *done = FALSE; - vquic_ctx_update_time(&ctx->q); + vquic_ctx_update_time(&ctx->q, Curl_pgrs_now(data)); if(!ctx->qconn) { result = cf_quiche_ctx_open(cf, data); @@ -1403,8 +1388,8 @@ static CURLcode cf_quiche_connect(struct Curl_cfilter *cf, if(quiche_conn_is_established(ctx->qconn)) { ctx->handshake_at = ctx->q.last_op; - CURL_TRC_CF(data, cf, "handshake complete after %dms", - (int)curlx_timediff(ctx->handshake_at, ctx->started_at)); + CURL_TRC_CF(data, cf, "handshake complete after %" FMT_TIMEDIFF_T "ms", + curlx_ptimediff_ms(&ctx->handshake_at, &ctx->started_at)); result = cf_quiche_verify_peer(cf, data); if(!result) { CURL_TRC_CF(data, cf, "peer verified"); @@ -1422,7 +1407,6 @@ static CURLcode cf_quiche_connect(struct Curl_cfilter *cf, } cf->connected = TRUE; *done = TRUE; - connkeep(cf->conn, "HTTP/3 default"); } } else if(quiche_conn_is_draining(ctx->qconn)) { @@ -1464,7 +1448,7 @@ static CURLcode cf_quiche_shutdown(struct Curl_cfilter *cf, int err; ctx->shutdown_started = TRUE; - vquic_ctx_update_time(&ctx->q); + vquic_ctx_update_time(&ctx->q, Curl_pgrs_now(data)); err = quiche_conn_close(ctx->qconn, TRUE, 0, NULL, 0); if(err) { CURL_TRC_CF(data, cf, "error %d adding shutdown packet, " @@ -1523,19 +1507,20 @@ static CURLcode cf_quiche_query(struct Curl_cfilter *cf, switch(query) { case CF_QUERY_MAX_CONCURRENT: { - curl_uint64_t max_streams = CONN_ATTACHED(cf->conn); + uint64_t max_streams = cf->conn->attached_xfers; if(!ctx->goaway && ctx->qconn) { max_streams += quiche_conn_peer_streams_left_bidi(ctx->qconn); } *pres1 = (max_streams > INT_MAX) ? INT_MAX : (int)max_streams; CURL_TRC_CF(data, cf, "query conn[%" FMT_OFF_T "]: " "MAX_CONCURRENT -> %d (%u in use)", - cf->conn->connection_id, *pres1, CONN_ATTACHED(cf->conn)); + cf->conn->connection_id, *pres1, cf->conn->attached_xfers); return CURLE_OK; } case CF_QUERY_CONNECT_REPLY_MS: if(ctx->q.got_first_byte) { - timediff_t ms = curlx_timediff(ctx->q.first_byte_at, ctx->started_at); + timediff_t ms = curlx_ptimediff_ms(&ctx->q.first_byte_at, + &ctx->started_at); *pres1 = (ms < INT_MAX) ? (int)ms : INT_MAX; } else @@ -1624,7 +1609,7 @@ struct Curl_cftype Curl_cft_http3 = { cf_quiche_close, cf_quiche_shutdown, cf_quiche_adjust_pollset, - cf_quiche_data_pending, + Curl_cf_def_data_pending, cf_quiche_send, cf_quiche_recv, cf_quiche_cntrl, @@ -1644,7 +1629,7 @@ CURLcode Curl_cf_quiche_create(struct Curl_cfilter **pcf, (void)data; (void)conn; - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { result = CURLE_OUT_OF_MEMORY; goto out; diff --git a/vendor/hydra/vendor/curl/lib/vquic/curl_quiche.h b/vendor/hydra/vendor/curl/lib/vquic/curl_quiche.h index bee966ee..6c0fb9ee 100644 --- a/vendor/hydra/vendor/curl/lib/vquic/curl_quiche.h +++ b/vendor/hydra/vendor/curl/lib/vquic/curl_quiche.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "../curl_setup.h" #if !defined(CURL_DISABLE_HTTP) && defined(USE_QUICHE) diff --git a/vendor/hydra/vendor/curl/lib/vquic/vquic-tls.c b/vendor/hydra/vendor/curl/lib/vquic/vquic-tls.c index f4ef06c3..3391d980 100644 --- a/vendor/hydra/vendor/curl/lib/vquic/vquic-tls.c +++ b/vendor/hydra/vendor/curl/lib/vquic/vquic-tls.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "../curl_setup.h" #if defined(USE_HTTP3) && \ @@ -45,18 +44,12 @@ #endif #include "../urldata.h" -#include "../curl_trc.h" #include "../cfilters.h" -#include "../multiif.h" #include "../vtls/keylog.h" #include "../vtls/vtls.h" #include "../vtls/vtls_scache.h" #include "vquic-tls.h" -/* The last 2 #include files should be in this order */ -#include "../curl_memory.h" -#include "../memdebug.h" - CURLcode Curl_vquic_tls_init(struct curl_tls_ctx *ctx, struct Curl_cfilter *cf, struct Curl_easy *data, @@ -147,7 +140,9 @@ CURLcode Curl_vquic_tls_before_recv(struct curl_tls_ctx *ctx, return result; } #else - (void)ctx; (void)cf; (void)data; + (void)ctx; + (void)cf; + (void)data; #endif return CURLE_OK; } @@ -168,26 +163,24 @@ CURLcode Curl_vquic_tls_verify_peer(struct curl_tls_ctx *ctx, (void)conn_config; result = Curl_ossl_check_peer_cert(cf, data, &ctx->ossl, peer); #elif defined(USE_GNUTLS) - if(conn_config->verifyhost) { - result = Curl_gtls_verifyserver(cf, data, ctx->gtls.session, - conn_config, &data->set.ssl, peer, - data->set.str[STRING_SSL_PINNEDPUBLICKEY]); - if(result) - return result; - } + result = Curl_gtls_verifyserver(cf, data, ctx->gtls.session, + conn_config, &data->set.ssl, peer, + data->set.str[STRING_SSL_PINNEDPUBLICKEY]); + if(result) + return result; #elif defined(USE_WOLFSSL) (void)data; if(conn_config->verifyhost) { - WOLFSSL_X509* cert = wolfSSL_get_peer_certificate(ctx->wssl.ssl); + WOLFSSL_X509 *cert = wolfSSL_get_peer_certificate(ctx->wssl.ssl); if(!cert) result = CURLE_OUT_OF_MEMORY; else if(peer->sni && - (wolfSSL_X509_check_host(cert, peer->sni, strlen(peer->sni), 0, NULL) - == WOLFSSL_FAILURE)) + (wolfSSL_X509_check_host(cert, peer->sni, strlen(peer->sni), 0, + NULL) == WOLFSSL_FAILURE)) result = CURLE_PEER_FAILED_VERIFICATION; else if(!peer->sni && - (wolfSSL_X509_check_ip_asc(cert, peer->hostname, 0) - == WOLFSSL_FAILURE)) + (wolfSSL_X509_check_ip_asc(cert, peer->hostname, + 0) == WOLFSSL_FAILURE)) result = CURLE_PEER_FAILED_VERIFICATION; wolfSSL_X509_free(cert); } @@ -200,7 +193,6 @@ CURLcode Curl_vquic_tls_verify_peer(struct curl_tls_ctx *ctx, return result; } - bool Curl_vquic_tls_get_ssl_info(struct curl_tls_ctx *ctx, bool give_ssl_ctx, struct curl_tlssessioninfo *info) diff --git a/vendor/hydra/vendor/curl/lib/vquic/vquic-tls.h b/vendor/hydra/vendor/curl/lib/vquic/vquic-tls.h index c694e23e..cff76543 100644 --- a/vendor/hydra/vendor/curl/lib/vquic/vquic-tls.h +++ b/vendor/hydra/vendor/curl/lib/vquic/vquic-tls.h @@ -23,16 +23,16 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "../curl_setup.h" -#include "../bufq.h" -#include "../vtls/vtls.h" -#include "../vtls/vtls_int.h" -#include "../vtls/openssl.h" #if defined(USE_HTTP3) && \ (defined(USE_OPENSSL) || defined(USE_GNUTLS) || defined(USE_WOLFSSL)) +#include "../bufq.h" +#include "../vtls/vtls.h" +#include "../vtls/vtls_int.h" + +#include "../vtls/openssl.h" #include "../vtls/wolfssl.h" struct ssl_peer; @@ -69,14 +69,14 @@ typedef CURLcode Curl_vquic_session_reuse_cb(struct Curl_cfilter *cf, /** * Initialize the QUIC TLS instances based of the SSL configurations * for the connection filter, transfer and peer. - * @param ctx the TLS context to initialize - * @param cf the connection filter involved - * @param data the transfer involved - * @param peer the peer that will be connected to - * @param alpns the ALPN specifications to negotiate, may be NULL - * @param cb_setup optional callback for early TLS config - * @param cb_user_data user_data param for callback - * @param ssl_user_data optional pointer to set in TLS application context + * @param ctx the TLS context to initialize + * @param cf the connection filter involved + * @param data the transfer involved + * @param peer the peer that will be connected to + * @param alpns the ALPN specifications to negotiate, may be NULL + * @param cb_setup optional callback for early TLS config + * @param cb_user_data user_data param for callback + * @param ssl_user_data optional pointer to set in TLS application context * @param session_reuse_cb callback to handle session reuse, signal early data */ CURLcode Curl_vquic_tls_init(struct curl_tls_ctx *ctx, diff --git a/vendor/hydra/vendor/curl/lib/vquic/vquic.c b/vendor/hydra/vendor/curl/lib/vquic/vquic.c index 7533001e..d7bfa991 100644 --- a/vendor/hydra/vendor/curl/lib/vquic/vquic.c +++ b/vendor/hydra/vendor/curl/lib/vquic/vquic.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "../curl_setup.h" #ifdef HAVE_NETINET_UDP_H @@ -40,23 +39,19 @@ #include "curl_osslq.h" #include "curl_quiche.h" #include "../multiif.h" +#include "../progress.h" #include "../rand.h" #include "vquic.h" #include "vquic_int.h" #include "../curlx/strerr.h" #include "../curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "../curl_memory.h" -#include "../memdebug.h" - #if !defined(CURL_DISABLE_HTTP) && defined(USE_HTTP3) #define NW_CHUNK_SIZE (64 * 1024) #define NW_SEND_CHUNKS 1 - int Curl_vquic_init(void) { #if defined(USE_NGTCP2) && defined(OPENSSL_QUIC_API2) @@ -78,7 +73,8 @@ void Curl_quic_ver(char *p, size_t len) #endif } -CURLcode vquic_ctx_init(struct cf_quic_ctx *qctx) +CURLcode vquic_ctx_init(struct Curl_easy *data, + struct cf_quic_ctx *qctx) { Curl_bufq_init2(&qctx->sendbuf, NW_CHUNK_SIZE, NW_SEND_CHUNKS, BUFQ_OPT_SOFT_LIMIT); @@ -97,7 +93,7 @@ CURLcode vquic_ctx_init(struct cf_quic_ctx *qctx) } } #endif - vquic_ctx_update_time(qctx); + vquic_ctx_set_time(qctx, Curl_pgrs_now(data)); return CURLE_OK; } @@ -107,9 +103,16 @@ void vquic_ctx_free(struct cf_quic_ctx *qctx) Curl_bufq_free(&qctx->sendbuf); } -void vquic_ctx_update_time(struct cf_quic_ctx *qctx) +void vquic_ctx_set_time(struct cf_quic_ctx *qctx, + const struct curltime *pnow) +{ + qctx->last_op = *pnow; +} + +void vquic_ctx_update_time(struct cf_quic_ctx *qctx, + const struct curltime *pnow) { - qctx->last_op = curlx_now(); + qctx->last_op = *pnow; } static CURLcode send_packet_no_gso(struct Curl_cfilter *cf, @@ -127,8 +130,8 @@ static CURLcode do_sendmsg(struct Curl_cfilter *cf, CURLcode result = CURLE_OK; #ifdef HAVE_SENDMSG struct iovec msg_iov; - struct msghdr msg = {0}; - ssize_t sent; + struct msghdr msg = { 0 }; + ssize_t rv; #if defined(__linux__) && defined(UDP_SEGMENT) uint8_t msg_ctrl[32]; struct cmsghdr *cm; @@ -144,6 +147,7 @@ static CURLcode do_sendmsg(struct Curl_cfilter *cf, if(pktlen > gsolen) { /* Only set this, when we need it. macOS, for example, * does not seem to like a msg_control of length 0. */ + memset(msg_ctrl, 0, sizeof(msg_ctrl)); msg.msg_control = msg_ctrl; assert(sizeof(msg_ctrl) >= CMSG_SPACE(sizeof(int))); msg.msg_controllen = CMSG_SPACE(sizeof(int)); @@ -155,12 +159,10 @@ static CURLcode do_sendmsg(struct Curl_cfilter *cf, } #endif - - while((sent = sendmsg(qctx->sockfd, &msg, 0)) == -1 && - SOCKERRNO == SOCKEINTR) + while((rv = sendmsg(qctx->sockfd, &msg, 0)) == -1 && SOCKERRNO == SOCKEINTR) ; - if(sent == -1) { + if(!curlx_sztouz(rv, psent)) { switch(SOCKERRNO) { case EAGAIN: #if EAGAIN != SOCKEWOULDBLOCK @@ -173,41 +175,41 @@ static CURLcode do_sendmsg(struct Curl_cfilter *cf, case EIO: if(pktlen > gsolen) { /* GSO failure */ - infof(data, "sendmsg() returned %zd (errno %d); disable GSO", sent, + infof(data, "sendmsg() returned %zd (errno %d); disable GSO", rv, SOCKERRNO); qctx->no_gso = TRUE; return send_packet_no_gso(cf, data, qctx, pkt, pktlen, gsolen, psent); } FALLTHROUGH(); default: - failf(data, "sendmsg() returned %zd (errno %d)", sent, SOCKERRNO); + failf(data, "sendmsg() returned %zd (errno %d)", rv, SOCKERRNO); result = CURLE_SEND_ERROR; goto out; } } - else if(pktlen != (size_t)sent) { - failf(data, "sendmsg() sent only %zd/%zu bytes", sent, pktlen); + else if(pktlen != *psent) { + failf(data, "sendmsg() sent only %zu/%zu bytes", *psent, pktlen); result = CURLE_SEND_ERROR; goto out; } #else - ssize_t sent; + ssize_t rv; (void)gsolen; *psent = 0; - while((sent = CURL_SEND(qctx->sockfd, (const char *)pkt, - (SEND_TYPE_ARG3)pktlen, 0)) == -1 && + while((rv = send(qctx->sockfd, (const char *)pkt, + (SEND_TYPE_ARG3)pktlen, 0)) == -1 && SOCKERRNO == SOCKEINTR) ; - if(sent == -1) { + if(!curlx_sztouz(rv, psent)) { if(SOCKERRNO == EAGAIN || SOCKERRNO == SOCKEWOULDBLOCK) { result = CURLE_AGAIN; goto out; } else { - failf(data, "send() returned %zd (errno %d)", sent, SOCKERRNO); + failf(data, "send() returned %zd (errno %d)", rv, SOCKERRNO); if(SOCKERRNO != SOCKEMSGSIZE) { result = CURLE_SEND_ERROR; goto out; @@ -218,7 +220,6 @@ static CURLcode do_sendmsg(struct Curl_cfilter *cf, } #endif (void)cf; - *psent = pktlen; out: return result; @@ -270,7 +271,7 @@ static CURLcode vquic_send_packets(struct Curl_cfilter *cf, unsigned char c; *psent = 0; Curl_rand(data, &c, 1); - if(c >= ((100-qctx->wblock_percent)*256/100)) { + if(c >= ((100 - qctx->wblock_percent) * 256 / 100)) { CURL_TRC_CF(data, cf, "vquic_flush() simulate EWOULDBLOCK"); return CURLE_AGAIN; } @@ -338,8 +339,7 @@ CURLcode vquic_send_tail_split(struct Curl_cfilter *cf, struct Curl_easy *data, qctx->split_gsolen = gsolen; qctx->gsolen = tail_gsolen; CURL_TRC_CF(data, cf, "vquic_send_tail_split: [%zu gso=%zu][%zu gso=%zu]", - qctx->split_len, qctx->split_gsolen, - tail_len, qctx->gsolen); + qctx->split_len, qctx->split_gsolen, tail_len, qctx->gsolen); return vquic_flush(cf, data, qctx); } @@ -447,12 +447,14 @@ static CURLcode recvmmsg_packets(struct Curl_cfilter *cf, ++calls; for(i = 0; i < mcount; ++i) { + /* A zero-length UDP packet is no QUIC packet. Ignore. */ + if(!mmsg[i].msg_len) + continue; total_nread += mmsg[i].msg_len; gso_size = vquic_msghdr_get_udp_gro(&mmsg[i].msg_hdr); - if(gso_size == 0) { + if(gso_size == 0) gso_size = mmsg[i].msg_len; - } result = recv_cb(bufs[i], mmsg[i].msg_len, gso_size, mmsg[i].msg_hdr.msg_name, @@ -480,7 +482,7 @@ static CURLcode recvmsg_packets(struct Curl_cfilter *cf, { struct iovec msg_iov; struct msghdr msg; - uint8_t buf[64*1024]; + uint8_t buf[64 * 1024]; struct sockaddr_storage remote_addr; size_t total_nread, pkts, calls; ssize_t rc; @@ -507,7 +509,7 @@ static CURLcode recvmsg_packets(struct Curl_cfilter *cf, while((rc = recvmsg(qctx->sockfd, &msg, 0)) == -1 && (SOCKERRNO == SOCKEINTR || SOCKERRNO == SOCKEMSGSIZE)) ; - if(rc == -1) { + if(!curlx_sztouz(rc, &nread)) { if(SOCKERRNO == EAGAIN || SOCKERRNO == SOCKEWOULDBLOCK) { goto out; } @@ -521,19 +523,21 @@ static CURLcode recvmsg_packets(struct Curl_cfilter *cf, } curlx_strerror(SOCKERRNO, errstr, sizeof(errstr)); failf(data, "QUIC: recvmsg() unexpectedly returned %zd (errno=%d; %s)", - rc, SOCKERRNO, errstr); + rc, SOCKERRNO, errstr); result = CURLE_RECV_ERROR; goto out; } - nread = (size_t)rc; total_nread += nread; ++calls; + /* A 0-length UDP packet is no QUIC packet */ + if(!nread) + continue; + gso_size = vquic_msghdr_get_udp_gro(&msg); - if(gso_size == 0) { + if(gso_size == 0) gso_size = nread; - } result = recv_cb(buf, nread, gso_size, msg.msg_name, msg.msg_namelen, 0, userp); @@ -556,23 +560,23 @@ static CURLcode recvfrom_packets(struct Curl_cfilter *cf, size_t max_pkts, vquic_recv_pkts_cb *recv_cb, void *userp) { - uint8_t buf[64*1024]; + uint8_t buf[64 * 1024]; int bufsize = (int)sizeof(buf); struct sockaddr_storage remote_addr; socklen_t remote_addrlen = sizeof(remote_addr); - size_t total_nread, pkts, calls = 0; - ssize_t nread; + size_t total_nread, pkts, calls = 0, nread; + ssize_t rv; char errstr[STRERROR_LEN]; CURLcode result = CURLE_OK; DEBUGASSERT(max_pkts > 0); for(pkts = 0, total_nread = 0; pkts < max_pkts;) { - while((nread = recvfrom(qctx->sockfd, (char *)buf, bufsize, 0, - (struct sockaddr *)&remote_addr, - &remote_addrlen)) == -1 && + while((rv = recvfrom(qctx->sockfd, (char *)buf, bufsize, 0, + (struct sockaddr *)&remote_addr, + &remote_addrlen)) == -1 && (SOCKERRNO == SOCKEINTR || SOCKERRNO == SOCKEMSGSIZE)) ; - if(nread == -1) { + if(!curlx_sztouz(rv, &nread)) { if(SOCKERRNO == EAGAIN || SOCKERRNO == SOCKEWOULDBLOCK) { CURL_TRC_CF(data, cf, "ingress, recvfrom -> EAGAIN"); goto out; @@ -587,16 +591,21 @@ static CURLcode recvfrom_packets(struct Curl_cfilter *cf, } curlx_strerror(SOCKERRNO, errstr, sizeof(errstr)); failf(data, "QUIC: recvfrom() unexpectedly returned %zd (errno=%d; %s)", - nread, SOCKERRNO, errstr); + rv, SOCKERRNO, errstr); result = CURLE_RECV_ERROR; goto out; } ++pkts; ++calls; - total_nread += (size_t)nread; - result = recv_cb(buf, (size_t)nread, (size_t)nread, - &remote_addr, remote_addrlen, 0, userp); + + /* A 0-length UDP packet is no QUIC packet */ + if(!nread) + continue; + + total_nread += nread; + result = recv_cb(buf, nread, nread, &remote_addr, remote_addrlen, + 0, userp); if(result) goto out; } @@ -667,12 +676,16 @@ CURLcode Curl_qlogdir(struct Curl_easy *data, if(!result) { int qlogfd = curlx_open(curlx_dyn_ptr(&fname), O_WRONLY | O_CREAT | CURL_O_BINARY, - data->set.new_file_perms); + data->set.new_file_perms +#ifdef _WIN32 + & (_S_IREAD | _S_IWRITE) +#endif + ); if(qlogfd != -1) *qlogfdp = qlogfd; } curlx_dyn_free(&fname); - free(qlog_dir); + curlx_free(qlog_dir); if(result) return result; } @@ -684,7 +697,7 @@ CURLcode Curl_cf_quic_create(struct Curl_cfilter **pcf, struct Curl_easy *data, struct connectdata *conn, const struct Curl_addrinfo *ai, - int transport) + uint8_t transport) { (void)transport; DEBUGASSERT(transport == TRNSPRT_QUIC); diff --git a/vendor/hydra/vendor/curl/lib/vquic/vquic.h b/vendor/hydra/vendor/curl/lib/vquic/vquic.h index 0f81334f..f5392eb0 100644 --- a/vendor/hydra/vendor/curl/lib/vquic/vquic.h +++ b/vendor/hydra/vendor/curl/lib/vquic/vquic.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "../curl_setup.h" #if !defined(CURL_DISABLE_HTTP) && defined(USE_HTTP3) @@ -40,12 +39,11 @@ CURLcode Curl_qlogdir(struct Curl_easy *data, size_t scidlen, int *qlogfdp); - CURLcode Curl_cf_quic_create(struct Curl_cfilter **pcf, struct Curl_easy *data, struct connectdata *conn, const struct Curl_addrinfo *ai, - int transport); + uint8_t transport); extern struct Curl_cftype Curl_cft_http3; diff --git a/vendor/hydra/vendor/curl/lib/vquic/vquic_int.h b/vendor/hydra/vendor/curl/lib/vquic/vquic_int.h index 4e5959a4..e602b7ee 100644 --- a/vendor/hydra/vendor/curl/lib/vquic/vquic_int.h +++ b/vendor/hydra/vendor/curl/lib/vquic/vquic_int.h @@ -23,41 +23,46 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "../curl_setup.h" + #include "../bufq.h" #ifdef USE_HTTP3 -#define MAX_PKT_BURST 10 +#define MAX_PKT_BURST 10 #define MAX_UDP_PAYLOAD_SIZE 1452 struct cf_quic_ctx { - curl_socket_t sockfd; /* connected UDP socket */ + curl_socket_t sockfd; /* connected UDP socket */ struct sockaddr_storage local_addr; /* address socket is bound to */ - socklen_t local_addrlen; /* length of local address */ - - struct bufq sendbuf; /* buffer for sending one or more packets */ - struct curltime first_byte_at; /* when first byte was recvd */ - struct curltime last_op; /* last (attempted) send/recv operation */ - struct curltime last_io; /* last successful socket IO */ - size_t gsolen; /* length of individual packets in send buf */ - size_t split_len; /* if != 0, buffer length after which GSO differs */ + socklen_t local_addrlen; /* length of local address */ + + struct bufq sendbuf; /* buffer for sending one or more packets */ + struct curltime first_byte_at; /* when first byte was recvd */ + struct curltime last_op; /* last (attempted) send/recv operation */ + struct curltime last_io; /* last successful socket IO */ + size_t gsolen; /* length of individual packets in send buf */ + size_t split_len; /* if != 0, buffer length after which GSO differs */ size_t split_gsolen; /* length of individual packets after split_len */ #ifdef DEBUGBUILD - int wblock_percent; /* percent of writes doing EAGAIN */ + int wblock_percent; /* percent of writes doing EAGAIN */ #endif BIT(got_first_byte); /* if first byte was received */ - BIT(no_gso); /* do not use gso on sending */ + BIT(no_gso); /* do not use gso on sending */ }; -#define H3_STREAM_CTX(ctx,data) \ - (data ? Curl_uint_hash_get(&(ctx)->streams, (data)->mid) : NULL) +#define H3_STREAM_CTX(ctx, data) \ + (data ? Curl_uint32_hash_get(&(ctx)->streams, (data)->mid) : NULL) -CURLcode vquic_ctx_init(struct cf_quic_ctx *qctx); +CURLcode vquic_ctx_init(struct Curl_easy *data, + struct cf_quic_ctx *qctx); void vquic_ctx_free(struct cf_quic_ctx *qctx); -void vquic_ctx_update_time(struct cf_quic_ctx *qctx); +void vquic_ctx_set_time(struct cf_quic_ctx *qctx, + const struct curltime *pnow); + +void vquic_ctx_update_time(struct cf_quic_ctx *qctx, + const struct curltime *pnow); void vquic_push_blocked_pkt(struct Curl_cfilter *cf, struct cf_quic_ctx *qctx, @@ -77,7 +82,6 @@ CURLcode vquic_send_tail_split(struct Curl_cfilter *cf, struct Curl_easy *data, CURLcode vquic_flush(struct Curl_cfilter *cf, struct Curl_easy *data, struct cf_quic_ctx *qctx); - typedef CURLcode vquic_recv_pkts_cb(const unsigned char *buf, size_t buflen, size_t gso_size, struct sockaddr_storage *remote_addr, diff --git a/vendor/hydra/vendor/curl/lib/vssh/libssh.c b/vendor/hydra/vendor/curl/lib/vssh/libssh.c index af3767ca..3e6cb3a8 100644 --- a/vendor/hydra/vendor/curl/lib/vssh/libssh.c +++ b/vendor/hydra/vendor/curl/lib/vssh/libssh.c @@ -24,13 +24,10 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "../curl_setup.h" #ifdef USE_LIBSSH -#include - #ifdef HAVE_NETINET_IN_H #include #endif @@ -45,26 +42,21 @@ #include #endif -#include #include "../urldata.h" #include "../sendf.h" +#include "../curl_trc.h" #include "../hostip.h" #include "../progress.h" #include "../transfer.h" -#include "../http.h" /* for HTTP proxy tunnel stuff */ #include "ssh.h" #include "../url.h" -#include "../speedcheck.h" -#include "../vtls/vtls.h" #include "../cfilters.h" #include "../connect.h" #include "../parsedate.h" /* for the week day and month names */ -#include "../sockaddr.h" /* required for Curl_sockaddr_storage */ #include "../curlx/strparse.h" #include "../multiif.h" #include "../select.h" -#include "../curlx/warnless.h" -#include "curl_path.h" +#include "vssh.h" #ifdef HAVE_UNISTD_H #include @@ -73,18 +65,14 @@ #include #endif -/* The last 2 #include files should be in this order */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* A recent macro provided by libssh. Or make our own. */ #ifndef SSH_STRING_FREE_CHAR -#define SSH_STRING_FREE_CHAR(x) \ - do { \ - if(x) { \ - ssh_string_free_char(x); \ - x = NULL; \ - } \ +#define SSH_STRING_FREE_CHAR(x) \ + do { \ + if(x) { \ + ssh_string_free_char(x); \ + x = NULL; \ + } \ } while(0) #endif @@ -116,10 +104,9 @@ static CURLcode sftp_doing(struct Curl_easy *data, static CURLcode sftp_disconnect(struct Curl_easy *data, struct connectdata *conn, bool dead); -static -CURLcode sftp_perform(struct Curl_easy *data, - bool *connected, - bool *dophase_done); +static CURLcode sftp_perform(struct Curl_easy *data, + bool *connected, + bool *dophase_done); static CURLcode myssh_pollset(struct Curl_easy *data, struct easy_pollset *ps); @@ -157,7 +144,8 @@ const struct Curl_handler Curl_handler_scp = { PORT_SSH, /* defport */ CURLPROTO_SCP, /* protocol */ CURLPROTO_SCP, /* family */ - PROTOPT_DIRLOCK | PROTOPT_CLOSEACTION | PROTOPT_NOURLQUERY /* flags */ + PROTOPT_DIRLOCK | PROTOPT_CLOSEACTION | /* flags */ + PROTOPT_NOURLQUERY | PROTOPT_CONN_REUSE }; /* @@ -186,55 +174,38 @@ const struct Curl_handler Curl_handler_sftp = { PORT_SSH, /* defport */ CURLPROTO_SFTP, /* protocol */ CURLPROTO_SFTP, /* family */ - PROTOPT_DIRLOCK | PROTOPT_CLOSEACTION - | PROTOPT_NOURLQUERY /* flags */ + PROTOPT_DIRLOCK | PROTOPT_CLOSEACTION | /* flags */ + PROTOPT_NOURLQUERY | PROTOPT_CONN_REUSE }; static CURLcode sftp_error_to_CURLE(int err) { switch(err) { - case SSH_FX_OK: - return CURLE_OK; + case SSH_FX_OK: + return CURLE_OK; - case SSH_FX_NO_SUCH_FILE: - case SSH_FX_NO_SUCH_PATH: - return CURLE_REMOTE_FILE_NOT_FOUND; + case SSH_FX_NO_SUCH_FILE: + case SSH_FX_NO_SUCH_PATH: + return CURLE_REMOTE_FILE_NOT_FOUND; - case SSH_FX_PERMISSION_DENIED: - case SSH_FX_WRITE_PROTECT: - return CURLE_REMOTE_ACCESS_DENIED; + case SSH_FX_PERMISSION_DENIED: + case SSH_FX_WRITE_PROTECT: + return CURLE_REMOTE_ACCESS_DENIED; - case SSH_FX_FILE_ALREADY_EXISTS: - return CURLE_REMOTE_FILE_EXISTS; + case SSH_FX_FILE_ALREADY_EXISTS: + return CURLE_REMOTE_FILE_EXISTS; - default: - break; + default: + break; } return CURLE_SSH; } -#if defined(DEBUGBUILD) && !defined(CURL_DISABLE_VERBOSE_STRINGS) -#define myssh_to(x,y,z) myssh_set_state(x,y,z, __LINE__) -#else -#define myssh_to(x,y,z) myssh_set_state(x,y,z) -#endif - -/* - * SSH State machine related code - */ -/* This is the ONLY way to change SSH state! */ -static void myssh_set_state(struct Curl_easy *data, - struct ssh_conn *sshc, - sshstate nowstate -#if defined(DEBUGBUILD) && !defined(CURL_DISABLE_VERBOSE_STRINGS) - , int lineno -#endif - ) +#ifndef CURL_DISABLE_VERBOSE_STRINGS +static const char *myssh_statename(sshstate state) { -#if defined(DEBUGBUILD) && !defined(CURL_DISABLE_VERBOSE_STRINGS) - /* for debug purposes */ - static const char *const names[] = { + static const char * const names[] = { "SSH_STOP", "SSH_INIT", "SSH_S_STARTUP", @@ -296,15 +267,33 @@ static void myssh_set_state(struct Curl_easy *data, "SSH_SESSION_FREE", "QUIT" }; + /* a precaution to make sure the lists are in sync */ + DEBUGASSERT(CURL_ARRAYSIZE(names) == SSH_LAST); + return ((size_t)state < CURL_ARRAYSIZE(names)) ? names[state] : ""; +} +#else +#define myssh_statename(x) "" +#endif /* !CURL_DISABLE_VERBOSE_STRINGS */ +#define myssh_to(x, y, z) myssh_set_state(x, y, z) +/* + * SSH State machine related code + */ +/* This is the ONLY way to change SSH state! */ +static void myssh_set_state(struct Curl_easy *data, + struct ssh_conn *sshc, + sshstate nowstate) +{ +#ifndef CURL_DISABLE_VERBOSE_STRINGS if(sshc->state != nowstate) { - infof(data, "SSH %p state change from %s to %s (line %d)", - (void *) sshc, names[sshc->state], names[nowstate], - lineno); + CURL_TRC_SSH(data, "[%s] -> [%s]", + myssh_statename(sshc->state), + myssh_statename(nowstate)); } -#endif +#else (void)data; +#endif sshc->state = nowstate; } @@ -330,8 +319,7 @@ static int myssh_is_known(struct Curl_easy *data, struct ssh_conn *sshc) enum curl_khmatch keymatch; struct curl_khkey foundkey; struct curl_khkey *knownkeyp = NULL; - curl_sshkeycallback func = - data->set.ssh_keyfunc; + curl_sshkeycallback func = data->set.ssh_keyfunc; struct ssh_knownhosts_entry *knownhostsentry = NULL; struct curl_khkey knownkey; @@ -345,8 +333,7 @@ static int myssh_is_known(struct Curl_easy *data, struct ssh_conn *sshc) char md5buffer[33]; const char *pubkey_md5 = data->set.str[STRING_SSH_HOST_PUBLIC_KEY_MD5]; - rc = ssh_get_publickey_hash(pubkey, SSH_PUBLICKEY_HASH_MD5, - &hash, &hlen); + rc = ssh_get_publickey_hash(pubkey, SSH_PUBLICKEY_HASH_MD5, &hash, &hlen); if(rc != SSH_OK || hlen != 16) { failf(data, "Denied establishing ssh session: md5 fingerprint not available"); @@ -354,7 +341,7 @@ static int myssh_is_known(struct Curl_easy *data, struct ssh_conn *sshc) } for(i = 0; i < 16; i++) - curl_msnprintf(&md5buffer[i*2], 3, "%02x", (unsigned char)hash[i]); + curl_msnprintf(&md5buffer[i * 2], 3, "%02x", (unsigned char)hash[i]); infof(data, "SSH MD5 fingerprint: %s", md5buffer); @@ -463,7 +450,7 @@ static int myssh_is_known(struct Curl_easy *data, struct ssh_conn *sshc) Curl_set_in_callback(data, TRUE); rc = func(data, knownkeyp, /* from the knownhosts file */ - &foundkey, /* from the remote host */ + &foundkey, /* from the remote host */ keymatch, data->set.ssh_keyfunc_userp); Curl_set_in_callback(data, FALSE); @@ -492,10 +479,12 @@ static int myssh_is_known(struct Curl_easy *data, struct ssh_conn *sshc) cleanup: if(found_base64) { - (free)(found_base64); + /* !checksrc! disable BANNEDFUNC 1 */ + free(found_base64); /* allocated by libssh, deallocate with system free */ } if(known_base64) { - (free)(known_base64); + /* !checksrc! disable BANNEDFUNC 1 */ + free(known_base64); /* allocated by libssh, deallocate with system free */ } if(hash) ssh_clean_pubkey_hash(&hash); @@ -519,8 +508,7 @@ static int myssh_to_SFTP_CLOSE(struct Curl_easy *data, struct ssh_conn *sshc) { myssh_to(data, sshc, SSH_SFTP_CLOSE); - sshc->actualcode = - sftp_error_to_CURLE(sftp_get_error(sshc->sftp_session)); + sshc->actualcode = sftp_error_to_CURLE(sftp_get_error(sshc->sftp_session)); return SSH_ERROR; } @@ -606,14 +594,13 @@ static int myssh_in_SFTP_READDIR(struct Curl_easy *data, } result = Curl_client_write(data, CLIENTWRITE_BODY, tmpLine, sshc->readdir_len + 1); - free(tmpLine); + curlx_free(tmpLine); if(result) { myssh_to(data, sshc, SSH_STOP); sshc->actualcode = result; return SSH_NO_ERROR; } - } else { if(curlx_dyn_add(&sshc->readdir_buf, sshc->readdir_longentry)) { @@ -684,8 +671,7 @@ static int myssh_in_SFTP_READDIR_LINK(struct Curl_easy *data, Curl_safefree(sshc->readdir_linkPath); - if(curlx_dyn_addf(&sshc->readdir_buf, " -> %s", - sshc->readdir_filename)) { + if(curlx_dyn_addf(&sshc->readdir_buf, " -> %s", sshc->readdir_filename)) { /* Not using: * return myssh_to_SFTP_CLOSE(data, sshc); * @@ -788,7 +774,7 @@ static int myssh_in_SFTP_QUOTE_STATVFS(struct Curl_easy *data, if(!result) { result = Curl_client_write(data, CLIENTWRITE_HEADER, tmp, strlen(tmp)); - free(tmp); + curlx_free(tmp); } if(result) { myssh_to(data, sshc, SSH_SFTP_CLOSE); @@ -808,56 +794,56 @@ static int myssh_auth_interactive(struct connectdata *conn, restart: switch(sshc->kbd_state) { - case 0: - rc = ssh_userauth_kbdint(sshc->ssh_session, NULL, NULL); - if(rc == SSH_AUTH_AGAIN) - return SSH_AGAIN; + case 0: + rc = ssh_userauth_kbdint(sshc->ssh_session, NULL, NULL); + if(rc == SSH_AUTH_AGAIN) + return SSH_AGAIN; - if(rc != SSH_AUTH_INFO) - return SSH_ERROR; + if(rc != SSH_AUTH_INFO) + return SSH_ERROR; - nprompts = ssh_userauth_kbdint_getnprompts(sshc->ssh_session); - if(nprompts != 1) - return SSH_ERROR; + nprompts = ssh_userauth_kbdint_getnprompts(sshc->ssh_session); + if(nprompts != 1) + return SSH_ERROR; - rc = ssh_userauth_kbdint_setanswer(sshc->ssh_session, 0, conn->passwd); - if(rc < 0) - return SSH_ERROR; + rc = ssh_userauth_kbdint_setanswer(sshc->ssh_session, 0, conn->passwd); + if(rc < 0) + return SSH_ERROR; - FALLTHROUGH(); - case 1: - sshc->kbd_state = 1; + FALLTHROUGH(); + case 1: + sshc->kbd_state = 1; - rc = ssh_userauth_kbdint(sshc->ssh_session, NULL, NULL); - if(rc == SSH_AUTH_AGAIN) - return SSH_AGAIN; - else if(rc == SSH_AUTH_SUCCESS) - rc = SSH_OK; - else if(rc == SSH_AUTH_INFO) { - nprompts = ssh_userauth_kbdint_getnprompts(sshc->ssh_session); - if(nprompts) - return SSH_ERROR; + rc = ssh_userauth_kbdint(sshc->ssh_session, NULL, NULL); + if(rc == SSH_AUTH_AGAIN) + return SSH_AGAIN; + else if(rc == SSH_AUTH_SUCCESS) + rc = SSH_OK; + else if(rc == SSH_AUTH_INFO) { + nprompts = ssh_userauth_kbdint_getnprompts(sshc->ssh_session); + if(nprompts) + return SSH_ERROR; - sshc->kbd_state = 2; - goto restart; - } - else - rc = SSH_ERROR; - break; - case 2: sshc->kbd_state = 2; + goto restart; + } + else + rc = SSH_ERROR; + break; + case 2: + sshc->kbd_state = 2; - rc = ssh_userauth_kbdint(sshc->ssh_session, NULL, NULL); - if(rc == SSH_AUTH_AGAIN) - return SSH_AGAIN; - else if(rc == SSH_AUTH_SUCCESS) - rc = SSH_OK; - else - rc = SSH_ERROR; + rc = ssh_userauth_kbdint(sshc->ssh_session, NULL, NULL); + if(rc == SSH_AUTH_AGAIN) + return SSH_AGAIN; + else if(rc == SSH_AUTH_SUCCESS) + rc = SSH_OK; + else + rc = SSH_ERROR; - break; - default: - return SSH_ERROR; + break; + default: + return SSH_ERROR; } sshc->kbd_state = 0; @@ -890,7 +876,7 @@ static int myssh_in_S_STARTUP(struct Curl_easy *data, myssh_block2waitfor(conn, sshc, (rc == SSH_AGAIN)); if(rc == SSH_AGAIN) { - DEBUGF(infof(data, "ssh_connect -> EAGAIN")); + CURL_TRC_SSH(data, "connect -> EAGAIN"); } else if(rc != SSH_OK) { failf(data, "Failure establishing ssh session"); @@ -935,7 +921,11 @@ static int myssh_in_AUTHLIST(struct Curl_easy *data, "keyboard-interactive, " : "", sshc->auth_methods & SSH_AUTH_METHOD_PASSWORD ? "password": ""); - if(sshc->auth_methods & SSH_AUTH_METHOD_PUBLICKEY) { + /* For public key auth we need either the private key or + CURLSSH_AUTH_AGENT. */ + if((sshc->auth_methods & SSH_AUTH_METHOD_PUBLICKEY) && + (data->set.str[STRING_SSH_PRIVATE_KEY] || + (data->set.ssh_auth_types & CURLSSH_AUTH_AGENT))) { myssh_to(data, sshc, SSH_AUTH_PKEY_INIT); infof(data, "Authentication using SSH public key file"); } @@ -967,8 +957,7 @@ static int myssh_in_AUTH_PKEY_INIT(struct Curl_easy *data, * (2) use the "default" keys. */ if(data->set.str[STRING_SSH_PRIVATE_KEY]) { if(sshc->pubkey && !data->set.ssl.key_passwd) { - rc = ssh_userauth_try_publickey(sshc->ssh_session, NULL, - sshc->pubkey); + rc = ssh_userauth_try_publickey(sshc->ssh_session, NULL, sshc->pubkey); if(rc == SSH_AUTH_AGAIN) return SSH_AGAIN; @@ -993,7 +982,7 @@ static int myssh_in_AUTH_PKEY_INIT(struct Curl_easy *data, } else { rc = ssh_userauth_publickey_auto(sshc->ssh_session, NULL, - data->set.ssl.key_passwd); + data->set.ssl.key_passwd); if(rc == SSH_AUTH_AGAIN) return SSH_AGAIN; @@ -1138,14 +1127,13 @@ static int myssh_in_UPLOAD_INIT(struct Curl_easy *data, attrs = sftp_stat(sshc->sftp_session, sshp->path); if(attrs) { curl_off_t size = attrs->size; + sftp_attributes_free(attrs); if(size < 0) { failf(data, "Bad file size (%" FMT_OFF_T ")", size); rc = myssh_to_ERROR(data, sshc, CURLE_BAD_DOWNLOAD_RESUME); return rc; } - data->state.resume_from = attrs->size; - - sftp_attributes_free(attrs); + data->state.resume_from = size; } else { data->state.resume_from = 0; @@ -1167,7 +1155,7 @@ static int myssh_in_UPLOAD_INIT(struct Curl_easy *data, } else /* Clear file before writing (normal behavior) */ - flags = O_WRONLY|O_CREAT|O_TRUNC; + flags = O_WRONLY | O_CREAT | O_TRUNC; if(sshc->sftp_file) sftp_close(sshc->sftp_file); @@ -1215,7 +1203,7 @@ static int myssh_in_UPLOAD_INIT(struct Curl_easy *data, } /* seekerr == CURL_SEEKFUNC_CANTSEEK (cannot seek to offset) */ do { - char scratch[4*1024]; + char scratch[4 * 1024]; size_t readthisamountnow = (data->state.resume_from - passed > (curl_off_t)sizeof(scratch)) ? @@ -1263,10 +1251,6 @@ static int myssh_in_UPLOAD_INIT(struct Curl_easy *data, /* not set by Curl_xfer_setup to preserve keepon bits */ data->conn->recv_idx = FIRSTSOCKET; - /* store this original bitmask setup to use later on if we cannot - figure out a "real" bitmask */ - sshc->orig_waitfor = data->req.keepon; - /* since we do not really wait for anything at this point, we want the state machine to move on as soon as possible so we mark this as dirty */ Curl_multi_mark_dirty(data); @@ -1330,44 +1314,11 @@ static int myssh_in_SFTP_DOWNLOAD_STAT(struct Curl_easy *data, return myssh_to_ERROR(data, sshc, CURLE_BAD_DOWNLOAD_RESUME); } if(data->state.use_range) { - curl_off_t from, to; - const char *p = data->state.range; - int from_t, to_t; - - from_t = curlx_str_number(&p, &from, CURL_OFF_T_MAX); - if(from_t == STRE_OVERFLOW) - return myssh_to_ERROR(data, sshc, CURLE_RANGE_ERROR); - - curlx_str_passblanks(&p); - (void)curlx_str_single(&p, '-'); - - to_t = curlx_str_numblanks(&p, &to); - if(to_t == STRE_OVERFLOW) - return myssh_to_ERROR(data, sshc, CURLE_RANGE_ERROR); - - if((to_t == STRE_NO_NUM) || (to >= size)) { - to = size - 1; - } - - if(from_t == STRE_NO_NUM) { - /* from is relative to end of file */ - from = size - to; - to = size - 1; - } - if(from > size) { - failf(data, "Offset (%" FMT_OFF_T ") was beyond file size (%" - FMT_OFF_T ")", from, size); - return myssh_to_ERROR(data, sshc, CURLE_BAD_DOWNLOAD_RESUME); - } - if(from > to) { - from = to; - size = 0; - } - else { - if((to - from) == CURL_OFF_T_MAX) - return myssh_to_ERROR(data, sshc, CURLE_RANGE_ERROR); - size = to - from + 1; - } + curl_off_t from; + CURLcode result = Curl_ssh_range(data, data->state.range, size, + &from, &size); + if(result) + return myssh_to_ERROR(data, sshc, result); rc = sftp_seek64(sshc->sftp_file, from); if(rc) @@ -1401,8 +1352,7 @@ static int myssh_in_SFTP_DOWNLOAD_STAT(struct Curl_easy *data, /* Now store the number of bytes we are expected to download */ data->req.size = size - data->state.resume_from; data->req.maxdownload = size - data->state.resume_from; - Curl_pgrsSetDownloadSize(data, - size - data->state.resume_from); + Curl_pgrsSetDownloadSize(data, size - data->state.resume_from); rc = sftp_seek64(sshc->sftp_file, data->state.resume_from); if(rc) @@ -1438,7 +1388,7 @@ static int myssh_in_SFTP_CLOSE(struct Curl_easy *data, } Curl_safefree(sshp->path); - DEBUGF(infof(data, "SFTP DONE done")); + CURL_TRC_SSH(data, "SFTP DONE done"); /* Check if nextstate is set and move .nextstate could be POSTQUOTE_INIT After nextstate is executed, the control should come back to @@ -1513,8 +1463,8 @@ static int myssh_in_SFTP_REALPATH(struct Curl_easy *data, if(!sshc->homedir) return myssh_to_ERROR(data, sshc, CURLE_COULDNT_CONNECT); - free(data->state.most_recent_ftp_entrypath); - data->state.most_recent_ftp_entrypath = strdup(sshc->homedir); + curlx_free(data->state.most_recent_ftp_entrypath); + data->state.most_recent_ftp_entrypath = curlx_strdup(sshc->homedir); if(!data->state.most_recent_ftp_entrypath) return myssh_to_ERROR(data, sshc, CURLE_OUT_OF_MEMORY); @@ -1522,7 +1472,7 @@ static int myssh_in_SFTP_REALPATH(struct Curl_easy *data, we get the homedir here, we get the "workingpath" in the DO action since the homedir will remain the same between request but the working path will not. */ - DEBUGF(infof(data, "SSH CONNECT phase done")); + CURL_TRC_SSH(data, "CONNECT phase done"); myssh_to(data, sshc, SSH_STOP); return SSH_NO_ERROR; } @@ -1608,11 +1558,11 @@ static int myssh_in_SFTP_QUOTE(struct Curl_easy *data, Curl_debug(data, CURLINFO_HEADER_OUT, "PWD\n", 4); Curl_debug(data, CURLINFO_HEADER_IN, tmp, strlen(tmp)); - /* this sends an FTP-like "header" to the header callback so that the - current directory can be read very similar to how it is read when + /* this sends an FTP-like "header" to the header callback so that + the current directory can be read similar to how it is read when using ordinary FTP. */ result = Curl_client_write(data, CLIENTWRITE_HEADER, tmp, strlen(tmp)); - free(tmp); + curlx_free(tmp); if(result) { myssh_to(data, sshc, SSH_SFTP_CLOSE); sshc->nextstate = SSH_NO_STATE; @@ -1711,7 +1661,7 @@ static int myssh_in_SFTP_QUOTE(struct Curl_easy *data, else if(!strncmp(cmd, "mkdir ", 6)) { if(*cp) return return_quote_error(data, sshc); - /* create dir */ + /* create directory */ myssh_to(data, sshc, SSH_SFTP_QUOTE_MKDIR); return SSH_NO_ERROR; } @@ -1737,7 +1687,7 @@ static int myssh_in_SFTP_QUOTE(struct Curl_easy *data, return SSH_NO_ERROR; } else if(!strncmp(cmd, "rmdir ", 6)) { - /* delete dir */ + /* delete directory */ if(*cp) return return_quote_error(data, sshc); myssh_to(data, sshc, SSH_SFTP_QUOTE_RMDIR); @@ -1894,7 +1844,7 @@ static int myssh_in_SFTP_QUOTE_STAT(struct Curl_easy *data, return SSH_NO_ERROR; } if(date > UINT_MAX) - /* because the liubssh API can't deal with a larger value */ + /* because the liubssh API cannot deal with a larger value */ date = UINT_MAX; if(!strncmp(cmd, "atime", 5)) sshc->quote_attrs->atime = (uint32_t)date; @@ -1909,6 +1859,18 @@ static int myssh_in_SFTP_QUOTE_STAT(struct Curl_easy *data, return SSH_NO_ERROR; } +static void conn_forget_socket(struct Curl_easy *data, int sockindex) +{ + struct connectdata *conn = data->conn; + if(conn && CONN_SOCK_IDX_VALID(sockindex)) { + struct Curl_cfilter *cf = conn->cfilter[sockindex]; + if(cf) + (void)Curl_conn_cf_cntrl(cf, data, TRUE, CF_CTRL_FORGET_SOCKET, 0, NULL); + fake_sclose(conn->sock[sockindex]); + conn->sock[sockindex] = CURL_SOCKET_BAD; + } +} + /* * ssh_statemach_act() runs the SSH state machine as far as it can without * blocking and without reaching the end. The data the pointer 'block' points @@ -2092,8 +2054,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, break; if(rc && !sshc->acceptfail) { Curl_safefree(sshc->quote_path1); - failf(data, "rm command failed: %s", - ssh_get_error(sshc->ssh_session)); + failf(data, "rm command failed: %s", ssh_get_error(sshc->ssh_session)); myssh_to(data, sshc, SSH_SFTP_CLOSE); sshc->nextstate = SSH_NO_STATE; sshc->actualcode = CURLE_QUOTE_ERROR; @@ -2135,7 +2096,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, if(data->state.upload) myssh_to(data, sshc, SSH_SFTP_UPLOAD_INIT); else if(sshp) { - if(sshp->path[strlen(sshp->path)-1] == '/') + if(sshp->path[strlen(sshp->path) - 1] == '/') myssh_to(data, sshc, SSH_SFTP_READDIR_INIT); else myssh_to(data, sshc, SSH_SFTP_DOWNLOAD_INIT); @@ -2191,9 +2152,9 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, ++sshc->slash_pos; if(rc < 0) { /* - * Abort if failure was not that the dir already exists or the - * permission was denied (creation might succeed further down the - * path) - retry on unspecific FAILURE also + * Abort if failure was not that the directory already exists or + * the permission was denied (creation might succeed further down + * the path) - retry on unspecific FAILURE also */ err = sftp_get_error(sshc->sftp_session); if((err != SSH_FX_FILE_ALREADY_EXISTS) && @@ -2309,10 +2270,6 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, /* not set by Curl_xfer_setup to preserve keepon bits */ data->conn->recv_idx = FIRSTSOCKET; - /* store this original bitmask setup to use later on if we cannot - figure out a "real" bitmask */ - sshc->orig_waitfor = data->req.keepon; - myssh_to(data, sshc, SSH_STOP); break; @@ -2330,26 +2287,26 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, FALLTHROUGH(); case SSH_SCP_DOWNLOAD: { - curl_off_t bytecount; + curl_off_t bytecount; - rc = ssh_scp_pull_request(sshc->scp_session); - if(rc != SSH_SCP_REQUEST_NEWFILE) { - err_msg = ssh_get_error(sshc->ssh_session); - failf(data, "%s", err_msg); - rc = myssh_to_ERROR(data, sshc, CURLE_REMOTE_FILE_NOT_FOUND); - break; - } + rc = ssh_scp_pull_request(sshc->scp_session); + if(rc != SSH_SCP_REQUEST_NEWFILE) { + err_msg = ssh_get_error(sshc->ssh_session); + failf(data, "%s", err_msg); + rc = myssh_to_ERROR(data, sshc, CURLE_REMOTE_FILE_NOT_FOUND); + break; + } - /* download data */ - bytecount = ssh_scp_request_get_size(sshc->scp_session); - data->req.maxdownload = (curl_off_t) bytecount; - Curl_xfer_setup_recv(data, FIRSTSOCKET, bytecount); + /* download data */ + bytecount = ssh_scp_request_get_size(sshc->scp_session); + data->req.maxdownload = (curl_off_t)bytecount; + Curl_xfer_setup_recv(data, FIRSTSOCKET, bytecount); - /* not set by Curl_xfer_setup to preserve keepon bits */ - conn->send_idx = 0; + /* not set by Curl_xfer_setup to preserve keepon bits */ + conn->send_idx = 0; - myssh_to(data, sshc, SSH_STOP); - break; + myssh_to(data, sshc, SSH_STOP); + break; } case SSH_SCP_DONE: if(data->state.upload) @@ -2381,7 +2338,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, ssh_scp_free(sshc->scp_session); sshc->scp_session = NULL; } - DEBUGF(infof(data, "SCP DONE phase complete")); + CURL_TRC_SSH(data, "SCP DONE phase complete"); ssh_set_blocking(sshc->ssh_session, 0); @@ -2411,7 +2368,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, /* conn->sock[FIRSTSOCKET] is closed by ssh_disconnect behind our back, tell the connection to forget about it. This libssh bug is fixed in 0.10.0. */ - Curl_conn_forget_socket(data, FIRSTSOCKET); + conn_forget_socket(data, FIRSTSOCKET); } SSH_STRING_FREE_CHAR(sshc->homedir); @@ -2435,10 +2392,10 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, sshc->nextstate = SSH_NO_STATE; myssh_to(data, sshc, SSH_STOP); break; - } - } while(!rc && (sshc->state != SSH_STOP)); - + /* break the loop only on STOP or SSH_AGAIN. If `rc` is some + * other error code, we will have progressed the state accordingly. */ + } while((rc != SSH_AGAIN) && (sshc->state != SSH_STOP)); if(rc == SSH_AGAIN) { /* we would block, we need to wait for the socket to be ready (in the @@ -2447,43 +2404,55 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, } if(!result && (sshc->state == SSH_STOP)) result = sshc->actualcode; - DEBUGF(infof(data, "SSH: myssh_statemach_act -> %d", result)); + CURL_TRC_SSH(data, "[%s] statemachine() -> %d, block=%d", + myssh_statename(sshc->state), result, *block); return result; } - /* called by the multi interface to figure out what socket(s) to wait for and for what actions in the DO_DONE, PERFORM and WAITPERFORM states */ static CURLcode myssh_pollset(struct Curl_easy *data, struct easy_pollset *ps) { - int flags = 0; struct connectdata *conn = data->conn; - if(conn->waitfor & KEEP_RECV) - flags |= CURL_POLL_IN; - if(conn->waitfor & KEEP_SEND) - flags |= CURL_POLL_OUT; - if(!conn->waitfor) - flags |= CURL_POLL_OUT; - return flags ? - Curl_pollset_change(data, ps, conn->sock[FIRSTSOCKET], flags, 0) : - CURLE_OK; + struct ssh_conn *sshc = Curl_conn_meta_get(conn, CURL_META_SSH_CONN); + curl_socket_t sock = conn->sock[FIRSTSOCKET]; + int waitfor; + + if(!sshc || (sock == CURL_SOCKET_BAD)) + return CURLE_FAILED_INIT; + + waitfor = sshc->waitfor ? sshc->waitfor : data->req.keepon; + if(waitfor) { + int flags = 0; + if(waitfor & KEEP_RECV) + flags |= CURL_POLL_IN; + if(waitfor & KEEP_SEND) + flags |= CURL_POLL_OUT; + DEBUGASSERT(flags); + CURL_TRC_SSH(data, "pollset, flags=%x", flags); + return Curl_pollset_change(data, ps, sock, flags, 0); + } + /* While we still have a session, we listen incoming data. */ + if(sshc->ssh_session) + return Curl_pollset_change(data, ps, sock, CURL_POLL_IN, 0); + return CURLE_OK; } static void myssh_block2waitfor(struct connectdata *conn, struct ssh_conn *sshc, bool block) { + (void)conn; if(block) { int dir = ssh_get_poll_flags(sshc->ssh_session); /* translate the libssh define bits into our own bit defines */ - conn->waitfor = + sshc->waitfor = ((dir & SSH_READ_PENDING) ? KEEP_RECV : 0) | ((dir & SSH_WRITE_PENDING) ? KEEP_SEND : 0); } else - /* if it did not block, use the original set */ - conn->waitfor = sshc->orig_waitfor; + sshc->waitfor = 0; } /* called repeatedly until done from multi.c */ @@ -2516,23 +2485,19 @@ static CURLcode myssh_block_statemach(struct Curl_easy *data, while((sshc->state != SSH_STOP) && !result) { bool block; - timediff_t left = 1000; - struct curltime now = curlx_now(); + timediff_t left_ms = 1000; result = myssh_statemach_act(data, sshc, sshp, &block); if(result) break; if(!disconnect) { - if(Curl_pgrsUpdate(data)) - return CURLE_ABORTED_BY_CALLBACK; - - result = Curl_speedcheck(data, now); + result = Curl_pgrsCheck(data); if(result) break; - left = Curl_timeleft(data, NULL, FALSE); - if(left < 0) { + left_ms = Curl_timeleft_ms(data, FALSE); + if(left_ms < 0) { failf(data, "Operation timed out"); return CURLE_OPERATION_TIMEDOUT; } @@ -2541,10 +2506,8 @@ static CURLcode myssh_block_statemach(struct Curl_easy *data, if(block) { curl_socket_t fd_read = conn->sock[FIRSTSOCKET]; /* wait for the socket to become ready */ - (void)Curl_socket_check(fd_read, CURL_SOCKET_BAD, - CURL_SOCKET_BAD, left > 1000 ? 1000 : left); + (void)SOCKET_READABLE(fd_read, left_ms > 1000 ? 1000 : left_ms); } - } return result; @@ -2556,7 +2519,7 @@ static void myssh_easy_dtor(void *key, size_t klen, void *entry) (void)key; (void)klen; Curl_safefree(sshp->path); - free(sshp); + curlx_free(sshp); } static void myssh_conn_dtor(void *key, size_t klen, void *entry) @@ -2565,7 +2528,7 @@ static void myssh_conn_dtor(void *key, size_t klen, void *entry) (void)key; (void)klen; sshc_cleanup(sshc); - free(sshc); + curlx_free(sshc); } /* @@ -2577,7 +2540,7 @@ static CURLcode myssh_setup_connection(struct Curl_easy *data, struct SSHPROTO *sshp; struct ssh_conn *sshc; - sshc = calloc(1, sizeof(*sshc)); + sshc = curlx_calloc(1, sizeof(*sshc)); if(!sshc) return CURLE_OUT_OF_MEMORY; @@ -2586,7 +2549,7 @@ static CURLcode myssh_setup_connection(struct Curl_easy *data, if(Curl_conn_meta_set(conn, CURL_META_SSH_CONN, sshc, myssh_conn_dtor)) return CURLE_OUT_OF_MEMORY; - sshp = calloc(1, sizeof(*sshp)); + sshp = curlx_calloc(1, sizeof(*sshp)); if(!sshp || Curl_meta_set(data, CURL_META_SSH_EASY, sshp, myssh_easy_dtor)) return CURLE_OUT_OF_MEMORY; @@ -2613,10 +2576,7 @@ static CURLcode myssh_connect(struct Curl_easy *data, bool *done) if(!sshc || !ssh) return CURLE_FAILED_INIT; - /* We default to persistent connections. We set this already in this connect - function to make the reuse checks properly be able to check this bit. */ - connkeep(conn, "SSH default"); - + CURL_TRC_SSH(data, "myssh_connect"); if(conn->handler->protocol & CURLPROTO_SCP) { conn->recv[FIRSTSOCKET] = scp_recv; conn->send[FIRSTSOCKET] = scp_send; @@ -2651,6 +2611,7 @@ static CURLcode myssh_connect(struct Curl_easy *data, bool *done) /* ignore */ } + CURL_TRC_SSH(data, "myssh_connect, set socket=%" FMT_SOCKET_T, sock); rc = ssh_options_set(sshc->ssh_session, SSH_OPTIONS_FD, &sock); if(rc != SSH_OK) { failf(data, "Could not set socket"); @@ -2670,6 +2631,11 @@ static CURLcode myssh_connect(struct Curl_easy *data, bool *done) infof(data, "Known hosts: %s", data->set.str[STRING_SSH_KNOWNHOSTS]); rc = ssh_options_set(sshc->ssh_session, SSH_OPTIONS_KNOWNHOSTS, data->set.str[STRING_SSH_KNOWNHOSTS]); + if(rc == SSH_OK) + /* libssh has two separate options for this. Set both to the same file + to avoid surprises */ + rc = ssh_options_set(sshc->ssh_session, SSH_OPTIONS_GLOBAL_KNOWNHOSTS, + data->set.str[STRING_SSH_KNOWNHOSTS]); if(rc != SSH_OK) { failf(data, "Could not set known hosts file path"); return CURLE_FAILED_INIT; @@ -2724,7 +2690,7 @@ static CURLcode scp_doing(struct Curl_easy *data, bool *dophase_done) result = myssh_multi_statemach(data, dophase_done); if(*dophase_done) { - DEBUGF(infof(data, "DO phase is complete")); + CURL_TRC_SSH(data, "DO phase is complete"); } return result; } @@ -2738,14 +2704,13 @@ static CURLcode scp_doing(struct Curl_easy *data, bool *dophase_done) * the options previously setup. */ -static -CURLcode scp_perform(struct Curl_easy *data, - bool *connected, bool *dophase_done) +static CURLcode scp_perform(struct Curl_easy *data, + bool *connected, bool *dophase_done) { CURLcode result = CURLE_OK; struct ssh_conn *sshc = Curl_conn_meta_get(data->conn, CURL_META_SSH_CONN); - DEBUGF(infof(data, "DO phase starts")); + CURL_TRC_SSH(data, "DO phase starts"); *dophase_done = FALSE; /* not done yet */ if(!sshc) @@ -2759,7 +2724,7 @@ CURLcode scp_perform(struct Curl_easy *data, *connected = Curl_conn_is_connected(data->conn, FIRSTSOCKET); if(*dophase_done) { - DEBUGF(infof(data, "DO phase is complete")); + CURL_TRC_SSH(data, "DO phase is complete"); } return result; @@ -2779,13 +2744,10 @@ static CURLcode myssh_do_it(struct Curl_easy *data, bool *done) data->req.size = -1; /* make sure this is unknown at this point */ sshc->actualcode = CURLE_OK; /* reset error code */ - sshc->secondCreateDirs = 0; /* reset the create dir attempt state + sshc->secondCreateDirs = 0; /* reset the create directory attempt state variable */ - Curl_pgrsSetUploadCounter(data, 0); - Curl_pgrsSetDownloadCounter(data, 0); - Curl_pgrsSetUploadSize(data, -1); - Curl_pgrsSetDownloadSize(data, -1); + Curl_pgrsReset(data); if(conn->handler->protocol & CURLPROTO_SCP) result = scp_perform(data, &connected, done); @@ -2895,7 +2857,6 @@ static CURLcode myssh_done(struct Curl_easy *data, return result; } - static CURLcode scp_done(struct Curl_easy *data, CURLcode status, bool premature) { @@ -2911,7 +2872,7 @@ static CURLcode scp_done(struct Curl_easy *data, CURLcode status, } static CURLcode scp_send(struct Curl_easy *data, int sockindex, - const void *mem, size_t len, bool eos, + const uint8_t *mem, size_t len, bool eos, size_t *pnwritten) { int rc; @@ -2987,15 +2948,14 @@ static CURLcode scp_recv(struct Curl_easy *data, int sockindex, * the options previously setup. */ -static -CURLcode sftp_perform(struct Curl_easy *data, - bool *connected, - bool *dophase_done) +static CURLcode sftp_perform(struct Curl_easy *data, + bool *connected, + bool *dophase_done) { struct ssh_conn *sshc = Curl_conn_meta_get(data->conn, CURL_META_SSH_CONN); CURLcode result = CURLE_OK; - DEBUGF(infof(data, "DO phase starts")); + CURL_TRC_SSH(data, "DO phase starts"); *dophase_done = FALSE; /* not done yet */ if(!sshc) @@ -3010,7 +2970,7 @@ CURLcode sftp_perform(struct Curl_easy *data, *connected = Curl_conn_is_connected(data->conn, FIRSTSOCKET); if(*dophase_done) { - DEBUGF(infof(data, "DO phase is complete")); + CURL_TRC_SSH(data, "DO phase is complete"); } return result; @@ -3022,7 +2982,7 @@ static CURLcode sftp_doing(struct Curl_easy *data, { CURLcode result = myssh_multi_statemach(data, dophase_done); if(*dophase_done) { - DEBUGF(infof(data, "DO phase is complete")); + CURL_TRC_SSH(data, "DO phase is complete"); } return result; } @@ -3039,7 +2999,7 @@ static CURLcode sftp_disconnect(struct Curl_easy *data, CURLcode result = CURLE_OK; (void)dead_connection; - DEBUGF(infof(data, "SSH DISCONNECT starts now")); + CURL_TRC_SSH(data, "DISCONNECT starts now"); if(sshc && sshc->ssh_session) { /* only if there is a session still around to use! */ @@ -3047,7 +3007,7 @@ static CURLcode sftp_disconnect(struct Curl_easy *data, result = myssh_block_statemach(data, sshc, sshp, TRUE); } - DEBUGF(infof(data, "SSH DISCONNECT is done")); + CURL_TRC_SSH(data, "DISCONNECT is done"); return result; } @@ -3072,7 +3032,7 @@ static CURLcode sftp_done(struct Curl_easy *data, CURLcode status, /* return number of sent bytes */ static CURLcode sftp_send(struct Curl_easy *data, int sockindex, - const void *mem, size_t len, bool eos, + const uint8_t *mem, size_t len, bool eos, size_t *pnwritten) { struct connectdata *conn = data->conn; @@ -3088,34 +3048,34 @@ static CURLcode sftp_send(struct Curl_easy *data, int sockindex, #if LIBSSH_VERSION_INT > SSH_VERSION_INT(0, 11, 0) switch(sshc->sftp_send_state) { - case 0: - sftp_file_set_nonblocking(sshc->sftp_file); - if(sftp_aio_begin_write(sshc->sftp_file, mem, len, - &sshc->sftp_send_aio) == SSH_ERROR) { - return CURLE_SEND_ERROR; - } - sshc->sftp_send_state = 1; - FALLTHROUGH(); - case 1: - nwrite = sftp_aio_wait_write(&sshc->sftp_send_aio); - myssh_block2waitfor(conn, sshc, (nwrite == SSH_AGAIN) ? TRUE : FALSE); - if(nwrite == SSH_AGAIN) - return CURLE_AGAIN; - else if(nwrite < 0) - return CURLE_SEND_ERROR; - - /* - * sftp_aio_wait_write() would free sftp_send_aio and - * assign it NULL in all cases except when it returns - * SSH_AGAIN. - */ - - sshc->sftp_send_state = 0; - *pnwritten = (size_t)nwrite; - return CURLE_OK; - default: - /* we never reach here */ + case 0: + sftp_file_set_nonblocking(sshc->sftp_file); + if(sftp_aio_begin_write(sshc->sftp_file, mem, len, + &sshc->sftp_send_aio) == SSH_ERROR) { return CURLE_SEND_ERROR; + } + sshc->sftp_send_state = 1; + FALLTHROUGH(); + case 1: + nwrite = sftp_aio_wait_write(&sshc->sftp_send_aio); + myssh_block2waitfor(conn, sshc, (nwrite == SSH_AGAIN) ? TRUE : FALSE); + if(nwrite == SSH_AGAIN) + return CURLE_AGAIN; + else if(nwrite < 0) + return CURLE_SEND_ERROR; + + /* + * sftp_aio_wait_write() would free sftp_send_aio and + * assign it NULL in all cases except when it returns + * SSH_AGAIN. + */ + + sshc->sftp_send_state = 0; + *pnwritten = (size_t)nwrite; + return CURLE_OK; + default: + /* we never reach here */ + return CURLE_SEND_ERROR; } #else /* @@ -3167,54 +3127,53 @@ static CURLcode sftp_recv(struct Curl_easy *data, int sockindex, return CURLE_FAILED_INIT; switch(sshc->sftp_recv_state) { - case 0: + case 0: #if LIBSSH_VERSION_INT > SSH_VERSION_INT(0, 11, 0) - if(sftp_aio_begin_read(sshc->sftp_file, len, - &sshc->sftp_recv_aio) == SSH_ERROR) { - return CURLE_RECV_ERROR; - } + if(sftp_aio_begin_read(sshc->sftp_file, len, + &sshc->sftp_recv_aio) == SSH_ERROR) { + return CURLE_RECV_ERROR; + } #else - sshc->sftp_file_index = - sftp_async_read_begin(sshc->sftp_file, (uint32_t)len); - if(sshc->sftp_file_index < 0) - return CURLE_RECV_ERROR; + sshc->sftp_file_index = + sftp_async_read_begin(sshc->sftp_file, (uint32_t)len); + if(sshc->sftp_file_index < 0) + return CURLE_RECV_ERROR; #endif - FALLTHROUGH(); - case 1: - sshc->sftp_recv_state = 1; + FALLTHROUGH(); + case 1: + sshc->sftp_recv_state = 1; #if LIBSSH_VERSION_INT > SSH_VERSION_INT(0, 11, 0) - nread = sftp_aio_wait_read(&sshc->sftp_recv_aio, mem, len); + nread = sftp_aio_wait_read(&sshc->sftp_recv_aio, mem, len); #else - nread = sftp_async_read(sshc->sftp_file, mem, (uint32_t)len, - (uint32_t)sshc->sftp_file_index); + nread = sftp_async_read(sshc->sftp_file, mem, (uint32_t)len, + (uint32_t)sshc->sftp_file_index); #endif - myssh_block2waitfor(conn, sshc, (nread == SSH_AGAIN)); + myssh_block2waitfor(conn, sshc, (nread == SSH_AGAIN)); - if(nread == SSH_AGAIN) - return CURLE_AGAIN; - else if(nread < 0) - return CURLE_RECV_ERROR; + if(nread == SSH_AGAIN) + return CURLE_AGAIN; + else if(nread < 0) + return CURLE_RECV_ERROR; - /* - * sftp_aio_wait_read() would free sftp_recv_aio and - * assign it NULL in all cases except when it returns - * SSH_AGAIN. - */ + /* + * sftp_aio_wait_read() would free sftp_recv_aio and + * assign it NULL in all cases except when it returns + * SSH_AGAIN. + */ - sshc->sftp_recv_state = 0; - *pnread = (size_t)nread; - return CURLE_OK; + sshc->sftp_recv_state = 0; + *pnread = (size_t)nread; + return CURLE_OK; - default: - /* we never reach here */ - return CURLE_RECV_ERROR; + default: + /* we never reach here */ + return CURLE_RECV_ERROR; } } - CURLcode Curl_ssh_init(void) { if(ssh_init()) { @@ -3234,4 +3193,4 @@ void Curl_ssh_version(char *buffer, size_t buflen) (void)curl_msnprintf(buffer, buflen, "libssh/%s", ssh_version(0)); } -#endif /* USE_LIBSSH */ +#endif /* USE_LIBSSH */ diff --git a/vendor/hydra/vendor/curl/lib/vssh/libssh2.c b/vendor/hydra/vendor/curl/lib/vssh/libssh2.c index 5990da25..5b2b3372 100644 --- a/vendor/hydra/vendor/curl/lib/vssh/libssh2.c +++ b/vendor/hydra/vendor/curl/lib/vssh/libssh2.c @@ -21,14 +21,11 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - -/* #define CURL_LIBSSH2_DEBUG */ - #include "../curl_setup.h" #ifdef USE_LIBSSH2 -#include +/* #define CURL_LIBSSH2_DEBUG */ #ifdef HAVE_NETINET_IN_H #include @@ -44,33 +41,24 @@ #include #endif -#include #include "../urldata.h" #include "../sendf.h" +#include "../curl_trc.h" #include "../hostip.h" #include "../progress.h" #include "../transfer.h" -#include "../http.h" /* for HTTP proxy tunnel stuff */ #include "ssh.h" #include "../url.h" -#include "../speedcheck.h" -#include "../vtls/vtls.h" #include "../cfilters.h" #include "../connect.h" #include "../parsedate.h" /* for the week day and month names */ -#include "../sockaddr.h" /* required for Curl_sockaddr_storage */ #include "../multiif.h" #include "../select.h" #include "../curlx/fopen.h" -#include "../curlx/warnless.h" -#include "curl_path.h" +#include "vssh.h" #include "../curlx/strparse.h" #include "../curlx/base64.h" /* for base64 encoding/decoding */ -/* The last 2 #include files should be in this order */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* Local functions: */ static const char *sftp_libssh2_strerror(unsigned long err); static LIBSSH2_ALLOC_FUNC(my_libssh2_malloc); @@ -124,11 +112,10 @@ const struct Curl_handler Curl_handler_scp = { PORT_SSH, /* defport */ CURLPROTO_SCP, /* protocol */ CURLPROTO_SCP, /* family */ - PROTOPT_DIRLOCK | PROTOPT_CLOSEACTION - | PROTOPT_NOURLQUERY /* flags */ + PROTOPT_DIRLOCK | PROTOPT_CLOSEACTION | /* flags */ + PROTOPT_NOURLQUERY | PROTOPT_CONN_REUSE }; - /* * SFTP protocol handler. */ @@ -155,16 +142,16 @@ const struct Curl_handler Curl_handler_sftp = { PORT_SSH, /* defport */ CURLPROTO_SFTP, /* protocol */ CURLPROTO_SFTP, /* family */ - PROTOPT_DIRLOCK | PROTOPT_CLOSEACTION - | PROTOPT_NOURLQUERY /* flags */ + PROTOPT_DIRLOCK | PROTOPT_CLOSEACTION | /* flags */ + PROTOPT_NOURLQUERY | PROTOPT_CONN_REUSE }; -static void -kbd_callback(const char *name, int name_len, const char *instruction, - int instruction_len, int num_prompts, - const LIBSSH2_USERAUTH_KBDINT_PROMPT *prompts, - LIBSSH2_USERAUTH_KBDINT_RESPONSE *responses, - void **abstract) +static void kbd_callback(const char *name, int name_len, + const char *instruction, int instruction_len, + int num_prompts, + const LIBSSH2_USERAUTH_KBDINT_PROMPT *prompts, + LIBSSH2_USERAUTH_KBDINT_RESPONSE *responses, + void **abstract) { struct Curl_easy *data = (struct Curl_easy *)*abstract; @@ -179,10 +166,10 @@ kbd_callback(const char *name, int name_len, const char *instruction, (void)name_len; (void)instruction; (void)instruction_len; -#endif /* CURL_LIBSSH2_DEBUG */ +#endif /* CURL_LIBSSH2_DEBUG */ if(num_prompts == 1) { struct connectdata *conn = data->conn; - responses[0].text = strdup(conn->passwd); + responses[0].text = curlx_strdup(conn->passwd); responses[0].length = responses[0].text == NULL ? 0 : curlx_uztoui(strlen(conn->passwd)); } @@ -192,30 +179,30 @@ kbd_callback(const char *name, int name_len, const char *instruction, static CURLcode sftp_libssh2_error_to_CURLE(unsigned long err) { switch(err) { - case LIBSSH2_FX_OK: - return CURLE_OK; + case LIBSSH2_FX_OK: + return CURLE_OK; - case LIBSSH2_FX_NO_SUCH_FILE: - case LIBSSH2_FX_NO_SUCH_PATH: - return CURLE_REMOTE_FILE_NOT_FOUND; + case LIBSSH2_FX_NO_SUCH_FILE: + case LIBSSH2_FX_NO_SUCH_PATH: + return CURLE_REMOTE_FILE_NOT_FOUND; - case LIBSSH2_FX_PERMISSION_DENIED: - case LIBSSH2_FX_WRITE_PROTECT: - case LIBSSH2_FX_LOCK_CONFlICT: - return CURLE_REMOTE_ACCESS_DENIED; + case LIBSSH2_FX_PERMISSION_DENIED: + case LIBSSH2_FX_WRITE_PROTECT: + case LIBSSH2_FX_LOCK_CONFlICT: + return CURLE_REMOTE_ACCESS_DENIED; - case LIBSSH2_FX_NO_SPACE_ON_FILESYSTEM: - case LIBSSH2_FX_QUOTA_EXCEEDED: - return CURLE_REMOTE_DISK_FULL; + case LIBSSH2_FX_NO_SPACE_ON_FILESYSTEM: + case LIBSSH2_FX_QUOTA_EXCEEDED: + return CURLE_REMOTE_DISK_FULL; - case LIBSSH2_FX_FILE_ALREADY_EXISTS: - return CURLE_REMOTE_FILE_EXISTS; + case LIBSSH2_FX_FILE_ALREADY_EXISTS: + return CURLE_REMOTE_FILE_EXISTS; - case LIBSSH2_FX_DIR_NOT_EMPTY: - return CURLE_QUOTE_ERROR; + case LIBSSH2_FX_DIR_NOT_EMPTY: + return CURLE_QUOTE_ERROR; - default: - break; + default: + break; } return CURLE_SSH; @@ -224,39 +211,39 @@ static CURLcode sftp_libssh2_error_to_CURLE(unsigned long err) static CURLcode libssh2_session_error_to_CURLE(int err) { switch(err) { - /* Ordered by order of appearance in libssh2.h */ - case LIBSSH2_ERROR_NONE: - return CURLE_OK; + /* Ordered by order of appearance in libssh2.h */ + case LIBSSH2_ERROR_NONE: + return CURLE_OK; - /* This is the error returned by libssh2_scp_recv2 - * on unknown file */ - case LIBSSH2_ERROR_SCP_PROTOCOL: - return CURLE_REMOTE_FILE_NOT_FOUND; + /* This is the error returned by libssh2_scp_recv2 + * on unknown file */ + case LIBSSH2_ERROR_SCP_PROTOCOL: + return CURLE_REMOTE_FILE_NOT_FOUND; - case LIBSSH2_ERROR_SOCKET_NONE: - return CURLE_COULDNT_CONNECT; + case LIBSSH2_ERROR_SOCKET_NONE: + return CURLE_COULDNT_CONNECT; - case LIBSSH2_ERROR_ALLOC: - return CURLE_OUT_OF_MEMORY; + case LIBSSH2_ERROR_ALLOC: + return CURLE_OUT_OF_MEMORY; - case LIBSSH2_ERROR_SOCKET_SEND: - return CURLE_SEND_ERROR; + case LIBSSH2_ERROR_SOCKET_SEND: + return CURLE_SEND_ERROR; - case LIBSSH2_ERROR_HOSTKEY_INIT: - case LIBSSH2_ERROR_HOSTKEY_SIGN: - case LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED: - case LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED: - return CURLE_PEER_FAILED_VERIFICATION; + case LIBSSH2_ERROR_HOSTKEY_INIT: + case LIBSSH2_ERROR_HOSTKEY_SIGN: + case LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED: + case LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED: + return CURLE_PEER_FAILED_VERIFICATION; - case LIBSSH2_ERROR_PASSWORD_EXPIRED: - return CURLE_LOGIN_DENIED; + case LIBSSH2_ERROR_PASSWORD_EXPIRED: + return CURLE_LOGIN_DENIED; - case LIBSSH2_ERROR_SOCKET_TIMEOUT: - case LIBSSH2_ERROR_TIMEOUT: - return CURLE_OPERATION_TIMEDOUT; + case LIBSSH2_ERROR_SOCKET_TIMEOUT: + case LIBSSH2_ERROR_TIMEOUT: + return CURLE_OPERATION_TIMEDOUT; - case LIBSSH2_ERROR_EAGAIN: - return CURLE_AGAIN; + case LIBSSH2_ERROR_EAGAIN: + return CURLE_AGAIN; } return CURLE_SSH; @@ -285,16 +272,9 @@ static LIBSSH2_FREE_FUNC(my_libssh2_free) Curl_cfree(ptr); } -/* - * SSH State machine related code - */ -/* This is the ONLY way to change SSH state! */ -static void myssh_state(struct Curl_easy *data, - struct ssh_conn *sshc, - sshstate nowstate) +#ifndef CURL_DISABLE_VERBOSE_STRINGS +static const char *myssh_statename(sshstate state) { -#if defined(DEBUGBUILD) && !defined(CURL_DISABLE_VERBOSE_STRINGS) - /* for debug purposes */ static const char * const names[] = { "SSH_STOP", "SSH_INIT", @@ -357,16 +337,33 @@ static void myssh_state(struct Curl_easy *data, "SSH_SESSION_FREE", "QUIT" }; - /* a precaution to make sure the lists are in sync */ DEBUGASSERT(CURL_ARRAYSIZE(names) == SSH_LAST); + return ((size_t)state < CURL_ARRAYSIZE(names)) ? names[state] : ""; +} +#else +#define myssh_statename(x) "" +#endif /* !CURL_DISABLE_VERBOSE_STRINGS */ + +#define myssh_state(x, y, z) myssh_set_state(x, y, z) +/* + * SSH State machine related code + */ +/* This is the ONLY way to change SSH state! */ +static void myssh_set_state(struct Curl_easy *data, + struct ssh_conn *sshc, + sshstate nowstate) +{ +#ifndef CURL_DISABLE_VERBOSE_STRINGS if(sshc->state != nowstate) { - infof(data, "SFTP %p state change from %s to %s", - (void *)sshc, names[sshc->state], names[nowstate]); + CURL_TRC_SSH(data, "[%s] -> [%s]", + myssh_statename(sshc->state), + myssh_statename(nowstate)); } -#endif +#else (void)data; +#endif sshc->state = nowstate; } @@ -603,7 +600,7 @@ static CURLcode ssh_check_fingerprint(struct Curl_easy *data, /* The length of fingerprint is 32 bytes for SHA256. * See libssh2_hostkey_hash documentation. */ - if(curlx_base64_encode(fingerprint, 32, &fingerprint_b64, + if(curlx_base64_encode((const uint8_t *)fingerprint, 32, &fingerprint_b64, &fingerprint_b64_len) != CURLE_OK) { myssh_state(data, sshc, SSH_SESSION_FREE); return CURLE_PEER_FAILED_VERIFICATION; @@ -636,12 +633,12 @@ static CURLcode ssh_check_fingerprint(struct Curl_easy *data, failf(data, "Denied establishing ssh session: mismatch sha256 fingerprint. " "Remote %s is not equal to %s", fingerprint_b64, pubkey_sha256); - free(fingerprint_b64); + curlx_free(fingerprint_b64); myssh_state(data, sshc, SSH_SESSION_FREE); return CURLE_PEER_FAILED_VERIFICATION; } - free(fingerprint_b64); + curlx_free(fingerprint_b64); infof(data, "SHA256 checksum match"); } @@ -657,7 +654,7 @@ static CURLcode ssh_check_fingerprint(struct Curl_easy *data, /* The fingerprint points to static storage (!), do not free() it. */ int i; for(i = 0; i < 16; i++) { - curl_msnprintf(&md5buffer[i*2], 3, "%02x", + curl_msnprintf(&md5buffer[i * 2], 3, "%02x", (unsigned char)fingerprint[i]); } @@ -697,7 +694,7 @@ static CURLcode ssh_check_fingerprint(struct Curl_easy *data, rc = data->set.ssh_hostkeyfunc(data->set.ssh_hostkeyfunc_userp, (int)keytype, remotekey, keylen); Curl_set_in_callback(data, FALSE); - if(rc!= CURLKHMATCH_OK) { + if(rc != CURLKHMATCH_OK) { myssh_state(data, sshc, SSH_SESSION_FREE); return CURLE_PEER_FAILED_VERIFICATION; } @@ -727,30 +724,20 @@ static CURLcode ssh_force_knownhost_key_type(struct Curl_easy *data, { CURLcode result = CURLE_OK; - static const char * const hostkey_method_ssh_ed25519 - = "ssh-ed25519"; - static const char * const hostkey_method_ssh_ecdsa_521 - = "ecdsa-sha2-nistp521"; - static const char * const hostkey_method_ssh_ecdsa_384 - = "ecdsa-sha2-nistp384"; - static const char * const hostkey_method_ssh_ecdsa_256 - = "ecdsa-sha2-nistp256"; - static const char * const hostkey_method_ssh_rsa_all - = "rsa-sha2-256,rsa-sha2-512,ssh-rsa"; - static const char * const hostkey_method_ssh_dss - = "ssh-dss"; - - const char *hostkey_method = NULL; - struct connectdata *conn = data->conn; - struct libssh2_knownhost* store = NULL; - const char *kh_name_end = NULL; - size_t kh_name_size = 0; - int port = 0; + static const char hostkey_method_ssh_ed25519[] = "ssh-ed25519"; + static const char hostkey_method_ssh_ecdsa_521[] = "ecdsa-sha2-nistp521"; + static const char hostkey_method_ssh_ecdsa_384[] = "ecdsa-sha2-nistp384"; + static const char hostkey_method_ssh_ecdsa_256[] = "ecdsa-sha2-nistp256"; + static const char hostkey_method_ssh_rsa_all[] = + "rsa-sha2-256,rsa-sha2-512,ssh-rsa"; + static const char hostkey_method_ssh_dss[] = "ssh-dss"; bool found = FALSE; if(sshc->kh && !data->set.str[STRING_SSH_HOST_PUBLIC_KEY_MD5] && !data->set.str[STRING_SSH_HOST_PUBLIC_KEY_SHA256]) { + struct libssh2_knownhost *store = NULL; + struct connectdata *conn = data->conn; /* lets try to find our host in the known hosts file */ while(!libssh2_knownhost_get(sshc->kh, &store, store)) { /* For non-standard ports, the name will be enclosed in */ @@ -758,17 +745,21 @@ static CURLcode ssh_force_knownhost_key_type(struct Curl_easy *data, if(store) { if(store->name) { if(store->name[0] == '[') { - kh_name_end = strstr(store->name, "]:"); + curl_off_t port; + size_t kh_name_size = 0; + const char *p; + const char *kh_name_end = strstr(store->name, "]:"); if(!kh_name_end) { infof(data, "Invalid host pattern %s in %s", store->name, data->set.str[STRING_SSH_KNOWNHOSTS]); continue; } - port = atoi(kh_name_end + 2); - if(kh_name_end && (port == conn->remote_port)) { + p = kh_name_end + 2; /* start of port number */ + if(!curlx_str_number(&p, &port, 0xffff) && + (kh_name_end && (port == conn->remote_port))) { kh_name_size = strlen(store->name) - 1 - strlen(kh_name_end); if(strncmp(store->name + 1, - conn->host.name, kh_name_size) == 0) { + conn->host.name, kh_name_size) == 0) { found = TRUE; break; } @@ -788,6 +779,7 @@ static CURLcode ssh_force_knownhost_key_type(struct Curl_easy *data, if(found) { int rc; + const char *hostkey_method = NULL; infof(data, "Found host %s in %s", conn->host.name, data->set.str[STRING_SSH_KNOWNHOSTS]); @@ -883,11 +875,11 @@ static CURLcode sftp_quote(struct Curl_easy *data, Curl_debug(data, CURLINFO_HEADER_OUT, "PWD\n", 4); Curl_debug(data, CURLINFO_HEADER_IN, tmp, strlen(tmp)); - /* this sends an FTP-like "header" to the header callback so that the - current directory can be read very similar to how it is read when + /* this sends an FTP-like "header" to the header callback so that + the current directory can be read similar to how it is read when using ordinary FTP. */ result = Curl_client_write(data, CLIENTWRITE_HEADER, tmp, strlen(tmp)); - free(tmp); + curlx_free(tmp); if(!result) myssh_state(data, sshc, SSH_SFTP_NEXT_QUOTE); return result; @@ -962,7 +954,7 @@ static CURLcode sftp_quote(struct Curl_easy *data, else if(!strncmp(cmd, "mkdir ", 6)) { if(*cp) return_quote_error(data, sshc); - /* create dir */ + /* create directory */ myssh_state(data, sshc, SSH_SFTP_QUOTE_MKDIR); return result; } @@ -985,7 +977,7 @@ static CURLcode sftp_quote(struct Curl_easy *data, else if(!strncmp(cmd, "rmdir ", 6)) { if(*cp) return_quote_error(data, sshc); - /* delete dir */ + /* delete directory */ myssh_state(data, sshc, SSH_SFTP_QUOTE_RMDIR); return result; } @@ -1008,11 +1000,10 @@ static CURLcode sftp_quote(struct Curl_easy *data, return CURLE_QUOTE_ERROR; } -static CURLcode -sftp_upload_init(struct Curl_easy *data, - struct ssh_conn *sshc, - struct SSHPROTO *sshp, - bool *blockp) +static CURLcode sftp_upload_init(struct Curl_easy *data, + struct ssh_conn *sshc, + struct SSHPROTO *sshp, + bool *blockp) { unsigned long flags; @@ -1139,7 +1130,7 @@ sftp_upload_init(struct Curl_easy *data, } /* seekerr == CURL_SEEKFUNC_CANTSEEK (cannot seek to offset) */ do { - char scratch[4*1024]; + char scratch[4 * 1024]; size_t readthisamountnow = (data->state.resume_from - passed > (curl_off_t)sizeof(scratch)) ? @@ -1182,10 +1173,6 @@ sftp_upload_init(struct Curl_easy *data, /* not set by Curl_xfer_setup to preserve keepon bits */ data->conn->recv_idx = FIRSTSOCKET; - /* store this original bitmask setup to use later on if we cannot - figure out a "real" bitmask */ - sshc->orig_waitfor = data->req.keepon; - /* since we do not really wait for anything at this point, we want the state machine to move on as soon as possible so mark this as dirty */ Curl_multi_mark_dirty(data); @@ -1209,8 +1196,11 @@ static CURLcode ssh_state_pkey_init(struct Curl_easy *data, sshc->rsa_pub = sshc->rsa = NULL; - if(data->set.str[STRING_SSH_PRIVATE_KEY]) - sshc->rsa = strdup(data->set.str[STRING_SSH_PRIVATE_KEY]); + if(data->set.str[STRING_SSH_PRIVATE_KEY]) { + sshc->rsa = curlx_strdup(data->set.str[STRING_SSH_PRIVATE_KEY]); + if(!sshc->rsa) + out_of_memory = TRUE; + } else { /* To ponder about: should really the lib be messing about with the HOME environment variable etc? */ @@ -1224,7 +1214,7 @@ static CURLcode ssh_state_pkey_init(struct Curl_easy *data, if(!sshc->rsa) out_of_memory = TRUE; else if(curlx_stat(sshc->rsa, &sbuf)) { - free(sshc->rsa); + curlx_free(sshc->rsa); sshc->rsa = curl_maprintf("%s/.ssh/id_dsa", home); if(!sshc->rsa) out_of_memory = TRUE; @@ -1232,19 +1222,19 @@ static CURLcode ssh_state_pkey_init(struct Curl_easy *data, Curl_safefree(sshc->rsa); } } - free(home); + curlx_free(home); } if(!out_of_memory && !sshc->rsa) { /* Nothing found; try the current dir. */ - sshc->rsa = strdup("id_rsa"); + sshc->rsa = curlx_strdup("id_rsa"); if(sshc->rsa && curlx_stat(sshc->rsa, &sbuf)) { - free(sshc->rsa); - sshc->rsa = strdup("id_dsa"); + curlx_free(sshc->rsa); + sshc->rsa = curlx_strdup("id_dsa"); if(sshc->rsa && curlx_stat(sshc->rsa, &sbuf)) { - free(sshc->rsa); + curlx_free(sshc->rsa); /* Out of guesses. Set to the empty string to avoid * surprising info messages. */ - sshc->rsa = strdup(""); + sshc->rsa = curlx_strdup(""); } } } @@ -1255,10 +1245,10 @@ static CURLcode ssh_state_pkey_init(struct Curl_easy *data, * libssh2 extract the public key from the private key file. * This is done by simply passing sshc->rsa_pub = NULL. */ - if(data->set.str[STRING_SSH_PUBLIC_KEY] + if(!out_of_memory && data->set.str[STRING_SSH_PUBLIC_KEY] /* treat empty string the same way as NULL */ && data->set.str[STRING_SSH_PUBLIC_KEY][0]) { - sshc->rsa_pub = strdup(data->set.str[STRING_SSH_PUBLIC_KEY]); + sshc->rsa_pub = curlx_strdup(data->set.str[STRING_SSH_PUBLIC_KEY]); if(!sshc->rsa_pub) out_of_memory = TRUE; } @@ -1286,11 +1276,10 @@ static CURLcode ssh_state_pkey_init(struct Curl_easy *data, return 0; } -static CURLcode -sftp_quote_stat(struct Curl_easy *data, - struct ssh_conn *sshc, - struct SSHPROTO *sshp, - bool *blockp) +static CURLcode sftp_quote_stat(struct Curl_easy *data, + struct ssh_conn *sshc, + struct SSHPROTO *sshp, + bool *blockp) { char *cmd = sshc->quote_item->data; sshc->acceptfail = FALSE; @@ -1398,11 +1387,10 @@ sftp_quote_stat(struct Curl_easy *data, return CURLE_QUOTE_ERROR; } -static CURLcode -sftp_download_stat(struct Curl_easy *data, - struct ssh_conn *sshc, - struct SSHPROTO *sshp, - bool *blockp) +static CURLcode sftp_download_stat(struct Curl_easy *data, + struct ssh_conn *sshc, + struct SSHPROTO *sshp, + bool *blockp) { LIBSSH2_SFTP_ATTRIBUTES attrs; int rc = libssh2_sftp_stat_ex(sshc->sftp_session, sshp->path, @@ -1434,42 +1422,11 @@ sftp_download_stat(struct Curl_easy *data, return CURLE_BAD_DOWNLOAD_RESUME; } if(data->state.use_range) { - curl_off_t from, to; - const char *p = data->state.range; - int to_t, from_t; - - from_t = curlx_str_number(&p, &from, CURL_OFF_T_MAX); - if(from_t == STRE_OVERFLOW) - return CURLE_RANGE_ERROR; - curlx_str_passblanks(&p); - (void)curlx_str_single(&p, '-'); - - to_t = curlx_str_numblanks(&p, &to); - if(to_t == STRE_OVERFLOW) - return CURLE_RANGE_ERROR; - if((to_t == STRE_NO_NUM) /* no "to" value given */ - || (to >= size)) { - to = size - 1; - } - if(from_t) { - /* from is relative to end of file */ - from = size - to; - to = size - 1; - } - if(from > size) { - failf(data, "Offset (%" FMT_OFF_T ") was beyond file size (%" - FMT_OFF_T ")", from, (curl_off_t)attrs.filesize); - return CURLE_BAD_DOWNLOAD_RESUME; - } - if(from > to) { - from = to; - size = 0; - } - else { - if((to - from) == CURL_OFF_T_MAX) - return CURLE_RANGE_ERROR; - size = to - from + 1; - } + curl_off_t from; + CURLcode result = Curl_ssh_range(data, data->state.range, size, + &from, &size); + if(result) + return result; libssh2_sftp_seek64(sshc->sftp_handle, (libssh2_uint64_t)from); } @@ -1502,8 +1459,7 @@ sftp_download_stat(struct Curl_easy *data, /* Now store the number of bytes we are expected to download */ data->req.size = attrs.filesize - data->state.resume_from; data->req.maxdownload = attrs.filesize - data->state.resume_from; - Curl_pgrsSetDownloadSize(data, - attrs.filesize - data->state.resume_from); + Curl_pgrsSetDownloadSize(data, attrs.filesize - data->state.resume_from); libssh2_sftp_seek64(sshc->sftp_handle, (libssh2_uint64_t)data->state.resume_from); } @@ -1541,7 +1497,7 @@ static CURLcode sftp_readdir(struct Curl_easy *data, return result; } if(rc > 0) { - size_t readdir_len = (size_t) rc; + size_t readdir_len = (size_t)rc; sshp->readdir_filename[readdir_len] = '\0'; if(data->set.list_only) { @@ -1673,8 +1629,7 @@ static CURLcode ssh_state_authlist(struct Curl_easy *data, myssh_state(data, sshc, SSH_SESSION_FREE); return libssh2_session_error_to_CURLE(rc); } - infof(data, "SSH authentication methods available: %s", - sshc->authlist); + infof(data, "SSH authentication methods available: %s", sshc->authlist); myssh_state(data, sshc, SSH_AUTH_PKEY_INIT); return CURLE_OK; @@ -1713,8 +1668,7 @@ static CURLcode ssh_state_auth_pkey(struct Curl_easy *data, err_msg = unknown; } else { - (void)libssh2_session_last_error(sshc->ssh_session, - &err_msg, NULL, 0); + (void)libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0); } infof(data, "SSH public key authentication failed: %s", err_msg); myssh_state(data, sshc, SSH_AUTH_PASS_INIT); @@ -1776,8 +1730,8 @@ static CURLcode ssh_state_auth_agent_init(struct Curl_easy *data, struct ssh_conn *sshc) { int rc = 0; - if((data->set.ssh_auth_types & CURLSSH_AUTH_AGENT) - && (strstr(sshc->authlist, "publickey") != NULL)) { + if((data->set.ssh_auth_types & CURLSSH_AUTH_AGENT) && + (strstr(sshc->authlist, "publickey") != NULL)) { /* Connect to the ssh-agent */ /* The agent could be shared by a curl thread i believe @@ -1872,8 +1826,8 @@ static CURLcode ssh_state_auth_agent(struct Curl_easy *data, static CURLcode ssh_state_auth_key_init(struct Curl_easy *data, struct ssh_conn *sshc) { - if((data->set.ssh_auth_types & CURLSSH_AUTH_KEYBOARD) - && (strstr(sshc->authlist, "keyboard-interactive") != NULL)) { + if((data->set.ssh_auth_types & CURLSSH_AUTH_KEYBOARD) && + (strstr(sshc->authlist, "keyboard-interactive") != NULL)) { myssh_state(data, sshc, SSH_AUTH_KEY); } else { @@ -1947,8 +1901,7 @@ static CURLcode ssh_state_sftp_init(struct Curl_easy *data, LIBSSH2_ERROR_EAGAIN) return CURLE_AGAIN; - (void)libssh2_session_last_error(sshc->ssh_session, - &err_msg, NULL, 0); + (void)libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0); failf(data, "Failure initializing sftp session: %s", err_msg); myssh_state(data, sshc, SSH_SESSION_FREE); return CURLE_FAILED_INIT; @@ -1973,12 +1926,12 @@ static CURLcode ssh_state_sftp_realpath(struct Curl_easy *data, myssh_state(data, sshc, SSH_STOP); if(rc > 0) { - free(sshc->homedir); - sshc->homedir = strdup(sshp->readdir_filename); + curlx_free(sshc->homedir); + sshc->homedir = curlx_strdup(sshp->readdir_filename); if(!sshc->homedir) return CURLE_OUT_OF_MEMORY; - free(data->state.most_recent_ftp_entrypath); - data->state.most_recent_ftp_entrypath = strdup(sshc->homedir); + curlx_free(data->state.most_recent_ftp_entrypath); + data->state.most_recent_ftp_entrypath = curlx_strdup(sshc->homedir); if(!data->state.most_recent_ftp_entrypath) return CURLE_OUT_OF_MEMORY; } @@ -1992,8 +1945,7 @@ static CURLcode ssh_state_sftp_realpath(struct Curl_easy *data, /* in this case, the error was not in the SFTP level but for example a time-out or similar */ result = CURLE_SSH; - DEBUGF(infof(data, "error = %lu makes libcurl = %d", - sftperr, (int)result)); + CURL_TRC_SSH(data, "error = %lu makes libcurl = %d", sftperr, (int)result); return result; } @@ -2001,7 +1953,7 @@ static CURLcode ssh_state_sftp_realpath(struct Curl_easy *data, get the homedir here, we get the "workingpath" in the DO action since the homedir will remain the same between request but the working path will not. */ - DEBUGF(infof(data, "SSH CONNECT phase done")); + CURL_TRC_SSH(data, "CONNECT phase done"); return CURLE_OK; } @@ -2103,10 +2055,10 @@ static CURLcode ssh_state_sftp_quote_setstat(struct Curl_easy *data, if(rc && !sshc->acceptfail) { unsigned long sftperr = libssh2_sftp_last_error(sshc->sftp_session); + failf(data, "Attempt to set SFTP stats for \"%s\" failed: %s", + sshc->quote_path2, sftp_libssh2_strerror(sftperr)); Curl_safefree(sshc->quote_path1); Curl_safefree(sshc->quote_path2); - failf(data, "Attempt to set SFTP stats failed: %s", - sftp_libssh2_strerror(sftperr)); myssh_state(data, sshc, SSH_SFTP_CLOSE); sshc->nextstate = SSH_NO_STATE; return CURLE_QUOTE_ERROR; @@ -2129,10 +2081,11 @@ static CURLcode ssh_state_sftp_quote_symlink(struct Curl_easy *data, if(rc && !sshc->acceptfail) { unsigned long sftperr = libssh2_sftp_last_error(sshc->sftp_session); + failf(data, "symlink \"%s\" to \"%s\" failed: %s", + sshc->quote_path1, sshc->quote_path2, + sftp_libssh2_strerror(sftperr)); Curl_safefree(sshc->quote_path1); Curl_safefree(sshc->quote_path2); - failf(data, "symlink command failed: %s", - sftp_libssh2_strerror(sftperr)); myssh_state(data, sshc, SSH_SFTP_CLOSE); sshc->nextstate = SSH_NO_STATE; return CURLE_QUOTE_ERROR; @@ -2152,9 +2105,9 @@ static CURLcode ssh_state_sftp_quote_mkdir(struct Curl_easy *data, if(rc && !sshc->acceptfail) { unsigned long sftperr = libssh2_sftp_last_error(sshc->sftp_session); + failf(data, "mkdir \"%s\" failed: %s", + sshc->quote_path1, sftp_libssh2_strerror(sftperr)); Curl_safefree(sshc->quote_path1); - failf(data, "mkdir command failed: %s", - sftp_libssh2_strerror(sftperr)); myssh_state(data, sshc, SSH_SFTP_CLOSE); sshc->nextstate = SSH_NO_STATE; return CURLE_QUOTE_ERROR; @@ -2180,10 +2133,11 @@ static CURLcode ssh_state_sftp_quote_rename(struct Curl_easy *data, if(rc && !sshc->acceptfail) { unsigned long sftperr = libssh2_sftp_last_error(sshc->sftp_session); + failf(data, "rename \"%s\" to \"%s\" failed: %s", + sshc->quote_path1, sshc->quote_path2, + sftp_libssh2_strerror(sftperr)); Curl_safefree(sshc->quote_path1); Curl_safefree(sshc->quote_path2); - failf(data, "rename command failed: %s", - sftp_libssh2_strerror(sftperr)); myssh_state(data, sshc, SSH_SFTP_CLOSE); sshc->nextstate = SSH_NO_STATE; return CURLE_QUOTE_ERROR; @@ -2202,9 +2156,9 @@ static CURLcode ssh_state_sftp_quote_rmdir(struct Curl_easy *data, if(rc && !sshc->acceptfail) { unsigned long sftperr = libssh2_sftp_last_error(sshc->sftp_session); + failf(data, "rmdir \"%s\" failed: %s", + sshc->quote_path1, sftp_libssh2_strerror(sftperr)); Curl_safefree(sshc->quote_path1); - failf(data, "rmdir command failed: %s", - sftp_libssh2_strerror(sftperr)); myssh_state(data, sshc, SSH_SFTP_CLOSE); sshc->nextstate = SSH_NO_STATE; return CURLE_QUOTE_ERROR; @@ -2223,8 +2177,9 @@ static CURLcode ssh_state_sftp_quote_unlink(struct Curl_easy *data, if(rc && !sshc->acceptfail) { unsigned long sftperr = libssh2_sftp_last_error(sshc->sftp_session); + failf(data, "rm \"%s\" failed: %s", + sshc->quote_path1, sftp_libssh2_strerror(sftperr)); Curl_safefree(sshc->quote_path1); - failf(data, "rm command failed: %s", sftp_libssh2_strerror(sftperr)); myssh_state(data, sshc, SSH_SFTP_CLOSE); sshc->nextstate = SSH_NO_STATE; return CURLE_QUOTE_ERROR; @@ -2246,9 +2201,9 @@ static CURLcode ssh_state_sftp_quote_statvfs(struct Curl_easy *data, if(rc && !sshc->acceptfail) { unsigned long sftperr = libssh2_sftp_last_error(sshc->sftp_session); + failf(data, "statvfs \"%s\" failed: %s", + sshc->quote_path1, sftp_libssh2_strerror(sftperr)); Curl_safefree(sshc->quote_path1); - failf(data, "statvfs command failed: %s", - sftp_libssh2_strerror(sftperr)); myssh_state(data, sshc, SSH_SFTP_CLOSE); sshc->nextstate = SSH_NO_STATE; return CURLE_QUOTE_ERROR; @@ -2285,7 +2240,7 @@ static CURLcode ssh_state_sftp_quote_statvfs(struct Curl_easy *data, } result = Curl_client_write(data, CLIENTWRITE_HEADER, tmp, strlen(tmp)); - free(tmp); + curlx_free(tmp); if(result) { myssh_state(data, sshc, SSH_SFTP_CLOSE); sshc->nextstate = SSH_NO_STATE; @@ -2311,9 +2266,9 @@ static CURLcode ssh_state_sftp_create_dirs_mkdir(struct Curl_easy *data, ++sshc->slash_pos; if(rc < 0) { /* - * Abort if failure was not that the dir already exists or the - * permission was denied (creation might succeed further down the - * path) - retry on unspecific FAILURE also + * Abort if failure was not that the directory already exists or + * the permission was denied (creation might succeed further down + * the path) - retry on unspecific FAILURE also */ unsigned long sftperr = libssh2_sftp_last_error(sshc->sftp_session); if((sftperr != LIBSSH2_FX_FILE_ALREADY_EXISTS) && @@ -2416,8 +2371,7 @@ static CURLcode ssh_state_scp_download_init(struct Curl_easy *data, LIBSSH2_ERROR_EAGAIN) return CURLE_AGAIN; - ssh_err = (int)(libssh2_session_last_error(sshc->ssh_session, - &err_msg, NULL, 0)); + ssh_err = libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0); failf(data, "%s", err_msg); myssh_state(data, sshc, SSH_SCP_CHANNEL_FREE); return libssh2_session_error_to_CURLE(ssh_err); @@ -2447,8 +2401,7 @@ static CURLcode ssh_state_sftp_close(struct Curl_easy *data, if(rc < 0) { char *err_msg = NULL; - (void)libssh2_session_last_error(sshc->ssh_session, - &err_msg, NULL, 0); + (void)libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0); infof(data, "Failed to close libssh2 file: %d %s", rc, err_msg); } sshc->sftp_handle = NULL; @@ -2456,7 +2409,7 @@ static CURLcode ssh_state_sftp_close(struct Curl_easy *data, Curl_safefree(sshp->path); - DEBUGF(infof(data, "SFTP DONE done")); + CURL_TRC_SSH(data, "SFTP DONE done"); /* Check if nextstate is set and move .nextstate could be POSTQUOTE_INIT After nextstate is executed, the control should come back to @@ -2486,8 +2439,7 @@ static CURLcode ssh_state_sftp_shutdown(struct Curl_easy *data, if(rc < 0) { char *err_msg = NULL; - (void)libssh2_session_last_error(sshc->ssh_session, &err_msg, - NULL, 0); + (void)libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0); infof(data, "Failed to close libssh2 file: %d %s", rc, err_msg); } sshc->sftp_handle = NULL; @@ -2559,8 +2511,7 @@ static CURLcode ssh_state_scp_upload_init(struct Curl_easy *data, LIBSSH2_ERROR_EAGAIN) return CURLE_AGAIN; - ssh_err = (int)(libssh2_session_last_error(sshc->ssh_session, - &err_msg, NULL, 0)); + ssh_err = libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0); failf(data, "%s", err_msg); myssh_state(data, sshc, SSH_SCP_CHANNEL_FREE); result = libssh2_session_error_to_CURLE(ssh_err); @@ -2580,10 +2531,6 @@ static CURLcode ssh_state_scp_upload_init(struct Curl_easy *data, /* not set by Curl_xfer_setup to preserve keepon bits */ data->conn->recv_idx = FIRSTSOCKET; - /* store this original bitmask setup to use later on if we cannot - figure out a "real" bitmask */ - sshc->orig_waitfor = data->req.keepon; - myssh_state(data, sshc, SSH_STOP); return CURLE_OK; @@ -2603,10 +2550,8 @@ static CURLcode ssh_state_session_disconnect(struct Curl_easy *data, if(rc < 0) { char *err_msg = NULL; - (void)libssh2_session_last_error(sshc->ssh_session, - &err_msg, NULL, 0); - infof(data, "Failed to free libssh2 scp subsystem: %d %s", - rc, err_msg); + (void)libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0); + infof(data, "Failed to free libssh2 scp subsystem: %d %s", rc, err_msg); } sshc->ssh_channel = NULL; } @@ -2618,10 +2563,8 @@ static CURLcode ssh_state_session_disconnect(struct Curl_easy *data, if(rc < 0) { char *err_msg = NULL; - (void)libssh2_session_last_error(sshc->ssh_session, - &err_msg, NULL, 0); - infof(data, "Failed to disconnect libssh2 session: %d %s", - rc, err_msg); + (void)libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0); + infof(data, "Failed to disconnect libssh2 session: %d %s", rc, err_msg); } } @@ -2786,8 +2729,7 @@ static CURLcode ssh_statemachine(struct Curl_easy *data, } break; - case SSH_SFTP_FILETIME: - { + case SSH_SFTP_FILETIME: { LIBSSH2_SFTP_ATTRIBUTES attrs; int rc; @@ -2814,7 +2756,7 @@ static CURLcode ssh_statemachine(struct Curl_easy *data, if(data->state.upload) myssh_state(data, sshc, SSH_SFTP_UPLOAD_INIT); else if(sshp) { - if(sshp->path[strlen(sshp->path)-1] == '/') + if(sshp->path[strlen(sshp->path) - 1] == '/') myssh_state(data, sshc, SSH_SFTP_READDIR_INIT); else myssh_state(data, sshc, SSH_SFTP_DOWNLOAD_INIT); @@ -3046,7 +2988,7 @@ static CURLcode ssh_statemachine(struct Curl_easy *data, } sshc->ssh_channel = NULL; } - DEBUGF(infof(data, "SCP DONE phase complete")); + CURL_TRC_SSH(data, "SCP DONE phase complete"); myssh_state(data, sshc, SSH_STOP); break; @@ -3080,6 +3022,8 @@ static CURLcode ssh_statemachine(struct Curl_easy *data, *block = TRUE; result = CURLE_OK; } + CURL_TRC_SSH(data, "[%s] statemachine() -> %d, block=%d", + myssh_statename(sshc->state), result, *block); return result; } @@ -3089,15 +3033,29 @@ static CURLcode ssh_statemachine(struct Curl_easy *data, static CURLcode ssh_pollset(struct Curl_easy *data, struct easy_pollset *ps) { - int flags = 0; struct connectdata *conn = data->conn; - if(conn->waitfor & KEEP_RECV) - flags |= CURL_POLL_IN; - if(conn->waitfor & KEEP_SEND) - flags |= CURL_POLL_OUT; - return flags ? - Curl_pollset_change(data, ps, conn->sock[FIRSTSOCKET], flags, 0) : - CURLE_OK; + struct ssh_conn *sshc = Curl_conn_meta_get(conn, CURL_META_SSH_CONN); + curl_socket_t sock = conn->sock[FIRSTSOCKET]; + int waitfor; + + if(!sshc || (sock == CURL_SOCKET_BAD)) + return CURLE_FAILED_INIT; + + waitfor = sshc->waitfor ? sshc->waitfor : data->req.keepon; + if(waitfor) { + int flags = 0; + if(waitfor & KEEP_RECV) + flags |= CURL_POLL_IN; + if(waitfor & KEEP_SEND) + flags |= CURL_POLL_OUT; + DEBUGASSERT(flags); + CURL_TRC_SSH(data, "pollset, flags=%x", flags); + return Curl_pollset_change(data, ps, sock, flags, 0); + } + /* While we still have a session, we listen incoming data. */ + if(sshc->ssh_session) + return Curl_pollset_change(data, ps, sock, CURL_POLL_IN, 0); + return CURLE_OK; } /* @@ -3111,20 +3069,18 @@ static void ssh_block2waitfor(struct Curl_easy *data, struct ssh_conn *sshc, bool block) { - struct connectdata *conn = data->conn; int dir = 0; + (void)data; if(block) { dir = libssh2_session_block_directions(sshc->ssh_session); if(dir) { /* translate the libssh2 define bits into our own bit defines */ - conn->waitfor = ((dir&LIBSSH2_SESSION_BLOCK_INBOUND) ? KEEP_RECV : 0) | - ((dir&LIBSSH2_SESSION_BLOCK_OUTBOUND) ? KEEP_SEND : 0); + sshc->waitfor = ((dir & LIBSSH2_SESSION_BLOCK_INBOUND) ? KEEP_RECV : 0) | + ((dir & LIBSSH2_SESSION_BLOCK_OUTBOUND) ? KEEP_SEND : 0); } } if(!dir) - /* It did not block or libssh2 did not reveal in which direction, put back - the original set */ - conn->waitfor = sshc->orig_waitfor; + sshc->waitfor = 0; } /* called repeatedly until done from multi.c */ @@ -3156,32 +3112,28 @@ static CURLcode ssh_block_statemach(struct Curl_easy *data, bool disconnect) { CURLcode result = CURLE_OK; - struct curltime dis = curlx_now(); + struct curltime start = *Curl_pgrs_now(data); while((sshc->state != SSH_STOP) && !result) { bool block; - timediff_t left = 1000; - struct curltime now = curlx_now(); + timediff_t left_ms = 1000; result = ssh_statemachine(data, sshc, sshp, &block); if(result) break; if(!disconnect) { - if(Curl_pgrsUpdate(data)) - return CURLE_ABORTED_BY_CALLBACK; - - result = Curl_speedcheck(data, now); + result = Curl_pgrsCheck(data); if(result) break; - left = Curl_timeleft(data, NULL, FALSE); - if(left < 0) { + left_ms = Curl_timeleft_ms(data, FALSE); + if(left_ms < 0) { failf(data, "Operation timed out"); return CURLE_OPERATION_TIMEDOUT; } } - else if(curlx_timediff(now, dis) > 1000) { + else if(curlx_ptimediff_ms(Curl_pgrs_now(data), &start) > 1000) { /* disconnect timeout */ failf(data, "Disconnect timed out"); result = CURLE_OK; @@ -3199,7 +3151,7 @@ static CURLcode ssh_block_statemach(struct Curl_easy *data, fd_write = sock; /* wait for the socket to become ready */ (void)Curl_socket_check(fd_read, CURL_SOCKET_BAD, fd_write, - left > 1000 ? 1000 : left); + left_ms > 1000 ? 1000 : left_ms); } } @@ -3214,7 +3166,7 @@ static void myssh_easy_dtor(void *key, size_t klen, void *entry) Curl_safefree(sshp->path); curlx_dyn_free(&sshp->readdir); curlx_dyn_free(&sshp->readdir_link); - free(sshp); + curlx_free(sshp); } static void myssh_conn_dtor(void *key, size_t klen, void *entry) @@ -3223,7 +3175,7 @@ static void myssh_conn_dtor(void *key, size_t klen, void *entry) (void)key; (void)klen; sshc_cleanup(sshc, NULL, TRUE); - free(sshc); + curlx_free(sshc); } /* @@ -3236,14 +3188,14 @@ static CURLcode ssh_setup_connection(struct Curl_easy *data, struct SSHPROTO *sshp; (void)conn; - sshc = calloc(1, sizeof(*sshc)); + sshc = curlx_calloc(1, sizeof(*sshc)); if(!sshc) return CURLE_OUT_OF_MEMORY; if(Curl_conn_meta_set(conn, CURL_META_SSH_CONN, sshc, myssh_conn_dtor)) return CURLE_OUT_OF_MEMORY; - sshp = calloc(1, sizeof(*sshp)); + sshp = curlx_calloc(1, sizeof(*sshp)); if(!sshp) return CURLE_OUT_OF_MEMORY; @@ -3333,24 +3285,24 @@ static CURLcode ssh_connect(struct Curl_easy *data, bool *done) { const char *crypto_str; switch(libssh2_crypto_engine()) { - case libssh2_gcrypt: - crypto_str = "libgcrypt"; - break; - case libssh2_mbedtls: - crypto_str = "mbedTLS"; - break; - case libssh2_openssl: - crypto_str = "openssl compatible"; - break; - case libssh2_os400qc3: - crypto_str = "OS400QC3"; - break; - case libssh2_wincng: - crypto_str = "WinCNG"; - break; - default: - crypto_str = NULL; - break; + case libssh2_gcrypt: + crypto_str = "libgcrypt"; + break; + case libssh2_mbedtls: + crypto_str = "mbedTLS"; + break; + case libssh2_openssl: + crypto_str = "openssl compatible"; + break; + case libssh2_os400qc3: + crypto_str = "OS400QC3"; + break; + case libssh2_wincng: + crypto_str = "WinCNG"; + break; + default: + crypto_str = NULL; + break; } if(crypto_str) infof(data, "libssh2 cryptography backend: %s", crypto_str); @@ -3360,10 +3312,6 @@ static CURLcode ssh_connect(struct Curl_easy *data, bool *done) if(!sshc) return CURLE_FAILED_INIT; - /* We default to persistent connections. We set this already in this connect - function to make the reuse checks properly be able to check this bit. */ - connkeep(conn, "SSH default"); - infof(data, "User: '%s'", conn->user); #ifdef CURL_LIBSSH2_DEBUG infof(data, "Password: %s", conn->passwd); @@ -3505,15 +3453,14 @@ static CURLcode ssh_connect(struct Curl_easy *data, bool *done) * the options previously setup. */ -static -CURLcode scp_perform(struct Curl_easy *data, - bool *connected, - bool *dophase_done) +static CURLcode scp_perform(struct Curl_easy *data, + bool *connected, + bool *dophase_done) { struct ssh_conn *sshc = Curl_conn_meta_get(data->conn, CURL_META_SSH_CONN); CURLcode result = CURLE_OK; - DEBUGF(infof(data, "DO phase starts")); + CURL_TRC_SSH(data, "DO phase starts"); *dophase_done = FALSE; /* not done yet */ if(!sshc) @@ -3528,7 +3475,7 @@ CURLcode scp_perform(struct Curl_easy *data, *connected = Curl_conn_is_connected(data->conn, FIRSTSOCKET); if(*dophase_done) { - DEBUGF(infof(data, "DO phase is complete")); + CURL_TRC_SSH(data, "DO phase is complete"); } return result; @@ -3542,7 +3489,7 @@ static CURLcode scp_doing(struct Curl_easy *data, result = ssh_multi_statemach(data, dophase_done); if(*dophase_done) { - DEBUGF(infof(data, "DO phase is complete")); + CURL_TRC_SSH(data, "DO phase is complete"); } return result; } @@ -3564,18 +3511,15 @@ static CURLcode ssh_do(struct Curl_easy *data, bool *done) return CURLE_FAILED_INIT; data->req.size = -1; /* make sure this is unknown at this point */ - sshc->secondCreateDirs = 0; /* reset the create dir attempt state + sshc->secondCreateDirs = 0; /* reset the create directory attempt state variable */ - Curl_pgrsSetUploadCounter(data, 0); - Curl_pgrsSetDownloadCounter(data, 0); - Curl_pgrsSetUploadSize(data, -1); - Curl_pgrsSetDownloadSize(data, -1); + Curl_pgrsReset(data); if(conn->handler->protocol & CURLPROTO_SCP) - result = scp_perform(data, &connected, done); + result = scp_perform(data, &connected, done); else - result = sftp_perform(data, &connected, done); + result = sftp_perform(data, &connected, done); return result; } @@ -3594,8 +3538,7 @@ static CURLcode sshc_cleanup(struct ssh_conn *sshc, struct Curl_easy *data, rc = libssh2_agent_disconnect(sshc->ssh_agent); if((rc < 0) && data) { char *err_msg = NULL; - (void)libssh2_session_last_error(sshc->ssh_session, - &err_msg, NULL, 0); + (void)libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0); infof(data, "Failed to disconnect from libssh2 agent: %d %s", rc, err_msg); } @@ -3615,8 +3558,7 @@ static CURLcode sshc_cleanup(struct ssh_conn *sshc, struct Curl_easy *data, rc = libssh2_sftp_close(sshc->sftp_handle); if((rc < 0) && data) { char *err_msg = NULL; - (void)libssh2_session_last_error(sshc->ssh_session, &err_msg, - NULL, 0); + (void)libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0); infof(data, "Failed to close libssh2 file: %d %s", rc, err_msg); } if(!block && (rc == LIBSSH2_ERROR_EAGAIN)) @@ -3629,10 +3571,8 @@ static CURLcode sshc_cleanup(struct ssh_conn *sshc, struct Curl_easy *data, rc = libssh2_channel_free(sshc->ssh_channel); if((rc < 0) && data) { char *err_msg = NULL; - (void)libssh2_session_last_error(sshc->ssh_session, - &err_msg, NULL, 0); - infof(data, "Failed to free libssh2 scp subsystem: %d %s", - rc, err_msg); + (void)libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0); + infof(data, "Failed to free libssh2 scp subsystem: %d %s", rc, err_msg); } if(!block && (rc == LIBSSH2_ERROR_EAGAIN)) return CURLE_AGAIN; @@ -3644,8 +3584,7 @@ static CURLcode sshc_cleanup(struct ssh_conn *sshc, struct Curl_easy *data, rc = libssh2_sftp_shutdown(sshc->sftp_session); if((rc < 0) && data) { char *err_msg = NULL; - (void)libssh2_session_last_error(sshc->ssh_session, - &err_msg, NULL, 0); + (void)libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0); infof(data, "Failed to stop libssh2 sftp subsystem: %d %s", rc, err_msg); } if(!block && (rc == LIBSSH2_ERROR_EAGAIN)) @@ -3658,8 +3597,7 @@ static CURLcode sshc_cleanup(struct ssh_conn *sshc, struct Curl_easy *data, rc = libssh2_session_free(sshc->ssh_session); if((rc < 0) && data) { char *err_msg = NULL; - (void)libssh2_session_last_error(sshc->ssh_session, - &err_msg, NULL, 0); + (void)libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0); infof(data, "Failed to free libssh2 session: %d %s", rc, err_msg); } if(!block && (rc == LIBSSH2_ERROR_EAGAIN)) @@ -3685,7 +3623,6 @@ static CURLcode sshc_cleanup(struct ssh_conn *sshc, struct Curl_easy *data, return CURLE_OK; } - /* BLOCKING, but the function is using the state machine so the only reason this is still blocking is that the multi interface code has no support for disconnecting operations that takes a while */ @@ -3733,7 +3670,6 @@ static CURLcode ssh_done(struct Curl_easy *data, CURLcode status) return result; } - static CURLcode scp_done(struct Curl_easy *data, CURLcode status, bool premature) { @@ -3747,7 +3683,7 @@ static CURLcode scp_done(struct Curl_easy *data, CURLcode status, } static CURLcode scp_send(struct Curl_easy *data, int sockindex, - const void *mem, size_t len, bool eos, + const uint8_t *mem, size_t len, bool eos, size_t *pnwritten) { struct connectdata *conn = data->conn; @@ -3763,7 +3699,8 @@ static CURLcode scp_send(struct Curl_easy *data, int sockindex, return CURLE_FAILED_INIT; /* libssh2_channel_write() returns int! */ - nwritten = (ssize_t) libssh2_channel_write(sshc->ssh_channel, mem, len); + nwritten = (ssize_t)libssh2_channel_write(sshc->ssh_channel, + (const char *)mem, len); ssh_block2waitfor(data, sshc, (nwritten == LIBSSH2_ERROR_EAGAIN)); @@ -3792,7 +3729,7 @@ static CURLcode scp_recv(struct Curl_easy *data, int sockindex, return CURLE_FAILED_INIT; /* libssh2_channel_read() returns int */ - nread = (ssize_t) libssh2_channel_read(sshc->ssh_channel, mem, len); + nread = (ssize_t)libssh2_channel_read(sshc->ssh_channel, mem, len); ssh_block2waitfor(data, sshc, (nread == LIBSSH2_ERROR_EAGAIN)); if(nread == LIBSSH2_ERROR_EAGAIN) @@ -3818,15 +3755,14 @@ static CURLcode scp_recv(struct Curl_easy *data, int sockindex, * the options previously setup. */ -static -CURLcode sftp_perform(struct Curl_easy *data, - bool *connected, - bool *dophase_done) +static CURLcode sftp_perform(struct Curl_easy *data, + bool *connected, + bool *dophase_done) { struct ssh_conn *sshc = Curl_conn_meta_get(data->conn, CURL_META_SSH_CONN); CURLcode result = CURLE_OK; - DEBUGF(infof(data, "DO phase starts")); + CURL_TRC_SSH(data, "DO phase starts"); *dophase_done = FALSE; /* not done yet */ if(!sshc) @@ -3841,7 +3777,7 @@ CURLcode sftp_perform(struct Curl_easy *data, *connected = Curl_conn_is_connected(data->conn, FIRSTSOCKET); if(*dophase_done) { - DEBUGF(infof(data, "DO phase is complete")); + CURL_TRC_SSH(data, "DO phase is complete"); } return result; @@ -3854,7 +3790,7 @@ static CURLcode sftp_doing(struct Curl_easy *data, CURLcode result = ssh_multi_statemach(data, dophase_done); if(*dophase_done) { - DEBUGF(infof(data, "DO phase is complete")); + CURL_TRC_SSH(data, "DO phase is complete"); } return result; } @@ -3873,15 +3809,14 @@ static CURLcode sftp_disconnect(struct Curl_easy *data, if(sshc) { if(sshc->ssh_session) { /* only if there is a session still around to use! */ - DEBUGF(infof(data, "SSH DISCONNECT starts now")); + CURL_TRC_SSH(data, "DISCONNECT starts now"); myssh_state(data, sshc, SSH_SFTP_SHUTDOWN); result = ssh_block_statemach(data, sshc, sshp, TRUE); - DEBUGF(infof(data, "SSH DISCONNECT is done -> %d", result)); + CURL_TRC_SSH(data, "DISCONNECT is done -> %d", result); } sshc_cleanup(sshc, data, TRUE); } return result; - } static CURLcode sftp_done(struct Curl_easy *data, CURLcode status, @@ -3906,7 +3841,7 @@ static CURLcode sftp_done(struct Curl_easy *data, CURLcode status, /* return number of sent bytes */ static CURLcode sftp_send(struct Curl_easy *data, int sockindex, - const void *mem, size_t len, bool eos, + const uint8_t *mem, size_t len, bool eos, size_t *pnwritten) { struct connectdata *conn = data->conn; @@ -3920,7 +3855,7 @@ static CURLcode sftp_send(struct Curl_easy *data, int sockindex, if(!sshc) return CURLE_FAILED_INIT; - nwrite = libssh2_sftp_write(sshc->sftp_handle, mem, len); + nwrite = libssh2_sftp_write(sshc->sftp_handle, (const char *)mem, len); ssh_block2waitfor(data, sshc, (nwrite == LIBSSH2_ERROR_EAGAIN)); @@ -3965,65 +3900,65 @@ static CURLcode sftp_recv(struct Curl_easy *data, int sockindex, static const char *sftp_libssh2_strerror(unsigned long err) { switch(err) { - case LIBSSH2_FX_NO_SUCH_FILE: - return "No such file or directory"; + case LIBSSH2_FX_NO_SUCH_FILE: + return "No such file or directory"; - case LIBSSH2_FX_PERMISSION_DENIED: - return "Permission denied"; + case LIBSSH2_FX_PERMISSION_DENIED: + return "Permission denied"; - case LIBSSH2_FX_FAILURE: - return "Operation failed"; + case LIBSSH2_FX_FAILURE: + return "Operation failed"; - case LIBSSH2_FX_BAD_MESSAGE: - return "Bad message from SFTP server"; + case LIBSSH2_FX_BAD_MESSAGE: + return "Bad message from SFTP server"; - case LIBSSH2_FX_NO_CONNECTION: - return "Not connected to SFTP server"; + case LIBSSH2_FX_NO_CONNECTION: + return "Not connected to SFTP server"; - case LIBSSH2_FX_CONNECTION_LOST: - return "Connection to SFTP server lost"; + case LIBSSH2_FX_CONNECTION_LOST: + return "Connection to SFTP server lost"; - case LIBSSH2_FX_OP_UNSUPPORTED: - return "Operation not supported by SFTP server"; + case LIBSSH2_FX_OP_UNSUPPORTED: + return "Operation not supported by SFTP server"; - case LIBSSH2_FX_INVALID_HANDLE: - return "Invalid handle"; + case LIBSSH2_FX_INVALID_HANDLE: + return "Invalid handle"; - case LIBSSH2_FX_NO_SUCH_PATH: - return "No such file or directory"; + case LIBSSH2_FX_NO_SUCH_PATH: + return "No such file or directory"; - case LIBSSH2_FX_FILE_ALREADY_EXISTS: - return "File already exists"; + case LIBSSH2_FX_FILE_ALREADY_EXISTS: + return "File already exists"; - case LIBSSH2_FX_WRITE_PROTECT: - return "File is write protected"; + case LIBSSH2_FX_WRITE_PROTECT: + return "File is write protected"; - case LIBSSH2_FX_NO_MEDIA: - return "No media"; + case LIBSSH2_FX_NO_MEDIA: + return "No media"; - case LIBSSH2_FX_NO_SPACE_ON_FILESYSTEM: - return "Disk full"; + case LIBSSH2_FX_NO_SPACE_ON_FILESYSTEM: + return "Disk full"; - case LIBSSH2_FX_QUOTA_EXCEEDED: - return "User quota exceeded"; + case LIBSSH2_FX_QUOTA_EXCEEDED: + return "User quota exceeded"; - case LIBSSH2_FX_UNKNOWN_PRINCIPLE: - return "Unknown principle"; + case LIBSSH2_FX_UNKNOWN_PRINCIPLE: + return "Unknown principle"; - case LIBSSH2_FX_LOCK_CONFlICT: - return "File lock conflict"; + case LIBSSH2_FX_LOCK_CONFlICT: + return "File lock conflict"; - case LIBSSH2_FX_DIR_NOT_EMPTY: - return "Directory not empty"; + case LIBSSH2_FX_DIR_NOT_EMPTY: + return "Directory not empty"; - case LIBSSH2_FX_NOT_A_DIRECTORY: - return "Not a directory"; + case LIBSSH2_FX_NOT_A_DIRECTORY: + return "Not a directory"; - case LIBSSH2_FX_INVALID_FILENAME: - return "Invalid filename"; + case LIBSSH2_FX_INVALID_FILENAME: + return "Invalid filename"; - case LIBSSH2_FX_LINK_LOOP: - return "Link points to itself"; + case LIBSSH2_FX_LINK_LOOP: + return "Link points to itself"; } return "Unknown error in libssh2"; } diff --git a/vendor/hydra/vendor/curl/lib/vssh/ssh.h b/vendor/hydra/vendor/curl/lib/vssh/ssh.h index e09111e6..6fdf3f79 100644 --- a/vendor/hydra/vendor/curl/lib/vssh/ssh.h +++ b/vendor/hydra/vendor/curl/lib/vssh/ssh.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "../curl_setup.h" #ifdef USE_LIBSSH2 @@ -36,8 +35,6 @@ #include #endif -#include "curl_path.h" - /* meta key for storing protocol meta at easy handle */ #define CURL_META_SSH_EASY "meta:proto:ssh:easy" /* meta key for storing protocol meta at connection */ @@ -149,14 +146,15 @@ struct ssh_conn { char *quote_path1; /* two generic pointers for the QUOTE stuff */ char *quote_path2; - char *homedir; /* when doing SFTP we figure out home dir in the - connect phase */ + char *homedir; /* when doing SFTP we figure out home directory + in the connect phase */ /* end of READDIR stuff */ int secondCreateDirs; /* counter use by the code to see if the second attempt has been made to change to/create a directory */ - int orig_waitfor; /* default READ/WRITE bits wait for */ + int waitfor; /* KEEP_RECV/KEEP_SEND bits overriding + pollset given flags */ char *slash_pos; /* used by the SFTP_CREATE_DIRS state */ #ifdef USE_LIBSSH @@ -216,7 +214,7 @@ struct ssh_conn { #ifdef USE_LIBSSH #if LIBSSH_VERSION_INT < SSH_VERSION_INT(0, 9, 0) -# error "SCP/SFTP protocols require libssh 0.9.0 or later" +#error "SCP/SFTP protocols require libssh 0.9.0 or later" #endif #endif @@ -226,7 +224,7 @@ struct ssh_conn { non-configure platforms */ #if !defined(LIBSSH2_VERSION_NUM) || (LIBSSH2_VERSION_NUM < 0x010208) -# error "SCP/SFTP protocols require libssh2 1.2.8 or later" +#error "SCP/SFTP protocols require libssh2 1.2.8 or later" /* 1.2.8 was released on April 5 2011 */ #endif @@ -246,7 +244,7 @@ void Curl_ssh_attach(struct Curl_easy *data, #else /* for non-SSH builds */ #define Curl_ssh_cleanup() -#define Curl_ssh_attach(x,y) +#define Curl_ssh_attach(x, y) #define Curl_ssh_init() 0 #endif diff --git a/vendor/hydra/vendor/curl/lib/vssh/curl_path.c b/vendor/hydra/vendor/curl/lib/vssh/vssh.c similarity index 77% rename from vendor/hydra/vendor/curl/lib/vssh/curl_path.c rename to vendor/hydra/vendor/curl/lib/vssh/vssh.c index a6d57252..77fa89b5 100644 --- a/vendor/hydra/vendor/curl/lib/vssh/curl_path.c +++ b/vendor/hydra/vendor/curl/lib/vssh/vssh.c @@ -21,17 +21,14 @@ * SPDX-License-Identifier: curl AND ISC * ***************************************************************************/ - #include "../curl_setup.h" #ifdef USE_SSH -#include "curl_path.h" -#include +#include "vssh.h" #include "../curlx/strparse.h" -#include "../curl_memory.h" +#include "../curl_trc.h" #include "../escape.h" -#include "../memdebug.h" #define MAX_SSHPATH_LEN 100000 /* arbitrary */ @@ -58,7 +55,7 @@ CURLcode Curl_getworkingpath(struct Curl_easy *data, (working_path_len > 3) && (!memcmp(working_path, "/~/", 3))) { /* It is referenced to the home directory, so strip the leading '/~/' */ if(curlx_dyn_addn(&npath, &working_path[3], working_path_len - 3)) { - free(working_path); + curlx_free(working_path); return CURLE_OUT_OF_MEMORY; } } @@ -66,7 +63,7 @@ CURLcode Curl_getworkingpath(struct Curl_easy *data, (!strcmp("/~", working_path) || ((working_path_len > 2) && !memcmp(working_path, "/~/", 3)))) { if(curlx_dyn_add(&npath, homedir)) { - free(working_path); + curlx_free(working_path); return CURLE_OUT_OF_MEMORY; } if(working_path_len > 2) { @@ -76,25 +73,25 @@ CURLcode Curl_getworkingpath(struct Curl_easy *data, /* Copy a separating '/' if homedir does not end with one */ len = curlx_dyn_len(&npath); p = curlx_dyn_ptr(&npath); - if(len && (p[len-1] != '/')) + if(len && (p[len - 1] != '/')) copyfrom = 2; if(curlx_dyn_addn(&npath, &working_path[copyfrom], working_path_len - copyfrom)) { - free(working_path); + curlx_free(working_path); return CURLE_OUT_OF_MEMORY; } } else { if(curlx_dyn_add(&npath, "/")) { - free(working_path); + curlx_free(working_path); return CURLE_OUT_OF_MEMORY; } } } if(curlx_dyn_len(&npath)) { - free(working_path); + curlx_free(working_path); /* store the pointer for the caller to receive */ *path = curlx_dyn_ptr(&npath); @@ -148,7 +145,6 @@ CURLcode Curl_get_pathname(const char **cpp, char **path, const char *homedir) if(!curlx_dyn_len(&out)) goto fail; - } else { struct Curl_str word; @@ -196,4 +192,50 @@ CURLcode Curl_get_pathname(const char **cpp, char **path, const char *homedir) return CURLE_QUOTE_ERROR; } -#endif /* if SSH is used */ +CURLcode Curl_ssh_range(struct Curl_easy *data, + const char *p, curl_off_t filesize, + curl_off_t *startp, curl_off_t *sizep) +{ + curl_off_t from, to; + int to_t; + int from_t = curlx_str_number(&p, &from, CURL_OFF_T_MAX); + if(from_t == STRE_OVERFLOW) + return CURLE_RANGE_ERROR; + curlx_str_passblanks(&p); + (void)curlx_str_single(&p, '-'); + + to_t = curlx_str_numblanks(&p, &to); + if((to_t == STRE_OVERFLOW) || (to_t && from_t) || *p) + return CURLE_RANGE_ERROR; + + if(from_t) { + /* no start point given, set from relative to end of file */ + if(!to) + /* "-0" is not a fine range */ + return CURLE_RANGE_ERROR; + else if(to > filesize) + to = filesize; + from = filesize - to; + to = filesize - 1; + } + else if(from > filesize) { + failf(data, "Offset (%" FMT_OFF_T ") was beyond file size (%" + FMT_OFF_T ")", from, filesize); + return CURLE_RANGE_ERROR; + } + else if((to_t == STRE_NO_NUM) || (to >= filesize)) + to = filesize - 1; + + if(from > to) { + failf(data, "Bad range: start offset larger than end offset"); + return CURLE_RANGE_ERROR; + } + if((to - from) == CURL_OFF_T_MAX) + return CURLE_RANGE_ERROR; + + *startp = from; + *sizep = to - from + 1; + return CURLE_OK; +} + +#endif /* USE_SSH */ diff --git a/vendor/hydra/vendor/curl/lib/vssh/curl_path.h b/vendor/hydra/vendor/curl/lib/vssh/vssh.h similarity index 88% rename from vendor/hydra/vendor/curl/lib/vssh/curl_path.h rename to vendor/hydra/vendor/curl/lib/vssh/vssh.h index 1c167f96..4bc6d808 100644 --- a/vendor/hydra/vendor/curl/lib/vssh/curl_path.h +++ b/vendor/hydra/vendor/curl/lib/vssh/vssh.h @@ -23,9 +23,8 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "../curl_setup.h" -#include + #include "../urldata.h" CURLcode Curl_getworkingpath(struct Curl_easy *data, @@ -33,4 +32,9 @@ CURLcode Curl_getworkingpath(struct Curl_easy *data, char **path); CURLcode Curl_get_pathname(const char **cpp, char **path, const char *homedir); + +CURLcode Curl_ssh_range(struct Curl_easy *data, + const char *range, curl_off_t filesize, + curl_off_t *startp, curl_off_t *sizep); + #endif /* HEADER_CURL_PATH_H */ diff --git a/vendor/hydra/vendor/curl/lib/vtls/apple.c b/vendor/hydra/vendor/curl/lib/vtls/apple.c index 87d5208d..9779e11e 100644 --- a/vendor/hydra/vendor/curl/lib/vtls/apple.c +++ b/vendor/hydra/vendor/curl/lib/vtls/apple.c @@ -50,39 +50,35 @@ #include #endif -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - #ifdef USE_APPLE_SECTRUST #define SSL_SYSTEM_VERIFIER -#if (defined(MAC_OS_X_VERSION_MAX_ALLOWED) \ - && MAC_OS_X_VERSION_MAX_ALLOWED >= 101400) \ - || (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) \ - && __IPHONE_OS_VERSION_MAX_ALLOWED >= 120000) +#if (defined(MAC_OS_X_VERSION_MAX_ALLOWED) && \ + MAC_OS_X_VERSION_MAX_ALLOWED >= 101400) || \ + (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && \ + __IPHONE_OS_VERSION_MAX_ALLOWED >= 120000) #define SUPPORTS_SecTrustEvaluateWithError 1 #endif -#if defined(SUPPORTS_SecTrustEvaluateWithError) \ - && ((defined(MAC_OS_X_VERSION_MIN_REQUIRED) \ - && MAC_OS_X_VERSION_MIN_REQUIRED >= 101400) \ - || (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) \ - && __IPHONE_OS_VERSION_MIN_REQUIRED >= 120000)) +#if defined(SUPPORTS_SecTrustEvaluateWithError) && \ + ((defined(MAC_OS_X_VERSION_MIN_REQUIRED) && \ + MAC_OS_X_VERSION_MIN_REQUIRED >= 101400) || \ + (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && \ + __IPHONE_OS_VERSION_MIN_REQUIRED >= 120000)) #define REQUIRES_SecTrustEvaluateWithError 1 #endif -#if defined(SUPPORTS_SecTrustEvaluateWithError) \ - && !defined(HAVE_BUILTIN_AVAILABLE) \ - && !defined(REQUIRES_SecTrustEvaluateWithError) +#if defined(SUPPORTS_SecTrustEvaluateWithError) && \ + !defined(HAVE_BUILTIN_AVAILABLE) && \ + !defined(REQUIRES_SecTrustEvaluateWithError) #undef SUPPORTS_SecTrustEvaluateWithError #endif -#if (defined(MAC_OS_X_VERSION_MAX_ALLOWED) \ - && MAC_OS_X_VERSION_MAX_ALLOWED >= 100900) \ - || (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) \ - && __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000) +#if (defined(MAC_OS_X_VERSION_MAX_ALLOWED) && \ + MAC_OS_X_VERSION_MAX_ALLOWED >= 100900) || \ + (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && \ + __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000) #define SUPPORTS_SecOCSP 1 #endif @@ -148,7 +144,7 @@ CURLcode Curl_vtls_apple_verify(struct Curl_cfilter *cf, * add `kSecRevocationRequirePositiveResponse` to the Apple * Trust policies, it interprets this as it NEEDs a confirmation * of a cert being NOT REVOKED. Which not in general available for - * certificates on the internet. + * certificates on the Internet. * It seems that applications using this policy are expected to PIN * their certificate public keys or verification will fail. * This does not seem to be what we want here. */ @@ -211,8 +207,7 @@ CURLcode Curl_vtls_apple_verify(struct Curl_cfilter *cf, #if defined(HAVE_BUILTIN_AVAILABLE) && defined(SUPPORTS_SecOCSP) if(ocsp_len > 0) { if(__builtin_available(macOS 10.9, iOS 7, tvOS 9, watchOS 2, *)) { - CFDataRef ocspdata = - CFDataCreate(NULL, ocsp_buf, (CFIndex)ocsp_len); + CFDataRef ocspdata = CFDataCreate(NULL, ocsp_buf, (CFIndex)ocsp_len); status = SecTrustSetOCSPResponse(trust, ocspdata); CFRelease(ocspdata); @@ -230,7 +225,7 @@ CURLcode Curl_vtls_apple_verify(struct Curl_cfilter *cf, #endif #ifdef SUPPORTS_SecTrustEvaluateWithError -#if defined(HAVE_BUILTIN_AVAILABLE) +#ifdef HAVE_BUILTIN_AVAILABLE if(__builtin_available(macOS 10.14, iOS 12, tvOS 12, watchOS 5, *)) { #else if(1) { @@ -244,11 +239,11 @@ CURLcode Curl_vtls_apple_verify(struct Curl_cfilter *cf, if(error_ref) { CFIndex size = CFStringGetMaximumSizeForEncoding( CFStringGetLength(error_ref), kCFStringEncodingUTF8); - err_desc = malloc(size + 1); + err_desc = curlx_malloc(size + 1); if(err_desc) { if(!CFStringGetCString(error_ref, err_desc, size, - kCFStringEncodingUTF8)) { - free(err_desc); + kCFStringEncodingUTF8)) { + curlx_free(err_desc); err_desc = NULL; } } @@ -266,17 +261,22 @@ CURLcode Curl_vtls_apple_verify(struct Curl_cfilter *cf, if(status != noErr) { failf(data, "Apple SecTrust verification failed: error %i", (int)status); + result = CURLE_PEER_FAILED_VERIFICATION; } else if((sec_result == kSecTrustResultUnspecified) || (sec_result == kSecTrustResultProceed)) { /* "unspecified" means system-trusted with no explicit user setting */ result = CURLE_OK; } + else { + /* Any other trust result is a verification failure in this context */ + result = CURLE_PEER_FAILED_VERIFICATION; + } #endif /* REQUIRES_SecTrustEvaluateWithError */ } out: - free(err_desc); + curlx_free(err_desc); if(error_ref) CFRelease(error_ref); if(error) diff --git a/vendor/hydra/vendor/curl/lib/vtls/apple.h b/vendor/hydra/vendor/curl/lib/vtls/apple.h index 3d84f878..dd1b5db3 100644 --- a/vendor/hydra/vendor/curl/lib/vtls/apple.h +++ b/vendor/hydra/vendor/curl/lib/vtls/apple.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "../curl_setup.h" #ifdef USE_APPLE_SECTRUST diff --git a/vendor/hydra/vendor/curl/lib/vtls/cipher_suite.c b/vendor/hydra/vendor/curl/lib/vtls/cipher_suite.c index 23fb3a3c..562a3477 100644 --- a/vendor/hydra/vendor/curl/lib/vtls/cipher_suite.c +++ b/vendor/hydra/vendor/curl/lib/vtls/cipher_suite.c @@ -24,8 +24,8 @@ #include "../curl_setup.h" #if defined(USE_MBEDTLS) || defined(USE_RUSTLS) + #include "cipher_suite.h" -#include /* * To support the CURLOPT_SSL_CIPHER_LIST option on SSL backends @@ -131,24 +131,24 @@ enum { CS_TXT_LEN, }; -#define CS_ZIP_IDX(a, b, c, d, e, f, g, h) \ -{ \ - (uint8_t) ((((a) << 2) & 0xFF) | ((b) & 0x3F) >> 4), \ - (uint8_t) ((((b) << 4) & 0xFF) | ((c) & 0x3F) >> 2), \ - (uint8_t) ((((c) << 6) & 0xFF) | ((d) & 0x3F)), \ - (uint8_t) ((((e) << 2) & 0xFF) | ((f) & 0x3F) >> 4), \ - (uint8_t) ((((f) << 4) & 0xFF) | ((g) & 0x3F) >> 2), \ - (uint8_t) ((((g) << 6) & 0xFF) | ((h) & 0x3F)) \ +#define CS_ZIP_IDX(a, b, c, d, e, f, g, h) \ +{ \ + (uint8_t)((((a) << 2) & 0xFF) | ((b) & 0x3F) >> 4), \ + (uint8_t)((((b) << 4) & 0xFF) | ((c) & 0x3F) >> 2), \ + (uint8_t)((((c) << 6) & 0xFF) | ((d) & 0x3F)), \ + (uint8_t)((((e) << 2) & 0xFF) | ((f) & 0x3F) >> 4), \ + (uint8_t)((((f) << 4) & 0xFF) | ((g) & 0x3F) >> 2), \ + (uint8_t)((((g) << 6) & 0xFF) | ((h) & 0x3F)) \ } -#define CS_ENTRY(id, a, b, c, d, e, f, g, h) \ -{ \ - id, \ - CS_ZIP_IDX( \ - CS_TXT_IDX_ ## a, CS_TXT_IDX_ ## b, \ - CS_TXT_IDX_ ## c, CS_TXT_IDX_ ## d, \ - CS_TXT_IDX_ ## e, CS_TXT_IDX_ ## f, \ - CS_TXT_IDX_ ## g, CS_TXT_IDX_ ## h \ - ) \ +#define CS_ENTRY(id, a, b, c, d, e, f, g, h) \ +{ \ + id, \ + CS_ZIP_IDX( \ + CS_TXT_IDX_ ## a, CS_TXT_IDX_ ## b, \ + CS_TXT_IDX_ ## c, CS_TXT_IDX_ ## d, \ + CS_TXT_IDX_ ## e, CS_TXT_IDX_ ## f, \ + CS_TXT_IDX_ ## g, CS_TXT_IDX_ ## h \ + ) \ } struct cs_entry { @@ -157,7 +157,7 @@ struct cs_entry { }; /* !checksrc! disable COMMANOSPACE all */ -static const struct cs_entry cs_list [] = { +static const struct cs_entry cs_list[] = { /* TLS 1.3 ciphers */ #if defined(USE_MBEDTLS) || defined(USE_RUSTLS) CS_ENTRY(0x1301, TLS,AES,128,GCM,SHA256,,,), @@ -547,10 +547,9 @@ static const struct cs_entry cs_list [] = { }; #define CS_LIST_LEN CURL_ARRAYSIZE(cs_list) -static int cs_str_to_zip(const char *cs_str, size_t cs_len, - uint8_t zip[6]) +static int cs_str_to_zip(const char *cs_str, size_t cs_len, uint8_t zip[6]) { - uint8_t indexes[8] = {0}; + uint8_t indexes[8] = { 0 }; const char *entry, *cur; const char *nxt = cs_str; const char *end = cs_str + cs_len; @@ -568,7 +567,8 @@ static int cs_str_to_zip(const char *cs_str, size_t cs_len, /* determine the length of the part */ cur = nxt; - for(; nxt < end && *nxt != '\0' && *nxt != separator; nxt++); + for(; nxt < end && *nxt != '\0' && *nxt != separator; nxt++) + ; len = nxt - cur; /* lookup index for the part (skip empty string at 0) */ @@ -581,24 +581,23 @@ static int cs_str_to_zip(const char *cs_str, size_t cs_len, if(idx == CS_TXT_LEN) return -1; - indexes[i++] = (uint8_t) idx; + indexes[i++] = (uint8_t)idx; } while(nxt < end && *(nxt++) != '\0'); /* zip the 8 indexes into 48 bits */ - zip[0] = (uint8_t) (indexes[0] << 2 | (indexes[1] & 0x3F) >> 4); - zip[1] = (uint8_t) (indexes[1] << 4 | (indexes[2] & 0x3F) >> 2); - zip[2] = (uint8_t) (indexes[2] << 6 | (indexes[3] & 0x3F)); - zip[3] = (uint8_t) (indexes[4] << 2 | (indexes[5] & 0x3F) >> 4); - zip[4] = (uint8_t) (indexes[5] << 4 | (indexes[6] & 0x3F) >> 2); - zip[5] = (uint8_t) (indexes[6] << 6 | (indexes[7] & 0x3F)); + zip[0] = (uint8_t)(indexes[0] << 2 | (indexes[1] & 0x3F) >> 4); + zip[1] = (uint8_t)(indexes[1] << 4 | (indexes[2] & 0x3F) >> 2); + zip[2] = (uint8_t)(indexes[2] << 6 | (indexes[3] & 0x3F)); + zip[3] = (uint8_t)(indexes[4] << 2 | (indexes[5] & 0x3F) >> 4); + zip[4] = (uint8_t)(indexes[5] << 4 | (indexes[6] & 0x3F) >> 2); + zip[5] = (uint8_t)(indexes[6] << 6 | (indexes[7] & 0x3F)); return 0; } -static int cs_zip_to_str(const uint8_t zip[6], - char *buf, size_t buf_size) +static int cs_zip_to_str(const uint8_t zip[6], char *buf, size_t buf_size) { - uint8_t indexes[8] = {0}; + uint8_t indexes[8] = { 0 }; const char *entry; char separator = '-'; int idx, i, r; @@ -659,13 +658,12 @@ uint16_t Curl_cipher_suite_lookup_id(const char *cs_str, size_t cs_len) static bool cs_is_separator(char c) { switch(c) { - case ' ': - case '\t': - case ':': - case ',': - case ';': - return TRUE; - default:; + case ' ': + case '\t': + case ':': + case ',': + case ';': + return TRUE; } return FALSE; } @@ -673,10 +671,12 @@ static bool cs_is_separator(char c) uint16_t Curl_cipher_suite_walk_str(const char **str, const char **end) { /* move string pointer to first non-separator or end of string */ - for(; cs_is_separator(*str[0]); (*str)++); + for(; cs_is_separator(*str[0]); (*str)++) + ; /* move end pointer to next separator or end of string */ - for(*end = *str; *end[0] != '\0' && !cs_is_separator(*end[0]); (*end)++); + for(*end = *str; *end[0] != '\0' && !cs_is_separator(*end[0]); (*end)++) + ; return Curl_cipher_suite_lookup_id(*str, *end - *str); } diff --git a/vendor/hydra/vendor/curl/lib/vtls/cipher_suite.h b/vendor/hydra/vendor/curl/lib/vtls/cipher_suite.h index a1dcbc52..a17284f8 100644 --- a/vendor/hydra/vendor/curl/lib/vtls/cipher_suite.h +++ b/vendor/hydra/vendor/curl/lib/vtls/cipher_suite.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "../curl_setup.h" #if defined(USE_MBEDTLS) || defined(USE_RUSTLS) diff --git a/vendor/hydra/vendor/curl/lib/vtls/gtls.c b/vendor/hydra/vendor/curl/lib/vtls/gtls.c index 40d8ad5b..934273e0 100644 --- a/vendor/hydra/vendor/curl/lib/vtls/gtls.c +++ b/vendor/hydra/vendor/curl/lib/vtls/gtls.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - /* * Source file for all GnuTLS-specific code for the TLS/SSL layer. No code * but vtls.c should ever call or use these functions. @@ -29,7 +28,6 @@ * Note: do not use the GnuTLS' *_t variable type names in this source code, * since they were not present in 1.0.X. */ - #include "../curl_setup.h" #ifdef USE_GNUTLS @@ -41,8 +39,7 @@ #include #include "../urldata.h" -#include "../sendf.h" -#include "../curlx/inet_pton.h" +#include "../curl_trc.h" #include "keylog.h" #include "gtls.h" #include "vtls.h" @@ -53,15 +50,9 @@ #include "../parsedate.h" #include "../connect.h" /* for the connect timeout */ #include "../progress.h" -#include "../select.h" #include "../strdup.h" #include "../curlx/fopen.h" -#include "../curlx/warnless.h" #include "x509asn1.h" -#include "../multiif.h" -#include "../curl_memory.h" -/* The last #include file should be: */ -#include "../memdebug.h" /* Enable GnuTLS debugging by defining GTLSDEBUG */ /*#define GTLSDEBUG */ @@ -69,12 +60,11 @@ #ifdef GTLSDEBUG static void tls_log_func(int level, const char *str) { - curl_mfprintf(stderr, "|<%d>| %s", level, str); + curl_mfprintf(stderr, "|<%d>| %s", level, str); } #endif -static bool gtls_inited = FALSE; -#if !defined(GNUTLS_VERSION_NUMBER) || (GNUTLS_VERSION_NUMBER < 0x03010a) +#if !defined(GNUTLS_VERSION_NUMBER) || (GNUTLS_VERSION_NUMBER < 0x030605) #error "too old GnuTLS version" #endif @@ -135,8 +125,7 @@ static ssize_t gtls_pull(void *s, void *buf, size_t blen) } result = Curl_conn_cf_recv(cf->next, data, buf, blen, &nread); - CURL_TRC_CF(data, cf, "glts_pull(len=%zu) -> %d, %zd", - blen, result, nread); + CURL_TRC_CF(data, cf, "glts_pull(len=%zu) -> %d, %zd", blen, result, nread); backend->gtls.io_result = result; if(result) { /* !checksrc! disable ERRNOVAR 1 */ @@ -149,44 +138,41 @@ static ssize_t gtls_pull(void *s, void *buf, size_t blen) return (ssize_t)nread; } -/* gtls_init() +/** + * gtls_init() * * Global GnuTLS init, called from Curl_ssl_init(). This calls functions that - * are not thread-safe and thus this function itself is not thread-safe and - * must only be called from within curl_global_init() to keep the thread - * situation under control! + * are not thread-safe (It is thread-safe since GnuTLS 3.3.0) and thus this + * function itself is not thread-safe and must only be called from within + * curl_global_init() to keep the thread situation under control! + * + * @retval 0 error initializing SSL + * @retval 1 SSL initialized successfully */ static int gtls_init(void) { int ret = 1; - if(!gtls_inited) { - ret = gnutls_global_init() ? 0 : 1; + ret = gnutls_global_init() ? 0 : 1; #ifdef GTLSDEBUG - gnutls_global_set_log_function(tls_log_func); - gnutls_global_set_log_level(2); + gnutls_global_set_log_function(tls_log_func); + gnutls_global_set_log_level(2); #endif - gtls_inited = TRUE; - } return ret; } static void gtls_cleanup(void) { - if(gtls_inited) { - gnutls_global_deinit(); - gtls_inited = FALSE; - } + gnutls_global_deinit(); + Curl_tls_keylog_close(); } #ifndef CURL_DISABLE_VERBOSE_STRINGS -static void showtime(struct Curl_easy *data, - const char *text, - time_t stamp) +static void showtime(struct Curl_easy *data, const char *text, time_t stamp) { struct tm buffer; const struct tm *tm = &buffer; char str[96]; - CURLcode result = Curl_gmtime(stamp, &buffer); + CURLcode result = curlx_gmtime(stamp, &buffer); if(result) return; @@ -215,13 +201,13 @@ static gnutls_datum_t load_file(const char *file) f = curlx_fopen(file, "rb"); if(!f) return loaded_file; - if(fseek(f, 0, SEEK_END) != 0 - || (filelen = ftell(f)) < 0 - || fseek(f, 0, SEEK_SET) != 0 - || !(ptr = malloc((size_t)filelen))) + if(fseek(f, 0, SEEK_END) != 0 || + (filelen = ftell(f)) < 0 || + fseek(f, 0, SEEK_SET) != 0 || + !(ptr = curlx_malloc((size_t)filelen))) goto out; if(fread(ptr, 1, (size_t)filelen, f) < (size_t)filelen) { - free(ptr); + curlx_free(ptr); goto out; } @@ -234,10 +220,9 @@ static gnutls_datum_t load_file(const char *file) static void unload_file(gnutls_datum_t data) { - free(data.data); + curlx_free(data.data); } - /* this function does an SSL/TLS (re-)handshake */ static CURLcode cf_gtls_handshake(struct Curl_cfilter *cf, struct Curl_easy *data) @@ -315,16 +300,17 @@ static gnutls_x509_crt_fmt_t gnutls_do_file_type(const char *type) return GNUTLS_X509_FMT_PEM; /* default to PEM */ } -#define GNUTLS_CIPHERS "NORMAL:-ARCFOUR-128:-CTYPE-ALL:+CTYPE-X509" +#define GNUTLS_CIPHERS "NORMAL:%PROFILE_MEDIUM:-ARCFOUR-128:" \ + "-CTYPE-ALL:+CTYPE-X509" /* If GnuTLS was compiled without support for SRP it will error out if SRP is requested in the priority string, so treat it specially */ #define GNUTLS_SRP "+SRP" #define QUIC_PRIORITY \ - "NORMAL:-VERS-ALL:+VERS-TLS1.3:-CIPHER-ALL:+AES-128-GCM:+AES-256-GCM:" \ - "+CHACHA20-POLY1305:+AES-128-CCM:-GROUP-ALL:+GROUP-SECP256R1:" \ - "+GROUP-X25519:+GROUP-SECP384R1:+GROUP-SECP521R1:" \ + "NORMAL:%PROFILE_MEDIUM:-VERS-ALL:+VERS-TLS1.3:-CIPHER-ALL:+AES-128-GCM:" \ + "+AES-256-GCM:+CHACHA20-POLY1305:+AES-128-CCM:-GROUP-ALL:" \ + "+GROUP-SECP256R1:+GROUP-X25519:+GROUP-SECP384R1:+GROUP-SECP521R1:" \ "%DISABLE_TLS13_COMPAT_MODE" static CURLcode @@ -349,7 +335,7 @@ gnutls_set_ssl_version_min_max(struct Curl_easy *data, if(ssl_version_max < CURL_SSLVERSION_MAX_TLSv1_3) { failf(data, "QUIC needs at least TLS version 1.3"); return CURLE_SSL_CONNECT_ERROR; - } + } *prioritylist = QUIC_PRIORITY; return CURLE_OK; } @@ -396,7 +382,7 @@ gnutls_set_ssl_version_min_max(struct Curl_easy *data, return CURLE_OK; } - failf(data, "GnuTLS: cannot set ssl protocol"); + failf(data, "GnuTLS: cannot set TLS protocol"); return CURLE_SSL_CONNECT_ERROR; } @@ -407,19 +393,19 @@ CURLcode Curl_gtls_shared_creds_create(struct Curl_easy *data, int rc; *pcreds = NULL; - shared = calloc(1, sizeof(*shared)); + shared = curlx_calloc(1, sizeof(*shared)); if(!shared) return CURLE_OUT_OF_MEMORY; rc = gnutls_certificate_allocate_credentials(&shared->creds); if(rc != GNUTLS_E_SUCCESS) { failf(data, "gnutls_cert_all_cred() failed: %s", gnutls_strerror(rc)); - free(shared); + curlx_free(shared); return CURLE_SSL_CONNECT_ERROR; } shared->refcount = 1; - shared->time = curlx_now(); + shared->time = *Curl_pgrs_now(data); *pcreds = shared; return CURLE_OK; } @@ -442,8 +428,8 @@ void Curl_gtls_shared_creds_free(struct gtls_shared_creds **pcreds) --shared->refcount; if(!shared->refcount) { gnutls_certificate_free_credentials(shared->creds); - free(shared->CAfile); - free(shared); + curlx_free(shared->CAfile); + curlx_free(shared); } } } @@ -470,7 +456,7 @@ static CURLcode gtls_populate_creds(struct Curl_cfilter *cf, #else rc = gnutls_certificate_set_x509_system_trust(creds); if(rc < 0) - infof(data, "error reading native ca store (%s), continuing anyway", + infof(data, "error reading native CA store (%s), continuing anyway", gnutls_strerror(rc)); else { infof(data, " Native: %d certificates from system trust", rc); @@ -480,7 +466,31 @@ static CURLcode gtls_populate_creds(struct Curl_cfilter *cf, #endif } - if(config->CAfile) { + if(config->ca_info_blob) { + gnutls_datum_t ca_info_datum; + if(config->ca_info_blob->len > (size_t)UINT_MAX) { + failf(data, "certificate blob too long: %zu bytes", + config->ca_info_blob->len); + return CURLE_SSL_CACERT_BADFILE; + } + ca_info_datum.data = config->ca_info_blob->data; + ca_info_datum.size = (unsigned int)config->ca_info_blob->len; + rc = gnutls_certificate_set_x509_trust_mem(creds, &ca_info_datum, + GNUTLS_X509_FMT_PEM); + creds_are_empty = creds_are_empty && (rc <= 0); + if(rc < 0) { + infof(data, "error reading CA cert blob (%s)%s", gnutls_strerror(rc), + (creds_are_empty ? "" : ", continuing anyway")); + if(creds_are_empty) { + ssl_config->certverifyresult = rc; + return CURLE_SSL_CACERT_BADFILE; + } + } + else + infof(data, " CA Blob: %d certificates", rc); + } + /* CURLOPT_CAINFO_BLOB overrides CURLOPT_CAINFO */ + else if(config->CAfile) { /* set the trusted CA cert bundle file */ gnutls_certificate_set_verify_flags(creds, GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT); @@ -490,7 +500,7 @@ static CURLcode gtls_populate_creds(struct Curl_cfilter *cf, GNUTLS_X509_FMT_PEM); creds_are_empty = creds_are_empty && (rc <= 0); if(rc < 0) { - infof(data, "error reading ca cert file %s (%s)%s", + infof(data, "error reading CA cert file %s (%s)%s", config->CAfile, gnutls_strerror(rc), (creds_are_empty ? "" : ", continuing anyway")); if(creds_are_empty) { @@ -508,7 +518,7 @@ static CURLcode gtls_populate_creds(struct Curl_cfilter *cf, GNUTLS_X509_FMT_PEM); creds_are_empty = creds_are_empty && (rc <= 0); if(rc < 0) { - infof(data, "error reading ca cert file %s (%s)%s", + infof(data, "error reading CA cert file %s (%s)%s", config->CApath, gnutls_strerror(rc), (creds_are_empty ? "" : ", continuing anyway")); if(creds_are_empty) { @@ -528,7 +538,7 @@ static CURLcode gtls_populate_creds(struct Curl_cfilter *cf, rc = gnutls_certificate_set_x509_crl_file(creds, config->CRLfile, GNUTLS_X509_FMT_PEM); if(rc < 0) { - failf(data, "error reading crl file %s (%s)", + failf(data, "error reading CRL file %s (%s)", config->CRLfile, gnutls_strerror(rc)); return CURLE_SSL_CRL_BADFILE; } @@ -542,12 +552,11 @@ static CURLcode gtls_populate_creds(struct Curl_cfilter *cf, /* key to use at `multi->proto_hash` */ #define MPROTO_GTLS_X509_KEY "tls:gtls:x509:share" -static bool gtls_shared_creds_expired(const struct Curl_easy *data, +static bool gtls_shared_creds_expired(struct Curl_easy *data, const struct gtls_shared_creds *sc) { const struct ssl_general_config *cfg = &data->set.general_ssl; - struct curltime now = curlx_now(); - timediff_t elapsed_ms = curlx_timediff(now, sc->time); + timediff_t elapsed_ms = curlx_ptimediff_ms(Curl_pgrs_now(data), &sc->time); timediff_t timeout_ms = cfg->ca_cache_timeout * (timediff_t)1000; if(timeout_ms < 0) @@ -566,20 +575,20 @@ static bool gtls_shared_creds_different(struct Curl_cfilter *cf, return strcmp(sc->CAfile, conn_config->CAfile); } -static struct gtls_shared_creds* -gtls_get_cached_creds(struct Curl_cfilter *cf, struct Curl_easy *data) +static struct gtls_shared_creds *gtls_get_cached_creds(struct Curl_cfilter *cf, + struct Curl_easy *data) { struct gtls_shared_creds *shared_creds; if(data->multi) { shared_creds = Curl_hash_pick(&data->multi->proto_hash, CURL_UNCONST(MPROTO_GTLS_X509_KEY), - sizeof(MPROTO_GTLS_X509_KEY)-1); - if(shared_creds && shared_creds->creds && - !gtls_shared_creds_expired(data, shared_creds) && - !gtls_shared_creds_different(cf, shared_creds)) { - return shared_creds; - } + sizeof(MPROTO_GTLS_X509_KEY) - 1); + if(shared_creds && shared_creds->creds && + !gtls_shared_creds_expired(data, shared_creds) && + !gtls_shared_creds_different(cf, shared_creds)) { + return shared_creds; + } } return NULL; } @@ -587,7 +596,7 @@ gtls_get_cached_creds(struct Curl_cfilter *cf, struct Curl_easy *data) static void gtls_shared_creds_hash_free(void *key, size_t key_len, void *p) { struct gtls_shared_creds *sc = p; - DEBUGASSERT(key_len == (sizeof(MPROTO_GTLS_X509_KEY)-1)); + DEBUGASSERT(key_len == (sizeof(MPROTO_GTLS_X509_KEY) - 1)); DEBUGASSERT(!memcmp(MPROTO_GTLS_X509_KEY, key, key_len)); (void)key; (void)key_len; @@ -608,7 +617,7 @@ static void gtls_set_cached_creds(struct Curl_cfilter *cf, return; if(conn_config->CAfile) { - sc->CAfile = strdup(conn_config->CAfile); + sc->CAfile = curlx_strdup(conn_config->CAfile); if(!sc->CAfile) return; } @@ -617,9 +626,9 @@ static void gtls_set_cached_creds(struct Curl_cfilter *cf, return; if(!Curl_hash_add2(&data->multi->proto_hash, - CURL_UNCONST(MPROTO_GTLS_X509_KEY), - sizeof(MPROTO_GTLS_X509_KEY)-1, - sc, gtls_shared_creds_hash_free)) { + CURL_UNCONST(MPROTO_GTLS_X509_KEY), + sizeof(MPROTO_GTLS_X509_KEY) - 1, + sc, gtls_shared_creds_hash_free)) { Curl_gtls_shared_creds_free(&sc); /* down reference again */ return; } @@ -636,7 +645,6 @@ CURLcode Curl_gtls_client_trust_setup(struct Curl_cfilter *cf, CURLcode result; int rc; - /* Consider the X509 store cacheable if it comes exclusively from a CAfile, or no source is provided and we are falling back to OpenSSL's built-in default. */ @@ -695,7 +703,7 @@ CURLcode Curl_gtls_cache_session(struct Curl_cfilter *cf, /* we always unconditionally get the session id here, as even if we already got it from the cache and asked to use it in the connection, it - might've been rejected and then a new one is in use now and we need to + might have been rejected and then a new one is in use now and we need to detect that. */ /* get the session ID data size */ @@ -703,7 +711,7 @@ CURLcode Curl_gtls_cache_session(struct Curl_cfilter *cf, if(!sdata_len) /* gnutls does this for some version combinations */ return CURLE_OK; - sdata = malloc(sdata_len); /* get a buffer for it */ + sdata = curlx_malloc(sdata_len); /* get a buffer for it */ if(!sdata) return CURLE_OUT_OF_MEMORY; @@ -717,7 +725,7 @@ CURLcode Curl_gtls_cache_session(struct Curl_cfilter *cf, if(quic_tp && quic_tp_len) { qtp_clone = Curl_memdup0((char *)quic_tp, quic_tp_len); if(!qtp_clone) { - free(sdata); + curlx_free(sdata); return CURLE_OUT_OF_MEMORY; } } @@ -747,10 +755,8 @@ int Curl_glts_get_ietf_proto(gnutls_session_t session) return CURL_IETF_PROTO_TLS1_1; case GNUTLS_TLS1_2: return CURL_IETF_PROTO_TLS1_2; -#if GNUTLS_VERSION_NUMBER >= 0x030603 case GNUTLS_TLS1_3: return CURL_IETF_PROTO_TLS1_3; -#endif default: return CURL_IETF_PROTO_UNKNOWN; } @@ -824,7 +830,7 @@ static CURLcode gtls_set_priority(struct Curl_cfilter *cf, if((conn_config->cipher_list[0] == '+') || (conn_config->cipher_list[0] == '-') || (conn_config->cipher_list[0] == '!')) { - /* add it to out own */ + /* add it to out own */ if(!curlx_dyn_len(&buf)) { /* not added yet */ result = curlx_dyn_add(&buf, priority); if(result) @@ -861,20 +867,15 @@ static CURLcode gtls_client_init(struct Curl_cfilter *cf, struct ssl_config_data *ssl_config = Curl_ssl_cf_get_config(cf, data); unsigned int init_flags; int rc; - bool sni = TRUE; /* default is SNI enabled */ const char *prioritylist; bool tls13support; CURLcode result; - if(!gtls_inited) - gtls_init(); - - if(config->version == CURL_SSLVERSION_SSLv2) { - failf(data, "GnuTLS does not support SSLv2"); + if(config->version == CURL_SSLVERSION_SSLv2 || + config->version == CURL_SSLVERSION_SSLv3) { + failf(data, "GnuTLS does not support SSLv2 or SSLv3"); return CURLE_SSL_CONNECT_ERROR; } - else if(config->version == CURL_SSLVERSION_SSLv3) - sni = FALSE; /* SSLv3 has no SNI */ /* allocate a shared creds struct */ result = Curl_gtls_shared_creds_create(data, >ls->shared_creds); @@ -886,7 +887,12 @@ static CURLcode gtls_client_init(struct Curl_cfilter *cf, infof(data, "Using TLS-SRP username: %s", config->username); rc = gnutls_srp_allocate_client_credentials(>ls->srp_client_cred); - if(rc != GNUTLS_E_SUCCESS) { + if(rc == GNUTLS_E_UNIMPLEMENTED_FEATURE) { + failf(data, "GnuTLS: TLS-SRP support not built in: %s", + gnutls_strerror(rc)); + return CURLE_NOT_BUILT_IN; + } + else if(rc != GNUTLS_E_SUCCESS) { failf(data, "gnutls_srp_allocate_client_cred() failed: %s", gnutls_strerror(rc)); return CURLE_OUT_OF_MEMORY; @@ -941,7 +947,7 @@ static CURLcode gtls_client_init(struct Curl_cfilter *cf, return CURLE_SSL_CONNECT_ERROR; } - if(sni && peer->sni) { + if(peer->sni) { if(gnutls_server_name_set(gtls->session, GNUTLS_NAME_DNS, peer->sni, strlen(peer->sni)) < 0) { failf(data, "Failed to set SNI"); @@ -957,16 +963,6 @@ static CURLcode gtls_client_init(struct Curl_cfilter *cf, /* "In GnuTLS 3.6.5, TLS 1.3 is enabled by default" */ tls13support = !!gnutls_check_version("3.6.5"); - /* Ensure +SRP comes at the *end* of all relevant strings so that it can be - * removed if a runtime error indicates that SRP is not supported by this - * GnuTLS version */ - - if(config->version == CURL_SSLVERSION_SSLv2 || - config->version == CURL_SSLVERSION_SSLv3) { - failf(data, "GnuTLS does not support SSLv2 or SSLv3"); - return CURLE_SSL_CONNECT_ERROR; - } - if(config->version == CURL_SSLVERSION_TLSv1_3) { if(!tls13support) { failf(data, "This GnuTLS installation does not support TLS 1.3"); @@ -1101,8 +1097,8 @@ static CURLcode gtls_on_session_reuse(struct Curl_cfilter *cf, connssl->earlydata_state = ssl_earlydata_await; connssl->state = ssl_connection_deferred; result = Curl_alpn_set_negotiated(cf, data, connssl, - (const unsigned char *)scs->alpn, - scs->alpn ? strlen(scs->alpn) : 0); + (const unsigned char *)scs->alpn, + scs->alpn ? strlen(scs->alpn) : 0); *do_early_data = !result; } return result; @@ -1135,7 +1131,7 @@ CURLcode Curl_gtls_ctx_init(struct gtls_ctx *gctx, /* This might be a reconnect, so we check for a session ID in the cache to speed up things. We need to do this before constructing the gnutls session since we need to set flags depending on the kind of reuse. */ - if(conn_config->cache_session) { + if(conn_config->cache_session && !conn_config->verifystatus) { result = Curl_ssl_scache_take(cf, data, peer->scache_key, &scs); if(result) goto out; @@ -1160,7 +1156,7 @@ CURLcode Curl_gtls_ctx_init(struct gtls_ctx *gctx, if(sess_reuse_cb) { result = sess_reuse_cb(cf, data, &alpns, scs, &do_early_data); if(result) - goto out; + goto out; } if(do_early_data) { /* We only try the ALPN protocol the session used before, @@ -1220,8 +1216,8 @@ CURLcode Curl_gtls_ctx_init(struct gtls_ctx *gctx, return result; } -static CURLcode -gtls_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) +static CURLcode gtls_connect_step1(struct Curl_cfilter *cf, + struct Curl_easy *data) { struct ssl_connect_data *connssl = cf->ctx; struct gtls_ssl_backend_data *backend = @@ -1304,7 +1300,7 @@ static CURLcode pkp_pin_peer_pubkey(struct Curl_easy *data, if(ret != GNUTLS_E_SHORT_MEMORY_BUFFER || len1 == 0) break; /* failed */ - buff1 = malloc(len1); + buff1 = curlx_malloc(len1); if(!buff1) break; /* failed */ @@ -1328,8 +1324,7 @@ static CURLcode pkp_pin_peer_pubkey(struct Curl_easy *data, return result; } -void Curl_gtls_report_handshake(struct Curl_easy *data, - struct gtls_ctx *gctx) +void Curl_gtls_report_handshake(struct Curl_easy *data, struct gtls_ctx *gctx) { #ifndef CURL_DISABLE_VERBOSE_STRINGS if(Curl_trc_is_verbose(data)) { @@ -1453,7 +1448,12 @@ static CURLcode gtls_verify_ocsp_status(struct Curl_easy *data, goto out; } - gnutls_ocsp_resp_init(&ocsp_resp); + rc = gnutls_ocsp_resp_init(&ocsp_resp); + if(rc < 0) { + failf(data, "Failed to initialize OCSP response object"); + result = CURLE_SSL_INVALIDCERTSTATUS; + goto out; + } rc = gnutls_ocsp_resp_import(ocsp_resp, &status_request); if(rc < 0) { @@ -1570,8 +1570,7 @@ static CURLcode glts_apple_verify(struct Curl_cfilter *cf, CURLcode result; result = Curl_vtls_apple_verify(cf, data, peer, chain->num_certs, - gtls_chain_get_der, chain, - NULL, 0); + gtls_chain_get_der, chain, NULL, 0); *pverified = !result; if(*pverified) infof(data, " SSL certificate verified by Apple SecTrust."); @@ -1579,14 +1578,13 @@ static CURLcode glts_apple_verify(struct Curl_cfilter *cf, } #endif /* USE_APPLE_SECTRUST */ -CURLcode -Curl_gtls_verifyserver(struct Curl_cfilter *cf, - struct Curl_easy *data, - gnutls_session_t session, - struct ssl_primary_config *config, - struct ssl_config_data *ssl_config, - struct ssl_peer *peer, - const char *pinned_key) +CURLcode Curl_gtls_verifyserver(struct Curl_cfilter *cf, + struct Curl_easy *data, + gnutls_session_t session, + struct ssl_primary_config *config, + struct ssl_config_data *ssl_config, + struct ssl_peer *peer, + const char *pinned_key) { struct gtls_cert_chain chain; gnutls_x509_crt_t x509_cert = NULL, x509_issuer = NULL; @@ -1627,19 +1625,27 @@ Curl_gtls_verifyserver(struct Curl_cfilter *cf, } if(data->set.ssl.certinfo && chain.certs) { - unsigned int i; - - result = Curl_ssl_init_certinfo(data, (int)chain.num_certs); - if(result) + if(chain.num_certs > MAX_ALLOWED_CERT_AMOUNT) { + failf(data, "%u certificates is more than allowed (%u)", + chain.num_certs, MAX_ALLOWED_CERT_AMOUNT); + result = CURLE_SSL_CONNECT_ERROR; goto out; + } + else { + unsigned int i; - for(i = 0; i < chain.num_certs; i++) { - const char *beg = (const char *) chain.certs[i].data; - const char *end = beg + chain.certs[i].size; - - result = Curl_extract_certinfo(data, (int)i, beg, end); + result = Curl_ssl_init_certinfo(data, (int)chain.num_certs); if(result) goto out; + + for(i = 0; i < chain.num_certs; i++) { + const char *beg = (const char *)chain.certs[i].data; + const char *end = beg + chain.certs[i].size; + + result = Curl_extract_certinfo(data, (int)i, beg, end); + if(result) + goto out; + } } } @@ -1666,8 +1672,7 @@ Curl_gtls_verifyserver(struct Curl_cfilter *cf, infof(data, " SSL certificate verified by GnuTLS"); #ifdef USE_APPLE_SECTRUST - if(!verified && ssl_config->native_ca_store && - (verify_status & GNUTLS_CERT_SIGNER_NOT_FOUND)) { + if(!verified && ssl_config->native_ca_store) { result = glts_apple_verify(cf, data, peer, &chain, &verified); if(result && (result != CURLE_PEER_FAILED_VERIFICATION)) goto out; /* unexpected error */ @@ -1818,51 +1823,8 @@ Curl_gtls_verifyserver(struct Curl_cfilter *cf, rc = (int)gnutls_x509_crt_check_hostname(x509_cert, peer->sni ? peer->sni : peer->hostname); -#if GNUTLS_VERSION_NUMBER < 0x030306 - /* Before 3.3.6, gnutls_x509_crt_check_hostname() did not check IP - addresses. */ - if(!rc) { -#ifdef USE_IPV6 - #define use_addr in6_addr -#else - #define use_addr in_addr -#endif - unsigned char addrbuf[sizeof(struct use_addr)]; - size_t addrlen = 0; - - if(curlx_inet_pton(AF_INET, peer->hostname, addrbuf) > 0) - addrlen = 4; -#ifdef USE_IPV6 - else if(curlx_inet_pton(AF_INET6, peer->hostname, addrbuf) > 0) - addrlen = 16; -#endif - - if(addrlen) { - unsigned char certaddr[sizeof(struct use_addr)]; - int i; - - for(i = 0; ; i++) { - size_t certaddrlen = sizeof(certaddr); - int ret = gnutls_x509_crt_get_subject_alt_name(x509_cert, i, certaddr, - &certaddrlen, NULL); - /* If this happens, it was not an IP address. */ - if(ret == GNUTLS_E_SHORT_MEMORY_BUFFER) - continue; - if(ret < 0) - break; - if(ret != GNUTLS_SAN_IPADDRESS) - continue; - if(certaddrlen == addrlen && !memcmp(addrbuf, certaddr, addrlen)) { - rc = 1; - break; - } - } - } - } -#endif - result = (!rc && config->verifyhost) ? - CURLE_PEER_FAILED_VERIFICATION : CURLE_OK; + CURLE_PEER_FAILED_VERIFICATION : CURLE_OK; gtls_msg_verify_result(data, peer, x509_cert, rc, config->verifyhost); if(result) goto out; @@ -1923,7 +1885,7 @@ static CURLcode gtls_send_earlydata(struct Curl_cfilter *cf, { struct ssl_connect_data *connssl = cf->ctx; struct gtls_ssl_backend_data *backend = - (struct gtls_ssl_backend_data *)connssl->backend; + (struct gtls_ssl_backend_data *)connssl->backend; CURLcode result = CURLE_OK; const unsigned char *buf; size_t blen; @@ -1933,8 +1895,7 @@ static CURLcode gtls_send_earlydata(struct Curl_cfilter *cf, backend->gtls.io_result = CURLE_OK; while(Curl_bufq_peek(&connssl->earlydata, &buf, &blen)) { n = gnutls_record_send_early_data(backend->gtls.session, buf, blen); - CURL_TRC_CF(data, cf, "gtls_send_earlydata(len=%zu) -> %zd", - blen, n); + CURL_TRC_CF(data, cf, "gtls_send_earlydata(len=%zu) -> %zd", blen, n); if(n < 0) { if(n == GNUTLS_E_AGAIN) result = CURLE_AGAIN; @@ -1969,10 +1930,11 @@ static CURLcode gtls_send_earlydata(struct Curl_cfilter *cf, */ static CURLcode gtls_connect_common(struct Curl_cfilter *cf, struct Curl_easy *data, - bool *done) { + bool *done) +{ struct ssl_connect_data *connssl = cf->ctx; struct gtls_ssl_backend_data *backend = - (struct gtls_ssl_backend_data *)connssl->backend; + (struct gtls_ssl_backend_data *)connssl->backend; CURLcode result = CURLE_OK; DEBUGASSERT(backend); @@ -2156,7 +2118,7 @@ static CURLcode gtls_shutdown(struct Curl_cfilter *cf, size_t i; DEBUGASSERT(backend); - /* If we have no handshaked connection or already shut down */ + /* If we have no handshaked connection or already shut down */ if(!backend->gtls.session || cf->shutdown || connssl->state != ssl_connection_complete) { *done = TRUE; @@ -2335,6 +2297,7 @@ const struct Curl_ssl Curl_ssl_gnutls = { SSLSUPP_CERTINFO | SSLSUPP_PINNEDPUBKEY | SSLSUPP_HTTPS_PROXY | + SSLSUPP_CAINFO_BLOB | SSLSUPP_CIPHER_LIST | SSLSUPP_CA_CACHE, diff --git a/vendor/hydra/vendor/curl/lib/vtls/gtls.h b/vendor/hydra/vendor/curl/lib/vtls/gtls.h index afbe51eb..ecdca0a6 100644 --- a/vendor/hydra/vendor/curl/lib/vtls/gtls.h +++ b/vendor/hydra/vendor/curl/lib/vtls/gtls.h @@ -23,9 +23,7 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "../curl_setup.h" -#include #ifdef USE_GNUTLS @@ -119,8 +117,7 @@ CURLcode Curl_gtls_cache_session(struct Curl_cfilter *cf, size_t quic_tp_len); /* Report properties of a successful handshake */ -void Curl_gtls_report_handshake(struct Curl_easy *data, - struct gtls_ctx *gctx); +void Curl_gtls_report_handshake(struct Curl_easy *data, struct gtls_ctx *gctx); extern const struct Curl_ssl Curl_ssl_gnutls; diff --git a/vendor/hydra/vendor/curl/lib/vtls/hostcheck.c b/vendor/hydra/vendor/curl/lib/vtls/hostcheck.c index 23ba3395..97063367 100644 --- a/vendor/hydra/vendor/curl/lib/vtls/hostcheck.c +++ b/vendor/hydra/vendor/curl/lib/vtls/hostcheck.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "../curl_setup.h" #if defined(USE_OPENSSL) || defined(USE_SCHANNEL) @@ -37,10 +36,6 @@ #include "hostcheck.h" #include "../hostip.h" -#include "../curl_memory.h" -/* The last #include file should be: */ -#include "../memdebug.h" - /* check the two input strings with given length, but do not assume they end in nul-bytes */ static bool pmatch(const char *hostname, size_t hostlen, @@ -88,16 +83,16 @@ static bool hostmatch(const char *hostname, DEBUGASSERT(hostlen); /* normalize pattern and hostname by stripping off trailing dots */ - if(hostname[hostlen-1]=='.') + if(hostname[hostlen - 1] == '.') hostlen--; - if(pattern[patternlen-1]=='.') + if(pattern[patternlen - 1] == '.') patternlen--; if(strncmp(pattern, "*.", 2)) return pmatch(hostname, hostlen, pattern, patternlen); - /* detect IP address as hostname and fail the match if so */ - else if(Curl_host_is_ipnum(hostname)) + /* detect host as IP address or starting with a dot and fail if so */ + else if(Curl_host_is_ipnum(hostname) || (hostname[0] == '.')) return FALSE; /* We require at least 2 dots in the pattern to avoid too wide wildcard @@ -129,4 +124,4 @@ bool Curl_cert_hostcheck(const char *match, size_t matchlen, return FALSE; } -#endif /* OPENSSL or SCHANNEL */ +#endif /* USE_OPENSSL || USE_SCHANNEL */ diff --git a/vendor/hydra/vendor/curl/lib/vtls/hostcheck.h b/vendor/hydra/vendor/curl/lib/vtls/hostcheck.h index b843d09c..d62c7213 100644 --- a/vendor/hydra/vendor/curl/lib/vtls/hostcheck.h +++ b/vendor/hydra/vendor/curl/lib/vtls/hostcheck.h @@ -23,8 +23,7 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - -#include +#include "../curl_setup.h" #if defined(USE_OPENSSL) || defined(USE_SCHANNEL) diff --git a/vendor/hydra/vendor/curl/lib/vtls/keylog.c b/vendor/hydra/vendor/curl/lib/vtls/keylog.c index 9179d38f..ace9cab1 100644 --- a/vendor/hydra/vendor/curl/lib/vtls/keylog.c +++ b/vendor/hydra/vendor/curl/lib/vtls/keylog.c @@ -31,19 +31,13 @@ defined(USE_RUSTLS) #include "keylog.h" -#include #include "../escape.h" #include "../curlx/fopen.h" -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* The fp for the open SSLKEYLOGFILE, or NULL if not open */ static FILE *keylog_file_fp; -void -Curl_tls_keylog_open(void) +void Curl_tls_keylog_open(void) { char *keylog_file_name; @@ -67,8 +61,7 @@ Curl_tls_keylog_open(void) } } -void -Curl_tls_keylog_close(void) +void Curl_tls_keylog_close(void) { if(keylog_file_fp) { curlx_fclose(keylog_file_fp); @@ -76,14 +69,12 @@ Curl_tls_keylog_close(void) } } -bool -Curl_tls_keylog_enabled(void) +bool Curl_tls_keylog_enabled(void) { return keylog_file_fp != NULL; } -bool -Curl_tls_keylog_write_line(const char *line) +bool Curl_tls_keylog_write_line(const char *line) { /* The current maximum valid keylog line length LF and NUL is 195. */ size_t linelen; @@ -111,10 +102,9 @@ Curl_tls_keylog_write_line(const char *line) return TRUE; } -bool -Curl_tls_keylog_write(const char *label, - const unsigned char client_random[CLIENT_RANDOM_SIZE], - const unsigned char *secret, size_t secretlen) +bool Curl_tls_keylog_write(const char *label, + const unsigned char client_random[CLIENT_RANDOM_SIZE], + const unsigned char *secret, size_t secretlen) { size_t pos, i; unsigned char line[KEYLOG_LABEL_MAXLEN + 1 + 2 * CLIENT_RANDOM_SIZE + 1 + @@ -154,4 +144,4 @@ Curl_tls_keylog_write(const char *label, return TRUE; } -#endif /* TLS or QUIC backend */ +#endif /* TLS or QUIC backend */ diff --git a/vendor/hydra/vendor/curl/lib/vtls/mbedtls.c b/vendor/hydra/vendor/curl/lib/vtls/mbedtls.c index ea8981b3..dff45a32 100644 --- a/vendor/hydra/vendor/curl/lib/vtls/mbedtls.c +++ b/vendor/hydra/vendor/curl/lib/vtls/mbedtls.c @@ -22,13 +22,11 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - /* * Source file for all mbedTLS-specific code for the TLS/SSL layer. No code * but vtls.c should ever call or use these functions. * */ - #include "../curl_setup.h" #ifdef USE_MBEDTLS @@ -38,7 +36,7 @@ #include #if MBEDTLS_VERSION_NUMBER < 0x03020000 - #error "mbedTLS 3.2.0 or later required" +#error "mbedTLS 3.2.0 or later required" #endif #include #include @@ -46,12 +44,12 @@ #include #include -#if MBEDTLS_VERSION_NUMBER < 0x04000000 -#define CURL_MBEDTLS_DRBG +#if MBEDTLS_VERSION_NUMBER < 0x04000000 && !defined(MBEDTLS_CTR_DRBG_C) +#error "MBEDTLS_CTR_DRBG_C is required for mbedTLS 3.x." #endif #include -#ifdef CURL_MBEDTLS_DRBG +#if MBEDTLS_VERSION_NUMBER < 0x04000000 #include #include #endif @@ -60,35 +58,22 @@ #endif #include "cipher_suite.h" #include "../urldata.h" -#include "../sendf.h" -#include "../curlx/inet_pton.h" +#include "../curl_trc.h" #include "mbedtls.h" #include "vtls.h" #include "vtls_int.h" #include "vtls_scache.h" #include "x509asn1.h" -#include "../parsedate.h" #include "../connect.h" /* for the connect timeout */ -#include "../select.h" -#include "../multiif.h" -#include "mbedtls_threadlock.h" #include "../strdup.h" #include "../curl_sha256.h" -/* The last 2 #include files should be in this order */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* ALPN for http2 */ #if defined(USE_HTTP2) && defined(MBEDTLS_SSL_ALPN) -# define HAS_ALPN_MBEDTLS +#define HAS_ALPN_MBEDTLS #endif struct mbed_ssl_backend_data { -#ifdef CURL_MBEDTLS_DRBG - mbedtls_ctr_drbg_context ctr_drbg; - mbedtls_entropy_context entropy; -#endif mbedtls_ssl_context ssl; mbedtls_x509_crt cacert; mbedtls_x509_crt clicert; @@ -107,55 +92,21 @@ struct mbed_ssl_backend_data { BIT(send_blocked); }; -/* apply threading? */ -#if (defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)) || defined(_WIN32) -#define HAS_THREADING_SUPPORT +/** A context for random number generation (RNG). + */ +#if MBEDTLS_VERSION_NUMBER < 0x04000000 +struct rng_context_t { + mbedtls_entropy_context entropy; + mbedtls_ctr_drbg_context drbg; +}; + +static struct rng_context_t rng; #endif #ifndef MBEDTLS_ERROR_C -#define mbedtls_strerror(a,b,c) b[0] = 0 +#define mbedtls_strerror(a, b, c) b[0] = 0 #endif -#if defined(CURL_MBEDTLS_DRBG) && defined(HAS_THREADING_SUPPORT) -static mbedtls_entropy_context ts_entropy; - -static int entropy_init_initialized = 0; - -static void entropy_init_mutex(mbedtls_entropy_context *ctx) -{ - /* lock 0 = entropy_init_mutex() */ - Curl_mbedtlsthreadlock_lock_function(0); - if(entropy_init_initialized == 0) { - mbedtls_entropy_init(ctx); - entropy_init_initialized = 1; - } - Curl_mbedtlsthreadlock_unlock_function(0); -} - -static void entropy_cleanup_mutex(mbedtls_entropy_context *ctx) -{ - /* lock 0 = use same lock as init */ - Curl_mbedtlsthreadlock_lock_function(0); - if(entropy_init_initialized == 1) { - mbedtls_entropy_free(ctx); - entropy_init_initialized = 0; - } - Curl_mbedtlsthreadlock_unlock_function(0); -} - -static int entropy_func_mutex(void *data, unsigned char *output, size_t len) -{ - int ret; - /* lock 1 = entropy_func_mutex() */ - Curl_mbedtlsthreadlock_lock_function(1); - ret = mbedtls_entropy_func(data, output, len); - Curl_mbedtlsthreadlock_unlock_function(1); - - return ret; -} - -#endif /* CURL_MBEDTLS_DRBG && HAS_THREADING_SUPPORT */ - #ifdef MBEDTLS_DEBUG static void mbed_debug(void *context, int level, const char *f_name, int line_nb, const char *line) @@ -187,8 +138,7 @@ static int mbedtls_bio_cf_write(void *bio, if(!data) return 0; - result = Curl_conn_cf_send(cf->next, data, (const char *)buf, blen, FALSE, - &nwritten); + result = Curl_conn_cf_send(cf->next, data, buf, blen, FALSE, &nwritten); CURL_TRC_CF(data, cf, "mbedtls_bio_cf_out_write(len=%zu) -> %d, %zu", blen, result, nwritten); if(CURLE_AGAIN == result) @@ -200,7 +150,7 @@ static int mbedtls_bio_cf_read(void *bio, unsigned char *buf, size_t blen) { struct Curl_cfilter *cf = bio; struct Curl_easy *data = CF_DATA_CURRENT(cf); - size_t nread; + size_t nread = 0; CURLcode result; DEBUGASSERT(data); @@ -215,29 +165,13 @@ static int mbedtls_bio_cf_read(void *bio, unsigned char *buf, size_t blen) blen, result, nread); if(CURLE_AGAIN == result) return MBEDTLS_ERR_SSL_WANT_READ; + /* nread is never larger than int here */ return result ? -1 : (int)nread; } -/* - * profile +/* See: + * https://web.archive.org/web/20200921194007/tls.mbed.org/discussions/generic/howto-determine-exact-buffer-len-for-mbedtls_pk_write_pubkey_der */ -static const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_fr = -{ - /* Hashes from SHA-1 and above */ - MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA1) | - MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_RIPEMD160) | - MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA224) | - MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA256) | - MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA384) | - MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA512), - 0xFFFFFFF, /* Any PK alg */ - 0xFFFFFFF, /* Any curve */ - 1024, /* RSA min key len */ -}; - -/* See https://web.archive.org/web/20200921194007/tls.mbed.org/discussions/ - generic/howto-determine-exact-buffer-len-for-mbedtls_pk_write_pubkey_der -*/ #define RSA_PUB_DER_MAX_BYTES (38 + 2 * MBEDTLS_MPI_MAX_SIZE) #define ECP_PUB_DER_MAX_BYTES (30 + 2 * MBEDTLS_ECP_MAX_BYTES) @@ -249,12 +183,13 @@ mbed_set_ssl_version_min_max(struct Curl_easy *data, struct mbed_ssl_backend_data *backend, struct ssl_primary_config *conn_config) { - /* TLS 1.0 and TLS 1.1 were dropped with mbedTLS 3.0.0 (2021). So, since - * then, and before the introduction of TLS 1.3 in 3.6.0 (2024), this - * function basically always sets TLS 1.2 as min/max, unless given - * unsupported option values. */ - - mbedtls_ssl_protocol_version ver_min = MBEDTLS_SSL_VERSION_TLS1_2; + mbedtls_ssl_protocol_version ver_min = +#ifdef MBEDTLS_SSL_PROTO_TLS1_2 + MBEDTLS_SSL_VERSION_TLS1_2 +#else + MBEDTLS_SSL_VERSION_TLS1_3 +#endif + ; mbedtls_ssl_protocol_version ver_max = #ifdef MBEDTLS_SSL_PROTO_TLS1_3 MBEDTLS_SSL_VERSION_TLS1_3 @@ -269,8 +204,10 @@ mbed_set_ssl_version_min_max(struct Curl_easy *data, case CURL_SSLVERSION_TLSv1_0: case CURL_SSLVERSION_TLSv1_1: case CURL_SSLVERSION_TLSv1_2: +#ifdef MBEDTLS_SSL_PROTO_TLS1_2 ver_min = MBEDTLS_SSL_VERSION_TLS1_2; break; +#endif case CURL_SSLVERSION_TLSv1_3: #ifdef MBEDTLS_SSL_PROTO_TLS1_3 ver_min = MBEDTLS_SSL_VERSION_TLS1_3; @@ -290,9 +227,11 @@ mbed_set_ssl_version_min_max(struct Curl_easy *data, ver_max = MBEDTLS_SSL_VERSION_TLS1_3; break; #endif +#ifdef MBEDTLS_SSL_PROTO_TLS1_2 case CURL_SSLVERSION_MAX_TLSv1_2: ver_max = MBEDTLS_SSL_VERSION_TLS1_2; break; +#endif case CURL_SSLVERSION_MAX_TLSv1_1: case CURL_SSLVERSION_MAX_TLSv1_0: default: @@ -311,9 +250,8 @@ mbed_set_ssl_version_min_max(struct Curl_easy *data, cipher suite present in other SSL implementations. Provide provisional support for specifying the cipher suite here. */ #ifdef MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8 -static int -mbed_cipher_suite_get_str(uint16_t id, char *buf, size_t buf_size, - bool prefer_rfc) +static int mbed_cipher_suite_get_str(uint16_t id, char *buf, size_t buf_size, + bool prefer_rfc) { if(id == MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8) curl_msnprintf(buf, buf_size, "%s", "TLS_ECJPAKE_WITH_AES_128_CCM_8"); @@ -322,8 +260,7 @@ mbed_cipher_suite_get_str(uint16_t id, char *buf, size_t buf_size, return 0; } -static uint16_t -mbed_cipher_suite_walk_str(const char **str, const char **end) +static uint16_t mbed_cipher_suite_walk_str(const char **str, const char **end) { uint16_t id = Curl_cipher_suite_walk_str(str, end); size_t len = *end - *str; @@ -352,10 +289,11 @@ mbed_set_selected_ciphers(struct Curl_easy *data, const char *ptr, *end; supported = mbedtls_ssl_list_ciphersuites(); - for(i = 0; supported[i] != 0; i++); + for(i = 0; supported[i] != 0; i++) + ; supported_len = i; - selected = malloc(sizeof(int) * (supported_len + 1)); + selected = curlx_malloc(sizeof(int) * (supported_len + 1)); if(!selected) return CURLE_OUT_OF_MEMORY; @@ -365,7 +303,7 @@ mbed_set_selected_ciphers(struct Curl_easy *data, if(!ciphers13) { /* Add default TLSv1.3 ciphers to selection */ for(j = 0; j < supported_len; j++) { - uint16_t id = (uint16_t) supported[j]; + uint16_t id = (uint16_t)supported[j]; if(strncmp(mbedtls_ssl_get_ciphersuite_name(id), "TLS1-3", 6) != 0) continue; @@ -384,23 +322,25 @@ mbed_set_selected_ciphers(struct Curl_easy *data, /* Check if cipher is supported */ if(id) { - for(i = 0; i < supported_len && supported[i] != id; i++); + for(i = 0; i < supported_len && supported[i] != id; i++) + ; if(i == supported_len) id = 0; } if(!id) { if(ptr[0] != '\0') infof(data, "mbedTLS: unknown cipher in list: \"%.*s\"", - (int) (end - ptr), ptr); + (int)(end - ptr), ptr); continue; } /* No duplicates allowed (so selected cannot overflow) */ - for(i = 0; i < count && selected[i] != id; i++); + for(i = 0; i < count && selected[i] != id; i++) + ; if(i < count) { if(i >= default13_count) infof(data, "mbedTLS: duplicate cipher in list: \"%.*s\"", - (int) (end - ptr), ptr); + (int)(end - ptr), ptr); continue; } @@ -416,12 +356,13 @@ mbed_set_selected_ciphers(struct Curl_easy *data, if(!ciphers12) { /* Add default TLSv1.2 ciphers to selection */ for(j = 0; j < supported_len; j++) { - uint16_t id = (uint16_t) supported[j]; + uint16_t id = (uint16_t)supported[j]; if(strncmp(mbedtls_ssl_get_ciphersuite_name(id), "TLS1-3", 6) == 0) continue; /* No duplicates allowed (so selected cannot overflow) */ - for(i = 0; i < count && selected[i] != id; i++); + for(i = 0; i < count && selected[i] != id; i++) + ; if(i < count) continue; @@ -433,7 +374,7 @@ mbed_set_selected_ciphers(struct Curl_easy *data, selected[count] = 0; if(count == 0) { - free(selected); + curlx_free(selected); failf(data, "mbedTLS: no supported cipher in list"); return CURLE_SSL_CIPHER; } @@ -445,42 +386,51 @@ mbed_set_selected_ciphers(struct Curl_easy *data, return CURLE_OK; } -static void -mbed_dump_cert_info(struct Curl_easy *data, const mbedtls_x509_crt *crt) +static void mbed_dump_cert_info(struct Curl_easy *data, + const mbedtls_x509_crt *crt) { #if defined(CURL_DISABLE_VERBOSE_STRINGS) || defined(MBEDTLS_X509_REMOVE_INFO) (void)data, (void)crt; #else const size_t bufsize = 16384; - char *p, *buffer = malloc(bufsize); + char *p, *buffer = curlx_malloc(bufsize); if(buffer && mbedtls_x509_crt_info(buffer, bufsize, " ", crt) > 0) { infof(data, "Server certificate:"); for(p = buffer; *p; p += *p != '\0') { size_t s = strcspn(p, "\n"); - infof(data, "%.*s", (int) s, p); + infof(data, "%.*s", (int)s, p); p += s; } } else infof(data, "Unable to dump certificate information"); - free(buffer); + curlx_free(buffer); #endif } -static void -mbed_extract_certinfo(struct Curl_easy *data, const mbedtls_x509_crt *crt) +static void mbed_extract_certinfo(struct Curl_easy *data, + const mbedtls_x509_crt *crt) { CURLcode result; const mbedtls_x509_crt *cur; + int cert_count = 0; int i; - for(i = 0, cur = crt; cur; ++i, cur = cur->next); - result = Curl_ssl_init_certinfo(data, i); + for(cur = crt; cur && cert_count <= MAX_ALLOWED_CERT_AMOUNT; cur = cur->next) + cert_count++; + + if(cert_count > MAX_ALLOWED_CERT_AMOUNT) { + infof(data, "Certificates is more than allowed (%u), skipping certinfo", + MAX_ALLOWED_CERT_AMOUNT); + return; + } + + result = Curl_ssl_init_certinfo(data, cert_count); for(i = 0, cur = crt; result == CURLE_OK && cur; ++i, cur = cur->next) { - const char *beg = (const char *) cur->raw.p; + const char *beg = (const char *)cur->raw.p; const char *end = beg + cur->raw.len; result = Curl_extract_certinfo(data, i, beg, end); } @@ -489,7 +439,7 @@ mbed_extract_certinfo(struct Curl_easy *data, const mbedtls_x509_crt *crt) static int mbed_verify_cb(void *ptr, mbedtls_x509_crt *crt, int depth, uint32_t *flags) { - struct Curl_cfilter *cf = (struct Curl_cfilter *) ptr; + struct Curl_cfilter *cf = (struct Curl_cfilter *)ptr; struct ssl_primary_config *conn_config = Curl_ssl_cf_get_primary_config(cf); struct Curl_easy *data = CF_DATA_CURRENT(cf); @@ -518,8 +468,8 @@ static int mbed_verify_cb(void *ptr, mbedtls_x509_crt *crt, return 0; } -static CURLcode -mbed_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) +static CURLcode mbed_connect_step1(struct Curl_cfilter *cf, + struct Curl_easy *data) { struct ssl_connect_data *connssl = cf->ctx; struct mbed_ssl_backend_data *backend = @@ -534,6 +484,9 @@ mbed_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) const char * const ssl_capath = conn_config->CApath; char * const ssl_cert = ssl_config->primary.clientcert; const struct curl_blob *ssl_cert_blob = ssl_config->primary.cert_blob; +#ifdef MBEDTLS_PEM_PARSE_C + const char * const ssl_cert_type = ssl_config->cert_type; +#endif const char * const ssl_crlfile = ssl_config->primary.CRLfile; const char *hostname = connssl->peer.hostname; int ret = -1; @@ -548,50 +501,49 @@ mbed_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) return CURLE_NOT_BUILT_IN; } -#ifdef CURL_MBEDTLS_DRBG -#ifdef HAS_THREADING_SUPPORT - mbedtls_ctr_drbg_init(&backend->ctr_drbg); - - ret = mbedtls_ctr_drbg_seed(&backend->ctr_drbg, entropy_func_mutex, - &ts_entropy, NULL, 0); - if(ret) { - mbedtls_strerror(ret, errorbuf, sizeof(errorbuf)); - failf(data, "mbedtls_ctr_drbg_seed returned (-0x%04X) %s", - -ret, errorbuf); - return CURLE_FAILED_INIT; - } -#else - mbedtls_entropy_init(&backend->entropy); - mbedtls_ctr_drbg_init(&backend->ctr_drbg); - - ret = mbedtls_ctr_drbg_seed(&backend->ctr_drbg, mbedtls_entropy_func, - &backend->entropy, NULL, 0); - if(ret) { - mbedtls_strerror(ret, errorbuf, sizeof(errorbuf)); - failf(data, "mbedtls_ctr_drbg_seed returned (-0x%04X) %s", - -ret, errorbuf); - return CURLE_FAILED_INIT; - } -#endif /* HAS_THREADING_SUPPORT */ -#endif /* CURL_MBEDTLS_DRBG */ - /* Load the trusted CA */ mbedtls_x509_crt_init(&backend->cacert); if(ca_info_blob && verifypeer) { - /* Unfortunately, mbedtls_x509_crt_parse() requires the data to be null - terminated even when provided the exact length, forcing us to waste - extra memory here. */ - unsigned char *newblob = Curl_memdup0(ca_info_blob->data, - ca_info_blob->len); - if(!newblob) - return CURLE_OUT_OF_MEMORY; - ret = mbedtls_x509_crt_parse(&backend->cacert, newblob, - ca_info_blob->len + 1); - free(newblob); +#ifdef MBEDTLS_PEM_PARSE_C + /* if DER or a null-terminated PEM just process using + mbedtls_x509_crt_parse(). */ + if((ssl_cert_type && curl_strequal(ssl_cert_type, "DER")) || + ((char *)(ca_info_blob->data))[ca_info_blob->len - 1] == '\0') { + + ret = mbedtls_x509_crt_parse(&backend->cacert, + ca_info_blob->data, + ca_info_blob->len); + } + else { /* they say it is PEM and it is not null-terminated */ + + /* Unfortunately, mbedtls_x509_crt_parse() requires the data to + be null-terminated if the data is PEM encoded (even when + provided the exact length). The function accepts PEM or DER + formats, but we cannot assume if the user passed in a PEM + format cert that it is null-terminated. */ + unsigned char *newblob = Curl_memdup0(ca_info_blob->data, + ca_info_blob->len); + if(!newblob) + return CURLE_OUT_OF_MEMORY; + + ret = mbedtls_x509_crt_parse(&backend->cacert, newblob, + ca_info_blob->len + 1); + curlx_free(newblob); + } +#else + /* DER encoded certs do not need to be null terminated + because it is a binary format. So if we are not compiling + with PEM_PARSE we can avoid the extra memory copies + altogether. */ + ret = mbedtls_x509_crt_parse_der(&backend->cacert, + ca_info_blob->data, + ca_info_blob->len); +#endif + if(ret < 0) { mbedtls_strerror(ret, errorbuf, sizeof(errorbuf)); - failf(data, "Error importing ca cert blob - mbedTLS: (-0x%04X) %s", + failf(data, "mbedTLS: error importing CA cert blob: (-0x%04X) %s", -ret, errorbuf); return CURLE_SSL_CERTPROBLEM; } @@ -603,12 +555,12 @@ mbed_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) if(ret < 0) { mbedtls_strerror(ret, errorbuf, sizeof(errorbuf)); - failf(data, "Error reading ca cert file %s - mbedTLS: (-0x%04X) %s", + failf(data, "mbedTLS: error reading CA cert file %s: (-0x%04X) %s", ssl_cafile, -ret, errorbuf); return CURLE_SSL_CACERT_BADFILE; } #else - failf(data, "mbedtls: functions that use the file system not built in"); + failf(data, "mbedTLS: functions that use the file system not built in"); return CURLE_NOT_BUILT_IN; #endif } @@ -619,14 +571,14 @@ mbed_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) if(ret < 0) { mbedtls_strerror(ret, errorbuf, sizeof(errorbuf)); - failf(data, "Error reading ca cert path %s - mbedTLS: (-0x%04X) %s", + failf(data, "mbedTLS: error reading CA cert path %s: (-0x%04X) %s", ssl_capath, -ret, errorbuf); if(verifypeer) return CURLE_SSL_CACERT_BADFILE; } #else - failf(data, "mbedtls: functions that use the file system not built in"); + failf(data, "mbedTLS: functions that use the file system not built in"); return CURLE_NOT_BUILT_IN; #endif } @@ -640,32 +592,56 @@ mbed_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) if(ret) { mbedtls_strerror(ret, errorbuf, sizeof(errorbuf)); - failf(data, "Error reading client cert file %s - mbedTLS: (-0x%04X) %s", + failf(data, "mbedTLS: error reading client cert file %s: (-0x%04X) %s", ssl_cert, -ret, errorbuf); return CURLE_SSL_CERTPROBLEM; } #else - failf(data, "mbedtls: functions that use the file system not built in"); + failf(data, "mbedTLS: functions that use the file system not built in"); return CURLE_NOT_BUILT_IN; #endif } if(ssl_cert_blob) { - /* Unfortunately, mbedtls_x509_crt_parse() requires the data to be null - terminated even when provided the exact length, forcing us to waste - extra memory here. */ - unsigned char *newblob = Curl_memdup0(ssl_cert_blob->data, - ssl_cert_blob->len); - if(!newblob) - return CURLE_OUT_OF_MEMORY; - ret = mbedtls_x509_crt_parse(&backend->clicert, newblob, - ssl_cert_blob->len + 1); - free(newblob); +#ifdef MBEDTLS_PEM_PARSE_C + /* if DER or a null-terminated PEM just process using + mbedtls_x509_crt_parse(). */ + if((ssl_cert_type && curl_strequal(ssl_cert_type, "DER")) || + ((char *)(ssl_cert_blob->data))[ssl_cert_blob->len - 1] == '\0') { + + ret = mbedtls_x509_crt_parse(&backend->clicert, + ssl_cert_blob->data, + ssl_cert_blob->len); + } + else { /* they say it is PEM and it is not null-terminated */ + + /* Unfortunately, mbedtls_x509_crt_parse() requires the data to + be null-terminated if the data is PEM encoded (even when + provided the exact length). The function accepts PEM or DER + formats, but we cannot assume if the user passed in a PEM + format cert that it is null-terminated. */ + unsigned char *newblob = Curl_memdup0(ssl_cert_blob->data, + ssl_cert_blob->len); + if(!newblob) + return CURLE_OUT_OF_MEMORY; + ret = mbedtls_x509_crt_parse(&backend->clicert, newblob, + ssl_cert_blob->len + 1); + curlx_free(newblob); + } +#else + /* DER encoded certs do not need to be null terminated + because it is a binary format. So if we are not compiling + with PEM_PARSE we can avoid the extra memory copies + altogether. */ + ret = mbedtls_x509_crt_parse_der(&backend->clicert, + ssl_cert_blob->data, + ssl_cert_blob->len); +#endif if(ret) { mbedtls_strerror(ret, errorbuf, sizeof(errorbuf)); - failf(data, "Error reading client cert data %s - mbedTLS: (-0x%04X) %s", + failf(data, "mbedTLS: error reading client cert data %s: (-0x%04X) %s", ssl_config->key, -ret, errorbuf); return CURLE_SSL_CERTPROBLEM; } @@ -691,7 +667,7 @@ mbed_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) ret = mbedtls_pk_parse_keyfile(&backend->pk, ssl_config->key, ssl_config->key_passwd, mbedtls_ctr_drbg_random, - &backend->ctr_drbg); + &rng.drbg); if(ret == 0 && !(mbedtls_pk_can_do(&backend->pk, MBEDTLS_PK_RSA) || mbedtls_pk_can_do(&backend->pk, MBEDTLS_PK_ECKEY))) ret = MBEDTLS_ERR_PK_TYPE_MISMATCH; @@ -699,12 +675,12 @@ mbed_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) if(ret) { mbedtls_strerror(ret, errorbuf, sizeof(errorbuf)); - failf(data, "Error reading private key %s - mbedTLS: (-0x%04X) %s", + failf(data, "mbedTLS: error reading private key %s: (-0x%04X) %s", ssl_config->key, -ret, errorbuf); return CURLE_SSL_CERTPROBLEM; } #else - failf(data, "mbedtls: functions that use the file system not built in"); + failf(data, "mbedTLS: functions that use the file system not built in"); return CURLE_NOT_BUILT_IN; #endif } @@ -729,7 +705,7 @@ mbed_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) (const unsigned char *)passwd, passwd ? strlen(passwd) : 0, mbedtls_ctr_drbg_random, - &backend->ctr_drbg); + &rng.drbg); if(ret == 0 && !(mbedtls_pk_can_do(&backend->pk, MBEDTLS_PK_RSA) || mbedtls_pk_can_do(&backend->pk, MBEDTLS_PK_ECKEY))) ret = MBEDTLS_ERR_PK_TYPE_MISMATCH; @@ -737,7 +713,7 @@ mbed_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) if(ret) { mbedtls_strerror(ret, errorbuf, sizeof(errorbuf)); - failf(data, "Error parsing private key - mbedTLS: (-0x%04X) %s", + failf(data, "mbedTLS: error parsing private key: (-0x%04X) %s", -ret, errorbuf); return CURLE_SSL_CERTPROBLEM; } @@ -754,19 +730,19 @@ mbed_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) if(ret) { mbedtls_strerror(ret, errorbuf, sizeof(errorbuf)); - failf(data, "Error reading CRL file %s - mbedTLS: (-0x%04X) %s", + failf(data, "mbedTLS: error reading CRL file %s: (-0x%04X) %s", ssl_crlfile, -ret, errorbuf); return CURLE_SSL_CRL_BADFILE; } #else - failf(data, "mbedtls: functions that use the file system not built in"); + failf(data, "mbedTLS: functions that use the file system not built in"); return CURLE_NOT_BUILT_IN; #endif } #else if(ssl_crlfile) { - failf(data, "mbedtls: crl support not built in"); + failf(data, "mbedTLS: CRL support not built in"); return CURLE_NOT_BUILT_IN; } #endif @@ -783,6 +759,18 @@ mbed_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) return CURLE_SSL_CONNECT_ERROR; } +#ifdef MBEDTLS_DEBUG + /* In order to make that work in mbedtls MBEDTLS_DEBUG_C must be defined. */ + mbedtls_ssl_conf_dbg(&backend->config, mbed_debug, data); + /* - 0 No debug + * - 1 Error + * - 2 State change + * - 3 Informational + * - 4 Verbose + */ + mbedtls_debug_set_threshold(4); +#endif + #if defined(MBEDTLS_SSL_SESSION_TICKETS) && \ MBEDTLS_VERSION_NUMBER >= 0x03060100 && MBEDTLS_VERSION_NUMBER < 0x04000000 /* New in mbedTLS 3.6.1, need to enable, default is now disabled. @@ -800,23 +788,23 @@ mbed_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) mbedtls_ssl_init(&backend->ssl); backend->initialized = TRUE; - /* new profile with RSA min key len = 1024 ... */ + /* use the default secure profile baked into mbedTLS */ mbedtls_ssl_conf_cert_profile(&backend->config, - &mbedtls_x509_crt_profile_fr); + &mbedtls_x509_crt_profile_next); ret = mbed_set_ssl_version_min_max(data, backend, conn_config); if(ret != CURLE_OK) return ret; -#ifdef CURL_MBEDTLS_DRBG +#if MBEDTLS_VERSION_NUMBER < 0x04000000 mbedtls_ssl_conf_rng(&backend->config, mbedtls_ctr_drbg_random, - &backend->ctr_drbg); + &rng.drbg); #endif ret = mbedtls_ssl_setup(&backend->ssl, &backend->config); if(ret) { mbedtls_strerror(ret, errorbuf, sizeof(errorbuf)); - failf(data, "ssl_setup failed - mbedTLS: (-0x%04X) %s", + failf(data, "mbedTLS: ssl_setup failed: (-0x%04X) %s", -ret, errorbuf); return CURLE_SSL_CONNECT_ERROR; } @@ -847,7 +835,6 @@ mbed_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) mbedtls_ssl_list_ciphersuites()); } - #ifdef MBEDTLS_SSL_RENEGOTIATION mbedtls_ssl_conf_renegotiation(&backend->config, MBEDTLS_SSL_RENEGOTIATION_ENABLED); @@ -928,18 +915,6 @@ mbed_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) } #endif -#ifdef MBEDTLS_DEBUG - /* In order to make that work in mbedtls MBEDTLS_DEBUG_C must be defined. */ - mbedtls_ssl_conf_dbg(&backend->config, mbed_debug, data); - /* - 0 No debug - * - 1 Error - * - 2 State change - * - 3 Informational - * - 4 Verbose - */ - mbedtls_debug_set_threshold(4); -#endif - /* give application a chance to interfere with mbedTLS set up. */ if(data->set.ssl.fsslctx) { CURLcode result = (*data->set.ssl.fsslctx)(data, &backend->config, @@ -955,20 +930,24 @@ mbed_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) return CURLE_OK; } -static CURLcode -mbed_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) +static CURLcode mbed_connect_step2(struct Curl_cfilter *cf, + struct Curl_easy *data) { +#if defined(MBEDTLS_PK_WRITE_C) || defined(HAS_ALPN_MBEDTLS) CURLcode result; +#endif int ret; struct ssl_connect_data *connssl = cf->ctx; struct mbed_ssl_backend_data *backend = (struct mbed_ssl_backend_data *)connssl->backend; +#ifdef MBEDTLS_PK_WRITE_C #ifndef CURL_DISABLE_PROXY const char * const pinnedpubkey = Curl_ssl_cf_is_proxy(cf) ? data->set.str[STRING_SSL_PINNEDPUBLICKEY_PROXY] : data->set.str[STRING_SSL_PINNEDPUBLICKEY]; #else const char * const pinnedpubkey = data->set.str[STRING_SSL_PINNEDPUBLICKEY]; +#endif #endif DEBUGASSERT(backend); @@ -1000,13 +979,14 @@ mbed_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) { char cipher_str[64]; uint16_t cipher_id; - cipher_id = (uint16_t) - mbedtls_ssl_get_ciphersuite_id_from_ssl(&backend->ssl); + cipher_id = + (uint16_t)mbedtls_ssl_get_ciphersuite_id_from_ssl(&backend->ssl); mbed_cipher_suite_get_str(cipher_id, cipher_str, sizeof(cipher_str), TRUE); infof(data, "mbedTLS: %s Handshake complete, cipher is %s", mbedtls_ssl_get_version(&backend->ssl), cipher_str); } +#ifdef MBEDTLS_PK_WRITE_C if(pinnedpubkey) { int size; const mbedtls_x509_crt *peercert; @@ -1019,12 +999,12 @@ mbed_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) return CURLE_SSL_PINNEDPUBKEYNOTMATCH; } - p = calloc(1, sizeof(*p)); + p = curlx_calloc(1, sizeof(*p)); if(!p) return CURLE_OUT_OF_MEMORY; - pubkey = malloc(PUB_DER_MAX_BYTES); + pubkey = curlx_malloc(PUB_DER_MAX_BYTES); if(!pubkey) { result = CURLE_OUT_OF_MEMORY; @@ -1056,11 +1036,12 @@ mbed_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) &pubkey[PUB_DER_MAX_BYTES - size], size); pinnedpubkey_error: mbedtls_x509_crt_free(p); - free(p); - free(pubkey); + curlx_free(p); + curlx_free(pubkey); if(result) return result; } +#endif #ifdef HAS_ALPN_MBEDTLS if(connssl->alpn) { @@ -1080,8 +1061,8 @@ mbed_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) return CURLE_OK; } -static CURLcode -mbed_new_session(struct Curl_cfilter *cf, struct Curl_easy *data) +static CURLcode mbed_new_session(struct Curl_cfilter *cf, + struct Curl_easy *data) { struct ssl_connect_data *connssl = cf->ctx; struct mbed_ssl_backend_data *backend = @@ -1114,7 +1095,7 @@ mbed_new_session(struct Curl_cfilter *cf, struct Curl_easy *data) goto out; } - sdata = malloc(slen); + sdata = curlx_malloc(slen); if(!sdata) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -1139,13 +1120,12 @@ mbed_new_session(struct Curl_cfilter *cf, struct Curl_easy *data) out: if(msession_alloced) mbedtls_ssl_session_free(&session); - free(sdata); + curlx_free(sdata); return result; } static CURLcode mbed_send(struct Curl_cfilter *cf, struct Curl_easy *data, - const void *mem, size_t len, - size_t *pnwritten) + const void *mem, size_t len, size_t *pnwritten) { struct ssl_connect_data *connssl = cf->ctx; struct mbed_ssl_backend_data *backend = @@ -1157,7 +1137,7 @@ static CURLcode mbed_send(struct Curl_cfilter *cf, struct Curl_easy *data, DEBUGASSERT(backend); *pnwritten = 0; connssl->io_need = CURL_SSL_IO_NEED_NONE; - /* mbedtls is picky when a mbedtls_ssl_write) was previously blocked. + /* mbedTLS is picky when a mbedtls_ssl_write() was previously blocked. * It requires to be called with the same amount of bytes again, or it * will lose bytes, e.g. reporting all was sent but they were not. * Remember the blocked length and use that when set. */ @@ -1312,19 +1292,12 @@ static void mbedtls_close(struct Curl_cfilter *cf, struct Curl_easy *data) Curl_safefree(backend->ciphersuites); mbedtls_ssl_config_free(&backend->config); mbedtls_ssl_free(&backend->ssl); -#ifdef CURL_MBEDTLS_DRBG - mbedtls_ctr_drbg_free(&backend->ctr_drbg); -#ifndef HAS_THREADING_SUPPORT - mbedtls_entropy_free(&backend->entropy); -#endif /* !HAS_THREADING_SUPPORT */ -#endif backend->initialized = FALSE; } } static CURLcode mbed_recv(struct Curl_cfilter *cf, struct Curl_easy *data, - char *buf, size_t buffersize, - size_t *pnread) + char *buf, size_t buffersize, size_t *pnread) { struct ssl_connect_data *connssl = cf->ctx; struct mbed_ssl_backend_data *backend = @@ -1341,6 +1314,7 @@ static CURLcode mbed_recv(struct Curl_cfilter *cf, struct Curl_easy *data, if(nread > 0) *pnread = (size_t)nread; else { + char errorbuf[128]; CURL_TRC_CF(data, cf, "mbedtls_ssl_read(len=%zu) -> -0x%04X", buffersize, -nread); switch(nread) { @@ -1360,14 +1334,12 @@ static CURLcode mbed_recv(struct Curl_cfilter *cf, struct Curl_easy *data, case MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY: result = CURLE_OK; break; - default: { - char errorbuf[128]; + default: mbedtls_strerror(nread, errorbuf, sizeof(errorbuf)); failf(data, "ssl_read returned: (-0x%04X) %s", -nread, errorbuf); result = CURLE_RECV_ERROR; break; } - } } return result; } @@ -1453,25 +1425,47 @@ static CURLcode mbedtls_connect(struct Curl_cfilter *cf, */ static int mbedtls_init(void) { +#if MBEDTLS_VERSION_NUMBER < 0x04000000 + int ret = 0; +#endif psa_status_t status; status = psa_crypto_init(); + if(status != PSA_SUCCESS) return 0; - if(!Curl_mbedtlsthreadlock_thread_setup()) + +#if MBEDTLS_VERSION_NUMBER < 0x04000000 + mbedtls_ctr_drbg_init(&rng.drbg); + mbedtls_entropy_init(&rng.entropy); + + ret = mbedtls_ctr_drbg_seed(&rng.drbg, mbedtls_entropy_func, &rng.entropy, + NULL, 0); + + if(ret) { + failf(NULL, " failed\n ! mbedtls_ctr_drbg_seed returned -0x%x\n", + (unsigned int)-ret); return 0; -#if defined(CURL_MBEDTLS_DRBG) && defined(HAS_THREADING_SUPPORT) - entropy_init_mutex(&ts_entropy); + } + + /* To prevent an adversary from reading your random data, + you can enable prediction resistance. + + Entropy is gathered before each mbedtls_ctr_drbg_random() call. + Only use this if you have ample supply of good entropy.*/ + mbedtls_ctr_drbg_set_prediction_resistance(&rng.drbg, + MBEDTLS_CTR_DRBG_PR_ON); #endif return 1; } static void mbedtls_cleanup(void) { -#if defined(CURL_MBEDTLS_DRBG) && defined(HAS_THREADING_SUPPORT) - entropy_cleanup_mutex(&ts_entropy); -#endif - (void)Curl_mbedtlsthreadlock_thread_cleanup(); mbedtls_psa_crypto_free(); + +#if MBEDTLS_VERSION_NUMBER < 0x04000000 + mbedtls_ctr_drbg_free(&rng.drbg); + mbedtls_entropy_free(&rng.entropy); +#endif } static bool mbedtls_data_pending(struct Curl_cfilter *cf, diff --git a/vendor/hydra/vendor/curl/lib/vtls/mbedtls_threadlock.c b/vendor/hydra/vendor/curl/lib/vtls/mbedtls_threadlock.c deleted file mode 100644 index ed70308b..00000000 --- a/vendor/hydra/vendor/curl/lib/vtls/mbedtls_threadlock.c +++ /dev/null @@ -1,134 +0,0 @@ -/*************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ - * \___|\___/|_| \_\_____| - * - * Copyright (C) Daniel Stenberg, , et al. - * Copyright (C) Hoi-Ho Chan, - * - * This software is licensed as described in the file COPYING, which - * you should have received as part of this distribution. The terms - * are also available at https://curl.se/docs/copyright.html. - * - * You may opt to use, copy, modify, merge, publish, distribute and/or sell - * copies of the Software, and permit persons to whom the Software is - * furnished to do so, under the terms of the COPYING file. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - * SPDX-License-Identifier: curl - * - ***************************************************************************/ -#include "../curl_setup.h" - -#if defined(USE_MBEDTLS) && \ - ((defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)) || \ - defined(_WIN32)) - -#if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H) -# include -# define MBEDTLS_MUTEX_T pthread_mutex_t -#elif defined(_WIN32) -# define MBEDTLS_MUTEX_T HANDLE -#endif - -#include "mbedtls_threadlock.h" - -/* The last 2 #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - -/* number of thread locks */ -#define NUMT 2 - -/* This array will store all of the mutexes available to Mbedtls. */ -static MBEDTLS_MUTEX_T *mutex_buf = NULL; - -int Curl_mbedtlsthreadlock_thread_setup(void) -{ - int i; - - mutex_buf = calloc(1, NUMT * sizeof(MBEDTLS_MUTEX_T)); - if(!mutex_buf) - return 0; /* error, no number of threads defined */ - - for(i = 0; i < NUMT; i++) { -#if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H) - if(pthread_mutex_init(&mutex_buf[i], NULL)) - return 0; /* pthread_mutex_init failed */ -#elif defined(_WIN32) - mutex_buf[i] = CreateMutex(0, FALSE, 0); - if(mutex_buf[i] == 0) - return 0; /* CreateMutex failed */ -#endif /* USE_THREADS_POSIX && HAVE_PTHREAD_H */ - } - - return 1; /* OK */ -} - -int Curl_mbedtlsthreadlock_thread_cleanup(void) -{ - int i; - - if(!mutex_buf) - return 0; /* error, no threads locks defined */ - - for(i = 0; i < NUMT; i++) { -#if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H) - if(pthread_mutex_destroy(&mutex_buf[i])) - return 0; /* pthread_mutex_destroy failed */ -#elif defined(_WIN32) - if(!CloseHandle(mutex_buf[i])) - return 0; /* CloseHandle failed */ -#endif /* USE_THREADS_POSIX && HAVE_PTHREAD_H */ - } - free(mutex_buf); - mutex_buf = NULL; - - return 1; /* OK */ -} - -int Curl_mbedtlsthreadlock_lock_function(int n) -{ - if(n < NUMT) { -#if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H) - if(pthread_mutex_lock(&mutex_buf[n])) { - DEBUGF(curl_mfprintf(stderr, "Error: " - "mbedtlsthreadlock_lock_function failed\n")); - return 0; /* pthread_mutex_lock failed */ - } -#elif defined(_WIN32) - if(WaitForSingleObject(mutex_buf[n], INFINITE) == WAIT_FAILED) { - DEBUGF(curl_mfprintf(stderr, "Error: " - "mbedtlsthreadlock_lock_function failed\n")); - return 0; /* pthread_mutex_lock failed */ - } -#endif /* USE_THREADS_POSIX && HAVE_PTHREAD_H */ - } - return 1; /* OK */ -} - -int Curl_mbedtlsthreadlock_unlock_function(int n) -{ - if(n < NUMT) { -#if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H) - if(pthread_mutex_unlock(&mutex_buf[n])) { - DEBUGF(curl_mfprintf(stderr, "Error: " - "mbedtlsthreadlock_unlock_function failed\n")); - return 0; /* pthread_mutex_unlock failed */ - } -#elif defined(_WIN32) - if(!ReleaseMutex(mutex_buf[n])) { - DEBUGF(curl_mfprintf(stderr, "Error: " - "mbedtlsthreadlock_unlock_function failed\n")); - return 0; /* pthread_mutex_lock failed */ - } -#endif /* USE_THREADS_POSIX && HAVE_PTHREAD_H */ - } - return 1; /* OK */ -} - -#endif /* USE_MBEDTLS */ diff --git a/vendor/hydra/vendor/curl/lib/vtls/openssl.c b/vendor/hydra/vendor/curl/lib/vtls/openssl.c index 764d8293..84e6eaad 100644 --- a/vendor/hydra/vendor/curl/lib/vtls/openssl.c +++ b/vendor/hydra/vendor/curl/lib/vtls/openssl.c @@ -21,18 +21,14 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - /* * Source file for all OpenSSL-specific code for the TLS/SSL layer. No code * but vtls.c should ever call or use these functions. */ - #include "../curl_setup.h" #if defined(USE_QUICHE) || defined(USE_OPENSSL) -#include - /* Wincrypt must be included before anything that could include OpenSSL. */ #ifdef USE_WIN32_CRYPTO #include @@ -46,15 +42,13 @@ #endif #include "../urldata.h" -#include "../sendf.h" +#include "../curl_trc.h" #include "../formdata.h" /* for the boundary function */ #include "../url.h" /* for the ssl config check function */ #include "../curlx/inet_pton.h" #include "openssl.h" #include "../connect.h" -#include "../slist.h" -#include "../select.h" -#include "../curlx/wait.h" +#include "../progress.h" #include "vtls.h" #include "vtls_int.h" #include "vtls_scache.h" @@ -65,10 +59,10 @@ #include "../multiif.h" #include "../curlx/strerr.h" #include "../curlx/strparse.h" +#include "../curlx/strcopy.h" #include "../strdup.h" #include "apple.h" -#include #include #include #ifndef OPENSSL_NO_DSA @@ -76,21 +70,15 @@ #endif #include #include -#include #include #include #include #include -#include #include #include #include -#ifdef HAVE_SSL_SET1_ECH_CONFIG_LIST -#define USE_ECH_OPENSSL -#endif - -#if defined(USE_ECH_OPENSSL) && !defined(HAVE_BORINGSSL_LIKE) +#if defined(HAVE_SSL_SET1_ECH_CONFIG_LIST) && !defined(HAVE_BORINGSSL_LIKE) #include #endif @@ -108,8 +96,10 @@ # if LIBRESSL_VERSION_NUMBER < 0x2090100fL /* 2019-04-13 */ # error "LibreSSL 2.9.1 or later required" # endif -#elif OPENSSL_VERSION_NUMBER < 0x1000201fL /* 2015-03-19 */ -# error "OpenSSL 1.0.2a or later required" +#elif !defined(HAVE_BORINGSSL_LIKE) +# ifndef HAVE_OPENSSL3 /* 2021-09-07 */ +# error "OpenSSL 3.0.0 or later required" +# endif #endif #if defined(HAVE_OPENSSL3) && !defined(OPENSSL_NO_UI_CONSOLE) @@ -123,45 +113,13 @@ static void ossl_provider_cleanup(struct Curl_easy *data); /* AWS-LC fixed a bug with large buffers in v1.61.0 which also introduced * X509_V_ERR_EC_KEY_EXPLICIT_PARAMS. */ -#if OPENSSL_VERSION_NUMBER >= 0x10100000L && \ - !defined(LIBRESSL_VERSION_NUMBER) && !defined(OPENSSL_IS_BORINGSSL) && \ +#if !defined(LIBRESSL_VERSION_NUMBER) && !defined(OPENSSL_IS_BORINGSSL) && \ (!defined(OPENSSL_IS_AWSLC) || defined(X509_V_ERR_EC_KEY_EXPLICIT_PARAMS)) #define HAVE_SSL_CTX_SET_DEFAULT_READ_BUFFER_LEN 1 #endif -#include "../curlx/warnless.h" - -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - #if defined(USE_OPENSSL_ENGINE) || defined(OPENSSL_HAS_PROVIDERS) #include - -#if OPENSSL_VERSION_NUMBER >= 0x10100000L -#define OSSL_UI_METHOD_CAST(x) (x) -#else -#define OSSL_UI_METHOD_CAST(x) CURL_UNCONST(x) -#endif -#endif - -#if OPENSSL_VERSION_NUMBER >= 0x10100000L /* OpenSSL 1.1.0+ and LibreSSL */ -#define HAVE_X509_GET0_EXTENSIONS 1 /* added in 1.1.0 -pre1 */ -#define HAVE_OPAQUE_EVP_PKEY 1 /* since 1.1.0 -pre3 */ -#define HAVE_OPAQUE_RSA_DSA_DH 1 /* since 1.1.0 -pre5 */ -#define HAVE_ERR_REMOVE_THREAD_STATE_DEPRECATED 1 -#else -/* For OpenSSL before 1.1.0 */ -#define ASN1_STRING_get0_data(x) ASN1_STRING_data(x) -#define X509_get0_notBefore(x) X509_get_notBefore(x) -#define X509_get0_notAfter(x) X509_get_notAfter(x) -#define OpenSSL_version_num() SSLeay() -#endif - -#if OPENSSL_VERSION_NUMBER >= 0x10002003L && \ - OPENSSL_VERSION_NUMBER <= 0x10002FFFL && \ - !defined(OPENSSL_NO_COMP) -#define HAVE_SSL_COMP_FREE_COMPRESSION_METHODS 1 #endif #ifdef HAVE_OPENSSL3 @@ -182,8 +140,7 @@ static void ossl_provider_cleanup(struct Curl_easy *data); * BoringSSL: no * LibreSSL: supported since 3.4.1 (released 2021-10-14) */ -#if ((OPENSSL_VERSION_NUMBER >= 0x10101000L && \ - !defined(LIBRESSL_VERSION_NUMBER)) || \ +#if (!defined(LIBRESSL_VERSION_NUMBER) || \ (defined(LIBRESSL_VERSION_NUMBER) && \ LIBRESSL_VERSION_NUMBER >= 0x3040100fL)) && \ !defined(OPENSSL_IS_BORINGSSL) @@ -198,7 +155,7 @@ static void ossl_provider_cleanup(struct Curl_easy *data); * BoringSSL: supported since 0.20240913.0 (commit 826ce15) * LibreSSL: no */ -#if OPENSSL_VERSION_NUMBER >= 0x10002000L && !defined(LIBRESSL_VERSION_NUMBER) +#ifndef LIBRESSL_VERSION_NUMBER #define HAVE_SSL_CTX_SET1_SIGALGS #endif @@ -208,7 +165,7 @@ static void ossl_provider_cleanup(struct Curl_easy *data); #define OSSL_PACKAGE "BoringSSL" #elif defined(OPENSSL_IS_AWSLC) #define OSSL_PACKAGE "AWS-LC" -#elif defined(USE_NGTCP2) && defined(USE_NGHTTP3) && \ +#elif defined(USE_NGTCP2) && defined(USE_NGHTTP3) && \ !defined(OPENSSL_QUIC_API2) #define OSSL_PACKAGE "quictls" #else @@ -224,30 +181,6 @@ typedef unsigned long sslerr_t; #endif #define ossl_valsize_t numcert_t -#if OPENSSL_VERSION_NUMBER >= 0x10100000L -/* up2date versions of OpenSSL maintain reasonably secure defaults without - * breaking compatibility, so it is better not to override the defaults in curl - */ -#define DEFAULT_CIPHER_SELECTION NULL -#else -/* not the case with old versions of OpenSSL */ -#define DEFAULT_CIPHER_SELECTION \ - "ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH" -#endif - -#if OPENSSL_VERSION_NUMBER >= 0x10100000L -#define HAVE_RANDOM_INIT_BY_DEFAULT 1 -#endif - -/* - * Whether the OpenSSL version has the API needed to support sharing an - * X509_STORE between connections. The API is: - * * `X509_STORE_up_ref` -- Introduced: OpenSSL 1.1.0. - */ -#if OPENSSL_VERSION_NUMBER >= 0x10100000L /* OpenSSL >= 1.1.0 */ -#define HAVE_SSL_X509_STORE_SHARE -#endif - static CURLcode ossl_certchain(struct Curl_easy *data, SSL *ssl); static CURLcode push_certinfo(struct Curl_easy *data, @@ -264,6 +197,13 @@ static CURLcode push_certinfo(struct Curl_easy *data, return result; } +static CURLcode pubkey_show(struct Curl_easy *data, + BIO *mem, + int num, + const char *type, + const char *name, + const BIGNUM *bn) WARN_UNUSED_RESULT; + static CURLcode pubkey_show(struct Curl_easy *data, BIO *mem, int num, @@ -280,27 +220,12 @@ static CURLcode pubkey_show(struct Curl_easy *data, return push_certinfo(data, mem, namebuf, num); } -#ifdef HAVE_OPAQUE_RSA_DSA_DH -#define print_pubkey_BN(_type, _name, _num) \ +#define print_pubkey_BN(_type, _name, _num) \ pubkey_show(data, mem, _num, #_type, #_name, _name) -#else -#define print_pubkey_BN(_type, _name, _num) \ -do { \ - if(_type->_name) { \ - pubkey_show(data, mem, _num, #_type, #_name, _type->_name); \ - } \ -} while(0) -#endif - static int asn1_object_dump(const ASN1_OBJECT *a, char *buf, size_t len) { - int i; -#if OPENSSL_VERSION_NUMBER >= 0x10100000L - i = i2t_ASN1_OBJECT(buf, (int)len, a); -#else - i = i2t_ASN1_OBJECT(buf, (int)len, CURL_UNCONST(a)); -#endif + int i = i2t_ASN1_OBJECT(buf, (int)len, a); return (i >= (int)len); /* buffer too small */ } @@ -310,10 +235,10 @@ static CURLcode X509V3_ext(struct Curl_easy *data, { int i; CURLcode result = CURLE_OK; -#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER) - const STACK_OF(X509_EXTENSION) *exts = extsarg; -#else +#ifdef LIBRESSL_VERSION_NUMBER STACK_OF(X509_EXTENSION) *exts = CURL_UNCONST(extsarg); +#else + const STACK_OF(X509_EXTENSION) *exts = extsarg; #endif if((int)sk_X509_EXTENSION_num(exts) <= 0) @@ -334,7 +259,7 @@ static CURLcode X509V3_ext(struct Curl_easy *data, if(asn1_object_dump(obj, namebuf, sizeof(namebuf))) /* make sure the name is null-terminated */ - namebuf [ sizeof(namebuf) - 1] = 0; + namebuf[sizeof(namebuf) - 1] = 0; if(!X509V3_EXT_print(bio_out, ext, 0, 0)) ASN1_STRING_print(bio_out, (ASN1_STRING *)X509_EXTENSION_get_data(ext)); @@ -349,7 +274,102 @@ static CURLcode X509V3_ext(struct Curl_easy *data, return result; } -#define MAX_ALLOWED_CERT_AMOUNT 100 +static CURLcode get_pkey_rsa(struct Curl_easy *data, + EVP_PKEY *pubkey, BIO *mem, int i) +{ + CURLcode result = CURLE_OK; +#ifndef HAVE_EVP_PKEY_GET_PARAMS + RSA *rsa = EVP_PKEY_get0_RSA(pubkey); +#endif /* !HAVE_EVP_PKEY_GET_PARAMS */ + DECLARE_PKEY_PARAM_BIGNUM(n); + DECLARE_PKEY_PARAM_BIGNUM(e); +#ifdef HAVE_EVP_PKEY_GET_PARAMS + EVP_PKEY_get_bn_param(pubkey, OSSL_PKEY_PARAM_RSA_N, &n); + EVP_PKEY_get_bn_param(pubkey, OSSL_PKEY_PARAM_RSA_E, &e); +#else + RSA_get0_key(rsa, &n, &e, NULL); +#endif /* HAVE_EVP_PKEY_GET_PARAMS */ + BIO_printf(mem, "%d", n ? BN_num_bits(n) : 0); + result = push_certinfo(data, mem, "RSA Public Key", i); + if(!result) { + result = print_pubkey_BN(rsa, n, i); + if(!result) + result = print_pubkey_BN(rsa, e, i); + } + FREE_PKEY_PARAM_BIGNUM(n); + FREE_PKEY_PARAM_BIGNUM(e); + return result; +} + +#ifndef OPENSSL_NO_DSA +static CURLcode get_pkey_dsa(struct Curl_easy *data, + EVP_PKEY *pubkey, BIO *mem, int i) +{ + CURLcode result = CURLE_OK; +#ifndef HAVE_EVP_PKEY_GET_PARAMS + DSA *dsa = EVP_PKEY_get0_DSA(pubkey); +#endif /* !HAVE_EVP_PKEY_GET_PARAMS */ + DECLARE_PKEY_PARAM_BIGNUM(p); + DECLARE_PKEY_PARAM_BIGNUM(q); + DECLARE_PKEY_PARAM_BIGNUM(g); + DECLARE_PKEY_PARAM_BIGNUM(pub_key); +#ifdef HAVE_EVP_PKEY_GET_PARAMS + EVP_PKEY_get_bn_param(pubkey, OSSL_PKEY_PARAM_FFC_P, &p); + EVP_PKEY_get_bn_param(pubkey, OSSL_PKEY_PARAM_FFC_Q, &q); + EVP_PKEY_get_bn_param(pubkey, OSSL_PKEY_PARAM_FFC_G, &g); + EVP_PKEY_get_bn_param(pubkey, OSSL_PKEY_PARAM_PUB_KEY, &pub_key); +#else + DSA_get0_pqg(dsa, &p, &q, &g); + DSA_get0_key(dsa, &pub_key, NULL); +#endif /* HAVE_EVP_PKEY_GET_PARAMS */ + result = print_pubkey_BN(dsa, p, i); + if(!result) + result = print_pubkey_BN(dsa, q, i); + if(!result) + result = print_pubkey_BN(dsa, g, i); + if(!result) + result = print_pubkey_BN(dsa, pub_key, i); + FREE_PKEY_PARAM_BIGNUM(p); + FREE_PKEY_PARAM_BIGNUM(q); + FREE_PKEY_PARAM_BIGNUM(g); + FREE_PKEY_PARAM_BIGNUM(pub_key); + return result; +} +#endif /* !OPENSSL_NO_DSA */ + +static CURLcode get_pkey_dh(struct Curl_easy *data, + EVP_PKEY *pubkey, BIO *mem, int i) +{ + CURLcode result; +#ifndef HAVE_EVP_PKEY_GET_PARAMS + DH *dh = EVP_PKEY_get0_DH(pubkey); +#endif /* !HAVE_EVP_PKEY_GET_PARAMS */ + DECLARE_PKEY_PARAM_BIGNUM(p); + DECLARE_PKEY_PARAM_BIGNUM(q); + DECLARE_PKEY_PARAM_BIGNUM(g); + DECLARE_PKEY_PARAM_BIGNUM(pub_key); +#ifdef HAVE_EVP_PKEY_GET_PARAMS + EVP_PKEY_get_bn_param(pubkey, OSSL_PKEY_PARAM_FFC_P, &p); + EVP_PKEY_get_bn_param(pubkey, OSSL_PKEY_PARAM_FFC_Q, &q); + EVP_PKEY_get_bn_param(pubkey, OSSL_PKEY_PARAM_FFC_G, &g); + EVP_PKEY_get_bn_param(pubkey, OSSL_PKEY_PARAM_PUB_KEY, &pub_key); +#else + DH_get0_pqg(dh, &p, &q, &g); + DH_get0_key(dh, &pub_key, NULL); +#endif /* HAVE_EVP_PKEY_GET_PARAMS */ + result = print_pubkey_BN(dh, p, i); + if(!result) + result = print_pubkey_BN(dh, q, i); + if(!result) + result = print_pubkey_BN(dh, g, i); + if(!result) + result = print_pubkey_BN(dh, pub_key, i); + FREE_PKEY_PARAM_BIGNUM(p); + FREE_PKEY_PARAM_BIGNUM(q); + FREE_PKEY_PARAM_BIGNUM(g); + FREE_PKEY_PARAM_BIGNUM(pub_key); + return result; +} static CURLcode ossl_certchain(struct Curl_easy *data, SSL *ssl) { @@ -382,6 +402,7 @@ static CURLcode ossl_certchain(struct Curl_easy *data, SSL *ssl) for(i = 0; !result && (i < (int)numcerts); i++) { ASN1_INTEGER *num; + const unsigned char *numdata; X509 *x = sk_X509_value(sk, (ossl_valsize_t)i); EVP_PKEY *pubkey = NULL; int j; @@ -403,15 +424,15 @@ static CURLcode ossl_certchain(struct Curl_easy *data, SSL *ssl) break; num = X509_get_serialNumber(x); - if(num->type == V_ASN1_NEG_INTEGER) + if(ASN1_STRING_type(num) == V_ASN1_NEG_INTEGER) BIO_puts(mem, "-"); - for(j = 0; j < num->length; j++) - BIO_printf(mem, "%02x", num->data[j]); + numdata = ASN1_STRING_get0_data(num); + for(j = 0; j < ASN1_STRING_length(num); j++) + BIO_printf(mem, "%02x", numdata[j]); result = push_certinfo(data, mem, "Serial Number", i); if(result) break; -#ifdef HAVE_X509_GET0_EXTENSIONS { const X509_ALGOR *sigalg = NULL; X509_PUBKEY *xpubkey = NULL; @@ -442,28 +463,6 @@ static CURLcode ossl_certchain(struct Curl_easy *data, SSL *ssl) if(result) break; } -#else - { - /* before OpenSSL 1.0.2 */ - X509_CINF *cinf = x->cert_info; - - i2a_ASN1_OBJECT(mem, cinf->signature->algorithm); - result = push_certinfo(data, mem, "Signature Algorithm", i); - - if(!result) { - i2a_ASN1_OBJECT(mem, cinf->key->algor->algorithm); - result = push_certinfo(data, mem, "Public Key Algorithm", i); - } - - if(!result) - result = X509V3_ext(data, i, cinf->extensions); - - if(result) - break; - - psig = x->signature; - } -#endif ASN1_TIME_print(mem, X509_get0_notBefore(x)); result = push_certinfo(data, mem, "Start date", i); @@ -479,133 +478,28 @@ static CURLcode ossl_certchain(struct Curl_easy *data, SSL *ssl) if(!pubkey) infof(data, " Unable to load public key"); else { - int pktype; -#ifdef HAVE_OPAQUE_EVP_PKEY - pktype = EVP_PKEY_id(pubkey); -#else - pktype = pubkey->type; -#endif - switch(pktype) { - case EVP_PKEY_RSA: { -#ifndef HAVE_EVP_PKEY_GET_PARAMS - RSA *rsa; -#ifdef HAVE_OPAQUE_EVP_PKEY - rsa = EVP_PKEY_get0_RSA(pubkey); -#else - rsa = pubkey->pkey.rsa; -#endif /* HAVE_OPAQUE_EVP_PKEY */ -#endif /* !HAVE_EVP_PKEY_GET_PARAMS */ - - { -#ifdef HAVE_OPAQUE_RSA_DSA_DH - DECLARE_PKEY_PARAM_BIGNUM(n); - DECLARE_PKEY_PARAM_BIGNUM(e); -#ifdef HAVE_EVP_PKEY_GET_PARAMS - EVP_PKEY_get_bn_param(pubkey, OSSL_PKEY_PARAM_RSA_N, &n); - EVP_PKEY_get_bn_param(pubkey, OSSL_PKEY_PARAM_RSA_E, &e); -#else - RSA_get0_key(rsa, &n, &e, NULL); -#endif /* HAVE_EVP_PKEY_GET_PARAMS */ - BIO_printf(mem, "%d", n ? BN_num_bits(n) : 0); -#else - BIO_printf(mem, "%d", rsa->n ? BN_num_bits(rsa->n) : 0); -#endif /* HAVE_OPAQUE_RSA_DSA_DH */ - result = push_certinfo(data, mem, "RSA Public Key", i); - if(result) - break; - print_pubkey_BN(rsa, n, i); - print_pubkey_BN(rsa, e, i); - FREE_PKEY_PARAM_BIGNUM(n); - FREE_PKEY_PARAM_BIGNUM(e); - } - + switch(EVP_PKEY_id(pubkey)) { + case EVP_PKEY_RSA: + result = get_pkey_rsa(data, pubkey, mem, i); break; - } - case EVP_PKEY_DSA: - { + #ifndef OPENSSL_NO_DSA -#ifndef HAVE_EVP_PKEY_GET_PARAMS - DSA *dsa; -#ifdef HAVE_OPAQUE_EVP_PKEY - dsa = EVP_PKEY_get0_DSA(pubkey); -#else - dsa = pubkey->pkey.dsa; -#endif /* HAVE_OPAQUE_EVP_PKEY */ -#endif /* !HAVE_EVP_PKEY_GET_PARAMS */ - { -#ifdef HAVE_OPAQUE_RSA_DSA_DH - DECLARE_PKEY_PARAM_BIGNUM(p); - DECLARE_PKEY_PARAM_BIGNUM(q); - DECLARE_PKEY_PARAM_BIGNUM(g); - DECLARE_PKEY_PARAM_BIGNUM(pub_key); -#ifdef HAVE_EVP_PKEY_GET_PARAMS - EVP_PKEY_get_bn_param(pubkey, OSSL_PKEY_PARAM_FFC_P, &p); - EVP_PKEY_get_bn_param(pubkey, OSSL_PKEY_PARAM_FFC_Q, &q); - EVP_PKEY_get_bn_param(pubkey, OSSL_PKEY_PARAM_FFC_G, &g); - EVP_PKEY_get_bn_param(pubkey, OSSL_PKEY_PARAM_PUB_KEY, &pub_key); -#else - DSA_get0_pqg(dsa, &p, &q, &g); - DSA_get0_key(dsa, &pub_key, NULL); -#endif /* HAVE_EVP_PKEY_GET_PARAMS */ -#endif /* HAVE_OPAQUE_RSA_DSA_DH */ - print_pubkey_BN(dsa, p, i); - print_pubkey_BN(dsa, q, i); - print_pubkey_BN(dsa, g, i); - print_pubkey_BN(dsa, pub_key, i); - FREE_PKEY_PARAM_BIGNUM(p); - FREE_PKEY_PARAM_BIGNUM(q); - FREE_PKEY_PARAM_BIGNUM(g); - FREE_PKEY_PARAM_BIGNUM(pub_key); - } -#endif /* !OPENSSL_NO_DSA */ + case EVP_PKEY_DSA: + result = get_pkey_dsa(data, pubkey, mem, i); break; - } - case EVP_PKEY_DH: { -#ifndef HAVE_EVP_PKEY_GET_PARAMS - DH *dh; -#ifdef HAVE_OPAQUE_EVP_PKEY - dh = EVP_PKEY_get0_DH(pubkey); -#else - dh = pubkey->pkey.dh; -#endif /* HAVE_OPAQUE_EVP_PKEY */ -#endif /* !HAVE_EVP_PKEY_GET_PARAMS */ - { -#ifdef HAVE_OPAQUE_RSA_DSA_DH - DECLARE_PKEY_PARAM_BIGNUM(p); - DECLARE_PKEY_PARAM_BIGNUM(q); - DECLARE_PKEY_PARAM_BIGNUM(g); - DECLARE_PKEY_PARAM_BIGNUM(pub_key); -#ifdef HAVE_EVP_PKEY_GET_PARAMS - EVP_PKEY_get_bn_param(pubkey, OSSL_PKEY_PARAM_FFC_P, &p); - EVP_PKEY_get_bn_param(pubkey, OSSL_PKEY_PARAM_FFC_Q, &q); - EVP_PKEY_get_bn_param(pubkey, OSSL_PKEY_PARAM_FFC_G, &g); - EVP_PKEY_get_bn_param(pubkey, OSSL_PKEY_PARAM_PUB_KEY, &pub_key); -#else - DH_get0_pqg(dh, &p, &q, &g); - DH_get0_key(dh, &pub_key, NULL); -#endif /* HAVE_EVP_PKEY_GET_PARAMS */ - print_pubkey_BN(dh, p, i); - print_pubkey_BN(dh, q, i); - print_pubkey_BN(dh, g, i); -#else - print_pubkey_BN(dh, p, i); - print_pubkey_BN(dh, g, i); -#endif /* HAVE_OPAQUE_RSA_DSA_DH */ - print_pubkey_BN(dh, pub_key, i); - FREE_PKEY_PARAM_BIGNUM(p); - FREE_PKEY_PARAM_BIGNUM(q); - FREE_PKEY_PARAM_BIGNUM(g); - FREE_PKEY_PARAM_BIGNUM(pub_key); - } +#endif + + case EVP_PKEY_DH: + result = get_pkey_dh(data, pubkey, mem, i); break; } - } EVP_PKEY_free(pubkey); } if(!result && psig) { - for(j = 0; j < psig->length; j++) - BIO_printf(mem, "%02x:", psig->data[j]); + const unsigned char *psigdata = ASN1_STRING_get0_data(psig); + for(j = 0; j < ASN1_STRING_length(psig); j++) + BIO_printf(mem, "%02x:", psigdata[j]); result = push_certinfo(data, mem, "Signature", i); } @@ -624,25 +518,14 @@ static CURLcode ossl_certchain(struct Curl_easy *data, SSL *ssl) return result; } -#endif /* quiche or OpenSSL */ +#endif /* USE_QUICHE || USE_OPENSSL */ #ifdef USE_OPENSSL -#if OPENSSL_VERSION_NUMBER < 0x10100000L -#define BIO_set_init(x,v) ((x)->init=(v)) -#define BIO_get_data(x) ((x)->ptr) -#define BIO_set_data(x,v) ((x)->ptr=(v)) -#define BIO_get_shutdown(x) ((x)->shutdown) -#define BIO_set_shutdown(x,v) ((x)->shutdown=(v)) -#endif /* HAVE_PRE_1_1_API */ - static int ossl_bio_cf_create(BIO *bio) { BIO_set_shutdown(bio, 1); BIO_set_init(bio, 1); -#if OPENSSL_VERSION_NUMBER < 0x10100000L - bio->num = -1; -#endif BIO_set_data(bio, NULL); return 1; } @@ -701,7 +584,8 @@ static int ossl_bio_cf_out_write(BIO *bio, const char *buf, int blen) if(blen < 0) return 0; - result = Curl_conn_cf_send(cf->next, data, buf, (size_t)blen, FALSE, + result = Curl_conn_cf_send(cf->next, data, + (const uint8_t *)buf, (size_t)blen, FALSE, &nwritten); CURL_TRC_CF(data, cf, "ossl_bio_cf_out_write(len=%d) -> %d, %zu", blen, result, nwritten); @@ -761,30 +645,6 @@ static int ossl_bio_cf_in_read(BIO *bio, char *buf, int blen) return result ? -1 : (int)nread; } -#if OPENSSL_VERSION_NUMBER < 0x10100000L - -static BIO_METHOD ossl_bio_cf_meth_1_0 = { - BIO_TYPE_MEM, - "OpenSSL CF BIO", - ossl_bio_cf_out_write, - ossl_bio_cf_in_read, - NULL, /* puts is never called */ - NULL, /* gets is never called */ - ossl_bio_cf_ctrl, - ossl_bio_cf_create, - ossl_bio_cf_destroy, - NULL -}; - -static BIO_METHOD *ossl_bio_cf_method_create(void) -{ - return &ossl_bio_cf_meth_1_0; -} - -#define ossl_bio_cf_method_free(m) Curl_nop_stmt - -#else - static BIO_METHOD *ossl_bio_cf_method_create(void) { BIO_METHOD *m = BIO_meth_new(BIO_TYPE_MEM, "OpenSSL CF BIO"); @@ -804,9 +664,6 @@ static void ossl_bio_cf_method_free(BIO_METHOD *m) BIO_meth_free(m); } -#endif - - #ifdef HAVE_KEYLOG_CALLBACK static void ossl_keylog_callback(const SSL *ssl, const char *line) { @@ -819,8 +676,7 @@ static void ossl_keylog_callback(const SSL *ssl, const char *line) * ossl_log_tls12_secret is called by libcurl to make the CLIENT_RANDOMs if the * OpenSSL being used does not have native support for doing that. */ -static void -ossl_log_tls12_secret(const SSL *ssl, bool *keylog_done) +static void ossl_log_tls12_secret(const SSL *ssl, bool *keylog_done) { const SSL_SESSION *session; unsigned char client_random[SSL3_RANDOM_SIZE]; @@ -836,19 +692,9 @@ ossl_log_tls12_secret(const SSL *ssl, bool *keylog_done) return; } -#if OPENSSL_VERSION_NUMBER >= 0x10100000L - /* ssl->s3 is not checked in OpenSSL 1.1.0-pre6, but let's assume that - * we have a valid SSL context if we have a non-NULL session. */ SSL_get_client_random(ssl, client_random, SSL3_RANDOM_SIZE); master_key_length = (int) SSL_SESSION_get_master_key(session, master_key, SSL_MAX_MASTER_KEY_LENGTH); -#else - if(ssl->s3 && session->master_key_length > 0) { - master_key_length = session->master_key_length; - memcpy(master_key, session->master_key, session->master_key_length); - memcpy(client_random, ssl->s3->client_random, SSL3_RANDOM_SIZE); - } -#endif ERR_pop_to_mark(); @@ -928,15 +774,13 @@ static char *ossl_strerror(unsigned long error, char *buf, size_t size) if(!*buf) { const char *msg = error ? "Unknown error" : "No error"; - if(strlen(msg) < size) - strcpy(buf, msg); + curlx_strcopy(buf, size, msg, strlen(msg)); } return buf; } -static int passwd_callback(char *buf, int num, int encrypting, - void *password) +static int passwd_callback(char *buf, int num, int encrypting, void *password) { DEBUGASSERT(encrypting == 0); @@ -970,58 +814,8 @@ static CURLcode ossl_seed(struct Curl_easy *data) data->multi->ssl_seeded = TRUE; return CURLE_OK; } -#ifdef HAVE_RANDOM_INIT_BY_DEFAULT - /* with OpenSSL 1.1.0+, a failed RAND_status is a showstopper */ failf(data, "Insufficient randomness"); return CURLE_SSL_CONNECT_ERROR; -#else - - /* fallback to a custom seeding of the PRNG using a hash based on a current - time */ - do { - unsigned char randb[64]; - size_t len = sizeof(randb); - size_t i, i_max; - for(i = 0, i_max = len / sizeof(struct curltime); i < i_max; ++i) { - struct curltime tv = curlx_now(); - curlx_wait_ms(1); - tv.tv_sec *= (time_t)i + 1; - tv.tv_usec *= (int)i + 2; - tv.tv_sec ^= ((curlx_now().tv_sec + (time_t)curlx_now().tv_usec) * - (time_t)(i + 3)) << 8; - tv.tv_usec ^= (int) ((curlx_now().tv_sec + (time_t)curlx_now().tv_usec) * - (time_t)(i + 4)) << 16; - memcpy(&randb[i * sizeof(struct curltime)], &tv, - sizeof(struct curltime)); - } - RAND_add(randb, (int)len, (double)len/2); - } while(!rand_enough()); - - /* - * Number of bytes to read from the random number seed file. This must be - * a finite value (because some entropy "files" like /dev/urandom have - * an infinite length), but must be large enough to provide enough - * entropy to properly seed OpenSSL's PRNG. - */ -# define RAND_LOAD_LENGTH 1024 - - { - /* generates a default path for the random seed file */ - char fname[256]; - fname[0] = 0; /* blank it first */ - RAND_file_name(fname, sizeof(fname)); - if(fname[0]) { - /* we got a filename to try */ - RAND_load_file(fname, RAND_LOAD_LENGTH); - if(rand_enough()) - return CURLE_OK; - } - } - - infof(data, "libcurl is now using a weak random seed"); - return rand_enough() ? CURLE_OK : - CURLE_SSL_CONNECT_ERROR; /* confusing error code */ -#endif } #ifndef SSL_FILETYPE_ENGINE @@ -1126,8 +920,7 @@ static int use_certificate_blob(SSL_CTX *ctx, const struct curl_blob *blob, } else if(type == SSL_FILETYPE_PEM) { /* ERR_R_PEM_LIB; */ - x = PEM_read_bio_X509(in, NULL, - passwd_callback, CURL_UNCONST(key_passwd)); + x = PEM_read_bio_X509(in, NULL, passwd_callback, CURL_UNCONST(key_passwd)); } else { ret = 0; @@ -1173,9 +966,9 @@ static int use_privatekey_blob(SSL_CTX *ctx, const struct curl_blob *blob, return ret; } -static int -use_certificate_chain_blob(SSL_CTX *ctx, const struct curl_blob *blob, - const char *key_passwd) +static int use_certificate_chain_blob(SSL_CTX *ctx, + const struct curl_blob *blob, + const char *key_passwd) { int ret = 0; X509 *x = NULL; @@ -1205,8 +998,7 @@ use_certificate_chain_blob(SSL_CTX *ctx, const struct curl_blob *blob, } while((ca = PEM_read_bio_X509(in, NULL, passwd_callback, - CURL_UNCONST(key_passwd))) - != NULL) { + CURL_UNCONST(key_passwd))) != NULL) { if(!SSL_CTX_add0_chain_cert(ctx, ca)) { X509_free(ca); @@ -1248,8 +1040,7 @@ static int enginecheck(struct Curl_easy *data, } if(data->state.engine) { - UI_METHOD *ui_method = - UI_create_method(OSSL_UI_METHOD_CAST("curl user interface")); + UI_METHOD *ui_method = UI_create_method("curl user interface"); if(!ui_method) { failf(data, "unable to create " OSSL_PACKAGE " user-interface method"); return 0; @@ -1310,8 +1101,7 @@ static int providercheck(struct Curl_easy *data, EVP_PKEY *priv_key = NULL; OSSL_STORE_CTX *store = NULL; OSSL_STORE_INFO *info = NULL; - UI_METHOD *ui_method = - UI_create_method(OSSL_UI_METHOD_CAST("curl user interface")); + UI_METHOD *ui_method = UI_create_method("curl user interface"); if(!ui_method) { failf(data, "unable to create " OSSL_PACKAGE " user-interface method"); return 0; @@ -1415,16 +1205,15 @@ static int engineload(struct Curl_easy *data, /* Load the certificate from the engine */ if(!ENGINE_ctrl_cmd(data->state.engine, cmd_name, 0, ¶ms, NULL, 1)) { - failf(data, "ssl engine cannot load client cert with id" - " '%s' [%s]", cert_file, + failf(data, "ssl engine cannot load client cert with id '%s' [%s]", + cert_file, ossl_strerror(ERR_get_error(), error_buffer, sizeof(error_buffer))); return 0; } if(!params.cert) { - failf(data, "ssl engine did not initialized the certificate " - "properly."); + failf(data, "ssl engine did not initialized the certificate properly."); return 0; } @@ -1432,6 +1221,7 @@ static int engineload(struct Curl_easy *data, failf(data, "unable to set client certificate [%s]", ossl_strerror(ERR_get_error(), error_buffer, sizeof(error_buffer))); + X509_free(params.cert); return 0; } X509_free(params.cert); /* we do not need the handle any more... */ @@ -1545,8 +1335,7 @@ static int pkcs12load(struct Curl_easy *data, if(cert_blob) { cert_bio = BIO_new_mem_buf(cert_blob->data, (int)(cert_blob->len)); if(!cert_bio) { - failf(data, - "BIO_new_mem_buf NULL, " OSSL_PACKAGE " error %s", + failf(data, "BIO_new_mem_buf NULL, " OSSL_PACKAGE " error %s", ossl_strerror(ERR_get_error(), error_buffer, sizeof(error_buffer)) ); return 0; @@ -1555,8 +1344,7 @@ static int pkcs12load(struct Curl_easy *data, else { cert_bio = BIO_new(BIO_s_file()); if(!cert_bio) { - failf(data, - "BIO_new return NULL, " OSSL_PACKAGE " error %s", + failf(data, "BIO_new return NULL, " OSSL_PACKAGE " error %s", ossl_strerror(ERR_get_error(), error_buffer, sizeof(error_buffer)) ); return 0; @@ -1579,11 +1367,9 @@ static int pkcs12load(struct Curl_easy *data, } if(!PKCS12_parse(p12, key_passwd, &pri, &x509, &ca)) { - failf(data, - "could not parse PKCS12 file, check password, " OSSL_PACKAGE + failf(data, "could not parse PKCS12 file, check password, " OSSL_PACKAGE " error %s", - ossl_strerror(ERR_get_error(), error_buffer, - sizeof(error_buffer)) ); + ossl_strerror(ERR_get_error(), error_buffer, sizeof(error_buffer))); PKCS12_free(p12); return 0; } @@ -1591,17 +1377,14 @@ static int pkcs12load(struct Curl_easy *data, PKCS12_free(p12); if(SSL_CTX_use_certificate(ctx, x509) != 1) { - failf(data, - "could not load PKCS12 client certificate, " OSSL_PACKAGE + failf(data, "could not load PKCS12 client certificate, " OSSL_PACKAGE " error %s", - ossl_strerror(ERR_get_error(), error_buffer, - sizeof(error_buffer)) ); + ossl_strerror(ERR_get_error(), error_buffer, sizeof(error_buffer))); goto fail; } if(SSL_CTX_use_PrivateKey(ctx, pri) != 1) { - failf(data, "unable to use private key from PKCS12 file '%s'", - cert_file); + failf(data, "unable to use private key from PKCS12 file '%s'", cert_file); goto fail; } @@ -1651,7 +1434,6 @@ static int pkcs12load(struct Curl_easy *data, return 1; } - static CURLcode client_cert(struct Curl_easy *data, SSL_CTX* ctx, char *cert_file, @@ -1690,10 +1472,10 @@ static CURLcode client_cert(struct Curl_easy *data, failf(data, "could not load PEM client certificate from %s, " OSSL_PACKAGE " error %s, " - "(no key found, wrong pass phrase, or wrong file format?)", + "(no key found, wrong passphrase, or wrong file format?)", (cert_blob ? "CURLOPT_SSLCERT_BLOB" : cert_file), ossl_strerror(ERR_get_error(), error_buffer, - sizeof(error_buffer)) ); + sizeof(error_buffer))); return CURLE_SSL_CERTPROBLEM; } break; @@ -1710,10 +1492,10 @@ static CURLcode client_cert(struct Curl_easy *data, failf(data, "could not load ASN1 client certificate from %s, " OSSL_PACKAGE " error %s, " - "(no key found, wrong pass phrase, or wrong file format?)", + "(no key found, wrong passphrase, or wrong file format?)", (cert_blob ? "CURLOPT_SSLCERT_BLOB" : cert_file), ossl_strerror(ERR_get_error(), error_buffer, - sizeof(error_buffer)) ); + sizeof(error_buffer))); return CURLE_SSL_CERTPROBLEM; } break; @@ -1799,13 +1581,7 @@ static CURLcode client_cert(struct Curl_easy *data, /* If RSA is used, do not check the private key if its flags indicate * it does not support it. */ EVP_PKEY *priv_key = SSL_get_privatekey(ssl); - int pktype; -#ifdef HAVE_OPAQUE_EVP_PKEY - pktype = EVP_PKEY_id(priv_key); -#else - pktype = priv_key->type; -#endif - if(pktype == EVP_PKEY_RSA) { + if(EVP_PKEY_id(priv_key) == EVP_PKEY_RSA) { RSA *rsa = EVP_PKEY_get1_RSA(priv_key); if(RSA_flags(rsa) & RSA_METHOD_FLAG_NO_CHECK) check_privkey = FALSE; @@ -1848,8 +1624,8 @@ static CURLcode x509_name_oneline(X509_NAME *a, struct dynbuf *d) if(rc != -1) { BIO_get_mem_ptr(bio_out, &biomem); result = curlx_dyn_addn(d, biomem->data, biomem->length); - BIO_free(bio_out); } + BIO_free(bio_out); } return result; } @@ -1863,7 +1639,6 @@ static CURLcode x509_name_oneline(X509_NAME *a, struct dynbuf *d) */ static int ossl_init(void) { -#if OPENSSL_VERSION_NUMBER >= 0x10100000L const uint64_t flags = #ifdef OPENSSL_INIT_ENGINE_ALL_BUILTIN /* not present in BoringSSL */ @@ -1876,28 +1651,6 @@ static int ossl_init(void) #endif 0; OPENSSL_init_ssl(flags, NULL); -#else - OPENSSL_load_builtin_modules(); - -#ifdef USE_OPENSSL_ENGINE - ENGINE_load_builtin_engines(); -#endif - -#ifndef CURL_DISABLE_OPENSSL_AUTO_LOAD_CONFIG - CONF_modules_load_file(NULL, NULL, - CONF_MFLAGS_DEFAULT_SECTION| - CONF_MFLAGS_IGNORE_MISSING_FILE); -#endif - - /* Let's get nice error messages */ - SSL_load_error_strings(); - - /* Init the global ciphers and digests */ - if(!SSLeay_add_ssl_algorithms()) - return 0; - - OpenSSL_add_all_algorithms(); -#endif Curl_tls_keylog_open(); @@ -1907,32 +1660,6 @@ static int ossl_init(void) /* Global cleanup */ static void ossl_cleanup(void) { -#if OPENSSL_VERSION_NUMBER >= 0x10100000L - /* OpenSSL 1.1 deprecates all these cleanup functions and - turns them into no-ops in OpenSSL 1.0 compatibility mode */ -#else - /* Free ciphers and digests lists */ - EVP_cleanup(); - -#ifdef USE_OPENSSL_ENGINE - /* Free engine list */ - ENGINE_cleanup(); -#endif - - /* Free OpenSSL error strings */ - ERR_free_strings(); - - /* Free thread local error state, destroying hash upon zero refcount */ - ERR_remove_thread_state(NULL); - - /* Free all memory allocated by all configuration modules */ - CONF_modules_free(); - -#ifdef HAVE_SSL_COMP_FREE_COMPRESSION_METHODS - SSL_COMP_free_compression_methods(); -#endif -#endif - Curl_tls_keylog_close(); } @@ -2075,7 +1802,7 @@ static CURLcode ossl_set_provider(struct Curl_easy *data, const char *iname) if(!libctx) return CURLE_OUT_OF_MEMORY; if(propq) { - data->state.propq = strdup(propq); + data->state.propq = curlx_strdup(propq); if(!data->state.propq) { OSSL_LIB_CTX_free(libctx); return CURLE_OUT_OF_MEMORY; @@ -2098,20 +1825,17 @@ static CURLcode ossl_set_provider(struct Curl_easy *data, const char *iname) return CURLE_OK; } - data->state.provider = - OSSL_PROVIDER_try_load(data->state.libctx, name, 1); + data->state.provider = OSSL_PROVIDER_try_load(data->state.libctx, name, 1); if(!data->state.provider) { char error_buffer[256]; failf(data, "Failed to initialize provider: %s", - ossl_strerror(ERR_get_error(), error_buffer, - sizeof(error_buffer))); + ossl_strerror(ERR_get_error(), error_buffer, sizeof(error_buffer))); ossl_provider_cleanup(data); return CURLE_SSL_ENGINE_NOTFOUND; } /* load the base provider as well */ - data->state.baseprov = - OSSL_PROVIDER_try_load(data->state.libctx, "base", 1); + data->state.baseprov = OSSL_PROVIDER_try_load(data->state.libctx, "base", 1); if(!data->state.baseprov) { ossl_provider_cleanup(data); failf(data, "Failed to load base"); @@ -2123,7 +1847,6 @@ static CURLcode ossl_set_provider(struct Curl_easy *data, const char *iname) } #endif - static CURLcode ossl_shutdown(struct Curl_cfilter *cf, struct Curl_easy *data, bool send_shutdown, bool *done) @@ -2286,13 +2009,6 @@ static void ossl_close_all(struct Curl_easy *data) #ifdef OPENSSL_HAS_PROVIDERS ossl_provider_cleanup(data); #endif -#ifndef HAVE_ERR_REMOVE_THREAD_STATE_DEPRECATED - /* OpenSSL 1.0.1 and 1.0.2 build an error queue that is stored per-thread - so we need to clean it here in case the thread will be killed. All OpenSSL - code should extract the error in association with the error so clearing - this queue here should be harmless at worst. */ - ERR_remove_thread_state(NULL); -#endif } /* ====================================================== */ @@ -2393,11 +2109,11 @@ static CURLcode ossl_verifyhost(struct Curl_easy *data, if(check->type == target) { /* get data and length */ const char *altptr = (const char *)ASN1_STRING_get0_data(check->d.ia5); - size_t altlen = (size_t) ASN1_STRING_length(check->d.ia5); + size_t altlen = (size_t)ASN1_STRING_length(check->d.ia5); switch(target) { case GEN_DNS: /* name/pattern comparison */ - /* The OpenSSL manpage explicitly says: "In general it cannot be + /* The OpenSSL man page explicitly says: "In general it cannot be assumed that the data returned by ASN1_STRING_data() is null terminated or does not contain embedded nulls." But also that "The actual format of the data will depend on the actual string @@ -2421,8 +2137,7 @@ static CURLcode ossl_verifyhost(struct Curl_easy *data, our server IP address is */ if((altlen == addrlen) && !memcmp(altptr, &addr, altlen)) { matched = TRUE; - infof(data, - " subjectAltName: \"%s\" matches cert's IP address!", + infof(data, " subjectAltName: \"%s\" matches cert's IP address!", peer->dispname); } break; @@ -2497,8 +2212,7 @@ static CURLcode ossl_verifyhost(struct Curl_easy *data, /* error already detected, pass through */ ; else if(!cn) { - failf(data, - "SSL: unable to obtain common name from peer certificate"); + failf(data, "SSL: unable to obtain common name from peer certificate"); result = CURLE_PEER_FAILED_VERIFICATION; } else if(!Curl_cert_hostcheck((const char *)cn, cnlen, @@ -2517,7 +2231,7 @@ static CURLcode ossl_verifyhost(struct Curl_easy *data, return result; } -#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_OCSP) +#ifndef OPENSSL_NO_OCSP static CURLcode verifystatus(struct Curl_cfilter *cf, struct Curl_easy *data, struct ossl_ctx *octx) @@ -2779,7 +2493,7 @@ static void ossl_trace(int direction, int ssl_ver, int content_type, const void *buf, size_t len, SSL *ssl, void *userp) { - const char *verstr = "???"; + const char *verstr; struct Curl_cfilter *cf = userp; struct Curl_easy *data = NULL; char unknown[32]; @@ -2814,13 +2528,9 @@ static void ossl_trace(int direction, int ssl_ver, int content_type, verstr = "TLSv1.2"; break; #endif -#ifdef TLS1_3_VERSION /* OpenSSL 1.1.1+, all forks */ case TLS1_3_VERSION: verstr = "TLSv1.3"; break; -#endif - case 0: - break; default: curl_msnprintf(unknown, sizeof(unknown), "(%x)", ssl_ver); verstr = unknown; @@ -2881,12 +2591,6 @@ static void ossl_trace(int direction, int ssl_ver, int content_type, (void)ssl; } -/* Check for ALPN support. */ -#ifndef OPENSSL_NO_TLSEXT -# define HAS_ALPN_OPENSSL -#endif - -#if OPENSSL_VERSION_NUMBER >= 0x10100000L /* 1.1.0 */ static CURLcode ossl_set_ssl_version_min_max(struct Curl_cfilter *cf, SSL_CTX *ctx, unsigned int ssl_version_min) @@ -2904,6 +2608,8 @@ ossl_set_ssl_version_min_max(struct Curl_cfilter *cf, SSL_CTX *ctx, long ossl_ssl_version_min = 0; long ossl_ssl_version_max = 0; #endif + /* it cannot be default here */ + DEBUGASSERT(curl_ssl_version_min != CURL_SSLVERSION_DEFAULT); switch(curl_ssl_version_min) { case CURL_SSLVERSION_TLSv1: /* TLS 1.x */ case CURL_SSLVERSION_TLSv1_0: @@ -2916,24 +2622,8 @@ ossl_set_ssl_version_min_max(struct Curl_cfilter *cf, SSL_CTX *ctx, ossl_ssl_version_min = TLS1_2_VERSION; break; case CURL_SSLVERSION_TLSv1_3: -#ifdef TLS1_3_VERSION ossl_ssl_version_min = TLS1_3_VERSION; break; -#else - return CURLE_NOT_BUILT_IN; -#endif - } - - /* CURL_SSLVERSION_DEFAULT means that no option was selected. - We do not want to pass 0 to SSL_CTX_set_min_proto_version as - it would enable all versions down to the lowest supported by - the library. - So we skip this, and stay with the library default - */ - if(curl_ssl_version_min != CURL_SSLVERSION_DEFAULT) { - if(!SSL_CTX_set_min_proto_version(ctx, ossl_ssl_version_min)) { - return CURLE_SSL_CONNECT_ERROR; - } } /* ... then, TLS max version */ @@ -2950,11 +2640,9 @@ ossl_set_ssl_version_min_max(struct Curl_cfilter *cf, SSL_CTX *ctx, case CURL_SSLVERSION_MAX_TLSv1_2: ossl_ssl_version_max = TLS1_2_VERSION; break; -#ifdef TLS1_3_VERSION case CURL_SSLVERSION_MAX_TLSv1_3: ossl_ssl_version_max = TLS1_3_VERSION; break; -#endif case CURL_SSLVERSION_MAX_NONE: /* none selected */ case CURL_SSLVERSION_MAX_DEFAULT: /* max selected */ default: @@ -2965,86 +2653,21 @@ ossl_set_ssl_version_min_max(struct Curl_cfilter *cf, SSL_CTX *ctx, break; } - if(!SSL_CTX_set_max_proto_version(ctx, ossl_ssl_version_max)) { + if(!SSL_CTX_set_min_proto_version(ctx, ossl_ssl_version_min) || + !SSL_CTX_set_max_proto_version(ctx, ossl_ssl_version_max)) return CURLE_SSL_CONNECT_ERROR; - } return CURLE_OK; } -#endif #ifdef HAVE_BORINGSSL_LIKE typedef uint32_t ctx_option_t; #elif defined(HAVE_OPENSSL3) typedef uint64_t ctx_option_t; -#elif OPENSSL_VERSION_NUMBER >= 0x10100000L && \ - !defined(LIBRESSL_VERSION_NUMBER) -typedef unsigned long ctx_option_t; -#else +#elif defined(LIBRESSL_VERSION_NUMBER) typedef long ctx_option_t; -#endif - -#if OPENSSL_VERSION_NUMBER < 0x10100000L /* 1.1.0 */ -static CURLcode -ossl_set_ssl_version_min_max_legacy(ctx_option_t *ctx_options, - struct Curl_cfilter *cf, - struct Curl_easy *data) -{ - struct ssl_primary_config *conn_config = Curl_ssl_cf_get_primary_config(cf); - long ssl_version = conn_config->version; - long ssl_version_max = conn_config->version_max; - - (void)data; /* In case it is unused. */ - - switch(ssl_version) { - case CURL_SSLVERSION_TLSv1_3: -#ifdef TLS1_3_VERSION - { - struct ssl_connect_data *connssl = cf->ctx; - struct ossl_ctx *octx = (struct ossl_ctx *)connssl->backend; - DEBUGASSERT(octx); - SSL_CTX_set_max_proto_version(octx->ssl_ctx, TLS1_3_VERSION); - *ctx_options |= SSL_OP_NO_TLSv1_2; - } #else - (void)ctx_options; - failf(data, OSSL_PACKAGE " was built without TLS 1.3 support"); - return CURLE_NOT_BUILT_IN; -#endif - FALLTHROUGH(); - case CURL_SSLVERSION_TLSv1_2: - *ctx_options |= SSL_OP_NO_TLSv1_1; - FALLTHROUGH(); - case CURL_SSLVERSION_TLSv1_1: - *ctx_options |= SSL_OP_NO_TLSv1; - FALLTHROUGH(); - case CURL_SSLVERSION_TLSv1_0: - case CURL_SSLVERSION_TLSv1: - break; - } - - switch(ssl_version_max) { - case CURL_SSLVERSION_MAX_TLSv1_0: - *ctx_options |= SSL_OP_NO_TLSv1_1; - FALLTHROUGH(); - case CURL_SSLVERSION_MAX_TLSv1_1: - *ctx_options |= SSL_OP_NO_TLSv1_2; - FALLTHROUGH(); - case CURL_SSLVERSION_MAX_TLSv1_2: -#ifdef TLS1_3_VERSION - *ctx_options |= SSL_OP_NO_TLSv1_3; -#endif - break; - case CURL_SSLVERSION_MAX_TLSv1_3: -#ifdef TLS1_3_VERSION - break; -#else - failf(data, OSSL_PACKAGE " was built without TLS 1.3 support"); - return CURLE_NOT_BUILT_IN; -#endif - } - return CURLE_OK; -} +typedef unsigned long ctx_option_t; #endif CURLcode Curl_ossl_add_session(struct Curl_cfilter *cf, @@ -3075,7 +2698,7 @@ CURLcode Curl_ossl_add_session(struct Curl_cfilter *cf, goto out; } - der_session_buf = der_session_ptr = malloc(der_session_size); + der_session_buf = der_session_ptr = curlx_malloc(der_session_size); if(!der_session_buf) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -3112,7 +2735,7 @@ CURLcode Curl_ossl_add_session(struct Curl_cfilter *cf, } out: - free(der_session_buf); + curlx_free(der_session_buf); return result; } @@ -3121,7 +2744,7 @@ CURLcode Curl_ossl_add_session(struct Curl_cfilter *cf, */ static int ossl_new_session_cb(SSL *ssl, SSL_SESSION *ssl_sessionid) { - struct Curl_cfilter *cf = (struct Curl_cfilter*) SSL_get_app_data(ssl); + struct Curl_cfilter *cf = (struct Curl_cfilter *)SSL_get_app_data(ssl); if(cf) { struct Curl_easy *data = CF_DATA_CURRENT(cf); struct ssl_connect_data *connssl = cf->ctx; @@ -3269,7 +2892,7 @@ static CURLcode ossl_win_load_store(struct Curl_easy *data, */ if(CertGetEnhancedKeyUsage(pContext, 0, NULL, &req_size)) { if(req_size && req_size > enhkey_usage_size) { - void *tmp = realloc(enhkey_usage, req_size); + void *tmp = curlx_realloc(enhkey_usage, req_size); if(!tmp) { failf(data, "SSL: Out of memory allocating for OID list"); @@ -3327,7 +2950,7 @@ static CURLcode ossl_win_load_store(struct Curl_easy *data, X509_free(x509); } - free(enhkey_usage); + curlx_free(enhkey_usage); CertFreeCertificateContext(pContext); CertCloseStore(hStore, 0); @@ -3522,7 +3145,7 @@ static CURLcode ossl_populate_x509_store(struct Curl_cfilter *cf, failf(data, "error loading CRL file: %s", ssl_crlfile); return CURLE_SSL_CRL_BADFILE; } - x509flags = X509_V_FLAG_CRL_CHECK|X509_V_FLAG_CRL_CHECK_ALL; + x509flags = X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL; infof(data, " CRLfile: %s", ssl_crlfile); } @@ -3550,61 +3173,61 @@ static CURLcode ossl_populate_x509_store(struct Curl_cfilter *cf, return result; } -#ifdef HAVE_SSL_X509_STORE_SHARE - /* key to use at `multi->proto_hash` */ -#define MPROTO_OSSL_X509_KEY "tls:ossl:x509:share" +#define MPROTO_OSSL_X509_KEY "tls:ossl:x509:share" struct ossl_x509_share { char *CAfile; /* CAfile path used to generate X509 store */ X509_STORE *store; /* cached X509 store or NULL if none */ struct curltime time; /* when the cached store was created */ BIT(store_is_empty); /* no certs/paths/blobs are in the store */ + BIT(no_partialchain); /* keep partial chain state */ }; static void oss_x509_share_free(void *key, size_t key_len, void *p) { struct ossl_x509_share *share = p; - DEBUGASSERT(key_len == (sizeof(MPROTO_OSSL_X509_KEY)-1)); + DEBUGASSERT(key_len == (sizeof(MPROTO_OSSL_X509_KEY) - 1)); DEBUGASSERT(!memcmp(MPROTO_OSSL_X509_KEY, key, key_len)); (void)key; (void)key_len; if(share->store) { X509_STORE_free(share->store); } - free(share->CAfile); - free(share); + curlx_free(share->CAfile); + curlx_free(share); } -static bool -ossl_cached_x509_store_expired(const struct Curl_easy *data, - const struct ossl_x509_share *mb) +static bool ossl_cached_x509_store_expired(struct Curl_easy *data, + const struct ossl_x509_share *mb) { const struct ssl_general_config *cfg = &data->set.general_ssl; if(cfg->ca_cache_timeout < 0) return FALSE; else { - struct curltime now = curlx_now(); - timediff_t elapsed_ms = curlx_timediff(now, mb->time); + timediff_t elapsed_ms = curlx_ptimediff_ms(Curl_pgrs_now(data), &mb->time); timediff_t timeout_ms = cfg->ca_cache_timeout * (timediff_t)1000; return elapsed_ms >= timeout_ms; } } -static bool -ossl_cached_x509_store_different(struct Curl_cfilter *cf, - const struct ossl_x509_share *mb) +static bool ossl_cached_x509_store_different(struct Curl_cfilter *cf, + const struct Curl_easy *data, + const struct ossl_x509_share *mb) { struct ssl_primary_config *conn_config = Curl_ssl_cf_get_primary_config(cf); + struct ssl_config_data *ssl_config = + Curl_ssl_cf_get_config(cf, CURL_UNCONST(data)); + if(mb->no_partialchain != ssl_config->no_partialchain) + return TRUE; if(!mb->CAfile || !conn_config->CAfile) return mb->CAfile != conn_config->CAfile; - return strcmp(mb->CAfile, conn_config->CAfile); } static X509_STORE *ossl_get_cached_x509_store(struct Curl_cfilter *cf, - const struct Curl_easy *data, + struct Curl_easy *data, bool *pempty) { struct Curl_multi *multi = data->multi; @@ -3615,10 +3238,10 @@ static X509_STORE *ossl_get_cached_x509_store(struct Curl_cfilter *cf, *pempty = TRUE; share = multi ? Curl_hash_pick(&multi->proto_hash, CURL_UNCONST(MPROTO_OSSL_X509_KEY), - sizeof(MPROTO_OSSL_X509_KEY)-1) : NULL; + sizeof(MPROTO_OSSL_X509_KEY) - 1) : NULL; if(share && share->store && !ossl_cached_x509_store_expired(data, share) && - !ossl_cached_x509_store_different(cf, share)) { + !ossl_cached_x509_store_different(cf, data, share)) { store = share->store; *pempty = share->store_is_empty; } @@ -3627,7 +3250,7 @@ static X509_STORE *ossl_get_cached_x509_store(struct Curl_cfilter *cf, } static void ossl_set_cached_x509_store(struct Curl_cfilter *cf, - const struct Curl_easy *data, + struct Curl_easy *data, X509_STORE *store, bool is_empty) { @@ -3640,26 +3263,28 @@ static void ossl_set_cached_x509_store(struct Curl_cfilter *cf, return; share = Curl_hash_pick(&multi->proto_hash, CURL_UNCONST(MPROTO_OSSL_X509_KEY), - sizeof(MPROTO_OSSL_X509_KEY)-1); + sizeof(MPROTO_OSSL_X509_KEY) - 1); if(!share) { - share = calloc(1, sizeof(*share)); + share = curlx_calloc(1, sizeof(*share)); if(!share) return; if(!Curl_hash_add2(&multi->proto_hash, CURL_UNCONST(MPROTO_OSSL_X509_KEY), - sizeof(MPROTO_OSSL_X509_KEY)-1, + sizeof(MPROTO_OSSL_X509_KEY) - 1, share, oss_x509_share_free)) { - free(share); + curlx_free(share); return; } } if(X509_STORE_up_ref(store)) { char *CAfile = NULL; + struct ssl_config_data *ssl_config = + Curl_ssl_cf_get_config(cf, CURL_UNCONST(data)); if(conn_config->CAfile) { - CAfile = strdup(conn_config->CAfile); + CAfile = curlx_strdup(conn_config->CAfile); if(!CAfile) { X509_STORE_free(store); return; @@ -3668,13 +3293,14 @@ static void ossl_set_cached_x509_store(struct Curl_cfilter *cf, if(share->store) { X509_STORE_free(share->store); - free(share->CAfile); + curlx_free(share->CAfile); } - share->time = curlx_now(); + share->time = *Curl_pgrs_now(data); share->store = store; share->store_is_empty = is_empty; share->CAfile = CAfile; + share->no_partialchain = ssl_config->no_partialchain; } } @@ -3718,25 +3344,6 @@ CURLcode Curl_ssl_setup_x509_store(struct Curl_cfilter *cf, return result; } -#else /* HAVE_SSL_X509_STORE_SHARE */ -CURLcode Curl_ssl_setup_x509_store(struct Curl_cfilter *cf, - struct Curl_easy *data, - struct ossl_ctx *octx) -{ - CURLcode result; - X509_STORE *store; - - ERR_set_mark(); - - store = SSL_CTX_get_cert_store(octx->ssl_ctx); - result = ossl_populate_x509_store(cf, data, octx, store); - - ERR_pop_to_mark(); - - return result; -} -#endif /* HAVE_SSL_X509_STORE_SHARE */ - static CURLcode ossl_init_session_and_alpns(struct ossl_ctx *octx, @@ -3787,8 +3394,10 @@ ossl_init_session_and_alpns(struct ossl_ctx *octx, bool do_early_data = FALSE; if(sess_reuse_cb) { result = sess_reuse_cb(cf, data, &alpns, scs, &do_early_data); - if(result) + if(result) { + SSL_SESSION_free(ssl_session); return result; + } } if(do_early_data) { /* We only try the ALPN protocol the session used before, @@ -3810,7 +3419,6 @@ ossl_init_session_and_alpns(struct ossl_ctx *octx, Curl_ssl_scache_return(cf, data, peer->scache_key, scs); } -#ifdef HAS_ALPN_OPENSSL if(alpns.count) { struct alpn_proto_buf proto; memset(&proto, 0, sizeof(proto)); @@ -3824,12 +3432,11 @@ ossl_init_session_and_alpns(struct ossl_ctx *octx, return CURLE_SSL_CONNECT_ERROR; } } -#endif return CURLE_OK; } -#ifdef USE_ECH_OPENSSL +#ifdef HAVE_SSL_SET1_ECH_CONFIG_LIST static CURLcode ossl_init_ech(struct ossl_ctx *octx, struct Curl_cfilter *cf, struct Curl_easy *data, @@ -3868,25 +3475,23 @@ static CURLcode ossl_init_ech(struct ossl_ctx *octx, if(data->set.tls_ech & CURLECH_HARD) return result; } - if(SSL_set1_ech_config_list(octx->ssl, ech_config, - ech_config_len) != 1) { + if(SSL_set1_ech_config_list(octx->ssl, ech_config, ech_config_len) != 1) { infof(data, "ECH: SSL_ECH_set1_ech_config_list failed"); if(data->set.tls_ech & CURLECH_HARD) { - free(ech_config); + curlx_free(ech_config); return CURLE_SSL_CONNECT_ERROR; } } - free(ech_config); + curlx_free(ech_config); trying_ech_now = 1; # else - ech_config = (unsigned char *) data->set.str[STRING_ECH_CONFIG]; + ech_config = (unsigned char *)data->set.str[STRING_ECH_CONFIG]; if(!ech_config) { infof(data, "ECH: ECHConfig from command line empty"); return CURLE_SSL_CONNECT_ERROR; } ech_config_len = strlen(data->set.str[STRING_ECH_CONFIG]); - if(SSL_set1_ech_config_list(octx->ssl, ech_config, - ech_config_len) != 1) { + if(SSL_set1_ech_config_list(octx->ssl, ech_config, ech_config_len) != 1) { infof(data, "ECH: SSL_ECH_set1_ech_config_list failed"); if(data->set.tls_ech & CURLECH_HARD) return CURLE_SSL_CONNECT_ERROR; @@ -3944,24 +3549,23 @@ static CURLcode ossl_init_ech(struct ossl_ctx *octx, infof(data, "ECH: inner: '%s', outer: '%s'", peer->hostname ? peer->hostname : "NULL", outername); result = SSL_ech_set1_server_names(octx->ssl, - peer->hostname, outername, - 0 /* do send outer */); + peer->hostname, outername, + 0 /* do send outer */); if(result != 1) { infof(data, "ECH: rv failed to set server name(s) %d [ERROR]", result); return CURLE_SSL_CONNECT_ERROR; } } # endif /* HAVE_BORINGSSL_LIKE */ - if(trying_ech_now - && SSL_set_min_proto_version(octx->ssl, TLS1_3_VERSION) != 1) { + if(trying_ech_now && + SSL_set_min_proto_version(octx->ssl, TLS1_3_VERSION) != 1) { infof(data, "ECH: cannot force TLSv1.3 [ERROR]"); return CURLE_SSL_CONNECT_ERROR; } return CURLE_OK; } -#endif /* USE_ECH_OPENSSL */ - +#endif /* HAVE_SSL_SET1_ECH_CONFIG_LIST */ static CURLcode ossl_init_ssl(struct ossl_ctx *octx, struct Curl_cfilter *cf, @@ -3982,7 +3586,7 @@ static CURLcode ossl_init_ssl(struct ossl_ctx *octx, SSL_set_app_data(octx->ssl, ssl_user_data); -#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_OCSP) +#ifndef OPENSSL_NO_OCSP if(Curl_ssl_cf_get_primary_config(cf)->verifystatus) SSL_set_tlsext_status_type(octx->ssl, TLSEXT_STATUSTYPE_ocsp); #endif @@ -3996,19 +3600,18 @@ static CURLcode ossl_init_ssl(struct ossl_ctx *octx, } } -#ifdef USE_ECH_OPENSSL +#ifdef HAVE_SSL_SET1_ECH_CONFIG_LIST { CURLcode result = ossl_init_ech(octx, cf, data, peer); if(result) return result; } -#endif /* USE_ECH_OPENSSL */ +#endif /* HAVE_SSL_SET1_ECH_CONFIG_LIST */ return ossl_init_session_and_alpns(octx, cf, data, peer, alpns_requested, sess_reuse_cb); } - static CURLcode ossl_init_method(struct Curl_cfilter *cf, struct Curl_easy *data, struct ssl_peer *peer, @@ -4030,11 +3633,7 @@ static CURLcode ossl_init_method(struct Curl_cfilter *cf, case CURL_SSLVERSION_TLSv1_2: case CURL_SSLVERSION_TLSv1_3: /* it will be handled later with the context options */ -#if OPENSSL_VERSION_NUMBER >= 0x10100000L *pmethod = TLS_client_method(); -#else - *pmethod = SSLv23_client_method(); -#endif break; case CURL_SSLVERSION_SSLv2: failf(data, "No SSLv2 support"); @@ -4058,10 +3657,8 @@ static CURLcode ossl_init_method(struct Curl_cfilter *cf, #ifdef USE_OPENSSL_QUIC *pmethod = OSSL_QUIC_client_method(); -#elif (OPENSSL_VERSION_NUMBER >= 0x10100000L) - *pmethod = TLS_method(); #else - *pmethod = SSLv23_client_method(); + *pmethod = TLS_method(); #endif break; default: @@ -4072,7 +3669,6 @@ static CURLcode ossl_init_method(struct Curl_cfilter *cf, return *pmethod ? CURLE_OK : CURLE_SSL_CONNECT_ERROR; } - CURLcode Curl_ossl_ctx_init(struct ossl_ctx *octx, struct Curl_cfilter *cf, struct Curl_easy *data, @@ -4136,7 +3732,7 @@ CURLcode Curl_ossl_ctx_init(struct ossl_ctx *octx, /* OpenSSL contains code to work around lots of bugs and flaws in various SSL-implementations. SSL_CTX_set_options() is used to enabled those - work-arounds. The manpage for this option states that SSL_OP_ALL enables + work-arounds. The man page for this option states that SSL_OP_ALL enables all the work-arounds and that "It is usually safe to use SSL_OP_ALL to enable the bug workaround options if compatibility with somewhat broken implementations is desired." @@ -4187,7 +3783,7 @@ CURLcode Curl_ossl_ctx_init(struct ossl_ctx *octx, /* "--tlsv" options mean TLS >= version */ case CURL_SSLVERSION_DEFAULT: - case CURL_SSLVERSION_TLSv1: /* TLS >= version 1.0 */ + case CURL_SSLVERSION_TLSv1: /* TLS >= version 1.0 */ case CURL_SSLVERSION_TLSv1_0: /* TLS >= version 1.0 */ case CURL_SSLVERSION_TLSv1_1: /* TLS >= version 1.1 */ case CURL_SSLVERSION_TLSv1_2: /* TLS >= version 1.2 */ @@ -4197,11 +3793,7 @@ CURLcode Curl_ossl_ctx_init(struct ossl_ctx *octx, ctx_options |= SSL_OP_NO_SSLv2; ctx_options |= SSL_OP_NO_SSLv3; -#if OPENSSL_VERSION_NUMBER >= 0x10100000L /* 1.1.0 */ result = ossl_set_ssl_version_min_max(cf, octx->ssl_ctx, ssl_version_min); -#else - result = ossl_set_ssl_version_min_max_legacy(&ctx_options, cf, data); -#endif if(result) return result; break; @@ -4218,7 +3810,7 @@ CURLcode Curl_ossl_ctx_init(struct ossl_ctx *octx, OpenSSL supports processing "jumbo TLS record" (8 TLS records) in one go for some algorithms, so match that here. Experimentation shows that a slightly larger buffer is needed - to avoid short reads. + to avoid short reads. However using a large buffer (8 packets) actually decreases performance. 4 packets is better. @@ -4232,7 +3824,7 @@ CURLcode Curl_ossl_ctx_init(struct ossl_ctx *octx, ciphers = conn_config->cipher_list; if(!ciphers && (peer->transport != TRNSPRT_QUIC)) - ciphers = DEFAULT_CIPHER_SELECTION; + ciphers = NULL; if(ciphers && (ssl_version_min < CURL_SSLVERSION_TLSv1_3)) { if(!SSL_CTX_set_cipher_list(octx->ssl_ctx, ciphers)) { failf(data, "failed setting cipher list: %s", ciphers); @@ -4406,8 +3998,7 @@ static CURLcode ossl_on_session_reuse(struct Curl_cfilter *cf, return result; } -void Curl_ossl_report_handshake(struct Curl_easy *data, - struct ossl_ctx *octx) +void Curl_ossl_report_handshake(struct Curl_easy *data, struct ossl_ctx *octx) { #ifndef CURL_DISABLE_VERBOSE_STRINGS if(Curl_trc_is_verbose(data)) { @@ -4435,7 +4026,6 @@ void Curl_ossl_report_handshake(struct Curl_easy *data, (void)data; (void)octx; #endif /* CURL_DISABLE_VERBOSE_STRINGS */ - } static CURLcode ossl_connect_step1(struct Curl_cfilter *cf, @@ -4477,21 +4067,20 @@ static CURLcode ossl_connect_step1(struct Curl_cfilter *cf, SSL_set_bio(octx->ssl, bio, bio); #endif -#ifdef HAS_ALPN_OPENSSL if(connssl->alpn && (connssl->state != ssl_connection_deferred)) { struct alpn_proto_buf proto; memset(&proto, 0, sizeof(proto)); Curl_alpn_to_proto_str(&proto, connssl->alpn); infof(data, VTLS_INFOF_ALPN_OFFER_1STR, proto.data); } -#endif + connssl->connecting_state = ssl_connect_2; return CURLE_OK; } -#ifdef USE_ECH_OPENSSL +#ifdef HAVE_SSL_SET1_ECH_CONFIG_LIST /* If we have retry configs, then trace those out */ -static void ossl_trace_ech_retry_configs(struct Curl_easy *data, SSL* ssl, +static void ossl_trace_ech_retry_configs(struct Curl_easy *data, SSL *ssl, int reason) { CURLcode result = CURLE_OK; @@ -4499,7 +4088,7 @@ static void ossl_trace_ech_retry_configs(struct Curl_easy *data, SSL* ssl, int rv = 1; # ifndef HAVE_BORINGSSL_LIKE char *inner = NULL; - unsigned char *rcs = NULL; + uint8_t *rcs = NULL; char *outer = NULL; # else const char *inner = NULL; @@ -4523,10 +4112,10 @@ static void ossl_trace_ech_retry_configs(struct Curl_easy *data, SSL* ssl, char *b64str = NULL; size_t blen = 0; - result = curlx_base64_encode((const char *)rcs, rcl, &b64str, &blen); + result = curlx_base64_encode(rcs, rcl, &b64str, &blen); if(!result && b64str) { infof(data, "ECH: retry_configs %s", b64str); - free(b64str); + curlx_free(b64str); #ifndef HAVE_BORINGSSL_LIKE rv = SSL_ech_get1_status(ssl, &inner, &outer); infof(data, "ECH: retry_configs for %s from %s, %d %d", @@ -4617,7 +4206,7 @@ static CURLcode ossl_connect_step2(struct Curl_cfilter *cf, else { /* untreated error */ sslerr_t errdetail; - char error_buffer[256]=""; + char error_buffer[256] = ""; CURLcode result; long lerr; int lib; @@ -4660,7 +4249,7 @@ static CURLcode ossl_connect_step2(struct Curl_cfilter *cf, ossl_strerror(errdetail, error_buffer, sizeof(error_buffer))); } #endif -#ifdef USE_ECH_OPENSSL +#ifdef HAVE_SSL_SET1_ECH_CONFIG_LIST else if((lib == ERR_LIB_SSL) && # ifndef HAVE_BORINGSSL_LIKE (reason == SSL_R_ECH_REQUIRED)) { @@ -4689,7 +4278,7 @@ static CURLcode ossl_connect_step2(struct Curl_cfilter *cf, * the SO_ERROR is also lost. */ if(CURLE_SSL_CONNECT_ERROR == result && errdetail == 0) { - char extramsg[80]=""; + char extramsg[80] = ""; int sockerr = SOCKERRNO; if(sockerr && detail == SSL_ERROR_SYSCALL) @@ -4707,7 +4296,7 @@ static CURLcode ossl_connect_step2(struct Curl_cfilter *cf, connssl->connecting_state = ssl_connect_3; Curl_ossl_report_handshake(data, octx); -#if defined(USE_ECH_OPENSSL) && !defined(HAVE_BORINGSSL_LIKE) +#if defined(HAVE_SSL_SET1_ECH_CONFIG_LIST) && !defined(HAVE_BORINGSSL_LIKE) if(ECH_ENABLED(data)) { char *inner = NULL, *outer = NULL; const char *status = NULL; @@ -4744,7 +4333,7 @@ static CURLcode ossl_connect_step2(struct Curl_cfilter *cf, break; default: status = "unexpected status"; - infof(data, "ECH: unexpected status %d",rv); + infof(data, "ECH: unexpected status %d", rv); } infof(data, "ECH: result: status is %s, inner is %s, outer is %s", (status ? status : "NULL"), @@ -4765,9 +4354,8 @@ static CURLcode ossl_connect_step2(struct Curl_cfilter *cf, else { infof(data, "ECH: result: status is not attempted"); } -#endif /* USE_ECH_OPENSSL && !HAVE_BORINGSSL_LIKE */ +#endif /* HAVE_SSL_SET1_ECH_CONFIG_LIST && !HAVE_BORINGSSL_LIKE */ -#ifdef HAS_ALPN_OPENSSL /* Sets data and len to negotiated protocol, len is 0 if no protocol was * negotiated */ @@ -4778,7 +4366,6 @@ static CURLcode ossl_connect_step2(struct Curl_cfilter *cf, return Curl_alpn_set_negotiated(cf, data, connssl, neg_protocol, len); } -#endif return CURLE_OK; } @@ -4788,7 +4375,7 @@ static CURLcode ossl_connect_step2(struct Curl_cfilter *cf, * Heavily modified from: * https://www.owasp.org/index.php/Certificate_and_Public_Key_Pinning#OpenSSL */ -static CURLcode ossl_pkp_pin_peer_pubkey(struct Curl_easy *data, X509* cert, +static CURLcode ossl_pkp_pin_peer_pubkey(struct Curl_easy *data, X509 *cert, const char *pinnedpubkey) { /* Scratch */ @@ -4812,7 +4399,7 @@ static CURLcode ossl_pkp_pin_peer_pubkey(struct Curl_easy *data, X509* cert, if(len1 < 1) break; /* failed */ - buff1 = temp = malloc(len1); + buff1 = temp = curlx_malloc(len1); if(!buff1) break; /* failed */ @@ -4834,14 +4421,13 @@ static CURLcode ossl_pkp_pin_peer_pubkey(struct Curl_easy *data, X509* cert, } while(0); if(buff1) - free(buff1); + curlx_free(buff1); return result; } -#if OPENSSL_VERSION_NUMBER >= 0x10100000L && \ - !(defined(LIBRESSL_VERSION_NUMBER) && \ - LIBRESSL_VERSION_NUMBER < 0x3060000fL) && \ +#if !(defined(LIBRESSL_VERSION_NUMBER) && \ + LIBRESSL_VERSION_NUMBER < 0x3060000fL) && \ !defined(HAVE_BORINGSSL_LIKE) && !defined(CURL_DISABLE_VERBOSE_STRINGS) static void infof_certstack(struct Curl_easy *data, const SSL *ssl) { @@ -4905,8 +4491,7 @@ static void infof_certstack(struct Curl_easy *data, const SSL *ssl) type_name = NULL; #endif - infof(data, - " Certificate level %d: " + infof(data, " Certificate level %d: " "Public key type %s%s (%d/%d Bits/secBits), signed using %s", cert_level, type_name ? type_name : "?", get_group_name == 0 ? "" : group_name_final, @@ -4924,8 +4509,8 @@ static CURLcode ossl_check_issuer(struct Curl_cfilter *cf, struct ssl_primary_config *conn_config = Curl_ssl_cf_get_primary_config(cf); X509 *issuer = NULL; BIO *fp = NULL; - char err_buf[256]=""; - bool strict = (conn_config->verifypeer || conn_config->verifyhost); + char err_buf[256] = ""; + bool verify_enabled = (conn_config->verifypeer || conn_config->verifyhost); CURLcode result = CURLE_OK; /* e.g. match issuer name with provided issuer certificate */ @@ -4949,7 +4534,7 @@ static CURLcode ossl_check_issuer(struct Curl_cfilter *cf, } if(BIO_read_filename(fp, conn_config->issuercert) <= 0) { - if(strict) + if(verify_enabled) failf(data, "SSL: Unable to open issuer cert (%s)", conn_config->issuercert); result = CURLE_SSL_ISSUER_ERROR; @@ -4960,7 +4545,7 @@ static CURLcode ossl_check_issuer(struct Curl_cfilter *cf, if(fp) { issuer = PEM_read_bio_X509(fp, NULL, ZERO_NULL, NULL); if(!issuer) { - if(strict) + if(verify_enabled) failf(data, "SSL: Unable to read issuer cert (%s)", conn_config->issuercert); result = CURLE_SSL_ISSUER_ERROR; @@ -4968,7 +4553,7 @@ static CURLcode ossl_check_issuer(struct Curl_cfilter *cf, } if(X509_check_issued(issuer, server_cert) != X509_V_OK) { - if(strict) + if(verify_enabled) failf(data, "SSL: Certificate issuer check failed (%s)", conn_config->issuercert); result = CURLE_SSL_ISSUER_ERROR; @@ -5016,8 +4601,6 @@ static CURLcode ossl_infof_cert(struct Curl_cfilter *cf, struct Curl_easy *data, X509 *server_cert) { - struct ssl_primary_config *conn_config = Curl_ssl_cf_get_primary_config(cf); - bool strict = (conn_config->verifypeer || conn_config->verifyhost); BIO *mem = NULL; struct dynbuf dname; char err_buf[256] = ""; @@ -5044,22 +4627,18 @@ static CURLcode ossl_infof_cert(struct Curl_cfilter *cf, infof(data, " subject: %s", result ? "[NONE]" : curlx_dyn_ptr(&dname)); ASN1_TIME_print(mem, X509_get0_notBefore(server_cert)); - len = BIO_get_mem_data(mem, (char **) &buf); + len = BIO_get_mem_data(mem, (char **)&buf); infof(data, " start date: %.*s", (int)len, buf); (void)BIO_reset(mem); ASN1_TIME_print(mem, X509_get0_notAfter(server_cert)); - len = BIO_get_mem_data(mem, (char **) &buf); + len = BIO_get_mem_data(mem, (char **)&buf); infof(data, " expire date: %.*s", (int)len, buf); (void)BIO_reset(mem); result = x509_name_oneline(X509_get_issuer_name(server_cert), &dname); - if(result) { - if(strict) - failf(data, "SSL: could not get X509-issuer name"); - result = CURLE_PEER_FAILED_VERIFICATION; + if(result) /* should be only fatal stuff like OOM */ goto out; - } infof(data, " issuer: %s", curlx_dyn_ptr(&dname)); out: @@ -5067,8 +4646,7 @@ static CURLcode ossl_infof_cert(struct Curl_cfilter *cf, curlx_dyn_free(&dname); return result; } -#endif /* ! CURL_DISABLE_VERBOSE_STRINGS */ - +#endif /* !CURL_DISABLE_VERBOSE_STRINGS */ #ifdef USE_APPLE_SECTRUST struct ossl_certs_ctx { @@ -5156,15 +4734,14 @@ CURLcode Curl_ossl_check_peer_cert(struct Curl_cfilter *cf, struct ssl_primary_config *conn_config = Curl_ssl_cf_get_primary_config(cf); CURLcode result = CURLE_OK; long ossl_verify; - bool strict = (conn_config->verifypeer || conn_config->verifyhost); X509 *server_cert; bool verified = FALSE; -#ifdef USE_APPLE_SECTRUST +#if !defined(OPENSSL_NO_OCSP) && defined(USE_APPLE_SECTRUST) bool sectrust_verified = FALSE; #endif if(data->set.ssl.certinfo && !octx->reused_session) { - /* asked to gather certificate info. Reused sessions don't have cert + /* asked to gather certificate info. Reused sessions do not have cert chains */ result = ossl_certchain(data, octx->ssl); if(result) @@ -5173,7 +4750,8 @@ CURLcode Curl_ossl_check_peer_cert(struct Curl_cfilter *cf, server_cert = SSL_get1_peer_certificate(octx->ssl); if(!server_cert) { - if(!strict) + /* no verification at all, this maybe acceptable */ + if(!(conn_config->verifypeer || conn_config->verifyhost)) goto out; failf(data, "SSL: could not get peer certificate"); @@ -5193,6 +4771,7 @@ CURLcode Curl_ossl_check_peer_cert(struct Curl_cfilter *cf, if(result) goto out; } + /* `verifyhost` is either OK or not requested from here on */ ossl_verify = SSL_get_verify_result(octx->ssl); ssl_config->certverifyresult = ossl_verify; @@ -5202,9 +4781,7 @@ CURLcode Curl_ossl_check_peer_cert(struct Curl_cfilter *cf, infof(data, "SSL certificate verified via OpenSSL."); #ifdef USE_APPLE_SECTRUST - if(!verified && - conn_config->verifypeer && ssl_config->native_ca_store && - (ossl_verify == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY)) { + if(!verified && conn_config->verifypeer && ssl_config->native_ca_store) { /* we verify using Apple SecTrust *unless* OpenSSL already verified. * This may happen if the application intercepted the OpenSSL callback * and installed its own. */ @@ -5214,22 +4791,25 @@ CURLcode Curl_ossl_check_peer_cert(struct Curl_cfilter *cf, if(verified) { infof(data, "SSL certificate verified via Apple SecTrust."); ssl_config->certverifyresult = X509_V_OK; +#ifndef OPENSSL_NO_OCSP sectrust_verified = TRUE; +#endif } } #endif if(!verified) { /* no trust established, report the OpenSSL status */ - failf(data, "SSL certificate OpenSSL verify result: %s (%ld)", - X509_verify_cert_error_string(ossl_verify), ossl_verify); - result = CURLE_PEER_FAILED_VERIFICATION; - if(conn_config->verifypeer) + if(conn_config->verifypeer) { + failf(data, "SSL certificate OpenSSL verify result: %s (%ld)", + X509_verify_cert_error_string(ossl_verify), ossl_verify); + result = CURLE_PEER_FAILED_VERIFICATION; goto out; + } infof(data, " SSL certificate verification failed, continuing anyway!"); } -#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_OCSP) +#ifndef OPENSSL_NO_OCSP if(conn_config->verifystatus && #ifdef USE_APPLE_SECTRUST !sectrust_verified && /* already verified via apple sectrust, cannot @@ -5495,8 +5075,7 @@ static CURLcode ossl_send(struct Curl_cfilter *cf, result = CURLE_AGAIN; octx->blocked_ssl_write_len = memlen; goto out; - case SSL_ERROR_SYSCALL: - { + case SSL_ERROR_SYSCALL: { int sockerr = SOCKERRNO; if(octx->io_result == CURLE_AGAIN) { @@ -5549,7 +5128,6 @@ static CURLcode ossl_recv(struct Curl_cfilter *cf, char error_buffer[256]; unsigned long sslerror; int buffsize; - struct connectdata *conn = cf->conn; struct ssl_connect_data *connssl = cf->ctx; struct ossl_ctx *octx = (struct ossl_ctx *)connssl->backend; CURLcode result = CURLE_OK; @@ -5579,7 +5157,7 @@ static CURLcode ossl_recv(struct Curl_cfilter *cf, if(cf->sockindex == FIRSTSOCKET) /* mark the connection for close if it is indeed the control connection */ - connclose(conn, "TLS close_notify"); + CURL_TRC_CF(data, cf, "TLS close_notify"); break; case SSL_ERROR_WANT_READ: connssl->io_need = CURL_SSL_IO_NEED_RECV; @@ -5660,8 +5238,6 @@ static CURLcode ossl_recv(struct Curl_cfilter *cf, static CURLcode ossl_get_channel_binding(struct Curl_easy *data, int sockindex, struct dynbuf *binding) { - /* required for X509_get_signature_nid support */ -#if OPENSSL_VERSION_NUMBER > 0x10100000L X509 *cert; int algo_nid; const EVP_MD *algo_type; @@ -5694,7 +5270,7 @@ static CURLcode ossl_get_channel_binding(struct Curl_easy *data, int sockindex, cert = SSL_get1_peer_certificate(octx->ssl); if(!cert) - /* No server certificate, don't do channel binding */ + /* No server certificate, do not do channel binding */ return CURLE_OK; if(!OBJ_find_sigid_algs(X509_get_signature_nid(cert), &algo_nid, NULL)) { @@ -5736,13 +5312,6 @@ static CURLcode ossl_get_channel_binding(struct Curl_easy *data, int sockindex, error: X509_free(cert); return result; -#else - /* No X509_get_signature_nid support */ - (void)data; - (void)sockindex; - (void)binding; - return CURLE_OK; -#endif } size_t Curl_ossl_version(char *buffer, size_t size) @@ -5771,41 +5340,9 @@ size_t Curl_ossl_version(char *buffer, size_t size) #elif defined(OPENSSL_IS_AWSLC) return curl_msnprintf(buffer, size, "%s/%s", OSSL_PACKAGE, AWSLC_VERSION_NUMBER_STRING); -#elif defined(OPENSSL_VERSION_STRING) /* OpenSSL 3+ */ +#else /* OpenSSL 3+ */ return curl_msnprintf(buffer, size, "%s/%s", OSSL_PACKAGE, OpenSSL_version(OPENSSL_VERSION_STRING)); -#else - /* not LibreSSL, BoringSSL and not using OpenSSL_version */ - - char sub[3]; - unsigned long ssleay_value; - sub[2]='\0'; - sub[1]='\0'; - ssleay_value = OpenSSL_version_num(); - if(ssleay_value&0xff0) { - int minor_ver = (ssleay_value >> 4) & 0xff; - if(minor_ver > 26) { - /* handle extended version introduced for 0.9.8za */ - sub[1] = (char) ((minor_ver - 1) % 26 + 'a' + 1); - sub[0] = 'z'; - } - else { - sub[0] = (char) (minor_ver + 'a' - 1); - } - } - else - sub[0]='\0'; - - return curl_msnprintf(buffer, size, "%s/%lx.%lx.%lx%s" -#ifdef OPENSSL_FIPS - "-fips" -#endif - , - OSSL_PACKAGE, - (ssleay_value >> 28) & 0xf, - (ssleay_value >> 20) & 0xff, - (ssleay_value >> 12) & 0xff, - sub); #endif } @@ -5827,7 +5364,6 @@ static CURLcode ossl_random(struct Curl_easy *data, return rc == 1 ? CURLE_OK : CURLE_FAILED_INIT; } -#ifndef OPENSSL_NO_SHA256 static CURLcode ossl_sha256sum(const unsigned char *tmp, /* input */ size_t tmplen, unsigned char *sha256sum /* output */, @@ -5849,11 +5385,10 @@ static CURLcode ossl_sha256sum(const unsigned char *tmp, /* input */ EVP_MD_CTX_destroy(mdctx); return CURLE_OK; } -#endif static bool ossl_cert_status_request(void) { -#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_OCSP) +#ifndef OPENSSL_NO_OCSP return TRUE; #else return FALSE; @@ -5884,7 +5419,7 @@ const struct Curl_ssl Curl_ssl_openssl = { #ifdef HAVE_SSL_CTX_SET1_SIGALGS SSLSUPP_SIGNATURE_ALGORITHMS | #endif -#ifdef USE_ECH_OPENSSL +#ifdef HAVE_SSL_SET1_ECH_CONFIG_LIST SSLSUPP_ECH | #endif SSLSUPP_CA_CACHE | @@ -5908,11 +5443,7 @@ const struct Curl_ssl Curl_ssl_openssl = { ossl_set_engine, /* set_engine or provider */ ossl_set_engine_default, /* set_engine_default */ ossl_engines_list, /* engines_list */ -#ifndef OPENSSL_NO_SHA256 ossl_sha256sum, /* sha256sum */ -#else - NULL, /* sha256sum */ -#endif ossl_recv, /* recv decrypted data */ ossl_send, /* send data to encrypt */ ossl_get_channel_binding /* get_channel_binding */ diff --git a/vendor/hydra/vendor/curl/lib/vtls/openssl.h b/vendor/hydra/vendor/curl/lib/vtls/openssl.h index 021d754a..aeeb8dd8 100644 --- a/vendor/hydra/vendor/curl/lib/vtls/openssl.h +++ b/vendor/hydra/vendor/curl/lib/vtls/openssl.h @@ -23,7 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "../curl_setup.h" #ifdef USE_OPENSSL @@ -51,8 +50,7 @@ * BoringSSL: supported since d28f59c27bac (committed 2015-11-19) * LibreSSL: not supported. 3.5.0+ has a stub function that does nothing. */ -#if (OPENSSL_VERSION_NUMBER >= 0x10101000L && \ - !defined(LIBRESSL_VERSION_NUMBER)) || defined(HAVE_BORINGSSL_LIKE) +#ifndef LIBRESSL_VERSION_NUMBER #define HAVE_KEYLOG_CALLBACK #endif @@ -151,8 +149,7 @@ CURLcode Curl_ossl_check_peer_cert(struct Curl_cfilter *cf, struct ssl_peer *peer); /* Report properties of a successful handshake */ -void Curl_ossl_report_handshake(struct Curl_easy *data, - struct ossl_ctx *octx); +void Curl_ossl_report_handshake(struct Curl_easy *data, struct ossl_ctx *octx); #endif /* USE_OPENSSL */ #endif /* HEADER_CURL_SSLUSE_H */ diff --git a/vendor/hydra/vendor/curl/lib/vtls/rustls.c b/vendor/hydra/vendor/curl/lib/vtls/rustls.c index 2173b3be..fc380b06 100644 --- a/vendor/hydra/vendor/curl/lib/vtls/rustls.c +++ b/vendor/hydra/vendor/curl/lib/vtls/rustls.c @@ -5,8 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) Jacob Hoffman-Andrews, - * + * Copyright (C) Jacob Hoffman-Andrews, * Copyright (C) kpcyrd, * Copyright (C) Daniel McCarney, * @@ -31,10 +30,9 @@ #include #include "../curlx/fopen.h" -#include "../curlx/inet_pton.h" #include "../curlx/strerr.h" #include "../urldata.h" -#include "../sendf.h" +#include "../curl_trc.h" #include "vtls.h" #include "vtls_int.h" #include "rustls.h" @@ -42,12 +40,7 @@ #include "cipher_suite.h" #include "x509asn1.h" -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - -struct rustls_ssl_backend_data -{ +struct rustls_ssl_backend_data { const struct rustls_client_config *config; struct rustls_connection *conn; size_t plain_out_buffered; @@ -62,17 +55,17 @@ static CURLcode map_error(const rustls_result r) return CURLE_PEER_FAILED_VERIFICATION; } switch(r) { - case RUSTLS_RESULT_OK: - return CURLE_OK; - case RUSTLS_RESULT_NULL_PARAMETER: - return CURLE_BAD_FUNCTION_ARGUMENT; - default: - return CURLE_RECV_ERROR; + case RUSTLS_RESULT_OK: + return CURLE_OK; + case RUSTLS_RESULT_NULL_PARAMETER: + return CURLE_BAD_FUNCTION_ARGUMENT; + default: + return CURLE_RECV_ERROR; } } -static void -rustls_failf(struct Curl_easy *data, const rustls_result rr, const char *msg) +static void rustls_failf(struct Curl_easy *data, const rustls_result rr, + const char *msg) { char errorbuf[STRERROR_LEN]; size_t errorlen; @@ -80,8 +73,8 @@ rustls_failf(struct Curl_easy *data, const rustls_result rr, const char *msg) failf(data, "%s: %.*s", msg, (int)errorlen, errorbuf); } -static bool -cr_data_pending(struct Curl_cfilter *cf, const struct Curl_easy *data) +static bool cr_data_pending(struct Curl_cfilter *cf, + const struct Curl_easy *data) { const struct ssl_connect_data *ctx = cf->ctx; struct rustls_ssl_backend_data *backend; @@ -97,11 +90,11 @@ struct io_ctx { struct Curl_easy *data; }; -static int -read_cb(void *userdata, uint8_t *buf, uintptr_t len, uintptr_t *out_n) +static int read_cb(void *userdata, uint8_t *buf, uintptr_t len, + uintptr_t *out_n) { const struct io_ctx *io_ctx = userdata; - struct ssl_connect_data *const connssl = io_ctx->cf->ctx; + struct ssl_connect_data * const connssl = io_ctx->cf->ctx; CURLcode result; int ret = 0; size_t nread; @@ -124,8 +117,8 @@ read_cb(void *userdata, uint8_t *buf, uintptr_t len, uintptr_t *out_n) return ret; } -static int -write_cb(void *userdata, const uint8_t *buf, uintptr_t len, uintptr_t *out_n) +static int write_cb(void *userdata, const uint8_t *buf, uintptr_t len, + uintptr_t *out_n) { const struct io_ctx *io_ctx = userdata; CURLcode result; @@ -133,7 +126,7 @@ write_cb(void *userdata, const uint8_t *buf, uintptr_t len, uintptr_t *out_n) size_t nwritten; result = Curl_conn_cf_send(io_ctx->cf->next, io_ctx->data, - (const char *)buf, len, FALSE, &nwritten); + buf, len, FALSE, &nwritten); if(result) { nwritten = 0; if(CURLE_AGAIN == result) @@ -150,8 +143,8 @@ write_cb(void *userdata, const uint8_t *buf, uintptr_t len, uintptr_t *out_n) static ssize_t tls_recv_more(struct Curl_cfilter *cf, struct Curl_easy *data, CURLcode *err) { - const struct ssl_connect_data *const connssl = cf->ctx; - struct rustls_ssl_backend_data *const backend = + const struct ssl_connect_data * const connssl = cf->ctx; + struct rustls_ssl_backend_data * const backend = (struct rustls_ssl_backend_data *)connssl->backend; struct io_ctx io_ctx; size_t tls_bytes_read = 0; @@ -190,12 +183,11 @@ static ssize_t tls_recv_more(struct Curl_cfilter *cf, * Filter receive method implementation. `plainbuf` and `plainlen` * are always not NULL/0. */ -static CURLcode -cr_recv(struct Curl_cfilter *cf, struct Curl_easy *data, - char *plainbuf, size_t plainlen, size_t *pnread) +static CURLcode cr_recv(struct Curl_cfilter *cf, struct Curl_easy *data, + char *plainbuf, size_t plainlen, size_t *pnread) { - const struct ssl_connect_data *const connssl = cf->ctx; - struct rustls_ssl_backend_data *const backend = + const struct ssl_connect_data * const connssl = cf->ctx; + struct rustls_ssl_backend_data * const backend = (struct rustls_ssl_backend_data *)connssl->backend; struct rustls_connection *rconn = NULL; CURLcode result = CURLE_OK; @@ -304,12 +296,12 @@ static CURLcode cr_flush_out(struct Curl_cfilter *cf, struct Curl_easy *data, * In that case, it will not read anything into Rustls' plaintext input buffer. * It will only drain Rustls' plaintext output buffer into the socket. */ -static CURLcode -cr_send(struct Curl_cfilter *cf, struct Curl_easy *data, - const void *plainbuf, size_t plainlen, size_t *pnwritten) +static CURLcode cr_send(struct Curl_cfilter *cf, struct Curl_easy *data, + const void *plainbuf, size_t plainlen, + size_t *pnwritten) { - const struct ssl_connect_data *const connssl = cf->ctx; - struct rustls_ssl_backend_data *const backend = + const struct ssl_connect_data * const connssl = cf->ctx; + struct rustls_ssl_backend_data * const backend = (struct rustls_ssl_backend_data *)connssl->backend; struct rustls_connection *rconn = NULL; size_t plainwritten = 0; @@ -383,18 +375,15 @@ cr_send(struct Curl_cfilter *cf, struct Curl_easy *data, /* A server certificate verify callback for Rustls that always returns RUSTLS_RESULT_OK, or in other words disable certificate verification. */ -static uint32_t -cr_verify_none(void *userdata, - const rustls_verify_server_cert_params *params) +static uint32_t cr_verify_none(void *userdata, + const rustls_verify_server_cert_params *params) { (void)userdata; (void)params; return RUSTLS_RESULT_OK; } -static int -read_file_into(const char *filename, - struct dynbuf *out) +static int read_file_into(const char *filename, struct dynbuf *out) { FILE *f = curlx_fopen(filename, FOPEN_READTEXT); if(!f) { @@ -468,16 +457,17 @@ cr_get_selected_ciphers(struct Curl_easy *data, if(!id) { if(ptr[0] != '\0') infof(data, "rustls: unknown cipher in list: \"%.*s\"", - (int) (end - ptr), ptr); + (int)(end - ptr), ptr); continue; } /* No duplicates allowed (so selected cannot overflow) */ - for(i = 0; i < count && selected[i] != entry; i++); + for(i = 0; i < count && selected[i] != entry; i++) + ; if(i < count) { if(i >= default13_count) infof(data, "rustls: duplicate cipher in list: \"%.*s\"", - (int) (end - ptr), ptr); + (int)(end - ptr), ptr); continue; } @@ -494,11 +484,12 @@ cr_get_selected_ciphers(struct Curl_easy *data, for(j = 0; j < default_len; j++) { entry = rustls_default_crypto_provider_ciphersuites_get(j); if(rustls_supported_ciphersuite_protocol_version(entry) == - RUSTLS_TLS_VERSION_TLSV1_3) + RUSTLS_TLS_VERSION_TLSV1_3) continue; /* No duplicates allowed (so selected cannot overflow) */ - for(i = 0; i < count && selected[i] != entry; i++); + for(i = 0; i < count && selected[i] != entry; i++) + ; if(i < count) continue; @@ -509,10 +500,10 @@ cr_get_selected_ciphers(struct Curl_easy *data, *selected_size = count; } -static void -cr_keylog_log_cb(struct rustls_str label, - const uint8_t *client_random, size_t client_random_len, - const uint8_t *secret, size_t secret_len) +static void cr_keylog_log_cb(struct rustls_str label, + const uint8_t *client_random, + size_t client_random_len, const uint8_t *secret, + size_t secret_len) { char clabel[KEYLOG_LABEL_MAXLEN]; (void)client_random_len; @@ -532,12 +523,11 @@ init_config_builder(struct Curl_easy *data, const struct rustls_crypto_provider *custom_provider = NULL; uint16_t tls_versions[2] = { - RUSTLS_TLS_VERSION_TLSV1_2, - RUSTLS_TLS_VERSION_TLSV1_3, + RUSTLS_TLS_VERSION_TLSV1_2, + RUSTLS_TLS_VERSION_TLSV1_3, }; size_t tls_versions_len = 2; - size_t cipher_suites_len = - rustls_default_crypto_provider_ciphersuites_len(); + size_t cipher_suites_len = rustls_default_crypto_provider_ciphersuites_len(); CURLcode result = CURLE_OK; rustls_result rr; @@ -586,7 +576,7 @@ init_config_builder(struct Curl_easy *data, } #endif /* USE_ECH */ - cipher_suites = malloc(sizeof(cipher_suites) * (cipher_suites_len)); + cipher_suites = curlx_malloc(sizeof(*cipher_suites) * (cipher_suites_len)); if(!cipher_suites) { result = CURLE_OUT_OF_MEMORY; goto cleanup; @@ -606,7 +596,7 @@ init_config_builder(struct Curl_easy *data, &custom_provider_builder); if(rr != RUSTLS_RESULT_OK) { rustls_failf(data, rr, - "failed to create crypto provider builder from default"); + "failed to create crypto provider builder from default"); result = CURLE_SSL_CIPHER; goto cleanup; } @@ -618,13 +608,13 @@ init_config_builder(struct Curl_easy *data, cipher_suites_len); if(rr != RUSTLS_RESULT_OK) { rustls_failf(data, rr, - "failed to set ciphersuites for crypto provider builder"); + "failed to set ciphersuites for crypto provider builder"); result = CURLE_SSL_CIPHER; goto cleanup; } - rr = rustls_crypto_provider_builder_build( - custom_provider_builder, &custom_provider); + rr = rustls_crypto_provider_builder_build(custom_provider_builder, + &custom_provider); if(rr != RUSTLS_RESULT_OK) { rustls_failf(data, rr, "failed to build custom crypto provider"); result = CURLE_SSL_CIPHER; @@ -632,9 +622,9 @@ init_config_builder(struct Curl_easy *data, } rr = rustls_client_config_builder_new_custom(custom_provider, - tls_versions, - tls_versions_len, - config_builder); + tls_versions, + tls_versions_len, + config_builder); if(rr != RUSTLS_RESULT_OK) { rustls_failf(data, rr, "failed to create client config builder"); result = CURLE_SSL_CIPHER; @@ -643,7 +633,7 @@ init_config_builder(struct Curl_easy *data, cleanup: if(cipher_suites) { - free(cipher_suites); + curlx_free(cipher_suites); } if(custom_provider_builder) { rustls_crypto_provider_builder_free(custom_provider_builder); @@ -657,7 +647,8 @@ init_config_builder(struct Curl_easy *data, static void init_config_builder_alpn(struct Curl_easy *data, const struct ssl_connect_data *connssl, - struct rustls_client_config_builder *config_builder) { + struct rustls_client_config_builder *config_builder) +{ struct alpn_proto_buf proto; rustls_slice_bytes alpn[ALPN_ENTRIES_MAX]; size_t i; @@ -672,8 +663,7 @@ init_config_builder_alpn(struct Curl_easy *data, infof(data, VTLS_INFOF_ALPN_OFFER_1STR, proto.data); } -static CURLcode -init_config_builder_verifier_crl( +static CURLcode init_config_builder_verifier_crl( struct Curl_easy *data, const struct ssl_primary_config *conn_config, struct rustls_web_pki_server_cert_verifier_builder *builder) @@ -709,7 +699,8 @@ init_config_builder_verifier(struct Curl_easy *data, struct rustls_client_config_builder *builder, const struct ssl_primary_config *conn_config, const struct curl_blob *ca_info_blob, - const char * const ssl_cafile) { + const char * const ssl_cafile) +{ const struct rustls_root_cert_store *roots = NULL; struct rustls_root_cert_store_builder *roots_builder = NULL; struct rustls_web_pki_server_cert_verifier_builder *verifier_builder = NULL; @@ -725,7 +716,6 @@ init_config_builder_verifier(struct Curl_easy *data, 1); if(rr != RUSTLS_RESULT_OK) { rustls_failf(data, rr, "failed to parse trusted certificates from blob"); - result = CURLE_SSL_CACERT_BADFILE; goto cleanup; } @@ -736,7 +726,6 @@ init_config_builder_verifier(struct Curl_easy *data, 1); if(rr != RUSTLS_RESULT_OK) { rustls_failf(data, rr, "failed to load trusted certificates"); - result = CURLE_SSL_CACERT_BADFILE; goto cleanup; } @@ -746,17 +735,19 @@ init_config_builder_verifier(struct Curl_easy *data, if(rr != RUSTLS_RESULT_OK) { rustls_failf(data, rr, "failed to build trusted root certificate store"); result = CURLE_SSL_CACERT_BADFILE; - if(result) { - goto cleanup; - } + goto cleanup; } verifier_builder = rustls_web_pki_server_cert_verifier_builder_new(roots); + if(!verifier_builder) { + result = CURLE_OUT_OF_MEMORY; + goto cleanup; + } if(conn_config->CRLfile) { result = init_config_builder_verifier_crl(data, - conn_config, - verifier_builder); + conn_config, + verifier_builder); if(result) { goto cleanup; } @@ -789,8 +780,7 @@ init_config_builder_verifier(struct Curl_easy *data, return result; } -static CURLcode -init_config_builder_platform_verifier( +static CURLcode init_config_builder_platform_verifier( struct Curl_easy *data, struct rustls_client_config_builder *builder) { @@ -890,10 +880,8 @@ init_config_builder_client_auth(struct Curl_easy *data, rr = rustls_certified_key_keys_match(certified_key); if(rr != RUSTLS_RESULT_OK) { - rustls_failf(data, - rr, + rustls_failf(data, rr, "rustls: client certificate and keypair files do not match:"); - result = CURLE_SSL_CERTPROBLEM; goto cleanup; } @@ -1002,7 +990,7 @@ init_config_builder_ech(struct Curl_easy *data, cleanup: /* if we base64 decoded, we can free now */ if(data->set.tls_ech & CURLECH_CLA_CFG && data->set.str[STRING_ECH_CONFIG]) { - free(ech_config); + curlx_free(ech_config); } if(dns) { Curl_resolv_unlink(data, &dns); @@ -1011,9 +999,9 @@ init_config_builder_ech(struct Curl_easy *data, } #endif /* USE_ECH */ -static CURLcode -cr_init_backend(struct Curl_cfilter *cf, struct Curl_easy *data, - struct rustls_ssl_backend_data *const backend) +static CURLcode cr_init_backend(struct Curl_cfilter *cf, + struct Curl_easy *data, + struct rustls_ssl_backend_data * const backend) { const struct ssl_connect_data *connssl = cf->ctx; const struct ssl_primary_config *conn_config = @@ -1091,13 +1079,9 @@ cr_init_backend(struct Curl_cfilter *cf, struct Curl_easy *data, return result; } - rr = rustls_client_config_builder_build( - config_builder, - &backend->config); + rr = rustls_client_config_builder_build(config_builder, &backend->config); if(rr != RUSTLS_RESULT_OK) { rustls_failf(data, rr, "failed to build client config"); - rustls_client_config_builder_free(config_builder); - rustls_client_config_free(backend->config); return CURLE_SSL_CONNECT_ERROR; } @@ -1107,6 +1091,8 @@ cr_init_backend(struct Curl_cfilter *cf, struct Curl_easy *data, &rconn); if(rr != RUSTLS_RESULT_OK) { rustls_failf(data, rr, "rustls_client_connection_new"); + rustls_client_config_free(backend->config); + backend->config = NULL; return CURLE_COULDNT_CONNECT; } DEBUGASSERT(rconn); @@ -1116,11 +1102,11 @@ cr_init_backend(struct Curl_cfilter *cf, struct Curl_easy *data, return result; } -static void -cr_set_negotiated_alpn(struct Curl_cfilter *cf, struct Curl_easy *data, - const struct rustls_connection *rconn) +static void cr_set_negotiated_alpn(struct Curl_cfilter *cf, + struct Curl_easy *data, + const struct rustls_connection *rconn) { - struct ssl_connect_data *const connssl = cf->ctx; + struct ssl_connect_data * const connssl = cf->ctx; const uint8_t *protocol = NULL; size_t len = 0; @@ -1133,12 +1119,11 @@ cr_set_negotiated_alpn(struct Curl_cfilter *cf, struct Curl_easy *data, * This function will set `*done` to true once the handshake is complete. * This function never reads the value of `*done*`. */ -static CURLcode -cr_connect(struct Curl_cfilter *cf, - struct Curl_easy *data, bool *done) +static CURLcode cr_connect(struct Curl_cfilter *cf, struct Curl_easy *data, + bool *done) { - struct ssl_connect_data *const connssl = cf->ctx; - const struct rustls_ssl_backend_data *const backend = + struct ssl_connect_data * const connssl = cf->ctx; + const struct rustls_ssl_backend_data * const backend = (struct rustls_ssl_backend_data *)connssl->backend; const struct rustls_connection *rconn = NULL; CURLcode tmperr = CURLE_OK; @@ -1165,9 +1150,9 @@ cr_connect(struct Curl_cfilter *cf, /* Read/write data until the handshake is done or the socket would block. */ for(;;) { /* - * Connection has been established according to Rustls. Set send/recv - * handlers, and update the state machine. - */ + * Connection has been established according to Rustls. Set send/recv + * handlers, and update the state machine. + */ connssl->io_need = CURL_SSL_IO_NEED_NONE; if(!rustls_connection_is_handshaking(rconn)) { /* Rustls claims it is no longer handshaking *before* it has @@ -1186,8 +1171,7 @@ cr_connect(struct Curl_cfilter *cf, } /* REALLY Done with the handshake. */ { - const uint16_t proto = - rustls_connection_get_protocol_version(rconn); + const uint16_t proto = rustls_connection_get_protocol_version(rconn); const rustls_str ciphersuite_name = rustls_connection_get_negotiated_ciphersuite_name(rconn); const rustls_str kex_group_name = @@ -1209,8 +1193,13 @@ cr_connect(struct Curl_cfilter *cf, if(data->set.ssl.certinfo) { size_t num_certs = 0; size_t i; - while(rustls_connection_get_peer_certificate(rconn, (int)num_certs)) { + while(rustls_connection_get_peer_certificate(rconn, num_certs)) { num_certs++; + if(num_certs > MAX_ALLOWED_CERT_AMOUNT) { + failf(data, "%zu certificates is more than allowed (%u)", + num_certs, MAX_ALLOWED_CERT_AMOUNT); + return CURLE_SSL_CONNECT_ERROR; + } } result = Curl_ssl_init_certinfo(data, (int)num_certs); if(result) @@ -1292,9 +1281,7 @@ cr_connect(struct Curl_cfilter *cf, DEBUGASSERT(FALSE); } -static void * -cr_get_internals(struct ssl_connect_data *connssl, - CURLINFO info) +static void *cr_get_internals(struct ssl_connect_data *connssl, CURLINFO info) { struct rustls_ssl_backend_data *backend = (struct rustls_ssl_backend_data *)connssl->backend; @@ -1303,10 +1290,8 @@ cr_get_internals(struct ssl_connect_data *connssl, return backend->conn; } -static CURLcode -cr_shutdown(struct Curl_cfilter *cf, - struct Curl_easy *data, - const bool send_shutdown, bool *done) +static CURLcode cr_shutdown(struct Curl_cfilter *cf, struct Curl_easy *data, + const bool send_shutdown, bool *done) { struct ssl_connect_data *connssl = cf->ctx; struct rustls_ssl_backend_data *backend = @@ -1368,8 +1353,7 @@ cr_shutdown(struct Curl_cfilter *cf, return result; } -static void -cr_close(struct Curl_cfilter *cf, struct Curl_easy *data) +static void cr_close(struct Curl_cfilter *cf, struct Curl_easy *data) { const struct ssl_connect_data *connssl = cf->ctx; struct rustls_ssl_backend_data *backend = @@ -1393,13 +1377,12 @@ static size_t cr_version(char *buffer, size_t size) return curl_msnprintf(buffer, size, "%.*s", (int)ver.len, ver.data); } -static CURLcode -cr_random(struct Curl_easy *data, unsigned char *entropy, size_t length) +static CURLcode cr_random(struct Curl_easy *data, unsigned char *entropy, + size_t length) { rustls_result rresult = 0; (void)data; - rresult = - rustls_default_crypto_provider_random(entropy, length); + rresult = rustls_default_crypto_provider_random(entropy, length); return map_error(rresult); } diff --git a/vendor/hydra/vendor/curl/lib/vtls/rustls.h b/vendor/hydra/vendor/curl/lib/vtls/rustls.h index 74d39d4d..2d3b0bb1 100644 --- a/vendor/hydra/vendor/curl/lib/vtls/rustls.h +++ b/vendor/hydra/vendor/curl/lib/vtls/rustls.h @@ -1,3 +1,5 @@ +#ifndef HEADER_CURL_RUSTLS_H +#define HEADER_CURL_RUSTLS_H /*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | @@ -5,8 +7,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) Jacob Hoffman-Andrews, - * + * Copyright (C) Jacob Hoffman-Andrews, * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -22,9 +23,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ -#ifndef HEADER_CURL_RUSTLS_H -#define HEADER_CURL_RUSTLS_H - #include "../curl_setup.h" #ifdef USE_RUSTLS diff --git a/vendor/hydra/vendor/curl/lib/vtls/schannel.c b/vendor/hydra/vendor/curl/lib/vtls/schannel.c index 50b81f67..891dfc4e 100644 --- a/vendor/hydra/vendor/curl/lib/vtls/schannel.c +++ b/vendor/hydra/vendor/curl/lib/vtls/schannel.c @@ -23,18 +23,16 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - /* * Source file for all Schannel-specific code for the TLS/SSL layer. No code * but vtls.c should ever call or use these functions. */ - #include "../curl_setup.h" #ifdef USE_SCHANNEL #ifndef USE_WINDOWS_SSPI -# error "cannot compile SCHANNEL support without SSPI." +#error "cannot compile SCHANNEL support without SSPI." #endif #include "schannel.h" @@ -42,17 +40,14 @@ #include "vtls.h" #include "vtls_int.h" #include "vtls_scache.h" -#include "../sendf.h" +#include "../curl_trc.h" #include "../connect.h" /* for the connect timeout */ #include "../strdup.h" #include "../strerror.h" #include "../select.h" /* for the socket readiness */ #include "../curlx/fopen.h" -#include "../curlx/inet_pton.h" /* for IP addr SNI check */ #include "../curlx/multibyte.h" -#include "../curlx/warnless.h" #include "x509asn1.h" -#include "../multiif.h" #include "../system_win32.h" #include "../curlx/version_win32.h" #include "../rand.h" @@ -60,10 +55,6 @@ #include "../progress.h" #include "../curl_sha256.h" -/* The last #include file should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* Some verbose debug messages are wrapped by SCH_DEV() instead of DEBUGF() * and only shown if CURL_SCHANNEL_DEV_DEBUG was defined at build time. These * messages are extra verbose and intended for curl developers debugging @@ -71,11 +62,11 @@ */ #ifdef CURL_SCHANNEL_DEV_DEBUG #define SCH_DEV(x) x -#define SCH_DEV_SHOWBOOL(x) \ +#define SCH_DEV_SHOWBOOL(x) \ infof(data, "schannel: " #x " %s", (x) ? "TRUE" : "FALSE"); #else -#define SCH_DEV(x) do { } while(0) -#define SCH_DEV_SHOWBOOL(x) do { } while(0) +#define SCH_DEV(x) do {} while(0) +#define SCH_DEV_SHOWBOOL(x) do {} while(0) #endif /* Offered by mingw-w64 v8+. MS SDK 7.0A+. */ @@ -119,12 +110,6 @@ #define CALG_SHA_256 0x0000800c #endif -/* Work around typo in CeGCC (as of 0.59.1) w32api headers */ -#if defined(__MINGW32CE__) && \ - !defined(ALG_CLASS_DHASH) && defined(ALG_CLASS_HASH) -#define ALG_CLASS_DHASH ALG_CLASS_HASH -#endif - /* Offered by mingw-w64 v4+. MS SDK 6.0A+. */ #ifndef PKCS12_NO_PERSIST_KEY #define PKCS12_NO_PERSIST_KEY 0x00008000 @@ -169,10 +154,9 @@ static void InitSecBufferDesc(SecBufferDesc *desc, SecBuffer *BufArr, desc->cBuffers = NumArrElem; } -static CURLcode -schannel_set_ssl_version_min_max(DWORD *enabled_protocols, - struct Curl_cfilter *cf, - struct Curl_easy *data) +static CURLcode schannel_set_ssl_version_min_max(DWORD *enabled_protocols, + struct Curl_cfilter *cf, + struct Curl_easy *data) { struct ssl_primary_config *conn_config = Curl_ssl_cf_get_primary_config(cf); long ssl_version = conn_config->version; @@ -232,7 +216,7 @@ struct algo { int id; }; -static const struct algo algs[]= { +static const struct algo algs[] = { CIPHEROPTION(CALG_MD2), CIPHEROPTION(CALG_MD4), CIPHEROPTION(CALG_MD5), @@ -340,8 +324,7 @@ static const struct algo algs[]= { {NULL, 0}, }; -static int -get_alg_id_by_name(const char *name) +static int get_alg_id_by_name(const char *name) { const char *nameEnd = strchr(name, ':'); size_t n = nameEnd ? (size_t)(nameEnd - name) : strlen(name); @@ -356,9 +339,8 @@ get_alg_id_by_name(const char *name) #define NUM_CIPHERS 47 /* There are 47 options listed above */ -static CURLcode -set_ssl_ciphers(SCHANNEL_CRED *schannel_cred, char *ciphers, - ALG_ID *algIds) +static CURLcode set_ssl_ciphers(SCHANNEL_CRED *schannel_cred, char *ciphers, + ALG_ID *algIds) { const char *startCur = ciphers; int algCount = 0; @@ -385,11 +367,9 @@ set_ssl_ciphers(SCHANNEL_CRED *schannel_cred, char *ciphers, return CURLE_OK; } -#ifndef UNDER_CE /* Function allocates memory for store_path only if CURLE_OK is returned */ -static CURLcode -get_cert_location(TCHAR *path, DWORD *store_name, TCHAR **store_path, - TCHAR **thumbprint) +static CURLcode get_cert_location(TCHAR *path, DWORD *store_name, + TCHAR **store_path, TCHAR **thumbprint) { TCHAR *sep; TCHAR *store_path_start; @@ -411,14 +391,11 @@ get_cert_location(TCHAR *path, DWORD *store_name, TCHAR **store_path, *store_name = CERT_SYSTEM_STORE_SERVICES; else if(_tcsncmp(path, TEXT("Users"), store_name_len) == 0) *store_name = CERT_SYSTEM_STORE_USERS; - else if(_tcsncmp(path, TEXT("CurrentUserGroupPolicy"), - store_name_len) == 0) + else if(_tcsncmp(path, TEXT("CurrentUserGroupPolicy"), store_name_len) == 0) *store_name = CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY; - else if(_tcsncmp(path, TEXT("LocalMachineGroupPolicy"), - store_name_len) == 0) + else if(_tcsncmp(path, TEXT("LocalMachineGroupPolicy"), store_name_len) == 0) *store_name = CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY; - else if(_tcsncmp(path, TEXT("LocalMachineEnterprise"), - store_name_len) == 0) + else if(_tcsncmp(path, TEXT("LocalMachineEnterprise"), store_name_len) == 0) *store_name = CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE; else return CURLE_SSL_CERTPROBLEM; @@ -434,18 +411,16 @@ get_cert_location(TCHAR *path, DWORD *store_name, TCHAR **store_path, return CURLE_SSL_CERTPROBLEM; *sep = TEXT('\0'); - *store_path = Curl_tcsdup(store_path_start); + *store_path = curlx_tcsdup(store_path_start); *sep = TEXT('\\'); if(!*store_path) return CURLE_OUT_OF_MEMORY; return CURLE_OK; } -#endif -static CURLcode -schannel_acquire_credential_handle(struct Curl_cfilter *cf, - struct Curl_easy *data) +static CURLcode schannel_acquire_credential_handle(struct Curl_cfilter *cf, + struct Curl_easy *data) { struct ssl_connect_data *connssl = cf->ctx; struct ssl_primary_config *conn_config = Curl_ssl_cf_get_primary_config(cf); @@ -473,37 +448,36 @@ schannel_acquire_credential_handle(struct Curl_cfilter *cf, if(ssl_config->no_revoke) { flags |= SCH_CRED_IGNORE_NO_REVOCATION_CHECK | - SCH_CRED_IGNORE_REVOCATION_OFFLINE; + SCH_CRED_IGNORE_REVOCATION_OFFLINE; DEBUGF(infof(data, "schannel: disabled server certificate revocation " - "checks")); + "checks")); } else if(ssl_config->revoke_best_effort) { flags |= SCH_CRED_IGNORE_NO_REVOCATION_CHECK | - SCH_CRED_IGNORE_REVOCATION_OFFLINE | SCH_CRED_REVOCATION_CHECK_CHAIN; + SCH_CRED_IGNORE_REVOCATION_OFFLINE | + SCH_CRED_REVOCATION_CHECK_CHAIN; DEBUGF(infof(data, "schannel: ignore revocation offline errors")); } else { flags |= SCH_CRED_REVOCATION_CHECK_CHAIN; - DEBUGF(infof(data, - "schannel: checking server certificate revocation")); + DEBUGF(infof(data, "schannel: checking server certificate revocation")); } } else { flags = SCH_CRED_MANUAL_CRED_VALIDATION | - SCH_CRED_IGNORE_NO_REVOCATION_CHECK | - SCH_CRED_IGNORE_REVOCATION_OFFLINE; - DEBUGF(infof(data, - "schannel: disabled server cert revocation checks")); + SCH_CRED_IGNORE_NO_REVOCATION_CHECK | + SCH_CRED_IGNORE_REVOCATION_OFFLINE; + DEBUGF(infof(data, "schannel: disabled server cert revocation checks")); } if(!conn_config->verifyhost) { flags |= SCH_CRED_NO_SERVERNAME_CHECK; DEBUGF(infof(data, "schannel: verifyhost setting prevents Schannel from " - "comparing the supplied target name with the subject " - "names in server certificates.")); + "comparing the supplied target name with the subject " + "names in server certificates.")); } if(!ssl_config->auto_client_cert) { @@ -520,8 +494,7 @@ schannel_acquire_credential_handle(struct Curl_cfilter *cf, case CURL_SSLVERSION_TLSv1_0: case CURL_SSLVERSION_TLSv1_1: case CURL_SSLVERSION_TLSv1_2: - case CURL_SSLVERSION_TLSv1_3: - { + case CURL_SSLVERSION_TLSv1_3: { result = schannel_set_ssl_version_min_max(&enabled_protocols, cf, data); if(result) return result; @@ -536,7 +509,6 @@ schannel_acquire_credential_handle(struct Curl_cfilter *cf, return CURLE_SSL_CONNECT_ERROR; } -#ifndef UNDER_CE /* client certificate */ if(data->set.ssl.primary.clientcert || data->set.ssl.primary.cert_blob) { DWORD cert_store_name = 0; @@ -563,24 +535,25 @@ schannel_acquire_credential_handle(struct Curl_cfilter *cf, result = get_cert_location(cert_path, &cert_store_name, &cert_store_path, &cert_thumbprint_str); - if(result && (data->set.ssl.primary.clientcert[0]!='\0')) + if(result && (data->set.ssl.primary.clientcert[0] != '\0')) fInCert = curlx_fopen(data->set.ssl.primary.clientcert, "rb"); if(result && !fInCert) { failf(data, "schannel: Failed to get certificate location" " or file for %s", data->set.ssl.primary.clientcert); - curlx_unicodefree(cert_path); + curlx_free(cert_path); return result; } } - if((fInCert || blob) && (data->set.ssl.cert_type) && - (!curl_strequal(data->set.ssl.cert_type, "P12"))) { + if((fInCert || blob) && data->set.ssl.cert_type && + !curl_strequal(data->set.ssl.cert_type, "P12")) { failf(data, "schannel: certificate format compatibility error " " for %s", blob ? "(memory blob)" : data->set.ssl.primary.clientcert); - curlx_unicodefree(cert_path); + curlx_free(cert_store_path); + curlx_free(cert_path); if(fInCert) curlx_fclose(fInCert); return CURLE_SSL_CERTPROBLEM; @@ -591,13 +564,14 @@ schannel_acquire_credential_handle(struct Curl_cfilter *cf, https://learn.microsoft.com/archive/msdn-technet-forums/3e7bc95f-b21a-4bcd-bd2c-7f996718cae5 */ CRYPT_DATA_BLOB datablob; - WCHAR* pszPassword; + WCHAR *pszPassword; size_t pwd_len = 0; int str_w_len = 0; int cert_find_flags; const char *cert_showfilename_error = blob ? "(memory blob)" : data->set.ssl.primary.clientcert; - curlx_unicodefree(cert_path); + curlx_free(cert_store_path); + curlx_free(cert_path); if(fInCert) { long cert_tell = 0; bool continue_reading = fseek(fInCert, 0, SEEK_END) == 0; @@ -609,8 +583,8 @@ schannel_acquire_credential_handle(struct Curl_cfilter *cf, certsize = (size_t)cert_tell; if(continue_reading) continue_reading = fseek(fInCert, 0, SEEK_SET) == 0; - if(continue_reading) - certdata = malloc(certsize + 1); + if(continue_reading && (certsize < CURL_MAX_INPUT_LENGTH)) + certdata = curlx_malloc(certsize + 1); if((!certdata) || ((int) fread(certdata, certsize, 1, fInCert) != 1)) continue_reading = FALSE; @@ -618,18 +592,18 @@ schannel_acquire_credential_handle(struct Curl_cfilter *cf, if(!continue_reading) { failf(data, "schannel: Failed to read cert file %s", data->set.ssl.primary.clientcert); - free(certdata); + curlx_free(certdata); return CURLE_SSL_CERTPROBLEM; } } /* Convert key-pair data to the in-memory certificate store */ - datablob.pbData = (BYTE*)certdata; + datablob.pbData = (BYTE *)certdata; datablob.cbData = (DWORD)certsize; if(data->set.ssl.key_passwd) pwd_len = strlen(data->set.ssl.key_passwd); - pszPassword = (WCHAR*)malloc(sizeof(WCHAR)*(pwd_len + 1)); + pszPassword = (WCHAR *)curlx_malloc(sizeof(WCHAR) * (pwd_len + 1)); if(pszPassword) { if(pwd_len > 0) str_w_len = MultiByteToWideChar(CP_UTF8, @@ -649,10 +623,10 @@ schannel_acquire_credential_handle(struct Curl_cfilter *cf, else cert_store = PFXImportCertStore(&datablob, pszPassword, 0); - free(pszPassword); + curlx_free(pszPassword); } if(!blob) - free(certdata); + curlx_free(certdata); if(!cert_store) { DWORD errorcode = GetLastError(); if(errorcode == ERROR_INVALID_PASSWORD) @@ -706,12 +680,12 @@ schannel_acquire_credential_handle(struct Curl_cfilter *cf, cert_store_name, (path_utf8 ? path_utf8 : "(unknown)"), GetLastError()); - free(cert_store_path); - curlx_unicodefree(path_utf8); - curlx_unicodefree(cert_path); + curlx_free(cert_store_path); + curlx_free(path_utf8); + curlx_free(cert_path); return CURLE_SSL_CERTPROBLEM; } - free(cert_store_path); + curlx_free(cert_store_path); cert_thumbprint.pbData = cert_thumbprint_data; cert_thumbprint.cbData = CERT_THUMBPRINT_DATA_LEN; @@ -722,7 +696,7 @@ schannel_acquire_credential_handle(struct Curl_cfilter *cf, cert_thumbprint_data, &cert_thumbprint.cbData, NULL, NULL)) { - curlx_unicodefree(cert_path); + curlx_free(cert_path); CertCloseStore(cert_store, 0); return CURLE_SSL_CERTPROBLEM; } @@ -731,7 +705,7 @@ schannel_acquire_credential_handle(struct Curl_cfilter *cf, cert_store, X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, 0, CERT_FIND_HASH, &cert_thumbprint, NULL); - curlx_unicodefree(cert_path); + curlx_free(cert_path); if(!client_certs[0]) { /* CRYPT_E_NOT_FOUND / E_INVALIDARG */ @@ -742,11 +716,10 @@ schannel_acquire_credential_handle(struct Curl_cfilter *cf, } client_cert_store = cert_store; } -#endif /* allocate memory for the reusable credential handle */ backend->cred = (struct Curl_schannel_cred *) - calloc(1, sizeof(struct Curl_schannel_cred)); + curlx_calloc(1, sizeof(struct Curl_schannel_cred)); if(!backend->cred) { failf(data, "schannel: unable to allocate memory"); @@ -866,16 +839,14 @@ schannel_acquire_credential_handle(struct Curl_cfilter *cf, return CURLE_OK; } -static CURLcode -schannel_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) +static CURLcode schannel_connect_step1(struct Curl_cfilter *cf, + struct Curl_easy *data) { size_t written = 0; struct ssl_connect_data *connssl = cf->ctx; struct schannel_ssl_backend_data *backend = (struct schannel_ssl_backend_data *)connssl->backend; -#ifndef UNDER_CE struct ssl_primary_config *conn_config = Curl_ssl_cf_get_primary_config(cf); -#endif struct ssl_config_data *ssl_config = Curl_ssl_cf_get_config(cf, data); SecBuffer outbuf; SecBufferDesc outbuf_desc; @@ -888,8 +859,7 @@ schannel_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) CURLcode result; DEBUGASSERT(backend); - DEBUGF(infof(data, - "schannel: SSL/TLS connection with %s port %d (step 1/3)", + DEBUGF(infof(data, "schannel: SSL/TLS connection with %s port %d (step 1/3)", connssl->peer.hostname, connssl->peer.port)); if(curlx_verify_windows_version(5, 1, 0, PLATFORM_WINNT, @@ -906,11 +876,6 @@ schannel_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) backend->use_alpn = FALSE; #endif -#ifdef UNDER_CE - /* certificate validation on Windows CE does not seem to work right; we will - * do it following a more manual process. */ - backend->use_manual_cred_validation = TRUE; -#else if(conn_config->CAfile || conn_config->ca_info_blob) { if(curlx_verify_windows_version(6, 1, 0, PLATFORM_WINNT, VERSION_GREATER_THAN_EQUAL)) { @@ -918,13 +883,12 @@ schannel_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) } else { failf(data, "schannel: this version of Windows is too old to support " - "certificate verification via CA bundle file."); + "certificate verification via CA bundle file."); return CURLE_SSL_CACERT_BADFILE; } } else backend->use_manual_cred_validation = FALSE; -#endif backend->cred = NULL; @@ -972,7 +936,7 @@ schannel_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) int cur = 0; int list_start_index = 0; unsigned int *extension_len = NULL; - unsigned short* list_len = NULL; + unsigned short *list_len = NULL; struct alpn_proto_buf proto; /* The first four bytes will be an unsigned int indicating number @@ -988,7 +952,7 @@ schannel_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) /* The next two bytes will be an unsigned short indicating the number of bytes used to list the preferred protocols. */ - list_len = (unsigned short*)(void *)(&alpn_buffer[cur]); + list_len = (unsigned short *)(void *)(&alpn_buffer[cur]); cur += (int)sizeof(unsigned short); list_start_index = cur; @@ -1026,8 +990,8 @@ schannel_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) /* security request flags */ backend->req_flags = ISC_REQ_SEQUENCE_DETECT | ISC_REQ_REPLAY_DETECT | - ISC_REQ_CONFIDENTIALITY | ISC_REQ_ALLOCATE_MEMORY | - ISC_REQ_STREAM; + ISC_REQ_CONFIDENTIALITY | ISC_REQ_ALLOCATE_MEMORY | + ISC_REQ_STREAM; if(!ssl_config->auto_client_cert) { backend->req_flags |= ISC_REQ_USE_SUPPLIED_CREDS; @@ -1035,7 +999,7 @@ schannel_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) /* allocate memory for the security context handle */ backend->ctxt = (struct Curl_schannel_ctxt *) - calloc(1, sizeof(struct Curl_schannel_ctxt)); + curlx_calloc(1, sizeof(struct Curl_schannel_ctxt)); if(!backend->ctxt) { failf(data, "schannel: unable to allocate memory"); return CURLE_OUT_OF_MEMORY; @@ -1090,7 +1054,8 @@ schannel_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) /* send initial handshake data which is now stored in output buffer */ result = Curl_conn_cf_send(cf->next, data, - outbuf.pvBuffer, outbuf.cbBuffer, FALSE, + (const uint8_t *)outbuf.pvBuffer, + outbuf.cbBuffer, FALSE, &written); Curl_pSecFn->FreeContextBuffer(outbuf.pvBuffer); if(result || (outbuf.cbBuffer != written)) { @@ -1150,8 +1115,8 @@ static CURLcode schannel_error(struct Curl_easy *data, } } -static CURLcode -schannel_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) +static CURLcode schannel_connect_step2(struct Curl_cfilter *cf, + struct Curl_easy *data) { struct ssl_connect_data *connssl = cf->ctx; struct schannel_ssl_backend_data *backend = @@ -1174,8 +1139,7 @@ schannel_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) doread = (connssl->io_need & CURL_SSL_IO_NEED_SEND) ? FALSE : TRUE; connssl->io_need = CURL_SSL_IO_NEED_NONE; - DEBUGF(infof(data, - "schannel: SSL/TLS connection with %s port %d (step 2/3)", + DEBUGF(infof(data, "schannel: SSL/TLS connection with %s port %d (step 2/3)", connssl->peer.hostname, connssl->peer.port)); if(!backend->cred || !backend->ctxt) @@ -1185,7 +1149,7 @@ schannel_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) if(!backend->decdata_buffer) { backend->decdata_offset = 0; backend->decdata_length = CURL_SCHANNEL_BUFFER_INIT_SIZE; - backend->decdata_buffer = malloc(backend->decdata_length); + backend->decdata_buffer = curlx_malloc(backend->decdata_length); if(!backend->decdata_buffer) { failf(data, "schannel: unable to allocate memory"); return CURLE_OUT_OF_MEMORY; @@ -1197,7 +1161,7 @@ schannel_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) backend->encdata_is_incomplete = FALSE; backend->encdata_offset = 0; backend->encdata_length = CURL_SCHANNEL_BUFFER_INIT_SIZE; - backend->encdata_buffer = malloc(backend->encdata_length); + backend->encdata_buffer = curlx_malloc(backend->encdata_length); if(!backend->encdata_buffer) { failf(data, "schannel: unable to allocate memory"); return CURLE_OUT_OF_MEMORY; @@ -1210,8 +1174,8 @@ schannel_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) /* increase internal encrypted data buffer */ size_t reallocated_length = backend->encdata_offset + CURL_SCHANNEL_BUFFER_FREE_SIZE; - reallocated_buffer = realloc(backend->encdata_buffer, - reallocated_length); + reallocated_buffer = curlx_realloc(backend->encdata_buffer, + reallocated_length); if(!reallocated_buffer) { failf(data, "schannel: unable to re-allocate memory"); @@ -1262,7 +1226,8 @@ schannel_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) backend->encdata_offset, backend->encdata_length)); /* setup input buffers */ - InitSecBuffer(&inbuf[0], SECBUFFER_TOKEN, malloc(backend->encdata_offset), + InitSecBuffer(&inbuf[0], SECBUFFER_TOKEN, + curlx_malloc(backend->encdata_offset), curlx_uztoul(backend->encdata_offset)); InitSecBuffer(&inbuf[1], SECBUFFER_EMPTY, NULL, 0); InitSecBufferDesc(&inbuf_desc, inbuf, 2); @@ -1284,12 +1249,12 @@ schannel_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) /* The socket must be writeable (or a poll error occurred) before we call InitializeSecurityContext to continue processing the received TLS - records. This is because that function is not idempotent and we don't + records. This is because that function is not idempotent and we do not support partial save/resume sending replies of handshake tokens. */ if(!SOCKET_WRITABLE(Curl_conn_cf_get_socket(cf, data), 0)) { SCH_DEV(infof(data, "schannel: handshake waiting for writeable socket")); connssl->io_need = CURL_SSL_IO_NEED_SEND; - free(inbuf[0].pvBuffer); + curlx_free(inbuf[0].pvBuffer); return CURLE_OK; } @@ -1323,7 +1288,8 @@ schannel_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) /* send handshake token to server */ result = Curl_conn_cf_send(cf->next, data, - outbuf[i].pvBuffer, outbuf[i].cbBuffer, + (const uint8_t *)outbuf[i].pvBuffer, + outbuf[i].cbBuffer, FALSE, &written); if(result || (outbuf[i].cbBuffer != written)) { failf(data, "schannel: failed to send next handshake data: " @@ -1378,7 +1344,8 @@ schannel_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) if(backend->encdata_offset > inbuf[1].cbBuffer) { memmove(backend->encdata_buffer, (backend->encdata_buffer + backend->encdata_offset) - - inbuf[1].cbBuffer, inbuf[1].cbBuffer); + inbuf[1].cbBuffer, + inbuf[1].cbBuffer); backend->encdata_offset = inbuf[1].cbBuffer; if(sspi_status == SEC_I_CONTINUE_NEEDED) { doread = FALSE; @@ -1432,8 +1399,7 @@ schannel_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) return CURLE_OK; } -static bool -valid_cert_encoding(const CERT_CONTEXT *cert_context) +static bool valid_cert_encoding(const CERT_CONTEXT *cert_context) { return (cert_context != NULL) && ((cert_context->dwCertEncodingType & X509_ASN_ENCODING) != 0) && @@ -1441,12 +1407,11 @@ valid_cert_encoding(const CERT_CONTEXT *cert_context) (cert_context->cbCertEncoded > 0); } -typedef bool(*Read_crt_func)(const CERT_CONTEXT *ccert_context, - bool reverse_order, void *arg); +typedef bool (*Read_crt_func)(const CERT_CONTEXT *ccert_context, + bool reverse_order, void *arg); -static void -traverse_cert_store(const CERT_CONTEXT *context, Read_crt_func func, - void *arg) +static void traverse_cert_store(const CERT_CONTEXT *context, + Read_crt_func func, void *arg) { const CERT_CONTEXT *current_context = NULL; bool should_continue = TRUE; @@ -1471,32 +1436,31 @@ traverse_cert_store(const CERT_CONTEXT *context, Read_crt_func func, CertFreeCertificateContext(current_context); } -static bool -cert_counter_callback(const CERT_CONTEXT *ccert_context, bool reverse_order, - void *certs_count) +static bool cert_counter_callback(const CERT_CONTEXT *ccert_context, + bool reverse_order, void *certs_count) { (void)reverse_order; if(valid_cert_encoding(ccert_context)) (*(int *)certs_count)++; + if(*(int *)certs_count > MAX_ALLOWED_CERT_AMOUNT) + return FALSE; return TRUE; } -struct Adder_args -{ +struct Adder_args { struct Curl_easy *data; CURLcode result; int idx; int certs_count; }; -static bool -add_cert_to_certinfo(const CERT_CONTEXT *ccert_context, bool reverse_order, - void *raw_arg) +static bool add_cert_to_certinfo(const CERT_CONTEXT *ccert_context, + bool reverse_order, void *raw_arg) { - struct Adder_args *args = (struct Adder_args*)raw_arg; + struct Adder_args *args = (struct Adder_args *)raw_arg; args->result = CURLE_OK; if(valid_cert_encoding(ccert_context)) { - const char *beg = (const char *) ccert_context->pbCertEncoded; + const char *beg = (const char *)ccert_context->pbCertEncoded; const char *end = beg + ccert_context->cbCertEncoded; int insert_index = reverse_order ? (args->certs_count - 1) - args->idx : args->idx; @@ -1516,7 +1480,7 @@ static void schannel_session_free(void *sessionid) cred->refcount--; if(cred->refcount == 0) { Curl_pSecFn->FreeCredentialsHandle(&cred->cred_handle); - curlx_unicodefree(cred->sni_hostname); + curlx_free(cred->sni_hostname); if(cred->client_cert_store) { CertCloseStore(cred->client_cert_store, 0); cred->client_cert_store = NULL; @@ -1526,8 +1490,8 @@ static void schannel_session_free(void *sessionid) } } -static CURLcode -schannel_connect_step3(struct Curl_cfilter *cf, struct Curl_easy *data) +static CURLcode schannel_connect_step3(struct Curl_cfilter *cf, + struct Curl_easy *data) { struct ssl_connect_data *connssl = cf->ctx; struct schannel_ssl_backend_data *backend = @@ -1542,8 +1506,7 @@ schannel_connect_step3(struct Curl_cfilter *cf, struct Curl_easy *data) DEBUGASSERT(ssl_connect_3 == connssl->connecting_state); DEBUGASSERT(backend); - DEBUGF(infof(data, - "schannel: SSL/TLS connection with %s port %d (step 3/3)", + DEBUGF(infof(data, "schannel: SSL/TLS connection with %s port %d (step 3/3)", connssl->peer.hostname, connssl->peer.port)); if(!backend->cred) @@ -1623,6 +1586,12 @@ schannel_connect_step3(struct Curl_cfilter *cf, struct Curl_easy *data) } traverse_cert_store(ccert_context, cert_counter_callback, &certs_count); + if(certs_count > MAX_ALLOWED_CERT_AMOUNT) { + failf(data, "%d certificates is more than allowed (%u)", + certs_count, MAX_ALLOWED_CERT_AMOUNT); + CertFreeCertificateContext(ccert_context); + return CURLE_SSL_CONNECT_ERROR; + } result = Curl_ssl_init_certinfo(data, certs_count); if(!result) { @@ -1748,7 +1717,7 @@ schannel_recv_renegotiate(struct Curl_cfilter *cf, struct Curl_easy *data, connssl->connecting_state = ssl_connect_2; memset(rs, 0, sizeof(*rs)); rs->io_need = CURL_SSL_IO_NEED_SEND; - rs->start_time = curlx_now(); + rs->start_time = *Curl_pgrs_now(data); rs->started = TRUE; } @@ -1757,7 +1726,7 @@ schannel_recv_renegotiate(struct Curl_cfilter *cf, struct Curl_easy *data, curl_socket_t readfd, writefd; timediff_t elapsed; - elapsed = curlx_timediff(curlx_now(), rs->start_time); + elapsed = curlx_ptimediff_ms(Curl_pgrs_now(data), &rs->start_time); if(elapsed >= MAX_RENEG_BLOCK_TIME) { failf(data, "schannel: renegotiation timeout"); result = CURLE_SSL_CONNECT_ERROR; @@ -1799,7 +1768,7 @@ schannel_recv_renegotiate(struct Curl_cfilter *cf, struct Curl_easy *data, * data needs to be sent then we block for a writeable socket that should * be writeable immediately except for OS resource constraints. For caller * send if handshake data needs to be received then we block for a readable - * socket, which could take some time, but it's more likely the user has + * socket, which could take some time, but it is more likely the user has * called recv since they had called it prior (only recv can start * renegotiation and probably the user is going to call it again to get * more of their data before calling send). @@ -1817,14 +1786,13 @@ schannel_recv_renegotiate(struct Curl_cfilter *cf, struct Curl_easy *data, for(;;) { int what; - timediff_t timeout, remaining; + timediff_t timeout_ms, remaining; - if(Curl_pgrsUpdate(data)) { - result = CURLE_ABORTED_BY_CALLBACK; + result = Curl_pgrsUpdate(data); + if(result) break; - } - elapsed = curlx_timediff(curlx_now(), rs->start_time); + elapsed = curlx_ptimediff_ms(Curl_pgrs_now(data), &rs->start_time); if(elapsed >= MAX_RENEG_BLOCK_TIME) { failf(data, "schannel: renegotiation timeout"); result = CURLE_SSL_CONNECT_ERROR; @@ -1833,31 +1801,31 @@ schannel_recv_renegotiate(struct Curl_cfilter *cf, struct Curl_easy *data, remaining = MAX_RENEG_BLOCK_TIME - elapsed; if(blocking) { - timeout = Curl_timeleft(data, NULL, FALSE); + timeout_ms = Curl_timeleft_ms(data, FALSE); - if(timeout < 0) { + if(timeout_ms < 0) { result = CURLE_OPERATION_TIMEDOUT; break; } /* the blocking is in intervals so that the progress function can be called every second */ - if(!timeout || timeout > 1000) - timeout = 1000; + if(!timeout_ms || timeout_ms > 1000) + timeout_ms = 1000; - if(timeout > remaining) - timeout = remaining; + if(timeout_ms > remaining) + timeout_ms = remaining; } else - timeout = 0; + timeout_ms = 0; SCH_DEV(infof(data, "schannel: renegotiation wait until socket is" "%s%s for up to %" FMT_TIMEDIFF_T " ms", ((readfd != CURL_SOCKET_BAD) ? " readable" : ""), ((writefd != CURL_SOCKET_BAD) ? " writeable" : ""), - timeout)); + timeout_ms)); - what = Curl_socket_check(readfd, CURL_SOCKET_BAD, writefd, timeout); + what = Curl_socket_check(readfd, CURL_SOCKET_BAD, writefd, timeout_ms); if(what > 0 && (what & (CURL_CSELECT_IN | CURL_CSELECT_OUT))) { SCH_DEV(infof(data, "schannel: renegotiation socket %s%s", @@ -1896,9 +1864,8 @@ schannel_recv_renegotiate(struct Curl_cfilter *cf, struct Curl_easy *data, return result; } -static CURLcode -schannel_send(struct Curl_cfilter *cf, struct Curl_easy *data, - const void *buf, size_t len, size_t *pnwritten) +static CURLcode schannel_send(struct Curl_cfilter *cf, struct Curl_easy *data, + const void *buf, size_t len, size_t *pnwritten) { size_t data_len = 0; unsigned char *ptr = NULL; @@ -1938,7 +1905,7 @@ schannel_send(struct Curl_cfilter *cf, struct Curl_easy *data, /* calculate the complete message length and allocate a buffer for it */ data_len = backend->stream_sizes.cbHeader + len + backend->stream_sizes.cbTrailer; - ptr = (unsigned char *)malloc(data_len); + ptr = (unsigned char *)curlx_malloc(data_len); if(!ptr) { return CURLE_OUT_OF_MEMORY; } @@ -1987,7 +1954,7 @@ schannel_send(struct Curl_cfilter *cf, struct Curl_easy *data, while(len > *pnwritten) { size_t this_write = 0; int what; - timediff_t timeout_ms = Curl_timeleft(data, NULL, FALSE); + timediff_t timeout_ms = Curl_timeleft_ms(data, FALSE); if(timeout_ms < 0) { /* we already got the timeout */ failf(data, "schannel: timed out sending data " @@ -2013,7 +1980,8 @@ schannel_send(struct Curl_cfilter *cf, struct Curl_easy *data, /* socket is writable */ result = Curl_conn_cf_send(cf->next, data, - ptr + *pnwritten, len - *pnwritten, + (const uint8_t *)ptr + *pnwritten, + len - *pnwritten, FALSE, &this_write); if(result == CURLE_AGAIN) continue; @@ -2027,7 +1995,7 @@ schannel_send(struct Curl_cfilter *cf, struct Curl_easy *data, else if(sspi_status == SEC_E_INSUFFICIENT_MEMORY) { result = CURLE_OUT_OF_MEMORY; } - else{ + else { result = CURLE_SEND_ERROR; } @@ -2041,9 +2009,8 @@ schannel_send(struct Curl_cfilter *cf, struct Curl_easy *data, return result; } -static CURLcode -schannel_recv(struct Curl_cfilter *cf, struct Curl_easy *data, - char *buf, size_t len, size_t *pnread) +static CURLcode schannel_recv(struct Curl_cfilter *cf, struct Curl_easy *data, + char *buf, size_t len, size_t *pnread) { size_t size = 0; size_t nread = 0; @@ -2116,8 +2083,8 @@ schannel_recv(struct Curl_cfilter *cf, struct Curl_easy *data, if(reallocated_length < min_encdata_length) { reallocated_length = min_encdata_length; } - reallocated_buffer = realloc(backend->encdata_buffer, - reallocated_length); + reallocated_buffer = curlx_realloc(backend->encdata_buffer, + reallocated_length); if(!reallocated_buffer) { result = CURLE_OUT_OF_MEMORY; failf(data, "schannel: unable to re-allocate memory"); @@ -2179,7 +2146,7 @@ schannel_recv(struct Curl_cfilter *cf, struct Curl_easy *data, /* https://learn.microsoft.com/windows/win32/api/sspi/nf-sspi-decryptmessage */ sspi_status = Curl_pSecFn->DecryptMessage(&backend->ctxt->ctxt_handle, - &inbuf_desc, 0, NULL); + &inbuf_desc, 0, NULL); /* check if everything went fine (server may want to renegotiate or shutdown the connection context) */ @@ -2202,8 +2169,8 @@ schannel_recv(struct Curl_cfilter *cf, struct Curl_easy *data, if(reallocated_length < len) { reallocated_length = len; } - reallocated_buffer = realloc(backend->decdata_buffer, - reallocated_length); + reallocated_buffer = curlx_realloc(backend->decdata_buffer, + reallocated_length); if(!reallocated_buffer) { result = CURLE_OUT_OF_MEMORY; failf(data, "schannel: unable to re-allocate memory"); @@ -2240,7 +2207,8 @@ schannel_recv(struct Curl_cfilter *cf, struct Curl_easy *data, buffer */ memmove(backend->encdata_buffer, (backend->encdata_buffer + backend->encdata_offset) - - inbuf[3].cbBuffer, inbuf[3].cbBuffer); + inbuf[3].cbBuffer, + inbuf[3].cbBuffer); backend->encdata_offset = inbuf[3].cbBuffer; } @@ -2459,7 +2427,8 @@ static CURLcode schannel_shutdown(struct Curl_cfilter *cf, size_t written; result = Curl_conn_cf_send(cf->next, data, - outbuf.pvBuffer, outbuf.cbBuffer, + (const uint8_t *)outbuf.pvBuffer, + outbuf.cbBuffer, FALSE, &written); Curl_pSecFn->FreeContextBuffer(outbuf.pvBuffer); if(!result) { @@ -2563,7 +2532,7 @@ static void schannel_close(struct Curl_cfilter *cf, struct Curl_easy *data) static int schannel_init(void) { -#if defined(HAS_ALPN_SCHANNEL) && !defined(UNDER_CE) +#ifdef HAS_ALPN_SCHANNEL typedef const char *(APIENTRY *WINE_GET_VERSION_FN)(void); #if defined(__clang__) && __clang_major__ >= 16 #pragma clang diagnostic push @@ -2571,22 +2540,24 @@ static int schannel_init(void) #endif WINE_GET_VERSION_FN p_wine_get_version = CURLX_FUNCTION_CAST(WINE_GET_VERSION_FN, - GetProcAddress(GetModuleHandleA("ntdll"), - "wine_get_version")); + GetProcAddress(GetModuleHandle(TEXT("ntdll")), "wine_get_version")); #if defined(__clang__) && __clang_major__ >= 16 #pragma clang diagnostic pop #endif if(p_wine_get_version) { /* WINE detected */ + curl_off_t ver = 0; const char *wine_version = p_wine_get_version(); /* e.g. "6.0.2" */ /* Assume ALPN support with WINE 6.0 or upper */ - s_win_has_alpn = wine_version && atoi(wine_version) >= 6; + if(wine_version) + curlx_str_number(&wine_version, &ver, 20); + s_win_has_alpn = (ver >= 6); } else { /* ALPN is supported on Windows 8.1 / Server 2012 R2 and above. */ s_win_has_alpn = curlx_verify_windows_version(6, 3, 0, PLATFORM_WINNT, VERSION_GREATER_THAN_EQUAL); } -#endif /* HAS_ALPN_SCHANNEL && !UNDER_CE */ +#endif /* HAS_ALPN_SCHANNEL */ return Curl_sspi_global_init() == CURLE_OK ? 1 : 0; } @@ -2646,7 +2617,6 @@ static CURLcode schannel_pkp_pin_peer_pubkey(struct Curl_cfilter *cf, break; /* failed */ } - if(!(((pCertContextServer->dwCertEncodingType & X509_ASN_ENCODING) != 0) && (pCertContextServer->cbCertEncoded > 0))) break; @@ -2704,12 +2674,7 @@ static void schannel_checksum(const unsigned char *input, if(!CryptCreateHash(hProv, algId, 0, 0, &hHash)) break; /* failed */ -#ifdef __MINGW32CE__ - /* workaround for CeGCC, should be (const BYTE*) */ - if(!CryptHashData(hHash, (BYTE*)CURL_UNCONST(input), (DWORD)inputlen, 0)) -#else if(!CryptHashData(hHash, input, (DWORD)inputlen, 0)) -#endif break; /* failed */ /* get hash size */ @@ -2753,7 +2718,7 @@ static void *schannel_get_internals(struct ssl_connect_data *connssl, } HCERTSTORE Curl_schannel_get_cached_cert_store(struct Curl_cfilter *cf, - const struct Curl_easy *data) + struct Curl_easy *data) { struct ssl_primary_config *conn_config = Curl_ssl_cf_get_primary_config(cf); struct Curl_multi *multi = data->multi; @@ -2762,7 +2727,6 @@ HCERTSTORE Curl_schannel_get_cached_cert_store(struct Curl_cfilter *cf, const struct ssl_general_config *cfg = &data->set.general_ssl; timediff_t timeout_ms; timediff_t elapsed_ms; - struct curltime now; unsigned char info_blob_digest[CURL_SHA256_DIGEST_LENGTH]; DEBUGASSERT(multi); @@ -2773,7 +2737,7 @@ HCERTSTORE Curl_schannel_get_cached_cert_store(struct Curl_cfilter *cf, share = Curl_hash_pick(&multi->proto_hash, CURL_UNCONST(MPROTO_SCHANNEL_CERT_SHARE_KEY), - sizeof(MPROTO_SCHANNEL_CERT_SHARE_KEY)-1); + sizeof(MPROTO_SCHANNEL_CERT_SHARE_KEY) - 1); if(!share || !share->cert_store) { return NULL; } @@ -2788,8 +2752,7 @@ HCERTSTORE Curl_schannel_get_cached_cert_store(struct Curl_cfilter *cf, negative timeout means retain forever. */ timeout_ms = cfg->ca_cache_timeout * (timediff_t)1000; if(timeout_ms >= 0) { - now = curlx_now(); - elapsed_ms = curlx_timediff(now, share->time); + elapsed_ms = curlx_ptimediff_ms(Curl_pgrs_now(data), &share->time); if(elapsed_ms >= timeout_ms) { return NULL; } @@ -2821,19 +2784,19 @@ HCERTSTORE Curl_schannel_get_cached_cert_store(struct Curl_cfilter *cf, static void schannel_cert_share_free(void *key, size_t key_len, void *p) { struct schannel_cert_share *share = p; - DEBUGASSERT(key_len == (sizeof(MPROTO_SCHANNEL_CERT_SHARE_KEY)-1)); + DEBUGASSERT(key_len == (sizeof(MPROTO_SCHANNEL_CERT_SHARE_KEY) - 1)); DEBUGASSERT(!memcmp(MPROTO_SCHANNEL_CERT_SHARE_KEY, key, key_len)); (void)key; (void)key_len; if(share->cert_store) { CertCloseStore(share->cert_store, 0); } - free(share->CAfile); - free(share); + curlx_free(share->CAfile); + curlx_free(share); } bool Curl_schannel_set_cached_cert_store(struct Curl_cfilter *cf, - const struct Curl_easy *data, + struct Curl_easy *data, HCERTSTORE cert_store) { struct ssl_primary_config *conn_config = Curl_ssl_cf_get_primary_config(cf); @@ -2851,17 +2814,17 @@ bool Curl_schannel_set_cached_cert_store(struct Curl_cfilter *cf, share = Curl_hash_pick(&multi->proto_hash, CURL_UNCONST(MPROTO_SCHANNEL_CERT_SHARE_KEY), - sizeof(MPROTO_SCHANNEL_CERT_SHARE_KEY)-1); + sizeof(MPROTO_SCHANNEL_CERT_SHARE_KEY) - 1); if(!share) { - share = calloc(1, sizeof(*share)); + share = curlx_calloc(1, sizeof(*share)); if(!share) { return FALSE; } if(!Curl_hash_add2(&multi->proto_hash, CURL_UNCONST(MPROTO_SCHANNEL_CERT_SHARE_KEY), - sizeof(MPROTO_SCHANNEL_CERT_SHARE_KEY)-1, + sizeof(MPROTO_SCHANNEL_CERT_SHARE_KEY) - 1, share, schannel_cert_share_free)) { - free(share); + curlx_free(share); return FALSE; } } @@ -2875,7 +2838,7 @@ bool Curl_schannel_set_cached_cert_store(struct Curl_cfilter *cf, } else { if(conn_config->CAfile) { - CAfile = strdup(conn_config->CAfile); + CAfile = curlx_strdup(conn_config->CAfile); if(!CAfile) { return FALSE; } @@ -2886,7 +2849,7 @@ bool Curl_schannel_set_cached_cert_store(struct Curl_cfilter *cf, if(share->cert_store) { CertCloseStore(share->cert_store, 0); } - free(share->CAfile); + curlx_free(share->CAfile); share->time = curlx_now(); share->cert_store = cert_store; diff --git a/vendor/hydra/vendor/curl/lib/vtls/schannel.h b/vendor/hydra/vendor/curl/lib/vtls/schannel.h index 9d0bea22..f66bcf29 100644 --- a/vendor/hydra/vendor/curl/lib/vtls/schannel.h +++ b/vendor/hydra/vendor/curl/lib/vtls/schannel.h @@ -58,7 +58,7 @@ /* has been included via the above . * Or in case of ldap.c, it was included via . * And since has this: - * #define X509_NAME ((LPCSTR) 7) + * #define X509_NAME ((LPCSTR)7) * * And in BoringSSL's there is: * typedef struct X509_name_st X509_NAME; @@ -69,15 +69,14 @@ * (and only here). */ #if defined(OPENSSL_IS_BORINGSSL) || defined(OPENSSL_IS_AWSLC) -# undef X509_NAME -# undef X509_CERT_PAIR -# undef X509_EXTENSIONS +#undef X509_NAME +#undef X509_CERT_PAIR +#undef X509_EXTENSIONS #endif extern const struct Curl_ssl Curl_ssl_schannel; -CURLcode Curl_verify_host(struct Curl_cfilter *cf, - struct Curl_easy *data); +CURLcode Curl_verify_host(struct Curl_cfilter *cf, struct Curl_easy *data); CURLcode Curl_verify_certificate(struct Curl_cfilter *cf, struct Curl_easy *data); diff --git a/vendor/hydra/vendor/curl/lib/vtls/schannel_int.h b/vendor/hydra/vendor/curl/lib/vtls/schannel_int.h index 05116dfa..0146bf86 100644 --- a/vendor/hydra/vendor/curl/lib/vtls/schannel_int.h +++ b/vendor/hydra/vendor/curl/lib/vtls/schannel_int.h @@ -31,7 +31,7 @@ #include "vtls.h" #include "../curl_sha256.h" -#if defined(_MSC_VER) && (_MSC_VER <= 1600) +#if defined(_MSC_VER) && (_MSC_VER < 1700) /* Workaround for warning: 'type cast' : conversion from 'int' to 'LPCSTR' of greater size */ #undef CERT_STORE_PROV_MEMORY @@ -158,10 +158,10 @@ struct num_ip_data { }; HCERTSTORE Curl_schannel_get_cached_cert_store(struct Curl_cfilter *cf, - const struct Curl_easy *data); + struct Curl_easy *data); bool Curl_schannel_set_cached_cert_store(struct Curl_cfilter *cf, - const struct Curl_easy *data, + struct Curl_easy *data, HCERTSTORE cert_store); #endif /* USE_SCHANNEL */ diff --git a/vendor/hydra/vendor/curl/lib/vtls/schannel_verify.c b/vendor/hydra/vendor/curl/lib/vtls/schannel_verify.c index a5084944..5129b8b0 100644 --- a/vendor/hydra/vendor/curl/lib/vtls/schannel_verify.c +++ b/vendor/hydra/vendor/curl/lib/vtls/schannel_verify.c @@ -23,57 +23,36 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - /* * Source file for Schannel-specific certificate verification. This code should * only be invoked by code in schannel.c. */ - #include "../curl_setup.h" #ifdef USE_SCHANNEL #ifndef USE_WINDOWS_SSPI -# error "cannot compile SCHANNEL support without SSPI." +#error "cannot compile SCHANNEL support without SSPI." #endif #include "schannel.h" #include "schannel_int.h" +#include "../curlx/fopen.h" #include "../curlx/inet_pton.h" #include "vtls.h" #include "vtls_int.h" -#include "../sendf.h" +#include "../curl_trc.h" #include "../strerror.h" #include "../curlx/winapi.h" #include "../curlx/multibyte.h" #include "hostcheck.h" #include "../curlx/version_win32.h" -/* The last #include file should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - #define BACKEND ((struct schannel_ssl_backend_data *)connssl->backend) -#ifdef __MINGW32CE__ -#define CERT_QUERY_OBJECT_BLOB 0x00000002 -#define CERT_QUERY_CONTENT_CERT 1 -#define CERT_QUERY_CONTENT_FLAG_CERT (1 << CERT_QUERY_CONTENT_CERT) -#define CERT_QUERY_FORMAT_BINARY 1 -#define CERT_QUERY_FORMAT_BASE64_ENCODED 2 -#define CERT_QUERY_FORMAT_ASN_ASCII_HEX_ENCODED 3 -#define CERT_QUERY_FORMAT_FLAG_ALL \ - (1 << CERT_QUERY_FORMAT_BINARY) | \ - (1 << CERT_QUERY_FORMAT_BASE64_ENCODED) | \ - (1 << CERT_QUERY_FORMAT_ASN_ASCII_HEX_ENCODED) -#define CERT_CHAIN_REVOCATION_CHECK_CHAIN 0x20000000 -#define CERT_NAME_DISABLE_IE4_UTF8_FLAG 0x00010000 -#define CERT_TRUST_IS_OFFLINE_REVOCATION 0x01000000 -#endif /* __MINGW32CE__ */ - #define MAX_CAFILE_SIZE 1048576 /* 1 MiB */ -#define BEGIN_CERT "-----BEGIN CERTIFICATE-----" -#define END_CERT "\n-----END CERTIFICATE-----" +#define BEGIN_CERT "-----BEGIN CERTIFICATE-----" +#define END_CERT "\n-----END CERTIFICATE-----" struct cert_chain_engine_config_win8 { DWORD cbSize; @@ -112,7 +91,6 @@ struct cert_chain_engine_config_win7 { HCERTSTORE hExclusiveTrustedPeople; }; -#ifndef UNDER_CE static int is_cr_or_lf(char c) { return c == '\r' || c == '\n'; @@ -178,11 +156,12 @@ static CURLcode add_certs_data_to_store(HCERTSTORE trust_store, const CERT_CONTEXT *cert_context = NULL; BOOL add_cert_result = FALSE; DWORD actual_content_type = 0; - DWORD cert_size = (DWORD) - ((end_cert_ptr + end_cert_len) - begin_cert_ptr); + DWORD cert_size = + (DWORD)((end_cert_ptr + end_cert_len) - begin_cert_ptr); cert_blob.pbData = (BYTE *)CURL_UNCONST(begin_cert_ptr); cert_blob.cbData = cert_size; + /* Caution: CryptQueryObject() is deprecated */ if(!CryptQueryObject(CERT_QUERY_OBJECT_BLOB, &cert_blob, CERT_QUERY_CONTENT_FLAG_CERT, @@ -221,7 +200,6 @@ static CURLcode add_certs_data_to_store(HCERTSTORE trust_store, cert_context, CERT_STORE_ADD_ALWAYS, NULL); - CertFreeCertificateContext(cert_context); if(!add_cert_result) { char buffer[WINAPI_ERROR_LEN]; failf(data, @@ -237,6 +215,21 @@ static CURLcode add_certs_data_to_store(HCERTSTORE trust_store, num_certs++; } } + + switch(actual_content_type) { + case CERT_QUERY_CONTENT_CERT: + case CERT_QUERY_CONTENT_SERIALIZED_CERT: + CertFreeCertificateContext(cert_context); + break; + case CERT_QUERY_CONTENT_CRL: + case CERT_QUERY_CONTENT_SERIALIZED_CRL: + CertFreeCRLContext((PCCRL_CONTEXT)cert_context); + break; + case CERT_QUERY_CONTENT_CTL: + case CERT_QUERY_CONTENT_SERIALIZED_CTL: + CertFreeCTLContext((PCCTL_CONTEXT)cert_context); + break; + } } } } @@ -244,13 +237,11 @@ static CURLcode add_certs_data_to_store(HCERTSTORE trust_store, if(result == CURLE_OK) { if(!num_certs) { - infof(data, - "schannel: did not add any certificates from CA file '%s'", + infof(data, "schannel: did not add any certificates from CA file '%s'", ca_file_text); } else { - infof(data, - "schannel: added %d certificate(s) from CA file '%s'", + infof(data, "schannel: added %d certificate(s) from CA file '%s'", num_certs, ca_file_text); } } @@ -262,41 +253,27 @@ static CURLcode add_certs_file_to_store(HCERTSTORE trust_store, struct Curl_easy *data) { CURLcode result; - HANDLE ca_file_handle = INVALID_HANDLE_VALUE; + HANDLE ca_file_handle; LARGE_INTEGER file_size; char *ca_file_buffer = NULL; - TCHAR *ca_file_tstr = NULL; size_t ca_file_bufsize = 0; DWORD total_bytes_read = 0; - ca_file_tstr = curlx_convert_UTF8_to_tchar(ca_file); - if(!ca_file_tstr) { - char buffer[WINAPI_ERROR_LEN]; - failf(data, - "schannel: invalid path name for CA file '%s': %s", - ca_file, - curlx_winapi_strerror(GetLastError(), buffer, sizeof(buffer))); - result = CURLE_SSL_CACERT_BADFILE; - goto cleanup; - } - /* * Read the CA file completely into memory before parsing it. This * optimizes for the common case where the CA file will be relatively * small ( < 1 MiB ). */ - ca_file_handle = CreateFile(ca_file_tstr, - GENERIC_READ, - FILE_SHARE_READ, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - NULL); + ca_file_handle = curlx_CreateFile(ca_file, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL); if(ca_file_handle == INVALID_HANDLE_VALUE) { char buffer[WINAPI_ERROR_LEN]; - failf(data, - "schannel: failed to open CA file '%s': %s", - ca_file, + failf(data, "schannel: failed to open CA file '%s': %s", ca_file, curlx_winapi_strerror(GetLastError(), buffer, sizeof(buffer))); result = CURLE_SSL_CACERT_BADFILE; goto cleanup; @@ -304,8 +281,7 @@ static CURLcode add_certs_file_to_store(HCERTSTORE trust_store, if(!GetFileSizeEx(ca_file_handle, &file_size)) { char buffer[WINAPI_ERROR_LEN]; - failf(data, - "schannel: failed to determine size of CA file '%s': %s", + failf(data, "schannel: failed to determine size of CA file '%s': %s", ca_file, curlx_winapi_strerror(GetLastError(), buffer, sizeof(buffer))); result = CURLE_SSL_CACERT_BADFILE; @@ -313,15 +289,14 @@ static CURLcode add_certs_file_to_store(HCERTSTORE trust_store, } if(file_size.QuadPart > MAX_CAFILE_SIZE) { - failf(data, - "schannel: CA file exceeds max size of %u bytes", + failf(data, "schannel: CA file exceeds max size of %u bytes", MAX_CAFILE_SIZE); result = CURLE_SSL_CACERT_BADFILE; goto cleanup; } ca_file_bufsize = (size_t)file_size.QuadPart; - ca_file_buffer = (char *)malloc(ca_file_bufsize + 1); + ca_file_buffer = (char *)curlx_malloc(ca_file_bufsize + 1); if(!ca_file_buffer) { result = CURLE_OUT_OF_MEMORY; goto cleanup; @@ -334,9 +309,7 @@ static CURLcode add_certs_file_to_store(HCERTSTORE trust_store, if(!ReadFile(ca_file_handle, ca_file_buffer + total_bytes_read, bytes_to_read, &bytes_read, NULL)) { char buffer[WINAPI_ERROR_LEN]; - failf(data, - "schannel: failed to read from CA file '%s': %s", - ca_file, + failf(data, "schannel: failed to read from CA file '%s': %s", ca_file, curlx_winapi_strerror(GetLastError(), buffer, sizeof(buffer))); result = CURLE_SSL_CACERT_BADFILE; goto cleanup; @@ -363,7 +336,6 @@ static CURLcode add_certs_file_to_store(HCERTSTORE trust_store, CloseHandle(ca_file_handle); } Curl_safefree(ca_file_buffer); - curlx_unicodefree(ca_file_tstr); return result; } @@ -387,10 +359,12 @@ static DWORD cert_get_name_string(struct Curl_easy *data, LPTSTR current_pos = NULL; DWORD i; -/* Offered by mingw-w64 v4+. MS SDK ~10+/~VS2017+. */ -#ifdef CERT_NAME_SEARCH_ALL_NAMES_FLAG /* CERT_NAME_SEARCH_ALL_NAMES_FLAG is available from Windows 8 onwards. */ if(Win8_compat) { +/* Offered by mingw-w64 v4+. MS SDK ~10+/~VS2017+. */ +#ifndef CERT_NAME_SEARCH_ALL_NAMES_FLAG +#define CERT_NAME_SEARCH_ALL_NAMES_FLAG 0x2 +#endif /* CertGetNameString will provide the 8-bit character string without * any decoding */ DWORD name_flags = @@ -403,10 +377,6 @@ static DWORD cert_get_name_string(struct Curl_easy *data, length); return actual_length; } -#else - (void)cert_context; - (void)Win8_compat; -#endif if(!alt_name_info) return 0; @@ -461,12 +431,11 @@ static DWORD cert_get_name_string(struct Curl_easy *data, } /* -* Returns TRUE if the hostname is a numeric IPv4/IPv6 Address, -* and populates the buffer with IPv4/IPv6 info. -*/ + * Returns TRUE if the hostname is a numeric IPv4/IPv6 Address, + * and populates the buffer with IPv4/IPv6 info. + */ -static bool get_num_host_info(struct num_ip_data *ip_blob, - LPCSTR hostname) +static bool get_num_host_info(struct num_ip_data *ip_blob, LPCSTR hostname) { struct in_addr ia; struct in6_addr ia6; @@ -526,75 +495,20 @@ static bool get_alt_name_info(struct Curl_easy *data, &decode_para, alt_name_info, alt_name_info_size)) { - failf(data, - "schannel: CryptDecodeObjectEx() returned no alternate name " - "information."); + failf(data, "schannel: CryptDecodeObjectEx() returned no alternate name " + "information."); return result; } result = TRUE; return result; } -#endif /* !UNDER_CE */ /* Verify the server's hostname */ -CURLcode Curl_verify_host(struct Curl_cfilter *cf, - struct Curl_easy *data) +CURLcode Curl_verify_host(struct Curl_cfilter *cf, struct Curl_easy *data) { CURLcode result = CURLE_PEER_FAILED_VERIFICATION; struct ssl_connect_data *connssl = cf->ctx; CERT_CONTEXT *pCertContextServer = NULL; -#ifdef UNDER_CE - TCHAR cert_hostname_buff[256]; - DWORD len; - - /* This code does not support certificates with multiple alternative names. - * Right now we are only asking for the first preferred alternative name. - * Instead we would need to do all via CERT_NAME_SEARCH_ALL_NAMES_FLAG - * (If Windows CE supports that?) and run this section in a loop for each. - * https://learn.microsoft.com/windows/win32/api/wincrypt/nf-wincrypt-certgetnamestringa - * curl: (51) schannel: CertGetNameString() certificate hostname - * (.google.com) did not match connection (google.com) - */ - len = CertGetNameString(pCertContextServer, - CERT_NAME_DNS_TYPE, - CERT_NAME_DISABLE_IE4_UTF8_FLAG, - NULL, - cert_hostname_buff, - 256); - if(len > 0) { - /* Comparing the cert name and the connection hostname encoded as UTF-8 - * is acceptable since both values are assumed to use ASCII - * (or some equivalent) encoding - */ - char *cert_hostname = curlx_convert_tchar_to_UTF8(cert_hostname_buff); - if(!cert_hostname) { - result = CURLE_OUT_OF_MEMORY; - } - else{ - const char *conn_hostname = connssl->peer.hostname; - if(Curl_cert_hostcheck(cert_hostname, strlen(cert_hostname), - conn_hostname, strlen(conn_hostname))) { - infof(data, - "schannel: connection hostname (%s) validated " - "against certificate name (%s)", - conn_hostname, cert_hostname); - result = CURLE_OK; - } - else{ - failf(data, - "schannel: connection hostname (%s) " - "does not match certificate name (%s)", - conn_hostname, cert_hostname); - } - Curl_safefree(cert_hostname); - } - } - else { - failf(data, - "schannel: CertGetNameString did not provide any " - "certificate name information"); - } -#else SECURITY_STATUS sspi_status; TCHAR *cert_hostname_buff = NULL; size_t cert_hostname_buff_index = 0; @@ -661,7 +575,7 @@ CURLcode Curl_verify_host(struct Curl_cfilter *cf, /* CertGetNameString guarantees that the returned name will not contain * embedded null bytes. This appears to be undocumented behavior. */ - cert_hostname_buff = (LPTSTR)malloc(len * sizeof(TCHAR)); + cert_hostname_buff = (LPTSTR)curlx_malloc(len * sizeof(TCHAR)); if(!cert_hostname_buff) { result = CURLE_OUT_OF_MEMORY; goto cleanup; @@ -720,7 +634,7 @@ CURLcode Curl_verify_host(struct Curl_cfilter *cf, result = CURLE_PEER_FAILED_VERIFICATION; } - curlx_unicodefree(cert_hostname); + curlx_free(cert_hostname); } } @@ -740,7 +654,6 @@ CURLcode Curl_verify_host(struct Curl_cfilter *cf, if(pCertContextServer) CertFreeCertificateContext(pCertContextServer); -#endif /* !UNDER_CE */ return result; } @@ -757,10 +670,8 @@ CURLcode Curl_verify_certificate(struct Curl_cfilter *cf, CERT_CONTEXT *pCertContextServer = NULL; const CERT_CHAIN_CONTEXT *pChainContext = NULL; HCERTCHAINENGINE cert_chain_engine = NULL; -#ifndef UNDER_CE HCERTSTORE trust_store = NULL; HCERTSTORE own_trust_store = NULL; -#endif /* !UNDER_CE */ DEBUGASSERT(BACKEND); @@ -776,7 +687,6 @@ CURLcode Curl_verify_certificate(struct Curl_cfilter *cf, result = CURLE_PEER_FAILED_VERIFICATION; } -#ifndef UNDER_CE if(result == CURLE_OK && (conn_config->CAfile || conn_config->ca_info_blob) && BACKEND->use_manual_cred_validation) { @@ -870,7 +780,6 @@ CURLcode Curl_verify_certificate(struct Curl_cfilter *cf, } } } -#endif /* !UNDER_CE */ if(result == CURLE_OK) { CERT_CHAIN_PARA ChainPara; @@ -904,7 +813,7 @@ CURLcode Curl_verify_certificate(struct Curl_cfilter *cf, * list URL, or when the list could not be downloaded because the * server is currently unreachable. */ dwTrustErrorMask &= ~(DWORD)(CERT_TRUST_REVOCATION_STATUS_UNKNOWN | - CERT_TRUST_IS_OFFLINE_REVOCATION); + CERT_TRUST_IS_OFFLINE_REVOCATION); } if(dwTrustErrorMask) { @@ -934,7 +843,6 @@ CURLcode Curl_verify_certificate(struct Curl_cfilter *cf, } } -#ifndef UNDER_CE if(cert_chain_engine) { CertFreeCertificateChainEngine(cert_chain_engine); } @@ -942,7 +850,6 @@ CURLcode Curl_verify_certificate(struct Curl_cfilter *cf, if(own_trust_store) { CertCloseStore(own_trust_store, 0); } -#endif /* !UNDER_CE */ if(pChainContext) CertFreeCertificateChain(pChainContext); diff --git a/vendor/hydra/vendor/curl/lib/vtls/vtls.c b/vendor/hydra/vendor/curl/lib/vtls/vtls.c index df0449cb..be0c032b 100644 --- a/vendor/hydra/vendor/curl/lib/vtls/vtls.c +++ b/vendor/hydra/vendor/curl/lib/vtls/vtls.c @@ -59,37 +59,29 @@ #include "rustls.h" /* Rustls versions */ #include "../slist.h" -#include "../sendf.h" +#include "../curl_trc.h" #include "../strcase.h" #include "../url.h" #include "../progress.h" -#include "../share.h" -#include "../multiif.h" #include "../curlx/fopen.h" -#include "../curlx/timeval.h" #include "../curl_sha256.h" -#include "../curlx/warnless.h" #include "../curlx/base64.h" #include "../curlx/inet_pton.h" #include "../connect.h" #include "../select.h" #include "../setopt.h" -#include "../rand.h" #include "../strdup.h" +#include "../curlx/strcopy.h" #ifdef USE_APPLE_SECTRUST #include #endif -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - #define CLONE_STRING(var) \ do { \ if(source->var) { \ - dest->var = strdup(source->var); \ + dest->var = curlx_strdup(source->var); \ if(!dest->var) \ return FALSE; \ } \ @@ -97,21 +89,20 @@ dest->var = NULL; \ } while(0) -#define CLONE_BLOB(var) \ - do { \ - if(blobdup(&dest->var, source->var)) \ - return FALSE; \ +#define CLONE_BLOB(var) \ + do { \ + if(blobdup(&dest->var, source->var)) \ + return FALSE; \ } while(0) -static CURLcode blobdup(struct curl_blob **dest, - struct curl_blob *src) +static CURLcode blobdup(struct curl_blob **dest, struct curl_blob *src) { DEBUGASSERT(dest); DEBUGASSERT(!*dest); if(src) { /* only if there is data to dupe! */ struct curl_blob *d; - d = malloc(sizeof(struct curl_blob) + src->len); + d = curlx_malloc(sizeof(struct curl_blob) + src->len); if(!d) return CURLE_OUT_OF_MEMORY; d->len = src->len; @@ -150,22 +141,28 @@ static const struct alpn_spec ALPN_SPEC_H2 = { static const struct alpn_spec ALPN_SPEC_H2_H11 = { { ALPN_H2, ALPN_HTTP_1_1 }, 2 }; +static const struct alpn_spec ALPN_SPEC_H11_H2 = { + { ALPN_HTTP_1_1, ALPN_H2 }, 2 +}; #endif #if !defined(CURL_DISABLE_HTTP) || !defined(CURL_DISABLE_PROXY) -static const struct alpn_spec * -alpn_get_spec(http_majors allowed, bool use_alpn) +static const struct alpn_spec *alpn_get_spec(http_majors wanted, + http_majors preferred, + bool use_alpn) { if(!use_alpn) return NULL; #ifdef USE_HTTP2 - if(allowed & CURL_HTTP_V2x) { - if(allowed & CURL_HTTP_V1x) - return &ALPN_SPEC_H2_H11; + if(wanted & CURL_HTTP_V2x) { + if(wanted & CURL_HTTP_V1x) + return (preferred == CURL_HTTP_V1x) ? + &ALPN_SPEC_H11_H2 : &ALPN_SPEC_H2_H11; return &ALPN_SPEC_H2; } #else - (void)allowed; + (void)wanted; + (void)preferred; #endif /* Use the ALPN protocol "http/1.1" for HTTP/1.x. Avoid "http/1.0" because some servers do not support it. */ @@ -174,7 +171,6 @@ alpn_get_spec(http_majors allowed, bool use_alpn) #endif /* !CURL_DISABLE_HTTP || !CURL_DISABLE_PROXY */ #endif /* USE_SSL */ - void Curl_ssl_easy_config_init(struct Curl_easy *data) { /* @@ -189,10 +185,9 @@ void Curl_ssl_easy_config_init(struct Curl_easy *data) #endif } -static bool -match_ssl_primary_config(struct Curl_easy *data, - struct ssl_primary_config *c1, - struct ssl_primary_config *c2) +static bool match_ssl_primary_config(struct Curl_easy *data, + struct ssl_primary_config *c1, + struct ssl_primary_config *c2) { (void)data; if((c1->version == c2->version) && @@ -310,7 +305,6 @@ CURLcode Curl_ssl_easy_config_complete(struct Curl_easy *data) if(result) return result; } - sslc->primary.CApath = data->set.str[STRING_SSL_CAPATH]; #endif #ifdef CURL_CA_BUNDLE if(!sslc->custom_cafile && !set->str[STRING_SSL_CAFILE]) { @@ -322,14 +316,14 @@ CURLcode Curl_ssl_easy_config_complete(struct Curl_easy *data) } sslc->primary.CAfile = data->set.str[STRING_SSL_CAFILE]; sslc->primary.CRLfile = data->set.str[STRING_SSL_CRLFILE]; + sslc->primary.CApath = data->set.str[STRING_SSL_CAPATH]; sslc->primary.issuercert = data->set.str[STRING_SSL_ISSUERCERT]; sslc->primary.issuercert_blob = data->set.blobs[BLOB_SSL_ISSUERCERT]; sslc->primary.cipher_list = data->set.str[STRING_SSL_CIPHER_LIST]; sslc->primary.cipher_list13 = data->set.str[STRING_SSL_CIPHER13_LIST]; sslc->primary.signature_algorithms = data->set.str[STRING_SSL_SIGNATURE_ALGORITHMS]; - sslc->primary.pinned_key = - data->set.str[STRING_SSL_PINNEDPUBLICKEY]; + sslc->primary.pinned_key = data->set.str[STRING_SSL_PINNEDPUBLICKEY]; sslc->primary.cert_blob = data->set.blobs[BLOB_CERT]; sslc->primary.ca_info_blob = data->set.blobs[BLOB_CAINFO]; sslc->primary.curves = data->set.str[STRING_SSL_EC_CURVES]; @@ -358,7 +352,6 @@ CURLcode Curl_ssl_easy_config_complete(struct Curl_easy *data) if(result) return result; } - sslc->primary.CApath = data->set.str[STRING_SSL_CAPATH_PROXY]; #endif #ifdef CURL_CA_BUNDLE if(!sslc->custom_cafile && !set->str[STRING_SSL_CAFILE_PROXY]) { @@ -370,6 +363,7 @@ CURLcode Curl_ssl_easy_config_complete(struct Curl_easy *data) #endif } sslc->primary.CAfile = data->set.str[STRING_SSL_CAFILE_PROXY]; + sslc->primary.CApath = data->set.str[STRING_SSL_CAPATH_PROXY]; sslc->primary.cipher_list = data->set.str[STRING_SSL_CIPHER_LIST_PROXY]; sslc->primary.cipher_list13 = data->set.str[STRING_SSL_CIPHER13_LIST_PROXY]; sslc->primary.pinned_key = data->set.str[STRING_SSL_PINNEDPUBLICKEY_PROXY]; @@ -503,16 +497,16 @@ static struct ssl_connect_data *cf_ctx_new(struct Curl_easy *data, struct ssl_connect_data *ctx; (void)data; - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) return NULL; ctx->ssl_impl = Curl_ssl; ctx->alpn = alpn; Curl_bufq_init2(&ctx->earlydata, CURL_SSL_EARLY_MAX, 1, BUFQ_OPT_NO_SPARES); - ctx->backend = calloc(1, ctx->ssl_impl->sizeof_ssl_backend_data); + ctx->backend = curlx_calloc(1, ctx->ssl_impl->sizeof_ssl_backend_data); if(!ctx->backend) { - free(ctx); + curlx_free(ctx); return NULL; } return ctx; @@ -523,8 +517,8 @@ static void cf_ctx_free(struct ssl_connect_data *ctx) if(ctx) { Curl_safefree(ctx->negotiated.alpn); Curl_bufq_free(&ctx->earlydata); - free(ctx->backend); - free(ctx); + curlx_free(ctx->backend); + curlx_free(ctx); } } @@ -542,9 +536,9 @@ void Curl_ssl_close_all(struct Curl_easy *data) Curl_ssl->close_all(data); } -CURLcode Curl_ssl_adjust_pollset(struct Curl_cfilter *cf, - struct Curl_easy *data, - struct easy_pollset *ps) +CURLcode Curl_ssl_adjust_pollset(struct Curl_cfilter *cf, + struct Curl_easy *data, + struct easy_pollset *ps) { struct ssl_connect_data *connssl = cf->ctx; @@ -617,7 +611,7 @@ void Curl_ssl_free_certinfo(struct Curl_easy *data) ci->certinfo[i] = NULL; } - free(ci->certinfo); /* free the actual array too */ + curlx_free(ci->certinfo); /* free the actual array too */ ci->certinfo = NULL; ci->num_of_certs = 0; } @@ -632,7 +626,7 @@ CURLcode Curl_ssl_init_certinfo(struct Curl_easy *data, int num) Curl_ssl_free_certinfo(data); /* Allocate the required certificate information structures */ - table = calloc((size_t) num, sizeof(struct curl_slist *)); + table = curlx_calloc((size_t)num, sizeof(struct curl_slist *)); if(!table) return CURLE_OUT_OF_MEMORY; @@ -665,8 +659,7 @@ CURLcode Curl_ssl_push_certinfo_len(struct Curl_easy *data, curlx_dyn_addn(&build, value, valuelen)) return CURLE_OUT_OF_MEMORY; - nl = Curl_slist_append_nodup(ci->certinfo[certnum], - curlx_dyn_ptr(&build)); + nl = Curl_slist_append_nodup(ci->certinfo[certnum], curlx_dyn_ptr(&build)); if(!nl) { curlx_dyn_free(&build); curl_slist_free_all(ci->certinfo[certnum]); @@ -772,8 +765,9 @@ CURLcode Curl_pin_peer_pubkey(struct Curl_easy *data, /* only do this if pinnedpubkey starts with "sha256//", length 8 */ if(!strncmp(pinnedpubkey, "sha256//", 8)) { CURLcode encode; - size_t encodedlen = 0; - char *encoded = NULL, *pinkeycopy, *begin_pos, *end_pos; + char *cert_hash = NULL; + const char *pinned_hash, *end_pos; + size_t cert_hash_len = 0, pinned_hash_len; unsigned char *sha256sumdigest; if(!Curl_ssl->sha256sum) { @@ -782,58 +776,45 @@ CURLcode Curl_pin_peer_pubkey(struct Curl_easy *data, } /* compute sha256sum of public key */ - sha256sumdigest = malloc(CURL_SHA256_DIGEST_LENGTH); + sha256sumdigest = curlx_malloc(CURL_SHA256_DIGEST_LENGTH); if(!sha256sumdigest) return CURLE_OUT_OF_MEMORY; encode = Curl_ssl->sha256sum(pubkey, pubkeylen, sha256sumdigest, CURL_SHA256_DIGEST_LENGTH); if(!encode) - encode = curlx_base64_encode((char *)sha256sumdigest, - CURL_SHA256_DIGEST_LENGTH, &encoded, - &encodedlen); + encode = curlx_base64_encode(sha256sumdigest, + CURL_SHA256_DIGEST_LENGTH, + &cert_hash, &cert_hash_len); Curl_safefree(sha256sumdigest); if(encode) return encode; - infof(data, " public key hash: sha256//%s", encoded); + infof(data, " public key hash: sha256//%s", cert_hash); - /* it starts with sha256//, copy so we can modify it */ - pinkeycopy = strdup(pinnedpubkey); - if(!pinkeycopy) { - Curl_safefree(encoded); - return CURLE_OUT_OF_MEMORY; - } - /* point begin_pos to the copy, and start extracting keys */ - begin_pos = pinkeycopy; - do { - end_pos = strstr(begin_pos, ";sha256//"); - /* - * if there is an end_pos, null-terminate, otherwise it will go to the - * end of the original string - */ - if(end_pos) - end_pos[0] = '\0'; - - /* compare base64 sha256 digests, 8 is the length of "sha256//" */ - if(encodedlen == strlen(begin_pos + 8) && - !memcmp(encoded, begin_pos + 8, encodedlen)) { + pinned_hash = pinnedpubkey; + while(pinned_hash && + !strncmp(pinned_hash, "sha256//", (sizeof("sha256//") - 1))) { + pinned_hash = pinned_hash + (sizeof("sha256//") - 1); + end_pos = strchr(pinned_hash, ';'); + pinned_hash_len = end_pos ? + (size_t)(end_pos - pinned_hash) : strlen(pinned_hash); + + /* compare base64 sha256 digests" */ + if(cert_hash_len == pinned_hash_len && + !memcmp(cert_hash, pinned_hash, cert_hash_len)) { + DEBUGF(infof(data, "public key hash matches pinned value")); result = CURLE_OK; break; } - /* - * change back the null-terminator we changed earlier, - * and look for next begin - */ - if(end_pos) { - end_pos[0] = ';'; - begin_pos = strstr(end_pos, "sha256//"); - } - } while(end_pos && begin_pos); - Curl_safefree(encoded); - Curl_safefree(pinkeycopy); + DEBUGF(infof(data, "public key hash does not match 'sha256//%.*s'", + (int)pinned_hash_len, pinned_hash)); + /* next one or we are at the end */ + pinned_hash = end_pos ? (end_pos + 1) : NULL; + } + Curl_safefree(cert_hash); } else { long filesize; @@ -861,7 +842,7 @@ CURLcode Curl_pin_peer_pubkey(struct Curl_easy *data, * if the size of our certificate is bigger than the file * size then it cannot match */ - size = curlx_sotouz((curl_off_t) filesize); + size = curlx_sotouz((curl_off_t)filesize); if(pubkeylen > size) goto end; @@ -1101,10 +1082,7 @@ static size_t multissl_version(char *buffer, size_t size) } if(size) { - if(backends_len < size) - strcpy(buffer, backends); - else - *buffer = 0; /* did not fit */ + curlx_strcopy(buffer, size, backends, backends_len); } return 0; } @@ -1130,7 +1108,7 @@ static int multissl_setup(const struct Curl_ssl *backend) for(i = 0; available_backends[i]; i++) { if(curl_strequal(env, available_backends[i]->info.name)) { Curl_ssl = available_backends[i]; - free(env); + curlx_free(env); return 0; } } @@ -1141,7 +1119,7 @@ static int multissl_setup(const struct Curl_ssl *backend) if(curl_strequal(CURL_DEFAULT_SSL_BACKEND, available_backends[i]->info.name)) { Curl_ssl = available_backends[i]; - free(env); + curlx_free(env); return 0; } } @@ -1149,7 +1127,7 @@ static int multissl_setup(const struct Curl_ssl *backend) /* Fall back to first available backend */ Curl_ssl = available_backends[0]; - free(env); + curlx_free(env); return 0; } @@ -1202,7 +1180,7 @@ void Curl_ssl_peer_cleanup(struct ssl_peer *peer) { Curl_safefree(peer->sni); if(peer->dispname != peer->hostname) - free(peer->dispname); + curlx_free(peer->dispname); peer->dispname = NULL; Curl_safefree(peer->hostname); Curl_safefree(peer->scache_key); @@ -1278,13 +1256,13 @@ CURLcode Curl_ssl_peer_init(struct ssl_peer *peer, goto out; } - peer->hostname = strdup(ehostname); + peer->hostname = curlx_strdup(ehostname); if(!peer->hostname) goto out; if(!edispname || !strcmp(ehostname, edispname)) peer->dispname = peer->hostname; else { - peer->dispname = strdup(edispname); + peer->dispname = curlx_strdup(edispname); if(!peer->dispname) goto out; } @@ -1293,10 +1271,10 @@ CURLcode Curl_ssl_peer_init(struct ssl_peer *peer, /* not an IP address, normalize according to RCC 6066 ch. 3, * max len of SNI is 2^16-1, no trailing dot */ size_t len = strlen(peer->hostname); - if(len && (peer->hostname[len-1] == '.')) + if(len && (peer->hostname[len - 1] == '.')) len--; if(len < USHRT_MAX) { - peer->sni = calloc(1, len + 1); + peer->sni = curlx_calloc(1, len + 1); if(!peer->sni) goto out; Curl_strntolower(peer->sni, peer->hostname, len); @@ -1385,8 +1363,9 @@ static CURLcode ssl_cf_connect(struct Curl_cfilter *cf, if(!result && *done) { cf->connected = TRUE; - if(connssl->state == ssl_connection_complete) - connssl->handshake_done = curlx_now(); + if(connssl->state == ssl_connection_complete) { + connssl->handshake_done = *Curl_pgrs_now(data); + } /* Connection can be deferred when sending early data */ DEBUGASSERT(connssl->state == ssl_connection_complete || connssl->state == ssl_connection_deferred); @@ -1435,7 +1414,7 @@ static CURLcode ssl_cf_connect_deferred(struct Curl_cfilter *cf, result = ssl_cf_set_earlydata(cf, data, buf, blen); if(result) return result; - /* we buffered any early data we'd like to send. Actually + /* we buffered any early data we would like to send. Actually * do the connect now which sends it and performs the handshake. */ connssl->earlydata_state = ssl_earlydata_sending; connssl->earlydata_skip = Curl_bufq_len(&connssl->earlydata); @@ -1489,7 +1468,7 @@ static bool ssl_cf_data_pending(struct Curl_cfilter *cf, static CURLcode ssl_cf_send(struct Curl_cfilter *cf, struct Curl_easy *data, - const void *buf, size_t blen, + const uint8_t *buf, size_t blen, bool eos, size_t *pnwritten) { struct ssl_connect_data *connssl = cf->ctx; @@ -1521,7 +1500,7 @@ static CURLcode ssl_cf_send(struct Curl_cfilter *cf, } else { *pnwritten = connssl->earlydata_skip; - buf = ((const char *)buf) + connssl->earlydata_skip; + buf = buf + connssl->earlydata_skip; blen -= connssl->earlydata_skip; connssl->earlydata_skip = 0; } @@ -1579,7 +1558,7 @@ static CURLcode ssl_cf_shutdown(struct Curl_cfilter *cf, *done = TRUE; /* If we have done the SSL handshake, shut down the connection cleanly */ if(cf->connected && (connssl->state == ssl_connection_complete) && - !cf->shutdown && Curl_ssl->shut_down) { + !cf->shutdown && Curl_ssl->shut_down) { struct cf_call_data save; CF_DATA_SAVE(save, cf, data); @@ -1739,6 +1718,7 @@ static CURLcode cf_ssl_create(struct Curl_cfilter **pcf, ctx = cf_ctx_new(data, NULL); #else ctx = cf_ctx_new(data, alpn_get_spec(data->state.http_neg.wanted, + data->state.http_neg.preferred, conn->bits.tls_enable_alpn)); #endif if(!ctx) { @@ -1791,17 +1771,17 @@ static CURLcode cf_ssl_proxy_create(struct Curl_cfilter **pcf, CURLcode result; /* ALPN is default, but if user explicitly disables it, obey */ bool use_alpn = data->set.ssl_enable_alpn; - http_majors allowed = CURL_HTTP_V1x; + http_majors wanted = CURL_HTTP_V1x; (void)conn; #ifdef USE_HTTP2 if(conn->http_proxy.proxytype == CURLPROXY_HTTPS2) { use_alpn = TRUE; - allowed = (CURL_HTTP_V1x|CURL_HTTP_V2x); + wanted = (CURL_HTTP_V1x | CURL_HTTP_V2x); } #endif - ctx = cf_ctx_new(data, alpn_get_spec(allowed, use_alpn)); + ctx = cf_ctx_new(data, alpn_get_spec(wanted, 0, use_alpn)); if(!ctx) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -1853,7 +1833,7 @@ static CURLcode vtls_shutdown_blocking(struct Curl_cfilter *cf, *done = FALSE; while(!result && !*done && loop--) { - timeout_ms = Curl_shutdown_timeleft(cf->conn, cf->sockindex, NULL); + timeout_ms = Curl_shutdown_timeleft(data, cf->conn, cf->sockindex); if(timeout_ms < 0) { /* no need to continue if time is already up */ @@ -1863,7 +1843,7 @@ static CURLcode vtls_shutdown_blocking(struct Curl_cfilter *cf, } result = connssl->ssl_impl->shut_down(cf, data, send_shutdown, done); - if(result ||*done) + if(result || *done) goto out; if(connssl->io_need) { @@ -1900,7 +1880,7 @@ CURLcode Curl_ssl_cfilter_remove(struct Curl_easy *data, if(cf->cft == &Curl_cft_ssl) { bool done; CURL_TRC_CF(data, cf, "shutdown and remove SSL, start"); - Curl_shutdown_start(data, sockindex, 0, NULL); + Curl_shutdown_start(data, sockindex, 0); result = vtls_shutdown_blocking(cf, data, send_shutdown, &done); Curl_shutdown_clear(data, sockindex); if(!result && !done) /* blocking failed? */ @@ -1952,7 +1932,7 @@ CURLcode Curl_alpn_to_proto_buf(struct alpn_proto_buf *buf, len = strlen(spec->entries[i]); if(len >= ALPN_NAME_MAX) return CURLE_FAILED_INIT; - blen = (unsigned char)len; + blen = (unsigned char)len; if(off + blen + 1 >= (int)sizeof(buf->data)) return CURLE_FAILED_INIT; buf->data[off++] = blen; @@ -2058,7 +2038,7 @@ CURLcode Curl_alpn_set_negotiated(struct Curl_cfilter *cf, if(proto && proto_len) { if(memchr(proto, '\0', proto_len)) { failf(data, "ALPN: server selected protocol contains NUL. " - "Refusing to continue."); + "Refusing to continue."); result = CURLE_SSL_CONNECT_ERROR; goto out; } diff --git a/vendor/hydra/vendor/curl/lib/vtls/vtls.h b/vendor/hydra/vendor/curl/lib/vtls/vtls.h index 180333e6..112681ae 100644 --- a/vendor/hydra/vendor/curl/lib/vtls/vtls.h +++ b/vendor/hydra/vendor/curl/lib/vtls/vtls.h @@ -32,24 +32,22 @@ struct Curl_cfilter; struct Curl_easy; struct dynbuf; -#define SSLSUPP_CA_PATH (1<<0) /* supports CAPATH */ -#define SSLSUPP_CERTINFO (1<<1) /* supports CURLOPT_CERTINFO */ -#define SSLSUPP_PINNEDPUBKEY (1<<2) /* supports CURLOPT_PINNEDPUBLICKEY */ -#define SSLSUPP_SSL_CTX (1<<3) /* supports CURLOPT_SSL_CTX */ -#define SSLSUPP_HTTPS_PROXY (1<<4) /* supports access via HTTPS proxies */ -#define SSLSUPP_TLS13_CIPHERSUITES (1<<5) /* supports TLS 1.3 ciphersuites */ -#define SSLSUPP_CAINFO_BLOB (1<<6) -#define SSLSUPP_ECH (1<<7) -#define SSLSUPP_CA_CACHE (1<<8) -#define SSLSUPP_CIPHER_LIST (1<<9) /* supports TLS 1.0-1.2 ciphersuites */ -#define SSLSUPP_SIGNATURE_ALGORITHMS (1<<10) /* supports TLS sigalgs */ +#define SSLSUPP_CA_PATH (1 << 0) /* supports CAPATH */ +#define SSLSUPP_CERTINFO (1 << 1) /* supports CURLOPT_CERTINFO */ +#define SSLSUPP_PINNEDPUBKEY (1 << 2) /* supports CURLOPT_PINNEDPUBLICKEY */ +#define SSLSUPP_SSL_CTX (1 << 3) /* supports CURLOPT_SSL_CTX */ +#define SSLSUPP_HTTPS_PROXY (1 << 4) /* supports access via HTTPS proxies */ +#define SSLSUPP_TLS13_CIPHERSUITES (1 << 5) /* supports TLS 1.3 ciphersuites */ +#define SSLSUPP_CAINFO_BLOB (1 << 6) +#define SSLSUPP_ECH (1 << 7) +#define SSLSUPP_CA_CACHE (1 << 8) +#define SSLSUPP_CIPHER_LIST (1 << 9) /* supports TLS 1.0-1.2 ciphersuites */ +#define SSLSUPP_SIGNATURE_ALGORITHMS (1 << 10) /* supports TLS sigalgs */ #ifdef USE_ECH # include "../curlx/base64.h" # define ECH_ENABLED(__data__) \ - (__data__->set.tls_ech && \ - !(__data__->set.tls_ech & CURLECH_DISABLE)\ - ) + (__data__->set.tls_ech && !(__data__->set.tls_ech & CURLECH_DISABLE)) #endif /* USE_ECH */ #define ALPN_ACCEPTED "ALPN: server accepted " @@ -96,7 +94,7 @@ CURLsslset Curl_init_sslset_nolock(curl_sslbackend id, const char *name, const curl_ssl_backend ***avail); #ifndef MAX_PINNED_PUBKEY_SIZE -#define MAX_PINNED_PUBKEY_SIZE 1048576 /* 1MB */ +#define MAX_PINNED_PUBKEY_SIZE 1048576 /* 1 MiB */ #endif curl_sslbackend Curl_ssl_backend(void); @@ -165,6 +163,7 @@ void Curl_ssl_version(char *buffer, size_t size); /* Certificate information list handling. */ #define CURL_X509_STR_MAX 100000 +#define MAX_ALLOWED_CERT_AMOUNT 100 void Curl_ssl_free_certinfo(struct Curl_easy *data); CURLcode Curl_ssl_init_certinfo(struct Curl_easy *data, int num); @@ -252,16 +251,16 @@ extern struct Curl_cftype Curl_cft_ssl_proxy; #define Curl_ssl_init() 1 #define Curl_ssl_cleanup() Curl_nop_stmt #define Curl_ssl_close_all(x) Curl_nop_stmt -#define Curl_ssl_set_engine(x,y) CURLE_NOT_BUILT_IN +#define Curl_ssl_set_engine(x, y) CURLE_NOT_BUILT_IN #define Curl_ssl_set_engine_default(x) CURLE_NOT_BUILT_IN #define Curl_ssl_engines_list(x) NULL #define Curl_ssl_free_certinfo(x) Curl_nop_stmt -#define Curl_ssl_random(x,y,z) ((void)x, CURLE_NOT_BUILT_IN) +#define Curl_ssl_random(x, y, z) ((void)x, CURLE_NOT_BUILT_IN) #define Curl_ssl_cert_status_request() FALSE -#define Curl_ssl_supports(a,b) FALSE -#define Curl_ssl_cfilter_add(a,b,c) CURLE_NOT_BUILT_IN -#define Curl_ssl_cfilter_remove(a,b,c) CURLE_OK -#define Curl_ssl_cf_get_config(a,b) NULL +#define Curl_ssl_supports(a, b) FALSE +#define Curl_ssl_cfilter_add(a, b, c) CURLE_NOT_BUILT_IN +#define Curl_ssl_cfilter_remove(a, b, c) CURLE_OK +#define Curl_ssl_cf_get_config(a, b) NULL #define Curl_ssl_cf_get_primary_config(a) NULL #endif diff --git a/vendor/hydra/vendor/curl/lib/vtls/vtls_int.h b/vendor/hydra/vendor/curl/lib/vtls/vtls_int.h index 8bf6c6c6..ec72b647 100644 --- a/vendor/hydra/vendor/curl/lib/vtls/vtls_int.h +++ b/vendor/hydra/vendor/curl/lib/vtls/vtls_int.h @@ -24,7 +24,9 @@ * ***************************************************************************/ #include "../curl_setup.h" + #include "../cfilters.h" +#include "../select.h" #include "../urldata.h" #include "vtls.h" @@ -71,8 +73,7 @@ CURLcode Curl_alpn_set_negotiated(struct Curl_cfilter *cf, const unsigned char *proto, size_t proto_len); -bool Curl_alpn_contains_proto(const struct alpn_spec *spec, - const char *proto); +bool Curl_alpn_contains_proto(const struct alpn_spec *spec, const char *proto); /* enum for the nonblocking SSL connection state machine */ typedef enum { @@ -99,11 +100,11 @@ typedef enum { } ssl_earlydata_state; #define CURL_SSL_IO_NEED_NONE (0) -#define CURL_SSL_IO_NEED_RECV (1<<0) -#define CURL_SSL_IO_NEED_SEND (1<<1) +#define CURL_SSL_IO_NEED_RECV (1 << 0) +#define CURL_SSL_IO_NEED_SEND (1 << 1) /* Max earlydata payload we want to send */ -#define CURL_SSL_EARLY_MAX (64*1024) +#define CURL_SSL_EARLY_MAX (64 * 1024) /* Information in each SSL cfilter context: cf->ctx */ struct ssl_connect_data { @@ -124,17 +125,13 @@ struct ssl_connect_data { ssl_connect_state connecting_state; ssl_earlydata_state earlydata_state; int io_need; /* TLS signals special SEND/RECV needs */ - BIT(use_alpn); /* if ALPN shall be used in handshake */ BIT(peer_closed); /* peer has closed connection */ BIT(prefs_checked); /* SSL preferences have been checked */ BIT(input_pending); /* data for SSL_read() may be available */ }; - #undef CF_CTX_CALL_DATA -#define CF_CTX_CALL_DATA(cf) \ - ((struct ssl_connect_data *)(cf)->ctx)->call_data - +#define CF_CTX_CALL_DATA(cf) ((struct ssl_connect_data *)(cf)->ctx)->call_data /* Definitions for SSL Implementations */ @@ -157,8 +154,7 @@ struct Curl_ssl { /* data_pending() shall return TRUE when it wants to get called again to drain internal buffers and deliver data instead of waiting for the socket to get readable */ - bool (*data_pending)(struct Curl_cfilter *cf, - const struct Curl_easy *data); + bool (*data_pending)(struct Curl_cfilter *cf, const struct Curl_easy *data); /* return 0 if a find random is filled in */ CURLcode (*random)(struct Curl_easy *data, unsigned char *entropy, @@ -181,7 +177,7 @@ struct Curl_ssl { struct curl_slist *(*engines_list)(struct Curl_easy *data); CURLcode (*sha256sum)(const unsigned char *input, size_t inputlen, - unsigned char *sha256sum, size_t sha256sumlen); + unsigned char *sha256sum, size_t sha256sumlen); CURLcode (*recv_plain)(struct Curl_cfilter *cf, struct Curl_easy *data, char *buf, size_t len, size_t *pnread); CURLcode (*send_plain)(struct Curl_cfilter *cf, struct Curl_easy *data, @@ -189,7 +185,6 @@ struct Curl_ssl { CURLcode (*get_channel_binding)(struct Curl_easy *data, int sockindex, struct dynbuf *binding); - }; extern const struct Curl_ssl *Curl_ssl; diff --git a/vendor/hydra/vendor/curl/lib/vtls/vtls_scache.c b/vendor/hydra/vendor/curl/lib/vtls/vtls_scache.c index b9abc6e3..df04ec7e 100644 --- a/vendor/hydra/vendor/curl/lib/vtls/vtls_scache.c +++ b/vendor/hydra/vendor/curl/lib/vtls/vtls_scache.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "../curl_setup.h" #ifdef USE_SSL @@ -41,15 +40,10 @@ #include "../strcase.h" #include "../url.h" #include "../llist.h" -#include "../share.h" +#include "../curl_share.h" #include "../curl_trc.h" #include "../curl_sha256.h" #include "../rand.h" -#include "../curlx/warnless.h" - -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" static bool cf_ssl_peer_key_is_global(const char *peer_key); @@ -104,42 +98,40 @@ static void cf_ssl_scache_session_ldestroy(void *udata, void *obj) { struct Curl_ssl_session *s = obj; (void)udata; - free(CURL_UNCONST(s->sdata)); - free(CURL_UNCONST(s->quic_tp)); - free((void *)s->alpn); - free(s); + curlx_free(CURL_UNCONST(s->sdata)); + curlx_free(CURL_UNCONST(s->quic_tp)); + curlx_free((void *)s->alpn); + curlx_free(s); } -CURLcode -Curl_ssl_session_create(void *sdata, size_t sdata_len, - int ietf_tls_id, const char *alpn, - curl_off_t valid_until, size_t earlydata_max, - struct Curl_ssl_session **psession) +CURLcode Curl_ssl_session_create(void *sdata, size_t sdata_len, + int ietf_tls_id, const char *alpn, + curl_off_t valid_until, size_t earlydata_max, + struct Curl_ssl_session **psession) { return Curl_ssl_session_create2(sdata, sdata_len, ietf_tls_id, alpn, valid_until, earlydata_max, NULL, 0, psession); } -CURLcode -Curl_ssl_session_create2(void *sdata, size_t sdata_len, - int ietf_tls_id, const char *alpn, - curl_off_t valid_until, size_t earlydata_max, - unsigned char *quic_tp, size_t quic_tp_len, - struct Curl_ssl_session **psession) +CURLcode Curl_ssl_session_create2(void *sdata, size_t sdata_len, + int ietf_tls_id, const char *alpn, + curl_off_t valid_until, size_t earlydata_max, + unsigned char *quic_tp, size_t quic_tp_len, + struct Curl_ssl_session **psession) { struct Curl_ssl_session *s; if(!sdata || !sdata_len) { - free(sdata); + curlx_free(sdata); return CURLE_BAD_FUNCTION_ARGUMENT; } *psession = NULL; - s = calloc(1, sizeof(*s)); + s = curlx_calloc(1, sizeof(*s)); if(!s) { - free(sdata); - free(quic_tp); + curlx_free(sdata); + curlx_free(quic_tp); return CURLE_OUT_OF_MEMORY; } @@ -151,7 +143,7 @@ Curl_ssl_session_create2(void *sdata, size_t sdata_len, s->quic_tp = quic_tp; s->quic_tp_len = quic_tp_len; if(alpn) { - s->alpn = strdup(alpn); + s->alpn = curlx_strdup(alpn); if(!s->alpn) { cf_ssl_scache_session_ldestroy(NULL, s); return CURLE_OUT_OF_MEMORY; @@ -231,7 +223,7 @@ cf_ssl_scache_peer_init(struct Curl_ssl_scache_peer *peer, DEBUGASSERT(!peer->ssl_peer_key); if(ssl_peer_key) { - peer->ssl_peer_key = strdup(ssl_peer_key); + peer->ssl_peer_key = curlx_strdup(ssl_peer_key); if(!peer->ssl_peer_key) goto out; peer->hmac_set = FALSE; @@ -246,17 +238,17 @@ cf_ssl_scache_peer_init(struct Curl_ssl_scache_peer *peer, goto out; } if(clientcert) { - peer->clientcert = strdup(clientcert); + peer->clientcert = curlx_strdup(clientcert); if(!peer->clientcert) goto out; } if(srp_username) { - peer->srp_username = strdup(srp_username); + peer->srp_username = curlx_strdup(srp_username); if(!peer->srp_username) goto out; } if(srp_password) { - peer->srp_password = strdup(srp_password); + peer->srp_password = curlx_strdup(srp_password); if(!peer->srp_password) goto out; } @@ -315,18 +307,18 @@ CURLcode Curl_ssl_scache_create(size_t max_peers, size_t i; *pscache = NULL; - peers = calloc(max_peers, sizeof(*peers)); + peers = curlx_calloc(max_peers, sizeof(*peers)); if(!peers) return CURLE_OUT_OF_MEMORY; - scache = calloc(1, sizeof(*scache)); + scache = curlx_calloc(1, sizeof(*scache)); if(!scache) { - free(peers); + curlx_free(peers); return CURLE_OUT_OF_MEMORY; } scache->magic = CURL_SCACHE_MAGIC; - scache->default_lifetime_secs = (24*60*60); /* 1 day */ + scache->default_lifetime_secs = (24 * 60 * 60); /* 1 day */ scache->peer_count = max_peers; scache->peers = peers; scache->age = 1; @@ -348,8 +340,8 @@ void Curl_ssl_scache_destroy(struct Curl_ssl_scache *scache) for(i = 0; i < scache->peer_count; ++i) { cf_ssl_scache_clear_peer(&scache->peers[i]); } - free(scache->peers); - free(scache); + curlx_free(scache->peers); + curlx_free(scache); } } @@ -386,10 +378,7 @@ static CURLcode cf_ssl_peer_key_add_path(struct dynbuf *buf, * valid when used in another process with different CWD. However, * when a path does not exist, this does not work. Then, we add * the path as is. */ -#ifdef UNDER_CE - (void)is_local; - return curlx_dyn_addf(buf, ":%s-%s", name, path); -#elif defined(_WIN32) +#ifdef _WIN32 char abspath[_MAX_PATH]; if(_fullpath(abspath, path, _MAX_PATH)) return curlx_dyn_addf(buf, ":%s-%s", name, abspath); @@ -399,7 +388,8 @@ static CURLcode cf_ssl_peer_key_add_path(struct dynbuf *buf, char *abspath = realpath(path, NULL); if(abspath) { CURLcode r = curlx_dyn_addf(buf, ":%s-%s", name, abspath); - (free)(abspath); /* allocated by libc, free without memdebug */ + /* !checksrc! disable BANNEDFUNC 1 */ + free(abspath); /* allocated by libc, free without memdebug */ return r; } *is_local = TRUE; @@ -513,7 +503,7 @@ CURLcode Curl_ssl_peer_key_make(struct Curl_cfilter *cf, if(ssl->version || ssl->version_max) { r = curlx_dyn_addf(&buf, ":TLSVER-%d-%d", ssl->version, - (ssl->version_max >> 16)); + (ssl->version_max >> 16)); if(r) goto out; } @@ -622,19 +612,18 @@ static bool cf_ssl_scache_match_auth(struct Curl_ssl_scache_peer *peer, else if(!Curl_safecmp(peer->clientcert, conn_config->clientcert)) return FALSE; #ifdef USE_TLS_SRP - if(Curl_timestrcmp(peer->srp_username, conn_config->username) || - Curl_timestrcmp(peer->srp_password, conn_config->password)) - return FALSE; + if(Curl_timestrcmp(peer->srp_username, conn_config->username) || + Curl_timestrcmp(peer->srp_password, conn_config->password)) + return FALSE; #endif return TRUE; } -static CURLcode -cf_ssl_find_peer_by_key(struct Curl_easy *data, - struct Curl_ssl_scache *scache, - const char *ssl_peer_key, - struct ssl_primary_config *conn_config, - struct Curl_ssl_scache_peer **ppeer) +static CURLcode cf_ssl_find_peer_by_key(struct Curl_easy *data, + struct Curl_ssl_scache *scache, + const char *ssl_peer_key, + struct ssl_primary_config *conn_config, + struct Curl_ssl_scache_peer **ppeer) { size_t i, peer_key_len = 0; CURLcode result = CURLE_OK; @@ -678,7 +667,7 @@ cf_ssl_find_peer_by_key(struct Curl_easy *data, /* remember peer_key for future lookups */ CURL_TRC_SSLS(data, "peer entry %zu key recovered: %s", i, ssl_peer_key); - scache->peers[i].ssl_peer_key = strdup(ssl_peer_key); + scache->peers[i].ssl_peer_key = curlx_strdup(ssl_peer_key); if(!scache->peers[i].ssl_peer_key) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -724,12 +713,11 @@ cf_ssl_get_free_peer(struct Curl_ssl_scache *scache) return peer; } -static CURLcode -cf_ssl_add_peer(struct Curl_easy *data, - struct Curl_ssl_scache *scache, - const char *ssl_peer_key, - struct ssl_primary_config *conn_config, - struct Curl_ssl_scache_peer **ppeer) +static CURLcode cf_ssl_add_peer(struct Curl_easy *data, + struct Curl_ssl_scache *scache, + const char *ssl_peer_key, + struct ssl_primary_config *conn_config, + struct Curl_ssl_scache_peer **ppeer) { struct Curl_ssl_scache_peer *peer = NULL; CURLcode result = CURLE_OK; @@ -1006,7 +994,7 @@ void Curl_ssl_scache_remove_all(struct Curl_cfilter *cf, #ifdef USE_SSLS_EXPORT -#define CURL_SSL_TICKET_MAX (16*1024) +#define CURL_SSL_TICKET_MAX (16 * 1024) static CURLcode cf_ssl_scache_peer_set_hmac(struct Curl_ssl_scache_peer *peer) { diff --git a/vendor/hydra/vendor/curl/lib/vtls/vtls_scache.h b/vendor/hydra/vendor/curl/lib/vtls/vtls_scache.h index 445f2105..2a99e779 100644 --- a/vendor/hydra/vendor/curl/lib/vtls/vtls_scache.h +++ b/vendor/hydra/vendor/curl/lib/vtls/vtls_scache.h @@ -24,6 +24,7 @@ * ***************************************************************************/ #include "../curl_setup.h" + #include "../cfilters.h" #include "../urldata.h" @@ -37,8 +38,8 @@ struct ssl_peer; /* RFC 8446 (TLSv1.3) restrict lifetime to one week max, for * other, less secure versions, we restrict it to a day */ -#define CURL_SCACHE_MAX_13_LIFETIME_SEC (60*60*24*7) -#define CURL_SCACHE_MAX_12_LIFETIME_SEC (60*60*24) +#define CURL_SCACHE_MAX_13_LIFETIME_SEC (60 * 60 * 24 * 7) +#define CURL_SCACHE_MAX_12_LIFETIME_SEC (60 * 60 * 24) /* Create a session cache for up to max_peers endpoints with a total * of up to max_sessions SSL sessions per peer */ @@ -142,22 +143,18 @@ struct Curl_ssl_session { * in case this is not known. * @param psession on return the scached session instance created */ -CURLcode -Curl_ssl_session_create(void *sdata, size_t sdata_len, - int ietf_tls_id, const char *alpn, - curl_off_t valid_until, - size_t earlydata_max, - struct Curl_ssl_session **psession); +CURLcode Curl_ssl_session_create(void *sdata, size_t sdata_len, + int ietf_tls_id, const char *alpn, + curl_off_t valid_until, size_t earlydata_max, + struct Curl_ssl_session **psession); /* Variation of session creation with quic transport parameter bytes, * Takes ownership of `quic_tp` regardless of return code. */ -CURLcode -Curl_ssl_session_create2(void *sdata, size_t sdata_len, - int ietf_tls_id, const char *alpn, - curl_off_t valid_until, - size_t earlydata_max, - unsigned char *quic_tp, size_t quic_tp_len, - struct Curl_ssl_session **psession); +CURLcode Curl_ssl_session_create2(void *sdata, size_t sdata_len, + int ietf_tls_id, const char *alpn, + curl_off_t valid_until, size_t earlydata_max, + unsigned char *quic_tp, size_t quic_tp_len, + struct Curl_ssl_session **psession); /* Destroy a `session` instance. Can be called with NULL. * Does NOT need locking. */ diff --git a/vendor/hydra/vendor/curl/lib/vtls/vtls_spack.c b/vendor/hydra/vendor/curl/lib/vtls/vtls_spack.c index 10d16f21..9eeb808b 100644 --- a/vendor/hydra/vendor/curl/lib/vtls/vtls_spack.c +++ b/vendor/hydra/vendor/curl/lib/vtls/vtls_spack.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "../curl_setup.h" #if defined(USE_SSL) && defined(USE_SSLS_EXPORT) @@ -32,21 +31,6 @@ #include "vtls_spack.h" #include "../strdup.h" -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - -#ifdef _MSC_VER -#if _MSC_VER >= 1600 -#include -#else -typedef unsigned char uint8_t; -typedef unsigned __int16 uint16_t; -typedef unsigned __int32 uint32_t; -typedef unsigned __int64 uint64_t; -#endif -#endif /* _MSC_VER */ - #ifndef UINT16_MAX #define UINT16_MAX 0xffff #endif @@ -67,8 +51,8 @@ static CURLcode spack_enc8(struct dynbuf *buf, uint8_t b) return curlx_dyn_addn(buf, &b, 1); } -static CURLcode -spack_dec8(uint8_t *val, const uint8_t **src, const uint8_t *end) +static CURLcode spack_dec8(uint8_t *val, const uint8_t **src, + const uint8_t *end) { if(end - *src < 1) return CURLE_READ_ERROR; @@ -85,8 +69,8 @@ static CURLcode spack_enc16(struct dynbuf *buf, uint16_t val) return curlx_dyn_addn(buf, nval, sizeof(nval)); } -static CURLcode -spack_dec16(uint16_t *val, const uint8_t **src, const uint8_t *end) +static CURLcode spack_dec16(uint16_t *val, const uint8_t **src, + const uint8_t *end) { if(end - *src < 2) return CURLE_READ_ERROR; @@ -105,8 +89,8 @@ static CURLcode spack_enc32(struct dynbuf *buf, uint32_t val) return curlx_dyn_addn(buf, nval, sizeof(nval)); } -static CURLcode -spack_dec32(uint32_t *val, const uint8_t **src, const uint8_t *end) +static CURLcode spack_dec32(uint32_t *val, const uint8_t **src, + const uint8_t *end) { if(end - *src < 4) return CURLE_READ_ERROR; @@ -122,7 +106,7 @@ static CURLcode spack_enc64(struct dynbuf *buf, uint64_t val) nval[0] = (uint8_t)(val >> 56); nval[1] = (uint8_t)(val >> 48); nval[2] = (uint8_t)(val >> 40); - nval[3] = (uint8_t)(val >> 32); \ + nval[3] = (uint8_t)(val >> 32); nval[4] = (uint8_t)(val >> 24); nval[5] = (uint8_t)(val >> 16); nval[6] = (uint8_t)(val >> 8); @@ -130,8 +114,8 @@ static CURLcode spack_enc64(struct dynbuf *buf, uint64_t val) return curlx_dyn_addn(buf, nval, sizeof(nval)); } -static CURLcode -spack_dec64(uint64_t *val, const uint8_t **src, const uint8_t *end) +static CURLcode spack_dec64(uint64_t *val, const uint8_t **src, + const uint8_t *end) { if(end - *src < 8) return CURLE_READ_ERROR; @@ -156,8 +140,8 @@ static CURLcode spack_encstr16(struct dynbuf *buf, const char *s) return r; } -static CURLcode -spack_decstr16(char **val, const uint8_t **src, const uint8_t *end) +static CURLcode spack_decstr16(char **val, const uint8_t **src, + const uint8_t *end) { uint16_t slen; CURLcode r; @@ -173,8 +157,8 @@ spack_decstr16(char **val, const uint8_t **src, const uint8_t *end) return *val ? CURLE_OK : CURLE_OUT_OF_MEMORY; } -static CURLcode spack_encdata16(struct dynbuf *buf, - const uint8_t *data, size_t data_len) +static CURLcode spack_encdata16(struct dynbuf *buf, const uint8_t *data, + size_t data_len) { CURLcode r; if(data_len > UINT16_MAX) @@ -186,9 +170,8 @@ static CURLcode spack_encdata16(struct dynbuf *buf, return r; } -static CURLcode -spack_decdata16(uint8_t **val, size_t *val_len, - const uint8_t **src, const uint8_t *end) +static CURLcode spack_decdata16(uint8_t **val, size_t *val_len, + const uint8_t **src, const uint8_t *end) { uint16_t data_len; CURLcode r; @@ -278,7 +261,7 @@ CURLcode Curl_ssl_session_unpack(struct Curl_easy *data, goto out; } - s = calloc(1, sizeof(*s)); + s = curlx_calloc(1, sizeof(*s)); if(!s) { r = CURLE_OUT_OF_MEMORY; goto out; diff --git a/vendor/hydra/vendor/curl/lib/vtls/wolfssl.c b/vendor/hydra/vendor/curl/lib/vtls/wolfssl.c index 9639709f..51037888 100644 --- a/vendor/hydra/vendor/curl/lib/vtls/wolfssl.c +++ b/vendor/hydra/vendor/curl/lib/vtls/wolfssl.c @@ -21,13 +21,11 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - /* * Source file for all wolfSSL specific code for the TLS/SSL layer. No code * but vtls.c should ever call or use these functions. * */ - #include "../curl_setup.h" #ifdef USE_WOLFSSL @@ -36,7 +34,6 @@ #include #include - #if LIBWOLFSSL_VERSION_HEX < 0x03004006 /* wolfSSL 3.4.6 (2015) */ #error "wolfSSL version should be at least 3.4.6" #endif @@ -54,35 +51,22 @@ #endif #endif -#include - #include "../urldata.h" -#include "../sendf.h" -#include "../curlx/inet_pton.h" +#include "../curl_trc.h" #include "vtls.h" #include "vtls_int.h" #include "vtls_scache.h" #include "keylog.h" -#include "../parsedate.h" #include "../connect.h" /* for the connect timeout */ #include "../progress.h" -#include "../select.h" #include "../strdup.h" +#include "../curlx/strcopy.h" #include "x509asn1.h" -#include "../multiif.h" #include #include #include "wolfssl.h" -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - -#ifdef HAVE_WOLFSSL_CTX_GENERATEECHCONFIG -#define USE_ECH_WOLFSSL -#endif - /* KEEP_PEER_CERT is a product of the presence of build time symbol OPENSSL_EXTRA without NO_CERTS, depending on the version. KEEP_PEER_CERT is in wolfSSL's settings.h, and the latter two are build time symbols in @@ -131,9 +115,9 @@ static CURLcode wssl_connect(struct Curl_cfilter *cf, * (--enable-opensslextra or --enable-all). */ #if defined(HAVE_SECRET_CALLBACK) && defined(WOLFSSL_TLS13) -static int -wssl_tls13_secret_callback(SSL *ssl, int id, const unsigned char *secret, - int secretSz, void *ctx) +static int wssl_tls13_secret_callback(SSL *ssl, int id, + const unsigned char *secret, + int secretSz, void *ctx) { const char *label; unsigned char client_random[SSL3_RANDOM_SIZE]; @@ -313,8 +297,7 @@ static long wssl_bio_cf_ctrl(WOLFSSL_BIO *bio, int cmd, long num, void *ptr) return ret; } -static int wssl_bio_cf_out_write(WOLFSSL_BIO *bio, - const char *buf, int blen) +static int wssl_bio_cf_out_write(WOLFSSL_BIO *bio, const char *buf, int blen) { struct Curl_cfilter *cf = wolfSSL_BIO_get_data(bio); struct ssl_connect_data *connssl = cf->ctx; @@ -334,7 +317,8 @@ static int wssl_bio_cf_out_write(WOLFSSL_BIO *bio, skiplen = (ssize_t)(blen - wssl->io_send_blocked_len); blen = wssl->io_send_blocked_len; } - result = Curl_conn_cf_send(cf->next, data, buf, blen, FALSE, &nwritten); + result = Curl_conn_cf_send(cf->next, data, + (const uint8_t *)buf, blen, FALSE, &nwritten); wssl->io_result = result; CURL_TRC_CF(data, cf, "bio_write(len=%d) -> %d, %zu", blen, result, nwritten); @@ -395,20 +379,24 @@ static int wssl_bio_cf_in_read(WOLFSSL_BIO *bio, char *buf, int blen) static WOLFSSL_BIO_METHOD *wssl_bio_cf_method = NULL; -static void wssl_bio_cf_init_methods(void) +static int wssl_bio_cf_init_methods(void) { wssl_bio_cf_method = wolfSSL_BIO_meth_new(WOLFSSL_BIO_MEMORY, - "wolfSSL CF BIO"); + "wolfSSL CF BIO"); + if(!wssl_bio_cf_method) + return FALSE; /* error */ wolfSSL_BIO_meth_set_write(wssl_bio_cf_method, &wssl_bio_cf_out_write); wolfSSL_BIO_meth_set_read(wssl_bio_cf_method, &wssl_bio_cf_in_read); wolfSSL_BIO_meth_set_ctrl(wssl_bio_cf_method, &wssl_bio_cf_ctrl); wolfSSL_BIO_meth_set_create(wssl_bio_cf_method, &wssl_bio_cf_create); wolfSSL_BIO_meth_set_destroy(wssl_bio_cf_method, &wssl_bio_cf_destroy); + return TRUE; /* fine */ } static void wssl_bio_cf_free_methods(void) { wolfSSL_BIO_meth_free(wssl_bio_cf_method); + wssl_bio_cf_method = NULL; } #else /* USE_BIO_CHAIN */ @@ -418,6 +406,7 @@ static void wssl_bio_cf_free_methods(void) #endif /* !USE_BIO_CHAIN */ +#ifdef HAVE_EX_DATA CURLcode Curl_wssl_cache_session(struct Curl_cfilter *cf, struct Curl_easy *data, const char *ssl_peer_key, @@ -429,7 +418,7 @@ CURLcode Curl_wssl_cache_session(struct Curl_cfilter *cf, { CURLcode result = CURLE_OK; struct Curl_ssl_session *sc_session = NULL; - unsigned char *sdata = NULL, *qtp_clone = NULL; + unsigned char *sdata = NULL, *sdata_ptr, *qtp_clone = NULL; unsigned int sdata_len; unsigned int earlydata_max = 0; @@ -442,13 +431,15 @@ CURLcode Curl_wssl_cache_session(struct Curl_cfilter *cf, result = CURLE_FAILED_INIT; goto out; } - sdata = calloc(1, sdata_len); + sdata = sdata_ptr = curlx_calloc(1, sdata_len); if(!sdata) { failf(data, "unable to allocate session buffer of %u bytes", sdata_len); result = CURLE_OUT_OF_MEMORY; goto out; } - sdata_len = wolfSSL_i2d_SSL_SESSION(session, &sdata); + /* wolfSSL right now does not change the last parameter here, but it + * might one day decide to do so for OpenSSL compatibility. */ + sdata_len = wolfSSL_i2d_SSL_SESSION(session, &sdata_ptr); if(sdata_len <= 0) { CURL_TRC_CF(data, cf, "fail to serialize session: %u", sdata_len); result = CURLE_FAILED_INIT; @@ -457,7 +448,7 @@ CURLcode Curl_wssl_cache_session(struct Curl_cfilter *cf, if(quic_tp && quic_tp_len) { qtp_clone = Curl_memdup0((char *)quic_tp, quic_tp_len); if(!qtp_clone) { - free(sdata); + curlx_free(sdata); return CURLE_OUT_OF_MEMORY; } } @@ -478,7 +469,7 @@ CURLcode Curl_wssl_cache_session(struct Curl_cfilter *cf, } out: - free(sdata); + curlx_free(sdata); return result; } @@ -486,7 +477,7 @@ static int wssl_vtls_new_session_cb(WOLFSSL *ssl, WOLFSSL_SESSION *session) { struct Curl_cfilter *cf; - cf = (struct Curl_cfilter*)wolfSSL_get_app_data(ssl); + cf = (struct Curl_cfilter *)wolfSSL_get_app_data(ssl); DEBUGASSERT(cf != NULL); if(cf && session) { struct ssl_connect_data *connssl = cf->ctx; @@ -501,6 +492,7 @@ static int wssl_vtls_new_session_cb(WOLFSSL *ssl, WOLFSSL_SESSION *session) } return 0; } +#endif static CURLcode wssl_on_session_reuse(struct Curl_cfilter *cf, struct Curl_easy *data, @@ -534,8 +526,8 @@ static CURLcode wssl_on_session_reuse(struct Curl_cfilter *cf, connssl->earlydata_state = ssl_earlydata_await; connssl->state = ssl_connection_deferred; result = Curl_alpn_set_negotiated(cf, data, connssl, - (const unsigned char *)scs->alpn, - scs->alpn ? strlen(scs->alpn) : 0); + (const unsigned char *)scs->alpn, + scs->alpn ? strlen(scs->alpn) : 0); *do_early_data = !result; } return result; @@ -577,8 +569,10 @@ wssl_setup_session(struct Curl_cfilter *cf, bool do_early_data = FALSE; if(sess_reuse_cb) { result = sess_reuse_cb(cf, data, alpns, scs, &do_early_data); - if(result) - goto out; + if(result) { + wolfSSL_SESSION_free(session); + goto out; + } } #ifdef WOLFSSL_EARLY_DATA if(do_early_data) { @@ -637,7 +631,7 @@ static CURLcode wssl_populate_x509_store(struct Curl_cfilter *cf, } #else infof(data, "ignoring native CA option because wolfSSL was built without " - "native CA support"); + "native CA support"); #endif } #endif /* !NO_FILESYSTEM */ @@ -685,7 +679,7 @@ static CURLcode wssl_populate_x509_store(struct Curl_cfilter *cf, /* Just continue with a warning if no strict certificate verification is required. */ infof(data, "error setting certificate verify locations," - " continuing anyway:"); + " continuing anyway:"); } } else { @@ -704,32 +698,30 @@ static CURLcode wssl_populate_x509_store(struct Curl_cfilter *cf, #define MPROTO_WSSL_X509_KEY "tls:wssl:x509:share" struct wssl_x509_share { - char *CAfile; /* CAfile path used to generate X509 store */ + char *CAfile; /* CAfile path used to generate X509 store */ WOLFSSL_X509_STORE *store; /* cached X509 store or NULL if none */ - struct curltime time; /* when the cached store was created */ + struct curltime time; /* when the cached store was created */ }; static void wssl_x509_share_free(void *key, size_t key_len, void *p) { struct wssl_x509_share *share = p; - DEBUGASSERT(key_len == (sizeof(MPROTO_WSSL_X509_KEY)-1)); + DEBUGASSERT(key_len == (sizeof(MPROTO_WSSL_X509_KEY) - 1)); DEBUGASSERT(!memcmp(MPROTO_WSSL_X509_KEY, key, key_len)); (void)key; (void)key_len; if(share->store) { wolfSSL_X509_STORE_free(share->store); } - free(share->CAfile); - free(share); + curlx_free(share->CAfile); + curlx_free(share); } -static bool -wssl_cached_x509_store_expired(const struct Curl_easy *data, - const struct wssl_x509_share *mb) +static bool wssl_cached_x509_store_expired(struct Curl_easy *data, + const struct wssl_x509_share *mb) { const struct ssl_general_config *cfg = &data->set.general_ssl; - struct curltime now = curlx_now(); - timediff_t elapsed_ms = curlx_timediff(now, mb->time); + timediff_t elapsed_ms = curlx_ptimediff_ms(Curl_pgrs_now(data), &mb->time); timediff_t timeout_ms = cfg->ca_cache_timeout * (timediff_t)1000; if(timeout_ms < 0) @@ -738,9 +730,8 @@ wssl_cached_x509_store_expired(const struct Curl_easy *data, return elapsed_ms >= timeout_ms; } -static bool -wssl_cached_x509_store_different(struct Curl_cfilter *cf, - const struct wssl_x509_share *mb) +static bool wssl_cached_x509_store_different(struct Curl_cfilter *cf, + const struct wssl_x509_share *mb) { struct ssl_primary_config *conn_config = Curl_ssl_cf_get_primary_config(cf); if(!mb->CAfile || !conn_config->CAfile) @@ -750,7 +741,7 @@ wssl_cached_x509_store_different(struct Curl_cfilter *cf, } static WOLFSSL_X509_STORE *wssl_get_cached_x509_store(struct Curl_cfilter *cf, - const struct Curl_easy *data) + struct Curl_easy *data) { struct Curl_multi *multi = data->multi; struct wssl_x509_share *share; @@ -759,7 +750,7 @@ static WOLFSSL_X509_STORE *wssl_get_cached_x509_store(struct Curl_cfilter *cf, DEBUGASSERT(multi); share = multi ? Curl_hash_pick(&multi->proto_hash, CURL_UNCONST(MPROTO_WSSL_X509_KEY), - sizeof(MPROTO_WSSL_X509_KEY)-1) : NULL; + sizeof(MPROTO_WSSL_X509_KEY) - 1) : NULL; if(share && share->store && !wssl_cached_x509_store_expired(data, share) && !wssl_cached_x509_store_different(cf, share)) { @@ -770,7 +761,7 @@ static WOLFSSL_X509_STORE *wssl_get_cached_x509_store(struct Curl_cfilter *cf, } static void wssl_set_cached_x509_store(struct Curl_cfilter *cf, - const struct Curl_easy *data, + struct Curl_easy *data, WOLFSSL_X509_STORE *store) { struct ssl_primary_config *conn_config = Curl_ssl_cf_get_primary_config(cf); @@ -782,17 +773,17 @@ static void wssl_set_cached_x509_store(struct Curl_cfilter *cf, return; share = Curl_hash_pick(&multi->proto_hash, CURL_UNCONST(MPROTO_WSSL_X509_KEY), - sizeof(MPROTO_WSSL_X509_KEY)-1); + sizeof(MPROTO_WSSL_X509_KEY) - 1); if(!share) { - share = calloc(1, sizeof(*share)); + share = curlx_calloc(1, sizeof(*share)); if(!share) return; if(!Curl_hash_add2(&multi->proto_hash, CURL_UNCONST(MPROTO_WSSL_X509_KEY), - sizeof(MPROTO_WSSL_X509_KEY)-1, + sizeof(MPROTO_WSSL_X509_KEY) - 1, share, wssl_x509_share_free)) { - free(share); + curlx_free(share); return; } } @@ -801,7 +792,7 @@ static void wssl_set_cached_x509_store(struct Curl_cfilter *cf, char *CAfile = NULL; if(conn_config->CAfile) { - CAfile = strdup(conn_config->CAfile); + CAfile = curlx_strdup(conn_config->CAfile); if(!CAfile) { wolfSSL_X509_STORE_free(store); return; @@ -810,10 +801,10 @@ static void wssl_set_cached_x509_store(struct Curl_cfilter *cf, if(share->store) { wolfSSL_X509_STORE_free(share->store); - free(share->CAfile); + curlx_free(share->CAfile); } - share->time = curlx_now(); + share->time = *Curl_pgrs_now(data); share->store = store; share->CAfile = CAfile; } @@ -864,17 +855,16 @@ CURLcode Curl_wssl_setup_x509_store(struct Curl_cfilter *cf, } } else { - /* We never share the CTX's store, use it. */ - WOLFSSL_X509_STORE *store = wolfSSL_CTX_get_cert_store(wssl->ssl_ctx); - result = wssl_populate_x509_store(cf, data, store, wssl); + /* We never share the CTX's store, use it. */ + WOLFSSL_X509_STORE *store = wolfSSL_CTX_get_cert_store(wssl->ssl_ctx); + result = wssl_populate_x509_store(cf, data, store, wssl); } return result; } #ifdef WOLFSSL_TLS13 -static CURLcode -wssl_add_default_ciphers(bool tls13, struct dynbuf *buf) +static CURLcode wssl_add_default_ciphers(bool tls13, struct dynbuf *buf) { int i; char *str; @@ -902,8 +892,7 @@ wssl_add_default_ciphers(bool tls13, struct dynbuf *buf) /* 4.2.0 (2019) */ #if LIBWOLFSSL_VERSION_HEX < 0x04002000 || !defined(OPENSSL_EXTRA) -static int -wssl_legacy_CTX_set_min_proto_version(WOLFSSL_CTX* ctx, int version) +static int wssl_legacy_CTX_set_min_proto_version(WOLFSSL_CTX *ctx, int version) { int res; switch(version) { @@ -930,8 +919,8 @@ wssl_legacy_CTX_set_min_proto_version(WOLFSSL_CTX* ctx, int version) } return res; } -static int -wssl_legacy_CTX_set_max_proto_version(WOLFSSL_CTX* ctx, int version) + +static int wssl_legacy_CTX_set_max_proto_version(WOLFSSL_CTX *ctx, int version) { (void)ctx, (void)version; return WOLFSSL_NOT_IMPLEMENTED; @@ -1037,66 +1026,72 @@ static CURLcode client_certificate(struct Curl_easy *data, static CURLcode ssl_version(struct Curl_easy *data, struct ssl_primary_config *conn_config, - struct wssl_ctx *wctx) + struct wssl_ctx *wctx, + int *min_version, int *max_version) { int res; + *min_version = *max_version = 0; switch(conn_config->version) { case CURL_SSLVERSION_DEFAULT: case CURL_SSLVERSION_TLSv1: case CURL_SSLVERSION_TLSv1_0: - res = wolfSSL_CTX_set_min_proto_version(wctx->ssl_ctx, TLS1_VERSION); + *min_version = TLS1_VERSION; break; case CURL_SSLVERSION_TLSv1_1: - res = wolfSSL_CTX_set_min_proto_version(wctx->ssl_ctx, TLS1_1_VERSION); + *min_version = TLS1_1_VERSION; break; case CURL_SSLVERSION_TLSv1_2: - res = wolfSSL_CTX_set_min_proto_version(wctx->ssl_ctx, TLS1_2_VERSION); + *min_version = TLS1_2_VERSION; break; #ifdef WOLFSSL_TLS13 case CURL_SSLVERSION_TLSv1_3: - res = wolfSSL_CTX_set_min_proto_version(wctx->ssl_ctx, TLS1_3_VERSION); + *min_version = TLS1_3_VERSION; break; #endif default: failf(data, "wolfSSL: unsupported minimum TLS version value"); return CURLE_SSL_CONNECT_ERROR; } - if(res != WOLFSSL_SUCCESS) { - failf(data, "wolfSSL: failed set the minimum TLS version"); - return CURLE_SSL_CONNECT_ERROR; - } switch(conn_config->version_max) { #ifdef WOLFSSL_TLS13 case CURL_SSLVERSION_MAX_TLSv1_3: - res = wolfSSL_CTX_set_max_proto_version(wctx->ssl_ctx, TLS1_3_VERSION); + *max_version = TLS1_3_VERSION; break; #endif case CURL_SSLVERSION_MAX_TLSv1_2: - res = wolfSSL_CTX_set_max_proto_version(wctx->ssl_ctx, TLS1_2_VERSION); + *max_version = TLS1_2_VERSION; break; case CURL_SSLVERSION_MAX_TLSv1_1: - res = wolfSSL_CTX_set_max_proto_version(wctx->ssl_ctx, TLS1_1_VERSION); + *max_version = TLS1_1_VERSION; break; case CURL_SSLVERSION_MAX_TLSv1_0: - res = wolfSSL_CTX_set_max_proto_version(wctx->ssl_ctx, TLS1_VERSION); + *max_version = TLS1_VERSION; break; case CURL_SSLVERSION_MAX_DEFAULT: case CURL_SSLVERSION_MAX_NONE: - res = WOLFSSL_SUCCESS; break; default: failf(data, "wolfSSL: unsupported maximum TLS version value"); return CURLE_SSL_CONNECT_ERROR; } + + res = wolfSSL_CTX_set_min_proto_version(wctx->ssl_ctx, *min_version); if(res != WOLFSSL_SUCCESS) { - failf(data, "wolfSSL: failed set the maximum TLS version"); + failf(data, "wolfSSL: failed set the minimum TLS version"); return CURLE_SSL_CONNECT_ERROR; } + + if(*max_version) { + res = wolfSSL_CTX_set_max_proto_version(wctx->ssl_ctx, *max_version); + if(res != WOLFSSL_SUCCESS) { + failf(data, "wolfSSL: failed set the maximum TLS version"); + return CURLE_SSL_CONNECT_ERROR; + } + } return CURLE_OK; } - #define QUIC_GROUPS "P-256:P-384:P-521" CURLcode Curl_wssl_ctx_init(struct wssl_ctx *wctx, @@ -1111,7 +1106,7 @@ CURLcode Curl_wssl_ctx_init(struct wssl_ctx *wctx, { struct ssl_config_data *ssl_config = Curl_ssl_cf_get_config(cf, data); struct ssl_primary_config *conn_config; - WOLFSSL_METHOD* req_method = NULL; + WOLFSSL_METHOD *req_method = NULL; struct alpn_spec alpns; char *curves; #ifdef WOLFSSL_HAVE_KYBER @@ -1120,6 +1115,7 @@ CURLcode Curl_wssl_ctx_init(struct wssl_ctx *wctx, #endif CURLcode result = CURLE_FAILED_INIT; unsigned char transport; + int tls_min, tls_max; DEBUGASSERT(!wctx->ssl_ctx); DEBUGASSERT(!wctx->ssl); @@ -1153,7 +1149,7 @@ CURLcode Curl_wssl_ctx_init(struct wssl_ctx *wctx, goto out; } - result = ssl_version(data, conn_config, wctx); + result = ssl_version(data, conn_config, wctx, &tls_min, &tls_max); if(result) goto out; @@ -1177,12 +1173,14 @@ CURLcode Curl_wssl_ctx_init(struct wssl_ctx *wctx, struct dynbuf c; curlx_dyn_init(&c, MAX_CIPHER_LEN); - if(ciphers13) - result = curlx_dyn_add(&c, ciphers13); - else - result = wssl_add_default_ciphers(TRUE, &c); + if(!tls_max || (tls_max >= TLS1_3_VERSION)) { + if(ciphers13) + result = curlx_dyn_add(&c, ciphers13); + else + result = wssl_add_default_ciphers(TRUE, &c); + } - if(!result) { + if(!result && (tls_min < TLS1_3_VERSION)) { if(ciphers12) { if(curlx_dyn_len(&c)) result = curlx_dyn_addn(&c, ":", 1); @@ -1257,10 +1255,12 @@ CURLcode Curl_wssl_ctx_init(struct wssl_ctx *wctx, } #endif +#ifdef HAVE_EX_DATA if(Curl_ssl_scache_use(cf, data) && (transport != TRNSPRT_QUIC)) { /* Register to get notified when a new session is received */ wolfSSL_CTX_sess_set_new_cb(wctx->ssl_ctx, wssl_vtls_new_session_cb); } +#endif if(cb_setup) { result = cb_setup(cf, data, cb_user_data); @@ -1301,7 +1301,11 @@ CURLcode Curl_wssl_ctx_init(struct wssl_ctx *wctx, goto out; } +#ifdef HAVE_EX_DATA wolfSSL_set_app_data(wctx->ssl, ssl_user_data); +#else + (void)ssl_user_data; +#endif #ifdef WOLFSSL_QUIC if(transport == TRNSPRT_QUIC) wolfSSL_set_quic_use_legacy_codepoint(wctx->ssl, 0); @@ -1344,8 +1348,7 @@ CURLcode Curl_wssl_ctx_init(struct wssl_ctx *wctx, /* Ensure the Client Random is preserved. */ wolfSSL_KeepArrays(wctx->ssl); #if defined(HAVE_SECRET_CALLBACK) && defined(WOLFSSL_TLS13) - wolfSSL_set_tls13_secret_cb(wctx->ssl, - wssl_tls13_secret_callback, NULL); + wolfSSL_set_tls13_secret_cb(wctx->ssl, wssl_tls13_secret_callback, NULL); #endif } #endif /* OPENSSL_EXTRA */ @@ -1358,7 +1361,7 @@ CURLcode Curl_wssl_ctx_init(struct wssl_ctx *wctx, } #endif /* HAVE_SECURE_RENEGOTIATION */ -#ifdef USE_ECH_WOLFSSL +#ifdef HAVE_WOLFSSL_CTX_GENERATEECHCONFIG if(ECH_ENABLED(data)) { int trying_ech_now = 0; @@ -1370,23 +1373,23 @@ CURLcode Curl_wssl_ctx_init(struct wssl_ctx *wctx, if(data->set.tls_ech == CURLECH_GREASE) { infof(data, "ECH: GREASE is done by default by wolfSSL: no need to ask"); } - if(data->set.tls_ech & CURLECH_CLA_CFG - && data->set.str[STRING_ECH_CONFIG]) { + if(data->set.tls_ech & CURLECH_CLA_CFG && + data->set.str[STRING_ECH_CONFIG]) { char *b64val = data->set.str[STRING_ECH_CONFIG]; word32 b64len = 0; - b64len = (word32) strlen(b64val); - if(b64len - && wolfSSL_SetEchConfigsBase64(wctx->ssl, b64val, b64len) - != WOLFSSL_SUCCESS) { + b64len = (word32)strlen(b64val); + if(b64len && + wolfSSL_SetEchConfigsBase64(wctx->ssl, + b64val, b64len) != WOLFSSL_SUCCESS) { if(data->set.tls_ech & CURLECH_HARD) { result = CURLE_SSL_CONNECT_ERROR; goto out; } } else { - trying_ech_now = 1; - infof(data, "ECH: ECHConfig from command line"); + trying_ech_now = 1; + infof(data, "ECH: ECHConfig from command line"); } } else { @@ -1411,8 +1414,8 @@ CURLcode Curl_wssl_ctx_init(struct wssl_ctx *wctx, size_t elen = rinfo->echconfiglist_len; infof(data, "ECH: ECHConfig from DoH HTTPS RR"); - if(wolfSSL_SetEchConfigs(wctx->ssl, ecl, (word32) elen) != - WOLFSSL_SUCCESS) { + if(wolfSSL_SetEchConfigs(wctx->ssl, ecl, (word32)elen) != + WOLFSSL_SUCCESS) { infof(data, "ECH: wolfSSL_SetEchConfigs failed"); if(data->set.tls_ech & CURLECH_HARD) { result = CURLE_SSL_CONNECT_ERROR; @@ -1443,7 +1446,7 @@ CURLcode Curl_wssl_ctx_init(struct wssl_ctx *wctx, } } -#endif /* USE_ECH_WOLFSSL */ +#endif /* HAVE_WOLFSSL_CTX_GENERATEECHCONFIG */ result = CURLE_OK; @@ -1463,8 +1466,8 @@ CURLcode Curl_wssl_ctx_init(struct wssl_ctx *wctx, * This function loads all the client/CA certificates and CRLs. Setup the TLS * layer and do all necessary magic. */ -static CURLcode -wssl_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) +static CURLcode wssl_connect_step1(struct Curl_cfilter *cf, + struct Curl_easy *data) { struct ssl_connect_data *connssl = cf->ctx; struct wssl_ctx *wssl = (struct wssl_ctx *)connssl->backend; @@ -1504,6 +1507,8 @@ wssl_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) { WOLFSSL_BIO *bio; + if(!wssl_bio_cf_method) + return CURLE_FAILED_INIT; bio = wolfSSL_BIO_new(wssl_bio_cf_method); if(!bio) return CURLE_OUT_OF_MEMORY; @@ -1511,21 +1516,23 @@ wssl_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) wolfSSL_BIO_set_data(bio, cf); wolfSSL_set_bio(wssl->ssl, bio, bio); } -#else /* USE_BIO_CHAIN */ +#else /* !USE_BIO_CHAIN */ + curl_socket_t sockfd = Curl_conn_cf_get_socket(cf, data); + if(sockfd > INT_MAX) { + failf(data, "SSL: socket value too large"); + return CURLE_SSL_CONNECT_ERROR; + } /* pass the raw socket into the SSL layer */ - if(!wolfSSL_set_fd(wssl->ssl, - (int)Curl_conn_cf_get_socket(cf, data))) { + if(!wolfSSL_set_fd(wssl->ssl, (int)sockfd)) { failf(data, "SSL: wolfSSL_set_fd failed"); return CURLE_SSL_CONNECT_ERROR; } -#endif /* !USE_BIO_CHAIN */ +#endif /* USE_BIO_CHAIN */ return CURLE_OK; } - -static char *wssl_strerror(unsigned long error, char *buf, - unsigned long size) +static char *wssl_strerror(unsigned long error, char *buf, unsigned long size) { DEBUGASSERT(size > 40); *buf = '\0'; @@ -1534,8 +1541,7 @@ static char *wssl_strerror(unsigned long error, char *buf, if(!*buf) { const char *msg = error ? "Unknown error" : "No error"; - /* the string fits because the assert above assures this */ - strcpy(buf, msg); + curlx_strcopy(buf, size, msg, strlen(msg)); } return buf; @@ -1608,7 +1614,6 @@ static CURLcode wssl_send_earlydata(struct Curl_cfilter *cf, { struct ssl_connect_data *connssl = cf->ctx; struct wssl_ctx *wssl = (struct wssl_ctx *)connssl->backend; - CURLcode result = CURLE_OK; const unsigned char *buf; size_t blen; @@ -1623,23 +1628,17 @@ static CURLcode wssl_send_earlydata(struct Curl_cfilter *cf, blen, rc, nwritten); if(rc < 0) { int err = wolfSSL_get_error(wssl->ssl, rc); + char error_buffer[256]; switch(err) { case WOLFSSL_ERROR_NONE: /* just did not get anything */ case WOLFSSL_ERROR_WANT_READ: case WOLFSSL_ERROR_WANT_WRITE: - result = CURLE_AGAIN; - break; - default: { - char error_buffer[256]; - CURL_TRC_CF(data, cf, "SSL send early data, error: '%s'(%d)", - wssl_strerror((unsigned long)err, error_buffer, - sizeof(error_buffer)), - err); - result = CURLE_SEND_ERROR; - break; - } + return CURLE_AGAIN; } - goto out; + CURL_TRC_CF(data, cf, "SSL send early data, error: '%s'(%d)", + wssl_strerror((unsigned long)err, error_buffer, + sizeof(error_buffer)), err); + return CURLE_SEND_ERROR; } Curl_bufq_skip(&connssl->earlydata, (size_t)nwritten); @@ -1649,13 +1648,11 @@ static CURLcode wssl_send_earlydata(struct Curl_cfilter *cf, if(!Curl_ssl_cf_is_proxy(cf)) Curl_pgrsEarlyData(data, (curl_off_t)connssl->earlydata_skip); infof(data, "SSL sending %zu bytes of early data", connssl->earlydata_skip); -out: - return result; + return CURLE_OK; } #endif /* WOLFSSL_EARLY_DATA */ -static CURLcode wssl_handshake(struct Curl_cfilter *cf, - struct Curl_easy *data) +static CURLcode wssl_handshake(struct Curl_cfilter *cf, struct Curl_easy *data) { struct ssl_connect_data *connssl = cf->ctx; struct wssl_ctx *wssl = (struct wssl_ctx *)connssl->backend; @@ -1713,7 +1710,7 @@ static CURLcode wssl_handshake(struct Curl_cfilter *cf, wolfSSL_FreeArrays(wssl->ssl); } } -#endif /* OPENSSL_EXTRA */ +#endif /* OPENSSL_EXTRA */ detail = wolfSSL_get_error(wssl->ssl, ret); CURL_TRC_CF(data, cf, "wolfSSL_connect() -> %d, detail=%d", ret, detail); @@ -1723,8 +1720,8 @@ static CURLcode wssl_handshake(struct Curl_cfilter *cf, if(ret == WOLFSSL_SUCCESS && conn_config->verifyhost && !connssl->peer.sni) { - /* we have an IP address as host name. */ - WOLFSSL_X509* cert = wolfSSL_get_peer_certificate(wssl->ssl); + /* we have an IP address as hostname. */ + WOLFSSL_X509 *cert = wolfSSL_get_peer_certificate(wssl->ssl); if(!cert) { failf(data, "unable to get peer certificate"); return CURLE_PEER_FAILED_VERIFICATION; @@ -1778,14 +1775,14 @@ static CURLcode wssl_handshake(struct Curl_cfilter *cf, } else if(wssl->io_result) { switch(wssl->io_result) { - case CURLE_SEND_ERROR: - case CURLE_RECV_ERROR: - return CURLE_SSL_CONNECT_ERROR; - default: - return wssl->io_result; + case CURLE_SEND_ERROR: + case CURLE_RECV_ERROR: + return CURLE_SSL_CONNECT_ERROR; + default: + return wssl->io_result; } } -#ifdef USE_ECH_WOLFSSL +#ifdef HAVE_WOLFSSL_CTX_GENERATEECHCONFIG else if(detail == -1) { /* try access a retry_config ECHConfigList for tracing */ byte echConfigs[1000]; @@ -1793,8 +1790,7 @@ static CURLcode wssl_handshake(struct Curl_cfilter *cf, int rv = 0; /* this currently does not produce the retry_configs */ - rv = wolfSSL_GetEchConfigs(wssl->ssl, echConfigs, - &echConfigsLen); + rv = wolfSSL_GetEchConfigs(wssl->ssl, echConfigs, &echConfigsLen); if(rv != WOLFSSL_SUCCESS) { infof(data, "Failed to get ECHConfigs"); } @@ -1802,11 +1798,11 @@ static CURLcode wssl_handshake(struct Curl_cfilter *cf, char *b64str = NULL; size_t blen = 0; - result = curlx_base64_encode((const char *)echConfigs, echConfigsLen, + result = curlx_base64_encode(echConfigs, echConfigsLen, &b64str, &blen); if(!result && b64str) infof(data, "ECH: (not yet) retry_configs %s", b64str); - free(b64str); + curlx_free(b64str); } return CURLE_SSL_CONNECT_ERROR; } @@ -2076,7 +2072,6 @@ size_t Curl_wssl_version(char *buffer, size_t size) #endif } - static int wssl_init(void) { int ret; @@ -2085,11 +2080,11 @@ static int wssl_init(void) Curl_tls_keylog_open(); #endif ret = (wolfSSL_Init() == WOLFSSL_SUCCESS); - wssl_bio_cf_init_methods(); + if(ret) + ret = wssl_bio_cf_init_methods(); return ret; } - static void wssl_cleanup(void) { wssl_bio_cf_free_methods(); @@ -2099,7 +2094,6 @@ static void wssl_cleanup(void) #endif } - static bool wssl_data_pending(struct Curl_cfilter *cf, const struct Curl_easy *data) { @@ -2116,15 +2110,14 @@ static bool wssl_data_pending(struct Curl_cfilter *cf, return FALSE; } -void Curl_wssl_report_handshake(struct Curl_easy *data, - struct wssl_ctx *wssl) +void Curl_wssl_report_handshake(struct Curl_easy *data, struct wssl_ctx *wssl) { #if (LIBWOLFSSL_VERSION_HEX >= 0x03009010) - infof(data, "SSL connection using %s / %s", - wolfSSL_get_version(wssl->ssl), - wolfSSL_get_cipher_name(wssl->ssl)); + infof(data, "SSL connection using %s / %s", + wolfSSL_get_version(wssl->ssl), + wolfSSL_get_cipher_name(wssl->ssl)); #else - infof(data, "SSL connected"); + infof(data, "SSL connected"); #endif } @@ -2285,7 +2278,7 @@ const struct Curl_ssl Curl_ssl_wolfssl = { #endif SSLSUPP_CA_PATH | SSLSUPP_CAINFO_BLOB | -#ifdef USE_ECH_WOLFSSL +#ifdef HAVE_WOLFSSL_CTX_GENERATEECHCONFIG SSLSUPP_ECH | #endif SSLSUPP_SSL_CTX | diff --git a/vendor/hydra/vendor/curl/lib/vtls/wolfssl.h b/vendor/hydra/vendor/curl/lib/vtls/wolfssl.h index 7ff4cfb8..736da9a1 100644 --- a/vendor/hydra/vendor/curl/lib/vtls/wolfssl.h +++ b/vendor/hydra/vendor/curl/lib/vtls/wolfssl.h @@ -41,9 +41,9 @@ extern const struct Curl_ssl Curl_ssl_wolfssl; struct wssl_ctx { struct WOLFSSL_CTX *ssl_ctx; - struct WOLFSSL *ssl; - CURLcode io_result; /* result of last BIO cfilter operation */ - CURLcode hs_result; /* result of handshake */ + struct WOLFSSL *ssl; + CURLcode io_result; /* result of last BIO cfilter operation */ + CURLcode hs_result; /* result of handshake */ int io_send_blocked_len; /* length of last BIO write that EAGAIN-ed */ BIT(x509_store_setup); /* x509 store has been set up */ BIT(shutting_down); /* TLS is being shut down */ @@ -75,6 +75,7 @@ CURLcode Curl_wssl_setup_x509_store(struct Curl_cfilter *cf, struct Curl_easy *data, struct wssl_ctx *wssl); +#ifdef HAVE_EX_DATA CURLcode Curl_wssl_cache_session(struct Curl_cfilter *cf, struct Curl_easy *data, const char *ssl_peer_key, @@ -83,13 +84,13 @@ CURLcode Curl_wssl_cache_session(struct Curl_cfilter *cf, const char *alpn, unsigned char *quic_tp, size_t quic_tp_len); +#endif CURLcode Curl_wssl_verify_pinned(struct Curl_cfilter *cf, struct Curl_easy *data, struct wssl_ctx *wssl); -void Curl_wssl_report_handshake(struct Curl_easy *data, - struct wssl_ctx *wssl); +void Curl_wssl_report_handshake(struct Curl_easy *data, struct wssl_ctx *wssl); #endif /* USE_WOLFSSL */ #endif /* HEADER_CURL_WOLFSSL_H */ diff --git a/vendor/hydra/vendor/curl/lib/vtls/x509asn1.c b/vendor/hydra/vendor/curl/lib/vtls/x509asn1.c index c5fc8635..e6fdb10d 100644 --- a/vendor/hydra/vendor/curl/lib/vtls/x509asn1.c +++ b/vendor/hydra/vendor/curl/lib/vtls/x509asn1.c @@ -21,7 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "../curl_setup.h" #if defined(USE_GNUTLS) || defined(USE_WOLFSSL) || defined(USE_SCHANNEL) || \ @@ -37,28 +36,19 @@ #define WANT_EXTRACT_CERTINFO /* uses Curl_extract_certinfo() */ #endif -#include #include "../urldata.h" -#include "../curl_ctype.h" -#include "hostcheck.h" #include "vtls.h" -#include "vtls_int.h" -#include "../sendf.h" -#include "../curlx/inet_pton.h" +#include "../curl_trc.h" #include "../curlx/base64.h" #include "x509asn1.h" #include "../curlx/dynbuf.h" -/* The last 2 #include files should be in this order */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* * Constants. */ /* Largest supported ASN.1 structure. */ -#define CURL_ASN1_MAX ((size_t) 0x40000) /* 256K */ +#define CURL_ASN1_MAX ((size_t)0x40000) /* 256K */ /* ASN.1 classes. */ /* #define CURL_ASN1_UNIVERSAL 0 */ @@ -96,7 +86,6 @@ /* #define CURL_ASN1_CHARACTER_STRING 29 */ #define CURL_ASN1_BMP_STRING 30 - #ifdef WANT_EXTRACT_CERTINFO /* ASN.1 OID table entry. */ struct Curl_OID { @@ -157,7 +146,7 @@ static const struct Curl_OID OIDtable[] = { { "2.16.840.1.101.3.4.2.2", "sha384" }, { "2.16.840.1.101.3.4.2.3", "sha512" }, { "1.2.840.113549.1.9.2", "unstructuredName" }, - { (const char *) NULL, (const char *) NULL } + { (const char *)NULL, (const char *)NULL } }; #endif /* WANT_EXTRACT_CERTINFO */ @@ -191,12 +180,12 @@ static const char *getASN1Element_(struct Curl_asn1Element *elem, if an error occurs. */ if(!beg || !end || beg >= end || !*beg || ((size_t)(end - beg) > CURL_ASN1_MAX) || - lvl >= CURL_ASN1_MAX_RECURSIONS) + lvl >= CURL_ASN1_MAX_RECURSIONS) return NULL; /* Process header byte. */ elem->header = beg; - b = (unsigned char) *beg++; + b = (unsigned char)*beg++; elem->constructed = (b & 0x20) != 0; elem->eclass = (b >> 6) & 3; b &= 0x1F; @@ -207,7 +196,7 @@ static const char *getASN1Element_(struct Curl_asn1Element *elem, /* Process length. */ if(beg >= end) return NULL; - b = (unsigned char) *beg++; + b = (unsigned char)*beg++; if(!(b & 0x80)) len = b; else if(!(b &= 0x7F)) { @@ -288,7 +277,7 @@ static CURLcode bool2str(struct dynbuf *store, { if(end - beg != 1) return CURLE_BAD_FUNCTION_ARGUMENT; - return curlx_dyn_add(store, *beg ? "TRUE": "FALSE"); + return curlx_dyn_add(store, *beg ? "TRUE" : "FALSE"); } /* @@ -302,13 +291,12 @@ static CURLcode octet2str(struct dynbuf *store, CURLcode result = CURLE_OK; while(!result && beg < end) - result = curlx_dyn_addf(store, "%02x:", (unsigned char) *beg++); + result = curlx_dyn_addf(store, "%02x:", (unsigned char)*beg++); return result; } -static CURLcode bit2str(struct dynbuf *store, - const char *beg, const char *end) +static CURLcode bit2str(struct dynbuf *store, const char *beg, const char *end) { /* Convert an ASN.1 bit string to a printable string. */ @@ -322,8 +310,7 @@ static CURLcode bit2str(struct dynbuf *store, * * Returns error. */ -static CURLcode int2str(struct dynbuf *store, - const char *beg, const char *end) +static CURLcode int2str(struct dynbuf *store, const char *beg, const char *end) { unsigned int val = 0; size_t n = end - beg; @@ -339,7 +326,7 @@ static CURLcode int2str(struct dynbuf *store, val = ~val; do - val = (val << 8) | *(const unsigned char *) beg++; + val = (val << 8) | *(const unsigned char *)beg++; while(beg < end); return curlx_dyn_addf(store, "%s%x", val >= 10 ? "0x" : "", val); } @@ -352,8 +339,8 @@ static CURLcode int2str(struct dynbuf *store, * * Returns error. */ -static CURLcode -utf8asn1str(struct dynbuf *to, int type, const char *from, const char *end) +static CURLcode utf8asn1str(struct dynbuf *to, int type, const char *from, + const char *end) { size_t inlength = end - from; int size = 1; @@ -394,14 +381,14 @@ utf8asn1str(struct dynbuf *to, int type, const char *from, const char *end) switch(size) { case 4: - wc = (wc << 8) | *(const unsigned char *) from++; - wc = (wc << 8) | *(const unsigned char *) from++; + wc = (wc << 8) | *(const unsigned char *)from++; + wc = (wc << 8) | *(const unsigned char *)from++; FALLTHROUGH(); case 2: - wc = (wc << 8) | *(const unsigned char *) from++; + wc = (wc << 8) | *(const unsigned char *)from++; FALLTHROUGH(); default: /* case 1: */ - wc = (wc << 8) | *(const unsigned char *) from++; + wc = (wc << 8) | *(const unsigned char *)from++; } if(wc >= 0x00000080) { if(wc >= 0x00000800) { @@ -410,19 +397,19 @@ utf8asn1str(struct dynbuf *to, int type, const char *from, const char *end) /* Invalid char. size for target encoding. */ return CURLE_WEIRD_SERVER_REPLY; } - buf[3] = (char) (0x80 | (wc & 0x3F)); + buf[3] = (char)(0x80 | (wc & 0x3F)); wc = (wc >> 6) | 0x00010000; charsize++; } - buf[2] = (char) (0x80 | (wc & 0x3F)); + buf[2] = (char)(0x80 | (wc & 0x3F)); wc = (wc >> 6) | 0x00000800; charsize++; } - buf[1] = (char) (0x80 | (wc & 0x3F)); + buf[1] = (char)(0x80 | (wc & 0x3F)); wc = (wc >> 6) | 0x000000C0; charsize++; } - buf[0] = (char) wc; + buf[0] = (char)wc; result = curlx_dyn_addn(to, buf, charsize); } } @@ -442,7 +429,7 @@ static CURLcode encodeOID(struct dynbuf *store, CURLcode result = CURLE_OK; /* Process the first two numbers. */ - y = *(const unsigned char *) beg++; + y = *(const unsigned char *)beg++; x = y / 40; y -= x * 40; @@ -456,7 +443,7 @@ static CURLcode encodeOID(struct dynbuf *store, do { if(x & 0xFF000000) return CURLE_OK; - y = *(const unsigned char *) beg++; + y = *(const unsigned char *)beg++; x = (x << 7) | (y & 0x7F); } while(y & 0x80); result = curlx_dyn_addf(store, ".%u", x); @@ -977,8 +964,8 @@ static CURLcode do_pubkey_field(struct Curl_easy *data, int certnum, } /* return 0 on success, 1 on error */ -static int do_pubkey(struct Curl_easy *data, int certnum, - const char *algo, struct Curl_asn1Element *param, +static int do_pubkey(struct Curl_easy *data, int certnum, const char *algo, + struct Curl_asn1Element *param, struct Curl_asn1Element *pubkey) { struct Curl_asn1Element elem; @@ -1023,7 +1010,7 @@ static int do_pubkey(struct Curl_easy *data, int certnum, len = ((elem.end - q) * 8); if(len) { unsigned int i; - for(i = *(const unsigned char *) q; !(i & 0x80); i <<= 1) + for(i = *(const unsigned char *)q; !(i & 0x80); i <<= 1) len--; } if(len > 32) @@ -1082,8 +1069,7 @@ static int do_pubkey(struct Curl_easy *data, int certnum, * Convert an ASN.1 distinguished name into a printable string. * Return error. */ -static CURLcode DNtostr(struct dynbuf *store, - struct Curl_asn1Element *dn) +static CURLcode DNtostr(struct dynbuf *store, struct Curl_asn1Element *dn) { return encodeDN(store, dn); } @@ -1139,7 +1125,7 @@ CURLcode Curl_extract_certinfo(struct Curl_easy *data, /* Version (always fits in less than 32 bits). */ version = 0; for(ptr = cert.version.beg; ptr < cert.version.end; ptr++) - version = (version << 8) | *(const unsigned char *) ptr; + version = (version << 8) | *(const unsigned char *)ptr; if(data->set.ssl.certinfo) { result = curlx_dyn_addf(&out, "%x", version); if(result) @@ -1167,8 +1153,7 @@ CURLcode Curl_extract_certinfo(struct Curl_easy *data, if(result) goto done; if(data->set.ssl.certinfo) { - result = ssl_push_certinfo_dyn(data, certnum, "Signature Algorithm", - &out); + result = ssl_push_certinfo_dyn(data, certnum, "Signature Algorithm", &out); if(result) goto done; } @@ -1228,7 +1213,7 @@ CURLcode Curl_extract_certinfo(struct Curl_easy *data, curlx_dyn_reset(&out); /* Generate PEM certificate. */ - result = curlx_base64_encode(cert.certificate.beg, + result = curlx_base64_encode((const uint8_t *)cert.certificate.beg, cert.certificate.end - cert.certificate.beg, &certptr, &clen); if(result) @@ -1260,7 +1245,7 @@ CURLcode Curl_extract_certinfo(struct Curl_easy *data, if(!result) result = curlx_dyn_add(&out, "-----END CERTIFICATE-----\n"); } - free(certptr); + curlx_free(certptr); if(!result) if(data->set.ssl.certinfo) result = ssl_push_certinfo_dyn(data, certnum, "Cert", &out); @@ -1274,5 +1259,5 @@ CURLcode Curl_extract_certinfo(struct Curl_easy *data, #endif /* WANT_EXTRACT_CERTINFO */ -#endif /* USE_GNUTLS or USE_WOLFSSL or USE_SCHANNEL or USE_MBEDTLS or +#endif /* USE_GNUTLS || USE_WOLFSSL || USE_SCHANNEL || USE_MBEDTLS || USE_RUSTLS */ diff --git a/vendor/hydra/vendor/curl/lib/vtls/x509asn1.h b/vendor/hydra/vendor/curl/lib/vtls/x509asn1.h index 51ea0c2c..ba2c3893 100644 --- a/vendor/hydra/vendor/curl/lib/vtls/x509asn1.h +++ b/vendor/hydra/vendor/curl/lib/vtls/x509asn1.h @@ -24,7 +24,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ - #include "../curl_setup.h" #if defined(USE_GNUTLS) || defined(USE_WOLFSSL) || defined(USE_SCHANNEL) || \ @@ -87,9 +86,9 @@ CURLcode Curl_x509_GTime2str(struct dynbuf *store, /* used by unit1657.c */ CURLcode Curl_x509_getASN1Element(struct Curl_asn1Element *elem, const char *beg, const char *end); -#endif -#endif +#endif /* USE_GNUTLS || USE_SCHANNEL || USE_MBEDTLS || RUSTLS */ +#endif /* UNITTESTS */ -#endif /* USE_GNUTLS or USE_WOLFSSL or USE_SCHANNEL or USE_MBEDTLS or +#endif /* USE_GNUTLS || USE_WOLFSSL || USE_SCHANNEL || USE_MBEDTLS || USE_RUSTLS */ #endif /* HEADER_CURL_X509ASN1_H */ diff --git a/vendor/hydra/vendor/curl/lib/ws.c b/vendor/hydra/vendor/curl/lib/ws.c index 683841ec..37cacae9 100644 --- a/vendor/hydra/vendor/curl/lib/ws.c +++ b/vendor/hydra/vendor/curl/lib/ws.c @@ -22,7 +22,6 @@ * ***************************************************************************/ #include "curl_setup.h" -#include #if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP) @@ -34,18 +33,14 @@ #include "curlx/base64.h" #include "connect.h" #include "sendf.h" +#include "curl_trc.h" #include "multiif.h" #include "ws.h" #include "easyif.h" #include "transfer.h" #include "select.h" -#include "curlx/nonblock.h" #include "curlx/strparse.h" - -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - +#include "curlx/strcopy.h" /*** RFC 6455 Section 5.2 @@ -57,11 +52,11 @@ |N|V|V|V| | | |1|2|3| | */ -#define WSBIT_FIN (0x80) -#define WSBIT_RSV1 (0x40) -#define WSBIT_RSV2 (0x20) -#define WSBIT_RSV3 (0x10) -#define WSBIT_RSV_MASK (WSBIT_RSV1 | WSBIT_RSV2 | WSBIT_RSV3) +#define WSBIT_FIN (0x80) +#define WSBIT_RSV1 (0x40) +#define WSBIT_RSV2 (0x20) +#define WSBIT_RSV3 (0x10) +#define WSBIT_RSV_MASK (WSBIT_RSV1 | WSBIT_RSV2 | WSBIT_RSV3) #define WSBIT_OPCODE_CONT (0x0) #define WSBIT_OPCODE_TEXT (0x1) #define WSBIT_OPCODE_BIN (0x2) @@ -73,10 +68,9 @@ #define WSBIT_MASK 0x80 /* buffer dimensioning */ -#define WS_CHUNK_SIZE 65535 +#define WS_CHUNK_SIZE 65535 #define WS_CHUNK_COUNT 2 - /* a client-side WS frame decoder, parsing frame headers and * payload, keeping track of current position and stats */ enum ws_dec_state { @@ -90,7 +84,7 @@ struct ws_decoder { int frame_flags; /* See the CURLWS_* defines */ curl_off_t payload_offset; /* the offset parsing is at */ curl_off_t payload_len; - unsigned char head[10]; + uint8_t head[10]; int head_len, head_total; enum ws_dec_state state; int cont_flags; @@ -102,8 +96,8 @@ struct ws_encoder { curl_off_t payload_len; /* payload length of current frame */ curl_off_t payload_remain; /* remaining payload of current */ unsigned int xori; /* xor index */ - unsigned char mask[4]; /* 32-bit mask for this connection */ - unsigned char firstbyte; /* first byte of frame we encode */ + uint8_t mask[4]; /* 32-bit mask for this connection */ + uint8_t firstbyte; /* first byte of frame we encode */ BIT(contfragment); /* set TRUE if the previous fragment sent was not final */ }; @@ -113,7 +107,7 @@ struct ws_encoder { struct ws_cntrl_frame { unsigned int type; size_t payload_len; - unsigned char payload[WS_MAX_CNTRL_LEN]; + uint8_t payload[WS_MAX_CNTRL_LEN]; }; /* A websocket connection with en- and decoder that treat frames @@ -129,166 +123,165 @@ struct websocket { size_t sendbuf_payload; /* number of payload bytes in sendbuf */ }; - -static const char *ws_frame_name_of_op(unsigned char firstbyte) +static const char *ws_frame_name_of_op(uint8_t firstbyte) { switch(firstbyte & WSBIT_OPCODE_MASK) { - case WSBIT_OPCODE_CONT: - return "CONT"; - case WSBIT_OPCODE_TEXT: - return "TEXT"; - case WSBIT_OPCODE_BIN: - return "BIN"; - case WSBIT_OPCODE_CLOSE: - return "CLOSE"; - case WSBIT_OPCODE_PING: - return "PING"; - case WSBIT_OPCODE_PONG: - return "PONG"; - default: - return "???"; + case WSBIT_OPCODE_CONT: + return "CONT"; + case WSBIT_OPCODE_TEXT: + return "TEXT"; + case WSBIT_OPCODE_BIN: + return "BIN"; + case WSBIT_OPCODE_CLOSE: + return "CLOSE"; + case WSBIT_OPCODE_PING: + return "PING"; + case WSBIT_OPCODE_PONG: + return "PONG"; + default: + return "???"; } } static int ws_frame_firstbyte2flags(struct Curl_easy *data, - unsigned char firstbyte, int cont_flags) + uint8_t firstbyte, int cont_flags) { switch(firstbyte) { - /* 0x00 - intermediate TEXT/BINARY fragment */ - case WSBIT_OPCODE_CONT: - if(!(cont_flags & CURLWS_CONT)) { - failf(data, "[WS] no ongoing fragmented message to resume"); - return 0; - } - return cont_flags | CURLWS_CONT; - /* 0x80 - final TEXT/BIN fragment */ - case (WSBIT_OPCODE_CONT | WSBIT_FIN): - if(!(cont_flags & CURLWS_CONT)) { - failf(data, "[WS] no ongoing fragmented message to resume"); - return 0; - } - return cont_flags & ~CURLWS_CONT; - /* 0x01 - first TEXT fragment */ - case WSBIT_OPCODE_TEXT: - if(cont_flags & CURLWS_CONT) { - failf(data, "[WS] fragmented message interrupted by new TEXT msg"); - return 0; - } - return CURLWS_TEXT | CURLWS_CONT; - /* 0x81 - unfragmented TEXT msg */ - case (WSBIT_OPCODE_TEXT | WSBIT_FIN): - if(cont_flags & CURLWS_CONT) { - failf(data, "[WS] fragmented message interrupted by new TEXT msg"); - return 0; - } - return CURLWS_TEXT; - /* 0x02 - first BINARY fragment */ - case WSBIT_OPCODE_BIN: - if(cont_flags & CURLWS_CONT) { - failf(data, "[WS] fragmented message interrupted by new BINARY msg"); - return 0; - } - return CURLWS_BINARY | CURLWS_CONT; - /* 0x82 - unfragmented BINARY msg */ - case (WSBIT_OPCODE_BIN | WSBIT_FIN): - if(cont_flags & CURLWS_CONT) { - failf(data, "[WS] fragmented message interrupted by new BINARY msg"); - return 0; - } - return CURLWS_BINARY; - /* 0x08 - first CLOSE fragment */ - case WSBIT_OPCODE_CLOSE: - failf(data, "[WS] invalid fragmented CLOSE frame"); + /* 0x00 - intermediate TEXT/BINARY fragment */ + case WSBIT_OPCODE_CONT: + if(!(cont_flags & CURLWS_CONT)) { + failf(data, "[WS] no ongoing fragmented message to resume"); return 0; - /* 0x88 - unfragmented CLOSE */ - case (WSBIT_OPCODE_CLOSE | WSBIT_FIN): - return CURLWS_CLOSE; - /* 0x09 - first PING fragment */ - case WSBIT_OPCODE_PING: - failf(data, "[WS] invalid fragmented PING frame"); + } + return cont_flags | CURLWS_CONT; + /* 0x80 - final TEXT/BIN fragment */ + case (WSBIT_OPCODE_CONT | WSBIT_FIN): + if(!(cont_flags & CURLWS_CONT)) { + failf(data, "[WS] no ongoing fragmented message to resume"); return 0; - /* 0x89 - unfragmented PING */ - case (WSBIT_OPCODE_PING | WSBIT_FIN): - return CURLWS_PING; - /* 0x0a - first PONG fragment */ - case WSBIT_OPCODE_PONG: - failf(data, "[WS] invalid fragmented PONG frame"); + } + return cont_flags & ~CURLWS_CONT; + /* 0x01 - first TEXT fragment */ + case WSBIT_OPCODE_TEXT: + if(cont_flags & CURLWS_CONT) { + failf(data, "[WS] fragmented message interrupted by new TEXT msg"); return 0; - /* 0x8a - unfragmented PONG */ - case (WSBIT_OPCODE_PONG | WSBIT_FIN): - return CURLWS_PONG; - /* invalid first byte */ - default: - if(firstbyte & WSBIT_RSV_MASK) - /* any of the reserved bits 0x40/0x20/0x10 are set */ - failf(data, "[WS] invalid reserved bits: %02x", firstbyte); - else - /* any of the reserved opcodes 0x3-0x7 or 0xb-0xf is used */ - failf(data, "[WS] invalid opcode: %02x", firstbyte); + } + return CURLWS_TEXT | CURLWS_CONT; + /* 0x81 - unfragmented TEXT msg */ + case (WSBIT_OPCODE_TEXT | WSBIT_FIN): + if(cont_flags & CURLWS_CONT) { + failf(data, "[WS] fragmented message interrupted by new TEXT msg"); return 0; + } + return CURLWS_TEXT; + /* 0x02 - first BINARY fragment */ + case WSBIT_OPCODE_BIN: + if(cont_flags & CURLWS_CONT) { + failf(data, "[WS] fragmented message interrupted by new BINARY msg"); + return 0; + } + return CURLWS_BINARY | CURLWS_CONT; + /* 0x82 - unfragmented BINARY msg */ + case (WSBIT_OPCODE_BIN | WSBIT_FIN): + if(cont_flags & CURLWS_CONT) { + failf(data, "[WS] fragmented message interrupted by new BINARY msg"); + return 0; + } + return CURLWS_BINARY; + /* 0x08 - first CLOSE fragment */ + case WSBIT_OPCODE_CLOSE: + failf(data, "[WS] invalid fragmented CLOSE frame"); + return 0; + /* 0x88 - unfragmented CLOSE */ + case (WSBIT_OPCODE_CLOSE | WSBIT_FIN): + return CURLWS_CLOSE; + /* 0x09 - first PING fragment */ + case WSBIT_OPCODE_PING: + failf(data, "[WS] invalid fragmented PING frame"); + return 0; + /* 0x89 - unfragmented PING */ + case (WSBIT_OPCODE_PING | WSBIT_FIN): + return CURLWS_PING; + /* 0x0a - first PONG fragment */ + case WSBIT_OPCODE_PONG: + failf(data, "[WS] invalid fragmented PONG frame"); + return 0; + /* 0x8a - unfragmented PONG */ + case (WSBIT_OPCODE_PONG | WSBIT_FIN): + return CURLWS_PONG; + /* invalid first byte */ + default: + if(firstbyte & WSBIT_RSV_MASK) + /* any of the reserved bits 0x40/0x20/0x10 are set */ + failf(data, "[WS] invalid reserved bits: %02x", firstbyte); + else + /* any of the reserved opcodes 0x3-0x7 or 0xb-0xf is used */ + failf(data, "[WS] invalid opcode: %02x", firstbyte); + return 0; } } static CURLcode ws_frame_flags2firstbyte(struct Curl_easy *data, unsigned int flags, bool contfragment, - unsigned char *pfirstbyte) + uint8_t *pfirstbyte) { *pfirstbyte = 0; switch(flags & ~CURLWS_OFFSET) { - case 0: - if(contfragment) { - CURL_TRC_WS(data, "no flags given; interpreting as continuation " - "fragment for compatibility"); - *pfirstbyte = (WSBIT_OPCODE_CONT | WSBIT_FIN); - return CURLE_OK; - } - failf(data, "[WS] no flags given"); - return CURLE_BAD_FUNCTION_ARGUMENT; - case CURLWS_CONT: - if(contfragment) { - infof(data, "[WS] setting CURLWS_CONT flag without message type is " - "supported for compatibility but highly discouraged"); - *pfirstbyte = WSBIT_OPCODE_CONT; - return CURLE_OK; - } - failf(data, "[WS] No ongoing fragmented message to continue"); - return CURLE_BAD_FUNCTION_ARGUMENT; - case CURLWS_TEXT: - *pfirstbyte = contfragment ? (WSBIT_OPCODE_CONT | WSBIT_FIN) - : (WSBIT_OPCODE_TEXT | WSBIT_FIN); - return CURLE_OK; - case (CURLWS_TEXT | CURLWS_CONT): - *pfirstbyte = contfragment ? WSBIT_OPCODE_CONT : WSBIT_OPCODE_TEXT; - return CURLE_OK; - case CURLWS_BINARY: - *pfirstbyte = contfragment ? (WSBIT_OPCODE_CONT | WSBIT_FIN) - : (WSBIT_OPCODE_BIN | WSBIT_FIN); - return CURLE_OK; - case (CURLWS_BINARY | CURLWS_CONT): - *pfirstbyte = contfragment ? WSBIT_OPCODE_CONT : WSBIT_OPCODE_BIN; - return CURLE_OK; - case CURLWS_CLOSE: - *pfirstbyte = WSBIT_OPCODE_CLOSE | WSBIT_FIN; - return CURLE_OK; - case (CURLWS_CLOSE | CURLWS_CONT): - failf(data, "[WS] CLOSE frame must not be fragmented"); - return CURLE_BAD_FUNCTION_ARGUMENT; - case CURLWS_PING: - *pfirstbyte = WSBIT_OPCODE_PING | WSBIT_FIN; + case 0: + if(contfragment) { + CURL_TRC_WS(data, "no flags given; interpreting as continuation " + "fragment for compatibility"); + *pfirstbyte = (WSBIT_OPCODE_CONT | WSBIT_FIN); return CURLE_OK; - case (CURLWS_PING | CURLWS_CONT): - failf(data, "[WS] PING frame must not be fragmented"); - return CURLE_BAD_FUNCTION_ARGUMENT; - case CURLWS_PONG: - *pfirstbyte = WSBIT_OPCODE_PONG | WSBIT_FIN; + } + failf(data, "[WS] no flags given"); + return CURLE_BAD_FUNCTION_ARGUMENT; + case CURLWS_CONT: + if(contfragment) { + infof(data, "[WS] setting CURLWS_CONT flag without message type is " + "supported for compatibility but highly discouraged"); + *pfirstbyte = WSBIT_OPCODE_CONT; return CURLE_OK; - case (CURLWS_PONG | CURLWS_CONT): - failf(data, "[WS] PONG frame must not be fragmented"); - return CURLE_BAD_FUNCTION_ARGUMENT; - default: - failf(data, "[WS] unknown flags: %x", flags); - return CURLE_BAD_FUNCTION_ARGUMENT; + } + failf(data, "[WS] No ongoing fragmented message to continue"); + return CURLE_BAD_FUNCTION_ARGUMENT; + case CURLWS_TEXT: + *pfirstbyte = contfragment ? (WSBIT_OPCODE_CONT | WSBIT_FIN) + : (WSBIT_OPCODE_TEXT | WSBIT_FIN); + return CURLE_OK; + case (CURLWS_TEXT | CURLWS_CONT): + *pfirstbyte = contfragment ? WSBIT_OPCODE_CONT : WSBIT_OPCODE_TEXT; + return CURLE_OK; + case CURLWS_BINARY: + *pfirstbyte = contfragment ? (WSBIT_OPCODE_CONT | WSBIT_FIN) + : (WSBIT_OPCODE_BIN | WSBIT_FIN); + return CURLE_OK; + case (CURLWS_BINARY | CURLWS_CONT): + *pfirstbyte = contfragment ? WSBIT_OPCODE_CONT : WSBIT_OPCODE_BIN; + return CURLE_OK; + case CURLWS_CLOSE: + *pfirstbyte = WSBIT_OPCODE_CLOSE | WSBIT_FIN; + return CURLE_OK; + case (CURLWS_CLOSE | CURLWS_CONT): + failf(data, "[WS] CLOSE frame must not be fragmented"); + return CURLE_BAD_FUNCTION_ARGUMENT; + case CURLWS_PING: + *pfirstbyte = WSBIT_OPCODE_PING | WSBIT_FIN; + return CURLE_OK; + case (CURLWS_PING | CURLWS_CONT): + failf(data, "[WS] PING frame must not be fragmented"); + return CURLE_BAD_FUNCTION_ARGUMENT; + case CURLWS_PONG: + *pfirstbyte = WSBIT_OPCODE_PONG | WSBIT_FIN; + return CURLE_OK; + case (CURLWS_PONG | CURLWS_CONT): + failf(data, "[WS] PONG frame must not be fragmented"); + return CURLE_BAD_FUNCTION_ARGUMENT; + default: + failf(data, "[WS] unknown flags: %x", flags); + return CURLE_BAD_FUNCTION_ARGUMENT; } } @@ -325,7 +318,7 @@ static CURLcode ws_send_raw_blocking(struct Curl_easy *data, struct websocket *ws, const char *buffer, size_t buflen); -typedef CURLcode ws_write_payload(const unsigned char *buf, size_t buflen, +typedef CURLcode ws_write_payload(const uint8_t *buf, size_t buflen, int frame_age, int frame_flags, curl_off_t payload_offset, curl_off_t payload_len, @@ -363,7 +356,7 @@ static CURLcode ws_dec_read_head(struct ws_decoder *dec, struct Curl_easy *data, struct bufq *inraw) { - const unsigned char *inbuf; + const uint8_t *inbuf; size_t inlen; while(Curl_bufq_peek(inraw, &inbuf, &inlen)) { @@ -455,13 +448,14 @@ static CURLcode ws_dec_read_head(struct ws_decoder *dec, failf(data, "[WS] frame length longer than 63 bit not supported"); return CURLE_RECV_ERROR; } - dec->payload_len = ((curl_off_t)dec->head[2] << 56) | + dec->payload_len = + (curl_off_t)dec->head[2] << 56 | (curl_off_t)dec->head[3] << 48 | (curl_off_t)dec->head[4] << 40 | (curl_off_t)dec->head[5] << 32 | (curl_off_t)dec->head[6] << 24 | (curl_off_t)dec->head[7] << 16 | - (curl_off_t)dec->head[8] << 8 | + (curl_off_t)dec->head[8] << 8 | dec->head[9]; break; default: @@ -485,16 +479,17 @@ static CURLcode ws_dec_pass_payload(struct ws_decoder *dec, ws_write_payload *write_cb, void *write_ctx) { - const unsigned char *inbuf; + const uint8_t *inbuf; size_t inlen; size_t nwritten; CURLcode result; - curl_off_t remain = dec->payload_len - dec->payload_offset; + size_t remain = curlx_sotouz_range(dec->payload_len - dec->payload_offset, + 0, SIZE_MAX); (void)data; while(remain && Curl_bufq_peek(inraw, &inbuf, &inlen)) { - if((curl_off_t)inlen > remain) - inlen = (size_t)remain; + if(inlen > remain) + inlen = remain; result = write_cb(inbuf, inlen, dec->frame_age, dec->frame_flags, dec->payload_offset, dec->payload_len, write_ctx, &nwritten); @@ -502,9 +497,10 @@ static CURLcode ws_dec_pass_payload(struct ws_decoder *dec, return result; Curl_bufq_skip(inraw, nwritten); dec->payload_offset += nwritten; - remain = dec->payload_len - dec->payload_offset; - CURL_TRC_WS(data, "passed %zu bytes payload, %" - FMT_OFF_T " remain", nwritten, remain); + remain = curlx_sotouz_range(dec->payload_len - dec->payload_offset, + 0, SIZE_MAX); + CURL_TRC_WS(data, "passed %zu bytes payload, %zu remain", + nwritten, remain); } return remain ? CURLE_AGAIN : CURLE_OK; @@ -541,7 +537,7 @@ static CURLcode ws_dec_pass(struct ws_decoder *dec, dec->state = WS_DEC_PAYLOAD; if(dec->payload_len == 0) { size_t nwritten; - const unsigned char tmp = '\0'; + const uint8_t tmp = '\0'; /* special case of a 0 length frame, need to write once */ result = write_cb(&tmp, 0, dec->frame_age, dec->frame_flags, 0, 0, write_ctx, &nwritten); @@ -614,7 +610,7 @@ static CURLcode ws_flush(struct Curl_easy *data, struct websocket *ws, bool blocking); static CURLcode ws_enc_send(struct Curl_easy *data, struct websocket *ws, - const unsigned char *buffer, + const uint8_t *buffer, size_t buflen, curl_off_t fragsize, unsigned int flags, @@ -624,7 +620,7 @@ static CURLcode ws_enc_add_pending(struct Curl_easy *data, static CURLcode ws_enc_add_cntrl(struct Curl_easy *data, struct websocket *ws, - const unsigned char *payload, + const uint8_t *payload, size_t plen, unsigned int frame_type) { @@ -651,19 +647,16 @@ static curl_off_t ws_payload_remain(curl_off_t payload_total, curl_off_t payload_offset, size_t payload_buffered) { - curl_off_t remain = payload_total - payload_offset; + curl_off_t buffered, remain = payload_total - payload_offset; if((payload_total < 0) || (payload_offset < 0) || (remain < 0)) return -1; -#if SIZEOF_SIZE_T >= SIZEOF_CURL_OFF_T - if(payload_buffered > (size_t)CURL_OFF_T_MAX) - return -1; -#endif - if(remain < (curl_off_t)payload_buffered) + buffered = curlx_uztoso(payload_buffered); + if(remain < buffered) return -1; - return remain - (curl_off_t)payload_buffered; + return remain - buffered; } -static CURLcode ws_cw_dec_next(const unsigned char *buf, size_t buflen, +static CURLcode ws_cw_dec_next(const uint8_t *buf, size_t buflen, int frame_age, int frame_flags, curl_off_t payload_offset, curl_off_t payload_len, @@ -729,7 +722,7 @@ static CURLcode ws_cw_write(struct Curl_easy *data, if(nbytes) { size_t nwritten; - result = Curl_bufq_write(&ctx->buf, (const unsigned char *)buf, + result = Curl_bufq_write(&ctx->buf, (const uint8_t *)buf, nbytes, &nwritten); if(result) { infof(data, "[WS] error adding data to buffer %d", result); @@ -775,7 +768,6 @@ static const struct Curl_cwtype ws_cw_decode = { sizeof(struct ws_cw_ctx) }; - static void ws_enc_info(struct ws_encoder *enc, struct Curl_easy *data, const char *msg) { @@ -827,8 +819,8 @@ static CURLcode ws_enc_add_frame(struct Curl_easy *data, curl_off_t payload_len, struct bufq *out) { - unsigned char firstb = 0; - unsigned char head[14]; + uint8_t firstb = 0; + uint8_t head[14]; CURLcode result; size_t hlen, nwritten; @@ -840,8 +832,8 @@ static CURLcode ws_enc_add_frame(struct Curl_easy *data, if(enc->payload_remain > 0) { /* trying to write a new frame before the previous one is finished */ - failf(data, "[WS] starting new frame with %zd bytes from last one " - "remaining to be sent", (ssize_t)enc->payload_remain); + failf(data, "[WS] starting new frame with %" FMT_OFF_T " bytes " + "from last one remaining to be sent", enc->payload_remain); return CURLE_SEND_ERROR; } @@ -871,24 +863,24 @@ static CURLcode ws_enc_add_frame(struct Curl_easy *data, head[0] = enc->firstbyte = firstb; if(payload_len > 65535) { head[1] = 127 | WSBIT_MASK; - head[2] = (unsigned char)((payload_len >> 56) & 0xff); - head[3] = (unsigned char)((payload_len >> 48) & 0xff); - head[4] = (unsigned char)((payload_len >> 40) & 0xff); - head[5] = (unsigned char)((payload_len >> 32) & 0xff); - head[6] = (unsigned char)((payload_len >> 24) & 0xff); - head[7] = (unsigned char)((payload_len >> 16) & 0xff); - head[8] = (unsigned char)((payload_len >> 8) & 0xff); - head[9] = (unsigned char)(payload_len & 0xff); + head[2] = (uint8_t)((payload_len >> 56) & 0xff); + head[3] = (uint8_t)((payload_len >> 48) & 0xff); + head[4] = (uint8_t)((payload_len >> 40) & 0xff); + head[5] = (uint8_t)((payload_len >> 32) & 0xff); + head[6] = (uint8_t)((payload_len >> 24) & 0xff); + head[7] = (uint8_t)((payload_len >> 16) & 0xff); + head[8] = (uint8_t)((payload_len >> 8) & 0xff); + head[9] = (uint8_t)(payload_len & 0xff); hlen = 10; } else if(payload_len >= 126) { head[1] = 126 | WSBIT_MASK; - head[2] = (unsigned char)((payload_len >> 8) & 0xff); - head[3] = (unsigned char)(payload_len & 0xff); + head[2] = (uint8_t)((payload_len >> 8) & 0xff); + head[3] = (uint8_t)(payload_len & 0xff); hlen = 4; } else { - head[1] = (unsigned char)payload_len | WSBIT_MASK; + head[1] = (uint8_t)payload_len | WSBIT_MASK; hlen = 2; } @@ -897,7 +889,7 @@ static CURLcode ws_enc_add_frame(struct Curl_easy *data, /* 4 bytes random */ - result = Curl_rand(data, (unsigned char *)&enc->mask, sizeof(enc->mask)); + result = Curl_rand(data, (uint8_t *)&enc->mask, sizeof(enc->mask)); if(result) return result; @@ -943,11 +935,11 @@ static CURLcode ws_enc_write_head(struct Curl_easy *data, static CURLcode ws_enc_write_payload(struct ws_encoder *enc, struct Curl_easy *data, - const unsigned char *buf, size_t buflen, + const uint8_t *buf, size_t buflen, struct bufq *out, size_t *pnwritten) { CURLcode result; - size_t i, len, n; + size_t i, len, n, remain; *pnwritten = 0; if(Curl_bufq_is_full(out)) @@ -955,11 +947,12 @@ static CURLcode ws_enc_write_payload(struct ws_encoder *enc, /* not the most performant way to do this */ len = buflen; - if((curl_off_t)len > enc->payload_remain) - len = (size_t)enc->payload_remain; + remain = curlx_sotouz_range(enc->payload_remain, 0, SIZE_MAX); + if(remain < len) + len = remain; for(i = 0; i < len; ++i) { - unsigned char c = buf[i] ^ enc->mask[enc->xori]; + uint8_t c = buf[i] ^ enc->mask[enc->xori]; result = Curl_bufq_write(out, &c, 1, &n); if(result) { if((result != CURLE_AGAIN) || !i) @@ -1019,7 +1012,7 @@ static CURLcode ws_enc_add_pending(struct Curl_easy *data, static CURLcode ws_enc_send(struct Curl_easy *data, struct websocket *ws, - const unsigned char *buffer, + const uint8_t *buffer, size_t buflen, curl_off_t fragsize, unsigned int flags, @@ -1036,7 +1029,7 @@ static CURLcode ws_enc_send(struct Curl_easy *data, * that needs to be encoded into the buffer */ if(buflen < ws->sendbuf_payload) { /* We have been called with LESS buffer data than before. This - * is not how it's supposed too work. */ + * is not how it is supposed too work. */ failf(data, "[WS] curl_ws_send() called with smaller 'buflen' than " "bytes already buffered in previous call, %zu vs %zu", buflen, ws->sendbuf_payload); @@ -1167,8 +1160,7 @@ static CURLcode cr_ws_read(struct Curl_easy *data, if(ws->enc.payload_remain) { CURL_TRC_WS(data, "current frame, %" FMT_OFF_T " remaining", ws->enc.payload_remain); - if(ws->enc.payload_remain < (curl_off_t)blen) - blen = (size_t)ws->enc.payload_remain; + blen = curlx_sotouz_range(ws->enc.payload_remain, 0, blen); } result = Curl_creader_read(data, reader->next, buf, blen, &nread, &eos); @@ -1198,7 +1190,7 @@ static CURLcode cr_ws_read(struct Curl_easy *data, goto out; } - result = ws_enc_write_payload(&ws->enc, data, (unsigned char *)buf, + result = ws_enc_write_payload(&ws->enc, data, (uint8_t *)buf, nread, &ws->sendbuf, &n); if(result) goto out; @@ -1234,7 +1226,6 @@ static const struct Curl_crtype ws_cr_encode = { sizeof(struct cr_ws_ctx) }; - struct wsfield { const char *name; const char *val; @@ -1244,12 +1235,12 @@ CURLcode Curl_ws_request(struct Curl_easy *data, struct dynbuf *req) { unsigned int i; CURLcode result = CURLE_OK; - unsigned char rand[16]; + uint8_t rand[16]; char *randstr; size_t randlen; char keyval[40]; struct SingleRequest *k = &data->req; - struct wsfield heads[]= { + struct wsfield heads[] = { { /* The request MUST contain an |Upgrade| header field whose value MUST include the "websocket" keyword. */ @@ -1273,23 +1264,22 @@ CURLcode Curl_ws_request(struct Curl_easy *data, struct dynbuf *req) heads[2].val = &keyval[0]; /* 16 bytes random */ - result = Curl_rand(data, (unsigned char *)rand, sizeof(rand)); + result = Curl_rand(data, rand, sizeof(rand)); if(result) return result; - result = curlx_base64_encode((char *)rand, sizeof(rand), &randstr, &randlen); + result = curlx_base64_encode(rand, sizeof(rand), &randstr, &randlen); if(result) return result; DEBUGASSERT(randlen < sizeof(keyval)); if(randlen >= sizeof(keyval)) { - free(randstr); + curlx_free(randstr); return CURLE_FAILED_INIT; } - strcpy(keyval, randstr); - free(randstr); + curlx_strcopy(keyval, sizeof(keyval), randstr, randlen); + curlx_free(randstr); for(i = 0; !result && (i < CURL_ARRAYSIZE(heads)); i++) { if(!Curl_checkheaders(data, heads[i].name, strlen(heads[i].name))) { - result = curlx_dyn_addf(req, "%s: %s\r\n", heads[i].name, - heads[i].val); + result = curlx_dyn_addf(req, "%s: %s\r\n", heads[i].name, heads[i].val); } } data->state.http_hd_upgrade = TRUE; @@ -1305,7 +1295,7 @@ static void ws_conn_dtor(void *key, size_t klen, void *entry) (void)klen; Curl_bufq_free(&ws->recvbuf); Curl_bufq_free(&ws->sendbuf); - free(ws); + curlx_free(ws); } /* @@ -1325,7 +1315,7 @@ CURLcode Curl_ws_accept(struct Curl_easy *data, ws = Curl_conn_meta_get(data->conn, CURL_META_PROTO_WS_CONN); if(!ws) { size_t chunk_size = WS_CHUNK_SIZE; - ws = calloc(1, sizeof(*ws)); + ws = curlx_calloc(1, sizeof(*ws)); if(!ws) return CURLE_OUT_OF_MEMORY; #ifdef DEBUGBUILD @@ -1333,7 +1323,7 @@ CURLcode Curl_ws_accept(struct Curl_easy *data, const char *p = getenv("CURL_WS_CHUNK_SIZE"); if(p) { curl_off_t l; - if(!curlx_str_number(&p, &l, 1*1024*1024)) + if(!curlx_str_number(&p, &l, 1 * 1024 * 1024)) chunk_size = (size_t)l; } } @@ -1393,7 +1383,7 @@ CURLcode Curl_ws_accept(struct Curl_easy *data, /* In CONNECT_ONLY setup, the payloads from `mem` need to be received * when using `curl_ws_recv` later on after this transfer is already * marked as DONE. */ - result = Curl_bufq_write(&ws->recvbuf, (const unsigned char *)mem, + result = Curl_bufq_write(&ws->recvbuf, (const uint8_t *)mem, nread, &nwritten); if(result) goto out; @@ -1452,7 +1442,7 @@ CURLcode Curl_ws_accept(struct Curl_easy *data, struct ws_collect { struct Curl_easy *data; struct websocket *ws; - unsigned char *buffer; + uint8_t *buffer; size_t buflen; size_t bufidx; int frame_age; @@ -1462,7 +1452,7 @@ struct ws_collect { bool written; }; -static CURLcode ws_client_collect(const unsigned char *buf, size_t buflen, +static CURLcode ws_client_collect(const uint8_t *buf, size_t buflen, int frame_age, int frame_flags, curl_off_t payload_offset, curl_off_t payload_len, @@ -1519,7 +1509,7 @@ static CURLcode ws_client_collect(const unsigned char *buf, size_t buflen, } static CURLcode nw_in_recv(void *reader_ctx, - unsigned char *buf, size_t buflen, + uint8_t *buf, size_t buflen, size_t *pnread) { struct Curl_easy *data = reader_ctx; @@ -1560,7 +1550,6 @@ CURLcode curl_ws_recv(CURL *d, void *buffer, return CURLE_BAD_FUNCTION_ARGUMENT; } - memset(&ctx, 0, sizeof(ctx)); ctx.data = data; ctx.ws = ws; @@ -1629,7 +1618,7 @@ static CURLcode ws_flush(struct Curl_easy *data, struct websocket *ws, { if(!Curl_bufq_is_empty(&ws->sendbuf)) { CURLcode result; - const unsigned char *out; + const uint8_t *out; size_t outlen, n; #ifdef DEBUGBUILD /* Simulate a blocking send after this chunk has been sent */ @@ -1638,7 +1627,7 @@ static CURLcode ws_flush(struct Curl_easy *data, struct websocket *ws, const char *p = getenv("CURL_WS_CHUNK_EAGAIN"); if(p) { curl_off_t l; - if(!curlx_str_number(&p, &l, 1*1024*1024)) + if(!curlx_str_number(&p, &l, 1 * 1024 * 1024)) chunk_egain = (size_t)l; } #endif @@ -1704,7 +1693,7 @@ static CURLcode ws_send_raw_blocking(struct Curl_easy *data, CURL_TRC_WS(data, "ws_send_raw_blocking() partial, %zu left to send", buflen); - left_ms = Curl_timeleft(data, NULL, FALSE); + left_ms = Curl_timeleft_ms(data, FALSE); if(left_ms < 0) { failf(data, "[WS] Timeout waiting for socket becoming writable"); return CURLE_SEND_ERROR; @@ -1713,8 +1702,7 @@ static CURLcode ws_send_raw_blocking(struct Curl_easy *data, /* POLLOUT socket */ if(sock == CURL_SOCKET_BAD) return CURLE_SEND_ERROR; - ev = Curl_socket_check(CURL_SOCKET_BAD, CURL_SOCKET_BAD, sock, - left_ms ? left_ms : 500); + ev = SOCKET_WRITABLE(sock, left_ms ? left_ms : 500); if(ev < 0) { failf(data, "[WS] Error while waiting for socket becoming writable"); return CURLE_SEND_ERROR; @@ -1767,7 +1755,7 @@ CURLcode curl_ws_send(CURL *d, const void *buffer_arg, unsigned int flags) { struct websocket *ws; - const unsigned char *buffer = buffer_arg; + const uint8_t *buffer = buffer_arg; CURLcode result = CURLE_OK; struct Curl_easy *data = d; size_t ndummy; @@ -1849,7 +1837,6 @@ static CURLcode ws_setup_conn(struct Curl_easy *data, return Curl_http_setup_conn(data, conn); } - const struct curl_ws_frame *curl_ws_meta(CURL *d) { /* we only return something for websocket, called from within the callback @@ -1861,7 +1848,6 @@ const struct curl_ws_frame *curl_ws_meta(CURL *d) ws = Curl_conn_meta_get(data->conn, CURL_META_PROTO_WS_CONN); if(ws) return &ws->recvframe; - } return NULL; } @@ -1924,13 +1910,13 @@ const struct Curl_handler Curl_handler_ws = { Curl_http, /* do_it */ Curl_http_done, /* done */ ZERO_NULL, /* do_more */ - Curl_http_connect, /* connect_it */ + ZERO_NULL, /* connect_it */ ZERO_NULL, /* connecting */ ZERO_NULL, /* doing */ ZERO_NULL, /* proto_pollset */ - Curl_http_do_pollset, /* doing_pollset */ + Curl_http_doing_pollset, /* doing_pollset */ ZERO_NULL, /* domore_pollset */ - ZERO_NULL, /* perform_pollset */ + Curl_http_perform_pollset, /* perform_pollset */ ZERO_NULL, /* disconnect */ Curl_http_write_resp, /* write_resp */ Curl_http_write_resp_hd, /* write_resp_hd */ @@ -1951,13 +1937,13 @@ const struct Curl_handler Curl_handler_wss = { Curl_http, /* do_it */ Curl_http_done, /* done */ ZERO_NULL, /* do_more */ - Curl_http_connect, /* connect_it */ + ZERO_NULL, /* connect_it */ NULL, /* connecting */ ZERO_NULL, /* doing */ NULL, /* proto_pollset */ - Curl_http_do_pollset, /* doing_pollset */ + Curl_http_doing_pollset, /* doing_pollset */ ZERO_NULL, /* domore_pollset */ - ZERO_NULL, /* perform_pollset */ + Curl_http_perform_pollset, /* perform_pollset */ ZERO_NULL, /* disconnect */ Curl_http_write_resp, /* write_resp */ Curl_http_write_resp_hd, /* write_resp_hd */ @@ -1968,11 +1954,10 @@ const struct Curl_handler Curl_handler_wss = { CURLPROTO_WSS, /* protocol */ CURLPROTO_HTTP, /* family */ PROTOPT_SSL | PROTOPT_CREDSPERREQUEST | /* flags */ - PROTOPT_USERPWDCTRL + PROTOPT_USERPWDCTRL }; #endif - #else CURLcode curl_ws_recv(CURL *curl, void *buffer, size_t buflen, @@ -2017,4 +2002,4 @@ CURL_EXTERN CURLcode curl_ws_start_frame(CURL *curl, return CURLE_NOT_BUILT_IN; } -#endif /* !CURL_DISABLE_WEBSOCKETS */ +#endif /* !CURL_DISABLE_WEBSOCKETS && !CURL_DISABLE_HTTP */ diff --git a/vendor/hydra/vendor/curl/lib/ws.h b/vendor/hydra/vendor/curl/lib/ws.h index b7655abb..a6e77069 100644 --- a/vendor/hydra/vendor/curl/lib/ws.h +++ b/vendor/hydra/vendor/curl/lib/ws.h @@ -38,10 +38,9 @@ extern const struct Curl_handler Curl_handler_ws; extern const struct Curl_handler Curl_handler_wss; #endif - #else -#define Curl_ws_request(x,y) CURLE_OK -#define Curl_ws_free(x) Curl_nop_stmt +#define Curl_ws_request(x, y) CURLE_OK +#define Curl_ws_free(x) Curl_nop_stmt #endif #endif /* HEADER_CURL_WS_H */