From 9fe9dd25183cc819968370360ecb2f6b012fc536 Mon Sep 17 00:00:00 2001 From: sbiscigl Date: Tue, 21 May 2024 15:56:11 -0400 Subject: [PATCH] address PR comments --- cmake/external_dependencies.cmake | 2 +- .../include/aws/core/utils/Array.h | 84 +++++++++---------- .../source/auth/signer/AWSAuthV4Signer.cpp | 4 +- .../utils/crypto/crt/CRTSecureRandomBytes.cpp | 5 +- 4 files changed, 44 insertions(+), 51 deletions(-) diff --git a/cmake/external_dependencies.cmake b/cmake/external_dependencies.cmake index 86b7c111392..1d21e1e027f 100644 --- a/cmake/external_dependencies.cmake +++ b/cmake/external_dependencies.cmake @@ -20,7 +20,7 @@ endif() # Encryption control # TODO: BYO Crypto is not implemented for CRT/Was not working in the latest version of the SDK. -if(NOT NO_ENCRYPTION) +if(NO_ENCRYPTION) message(FATAL_ERROR "BYO_CRYPTO is not currently implemented and has been broken since version 1.9") set(ENABLE_INJECTED_ENCRYPTION ON) message(STATUS "Encryption: None") diff --git a/src/aws-cpp-sdk-core/include/aws/core/utils/Array.h b/src/aws-cpp-sdk-core/include/aws/core/utils/Array.h index 04194e7ff1f..8b46862ae39 100644 --- a/src/aws-cpp-sdk-core/include/aws/core/utils/Array.h +++ b/src/aws-cpp-sdk-core/include/aws/core/utils/Array.h @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -39,7 +40,7 @@ namespace Aws * Create new empty array of size arraySize. Default argument is 0. If it is empty then no allocation happens. */ Array(size_t arraySize = 0) : - m_size(arraySize), + m_capacity(arraySize), m_length(arraySize), m_data(arraySize > 0 ? Aws::MakeUniqueArray(arraySize, ARRAY_ALLOCATION_TAG) : nullptr) { @@ -49,30 +50,25 @@ namespace Aws * Create new array and initialize it to a raw array */ Array(const T* arrayToCopy, size_t arraySize) : - m_size(arraySize), + m_capacity(arraySize), m_length(arraySize), m_data(nullptr) { - if (arrayToCopy != nullptr && m_size > 0) + if (arrayToCopy != nullptr && m_capacity > 0) { - m_data.reset(Aws::NewArray(m_size, ARRAY_ALLOCATION_TAG)); - -#ifdef _WIN32 - std::copy(arrayToCopy, arrayToCopy + arraySize, stdext::checked_array_iterator< T * >(m_data.get(), m_size)); -#else + m_data.reset(Aws::NewArray(m_capacity, ARRAY_ALLOCATION_TAG)); std::copy(arrayToCopy, arrayToCopy + arraySize, m_data.get()); -#endif // MSVC } } /** * Create new array with a pointer and its dimensions. */ - Array(size_t m_size, - size_t m_length, + Array(size_t capacity, + size_t length, UniqueArrayPtr m_data) - : m_size(m_size), - m_length(m_length), + : m_capacity(capacity), + m_length(length), m_data(std::move(m_data)) { } @@ -88,20 +84,16 @@ namespace Aws totalSize += array->m_length; } - m_size = totalSize; - m_data.reset(Aws::NewArray(m_size, ARRAY_ALLOCATION_TAG)); + m_capacity = totalSize; + m_data.reset(Aws::NewArray(m_capacity, ARRAY_ALLOCATION_TAG)); size_t location = 0; for(auto& arr : toMerge) { - if(arr->m_size > 0 && arr->m_data) + if(arr->m_capacity > 0 && arr->m_data) { size_t arraySize = arr->m_length; -#ifdef _WIN32 - std::copy(arr->m_data.get(), arr->m_data.get() + arraySize, stdext::checked_array_iterator< T * >(m_data.get() + location, m_length)); -#else std::copy(arr->m_data.get(), arr->m_data.get() + arraySize, m_data.get() + location); -#endif // MSVC location += arraySize; } } @@ -110,29 +102,24 @@ namespace Aws Array(const Array& other) { - m_size = other.m_size; + m_capacity = other.m_capacity; m_length = other.m_length; m_data = nullptr; - if (m_size > 0) + if (m_capacity > 0) { - m_data.reset(Aws::NewArray(m_size, ARRAY_ALLOCATION_TAG)); - -#ifdef _WIN32 - std::copy(other.m_data.get(), other.m_data.get() + other.m_size, stdext::checked_array_iterator< T * >(m_data.get(), m_size)); -#else - std::copy(other.m_data.get(), other.m_data.get() + other.m_size, m_data.get()); -#endif // MSVC + m_data.reset(Aws::NewArray(m_capacity, ARRAY_ALLOCATION_TAG)); + std::copy(other.m_data.get(), other.m_data.get() + other.m_capacity, m_data.get()); } } //move c_tor Array(Array&& other) noexcept: - m_size(other.m_size), + m_capacity(other.m_capacity), m_length(other.m_length), m_data(std::move(other.m_data)) { - other.m_size = 0; + other.m_capacity = 0; other.m_data = nullptr; } @@ -145,19 +132,14 @@ namespace Aws return *this; } - m_size = other.m_size; + m_capacity = other.m_capacity; m_length = other.m_length; m_data = nullptr; - if (m_size > 0) + if (m_capacity > 0) { - m_data.reset(Aws::NewArray(m_size, ARRAY_ALLOCATION_TAG)); - -#ifdef _WIN32 - std::copy(other.m_data.get(), other.m_data.get() + other.m_length, stdext::checked_array_iterator< T * >(m_data.get(), m_size)); -#else + m_data.reset(Aws::NewArray(m_capacity, ARRAY_ALLOCATION_TAG)); std::copy(other.m_data.get(), other.m_data.get() + other.m_length, m_data.get()); -#endif // MSVC } return *this; @@ -165,19 +147,29 @@ namespace Aws Array& operator=(Array&& other) noexcept { - m_size = other.m_size; + m_capacity = other.m_capacity; m_length = other.m_length; m_data = std::move(other.m_data); return *this; } + Array(const Aws::String& string): + + m_capacity(string.capacity()), + m_length(string.length()), + m_data(nullptr) + { + m_data.reset(Aws::NewArray(m_capacity, ARRAY_ALLOCATION_TAG)); + std::copy(string.c_str(), string.c_str() + string.length(), m_data.get()); + } + bool operator==(const Array& other) const { if (this == &other) return true; - if (m_size == 0 && other.m_size == 0) + if (m_capacity == 0 && other.m_capacity == 0) { return true; } @@ -187,7 +179,7 @@ namespace Aws return false; } - if (m_length == other.m_length && m_size == other.m_size && m_data && other.m_data) + if (m_length == other.m_length && m_capacity == other.m_capacity && m_data && other.m_data) { for (unsigned i = 0; i < m_length; ++i) { @@ -235,7 +227,7 @@ namespace Aws inline size_t GetSize() const { - return m_size; + return m_capacity; } inline T* GetUnderlyingData() const @@ -249,7 +241,7 @@ namespace Aws } protected: - size_t m_size; + size_t m_capacity; size_t m_length; Aws::UniqueArrayPtr m_data; }; @@ -273,7 +265,7 @@ namespace Aws CryptoBuffer& operator=(CryptoBuffer&& other) { ByteBuffer::operator=(std::move(other)); return *this; } CryptoBuffer(Crt::ByteBuf&& other) noexcept : ByteBuffer( - other.len, + other.capacity, other.len, nullptr) { @@ -285,7 +277,7 @@ namespace Aws CryptoBuffer& operator=(Crt::ByteBuf&& other) noexcept { - m_size = other.len; + m_capacity = other.capacity; m_length = other.len; m_data.reset(other.buffer); other.capacity = 0; diff --git a/src/aws-cpp-sdk-core/source/auth/signer/AWSAuthV4Signer.cpp b/src/aws-cpp-sdk-core/source/auth/signer/AWSAuthV4Signer.cpp index 8931c290bc4..a14a7b06d05 100644 --- a/src/aws-cpp-sdk-core/source/auth/signer/AWSAuthV4Signer.cpp +++ b/src/aws-cpp-sdk-core/source/auth/signer/AWSAuthV4Signer.cpp @@ -560,9 +560,7 @@ Aws::Utils::ByteBuffer AWSAuthV4Signer::ComputeHash(const Aws::String& secretKey { Aws::String signingKey(Aws::Auth::AWSAuthHelper::SIGNING_KEY); signingKey.append(secretKey); - auto kDate = HashingUtils::CalculateSHA256HMAC( - ByteBuffer((unsigned char *) simpleDate.c_str(), simpleDate.length()), - ByteBuffer((unsigned char *) signingKey.c_str(), signingKey.length())); + auto kDate = HashingUtils::CalculateSHA256HMAC(simpleDate, signingKey); if (kDate.GetLength() == 0) { diff --git a/src/aws-cpp-sdk-core/source/utils/crypto/crt/CRTSecureRandomBytes.cpp b/src/aws-cpp-sdk-core/source/utils/crypto/crt/CRTSecureRandomBytes.cpp index 2b380fe38a6..62c477784df 100644 --- a/src/aws-cpp-sdk-core/source/utils/crypto/crt/CRTSecureRandomBytes.cpp +++ b/src/aws-cpp-sdk-core/source/utils/crypto/crt/CRTSecureRandomBytes.cpp @@ -14,7 +14,10 @@ namespace Aws void CRTSecureRandomBytes::GetBytes(unsigned char *buffer, std::size_t bufferSize) { auto outputBuf = Crt::ByteBufFromEmptyArray(buffer, bufferSize); - (void)Crt::Crypto::GenerateRandomBytes(outputBuf, bufferSize); + if (!Crt::Crypto::GenerateRandomBytes(outputBuf, bufferSize)) + { + AWS_UNREACHABLE(); + } } } }