From 37d3442dc789d22fa802c9513c7fefbd2614b3a2 Mon Sep 17 00:00:00 2001 From: B Stack Date: Wed, 18 Mar 2020 14:13:41 -0400 Subject: add upstream 10.22 --- zen/format_unit.cpp | 2 +- zen/open_ssl.cpp | 17 ++++++++++++----- zen/string_base.h | 7 ++++--- zen/zstring.cpp | 2 +- 4 files changed, 18 insertions(+), 10 deletions(-) (limited to 'zen') diff --git a/zen/format_unit.cpp b/zen/format_unit.cpp index 91a881dc..eeebda53 100644 --- a/zen/format_unit.cpp +++ b/zen/format_unit.cpp @@ -191,7 +191,7 @@ std::wstring zen::formatNumber(int64_t n) std::wstring zen::formatUtcToLocalTime(time_t utcTime) { - auto errorMsg = [&] { return _("Error") + L" (time_t: " + numberTo(utcTime) + L")"; }; + auto errorMsg = [&] { return _("Error") + L" (time_t: " + numberTo(utcTime) + L')'; }; TimeComp loc = getLocalTime(utcTime); diff --git a/zen/open_ssl.cpp b/zen/open_ssl.cpp index b823f8ca..0f1da3fc 100644 --- a/zen/open_ssl.cpp +++ b/zen/open_ssl.cpp @@ -18,7 +18,7 @@ using namespace zen; #error FFS, we are royally screwed! #endif -static_assert(OPENSSL_VERSION_NUMBER >= 0x10100000L, "OpenSSL version too old"); +static_assert(OPENSSL_VERSION_NUMBER >= 0x1010105fL, "OpenSSL version too old"); void zen::openSslInit() @@ -68,7 +68,7 @@ std::wstring formatOpenSSLError(const std::wstring& functionName, unsigned long std::wstring formatLastOpenSSLError(const std::wstring& functionName) { - const unsigned long ec = ::ERR_peek_last_error(); + const auto ec = ::ERR_peek_last_error(); ::ERR_clear_error(); //clean up for next OpenSSL operation on this thread return formatOpenSSLError(functionName, ec); } @@ -566,9 +566,16 @@ public: if (rv != 1) { const int sslError = ::SSL_get_error(ssl_, rv); - if (sslError == SSL_ERROR_ZERO_RETURN || //EOF + close_notify alert - (sslError == SSL_ERROR_SYSCALL && ::ERR_peek_last_error() == 0)) //EOF: only expected for HTTP/1.0 + if (sslError == SSL_ERROR_ZERO_RETURN) + return 0; //EOF + close_notify alert + + warn_static("find a better solution for SSL_read_ex + EOF") + //"sslError == SSL_ERROR_SYSCALL && ::ERR_peek_last_error() == 0" => obsolete as of OpenSSL 1.1.1e + //https://github.com/openssl/openssl/issues/10880#issuecomment-575746226 + const auto ec = ::ERR_peek_last_error(); + if (sslError == SSL_ERROR_SSL && ERR_GET_REASON(ec) == SSL_R_UNEXPECTED_EOF_WHILE_READING) //EOF: only expected for HTTP/1.0 return 0; + throw SysError(formatLastOpenSSLError(L"SSL_read_ex") + L' ' + formatSslErrorCode(sslError)); } assert(bytesReceived > 0); //SSL_read_ex() considers EOF an error! @@ -764,7 +771,7 @@ std::string zen::convertPuttyKeyToPkix(const std::string& keyStream, const std:: auto numToBeString = [](size_t n) -> std::string { - static_assert(usingLittleEndian() && sizeof(n) >= 4); + static_assert(usingLittleEndian()&& sizeof(n) >= 4); const char* numStr = reinterpret_cast(&n); return { numStr[3], numStr[2], numStr[1], numStr[0] }; //big endian! }; diff --git a/zen/string_base.h b/zen/string_base.h index d2e00baf..42e1bdf3 100644 --- a/zen/string_base.h +++ b/zen/string_base.h @@ -328,11 +328,11 @@ template class SP> inline Zbase operator template class SP> inline Zbase operator+(Zbase&& lhs, const Char* rhs) { return std::move(lhs += rhs); } //lhs, is an l-value parameter... template class SP> inline Zbase operator+(Zbase&& lhs, Char rhs) { return std::move(lhs += rhs); } //and not a local variable => no copy elision -template class SP> inline Zbase operator+( Char lhs, const Zbase& rhs) { return Zbase(&lhs, 1) += rhs; } template class SP> inline Zbase operator+(const Char* lhs, const Zbase& rhs) { return Zbase(lhs ) += rhs; } +template class SP> inline Zbase operator+( Char lhs, const Zbase& rhs) { return Zbase(&lhs, 1) += rhs; } - - +template class SP> inline Zbase operator+(const Zbase&, int) = delete; //detect usage errors +template class SP> inline Zbase operator+(int, const Zbase&) = delete; // @@ -567,6 +567,7 @@ template class SP> inline Char& Zbase::operator[](size_t pos) { assert(pos < length()); //design by contract! no runtime check! + reserve(length()); //make unshared! return rawStr_[pos]; } diff --git a/zen/zstring.cpp b/zen/zstring.cpp index 046a3bd4..82082df0 100644 --- a/zen/zstring.cpp +++ b/zen/zstring.cpp @@ -59,7 +59,7 @@ Zstring getUnicodeNormalForm(const Zstring& str) { gchar* outStr = ::g_utf8_normalize(str.c_str(), str.length(), G_NORMALIZE_DEFAULT_COMPOSE); if (!outStr) - throw SysError(L"g_utf8_normalize: conversion failed. (" + utfTo(str) + L")"); + throw SysError(L"g_utf8_normalize: conversion failed. (" + utfTo(str) + L')'); ZEN_ON_SCOPE_EXIT(::g_free(outStr)); return outStr; -- cgit