diff --git a/pyproject.toml b/pyproject.toml index 82af220fc..6a4f5e704 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,7 +8,7 @@ requires = [ [tool.cibuildwheel] # skip musl and pypy -skip = ["*-musllinux*", "pp*"] +skip = ["*-musllinux*", "pp*","cp37-*", "*-win32"] #test-requires = "pytest" #test-command = "python -X dev -m pytest {project}/tests" diff --git a/src/vendor/azure-uamqp-c/build/.vsts-ci.yml b/src/vendor/azure-uamqp-c/build/.vsts-ci.yml index 2cc8da966..c50b547af 100644 --- a/src/vendor/azure-uamqp-c/build/.vsts-ci.yml +++ b/src/vendor/azure-uamqp-c/build/.vsts-ci.yml @@ -2,10 +2,27 @@ name: $(BuildID)_$(BuildDefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd)$(Re variables: runCodesignValidationInjection: false resources: -- repo: self - clean: true + containers: + - container: linux-c-ubuntu-2004 + endpoint: csdk-containers + image: csdkcontainerregistry.azurecr.io/linux-c-ubuntu-2004:latest + - container: linux-c-ubuntu-clang + endpoint: csdk-containers + image: csdkcontainerregistry.azurecr.io/linux-c-ubuntu-clang:latest + - container: linux-c-debian-buster + endpoint: csdk-containers + image: csdkcontainerregistry.azurecr.io/linux-c-debian-buster:latest + - container: linux-c-ubuntu-wolfssl + endpoint: csdk-containers + image: csdkcontainerregistry.azurecr.io/linux-c-ubuntu-wolfssl:latest + - container: raspberrypi-c-buster + endpoint: csdk-containers + image: csdkcontainerregistry.azurecr.io/raspberrypi-c-buster:brown jobs: - job: checksubmodule + variables: + CodeQL.Enabled: false + displayName: Check Submodules pool: vmImage: 'ubuntu-20.04' steps: @@ -21,15 +38,16 @@ jobs: displayName: 'setup' - script: | npm install check_submodules - ./../../node_modules/.bin/check_submodules . master + node_modules/.bin/check_submodules . master displayName: 'build' - job: windowsx86 + displayName: Windows x86 pool: - name: 'sdk-c--win-vs2017' + name: 'sdk-c--win-vs2022' steps: - script: | if exist jenkins\windows_c.cmd ( - call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\VsDevCmd.bat" + call jenkins\windows_c_VsDevCmd.cmd call jenkins\windows_c.cmd) displayName: 'build' env: @@ -48,47 +66,18 @@ jobs: DPS_GLOBALDEVICEENDPOINT_INVALIDCERT: $(DPS-GLOBALDEVICEENDPOINT-INVALIDCERT) PROVISIONING_CONNECTION_STRING_INVALIDCERT: $(PROVISIONING-CONNECTION-STRING-INVALIDCERT) UAMQP_E2E_DEVICE_KEY: $(UAMQP-E2E-DEVICE-KEY) - - script: cd .. && rd /Q /S $(Agent.BuildDirectory)\s - displayName: 'cleanup' - condition: always() -- job: raspberrypi - variables: - _PREVIEW_VSTS_DOCKER_IMAGE: "aziotbld/raspberrypi-c-buster:brown" - pool: - name: 'sdk-c--ubuntu-18' - displayName: raspberrypi - steps: - - script: | - chmod +x jenkins/raspberrypi_c_buster.sh - ./jenkins/raspberrypi_c_buster.sh - displayName: 'build' - - script: sudo rm -rf $(Agent.BuildDirectory)/* - displayName: 'cleanup' -- job: linuxoptions +- job: windowsx64 variables: - _PREVIEW_VSTS_DOCKER_IMAGE: "aziotbld/vsts-linux-c-ubuntu" - pool: - name: 'sdk-c--ubuntu-18' - displayName: 'linux-options' - steps: - - script: | - if [ -f "jenkins/linux_c_option_test.sh" ] - then - sudo ./jenkins/linux_c_option_test.sh - fi - displayName: 'build' - condition: always() - - script: sudo rm -rf $(Agent.BuildDirectory)/* - displayName: 'cleanup' - condition: always() -- job: windowsdynamic + CodeQL.Enabled: true + CodeQL.Language: cpp pool: - name: 'sdk-c--win-vs2017' + name: 'sdk-c--win-vs2022' + displayName: 'Windows x64' steps: - script: | - if exist jenkins\windows_c_build_as_dynamic.cmd ( - call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\VsDevCmd.bat" - call jenkins\windows_c_build_as_dynamic.cmd) + if exist jenkins\windows_c.cmd ( + call jenkins\windows_c_VsDevCmd.cmd + call jenkins\windows_c.cmd --platform x64) displayName: 'build' env: IOTHUB_CONNECTION_STRING: $(IOTHUB-CONNECTION-STRING) @@ -103,23 +92,21 @@ jobs: IOT_DPS_ID_SCOPE: $(IOT-DPS-ID-SCOPE) IOTHUB_CA_ROOT_CERT: $(IOTHUB-CA-ROOT-CERT) IOTHUB_CA_ROOT_CERT_KEY: $(IOTHUB-CA-ROOT-CERT-KEY) + IOT_DPS_GLOBAL_ENDPOINT: $(IOT-DPS-GLOBAL-ENDPOINT) IOTHUB_DEVICE_CONN_STRING_INVALIDCERT: $(IOTHUB-DEVICE-CONN-STRING-INVALIDCERT) IOTHUB_CONN_STRING_INVALIDCERT: $(IOTHUB-CONN-STRING-INVALIDCERT) DPS_GLOBALDEVICEENDPOINT_INVALIDCERT: $(DPS-GLOBALDEVICEENDPOINT-INVALIDCERT) PROVISIONING_CONNECTION_STRING_INVALIDCERT: $(PROVISIONING-CONNECTION-STRING-INVALIDCERT) UAMQP_E2E_DEVICE_KEY: $(UAMQP-E2E-DEVICE-KEY) - - script: cd .. && rd /Q /S $(Agent.BuildDirectory)\s - displayName: 'cleanup' - condition: always() -- job: OSX +- job: windowsdynamic + displayName: Windows Dynamic pool: - name: OSX + name: 'sdk-c--win-vs2022' steps: - script: | - if [ -f "jenkins/osx_gcc_openssl.sh" ] - then - ./jenkins/osx_gcc_openssl.sh - fi + if exist jenkins\windows_c_build_as_dynamic.cmd ( + call jenkins\windows_c_VsDevCmd.cmd + call jenkins\windows_c_build_as_dynamic.cmd) displayName: 'build' env: IOTHUB_CONNECTION_STRING: $(IOTHUB-CONNECTION-STRING) @@ -134,21 +121,16 @@ jobs: IOT_DPS_ID_SCOPE: $(IOT-DPS-ID-SCOPE) IOTHUB_CA_ROOT_CERT: $(IOTHUB-CA-ROOT-CERT) IOTHUB_CA_ROOT_CERT_KEY: $(IOTHUB-CA-ROOT-CERT-KEY) - IOT_DPS_GLOBAL_ENDPOINT: $(IOT-DPS-GLOBAL-ENDPOINT) IOTHUB_DEVICE_CONN_STRING_INVALIDCERT: $(IOTHUB-DEVICE-CONN-STRING-INVALIDCERT) IOTHUB_CONN_STRING_INVALIDCERT: $(IOTHUB-CONN-STRING-INVALIDCERT) DPS_GLOBALDEVICEENDPOINT_INVALIDCERT: $(DPS-GLOBALDEVICEENDPOINT-INVALIDCERT) PROVISIONING_CONNECTION_STRING_INVALIDCERT: $(PROVISIONING-CONNECTION-STRING-INVALIDCERT) UAMQP_E2E_DEVICE_KEY: $(UAMQP-E2E-DEVICE-KEY) - - script: rm -rf $(Agent.BuildDirectory)/* - displayName: 'cleanup' - condition: always() - job: clang - variables: - _PREVIEW_VSTS_DOCKER_IMAGE: "aziotbld/ubuntu-clang" + container: linux-c-ubuntu-clang pool: - name: 'sdk-c--ubuntu-18' - displayName: 'clang' + name: 'sdk-c--ubuntu-22' + displayName: 'Linux Ubuntu Clang' steps: - script: | if [ -f "jenkins/ubuntu_clang.sh" ] @@ -177,22 +159,18 @@ jobs: DPS_GLOBALDEVICEENDPOINT_INVALIDCERT: $(DPS-GLOBALDEVICEENDPOINT-INVALIDCERT) PROVISIONING_CONNECTION_STRING_INVALIDCERT: $(PROVISIONING-CONNECTION-STRING-INVALIDCERT) UAMQP_E2E_DEVICE_KEY: $(UAMQP-E2E-DEVICE-KEY) - - script: sudo rm -rf $(Agent.BuildDirectory)/* - displayName: 'cleanup' - condition: always() -- job: ubuntu1604 - variables: - _PREVIEW_VSTS_DOCKER_IMAGE: "aziotbld/linux-c-ubuntu" +- job: ubuntu2004 + container: linux-c-ubuntu-2004 pool: - name: 'sdk-c--ubuntu-18' - displayName: 'ubuntu1604' + name: 'sdk-c--ubuntu-22' + displayName: 'Linux Ubuntu 20.04' steps: - script: | - if [ -f "jenkins/ubuntu1604_c.sh" ] + if [ -f "jenkins/ubuntu_c.sh" ] then export OPENSSL_ia32cap=0x00000000 sudo chmod -R 755 . - sudo -E ./jenkins/ubuntu1604_c.sh + sudo -E ./jenkins/ubuntu_c.sh fi displayName: 'build' env: @@ -214,22 +192,31 @@ jobs: DPS_GLOBALDEVICEENDPOINT_INVALIDCERT: $(DPS-GLOBALDEVICEENDPOINT-INVALIDCERT) PROVISIONING_CONNECTION_STRING_INVALIDCERT: $(PROVISIONING-CONNECTION-STRING-INVALIDCERT) UAMQP_E2E_DEVICE_KEY: $(UAMQP-E2E-DEVICE-KEY) - - script: sudo rm -rf $(Agent.BuildDirectory)/* - displayName: 'cleanup' +- job: linuxoptions + container: linux-c-ubuntu-2004 + pool: + name: 'sdk-c--ubuntu-22' + displayName: 'Linux Ubuntu 20.04 with Options' + steps: + - script: | + if [ -f "jenkins/linux_c_option_test.sh" ] + then + sudo ./jenkins/linux_c_option_test.sh + fi + displayName: 'build' condition: always() -- job: linux_install_deps - variables: - _PREVIEW_VSTS_DOCKER_IMAGE: "aziotbld/c-debian" +- job: wolfssl + container: linux-c-ubuntu-wolfssl pool: - name: 'sdk-c--ubuntu-18' - displayName: 'linux_install_deps' + name: 'sdk-c--ubuntu-22' + displayName: 'Linux Ubuntu with WolfSSL' steps: - script: | - if [ -f "jenkins/linux_install_deps.sh" ] + if [ -f "jenkins/linux_wolfssl.sh" ] then - sudo chmod 755 jenkins/linux_install_deps.sh - sudo -E ./jenkins/linux_install_deps.sh - sudo jenkins/linux_install_deps.sh + LD_LIBRARY_PATH=/usr/local/lib + LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/my_library/ + sudo ./jenkins/linux_wolfssl.sh fi displayName: 'build' env: @@ -251,22 +238,18 @@ jobs: DPS_GLOBALDEVICEENDPOINT_INVALIDCERT: $(DPS-GLOBALDEVICEENDPOINT-INVALIDCERT) PROVISIONING_CONNECTION_STRING_INVALIDCERT: $(PROVISIONING-CONNECTION-STRING-INVALIDCERT) UAMQP_E2E_DEVICE_KEY: $(UAMQP-E2E-DEVICE-KEY) - - script: sudo rm -rf $(Agent.BuildDirectory)/* - displayName: 'cleanup' - condition: always() - job: debian - variables: - _PREVIEW_VSTS_DOCKER_IMAGE: "aziotbld/c-debian" + container: linux-c-debian-buster pool: - name: 'sdk-c--ubuntu-18' - displayName: 'debian' + name: 'sdk-c--ubuntu-22' + displayName: 'Linux Debian (Buster)' steps: - script: | if [ -f "jenkins/debian_c.sh" ] then sudo chmod 755 jenkins/debian_c.sh - sudo -E ./debian_c.sh - sudo jenkins/debian_c.sh + sudo -E ./jenkins/debian_c.sh + sudo ./jenkins/debian_c.sh fi displayName: 'build' env: @@ -288,22 +271,18 @@ jobs: DPS_GLOBALDEVICEENDPOINT_INVALIDCERT: $(DPS-GLOBALDEVICEENDPOINT-INVALIDCERT) PROVISIONING_CONNECTION_STRING_INVALIDCERT: $(PROVISIONING-CONNECTION-STRING-INVALIDCERT) UAMQP_E2E_DEVICE_KEY: $(UAMQP-E2E-DEVICE-KEY) - - script: sudo rm -rf $(Agent.BuildDirectory)/* - displayName: 'cleanup' - condition: always() -- job: wolfssl - variables: - _PREVIEW_VSTS_DOCKER_IMAGE: "aziotbld/vsts-c-wolfssl" +- job: linux_install_deps + container: linux-c-debian-buster pool: - name: 'sdk-c--ubuntu-18' - displayName: 'wolfssl' + name: 'sdk-c--ubuntu-22' + displayName: 'Linux Debian (Buster) with Installed Deps' steps: - script: | - if [ -f "jenkins/linux_wolfssl.sh" ] + if [ -f "jenkins/linux_install_deps.sh" ] then - LD_LIBRARY_PATH=/usr/local/lib - LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/my_library/ - sudo jenkins/linux_wolfssl.sh + sudo chmod 755 jenkins/linux_install_deps.sh + sudo -E ./jenkins/linux_install_deps.sh + sudo jenkins/linux_install_deps.sh fi displayName: 'build' env: @@ -324,19 +303,18 @@ jobs: IOTHUB_CONN_STRING_INVALIDCERT: $(IOTHUB-CONN-STRING-INVALIDCERT) DPS_GLOBALDEVICEENDPOINT_INVALIDCERT: $(DPS-GLOBALDEVICEENDPOINT-INVALIDCERT) PROVISIONING_CONNECTION_STRING_INVALIDCERT: $(PROVISIONING-CONNECTION-STRING-INVALIDCERT) - UAMQP_E2E_DEVICE_KEY: $(UAMQP-E2E-DEVICE-KEY) - - script: sudo rm -rf $(Agent.BuildDirectory)/* - displayName: 'cleanup' - condition: always() -- job: windowsx64 +- job: OSX + displayName: OSX + variables: + CodeQL.Enabled: false pool: - name: 'sdk-c--win-vs2017' - displayName: 'windowsx64' + vmImage: 'macOS-13' steps: - script: | - if exist jenkins\windows_c.cmd ( - call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\VsDevCmd.bat" - call jenkins\windows_c.cmd --platform x64) + if [ -f "jenkins/osx_gcc_openssl.sh" ] + then + ./jenkins/osx_gcc_openssl.sh + fi displayName: 'build' env: IOTHUB_CONNECTION_STRING: $(IOTHUB-CONNECTION-STRING) @@ -357,12 +335,12 @@ jobs: DPS_GLOBALDEVICEENDPOINT_INVALIDCERT: $(DPS-GLOBALDEVICEENDPOINT-INVALIDCERT) PROVISIONING_CONNECTION_STRING_INVALIDCERT: $(PROVISIONING-CONNECTION-STRING-INVALIDCERT) UAMQP_E2E_DEVICE_KEY: $(UAMQP-E2E-DEVICE-KEY) - - script: cd .. && rd /Q /S $(Agent.BuildDirectory)\s - displayName: 'cleanup' - condition: always() - job: xcodenative + displayName: XCode Native + variables: + CodeQL.Enabled: false pool: - name: OSX + vmImage: 'macOS-13' steps: - script: | if [ -f "jenkins/osx_xcode_native.sh" ] @@ -390,6 +368,25 @@ jobs: DPS_GLOBALDEVICEENDPOINT_INVALIDCERT: $(DPS-GLOBALDEVICEENDPOINT-INVALIDCERT) PROVISIONING_CONNECTION_STRING_INVALIDCERT: $(PROVISIONING-CONNECTION-STRING-INVALIDCERT) UAMQP_E2E_DEVICE_KEY: $(UAMQP-E2E-DEVICE-KEY) - - script: rm -rf $(Agent.BuildDirectory)/* - displayName: 'cleanup' - condition: always() +- job: raspberrypi + container: raspberrypi-c-buster + pool: + name: 'sdk-c--ubuntu-22' + displayName: Raspberry Pi + steps: + - script: | + chmod +x jenkins/raspberrypi_c_buster.sh + ./jenkins/raspberrypi_c_buster.sh + displayName: 'build' +- job: DotNET + displayName: .NET + variables: + CodeQL.Enabled: true + CodeQL.Language: csharp + pool: + vmImage: 'windows-latest' + steps: + - script: | + dotnet build uamqp_generator\uamqp_generator.sln + displayName: 'Build' + diff --git a/src/vendor/azure-uamqp-c/build_all/windows/build.cmd b/src/vendor/azure-uamqp-c/build_all/windows/build.cmd index 16cf71ad2..eda9ddc83 100644 --- a/src/vendor/azure-uamqp-c/build_all/windows/build.cmd +++ b/src/vendor/azure-uamqp-c/build_all/windows/build.cmd @@ -105,11 +105,6 @@ rem no error checking pushd %build-root%\cmake\%CMAKE_DIR% echo ***checking msbuild*** -where /q msbuild -IF ERRORLEVEL 1 ( -echo ***setting VC paths*** - IF EXIST "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\VsMSBuildCmd.bat" call "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\VsMSBuildCmd.bat" -) where msbuild if %MAKE_NUGET_PKG% == yes ( @@ -124,7 +119,7 @@ if %MAKE_NUGET_PKG% == yes ( ) mkdir %build-root%\cmake\uamqp_x64 pushd %build-root%\cmake\uamqp_x64 - cmake %build-root% -G "Visual Studio 15 2017" -A x64 + cmake %build-root% -A x64 if not !ERRORLEVEL!==0 exit /b !ERRORLEVEL! popd @@ -134,20 +129,20 @@ if %MAKE_NUGET_PKG% == yes ( ) mkdir %build-root%\cmake\uamqp_arm pushd %build-root%\cmake\uamqp_arm - cmake %build-root% -G "Visual Studio 15 2017" -A ARM + cmake %build-root% -A ARM if not !ERRORLEVEL!==0 exit /b !ERRORLEVEL! ) else if %build-platform% == Win32 ( echo ***Running CMAKE for Win32*** - cmake %build-root% -Drun_unittests:BOOL=ON -Drun_e2e_tests:BOOL=ON -G "Visual Studio 15 2017" -A Win32 + cmake %build-root% -Drun_unittests:BOOL=ON -Drun_e2e_tests:BOOL=ON -A Win32 -G %VSVERSION% if not !ERRORLEVEL!==0 exit /b !ERRORLEVEL! ) else if %build-platform% == arm ( echo ***Running CMAKE for ARM*** - cmake %build-root% -Drun_unittests:BOOL=ON -Drun_e2e_tests:BOOL=ON -G "Visual Studio 15 2017" -A ARM + cmake %build-root% -Drun_unittests:BOOL=ON -Drun_e2e_tests:BOOL=ON -A ARM -G %VSVERSION% if not !ERRORLEVEL!==0 exit /b !ERRORLEVEL! ) else ( echo ***Running CMAKE for Win64*** - cmake %build-root% -Drun_unittests:BOOL=ON -Drun_e2e_tests:BOOL=ON -G "Visual Studio 15 2017" -A x64 + cmake %build-root% -Drun_unittests:BOOL=ON -Drun_e2e_tests:BOOL=ON -A x64 -G %VSVERSION% if not !ERRORLEVEL!==0 exit /b !ERRORLEVEL! ) diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/CMakeLists.txt b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/CMakeLists.txt index 4a6b931fa..502acc91a 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/CMakeLists.txt +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/CMakeLists.txt @@ -29,11 +29,17 @@ option(use_builtin_httpapi "set use_builtin_httpapi to ON to use the built-in ht option(use_cppunittest "set use_cppunittest to ON to build CppUnitTest tests on Windows (default is OFF)" OFF) option(suppress_header_searches "do not try to find headers - used when compiler check will fail" OFF) option(use_custom_heap "use externally defined heap functions instead of the malloc family" OFF) +option(no_openssl_engine "Disables the use of ENGINEs in OpenSSL" OFF) +option(enable_ipv6 "set enable_ipv6 to ON to enable dual-ip-stack (IPv4 and IPv6) support (default is OFF for IPv4 only)" OFF) if(${use_custom_heap}) add_definitions(-DGB_USE_CUSTOM_HEAP) endif() +if (${enable_ipv6}) + add_definitions(-DIPV6_ENABLED) +endif() + if(WIN32) option(use_schannel "set use_schannel to ON if schannel is to be used, set to OFF to not use schannel" ON) option(use_openssl "set use_openssl to ON if openssl is to be used, set to OFF to not use openssl" OFF) @@ -48,7 +54,7 @@ if(WIN32) else() option(use_schannel "set use_schannel to ON if schannel is to be used, set to OFF to not use schannel" OFF) - if(MACOSX) + if(DEFINED MACOSX) option(use_openssl "set use_openssl to ON if openssl is to be used, set to OFF to not use openssl" OFF) option(use_socketio "set use_socketio to ON if socketio is to be included in the library, set to OFF if a different implementation will be provided" OFF) else() @@ -65,7 +71,7 @@ option(no_logging "disable logging (default is OFF)" OFF) # The options setting for use_socketio is not reliable. If openssl is used, make sure it's on, # and if apple tls is used then use_socketio must be off. -if (MACOSX) +if (DEFINED MACOSX) if (${use_openssl}) set(use_socketio ON) else() @@ -106,6 +112,10 @@ if(${memory_trace}) endif() if(${use_openssl}) + if(${no_openssl_engine}) + add_definitions(-DOPENSSL_NO_ENGINE) + endif() + if("${OPENSSL_ROOT_DIR}" STREQUAL "" AND NOT ("$ENV{OpenSSLDir}" STREQUAL "")) set(OPENSSL_ROOT_DIR $ENV{OpenSSLDir} CACHE PATH "") endif() @@ -115,6 +125,14 @@ if(${use_openssl}) if (NOT TARGET OpenSSL::SSL OR NOT TARGET OpenSSL::Crypto OR NOT ${OPENSSL_INCLUDE_DIR}) find_package(OpenSSL REQUIRED) endif() + + # The block below enables the v1 back-compatibility layer in OpenSSL 3, + # if using that version or later. For reference, please check the OpenSSL + # official documentation: https://www.openssl.org/docs/man3.0/man7/openssl_user_macros.html + if (DEFINED OPENSSL_VERSION AND (${OPENSSL_VERSION} GREATER_EQUAL 3)) + add_definitions(-DOPENSSL_API_COMPAT=0x10101000L) + endif() + include_directories(${OPENSSL_INCLUDE_DIR}) endif() @@ -214,7 +232,6 @@ set(source_c_files ./src/gbnetwork.c ./src/gb_stdio.c ./src/gb_time.c - ./src/gb_rand.c ./src/hmac.c ./src/hmacsha256.c ./src/xio.c @@ -238,6 +255,7 @@ set(source_c_files ${CONDITION_C_FILE} ${LOCK_C_FILE} ${TIMER_C_FILE} + ${RANDOM_C_FILE} ${STRING_UTILS_C_FILE} ${PLATFORM_C_FILE} ${SOCKETIO_C_FILE} @@ -262,6 +280,7 @@ if(${use_http}) ./src/httpheaders.c ${HTTP_C_FILE} ) + add_definitions(-DUSE_HTTP) endif() if(${use_schannel}) @@ -336,7 +355,6 @@ set(source_h_files ./inc/azure_c_shared_utility/gbnetwork.h ./inc/azure_c_shared_utility/gb_stdio.h ./inc/azure_c_shared_utility/gb_time.h - ./inc/azure_c_shared_utility/gb_rand.h ./inc/azure_c_shared_utility/hmac.h ./inc/azure_c_shared_utility/hmacsha256.h ./inc/azure_c_shared_utility/http_proxy_io.h @@ -373,7 +391,7 @@ set(source_h_files ./inc/azure_c_shared_utility/tlsio.h ./inc/azure_c_shared_utility/optionhandler.h ./inc/azure_c_shared_utility/memory_data.h - ./inc/azure_c_shared_utility/safe_math.h + ./inc/azure_c_shared_utility/safe_math.h ${LOGGING_STACKTRACE_H_FILE} ) @@ -451,11 +469,12 @@ SOURCE_GROUP(devdoc FILES ${aziotsharedutil_md_files}) # Add ignore deprecated functions so we may use 1.1.1 APIs # in OpenSSL 3 -if(LINUX) +if(DEFINED LINUX OR DEFINED MACOSX) set_property( SOURCE ${CMAKE_CURRENT_LIST_DIR}/adapters/tlsio_openssl.c ${CMAKE_CURRENT_LIST_DIR}/adapters/x509_openssl.c + ${CMAKE_CURRENT_LIST_DIR}/adapters/httpapi_curl.c PROPERTY COMPILE_OPTIONS -Wno-deprecated-declarations ) @@ -609,6 +628,14 @@ if(LINUX) link_directories(${UUID_LIBRARY_DIRS}) set(aziotsharedutil_target_libs ${aziotsharedutil_target_libs} -L${UUID_LIBRARY_DIRS} ${UUID_LIBRARIES}) else() + if (DEFINED UUID_INCLUDE_DIR) + include_directories(${UUID_INCLUDE_DIR}) + endif() + + if (DEFINED UUID_LIBRARY_DIRS) + link_directories(${UUID_LIBRARY_DIRS}) + endif() + set(aziotsharedutil_target_libs ${aziotsharedutil_target_libs} uuid) endif() endif() diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/README.md b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/README.md index 5f341f7e7..00147db0e 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/README.md +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/README.md @@ -85,7 +85,8 @@ In order to turn on/off the tlsio implementations use the following CMAKE option * `-Duse_http:bool={ON/OFF}` - turns on/off the HTTP API support. * `-Duse_installed_dependencies:bool={ON/OFF}` - turns on/off building azure-c-shared-utility using installed dependencies. This package may only be installed if this flag is ON. * `-Drun_unittests:bool={ON/OFF}` - enables building of unit tests. Default is OFF. - +* `-Duse_default_uuid:bool={ON/OFF}` - use the out-of-the-box UUID implementation that comes with the SDK rather than platform specific implementations. Default is OFF. +* `-Dno_openssl_engine:bool={ON/OFF}` - disables the use of ENGINEs in OpenSSL. Default is OFF. ## Porting to new devices diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/SECURITY.MD b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/SECURITY.MD index 8a5d128f3..0e81b34a1 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/SECURITY.MD +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/SECURITY.MD @@ -4,7 +4,7 @@ Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/). -If you believe you have found a security vulnerability in any Microsoft-owned repository that meets Microsoft's [Microsoft's definition of a security vulnerability](https://docs.microsoft.com/en-us/previous-versions/tn-archive/cc751383(v=technet.10)) of a security vulnerability, please report it to us as described below. +If you believe you have found a security vulnerability in any Microsoft-owned repository that meets Microsoft's [Microsoft's definition of a security vulnerability](https://docs.microsoft.com/previous-versions/tn-archive/cc751383(v=technet.10)) of a security vulnerability, please report it to us as described below. ## Reporting Security Issues @@ -12,7 +12,7 @@ If you believe you have found a security vulnerability in any Microsoft-owned re Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://msrc.microsoft.com/create-report). -If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/en-us/msrc/pgp-key-msrc). +If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/msrc/pgp-key-msrc). You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc). @@ -36,6 +36,6 @@ We prefer all communications to be in English. ## Policy -Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://www.microsoft.com/en-us/msrc/cvd). +Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://www.microsoft.com/msrc/cvd). diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/httpapi_compact.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/httpapi_compact.c index 23c0ce74f..feca4a278 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/httpapi_compact.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/httpapi_compact.c @@ -18,6 +18,7 @@ #include "azure_c_shared_utility/threadapi.h" #include "azure_c_shared_utility/shared_util_options.h" #include "azure_c_shared_utility/http_proxy_io.h" +#include "azure_c_shared_utility/safe_math.h" #ifdef _MSC_VER #define snprintf _snprintf @@ -431,7 +432,18 @@ static void on_bytes_received(void* context, const unsigned char* buffer, size_t else { /* Here we got some bytes so we'll buffer them so the receive functions can consumer it */ - new_received_bytes = (unsigned char*)realloc(http_instance->received_bytes, http_instance->received_bytes_count + size); + size_t malloc_size = http_instance->received_bytes_count + size; + if (malloc_size < size) + { + // check for int overflow + new_received_bytes = NULL; + LogError("Invalid size parameter"); + } + else + { + new_received_bytes = (unsigned char*)realloc(http_instance->received_bytes, malloc_size); + } + if (new_received_bytes == NULL) { http_instance->is_io_error = 1; @@ -1301,15 +1313,25 @@ HTTPAPI_RESULT HTTPAPI_SetOption(HTTP_HANDLE handle, const char* optionName, con result = HTTPAPI_OK; http_instance->certificate = (char*)value; #else - int len; if (http_instance->certificate) { free(http_instance->certificate); } - len = (int)strlen((char*)value); - http_instance->certificate = (char*)malloc((len + 1) * sizeof(char)); + size_t len = strlen((char*)value); + size_t malloc_size = safe_add_size_t(len, 1); + malloc_size = safe_multiply_size_t(malloc_size, sizeof(char)); + if (malloc_size == SIZE_MAX) + { + LogError("Invalid malloc size"); + http_instance->certificate = NULL; + } + else + { + http_instance->certificate = (char*)malloc(malloc_size); + } + if (http_instance->certificate == NULL) { /*Codes_SRS_HTTPAPI_COMPACT_21_062: [ If any memory allocation get fail, the HTTPAPI_SetOption shall return HTTPAPI_ALLOC_FAILED. ]*/ @@ -1326,14 +1348,24 @@ HTTPAPI_RESULT HTTPAPI_SetOption(HTTP_HANDLE handle, const char* optionName, con } else if (strcmp(SU_OPTION_X509_CERT, optionName) == 0 || strcmp(OPTION_X509_ECC_CERT, optionName) == 0) { - int len; if (http_instance->x509ClientCertificate) { free(http_instance->x509ClientCertificate); } - len = (int)strlen((char*)value); - http_instance->x509ClientCertificate = (char*)malloc((len + 1) * sizeof(char)); + size_t len = strlen((char*)value); + size_t malloc_size = safe_add_size_t(len, 1); + malloc_size = safe_multiply_size_t(malloc_size, sizeof(char)); + if (malloc_size == SIZE_MAX) + { + LogError("Invalid malloc size"); + http_instance->x509ClientCertificate = NULL; + } + else + { + http_instance->x509ClientCertificate = (char*)malloc(malloc_size); + } + if (http_instance->x509ClientCertificate == NULL) { /*Codes_SRS_HTTPAPI_COMPACT_21_062: [ If any memory allocation get fail, the HTTPAPI_SetOption shall return HTTPAPI_ALLOC_FAILED. ]*/ @@ -1349,14 +1381,24 @@ HTTPAPI_RESULT HTTPAPI_SetOption(HTTP_HANDLE handle, const char* optionName, con } else if (strcmp(SU_OPTION_X509_PRIVATE_KEY, optionName) == 0 || strcmp(OPTION_X509_ECC_KEY, optionName) == 0) { - int len; if (http_instance->x509ClientPrivateKey) { free(http_instance->x509ClientPrivateKey); } - len = (int)strlen((char*)value); - http_instance->x509ClientPrivateKey = (char*)malloc((len + 1) * sizeof(char)); + size_t len = strlen((char*)value); + size_t malloc_size = safe_add_size_t(len, 1); + malloc_size = safe_multiply_size_t(malloc_size, sizeof(char)); + if (malloc_size == SIZE_MAX) + { + LogError("Invalid malloc size"); + http_instance->x509ClientPrivateKey = NULL; + } + else + { + http_instance->x509ClientPrivateKey = (char*)malloc(malloc_size); + } + if (http_instance->x509ClientPrivateKey == NULL) { /*Codes_SRS_HTTPAPI_COMPACT_21_062: [ If any memory allocation get fail, the HTTPAPI_SetOption shall return HTTPAPI_ALLOC_FAILED. ]*/ @@ -1482,7 +1524,17 @@ HTTPAPI_RESULT HTTPAPI_CloneOption(const char* optionName, const void* value, co result = HTTPAPI_OK; #else certLen = strlen((const char*)value); - tempCert = (char*)malloc((certLen + 1) * sizeof(char)); + size_t malloc_size = safe_add_size_t(certLen, 1); + malloc_size = safe_multiply_size_t(malloc_size, sizeof(char)); + if (malloc_size == SIZE_MAX) + { + tempCert = NULL; + } + else + { + tempCert = (char*)malloc(malloc_size); + } + if (tempCert == NULL) { /*Codes_SRS_HTTPAPI_COMPACT_21_070: [ If any memory allocation get fail, the HTTPAPI_CloneOption shall return HTTPAPI_ALLOC_FAILED. ]*/ @@ -1500,7 +1552,18 @@ HTTPAPI_RESULT HTTPAPI_CloneOption(const char* optionName, const void* value, co else if (strcmp(SU_OPTION_X509_CERT, optionName) == 0 || strcmp(OPTION_X509_ECC_CERT, optionName) == 0) { certLen = strlen((const char*)value); - tempCert = (char*)malloc((certLen + 1) * sizeof(char)); + size_t malloc_size = safe_add_size_t(certLen, 1); + malloc_size = safe_multiply_size_t(malloc_size, sizeof(char)); + if (malloc_size == SIZE_MAX) + { + LogError("Invalid malloc size"); + tempCert = NULL; + } + else + { + tempCert = (char*)malloc(malloc_size); + } + if (tempCert == NULL) { /*Codes_SRS_HTTPAPI_COMPACT_21_070: [ If any memory allocation get fail, the HTTPAPI_CloneOption shall return HTTPAPI_ALLOC_FAILED. ]*/ @@ -1517,7 +1580,18 @@ HTTPAPI_RESULT HTTPAPI_CloneOption(const char* optionName, const void* value, co else if (strcmp(SU_OPTION_X509_PRIVATE_KEY, optionName) == 0 || strcmp(OPTION_X509_ECC_KEY, optionName) == 0) { certLen = strlen((const char*)value); - tempCert = (char*)malloc((certLen + 1) * sizeof(char)); + size_t malloc_size = safe_add_size_t(certLen, 1); + malloc_size = safe_multiply_size_t(malloc_size, sizeof(char)); + if (malloc_size == SIZE_MAX) + { + LogError("Invalid malloc size"); + tempCert = NULL; + } + else + { + tempCert = (char*)malloc(malloc_size); + } + if (tempCert == NULL) { /*Codes_SRS_HTTPAPI_COMPACT_21_070: [ If any memory allocation get fail, the HTTPAPI_CloneOption shall return HTTPAPI_ALLOC_FAILED. ]*/ diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/httpapi_curl.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/httpapi_curl.c index 359ecedab..20dbec3a6 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/httpapi_curl.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/httpapi_curl.c @@ -16,6 +16,7 @@ #include "azure_c_shared_utility/xlogging.h" #ifdef USE_OPENSSL #include "azure_c_shared_utility/x509_openssl.h" +#include "openssl/engine.h" #elif USE_WOLFSSL #define WOLFSSL_OPTIONS_IGNORE_SYS #include "wolfssl/options.h" @@ -26,6 +27,7 @@ #include "mbedtls/ssl.h" #endif #include "azure_c_shared_utility/shared_util_options.h" +#include "azure_c_shared_utility/safe_math.h" #define TEMP_BUFFER_SIZE 1024 @@ -44,7 +46,13 @@ typedef struct HTTP_HANDLE_DATA_TAG const char* x509privatekey; const char* x509certificate; const char* certificates; /*a list of CA certificates*/ -#if USE_MBEDTLS +#if USE_OPENSSL + OPTION_OPENSSL_KEY_TYPE x509privatekeytype; +#ifndef OPENSSL_NO_ENGINE + char* engineId; + ENGINE* engine; +#endif // OPENSSL_NO_ENGINE +#elif USE_MBEDTLS mbedtls_x509_crt cert; mbedtls_pk_context key; mbedtls_x509_crt trusted_certificates; @@ -111,52 +119,107 @@ HTTP_HANDLE HTTPAPI_CreateConnection(const char* hostName) httpHandleData = (HTTP_HANDLE_DATA*)malloc(sizeof(HTTP_HANDLE_DATA)); if (httpHandleData != NULL) { - size_t hostURL_size = strlen("https://") + strlen(hostName) + 1; - httpHandleData->hostURL = malloc(hostURL_size); + size_t hostURL_size = safe_add_size_t(strlen("https://"), strlen(hostName)); + hostURL_size = safe_add_size_t(hostURL_size, 1); + + if (hostURL_size == SIZE_MAX) + { + LogError("invalid malloc size"); + httpHandleData->hostURL = NULL; + } + else + { + httpHandleData->hostURL = malloc(hostURL_size); + } + if (httpHandleData->hostURL == NULL) { LogError("unable to malloc"); free(httpHandleData); httpHandleData = NULL; } + else if ((strcpy_s(httpHandleData->hostURL, hostURL_size, "https://") != 0) || + (strcat_s(httpHandleData->hostURL, hostURL_size, hostName) != 0)) + { + LogError("unable to set hostURL"); + free(httpHandleData->hostURL); + free(httpHandleData); + httpHandleData = NULL; + } + else if ((httpHandleData->curl = curl_easy_init()) == NULL) + { + LogError("unable to init cURL structure"); + free(httpHandleData->hostURL); + free(httpHandleData); + httpHandleData = NULL; + } else { - if ((strcpy_s(httpHandleData->hostURL, hostURL_size, "https://") == 0) && - (strcat_s(httpHandleData->hostURL, hostURL_size, hostName) == 0)) +#ifdef USE_BEARSSL + // Gate testing currently supports version of cURL prior to cURL's BearSSL or SecureTransport support. + // To pass Gates, cannot directly reference CURLSSLBACKEND_BEARSSL or CURLSSLBACKEND_SECURETRANSPORT. + // Skipping validation of cURL's ssl backend. + LogInfo("If using BearSSL with the C SDK, please confirm cURL is also configured to use BearSSL."); +#elif defined USE_OPENSSL || defined USE_WOLFSSL || defined USE_MBEDTLS + + // Check C SDK TLS platform matches cURL's + const struct curl_tlssessioninfo* info = NULL; + CURLcode result = curl_easy_getinfo(httpHandleData->curl, CURLINFO_TLS_SSL_PTR, &info); + + if (result != CURLE_OK || info == NULL) { - httpHandleData->curl = curl_easy_init(); - if (httpHandleData->curl == NULL) - { - free(httpHandleData->hostURL); - free(httpHandleData); - httpHandleData = NULL; - } - else - { - httpHandleData->timeout = 242 * 1000; /*242 seconds seems like a nice enough time. Reasone for 242: - 1. http://curl.haxx.se/libcurl/c/CURLOPT_TIMEOUT.html says Normally, name lookups can take a considerable time and limiting operations to less than a few minutes risk aborting perfectly normal operations. - 2. 256KB of data... at 9600 bps transfers in about 218 seconds. Add to that a buffer of 10%... round it up to 242 :)*/ - httpHandleData->lowSpeedTime = 0; - httpHandleData->lowSpeedLimit = 0; - httpHandleData->forbidReuse = 0; - httpHandleData->freshConnect = 0; - httpHandleData->verbose = 0; - httpHandleData->x509certificate = NULL; - httpHandleData->x509privatekey = NULL; - httpHandleData->certificates = NULL; -#if USE_MBEDTLS - mbedtls_x509_crt_init(&httpHandleData->cert); - mbedtls_pk_init(&httpHandleData->key); - mbedtls_x509_crt_init(&httpHandleData->trusted_certificates); -#endif - } + LogError("unable to get cURL backend SSL info"); } else { - free(httpHandleData->hostURL); - free(httpHandleData); - httpHandleData = NULL; + #ifdef USE_OPENSSL + if (CURLSSLBACKEND_OPENSSL != (int32_t)info->backend) + { + char* SDKSSLName = "OpenSSL"; + #elif USE_WOLFSSL + if (CURLSSLBACKEND_WOLFSSL != (int32_t)info->backend) + { + char* SDKSSLName = "wolfSSL"; + #elif USE_MBEDTLS + if (CURLSSLBACKEND_MBEDTLS != (int32_t)info->backend) + { + char* SDKSSLName = "mbedTLS"; + #else + // Should not get here. + #endif + LogError("curl_sslbackend (%d) currently used by cURL does not match TLS platform (%s) " + "used by C SDK on Linux or OSX. Please configure and compile cURL to use %s.", + info->backend, SDKSSLName, SDKSSLName); + } } +#else // Other, possibly SecureTransport. + // Gate testing currently supports version of cURL prior to cURL's BearSSL or SecureTransport support. + // To pass Gates, cannot directly reference CURLSSLBACKEND_BEARSSL or CURLSSLBACKEND_SECURETRANSPORT. + // Skipping validation of cURL's ssl backend. + LogInfo("If using SecureTransport with the C SDK, please confirm cURL is also configured to use SecureTransport."); +#endif + httpHandleData->timeout = 242 * 1000; /*242 seconds seems like a nice enough time. Reasone for 242: + 1. http://curl.haxx.se/libcurl/c/CURLOPT_TIMEOUT.html says Normally, name lookups can take a considerable time and limiting operations to less than a few minutes risk aborting perfectly normal operations. + 2. 256KB of data... at 9600 bps transfers in about 218 seconds. Add to that a buffer of 10%... round it up to 242 :)*/ + httpHandleData->lowSpeedTime = 0; + httpHandleData->lowSpeedLimit = 0; + httpHandleData->forbidReuse = 0; + httpHandleData->freshConnect = 0; + httpHandleData->verbose = 0; + httpHandleData->x509certificate = NULL; + httpHandleData->x509privatekey = NULL; + httpHandleData->certificates = NULL; +#ifdef USE_OPENSSL + httpHandleData->x509privatekeytype = KEY_TYPE_DEFAULT; +#ifndef OPENSSL_NO_ENGINE + httpHandleData->engineId = NULL; + httpHandleData->engine = NULL; +#endif // OPENSSL_NO_ENGINE +#elif USE_MBEDTLS + mbedtls_x509_crt_init(&httpHandleData->cert); + mbedtls_pk_init(&httpHandleData->key); + mbedtls_x509_crt_init(&httpHandleData->trusted_certificates); +#endif } } } @@ -170,8 +233,23 @@ void HTTPAPI_CloseConnection(HTTP_HANDLE handle) if (httpHandleData != NULL) { free(httpHandleData->hostURL); + httpHandleData->hostURL = NULL; curl_easy_cleanup(httpHandleData->curl); -#if USE_MBEDTLS +#ifdef USE_OPENSSL +#ifndef OPENSSL_NO_ENGINE + if (httpHandleData->engine != NULL) + { + ENGINE_free(httpHandleData->engine); + httpHandleData->engine = NULL; + } + + if (httpHandleData->engineId != NULL) + { + free(httpHandleData->engineId); + httpHandleData->engineId = NULL; + } +#endif // OPENSSL_NO_ENGINE +#elif USE_MBEDTLS mbedtls_x509_crt_free(&httpHandleData->cert); mbedtls_pk_free(&httpHandleData->key); mbedtls_x509_crt_free(&httpHandleData->trusted_certificates); @@ -216,7 +294,20 @@ static size_t ContentWriteFunction(void *ptr, size_t size, size_t nmemb, void *u (ptr != NULL) && (size * nmemb > 0)) { - void* newBuffer = realloc(responseContentBuffer->buffer, responseContentBuffer->bufferSize + (size * nmemb)); + size_t malloc_size = safe_multiply_size_t(size, nmemb); + malloc_size = safe_add_size_t(malloc_size, responseContentBuffer->bufferSize); + + void* newBuffer; + if (malloc_size == SIZE_MAX) + { + LogError("Invalid buffer size"); + newBuffer = NULL; + } + else + { + newBuffer = realloc(responseContentBuffer->buffer, malloc_size); + } + if (newBuffer != NULL) { responseContentBuffer->buffer = newBuffer; @@ -225,11 +316,12 @@ static size_t ContentWriteFunction(void *ptr, size_t size, size_t nmemb, void *u } else { - LogError("Could not allocate buffer of size %lu", (unsigned long)(responseContentBuffer->bufferSize + (size * nmemb))); + LogError("Could not allocate buffer of size %lu", (unsigned long)(malloc_size)); responseContentBuffer->error = 1; if (responseContentBuffer->buffer != NULL) { free(responseContentBuffer->buffer); + responseContentBuffer->buffer = NULL; } } } @@ -255,13 +347,33 @@ static CURLcode ssl_ctx_callback(CURL *curl, void *ssl_ctx, void *userptr) HTTP_HANDLE_DATA *httpHandleData = (HTTP_HANDLE_DATA *)userptr; #ifdef USE_OPENSSL /*trying to set the x509 per device certificate*/ +#ifndef OPENSSL_NO_ENGINE + if (httpHandleData->x509privatekeytype == KEY_TYPE_ENGINE) { + ENGINE_load_builtin_engines(); + httpHandleData->engine = ENGINE_by_id(httpHandleData->engineId); + } + if (httpHandleData->x509privatekeytype == KEY_TYPE_ENGINE && httpHandleData->engine == NULL) + { + LogError("unable to load engine by ID: %s", httpHandleData->engineId); + result = CURLE_SSL_CERTPROBLEM; + } + else if ( + (httpHandleData->x509certificate != NULL) && (httpHandleData->x509privatekey != NULL) && + (x509_openssl_add_credentials(ssl_ctx, httpHandleData->x509certificate, httpHandleData->x509privatekey, httpHandleData->x509privatekeytype, httpHandleData->engine) != 0) + ) +#else // OPENSSL_NO_ENGINE if ( (httpHandleData->x509certificate != NULL) && (httpHandleData->x509privatekey != NULL) && - (x509_openssl_add_credentials(ssl_ctx, httpHandleData->x509certificate, httpHandleData->x509privatekey, KEY_TYPE_DEFAULT, NULL) != 0) + (x509_openssl_add_credentials(ssl_ctx, httpHandleData->x509certificate, httpHandleData->x509privatekey, httpHandleData->x509privatekeytype) != 0) ) +#endif // OPENSSL_NO_ENGINE { LogError("unable to x509_openssl_add_credentials"); result = CURLE_SSL_CERTPROBLEM; +#ifndef OPENSSL_NO_ENGINE + ENGINE_free(httpHandleData->engine); + httpHandleData->engine = NULL; +#endif // OPENSSL_NO_ENGINE } /*trying to set CA certificates*/ else if ( @@ -271,6 +383,10 @@ static CURLcode ssl_ctx_callback(CURL *curl, void *ssl_ctx, void *userptr) { LogError("failure in x509_openssl_add_certificates"); result = CURLE_SSL_CERTPROBLEM; +#ifndef OPENSSL_NO_ENGINE + ENGINE_free(httpHandleData->engine); + httpHandleData->engine = NULL; +#endif // OPENSSL_NO_ENGINE } #elif USE_WOLFSSL if ( @@ -364,8 +480,18 @@ HTTPAPI_RESULT HTTPAPI_ExecuteRequest(HTTP_HANDLE handle, HTTPAPI_REQUEST_TYPE r else { char* tempHostURL; - size_t tempHostURL_size = strlen(httpHandleData->hostURL) + strlen(relativePath) + 1; - tempHostURL = malloc(tempHostURL_size); + size_t tempHostURL_size = safe_add_size_t(strlen(httpHandleData->hostURL), strlen(relativePath)); + tempHostURL_size = safe_add_size_t(tempHostURL_size, 1); + if (tempHostURL_size == SIZE_MAX) + { + LogError("Invalid malloc size"); + tempHostURL = NULL; + } + else + { + tempHostURL = malloc(tempHostURL_size); + } + if (tempHostURL == NULL) { result = HTTPAPI_ERROR; @@ -702,6 +828,7 @@ HTTPAPI_RESULT HTTPAPI_ExecuteRequest(HTTP_HANDLE handle, HTTPAPI_REQUEST_TYPE r if (responseContentBuffer.buffer != NULL) { free(responseContentBuffer.buffer); + responseContentBuffer.buffer = NULL; } } } @@ -764,6 +891,36 @@ HTTPAPI_RESULT HTTPAPI_SetOption(HTTP_HANDLE handle, const char* optionName, con httpHandleData->verbose = *(const long*)value; result = HTTPAPI_OK; } +#ifdef USE_OPENSSL + else if (strcmp(OPTION_OPENSSL_PRIVATE_KEY_TYPE, optionName) == 0) + { + const OPTION_OPENSSL_KEY_TYPE type = *(const OPTION_OPENSSL_KEY_TYPE*)value; + if (type == KEY_TYPE_DEFAULT || type == KEY_TYPE_ENGINE) + { + httpHandleData->x509privatekeytype = type; + result = HTTPAPI_OK; + } + else + { + LogError("Unknown x509PrivatekeyType: %i", type); + result = HTTPAPI_ERROR; + } + } +#ifndef OPENSSL_NO_ENGINE + else if (strcmp(OPTION_OPENSSL_ENGINE, optionName) == 0) + { + if (mallocAndStrcpy_s((char**)&httpHandleData->engineId, value) != 0) + { + LogError("unable to mallocAndStrcpy_s x509PrivatekeyType"); + result = HTTPAPI_ERROR; + } + else + { + result = HTTPAPI_OK; + } + } +#endif // OPENSSL_NO_ENGINE +#endif else if (strcmp(SU_OPTION_X509_PRIVATE_KEY, optionName) == 0 || strcmp(OPTION_X509_ECC_KEY, optionName) == 0) { httpHandleData->x509privatekey = value; @@ -845,8 +1002,18 @@ HTTPAPI_RESULT HTTPAPI_SetOption(HTTP_HANDLE handle, const char* optionName, con { if (proxy_data->username != NULL && proxy_data->password != NULL) { - size_t authLen = strlen(proxy_data->username)+strlen(proxy_data->password)+1; - proxy_auth = malloc(authLen+1); + size_t authLen = safe_add_size_t(strlen(proxy_data->username), strlen(proxy_data->password)); + authLen = safe_add_size_t(authLen, 2); + if (authLen == SIZE_MAX) + { + LogError("Invalid malloc size"); + proxy_auth = NULL; + } + else + { + proxy_auth = malloc(authLen); + } + if (proxy_auth == NULL) { LogError("failure allocating proxy authentication"); @@ -873,6 +1040,7 @@ HTTPAPI_RESULT HTTPAPI_SetOption(HTTP_HANDLE handle, const char* optionName, con } } free(proxy_auth); + proxy_auth = NULL; } } else @@ -975,10 +1143,50 @@ HTTPAPI_RESULT HTTPAPI_CloneOption(const char* optionName, const void* value, co } else { - /*return OK when the certificate has been clones successfully*/ + /*return OK when the certificate has been cloned successfully*/ result = HTTPAPI_OK; } } +#ifdef USE_OPENSSL + else if (strcmp(OPTION_OPENSSL_PRIVATE_KEY_TYPE, optionName) == 0) + { + const OPTION_OPENSSL_KEY_TYPE type = *(const OPTION_OPENSSL_KEY_TYPE*)value; + if (type == KEY_TYPE_DEFAULT || type == KEY_TYPE_ENGINE) + { + OPTION_OPENSSL_KEY_TYPE* temp = malloc(sizeof(OPTION_OPENSSL_KEY_TYPE)); + if (temp == NULL) + { + LogError("unable to clone x509PrivatekeyType"); + result = HTTPAPI_ERROR; + } + else + { + *temp = type; + *savedValue = temp; + result = HTTPAPI_OK; + } + } + else + { + LogError("Unknown x509PrivatekeyType: %i", type); + result = HTTPAPI_ERROR; + } + } + else if (strcmp(OPTION_OPENSSL_ENGINE, optionName) == 0) + { + /*this is getting the engine. In this case, value is a pointer to a const char* that contains the engine as a null terminated string*/ + if (mallocAndStrcpy_s((char**)savedValue, value) != 0) + { + LogError("unable to clone %s", optionName); + result = HTTPAPI_ERROR; + } + else + { + /*return OK when the engine has been cloned successfully*/ + result = HTTPAPI_OK; + } + } +#endif else if (strcmp(SU_OPTION_X509_PRIVATE_KEY, optionName) == 0 || strcmp(OPTION_X509_ECC_KEY, optionName) == 0) { /*this is getting the x509 private key. In this case, value is a pointer to a const char* that contains the private key as a null terminated string*/ @@ -989,7 +1197,7 @@ HTTPAPI_RESULT HTTPAPI_CloneOption(const char* optionName, const void* value, co } else { - /*return OK when the private key has been clones successfully*/ + /*return OK when the private key has been cloned successfully*/ result = HTTPAPI_OK; } } @@ -1002,7 +1210,7 @@ HTTPAPI_RESULT HTTPAPI_CloneOption(const char* optionName, const void* value, co } else { - /*return OK when the certificates have been clones successfully*/ + /*return OK when the certificates have been cloned successfully*/ result = HTTPAPI_OK; } } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/httpapi_tirtos.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/httpapi_tirtos.c index ba7a8eae0..88d0b9939 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/httpapi_tirtos.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/httpapi_tirtos.c @@ -10,6 +10,7 @@ #include "azure_c_shared_utility/httpapi.h" #include "azure_c_shared_utility/strings.h" #include "azure_c_shared_utility/xlogging.h" +#include "azure_c_shared_utility/safe_math.h" #define CONTENT_BUF_LEN 128 @@ -198,7 +199,17 @@ HTTPAPI_RESULT HTTPAPI_ExecuteRequest(HTTP_HANDLE handle, } if (cnt < offset + ret) { - hname = (char *)realloc(hname, offset + ret); + size_t malloc_size = safe_add_size_t(offset, ret); + if (malloc_size == SIZE_MAX) + { + LogError("invalid realloc size"); + hname = NULL; + } + else + { + hname = (char*)realloc(hname, malloc_size); + } + if (hname == NULL) { LogError("Failed reallocating memory"); ret = HTTPAPI_ALLOC_FAILED; diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/httpapi_winhttp.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/httpapi_winhttp.c index ccab6fe84..a1d992c06 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/httpapi_winhttp.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/httpapi_winhttp.c @@ -16,6 +16,7 @@ #include "azure_c_shared_utility/strings.h" #include "azure_c_shared_utility/x509_schannel.h" #include "azure_c_shared_utility/shared_util_options.h" +#include "azure_c_shared_utility/safe_math.h" MU_DEFINE_ENUM_STRINGS(HTTPAPI_RESULT, HTTPAPI_RESULT_VALUES) @@ -51,8 +52,20 @@ static size_t nUsersOfHTTPAPI = 0; /*used for reference counting (a weak one)*/ static char* ConcatHttpHeaders(HTTP_HEADERS_HANDLE httpHeadersHandle, size_t toAlloc, size_t headersCount) { - char *result = (char*)malloc(toAlloc * sizeof(char) + 1); size_t i; + char* result; + + size_t malloc_size = safe_multiply_size_t(toAlloc, sizeof(char)); + malloc_size = safe_add_size_t(malloc_size, 1); + if (malloc_size == SIZE_MAX) + { + LogError("Invalid malloc size"); + result = NULL; + } + else + { + result = (char*)malloc(malloc_size); + } if (result == NULL) { @@ -132,6 +145,7 @@ static HTTPAPI_RESULT ConstructHeadersString(HTTP_HEADERS_HANDLE httpHeadersHand { char *httpHeadersA; size_t requiredCharactersForHeaders; + size_t malloc_size; if ((httpHeadersA = ConcatHttpHeaders(httpHeadersHandle, toAlloc, headersCount)) == NULL) { @@ -143,7 +157,8 @@ static HTTPAPI_RESULT ConstructHeadersString(HTTP_HEADERS_HANDLE httpHeadersHand result = HTTPAPI_STRING_PROCESSING_ERROR; LogError("MultiByteToWideChar failed, GetLastError=0x%08x (result = %" PRI_MU_ENUM ")", GetLastError(), MU_ENUM_VALUE(HTTPAPI_RESULT, result)); } - else if ((*httpHeaders = (wchar_t*)malloc((requiredCharactersForHeaders + 1) * sizeof(wchar_t))) == NULL) + else if ((malloc_size = safe_multiply_size_t(safe_add_size_t(requiredCharactersForHeaders, 1), sizeof(wchar_t))) == SIZE_MAX || + (*httpHeaders = (wchar_t*)malloc(malloc_size)) == NULL) { result = HTTPAPI_ALLOC_FAILED; LogError("Cannot allocate memory (result = %" PRI_MU_ENUM ")", MU_ENUM_VALUE(HTTPAPI_RESULT, result)); @@ -245,7 +260,7 @@ HTTPAPI_RESULT HTTPAPI_Init(void) } else { - DWORD supportedProtocols = WINHTTP_FLAG_SECURE_PROTOCOL_TLS1 | // TLS 1.0 is support for back-compat reasons (https://docs.microsoft.com/en-us/azure/iot-fundamentals/iot-security-deployment) + DWORD supportedProtocols = WINHTTP_FLAG_SECURE_PROTOCOL_TLS1 | // TLS 1.0 is support for back-compat reasons (https://docs.microsoft.com/azure/iot-fundamentals/iot-security-deployment) WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_1 | WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2; @@ -332,7 +347,17 @@ HTTP_HANDLE HTTPAPI_CreateConnection(const char* hostName) } else { - hostNameTemp = (wchar_t*)malloc(sizeof(wchar_t) * hostNameTemp_size); + size_t malloc_size = safe_multiply_size_t(sizeof(wchar_t), hostNameTemp_size); + if (malloc_size == SIZE_MAX) + { + LogError("Invalid malloc size"); + hostNameTemp = NULL; + } + else + { + hostNameTemp = (wchar_t*)malloc(malloc_size); + } + if (hostNameTemp == NULL) { LogError("malloc failed"); @@ -454,7 +479,8 @@ static HTTPAPI_RESULT InitiateWinhttpRequest(HTTP_HANDLE_DATA* handleData, HTTPA const wchar_t* requestTypeString; size_t requiredCharactersForRelativePath; wchar_t* relativePathTemp = NULL; - + size_t malloc_size; + if ((requestTypeString = GetHttpRequestString(requestType)) == NULL) { result = HTTPAPI_INVALID_ARG; @@ -465,7 +491,12 @@ static HTTPAPI_RESULT InitiateWinhttpRequest(HTTP_HANDLE_DATA* handleData, HTTPA result = HTTPAPI_STRING_PROCESSING_ERROR; LogError("MultiByteToWideChar failed, GetLastError=0x%08x", GetLastError()); } - else if ((relativePathTemp = (wchar_t*)malloc((requiredCharactersForRelativePath + 1) * sizeof(wchar_t))) == NULL) + else if ((malloc_size = safe_multiply_size_t(safe_add_size_t(requiredCharactersForRelativePath, 1), sizeof(wchar_t))) == SIZE_MAX) + { + LogError("malloc invalid size"); + result = HTTPAPI_ALLOC_FAILED; + } + else if ((relativePathTemp = (wchar_t*)malloc(malloc_size)) == NULL) { result = HTTPAPI_ALLOC_FAILED; LogError("malloc failed (result = %" PRI_MU_ENUM ")", MU_ENUM_VALUE(HTTPAPI_RESULT, result)); @@ -780,7 +811,18 @@ static HTTPAPI_RESULT ReceiveResponseHeaders(HINTERNET requestHandle, HTTP_HEADE &responseHeadersTempLength, WINHTTP_NO_HEADER_INDEX); - if ((responseHeadersTemp = (wchar_t*)malloc(responseHeadersTempLength + 2)) == NULL) + size_t malloc_size = safe_add_size_t((size_t)responseHeadersTempLength, 2); + if (malloc_size == SIZE_MAX) + { + LogError("Invalid malloc size"); + responseHeadersTemp = NULL; + } + else + { + responseHeadersTemp = (wchar_t*)malloc(malloc_size); + } + + if (responseHeadersTemp == NULL) { result = HTTPAPI_ALLOC_FAILED; LogError("malloc failed: (result = %" PRI_MU_ENUM ")", MU_ENUM_VALUE(HTTPAPI_RESULT, result)); @@ -816,7 +858,13 @@ static HTTPAPI_RESULT ReceiveResponseHeaders(HINTERNET requestHandle, HTTP_HEADE LogError("WideCharToMultiByte failed"); break; } - else if ((tokenTemp = (char*)malloc(sizeof(char) * tokenTemp_size)) == NULL) + else if ((malloc_size = safe_multiply_size_t(sizeof(char), tokenTemp_size)) == SIZE_MAX) + { + result = HTTPAPI_ALLOC_FAILED; + LogError("invalid malloc size"); + break; + } + else if ((tokenTemp = (char*)malloc(malloc_size)) == NULL) { result = HTTPAPI_ALLOC_FAILED; LogError("malloc failed"); diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/linux_time.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/linux_time.c index 377c62da9..fe2b7509a 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/linux_time.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/linux_time.c @@ -61,7 +61,7 @@ int get_time_ns(struct timespec* ts) return err; } -int64_t get_time_ms() +int64_t get_time_ms(void) { struct timespec ts; if (get_time_ns(&ts) != 0) diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/lock_win32.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/lock_win32.c index e0b238eb9..9b0f53291 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/lock_win32.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/lock_win32.c @@ -78,7 +78,13 @@ LOCK_RESULT Unlock(LOCK_HANDLE handle) } else { +#ifdef _MSC_VER +#pragma warning(disable:26110) // Warning C26110: Caller failing to hold lock 'handle' before calling function 'ReleaseSRWLockExclusive'. +#endif ReleaseSRWLockExclusive((SRWLOCK*)handle); +#ifdef _MSC_VER +#pragma warning (default:26110) +#endif /* Codes_SRS_LOCK_10_009: [Unlock on success shall return LOCK_OK] */ result = LOCK_OK; diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/platform_linux.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/platform_linux.c index 0724ff77d..1e9fd081f 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/platform_linux.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/platform_linux.c @@ -4,7 +4,9 @@ #include "azure_c_shared_utility/platform.h" #include "azure_c_shared_utility/xio.h" #include "azure_c_shared_utility/xlogging.h" +#ifdef USE_HTTP #include "azure_c_shared_utility/httpapiex.h" +#endif // USE_HTTP #ifdef USE_OPENSSL #include "azure_c_shared_utility/tlsio_openssl.h" #else @@ -30,6 +32,7 @@ const IO_INTERFACE_DESCRIPTION* tlsio_openssl_get_interface_description(); int platform_init(void) { int result = 0; +#ifdef USE_HTTP #ifndef DONT_USE_UPLOADTOBLOB if (HTTPAPIEX_Init() == HTTPAPIEX_ERROR) { @@ -37,6 +40,7 @@ int platform_init(void) result = MU_FAILURE; } #endif /* DONT_USE_UPLOADTOBLOB */ +#endif /* USE_HTTP */ #ifdef USE_OPENSSL if (result == 0) { @@ -91,9 +95,12 @@ STRING_HANDLE platform_get_platform_info(PLATFORM_INFO_OPTION options) void platform_deinit(void) { +#ifdef USE_HTTP #ifndef DONT_USE_UPLOADTOBLOB HTTPAPIEX_Deinit(); #endif /* DONT_USE_UPLOADTOBLOB */ +#endif /* USE_HTTP */ + #ifdef USE_OPENSSL tlsio_openssl_deinit(); #elif USE_WOLFSSL diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/platform_win32.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/platform_win32.c index a029a1df0..cdb2120e3 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/platform_win32.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/platform_win32.c @@ -171,7 +171,9 @@ STRING_HANDLE platform_get_platform_info(PLATFORM_INFO_OPTION options) result = NULL; memset(&osvi, 0, sizeof(osvi)); osvi.dwOSVersionInfoSize = sizeof(osvi); -#pragma warning(disable:4996) +#ifdef _MSC_VER +#pragma warning(disable:4996 28159) // GetVersionEx is deprecated +#endif if (GetVersionEx(&osvi)) { DWORD product_type; @@ -186,7 +188,9 @@ STRING_HANDLE platform_get_platform_info(PLATFORM_INFO_OPTION options) DWORD dwVersion = GetVersion(); result = STRING_construct_sprintf("(native; WindowsProduct:Windows NT %d.%d; %s", LOBYTE(LOWORD(dwVersion)), HIBYTE(LOWORD(dwVersion)), arch); } -#pragma warning(default:4996) +#ifdef _MSC_VER +#pragma warning(default:4996 28159) +#endif if (result == NULL) { diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/random_posix.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/random_posix.c new file mode 100644 index 000000000..d26cd70b4 --- /dev/null +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/random_posix.c @@ -0,0 +1,20 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +#ifdef __cplusplus +#include +#else +#include +#endif + +#include "azure_c_shared_utility/random.h" + +void RANDOM_seed(unsigned int seed) +{ + srandom(seed); +} + +int RANDOM_generate(void) +{ + return random(); +} diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/random_stub.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/random_stub.c new file mode 100644 index 000000000..bb51a005b --- /dev/null +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/random_stub.c @@ -0,0 +1,20 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +#ifdef __cplusplus +#include +#else +#include +#endif + +#include "azure_c_shared_utility/random.h" + +void RANDOM_seed(unsigned int seed) +{ + srand(seed); +} + +int RANDOM_generate(void) +{ + return rand(); +} diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/socketio_berkeley.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/socketio_berkeley.c index 1b2532a40..c13cd40ec 100755 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/socketio_berkeley.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/socketio_berkeley.c @@ -47,6 +47,7 @@ #include "azure_c_shared_utility/xlogging.h" #include "azure_c_shared_utility/const_defines.h" #include "azure_c_shared_utility/dns_resolver.h" +#include "azure_c_shared_utility/safe_math.h" #include #include #include @@ -126,15 +127,19 @@ static void* socketio_CloneOption(const char* name, const void* value) } else { - if ((result = malloc(sizeof(char) * (strlen((char*)value) + 1))) == NULL) + size_t malloc_size = safe_add_size_t(strlen((char*)value), 1); + malloc_size = safe_multiply_size_t(malloc_size, sizeof(char)); + if (malloc_size == SIZE_MAX) + { + LogError("Invalid malloc size"); + } + else if ((result = malloc(malloc_size)) == NULL) { LogError("Failed cloning option %s (malloc failed)", name); } - else if (strcpy((char*)result, (char*)value) == NULL) + else { - LogError("Failed cloning option %s (strcpy failed)", name); - free(result); - result = NULL; + strcpy((char *)result, (char *)value); } } } @@ -283,165 +288,6 @@ static int lookup_address(SOCKET_IO_INSTANCE* socket_io_instance) return result; } -static int initiate_socket_connection(SOCKET_IO_INSTANCE* socket_io_instance) -{ - int result; - int flags; - struct addrinfo* addr = NULL; - struct sockaddr* connect_addr = NULL; - struct sockaddr_un addrInfoUn; - socklen_t connect_addr_len; - - if(socket_io_instance->address_type == ADDRESS_TYPE_IP) - { - if(!dns_resolver_is_lookup_complete(socket_io_instance->dns_resolver)) - { - LogError("DNS did not resolve IP address"); - result = MU_FAILURE; - } - else - { - addr = dns_resolver_get_addrInfo(socket_io_instance->dns_resolver); - - if (addr == NULL) - { - LogError("DNS resolution failed"); - result = MU_FAILURE; - } - else - { - connect_addr = addr->ai_addr; - connect_addr_len = sizeof(*addr->ai_addr); - result = 0; - } - } - } - else - { - size_t hostname_len = strlen(socket_io_instance->hostname); - if (hostname_len + 1 > sizeof(addrInfoUn.sun_path)) - { - LogError("Hostname %s is too long for a unix socket (max len = %lu)", socket_io_instance->hostname, (unsigned long)sizeof(addrInfoUn.sun_path)); - result = MU_FAILURE; - } - else - { - memset(&addrInfoUn, 0, sizeof(addrInfoUn)); - addrInfoUn.sun_family = AF_UNIX; - // No need to add NULL terminator due to the above memset - (void)memcpy(addrInfoUn.sun_path, socket_io_instance->hostname, hostname_len); - - connect_addr = (struct sockaddr*)&addrInfoUn; - connect_addr_len = sizeof(addrInfoUn); - result = 0; - } - } - - if(result == 0) - { - if ((-1 == (flags = fcntl(socket_io_instance->socket, F_GETFL, 0))) || - (fcntl(socket_io_instance->socket, F_SETFL, flags | O_NONBLOCK) == -1)) - { - LogError("Failure: fcntl failure."); - result = MU_FAILURE; - } - else - { - result = connect(socket_io_instance->socket, connect_addr, connect_addr_len); - if ((result != 0) && (errno != EINPROGRESS)) - { - LogError("Failure: connect failure %d.", errno); - result = MU_FAILURE; - } - else - { - // Async connect will return -1. - result = 0; - if (socket_io_instance->on_io_open_complete != NULL) - { - socket_io_instance->on_io_open_complete(socket_io_instance->on_io_open_complete_context, IO_OPEN_OK /*: IO_OPEN_ERROR*/); - } - } - } - } - - return result; -} - -static int lookup_address_and_initiate_socket_connection(SOCKET_IO_INSTANCE* socket_io_instance) -{ - int result; - - result = lookup_address(socket_io_instance); - - if(socket_io_instance->io_state == IO_STATE_OPEN) - { - if (result == 0) - { - result = initiate_socket_connection(socket_io_instance); - } - } - - return result; -} - -static int wait_for_connection(SOCKET_IO_INSTANCE* socket_io_instance) -{ - int result; - int err; - int retval; - int select_errno = 0; - - fd_set fdset; - struct timeval tv; - - FD_ZERO(&fdset); - FD_SET(socket_io_instance->socket, &fdset); - tv.tv_sec = CONNECT_TIMEOUT; - tv.tv_usec = 0; - - do - { - retval = select(socket_io_instance->socket + 1, NULL, &fdset, NULL, &tv); - - if (retval < 0) - { - select_errno = errno; - } - } while (retval < 0 && select_errno == EINTR); - - if (retval != 1) - { - LogError("Failure: select failure."); - result = MU_FAILURE; - } - else - { - int so_error = 0; - socklen_t len = sizeof(so_error); - err = getsockopt(socket_io_instance->socket, SOL_SOCKET, SO_ERROR, &so_error, &len); - if (err != 0) - { - LogError("Failure: getsockopt failure %d.", errno); - result = MU_FAILURE; - } - else if (so_error != 0) - { - err = so_error; - LogError("Failure: connect failure %d.", so_error); - result = MU_FAILURE; - } - else - { - result = 0; - } - } - - return result; -} - - - #ifndef __APPLE__ static void destroy_network_interface_descriptions(NETWORK_INTERFACE_DESCRIPTION* nid) { @@ -474,31 +320,36 @@ static void destroy_network_interface_descriptions(NETWORK_INTERFACE_DESCRIPTION static NETWORK_INTERFACE_DESCRIPTION* create_network_interface_description(struct ifreq *ifr, NETWORK_INTERFACE_DESCRIPTION* previous_nid) { NETWORK_INTERFACE_DESCRIPTION* result; + size_t malloc_size; if ((result = (NETWORK_INTERFACE_DESCRIPTION*)malloc(sizeof(NETWORK_INTERFACE_DESCRIPTION))) == NULL) { LogError("Failed allocating NETWORK_INTERFACE_DESCRIPTION"); } - else if ((result->name = (char*)malloc(sizeof(char) * (strlen(ifr->ifr_name) + 1))) == NULL) + else if ((malloc_size = safe_multiply_size_t(safe_add_size_t(strlen(ifr->ifr_name), 1), sizeof(char))) == SIZE_MAX) { - LogError("failed setting interface description name (malloc failed)"); + LogError("invalid malloc size"); destroy_network_interface_descriptions(result); result = NULL; } - else if (strcpy(result->name, ifr->ifr_name) == NULL) + else if ((result->name = (char*)malloc(malloc_size)) == NULL) { - LogError("failed setting interface description name (strcpy failed)"); + LogError("failed setting interface description name (malloc failed)"); destroy_network_interface_descriptions(result); result = NULL; } else { + strcpy(result->name, ifr->ifr_name); + char* ip_address; unsigned char* mac = (unsigned char*)ifr->ifr_hwaddr.sa_data; + size_t malloc_size = safe_multiply_size_t(sizeof(char), MAC_ADDRESS_STRING_LENGTH); - if ((result->mac_address = (char*)malloc(sizeof(char) * MAC_ADDRESS_STRING_LENGTH)) == NULL) + if (malloc_size == SIZE_MAX || + (result->mac_address = (char*)malloc(malloc_size)) == NULL) { - LogError("failed formatting mac address (malloc failed)"); + LogError("failed formatting mac address (malloc failed) size:%zu", malloc_size); destroy_network_interface_descriptions(result); result = NULL; } @@ -514,20 +365,21 @@ static NETWORK_INTERFACE_DESCRIPTION* create_network_interface_description(struc destroy_network_interface_descriptions(result); result = NULL; } - else if ((result->ip_address = (char*)malloc(sizeof(char) * (strlen(ip_address) + 1))) == NULL) + else if ((malloc_size = safe_multiply_size_t(safe_add_size_t(strlen(ip_address), 1), sizeof(char))) == SIZE_MAX) { - LogError("failed setting the ip address (malloc failed)"); + LogError("invalid malloc size"); destroy_network_interface_descriptions(result); result = NULL; } - else if (strcpy(result->ip_address, ip_address) == NULL) + else if ((result->ip_address = (char*)malloc(malloc_size)) == NULL) { - LogError("failed setting the ip address (strcpy failed)"); + LogError("failed setting the ip address (malloc failed)"); destroy_network_interface_descriptions(result); result = NULL; } else { + strcpy(result->ip_address, ip_address); result->next = NULL; if (previous_nid != NULL) @@ -659,6 +511,212 @@ static int set_target_network_interface(int socket, char* mac_address) } #endif //__APPLE__ +static int initiate_socket_connection(SOCKET_IO_INSTANCE* socket_io_instance) +{ + int result; + int flags; + struct addrinfo* addr = NULL; + struct sockaddr_un addrInfoUn; + + if(socket_io_instance->address_type == ADDRESS_TYPE_IP) + { + if(!dns_resolver_is_lookup_complete(socket_io_instance->dns_resolver)) + { + LogError("DNS did not resolve hostname IP address. Hostname:%s", socket_io_instance->hostname); + result = MU_FAILURE; + } + else + { + addr = dns_resolver_get_addrInfo(socket_io_instance->dns_resolver); + + if (addr == NULL) + { + LogError("DNS resolution failed. Hostname:%s", socket_io_instance->hostname); + result = MU_FAILURE; + } + else + { + result = 0; + } + } + } + else + { + if (socket_io_instance->hostname != NULL) + { + size_t hostname_len = strlen(socket_io_instance->hostname); + if (hostname_len + 1 > sizeof(addrInfoUn.sun_path)) + { + LogError("Hostname %s is too long for a unix socket (max len = %lu)", socket_io_instance->hostname, (unsigned long)sizeof(addrInfoUn.sun_path)); + result = MU_FAILURE; + } + else + { + memset(&addrInfoUn, 0, sizeof(addrInfoUn)); + addrInfoUn.sun_family = AF_UNIX; + // No need to add NULL terminator due to the above memset + (void)memcpy(addrInfoUn.sun_path, socket_io_instance->hostname, hostname_len); + result = 0; + } + } + else + { + LogError("Hostname is NULL"); + result = MU_FAILURE; + } + } + + if(result == 0) + { + if (socket_io_instance->address_type == ADDRESS_TYPE_IP) + { + socket_io_instance->socket = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol); + } + else + { + socket_io_instance->socket = socket(AF_UNIX, SOCK_STREAM, 0); + } + + if (socket_io_instance->socket < SOCKET_SUCCESS) + { + LogError("Failure: socket create failure %d.", socket_io_instance->socket); + result = MU_FAILURE; + } + #ifndef __APPLE__ + else if (socket_io_instance->target_mac_address != NULL && + set_target_network_interface(socket_io_instance->socket, socket_io_instance->target_mac_address) != 0) + { + LogError("Failure: failed selecting target network interface (MACADDR=%s).", socket_io_instance->target_mac_address); + result = MU_FAILURE; + } + #endif //__APPLE__ + else if ((-1 == (flags = fcntl(socket_io_instance->socket, F_GETFL, 0))) || + (fcntl(socket_io_instance->socket, F_SETFL, flags | O_NONBLOCK) == -1)) + { + LogError("Failure: fcntl failure."); + result = MU_FAILURE; + } + else + { + if (socket_io_instance->address_type == ADDRESS_TYPE_IP) + { + result = connect(socket_io_instance->socket, addr->ai_addr, addr->ai_addrlen); + } + else + { + result = connect(socket_io_instance->socket, (struct sockaddr *)&addrInfoUn, sizeof(addrInfoUn)); + } + + if ((result != 0) && (errno != EINPROGRESS)) + { + LogError("Failure: connect failure %d.", errno); + result = MU_FAILURE; + } + else // result == 0 || errno == EINPROGRESS + { + // Async connect will return -1. + result = 0; + if (socket_io_instance->on_io_open_complete != NULL) + { + socket_io_instance->on_io_open_complete(socket_io_instance->on_io_open_complete_context, IO_OPEN_OK /*: IO_OPEN_ERROR*/); + } + } + } + + if (result != 0) + { + if (socket_io_instance->socket >= SOCKET_SUCCESS) + { + close(socket_io_instance->socket); + } + socket_io_instance->socket = INVALID_SOCKET; + } + } + + return result; +} + +static int lookup_address_and_initiate_socket_connection(SOCKET_IO_INSTANCE* socket_io_instance) +{ + int result; + + result = lookup_address(socket_io_instance); + + if(socket_io_instance->io_state == IO_STATE_OPEN) + { + if (result == 0) + { + result = initiate_socket_connection(socket_io_instance); + } + } + + return result; +} + +static int wait_for_socket_connection(SOCKET_IO_INSTANCE* socket_io_instance) +{ + int result; + int err; + int retval; + int select_errno = 0; + + fd_set fdset; + struct timeval tv; + + FD_ZERO(&fdset); + FD_SET(socket_io_instance->socket, &fdset); + tv.tv_sec = CONNECT_TIMEOUT; + tv.tv_usec = 0; + + do + { + retval = select(socket_io_instance->socket + 1, NULL, &fdset, NULL, &tv); + + if (retval < 0) + { + select_errno = errno; + } + } while (retval < 0 && select_errno == EINTR); + + if (retval != 1) + { + LogError("Failure: select failure."); + result = MU_FAILURE; + } + else + { + int so_error = 0; + socklen_t len = sizeof(so_error); + err = getsockopt(socket_io_instance->socket, SOL_SOCKET, SO_ERROR, &so_error, &len); + if (err != 0) + { + LogError("Failure: getsockopt failure %d.", errno); + result = MU_FAILURE; + } + else if (so_error != 0) + { + err = so_error; + LogError("Failure: connect failure %d.", so_error); + result = MU_FAILURE; + } + else + { + result = 0; + } + } + + if (result != 0) + { + if (socket_io_instance->socket >= SOCKET_SUCCESS) + { + close(socket_io_instance->socket); + } + socket_io_instance->socket = INVALID_SOCKET; + } + + return result; +} + static void destroy_socket_io_instance(SOCKET_IO_INSTANCE* instance) { if (instance->dns_resolver != NULL) @@ -706,10 +764,19 @@ CONCRETE_IO_HANDLE socketio_create(void* io_create_parameters) { if (socket_io_config->hostname != NULL) { - result->hostname = (char*)malloc(strlen(socket_io_config->hostname) + 1); - if (result->hostname != NULL) + size_t malloc_size = safe_add_size_t(strlen(socket_io_config->hostname), 1); + if (malloc_size == SIZE_MAX) { - (void)strcpy(result->hostname, socket_io_config->hostname); + LogError("invalid malloc size"); + result->hostname = NULL; + } + else + { + result->hostname = (char*)malloc(malloc_size); + if (result->hostname != NULL) + { + (void)strcpy(result->hostname, socket_io_config->hostname); + } } result->socket = INVALID_SOCKET; @@ -810,30 +877,15 @@ int socketio_open(CONCRETE_IO_HANDLE socket_io, ON_IO_OPEN_COMPLETE on_io_open_c } else { - socket_io_instance->socket = socket (socket_io_instance->address_type == ADDRESS_TYPE_IP ? AF_INET : AF_UNIX, SOCK_STREAM, 0); - if (socket_io_instance->socket < SOCKET_SUCCESS) - { - LogError("Failure: socket create failure %d.", socket_io_instance->socket); - result = MU_FAILURE; - } -#ifndef __APPLE__ - else if (socket_io_instance->target_mac_address != NULL && - set_target_network_interface(socket_io_instance->socket, socket_io_instance->target_mac_address) != 0) - { - LogError("Failure: failed selecting target network interface (MACADDR=%s).", socket_io_instance->target_mac_address); - result = MU_FAILURE; - } -#endif //__APPLE__ - else if ((result = lookup_address_and_initiate_socket_connection(socket_io_instance)) != 0) + if ((result = lookup_address_and_initiate_socket_connection(socket_io_instance)) != 0) { LogError("lookup_address_and_connect_socket failed"); } - else if ((result = wait_for_connection(socket_io_instance)) != 0) + else if ((socket_io_instance->io_state == IO_STATE_OPEN) && (result = wait_for_socket_connection(socket_io_instance)) != 0) { - LogError("wait_for_connection failed"); - } - - if (result == 0) + LogError("wait_for_socket_connection failed"); + } + else { socket_io_instance->on_bytes_received = on_bytes_received; socket_io_instance->on_bytes_received_context = on_bytes_received_context; @@ -844,14 +896,6 @@ int socketio_open(CONCRETE_IO_HANDLE socket_io, ON_IO_OPEN_COMPLETE on_io_open_c socket_io_instance->on_io_open_complete = on_io_open_complete; socket_io_instance->on_io_open_complete_context = on_io_open_complete_context; } - else - { - if (socket_io_instance->socket >= SOCKET_SUCCESS) - { - close(socket_io_instance->socket); - } - socket_io_instance->socket = INVALID_SOCKET; - } } } @@ -939,14 +983,14 @@ int socketio_send(CONCRETE_IO_HANDLE socket_io, const void* buffer, size_t size, ssize_t send_result = send(socket_io_instance->socket, buffer, size, MSG_NOSIGNAL); if ((size_t)send_result != size) { - if (send_result == SOCKET_SEND_FAILURE && errno != EAGAIN) + if (send_result == SOCKET_SEND_FAILURE && errno != EAGAIN && errno != ENOBUFS) { LogError("Failure: sending socket failed. errno=%d (%s).", errno, strerror(errno)); result = MU_FAILURE; } else { - /*send says "come back later" with EAGAIN - likely the socket buffer cannot accept more data*/ + /*send says "come back later" with EAGAIN, ENOBUFS - likely the socket buffer cannot accept more data*/ /* queue data */ size_t bytes_sent = (send_result < 0 ? 0 : send_result); @@ -1002,7 +1046,7 @@ void socketio_dowork(CONCRETE_IO_HANDLE socket_io) { if (send_result == INVALID_SOCKET) { - if (errno == EAGAIN) /*send says "come back later" with EAGAIN - likely the socket buffer cannot accept more data*/ + if (errno == EAGAIN || errno == ENOBUFS) /*send says "come back later" with EAGAIN, ENOBUFS - likely the socket buffer cannot accept more data*/ { /*do nothing until next dowork */ break; @@ -1011,6 +1055,7 @@ void socketio_dowork(CONCRETE_IO_HANDLE socket_io) { free(pending_socket_io->bytes); free(pending_socket_io); + pending_socket_io = NULL; (void)singlylinkedlist_remove(socket_io_instance->pending_io_list, first_pending_io); LogError("Failure: sending Socket information. errno=%d (%s).", errno, strerror(errno)); @@ -1034,6 +1079,7 @@ void socketio_dowork(CONCRETE_IO_HANDLE socket_io) free(pending_socket_io->bytes); free(pending_socket_io); + pending_socket_io = NULL; if (singlylinkedlist_remove(socket_io_instance->pending_io_list, first_pending_io) != 0) { indicate_error(socket_io_instance); @@ -1085,7 +1131,16 @@ void socketio_dowork(CONCRETE_IO_HANDLE socket_io) { if(socket_io_instance->io_state == IO_STATE_OPEN) { - initiate_socket_connection(socket_io_instance); + if (initiate_socket_connection(socket_io_instance) != 0) + { + LogError("Socketio_Failure: initiate_socket_connection failed"); + indicate_error(socket_io_instance); + } + else if (wait_for_socket_connection(socket_io_instance) != 0) + { + LogError("Socketio_Failure: wait_for_socket_connection failed"); + indicate_error(socket_io_instance); + } } } @@ -1183,25 +1238,26 @@ int socketio_setoption(CONCRETE_IO_HANDLE socket_io, const char* optionName, con LogError("option not supported."); result = MU_FAILURE; #else + size_t malloc_size; if (strlen(value) == 0) { LogError("option value must be a valid mac address"); result = MU_FAILURE; } - else if ((socket_io_instance->target_mac_address = (char*)malloc(sizeof(char) * (strlen(value) + 1))) == NULL) + else if ((malloc_size = safe_multiply_size_t(safe_add_size_t(strlen(value), 1), sizeof(char))) == SIZE_MAX) { - LogError("failed setting net_interface_mac_address option (malloc failed)"); + LogError("invalid malloc size"); result = MU_FAILURE; + socket_io_instance->target_mac_address = NULL; } - else if (strcpy(socket_io_instance->target_mac_address, value) == NULL) + else if ((socket_io_instance->target_mac_address = (char*)malloc(malloc_size)) == NULL) { - LogError("failed setting net_interface_mac_address option (strcpy failed)"); - free(socket_io_instance->target_mac_address); - socket_io_instance->target_mac_address = NULL; + LogError("failed setting net_interface_mac_address option (malloc failed)"); result = MU_FAILURE; } else { + strcpy(socket_io_instance->target_mac_address, value); strtoup(socket_io_instance->target_mac_address); result = 0; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/socketio_win32.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/socketio_win32.c index c82d88ce1..0c8cf5989 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/socketio_win32.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/socketio_win32.c @@ -18,6 +18,7 @@ #include "azure_c_shared_utility/shared_util_options.h" #include "azure_c_shared_utility/xlogging.h" #include "azure_c_shared_utility/dns_resolver.h" +#include "azure_c_shared_utility/safe_math.h" typedef enum IO_STATE_TAG { @@ -123,6 +124,7 @@ static int add_pending_io(SOCKET_IO_INSTANCE* socket_io_instance, const unsigned { LogError("Allocation Failure: Unable to allocate pending list."); free(pending_socket_io); + pending_socket_io = NULL; result = MU_FAILURE; } else @@ -138,6 +140,7 @@ static int add_pending_io(SOCKET_IO_INSTANCE* socket_io_instance, const unsigned LogError("Failure: Unable to add socket to pending list."); free(pending_socket_io->bytes); free(pending_socket_io); + pending_socket_io = NULL; result = MU_FAILURE; } else @@ -336,10 +339,19 @@ CONCRETE_IO_HANDLE socketio_create(void* io_create_parameters) { if (socket_io_config->hostname != NULL) { - result->hostname = (char*)malloc(strlen(socket_io_config->hostname) + 1); - if (result->hostname != NULL) + size_t malloc_size = safe_add_size_t(strlen(socket_io_config->hostname), 1); + if (malloc_size == SIZE_MAX) { - (void)strcpy(result->hostname, socket_io_config->hostname); + LogError("Invalid malloc size"); + result->hostname = NULL; + } + else + { + result->hostname = (char*)malloc(malloc_size); + if (result->hostname != NULL) + { + (void)strcpy(result->hostname, socket_io_config->hostname); + } } result->socket = INVALID_SOCKET; @@ -635,6 +647,7 @@ void socketio_dowork(CONCRETE_IO_HANDLE socket_io) { free(pending_socket_io->bytes); free(pending_socket_io); + pending_socket_io = NULL; (void)singlylinkedlist_remove(socket_io_instance->pending_io_list, first_pending_io); } else @@ -651,6 +664,7 @@ void socketio_dowork(CONCRETE_IO_HANDLE socket_io) free(pending_socket_io->bytes); free(pending_socket_io); + pending_socket_io = NULL; if (singlylinkedlist_remove(socket_io_instance->pending_io_list, first_pending_io) != 0) { LogError("Failure: removing socket from list"); diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/srw_lock.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/srw_lock.c index 716c4e4b2..0c1cefbce 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/srw_lock.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/srw_lock.c @@ -223,7 +223,13 @@ void srw_lock_release_exclusive(SRW_LOCK_HANDLE handle) { if (!handle->doStatistics) { +#ifdef _MSC_VER +#pragma warning(disable:26110) // Warning C26110: Caller failing to hold lock 'handle->lock' before calling function 'ReleaseSRWLockExclusive'. +#endif ReleaseSRWLockExclusive(&handle->lock); +#ifdef _MSC_VER +#pragma warning (default:26110) +#endif } else { @@ -234,7 +240,13 @@ void srw_lock_release_exclusive(SRW_LOCK_HANDLE handle) (void)QueryPerformanceCounter(&start); /*Codes_SRS_SRW_LOCK_02_010: [ srw_lock_release_exclusive shall call ReleaseSRWLockExclusive. ]*/ +#ifdef _MSC_VER +#pragma warning(disable:26110) // Warning C26110: Caller failing to hold lock 'handle->lock' before calling function 'ReleaseSRWLockExclusive'. +#endif ReleaseSRWLockExclusive(&handle->lock); +#ifdef _MSC_VER +#pragma warning (default:26110) +#endif (void)QueryPerformanceCounter(&stop); /*measure release time*/ (void)InterlockedAdd64(&handle->totalCounts_ReleaseSRWLockExclusive, (stop.QuadPart - start.QuadPart)); diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/string_utils.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/string_utils.c index d8ea29447..4388a36bd 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/string_utils.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/string_utils.c @@ -10,6 +10,7 @@ #include "azure_macro_utils/macro_utils.h" #include "azure_c_shared_utility/gballoc.h" #include "azure_c_shared_utility/xlogging.h" +#include "azure_c_shared_utility/safe_math.h" #include "azure_c_shared_utility/string_utils.h" @@ -19,22 +20,30 @@ IMPLEMENT_MOCKABLE_FUNCTION(, char*, vsprintf_char, const char*, format, va_list int neededSize = vsnprintf(NULL, 0, format, va); if (neededSize < 0) { - LogError("failure in vsnprintf"); + LogError("failure in vsnprintf, neededSize=%d", neededSize); result = NULL; } else { - result = (char*)malloc(((unsigned long long)neededSize + 1) * sizeof(char)); - if (result == NULL) + size_t len = safe_add_size_t((unsigned long long)neededSize, 1); + size_t malloc_size = safe_multiply_size_t(len, sizeof(char)); + if (malloc_size == SIZE_MAX) + { + LogError("invalid malloc size, size:%zu", malloc_size); + result = NULL; + /*return as is*/ + } + else if ((result = (char*)malloc(malloc_size)) == NULL) { LogError("failure in malloc"); /*return as is*/ } else { - if (vsnprintf(result, (unsigned long long)neededSize + 1, format, va) != neededSize) + int out_len = vsnprintf(result, len, format, va); + if (out_len != neededSize) { - LogError("inconsistent vsnprintf behavior"); + LogError("inconsistent vsnprintf behavior, len=%zu, out_len=%d", len, out_len); free(result); result = NULL; } @@ -54,8 +63,15 @@ IMPLEMENT_MOCKABLE_FUNCTION(, wchar_t*, vsprintf_wchar, const wchar_t*, format, } else { - result = (wchar_t*)malloc(((unsigned long long)neededSize + 1)*sizeof(wchar_t)); - if (result == NULL) + size_t malloc_size = safe_add_size_t((unsigned long long)neededSize, 1); + malloc_size = safe_multiply_size_t(malloc_size, sizeof(wchar_t)); + if (malloc_size == SIZE_MAX) + { + LogError("invalid malloc size"); + result = NULL; + /*return as is*/ + } + else if ((result = (wchar_t*)malloc(malloc_size)) == NULL) { LogError("failure in malloc"); /*return as is*/ @@ -169,8 +185,15 @@ IMPLEMENT_MOCKABLE_FUNCTION(, wchar_t*, mbs_to_wcs, const char*, source) } else { - result = (wchar_t*)malloc(sizeof(wchar_t)*(nwc+1)); - if (result == NULL) + size_t malloc_size = safe_add_size_t(nwc, 1); + malloc_size = safe_multiply_size_t(malloc_size, sizeof(wchar_t)); + if (malloc_size == SIZE_MAX) + { + LogError("invalid malloc size"); + result = NULL; + /*return as is*/ + } + else if ((result = (wchar_t*)malloc(malloc_size)) == NULL) { LogError("failure in malloc"); /*return as is*/ @@ -216,8 +239,15 @@ IMPLEMENT_MOCKABLE_FUNCTION(, char*, wcs_to_mbs, const wchar_t*, source) } else { - result = (char*)malloc(sizeof(char)*(nc + 1)); - if (result == NULL) + size_t malloc_size = safe_add_size_t(nc, 1); + malloc_size = safe_multiply_size_t(malloc_size, sizeof(char)); + if (malloc_size == SIZE_MAX) + { + LogError("invalid malloc size"); + result = NULL; + /*return as is*/ + } + else if ((result = (char*)malloc(malloc_size)) == NULL) { LogError("failure in malloc"); /*return as is*/ diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/tlsio_bearssl.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/tlsio_bearssl.c index cbed1a64b..4c6f93962 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/tlsio_bearssl.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/tlsio_bearssl.c @@ -41,6 +41,7 @@ #include "azure_c_shared_utility/vector.h" #include "azure_c_shared_utility/buffer_.h" #include "azure_c_shared_utility/tlsio_bearssl.h" +#include "azure_c_shared_utility/safe_math.h" static const char *const OPTION_UNDERLYING_IO_OPTIONS = "underlying_io_options"; @@ -337,6 +338,7 @@ VECTOR_HANDLE decode_pem(const void *src, size_t len) po.data = BUFFER_u_char(bv); po.data_len = BUFFER_length(bv); free(bv); + bv = NULL; VECTOR_push_back(pem_list, &po, 1); po.name = NULL; po.data = NULL; @@ -378,7 +380,9 @@ VECTOR_HANDLE decode_pem(const void *src, size_t len) VECTOR_clear(pem_list); free(po.name); + po.name = NULL; BUFFER_delete(bv); + bv = NULL; pem_list = NULL; } } @@ -396,9 +400,15 @@ static void free_private_key(private_key *privkey) free(privkey->key.rsa.dp); free(privkey->key.rsa.q); free(privkey->key.rsa.p); + privkey->key.rsa.iq = NULL; + privkey->key.rsa.dq = NULL; + privkey->key.rsa.dp = NULL; + privkey->key.rsa.q = NULL; + privkey->key.rsa.p = NULL; break; case BR_KEYTYPE_EC: free(privkey->key.ec.x); + privkey->key.ec.x = NULL; break; default: LogError("Unknown private key type %d", privkey->key_type); @@ -676,9 +686,12 @@ void free_ta_contents(br_x509_trust_anchor *ta) case BR_KEYTYPE_RSA: free(ta->pkey.key.rsa.n); free(ta->pkey.key.rsa.e); + ta->pkey.key.rsa.n = NULL; + ta->pkey.key.rsa.e = NULL; break; case BR_KEYTYPE_EC: free(ta->pkey.key.ec.q); + ta->pkey.key.ec.q = NULL; break; } } @@ -689,6 +702,7 @@ void free_certificates(br_x509_certificate *certs, size_t num) for (u = 0; u < num; u ++) { free(certs[u].data); + certs[u].data = NULL; } } @@ -724,6 +738,7 @@ static int certificate_to_trust_anchor(br_x509_certificate *xc, br_x509_trust_an ta->dn.data = BUFFER_u_char(vdn); ta->dn.len = BUFFER_length(vdn); free(vdn); + vdn = NULL; ta->flags = 0; if (br_x509_decoder_isCA(&dc)) @@ -800,7 +815,16 @@ static size_t get_trusted_anchors(const char *certificates, size_t len, br_x509_ } else { - anchArray = (br_x509_trust_anchor *)malloc(sizeof(br_x509_trust_anchor) * num); + size_t malloc_size = safe_multiply_size_t(sizeof(br_x509_trust_anchor), num); + if (malloc_size == SIZE_MAX) + { + LogError("Invalid buffer size for trustedanchors"); + anchArray = NULL; + } + else + { + anchArray = (br_x509_trust_anchor*)malloc(malloc_size); + } if (anchArray == NULL) { @@ -1568,6 +1592,7 @@ int tlsio_bearssl_setoption(CONCRETE_IO_HANDLE tls_io, const char *optionName, c { // Free the memory if it has been previously allocated free(tls_io_instance->x509_certificate); + tls_io_instance->x509_certificate = NULL; } if (mallocAndStrcpy_s(&tls_io_instance->x509_certificate, (const char *)value) != 0) @@ -1597,6 +1622,7 @@ int tlsio_bearssl_setoption(CONCRETE_IO_HANDLE tls_io, const char *optionName, c { // Free the memory if it has been previously allocated free(tls_io_instance->x509_private_key); + tls_io_instance->x509_private_key = NULL; } if (mallocAndStrcpy_s(&tls_io_instance->x509_private_key, (const char *)value) != 0) diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/tlsio_mbedtls.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/tlsio_mbedtls.c index 9c06753f9..81e31ae1d 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/tlsio_mbedtls.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/tlsio_mbedtls.c @@ -24,6 +24,7 @@ #include "azure_c_shared_utility/crt_abstractions.h" #include "azure_c_shared_utility/shared_util_options.h" #include "azure_c_shared_utility/threadapi.h" +#include "azure_c_shared_utility/safe_math.h" static const char *const OPTION_UNDERLYING_IO_OPTIONS = "underlying_io_options"; @@ -206,12 +207,19 @@ static void on_underlying_io_bytes_received(void *context, const unsigned char * { if (context != NULL) { + unsigned char* new_socket_io_read_bytes; TLS_IO_INSTANCE *tls_io_instance = (TLS_IO_INSTANCE *)context; - unsigned char *new_socket_io_read_bytes = (unsigned char *)realloc(tls_io_instance->socket_io_read_bytes, tls_io_instance->socket_io_read_byte_count + size); - - if (new_socket_io_read_bytes == NULL) + size_t realloc_size = safe_add_size_t(tls_io_instance->socket_io_read_byte_count, size); + if (realloc_size == SIZE_MAX) { + LogError("Invalid realloc size"); + tls_io_instance->tlsio_state = TLSIO_STATE_ERROR; + indicate_error(tls_io_instance); + } + else if ((new_socket_io_read_bytes = (unsigned char*)realloc(tls_io_instance->socket_io_read_bytes, realloc_size)) == NULL) + { + LogError("realloc failed"); tls_io_instance->tlsio_state = TLSIO_STATE_ERROR; indicate_error(tls_io_instance); } @@ -334,21 +342,31 @@ static int on_io_recv(void *context, unsigned char *buf, size_t sz) if (result > 0) { - (void)memcpy((void *)buf, tls_io_instance->socket_io_read_bytes, result); - (void)memmove(tls_io_instance->socket_io_read_bytes, tls_io_instance->socket_io_read_bytes + result, tls_io_instance->socket_io_read_byte_count - result); - tls_io_instance->socket_io_read_byte_count -= result; - if (tls_io_instance->socket_io_read_byte_count > 0) + size_t read_byte_count = safe_subtract_size_t(tls_io_instance->socket_io_read_byte_count, (size_t)result); + if (read_byte_count != SIZE_MAX) { - new_socket_io_read_bytes = (unsigned char *)realloc(tls_io_instance->socket_io_read_bytes, tls_io_instance->socket_io_read_byte_count); - if (new_socket_io_read_bytes != NULL) + (void)memcpy((void*)buf, tls_io_instance->socket_io_read_bytes, result); + (void)memmove(tls_io_instance->socket_io_read_bytes, tls_io_instance->socket_io_read_bytes + result, read_byte_count); + + tls_io_instance->socket_io_read_byte_count = read_byte_count; + if (tls_io_instance->socket_io_read_byte_count > 0) { - tls_io_instance->socket_io_read_bytes = new_socket_io_read_bytes; + new_socket_io_read_bytes = (unsigned char*)realloc(tls_io_instance->socket_io_read_bytes, tls_io_instance->socket_io_read_byte_count); + if (new_socket_io_read_bytes != NULL) + { + tls_io_instance->socket_io_read_bytes = new_socket_io_read_bytes; + } + } + else + { + free(tls_io_instance->socket_io_read_bytes); + tls_io_instance->socket_io_read_bytes = NULL; } } else { - free(tls_io_instance->socket_io_read_bytes); - tls_io_instance->socket_io_read_bytes = NULL; + LogError("Tlsio_Failure: memmove invalid size."); + return MBEDTLS_ERR_SSL_INTERNAL_ERROR; } } @@ -581,8 +599,6 @@ void tlsio_mbedtls_destroy(CONCRETE_IO_HANDLE tls_io) mbedtls_uninit(tls_io_instance); - xio_close(tls_io_instance->socket_io, NULL, NULL); - if (tls_io_instance->socket_io_read_bytes != NULL) { free(tls_io_instance->socket_io_read_bytes); @@ -715,7 +731,7 @@ int tlsio_mbedtls_close(CONCRETE_IO_HANDLE tls_io, ON_IO_CLOSE_COMPLETE on_io_cl return result; } -int tlsio_mbedtls_send(CONCRETE_IO_HANDLE tls_io, const void *buffer, size_t size, ON_SEND_COMPLETE on_send_complete, void *callback_context) +int tlsio_mbedtls_send(CONCRETE_IO_HANDLE tls_io, const void *buffer, size_t size, ON_SEND_COMPLETE on_send_complete_callback, void *callback_context) { int result = 0; @@ -734,7 +750,7 @@ int tlsio_mbedtls_send(CONCRETE_IO_HANDLE tls_io, const void *buffer, size_t siz } else { - tls_io_instance->send_complete_info.on_send_complete = on_send_complete; + tls_io_instance->send_complete_info.on_send_complete = on_send_complete_callback; tls_io_instance->send_complete_info.on_send_complete_callback_context = callback_context; tls_io_instance->send_complete_info.last_fragmented_req_status = IO_SEND_OK; int out_left = (int)size; diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/tlsio_openssl.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/tlsio_openssl.c index 1832994cd..23104e690 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/tlsio_openssl.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/tlsio_openssl.c @@ -21,6 +21,7 @@ #include "azure_c_shared_utility/shared_util_options.h" #include "azure_c_shared_utility/gballoc.h" #include "azure_c_shared_utility/const_defines.h" +#include "azure_c_shared_utility/safe_math.h" typedef enum TLSIO_STATE_TAG { @@ -607,10 +608,11 @@ static int openssl_static_locks_install(void) } else { - openssl_locks = malloc(CRYPTO_num_locks() * sizeof(LOCK_HANDLE)); - if (openssl_locks == NULL) + size_t malloc_size = safe_multiply_size_t(CRYPTO_num_locks(), sizeof(LOCK_HANDLE)); + if (malloc_size == SIZE_MAX || + (openssl_locks = malloc(malloc_size)) == NULL) { - LogError("Failed to allocate locks"); + LogError("Failed to allocate locks, size:%zu", malloc_size); result = MU_FAILURE; } else @@ -759,11 +761,14 @@ void engine_destroy(TLS_IO_INSTANCE* tls) { if(tls->engine != NULL) { + #ifndef OPENSSL_NO_ENGINE ENGINE_free(tls->engine); // Release structural reference. + #endif // OPENSSL_NO_ENGINE tls->engine = NULL; } } +#ifndef OPENSSL_NO_ENGINE int engine_load(TLS_IO_INSTANCE* tls) { int result; @@ -782,6 +787,7 @@ int engine_load(TLS_IO_INSTANCE* tls) return result; } +#endif // OPENSSL_NO_ENGINE static void close_openssl_instance(TLS_IO_INSTANCE* tls_io_instance) { @@ -844,11 +850,15 @@ static void on_underlying_io_open_complete(void* context, IO_OPEN_RESULT open_re } else { + LogError("Invalid open_result. Expected result is IO_OPEN_OK."); tls_io_instance->tlsio_state = TLSIO_STATE_NOT_OPEN; indicate_open_complete(tls_io_instance, IO_OPEN_ERROR); - LogError("Invalid tlsio_state. Expected state is TLSIO_STATE_OPENING_UNDERLYING_IO."); } } + else + { + LogError("Invalid tlsio_state. Expected state is TLSIO_STATE_OPENING_UNDERLYING_IO."); + } } static void on_underlying_io_error(void* context) @@ -1052,7 +1062,7 @@ static int create_openssl_instance(TLS_IO_INSTANCE* tlsInstance) const SSL_METHOD* method = NULL; -#if (OPENSSL_VERSION_NUMBER < 0x10100000L) || (OPENSSL_VERSION_NUMBER >= 0x20000000L) +#if (OPENSSL_VERSION_NUMBER < 0x10100000L) || defined(LIBRESSL_VERSION_NUMBER) if (tlsInstance->tls_version == VERSION_1_2) { method = TLSv1_2_method(); @@ -1077,6 +1087,7 @@ static int create_openssl_instance(TLS_IO_INSTANCE* tlsInstance) log_ERR_get_error("Failed allocating OpenSSL context."); result = MU_FAILURE; } + #ifndef OPENSSL_NO_ENGINE else if ((tlsInstance->engine_id != NULL) && (engine_load(tlsInstance) != 0)) { @@ -1084,6 +1095,7 @@ static int create_openssl_instance(TLS_IO_INSTANCE* tlsInstance) tlsInstance->ssl_context = NULL; result = MU_FAILURE; } + #endif // OPENSSL_NO_ENGINE else if ((tlsInstance->cipher_list != NULL) && (SSL_CTX_set_cipher_list(tlsInstance->ssl_context, tlsInstance->cipher_list)) != 1) { @@ -1109,8 +1121,12 @@ static int create_openssl_instance(TLS_IO_INSTANCE* tlsInstance) tlsInstance->ssl_context, tlsInstance->x509_certificate, tlsInstance->x509_private_key, + #ifndef OPENSSL_NO_ENGINE tlsInstance->x509_private_key_type, tlsInstance->engine) != 0) + #else // OPENSSL_NO_ENGINE + tlsInstance->x509_private_key_type) != 0) + #endif // OPENSSL_NO_ENGINE ) { engine_destroy(tlsInstance); @@ -1248,7 +1264,7 @@ void tlsio_openssl_deinit(void) #if (OPENSSL_VERSION_NUMBER < 0x10000000L) ERR_remove_state(0); -#elif (OPENSSL_VERSION_NUMBER < 0x10100000L) || (OPENSSL_VERSION_NUMBER >= 0x20000000L) +#elif (OPENSSL_VERSION_NUMBER < 0x10100000L) || defined(LIBRESSL_VERSION_NUMBER) ERR_remove_thread_state(NULL); #endif #if (OPENSSL_VERSION_NUMBER >= 0x10002000L) && (OPENSSL_VERSION_NUMBER < 0x10010000L) && (SSL_COMP_free_compression_methods) @@ -1376,7 +1392,9 @@ void tlsio_openssl_destroy(CONCRETE_IO_HANDLE tls_io) tls_io_instance->cipher_list = NULL; } free((void*)tls_io_instance->x509_certificate); + tls_io_instance->x509_certificate = NULL; free((void*)tls_io_instance->x509_private_key); + tls_io_instance->x509_private_key = NULL; close_openssl_instance(tls_io_instance); if (tls_io_instance->underlying_io != NULL) { @@ -1384,6 +1402,7 @@ void tlsio_openssl_destroy(CONCRETE_IO_HANDLE tls_io) tls_io_instance->underlying_io = NULL; } free(tls_io_instance->hostname); + tls_io_instance->hostname = NULL; if (tls_io_instance->engine_id != NULL) { free(tls_io_instance->engine_id); @@ -1640,9 +1659,11 @@ int tlsio_openssl_setoption(CONCRETE_IO_HANDLE tls_io, const char* optionName, c // Store the certificate len = strlen(cert); - tls_io_instance->certificate = malloc(len + 1); - if (tls_io_instance->certificate == NULL) + size_t malloc_size = safe_add_size_t(len, 1); + if (malloc_size == SIZE_MAX || + (tls_io_instance->certificate = malloc(malloc_size)) == NULL) { + LogError("malloc failure, size:%zu", malloc_size); result = MU_FAILURE; } else @@ -1719,6 +1740,7 @@ int tlsio_openssl_setoption(CONCRETE_IO_HANDLE tls_io, const char* optionName, c } } } + #ifndef OPENSSL_NO_ENGINE else if (strcmp(OPTION_OPENSSL_ENGINE, optionName) == 0) { ENGINE_load_builtin_engines(); @@ -1733,6 +1755,7 @@ int tlsio_openssl_setoption(CONCRETE_IO_HANDLE tls_io, const char* optionName, c result = 0; } } + #endif // OPENSSL_NO_ENGINE else if (strcmp(OPTION_OPENSSL_PRIVATE_KEY_TYPE, optionName) == 0) { const OPTION_OPENSSL_KEY_TYPE type = *(const OPTION_OPENSSL_KEY_TYPE*)value; diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/tlsio_schannel.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/tlsio_schannel.c index ad73b38fb..850d81961 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/tlsio_schannel.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/tlsio_schannel.c @@ -21,6 +21,7 @@ #include "azure_c_shared_utility/singlylinkedlist.h" #include "azure_c_shared_utility/shared_util_options.h" #include "azure_c_shared_utility/gballoc.h" +#include "azure_c_shared_utility/safe_math.h" #define TLSIO_STATE_VALUES \ TLSIO_STATE_NOT_OPEN, \ @@ -515,13 +516,15 @@ static int send_chunk(CONCRETE_IO_HANDLE tls_io, const void* buffer, size_t size } else { + unsigned char* out_buffer; SecBuffer security_buffers[4]; SecBufferDesc security_buffers_desc; - size_t needed_buffer = sizes.cbHeader + size + sizes.cbTrailer; - unsigned char* out_buffer = (unsigned char*)malloc(needed_buffer); - if (out_buffer == NULL) + size_t needed_buffer = safe_add_size_t(sizes.cbHeader, size); + needed_buffer = safe_add_size_t(needed_buffer, sizes.cbTrailer); + if (needed_buffer == SIZE_MAX || + (out_buffer = (unsigned char*)malloc(needed_buffer)) == NULL) { - LogError("malloc failed"); + LogError("malloc failed, size:%zu", needed_buffer); result = MU_FAILURE; } else @@ -553,7 +556,7 @@ static int send_chunk(CONCRETE_IO_HANDLE tls_io, const void* buffer, size_t size } else { - if (xio_send(tls_io_instance->socket_io, out_buffer, security_buffers[0].cbBuffer + security_buffers[1].cbBuffer + security_buffers[2].cbBuffer, on_send_complete, callback_context) != 0) + if (xio_send(tls_io_instance->socket_io, out_buffer, (size_t)security_buffers[0].cbBuffer + (size_t)security_buffers[1].cbBuffer + (size_t)security_buffers[2].cbBuffer, on_send_complete, callback_context) != 0) { LogError("xio_send failed"); result = MU_FAILURE; @@ -762,6 +765,8 @@ static void on_underlying_io_bytes_received(void* context, const unsigned char* indicate_error(tls_io_instance); } } + + first_pending_io = singlylinkedlist_get_head_item(tls_io_instance->pending_io_list); } } } @@ -835,8 +840,18 @@ static void on_underlying_io_bytes_received(void* context, const unsigned char* } break; } - FreeContextBuffer(output_buffers[0].pvBuffer); - FreeContextBuffer(output_buffers[1].pvBuffer); + + if (output_buffers[0].pvBuffer != NULL) + { + FreeContextBuffer(output_buffers[0].pvBuffer); + output_buffers[0].pvBuffer = NULL; + } + + if (output_buffers[1].pvBuffer != NULL) + { + FreeContextBuffer(output_buffers[1].pvBuffer); + output_buffers[1].pvBuffer = NULL; + } } else if (tls_io_instance->tlsio_state == TLSIO_STATE_OPEN) { @@ -977,8 +992,18 @@ static void on_underlying_io_bytes_received(void* context, const unsigned char* } } } - FreeContextBuffer(output_buffers[0].pvBuffer); - FreeContextBuffer(output_buffers[1].pvBuffer); + + if (output_buffers[0].pvBuffer != NULL) + { + FreeContextBuffer(output_buffers[0].pvBuffer); + output_buffers[0].pvBuffer = NULL; + } + + if (output_buffers[1].pvBuffer != NULL) + { + FreeContextBuffer(output_buffers[1].pvBuffer); + output_buffers[1].pvBuffer = NULL; + } break; } @@ -1069,10 +1094,12 @@ CONCRETE_IO_HANDLE tlsio_schannel_create(void* io_create_parameters) { (void)memset(result, 0, sizeof(TLS_IO_INSTANCE)); - result->host_name = (SEC_TCHAR*)malloc(sizeof(SEC_TCHAR) * (1 + strlen(tls_io_config->hostname))); - if (result->host_name == NULL) + size_t malloc_size = safe_add_size_t(strlen(tls_io_config->hostname), 1); + malloc_size = safe_multiply_size_t(malloc_size, sizeof(SEC_TCHAR)); + if (malloc_size == SIZE_MAX || + (result->host_name = (SEC_TCHAR*)malloc(malloc_size)) == NULL) { - LogError("malloc failed"); + LogError("malloc failed, size:%zu", malloc_size); free(result); result = NULL; } @@ -1162,30 +1189,38 @@ void tlsio_schannel_destroy(CONCRETE_IO_HANDLE tls_io) if (tls_io_instance->received_bytes != NULL) { free(tls_io_instance->received_bytes); + tls_io_instance->received_bytes = NULL; } if (tls_io_instance->trustedCertificate != NULL) { free(tls_io_instance->trustedCertificate); + tls_io_instance->trustedCertificate = NULL; } if (tls_io_instance->x509_schannel_handle != NULL) { x509_schannel_destroy(tls_io_instance->x509_schannel_handle); + tls_io_instance->x509_schannel_handle = NULL; } if (tls_io_instance->x509certificate != NULL) { free(tls_io_instance->x509certificate); + tls_io_instance->x509certificate = NULL; } if (tls_io_instance->x509privatekey != NULL) { free(tls_io_instance->x509privatekey); + tls_io_instance->x509privatekey = NULL; } xio_destroy(tls_io_instance->socket_io); + tls_io_instance->socket_io = NULL; + free(tls_io_instance->host_name); + tls_io_instance->host_name = NULL; first_pending_io = singlylinkedlist_get_head_item(tls_io_instance->pending_io_list); while (first_pending_io != NULL) @@ -1207,7 +1242,11 @@ void tlsio_schannel_destroy(CONCRETE_IO_HANDLE tls_io) if (singlylinkedlist_remove(tls_io_instance->pending_io_list, first_pending_io) != 0) { LogError("Failure: removing pending IO from list"); + indicate_error(tls_io_instance); + break; } + + first_pending_io = singlylinkedlist_get_head_item(tls_io_instance->pending_io_list); } } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/tlsio_wolfssl.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/tlsio_wolfssl.c index 0b1ed649c..41f280748 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/tlsio_wolfssl.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/tlsio_wolfssl.c @@ -18,6 +18,7 @@ #include "azure_c_shared_utility/optimize_size.h" #include "azure_c_shared_utility/xlogging.h" #include "azure_c_shared_utility/shared_util_options.h" +#include "azure_c_shared_utility/safe_math.h" typedef enum TLSIO_STATE_ENUM_TAG { @@ -303,11 +304,13 @@ static void on_underlying_io_bytes_received(void* context, const unsigned char* if (context != NULL) { TLS_IO_INSTANCE* tls_io_instance = (TLS_IO_INSTANCE*)context; + unsigned char* new_socket_io_read_bytes; - unsigned char* new_socket_io_read_bytes = (unsigned char*)realloc(tls_io_instance->socket_io_read_bytes, tls_io_instance->socket_io_read_byte_count + size); - if (new_socket_io_read_bytes == NULL) + size_t realloc_size = safe_add_size_t(tls_io_instance->socket_io_read_byte_count, size); + if (realloc_size == SIZE_MAX || + (new_socket_io_read_bytes = (unsigned char*)realloc(tls_io_instance->socket_io_read_bytes, realloc_size)) == NULL) { - LogError("Failed allocating memory for received bytes"); + LogError("Failed allocating memory for received bytes, size:%zu", realloc_size); tls_io_instance->tlsio_state = TLSIO_STATE_ERROR; indicate_error(tls_io_instance); } @@ -404,9 +407,11 @@ static int on_io_recv(WOLFSSL *ssl, char *buf, int sz, void *context) if (result > 0) { + size_t read_byte_count = safe_subtract_size_t(tls_io_instance->socket_io_read_byte_count, (size_t)result); (void)memcpy(buf, tls_io_instance->socket_io_read_bytes, result); - (void)memmove(tls_io_instance->socket_io_read_bytes, tls_io_instance->socket_io_read_bytes + result, tls_io_instance->socket_io_read_byte_count - result); - tls_io_instance->socket_io_read_byte_count -= result; + (void)memmove(tls_io_instance->socket_io_read_bytes, tls_io_instance->socket_io_read_bytes + result, read_byte_count); + + tls_io_instance->socket_io_read_byte_count = read_byte_count; if (tls_io_instance->socket_io_read_byte_count > 0) { new_socket_io_read_bytes = (unsigned char*)realloc(tls_io_instance->socket_io_read_bytes, tls_io_instance->socket_io_read_byte_count); @@ -1033,6 +1038,11 @@ int tlsio_wolfssl_setoption(CONCRETE_IO_HANDLE tls_io, const char* optionName, c result = 0; } } + else + { + LogError("tlsio WolfSSL layer does not support disabling debug_logs after they have been enabled."); + result = MU_FAILURE; + } } #endif // LIBWOLFSSL_VERSION_HEX >= 0x04000000 else diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/x509_openssl.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/x509_openssl.c index cee380adc..dc4edbda4 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/x509_openssl.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/x509_openssl.c @@ -11,7 +11,9 @@ #include "openssl/x509.h" #include "openssl/pem.h" #include "openssl/err.h" +#ifndef OPENSSL_NO_ENGINE #include "openssl/engine.h" +#endif // OPENSSL_NO_ENGINE #ifdef __APPLE__ #ifndef EVP_PKEY_id @@ -219,6 +221,7 @@ int x509_openssl_add_pem_file_key(SSL_CTX* ssl_ctx, const char* x509privatekey) return result; } +#ifndef OPENSSL_NO_ENGINE int x509_openssl_add_engine_key(SSL_CTX* ssl_ctx, const char* x509privatekey_id, ENGINE* engine) { int result; @@ -270,13 +273,22 @@ int x509_openssl_add_engine_key(SSL_CTX* ssl_ctx, const char* x509privatekey_id, return result; } +#endif // OPENSSL_NO_ENGINE +#ifndef OPENSSL_NO_ENGINE int x509_openssl_add_credentials( SSL_CTX* ssl_ctx, const char* x509certificate, const char* x509privatekey, OPTION_OPENSSL_KEY_TYPE x509privatekeytype, ENGINE* engine) +#else // OPENSSL_NO_ENGINE +int x509_openssl_add_credentials( + SSL_CTX* ssl_ctx, + const char* x509certificate, + const char* x509privatekey, + OPTION_OPENSSL_KEY_TYPE x509privatekeytype) +#endif // OPENSSL_NO_ENGINE { int result; if (ssl_ctx == NULL || x509certificate == NULL || x509privatekey == NULL) @@ -285,11 +297,13 @@ int x509_openssl_add_credentials( LogError("invalid parameter detected: ssl_ctx=%p, x509certificate=%p, x509privatekey=%p", ssl_ctx, x509certificate, x509privatekey); result = MU_FAILURE; } +#ifndef OPENSSL_NO_ENGINE else if ((x509privatekeytype == KEY_TYPE_ENGINE) && (engine == NULL)) { LogError("OpenSSL Engine must be configured when KEY_TYPE_ENGINE is used."); result = MU_FAILURE; } +#endif // OPENSSL_NO_ENGINE else { // Configure private key. @@ -297,13 +311,16 @@ int x509_openssl_add_credentials( { result = x509_openssl_add_pem_file_key(ssl_ctx, x509privatekey); } + #ifndef OPENSSL_NO_ENGINE else if (x509privatekeytype == KEY_TYPE_ENGINE) { result = x509_openssl_add_engine_key(ssl_ctx, x509privatekey, engine); } + #endif // OPENSSL_NO_ENGINE else { - result = 0; + LogError("Unexpected value of OPTION_OPENSSL_KEY_TYPE (%d)", x509privatekeytype); + result = MU_FAILURE; } if (result == 0) @@ -423,4 +440,4 @@ int x509_openssl_add_certificates(SSL_CTX* ssl_ctx, const char* certificates) } } return result; -} \ No newline at end of file +} diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/x509_schannel.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/x509_schannel.c index 1d91d9600..4fc3b2172 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/x509_schannel.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/x509_schannel.c @@ -6,6 +6,8 @@ #include "azure_c_shared_utility/gballoc.h" #include "azure_c_shared_utility/x509_schannel.h" #include "azure_c_shared_utility/xlogging.h" +#include "azure_c_shared_utility/safe_math.h" + #if _MSC_VER > 1500 #include #endif @@ -153,19 +155,21 @@ static int set_ecc_certificate_info(X509_SCHANNEL_HANDLE_DATA* x509_handle, unsi { int result; #if _MSC_VER > 1500 + BCRYPT_ECCKEY_BLOB* pKeyBlob; SECURITY_STATUS status; CRYPT_BIT_BLOB* pPubKeyBlob = &x509_handle->x509certificate_context->pCertInfo->SubjectPublicKeyInfo.PublicKey; CRYPT_ECC_PRIVATE_KEY_INFO* pPrivKeyInfo = (CRYPT_ECC_PRIVATE_KEY_INFO*)x509privatekeyBlob; DWORD pubSize = pPubKeyBlob->cbData - 1; DWORD privSize = pPrivKeyInfo->PrivateKey.cbData; - DWORD keyBlobSize = sizeof(BCRYPT_ECCKEY_BLOB) + pubSize + privSize; + size_t keyBlobSize = safe_add_size_t(safe_add_size_t(sizeof(BCRYPT_ECCKEY_BLOB), pubSize), privSize); BYTE* pubKeyBuf = pPubKeyBlob->pbData + 1; BYTE* privKeyBuf = pPrivKeyInfo->PrivateKey.pbData; - BCRYPT_ECCKEY_BLOB* pKeyBlob = (BCRYPT_ECCKEY_BLOB*)malloc(keyBlobSize); - if (pKeyBlob == NULL) + + if (keyBlobSize == SIZE_MAX || + (pKeyBlob = (BCRYPT_ECCKEY_BLOB*)malloc(keyBlobSize)) == NULL) { /*Codes_SRS_X509_SCHANNEL_02_010: [ Otherwise, x509_schannel_create shall fail and return a NULL X509_SCHANNEL_HANDLE. ]*/ - LogError("Failed to malloc NCrypt private key blob"); + LogError("Failed to malloc NCrypt private key blob, size:%zu", keyBlobSize); result = MU_FAILURE; } else @@ -200,7 +204,7 @@ static int set_ecc_certificate_info(X509_SCHANNEL_HANDLE_DATA* x509_handle, unsi /*Codes_SRS_X509_SCHANNEL_02_006: [ x509_schannel_create shall import the private key by calling CryptImportKey. ] */ /*NOTE: As no WinCrypt key storage provider supports ECC keys, NCrypt is used instead*/ - status = NCryptImportKey(x509_handle->hProv, 0, BCRYPT_ECCPRIVATE_BLOB, &ncBufDesc, &x509_handle->x509hcryptkey, (BYTE*)pKeyBlob, keyBlobSize, NCRYPT_OVERWRITE_KEY_FLAG); + status = NCryptImportKey(x509_handle->hProv, 0, BCRYPT_ECCPRIVATE_BLOB, &ncBufDesc, &x509_handle->x509hcryptkey, (BYTE*)pKeyBlob, (DWORD)keyBlobSize, NCRYPT_OVERWRITE_KEY_FLAG); if (status == ERROR_SUCCESS) { status2 = NCryptFreeObject(x509_handle->x509hcryptkey); @@ -511,7 +515,7 @@ static int add_certificates_to_store(const char* trustedCertificate, HCERTSTORE LogError("Cannot encode trusted certificate"); result = MU_FAILURE; } - else if (CertAddEncodedCertificateToStore(hCertStore, X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, trustedCertificateEncoded, trustedCertificateEncodedLen, CERT_STORE_ADD_REPLACE_EXISTING, NULL) != TRUE) + else if (CertAddEncodedCertificateToStore(hCertStore, X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, trustedCertificateEncoded, trustedCertificateEncodedLen, CERT_STORE_ADD_NEW, NULL) != TRUE) { lastError = GetLastError(); LogError("CertAddEncodedCertificateToStore failed with error 0x%08x", lastError); @@ -559,21 +563,20 @@ int x509_verify_certificate_in_chain(const char* trustedCertificate, PCCERT_CONT else { CERT_CHAIN_ENGINE_CONFIG EngineConfig; - CERT_CHAIN_PARA ChainPara; - CERT_CHAIN_POLICY_PARA PolicyPara; - CERT_CHAIN_POLICY_STATUS PolicyStatus; - memset(&EngineConfig, 0, sizeof(EngineConfig)); EngineConfig.cbSize = sizeof(EngineConfig); EngineConfig.dwFlags = CERT_CHAIN_ENABLE_CACHE_AUTO_UPDATE | CERT_CHAIN_ENABLE_SHARE_STORE; EngineConfig.hExclusiveRoot = hCertStore; + CERT_CHAIN_PARA ChainPara; memset(&ChainPara, 0, sizeof(ChainPara)); ChainPara.cbSize = sizeof(ChainPara); + CERT_CHAIN_POLICY_PARA PolicyPara; memset(&PolicyPara, 0, sizeof(PolicyPara)); PolicyPara.cbSize = sizeof(PolicyPara); + CERT_CHAIN_POLICY_STATUS PolicyStatus; memset(&PolicyStatus, 0, sizeof(PolicyStatus)); PolicyStatus.cbSize = sizeof(PolicyStatus); diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/build/.vsts-ci.yml b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/build/.vsts-ci.yml index 5b6d86d3c..37d55e68a 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/build/.vsts-ci.yml +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/build/.vsts-ci.yml @@ -1,9 +1,36 @@ name: $(BuildID)_$(BuildDefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r) resources: -- repo: self - clean: true + containers: + - container: linux-c-ubuntu-2204 + endpoint: csdk-containers + image: csdkcontainerregistry.azurecr.io/linux-c-ubuntu-2204:latest + - container: linux-c-ubuntu-2004 + endpoint: csdk-containers + image: csdkcontainerregistry.azurecr.io/linux-c-ubuntu-2004:latest + - container: linux-c-ubuntu-clang + endpoint: csdk-containers + image: csdkcontainerregistry.azurecr.io/linux-c-ubuntu-clang:latest + - container: linux-c-ubuntu-c-ares + endpoint: csdk-containers + image: csdkcontainerregistry.azurecr.io/linux-c-ubuntu-c-ares:latest + - container: linux-c-ubuntu-wolfssl + endpoint: csdk-containers + image: csdkcontainerregistry.azurecr.io/linux-c-ubuntu-wolfssl:latest + - container: linux-c-ubuntu-bearssl + endpoint: csdk-containers + image: csdkcontainerregistry.azurecr.io/linux-c-ubuntu-bearssl:latest + - container: linux-c-ubuntu-mbed + endpoint: csdk-containers + image: csdkcontainerregistry.azurecr.io/linux-c-ubuntu-mbed:latest + - container: linux-c-debian-buster + endpoint: csdk-containers + image: csdkcontainerregistry.azurecr.io/linux-c-debian-buster:latest + - container: raspberrypi-c-buster + endpoint: csdk-containers + image: csdkcontainerregistry.azurecr.io/raspberrypi-c-buster:brown jobs: - job: checksubmodule + displayName: Check Submodule pool: vmImage: 'ubuntu-20.04' steps: @@ -14,22 +41,25 @@ jobs: python-software-properties \ build-essential \ pkg-config - sudo curl -sL https://deb.nodesource.com/setup_6.x | bash - + sudo curl -sL https://deb.nodesource.com/setup_16.x | bash - sudo apt-get install -y nodejs - displayName: 'setup' + displayName: 'Setup' - script: | npm install check_submodules - ./../../node_modules/.bin/check_submodules . master - displayName: 'build' + node_modules/.bin/check_submodules . master + displayName: 'Build' - job: windowsx86 + displayName: Windows x86 pool: - vmImage: 'vs2017-win2016' + name: 'sdk-c--win-vs2022' steps: - script: | if exist jenkins\windows_c.cmd ( - call "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\VsDevCmd.bat" call jenkins\windows_c.cmd) - displayName: 'build' + displayName: 'Build' + - script: | + call jenkins\windows_c_VsDevCmd.cmd && cd cmake && ctest -T test --no-compress-output -C "Debug" -V -j 16 --schedule-random + displayName: "Run Tests" env: IOTHUB_CONNECTION_STRING: $(IOTHUB-CONNECTION-STRING) IOTHUB_EVENTHUB_CONNECTION_STRING: $(IOTHUB-EVENTHUB-CONNECTION-STRING) @@ -45,48 +75,53 @@ jobs: IOTHUB_CONN_STRING_INVALIDCERT: $(IOTHUB-CONN-STRING-INVALIDCERT) DPS_GLOBALDEVICEENDPOINT_INVALIDCERT: $(DPS-GLOBALDEVICEENDPOINT-INVALIDCERT) PROVISIONING_CONNECTION_STRING_INVALIDCERT: $(PROVISIONING-CONNECTION-STRING-INVALIDCERT) - - script: cd .. && rd /Q /S $(Agent.BuildDirectory)\s - displayName: 'cleanup' - condition: always() -- job: raspberrypi + - task: ComponentGovernanceComponentDetection@0 + displayName: 'Component Detection' +- job: windowsx64 variables: - _PREVIEW_VSTS_DOCKER_IMAGE: "aziotbld/raspberrypi-c-buster:brown" - pool: - name: 'sdk-c--ubuntu-18' - displayName: raspberrypi + CodeQL.Enabled: true + CodeQL.Language: cpp + pool: + name: 'sdk-c--win-vs2022' + displayName: 'Windows x64' steps: - script: | - chmod +x jenkins/raspberrypi_c_buster.sh - ./jenkins/raspberrypi_c_buster.sh - displayName: 'build' - - script: sudo rm -rf $(Agent.BuildDirectory)/* - displayName: 'cleanup' -- job: linuxoptions - variables: - _PREVIEW_VSTS_DOCKER_IMAGE: "aziotbld/vsts-linux-c-ubuntu" - pool: - name: 'sdk-c--ubuntu-18' - displayName: 'linux-options' - steps: + if exist jenkins\windows_c.cmd ( + call jenkins\windows_c.cmd --platform x64) + displayName: 'Build' - script: | - if [ -f "jenkins/linux_c_option_test.sh" ] - then - sudo ./jenkins/linux_c_option_test.sh - fi - displayName: 'build' - condition: always() - - script: sudo rm -rf $(Agent.BuildDirectory)/* - displayName: 'cleanup' - condition: always() + call jenkins\windows_c_VsDevCmd.cmd x64 && cd cmake && ctest -T test --no-compress-output -C "Debug" -V -j 16 --schedule-random + displayName: "Run Tests" + env: + IOTHUB_CONNECTION_STRING: $(IOTHUB-CONNECTION-STRING) + IOTHUB_EVENTHUB_CONNECTION_STRING: $(IOTHUB-EVENTHUB-CONNECTION-STRING) + IOTHUB_E2E_X509_CERT_BASE64: $(IOTHUB-E2E-X509-CERT-BASE64) + IOTHUB_E2E_X509_PRIVATE_KEY_BASE64: $(IOTHUB-E2E-X509-PRIVATE-KEY-BASE64) + IOTHUB_E2E_X509_THUMBPRINT: $(IOTHUB-E2E-X509-THUMBPRINT) + IOTHUB_POLICY_KEY: $(IOTHUB-POLICY-KEY) + IOTHUB_PARTITION_COUNT: $(IOTHUB-PARTITION-COUNT) + STORAGE_ACCOUNT_CONNECTION_STRING: $(STORAGE-ACCOUNT-CONNECTION-STRING) + IOT_DPS_CONNECTION_STRING: $(IOT-DPS-CONNECTION-STRING) + IOT_DPS_ID_SCOPE: $(IOT-DPS-ID-SCOPE) + IOTHUB_CA_ROOT_CERT: $(IOTHUB-CA-ROOT-CERT) + IOTHUB_CA_ROOT_CERT_KEY: $(IOTHUB-CA-ROOT-CERT-KEY) + IOT_DPS_GLOBAL_ENDPOINT: $(IOT-DPS-GLOBAL-ENDPOINT) + IOTHUB_DEVICE_CONN_STRING_INVALIDCERT: $(IOTHUB-DEVICE-CONN-STRING-INVALIDCERT) + IOTHUB_CONN_STRING_INVALIDCERT: $(IOTHUB-CONN-STRING-INVALIDCERT) + DPS_GLOBALDEVICEENDPOINT_INVALIDCERT: $(DPS-GLOBALDEVICEENDPOINT-INVALIDCERT) + PROVISIONING_CONNECTION_STRING_INVALIDCERT: $(PROVISIONING-CONNECTION-STRING-INVALIDCERT) + - task: ComponentGovernanceComponentDetection@0 + displayName: 'Component Detection' - job: windowsdynamic + displayName: Windows Dynamic pool: - vmImage: 'vs2017-win2016' + name: 'sdk-c--win-vs2022' steps: - script: | if exist jenkins\windows_c_build_as_dynamic.cmd ( - call "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\VsDevCmd.bat" + call jenkins\windows_c_VsDevCmd.cmd call jenkins\windows_c_build_as_dynamic.cmd) - displayName: 'build' + displayName: 'Build' env: IOTHUB_CONNECTION_STRING: $(IOTHUB-CONNECTION-STRING) IOTHUB_EVENTHUB_CONNECTION_STRING: $(IOTHUB-EVENTHUB-CONNECTION-STRING) @@ -104,19 +139,25 @@ jobs: IOTHUB_CONN_STRING_INVALIDCERT: $(IOTHUB-CONN-STRING-INVALIDCERT) DPS_GLOBALDEVICEENDPOINT_INVALIDCERT: $(DPS-GLOBALDEVICEENDPOINT-INVALIDCERT) PROVISIONING_CONNECTION_STRING_INVALIDCERT: $(PROVISIONING-CONNECTION-STRING-INVALIDCERT) - - script: cd .. && rd /Q /S $(Agent.BuildDirectory)\s - displayName: 'cleanup' - condition: always() -- job: OSX + - task: ComponentGovernanceComponentDetection@0 + displayName: 'Component Detection' +- job: clang + container: linux-c-ubuntu-clang pool: - name: OSX + name: 'sdk-c--ubuntu-22' + displayName: 'Linux Ubuntu Clang' steps: - script: | - if [ -f "jenkins/osx_gcc_openssl.sh" ] + if [ -f "jenkins/ubuntu_clang.sh" ] then - ./jenkins/osx_gcc_openssl.sh + export OPENSSL_ia32cap=0x00000000 + sudo chmod -R 755 . + sudo -E ./jenkins/ubuntu_clang.sh fi - displayName: 'build' + displayName: 'Build' + - script: | + cd cmake && sudo -E ../build_all/linux/run_tests.sh + displayName: "Run Tests" env: IOTHUB_CONNECTION_STRING: $(IOTHUB-CONNECTION-STRING) IOTHUB_EVENTHUB_CONNECTION_STRING: $(IOTHUB-EVENTHUB-CONNECTION-STRING) @@ -135,24 +176,23 @@ jobs: IOTHUB_CONN_STRING_INVALIDCERT: $(IOTHUB-CONN-STRING-INVALIDCERT) DPS_GLOBALDEVICEENDPOINT_INVALIDCERT: $(DPS-GLOBALDEVICEENDPOINT-INVALIDCERT) PROVISIONING_CONNECTION_STRING_INVALIDCERT: $(PROVISIONING-CONNECTION-STRING-INVALIDCERT) - - script: rm -rf $(Agent.BuildDirectory)/* - displayName: 'cleanup' - condition: always() -- job: clang - variables: - _PREVIEW_VSTS_DOCKER_IMAGE: "aziotbld/ubuntu-clang" - pool: - name: 'sdk-c--ubuntu-18' - displayName: 'clang' +- job: ubuntu2004 + container: linux-c-ubuntu-2004 + pool: + name: 'sdk-c--ubuntu-22' + displayName: 'Linux Ubuntu 20.04' steps: - script: | - if [ -f "jenkins/ubuntu_clang.sh" ] + if [ -f "jenkins/ubuntu_c.sh" ] then export OPENSSL_ia32cap=0x00000000 sudo chmod -R 755 . - sudo -E ./jenkins/ubuntu_clang.sh + sudo -E ./jenkins/ubuntu_c.sh fi - displayName: 'build' + displayName: 'Build' + - script: | + cd cmake && sudo -E ../build_all/linux/run_tests.sh + displayName: "Run Tests" env: IOTHUB_CONNECTION_STRING: $(IOTHUB-CONNECTION-STRING) IOTHUB_EVENTHUB_CONNECTION_STRING: $(IOTHUB-EVENTHUB-CONNECTION-STRING) @@ -171,24 +211,23 @@ jobs: IOTHUB_CONN_STRING_INVALIDCERT: $(IOTHUB-CONN-STRING-INVALIDCERT) DPS_GLOBALDEVICEENDPOINT_INVALIDCERT: $(DPS-GLOBALDEVICEENDPOINT-INVALIDCERT) PROVISIONING_CONNECTION_STRING_INVALIDCERT: $(PROVISIONING-CONNECTION-STRING-INVALIDCERT) - - script: sudo rm -rf $(Agent.BuildDirectory)/* - displayName: 'cleanup' - condition: always() -- job: ubuntu1604 - variables: - _PREVIEW_VSTS_DOCKER_IMAGE: "aziotbld/linux-c-ubuntu" +- job: ubuntu2204 + container: linux-c-ubuntu-2204 pool: - name: 'sdk-c--ubuntu-18' - displayName: 'ubuntu1604' + name: 'sdk-c--ubuntu-22' + displayName: 'Linux Ubuntu 22.04' steps: - script: | - if [ -f "jenkins/ubuntu1604_c.sh" ] + if [ -f "jenkins/ubuntu_c.sh" ] then export OPENSSL_ia32cap=0x00000000 sudo chmod -R 755 . - sudo -E ./jenkins/ubuntu1604_c.sh + sudo -E ./jenkins/ubuntu_c.sh fi - displayName: 'build' + displayName: 'Build' + - script: | + cd cmake && sudo -E ../build_all/linux/run_tests.sh + displayName: "Run Tests" env: IOTHUB_CONNECTION_STRING: $(IOTHUB-CONNECTION-STRING) IOTHUB_EVENTHUB_CONNECTION_STRING: $(IOTHUB-EVENTHUB-CONNECTION-STRING) @@ -207,15 +246,95 @@ jobs: IOTHUB_CONN_STRING_INVALIDCERT: $(IOTHUB-CONN-STRING-INVALIDCERT) DPS_GLOBALDEVICEENDPOINT_INVALIDCERT: $(DPS-GLOBALDEVICEENDPOINT-INVALIDCERT) PROVISIONING_CONNECTION_STRING_INVALIDCERT: $(PROVISIONING-CONNECTION-STRING-INVALIDCERT) - - script: sudo rm -rf $(Agent.BuildDirectory)/* - displayName: 'cleanup' +- job: linuxoptions + displayName: 'Linux Ubuntu 20.04 with Options' + container: linux-c-ubuntu-2004 + pool: + name: 'sdk-c--ubuntu-22' + steps: + - script: | + if [ -f "jenkins/linux_c_option_test.sh" ] + then + sudo ./jenkins/linux_c_option_test.sh + fi + displayName: 'Build' condition: always() +- job: linux_installed_deps + container: linux-c-ubuntu-2004 + pool: + name: 'sdk-c--ubuntu-22' + displayName: 'Linux with Installed Deps' + steps: + - script: | + export OPENSSL_ia32cap=0x00000000 + sudo chmod -R 755 . + sudo -E ./jenkins/linux_install_deps.sh + displayName: 'Build' + env: + IOTHUB_CONNECTION_STRING: $(IOTHUB-CONNECTION-STRING) + IOTHUB_EVENTHUB_CONNECTION_STRING: $(IOTHUB-EVENTHUB-CONNECTION-STRING) + IOTHUB_E2E_X509_CERT_BASE64: $(IOTHUB-E2E-X509-CERT-BASE64) + IOTHUB_E2E_X509_PRIVATE_KEY_BASE64: $(IOTHUB-E2E-X509-PRIVATE-KEY-BASE64) + IOTHUB_E2E_X509_THUMBPRINT: $(IOTHUB-E2E-X509-THUMBPRINT) + IOTHUB_POLICY_KEY: $(IOTHUB-POLICY-KEY) + STORAGE_ACCOUNT_CONNECTION_STRING: $(STORAGE-ACCOUNT-CONNECTION-STRING) + IOT_DPS_CONNECTION_STRING: $(IOT-DPS-CONNECTION-STRING) + IOT_DPS_ID_SCOPE: $(IOT-DPS-ID-SCOPE) + IOTHUB_CA_ROOT_CERT: $(IOTHUB-CA-ROOT-CERT) + IOTHUB_CA_ROOT_CERT_KEY: $(IOTHUB-CA-ROOT-CERT-KEY) + IOT_DPS_GLOBAL_ENDPOINT: $(IOT-DPS-GLOBAL-ENDPOINT) + IOTHUB_DEVICE_CONN_STRING_INVALIDCERT: $(IOTHUB-DEVICE-CONN-STRING-INVALIDCERT) + IOTHUB_CONN_STRING_INVALIDCERT: $(IOTHUB-CONN-STRING-INVALIDCERT) + DPS_GLOBALDEVICEENDPOINT_INVALIDCERT: $(DPS-GLOBALDEVICEENDPOINT-INVALIDCERT) + PROVISIONING_CONNECTION_STRING_INVALIDCERT: $(PROVISIONING-CONNECTION-STRING-INVALIDCERT) + IOT_DPS_INDIVIDUAL_X509_CERTIFICATE: $(IOTHUB-E2E-X509-ECC-CERT-BASE64) + IOT_DPS_INDIVIDUAL_X509_KEY: $(IOTHUB-E2E-X509-ECC-PRIVATE-KEY-BASE64) + IOT_DPS_INDIVIDUAL_REGISTRATION_ID: $(IOT-DPS-INDIVIDUAL-REGISTRATION-ID) +- job: cares + container: linux-c-ubuntu-c-ares + pool: + name: 'sdk-c--ubuntu-22' + displayName: 'Linux with C-Ares' + steps: + - script: | + sudo -E bash jenkins/linux_cares.sh + displayName: 'Build' + - script: | + cd cmake && sudo -E ../build_all/linux/run_tests.sh + displayName: "Run Tests" + env: + IOTHUB_CONNECTION_STRING: $(IOTHUB-CONNECTION-STRING) + IOTHUB_EVENTHUB_CONNECTION_STRING: $(IOTHUB-EVENTHUB-CONNECTION-STRING) + IOTHUB_E2E_X509_CERT_BASE64: $(IOTHUB-E2E-X509-CERT-BASE64) + IOTHUB_E2E_X509_PRIVATE_KEY_BASE64: $(IOTHUB-E2E-X509-PRIVATE-KEY-BASE64) + IOTHUB_E2E_X509_THUMBPRINT: $(IOTHUB-E2E-X509-THUMBPRINT) + IOTHUB_POLICY_KEY: $(IOTHUB-POLICY-KEY) + STORAGE_ACCOUNT_CONNECTION_STRING: $(STORAGE-ACCOUNT-CONNECTION-STRING) + IOT_DPS_CONNECTION_STRING: $(IOT-DPS-CONNECTION-STRING) + IOT_DPS_ID_SCOPE: $(IOT-DPS-ID-SCOPE) + IOTHUB_CA_ROOT_CERT: $(IOTHUB-CA-ROOT-CERT) + IOTHUB_CA_ROOT_CERT_KEY: $(IOTHUB-CA-ROOT-CERT-KEY) + IOT_DPS_GLOBAL_ENDPOINT: $(IOT-DPS-GLOBAL-ENDPOINT) + IOTHUB_DEVICE_CONN_STRING_INVALIDCERT: $(IOTHUB-DEVICE-CONN-STRING-INVALIDCERT) + IOTHUB_CONN_STRING_INVALIDCERT: $(IOTHUB-CONN-STRING-INVALIDCERT) + DPS_GLOBALDEVICEENDPOINT_INVALIDCERT: $(DPS-GLOBALDEVICEENDPOINT-INVALIDCERT) + PROVISIONING_CONNECTION_STRING_INVALIDCERT: $(PROVISIONING-CONNECTION-STRING-INVALIDCERT) + IOT_DPS_INDIVIDUAL_X509_CERTIFICATE: $(IOTHUB-E2E-X509-ECC-CERT-BASE64) + IOT_DPS_INDIVIDUAL_X509_KEY: $(IOTHUB-E2E-X509-ECC-PRIVATE-KEY-BASE64) + IOT_DPS_INDIVIDUAL_REGISTRATION_ID: $(IOT-DPS-INDIVIDUAL-REGISTRATION-ID) + - task: PublishTestResults@2 + displayName: 'Publish C Ares Results' + inputs: + testRunner: CTest + testResultsFiles: '**/Test.xml' + mergeTestResults: true + testRunTitle: 'cares' + condition: succeededOrFailed() - job: debian - variables: - _PREVIEW_VSTS_DOCKER_IMAGE: "aziotbld/c-debian" + container: linux-c-debian-buster pool: - name: 'sdk-c--ubuntu-18' - displayName: 'debian' + name: 'sdk-c--ubuntu-22' + displayName: 'Linux Debian (Buster)' steps: - script: | if [ -f "jenkins/debian_c.sh" ] @@ -224,7 +343,10 @@ jobs: sudo -E ./debian_c.sh sudo jenkins/debian_c.sh fi - displayName: 'build' + displayName: 'Build' + - script: | + cd cmake && sudo -E ../build_all/linux/run_tests.sh + displayName: "Run Tests" env: IOTHUB_CONNECTION_STRING: $(IOTHUB-CONNECTION-STRING) IOTHUB_EVENTHUB_CONNECTION_STRING: $(IOTHUB-EVENTHUB-CONNECTION-STRING) @@ -243,23 +365,23 @@ jobs: IOTHUB_CONN_STRING_INVALIDCERT: $(IOTHUB-CONN-STRING-INVALIDCERT) DPS_GLOBALDEVICEENDPOINT_INVALIDCERT: $(DPS-GLOBALDEVICEENDPOINT-INVALIDCERT) PROVISIONING_CONNECTION_STRING_INVALIDCERT: $(PROVISIONING-CONNECTION-STRING-INVALIDCERT) - - script: sudo rm -rf $(Agent.BuildDirectory)/* - displayName: 'cleanup' - condition: always() - job: linux_mbed - variables: - _PREVIEW_VSTS_DOCKER_IMAGE: "aziotbld/linux-c-mbed" + container: linux-c-ubuntu-mbed pool: - name: 'sdk-c--ubuntu-18' - displayName: 'linux_mbed' + name: 'sdk-c--ubuntu-22' + displayName: 'mbedTLS' steps: + - script: | + chmod +x jenkins/linux_mbed_clang_buildonly.sh + ./jenkins/linux_mbed_clang_buildonly.sh + displayName: 'Clang Build' - script: | if [ -f "jenkins/debian_c.sh" ] then sudo chmod 755 jenkins/linux_mbed.sh sudo -E ./jenkins/linux_mbed.sh fi - displayName: 'build' + displayName: 'Build' env: IOTHUB_CONNECTION_STRING: $(IOTHUB-CONNECTION-STRING) IOTHUB_EVENTHUB_CONNECTION_STRING: $(IOTHUB-EVENTHUB-CONNECTION-STRING) @@ -277,16 +399,16 @@ jobs: IOTHUB_CONN_STRING_INVALIDCERT: $(IOTHUB-CONN-STRING-INVALIDCERT) DPS_GLOBALDEVICEENDPOINT_INVALIDCERT: $(DPS-GLOBALDEVICEENDPOINT-INVALIDCERT) PROVISIONING_CONNECTION_STRING_INVALIDCERT: $(PROVISIONING-CONNECTION-STRING-INVALIDCERT) - - script: sudo rm -rf $(Agent.BuildDirectory)/* - displayName: 'cleanup' - condition: always() - job: wolfssl - variables: - _PREVIEW_VSTS_DOCKER_IMAGE: "aziotbld/vsts-c-wolfssl" + container: linux-c-ubuntu-wolfssl pool: - name: 'sdk-c--ubuntu-18' - displayName: 'wolfssl' + name: 'sdk-c--ubuntu-22' + displayName: 'WolfSSL' steps: + - script: | + chmod +x jenkins/linux_wolfssl_clang_buildonly.sh + ./jenkins/linux_wolfssl_clang_buildonly.sh + displayName: 'Clang Build' - script: | cmake --version cc --version @@ -298,7 +420,7 @@ jobs: LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/my_library/ sudo jenkins/linux_wolfssl.sh fi - displayName: 'build' + displayName: 'Build' env: IOTHUB_CONNECTION_STRING: $(IOTHUB-CONNECTION-STRING) IOTHUB_EVENTHUB_CONNECTION_STRING: $(IOTHUB-EVENTHUB-CONNECTION-STRING) @@ -317,16 +439,16 @@ jobs: IOTHUB_CONN_STRING_INVALIDCERT: $(IOTHUB-CONN-STRING-INVALIDCERT) DPS_GLOBALDEVICEENDPOINT_INVALIDCERT: $(DPS-GLOBALDEVICEENDPOINT-INVALIDCERT) PROVISIONING_CONNECTION_STRING_INVALIDCERT: $(PROVISIONING-CONNECTION-STRING-INVALIDCERT) - - script: sudo rm -rf $(Agent.BuildDirectory)/* - displayName: 'cleanup' - condition: always() - job: bearssl - variables: - _PREVIEW_VSTS_DOCKER_IMAGE: "aziotbld/vsts-c-bearssl" + container: linux-c-ubuntu-bearssl pool: - name: 'sdk-c--ubuntu-18' - displayName: 'bearssl' + name: 'sdk-c--ubuntu-22' + displayName: 'BearSSL' steps: + - script: | + chmod +x jenkins/linux_bearssl_clang_buildonly.sh + ./jenkins/linux_bearssl_clang_buildonly.sh + displayName: 'Clang Build' - script: | LD_LIBRARY_PATH=/usr/local/lib LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/my_library/ @@ -334,7 +456,7 @@ jobs: bearsslDir=/beary export bearsslDir sudo bash jenkins/linux_bearssl.sh - displayName: 'build' + displayName: 'Build' env: IOTHUB_CONNECTION_STRING: $(IOTHUB-CONNECTION-STRING) IOTHUB_EVENTHUB_CONNECTION_STRING: $(IOTHUB-EVENTHUB-CONNECTION-STRING) @@ -353,19 +475,20 @@ jobs: IOTHUB_CONN_STRING_INVALIDCERT: $(IOTHUB-CONN-STRING-INVALIDCERT) DPS_GLOBALDEVICEENDPOINT_INVALIDCERT: $(DPS-GLOBALDEVICEENDPOINT-INVALIDCERT) PROVISIONING_CONNECTION_STRING_INVALIDCERT: $(PROVISIONING-CONNECTION-STRING-INVALIDCERT) - - script: sudo rm -rf $(Agent.BuildDirectory)/* - displayName: 'cleanup' - condition: always() -- job: windowsx64 +- job: OSX + displayName: OSX pool: - vmImage: 'vs2017-win2016' - displayName: 'windowsx64' + vmImage: 'macOS-13' steps: - script: | - if exist jenkins\windows_c.cmd ( - call "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\VsDevCmd.bat" - call jenkins\windows_c.cmd --platform x64) - displayName: 'build' + if [ -f "jenkins/osx_gcc_openssl.sh" ] + then + ./jenkins/osx_gcc_openssl.sh + fi + displayName: 'Build' + - script: | + cd cmake && ctest -T test --no-compress-output -C "Debug" -V -j 8 --schedule-random + displayName: "Run Tests" env: IOTHUB_CONNECTION_STRING: $(IOTHUB-CONNECTION-STRING) IOTHUB_EVENTHUB_CONNECTION_STRING: $(IOTHUB-EVENTHUB-CONNECTION-STRING) @@ -384,12 +507,13 @@ jobs: IOTHUB_CONN_STRING_INVALIDCERT: $(IOTHUB-CONN-STRING-INVALIDCERT) DPS_GLOBALDEVICEENDPOINT_INVALIDCERT: $(DPS-GLOBALDEVICEENDPOINT-INVALIDCERT) PROVISIONING_CONNECTION_STRING_INVALIDCERT: $(PROVISIONING-CONNECTION-STRING-INVALIDCERT) - - script: cd .. && rd /Q /S $(Agent.BuildDirectory)\s - displayName: 'cleanup' + - task: ComponentGovernanceComponentDetection@0 + displayName: 'Component Detection' condition: always() - job: xcodenative + displayName: XCode Native pool: - name: OSX + vmImage: 'macOS-13' steps: - script: | if [ -f "jenkins/osx_xcode_native.sh" ] @@ -397,7 +521,11 @@ jobs: DYLD_LIBRARY_PATH=/usr/local/Cellar/curl/7.61.0/lib ./jenkins/osx_xcode_native.sh fi - displayName: 'build' + displayName: 'Build' + - script: | + export DYLD_LIBRARY_PATH=/usr/local/Cellar/curl/7.61.0/lib + cd cmake && ctest -T test --no-compress-output -C "Debug" -V -j $TEST_JOB_COUNT --schedule-random + displayName: "Run Tests" env: IOTHUB_CONNECTION_STRING: $(IOTHUB-CONNECTION-STRING) IOTHUB_EVENTHUB_CONNECTION_STRING: $(IOTHUB-EVENTHUB-CONNECTION-STRING) @@ -416,6 +544,26 @@ jobs: IOTHUB_CONN_STRING_INVALIDCERT: $(IOTHUB-CONN-STRING-INVALIDCERT) DPS_GLOBALDEVICEENDPOINT_INVALIDCERT: $(DPS-GLOBALDEVICEENDPOINT-INVALIDCERT) PROVISIONING_CONNECTION_STRING_INVALIDCERT: $(PROVISIONING-CONNECTION-STRING-INVALIDCERT) - - script: rm -rf $(Agent.BuildDirectory)/* - displayName: 'cleanup' - condition: always() + - task: ComponentGovernanceComponentDetection@0 + displayName: 'Component Detection' +- job: raspberrypi + displayName: Raspberry Pi + container: raspberrypi-c-buster + pool: + name: 'sdk-c--ubuntu-22' + steps: + - script: | + chmod +x jenkins/raspberrypi_c_buster.sh + ./jenkins/raspberrypi_c_buster.sh + displayName: 'Build' +- job: DotNET + displayName: .NET + variables: + CodeQL.Enabled: true + CodeQL.Language: csharp + pool: + vmImage: 'windows-latest' + steps: + - script: | + dotnet build testtools\SerialPort\SerialPort.sln + displayName: 'Build' diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/build_all/linux/run_tests.sh b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/build_all/linux/run_tests.sh new file mode 100644 index 000000000..41835338c --- /dev/null +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/build_all/linux/run_tests.sh @@ -0,0 +1,16 @@ +#! /bin/bash + +# Copyright (c) Microsoft. All rights reserved. +# Licensed under the MIT license. See LICENSE file in the project root for full license information. + +set -o errexit # Exit if command failed. +set -o pipefail # Exit if pipe failed. + +# Only for testing E2E behaviour !!! +TEST_CORES=16 + +# Refresh dynamic libs to link to +sudo ldconfig + +ctest -T test --no-compress-output -C "Debug" -V -j $TEST_CORES --schedule-random + diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/build_all/windows/build.cmd b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/build_all/windows/build.cmd index ba8219156..f3f0540cc 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/build_all/windows/build.cmd +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/build_all/windows/build.cmd @@ -97,6 +97,17 @@ rem no error checking pushd %build-root%\cmake\%CMAKE_DIR% +call %build-root%\jenkins\windows_c_VsDevCmd.cmd %build-platform% + +echo ***checking msbuild*** +where /q msbuild + +where msbuild +IF ERRORLEVEL 1 ( + echo ERROR: msbuild not found!!! + goto :eof +) + if %MAKE_NUGET_PKG% == yes ( echo ***Running CMAKE for Win32 *** cmake %build-root% @@ -120,19 +131,19 @@ if %MAKE_NUGET_PKG% == yes ( ) mkdir %build-root%\cmake\shared-util_arm pushd %build-root%\cmake\shared-util_arm - cmake %build-root% -G "Visual Studio 15 2017" -A ARM + cmake %build-root% -A ARM if not !ERRORLEVEL!==0 exit /b !ERRORLEVEL! ) else if %build-platform% == Win32 ( echo ***Running CMAKE for Win32*** - cmake %build-root% -G "Visual Studio 15 2017" -A Win32 -Drun_unittests:bool=ON -Duse_wsio:bool=ON -Drun_int_tests=ON + cmake %build-root% -A Win32 -Drun_unittests:bool=ON -Duse_wsio:bool=ON -Drun_int_tests=ON -G %VSVERSION% if not !ERRORLEVEL!==0 exit /b !ERRORLEVEL! ) else if %build-platform% == ARM ( echo ***Running CMAKE for ARM*** - cmake %build-root% -G "Visual Studio 15 2017" -A ARM -Drun_unittests:bool=ON -Drun_int_tests=ON + cmake %build-root% -A ARM -Drun_unittests:bool=ON -Drun_int_tests=ON -G %VSVERSION% if not !ERRORLEVEL!==0 exit /b !ERRORLEVEL! ) else ( echo ***Running CMAKE for Win64*** - cmake %build-root% -G "Visual Studio 15 2017" -A x64 -Drun_unittests:bool=ON -Drun_int_tests=ON -Duse_cppunittest=ON + cmake %build-root% -A x64 -Drun_unittests:bool=ON -Drun_int_tests=ON -G %VSVERSION% if not !ERRORLEVEL!==0 exit /b !ERRORLEVEL! ) @@ -161,9 +172,6 @@ if %MAKE_NUGET_PKG% == yes ( msbuild /m %SOLUTION_NAME%.sln /p:Configuration=%build-config% if not !ERRORLEVEL!==0 exit /b !ERRORLEVEL! ) - - ctest -C "debug" -V - if not !ERRORLEVEL!==0 exit /b !ERRORLEVEL! ) popd diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/configs/azure_c_shared_utilityConfig.cmake b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/configs/azure_c_shared_utilityConfig.cmake index 416dd1cc4..2d7c733e0 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/configs/azure_c_shared_utilityConfig.cmake +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/configs/azure_c_shared_utilityConfig.cmake @@ -2,8 +2,10 @@ #Licensed under the MIT license. See LICENSE file in the project root for full license information. if(UNIX) - include(CMakeFindDependencyMacro) - find_dependency(CURL) + if(${use_http}) + include(CMakeFindDependencyMacro) + find_dependency(CURL) + endif() endif() include("${CMAKE_CURRENT_LIST_DIR}/azure_c_shared_utilityTargets.cmake") diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/configs/azure_c_shared_utilityFunctions.cmake b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/configs/azure_c_shared_utilityFunctions.cmake index 818fc8a9a..9b6e1d1cd 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/configs/azure_c_shared_utilityFunctions.cmake +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/configs/azure_c_shared_utilityFunctions.cmake @@ -700,6 +700,7 @@ function(set_platform_files c_shared_dir) set(SRW_LOCK_C_FILE ${c_shared_dir}/adapters/srw_lock.c PARENT_SCOPE) set(TIMER_C_FILE ${c_shared_dir}/adapters/timer.c PARENT_SCOPE) set(STRING_UTILS_C_FILE ${c_shared_dir}/adapters/string_utils.c PARENT_SCOPE) + set(RANDOM_C_FILE ${c_shared_dir}/adapters/random_stub.c PARENT_SCOPE) if (${use_builtin_httpapi}) set(HTTP_C_FILE ${c_shared_dir}/adapters/httpapi_compact.c PARENT_SCOPE) @@ -754,6 +755,12 @@ function(set_platform_files c_shared_dir) else() set(DNS_C_FILE ${c_shared_dir}/src/dns_resolver_sync.c PARENT_SCOPE) endif() + + if(UNIX AND NOT MACOSX) + set(RANDOM_C_FILE ${c_shared_dir}/adapters/random_posix.c PARENT_SCOPE) + else() + set(RANDOM_C_FILE ${c_shared_dir}/adapters/random_stub.c PARENT_SCOPE) + endif() endif() if(WIN32 OR MACOSX OR LINUX) diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/configs/azure_iot_build_rules.cmake b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/configs/azure_iot_build_rules.cmake index 63a75bcaf..a434da60b 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/configs/azure_iot_build_rules.cmake +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/configs/azure_iot_build_rules.cmake @@ -74,7 +74,8 @@ elseif(UNIX) #LINUX OR APPLE set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror") if(NOT (IN_OPENWRT OR APPLE)) - set (CMAKE_C_FLAGS "-D_POSIX_C_SOURCE=200112L ${CMAKE_C_FLAGS}") + # _XOPEN_SOURCE=500 is required for glibc to expose random and srandom. + set (CMAKE_C_FLAGS "-D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=500 ${CMAKE_C_FLAGS}") endif() endif() diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/deps/umock-c/deps/testrunner/tools/kick_jenkins.cmd b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/deps/umock-c/deps/testrunner/tools/kick_jenkins.cmd new file mode 100644 index 000000000..b96c1f4d4 --- /dev/null +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/deps/umock-c/deps/testrunner/tools/kick_jenkins.cmd @@ -0,0 +1,124 @@ +@REM Copyright (c) Microsoft. All rights reserved. +@REM Licensed under the MIT license. See LICENSE file in the project root for full license information. + +@setlocal EnableExtensions EnableDelayedExpansion +@echo off + +set current-path=%~dp0 + +rem // remove trailing slash +set current-path=%current-path:~0,-1% + +set build-root=%current-path%\.. +rem // resolve to fully qualified path +for %%i in ("%build-root%") do set build-root=%%~fi + +REM check that we have a valid argument +if "%1" equ "" ( + set jenkins_job=_integrate-into-develop +) else if /i "%1" equ "c" ( + set jenkins_job=_integrate-into-develop-c-and-wrappers +) else if /i "%1" equ "csharp" ( + set jenkins_job=_integrate-into-develop-csharp +) else if /i "%1" equ "java" ( + set jenkins_job=_integrate-into-develop-java +) else if /i "%1" equ "node" ( + set jenkins_job=_integrate-into-develop-node +) else ( + echo Usage: + echo kick_jenkins + echo or + echo "kick_jenkins c | csharp | java | node" + exit /b 1 +) + +REM check that we have java handy +call :checkExists java +if not !ERRORLEVEL!==0 exit /b !ERRORLEVEL! + +REM check that jenkins-cli.jar is in the repository's tools folder +if not exist %build-root%\tools\jenkins-cli.jar ( + echo jenkins-cli does not exist + echo Downloading from repository: + echo http://azure-iot-sdks-ci.westus.cloudapp.azure.com:8080/jnlpJars/jenkins-cli.jar + + powershell -Command "Invoke-WebRequest http://azure-iot-sdks-ci.westus.cloudapp.azure.com:8080/jnlpJars/jenkins-cli.jar -OutFile %build-root%\tools\jenkins-cli.jar" + + if not !ERRORLEVEL!==0 ( + echo Failed downloading jenkins-cli.jar + echo Use the following link to manually download it into the tools folder of your repository: + echo http://azure-iot-sdks-ci.westus.cloudapp.azure.com:8080/jnlpJars/jenkins-cli.jar + exit /b 1 + ) +) + +REM find current branch +for /f "usebackq tokens=*" %%i in (`git symbolic-ref -q HEAD`) do set "current_branch_ref=%%i" +if defined current_branch_ref set "current_branch=%current_branch_ref:refs/heads/=%" + +REM handle detached HEAD +if not defined current_branch ( + echo You're not on any branch! Aborting... + goto :eof +) + +REM Must be on a topic branch when running this script +set __exit=1 +if not "%current_branch%"=="master" if not "%current_branch%"=="develop" set __exit=0 +if %__exit%==1 ( + echo You cannot call this script from 'develop' or 'master'. Change to a topic branch first. Aborting... + goto :eof +) + +REM find tracking branch +for /f "usebackq tokens=*" %%i in (`git rev-parse --symbolic-full-name --abbrev-ref @{u}`) do set "tracking_branch=%%i" +if not defined tracking_branch ( + echo Branch ^'%current_branch%^' is not tracking a remote branch! First try ^'git branch -u ^/^^' to set tracking info. Aborting... + goto :eof +) + +for /f "usebackq tokens=*" %%i in (`git config branch.%current_branch%.remote`) do set "remote=%%i" +if not defined remote ( + REM should never happen... + echo Cannot isolate remote name for tracking branch ^'%tracking_branch%^'! Aborting... + goto :eof +) + +REM get the tracking branch name only e.g., origin/topic -> topic +for /f "usebackq tokens=*" %%i in (`call echo %%tracking_branch:%remote%/^=%%`) do set "tracking_name=%%i" + +REM find repo url +for /f "usebackq tokens=*" %%i in (`git ls-remote --heads --get-url %remote%`) do set "repo_url=%%i" +if not defined repo_url ( + echo Cannot find the remote repository URL! Aborting... + goto :eof +) + +echo **************************************************************** +echo commit_id: %current_branch% +echo repo_url: %repo_url% +echo remote: %remote% +echo trackingN: %tracking_name% +echo jenkinJob: %jenkins_job% +echo **************************************************************** + + +REM kick off the build! +java -jar "%build-root%"\tools\jenkins-cli.jar -s http://azure-iot-sdks-ci.westus.cloudapp.azure.com:8080/ build %jenkins_job% -p COMMIT_ID=%tracking_name% -p AZURE_REPO=%repo_url% -p BRANCH_TO_MERGE_TO=develop -s -v + +rem ----------------------------------------------------------------------------- +rem -- done +rem ----------------------------------------------------------------------------- +goto :eof + +rem ----------------------------------------------------------------------------- +rem -- helper subroutines +rem ----------------------------------------------------------------------------- +:checkExists +where %~1 >nul 2>nul +if not !ERRORLEVEL!==0 ( + echo "%~1" not found. Please make sure that "%~1" is installed and available in the path. + exit /b !ERRORLEVEL! +) +goto :eof + diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/deps/umock-c/src/umocktypes_wcharptr.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/deps/umock-c/src/umocktypes_wcharptr.c index 3518277a0..dbce8b066 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/deps/umock-c/src/umocktypes_wcharptr.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/deps/umock-c/src/umocktypes_wcharptr.c @@ -44,9 +44,10 @@ char* umocktypes_stringify_wcharptr(const wchar_t** value) { /* Codes_SRS_UMOCKTYPES_WCHARPTR_01_002: [ umocktypes_stringify_wcharptr shall return a string containing the string representation of value, enclosed by quotes ("value"). ] */ const wchar_t* same_as_source = *value; + size_t num_characters; mbstate_t state; mbstate_t_init(&state); - size_t num_characters = wcsrtombs(NULL, &same_as_source, 0, &state); + num_characters = wcsrtombs(NULL, &same_as_source, 0, &state); if (num_characters == (size_t)(-1)) { UMOCK_LOG("failure to get the length of the string: %s", strerror(errno)); @@ -201,9 +202,10 @@ char* umocktypes_stringify_const_wcharptr(const wchar_t** value) { /* Codes_SRS_UMOCKTYPES_WCHARPTR_01_019: [ umocktypes_stringify_const_wcharptr shall return a string containing the string representation of value, enclosed by quotes ("value"). ] */ const wchar_t* same_as_source = *value; + size_t num_characters; mbstate_t state; mbstate_t_init(&state); - size_t num_characters = wcsrtombs(NULL, &same_as_source, 0, &state); + num_characters = wcsrtombs(NULL, &same_as_source, 0, &state); if (num_characters == (size_t)(-1)) { UMOCK_LOG("failure to get the length of the string: %s", strerror(errno)); diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/devdoc/http_proxy_io_requirements.md b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/devdoc/http_proxy_io_requirements.md index 8187024c0..8410874a2 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/devdoc/http_proxy_io_requirements.md +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/devdoc/http_proxy_io_requirements.md @@ -332,6 +332,7 @@ extern const IO_INTERFACE_DESCRIPTION* http_proxy_io_get_interface_description(v except not limited to 76 char/line> user-pass = userid ":" password userid = * +[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Not a password")] password = *TEXT **SRS_HTTP_PROXY_IO_01_093: [** Userids might be case sensitive. **]** diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/devdoc/porting_guide.md b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/devdoc/porting_guide.md index 58b0d5cd9..59c353708 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/devdoc/porting_guide.md +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/devdoc/porting_guide.md @@ -254,7 +254,7 @@ _Chained_ adapter implementations include: - [tlsio_openssl for Windows, Linux, and Mac](https://github.com/Azure/azure-c-shared-utility/blob/master/adapters/tlsio_openssl.c) - [tlsio_schannel for Windows only](https://github.com/Azure/azure-c-shared-utility/blob/master/adapters/tlsio_schannel.c) - [tlsio_wolfssl for embedded devices](https://github.com/Azure/azure-c-shared-utility/blob/master/adapters/tlsio_wolfssl.c) -- [tlsio_mbedtls for mbed](https://github.com/Azure/azure-c-shared-utility/blob/master/adapters/tlsio_mbedtls.c) +- [tlsio_mbedtls for embedded devices](https://github.com/Azure/azure-c-shared-utility/blob/master/adapters/tlsio_mbedtls.c) #### Existing socketio implementations for _chained_ tlsio adapters There is no spec for socketio adapters, so it is necessary to copy the behavior of an existing one, and @@ -265,7 +265,6 @@ purge their pending io lists during socketio_destroy, which is incorrect. The pe lists should be purged during socketio_close instead. - [socketio_berkeley for Linux, easily adapted to any Berkeley socket](https://github.com/Azure/azure-c-shared-utility/blob/master/adapters/socketio_berkeley.c) - [socketio_win32 for Windows](https://github.com/Azure/azure-c-shared-utility/blob/master/adapters/socketio_win32.c) -- [socketio_mbed for mbed](https://github.com/Azure/azure-c-shared-utility/blob/master/adapters/socketio_mbed.c) - [tlsio_cyclonessl_socket for use with cyclonessl](https://github.com/Azure/azure-c-shared-utility/blob/master/src/tlsio_cyclonessl_socket.c) ### Adding device support repositories diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/devdoc/sastoken_requirements.md b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/devdoc/sastoken_requirements.md index 94b1aa684..7893fd48e 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/devdoc/sastoken_requirements.md +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/devdoc/sastoken_requirements.md @@ -7,7 +7,7 @@ This function is used to create a SAS token. ## References [Keyed-Hashing for Message Authentication, RFC2104](https://www.ietf.org/rfc/rfc2104.txt) -[SASToken format](https://azure.microsoft.com/en-us/documentation/articles/storage-dotnet-shared-access-signature-part-1/) +[SASToken format](https://azure.microsoft.com/documentation/articles/storage-dotnet-shared-access-signature-part-1/) ## Exposed API diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/devdoc/uws_frame_encoder_requirements.md b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/devdoc/uws_frame_encoder_requirements.md index f74395dcd..5b136ad20 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/devdoc/uws_frame_encoder_requirements.md +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/devdoc/uws_frame_encoder_requirements.md @@ -64,7 +64,7 @@ extern int uws_frame_encoder_encode(BUFFER_HANDLE encode_buffer, WS_FRAME_TYPE o **SRS_UWS_FRAME_ENCODER_01_052: [** If `reserved` has any bits set except the lowest 3 then `uws_frame_encoder_encode` shall fail and return NULL. **]** -**SRS_UWS_FRAME_ENCODER_01_053: [** In order to obtain a 32 bit value for masking, `gb_rand` shall be used 4 times (for each byte). **]** +**SRS_UWS_FRAME_ENCODER_01_053: [** In order to obtain a 32 bit value for masking, `RANDOM_generate` shall be used 4 times (for each byte). **]** ### RFC6455 relevant parts diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/inc/azure_c_shared_utility/random.h b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/inc/azure_c_shared_utility/random.h new file mode 100644 index 000000000..1ea9fb502 --- /dev/null +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/inc/azure_c_shared_utility/random.h @@ -0,0 +1,20 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +#ifndef RANDOM_H +#define RANDOM_H + +#include "umock_c/umock_c_prod.h" + +#ifdef __cplusplus +extern "C" { +#endif + +MOCKABLE_FUNCTION(, void, RANDOM_seed, unsigned int, seed); +MOCKABLE_FUNCTION(, int, RANDOM_generate); + +#ifdef __cplusplus +} +#endif + +#endif /* RANDOM_H */ diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/inc/azure_c_shared_utility/refcount.h b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/inc/azure_c_shared_utility/refcount.h index dc8bf00d1..cb548aab7 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/inc/azure_c_shared_utility/refcount.h +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/inc/azure_c_shared_utility/refcount.h @@ -57,7 +57,16 @@ MU_C2(REFCOUNT_, type) #define DEFINE_CREATE_WITH_EXTRA_SIZE(type) \ static type* REFCOUNT_TYPE_DECLARE_CREATE_WITH_EXTRA_SIZE(type)(size_t size) \ { \ - REFCOUNT_TYPE(type)* ref_counted = (REFCOUNT_TYPE(type)*)malloc(sizeof(REFCOUNT_TYPE(type)) + size); \ + REFCOUNT_TYPE(type)* ref_counted; \ + size_t malloc_size = sizeof(REFCOUNT_TYPE(type)) + size; \ + if (malloc_size < size) \ + { \ + ref_counted = NULL; \ + } \ + else \ + { \ + ref_counted = (REFCOUNT_TYPE(type)*)malloc(malloc_size); \ + } \ type* result; \ if (ref_counted == NULL) \ { \ diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/inc/azure_c_shared_utility/safe_math.h b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/inc/azure_c_shared_utility/safe_math.h index cf8198d69..d76f7da81 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/inc/azure_c_shared_utility/safe_math.h +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/inc/azure_c_shared_utility/safe_math.h @@ -14,4 +14,4 @@ #define safe_multiply_size_t(a, b) (((a) == 0 || (b) == 0) ? 0 : (((SIZE_MAX / (size_t)(a)) >= (size_t)(b)) ? (size_t)(a) * (size_t)(b) : SIZE_MAX)) -#endif // SAFE_MATH_H \ No newline at end of file +#endif // SAFE_MATH_H diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/inc/azure_c_shared_utility/x509_openssl.h b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/inc/azure_c_shared_utility/x509_openssl.h index 28c2e7b04..a2f3cb41c 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/inc/azure_c_shared_utility/x509_openssl.h +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/inc/azure_c_shared_utility/x509_openssl.h @@ -14,7 +14,11 @@ extern "C" { #include "umock_c/umock_c_prod.h" MOCKABLE_FUNCTION(,int, x509_openssl_add_certificates, SSL_CTX*, ssl_ctx, const char*, certificates); +#ifndef OPENSSL_NO_ENGINE MOCKABLE_FUNCTION(,int, x509_openssl_add_credentials, SSL_CTX*, ssl_ctx, const char*, x509certificate, const char*, x509privatekey, OPTION_OPENSSL_KEY_TYPE, x509privatekeytype, ENGINE*, engine); +#else // OPENSSL_NO_ENGINE +MOCKABLE_FUNCTION(,int, x509_openssl_add_credentials, SSL_CTX*, ssl_ctx, const char*, x509certificate, const char*, x509privatekey, OPTION_OPENSSL_KEY_TYPE, x509privatekeytype); +#endif // OPENSSL_NO_ENGINE #ifdef __cplusplus } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/inc/azure_c_shared_utility/xlogging.h b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/inc/azure_c_shared_utility/xlogging.h index a38a9b5d9..f64c3f969 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/inc/azure_c_shared_utility/xlogging.h +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/inc/azure_c_shared_utility/xlogging.h @@ -29,11 +29,7 @@ #ifdef __cplusplus /* Some compilers do not want to play by the standard, specifically ARM CC */ -#ifdef MBED_BUILD_TIMESTAMP -#include -#else #include -#endif #else #include #endif /* __cplusplus */ @@ -140,9 +136,11 @@ typedef void(*LOGGER_LOG_GETLASTERROR)(const char* file, const char* func, int l } \ else \ { \ + char* formatWithStack; \ size_t formatSize = strlen(format); \ - char* formatWithStack = (char*)logging_malloc(formatSize + sizeof("STACK_PRINT_FORMAT")); \ - if (formatWithStack == NULL) \ + size_t mallocSize = formatSize + sizeof("STACK_PRINT_FORMAT"); \ + if (mallocSize < formatSize || /* int overflow check */ \ + (formatWithStack = (char*)logging_malloc(mallocSize)) == NULL) \ { \ l(log_category, __FILE__, FUNC_NAME, __LINE__, log_options, format, __VA_ARGS__); \ } \ diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/debian_c.sh b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/debian_c.sh index db10c2992..383752634 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/debian_c.sh +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/debian_c.sh @@ -7,7 +7,7 @@ set -e build_root=$(cd "$(dirname "$0")/.." && pwd) cd $build_root -build_folder=$build_root"/cmake/shared-util_linux" +build_folder=$build_root"/cmake" # Set the default cores CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu) @@ -18,9 +18,4 @@ pushd $build_folder cmake -Drun_valgrind:BOOL=ON $build_root -Drun_unittests:BOOL=ON make --jobs=$CORES -#use doctored openssl -export LD_LIBRARY_PATH=/usr/local/ssl/lib -ctest -j $CORES --output-on-failure -export LD_LIBRARY_PATH= - popd diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/linux_bearssl.sh b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/linux_bearssl.sh index b060950ba..b58864c69 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/linux_bearssl.sh +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/linux_bearssl.sh @@ -11,7 +11,7 @@ curl --version # Set the default cores CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu) -cmake . -Bcmake -Duse_bearssl:BOOL=ON -Drun_unittests:BOOL=ON -Duse_openssl:BOOL=OFF +cmake . -Bcmake -Duse_bearssl:BOOL=ON -Drun_unittests:BOOL=ON -Duse_openssl:BOOL=OFF -D CMAKE_C_COMPILER=gcc cd cmake make --jobs=$CORES diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/linux_bearssl_clang_buildonly.sh b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/linux_bearssl_clang_buildonly.sh new file mode 100644 index 000000000..a11f01a77 --- /dev/null +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/linux_bearssl_clang_buildonly.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# Copyright (c) Microsoft. All rights reserved. +# Licensed under the MIT license. See LICENSE file in the project root for full license information. + +set -e + +# Print version +cat /etc/*release | grep VERSION* +gcc --version +curl --version + +# Set the default cores +CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu) +cmake . -Bcmake -Duse_bearssl:BOOL=ON -Drun_unittests:BOOL=ON -Duse_openssl:BOOL=OFF -D CMAKE_C_COMPILER=clang -D CMAKE_CXX_COMPILER=clang++ +cd cmake + +make --jobs=$CORES + diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/linux_c_option_test.sh b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/linux_c_option_test.sh new file mode 100644 index 000000000..436a2aac3 --- /dev/null +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/linux_c_option_test.sh @@ -0,0 +1,59 @@ +#!/bin/bash +#set -o pipefail +# +# Copyright (c) Microsoft. All rights reserved. +# Licensed under the MIT license. See LICENSE file in the project root for full license information. + +set -e + +cat /etc/*release | grep VERSION* +gcc --version +openssl version + +script_dir=$(cd "$(dirname "$0")" && pwd) +build_root=$(cd "${script_dir}/.." && pwd) +build_folder=$build_root"/cmake" + +# Set the default cores +MAKE_CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu) + +echo "Initial MAKE_CORES=$MAKE_CORES" + +# Make sure there is enough virtual memory on the device to handle more than one job +MINVSPACE="1500000" + +# Acquire total memory and total swap space setting them to zero in the event the command fails +MEMAR=( $(sed -n -e 's/^MemTotal:[^0-9]*\([0-9][0-9]*\).*/\1/p' -e 's/^SwapTotal:[^0-9]*\([0-9][0-9]*\).*/\1/p' /proc/meminfo) ) +[ -z "${MEMAR[0]##*[!0-9]*}" ] && MEMAR[0]=0 +[ -z "${MEMAR[1]##*[!0-9]*}" ] && MEMAR[1]=0 + +let VSPACE=${MEMAR[0]}+${MEMAR[1]} + +if [ "$VSPACE" -lt "$MINVSPACE" ] ; then +echo "WARNING: Not enough space. Setting MAKE_CORES=1" +MAKE_CORES=1 +fi + +declare -a arr=( + "-Dskip_samples=ON" + "-Dno_logging=ON" + "-Denable_raw_logging=ON" + "-Denable_raw_logging=ON -Dno_logging=ON" + "-Duse_builtin_httpapi=ON" + "-Duse_default_uuid=ON" + "-Dno_openssl_engine=ON" + "-Duse_http=OFF" +) + +for item in "${arr[@]}" +do + rm -r -f $build_folder + mkdir -p $build_folder + pushd $build_folder + + echo "executing cmake/make with options <<$item>>" + cmake $build_root "$item" + + make --jobs=$MAKE_CORES +done +popd diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/linux_cares.sh b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/linux_cares.sh new file mode 100644 index 000000000..8ad872b2d --- /dev/null +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/linux_cares.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# Copyright (c) Microsoft. All rights reserved. +# Licensed under the MIT license. See LICENSE file in the project root for full license information. + +set -x # Set trace on +set -o errexit # Exit if command failed +set -o nounset # Exit if variable not set +set -o pipefail # Exit if pipe failed + +# Print version +cat /etc/*release | grep VERSION* +gcc --version +curl --version + +# Set the default cores +CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu) +cmake . -Bcmake -Duse_c_ares:BOOL=ON -Drun_e2e_tests:BOOL=ON +cd cmake + +make --jobs=$CORES diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/linux_install_deps.sh b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/linux_install_deps.sh index 1bc10932a..10aea8994 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/linux_install_deps.sh +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/linux_install_deps.sh @@ -17,7 +17,7 @@ cd $build_root echo "Build Root $build_root" -sdk_build_folder=$build_root"/cmake/install_deps" +sdk_build_folder=$build_root"/cmake" # Build the SDK rm -rf $sdk_build_folder diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/linux_mbed.sh b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/linux_mbed.sh index 99af72dac..541f7dc29 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/linux_mbed.sh +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/linux_mbed.sh @@ -7,7 +7,7 @@ set -e build_root=$(cd "$(dirname "$0")/.." && pwd) cd $build_root -build_folder=$build_root"/cmake/shared-util_linux" +build_folder=$build_root"/cmake" # Set the default cores CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu) @@ -15,7 +15,7 @@ CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu) rm -r -f $build_folder mkdir -p $build_folder pushd $build_folder -cmake -Drun_valgrind:BOOL=ON -Duse_mbedtls=ON -Duse_openssl=OFF $build_root -Drun_unittests:BOOL=ON +cmake -Drun_valgrind:BOOL=ON -Duse_mbedtls=ON -Duse_openssl=OFF $build_root -Drun_unittests:BOOL=ON -D CMAKE_C_COMPILER=gcc -D CMAKE_CXX_COMPILER=g++ make --jobs=$CORES ctest -j $CORES --output-on-failure diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/linux_mbed_clang_buildonly.sh b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/linux_mbed_clang_buildonly.sh new file mode 100644 index 000000000..bdd6bbf43 --- /dev/null +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/linux_mbed_clang_buildonly.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# Copyright (c) Microsoft. All rights reserved. +# Licensed under the MIT license. See LICENSE file in the project root for full license information. + +set -e + +build_root=$(cd "$(dirname "$0")/.." && pwd) +cd $build_root + +build_folder=$build_root"/cmake" + +# Set the default cores +CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu) + +rm -r -f $build_folder +mkdir -p $build_folder +pushd $build_folder +cmake -Drun_valgrind:BOOL=ON -Duse_mbedtls=ON -Duse_openssl=OFF $build_root -Drun_unittests:BOOL=ON -D CMAKE_C_COMPILER=clang -D CMAKE_CXX_COMPILER=clang++ +make --jobs=$CORES + +popd diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/linux_wolfssl.sh b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/linux_wolfssl.sh index 8512b6f8b..e9f8539ad 100755 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/linux_wolfssl.sh +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/linux_wolfssl.sh @@ -7,7 +7,7 @@ set -e build_root=$(cd "$(dirname "$0")/.." && pwd) cd $build_root -build_folder=$build_root"/cmake/shared-util_linux" +build_folder=$build_root"/cmake" # Set the default cores CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu) @@ -15,7 +15,7 @@ CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu) rm -r -f $build_folder mkdir -p $build_folder pushd $build_folder -cmake $build_root -Drun_unittests:BOOL=ON -Duse_wolfssl:BOOL=ON -Duse_openssl:BOOL=OFF +cmake $build_root -Drun_unittests:BOOL=ON -Duse_wolfssl:BOOL=ON -Duse_openssl:BOOL=OFF -D CMAKE_C_COMPILER=gcc make --jobs=$CORES #use doctored openssl diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/linux_wolfssl_clang_buildonly.sh b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/linux_wolfssl_clang_buildonly.sh new file mode 100644 index 000000000..c26f25372 --- /dev/null +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/linux_wolfssl_clang_buildonly.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# Copyright (c) Microsoft. All rights reserved. +# Licensed under the MIT license. See LICENSE file in the project root for full license information. + +set -e + +build_root=$(cd "$(dirname "$0")/.." && pwd) +cd $build_root + +build_folder=$build_root"/cmake" + +# Set the default cores +CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu) + +rm -r -f $build_folder +mkdir -p $build_folder +pushd $build_folder +cmake $build_root -Drun_unittests:BOOL=ON -Duse_wolfssl:BOOL=ON -Duse_openssl:BOOL=OFF -D CMAKE_C_COMPILER=clang -D CMAKE_CXX_COMPILER=clang++ +make --jobs=$CORES + +popd diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/osx_gcc_openssl.sh b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/osx_gcc_openssl.sh index 98c5f5df8..8019c160c 100755 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/osx_gcc_openssl.sh +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/osx_gcc_openssl.sh @@ -16,5 +16,3 @@ mkdir -p $build_folder pushd $build_folder cmake .. -DOPENSSL_ROOT_DIR:PATH=/usr/local/opt/openssl -Duse_openssl:bool=ON -Drun_unittests:bool=ON cmake --build . -- --jobs=$CORES -ctest -C "debug" -V -popd diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/raspberrypi_c.sh b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/raspberrypi_c.sh index efcadea91..88d98dcfc 100755 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/raspberrypi_c.sh +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/raspberrypi_c.sh @@ -75,7 +75,7 @@ SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) EOM -build_folder=$build_root"/cmake/shared-util_linux" +build_folder=$build_root"/cmake" # Set the default cores CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu) diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/ubuntu_c.sh b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/ubuntu_c.sh new file mode 100644 index 000000000..d2a2de49f --- /dev/null +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/ubuntu_c.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# Copyright (c) Microsoft. All rights reserved. +# Licensed under the MIT license. See LICENSE file in the project root for full license information. + +set -e + +build_root=$(cd "$(dirname "$0")/.." && pwd) +cd $build_root + +build_folder=$build_root"/cmake" + +# Set the default cores +CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu) + +rm -r -f $build_folder +mkdir -p $build_folder +pushd $build_folder +cmake $build_root -Drun_unittests:BOOL=ON -Drun_valgrind:BOOL=ON +make --jobs=$CORES + +popd diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/ubuntu_clang.sh b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/ubuntu_clang.sh index 58ae9cb11..310b40b16 100755 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/ubuntu_clang.sh +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/ubuntu_clang.sh @@ -14,7 +14,6 @@ mkdir -p $build_folder pushd $build_folder cmake .. -Drun_valgrind:BOOL=ON -Drun_unittests:bool=ON cmake --build . -- --jobs=$(nproc) -ctest -C "debug" -V -j $(nproc) --output-on-failure popd : \ No newline at end of file diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/windows_c_VsDevCmd.cmd b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/windows_c_VsDevCmd.cmd new file mode 100644 index 000000000..8f6612707 --- /dev/null +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/jenkins/windows_c_VsDevCmd.cmd @@ -0,0 +1,27 @@ +@REM Copyright (c) Microsoft. All rights reserved. +@REM Licensed under the MIT license. See LICENSE file in the project root for full license information. + +echo ***setting VC paths*** +IF EXIST "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\VsMSBuildCmd.bat" ( + call "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\VsMSBuildCmd.bat" + set VSVERSION="Visual Studio 15 2017" +) ELSE IF EXIST "%ProgramFiles%\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\VsDevCmd.bat" ( + IF "%1" == "x64" ( + call "%ProgramFiles%\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\VsDevCmd.bat" -arch=amd64 + ) ELSE ( + call "%ProgramFiles%\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\VsDevCmd.bat" + ) + set VSVERSION="Visual Studio 17 2022" +) ELSE ( + echo "ERROR: Did not find Microsoft Visual Studio" + EXIT 1 +) + +where /q msbuild +IF ERRORLEVEL 1 ( + echo "ERROR: Did not find msbuild" + exit %ERRORLEVEL% +) + +where msbuild +msbuild -version diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/pal/ios-osx/tlsio_appleios.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/pal/ios-osx/tlsio_appleios.c index de308ac53..4fc5fbf82 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/pal/ios-osx/tlsio_appleios.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/pal/ios-osx/tlsio_appleios.c @@ -15,6 +15,7 @@ #include "azure_c_shared_utility/singlylinkedlist.h" #include "azure_c_shared_utility/crt_abstractions.h" #include "azure_c_shared_utility/tlsio_options.h" +#include "azure_c_shared_utility/safe_math.h" #include @@ -694,15 +695,16 @@ static int tlsio_appleios_send_async(CONCRETE_IO_HANDLE tls_io, const void* buff if (strncmp((const char*)buffer, WEBSOCKET_HEADER_START, WEBSOCKET_HEADER_START_SIZE) == 0) { add_no_cert_url_parameter = true; - size += WEBSOCKET_HEADER_NO_CERT_PARAM_SIZE; + size = safe_add_size_t(size, WEBSOCKET_HEADER_NO_CERT_PARAM_SIZE); } } /* Codes_SRS_TLSIO_30_063: [ The tlsio_appleios_compact_send shall enqueue for transmission the on_send_complete, the callback_context, the size, and the contents of buffer. ]*/ - if ((pending_transmission->bytes = (unsigned char*)malloc(size)) == NULL) + if (size == SIZE_MAX || + (pending_transmission->bytes = (unsigned char*)malloc(size)) == NULL) { /* Codes_SRS_TLSIO_30_064: [ If the supplied message cannot be enqueued for transmission, tlsio_appleios_compact_send shall log an error and return FAILURE. ]*/ - LogError("malloc failed"); + LogError("malloc failed, size:%zu", size); free(pending_transmission); result = MU_FAILURE; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/pal/tlsio_options.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/pal/tlsio_options.c index a802b6129..d75942e9f 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/pal/tlsio_options.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/pal/tlsio_options.c @@ -61,6 +61,9 @@ void tlsio_options_release_resources(TLSIO_OPTIONS* options) free((void*)options->trusted_certs); free((void*)options->x509_cert); free((void*)options->x509_key); + options->trusted_certs = NULL; + options->x509_cert = NULL; + options->x509_key = NULL; } else { diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/aziotsharedutil.def b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/aziotsharedutil.def index 9e778dbde..e2391bb3d 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/aziotsharedutil.def +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/aziotsharedutil.def @@ -129,6 +129,8 @@ EXPORTS STRING_quote STRING_sprintf STRING_replace + RANDOM_seed + RANDOM_generate THREADAPI_RESULTStringStorage THREADAPI_RESULTStrings THREADAPI_RESULT_FromString @@ -174,7 +176,6 @@ EXPORTS connectionstringparser_splitHostName_from_char consolelogger_log consolelogger_log_with_GetLastError - gb_rand gballoc_calloc gballoc_deinit gballoc_free diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/azure_base32.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/azure_base32.c index c47ca6e43..08de53922 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/azure_base32.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/azure_base32.c @@ -8,6 +8,7 @@ #include "azure_c_shared_utility/xlogging.h" #include "azure_c_shared_utility/gballoc.h" #include "azure_c_shared_utility/strings.h" +#include "azure_c_shared_utility/safe_math.h" #include "azure_c_shared_utility/azure_base32.h" @@ -71,9 +72,14 @@ static char* base32_encode_impl(const unsigned char* source, size_t src_size) char* result; // Allocate target buffer - size_t output_len = base32_encoding_length(src_size); + size_t output_len = safe_add_size_t(base32_encoding_length(src_size), 1); + if (output_len == SIZE_MAX) + { + result = NULL; + LogError("invalid src_size"); + } /* Codes_SRS_BASE32_07_009: [ base32_encode_impl shall allocate the buffer to the size of the encoding value. ] */ - if ((result = (char*)malloc(output_len + 1)) == NULL) + else if ((result = (char*)malloc(output_len)) == NULL) { LogError("Failure allocating output buffer"); } @@ -91,11 +97,11 @@ static char* base32_encode_impl(const unsigned char* source, size_t src_size) unsigned char pos7 = 0; unsigned char pos8 = 0; - memset(result, 0, output_len + 1); + memset(result, 0, output_len); // Go through the source buffer sectioning off blocks of 5 /* Codes_SRS_BASE32_07_010: [ base32_encode_impl shall look through source and separate each block into 5 bit chunks ] */ - while (src_size >= 1 && result != NULL) + while (src_size >= 1) { pos1 = pos2 = pos3 = pos4 = pos5 = pos6 = pos7 = pos8 = 0; block_len = src_size > TARGET_BLOCK_SIZE ? TARGET_BLOCK_SIZE : src_size; @@ -141,6 +147,14 @@ static char* base32_encode_impl(const unsigned char* source, size_t src_size) break; } + if ((result_len + 8) > output_len) + { + LogError("result buffer is too small"); + free(result); + result = NULL; + break; + } + /* Codes_SRS_BASE32_07_011: [ base32_encode_impl shall then map the 5 bit chunks into one of the BASE32 values (a-z,2,3,4,5,6,7) values. ] */ result[result_len++] = BASE32_VALUES[pos1]; result[result_len++] = BASE32_VALUES[pos2]; diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/azure_base64.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/azure_base64.c index c9ba63fce..1e8adfaf7 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/azure_base64.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/azure_base64.c @@ -6,6 +6,7 @@ #include "azure_c_shared_utility/gballoc.h" #include "azure_c_shared_utility/azure_base64.h" #include "azure_c_shared_utility/xlogging.h" +#include "azure_c_shared_utility/safe_math.h" #define splitInt(intVal, bytePos) (char)((intVal >> (bytePos << 3)) & 0xFF) @@ -236,13 +237,19 @@ static STRING_HANDLE Base64_Encode_Internal(const unsigned char* source, size_t { STRING_HANDLE result; size_t neededSize = 0; + bool isBufferOverflow = false; char* encoded; size_t currentPosition = 0; - neededSize += (size == 0) ? (0) : ((((size - 1) / 3) + 1) * 4); - neededSize += 1; /*+1 because \0 at the end of the string*/ + neededSize = safe_add_size_t(neededSize, (size == 0) ? (0) : safe_multiply_size_t(safe_add_size_t(((safe_subtract_size_t(size, 1)) / 3), 1), 4)); + neededSize = safe_add_size_t(neededSize, 1); /*+1 because \0 at the end of the string*/ + + if (neededSize == 0 || neededSize == SIZE_MAX) + { + result = NULL; + LogError("Azure_Base64_Encode:: Invalid size parameter, neededSize:%zu.", neededSize); + } /*Codes_SRS_BASE64_06_006: [If when allocating memory to produce the encoding a failure occurs then Azure_Base64_Encode shall return NULL.]*/ - encoded = (char*)malloc(neededSize); - if (encoded == NULL) + else if ((encoded = (char*)malloc(neededSize)) == NULL) { result = NULL; LogError("Azure_Base64_Encode:: Allocation failed."); @@ -270,43 +277,87 @@ static STRING_HANDLE Base64_Encode_Internal(const unsigned char* source, size_t source[currentPosition + 2] & 0x3F ); currentPosition += 3; + + if ((destinationPosition + 4) > neededSize) + { + LogError("Azure_Base64_Encode:: Invalid buffer size."); + isBufferOverflow = true; + break; + } encoded[destinationPosition++] = c1; encoded[destinationPosition++] = c2; encoded[destinationPosition++] = c3; encoded[destinationPosition++] = c4; } - if (size - currentPosition == 2) + + if (!isBufferOverflow && size - currentPosition == 2) { - char c1 = base64char(source[currentPosition] >> 2); - char c2 = base64char( - ((source[currentPosition] & 0x03) << 4) | + if ((destinationPosition + 4) > neededSize) + { + LogError("Azure_Base64_Encode:: Invalid buffer size."); + isBufferOverflow = true; + } + else + { + char c1 = base64char(source[currentPosition] >> 2); + char c2 = base64char( + ((source[currentPosition] & 0x03) << 4) | (source[currentPosition + 1] >> 4) - ); - char c3 = base64b16(source[currentPosition + 1] & 0x0F); - encoded[destinationPosition++] = c1; - encoded[destinationPosition++] = c2; - encoded[destinationPosition++] = c3; - encoded[destinationPosition++] = '='; + ); + char c3 = base64b16(source[currentPosition + 1] & 0x0F); + encoded[destinationPosition++] = c1; + encoded[destinationPosition++] = c2; + encoded[destinationPosition++] = c3; + encoded[destinationPosition++] = '='; + } } - else if (size - currentPosition == 1) + else if (!isBufferOverflow && size - currentPosition == 1) { - char c1 = base64char(source[currentPosition] >> 2); - char c2 = base64b8(source[currentPosition] & 0x03); - encoded[destinationPosition++] = c1; - encoded[destinationPosition++] = c2; - encoded[destinationPosition++] = '='; - encoded[destinationPosition++] = '='; + if ((destinationPosition + 4) > neededSize) + { + LogError("Azure_Base64_Encode:: Invalid buffer size."); + isBufferOverflow = true; + } + else + { + char c1 = base64char(source[currentPosition] >> 2); + char c2 = base64b8(source[currentPosition] & 0x03); + encoded[destinationPosition++] = c1; + encoded[destinationPosition++] = c2; + encoded[destinationPosition++] = '='; + encoded[destinationPosition++] = '='; + } } /*null terminating the string*/ - encoded[destinationPosition] = '\0'; - /*Codes_SRS_BASE64_06_007: [Otherwise Azure_Base64_Encode shall return a pointer to STRING, that string contains the base 64 encoding of input.]*/ - result = STRING_new_with_memory(encoded); - if (result == NULL) + if (!isBufferOverflow) + { + if ((destinationPosition + 1) > neededSize) + { + LogError("Azure_Base64_Encode:: Invalid buffer size."); + isBufferOverflow = true; + } + else + { + encoded[destinationPosition] = '\0'; + } + } + + if (isBufferOverflow) { free(encoded); - LogError("Azure_Base64_Encode:: Allocation failed for return value."); + result = NULL; + } + else + { + /*Codes_SRS_BASE64_06_007: [Otherwise Azure_Base64_Encode shall return a pointer to STRING, that string contains the base 64 encoding of input.]*/ + result = STRING_new_with_memory(encoded); + if (result == NULL) + { + free(encoded); + LogError("Azure_Base64_Encode:: Allocation failed for return value."); + } } } return result; diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/buffer.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/buffer.c index ffd1dbea4..845994281 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/buffer.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/buffer.c @@ -8,6 +8,7 @@ #include "azure_c_shared_utility/buffer_.h" #include "azure_c_shared_utility/optimize_size.h" #include "azure_c_shared_utility/xlogging.h" +#include "azure_c_shared_utility/safe_math.h" typedef struct BUFFER_TAG { @@ -210,7 +211,7 @@ int BUFFER_append_build(BUFFER_HANDLE handle, const unsigned char* source, size_ if (handle->buffer == NULL) { /* Codes_SRS_BUFFER_07_030: [ if handle->buffer is NULL BUFFER_append_build shall allocate the a buffer of size bytes... ] */ - if (BUFFER_safemalloc(handle, size) != 0) + if (BUFFER_safemalloc(handle, size) != 0 || handle->buffer == NULL) { /* Codes_SRS_BUFFER_07_035: [ If any error is encountered BUFFER_append_build shall return a non-null value. ] */ LogError("Failure with BUFFER_safemalloc"); @@ -227,11 +228,13 @@ int BUFFER_append_build(BUFFER_HANDLE handle, const unsigned char* source, size_ else { /* Codes_SRS_BUFFER_07_032: [ if handle->buffer is not NULL BUFFER_append_build shall realloc the buffer to be the handle->size + size ] */ - unsigned char* temp = (unsigned char*)realloc(handle->buffer, handle->size + size); - if (temp == NULL) + unsigned char* temp; + size_t malloc_size = safe_add_size_t(handle->size, size); + if (malloc_size == SIZE_MAX || + (temp = (unsigned char*)realloc(handle->buffer, malloc_size)) == NULL) { /* Codes_SRS_BUFFER_07_035: [ If any error is encountered BUFFER_append_build shall return a non-null value. ] */ - LogError("Failure reallocating temporary buffer"); + LogError("Failure reallocating temporary buffer, size:%zu", malloc_size); result = MU_FAILURE; } else @@ -356,12 +359,14 @@ int BUFFER_enlarge(BUFFER_HANDLE handle, size_t enlargeSize) } else { + unsigned char* temp; BUFFER* b = (BUFFER*)handle; - unsigned char* temp = (unsigned char*)realloc(b->buffer, b->size + enlargeSize); - if (temp == NULL) + size_t malloc_size = safe_add_size_t(b->size, enlargeSize); + if (malloc_size == SIZE_MAX || + (temp = (unsigned char*)realloc(b->buffer, malloc_size)) == NULL) { /* Codes_SRS_BUFFER_07_018: [BUFFER_enlarge shall return a nonzero result if any error is encountered.] */ - LogError("Failure: allocating temp buffer."); + LogError("Failure: allocating temp buffer, size:%zu", malloc_size); result = MU_FAILURE; } else @@ -493,8 +498,10 @@ int BUFFER_append(BUFFER_HANDLE handle1, BUFFER_HANDLE handle2) else { // b2->size != 0, whatever b1->size is - unsigned char* temp = (unsigned char*)realloc(b1->buffer, b1->size + b2->size); - if (temp == NULL) + unsigned char* temp; + size_t malloc_size = safe_add_size_t(b1->size, b2->size); + if (malloc_size == SIZE_MAX || + (temp = (unsigned char*)realloc(b1->buffer, malloc_size)) == NULL) { /* Codes_SRS_BUFFER_07_023: [BUFFER_append shall return a nonzero upon any error that is encountered.] */ LogError("Failure: allocating temp buffer."); @@ -540,12 +547,13 @@ int BUFFER_prepend(BUFFER_HANDLE handle1, BUFFER_HANDLE handle2) else { //put b2 ahead of b1: [b2][b1], return b1 + size_t malloc_size = safe_add_size_t(b1->size, b2->size); if (b2->size == 0) { // do nothing result = 0; } - else if (b1->size + b2->size < b2->size) + else if (malloc_size == SIZE_MAX) { LogError("Failure: size_t overflow."); result = MU_FAILURE; @@ -553,7 +561,7 @@ int BUFFER_prepend(BUFFER_HANDLE handle1, BUFFER_HANDLE handle2) else { // b2->size != 0 - unsigned char* temp = (unsigned char*)malloc(b1->size + b2->size); + unsigned char* temp = (unsigned char*)malloc(malloc_size); if (temp == NULL) { /* Codes_SRS_BUFFER_01_005: [ BUFFER_prepend shall return a non-zero upon value any error that is encountered. ]*/ @@ -564,9 +572,15 @@ int BUFFER_prepend(BUFFER_HANDLE handle1, BUFFER_HANDLE handle2) { /* Codes_SRS_BUFFER_01_004: [ BUFFER_prepend concatenates handle1 onto handle2 without modifying handle1 and shall return zero on success. ]*/ // Append the BUFFER +#ifdef _MSC_VER +#pragma warning(disable:6386) // Buffer overrun while writing to 'temp' +#endif (void)memcpy(temp, b2->buffer, b2->size); // start from b1->size to append b1 (void)memcpy(&temp[b2->size], b1->buffer, b1->size); +#ifdef _MSC_VER +#pragma warning (default:6386) +#endif free(b1->buffer); b1->buffer = temp; b1->size += b2->size; diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/consolelogger.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/consolelogger.c index a43fca958..9e5902178 100755 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/consolelogger.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/consolelogger.c @@ -15,20 +15,20 @@ static char* vprintf_alloc(const char* format, va_list va) { char* result; int neededSize = vsnprintf(NULL, 0, format, va); - if (neededSize < 0) + if (neededSize < 0 || (neededSize + 1) < 0) { result = NULL; } else { - result = (char*)malloc(neededSize + 1); + result = (char*)malloc((size_t)neededSize + 1); if (result == NULL) { /*return as is*/ } else { - if (vsnprintf(result, neededSize + 1, format, va) != neededSize) + if (vsnprintf(result, (size_t)neededSize + 1, format, va) != neededSize) { free(result); result = NULL; @@ -157,6 +157,9 @@ void consolelogger_log_with_GetLastError(const char* file, const char* func, int timeString = get_ctime(&t); #endif // LOGGER_DISABLE_PAL + // In case time is not implemented + timeString = timeString == NULL ? "" : timeString; + systemMessage = printf_alloc("Error: Time:%.24s File:%s Func:%s Line:%d %s", timeString, file, func, line, lastErrorAsString); if (systemMessage == NULL) @@ -221,6 +224,9 @@ void consolelogger_log(LOG_CATEGORY log_category, const char* file, const char* timeString = get_ctime(&t); #endif // LOGGER_DISABLE_PAL + // In case time is not implemented + timeString = timeString == NULL ? "" : timeString; + switch (log_category) { case AZ_LOG_INFO: diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/constbuffer.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/constbuffer.c index 78414f05e..873846b79 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/constbuffer.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/constbuffer.c @@ -33,7 +33,18 @@ static CONSTBUFFER_HANDLE CONSTBUFFER_Create_Internal(const unsigned char* sourc CONSTBUFFER_HANDLE result; /*Codes_SRS_CONSTBUFFER_02_005: [The non-NULL handle returned by CONSTBUFFER_Create shall have its ref count set to "1".]*/ /*Codes_SRS_CONSTBUFFER_02_010: [The non-NULL handle returned by CONSTBUFFER_CreateFromBuffer shall have its ref count set to "1".]*/ - result = (CONSTBUFFER_HANDLE)calloc(1, (sizeof(CONSTBUFFER_HANDLE_DATA) + size)); + size_t malloc_size = sizeof(CONSTBUFFER_HANDLE_DATA) + size; + if (malloc_size < size) + { + result = NULL; + LogError("invalid size parameter"); + /*return as is*/ + } + else + { + result = (CONSTBUFFER_HANDLE)calloc(1, malloc_size); + } + if (result == NULL) { /*Codes_SRS_CONSTBUFFER_02_003: [If creating the copy fails then CONSTBUFFER_Create shall return NULL.]*/ diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/constbuffer_array.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/constbuffer_array.c index adea53e57..fd5314696 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/constbuffer_array.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/constbuffer_array.c @@ -18,7 +18,7 @@ typedef struct CONSTBUFFER_ARRAY_HANDLE_DATA_TAG bool created_with_moved_memory; CONSTBUFFER_HANDLE* buffers; #ifdef _MSC_VER - /*warning C4200: nonstandard extension used: zero-sized array in struct/union : looks very standard in C99 and it is called flexible array. Documentation-wise is a flexible array, but called "unsized" in Microsoft's docs*/ /*https://msdn.microsoft.com/en-us/library/b6fae073.aspx*/ + /*warning C4200: nonstandard extension used: zero-sized array in struct/union : looks very standard in C99 and it is called flexible array. Documentation-wise is a flexible array, but called "unsized" in Microsoft's docs*/ /*https://msdn.microsoft.com/library/b6fae073.aspx*/ #pragma warning(disable:4200) #endif CONSTBUFFER_HANDLE buffers_memory[]; @@ -236,7 +236,7 @@ IMPLEMENT_MOCKABLE_FUNCTION(, CONSTBUFFER_ARRAY_HANDLE, constbuffer_array_add_fr else { /*Codes_SRS_CONSTBUFFER_ARRAY_02_042: [ constbuffer_array_add_front shall allocate enough memory to hold all of constbuffer_array_handle existing CONSTBUFFER_HANDLE and constbuffer_handle. ]*/ - result = REFCOUNT_TYPE_CREATE_WITH_EXTRA_SIZE(CONSTBUFFER_ARRAY_HANDLE_DATA, (constbuffer_array_handle->nBuffers + 1) * sizeof(CONSTBUFFER_HANDLE)); + result = REFCOUNT_TYPE_CREATE_WITH_EXTRA_SIZE(CONSTBUFFER_ARRAY_HANDLE_DATA, ((size_t)constbuffer_array_handle->nBuffers + 1) * sizeof(CONSTBUFFER_HANDLE)); if (result == NULL) { /*Codes_SRS_CONSTBUFFER_ARRAY_02_011: [ If there any failures constbuffer_array_add_front shall fail and return NULL. ]*/ @@ -448,6 +448,7 @@ IMPLEMENT_MOCKABLE_FUNCTION(, void, constbuffer_array_dec_ref, CONSTBUFFER_ARRAY if (constbuffer_array_handle->created_with_moved_memory) { free(constbuffer_array_handle->buffers); + constbuffer_array_handle->buffers = NULL; } REFCOUNT_TYPE_DESTROY(CONSTBUFFER_ARRAY_HANDLE_DATA, constbuffer_array_handle); diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/constbuffer_array_batcher.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/constbuffer_array_batcher.c index 8f096c3b2..81f057def 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/constbuffer_array_batcher.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/constbuffer_array_batcher.c @@ -6,6 +6,7 @@ #include "azure_c_shared_utility/xlogging.h" #include "azure_c_shared_utility/constbuffer_array_batcher.h" #include "azure_c_shared_utility/memory_data.h" +#include "azure_c_shared_utility/safe_math.h" CONSTBUFFER_ARRAY_HANDLE constbuffer_array_batcher_batch(CONSTBUFFER_ARRAY_HANDLE* payloads, uint32_t count) { @@ -24,7 +25,7 @@ CONSTBUFFER_ARRAY_HANDLE constbuffer_array_batcher_batch(CONSTBUFFER_ARRAY_HANDL else { uint32_t i; - uint32_t total_buffer_count = 0; + size_t total_buffer_count = 0; uint32_t* header_memory; for (i = 0; i < count; i++) @@ -45,16 +46,18 @@ CONSTBUFFER_ARRAY_HANDLE constbuffer_array_batcher_batch(CONSTBUFFER_ARRAY_HANDL /* Codes_SRS_CONSTBUFFER_ARRAY_BATCHER_01_003: [ Otherwise constbuffer_array_batcher_batch shall obtain the number of buffers used by each CONSTBUFFER_ARRAY. ]*/ /* Codes_SRS_CONSTBUFFER_ARRAY_BATCHER_01_004: [ constbuffer_array_batcher_batch shall allocate memory for the header buffer (enough to hold the entire batch header namingly (count + 1) uint32_t values). ]*/ - header_memory = malloc(sizeof(uint32_t) * (count + 1)); - if (header_memory == NULL) + size_t count_size_t = (size_t)count; // handle -Werror=type-limits + size_t malloc_size = safe_add_size_t(count_size_t, 1); + malloc_size = safe_multiply_size_t(malloc_size, sizeof(uint32_t)); + if (malloc_size == SIZE_MAX || + (header_memory = malloc(malloc_size)) == NULL) { /* Codes_SRS_CONSTBUFFER_ARRAY_BATCHER_01_010: [ If any error occurrs, constbuffer_array_batcher_batch shall fail and return NULL. ]*/ - LogError("malloc failed"); + LogError("malloc failed, size:%zu", malloc_size); } else { CONSTBUFFER_HANDLE* all_buffers; - uint32_t all_buffers_array_size; /* Codes_SRS_CONSTBUFFER_ARRAY_BATCHER_01_005: [ count shall be written as the first uint32_t in the header memory. ]*/ write_uint32_t((void*)&header_memory[0], count); @@ -73,9 +76,14 @@ CONSTBUFFER_ARRAY_HANDLE constbuffer_array_batcher_batch(CONSTBUFFER_ARRAY_HANDL } /* Codes_SRS_CONSTBUFFER_ARRAY_BATCHER_01_007: [ constbuffer_array_batcher_batch shall allocate enough memory for all the buffer handles in all the arrays + one extra header buffer handle. ]*/ - all_buffers_array_size = total_buffer_count + 1; - all_buffers = malloc(sizeof(CONSTBUFFER_HANDLE) * ((size_t)all_buffers_array_size)); - if (all_buffers == NULL) + size_t all_buffers_array_size = safe_add_size_t(total_buffer_count, 1); + malloc_size = safe_multiply_size_t(sizeof(CONSTBUFFER_HANDLE), (all_buffers_array_size)); + + if (malloc_size == SIZE_MAX) + { + LogError("malloc size is invalid"); + } + else if ((all_buffers = malloc(malloc_size)) == NULL) { /* Codes_SRS_CONSTBUFFER_ARRAY_BATCHER_01_010: [ If any error occurrs, constbuffer_array_batcher_batch shall fail and return NULL. ]*/ LogError("malloc failed"); @@ -84,9 +92,12 @@ CONSTBUFFER_ARRAY_HANDLE constbuffer_array_batcher_batch(CONSTBUFFER_ARRAY_HANDL { uint32_t current_index = 0; - /* Codes_SRS_CONSTBUFFER_ARRAY_BATCHER_01_008: [ constbuffer_array_batcher_batch shall populate the first handle in the newly allocated handles array with the header buffer handle. ]*/ - all_buffers[current_index] = CONSTBUFFER_CreateWithMoveMemory((void*)header_memory, sizeof(uint32_t) * (count + 1)); - if (all_buffers[current_index] == NULL) + size_t move_memory_size = safe_multiply_size_t(sizeof(uint32_t), ((size_t)count + 1)); + if (move_memory_size == SIZE_MAX) + { + LogError("invalid malloc size in CONSTBUFFER_CreateWithMoveMemory"); + } + else if ((all_buffers[current_index] = CONSTBUFFER_CreateWithMoveMemory((void*)header_memory, move_memory_size)) == NULL) { /* Codes_SRS_CONSTBUFFER_ARRAY_BATCHER_01_010: [ If any error occurrs, constbuffer_array_batcher_batch shall fail and return NULL. ]*/ LogError("CONSTBUFFER_CreateWithMoveMemory failed"); @@ -107,14 +118,26 @@ CONSTBUFFER_ARRAY_HANDLE constbuffer_array_batcher_batch(CONSTBUFFER_ARRAY_HANDL for (j = 0; j < buffer_count; j++) { +#ifdef _MSC_VER +#pragma warning(disable:6386) // warning C6386: Buffer overrun while writing to 'all_buffers' +#endif all_buffers[current_index++] = constbuffer_array_get_buffer(payloads[i], j); +#ifdef _MSC_VER +#pragma warning (default:6386) +#endif } } - result = constbuffer_array_create(all_buffers, all_buffers_array_size); + result = constbuffer_array_create(all_buffers, (uint32_t)all_buffers_array_size); for (i = 0; i < all_buffers_array_size; i++) { +#ifdef _MSC_VER +#pragma warning(disable:6385) // warning C6385: Reading invalid data from 'all_buffers' +#endif CONSTBUFFER_DecRef(all_buffers[i]); +#ifdef _MSC_VER +#pragma warning (default:6385) +#endif } if (result == NULL) @@ -124,7 +147,7 @@ CONSTBUFFER_ARRAY_HANDLE constbuffer_array_batcher_batch(CONSTBUFFER_ARRAY_HANDL else { free(all_buffers); - + all_buffers = NULL; goto all_ok; } } @@ -207,11 +230,14 @@ CONSTBUFFER_ARRAY_HANDLE* constbuffer_array_batcher_unbatch(CONSTBUFFER_ARRAY_HA else { /* Codes_SRS_CONSTBUFFER_ARRAY_BATCHER_01_017: [ constbuffer_array_batcher_unbatch shall allocate enough memory to hold the handles for buffer arrays that will be unbatched. ]*/ - result = malloc(sizeof(CONSTBUFFER_ARRAY_HANDLE) * batch_payload_count); - if (result == NULL) + size_t batch_payload_count_size_t = (size_t)batch_payload_count; // handle -Werror=type-limits + size_t malloc_size = safe_multiply_size_t(sizeof(CONSTBUFFER_ARRAY_HANDLE), batch_payload_count_size_t); + if (malloc_size == SIZE_MAX || + (result = malloc(malloc_size)) == NULL) { /* Codes_SRS_CONSTBUFFER_ARRAY_BATCHER_01_022: [ If any error occurs, constbuffer_array_batcher_unbatch shall fail and return NULL. ]*/ - LogError("malloc failed"); + LogError("malloc failed, size:%zu", malloc_size); + result = NULL; } else { @@ -240,11 +266,14 @@ CONSTBUFFER_ARRAY_HANDLE* constbuffer_array_batcher_unbatch(CONSTBUFFER_ARRAY_HA } else { - CONSTBUFFER_HANDLE* payload_buffers = malloc(sizeof(CONSTBUFFER_HANDLE) * buffer_count); - if (payload_buffers == NULL) + CONSTBUFFER_HANDLE* payload_buffers; + size_t buffer_count_size_t = (size_t)buffer_count; // handle -Werror=type-limits + malloc_size = safe_multiply_size_t(sizeof(CONSTBUFFER_HANDLE), buffer_count_size_t); + if (malloc_size == SIZE_MAX || + (payload_buffers = malloc(malloc_size)) == NULL) { /* Codes_SRS_CONSTBUFFER_ARRAY_BATCHER_01_022: [ If any error occurs, constbuffer_array_batcher_unbatch shall fail and return NULL. ]*/ - LogError("malloc failed"); + LogError("malloc failed, size:%zu", malloc_size); break; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/crt_abstractions.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/crt_abstractions.c index 14fcebb7c..b10e562a9 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/crt_abstractions.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/crt_abstractions.c @@ -14,6 +14,7 @@ #include "azure_c_shared_utility/gballoc.h" #include "azure_c_shared_utility/optimize_size.h" #include "azure_c_shared_utility/crt_abstractions.h" +#include "azure_c_shared_utility/safe_math.h" // VS 2008 does not have INFINITY and all the nice goodies... #if defined (TIZENRT) @@ -597,7 +598,7 @@ float strtof_s(const char* nptr, char** endptr) result = NAN; break; case FST_NUMBER: - val = fraction * pow(10.0, (double)exponential) * (double)signal; + val = fraction * pow((double)10.0, (double)exponential) * (double)signal; if ((val >= ((double)FLT_MAX * (-1.0))) && (val <= (double)FLT_MAX)) { /*Codes_SRS_CRT_ABSTRACTIONS_21_016: [The strtof_s must return the float that represents the value in the initial part of the string. If any.]*/ @@ -655,7 +656,13 @@ long double strtold_s(const char* nptr, char** endptr) break; case FST_NAN: /*Codes_SRS_CRT_ABSTRACTIONS_21_034: [If the string is 'NAN' or 'NAN(...)' (ignoring case), the strtold_s must return 0.0 and points endptr to the first character after the 'NAN' sequence.]*/ - result = (long double)((float)NAN); +#ifdef _MSC_VER +#pragma warning(disable:26451) // warning C26451: overflow in constant arithmetic +#endif + result = (long double)NAN; +#ifdef _MSC_VER +#pragma warning (default:26451) +#endif break; case FST_NUMBER: if ((exponential != DBL_MAX_10_EXP || (fraction <= 1.7976931348623158)) && @@ -706,11 +713,13 @@ int mallocAndStrcpy_s(char** destination, const char* source) } else { + char* temp; size_t l = strlen(source); - char* temp = (char*)malloc(l + 1); + size_t malloc_size = safe_add_size_t(l, 1); /*Codes_SRS_CRT_ABSTRACTIONS_99_037: [Upon failure to allocate memory for the destination, the function will return ENOMEM.]*/ - if (temp == NULL) + if (malloc_size == SIZE_MAX || + (temp = (char*)malloc(malloc_size)) == NULL) { result = ENOMEM; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/dns_resolver_ares.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/dns_resolver_ares.c index fea80ca99..fe5b0c546 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/dns_resolver_ares.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/dns_resolver_ares.c @@ -21,11 +21,19 @@ // The default definition handles lwIP. Please add comments for other systems tested. #define EXTRACT_IPV4(ptr) ((struct sockaddr_in *) ptr->ai_addr)->sin_addr.s_addr +#ifdef IPV6_ENABLED +// EXTRACT_IPV6 pulls the uint32_t IPv6 address out of an addrinfo struct +#define EXTRACT_IPV6(ptr) ((struct sockaddr_in6 *) ptr->ai_addr)->sin6_addr.s6_addr +#endif // IPV6_ENABLED + typedef struct { char* hostname; int port; uint32_t ip_v4; +#ifdef IPV6_ENABLED + uint8_t ip_v6[16]; +#endif // IPV6_ENABLED bool is_complete; bool is_failed; bool in_progress; @@ -47,7 +55,7 @@ DNSRESOLVER_HANDLE dns_resolver_create(const char* hostname, int port, const DNS } else { - result = malloc(sizeof(DNSRESOLVER_INSTANCE)); + result = calloc(1, sizeof(DNSRESOLVER_INSTANCE)); if (result == NULL) { /* Codes_SRS_dns_resolver_30_014: [ On any failure, dns_resolver_create shall log an error and return NULL. ]*/ @@ -61,6 +69,9 @@ DNSRESOLVER_HANDLE dns_resolver_create(const char* hostname, int port, const DNS result->is_failed = false; result->in_progress = false; result->ip_v4 = 0; +#ifdef IPV6_ENABLED + memset(result->ip_v6, 0, sizeof(result->ip_v6)); // zero out the IPv6 address +#endif // IPV6_ENABLED result->port = port; /* Codes_SRS_dns_resolver_30_010: [ dns_resolver_create shall make a copy of the hostname parameter to allow immediate deletion by the caller. ]*/ ms_result = mallocAndStrcpy_s(&result->hostname, hostname); @@ -108,7 +119,10 @@ static void query_completed_cb(void *arg, int status, int timeouts, struct hoste int i; struct addrinfo *ptr = NULL; struct sockaddr_in *addr; - +#ifdef IPV6_ENABLED + struct sockaddr_in6 *addr6; +#endif // IPV6_ENABLED + DNSRESOLVER_INSTANCE *dns = (DNSRESOLVER_INSTANCE *)arg; (void)timeouts; @@ -126,20 +140,59 @@ static void query_completed_cb(void *arg, int status, int timeouts, struct hoste dns->is_complete = true; dns->in_progress = false; } +#ifdef IPV6_ENABLED + else if (he->h_addrtype == AF_INET6) + { + ptr = dns->addrInfo; + + ptr->ai_addr = calloc(1, sizeof(struct sockaddr_in6)); + + if(ptr->ai_addr == NULL) + { + LogError("dns addrinfo ai_addr: allocation failed"); + free(dns->addrInfo); + dns->addrInfo = NULL; + dns->is_failed = true; + dns->is_complete = true; + dns->in_progress = false; + } + else + { + addr6 = (void *)ptr->ai_addr; + + memcpy(&addr6->sin6_addr, he->h_addr_list[0], sizeof(struct in6_addr)); + addr6->sin6_family = AF_INET6; + addr6->sin6_port = htons((unsigned short)dns->port); + + /* Codes_SRS_dns_resolver_30_033: [ If dns_resolver_is_create_complete has returned true and the lookup process has failed, dns_resolver_get_ipv4 shall return 0. ]*/ + memcpy(dns->ip_v6, EXTRACT_IPV6(ptr), 16); // IPv6 address is 16 bytes + dns->addrInfo->ai_addrlen = sizeof(struct sockaddr_in6); + dns->addrInfo->ai_family = AF_INET6; + dns->addrInfo->ai_socktype = SOCK_STREAM; + dns->addrInfo->ai_protocol = IPPROTO_TCP; + + dns->is_failed = (dns->ip_v6 == 0); + dns->is_complete = true; + dns->in_progress = false; + } + } +#endif // IPV6_ENABLED else { ptr = dns->addrInfo; - + ptr->ai_addr = calloc(1, sizeof(struct sockaddr_in)); + if(ptr->ai_addr == NULL) { LogError("dns addrinfo ai_addr: allocation failed"); free(dns->addrInfo); + dns->addrInfo = NULL; dns->is_failed = true; dns->is_complete = true; dns->in_progress = false; - } - else + } + else { addr = (void *)ptr->ai_addr; @@ -151,11 +204,17 @@ static void query_completed_cb(void *arg, int status, int timeouts, struct hoste /* Codes_SRS_dns_resolver_30_033: [ If dns_resolver_is_create_complete has returned true and the lookup process has failed, dns_resolver_get_ipv4 shall return 0. ]*/ dns->ip_v4 = EXTRACT_IPV4(ptr); + dns->addrInfo->ai_addrlen = sizeof(struct sockaddr_in); + dns->addrInfo->ai_family = AF_INET; + dns->addrInfo->ai_socktype = SOCK_STREAM; + dns->addrInfo->ai_protocol = IPPROTO_TCP; + dns->is_failed = (dns->ip_v4 == 0); dns->is_complete = true; dns->in_progress = false; } + } } } @@ -188,7 +247,11 @@ bool dns_resolver_is_lookup_complete(DNSRESOLVER_HANDLE dns_in) } else if(!dns->in_progress) { +#ifdef IPV6_ENABLED + ares_gethostbyname(dns->ares_resolver, dns->hostname, AF_UNSPEC, query_completed_cb, (void*)dns); +#else ares_gethostbyname(dns->ares_resolver, dns->hostname, AF_INET, query_completed_cb, (void*)dns); +#endif // IPV6_ENABLED dns->in_progress = true; // This synchronous implementation is incapable of being incomplete, so SRS_dns_resolver_30_023 does not ever happen /* Codes_SRS_dns_resolver_30_023: [ If the DNS lookup process is not yet complete, dns_resolver_is_create_complete shall return false. ]*/ diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/dns_resolver_sync.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/dns_resolver_sync.c index 3ef601945..fbd45f53f 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/dns_resolver_sync.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/dns_resolver_sync.c @@ -21,11 +21,19 @@ // The default definition handles lwIP. Please add comments for other systems tested. #define EXTRACT_IPV4(ptr) ((struct sockaddr_in *) ptr->ai_addr)->sin_addr.s_addr +#ifdef IPV6_ENABLED +// EXTRACT_IPV6 pulls the uint32_t IPv6 address out of an addrinfo struct +#define EXTRACT_IPV6(ptr) ((struct sockaddr_in6 *) ptr->ai_addr)->sin6_addr.s6_addr +#endif // IPV6_ENABLED + typedef struct { char* hostname; int port; uint32_t ip_v4; +#ifdef IPV6_ENABLED + uint8_t ip_v6[16]; +#endif // IPV6_ENABLED bool is_complete; bool is_failed; struct addrinfo* addrInfo; @@ -44,7 +52,7 @@ DNSRESOLVER_HANDLE dns_resolver_create(const char* hostname, int port, const DNS } else { - result = malloc(sizeof(DNSRESOLVER_INSTANCE)); + result = calloc(1, sizeof(DNSRESOLVER_INSTANCE)); if (result == NULL) { /* Codes_SRS_dns_resolver_30_014: [ On any failure, dns_resolver_create shall log an error and return NULL. ]*/ @@ -56,7 +64,6 @@ DNSRESOLVER_HANDLE dns_resolver_create(const char* hostname, int port, const DNS int ms_result; result->is_complete = false; result->is_failed = false; - result->ip_v4 = 0; result->port = port; /* Codes_SRS_dns_resolver_30_010: [ dns_resolver_create shall make a copy of the hostname parameter to allow immediate deletion by the caller. ]*/ ms_result = mallocAndStrcpy_s(&result->hostname, hostname); @@ -102,7 +109,11 @@ bool dns_resolver_is_lookup_complete(DNSRESOLVER_HANDLE dns_in) // Setup the hints address info structure // which is passed to the getaddrinfo() function memset(&hints, 0, sizeof(hints)); +#ifdef IPV6_ENABLED + hints.ai_family = AF_UNSPEC; +#else hints.ai_family = AF_INET; +#endif // IPV6_ENABLED hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = 0; @@ -130,11 +141,23 @@ bool dns_resolver_is_lookup_complete(DNSRESOLVER_HANDLE dns_in) case AF_INET: /* Codes_SRS_dns_resolver_30_032: [ If dns_resolver_is_create_complete has returned true and the lookup process has succeeded, dns_resolver_get_ipv4 shall return the discovered IPv4 address. ]*/ dns->ip_v4 = EXTRACT_IPV4(ptr); + dns->is_failed = false; break; +#ifdef IPV6_ENABLED + case AF_INET6: + memcpy(dns->ip_v6, EXTRACT_IPV6(ptr), 16); + dns->is_failed = false; + break; +#endif // IPV6_ENABLED } } /* Codes_SRS_dns_resolver_30_033: [ If dns_resolver_is_create_complete has returned true and the lookup process has failed, dns_resolver_get_ipv4 shall return 0. ]*/ +#ifdef IPV6_ENABLED + uint8_t zero[16] = { 0 }; // IPv6 address of all zeroes + dns->is_failed = (dns->ip_v4 == 0) && (memcmp(dns->ip_v6, zero, 16) == 0); +#else dns->is_failed = (dns->ip_v4 == 0); +#endif // IPV6_ENABLED } else { diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/etwlogger_driver.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/etwlogger_driver.c index 7446c418e..c07647705 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/etwlogger_driver.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/etwlogger_driver.c @@ -22,7 +22,7 @@ static char* vprintf_alloc(const char* format, va_list va) { char* result; int neededSize = vsnprintf(NULL, 0, format, va); - if (neededSize < 0) + if (neededSize < 0 || (neededSize + 1) < 0) { result = NULL; } @@ -138,7 +138,7 @@ static void lazyRegisterEventProvider(void) TLG_STATUS t = TraceLoggingRegister(g_hMyComponentProvider); if (SUCCEEDED(t)) { - LogInfo("block_storage_2 ETW provider was registered succesfully (self test). Executable file full path name = %s", _pgmptr); /*_pgmptr comes from https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-getmodulefilenamea */ + LogInfo("block_storage_2 ETW provider was registered succesfully (self test). Executable file full path name = %s", _pgmptr); /*_pgmptr comes from https://docs.microsoft.com/windows/win32/api/libloaderapi/nf-libloaderapi-getmodulefilenamea */ } else { diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/gballoc.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/gballoc.c index 39fc311c4..f1faa4581 100755 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/gballoc.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/gballoc.c @@ -6,6 +6,7 @@ #include "azure_c_shared_utility/lock.h" #include "azure_c_shared_utility/optimize_size.h" #include "azure_c_shared_utility/xlogging.h" +#include "azure_c_shared_utility/safe_math.h" #ifndef GB_USE_CUSTOM_HEAP @@ -117,7 +118,7 @@ void* gballoc_malloc(size_t size) head = allocation; g_allocations++; - totalSize += size; + totalSize = safe_add_size_t(totalSize, size); /* Codes_SRS_GBALLOC_01_011: [The maximum total memory used shall be the maximum of the total memory used at any point.] */ if (maxSize < totalSize) { @@ -168,12 +169,12 @@ void* gballoc_calloc(size_t nmemb, size_t size) { /* Codes_SRS_GBALLOC_01_021: [If the underlying calloc call is successful, gballoc_calloc shall increment the total memory used with nmemb*size.] */ allocation->ptr = result; - allocation->size = nmemb * size; + allocation->size = safe_multiply_size_t(nmemb, size); allocation->next = head; head = allocation; g_allocations++; - totalSize += allocation->size; + totalSize = safe_add_size_t(totalSize, allocation->size); /* Codes_SRS_GBALLOC_01_011: [The maximum total memory used shall be the maximum of the total memory used at any point.] */ if (maxSize < totalSize) { @@ -266,7 +267,7 @@ void* gballoc_realloc(void* ptr, size_t size) } /* Codes_SRS_GBALLOC_01_007: [If realloc is successful, gballoc_realloc shall also increment the total memory used value tracked by this module.] */ - totalSize += size; + totalSize = safe_add_size_t(totalSize, size); g_allocations++; /* Codes_SRS_GBALLOC_01_011: [The maximum total memory used shall be the maximum of the total memory used at any point.] */ @@ -308,7 +309,7 @@ void gballoc_free(void* ptr) { /* Codes_SRS_GBALLOC_01_008: [gballoc_free shall call the C99 free function.] */ free(ptr); - totalSize -= curr->size; + totalSize = safe_subtract_size_t(totalSize, curr->size); if (prev != NULL) { prev->next = curr->next; @@ -326,7 +327,13 @@ void gballoc_free(void* ptr) curr = (ALLOCATION*)curr->next; } +#ifdef _MSC_VER +#pragma warning(disable:6001) // Using uninitialized memory 'curr' +#endif if ((curr == NULL) && (ptr != NULL)) +#ifdef _MSC_VER +#pragma warning (default:6001) +#endif { /* Codes_SRS_GBALLOC_01_019: [When the ptr pointer cannot be found in the pointers tracked by gballoc, gballoc_free shall not free any memory.] */ @@ -418,7 +425,7 @@ size_t gballoc_getAllocationCount(void) return result; } -void gballoc_resetMetrics() +void gballoc_resetMetrics(void) { /* Codes_SRS_GBALLOC_07_005: [ If gballoc was not initialized gballoc_reset Metrics shall do nothing.] */ if (gballocState != GBALLOC_STATE_INIT) diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/gbnetwork.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/gbnetwork.c index 430872e8f..e0fae54d3 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/gbnetwork.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/gbnetwork.c @@ -68,7 +68,7 @@ void gbnetwork_deinit(void) gbnetworkState = GBNETWORK_STATE_NOT_INIT; } -void gbnetwork_resetMetrics() +void gbnetwork_resetMetrics(void) { if (gbnetworkState != GBNETWORK_STATE_INIT) { @@ -189,7 +189,7 @@ uint64_t gbnetwork_getNumSends(void) return result; } -uint64_t gbnetwork_getBytesRecv() +uint64_t gbnetwork_getBytesRecv(void) { uint64_t result; @@ -211,7 +211,7 @@ uint64_t gbnetwork_getBytesRecv() return result; } -uint64_t gbnetwork_getNumRecv() +uint64_t gbnetwork_getNumRecv(void) { uint64_t result; diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/http_proxy_io.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/http_proxy_io.c index 45fb3e1d5..8b4325bcb 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/http_proxy_io.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/http_proxy_io.c @@ -12,6 +12,7 @@ #include "azure_c_shared_utility/crt_abstractions.h" #include "azure_c_shared_utility/http_proxy_io.h" #include "azure_c_shared_utility/azure_base64.h" +#include "azure_c_shared_utility/safe_math.h" static const char* const OPTION_UNDERLYING_IO_OPTIONS = "underlying_io_options"; @@ -315,11 +316,13 @@ static void on_underlying_io_open_complete(void* context, IO_OPEN_RESULT open_re } else { - plain_auth_string_bytes = (char*)malloc(plain_auth_string_length + 1); - if (plain_auth_string_bytes == NULL) + size_t malloc_size = safe_add_size_t((size_t)plain_auth_string_length, 1); + if (malloc_size == SIZE_MAX || + (plain_auth_string_bytes = (char*)malloc(malloc_size)) == NULL) { /* Codes_SRS_HTTP_PROXY_IO_01_062: [ If any failure is encountered while constructing the request, the on_open_complete callback shall be triggered with IO_OPEN_ERROR, passing also the on_open_complete_context argument as context. ]*/ encoded_auth_string = NULL; + plain_auth_string_bytes = NULL; indicate_open_complete_error_and_close(http_proxy_io_instance); } else @@ -391,8 +394,10 @@ static void on_underlying_io_open_complete(void* context, IO_OPEN_RESULT open_re } else { - char* connect_request = (char*)malloc(connect_request_length + 1); - if (connect_request == NULL) + char* connect_request; + size_t malloc_size = safe_add_size_t((size_t)connect_request_length, 1); + if (malloc_size == SIZE_MAX || + (connect_request = (char*)malloc(malloc_size)) == NULL) { /* Codes_SRS_HTTP_PROXY_IO_01_062: [ If any failure is encountered while constructing the request, the on_open_complete callback shall be triggered with IO_OPEN_ERROR, passing also the on_open_complete_context argument as context. ]*/ LogError("Cannot allocate memory for CONNECT request"); @@ -631,8 +636,16 @@ static void on_underlying_io_bytes_received(void* context, const unsigned char* case HTTP_PROXY_IO_STATE_WAITING_FOR_CONNECT_RESPONSE: { /* Codes_SRS_HTTP_PROXY_IO_01_065: [ When bytes are received and the response to the CONNECT request was not yet received, the bytes shall be accumulated until a double new-line is detected. ]*/ - unsigned char* new_receive_buffer = (unsigned char*)realloc(http_proxy_io_instance->receive_buffer, http_proxy_io_instance->receive_buffer_size + size + 1); - if (new_receive_buffer == NULL) + // size_t malloc_size = http_proxy_io_instance->receive_buffer_size + size + 1; + size_t realloc_size = safe_add_size_t(safe_add_size_t(http_proxy_io_instance->receive_buffer_size, size), 1); + + unsigned char* new_receive_buffer = NULL; + if (realloc_size == SIZE_MAX) + { + LogError("Invalid memory size for received data"); + indicate_open_complete_error_and_close(http_proxy_io_instance); + } + else if ((new_receive_buffer = (unsigned char*)realloc(http_proxy_io_instance->receive_buffer, realloc_size)) == NULL) { /* Codes_SRS_HTTP_PROXY_IO_01_067: [ If allocating memory for the buffered bytes fails, the on_open_complete callback shall be triggered with IO_OPEN_ERROR, passing also the on_open_complete_context argument as context. ]*/ LogError("Cannot allocate memory for received data"); @@ -649,8 +662,13 @@ static void on_underlying_io_bytes_received(void* context, const unsigned char* { const char* request_end_ptr; +#ifdef _MSC_VER +#pragma warning(disable:6386) // Warning C6386: Buffer overrun while writing to 'http_proxy_io_instance->receive_buffer' +#endif http_proxy_io_instance->receive_buffer[http_proxy_io_instance->receive_buffer_size] = 0; - +#ifdef _MSC_VER +#pragma warning (default:6386) +#endif /* Codes_SRS_HTTP_PROXY_IO_01_066: [ When a double new-line is detected the response shall be parsed in order to extract the status code. ]*/ if ((http_proxy_io_instance->receive_buffer_size >= 4) && ((request_end_ptr = strstr((const char*)http_proxy_io_instance->receive_buffer, "\r\n\r\n")) != NULL)) @@ -1011,18 +1029,29 @@ static OPTIONHANDLER_HANDLE http_proxy_io_retrieve_options(CONCRETE_IO_HANDLE ht OPTIONHANDLER_HANDLE underlying_io_options; /* Codes_SRS_HTTP_PROXY_IO_01_046: [ http_proxy_io_retrieve_options shall return an OPTIONHANDLER_HANDLE obtained by calling xio_retrieveoptions on the underlying IO created in http_proxy_io_create. ]*/ - if ((underlying_io_options = xio_retrieveoptions(http_proxy_io_instance->underlying_io)) == NULL || - OptionHandler_AddOption(result, OPTION_UNDERLYING_IO_OPTIONS, underlying_io_options) != OPTIONHANDLER_OK) + if ((underlying_io_options = xio_retrieveoptions(http_proxy_io_instance->underlying_io)) == NULL) { /* Codes_SRS_HTTP_PROXY_IO_01_048: [ If xio_retrieveoptions fails, http_proxy_io_retrieve_options shall return NULL. ]*/ - LogError("unable to save underlying_io options"); - OptionHandler_Destroy(underlying_io_options); + LogError("unable to retrieve underlying_io options"); OptionHandler_Destroy(result); result = NULL; } - else + else { - // All is fine. + if (OptionHandler_AddOption(result, OPTION_UNDERLYING_IO_OPTIONS, underlying_io_options) != OPTIONHANDLER_OK) + { + /* Codes_SRS_HTTP_PROXY_IO_01_048: [ If xio_retrieveoptions fails, http_proxy_io_retrieve_options shall return NULL. ]*/ + LogError("unable to save underlying_io options"); + OptionHandler_Destroy(result); + result = NULL; + } + else + { + // All is fine. + } + + // Must destroy since OptionHandler_AddOption creates a copy of it. + OptionHandler_Destroy(underlying_io_options); } } } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/httpapiex.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/httpapiex.c index a6454177a..12dd3eb25 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/httpapiex.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/httpapiex.c @@ -300,6 +300,7 @@ static int buildAllRequests(HTTPAPIEX_HANDLE_DATA* handle, HTTPAPI_REQUEST_TYPE if (*isOriginalRequestHttpHeadersHandle == false) { HTTPHeaders_Free(*toBeUsedRequestHttpHeadersHandle); + *toBeUsedRequestHttpHeadersHandle = NULL; } LogError("unable to build response content"); result = MU_FAILURE; @@ -314,14 +315,17 @@ static int buildAllRequests(HTTPAPIEX_HANDLE_DATA* handle, HTTPAPI_REQUEST_TYPE if (*isOriginalRequestContent == false) { BUFFER_delete(*toBeUsedRequestContent); + *toBeUsedRequestContent = NULL; } if (*isOriginalRequestHttpHeadersHandle == false) { HTTPHeaders_Free(*toBeUsedRequestHttpHeadersHandle); + *toBeUsedRequestHttpHeadersHandle = NULL; } if (*isOriginalResponseHttpHeadersHandle == false) { HTTPHeaders_Free(*toBeUsedResponseHttpHeadersHandle); + *toBeUsedResponseHttpHeadersHandle = NULL; } LogError("unable to build response content"); result = MU_FAILURE; @@ -550,18 +554,22 @@ HTTPAPIEX_RESULT HTTPAPIEX_ExecuteRequest(HTTPAPIEX_HANDLE handle, HTTPAPI_REQUE if (isOriginalRequestContent == false) { BUFFER_delete(toBeUsedRequestContent); + toBeUsedRequestContent = NULL; } if (isOriginalRequestHttpHeadersHandle == false) { HTTPHeaders_Free(toBeUsedRequestHttpHeadersHandle); + toBeUsedRequestHttpHeadersHandle = NULL; } if (isOriginalResponseContent == false) { BUFFER_delete(toBeUsedResponseContent); + toBeUsedResponseContent = NULL; } if (isOriginalResponseHttpHeadersHandle == false) { HTTPHeaders_Free(toBeUsedResponseHttpHeadersHandle); + toBeUsedResponseHttpHeadersHandle = NULL; } } } @@ -596,6 +604,8 @@ void HTTPAPIEX_Destroy(HTTPAPIEX_HANDLE handle) HTTPAPIEX_SAVED_OPTION* savedOption = (HTTPAPIEX_SAVED_OPTION*)VECTOR_element(handleData->savedOptions, i); free((void*)savedOption->optionName); free((void*)savedOption->value); + savedOption->optionName = NULL; + savedOption->value = NULL; } VECTOR_destroy(handleData->savedOptions); diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/httpapiexsas.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/httpapiexsas.c index fad69fb10..58d7527ce 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/httpapiexsas.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/httpapiexsas.c @@ -105,9 +105,12 @@ HTTPAPIEX_SAS_HANDLE HTTPAPIEX_SAS_Create(STRING_HANDLE key, STRING_HANDLE uriRe void HTTPAPIEX_SAS_Destroy(HTTPAPIEX_SAS_HANDLE handle) { +#ifdef _MSC_VER +#pragma warning(disable:6001) // Using uninitialized memory '*state' +#endif /*Codes_SRS_HTTPAPIEXSAS_06_005: [If the parameter handle is NULL then HTTAPIEX_SAS_Destroy shall do nothing and return.]*/ HTTPAPIEX_SAS_STATE* state = (HTTPAPIEX_SAS_STATE*)handle; - if (state) + if (state != NULL) { /*Codes_SRS_HTTPAPIEXSAS_06_006: [HTTAPIEX_SAS_Destroy shall deallocate any structures denoted by the parameter handle.]*/ if (state->key) @@ -124,6 +127,9 @@ void HTTPAPIEX_SAS_Destroy(HTTPAPIEX_SAS_HANDLE handle) } free(state); } +#ifdef _MSC_VER +#pragma warning (default:6001) +#endif } HTTPAPIEX_RESULT HTTPAPIEX_SAS_ExecuteRequest(HTTPAPIEX_SAS_HANDLE sasHandle, HTTPAPIEX_HANDLE handle, HTTPAPI_REQUEST_TYPE requestType, const char* relativePath, HTTP_HEADERS_HANDLE requestHttpHeadersHandle, BUFFER_HANDLE requestContent, unsigned int* statusCode, HTTP_HEADERS_HANDLE responseHeadersHandle, BUFFER_HANDLE responseContent) diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/httpheaders.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/httpheaders.c index faa8dd4d4..e875024f8 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/httpheaders.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/httpheaders.c @@ -9,6 +9,7 @@ #include "azure_c_shared_utility/httpheaders.h" #include "azure_c_shared_utility/crt_abstractions.h" #include "azure_c_shared_utility/xlogging.h" +#include "azure_c_shared_utility/safe_math.h" MU_DEFINE_ENUM_STRINGS(HTTP_HEADERS_RESULT, HTTP_HEADERS_RESULT_VALUES); @@ -111,14 +112,19 @@ static HTTP_HEADERS_RESULT headers_ReplaceHeaderNameValuePair(HTTP_HEADERS_HANDL if (!replace && (existingValue != NULL)) { + char* newValue; size_t existingValueLen = strlen(existingValue); size_t valueLen = strlen(value); - char* newValue = (char*)malloc(sizeof(char) * (existingValueLen + /*COMMA_AND_SPACE_LENGTH*/ 2 + valueLen + /*EOL*/ 1)); - if (newValue == NULL) + size_t malloc_size = safe_add_size_t(existingValueLen, /*COMMA_AND_SPACE_LENGTH*/ 2); + malloc_size = safe_add_size_t(malloc_size, valueLen); + malloc_size = safe_add_size_t(malloc_size, /*EOL*/ 1); + malloc_size = safe_multiply_size_t(malloc_size, sizeof(char)); + if (malloc_size == SIZE_MAX || + (newValue = (char*)malloc(malloc_size)) == NULL) { /*Codes_SRS_HTTP_HEADERS_99_015:[ The function shall return HTTP_HEADERS_ALLOC_FAILED when an internal request to allocate memory fails.]*/ result = HTTP_HEADERS_ALLOC_FAILED; - LogError("failed to malloc , result= %" PRI_MU_ENUM "", MU_ENUM_VALUE(HTTP_HEADERS_RESULT, result)); + LogError("failed to malloc, size= %zu, result= %" PRI_MU_ENUM "", malloc_size, MU_ENUM_VALUE(HTTP_HEADERS_RESULT, result)); } else { @@ -273,12 +279,17 @@ HTTP_HEADERS_RESULT HTTPHeaders_GetHeader(HTTP_HEADERS_HANDLE handle, size_t ind { size_t keyLen = strlen(keys[index]); size_t valueLen = strlen(values[index]); - *destination = (char*)malloc(sizeof(char) * (keyLen + /*COLON_AND_SPACE_LENGTH*/ 2 + valueLen + /*EOL*/ 1)); - if (*destination == NULL) + size_t malloc_size = safe_add_size_t(keyLen, /*COLON_AND_SPACE_LENGTH*/ 2); + malloc_size = safe_add_size_t(malloc_size, valueLen); + malloc_size = safe_add_size_t(malloc_size, /*EOL*/ 1); + malloc_size = safe_multiply_size_t(malloc_size, sizeof(char)); + if (malloc_size == SIZE_MAX || + (*destination = (char*)malloc(malloc_size)) == NULL) { /*Codes_SRS_HTTP_HEADERS_99_034:[ The function shall return HTTP_HEADERS_ERROR when an internal error occurs]*/ result = HTTP_HEADERS_ERROR; - LogError("unable to malloc, result= %" PRI_MU_ENUM "", MU_ENUM_VALUE(HTTP_HEADERS_RESULT, result)); + *destination = NULL; + LogError("unable to malloc, size=%zu, result= %" PRI_MU_ENUM "", malloc_size, MU_ENUM_VALUE(HTTP_HEADERS_RESULT, result)); } else { diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/map.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/map.c index 430d7a302..50e8ee13d 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/map.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/map.c @@ -8,6 +8,7 @@ #include "azure_c_shared_utility/optimize_size.h" #include "azure_c_shared_utility/xlogging.h" #include "azure_c_shared_utility/strings.h" +#include "azure_c_shared_utility/safe_math.h" MU_DEFINE_ENUM_STRINGS(MAP_RESULT, MAP_RESULT_VALUES); @@ -162,10 +163,13 @@ MAP_HANDLE Map_Clone(MAP_HANDLE handle) static int Map_IncreaseStorageKeysValues(MAP_HANDLE_DATA* handleData) { int result; - char** newKeys = (char**)realloc(handleData->keys, (handleData->count + 1) * sizeof(char*)); - if (newKeys == NULL) + char** newKeys; + size_t realloc_size = safe_add_size_t(handleData->count, 1); + realloc_size = safe_multiply_size_t(realloc_size, sizeof(char*)); + if (realloc_size == SIZE_MAX || + (newKeys = (char**)realloc(handleData->keys, realloc_size)) == NULL) { - LogError("realloc error"); + LogError("realloc error, size:%zu", realloc_size); result = MU_FAILURE; } else @@ -173,10 +177,12 @@ static int Map_IncreaseStorageKeysValues(MAP_HANDLE_DATA* handleData) char** newValues; handleData->keys = newKeys; handleData->keys[handleData->count] = NULL; - newValues = (char**)realloc(handleData->values, (handleData->count + 1) * sizeof(char*)); - if (newValues == NULL) + realloc_size = safe_add_size_t(handleData->count, 1); + realloc_size = safe_multiply_size_t(realloc_size, sizeof(char*)); + if (realloc_size == SIZE_MAX || + (newValues = (char**)realloc(handleData->values, realloc_size)) == NULL) { - LogError("realloc error"); + LogError("realloc error, size:%zu", realloc_size); if (handleData->count == 0) /*avoiding an implementation defined behavior */ { free(handleData->keys); @@ -184,10 +190,12 @@ static int Map_IncreaseStorageKeysValues(MAP_HANDLE_DATA* handleData) } else { - char** undoneKeys = (char**)realloc(handleData->keys, (handleData->count) * sizeof(char*)); - if (undoneKeys == NULL) + char** undoneKeys; + realloc_size = safe_multiply_size_t((handleData->count), sizeof(char*)); + if (realloc_size == SIZE_MAX || + (undoneKeys = (char**)realloc(handleData->keys, realloc_size)) == NULL) { - LogError("CATASTROPHIC error, unable to undo through realloc to a smaller size"); + LogError("CATASTROPHIC error, unable to undo through realloc to a smaller size, size:%zu", realloc_size); } else { @@ -222,20 +230,24 @@ static void Map_DecreaseStorageKeysValues(MAP_HANDLE_DATA* handleData) { /*certainly > 1...*/ char** undoneValues; - char** undoneKeys = (char**)realloc(handleData->keys, sizeof(char*)* (handleData->count - 1)); - if (undoneKeys == NULL) + char** undoneKeys; + size_t realloc_size = safe_subtract_size_t(handleData->count, 1); + realloc_size = safe_multiply_size_t(realloc_size, sizeof(char*)); + + if (realloc_size == SIZE_MAX || + (undoneKeys = (char**)realloc(handleData->keys, realloc_size)) == NULL) { - LogError("CATASTROPHIC error, unable to undo through realloc to a smaller size"); + LogError("CATASTROPHIC error, unable to undo through realloc to a smaller size, size:%zu", realloc_size); } else { handleData->keys = undoneKeys; } - undoneValues = (char**)realloc(handleData->values, sizeof(char*)* (handleData->count - 1)); - if (undoneValues == NULL) + if (realloc_size == SIZE_MAX || + (undoneValues = (char**)realloc(handleData->values, realloc_size)) == NULL) { - LogError("CATASTROPHIC error, unable to undo through realloc to a smaller size"); + LogError("CATASTROPHIC error, unable to undo through realloc to a smaller size, size:%zu", realloc_size); } else { @@ -418,18 +430,21 @@ MAP_RESULT Map_AddOrUpdate(MAP_HANDLE handle, const char* key, const char* value else { /*Codes_SRS_MAP_02_016: [If the key already exists, then Map_AddOrUpdate shall overwrite the value of the existing key with parameter value.]*/ + char* newValue; size_t index = whereIsIt - handleData->keys; size_t valueLength = strlen(value); /*try to realloc value of this key*/ - char* newValue = (char*)realloc(handleData->values[index],valueLength + 1); - if (newValue == NULL) + size_t realloc_size = safe_add_size_t(valueLength, 1); + if (realloc_size == SIZE_MAX || + (newValue = (char*)realloc(handleData->values[index], realloc_size)) == NULL) { + LogError("CATASTROPHIC error, unable to realloc, size:%zu", realloc_size); result = MAP_ERROR; LOG_MAP_ERROR; } else { - (void)memcpy(newValue, value, valueLength + 1); + (void)memcpy(newValue, value, realloc_size); handleData->values[index] = newValue; /*Codes_SRS_MAP_02_019: [Otherwise, Map_AddOrUpdate shall return MAP_OK.] */ result = MAP_OK; diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/sastoken.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/sastoken.c index 62da50cdb..0f5207c70 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/sastoken.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/sastoken.c @@ -14,6 +14,7 @@ #include "azure_c_shared_utility/buffer_.h" #include "azure_c_shared_utility/xlogging.h" #include "azure_c_shared_utility/crt_abstractions.h" +#include "azure_c_shared_utility/safe_math.h" static double getExpiryValue(const char* expiryASCII) { @@ -23,7 +24,7 @@ static double getExpiryValue(const char* expiryASCII) { if (expiryASCII[i] >= '0' && expiryASCII[i] <= '9') { - value = value * 10 + ((double)expiryASCII[i] - (double)'0'); + value = value * 10.0 + ((double)expiryASCII[i] - (double)'0'); } else { @@ -152,17 +153,21 @@ bool SASToken_Validate(STRING_HANDLE sasToken) } else { - char* expiryASCII = (char*)malloc(seStop - seStart + 1); + char* expiryASCII; + size_t malloc_size = safe_subtract_size_t((size_t)seStop, (size_t)seStart); + malloc_size = safe_add_size_t(malloc_size, 1); /*Codes_SRS_SASTOKEN_25_031: [**If malloc fails during validation then SASToken_Validate shall return false.**]***/ - if (expiryASCII == NULL) + if (malloc_size == SIZE_MAX || + (expiryASCII = (char*)malloc(malloc_size)) == NULL) { + LogError("malloc error, size:%zu", malloc_size); result = false; } else { double expiry; // Add the Null terminator here - memset(expiryASCII, 0, seStop - seStart + 1); + memset(expiryASCII, 0, (size_t)seStop - (size_t)seStart + 1); for (i = seStart; i < seStop; i++) { // The se contains the expiration values, if a & token is encountered then diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/sha1.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/sha1.c index 3917c1f27..6b38a174f 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/sha1.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/sha1.c @@ -144,17 +144,24 @@ int SHA1Input(SHA1Context *context, const uint8_t *message_array, unsigned int l } else { - while (length-- && !context->Corrupted) + while (length-- && !context->Corrupted) //shaInputTooLong { - context->Message_Block[context->Message_Block_Index++] = (*message_array & 0xFF); + if (context->Message_Block_Index < SHA1_Message_Block_Size) + { + context->Message_Block[context->Message_Block_Index++] = (*message_array & 0xFF); - if (!SHA1AddLength(context, 8) && (context->Message_Block_Index == SHA1_Message_Block_Size)) + if (!SHA1AddLength(context, 8) && (context->Message_Block_Index == SHA1_Message_Block_Size)) + { + SHA1ProcessMessageBlock(context); + } + message_array++; + } + else { - SHA1ProcessMessageBlock(context); + result = context->Corrupted = shaBadParam; } - message_array++; } - result = shaSuccess; + result = context->Corrupted; } return result; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/sha224.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/sha224.c index 64cddc8d1..0bdf16303 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/sha224.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/sha224.c @@ -241,15 +241,22 @@ int SHA256Input(SHA256Context *context, const uint8_t *message_array, unsigned i { while (length-- && !context->Corrupted) { - context->Message_Block[context->Message_Block_Index++] = (*message_array & 0xFF); + if (context->Message_Block_Index < SHA256_Message_Block_Size) + { + context->Message_Block[context->Message_Block_Index++] = (*message_array & 0xFF); - if (!SHA224_256AddLength(context, 8) && (context->Message_Block_Index == SHA256_Message_Block_Size)) + if (!SHA224_256AddLength(context, 8) && (context->Message_Block_Index == SHA256_Message_Block_Size)) + { + SHA224_256ProcessMessageBlock(context); + } + message_array++; + } + else { - SHA224_256ProcessMessageBlock(context); + result = context->Corrupted = shaBadParam; } - message_array++; } - result = shaSuccess; + result = context->Corrupted; } return result; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/sha384-512.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/sha384-512.c index 84d1b1dd7..7adb8b6ef 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/sha384-512.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/sha384-512.c @@ -484,17 +484,24 @@ int SHA512Input(SHA512Context *context, return context->Corrupted; while (length-- && !context->Corrupted) { - context->Message_Block[context->Message_Block_Index++] = - (*message_array & 0xFF); - - if (!SHA384_512AddLength(context, 8) && - (context->Message_Block_Index == SHA512_Message_Block_Size)) - SHA384_512ProcessMessageBlock(context); - - message_array++; + if (context->Message_Block_Index < SHA512_Message_Block_Size) + { + context->Message_Block[context->Message_Block_Index++] = + (*message_array & 0xFF); + + if (!SHA384_512AddLength(context, 8) && + (context->Message_Block_Index == SHA512_Message_Block_Size)) + SHA384_512ProcessMessageBlock(context); + + message_array++; + } + else + { + context->Corrupted = shaBadParam; + } } - return shaSuccess; + return context->Corrupted; } /* diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/singlylinkedlist.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/singlylinkedlist.c index 29d194adc..0df5e2f94 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/singlylinkedlist.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/singlylinkedlist.c @@ -47,6 +47,7 @@ void singlylinkedlist_destroy(SINGLYLINKEDLIST_HANDLE list) LIST_ITEM_INSTANCE* current_item = list_instance->head; list_instance->head = (LIST_ITEM_INSTANCE*)current_item->next; free(current_item); + current_item = NULL; } /* Codes_SRS_LIST_01_003: [singlylinkedlist_destroy shall free all resources associated with the list identified by the handle argument.] */ @@ -141,7 +142,13 @@ int singlylinkedlist_remove(SINGLYLINKEDLIST_HANDLE list, LIST_ITEM_HANDLE item) current_item = (LIST_ITEM_INSTANCE*)current_item->next; } +#ifdef _MSC_VER +#pragma warning(disable:6001) // Using uninitialized memory 'current_item' +#endif if (current_item == NULL) +#ifdef _MSC_VER +#pragma warning (default:6001) +#endif { /* Codes_SRS_LIST_01_025: [If the item item_handle is not found in the list, then singlylinkedlist_remove shall fail and return a non-zero value.] */ result = MU_FAILURE; diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/string_token.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/string_token.c index 561388ad2..15099e059 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/string_token.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/string_token.c @@ -9,6 +9,7 @@ #include "azure_c_shared_utility/xlogging.h" #include "azure_c_shared_utility/crt_abstractions.h" #include "azure_c_shared_utility/string_token.h" +#include "azure_c_shared_utility/safe_math.h" typedef struct STRING_TOKEN_TAG { @@ -22,9 +23,14 @@ typedef struct STRING_TOKEN_TAG static size_t* get_delimiters_lengths(const char** delimiters, size_t n_delims) { + size_t malloc_size = safe_multiply_size_t(sizeof(size_t), n_delims); size_t* result; - - if ((result = malloc(sizeof(size_t) * n_delims)) == NULL) + if (malloc_size == SIZE_MAX) + { + LogError("malloc size overflow"); + result = NULL; + } + else if ((result = malloc(malloc_size)) == NULL) { LogError("Failed to allocate array for delimiters lengths"); } @@ -41,7 +47,14 @@ static size_t* get_delimiters_lengths(const char** delimiters, size_t n_delims) result = NULL; break; } - else + else if (((i+1) * sizeof(size_t)) > malloc_size) + { + LogError("buffer overflow"); + free(result); + result = NULL; + break; + } + else { result[i] = strlen(delimiters[i]); } @@ -326,10 +339,12 @@ int StringToken_Split(const char* source, size_t length, const char** delimiters // Codes_SRS_STRING_TOKENIZER_09_025: [ The tokens shall be stored in tokens, and their count stored in token_count ] *token_count = (*token_count) + 1; - if ((temp_token = (char**)realloc(*tokens, sizeof(char*) * (*token_count))) == NULL) + size_t realloc_size = safe_multiply_size_t(sizeof(char*), (*token_count)); + if (realloc_size == SIZE_MAX || + (temp_token = (char**)realloc(*tokens, realloc_size)) == NULL) { // Codes_SRS_STRING_TOKENIZER_09_026: [ If any failures splitting or storing the tokens occur the function shall return a non-zero value ] - LogError("Failed re-allocating the token array"); + LogError("Failed re-allocating the token array, size=%zu", realloc_size); (*token_count)--; result = MU_FAILURE; break; @@ -337,14 +352,16 @@ int StringToken_Split(const char* source, size_t length, const char** delimiters else { *tokens = temp_token; + size_t malloc_size; if (tokenLength == 0) { (*tokens)[(*token_count) - 1] = NULL; } - else if (((*tokens)[(*token_count) - 1] = (char*)malloc(sizeof(char) * (tokenLength + 1))) == NULL) + else if ((malloc_size = safe_multiply_size_t(safe_add_size_t(tokenLength, 1), sizeof(char))) == SIZE_MAX || + ((*tokens)[(*token_count) - 1] = (char*)malloc(malloc_size)) == NULL) { // Codes_SRS_STRING_TOKENIZER_09_026: [ If any failures splitting or storing the tokens occur the function shall return a non-zero value ] - LogError("Failed copying token into array"); + LogError("Failed copying token into array, size=%zu", malloc_size); *token_count = (*token_count) - 1; result = MU_FAILURE; break; diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/strings.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/strings.c index ed4d30767..1cd7e6521 100755 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/strings.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/strings.c @@ -10,6 +10,7 @@ #include "azure_c_shared_utility/strings.h" #include "azure_c_shared_utility/optimize_size.h" #include "azure_c_shared_utility/xlogging.h" +#include "azure_c_shared_utility/safe_math.h" static const char hexToASCII[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; @@ -57,16 +58,18 @@ STRING_HANDLE STRING_clone(STRING_HANDLE handle) { STRING* source = (STRING*)handle; /*Codes_SRS_STRING_02_003: [If STRING_clone fails for any reason, it shall return NULL.] */ - size_t sourceLen = strlen(source->s); - if ((result->s = (char*)malloc(sourceLen + 1)) == NULL) + size_t sourceLen = safe_add_size_t(strlen(source->s), 1); + + if (sourceLen == SIZE_MAX || + (result->s = (char*)malloc(sourceLen)) == NULL) { - LogError("Failure allocating clone value."); + LogError("Failure allocating clone value. size=%zu", sourceLen); free(result); result = NULL; } else { - (void)memcpy(result->s, source->s, sourceLen + 1); + (void)memcpy(result->s, source->s, sourceLen); } } else @@ -91,8 +94,8 @@ STRING_HANDLE STRING_construct(const char* psz) STRING* str; if ((str = (STRING*)malloc(sizeof(STRING))) != NULL) { - size_t nLen = strlen(psz) + 1; - if ((str->s = (char*)malloc(nLen)) != NULL) + size_t nLen = safe_add_size_t(strlen(psz), 1); + if (nLen != SIZE_MAX && (str->s = (char*)malloc(nLen)) != NULL) { (void)memcpy(str->s, psz, nLen); result = (STRING_HANDLE)str; @@ -100,7 +103,7 @@ STRING_HANDLE STRING_construct(const char* psz) /* Codes_SRS_STRING_07_032: [STRING_construct encounters any error it shall return a NULL value.] */ else { - LogError("Failure allocating constructed value."); + LogError("Failure allocating constructed value. size=%zu", nLen); free(str); result = NULL; } @@ -116,7 +119,7 @@ STRING_HANDLE STRING_construct(const char* psz) } #if defined(__GNUC__) -__attribute__ ((format (printf, 1, 2))) +__attribute__((format(printf, 1, 2))) #endif STRING_HANDLE STRING_construct_sprintf(const char* format, ...) { @@ -144,11 +147,11 @@ STRING_HANDLE STRING_construct_sprintf(const char* format, ...) result = (STRING*)malloc(sizeof(STRING)); if (result != NULL) { - result->s = (char*)malloc(length+1); - if (result->s != NULL) + size_t malloc_size = safe_add_size_t((size_t)length, 1); + if (malloc_size != SIZE_MAX && (result->s = (char*)malloc(malloc_size)) != NULL) { va_start(arg_list, format); - if (vsnprintf(result->s, length+1, format, arg_list) < 0) + if (vsnprintf(result->s, malloc_size, format, arg_list) < 0) { /* Codes_SRS_STRING_07_040: [If any error is encountered STRING_construct_sprintf shall return NULL.] */ free(result->s); @@ -163,7 +166,7 @@ STRING_HANDLE STRING_construct_sprintf(const char* format, ...) /* Codes_SRS_STRING_07_040: [If any error is encountered STRING_construct_sprintf shall return NULL.] */ free(result); result = NULL; - LogError("Failure: allocation sprintf value failed."); + LogError("Failure: allocation sprintf value failed. size=%zu", malloc_size); } } else @@ -229,7 +232,8 @@ STRING_HANDLE STRING_new_quoted(const char* source) else if ((result = (STRING*)malloc(sizeof(STRING))) != NULL) { size_t sourceLength = strlen(source); - if ((result->s = (char*)malloc(sourceLength + 3)) != NULL) + size_t malloc_size = safe_add_size_t(sourceLength, 3); + if (malloc_size != SIZE_MAX && (result->s = (char*)malloc(malloc_size)) != NULL) { result->s[0] = '"'; (void)memcpy(result->s + 1, source, sourceLength); @@ -239,7 +243,7 @@ STRING_HANDLE STRING_new_quoted(const char* source) else { /* Codes_SRS_STRING_07_031: [STRING_new_quoted shall return a NULL STRING_HANDLE if any error is encountered.] */ - LogError("Failure allocating quoted string value."); + LogError("Failure allocating quoted string value. size=%zu", malloc_size); free(result); result = NULL; } @@ -297,12 +301,23 @@ STRING_HANDLE STRING_new_JSON(const char* source) } else { - if ((result = (STRING*)malloc(sizeof(STRING))) == NULL) + //size_t malloc_len = vlen + 5 * nControlCharacters + nEscapeCharacters + 3; + size_t malloc_len = safe_multiply_size_t(5, nControlCharacters); + malloc_len = safe_add_size_t(malloc_len, vlen); + malloc_len = safe_add_size_t(malloc_len, nEscapeCharacters); + malloc_len = safe_add_size_t(malloc_len, 3); + + if (malloc_len == SIZE_MAX) + { + result = NULL; + LogError("malloc len overflow"); + } + else if ((result = (STRING*)malloc(sizeof(STRING))) == NULL) { /*Codes_SRS_STRING_02_021: [If the complete JSON representation cannot be produced, then STRING_new_JSON shall fail and return NULL.] */ LogError("malloc json failure"); } - else if ((result->s = (char*)malloc(vlen + 5 * nControlCharacters + nEscapeCharacters + 3)) == NULL) + else if ((result->s = (char*)malloc(malloc_len)) == NULL) { /*Codes_SRS_STRING_02_021: [If the complete JSON representation cannot be produced, then STRING_new_JSON shall fail and return NULL.] */ free(result); @@ -316,7 +331,7 @@ STRING_HANDLE STRING_new_JSON(const char* source) result->s[pos++] = '"'; for (i = 0; i < vlen; i++) { - if (source[i] <= 0x1F) + if ((source[i] <= 0x1F) && ((pos + 6) <= malloc_len)) { /*Codes_SRS_STRING_02_019: [If the character code is less than 0x20 then it shall be represented as \u00xx, where xx is the hex representation of the character code.]*/ result->s[pos++] = '\\'; @@ -326,34 +341,51 @@ STRING_HANDLE STRING_new_JSON(const char* source) result->s[pos++] = hexToASCII[(source[i] & 0xF0) >> 4]; /*high nibble*/ result->s[pos++] = hexToASCII[source[i] & 0x0F]; /*low nibble*/ } - else if (source[i] == '"') + else if ((source[i] == '"') && ((pos + 2) <= malloc_len)) { /*Codes_SRS_STRING_02_016: [If the character is " (quote) then it shall be repsented as \".] */ result->s[pos++] = '\\'; result->s[pos++] = '"'; } - else if (source[i] == '\\') + else if ((source[i] == '\\') && ((pos + 2) <= malloc_len)) { /*Codes_SRS_STRING_02_017: [If the character is \ (backslash) then it shall represented as \\.] */ result->s[pos++] = '\\'; result->s[pos++] = '\\'; } - else if (source[i] == '/') + else if ((source[i] == '/') && ((pos + 2) <= malloc_len)) { /*Codes_SRS_STRING_02_018: [If the character is / (slash) then it shall be represented as \/.] */ result->s[pos++] = '\\'; result->s[pos++] = '/'; } - else + else if (pos < malloc_len) { /*Codes_SRS_STRING_02_013: [The string shall copy the characters of source "as they are" (until the '\0' character) with the following exceptions:] */ result->s[pos++] = source[i]; } + else + { + free(result->s); + free(result); + result = NULL; + break; + } + } + + if ((pos + 1) < malloc_len) + { + /*Codes_SRS_STRING_02_020: [The string shall end with " (quote).] */ + result->s[pos++] = '"'; + /*zero terminating it*/ + result->s[pos] = '\0'; + } + else + { + free(result->s); + free(result); + result = NULL; } - /*Codes_SRS_STRING_02_020: [The string shall end with " (quote).] */ - result->s[pos++] = '"'; - /*zero terminating it*/ - result->s[pos] = '\0'; } } @@ -378,11 +410,13 @@ int STRING_concat(STRING_HANDLE handle, const char* s2) STRING* s1 = (STRING*)handle; size_t s1Length = strlen(s1->s); size_t s2Length = strlen(s2); - char* temp = (char*)realloc(s1->s, s1Length + s2Length + 1); - if (temp == NULL) + size_t realloc_size = safe_add_size_t(safe_add_size_t(s1Length, s2Length), 1); + char* temp; + if (realloc_size == SIZE_MAX || + (temp = (char*)realloc(s1->s, realloc_size)) == NULL) { /* Codes_SRS_STRING_07_013: [STRING_concat shall return a nonzero number if an error is encountered.] */ - LogError("Failure reallocating value."); + LogError("Failure reallocating value. size=%zu", realloc_size); result = MU_FAILURE; } else @@ -415,11 +449,13 @@ int STRING_concat_with_STRING(STRING_HANDLE s1, STRING_HANDLE s2) size_t s1Length = strlen(dest->s); size_t s2Length = strlen(src->s); - char* temp = (char*)realloc(dest->s, s1Length + s2Length + 1); - if (temp == NULL) + size_t realloc_size = safe_add_size_t(safe_add_size_t(s1Length, s2Length), 1); + char* temp; + if (realloc_size == SIZE_MAX || + (temp = (char*)realloc(dest->s, realloc_size)) == NULL) { /* Codes_SRS_STRING_07_035: [String_Concat_with_STRING shall return a nonzero number if an error is encountered.] */ - LogError("Failure reallocating value"); + LogError("Failure reallocating value, size:%zu", realloc_size); result = MU_FAILURE; } else @@ -452,10 +488,12 @@ int STRING_copy(STRING_HANDLE handle, const char* s2) if (s1->s != s2) { size_t s2Length = strlen(s2); - char* temp = (char*)realloc(s1->s, s2Length + 1); - if (temp == NULL) + size_t realloc_size = safe_add_size_t(s2Length, 1); + char* temp; + if (realloc_size == SIZE_MAX || + (temp = (char*)realloc(s1->s, realloc_size)) == NULL) { - LogError("Failure reallocating value."); + LogError("Failure reallocating value. size=%zu", realloc_size); /* Codes_SRS_STRING_07_027: [STRING_copy shall return a nonzero value if any error is encountered.] */ result = MU_FAILURE; } @@ -497,10 +535,11 @@ int STRING_copy_n(STRING_HANDLE handle, const char* s2, size_t n) s2Length = n; } - temp = (char*)realloc(s1->s, s2Length + 1); - if (temp == NULL) + size_t realloc_size = safe_add_size_t(s2Length, 1); + if (realloc_size == SIZE_MAX || + (temp = (char*)realloc(s1->s, realloc_size)) == NULL) { - LogError("Failure reallocating value."); + LogError("Failure reallocating value. size=%zu", realloc_size); /* Codes_SRS_STRING_07_028: [STRING_copy_n shall return a nonzero value if any error is encountered.] */ result = MU_FAILURE; } @@ -517,7 +556,7 @@ int STRING_copy_n(STRING_HANDLE handle, const char* s2, size_t n) } #if defined(__GNUC__) -__attribute__ ((format (printf, 2, 3))) +__attribute__((format(printf, 2, 3))) #endif int STRING_sprintf(STRING_HANDLE handle, const char* format, ...) { @@ -561,12 +600,13 @@ int STRING_sprintf(STRING_HANDLE handle, const char* format, ...) STRING* s1 = (STRING*)handle; char* temp; size_t s1Length = strlen(s1->s); - temp = (char*)realloc(s1->s, s1Length + s2Length + 1); - if (temp != NULL) + size_t realloc_size = safe_add_size_t(safe_add_size_t(s1Length, s2Length), 1); + if (realloc_size != SIZE_MAX && + (temp = (char*)realloc(s1->s, realloc_size)) != NULL) { s1->s = temp; va_start(arg_list, format); - if (vsnprintf(s1->s + s1Length, s1Length + s2Length + 1, format, arg_list) < 0) + if (vsnprintf(s1->s + s1Length, realloc_size, format, arg_list) < 0) { /* Codes_SRS_STRING_07_043: [If any error is encountered STRING_sprintf shall return a non zero value.] */ LogError("Failure vsnprintf formatting error"); @@ -583,7 +623,7 @@ int STRING_sprintf(STRING_HANDLE handle, const char* format, ...) else { /* Codes_SRS_STRING_07_043: [If any error is encountered STRING_sprintf shall return a non zero value.] */ - LogError("Failure unable to reallocate memory"); + LogError("Failure unable to reallocate memory. size=%zu", realloc_size); result = MU_FAILURE; } } @@ -607,10 +647,12 @@ int STRING_quote(STRING_HANDLE handle) { STRING* s1 = (STRING*)handle; size_t s1Length = strlen(s1->s); - char* temp = (char*)realloc(s1->s, s1Length + 2 + 1);/*2 because 2 quotes, 1 because '\0'*/ - if (temp == NULL) + size_t realloc_size = safe_add_size_t(safe_add_size_t(s1Length, 2), 1); /*2 because 2 quotes, 1 because '\0'*/ + char* temp; + if (realloc_size == SIZE_MAX || + (temp = (char*)realloc(s1->s, realloc_size)) == NULL) { - LogError("Failure reallocating value."); + LogError("Failure reallocating value. size=%zu", realloc_size); /* Codes_SRS_STRING_07_029: [STRING_quote shall return a nonzero value if any error is encountered.] */ result = MU_FAILURE; } @@ -724,7 +766,9 @@ STRING_HANDLE STRING_construct_n(const char* psz, size_t n) STRING* str; if ((str = (STRING*)malloc(sizeof(STRING))) != NULL) { - if ((str->s = (char*)malloc(len + 1)) != NULL) + size_t malloc_size = safe_add_size_t(len, 1); + if (malloc_size != SIZE_MAX && + (str->s = (char*)malloc(malloc_size)) != NULL) { (void)memcpy(str->s, psz, n); str->s[n] = '\0'; @@ -733,7 +777,7 @@ STRING_HANDLE STRING_construct_n(const char* psz, size_t n) /* Codes_SRS_STRING_02_010: [In all other error cases, STRING_construct_n shall return NULL.] */ else { - LogError("Failure allocating value."); + LogError("Failure allocating value. size=%zu", malloc_size); free(str); result = NULL; } @@ -799,11 +843,12 @@ STRING_HANDLE STRING_from_byte_array(const unsigned char* source, size_t size) else { /*Codes_SRS_STRING_02_023: [ Otherwise, STRING_from_BUFFER shall build a string that has the same content (byte-by-byte) as source and return a non-NULL handle. ]*/ - result->s = (char*)malloc(size + 1); - if (result->s == NULL) + size_t malloc_size = safe_add_size_t(size, 1); + if (malloc_size == SIZE_MAX || + (result->s = (char*)malloc(malloc_size)) == NULL) { /*Codes_SRS_STRING_02_024: [ If building the string fails, then STRING_from_BUFFER shall fail and return NULL. ]*/ - LogError("oom - unable to malloc"); + LogError("oom - unable to malloc, size=%zu", malloc_size); free(result); result = NULL; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/urlencode.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/urlencode.c index fb2a7b5e8..45fbc0fa1 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/urlencode.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/urlencode.c @@ -8,6 +8,7 @@ #include "azure_c_shared_utility/xlogging.h" #include "azure_c_shared_utility/strings.h" #include "azure_c_shared_utility/crt_abstractions.h" +#include "azure_c_shared_utility/safe_math.h" #define NIBBLE_TO_STRING(c) (char)((c) < 10 ? (c) + '0' : (c) - 10 + 'a') #define NIBBLE_FROM_STRING(c) (char)(ISDIGIT(c) ? (c) - '0' : TOUPPER(c) + 10 - 'A') @@ -136,7 +137,7 @@ static size_t calculateDecodedStringSize(const char* encodedString, size_t len) } else { - decodedSize++; + decodedSize = safe_add_size_t(decodedSize, 1); next_step = 3; } } @@ -148,7 +149,7 @@ static size_t calculateDecodedStringSize(const char* encodedString, size_t len) //safe character else { - decodedSize++; + decodedSize = safe_add_size_t(decodedSize, 1); next_step = 1; } @@ -162,7 +163,8 @@ static size_t calculateDecodedStringSize(const char* encodedString, size_t len) } else { - decodedSize++; //add space for the null terminator + //add space for the null terminator + decodedSize = safe_add_size_t(decodedSize, 1); } } return decodedSize; @@ -229,14 +231,15 @@ static STRING_HANDLE encode_url_data(const char* text) do { currentUnsignedChar = (unsigned char)(*iterator++); - lengthOfResult += URL_PrintableCharSize(currentUnsignedChar); + lengthOfResult = safe_add_size_t(lengthOfResult, URL_PrintableCharSize(currentUnsignedChar)); } while (currentUnsignedChar != 0); - if ((encodedURL = (char*)malloc(lengthOfResult)) == NULL) + if (lengthOfResult == SIZE_MAX || + (encodedURL = (char*)malloc(lengthOfResult)) == NULL) { /*Codes_SRS_URL_ENCODE_06_002: [If an error occurs during the encoding of input then URL_Encode will return NULL.]*/ result = NULL; - LogError("URL_Encode:: MALLOC failure on encode."); + LogError("URL_Encode:: MALLOC failure on encode. size=%zu", lengthOfResult); } else { diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/uuid.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/uuid.c index 7a8462ab2..4ce0aba13 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/uuid.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/uuid.c @@ -8,11 +8,20 @@ #include "azure_c_shared_utility/uniqueid.h" #include "azure_c_shared_utility/optimize_size.h" #include "azure_c_shared_utility/xlogging.h" +#include "azure_c_shared_utility/safe_math.h" #define UUID_STRING_LENGTH 36 #define UUID_STRING_SIZE (UUID_STRING_LENGTH + 1) #define __SUCCESS__ 0 -#define UUID_FORMAT_STRING "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x" +#define HEXA_DIGIT_VAL(c) \ + ((((c) >= '0') && ((c) <= '9')) \ + ? ((c) - '0') \ + : (((c) >= 'a') && ((c) <= 'f')) \ + ? ((c) - 'a' + 10) \ + : (((c) >= 'A') && ((c) <= 'F')) ? ((c) - 'A' + 10) : -1) +#define MUST_BE_DASH(pos) \ + (pos == 8 || pos == 13 || pos == 18 || pos == 23) + int UUID_from_string(const char* uuid_string, UUID_T* uuid) { @@ -47,15 +56,30 @@ int UUID_from_string(const char* uuid_string, UUID_T* uuid) { if (uuid_string[i] == '-') { - i++; + if (!MUST_BE_DASH(i)) + { + // Codes_SRS_UUID_09_009: [ If uuid fails to be generated, UUID_from_string shall return a non-zero value ] + LogError("Failed decoding UUID string (%lu)", (unsigned long)i); + result = MU_FAILURE; + break; + } + else + { + i++; + } } else { - char double_hex_digit[3] = { 0, 0, 0 }; - - (void)memcpy(double_hex_digit, uuid_string + i, 2); - - if (sscanf(double_hex_digit, "%02hhx", uuid_bytes + j) != 1) + int higherOrderDigit = HEXA_DIGIT_VAL(uuid_string[i]); + int lowerOrderDigit = HEXA_DIGIT_VAL(uuid_string[i + 1]); + +#ifdef _MSC_VER +#pragma warning(disable:6328) // warning C6328: Size mismatch +#endif + if (higherOrderDigit == -1 || lowerOrderDigit == -1) +#ifdef _MSC_VER +#pragma warning (default:6328) +#endif { // Codes_SRS_UUID_09_009: [ If uuid fails to be generated, UUID_from_string shall return a non-zero value ] LogError("Failed decoding UUID string (%lu)", (unsigned long)i); @@ -64,6 +88,8 @@ int UUID_from_string(const char* uuid_string, UUID_T* uuid) } else { + // Multiplying the higherOrderDigit by 16. + uuid_bytes[j] = (char)((higherOrderDigit << 4) + lowerOrderDigit); i += 2; j++; } @@ -78,6 +104,7 @@ int UUID_from_string(const char* uuid_string, UUID_T* uuid) char* UUID_to_string(const UUID_T* uuid) { char* result; + size_t malloc_size; // Codes_SRS_UUID_09_011: [ If uuid is NULL, UUID_to_string shall return a non-zero value ] if (uuid == NULL) @@ -85,8 +112,13 @@ char* UUID_to_string(const UUID_T* uuid) LogError("Invalid argument (uuid is NULL)"); result = NULL; } + else if ((malloc_size = safe_multiply_size_t(sizeof(char), UUID_STRING_SIZE)) == SIZE_MAX) + { + LogError("Invalid malloc size"); + result = NULL; + } // Codes_SRS_UUID_09_012: [ UUID_to_string shall allocate a valid UUID string (uuid_string) as per RFC 4122 ] - else if ((result = (char*)malloc(sizeof(char) * UUID_STRING_SIZE)) == NULL) + else if ((result = (char*)malloc(malloc_size)) == NULL) { // Codes_SRS_UUID_09_013: [ If uuid_string fails to be allocated, UUID_to_string shall return NULL ] LogError("Failed allocating UUID string"); @@ -128,11 +160,12 @@ int UUID_generate(UUID_T* uuid) else { char* uuid_string; - - if ((uuid_string = (char*)malloc(sizeof(char) * UUID_STRING_SIZE)) == NULL) + size_t malloc_size; + if ((malloc_size = safe_multiply_size_t(sizeof(char), UUID_STRING_SIZE)) == SIZE_MAX || + (uuid_string = (char*)malloc(malloc_size)) == NULL) { // Codes_SRS_UUID_09_003: [ If the UUID string fails to be obtained, UUID_generate shall fail and return a non-zero value ] - LogError("Failed allocating UUID string"); + LogError("Failed allocating UUID string, size=%zu", malloc_size); result = MU_FAILURE; } else diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/uws_client.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/uws_client.c index 607b6116c..d94392a31 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/uws_client.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/uws_client.c @@ -20,11 +20,12 @@ #include "azure_c_shared_utility/uws_frame_encoder.h" #include "azure_c_shared_utility/crt_abstractions.h" #include "azure_c_shared_utility/utf8_checker.h" -#include "azure_c_shared_utility/gb_rand.h" +#include "azure_c_shared_utility/random.h" #include "azure_c_shared_utility/azure_base64.h" #include "azure_c_shared_utility/optionhandler.h" #include "azure_c_shared_utility/map.h" #include "azure_c_shared_utility/shared_util_options.h" +#include "azure_c_shared_utility/safe_math.h" static const char* UWS_CLIENT_OPTIONS = "uWSClientOptions"; @@ -96,6 +97,7 @@ typedef struct UWS_CLIENT_INSTANCE_TAG ON_WS_CLOSE_COMPLETE on_ws_close_complete; void* on_ws_close_complete_context; unsigned char* stream_buffer; + size_t stream_buffer_size; size_t stream_buffer_count; unsigned char* fragment_buffer; size_t fragment_buffer_count; @@ -290,11 +292,12 @@ UWS_CLIENT_HANDLE uws_client_create(const char* hostname, unsigned int port, con } else { - result->protocols = (WS_INSTANCE_PROTOCOL*)malloc(sizeof(WS_INSTANCE_PROTOCOL) * protocol_count); - if (result->protocols == NULL) + size_t malloc_size = safe_multiply_size_t(sizeof(WS_INSTANCE_PROTOCOL), protocol_count); + if (malloc_size == SIZE_MAX || + (result->protocols = (WS_INSTANCE_PROTOCOL*)malloc(malloc_size)) == NULL) { /* Codes_SRS_UWS_CLIENT_01_414: [ If allocating memory for the copied protocol information fails then uws_client_create shall fail and return NULL. ]*/ - LogError("Cannot allocate memory for the protocols array."); + LogError("Cannot allocate memory for the protocols array. size=%zu", malloc_size); xio_destroy(result->underlying_io); singlylinkedlist_destroy(result->pending_sends); Map_Destroy(result->request_headers); @@ -473,11 +476,12 @@ UWS_CLIENT_HANDLE uws_client_create_with_io(const IO_INTERFACE_DESCRIPTION* io_i } else { - result->protocols = (WS_INSTANCE_PROTOCOL*)malloc(sizeof(WS_INSTANCE_PROTOCOL) * protocol_count); - if (result->protocols == NULL) + size_t malloc_size = safe_multiply_size_t(sizeof(WS_INSTANCE_PROTOCOL), protocol_count); + if (malloc_size == SIZE_MAX || + (result->protocols = (WS_INSTANCE_PROTOCOL*)malloc(malloc_size)) == NULL) { /* Codes_SRS_UWS_CLIENT_01_414: [ If allocating memory for the copied protocol information fails then uws_client_create shall fail and return NULL. ]*/ - LogError("Cannot allocate memory for the protocols array."); + LogError("Cannot allocate memory for the protocols array. size=%zu", malloc_size); xio_destroy(result->underlying_io); singlylinkedlist_destroy(result->pending_sends); Map_Destroy(result->request_headers); @@ -545,6 +549,8 @@ void uws_client_destroy(UWS_CLIENT_HANDLE uws_client) { free(uws_client->stream_buffer); free(uws_client->fragment_buffer); + uws_client->stream_buffer = NULL; + uws_client->fragment_buffer = NULL; /* Codes_SRS_UWS_CLIENT_01_021: [ uws_client_destroy shall perform a close action if the uws instance has already been open. ]*/ switch (uws_client->uws_state) @@ -566,9 +572,11 @@ void uws_client_destroy(UWS_CLIENT_HANDLE uws_client) for (i = 0; i < uws_client->protocol_count; i++) { free(uws_client->protocols[i].protocol); + uws_client->protocols[i].protocol = NULL; } free(uws_client->protocols); + uws_client->protocols = NULL; } /* Codes_SRS_UWS_CLIENT_01_019: [ uws_client_destroy shall free all resources associated with the uws instance. ]*/ @@ -700,9 +708,11 @@ static char* get_request_headers(MAP_HANDLE headers) length += strlen(keys[i]) + strlen(values[i]) + 4; } - if ((result = (char*)malloc(sizeof(char) * (length + 1))) == NULL) + size_t malloc_size = safe_multiply_size_t(safe_add_size_t(length, 1), sizeof(char)); + if (malloc_size == SIZE_MAX || + (result = (char*)malloc(malloc_size)) == NULL) { - LogError("Failed allocating string for request headers"); + LogError("Failed allocating string for request headers, size=%zu", malloc_size); result = NULL; } else @@ -776,7 +786,7 @@ static void on_underlying_io_open_complete(void* context, IO_OPEN_RESULT open_re /* Codes_SRS_UWS_CLIENT_01_090: [ The nonce MUST be selected randomly for each connection. ]*/ for (i = 0; i < sizeof(nonce); i++) { - nonce[i] = (unsigned char)gb_rand(); + nonce[i] = (unsigned char)RANDOM_generate(); } /* Codes_SRS_UWS_CLIENT_01_497: [ The nonce needed for the upgrade request shall be Base64 encoded with Azure_Base64_Encode_Bytes. ]*/ @@ -829,8 +839,9 @@ static void on_underlying_io_open_complete(void* context, IO_OPEN_RESULT open_re } else { - upgrade_request = (char*)malloc(upgrade_request_length + 1); - if (upgrade_request == NULL) + size_t malloc_size = safe_add_size_t((size_t)upgrade_request_length, 1); + if (malloc_size == SIZE_MAX || + (upgrade_request = (char*)malloc(malloc_size)) == NULL) { /* Codes_SRS_UWS_CLIENT_01_406: [ If not enough memory can be allocated to construct the WebSocket upgrade request, uws shall report that the open failed by calling the on_ws_open_complete callback passed to uws_client_open_async with WS_OPEN_ERROR_NOT_ENOUGH_MEMORY. ]*/ LogError("Cannot allocate memory for the WebSocket upgrade request"); @@ -863,6 +874,7 @@ static void on_underlying_io_open_complete(void* context, IO_OPEN_RESULT open_re } free(upgrade_request); + upgrade_request = NULL; } } @@ -1041,8 +1053,10 @@ static int ParseHttpResponse(const char* src, int* dst) static int process_frame_fragment(UWS_CLIENT_INSTANCE *uws_client, size_t length, size_t needed_bytes) { int result; - unsigned char *new_fragment_bytes = (unsigned char *)realloc(uws_client->fragment_buffer, uws_client->fragment_buffer_count + length); - if (new_fragment_bytes == NULL) + unsigned char* new_fragment_bytes; + size_t realloc_size = safe_add_size_t(uws_client->fragment_buffer_count, length); + if (realloc_size == SIZE_MAX || + (new_fragment_bytes = (unsigned char*)realloc(uws_client->fragment_buffer, realloc_size)) == NULL) { /* Codes_SRS_UWS_CLIENT_01_379: [ If allocating memory for accumulating the bytes fails, uws shall report that the open failed by calling the on_ws_open_complete callback passed to uws_client_open_async with WS_OPEN_ERROR_NOT_ENOUGH_MEMORY. ]*/ LogError("Cannot allocate memory for received data"); @@ -1093,8 +1107,12 @@ static void on_underlying_io_bytes_received(void* context, const unsigned char* case UWS_STATE_WAITING_FOR_UPGRADE_RESPONSE: { /* Codes_SRS_UWS_CLIENT_01_378: [ When on_underlying_io_bytes_received is called while the uws is OPENING, the received bytes shall be accumulated in order to attempt parsing the WebSocket Upgrade response. ]*/ - unsigned char* new_received_bytes = (unsigned char*)realloc(uws_client->stream_buffer, uws_client->stream_buffer_count + size + 1); - if (new_received_bytes == NULL) + unsigned char* new_received_bytes; + + //size_t realloc_size = uws_client->stream_buffer_count + size + 1; **using safe int** + uws_client->stream_buffer_size = safe_add_size_t(safe_add_size_t(uws_client->stream_buffer_count, size), 1); + if (uws_client->stream_buffer_size == SIZE_MAX || + (new_received_bytes = (unsigned char*)realloc(uws_client->stream_buffer, uws_client->stream_buffer_size)) == NULL) { /* Codes_SRS_UWS_CLIENT_01_379: [ If allocating memory for accumulating the bytes fails, uws shall report that the open failed by calling the on_ws_open_complete callback passed to uws_client_open_async with WS_OPEN_ERROR_NOT_ENOUGH_MEMORY. ]*/ indicate_ws_open_complete_error_and_close(uws_client, WS_OPEN_ERROR_NOT_ENOUGH_MEMORY); @@ -1116,8 +1134,12 @@ static void on_underlying_io_bytes_received(void* context, const unsigned char* case UWS_STATE_CLOSING_WAITING_FOR_CLOSE: { /* Codes_SRS_UWS_CLIENT_01_385: [ If the state of the uws instance is OPEN, the received bytes shall be used for decoding WebSocket frames. ]*/ - unsigned char* new_received_bytes = (unsigned char*)realloc(uws_client->stream_buffer, uws_client->stream_buffer_count + size + 1); - if (new_received_bytes == NULL) + unsigned char* new_received_bytes; + + //size_t realloc_size = uws_client->stream_buffer_count + size + 1; **using safe int** + uws_client->stream_buffer_size = safe_add_size_t(safe_add_size_t(uws_client->stream_buffer_count, size), 1); + if (uws_client->stream_buffer_size == SIZE_MAX || + (new_received_bytes = (unsigned char*)realloc(uws_client->stream_buffer, uws_client->stream_buffer_size)) == NULL) { /* Codes_SRS_UWS_CLIENT_01_418: [ If allocating memory for the bytes accumulated for decoding WebSocket frames fails, an error shall be indicated by calling the on_ws_error callback with WS_ERROR_NOT_ENOUGH_MEMORY. ]*/ LogError("Cannot allocate memory for received data"); @@ -1211,7 +1233,9 @@ static void on_underlying_io_bytes_received(void* context, const unsigned char* /* Codes_SRS_UWS_CLIENT_01_277: [ To receive WebSocket data, an endpoint listens on the underlying network connection. ]*/ /* Codes_SRS_UWS_CLIENT_01_278: [ Incoming data MUST be parsed as WebSocket frames as defined in Section 5.2. ]*/ - if (uws_client->stream_buffer_count >= needed_bytes) + if (uws_client->stream_buffer_count >= needed_bytes && + uws_client->stream_buffer_size > 1 // validate uws_client->stream_buffer[1] access + ) { unsigned char has_error = 0; @@ -1232,7 +1256,9 @@ static void on_underlying_io_bytes_received(void* context, const unsigned char* { /* Codes_SRS_UWS_CLIENT_01_165: [ If 126, the following 2 bytes interpreted as a 16-bit unsigned integer are the payload length. ]*/ needed_bytes += 2; - if (uws_client->stream_buffer_count >= needed_bytes) + if (uws_client->stream_buffer_count >= needed_bytes && + uws_client->stream_buffer_size > 3 // validate access upto stream_buffer[3] + ) { /* Codes_SRS_UWS_CLIENT_01_167: [ Multibyte length quantities are expressed in network byte order. ]*/ length = ((size_t)(uws_client->stream_buffer[2]) << 8) + (size_t)uws_client->stream_buffer[3]; @@ -1248,7 +1274,7 @@ static void on_underlying_io_bytes_received(void* context, const unsigned char* } else { - needed_bytes += (size_t)length; + needed_bytes = safe_add_size_t(needed_bytes, length); } } } @@ -1258,7 +1284,7 @@ static void on_underlying_io_bytes_received(void* context, const unsigned char* needed_bytes += 8; if (uws_client->stream_buffer_count >= needed_bytes) { - if ((uws_client->stream_buffer[2] & 0x80) != 0) + if (uws_client->stream_buffer_size <= 2 || (uws_client->stream_buffer[2] & 0x80) != 0) { LogError("Bad frame: received a 64 bit length frame with the highest bit set"); @@ -1266,10 +1292,15 @@ static void on_underlying_io_bytes_received(void* context, const unsigned char* indicate_ws_error(uws_client, WS_ERROR_BAD_FRAME_RECEIVED); has_error = 1; } + else if (uws_client->stream_buffer_size <= 9) // validate access upto stream_buffer[9] below + { + indicate_ws_error(uws_client, WS_ERROR_BAD_FRAME_RECEIVED); + has_error = 1; + } else { /* Codes_SRS_UWS_CLIENT_01_167: [ Multibyte length quantities are expressed in network byte order. ]*/ - length = (size_t)(((uint64_t)(uws_client->stream_buffer[2]) << 56) + + uint64_t length_uint64 = (((uint64_t)(uws_client->stream_buffer[2]) << 56) + (((uint64_t)uws_client->stream_buffer[3]) << 48) + (((uint64_t)uws_client->stream_buffer[4]) << 40) + (((uint64_t)uws_client->stream_buffer[5]) << 32) + @@ -1278,7 +1309,12 @@ static void on_underlying_io_bytes_received(void* context, const unsigned char* (((uint64_t)uws_client->stream_buffer[8]) << 8) + (uint64_t)(uws_client->stream_buffer[9])); - if (length < 65536) + length = (size_t)(length_uint64); + needed_bytes = safe_add_size_t(needed_bytes, length); + + if (length < 65536 || + length_uint64 >= (SIZE_MAX/2) || // limit max pack size to 1/2 process memory + needed_bytes == SIZE_MAX) { /* Codes_SRS_UWS_CLIENT_01_168: [ Note that in all cases, the minimal number of bytes MUST be used to encode the length, for example, the length of a 124-byte-long string can't be encoded as the sequence 126, 0, 124. ]*/ LogError("Bad frame: received a %u length on the 64 bit length", (unsigned int)length); @@ -1287,16 +1323,12 @@ static void on_underlying_io_bytes_received(void* context, const unsigned char* indicate_ws_error(uws_client, WS_ERROR_BAD_FRAME_RECEIVED); has_error = 1; } - else - { - needed_bytes += length; - } } } } else { - needed_bytes += length; + needed_bytes = safe_add_size_t(needed_bytes, length); } if ((has_error == 0) && @@ -1391,7 +1423,19 @@ static void on_underlying_io_bytes_received(void* context, const unsigned char* /* Codes_SRS_UWS_CLIENT_01_282: [ If the frame comprises an unfragmented message (Section 5.4), it is said that _A WebSocket Message Has Been Received_ with type /type/ and data /data/. ]*/ if (is_final) { - uws_client->on_ws_frame_received(uws_client->on_ws_frame_received_context, WS_FRAME_TYPE_BINARY, uws_client->stream_buffer + needed_bytes - length, length); + size_t stream_buffer_idx = safe_add_size_t(uws_client->stream_buffer, needed_bytes); + stream_buffer_idx = safe_subtract_size_t(stream_buffer_idx, length); + if (stream_buffer_idx != SIZE_MAX) + { + uws_client->on_ws_frame_received(uws_client->on_ws_frame_received_context, WS_FRAME_TYPE_BINARY, (const unsigned char*)stream_buffer_idx, length); + } + else + { + LogError("Invalid packet length, stream_buffer_idx=%zu", stream_buffer_idx); + indicate_ws_error(uws_client, WS_ERROR_BAD_FRAME_RECEIVED); + decode_stream = 1; + break; + } } else { diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/uws_frame_encoder.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/uws_frame_encoder.c index cd74d9cc1..6da2e3487 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/uws_frame_encoder.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/uws_frame_encoder.c @@ -5,7 +5,7 @@ #include #include #include "azure_c_shared_utility/gballoc.h" -#include "azure_c_shared_utility/gb_rand.h" +#include "azure_c_shared_utility/random.h" #include "azure_c_shared_utility/uws_frame_encoder.h" #include "azure_c_shared_utility/xlogging.h" #include "azure_c_shared_utility/buffer_.h" @@ -148,17 +148,17 @@ BUFFER_HANDLE uws_frame_encoder_encode(WS_FRAME_TYPE opcode, const unsigned char /* Codes_SRS_UWS_FRAME_ENCODER_01_033: [ A masked frame MUST have the field frame-masked set to 1, as defined in Section 5.2. ]*/ buffer[1] |= 0x80; - /* Codes_SRS_UWS_FRAME_ENCODER_01_053: [ In order to obtain a 32 bit value for masking, gb_rand shall be used 4 times (for each byte). ]*/ + /* Codes_SRS_UWS_FRAME_ENCODER_01_053: [ In order to obtain a 32 bit value for masking, RANDOM_generate shall be used 4 times (for each byte). ]*/ /* Codes_SRS_UWS_FRAME_ENCODER_01_016: [ If set to 1, a masking key is present in masking-key, and this is used to unmask the "Payload data" as per Section 5.3. ]*/ /* Codes_SRS_UWS_FRAME_ENCODER_01_026: [ This field is present if the mask bit is set to 1 and is absent if the mask bit is set to 0. ]*/ /* Codes_SRS_UWS_FRAME_ENCODER_01_034: [ The masking key is contained completely within the frame, as defined in Section 5.2 as frame-masking-key. ]*/ /* Codes_SRS_UWS_FRAME_ENCODER_01_036: [ The masking key is a 32-bit value chosen at random by the client. ]*/ /* Codes_SRS_UWS_FRAME_ENCODER_01_037: [ When preparing a masked frame, the client MUST pick a fresh masking key from the set of allowed 32-bit values. ]*/ /* Codes_SRS_UWS_FRAME_ENCODER_01_038: [ The masking key needs to be unpredictable; thus, the masking key MUST be derived from a strong source of entropy, and the masking key for a given frame MUST NOT make it simple for a server/proxy to predict the masking key for a subsequent frame. ]*/ - buffer[header_bytes - 4] = (unsigned char)gb_rand(); - buffer[header_bytes - 3] = (unsigned char)gb_rand(); - buffer[header_bytes - 2] = (unsigned char)gb_rand(); - buffer[header_bytes - 1] = (unsigned char)gb_rand(); + buffer[header_bytes - 4] = (unsigned char)RANDOM_generate(); + buffer[header_bytes - 3] = (unsigned char)RANDOM_generate(); + buffer[header_bytes - 2] = (unsigned char)RANDOM_generate(); + buffer[header_bytes - 1] = (unsigned char)RANDOM_generate(); } if (length > 0) diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/vector.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/vector.c index b4f872834..0f1923d05 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/vector.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/src/vector.c @@ -6,6 +6,7 @@ #include "azure_c_shared_utility/vector.h" #include "azure_c_shared_utility/optimize_size.h" #include "azure_c_shared_utility/xlogging.h" +#include "azure_c_shared_utility/safe_math.h" #include "azure_c_shared_utility/vector_types_internal.h" @@ -102,11 +103,13 @@ IMPLEMENT_MOCKABLE_FUNCTION(, int, VECTOR_push_back, VECTOR_HANDLE, handle, cons size_t curSize = handle->elementSize * handle->count; size_t appendSize = handle->elementSize * numElements; - void* temp = realloc(handle->storage, curSize + appendSize); - if (temp == NULL) + void* temp; + size_t realloc_size = safe_add_size_t(curSize, appendSize); + if (realloc_size == SIZE_MAX || + (temp = realloc(handle->storage, realloc_size)) == NULL) { /* Codes_SRS_VECTOR_10_012: [VECTOR_push_back shall fail and return non-zero if memory allocation fails.] */ - LogError("realloc failed."); + LogError("realloc failed. size=%zu", realloc_size); result = MU_FAILURE; } else @@ -170,10 +173,11 @@ IMPLEMENT_MOCKABLE_FUNCTION(, void, VECTOR_erase, VECTOR_HANDLE, handle, void*, { void* tmp; (void)memmove(elements, src, srcEnd - src); - tmp = realloc(handle->storage, (handle->elementSize * handle->count)); - if (tmp == NULL) + size_t realloc_size = safe_multiply_size_t(handle->elementSize, handle->count); + if (realloc_size == SIZE_MAX || + (tmp = realloc(handle->storage, realloc_size)) == NULL) { - LogInfo("realloc failed. Keeping original internal storage pointer."); + LogInfo("realloc failed. Keeping original internal storage pointer. size=%zu", realloc_size); } else { diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/CMakeLists.txt b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/CMakeLists.txt index 2cfc2d475..cb5e5750f 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/CMakeLists.txt +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/CMakeLists.txt @@ -30,7 +30,7 @@ if(${run_unittests}) add_subdirectory(httpapicompact_ut) endif() add_subdirectory(singlylinkedlist_ut) - add_subdirectory(lock_ut) + add_subdirectory(lock_ut) add_subdirectory(map_ut) add_subdirectory(refcount_ut) add_subdirectory(sastoken_ut) @@ -46,8 +46,9 @@ if(${run_unittests}) endif() #normally, with proper include paths, the below tests can be run under windows too. - if(${use_openssl}) - add_subdirectory(x509_openssl_ut) + if(${use_openssl} AND NOT DEFINED MACOSX) + add_subdirectory(x509_openssl_ut/engine) + add_subdirectory(x509_openssl_ut/no_engine) endif() add_subdirectory(string_tokenizer_ut) @@ -91,9 +92,9 @@ if(${run_unittests}) add_subdirectory(utf8_checker_ut) add_subdirectory(http_proxy_io_ut) - if(NOT DEFINED MACOSX) - #add_subdirectory(socket_async_ut) - #add_subdirectory(dns_resolver_ut) + if(DEFINED LINUX) + add_subdirectory(dns_resolver_ut) + add_subdirectory(socket_async_ut) endif() #Add template as reference for new tests diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/agenttime_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/agenttime_ut/main.c index b12e6f59c..001d46964 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/agenttime_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/agenttime_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(agenttime_unittests, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/azure_base32_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/azure_base32_ut/main.c index 48c154fbc..e044a6ee6 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/azure_base32_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/azure_base32_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(azure_base32_ut, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/azure_base64_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/azure_base64_ut/main.c index f0b93c935..0b29efa3e 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/azure_base64_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/azure_base64_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(base64_unittests, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/condition_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/condition_ut/main.c index e609717a2..cd0344af8 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/condition_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/condition_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(Condition_UnitTests, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/connectionstringparser_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/connectionstringparser_ut/main.c index 2072f9581..9fcd26cac 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/connectionstringparser_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/connectionstringparser_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(connectionstringparser_ut, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/constbuffer_array_batcher_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/constbuffer_array_batcher_ut/main.c index 5b20a8548..403e292ce 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/constbuffer_array_batcher_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/constbuffer_array_batcher_ut/main.c @@ -7,5 +7,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(constbuffer_array_batcher_unittests, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/constbuffer_array_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/constbuffer_array_ut/main.c index 4ead7f313..7f7bebd11 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/constbuffer_array_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/constbuffer_array_ut/main.c @@ -7,5 +7,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(constbuffer_array_unittests, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/constbuffer_ut/CMakeLists.txt b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/constbuffer_ut/CMakeLists.txt index 2ce9a387a..6a2088b68 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/constbuffer_ut/CMakeLists.txt +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/constbuffer_ut/CMakeLists.txt @@ -16,3 +16,4 @@ set(${theseTestsName}_h_files build_c_test_artifacts(${theseTestsName} ON "tests/azure_c_shared_utility_tests") +compile_c_test_artifacts_as(${theseTestsName} C99) diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/constmap_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/constmap_ut/main.c index 1849913f9..588e0fc75 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/constmap_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/constmap_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(constmap_unittests, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/crtabstractions_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/crtabstractions_ut/main.c index 67b967dc8..3fcc3e387 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/crtabstractions_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/crtabstractions_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(CRTAbstractions_UnitTests, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/dns_resolver_ut/dns_resolver_ut.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/dns_resolver_ut/dns_resolver_ut.c index 5ea9e3404..128fa0642 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/dns_resolver_ut/dns_resolver_ut.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/dns_resolver_ut/dns_resolver_ut.c @@ -39,6 +39,11 @@ void* my_gballoc_malloc(size_t size) return malloc(size); } +void* my_gballoc_calloc(size_t nmemb, size_t size) +{ + return calloc(nmemb, size); +} + void* my_gballoc_realloc(void* ptr, size_t size) { return realloc(ptr, size); @@ -140,6 +145,7 @@ BEGIN_TEST_SUITE(dns_resolver_ut) ASSERT_ARE_EQUAL(int, 0, result); REGISTER_GLOBAL_MOCK_HOOK(gballoc_malloc, my_gballoc_malloc); + REGISTER_GLOBAL_MOCK_HOOK(gballoc_calloc, my_gballoc_calloc); REGISTER_GLOBAL_MOCK_FAIL_RETURN(gballoc_malloc, NULL); REGISTER_GLOBAL_MOCK_HOOK(gballoc_free, my_gballoc_free); @@ -187,7 +193,7 @@ BEGIN_TEST_SUITE(dns_resolver_ut) TEST_FUNCTION(dns_resolver__is_complete_repeated_call__succeeds) { ///arrange - DNSRESOLVER_HANDLE dns = dns_resolver_create("fake.com", NULL); + DNSRESOLVER_HANDLE dns = dns_resolver_create("fake.com", 53, NULL); // We're calling this twice bool result = dns_resolver_is_lookup_complete(dns); uint32_t ipv4 = dns_resolver_get_ipv4(dns); @@ -220,7 +226,7 @@ BEGIN_TEST_SUITE(dns_resolver_ut) { ///arrange bool result; - DNSRESOLVER_HANDLE dns = dns_resolver_create("fake.com", NULL); + DNSRESOLVER_HANDLE dns = dns_resolver_create("fake.com", 53, NULL); umock_c_reset_all_calls(); STRICT_EXPECTED_CALL(getaddrinfo(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); @@ -240,7 +246,7 @@ BEGIN_TEST_SUITE(dns_resolver_ut) ///arrange bool result; uint32_t ipv4; - DNSRESOLVER_HANDLE dns = dns_resolver_create("fake.com", NULL); + DNSRESOLVER_HANDLE dns = dns_resolver_create("fake.com", 53, NULL); umock_c_reset_all_calls(); STRICT_EXPECTED_CALL(getaddrinfo(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); result = dns_resolver_is_lookup_complete(dns); @@ -261,7 +267,7 @@ BEGIN_TEST_SUITE(dns_resolver_ut) { ///arrange bool result; - DNSRESOLVER_HANDLE dns = dns_resolver_create("fake.com", NULL); + DNSRESOLVER_HANDLE dns = dns_resolver_create("fake.com", 53, NULL); umock_c_reset_all_calls(); STRICT_EXPECTED_CALL(getaddrinfo(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)).SetReturn(GETADDRINFO_FAIL); @@ -281,7 +287,7 @@ BEGIN_TEST_SUITE(dns_resolver_ut) ///arrange bool result; uint32_t ipv4; - DNSRESOLVER_HANDLE dns = dns_resolver_create("fake.com", NULL); + DNSRESOLVER_HANDLE dns = dns_resolver_create("fake.com", 53, NULL); umock_c_reset_all_calls(); STRICT_EXPECTED_CALL(getaddrinfo(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)).SetReturn(GETADDRINFO_FAIL); result = dns_resolver_is_lookup_complete(dns); @@ -314,7 +320,7 @@ BEGIN_TEST_SUITE(dns_resolver_ut) TEST_FUNCTION(dns_resolver__get_ipv4_too_early__fails) { ///arrange - DNSRESOLVER_HANDLE dns = dns_resolver_create("fake.com", NULL); + DNSRESOLVER_HANDLE dns = dns_resolver_create("fake.com", 53, NULL); ///act uint32_t result = dns_resolver_get_ipv4(dns); @@ -355,7 +361,7 @@ BEGIN_TEST_SUITE(dns_resolver_ut) TEST_FUNCTION(dns_resolver__destroy__success) { ///arrange - DNSRESOLVER_HANDLE result = dns_resolver_create("fake.com", NULL); + DNSRESOLVER_HANDLE result = dns_resolver_create("fake.com", 53, NULL); umock_c_reset_all_calls(); STRICT_EXPECTED_CALL(gballoc_free(IGNORED_NUM_ARG)); // copy hostname @@ -373,11 +379,11 @@ BEGIN_TEST_SUITE(dns_resolver_ut) { ///arrange DNSRESOLVER_HANDLE result; - STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); // copy hostname + STRICT_EXPECTED_CALL(gballoc_calloc(IGNORED_NUM_ARG, IGNORED_NUM_ARG)); // copy hostname STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); // instance ///act - result = dns_resolver_create("fake.com", NULL); + result = dns_resolver_create("fake.com", 53, NULL); ///assert ASSERT_IS_NOT_NULL(result); @@ -395,7 +401,7 @@ BEGIN_TEST_SUITE(dns_resolver_ut) int negativeTestsInitResult = umock_c_negative_tests_init(); ASSERT_ARE_EQUAL(int, 0, negativeTestsInitResult); - STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); // copy hostname + STRICT_EXPECTED_CALL(gballoc_calloc(IGNORED_NUM_ARG, IGNORED_NUM_ARG)); // copy hostname STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); // instance umock_c_negative_tests_snapshot(); @@ -407,7 +413,7 @@ BEGIN_TEST_SUITE(dns_resolver_ut) umock_c_negative_tests_fail_call(i); ///act - result = dns_resolver_create("fake.com", NULL); + result = dns_resolver_create("fake.com", 53, NULL); ///assert ASSERT_IS_NULL(result); @@ -423,7 +429,7 @@ BEGIN_TEST_SUITE(dns_resolver_ut) ///arrange ///act - DNSRESOLVER_HANDLE result = dns_resolver_create(NULL, NULL); + DNSRESOLVER_HANDLE result = dns_resolver_create(NULL, 53, NULL); ///assert ASSERT_IS_NULL(result, "Unexpected success with NULL hostname"); diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/dns_resolver_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/dns_resolver_ut/main.c index 9bf7f3ac8..85040f028 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/dns_resolver_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/dns_resolver_ut/main.c @@ -12,5 +12,5 @@ int main(void) */ RUN_TEST_SUITE(dns_resolver_ut, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/doublylinkedlist_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/doublylinkedlist_ut/main.c index b3d25e379..d593d0638 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/doublylinkedlist_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/doublylinkedlist_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(doublylinkedlist_unittests, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/gballoc_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/gballoc_ut/main.c index fb3762b09..1226fe458 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/gballoc_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/gballoc_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(GBAlloc_UnitTests, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/gballoc_without_init_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/gballoc_without_init_ut/main.c index 82e6bd19f..e7b097a0e 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/gballoc_without_init_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/gballoc_without_init_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(GBAlloc_For_Init_UnitTests, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/hmacsha256_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/hmacsha256_ut/main.c index 7a88832ff..67fd09318 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/hmacsha256_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/hmacsha256_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(HMACSHA256_UnitTests, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/http_proxy_io_ut/http_proxy_io_ut.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/http_proxy_io_ut/http_proxy_io_ut.c index 981f32f39..1a837409f 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/http_proxy_io_ut/http_proxy_io_ut.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/http_proxy_io_ut/http_proxy_io_ut.c @@ -1564,6 +1564,7 @@ TEST_FUNCTION(http_proxy_io_retrieve_options_calls_the_underlying_retrieve_optio STRICT_EXPECTED_CALL(OptionHandler_Create(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(xio_retrieveoptions(TEST_IO_HANDLE)); STRICT_EXPECTED_CALL(OptionHandler_AddOption(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(OptionHandler_Destroy(IGNORED_PTR_ARG)); // act result = http_proxy_io_get_interface_description()->concrete_io_retrieveoptions(http_io); @@ -1581,7 +1582,6 @@ TEST_FUNCTION(http_proxy_io_clone_option_succeeds) { // arrange CONCRETE_IO_HANDLE http_io; - OPTIONHANDLER_HANDLE options; http_io = http_proxy_io_get_interface_description()->concrete_io_create((void*)&default_http_proxy_io_config); @@ -1589,7 +1589,7 @@ TEST_FUNCTION(http_proxy_io_clone_option_succeeds) STRICT_EXPECTED_CALL(OptionHandler_Create(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(xio_retrieveoptions(TEST_IO_HANDLE)); STRICT_EXPECTED_CALL(OptionHandler_AddOption(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); - options = http_proxy_io_get_interface_description()->concrete_io_retrieveoptions(http_io); + http_proxy_io_get_interface_description()->concrete_io_retrieveoptions(http_io); ASSERT_IS_NOT_NULL(tlsio_clone_option); @@ -1613,7 +1613,6 @@ TEST_FUNCTION(http_proxy_io_destroy_option_succeeds) { // arrange CONCRETE_IO_HANDLE http_io; - OPTIONHANDLER_HANDLE options; http_io = http_proxy_io_get_interface_description()->concrete_io_create((void*)&default_http_proxy_io_config); @@ -1621,7 +1620,7 @@ TEST_FUNCTION(http_proxy_io_destroy_option_succeeds) STRICT_EXPECTED_CALL(OptionHandler_Create(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(xio_retrieveoptions(TEST_IO_HANDLE)); STRICT_EXPECTED_CALL(OptionHandler_AddOption(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); - options = http_proxy_io_get_interface_description()->concrete_io_retrieveoptions(http_io); + http_proxy_io_get_interface_description()->concrete_io_retrieveoptions(http_io); ASSERT_IS_NOT_NULL(tlsio_destroy_option); @@ -1666,7 +1665,6 @@ TEST_FUNCTION(when_xio_retrieveoptions_fails_then_http_proxy_io_retrieve_options STRICT_EXPECTED_CALL(xio_retrieveoptions(TEST_IO_HANDLE)) .SetReturn(NULL); STRICT_EXPECTED_CALL(OptionHandler_Destroy(IGNORED_PTR_ARG)); - STRICT_EXPECTED_CALL(OptionHandler_Destroy(IGNORED_PTR_ARG)); // act result = http_proxy_io_get_interface_description()->concrete_io_retrieveoptions(http_io); diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/http_proxy_io_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/http_proxy_io_ut/main.c index b50f762fd..39268ec02 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/http_proxy_io_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/http_proxy_io_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(http_proxy_io_unittests, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/httpapicompact_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/httpapicompact_ut/main.c index 254f134c7..318e644d9 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/httpapicompact_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/httpapicompact_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(httpapicompact_ut, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/httpapiex_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/httpapiex_ut/main.c index faaebf8b9..49fea80be 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/httpapiex_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/httpapiex_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(httpapiex_unittests, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/httpapiexsas_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/httpapiexsas_ut/main.c index f67bb2794..763287e03 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/httpapiexsas_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/httpapiexsas_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(httpapiexsas_unittests, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/httpheaders_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/httpheaders_ut/main.c index cd8be764f..45ce6d77b 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/httpheaders_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/httpheaders_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(HTTPHeaders_UnitTests, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/lock_ut/CMakeLists.txt b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/lock_ut/CMakeLists.txt index cf8229cb4..183734e41 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/lock_ut/CMakeLists.txt +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/lock_ut/CMakeLists.txt @@ -16,3 +16,4 @@ set(${theseTestsName}_h_files build_c_test_artifacts(${theseTestsName} ON "tests/azure_c_shared_utility_tests") +compile_c_test_artifacts_as(${theseTestsName} C99) diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/lock_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/lock_ut/main.c index 4fedd694f..128db2dcf 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/lock_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/lock_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(LOCK_UnitTests, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/map_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/map_ut/main.c index 454f2f2c0..23619bee7 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/map_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/map_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(map_unittests, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/memory_data_ut/CMakeLists.txt b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/memory_data_ut/CMakeLists.txt index 196a929c0..a2f2bddf0 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/memory_data_ut/CMakeLists.txt +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/memory_data_ut/CMakeLists.txt @@ -12,6 +12,12 @@ set(${theseTestsName}_c_files set(${theseTestsName}_h_files ) -build_c_test_artifacts(${theseTestsName} ON "tests/azure_c_shared_utility_tests" ADDITIONAL_LIBS aziotsharedutil) +file(COPY ../valgrind_suppressions.supp DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +build_c_test_artifacts(${theseTestsName} ON "tests/azure_c_shared_utility_tests" + ADDITIONAL_LIBS + aziotsharedutil + VALGRIND_SUPPRESSIONS_FILE + valgrind_suppressions.supp +) compile_c_test_artifacts_as(${theseTestsName} C99) diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/memory_data_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/memory_data_ut/main.c index 51ab5097d..e2597d7c1 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/memory_data_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/memory_data_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(memory_data_ut, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/optionhandler_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/optionhandler_ut/main.c index 8c5c6308c..aa62c32aa 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/optionhandler_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/optionhandler_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(optionhandler_unittests, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/platform_win32_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/platform_win32_ut/main.c index 9e28aaf23..c9213be23 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/platform_win32_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/platform_win32_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(platform_win32_ut, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/refcount_ut/CMakeLists.txt b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/refcount_ut/CMakeLists.txt index 58cffe0f5..ecaecd0dc 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/refcount_ut/CMakeLists.txt +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/refcount_ut/CMakeLists.txt @@ -16,3 +16,5 @@ set(${theseTestsName}_h_files ) build_c_test_artifacts(${theseTestsName} ON "tests/azure_c_shared_utility_tests") + +compile_c_test_artifacts_as(${theseTestsName} C99) diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/refcount_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/refcount_ut/main.c index e71002131..30938d1a3 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/refcount_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/refcount_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(refcount_unittests, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/refcount_ut/refcount_ut.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/refcount_ut/refcount_ut.c index 9b0e8b9c0..f0a49f570 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/refcount_ut/refcount_ut.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/refcount_ut/refcount_ut.c @@ -184,9 +184,9 @@ BEGIN_TEST_SUITE(refcount_unittests) TEST_FUNCTION(refcount_INC_REF_and_DEC_REF_after_create_says_we_should_not_free) { ///arrange - POS_HANDLE p, clone_of_p; + POS_HANDLE p; p = Pos_Create(2); - clone_of_p = Pos_Clone(p); + Pos_Clone(p); umock_c_reset_all_calls(); ///act diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/sastoken_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/sastoken_ut/main.c index d44ca2d7c..bccdad0fe 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/sastoken_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/sastoken_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(sastoken_unittests, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/sha_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/sha_ut/main.c index 79058982f..a8ccfb7b3 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/sha_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/sha_ut/main.c @@ -7,5 +7,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(sha_ut, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/singlylinkedlist_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/singlylinkedlist_ut/main.c index 29a4d2eb8..6edc0c09d 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/singlylinkedlist_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/singlylinkedlist_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(singlylinkedlist_unittests, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/socket_async_ut/CMakeLists.txt b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/socket_async_ut/CMakeLists.txt index 3897bae47..b372d8c9d 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/socket_async_ut/CMakeLists.txt +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/socket_async_ut/CMakeLists.txt @@ -32,4 +32,4 @@ keep_alive.h build_c_test_artifacts(${theseTestsName} ON "tests/azure_c_shared_utility_tests") -compile_c_test_artifacts_as(${theseTestsName} C11) \ No newline at end of file +compile_c_test_artifacts_as(${theseTestsName} C99) \ No newline at end of file diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/socket_async_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/socket_async_ut/main.c index 427c1b5ac..ae2f565b9 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/socket_async_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/socket_async_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(socket_async_ut, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/socketio_berkeley_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/socketio_berkeley_ut/main.c index 73ddbe012..8ff6664c1 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/socketio_berkeley_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/socketio_berkeley_ut/main.c @@ -7,5 +7,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(socketio_berkeley_unittests, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/socketio_win32_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/socketio_win32_ut/main.c index c83e99a11..adfaf8640 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/socketio_win32_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/socketio_win32_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(socketio_win32_unittests, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/srw_lock_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/srw_lock_ut/main.c index bd0149238..a7432442a 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/srw_lock_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/srw_lock_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(srw_lock_unittests, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } \ No newline at end of file diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/string_utils_int/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/string_utils_int/main.c index 498f49c21..fe75de6fd 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/string_utils_int/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/string_utils_int/main.c @@ -7,5 +7,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(string_utils_int_tests, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/string_utils_int/string_utils_int.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/string_utils_int/string_utils_int.c index 24cd289ec..b050a05c6 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/string_utils_int/string_utils_int.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/string_utils_int/string_utils_int.c @@ -50,7 +50,7 @@ TEST_FUNCTION(mbs_to_wcs_converts_a_simple_LOCALE_C_string) free(result); } -/*the values in this test are taken from https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/mbstowcs-mbstowcs-l?view=vs-2017*/ +/*the values in this test are taken from https://docs.microsoft.com/cpp/c-runtime-library/reference/mbstowcs-mbstowcs-l?view=vs-2017*/ TEST_FUNCTION(mbs_to_wcs_converts_a_Japanese_string) { ///arrange @@ -90,7 +90,7 @@ TEST_FUNCTION(wcs_to_mbs_converts_a_simple_LOCALE_C_string) free(result); } -/*the values in this test are taken from https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/mbstowcs-mbstowcs-l?view=vs-2017*/ +/*the values in this test are taken from https://docs.microsoft.com/cpp/c-runtime-library/reference/mbstowcs-mbstowcs-l?view=vs-2017*/ TEST_FUNCTION(wcs_to_mbs_converts_a_Japanese_string) { ///arrange diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/template_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/template_ut/main.c index 2263eb669..490baaec0 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/template_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/template_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(template_ut, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tickcounter_freertos_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tickcounter_freertos_ut/main.c index 92e5ebdb9..3ecea1aad 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tickcounter_freertos_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tickcounter_freertos_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(tickcounter_freertos_unittests, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tickcounter_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tickcounter_ut/main.c index f0d2a3cc3..bd13d6c25 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tickcounter_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tickcounter_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(tickcounter_unittests, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_bearssl_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_bearssl_ut/main.c index 18da5be3d..a68a4020d 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_bearssl_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_bearssl_ut/main.c @@ -7,5 +7,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(tlsio_bearssl_ut, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_cyclonessl_socket_bsd_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_cyclonessl_socket_bsd_ut/main.c index f4ced949e..efa8e83bd 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_cyclonessl_socket_bsd_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_cyclonessl_socket_bsd_ut/main.c @@ -7,5 +7,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(tlsio_cyclonessl_socket_bsd_unittests, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_cyclonessl_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_cyclonessl_ut/main.c index 0017cb4d0..5a5294b0f 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_cyclonessl_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_cyclonessl_ut/main.c @@ -7,5 +7,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(tlsio_cyclonessl_unittests, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_mbedtls_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_mbedtls_ut/main.c index ea91b28a8..48643d2db 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_mbedtls_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_mbedtls_ut/main.c @@ -7,5 +7,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(tlsio_mbedtls_ut, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_mbedtls_ut/tlsio_mbedtls_ut.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_mbedtls_ut/tlsio_mbedtls_ut.c index 4f1d34cda..3f2844926 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_mbedtls_ut/tlsio_mbedtls_ut.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_mbedtls_ut/tlsio_mbedtls_ut.c @@ -574,7 +574,6 @@ BEGIN_TEST_SUITE(tlsio_mbedtls_ut) STRICT_EXPECTED_CALL(mbedtls_pk_free(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(mbedtls_ctr_drbg_free(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(mbedtls_entropy_free(IGNORED_PTR_ARG)); - STRICT_EXPECTED_CALL(xio_close(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(xio_destroy(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(gballoc_free(IGNORED_NUM_ARG)); diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_options_ut/CMakeLists.txt b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_options_ut/CMakeLists.txt index 70ae7ae51..733fd3ace 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_options_ut/CMakeLists.txt +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_options_ut/CMakeLists.txt @@ -21,3 +21,4 @@ set(${theseTestsName}_h_files build_c_test_artifacts(${theseTestsName} ON "tests/azure_c_shared_utility_tests") +compile_c_test_artifacts_as(${theseTestsName} C99) diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_options_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_options_ut/main.c index d80495c15..c9a10429c 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_options_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_options_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(tlsio_options_unittests, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_options_ut/tlsio_options_ut.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_options_ut/tlsio_options_ut.c index 02fbf9ee9..b2e434c71 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_options_ut/tlsio_options_ut.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_options_ut/tlsio_options_ut.c @@ -444,12 +444,11 @@ TEST_FUNCTION(tlsio_options__set_malloc_fail__fails) TEST_FUNCTION(tlsio_options__release_resources__succeeds) { ///arrange - TLSIO_OPTIONS_RESULT result; TLSIO_OPTIONS options; tlsio_options_initialize(&options, TLSIO_OPTION_BIT_TRUSTED_CERTS | TLSIO_OPTION_BIT_x509_RSA_CERT); - result = tlsio_options_set(&options, OPTION_TRUSTED_CERT, fake_trusted_cert); - result = tlsio_options_set(&options, SU_OPTION_X509_CERT, fake_x509_cert); - result = tlsio_options_set(&options, SU_OPTION_X509_PRIVATE_KEY, fake_x509_key); + tlsio_options_set(&options, OPTION_TRUSTED_CERT, fake_trusted_cert); + tlsio_options_set(&options, SU_OPTION_X509_CERT, fake_x509_cert); + tlsio_options_set(&options, SU_OPTION_X509_PRIVATE_KEY, fake_x509_key); ///act tlsio_options_release_resources(&options); diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_wolfssl_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_wolfssl_ut/main.c index 4b589b314..7ef93761d 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_wolfssl_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_wolfssl_ut/main.c @@ -7,5 +7,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(tlsio_wolfssl_ut, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_wolfssl_ut/tlsio_wolfssl_ut.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_wolfssl_ut/tlsio_wolfssl_ut.c index c963a2aba..277f1dc11 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_wolfssl_ut/tlsio_wolfssl_ut.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/tlsio_wolfssl_ut/tlsio_wolfssl_ut.c @@ -826,12 +826,12 @@ TEST_FUNCTION(tlsio_wolfssl_setoption_debug_log_succeed) CONCRETE_IO_HANDLE io_handle = tlsio_wolfssl_create(&tls_io_config); umock_c_reset_all_calls(); - STRICT_EXPECTED_CALL(wolfSSL_Debugging_ON()).SetReturn(0); - STRICT_EXPECTED_CALL(wolfSSL_SetLoggingCb(IGNORED_PTR_ARG)).SetReturn(0); + STRICT_EXPECTED_CALL(wolfSSL_Debugging_ON()).SetReturn(1); + STRICT_EXPECTED_CALL(wolfSSL_SetLoggingCb(IGNORED_PTR_ARG)).SetReturn(1); //act int debugLogEnable = true; - int test_result = tlsio_wolfssl_setoption(io_handle, "debugLog", &debugLogEnable); + int test_result = tlsio_wolfssl_setoption(io_handle, "debug_log", &debugLogEnable); //assert ASSERT_ARE_EQUAL(int, 0, test_result); @@ -839,6 +839,27 @@ TEST_FUNCTION(tlsio_wolfssl_setoption_debug_log_succeed) //clean tlsio_wolfssl_destroy(io_handle); } + +TEST_FUNCTION(tlsio_wolfssl_setoption_debug_log_disable_fail) +{ + //arrange + TLSIO_CONFIG tls_io_config; + memset(&tls_io_config, 0, sizeof(tls_io_config)); + tls_io_config.hostname = TEST_HOSTNAME; + CONCRETE_IO_HANDLE io_handle = tlsio_wolfssl_create(&tls_io_config); + umock_c_reset_all_calls(); + + //act + // Unlike standard option handlers, turning debug_log off is done via NULL instead of a non-zero int. + int* debugLogEnable = NULL; + int test_result = tlsio_wolfssl_setoption(io_handle, "debug_log", NULL); + + //assert + ASSERT_ARE_NOT_EQUAL(int, 0, test_result); + + //clean + tlsio_wolfssl_destroy(io_handle); +} #endif TEST_FUNCTION(tlsio_wolfssl_on_underlying_io_bytes_received_ctx_NULL_succeess) diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/uniqueid_ut/CMakeLists.txt b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/uniqueid_ut/CMakeLists.txt index 2604d7510..839ecbec0 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/uniqueid_ut/CMakeLists.txt +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/uniqueid_ut/CMakeLists.txt @@ -35,3 +35,5 @@ elseif(UNIX) build_c_test_artifacts(${uniqueid_ut_test_file} ON "tests/azure_c_shared_utility_tests" ADDITIONAL_LIBS uuid) endif() endif() + +compile_c_test_artifacts_as(${uniqueid_ut_test_file} C99) diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/uniqueid_ut/uniqueid_ut_linux.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/uniqueid_ut/uniqueid_ut_linux.c index 18943b9ca..9eaaaad68 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/uniqueid_ut/uniqueid_ut_linux.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/uniqueid_ut/uniqueid_ut_linux.c @@ -7,6 +7,7 @@ #include #endif +#include "azure_macro_utils/macro_utils.h" #include "testrunnerswitcher.h" #include "azure_c_shared_utility/uniqueid.h" diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/urlencode_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/urlencode_ut/main.c index 324ba3690..93f17f375 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/urlencode_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/urlencode_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(URLEncode_UnitTests, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/utf8_checker_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/utf8_checker_ut/main.c index dc7aae857..c3c6ad68e 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/utf8_checker_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/utf8_checker_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(utf8_checker_ut, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/uuid_ut/uuid_ut.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/uuid_ut/uuid_ut.c index fb7cd0eec..167cd72b9 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/uuid_ut/uuid_ut.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/uuid_ut/uuid_ut.c @@ -37,6 +37,27 @@ static void on_umock_c_error(UMOCK_C_ERROR_CODE error_code) static const UUID_T TEST_UUID = { 222, 193, 74, 152, 197, 252, 67, 14, 180, 227, 51, 193, 196, 52, 220, 175 }; static char* TEST_UUID_STRING = "dec14a98-c5fc-430e-b4e3-33c1c434dcaf"; +static const char* INVALID_UUIDS[] = +{ + "d", + "-", + "dec14a98", + "dec14a98-c5fc", + "dec14a98-c5fc-430e-b4e3-", + "dec14a98-c5fc-430e-b4e3-33c1c434dca", + "dec14a98c5fc-430e-b4e3-33c1c434dcaf", + "dec14a98c5fc-430e-b4e3-33c1c434dcaf1", + "dec14a98-c5fc430e-b4e3-33c1c434dcaf", + "dec14a98-c5fc-430eb4e3-33c1c434dcaf", + "dec14a98-c5fc-430e-b4e333c1c434dcaf", + "dec14a98c5fc430eb4e333c1c434dcaf", + "dec14a98-c5fc-430e-b4e3-33c1c434dca-", + "dec14a98-c5fc-430e-b-e3-33c1c434dcaf", + "dec14a98-c5fc-43-e-b4e3-33c1c434dcaf", + "dec14a98-c-fc-430e-b4e3-33c1c434dcaf", + "dec14-98-c5fc-430e-b4e3-33c1c434dcaf", + "-ec14a98-c5fc-430e-b4e3-33c1c434dcaf", +}; static UNIQUEID_RESULT mock_UniqueId_Generate_result; static UNIQUEID_RESULT mock_UniqueId_Generate(char* uid, size_t bufferSize) @@ -321,6 +342,24 @@ TEST_FUNCTION(UUID_from_string_succeed) } } +TEST_FUNCTION(UUID_from_string_invalid_fails) +{ + //Arrange + int result; + UUID_T uuid; + + umock_c_reset_all_calls(); + + for (size_t i = 0; i < sizeof(INVALID_UUIDS)/sizeof(INVALID_UUIDS[0]); i++) + { + //Act + result = UUID_from_string(INVALID_UUIDS[i], &uuid); + + //Assert + ASSERT_ARE_NOT_EQUAL(int, 0, result); + } +} + // Tests_SRS_UUID_09_009: [ If uuid fails to be generated, UUID_from_string shall return a non-zero value ] // To be implemented once sscanf mock is implemented. diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/uws_client_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/uws_client_ut/main.c index 6b3a7b197..9b76455a4 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/uws_client_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/uws_client_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(uws_client_ut, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/uws_client_ut/uws_client_ut.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/uws_client_ut/uws_client_ut.c index 5409d5ae6..ffbab56be 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/uws_client_ut/uws_client_ut.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/uws_client_ut/uws_client_ut.c @@ -59,7 +59,7 @@ Tests_SRS_UWS_CLIENT_01_211: [ One implication of this is that in absence of ext #include "azure_c_shared_utility/singlylinkedlist.h" #include "azure_c_shared_utility/tlsio.h" #include "azure_c_shared_utility/uws_frame_encoder.h" -#include "azure_c_shared_utility/gb_rand.h" +#include "azure_c_shared_utility/random.h" #include "azure_c_shared_utility/azure_base64.h" #include "azure_c_shared_utility/map.h" @@ -2872,7 +2872,7 @@ TEST_FUNCTION(on_underlying_io_open_complete_with_OK_prepares_and_sends_the_WebS /* get the random 16 bytes */ for (i = 0; i < 16; i++) { - EXPECTED_CALL(gb_rand()).SetReturn((int)i); + EXPECTED_CALL(RANDOM_generate()).SetReturn((int)i); expected_nonce[i] = (unsigned char)i; } @@ -2918,7 +2918,7 @@ TEST_FUNCTION(when_base64_encode_fails_on_underlying_io_open_complete_triggers_t /* get the random 16 bytes */ for (i = 0; i < 16; i++) { - EXPECTED_CALL(gb_rand()).SetReturn((int)i); + EXPECTED_CALL(RANDOM_generate()).SetReturn((int)i); expected_nonce[i] = (unsigned char)i; } @@ -2956,7 +2956,7 @@ TEST_FUNCTION(when_allocating_memory_for_the_websocket_upgrade_request_fails_the /* get the random 16 bytes */ for (i = 0; i < 16; i++) { - EXPECTED_CALL(gb_rand()).SetReturn((int)i); + EXPECTED_CALL(RANDOM_generate()).SetReturn((int)i); expected_nonce[i] = (unsigned char)i; } @@ -3004,7 +3004,7 @@ TEST_FUNCTION(uws_client_open_async_after_WS_OPEN_ERROR_NOT_ENOUGH_MEMORY_succee /* get the random 16 bytes */ for (i = 0; i < 16; i++) { - EXPECTED_CALL(gb_rand()).SetReturn((int)i); + EXPECTED_CALL(RANDOM_generate()).SetReturn((int)i); expected_nonce[i] = (unsigned char)i; } @@ -3055,7 +3055,7 @@ TEST_FUNCTION(when_sending_the_upgrade_request_fails_the_error_WS_OPEN_ERROR_CAN /* get the random 16 bytes */ for (i = 0; i < 16; i++) { - EXPECTED_CALL(gb_rand()).SetReturn((int)i); + EXPECTED_CALL(RANDOM_generate()).SetReturn((int)i); expected_nonce[i] = (unsigned char)i; } @@ -3107,7 +3107,7 @@ TEST_FUNCTION(uws_client_open_async_after_WS_OPEN_ERROR_CANNOT_SEND_UPGRADE_REQU /* get the random 16 bytes */ for (i = 0; i < 16; i++) { - EXPECTED_CALL(gb_rand()).SetReturn((int)i); + EXPECTED_CALL(RANDOM_generate()).SetReturn((int)i); expected_nonce[i] = (unsigned char)i; } @@ -6704,7 +6704,6 @@ TEST_FUNCTION(when_xio_close_fails_in_on_underlying_io_close_sent_and_CLOSE_init UWS_CLIENT_HANDLE uws_client; const char test_upgrade_response[] = "HTTP/1.1 101 Switching Protocols\r\n\r\n"; const unsigned char close_frame[] = { 0x88, 0x00 }; - int result; tlsio_config.hostname = "test_host"; tlsio_config.port = 444; @@ -6732,7 +6731,7 @@ TEST_FUNCTION(when_xio_close_fails_in_on_underlying_io_close_sent_and_CLOSE_init .IgnoreArgument_on_io_error_context(); // act - result = uws_client_open_async(uws_client, test_on_ws_open_complete, (void*)0x4242, test_on_ws_frame_received, (void*)0x4243, test_on_ws_peer_closed, (void*)0x4301, test_on_ws_error, (void*)0x4244); + uws_client_open_async(uws_client, test_on_ws_open_complete, (void*)0x4242, test_on_ws_frame_received, (void*)0x4243, test_on_ws_peer_closed, (void*)0x4301, test_on_ws_error, (void*)0x4244); // assert ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/uws_frame_encoder_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/uws_frame_encoder_ut/main.c index baec8a1e6..b5c85da28 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/uws_frame_encoder_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/uws_frame_encoder_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(uws_frame_encoder_ut, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/uws_frame_encoder_ut/uws_frame_encoder_ut.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/uws_frame_encoder_ut/uws_frame_encoder_ut.c index 4c09aecae..5c4b591ab 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/uws_frame_encoder_ut/uws_frame_encoder_ut.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/uws_frame_encoder_ut/uws_frame_encoder_ut.c @@ -29,7 +29,7 @@ void real_free(void* ptr) #define ENABLE_MOCKS #include "azure_c_shared_utility/gballoc.h" -#include "azure_c_shared_utility/gb_rand.h" +#include "azure_c_shared_utility/random.h" #include "azure_c_shared_utility/buffer_.h" #undef ENABLE_MOCKS @@ -880,7 +880,7 @@ TEST_FUNCTION(uws_frame_encoder_encodes_a_reserved_control_frame_F) } /* Tests_SRS_UWS_FRAME_ENCODER_01_015: [ Defines whether the "Payload data" is masked. ]*/ -/* Tests_SRS_UWS_FRAME_ENCODER_01_053: [ In order to obtain a 32 bit value for masking, gb_rand shall be used 4 times (for each byte). ]*/ +/* Tests_SRS_UWS_FRAME_ENCODER_01_053: [ In order to obtain a 32 bit value for masking, RANDOM_generate shall be used 4 times (for each byte). ]*/ /* Tests_SRS_UWS_FRAME_ENCODER_01_016: [ If set to 1, a masking key is present in masking-key, and this is used to unmask the "Payload data" as per Section 5.3. ]*/ /* Tests_SRS_UWS_FRAME_ENCODER_01_026: [ This field is present if the mask bit is set to 1 and is absent if the mask bit is set to 0. ]*/ /* Tests_SRS_UWS_FRAME_ENCODER_01_042: [ The payload length, indicated in the framing as frame-payload-length, does NOT include the length of the masking key. ]*/ @@ -897,13 +897,13 @@ TEST_FUNCTION(uws_frame_encoder_encode_encodes_a_masked_zero_length_binary_frame .ValidateArgumentValue_handle(&newly_created_buffer); STRICT_EXPECTED_CALL(BUFFER_u_char(IGNORED_PTR_ARG)) .ValidateArgumentValue_handle(&newly_created_buffer); - STRICT_EXPECTED_CALL(gb_rand()) + STRICT_EXPECTED_CALL(RANDOM_generate()) .SetReturn(0xFF); - STRICT_EXPECTED_CALL(gb_rand()) + STRICT_EXPECTED_CALL(RANDOM_generate()) .SetReturn(0xFF); - STRICT_EXPECTED_CALL(gb_rand()) + STRICT_EXPECTED_CALL(RANDOM_generate()) .SetReturn(0xFF); - STRICT_EXPECTED_CALL(gb_rand()) + STRICT_EXPECTED_CALL(RANDOM_generate()) .SetReturn(0xFF); // act @@ -921,7 +921,7 @@ TEST_FUNCTION(uws_frame_encoder_encode_encodes_a_masked_zero_length_binary_frame } /* Tests_SRS_UWS_FRAME_ENCODER_01_015: [ Defines whether the "Payload data" is masked. ]*/ -/* Tests_SRS_UWS_FRAME_ENCODER_01_053: [ In order to obtain a 32 bit value for masking, gb_rand shall be used 4 times (for each byte). ]*/ +/* Tests_SRS_UWS_FRAME_ENCODER_01_053: [ In order to obtain a 32 bit value for masking, RANDOM_generate shall be used 4 times (for each byte). ]*/ /* Tests_SRS_UWS_FRAME_ENCODER_01_016: [ If set to 1, a masking key is present in masking-key, and this is used to unmask the "Payload data" as per Section 5.3. ]*/ /* Tests_SRS_UWS_FRAME_ENCODER_01_026: [ This field is present if the mask bit is set to 1 and is absent if the mask bit is set to 0. ]*/ /* Tests_SRS_UWS_FRAME_ENCODER_01_042: [ The payload length, indicated in the framing as frame-payload-length, does NOT include the length of the masking key. ]*/ @@ -938,13 +938,13 @@ TEST_FUNCTION(uws_frame_encoder_encode_encodes_a_masked_zero_length_binary_frame .ValidateArgumentValue_handle(&newly_created_buffer); STRICT_EXPECTED_CALL(BUFFER_u_char(IGNORED_PTR_ARG)) .ValidateArgumentValue_handle(&newly_created_buffer); - STRICT_EXPECTED_CALL(gb_rand()) + STRICT_EXPECTED_CALL(RANDOM_generate()) .SetReturn(0x42); - STRICT_EXPECTED_CALL(gb_rand()) + STRICT_EXPECTED_CALL(RANDOM_generate()) .SetReturn(0x43); - STRICT_EXPECTED_CALL(gb_rand()) + STRICT_EXPECTED_CALL(RANDOM_generate()) .SetReturn(0x44); - STRICT_EXPECTED_CALL(gb_rand()) + STRICT_EXPECTED_CALL(RANDOM_generate()) .SetReturn(0x45); // act @@ -1209,13 +1209,13 @@ TEST_FUNCTION(uws_frame_encoder_encode_masks_a_1_byte_frame_with_0_as_mask) .ValidateArgumentValue_handle(&newly_created_buffer); STRICT_EXPECTED_CALL(BUFFER_u_char(IGNORED_PTR_ARG)) .ValidateArgumentValue_handle(&newly_created_buffer); - STRICT_EXPECTED_CALL(gb_rand()) + STRICT_EXPECTED_CALL(RANDOM_generate()) .SetReturn(0x00); - STRICT_EXPECTED_CALL(gb_rand()) + STRICT_EXPECTED_CALL(RANDOM_generate()) .SetReturn(0x00); - STRICT_EXPECTED_CALL(gb_rand()) + STRICT_EXPECTED_CALL(RANDOM_generate()) .SetReturn(0x00); - STRICT_EXPECTED_CALL(gb_rand()) + STRICT_EXPECTED_CALL(RANDOM_generate()) .SetReturn(0x00); // act @@ -1255,13 +1255,13 @@ TEST_FUNCTION(uws_frame_encoder_encode_masks_a_1_byte_frame_with_0xFF_as_mask) .ValidateArgumentValue_handle(&newly_created_buffer); STRICT_EXPECTED_CALL(BUFFER_u_char(IGNORED_PTR_ARG)) .ValidateArgumentValue_handle(&newly_created_buffer); - STRICT_EXPECTED_CALL(gb_rand()) + STRICT_EXPECTED_CALL(RANDOM_generate()) .SetReturn(0xFF); - STRICT_EXPECTED_CALL(gb_rand()) + STRICT_EXPECTED_CALL(RANDOM_generate()) .SetReturn(0x00); - STRICT_EXPECTED_CALL(gb_rand()) + STRICT_EXPECTED_CALL(RANDOM_generate()) .SetReturn(0x00); - STRICT_EXPECTED_CALL(gb_rand()) + STRICT_EXPECTED_CALL(RANDOM_generate()) .SetReturn(0x00); // act @@ -1301,13 +1301,13 @@ TEST_FUNCTION(uws_frame_encoder_encode_masks_a_4_byte_frame_with_0xFF_as_mask) .ValidateArgumentValue_handle(&newly_created_buffer); STRICT_EXPECTED_CALL(BUFFER_u_char(IGNORED_PTR_ARG)) .ValidateArgumentValue_handle(&newly_created_buffer); - STRICT_EXPECTED_CALL(gb_rand()) + STRICT_EXPECTED_CALL(RANDOM_generate()) .SetReturn(0xFF); - STRICT_EXPECTED_CALL(gb_rand()) + STRICT_EXPECTED_CALL(RANDOM_generate()) .SetReturn(0xFF); - STRICT_EXPECTED_CALL(gb_rand()) + STRICT_EXPECTED_CALL(RANDOM_generate()) .SetReturn(0xFF); - STRICT_EXPECTED_CALL(gb_rand()) + STRICT_EXPECTED_CALL(RANDOM_generate()) .SetReturn(0xFF); // act @@ -1347,13 +1347,13 @@ TEST_FUNCTION(uws_frame_encoder_encode_masks_a_5_byte_frame_with_0xFF_as_mask) .ValidateArgumentValue_handle(&newly_created_buffer); STRICT_EXPECTED_CALL(BUFFER_u_char(IGNORED_PTR_ARG)) .ValidateArgumentValue_handle(&newly_created_buffer); - STRICT_EXPECTED_CALL(gb_rand()) + STRICT_EXPECTED_CALL(RANDOM_generate()) .SetReturn(0xFF); - STRICT_EXPECTED_CALL(gb_rand()) + STRICT_EXPECTED_CALL(RANDOM_generate()) .SetReturn(0xFF); - STRICT_EXPECTED_CALL(gb_rand()) + STRICT_EXPECTED_CALL(RANDOM_generate()) .SetReturn(0xFF); - STRICT_EXPECTED_CALL(gb_rand()) + STRICT_EXPECTED_CALL(RANDOM_generate()) .SetReturn(0xFF); // act @@ -1393,13 +1393,13 @@ TEST_FUNCTION(uws_frame_encoder_encode_masks_a_8_byte_frame_with_different_mask_ .ValidateArgumentValue_handle(&newly_created_buffer); STRICT_EXPECTED_CALL(BUFFER_u_char(IGNORED_PTR_ARG)) .ValidateArgumentValue_handle(&newly_created_buffer); - STRICT_EXPECTED_CALL(gb_rand()) + STRICT_EXPECTED_CALL(RANDOM_generate()) .SetReturn(0x00); - STRICT_EXPECTED_CALL(gb_rand()) + STRICT_EXPECTED_CALL(RANDOM_generate()) .SetReturn(0xFF); - STRICT_EXPECTED_CALL(gb_rand()) + STRICT_EXPECTED_CALL(RANDOM_generate()) .SetReturn(0xAA); - STRICT_EXPECTED_CALL(gb_rand()) + STRICT_EXPECTED_CALL(RANDOM_generate()) .SetReturn(0x42); // act diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/valgrind_suppressions.supp b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/valgrind_suppressions.supp new file mode 100644 index 000000000..7b025a6d3 --- /dev/null +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/valgrind_suppressions.supp @@ -0,0 +1,59 @@ +{ + Suppress pthread destroy with invalid arg + Helgrind:Misc + obj:/usr/lib/x86_64-linux-gnu/valgrind/vgpreload_helgrind-amd64-linux.so + obj:/usr/lib/x86_64-linux-gnu/libp11-kit.so.0.3.0 + fun:_dl_fini + fun:__run_exit_handlers + fun:exit + fun:(below main) +} +{ + + Helgrind:Misc + obj:/usr/lib/x86_64-linux-gnu/valgrind/vgpreload_helgrind-amd64-linux.so + fun:_dl_fini + fun:__run_exit_handlers + fun:exit + fun:(below main) +} +{ + Suppress "is not a mutex" + drd:MutexErr + fun:pthread_mutex_destroy + obj:/usr/lib/x86_64-linux-gnu/libp11-kit.so.0.3.0 + fun:_dl_fini + fun:__run_exit_handlers + fun:exit + fun:(below main) +} +{ + Suppress "is not a mutex" + drd:MutexErr + fun:pthread_mutex_destroy + fun:_dl_fini + fun:__run_exit_handlers + fun:exit + fun:(below main) +} +{ + + drd:MutexErr + fun:pthread_mutex_destroy_intercept + fun:pthread_mutex_destroy + obj:/usr/lib/x86_64-linux-gnu/libp11-kit.so.0.3.0 + fun:_dl_fini + fun:__run_exit_handlers + fun:exit + fun:(below main) +} +{ + + drd:MutexErr + fun:pthread_mutex_destroy_intercept + fun:pthread_mutex_destroy + fun:_dl_fini + fun:__run_exit_handlers + fun:exit + fun:(below main) +} diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/vector_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/vector_ut/main.c index 60f89d5f2..17911d469 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/vector_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/vector_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(Vector_UnitTests, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/wsio_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/wsio_ut/main.c index 47515719c..8b0699d59 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/wsio_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/wsio_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(wsio_ut, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/x509_openssl_ut/engine/CMakeLists.txt b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/x509_openssl_ut/engine/CMakeLists.txt new file mode 100644 index 000000000..76ae2abcd --- /dev/null +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/x509_openssl_ut/engine/CMakeLists.txt @@ -0,0 +1,30 @@ +#Copyright (c) Microsoft. All rights reserved. +#Licensed under the MIT license. See LICENSE file in the project root for full license information. + +cmake_minimum_required (VERSION 3.5) + +set(theseTestsName x509_openssl_ut_engine) + +set(${theseTestsName}_test_files +../x509_openssl_ut.c +) + +if(LINUX) + set_property( + SOURCE + ../../adapters/x509_openssl.c + PROPERTY COMPILE_OPTIONS + -Wno-deprecated-declarations + ) +endif() + +set(${theseTestsName}_c_files +../../../adapters/x509_openssl.c +) + +set(${theseTestsName}_h_files +) + +build_c_test_artifacts(${theseTestsName} ON "tests/azure_c_shared_utility_tests") + +compile_c_test_artifacts_as(${theseTestsName} C99) diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/x509_openssl_ut/engine/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/x509_openssl_ut/engine/main.c new file mode 100644 index 000000000..dcd8233c1 --- /dev/null +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/x509_openssl_ut/engine/main.c @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +#include "testrunnerswitcher.h" + +int main(void) +{ + size_t failedTestCount = 0; + RUN_TEST_SUITE(x509_openssl_unittests, failedTestCount); + return (int)failedTestCount; +} diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/x509_openssl_ut/no_engine/CMakeLists.txt b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/x509_openssl_ut/no_engine/CMakeLists.txt new file mode 100644 index 000000000..eb2d31f75 --- /dev/null +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/x509_openssl_ut/no_engine/CMakeLists.txt @@ -0,0 +1,23 @@ +#Copyright (c) Microsoft. All rights reserved. +#Licensed under the MIT license. See LICENSE file in the project root for full license information. + +cmake_minimum_required (VERSION 3.5) + +set(theseTestsName x509_openssl_ut_no_engine) + +set(${theseTestsName}_test_files +../x509_openssl_ut.c +) + +set(${theseTestsName}_c_files +../../../adapters/x509_openssl.c +) + +set(${theseTestsName}_h_files +) + +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DOPENSSL_NO_ENGINE") + +build_c_test_artifacts(${theseTestsName} ON "tests/azure_c_shared_utility_tests") + +compile_c_test_artifacts_as(${theseTestsName} C99) diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/x509_openssl_ut/no_engine/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/x509_openssl_ut/no_engine/main.c new file mode 100644 index 000000000..dcd8233c1 --- /dev/null +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/x509_openssl_ut/no_engine/main.c @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +#include "testrunnerswitcher.h" + +int main(void) +{ + size_t failedTestCount = 0; + RUN_TEST_SUITE(x509_openssl_unittests, failedTestCount); + return (int)failedTestCount; +} diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/x509_openssl_ut/x509_openssl_ut.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/x509_openssl_ut/x509_openssl_ut.c index b3349f6b0..12cd0be37 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/x509_openssl_ut/x509_openssl_ut.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/x509_openssl_ut/x509_openssl_ut.c @@ -34,7 +34,9 @@ static void my_gballoc_free(void* s) #include "openssl/bio.h" #include "openssl/rsa.h" #include "openssl/evp.h" +#ifndef OPENSSL_NO_ENGINE #include "openssl/engine.h" +#endif // OPENSSL_NO_ENGINE #include "azure_c_shared_utility/x509_openssl.h" #include "umock_c/umocktypes_charptr.h" @@ -117,10 +119,12 @@ MOCKABLE_FUNCTION(, long, SSL_CTX_ctrl, SSL_CTX*, ctx, int, cmd, long, larg, voi MOCKABLE_FUNCTION(, unsigned long, ERR_peek_last_error); MOCKABLE_FUNCTION(, void, ERR_clear_error); +#ifndef OPENSSL_NO_ENGINE MOCKABLE_FUNCTION(, int, ENGINE_init, ENGINE*, e); MOCKABLE_FUNCTION(, int, ENGINE_set_default, ENGINE*, e, unsigned int, flags); MOCKABLE_FUNCTION(, EVP_PKEY*, ENGINE_load_private_key, ENGINE*, e, const char*, key_id, UI_METHOD*, ui_method, void*, callback_data); MOCKABLE_FUNCTION(, int, ENGINE_finish, ENGINE*, e); +#endif // OPENSSL_NO_ENGINE #ifndef __APPLE__ MOCKABLE_FUNCTION(, int, EVP_PKEY_id, const EVP_PKEY*, pkey); @@ -222,7 +226,9 @@ typedef struct replace_evp_pkey_st_tag #define TEST_X509_STORE (X509_STORE *)"le store" #define TEST_BIO_METHOD (BIO_METHOD*)"le method" #define TEST_BIO (BIO*)"le bio" +#ifndef OPENSSL_NO_ENGINE #define TEST_ENGINE (ENGINE*)"the engine" +#endif // OPENSSL_NO_ENGINE #define TEST_KEY_ID "the key id" static const char* TEST_PUBLIC_CERTIFICATE = "PUBLIC CERTIFICATE"; @@ -285,10 +291,12 @@ BEGIN_TEST_SUITE(x509_openssl_unittests) REGISTER_GLOBAL_MOCK_RETURNS(SSL_CTX_use_PrivateKey, 1, 0); REGISTER_GLOBAL_MOCK_HOOK(SSL_CTX_ctrl, my_SSL_CTX_ctrl); + #ifndef OPENSSL_NO_ENGINE REGISTER_GLOBAL_MOCK_RETURNS(ENGINE_init, 1, 0); REGISTER_GLOBAL_MOCK_RETURNS(ENGINE_set_default, 1, 0); REGISTER_GLOBAL_MOCK_RETURNS(ENGINE_load_private_key, g_evp_pkey, NULL); REGISTER_GLOBAL_MOCK_RETURNS(ENGINE_finish, 1, 0); + #endif // OPENSSL_NO_ENGINE } TEST_SUITE_CLEANUP(TestClassCleanup) @@ -348,7 +356,7 @@ BEGIN_TEST_SUITE(x509_openssl_unittests) STRICT_EXPECTED_CALL(BIO_new_mem_buf((void*)TEST_PUBLIC_CERTIFICATE, -1)); STRICT_EXPECTED_CALL(PEM_read_bio_X509_AUX(IGNORED_PTR_ARG, NULL, NULL, NULL)); STRICT_EXPECTED_CALL(SSL_CTX_use_certificate(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); -#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) && (OPENSSL_VERSION_NUMBER < 0x20000000L) +#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) || defined(LIBRESSL_VERSION_NUMBER) // Actual macro name: SSL_CTX_clear_extra_chain_certs: STRICT_EXPECTED_CALL(SSL_CTX_ctrl(TEST_SSL_CTX_STRUCTURE, SSL_CTRL_CLEAR_EXTRA_CHAIN_CERTS, 0, NULL)); #endif @@ -376,6 +384,7 @@ BEGIN_TEST_SUITE(x509_openssl_unittests) setup_load_certificate_chain_mocks(); } + #ifndef OPENSSL_NO_ENGINE static void setup_add_credentials_engine() { // x509_openssl_add_pem_file_key @@ -387,6 +396,7 @@ BEGIN_TEST_SUITE(x509_openssl_unittests) STRICT_EXPECTED_CALL(ENGINE_finish(TEST_ENGINE)); setup_load_certificate_chain_mocks(); } + #endif // OPENSSL_NO_ENGINE /*Tests_SRS_X509_OPENSSL_02_001: [ If any argument is NULL then x509_openssl_add_credentials shall fail and return a non-zero value. ]*/ TEST_FUNCTION(x509_openssl_add_credentials_with_NULL_SSL_CTX_fails) @@ -394,7 +404,11 @@ BEGIN_TEST_SUITE(x509_openssl_unittests) //arrange //act + #ifndef OPENSSL_NO_ENGINE int result = x509_openssl_add_credentials(NULL, TEST_PUBLIC_CERTIFICATE, "privatekey", KEY_TYPE_DEFAULT, NULL); + #else // OPENSSL_NO_ENGINE + int result = x509_openssl_add_credentials(NULL, TEST_PUBLIC_CERTIFICATE, "privatekey", KEY_TYPE_DEFAULT); + #endif // OPENSSL_NO_ENGINE //assert ASSERT_ARE_NOT_EQUAL(int, 0, result); @@ -408,7 +422,11 @@ BEGIN_TEST_SUITE(x509_openssl_unittests) //arrange //act + #ifndef OPENSSL_NO_ENGINE int result = x509_openssl_add_credentials(TEST_SSL_CTX, NULL, "privatekey", KEY_TYPE_DEFAULT, NULL); + #else // OPENSSL_NO_ENGINE + int result = x509_openssl_add_credentials(TEST_SSL_CTX, NULL, "privatekey", KEY_TYPE_DEFAULT); + #endif // OPENSSL_NO_ENGINE //assert ASSERT_ARE_NOT_EQUAL(int, 0, result); @@ -422,7 +440,11 @@ BEGIN_TEST_SUITE(x509_openssl_unittests) //arrange //act - int result = x509_openssl_add_credentials(TEST_SSL_CTX, TEST_PUBLIC_CERTIFICATE, NULL, KEY_TYPE_DEFAULT, NULL); + #ifndef OPENSSL_NO_ENGINE + int result = x509_openssl_add_credentials(TEST_SSL_CTX, TEST_PUBLIC_CERTIFICATE, NULL, KEY_TYPE_DEFAULT, TEST_ENGINE); + #else // OPENSSL_NO_ENGINE + int result = x509_openssl_add_credentials(TEST_SSL_CTX, TEST_PUBLIC_CERTIFICATE, NULL, KEY_TYPE_DEFAULT); + #endif // OPENSSL_NO_ENGINE //assert ASSERT_ARE_NOT_EQUAL(int, 0, result); @@ -435,7 +457,11 @@ BEGIN_TEST_SUITE(x509_openssl_unittests) //arrange //act + #ifndef OPENSSL_NO_ENGINE int result = x509_openssl_add_credentials(TEST_SSL_CTX, NULL, "privatekey", KEY_TYPE_ENGINE, TEST_ENGINE); + #else + int result = x509_openssl_add_credentials(TEST_SSL_CTX, NULL, "privatekey", KEY_TYPE_DEFAULT); + #endif // OPENSSL_NO_ENGINE //assert ASSERT_ARE_NOT_EQUAL(int, 0, result); @@ -448,7 +474,11 @@ BEGIN_TEST_SUITE(x509_openssl_unittests) //arrange //act + #ifndef OPENSSL_NO_ENGINE int result = x509_openssl_add_credentials(TEST_SSL_CTX, TEST_PUBLIC_CERTIFICATE, NULL, KEY_TYPE_ENGINE, TEST_ENGINE); + #else + int result = x509_openssl_add_credentials(TEST_SSL_CTX, TEST_PUBLIC_CERTIFICATE, NULL, KEY_TYPE_DEFAULT); + #endif // OPENSSL_NO_ENGINE //assert ASSERT_ARE_NOT_EQUAL(int, 0, result); @@ -456,6 +486,7 @@ BEGIN_TEST_SUITE(x509_openssl_unittests) //cleanup } + #ifndef OPENSSL_NO_ENGINE TEST_FUNCTION(x509_openssl_engine_add_credentials_with_NULL_engine_fails) { //arrange @@ -468,6 +499,7 @@ BEGIN_TEST_SUITE(x509_openssl_unittests) //cleanup } + #endif // OPENSSL_NO_ENGINE /*Tests_SRS_X509_OPENSSL_02_002: [ x509_openssl_add_credentials shall use BIO_new_mem_buf to create a memory BIO from the x509 certificate. ] */ /*Tests_SRS_X509_OPENSSL_02_003: [ x509_openssl_add_credentials shall use PEM_read_bio_X509 to read the x509 certificate. ] */ @@ -481,7 +513,11 @@ BEGIN_TEST_SUITE(x509_openssl_unittests) setup_add_credentials_pem_file(true); //act + #ifndef OPENSSL_NO_ENGINE int result = x509_openssl_add_credentials(TEST_SSL_CTX_STRUCTURE, TEST_PUBLIC_CERTIFICATE, TEST_PRIVATE_CERTIFICATE, KEY_TYPE_DEFAULT, NULL); + #else // OPENSSL_NO_ENGINE + int result = x509_openssl_add_credentials(TEST_SSL_CTX_STRUCTURE, TEST_PUBLIC_CERTIFICATE, TEST_PRIVATE_CERTIFICATE, KEY_TYPE_DEFAULT); + #endif // OPENSSL_NO_ENGINE //assert ASSERT_ARE_EQUAL(int, 0, result); @@ -495,7 +531,11 @@ BEGIN_TEST_SUITE(x509_openssl_unittests) setup_add_credentials_pem_file(false); //act + #ifndef OPENSSL_NO_ENGINE int result = x509_openssl_add_credentials(TEST_SSL_CTX_STRUCTURE, TEST_PUBLIC_CERTIFICATE, TEST_PRIVATE_CERTIFICATE, KEY_TYPE_DEFAULT, NULL); + #else // OPENSSL_NO_ENGINE + int result = x509_openssl_add_credentials(TEST_SSL_CTX_STRUCTURE, TEST_PUBLIC_CERTIFICATE, TEST_PRIVATE_CERTIFICATE, KEY_TYPE_DEFAULT); + #endif // OPENSSL_NO_ENGINE //assert ASSERT_ARE_EQUAL(int, 0, result); @@ -504,6 +544,7 @@ BEGIN_TEST_SUITE(x509_openssl_unittests) //cleanup } + #ifndef OPENSSL_NO_ENGINE TEST_FUNCTION(x509_openssl_engine_add_credentials_happy_path) { setup_add_credentials_engine(); @@ -517,6 +558,7 @@ BEGIN_TEST_SUITE(x509_openssl_unittests) //cleanup } + #endif // OPENSSL_NO_ENGINE void x509_openssl_add_credentials_fails(bool is_rsa, bool use_engine) { @@ -530,14 +572,16 @@ BEGIN_TEST_SUITE(x509_openssl_unittests) { setup_add_credentials_pem_file(is_rsa); } + #ifndef OPENSSL_NO_ENGINE else { setup_add_credentials_engine(); } + #endif // OPENSSL_NO_ENGINE umock_c_negative_tests_snapshot(); -#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) && (OPENSSL_VERSION_NUMBER < 0x20000000L) +#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) || defined(LIBRESSL_VERSION_NUMBER) #ifdef __APPLE__ size_t calls_cannot_fail_rsa[] = { 4, 5, 6, 10, 12, 13, 14 }; size_t calls_cannot_fail_ecc[] = { 3, 4, 8, 10, 11, 12} ; @@ -566,11 +610,13 @@ BEGIN_TEST_SUITE(x509_openssl_unittests) calls_cannot_fail = is_rsa ? calls_cannot_fail_rsa : calls_cannot_fail_ecc; calls_cannot_fail_size = is_rsa ? sizeof(calls_cannot_fail_rsa) / sizeof(calls_cannot_fail_rsa[0]) : sizeof(calls_cannot_fail_ecc) / sizeof(calls_cannot_fail_ecc[0]); } + #ifndef OPENSSL_NO_ENGINE else { calls_cannot_fail = calls_cannot_fail_engine; calls_cannot_fail_size = sizeof(calls_cannot_fail_engine) / sizeof(calls_cannot_fail_engine[0]); } + #endif // OPENSSL_NO_ENGINE //act int result; @@ -592,12 +638,18 @@ BEGIN_TEST_SUITE(x509_openssl_unittests) if (!use_engine) { + #ifndef OPENSSL_NO_ENGINE result = x509_openssl_add_credentials(TEST_SSL_CTX_STRUCTURE, TEST_PUBLIC_CERTIFICATE, TEST_PRIVATE_CERTIFICATE, KEY_TYPE_DEFAULT, NULL); + #else // OPENSSL_NO_ENGINE + result = x509_openssl_add_credentials(TEST_SSL_CTX_STRUCTURE, TEST_PUBLIC_CERTIFICATE, TEST_PRIVATE_CERTIFICATE, KEY_TYPE_DEFAULT); + #endif // OPENSSL_NO_ENGINE } + #ifndef OPENSSL_NO_ENGINE else { result = x509_openssl_add_credentials(TEST_SSL_CTX_STRUCTURE, TEST_PUBLIC_CERTIFICATE, TEST_KEY_ID, KEY_TYPE_ENGINE, TEST_ENGINE); } + #endif // OPENSSL_NO_ENGINE //assert ASSERT_ARE_NOT_EQUAL(int, 0, result, tmp_msg); @@ -619,10 +671,12 @@ BEGIN_TEST_SUITE(x509_openssl_unittests) x509_openssl_add_credentials_fails(/* is_rsa: */ false, /* use_engine: */ false); } + #ifndef OPENSSL_NO_ENGINE TEST_FUNCTION(x509_openssl_add_engine_credentials_fails) { x509_openssl_add_credentials_fails(/* is_rsa: */ false, /* use_engine: */ true); } + #endif // OPENSSL_NO_ENGINE /*Tests_SRS_X509_OPENSSL_02_010: [ If ssl_ctx is NULL then x509_openssl_add_certificates shall fail and return a non-zero value. ]*/ TEST_FUNCTION(x509_openssl_add_certificates_with_NULL_ssl_ctx_fails) diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/x509_schannel_int/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/x509_schannel_int/main.c index af3f30df8..8f3f5f5ec 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/x509_schannel_int/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/x509_schannel_int/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(x509_schannel_int, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/x509_schannel_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/x509_schannel_ut/main.c index 6e0f7de92..98182afc7 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/x509_schannel_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/x509_schannel_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(x509_schannel_unittests, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/xio_ut/main.c b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/xio_ut/main.c index 98f8848a1..678db651e 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/xio_ut/main.c +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/xio_ut/main.c @@ -8,5 +8,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(xio_unittests, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/testtools/CMakeLists.txt b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/testtools/CMakeLists.txt index 2310abc13..1b37208a3 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/testtools/CMakeLists.txt +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/testtools/CMakeLists.txt @@ -8,6 +8,10 @@ include("../configs/azure_c_shared_utilityFunctions.cmake") usePermissiveRulesForSamplesAndTests() if(NOT ${use_installed_dependencies}) + if(MACOSX) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-strict-prototypes") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-strict-prototypes") + endif() if ((NOT TARGET ctest) AND (EXISTS ${CMAKE_CURRENT_LIST_DIR}/ctest/CMakeLists.txt)) add_subdirectory(ctest) endif() diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/testtools/SerialPort/SerialPort/App.config b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/testtools/SerialPort/SerialPort/App.config index 8e1564635..4bfa00561 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/testtools/SerialPort/SerialPort/App.config +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/testtools/SerialPort/SerialPort/App.config @@ -1,6 +1,6 @@ - + - + - \ No newline at end of file + diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/testtools/SerialPort/SerialPort/SerialPort.csproj b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/testtools/SerialPort/SerialPort/SerialPort.csproj index 13c4f5835..02cce2de5 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/testtools/SerialPort/SerialPort/SerialPort.csproj +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/testtools/SerialPort/SerialPort/SerialPort.csproj @@ -9,8 +9,9 @@ Properties Azure.IoT.Internal.Tools Azure.IoT.Internal.Tools.SerialPort - v4.5 + v4.8 512 + AnyCPU diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/testtools/micromock/inc/micromocktestrunnerhooks.h b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/testtools/micromock/inc/micromocktestrunnerhooks.h index 5034312e4..8e553ad70 100644 --- a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/testtools/micromock/inc/micromocktestrunnerhooks.h +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/testtools/micromock/inc/micromocktestrunnerhooks.h @@ -14,11 +14,7 @@ #define MOCK_ASSERT(expected, actual, assertString) ASSERT_ARE_EQUAL((expected), (actual), (assertString)) #define MOCK_FAIL(expression) ASSERT_FAIL(expression) -#ifndef MBED_BUILD_TIMESTAMP #define MOCK_THROW(mockException) throw(mockException) -#else -#define MOCK_THROW(mockException) -#endif #else // MOCK_ASSERT #define MOCK_THROW(...) diff --git a/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/testtools/testrunner/tools/kick_jenkins.cmd b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/testtools/testrunner/tools/kick_jenkins.cmd new file mode 100644 index 000000000..b96c1f4d4 --- /dev/null +++ b/src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/testtools/testrunner/tools/kick_jenkins.cmd @@ -0,0 +1,124 @@ +@REM Copyright (c) Microsoft. All rights reserved. +@REM Licensed under the MIT license. See LICENSE file in the project root for full license information. + +@setlocal EnableExtensions EnableDelayedExpansion +@echo off + +set current-path=%~dp0 + +rem // remove trailing slash +set current-path=%current-path:~0,-1% + +set build-root=%current-path%\.. +rem // resolve to fully qualified path +for %%i in ("%build-root%") do set build-root=%%~fi + +REM check that we have a valid argument +if "%1" equ "" ( + set jenkins_job=_integrate-into-develop +) else if /i "%1" equ "c" ( + set jenkins_job=_integrate-into-develop-c-and-wrappers +) else if /i "%1" equ "csharp" ( + set jenkins_job=_integrate-into-develop-csharp +) else if /i "%1" equ "java" ( + set jenkins_job=_integrate-into-develop-java +) else if /i "%1" equ "node" ( + set jenkins_job=_integrate-into-develop-node +) else ( + echo Usage: + echo kick_jenkins + echo or + echo "kick_jenkins c | csharp | java | node" + exit /b 1 +) + +REM check that we have java handy +call :checkExists java +if not !ERRORLEVEL!==0 exit /b !ERRORLEVEL! + +REM check that jenkins-cli.jar is in the repository's tools folder +if not exist %build-root%\tools\jenkins-cli.jar ( + echo jenkins-cli does not exist + echo Downloading from repository: + echo http://azure-iot-sdks-ci.westus.cloudapp.azure.com:8080/jnlpJars/jenkins-cli.jar + + powershell -Command "Invoke-WebRequest http://azure-iot-sdks-ci.westus.cloudapp.azure.com:8080/jnlpJars/jenkins-cli.jar -OutFile %build-root%\tools\jenkins-cli.jar" + + if not !ERRORLEVEL!==0 ( + echo Failed downloading jenkins-cli.jar + echo Use the following link to manually download it into the tools folder of your repository: + echo http://azure-iot-sdks-ci.westus.cloudapp.azure.com:8080/jnlpJars/jenkins-cli.jar + exit /b 1 + ) +) + +REM find current branch +for /f "usebackq tokens=*" %%i in (`git symbolic-ref -q HEAD`) do set "current_branch_ref=%%i" +if defined current_branch_ref set "current_branch=%current_branch_ref:refs/heads/=%" + +REM handle detached HEAD +if not defined current_branch ( + echo You're not on any branch! Aborting... + goto :eof +) + +REM Must be on a topic branch when running this script +set __exit=1 +if not "%current_branch%"=="master" if not "%current_branch%"=="develop" set __exit=0 +if %__exit%==1 ( + echo You cannot call this script from 'develop' or 'master'. Change to a topic branch first. Aborting... + goto :eof +) + +REM find tracking branch +for /f "usebackq tokens=*" %%i in (`git rev-parse --symbolic-full-name --abbrev-ref @{u}`) do set "tracking_branch=%%i" +if not defined tracking_branch ( + echo Branch ^'%current_branch%^' is not tracking a remote branch! First try ^'git branch -u ^/^^' to set tracking info. Aborting... + goto :eof +) + +for /f "usebackq tokens=*" %%i in (`git config branch.%current_branch%.remote`) do set "remote=%%i" +if not defined remote ( + REM should never happen... + echo Cannot isolate remote name for tracking branch ^'%tracking_branch%^'! Aborting... + goto :eof +) + +REM get the tracking branch name only e.g., origin/topic -> topic +for /f "usebackq tokens=*" %%i in (`call echo %%tracking_branch:%remote%/^=%%`) do set "tracking_name=%%i" + +REM find repo url +for /f "usebackq tokens=*" %%i in (`git ls-remote --heads --get-url %remote%`) do set "repo_url=%%i" +if not defined repo_url ( + echo Cannot find the remote repository URL! Aborting... + goto :eof +) + +echo **************************************************************** +echo commit_id: %current_branch% +echo repo_url: %repo_url% +echo remote: %remote% +echo trackingN: %tracking_name% +echo jenkinJob: %jenkins_job% +echo **************************************************************** + + +REM kick off the build! +java -jar "%build-root%"\tools\jenkins-cli.jar -s http://azure-iot-sdks-ci.westus.cloudapp.azure.com:8080/ build %jenkins_job% -p COMMIT_ID=%tracking_name% -p AZURE_REPO=%repo_url% -p BRANCH_TO_MERGE_TO=develop -s -v + +rem ----------------------------------------------------------------------------- +rem -- done +rem ----------------------------------------------------------------------------- +goto :eof + +rem ----------------------------------------------------------------------------- +rem -- helper subroutines +rem ----------------------------------------------------------------------------- +:checkExists +where %~1 >nul 2>nul +if not !ERRORLEVEL!==0 ( + echo "%~1" not found. Please make sure that "%~1" is installed and available in the path. + exit /b !ERRORLEVEL! +) +goto :eof + diff --git a/src/vendor/azure-uamqp-c/deps/umock-c/deps/testrunner/tools/kick_jenkins.cmd b/src/vendor/azure-uamqp-c/deps/umock-c/deps/testrunner/tools/kick_jenkins.cmd new file mode 100644 index 000000000..b96c1f4d4 --- /dev/null +++ b/src/vendor/azure-uamqp-c/deps/umock-c/deps/testrunner/tools/kick_jenkins.cmd @@ -0,0 +1,124 @@ +@REM Copyright (c) Microsoft. All rights reserved. +@REM Licensed under the MIT license. See LICENSE file in the project root for full license information. + +@setlocal EnableExtensions EnableDelayedExpansion +@echo off + +set current-path=%~dp0 + +rem // remove trailing slash +set current-path=%current-path:~0,-1% + +set build-root=%current-path%\.. +rem // resolve to fully qualified path +for %%i in ("%build-root%") do set build-root=%%~fi + +REM check that we have a valid argument +if "%1" equ "" ( + set jenkins_job=_integrate-into-develop +) else if /i "%1" equ "c" ( + set jenkins_job=_integrate-into-develop-c-and-wrappers +) else if /i "%1" equ "csharp" ( + set jenkins_job=_integrate-into-develop-csharp +) else if /i "%1" equ "java" ( + set jenkins_job=_integrate-into-develop-java +) else if /i "%1" equ "node" ( + set jenkins_job=_integrate-into-develop-node +) else ( + echo Usage: + echo kick_jenkins + echo or + echo "kick_jenkins c | csharp | java | node" + exit /b 1 +) + +REM check that we have java handy +call :checkExists java +if not !ERRORLEVEL!==0 exit /b !ERRORLEVEL! + +REM check that jenkins-cli.jar is in the repository's tools folder +if not exist %build-root%\tools\jenkins-cli.jar ( + echo jenkins-cli does not exist + echo Downloading from repository: + echo http://azure-iot-sdks-ci.westus.cloudapp.azure.com:8080/jnlpJars/jenkins-cli.jar + + powershell -Command "Invoke-WebRequest http://azure-iot-sdks-ci.westus.cloudapp.azure.com:8080/jnlpJars/jenkins-cli.jar -OutFile %build-root%\tools\jenkins-cli.jar" + + if not !ERRORLEVEL!==0 ( + echo Failed downloading jenkins-cli.jar + echo Use the following link to manually download it into the tools folder of your repository: + echo http://azure-iot-sdks-ci.westus.cloudapp.azure.com:8080/jnlpJars/jenkins-cli.jar + exit /b 1 + ) +) + +REM find current branch +for /f "usebackq tokens=*" %%i in (`git symbolic-ref -q HEAD`) do set "current_branch_ref=%%i" +if defined current_branch_ref set "current_branch=%current_branch_ref:refs/heads/=%" + +REM handle detached HEAD +if not defined current_branch ( + echo You're not on any branch! Aborting... + goto :eof +) + +REM Must be on a topic branch when running this script +set __exit=1 +if not "%current_branch%"=="master" if not "%current_branch%"=="develop" set __exit=0 +if %__exit%==1 ( + echo You cannot call this script from 'develop' or 'master'. Change to a topic branch first. Aborting... + goto :eof +) + +REM find tracking branch +for /f "usebackq tokens=*" %%i in (`git rev-parse --symbolic-full-name --abbrev-ref @{u}`) do set "tracking_branch=%%i" +if not defined tracking_branch ( + echo Branch ^'%current_branch%^' is not tracking a remote branch! First try ^'git branch -u ^/^^' to set tracking info. Aborting... + goto :eof +) + +for /f "usebackq tokens=*" %%i in (`git config branch.%current_branch%.remote`) do set "remote=%%i" +if not defined remote ( + REM should never happen... + echo Cannot isolate remote name for tracking branch ^'%tracking_branch%^'! Aborting... + goto :eof +) + +REM get the tracking branch name only e.g., origin/topic -> topic +for /f "usebackq tokens=*" %%i in (`call echo %%tracking_branch:%remote%/^=%%`) do set "tracking_name=%%i" + +REM find repo url +for /f "usebackq tokens=*" %%i in (`git ls-remote --heads --get-url %remote%`) do set "repo_url=%%i" +if not defined repo_url ( + echo Cannot find the remote repository URL! Aborting... + goto :eof +) + +echo **************************************************************** +echo commit_id: %current_branch% +echo repo_url: %repo_url% +echo remote: %remote% +echo trackingN: %tracking_name% +echo jenkinJob: %jenkins_job% +echo **************************************************************** + + +REM kick off the build! +java -jar "%build-root%"\tools\jenkins-cli.jar -s http://azure-iot-sdks-ci.westus.cloudapp.azure.com:8080/ build %jenkins_job% -p COMMIT_ID=%tracking_name% -p AZURE_REPO=%repo_url% -p BRANCH_TO_MERGE_TO=develop -s -v + +rem ----------------------------------------------------------------------------- +rem -- done +rem ----------------------------------------------------------------------------- +goto :eof + +rem ----------------------------------------------------------------------------- +rem -- helper subroutines +rem ----------------------------------------------------------------------------- +:checkExists +where %~1 >nul 2>nul +if not !ERRORLEVEL!==0 ( + echo "%~1" not found. Please make sure that "%~1" is installed and available in the path. + exit /b !ERRORLEVEL! +) +goto :eof + diff --git a/src/vendor/azure-uamqp-c/deps/umock-c/src/umocktypes_wcharptr.c b/src/vendor/azure-uamqp-c/deps/umock-c/src/umocktypes_wcharptr.c index 0c4ed9245..3518277a0 100644 --- a/src/vendor/azure-uamqp-c/deps/umock-c/src/umocktypes_wcharptr.c +++ b/src/vendor/azure-uamqp-c/deps/umock-c/src/umocktypes_wcharptr.c @@ -14,9 +14,9 @@ static void mbstate_t_init(mbstate_t* ps) { + (void)memset(ps, 0, sizeof(*ps)); const wchar_t empty[] = L""; const wchar_t* srcp = empty; - (void)memset(ps, 0, sizeof(*ps)); (void)wcsrtombs(NULL, &srcp, 0, ps); } @@ -44,10 +44,9 @@ char* umocktypes_stringify_wcharptr(const wchar_t** value) { /* Codes_SRS_UMOCKTYPES_WCHARPTR_01_002: [ umocktypes_stringify_wcharptr shall return a string containing the string representation of value, enclosed by quotes ("value"). ] */ const wchar_t* same_as_source = *value; - size_t num_characters; mbstate_t state; mbstate_t_init(&state); - num_characters = wcsrtombs(NULL, &same_as_source, 0, &state); + size_t num_characters = wcsrtombs(NULL, &same_as_source, 0, &state); if (num_characters == (size_t)(-1)) { UMOCK_LOG("failure to get the length of the string: %s", strerror(errno)); @@ -202,10 +201,9 @@ char* umocktypes_stringify_const_wcharptr(const wchar_t** value) { /* Codes_SRS_UMOCKTYPES_WCHARPTR_01_019: [ umocktypes_stringify_const_wcharptr shall return a string containing the string representation of value, enclosed by quotes ("value"). ] */ const wchar_t* same_as_source = *value; - size_t num_characters; mbstate_t state; mbstate_t_init(&state); - num_characters = wcsrtombs(NULL, &same_as_source, 0, &state); + size_t num_characters = wcsrtombs(NULL, &same_as_source, 0, &state); if (num_characters == (size_t)(-1)) { UMOCK_LOG("failure to get the length of the string: %s", strerror(errno)); diff --git a/src/vendor/azure-uamqp-c/devdoc/sasl_frame_codec_requirements.md b/src/vendor/azure-uamqp-c/devdoc/sasl_frame_codec_requirements.md index de491f149..98a923f66 100644 --- a/src/vendor/azure-uamqp-c/devdoc/sasl_frame_codec_requirements.md +++ b/src/vendor/azure-uamqp-c/devdoc/sasl_frame_codec_requirements.md @@ -92,4 +92,6 @@ SASL performatives are framed as per Part 2: section 2.3. **SRS_SASL_FRAME_CODEC Figure 5.5: SASL Frame -**SRS_SASL_FRAME_CODEC_01_016: [**The maximum size of a SASL frame is defined by MIN-MAX-FRAME-SIZE.**]** There is no mechanism within the SASL negotiation to negotiate a different size. **SRS_SASL_FRAME_CODEC_01_047: [**The frame body of a SASL frame MUST contain exactly one AMQP type, whose type encoding MUST have provides="sasl-frame".**]** Receipt of an empty frame is an irrecoverable error. +**SRS_SASL_FRAME_CODEC_01_016: [**The maximum size of a SASL frame is defined by MIN-MAX-FRAME-SIZE.**]** There is no mechanism within the SASL negotiation to negotiate a different size. +**SRS_SASL_FRAME_CODEC_01_017: [**The minimum size of a SASL frame is defined by MIN_FRAME_SIZE (1 byte).**]** Allowing size of zero can expose a vulnerability to malloc attacks. +**SRS_SASL_FRAME_CODEC_01_047: [**The frame body of a SASL frame MUST contain exactly one AMQP type, whose type encoding MUST have provides="sasl-frame".**]** Receipt of an empty frame is an irrecoverable error. diff --git a/src/vendor/azure-uamqp-c/devdoc/sasl_plain_requirements.md b/src/vendor/azure-uamqp-c/devdoc/sasl_plain_requirements.md index 25810bd80..aa95b05ab 100644 --- a/src/vendor/azure-uamqp-c/devdoc/sasl_plain_requirements.md +++ b/src/vendor/azure-uamqp-c/devdoc/sasl_plain_requirements.md @@ -108,6 +108,7 @@ The formal grammar for the client message using Augmented BNF [ABNF] follows. **SRS_SASL_PLAIN_01_019: [** message = [authzid] UTF8NUL authcid UTF8NUL passwd**]** **SRS_SASL_PLAIN_01_020: [** authcid = 1*SAFE ; MUST accept up to 255 octets**]** **SRS_SASL_PLAIN_01_021: [** authzid = 1*SAFE ; MUST accept up to 255 octets**]** +[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Not a password")] **SRS_SASL_PLAIN_01_022: [** passwd = 1*SAFE ; MUST accept up to 255 octets**]** UTF8NUL = %x00 ; UTF-8 encoded NUL character diff --git a/src/vendor/azure-uamqp-c/jenkins/debian_c.sh b/src/vendor/azure-uamqp-c/jenkins/debian_c.sh new file mode 100644 index 000000000..a68f272a2 --- /dev/null +++ b/src/vendor/azure-uamqp-c/jenkins/debian_c.sh @@ -0,0 +1,33 @@ +#!/bin/bash +# Copyright (c) Microsoft. All rights reserved. +# Licensed under the MIT license. See LICENSE file in the project root for full license information. +# + +set -e + +script_dir=$(cd "$(dirname "$0")" && pwd) +build_root=$(cd "${script_dir}/.." && pwd) +log_dir=$build_root +make_install= +build_folder=$build_root"/cmake/uhttp" + +rm -r -f $build_folder +mkdir -p $build_folder +pushd $build_folder +cmake ../.. -Drun_valgrind:BOOL=ON -Drun_unittests:bool=ON +if [ $? != 0 ];then +echo "Failure running cmake" +fi + +cmake --build . -- --jobs=$(nproc) +if [ $? != 0 ];then +echo "Failure running build" +fi + +ctest -j $(nproc) -C "debug" -V +if [ $? != 0 ];then +echo "Failure running ctest" +fi + +popd +: \ No newline at end of file diff --git a/src/vendor/azure-uamqp-c/jenkins/linux_c_option_test.sh b/src/vendor/azure-uamqp-c/jenkins/linux_c_option_test.sh new file mode 100644 index 000000000..960cdc63b --- /dev/null +++ b/src/vendor/azure-uamqp-c/jenkins/linux_c_option_test.sh @@ -0,0 +1,55 @@ +#!/bin/bash +#set -o pipefail +# +# Copyright (c) Microsoft. All rights reserved. +# Licensed under the MIT license. See LICENSE file in the project root for full license information. + +set -e + +cat /etc/*release | grep VERSION* +gcc --version +openssl version + +script_dir=$(cd "$(dirname "$0")" && pwd) +build_root=$(cd "${script_dir}/.." && pwd) +build_folder=$build_root"/cmake/mqtt_option" + +# Set the default cores +MAKE_CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu) + +echo "Initial MAKE_CORES=$MAKE_CORES" + +# Make sure there is enough virtual memory on the device to handle more than one job +MINVSPACE="1500000" + +# Acquire total memory and total swap space setting them to zero in the event the command fails +MEMAR=( $(sed -n -e 's/^MemTotal:[^0-9]*\([0-9][0-9]*\).*/\1/p' -e 's/^SwapTotal:[^0-9]*\([0-9][0-9]*\).*/\1/p' /proc/meminfo) ) +[ -z "${MEMAR[0]##*[!0-9]*}" ] && MEMAR[0]=0 +[ -z "${MEMAR[1]##*[!0-9]*}" ] && MEMAR[1]=0 + +let VSPACE=${MEMAR[0]}+${MEMAR[1]} + +if [ "$VSPACE" -lt "$MINVSPACE" ] ; then +echo "WARNING: Not enough space. Setting MAKE_CORES=1" +MAKE_CORES=1 +fi + +declare -a arr=( + "-Dskip_samples=ON" + "-Dno_logging=ON" + "-Denable_raw_logging=ON" + "-Denable_raw_logging=ON -Dno_logging=ON" +) + +for item in "${arr[@]}" +do + rm -r -f $build_folder + mkdir -p $build_folder + pushd $build_folder + + echo "executing cmake/make with options <<$item>>" + cmake $build_root "$item" + + make --jobs=$MAKE_CORES +done +popd diff --git a/src/vendor/azure-uamqp-c/jenkins/linux_wolfssl.sh b/src/vendor/azure-uamqp-c/jenkins/linux_wolfssl.sh new file mode 100644 index 000000000..dace52a81 --- /dev/null +++ b/src/vendor/azure-uamqp-c/jenkins/linux_wolfssl.sh @@ -0,0 +1,26 @@ +#!/bin/bash +# Copyright (c) Microsoft. All rights reserved. +# Licensed under the MIT license. See LICENSE file in the project root for full license information. + +set -e + +build_root=$(cd "$(dirname "$0")/.." && pwd) +cd $build_root + +build_folder=$build_root"/cmake/shared-util_linux" + +# Set the default cores +CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu) + +rm -r -f $build_folder +mkdir -p $build_folder +pushd $build_folder +cmake $build_root -Drun_unittests:BOOL=ON -Duse_wolfssl:BOOL=ON -Duse_openssl:BOOL=OFF -D CMAKE_C_COMPILER=gcc +make --jobs=$CORES + +#use doctored openssl +export LD_LIBRARY_PATH=/usr/local/ssl/lib +ctest -j $CORES --output-on-failure +export LD_LIBRARY_PATH= + +popd diff --git a/src/vendor/azure-uamqp-c/jenkins/ubuntu_c.sh b/src/vendor/azure-uamqp-c/jenkins/ubuntu_c.sh new file mode 100644 index 000000000..4ea3c492e --- /dev/null +++ b/src/vendor/azure-uamqp-c/jenkins/ubuntu_c.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# Copyright (c) Microsoft. All rights reserved. +# Licensed under the MIT license. See LICENSE file in the project root for full license information. +# + +set -e + +script_dir=$(cd "$(dirname "$0")" && pwd) +build_root=$(cd "${script_dir}/.." && pwd) +log_dir=$build_root +make_install= +build_folder=$build_root"/cmake" + +rm -r -f $build_folder +mkdir -p $build_folder +pushd $build_folder +cmake .. -Drun_valgrind:BOOL=ON -Drun_unittests:bool=ON -Drun_e2e_tests:bool=ON +cmake --build . -- --jobs=$(nproc) +ctest -C "debug" -V +if [[ $make_install == 1 ]] ; +then + echo "Installing packaging" + # install the package + make install +fi + +popd +: \ No newline at end of file diff --git a/src/vendor/azure-uamqp-c/jenkins/windows_c_VsDevCmd.cmd b/src/vendor/azure-uamqp-c/jenkins/windows_c_VsDevCmd.cmd new file mode 100644 index 000000000..8f6612707 --- /dev/null +++ b/src/vendor/azure-uamqp-c/jenkins/windows_c_VsDevCmd.cmd @@ -0,0 +1,27 @@ +@REM Copyright (c) Microsoft. All rights reserved. +@REM Licensed under the MIT license. See LICENSE file in the project root for full license information. + +echo ***setting VC paths*** +IF EXIST "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\VsMSBuildCmd.bat" ( + call "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\VsMSBuildCmd.bat" + set VSVERSION="Visual Studio 15 2017" +) ELSE IF EXIST "%ProgramFiles%\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\VsDevCmd.bat" ( + IF "%1" == "x64" ( + call "%ProgramFiles%\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\VsDevCmd.bat" -arch=amd64 + ) ELSE ( + call "%ProgramFiles%\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\VsDevCmd.bat" + ) + set VSVERSION="Visual Studio 17 2022" +) ELSE ( + echo "ERROR: Did not find Microsoft Visual Studio" + EXIT 1 +) + +where /q msbuild +IF ERRORLEVEL 1 ( + echo "ERROR: Did not find msbuild" + exit %ERRORLEVEL% +) + +where msbuild +msbuild -version diff --git a/src/vendor/azure-uamqp-c/jenkins/windows_c_build_as_dynamic.cmd b/src/vendor/azure-uamqp-c/jenkins/windows_c_build_as_dynamic.cmd new file mode 100644 index 000000000..514682b38 --- /dev/null +++ b/src/vendor/azure-uamqp-c/jenkins/windows_c_build_as_dynamic.cmd @@ -0,0 +1,24 @@ +@REM Copyright (c) Microsoft. All rights reserved. +@REM Licensed under the MIT license. See LICENSE file in the project root for full license information. + +@setlocal +@echo off + +set cmake_dir=dynamic_build +set build-root=%~dp0.. +@REM // resolve to fully qualified path +for %%i in ("%build-root%") do set build-root=%%~fi + +if EXIST %build-root%\cmake\%cmake_dir% ( + rmdir /s/q %build-root%\cmake\%cmake_dir% +) +mkdir %build-root%\cmake\%cmake_dir% +if errorlevel 1 goto :eof + +cd %build-root%\cmake\%cmake_dir% + +cmake -Dskip_samples=ON -Dbuild_as_dynamic=ON ..\.. +if errorlevel 1 goto :eof + +cmake --build . -- /m +if errorlevel 1 goto :eof diff --git a/src/vendor/azure-uamqp-c/readme.md b/src/vendor/azure-uamqp-c/readme.md index f24abf609..95a1a9b17 100644 --- a/src/vendor/azure-uamqp-c/readme.md +++ b/src/vendor/azure-uamqp-c/readme.md @@ -2,7 +2,7 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope # uAMQP -`uAMQP` is a general purpose C library for AMQP 1.0. +`uAMQP` is a C library for AMQP 1.0 communication to Azure Cloud Services. The goals are: @@ -10,10 +10,7 @@ The goals are: - Optimizing for low RAM footprint - Be as portable as possible -It is currently mostly a client side implementation only. -Although much of the standard is symmetrical, there are parts that are asymmetrical, like the SASL handshake. - -The server side support of `uAMQP` (for example for SASL) is currently work in progress. +It is currently a client side implementation only. ## Dependencies diff --git a/src/vendor/azure-uamqp-c/src/amqp_definitions.c b/src/vendor/azure-uamqp-c/src/amqp_definitions.c index 6952316f7..04261ad3c 100644 --- a/src/vendor/azure-uamqp-c/src/amqp_definitions.c +++ b/src/vendor/azure-uamqp-c/src/amqp_definitions.c @@ -18516,3 +18516,4 @@ int modified_set_message_annotations(MODIFIED_HANDLE modified, fields message_an return result; } + diff --git a/src/vendor/azure-uamqp-c/src/amqpvalue_to_string.c b/src/vendor/azure-uamqp-c/src/amqpvalue_to_string.c index 964ce46e9..b5148a414 100644 --- a/src/vendor/azure-uamqp-c/src/amqpvalue_to_string.c +++ b/src/vendor/azure-uamqp-c/src/amqpvalue_to_string.c @@ -13,6 +13,7 @@ #include "azure_c_shared_utility/uuid.h" #include "azure_uamqp_c/amqpvalue_to_string.h" #include "azure_uamqp_c/amqpvalue.h" +#include "azure_c_shared_utility/safe_math.h" #if _WIN32 /* The MS runtime does not have snprintf */ @@ -35,10 +36,11 @@ static int string_concat(char** string, const char* to_concat) src_length = 0; } - new_string = (char*)realloc(*string, src_length + length); - if (new_string == NULL) + size_t realloc_size = safe_add_size_t(src_length, length); + if (realloc_size == SIZE_MAX || + (new_string = (char*)realloc(*string, realloc_size)) == NULL) { - LogError("Cannot allocate memory for the new string"); + LogError("Cannot allocate memory for the new string, size:%zu", realloc_size); result = MU_FAILURE; } else diff --git a/src/vendor/azure-uamqp-c/src/async_operation.c b/src/vendor/azure-uamqp-c/src/async_operation.c index 28f37302a..6b802b111 100644 --- a/src/vendor/azure-uamqp-c/src/async_operation.c +++ b/src/vendor/azure-uamqp-c/src/async_operation.c @@ -42,6 +42,7 @@ ASYNC_OPERATION_HANDLE async_operation_create(ASYNC_OPERATION_CANCEL_HANDLER_FUN else { /* Codes_SRS_ASYNC_OPERATION_01_001: [ `async_operation_create` shall return a non-NULL handle to a newly created asynchronous operation instance.]*/ + (void)memset(async_operation, 0, context_size); async_operation->async_operation_cancel_handler = async_operation_cancel_handler; } } diff --git a/src/vendor/azure-uamqp-c/src/connection.c b/src/vendor/azure-uamqp-c/src/connection.c index 028aaadd5..cea721ef2 100644 --- a/src/vendor/azure-uamqp-c/src/connection.c +++ b/src/vendor/azure-uamqp-c/src/connection.c @@ -2195,4 +2195,4 @@ void connection_unsubscribe_on_connection_close_received(ON_CONNECTION_CLOSED_EV event_subscription->on_connection_close_received = NULL; event_subscription->context = NULL; } -} \ No newline at end of file +} diff --git a/src/vendor/azure-uamqp-c/src/sasl_plain.c b/src/vendor/azure-uamqp-c/src/sasl_plain.c index 87829ccec..da34fc239 100644 --- a/src/vendor/azure-uamqp-c/src/sasl_plain.c +++ b/src/vendor/azure-uamqp-c/src/sasl_plain.c @@ -7,6 +7,7 @@ #include "azure_c_shared_utility/gballoc.h" #include "azure_c_shared_utility/xlogging.h" #include "azure_uamqp_c/sasl_plain.h" +#include "azure_c_shared_utility/safe_math.h" typedef struct SASL_PLAIN_INSTANCE_TAG { @@ -66,8 +67,17 @@ CONCRETE_SASL_MECHANISM_HANDLE saslplain_create(void* config) else { /* Ignore UTF8 for now */ - result->init_bytes = (unsigned char*)malloc(authzid_length + authcid_length + passwd_length + 2); - if (result->init_bytes == NULL) + //size_t malloc_size = authzid_length + authcid_length + passwd_length + 2); // use safe add + size_t malloc_size = safe_add_size_t(authzid_length, authcid_length); + malloc_size = safe_add_size_t(malloc_size, passwd_length); + malloc_size = safe_add_size_t(malloc_size, 2); + + if (malloc_size == SIZE_MAX) + { + LogError("malloc size overflow"); + result = NULL; + } + else if ((result->init_bytes = (unsigned char*)malloc(malloc_size)) == NULL) { /* Codes_SRS_SASL_PLAIN_01_002: [If allocating the memory needed for the saslplain instance fails then `saslplain_create` shall return NULL.] */ LogError("Cannot allocate init bytes"); @@ -88,11 +98,22 @@ CONCRETE_SASL_MECHANISM_HANDLE saslplain_create(void* config) (void)memcpy(result->init_bytes, sasl_plain_config->authzid, authzid_length); } - result->init_bytes[authzid_length] = 0; - (void)memcpy(result->init_bytes + authzid_length + 1, sasl_plain_config->authcid, authcid_length); - result->init_bytes[authzid_length + authcid_length + 1] = 0; - (void)memcpy(result->init_bytes + authzid_length + authcid_length + 2, sasl_plain_config->passwd, passwd_length); - result->init_bytes_length = (uint32_t)(authzid_length + authcid_length + passwd_length + 2); + size_t init_bytes_length = safe_add_size_t(safe_add_size_t(authzid_length, authcid_length), 1); + if (authzid_length < malloc_size && init_bytes_length < malloc_size) + { + result->init_bytes[authzid_length] = 0; + (void)memcpy(result->init_bytes + authzid_length + 1, sasl_plain_config->authcid, authcid_length); + result->init_bytes[init_bytes_length] = 0; + (void)memcpy(result->init_bytes + authzid_length + authcid_length + 2, sasl_plain_config->passwd, passwd_length); + result->init_bytes_length = (uint32_t)(authzid_length + authcid_length + passwd_length + 2); + } + else + { + LogError("invalid buffer size"); + free(result->init_bytes); + free(result); + result = NULL; + } } } } diff --git a/src/vendor/azure-uamqp-c/tests/CMakeLists.txt b/src/vendor/azure-uamqp-c/tests/CMakeLists.txt index f7f6a3ade..2e024ed40 100644 --- a/src/vendor/azure-uamqp-c/tests/CMakeLists.txt +++ b/src/vendor/azure-uamqp-c/tests/CMakeLists.txt @@ -13,6 +13,7 @@ add_subdirectory(cbs_ut) add_subdirectory(connection_ut) add_subdirectory(frame_codec_ut) add_subdirectory(header_detect_io_ut) +add_subdirectory(link_ut) add_subdirectory(message_ut) add_subdirectory(sasl_anonymous_ut) add_subdirectory(sasl_frame_codec_ut) diff --git a/src/vendor/azure-uamqp-c/tests/amqp_frame_codec_ut/main.c b/src/vendor/azure-uamqp-c/tests/amqp_frame_codec_ut/main.c index e7bbe6825..ba89d834d 100644 --- a/src/vendor/azure-uamqp-c/tests/amqp_frame_codec_ut/main.c +++ b/src/vendor/azure-uamqp-c/tests/amqp_frame_codec_ut/main.c @@ -7,5 +7,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(amqp_frame_codec_ut, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/tests/amqp_management_ut/main.c b/src/vendor/azure-uamqp-c/tests/amqp_management_ut/main.c index da07f9091..57d1ecdd8 100644 --- a/src/vendor/azure-uamqp-c/tests/amqp_management_ut/main.c +++ b/src/vendor/azure-uamqp-c/tests/amqp_management_ut/main.c @@ -7,5 +7,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(amqp_management_ut, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/tests/amqpvalue_ut/main.c b/src/vendor/azure-uamqp-c/tests/amqpvalue_ut/main.c index ecfd5b35e..2b58ea268 100644 --- a/src/vendor/azure-uamqp-c/tests/amqpvalue_ut/main.c +++ b/src/vendor/azure-uamqp-c/tests/amqpvalue_ut/main.c @@ -7,5 +7,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(amqpvalue_ut, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/tests/async_operation_ut/main.c b/src/vendor/azure-uamqp-c/tests/async_operation_ut/main.c index 146742f1a..0a4fb71cf 100644 --- a/src/vendor/azure-uamqp-c/tests/async_operation_ut/main.c +++ b/src/vendor/azure-uamqp-c/tests/async_operation_ut/main.c @@ -7,5 +7,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(async_operation_ut, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/tests/cbs_ut/main.c b/src/vendor/azure-uamqp-c/tests/cbs_ut/main.c index a904ca93f..f9e1512d1 100644 --- a/src/vendor/azure-uamqp-c/tests/cbs_ut/main.c +++ b/src/vendor/azure-uamqp-c/tests/cbs_ut/main.c @@ -7,5 +7,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(cbs_ut, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/tests/connection_ut/main.c b/src/vendor/azure-uamqp-c/tests/connection_ut/main.c index 9f4bec594..f141ce79d 100644 --- a/src/vendor/azure-uamqp-c/tests/connection_ut/main.c +++ b/src/vendor/azure-uamqp-c/tests/connection_ut/main.c @@ -7,5 +7,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(connection_ut, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/tests/frame_codec_ut/main.c b/src/vendor/azure-uamqp-c/tests/frame_codec_ut/main.c index 70fbf32bc..d5962cf50 100644 --- a/src/vendor/azure-uamqp-c/tests/frame_codec_ut/main.c +++ b/src/vendor/azure-uamqp-c/tests/frame_codec_ut/main.c @@ -7,5 +7,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(frame_codec_ut, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/tests/header_detect_io_ut/main.c b/src/vendor/azure-uamqp-c/tests/header_detect_io_ut/main.c index aa7cd627a..90fce60fb 100644 --- a/src/vendor/azure-uamqp-c/tests/header_detect_io_ut/main.c +++ b/src/vendor/azure-uamqp-c/tests/header_detect_io_ut/main.c @@ -7,5 +7,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(header_detect_io_ut, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/tests/iothub_e2e/CMakeLists.txt b/src/vendor/azure-uamqp-c/tests/iothub_e2e/CMakeLists.txt index a6217e233..c9ed6e42b 100644 --- a/src/vendor/azure-uamqp-c/tests/iothub_e2e/CMakeLists.txt +++ b/src/vendor/azure-uamqp-c/tests/iothub_e2e/CMakeLists.txt @@ -12,6 +12,12 @@ set(${theseTestsName}_c_files set(${theseTestsName}_h_files ) -build_c_test_artifacts(${theseTestsName} ON "tests/uamqp_tests" ADDITIONAL_LIBS uamqp) +file(COPY ../valgrind_suppressions.supp DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +build_c_test_artifacts(${theseTestsName} ON "tests/uamqp_tests" + ADDITIONAL_LIBS + uamqp + VALGRIND_SUPPRESSIONS_FILE + valgrind_suppressions.supp +) compile_c_test_artifacts_as(${theseTestsName} C99) diff --git a/src/vendor/azure-uamqp-c/tests/iothub_e2e/main.c b/src/vendor/azure-uamqp-c/tests/iothub_e2e/main.c index 2d1147f15..d46dfc484 100644 --- a/src/vendor/azure-uamqp-c/tests/iothub_e2e/main.c +++ b/src/vendor/azure-uamqp-c/tests/iothub_e2e/main.c @@ -7,5 +7,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(iothub_e2e, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/tests/link_ut/CMakeLists.txt b/src/vendor/azure-uamqp-c/tests/link_ut/CMakeLists.txt new file mode 100644 index 000000000..a91bcfe54 --- /dev/null +++ b/src/vendor/azure-uamqp-c/tests/link_ut/CMakeLists.txt @@ -0,0 +1,18 @@ +#Copyright (c) Microsoft. All rights reserved. +#Licensed under the MIT license. See LICENSE file in the project root for full license information. + +set(theseTestsName link_ut) +set(${theseTestsName}_test_files +${theseTestsName}.c +) + +set(${theseTestsName}_c_files +../../src/link.c +) + +set(${theseTestsName}_h_files +) + +build_c_test_artifacts(${theseTestsName} ON "tests/uamqp_tests") + +compile_c_test_artifacts_as(${theseTestsName} C99) diff --git a/src/vendor/azure-uamqp-c/tests/link_ut/link_ut.c b/src/vendor/azure-uamqp-c/tests/link_ut/link_ut.c new file mode 100644 index 000000000..038d9335f --- /dev/null +++ b/src/vendor/azure-uamqp-c/tests/link_ut/link_ut.c @@ -0,0 +1,1256 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +#ifdef __cplusplus +#include +#include +#include +#else +#include +#include +#include +#include +#endif + +#include "azure_macro_utils/macro_utils.h" +#include "testrunnerswitcher.h" +#include "umock_c/umock_c.h" +#include "umock_c/umock_c_negative_tests.h" +#include "umock_c/umocktypes_bool.h" +#include "umock_c/umocktypes_stdint.h" + +static void* my_gballoc_malloc(size_t size) +{ + return malloc(size); +} + +static void* my_gballoc_calloc(size_t nmemb, size_t size) +{ + return calloc(nmemb, size); +} + +static void* my_gballoc_realloc(void* ptr, size_t size) +{ + return realloc(ptr, size); +} + +static void my_gballoc_free(void* ptr) +{ + free(ptr); +} + +#define ENABLE_MOCKS + +#include "azure_c_shared_utility/gballoc.h" +#include "azure_c_shared_utility/singlylinkedlist.h" +#include "azure_c_shared_utility/tickcounter.h" +#include "azure_uamqp_c/session.h" +#include "azure_uamqp_c/amqpvalue.h" +#include "azure_uamqp_c/amqp_definitions.h" +#include "azure_uamqp_c/amqp_frame_codec.h" +#include "azure_uamqp_c/async_operation.h" + +#undef ENABLE_MOCK_FILTERING_SWITCH +#define ENABLE_MOCK_FILTERING +#define please_mock_transfer_set_delivery_tag MOCK_ENABLED +#undef ENABLE_MOCK_FILTERING_SWITCH +#undef ENABLE_MOCK_FILTERING + +#undef ENABLE_MOCKS + +#include "azure_uamqp_c/link.h" + +static SESSION_HANDLE TEST_SESSION_HANDLE = (SESSION_HANDLE)0x4000; +const char* TEST_LINK_NAME_1 = "test_link_name_1"; +static TICK_COUNTER_HANDLE TEST_TICK_COUNTER_HANDLE = (TICK_COUNTER_HANDLE)0x4001; +static SINGLYLINKEDLIST_HANDLE TEST_SINGLYLINKEDLIST_HANDLE = (SINGLYLINKEDLIST_HANDLE)0x4002; +static LINK_ENDPOINT_HANDLE TEST_LINK_ENDPOINT = (LINK_ENDPOINT_HANDLE)0x4003; +const AMQP_VALUE TEST_LINK_SOURCE = (AMQP_VALUE)0x4004; +const AMQP_VALUE TEST_LINK_TARGET = (AMQP_VALUE)0x4005; +const AMQP_VALUE TEST_AMQP_VALUE = (AMQP_VALUE)0x4006; +const LIST_ITEM_HANDLE TEST_LIST_ITEM_HANDLE = (LIST_ITEM_HANDLE)0x4007; +const TRANSFER_HANDLE TEST_TRANSFER_HANDLE = (TRANSFER_HANDLE)0x4008; +#define AMQP_BATCHING_FORMAT_CODE 0x80013700 + +static TEST_MUTEX_HANDLE g_testByTest; + +MU_DEFINE_ENUM_STRINGS(UMOCK_C_ERROR_CODE, UMOCK_C_ERROR_CODE_VALUES) + +static void on_umock_c_error(UMOCK_C_ERROR_CODE error_code) +{ + ASSERT_FAIL("umock_c reported error :%" PRI_MU_ENUM "", MU_ENUM_VALUE(UMOCK_C_ERROR_CODE, error_code)); +} + +static int umocktypes_copy_bool_ptr(bool** destination, const bool* source) +{ + int result; + + *destination = (bool*)my_gballoc_malloc(sizeof(bool)); + if (*destination == NULL) + { + result = MU_FAILURE; + } + else + { + *(*destination) = (*source); + + result = 0; + } + + return result; +} + +static void umocktypes_free_bool_ptr(bool** value) +{ + if (*value != NULL) + { + my_gballoc_free(*value); + } +} + +static char* umocktypes_stringify_bool_ptr(const bool** value) +{ + char* result; + + result = (char*)my_gballoc_malloc(8); + if (result != NULL) + { + if (*value == NULL) + { + (void)strcpy(result, "{NULL}"); + } + else if (*(*value) == true) + { + (void)strcpy(result, "{true}"); + } + else + { + (void)strcpy(result, "{false}"); + } + } + + return result; +} + +static int umocktypes_are_equal_bool_ptr(bool** left, bool** right) +{ + int result; + + if (*left == *right) + { + result = 1; + } + else + { + if (*(*left) == *(*right)) + { + result = 1; + } + else + { + result = 0; + } + } + + return result; +} + + +// bool FLOW_HANDLE functions + +static int umocktypes_copy_FLOW_HANDLE(FLOW_HANDLE* destination, const FLOW_HANDLE* source) +{ + int result = 0; + + *(destination) = *(source); + + return result; +} + +static void umocktypes_free_FLOW_HANDLE(FLOW_HANDLE* value) +{ + (void)value; +} + +static char* umocktypes_stringify_FLOW_HANDLE(const FLOW_HANDLE* value) +{ + char temp_buffer[32]; + char* result; + size_t length = sprintf(temp_buffer, "%p", (void*)*value); + if (length < 0) + { + result = NULL; + } + else + { + result = (char*)malloc(length + 1); + if (result != NULL) + { + (void)memcpy(result, temp_buffer, length + 1); + } + } + return result; +} + +static int umocktypes_are_equal_FLOW_HANDLE(FLOW_HANDLE* left, FLOW_HANDLE* right) +{ + int result; + + if (*left == *right) + { + result = 1; + } + else + { + result = 0; + } + + return result; +} + +// TRANSFER umock functions + +static int umocktypes_copy_TRANSFER_HANDLE(TRANSFER_HANDLE* destination, const TRANSFER_HANDLE* source) +{ + int result = 0; + + *(destination) = *(source); + + return result; +} + +static void umocktypes_free_TRANSFER_HANDLE(TRANSFER_HANDLE* value) +{ + (void)value; +} + +static char* umocktypes_stringify_TRANSFER_HANDLE(const TRANSFER_HANDLE* value) +{ + char temp_buffer[32]; + char* result; + size_t length = sprintf(temp_buffer, "%p", (void*)*value); + if (length < 0) + { + result = NULL; + } + else + { + result = (char*)malloc(length + 1); + if (result != NULL) + { + (void)memcpy(result, temp_buffer, length + 1); + } + } + return result; +} + +static int umocktypes_are_equal_TRANSFER_HANDLE(TRANSFER_HANDLE* left, TRANSFER_HANDLE* right) +{ + int result; + + if (*left == *right) + { + result = 1; + } + else + { + result = 0; + } + + return result; +} + +// delivery_tag mocks + +static char* umock_stringify_delivery_tag(const delivery_tag* value) +{ + char* result = (char*)my_gballoc_malloc(1); + (void)value; + result[0] = '\0'; + return result; +} + +static int umock_are_equal_delivery_tag(const delivery_tag* left, const delivery_tag* right) +{ + int result; + + if (left->length != right->length) + { + result = 0; + } + else + { + if (memcmp(left->bytes, right->bytes, left->length) == 0) + { + result = 1; + } + else + { + result = 0; + } + } + + return result; +} + +static int umock_copy_delivery_tag(delivery_tag* destination, const delivery_tag* source) +{ + int result; + + destination->bytes = (const unsigned char*)my_gballoc_malloc(source->length); + if (destination->bytes == NULL) + { + result = -1; + } + else + { + (void)memcpy((void*)destination->bytes, source->bytes, source->length); + destination->length = source->length; + result = 0; + } + + return result; +} + +static void umock_free_delivery_tag(delivery_tag* value) +{ + my_gballoc_free((void*)value->bytes); + value->bytes = NULL; + value->length = 0; +} + + +static TRANSFER_HANDLE test_on_transfer_received_transfer; +static uint32_t test_on_transfer_received_payload_size; +static unsigned char test_on_transfer_received_payload_bytes[2048]; +static AMQP_VALUE test_on_transfer_received(void* context, TRANSFER_HANDLE transfer, uint32_t payload_size, const unsigned char* payload_bytes) +{ + (void)context; + test_on_transfer_received_transfer = transfer; + test_on_transfer_received_payload_size = payload_size; + memcpy(test_on_transfer_received_payload_bytes, payload_bytes, payload_size); + + return (AMQP_VALUE)0x6000; +} + +static LINK_STATE test_on_link_state_changed_new_link_state; +LINK_STATE test_on_link_state_changed_previous_link_state; +static void test_on_link_state_changed(void* context, LINK_STATE new_link_state, LINK_STATE previous_link_state) +{ + (void)context; + test_on_link_state_changed_new_link_state = new_link_state; + test_on_link_state_changed_previous_link_state = previous_link_state; +} + +static void test_on_link_flow_on(void* context) +{ + (void)context; +} + +static void on_delivery_settled(void* context, delivery_number delivery_no, LINK_DELIVERY_SETTLE_REASON reason, AMQP_VALUE delivery_state) +{ + (void)context; + (void)delivery_no; + (void)reason; + (void)delivery_state; +} + +static LINK_HANDLE create_link(role link_role) +{ + umock_c_reset_all_calls(); + + STRICT_EXPECTED_CALL(gballoc_calloc(IGNORED_NUM_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(amqpvalue_clone(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(amqpvalue_clone(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(tickcounter_create()); + STRICT_EXPECTED_CALL(singlylinkedlist_create()); + STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(session_create_link_endpoint(TEST_SESSION_HANDLE, TEST_LINK_NAME_1)); + STRICT_EXPECTED_CALL(session_set_link_endpoint_callback(TEST_LINK_ENDPOINT, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + + return link_create(TEST_SESSION_HANDLE, TEST_LINK_NAME_1, link_role, TEST_LINK_SOURCE, TEST_LINK_TARGET); +} + +// If on_session_state_changed it does the full attach, including receiving the ATTACH response. +static int attach_link(LINK_HANDLE link, role link_role, ON_ENDPOINT_FRAME_RECEIVED* on_frame_received, ON_SESSION_STATE_CHANGED* on_session_state_changed) +{ + int result; + + umock_c_reset_all_calls(); + + ATTACH_HANDLE attach = (ATTACH_HANDLE)0x4999; + + STRICT_EXPECTED_CALL(session_begin(TEST_SESSION_HANDLE)); + + if (on_session_state_changed != NULL) + { + STRICT_EXPECTED_CALL(session_start_link_endpoint(TEST_LINK_ENDPOINT, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, link)) + .CaptureArgumentValue_frame_received_callback(on_frame_received) + .CaptureArgumentValue_on_session_state_changed(on_session_state_changed); + + result = link_attach(link, test_on_transfer_received, test_on_link_state_changed, test_on_link_flow_on, NULL); + } + else + { + ON_SESSION_STATE_CHANGED local_on_session_state_changed = NULL; + ON_ENDPOINT_FRAME_RECEIVED local_on_frame_received = NULL; + AMQP_VALUE performative = (AMQP_VALUE)0x5000; + AMQP_VALUE descriptor = (AMQP_VALUE)0x5001; + uint32_t frame_payload_size = 30; + const unsigned char payload_bytes[30] = { 0 }; + uint64_t max_message_size = 123456; + + STRICT_EXPECTED_CALL(session_start_link_endpoint(TEST_LINK_ENDPOINT, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, link)) + .CaptureArgumentValue_frame_received_callback(&local_on_frame_received) + .CaptureArgumentValue_on_session_state_changed(&local_on_session_state_changed); + + result = link_attach(link, test_on_transfer_received, test_on_link_state_changed, test_on_link_flow_on, NULL); + + umock_c_reset_all_calls(); + STRICT_EXPECTED_CALL(attach_create(IGNORED_PTR_ARG, IGNORED_NUM_ARG, IGNORED_NUM_ARG)) + .SetReturn(attach); + STRICT_EXPECTED_CALL(attach_set_snd_settle_mode(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(attach_set_rcv_settle_mode(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(attach_set_role(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(attach_set_source(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(attach_set_target(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + + if (link_role == role_sender) + { + STRICT_EXPECTED_CALL(attach_set_initial_delivery_count(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + } + + STRICT_EXPECTED_CALL(attach_set_max_message_size(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(session_send_attach(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(attach_destroy(IGNORED_PTR_ARG)); + + local_on_session_state_changed(link, SESSION_STATE_MAPPED, SESSION_STATE_UNMAPPED); + ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); + + umock_c_reset_all_calls(); + // ATTACH response + STRICT_EXPECTED_CALL(amqpvalue_get_inplace_descriptor(performative)) + .SetReturn(descriptor); + STRICT_EXPECTED_CALL(is_attach_type_by_descriptor(IGNORED_PTR_ARG)) + .SetReturn(true); + STRICT_EXPECTED_CALL(amqpvalue_get_attach(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(attach_get_max_message_size(IGNORED_PTR_ARG, IGNORED_PTR_ARG)) + .CopyOutArgumentBuffer(2, &max_message_size, sizeof(max_message_size)); + STRICT_EXPECTED_CALL(attach_destroy(IGNORED_PTR_ARG)); + + local_on_frame_received(link, performative, frame_payload_size, payload_bytes); + + // FLOW received from remote endpoint. + + if (link_role == role_sender) + { + FLOW_HANDLE flow = (FLOW_HANDLE)0x5679; + uint32_t link_credit = 10000; + delivery_number delivery_count = 0; + + STRICT_EXPECTED_CALL(amqpvalue_get_inplace_descriptor(performative)) + .SetReturn(descriptor); + STRICT_EXPECTED_CALL(is_attach_type_by_descriptor(IGNORED_PTR_ARG)) + .SetReturn(false); + STRICT_EXPECTED_CALL(is_flow_type_by_descriptor(IGNORED_PTR_ARG)) + .SetReturn(true); + STRICT_EXPECTED_CALL(amqpvalue_get_flow(IGNORED_PTR_ARG, IGNORED_PTR_ARG)) + .CopyOutArgumentBuffer(2, &flow, sizeof(flow)); + STRICT_EXPECTED_CALL(flow_get_link_credit(IGNORED_PTR_ARG, IGNORED_PTR_ARG)) + .CopyOutArgumentBuffer(2, &link_credit, sizeof(link_credit)) + .SetReturn(0); + STRICT_EXPECTED_CALL(flow_get_delivery_count(IGNORED_PTR_ARG, IGNORED_PTR_ARG)) + .CopyOutArgumentBuffer(2, &delivery_count, sizeof(delivery_count)) + .SetReturn(0); + STRICT_EXPECTED_CALL(flow_destroy(IGNORED_PTR_ARG)); + + local_on_frame_received(link, performative, frame_payload_size, payload_bytes); + } + + ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); + + if (on_frame_received != NULL) + { + *on_frame_received = local_on_frame_received; + } + } + + return result; +} + +BEGIN_TEST_SUITE(link_ut) + +TEST_SUITE_INITIALIZE(suite_init) +{ + int result; + + g_testByTest = TEST_MUTEX_CREATE(); + ASSERT_IS_NOT_NULL(g_testByTest); + + umock_c_init(on_umock_c_error); + + result = umocktypes_bool_register_types(); + ASSERT_ARE_EQUAL(int, 0, result, "Failed registering bool types"); + + result = umocktypes_stdint_register_types(); + ASSERT_ARE_EQUAL(int, 0, result, "Failed registering stdint types"); + + REGISTER_GLOBAL_MOCK_HOOK(gballoc_malloc, my_gballoc_malloc); + REGISTER_GLOBAL_MOCK_HOOK(gballoc_calloc, my_gballoc_calloc); + REGISTER_GLOBAL_MOCK_HOOK(gballoc_realloc, my_gballoc_realloc); + REGISTER_GLOBAL_MOCK_HOOK(gballoc_free, my_gballoc_free); + REGISTER_UMOCK_ALIAS_TYPE(transfer_number, uint32_t); + REGISTER_UMOCK_ALIAS_TYPE(role, bool); + REGISTER_UMOCK_ALIAS_TYPE(delivery_number, uint32_t); + REGISTER_UMOCK_ALIAS_TYPE(sequence_no, uint32_t); + REGISTER_UMOCK_ALIAS_TYPE(handle, uint32_t); + REGISTER_UMOCK_ALIAS_TYPE(sender_settle_mode, uint8_t); + REGISTER_UMOCK_ALIAS_TYPE(receiver_settle_mode, uint8_t); + REGISTER_UMOCK_ALIAS_TYPE(DISPOSITION_HANDLE, void*); + REGISTER_UMOCK_ALIAS_TYPE(AMQP_VALUE, void*); + REGISTER_UMOCK_ALIAS_TYPE(TICK_COUNTER_HANDLE, void*); + REGISTER_UMOCK_ALIAS_TYPE(SINGLYLINKEDLIST_HANDLE, void*); + REGISTER_UMOCK_ALIAS_TYPE(LIST_ITEM_HANDLE, void*); + REGISTER_UMOCK_ALIAS_TYPE(SESSION_HANDLE, void*); + REGISTER_UMOCK_ALIAS_TYPE(ATTACH_HANDLE, void*); + REGISTER_UMOCK_ALIAS_TYPE(LINK_ENDPOINT_HANDLE, void*); + REGISTER_UMOCK_ALIAS_TYPE(ON_LINK_ENDPOINT_DESTROYED_CALLBACK, void*); + REGISTER_UMOCK_ALIAS_TYPE(ON_ENDPOINT_FRAME_RECEIVED, void*); + REGISTER_UMOCK_ALIAS_TYPE(ON_TRANSFER_RECEIVED, void*); + REGISTER_UMOCK_ALIAS_TYPE(ON_LINK_STATE_CHANGED, void*); + REGISTER_UMOCK_ALIAS_TYPE(ON_LINK_FLOW_ON, void*); + REGISTER_UMOCK_ALIAS_TYPE(ON_SESSION_STATE_CHANGED, void*); + REGISTER_UMOCK_ALIAS_TYPE(ON_SESSION_FLOW_ON, void*); + REGISTER_UMOCK_ALIAS_TYPE(ASYNC_OPERATION_CANCEL_HANDLER_FUNC, void*); + REGISTER_UMOCK_ALIAS_TYPE(ASYNC_OPERATION_HANDLE, void*); + REGISTER_UMOCK_ALIAS_TYPE(message_format, uint32_t); + REGISTER_UMOCK_ALIAS_TYPE(ON_SEND_COMPLETE, void*); + REGISTER_UMOCK_ALIAS_TYPE(SESSION_SEND_TRANSFER_RESULT, int); + + REGISTER_GLOBAL_MOCK_RETURNS(tickcounter_create, TEST_TICK_COUNTER_HANDLE, NULL); + REGISTER_GLOBAL_MOCK_RETURNS(singlylinkedlist_create, TEST_SINGLYLINKEDLIST_HANDLE, NULL); + REGISTER_GLOBAL_MOCK_RETURNS(session_create_link_endpoint, TEST_LINK_ENDPOINT, NULL); + REGISTER_GLOBAL_MOCK_RETURNS(session_start_link_endpoint, 0, 1); + + REGISTER_GLOBAL_MOCK_FAIL_RETURN(async_operation_create, NULL); + REGISTER_GLOBAL_MOCK_RETURNS(transfer_create, TEST_TRANSFER_HANDLE, NULL); + REGISTER_GLOBAL_MOCK_RETURNS(transfer_set_delivery_tag, 0, 1); + REGISTER_GLOBAL_MOCK_RETURNS(transfer_set_message_format, 0, 1); + REGISTER_GLOBAL_MOCK_RETURNS(transfer_set_settled, 0, 1); + REGISTER_GLOBAL_MOCK_RETURNS(amqpvalue_create_transfer, TEST_AMQP_VALUE, NULL); + REGISTER_GLOBAL_MOCK_RETURNS(tickcounter_get_current_ms, 0, 1); + REGISTER_GLOBAL_MOCK_RETURNS(singlylinkedlist_add, TEST_LIST_ITEM_HANDLE, NULL); + REGISTER_GLOBAL_MOCK_RETURNS(singlylinkedlist_remove, 0, 1); + REGISTER_GLOBAL_MOCK_RETURNS(session_send_transfer, 0, 1); + + REGISTER_TYPE(FLOW_HANDLE, FLOW_HANDLE); + REGISTER_TYPE(TRANSFER_HANDLE, TRANSFER_HANDLE); + REGISTER_TYPE(bool*, bool_ptr); + REGISTER_TYPE(uint32_t, uint32_t); + + REGISTER_UMOCK_VALUE_TYPE(delivery_tag); +} + +TEST_SUITE_CLEANUP(suite_cleanup) +{ + umock_c_deinit(); + + TEST_MUTEX_DESTROY(g_testByTest); +} + +TEST_FUNCTION_INITIALIZE(test_init) +{ + if (TEST_MUTEX_ACQUIRE(g_testByTest)) + { + ASSERT_FAIL("our mutex is ABANDONED. Failure in test framework"); + } + + umock_c_reset_all_calls(); +} + +TEST_FUNCTION_CLEANUP(test_cleanup) +{ + TEST_MUTEX_RELEASE(g_testByTest); +} + +TEST_FUNCTION(link_create_succeeds) +{ + // arrange + AMQP_VALUE link_source = TEST_LINK_SOURCE; + AMQP_VALUE link_target = TEST_LINK_TARGET; + + umock_c_reset_all_calls(); + + STRICT_EXPECTED_CALL(gballoc_calloc(IGNORED_NUM_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(amqpvalue_clone(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(amqpvalue_clone(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(tickcounter_create()); + STRICT_EXPECTED_CALL(singlylinkedlist_create()); + STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(session_create_link_endpoint(TEST_SESSION_HANDLE, TEST_LINK_NAME_1)); + STRICT_EXPECTED_CALL(session_set_link_endpoint_callback(TEST_LINK_ENDPOINT, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + + // act + LINK_HANDLE link = link_create(TEST_SESSION_HANDLE, TEST_LINK_NAME_1, role_receiver, link_source, link_target); + + // assert + ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); + ASSERT_IS_NOT_NULL(link); + + // cleanup + link_destroy(link); +} + +TEST_FUNCTION(link_attach_succeeds) +{ + // arrange + LINK_HANDLE link = create_link(role_receiver); + ON_ENDPOINT_FRAME_RECEIVED on_frame_received = NULL; + + umock_c_reset_all_calls(); + + STRICT_EXPECTED_CALL(session_begin(TEST_SESSION_HANDLE)); + STRICT_EXPECTED_CALL(session_start_link_endpoint(TEST_LINK_ENDPOINT, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, link)) + .CaptureArgumentValue_frame_received_callback(&on_frame_received); + + // act + int result = link_attach(link, test_on_transfer_received, test_on_link_state_changed, test_on_link_flow_on, NULL); + + // assert + ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); + ASSERT_ARE_EQUAL(int, 0, result); + ASSERT_IS_NOT_NULL(on_frame_received); + + // cleanup + link_destroy(link); +} + +TEST_FUNCTION(link_receiver_frame_received_succeeds) +{ + // arrange + LINK_HANDLE link = create_link(role_receiver); + ON_ENDPOINT_FRAME_RECEIVED on_frame_received = NULL; + ON_SESSION_STATE_CHANGED on_session_state_changed = NULL; + int attach_result = attach_link(link, role_receiver, &on_frame_received, &on_session_state_changed); + ASSERT_ARE_EQUAL(int, 0, attach_result); + + AMQP_VALUE performative = (AMQP_VALUE)0x5000; + AMQP_VALUE descriptor = (AMQP_VALUE)0x5001; + FLOW_HANDLE flow = (FLOW_HANDLE)0x5002; + uint32_t frame_payload_size = 30; + const unsigned char payload_bytes[30] = { 0 }; + + umock_c_reset_all_calls(); + STRICT_EXPECTED_CALL(amqpvalue_get_inplace_descriptor(performative)) + .SetReturn(descriptor); + STRICT_EXPECTED_CALL(is_attach_type_by_descriptor(IGNORED_PTR_ARG)) + .SetReturn(false); + STRICT_EXPECTED_CALL(is_flow_type_by_descriptor(IGNORED_PTR_ARG)) + .SetReturn(1); + STRICT_EXPECTED_CALL(amqpvalue_get_flow(IGNORED_PTR_ARG, IGNORED_PTR_ARG)) + .CopyOutArgumentBuffer(2, &flow, sizeof(flow)); + STRICT_EXPECTED_CALL(flow_destroy(IGNORED_PTR_ARG)); + + // act + on_frame_received(link, performative, frame_payload_size, payload_bytes); + + // assert + ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); + + // cleanup + link_destroy(link); +} + +TEST_FUNCTION(link_sender_frame_received_succeeds) +{ + // arrange + LINK_HANDLE link = create_link(role_sender); + ON_ENDPOINT_FRAME_RECEIVED on_frame_received = NULL; + ON_SESSION_STATE_CHANGED on_session_state_changed = NULL; + int attach_result = attach_link(link, role_sender, &on_frame_received, &on_session_state_changed); + ASSERT_ARE_EQUAL(int, 0, attach_result); + + AMQP_VALUE performative = (AMQP_VALUE)0x5000; + AMQP_VALUE descriptor = (AMQP_VALUE)0x5001; + FLOW_HANDLE flow = (FLOW_HANDLE)0x5002; + uint32_t frame_payload_size = 30; + const unsigned char payload_bytes[30] = { 0 }; + uint32_t link_credit_value = 700; + uint32_t delivery_count_value = 300; + + umock_c_reset_all_calls(); + STRICT_EXPECTED_CALL(amqpvalue_get_inplace_descriptor(performative)) + .SetReturn(descriptor); + STRICT_EXPECTED_CALL(is_attach_type_by_descriptor(IGNORED_PTR_ARG)) + .SetReturn(false); + STRICT_EXPECTED_CALL(is_flow_type_by_descriptor(IGNORED_PTR_ARG)) + .SetReturn(1); + STRICT_EXPECTED_CALL(amqpvalue_get_flow(IGNORED_PTR_ARG, IGNORED_PTR_ARG)) + .CopyOutArgumentBuffer(2, &flow, sizeof(flow)); + STRICT_EXPECTED_CALL(flow_get_link_credit(IGNORED_PTR_ARG, IGNORED_PTR_ARG)) + .CopyOutArgumentBuffer(2, &link_credit_value, sizeof(link_credit_value)); + STRICT_EXPECTED_CALL(flow_get_delivery_count(IGNORED_PTR_ARG, IGNORED_PTR_ARG)) + .CopyOutArgumentBuffer(2, &delivery_count_value, sizeof(delivery_count_value)); + STRICT_EXPECTED_CALL(flow_destroy(IGNORED_PTR_ARG)); + + // act + on_frame_received(link, performative, frame_payload_size, payload_bytes); + + // assert + ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); + + // cleanup + link_destroy(link); +} + +TEST_FUNCTION(link_receiver_frame_received_get_flow_fails_no_double_free_fails) +{ + // arrange + LINK_HANDLE link = create_link(role_receiver); + ON_ENDPOINT_FRAME_RECEIVED on_frame_received = NULL; + ON_SESSION_STATE_CHANGED on_session_state_changed = NULL; + int attach_result = attach_link(link, role_receiver, &on_frame_received, &on_session_state_changed); + ASSERT_ARE_EQUAL(int, 0, attach_result); + + AMQP_VALUE performative = (AMQP_VALUE)0x5000; + AMQP_VALUE descriptor = (AMQP_VALUE)0x5001; + FLOW_HANDLE flow = NULL; + uint32_t frame_payload_size = 30; + const unsigned char payload_bytes[30] = { 0 }; + + umock_c_reset_all_calls(); + STRICT_EXPECTED_CALL(amqpvalue_get_inplace_descriptor(performative)) + .SetReturn(descriptor); + STRICT_EXPECTED_CALL(is_attach_type_by_descriptor(IGNORED_PTR_ARG)) + .SetReturn(false); + STRICT_EXPECTED_CALL(is_flow_type_by_descriptor(IGNORED_PTR_ARG)) + .SetReturn(1); + STRICT_EXPECTED_CALL(amqpvalue_get_flow(IGNORED_PTR_ARG, IGNORED_PTR_ARG)) + .CopyOutArgumentBuffer(2, &flow, sizeof(flow)) + .SetReturn(1); + + // act + on_frame_received(link, performative, frame_payload_size, payload_bytes); + + // assert + ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); + + // cleanup + link_destroy(link); +} + +TEST_FUNCTION(link_receiver_default_max_credit_succeeds) +{ + // arrange + const int DEFAULT_LINK_CREDIT = 10000; + + LINK_HANDLE link = create_link(role_receiver); + + ON_ENDPOINT_FRAME_RECEIVED on_frame_received = NULL; + ON_SESSION_STATE_CHANGED on_session_state_changed = NULL; + int attach_result = attach_link(link, role_receiver, &on_frame_received, &on_session_state_changed); + ASSERT_ARE_EQUAL(int, 0, attach_result); + + ATTACH_HANDLE attach = (ATTACH_HANDLE)0x4999; + AMQP_VALUE performative = (AMQP_VALUE)0x5000; + AMQP_VALUE descriptor = (AMQP_VALUE)0x5001; + FLOW_HANDLE flow = (FLOW_HANDLE)0x5002; + TRANSFER_HANDLE transfer = (TRANSFER_HANDLE)0x5003; + uint32_t frame_payload_size = 30; + const unsigned char payload_bytes[30] = { 0 }; + bool more = false; + DISPOSITION_HANDLE disposition = (DISPOSITION_HANDLE)0x5005; + + umock_c_reset_all_calls(); + STRICT_EXPECTED_CALL(attach_create(IGNORED_PTR_ARG, IGNORED_NUM_ARG, IGNORED_NUM_ARG)) + .SetReturn(attach); + STRICT_EXPECTED_CALL(attach_set_snd_settle_mode(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(attach_set_rcv_settle_mode(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(attach_set_role(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(attach_set_source(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(attach_set_target(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + + STRICT_EXPECTED_CALL(attach_set_max_message_size(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(session_send_attach(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(attach_destroy(IGNORED_PTR_ARG)); + + on_session_state_changed(link, SESSION_STATE_MAPPED, SESSION_STATE_UNMAPPED); + ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); + + umock_c_reset_all_calls(); + STRICT_EXPECTED_CALL(amqpvalue_get_inplace_descriptor(performative)) + .SetReturn(descriptor); + STRICT_EXPECTED_CALL(is_attach_type_by_descriptor(IGNORED_PTR_ARG)) + .SetReturn(false); + STRICT_EXPECTED_CALL(is_flow_type_by_descriptor(IGNORED_PTR_ARG)) + .SetReturn(1); + STRICT_EXPECTED_CALL(amqpvalue_get_flow(IGNORED_PTR_ARG, IGNORED_PTR_ARG)) + .CopyOutArgumentBuffer(2, &flow, sizeof(flow)); + STRICT_EXPECTED_CALL(flow_destroy(IGNORED_PTR_ARG)); + on_frame_received(link, performative, frame_payload_size, payload_bytes); + ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); + + umock_c_reset_all_calls(); + // First transfer results in FLOW to set link credit. + STRICT_EXPECTED_CALL(amqpvalue_get_inplace_descriptor(performative)) + .SetReturn(descriptor); + STRICT_EXPECTED_CALL(is_attach_type_by_descriptor(IGNORED_PTR_ARG)) + .SetReturn(false); + STRICT_EXPECTED_CALL(is_flow_type_by_descriptor(IGNORED_PTR_ARG)) + .SetReturn(false); + STRICT_EXPECTED_CALL(is_transfer_type_by_descriptor(IGNORED_PTR_ARG)) + .SetReturn(true); + STRICT_EXPECTED_CALL(amqpvalue_get_transfer(IGNORED_PTR_ARG, IGNORED_PTR_ARG)) + .CopyOutArgumentBuffer(2, &transfer, sizeof(transfer)); + // send_flow + STRICT_EXPECTED_CALL(flow_create(IGNORED_NUM_ARG, IGNORED_NUM_ARG, IGNORED_NUM_ARG)) + .SetReturn(flow); + STRICT_EXPECTED_CALL(flow_set_link_credit(IGNORED_PTR_ARG, DEFAULT_LINK_CREDIT)); + STRICT_EXPECTED_CALL(flow_set_handle(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(flow_set_delivery_count(IGNORED_PTR_ARG, 0)); + STRICT_EXPECTED_CALL(session_send_flow(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(flow_destroy(IGNORED_PTR_ARG)); + // continue processing TRANSFER + STRICT_EXPECTED_CALL(transfer_get_more(IGNORED_PTR_ARG, IGNORED_PTR_ARG)) + .CopyOutArgumentBuffer(2, &more, sizeof(bool)); + STRICT_EXPECTED_CALL(transfer_get_delivery_id(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(disposition_create(IGNORED_NUM_ARG, IGNORED_NUM_ARG)) + .SetReturn(disposition); + STRICT_EXPECTED_CALL(disposition_set_last(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(disposition_set_settled(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(disposition_set_state(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(session_send_disposition(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(disposition_destroy(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(amqpvalue_destroy(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(transfer_destroy(IGNORED_PTR_ARG)); + + // act + on_frame_received(link, performative, frame_payload_size, payload_bytes); + + // assert + ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); + + // cleanup + link_destroy(link); +} + +TEST_FUNCTION(link_receiver_link_credit_replenish_succeeds) +{ + // arrange + LINK_HANDLE link = create_link(role_receiver); + ASSERT_ARE_EQUAL(int, 0, link_set_max_link_credit(link, 5)); + + ON_ENDPOINT_FRAME_RECEIVED on_frame_received = NULL; + ON_SESSION_STATE_CHANGED on_session_state_changed = NULL; + int attach_result = attach_link(link, role_receiver, &on_frame_received, &on_session_state_changed); + ASSERT_ARE_EQUAL(int, 0, attach_result); + + ATTACH_HANDLE attach = (ATTACH_HANDLE)0x4999; + AMQP_VALUE performative = (AMQP_VALUE)0x5000; + AMQP_VALUE descriptor = (AMQP_VALUE)0x5001; + FLOW_HANDLE flow = (FLOW_HANDLE)0x5002; + TRANSFER_HANDLE transfer = (TRANSFER_HANDLE)0x5003; + uint32_t frame_payload_size = 30; + const unsigned char payload_bytes[30] = { 0 }; + bool more = false; + DISPOSITION_HANDLE disposition = (DISPOSITION_HANDLE)0x5005; + + umock_c_reset_all_calls(); + STRICT_EXPECTED_CALL(attach_create(IGNORED_PTR_ARG, IGNORED_NUM_ARG, IGNORED_NUM_ARG)) + .SetReturn(attach); + STRICT_EXPECTED_CALL(attach_set_snd_settle_mode(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(attach_set_rcv_settle_mode(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(attach_set_role(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(attach_set_source(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(attach_set_target(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + + STRICT_EXPECTED_CALL(attach_set_max_message_size(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(session_send_attach(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(attach_destroy(IGNORED_PTR_ARG)); + + on_session_state_changed(link, SESSION_STATE_MAPPED, SESSION_STATE_UNMAPPED); + ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); + + umock_c_reset_all_calls(); + STRICT_EXPECTED_CALL(amqpvalue_get_inplace_descriptor(performative)) + .SetReturn(descriptor); + STRICT_EXPECTED_CALL(is_attach_type_by_descriptor(IGNORED_PTR_ARG)) + .SetReturn(false); + STRICT_EXPECTED_CALL(is_flow_type_by_descriptor(IGNORED_PTR_ARG)) + .SetReturn(1); + STRICT_EXPECTED_CALL(amqpvalue_get_flow(IGNORED_PTR_ARG, IGNORED_PTR_ARG)) + .CopyOutArgumentBuffer(2, &flow, sizeof(flow)); + STRICT_EXPECTED_CALL(flow_destroy(IGNORED_PTR_ARG)); + on_frame_received(link, performative, frame_payload_size, payload_bytes); + ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); + + umock_c_reset_all_calls(); + // First transfer results in FLOW to set link credit. + STRICT_EXPECTED_CALL(amqpvalue_get_inplace_descriptor(performative)) + .SetReturn(descriptor); + STRICT_EXPECTED_CALL(is_attach_type_by_descriptor(IGNORED_PTR_ARG)) + .SetReturn(false); + STRICT_EXPECTED_CALL(is_flow_type_by_descriptor(IGNORED_PTR_ARG)) + .SetReturn(false); + STRICT_EXPECTED_CALL(is_transfer_type_by_descriptor(IGNORED_PTR_ARG)) + .SetReturn(true); + STRICT_EXPECTED_CALL(amqpvalue_get_transfer(IGNORED_PTR_ARG, IGNORED_PTR_ARG)) + .CopyOutArgumentBuffer(2, &transfer, sizeof(transfer)); + // send_flow + STRICT_EXPECTED_CALL(flow_create(IGNORED_NUM_ARG, IGNORED_NUM_ARG, IGNORED_NUM_ARG)) + .SetReturn(flow); + STRICT_EXPECTED_CALL(flow_set_link_credit(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(flow_set_handle(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(flow_set_delivery_count(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(session_send_flow(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(flow_destroy(IGNORED_PTR_ARG)); + // continue processing TRANSFER + STRICT_EXPECTED_CALL(transfer_get_more(IGNORED_PTR_ARG, IGNORED_PTR_ARG)) + .CopyOutArgumentBuffer(2, &more, sizeof(bool)); + STRICT_EXPECTED_CALL(transfer_get_delivery_id(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(disposition_create(IGNORED_NUM_ARG, IGNORED_NUM_ARG)) + .SetReturn(disposition); + STRICT_EXPECTED_CALL(disposition_set_last(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(disposition_set_settled(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(disposition_set_state(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(session_send_disposition(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(disposition_destroy(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(amqpvalue_destroy(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(transfer_destroy(IGNORED_PTR_ARG)); + on_frame_received(link, performative, frame_payload_size, payload_bytes); + ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); + + umock_c_reset_all_calls(); + + // act + // First 3 transfers result in no FLOW. + for (int i = 0; i < 3; i++) + { + STRICT_EXPECTED_CALL(amqpvalue_get_inplace_descriptor(performative)) + .SetReturn(descriptor); + STRICT_EXPECTED_CALL(is_attach_type_by_descriptor(IGNORED_PTR_ARG)) + .SetReturn(false); + STRICT_EXPECTED_CALL(is_flow_type_by_descriptor(IGNORED_PTR_ARG)) + .SetReturn(false); + STRICT_EXPECTED_CALL(is_transfer_type_by_descriptor(IGNORED_PTR_ARG)) + .SetReturn(true); + STRICT_EXPECTED_CALL(amqpvalue_get_transfer(IGNORED_PTR_ARG, IGNORED_PTR_ARG)) + .CopyOutArgumentBuffer(2, &transfer, sizeof(transfer)); + STRICT_EXPECTED_CALL(transfer_get_more(IGNORED_PTR_ARG, IGNORED_PTR_ARG)) + .CopyOutArgumentBuffer(2, &more, sizeof(bool)); + STRICT_EXPECTED_CALL(transfer_get_delivery_id(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(disposition_create(IGNORED_NUM_ARG, IGNORED_NUM_ARG)) + .SetReturn(disposition); + STRICT_EXPECTED_CALL(disposition_set_last(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(disposition_set_settled(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(disposition_set_state(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(session_send_disposition(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(disposition_destroy(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(amqpvalue_destroy(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(transfer_destroy(IGNORED_PTR_ARG)); + on_frame_received(link, performative, frame_payload_size, payload_bytes); + } + + // And 4th does result in FLOW. + STRICT_EXPECTED_CALL(amqpvalue_get_inplace_descriptor(performative)) + .SetReturn(descriptor); + STRICT_EXPECTED_CALL(is_attach_type_by_descriptor(IGNORED_PTR_ARG)) + .SetReturn(false); + STRICT_EXPECTED_CALL(is_flow_type_by_descriptor(IGNORED_PTR_ARG)) + .SetReturn(false); + STRICT_EXPECTED_CALL(is_transfer_type_by_descriptor(IGNORED_PTR_ARG)) + .SetReturn(true); + STRICT_EXPECTED_CALL(amqpvalue_get_transfer(IGNORED_PTR_ARG, IGNORED_PTR_ARG)) + .CopyOutArgumentBuffer(2, &transfer, sizeof(transfer)); + // send_flow + STRICT_EXPECTED_CALL(flow_create(IGNORED_NUM_ARG, IGNORED_NUM_ARG, IGNORED_NUM_ARG)) + .SetReturn(flow); + STRICT_EXPECTED_CALL(flow_set_link_credit(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(flow_set_handle(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(flow_set_delivery_count(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(session_send_flow(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(flow_destroy(IGNORED_PTR_ARG)); + // continue processing TRANSFER + STRICT_EXPECTED_CALL(transfer_get_more(IGNORED_PTR_ARG, IGNORED_PTR_ARG)) + .CopyOutArgumentBuffer(2, &more, sizeof(bool)); + STRICT_EXPECTED_CALL(transfer_get_delivery_id(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(disposition_create(IGNORED_NUM_ARG, IGNORED_NUM_ARG)) + .SetReturn(disposition); + STRICT_EXPECTED_CALL(disposition_set_last(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(disposition_set_settled(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(disposition_set_state(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(session_send_disposition(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(disposition_destroy(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(amqpvalue_destroy(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(transfer_destroy(IGNORED_PTR_ARG)); + on_frame_received(link, performative, frame_payload_size, payload_bytes); + + // assert + ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); + + // cleanup + link_destroy(link); +} + +TEST_FUNCTION(link_transfer_async_success) +{ + // arrange + LINK_HANDLE link = create_link(role_sender); + + ON_ENDPOINT_FRAME_RECEIVED on_frame_received = NULL; + LINK_TRANSFER_RESULT link_transfer_error; + tickcounter_ms_t send_timeout = 1000; + uint8_t data_bytes[16]; + PAYLOAD payload; + payload.bytes = (const unsigned char*)data_bytes; + payload.length = 0; + const size_t message_count = 1; + uint8_t async_op_result[128]; + unsigned char delivery_tag_bytes[10]; + delivery_tag moot_delivery_tag; + moot_delivery_tag.bytes = delivery_tag_bytes; + moot_delivery_tag.length = sizeof(delivery_tag_bytes); + + int attach_result = attach_link(link, role_sender, &on_frame_received, NULL); + ASSERT_ARE_EQUAL(int, 0, attach_result); + + umock_c_reset_all_calls(); + STRICT_EXPECTED_CALL(async_operation_create(IGNORED_PTR_ARG, IGNORED_NUM_ARG)) + .SetReturn((ASYNC_OPERATION_HANDLE)async_op_result); + STRICT_EXPECTED_CALL(transfer_create(IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(transfer_set_delivery_tag(IGNORED_PTR_ARG, moot_delivery_tag)) + .IgnoreArgument_delivery_tag_value(); // Important for making umock-c work with custom value arguments. + STRICT_EXPECTED_CALL(transfer_set_message_format(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(transfer_set_settled(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(amqpvalue_create_transfer(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(tickcounter_get_current_ms(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(singlylinkedlist_add(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(session_send_transfer(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_NUM_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)) + .SetReturn(SESSION_SEND_TRANSFER_OK); + STRICT_EXPECTED_CALL(amqpvalue_destroy(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(transfer_destroy(IGNORED_PTR_ARG)); + + // act + ASYNC_OPERATION_HANDLE async_result = link_transfer_async(link, AMQP_BATCHING_FORMAT_CODE, &payload, message_count, on_delivery_settled, NULL, &link_transfer_error, send_timeout); + + // assert + ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); + ASSERT_IS_NOT_NULL(async_result); + + // cleanup + link_destroy(link); +} + +TEST_FUNCTION(link_transfer_async_SESSION_SEND_TRANSFER_ERROR_fails) +{ + // arrange + LINK_HANDLE link = create_link(role_sender); + + ON_ENDPOINT_FRAME_RECEIVED on_frame_received = NULL; + LINK_TRANSFER_RESULT link_transfer_error; + tickcounter_ms_t send_timeout = 1000; + uint8_t data_bytes[16]; + PAYLOAD payload; + payload.bytes = (const unsigned char*)data_bytes; + payload.length = 0; + const size_t message_count = 1; + uint8_t async_op_result[128]; + unsigned char delivery_tag_bytes[10]; + delivery_tag moot_delivery_tag; + moot_delivery_tag.bytes = delivery_tag_bytes; + moot_delivery_tag.length = sizeof(delivery_tag_bytes); + + int attach_result = attach_link(link, role_sender, &on_frame_received, NULL); + ASSERT_ARE_EQUAL(int, 0, attach_result); + + umock_c_reset_all_calls(); + STRICT_EXPECTED_CALL(async_operation_create(IGNORED_PTR_ARG, IGNORED_NUM_ARG)) + .SetReturn((ASYNC_OPERATION_HANDLE)async_op_result); + STRICT_EXPECTED_CALL(transfer_create(IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(transfer_set_delivery_tag(IGNORED_PTR_ARG, moot_delivery_tag)) + .IgnoreArgument_delivery_tag_value(); // Important for making umock-c work with custom value arguments. + STRICT_EXPECTED_CALL(transfer_set_message_format(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(transfer_set_settled(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(amqpvalue_create_transfer(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(tickcounter_get_current_ms(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(singlylinkedlist_add(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(session_send_transfer(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_NUM_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)) + .SetReturn(SESSION_SEND_TRANSFER_ERROR); + STRICT_EXPECTED_CALL(singlylinkedlist_remove(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(async_operation_destroy(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(amqpvalue_destroy(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(transfer_destroy(IGNORED_PTR_ARG)); + + // act + ASYNC_OPERATION_HANDLE async_result = link_transfer_async(link, AMQP_BATCHING_FORMAT_CODE, &payload, message_count, on_delivery_settled, NULL, &link_transfer_error, send_timeout); + + // assert + ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); + ASSERT_IS_NULL(async_result); + + // cleanup + link_destroy(link); +} + +TEST_FUNCTION(link_transfer_async_SESSION_SEND_TRANSFER_BUSY_fails) +{ + // arrange + LINK_HANDLE link = create_link(role_sender); + + ON_ENDPOINT_FRAME_RECEIVED on_frame_received = NULL; + LINK_TRANSFER_RESULT link_transfer_error; + tickcounter_ms_t send_timeout = 1000; + uint8_t data_bytes[16]; + PAYLOAD payload; + payload.bytes = (const unsigned char*)data_bytes; + payload.length = 0; + const size_t message_count = 1; + uint8_t async_op_result[128]; + unsigned char delivery_tag_bytes[10]; + delivery_tag moot_delivery_tag; + moot_delivery_tag.bytes = delivery_tag_bytes; + moot_delivery_tag.length = sizeof(delivery_tag_bytes); + + int attach_result = attach_link(link, role_sender, &on_frame_received, NULL); + ASSERT_ARE_EQUAL(int, 0, attach_result); + + umock_c_reset_all_calls(); + STRICT_EXPECTED_CALL(async_operation_create(IGNORED_PTR_ARG, IGNORED_NUM_ARG)) + .SetReturn((ASYNC_OPERATION_HANDLE)async_op_result); + STRICT_EXPECTED_CALL(transfer_create(IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(transfer_set_delivery_tag(IGNORED_PTR_ARG, moot_delivery_tag)) + .IgnoreArgument_delivery_tag_value(); // Important for making umock-c work with custom value arguments. + STRICT_EXPECTED_CALL(transfer_set_message_format(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(transfer_set_settled(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(amqpvalue_create_transfer(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(tickcounter_get_current_ms(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(singlylinkedlist_add(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(session_send_transfer(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_NUM_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)) + .SetReturn(SESSION_SEND_TRANSFER_BUSY); + STRICT_EXPECTED_CALL(singlylinkedlist_remove(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(async_operation_destroy(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(amqpvalue_destroy(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(transfer_destroy(IGNORED_PTR_ARG)); + + // act + ASYNC_OPERATION_HANDLE async_result = link_transfer_async(link, AMQP_BATCHING_FORMAT_CODE, &payload, message_count, on_delivery_settled, NULL, &link_transfer_error, send_timeout); + + // assert + ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); + ASSERT_IS_NULL(async_result); + + // cleanup + link_destroy(link); +} + +// If `session_send_transfer` fails internally, depending on the point where it fails `remove_all_pending_deliveries` might be called, +// causing the ASYNC_OPERATION_HANDLE/DELIVERY_INSTANCE variable `result` to be removed from `link->pending_deliveries` and destroyed. +// Then when `session_send_transfer` returns, in such cases `singlylinkedlist_remove` will fail and `async_operation_destroy` should not be called (to avoid a double-free). +TEST_FUNCTION(link_transfer_async_SESSION_SEND_TRANSFER_ERROR_result_already_destroyed_fails) +{ + // arrange + LINK_HANDLE link = create_link(role_sender); + + ON_ENDPOINT_FRAME_RECEIVED on_frame_received = NULL; + LINK_TRANSFER_RESULT link_transfer_error; + tickcounter_ms_t send_timeout = 1000; + uint8_t data_bytes[16]; + PAYLOAD payload; + payload.bytes = (const unsigned char*)data_bytes; + payload.length = 0; + const size_t message_count = 1; + uint8_t async_op_result[128]; + unsigned char delivery_tag_bytes[10]; + delivery_tag moot_delivery_tag; + moot_delivery_tag.bytes = delivery_tag_bytes; + moot_delivery_tag.length = sizeof(delivery_tag_bytes); + + int attach_result = attach_link(link, role_sender, &on_frame_received, NULL); + ASSERT_ARE_EQUAL(int, 0, attach_result); + + umock_c_reset_all_calls(); + STRICT_EXPECTED_CALL(async_operation_create(IGNORED_PTR_ARG, IGNORED_NUM_ARG)) + .SetReturn((ASYNC_OPERATION_HANDLE)async_op_result); + STRICT_EXPECTED_CALL(transfer_create(IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(transfer_set_delivery_tag(IGNORED_PTR_ARG, moot_delivery_tag)) + .IgnoreArgument_delivery_tag_value(); // Important for making umock-c work with custom value arguments. + STRICT_EXPECTED_CALL(transfer_set_message_format(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(transfer_set_settled(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(amqpvalue_create_transfer(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(tickcounter_get_current_ms(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(singlylinkedlist_add(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(session_send_transfer(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_NUM_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)) + .SetReturn(SESSION_SEND_TRANSFER_ERROR); + STRICT_EXPECTED_CALL(singlylinkedlist_remove(IGNORED_PTR_ARG, IGNORED_PTR_ARG)) + .SetReturn(1); // result has already been removed from link->pending_deliveries. + // Do not expect async_operation_destroy! + STRICT_EXPECTED_CALL(amqpvalue_destroy(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(transfer_destroy(IGNORED_PTR_ARG)); + + // act + ASYNC_OPERATION_HANDLE async_result = link_transfer_async(link, AMQP_BATCHING_FORMAT_CODE, &payload, message_count, on_delivery_settled, NULL, &link_transfer_error, send_timeout); + + // assert + ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); + ASSERT_IS_NULL(async_result); + + // cleanup + link_destroy(link); +} + +// If `session_send_transfer` fails internally, depending on the point where it fails `remove_all_pending_deliveries` might be called, +// causing the ASYNC_OPERATION_HANDLE/DELIVERY_INSTANCE variable `result` to be removed from `link->pending_deliveries` and destroyed. +// Then when `session_send_transfer` returns, in such cases `singlylinkedlist_remove` will fail and `async_operation_destroy` should not be called (to avoid a double-free). +TEST_FUNCTION(link_transfer_async_SESSION_SEND_TRANSFER_BUSY_result_already_destroyed_fails) +{ + // arrange + LINK_HANDLE link = create_link(role_sender); + + ON_ENDPOINT_FRAME_RECEIVED on_frame_received = NULL; + LINK_TRANSFER_RESULT link_transfer_error; + tickcounter_ms_t send_timeout = 1000; + uint8_t data_bytes[16]; + PAYLOAD payload; + payload.bytes = (const unsigned char*)data_bytes; + payload.length = 0; + const size_t message_count = 1; + uint8_t async_op_result[128]; + unsigned char delivery_tag_bytes[10]; + delivery_tag moot_delivery_tag; + moot_delivery_tag.bytes = delivery_tag_bytes; + moot_delivery_tag.length = sizeof(delivery_tag_bytes); + + int attach_result = attach_link(link, role_sender, &on_frame_received, NULL); + ASSERT_ARE_EQUAL(int, 0, attach_result); + + umock_c_reset_all_calls(); + STRICT_EXPECTED_CALL(async_operation_create(IGNORED_PTR_ARG, IGNORED_NUM_ARG)) + .SetReturn((ASYNC_OPERATION_HANDLE)async_op_result); + STRICT_EXPECTED_CALL(transfer_create(IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(transfer_set_delivery_tag(IGNORED_PTR_ARG, moot_delivery_tag)) + .IgnoreArgument_delivery_tag_value(); // Important for making umock-c work with custom value arguments. + STRICT_EXPECTED_CALL(transfer_set_message_format(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(transfer_set_settled(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(amqpvalue_create_transfer(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(tickcounter_get_current_ms(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(singlylinkedlist_add(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(session_send_transfer(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_NUM_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)) + .SetReturn(SESSION_SEND_TRANSFER_BUSY); + STRICT_EXPECTED_CALL(singlylinkedlist_remove(IGNORED_PTR_ARG, IGNORED_PTR_ARG)) + .SetReturn(1); // result has already been removed from link->pending_deliveries. + // Do not expect async_operation_destroy! + STRICT_EXPECTED_CALL(amqpvalue_destroy(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(transfer_destroy(IGNORED_PTR_ARG)); + + // act + ASYNC_OPERATION_HANDLE async_result = link_transfer_async(link, AMQP_BATCHING_FORMAT_CODE, &payload, message_count, on_delivery_settled, NULL, &link_transfer_error, send_timeout); + + // assert + ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); + ASSERT_IS_NULL(async_result); + + // cleanup + link_destroy(link); +} + +END_TEST_SUITE(link_ut) diff --git a/src/vendor/azure-uamqp-c/tests/link_ut/main.c b/src/vendor/azure-uamqp-c/tests/link_ut/main.c new file mode 100644 index 000000000..46ef892ac --- /dev/null +++ b/src/vendor/azure-uamqp-c/tests/link_ut/main.c @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +#include "testrunnerswitcher.h" + +int main(void) +{ + size_t failedTestCount = 0; + RUN_TEST_SUITE(link_ut, failedTestCount); + return (int)failedTestCount; +} diff --git a/src/vendor/azure-uamqp-c/tests/local_client_server_tcp_e2e/CMakeLists.txt b/src/vendor/azure-uamqp-c/tests/local_client_server_tcp_e2e/CMakeLists.txt index 2e1e6b521..287356b66 100644 --- a/src/vendor/azure-uamqp-c/tests/local_client_server_tcp_e2e/CMakeLists.txt +++ b/src/vendor/azure-uamqp-c/tests/local_client_server_tcp_e2e/CMakeLists.txt @@ -12,6 +12,12 @@ set(${theseTestsName}_c_files set(${theseTestsName}_h_files ) -build_c_test_artifacts(${theseTestsName} ON "tests/uamqp_tests" ADDITIONAL_LIBS uamqp) +file(COPY ../valgrind_suppressions.supp DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +build_c_test_artifacts(${theseTestsName} ON "tests/uamqp_tests" + ADDITIONAL_LIBS + uamqp + VALGRIND_SUPPRESSIONS_FILE + valgrind_suppressions.supp +) compile_c_test_artifacts_as(${theseTestsName} C99) diff --git a/src/vendor/azure-uamqp-c/tests/local_client_server_tcp_e2e/main.c b/src/vendor/azure-uamqp-c/tests/local_client_server_tcp_e2e/main.c index 85f389b2a..0df8f4398 100644 --- a/src/vendor/azure-uamqp-c/tests/local_client_server_tcp_e2e/main.c +++ b/src/vendor/azure-uamqp-c/tests/local_client_server_tcp_e2e/main.c @@ -7,5 +7,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(local_client_server_tcp_e2e, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/tests/message_ut/main.c b/src/vendor/azure-uamqp-c/tests/message_ut/main.c index dfd322b3b..dfae01450 100644 --- a/src/vendor/azure-uamqp-c/tests/message_ut/main.c +++ b/src/vendor/azure-uamqp-c/tests/message_ut/main.c @@ -7,5 +7,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(message_ut, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/tests/sasl_anonymous_ut/main.c b/src/vendor/azure-uamqp-c/tests/sasl_anonymous_ut/main.c index 4d1e8c0da..e64623039 100644 --- a/src/vendor/azure-uamqp-c/tests/sasl_anonymous_ut/main.c +++ b/src/vendor/azure-uamqp-c/tests/sasl_anonymous_ut/main.c @@ -7,5 +7,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(sasl_anonymous_ut, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/tests/sasl_frame_codec_ut/main.c b/src/vendor/azure-uamqp-c/tests/sasl_frame_codec_ut/main.c index 5a32a1664..4690571de 100644 --- a/src/vendor/azure-uamqp-c/tests/sasl_frame_codec_ut/main.c +++ b/src/vendor/azure-uamqp-c/tests/sasl_frame_codec_ut/main.c @@ -7,5 +7,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(sasl_frame_codec_ut, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/tests/sasl_frame_codec_ut/sasl_frame_codec_ut.c b/src/vendor/azure-uamqp-c/tests/sasl_frame_codec_ut/sasl_frame_codec_ut.c index b2fe128b7..7af47a8d0 100644 --- a/src/vendor/azure-uamqp-c/tests/sasl_frame_codec_ut/sasl_frame_codec_ut.c +++ b/src/vendor/azure-uamqp-c/tests/sasl_frame_codec_ut/sasl_frame_codec_ut.c @@ -58,6 +58,7 @@ static void my_gballoc_free(void* ptr) #define TEST_AMQP_VALUE (AMQP_VALUE)0x4246 #define TEST_CONTEXT (void*)0x4247 +#define TEST_MIN_FRAME_SIZE 1 #define TEST_MIX_MAX_FRAME_SIZE 512 static const unsigned char default_test_encoded_bytes[2] = { 0x42, 0x43 }; @@ -860,6 +861,43 @@ TEST_FUNCTION(when_encoding_a_sasl_frame_value_that_makes_the_frame_be_the_max_s sasl_frame_codec_destroy(sasl_frame_codec); } +/* Tests_SRS_SASL_FRAME_CODEC_01_017: [The minimum size of a SASL frame is defined by MIN_FRAME_SIZE (1 byte).] */ +TEST_FUNCTION(when_encoding_a_sasl_frame_value_that_makes_the_frame_be_the_min_size_sasl_frame_codec_encode_frame_succeeds) +{ + // arrange + SASL_FRAME_CODEC_HANDLE sasl_frame_codec = sasl_frame_codec_create(TEST_FRAME_CODEC_HANDLE, test_on_sasl_frame_received, test_on_sasl_frame_codec_error, TEST_CONTEXT); + PAYLOAD payload; + size_t sasl_frame_value_size; + unsigned char encoded_bytes[TEST_MIN_FRAME_SIZE] = { 0 }; + int result; + umock_c_reset_all_calls(); + + test_encoded_bytes = encoded_bytes; + test_encoded_bytes_size = sizeof(encoded_bytes); + payload.bytes = test_encoded_bytes; + payload.length = test_encoded_bytes_size; + + sasl_frame_value_size = test_encoded_bytes_size; + STRICT_EXPECTED_CALL(amqpvalue_get_inplace_descriptor(TEST_AMQP_VALUE)); + STRICT_EXPECTED_CALL(amqpvalue_get_ulong(TEST_DESCRIPTOR_AMQP_VALUE, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(amqpvalue_get_encoded_size(TEST_AMQP_VALUE, IGNORED_PTR_ARG)) + .CopyOutArgumentBuffer(2, &sasl_frame_value_size, sizeof(sasl_frame_value_size)); + STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(amqpvalue_encode(TEST_AMQP_VALUE, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(frame_codec_encode_frame(TEST_FRAME_CODEC_HANDLE, FRAME_TYPE_SASL, &payload, 1, NULL, 0, test_on_bytes_encoded, (void*)0x4242)); + STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG)); + + // act + result = sasl_frame_codec_encode_frame(sasl_frame_codec, TEST_AMQP_VALUE, test_on_bytes_encoded, (void*)0x4242); + + // assert + ASSERT_ARE_EQUAL(int, 0, result); + ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); + + // cleanup + sasl_frame_codec_destroy(sasl_frame_codec); +} + /* Tests_SRS_SASL_FRAME_CODEC_01_016: [The maximum size of a SASL frame is defined by MIN-MAX-FRAME-SIZE.] */ TEST_FUNCTION(when_encoding_a_sasl_frame_value_that_makes_the_frame_exceed_the_allowed_size_sasl_frame_codec_encode_frame_fails) { @@ -893,6 +931,40 @@ TEST_FUNCTION(when_encoding_a_sasl_frame_value_that_makes_the_frame_exceed_the_a sasl_frame_codec_destroy(sasl_frame_codec); } +/* Tests_SRS_SASL_FRAME_CODEC_01_017: [The minimum size of a SASL frame is defined by MIN_FRAME_SIZE (1 byte).] */ +TEST_FUNCTION(when_encoding_a_sasl_frame_value_that_makes_the_frame_short_of_the_min_size_sasl_frame_codec_encode_frame_fails) +{ + // arrange + SASL_FRAME_CODEC_HANDLE sasl_frame_codec = sasl_frame_codec_create(TEST_FRAME_CODEC_HANDLE, test_on_sasl_frame_received, test_on_sasl_frame_codec_error, TEST_CONTEXT); + // PAYLOAD payload; + // unsigned char encoded_bytes[0]; + size_t sasl_frame_value_size; + int result; + umock_c_reset_all_calls(); + + // payload.bytes = test_encoded_bytes; + // payload.length = test_encoded_bytes_size; + + // test_encoded_bytes = encoded_bytes; + // test_encoded_bytes_size = sizeof(encoded_bytes); + // sasl_frame_value_size = test_encoded_bytes_size; + sasl_frame_value_size = 0; + STRICT_EXPECTED_CALL(amqpvalue_get_inplace_descriptor(TEST_AMQP_VALUE)); + STRICT_EXPECTED_CALL(amqpvalue_get_ulong(TEST_DESCRIPTOR_AMQP_VALUE, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(amqpvalue_get_encoded_size(TEST_AMQP_VALUE, IGNORED_PTR_ARG)) + .CopyOutArgumentBuffer(2, &sasl_frame_value_size, sizeof(sasl_frame_value_size)); + + // act + result = sasl_frame_codec_encode_frame(sasl_frame_codec, TEST_AMQP_VALUE, test_on_bytes_encoded, (void*)0x4242); + + // assert + ASSERT_ARE_NOT_EQUAL(int, 0, result); + ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); + + // cleanup + sasl_frame_codec_destroy(sasl_frame_codec); +} + /* Tests_SRS_SASL_FRAME_CODEC_01_034: [If any error occurs during encoding, sasl_frame_codec_encode_frame shall fail and return a non-zero value.] */ TEST_FUNCTION(when_the_sasl_frame_value_has_a_descriptor_ulong_lower_than_MECHANISMS_frame_codec_encode_frame_fails) { diff --git a/src/vendor/azure-uamqp-c/tests/sasl_mechanism_ut/main.c b/src/vendor/azure-uamqp-c/tests/sasl_mechanism_ut/main.c index 0a787e4cf..7e0d2476e 100644 --- a/src/vendor/azure-uamqp-c/tests/sasl_mechanism_ut/main.c +++ b/src/vendor/azure-uamqp-c/tests/sasl_mechanism_ut/main.c @@ -7,5 +7,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(sasl_mechanism_ut, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/tests/sasl_plain_ut/main.c b/src/vendor/azure-uamqp-c/tests/sasl_plain_ut/main.c index 460a26bc1..4e112decc 100644 --- a/src/vendor/azure-uamqp-c/tests/sasl_plain_ut/main.c +++ b/src/vendor/azure-uamqp-c/tests/sasl_plain_ut/main.c @@ -7,5 +7,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(sasl_plain_ut, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/tests/sasl_server_mechanism_ut/main.c b/src/vendor/azure-uamqp-c/tests/sasl_server_mechanism_ut/main.c index 0ac11dc11..ba66aee66 100644 --- a/src/vendor/azure-uamqp-c/tests/sasl_server_mechanism_ut/main.c +++ b/src/vendor/azure-uamqp-c/tests/sasl_server_mechanism_ut/main.c @@ -7,5 +7,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(sasl_server_mechanism_ut, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/tests/saslclientio_ut/main.c b/src/vendor/azure-uamqp-c/tests/saslclientio_ut/main.c index bffb20833..6a9a6e8b8 100644 --- a/src/vendor/azure-uamqp-c/tests/saslclientio_ut/main.c +++ b/src/vendor/azure-uamqp-c/tests/saslclientio_ut/main.c @@ -7,5 +7,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(saslclientio_ut, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/tests/session_ut/main.c b/src/vendor/azure-uamqp-c/tests/session_ut/main.c index 4e1634527..51709881d 100644 --- a/src/vendor/azure-uamqp-c/tests/session_ut/main.c +++ b/src/vendor/azure-uamqp-c/tests/session_ut/main.c @@ -7,5 +7,5 @@ int main(void) { size_t failedTestCount = 0; RUN_TEST_SUITE(session_ut, failedTestCount); - return failedTestCount; + return (int)failedTestCount; } diff --git a/src/vendor/azure-uamqp-c/tests/valgrind_suppressions.supp b/src/vendor/azure-uamqp-c/tests/valgrind_suppressions.supp new file mode 100644 index 000000000..847c9be3e --- /dev/null +++ b/src/vendor/azure-uamqp-c/tests/valgrind_suppressions.supp @@ -0,0 +1,38 @@ +{ + suppress mutex destroy + Helgrind:Misc + obj:/usr/lib/x86_64-linux-gnu/valgrind/vgpreload_helgrind-amd64-linux.so + obj:/usr/lib/x86_64-linux-gnu/libp11-kit.so.0.3.0 + fun:_dl_fini + fun:__run_exit_handlers + fun:exit + fun:(below main) +} +{ + suppress mutex destroy + Helgrind:Misc + obj:/usr/lib/x86_64-linux-gnu/valgrind/vgpreload_helgrind-amd64-linux.so + fun:_dl_fini + fun:__run_exit_handlers + fun:exit + fun:(below main) +} +{ + suppress mutex destroy + drd:MutexErr + fun:pthread_mutex_destroy + obj:/usr/lib/x86_64-linux-gnu/libp11-kit.so.0.3.0 + fun:_dl_fini + fun:__run_exit_handlers + fun:exit + fun:(below main) +} +{ + suppress "is not a mutex" + drd:MutexErr + fun:pthread_mutex_destroy + fun:_dl_fini + fun:__run_exit_handlers + fun:exit + fun:(below main) +} \ No newline at end of file diff --git a/src/vendor/azure-uamqp-c/uamqp_generator/App.config b/src/vendor/azure-uamqp-c/uamqp_generator/App.config index 8e1564635..4bfa00561 100644 --- a/src/vendor/azure-uamqp-c/uamqp_generator/App.config +++ b/src/vendor/azure-uamqp-c/uamqp_generator/App.config @@ -1,6 +1,6 @@ - + - + - \ No newline at end of file + diff --git a/src/vendor/azure-uamqp-c/uamqp_generator/amqp_definitions_c.cs b/src/vendor/azure-uamqp-c/uamqp_generator/amqp_definitions_c.cs index 9ffbe63af..4293b9568 100644 --- a/src/vendor/azure-uamqp-c/uamqp_generator/amqp_definitions_c.cs +++ b/src/vendor/azure-uamqp-c/uamqp_generator/amqp_definitions_c.cs @@ -2953,4 +2953,4 @@ public ToStringInstanceHelper ToStringHelper #endregion } #endregion -} \ No newline at end of file +} diff --git a/src/vendor/azure-uamqp-c/uamqp_generator/amqp_definitions_c.tt b/src/vendor/azure-uamqp-c/uamqp_generator/amqp_definitions_c.tt index c96c46166..efdf6a94a 100644 --- a/src/vendor/azure-uamqp-c/uamqp_generator/amqp_definitions_c.tt +++ b/src/vendor/azure-uamqp-c/uamqp_generator/amqp_definitions_c.tt @@ -671,4 +671,4 @@ bool is_<#= type_name.ToLower() #>_type_by_descriptor(AMQP_VALUE descriptor) <# } #> <# } #> -<# } #> \ No newline at end of file +<# } #> diff --git a/src/vendor/azure-uamqp-c/uamqp_generator/amqp_definitions_h.cs b/src/vendor/azure-uamqp-c/uamqp_generator/amqp_definitions_h.cs index 2cb889c37..7c0589017 100644 --- a/src/vendor/azure-uamqp-c/uamqp_generator/amqp_definitions_h.cs +++ b/src/vendor/azure-uamqp-c/uamqp_generator/amqp_definitions_h.cs @@ -19,9 +19,9 @@ namespace amqplib_generator /// Class to produce the template output /// - #line 1 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 1 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_h.tt" [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "17.0.0.0")] - public partial class amqp_definitions_type_h : amqp_definitions_type_hBase + public partial class amqp_definitions_h : amqp_definitions_hBase { #line hidden /// @@ -31,7 +31,7 @@ public virtual string TransformText() { this.Write("\r\n"); - #line 8 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 8 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_h.tt" amqp amqp = Program.LoadAMQPTypes(); #line default @@ -43,608 +43,84 @@ public virtual string TransformText() // This file is generated. DO NOT EDIT it manually. // The generator that produces it is located at /uamqp_generator/uamqp_generator.sln +#ifndef AMQP_DEFINITIONS_H +#define AMQP_DEFINITIONS_H + +#ifdef __cplusplus +#include +extern ""C"" { +#else +#include +#include +#endif + +#include ""azure_uamqp_c/amqpvalue.h"" +#include ""umock_c/umock_c_prod.h"" + "); - #line 16 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - type type = Program.CurrentTypeObject; - - #line default - #line hidden - - #line 17 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - string type_name = type.name.ToLower().Replace('-', '_'); - - #line default - #line hidden - - #line 18 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - string amqpDefinitionName = $"AMQP_DEFINITIONS_{type_name.ToUpper()}_H"; - - #line default - #line hidden - this.Write("#ifndef "); - - #line 19 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(amqpDefinitionName)); - - #line default - #line hidden - this.Write("\r\n#define "); - - #line 20 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(amqpDefinitionName)); - - #line default - #line hidden - this.Write("\r\n\r\n\r\n#ifdef __cplusplus\r\n#include \r\nextern \"C\" {\r\n#else\r\n#include \r\n#include \r\n#endif\r\n\r\n#include \"azure_uamqp_c/amqpvalue.h\"\r\n#in" + - "clude \"umock_c/umock_c_prod.h\"\r\n\r\n"); - - #line 34 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - if (type.@class == typeClass.composite) - - #line default - #line hidden - - #line 35 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - { - - #line default - #line hidden - this.Write(" typedef struct "); - - #line 36 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(type_name.ToUpper())); - - #line default - #line hidden - this.Write("_INSTANCE_TAG* "); - - #line 36 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(type_name.ToUpper())); - - #line default - #line hidden - this.Write("_HANDLE;\r\n\r\n"); - - #line 38 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - string arg_list = Program.GetMandatoryArgListMock(type); - - #line default - #line hidden - this.Write(" MOCKABLE_FUNCTION(, "); - - #line 39 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(type_name.ToUpper())); - - #line default - #line hidden - this.Write("_HANDLE, "); - - #line 39 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(type_name)); - - #line default - #line hidden - this.Write("_create "); - - #line 39 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(arg_list)); - - #line default - #line hidden - this.Write(");\r\n MOCKABLE_FUNCTION(, "); - - #line 40 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(type_name.ToUpper())); - - #line default - #line hidden - this.Write("_HANDLE, "); - - #line 40 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(type_name)); - - #line default - #line hidden - this.Write("_clone, "); - - #line 40 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(type_name.ToUpper())); - - #line default - #line hidden - this.Write("_HANDLE, value);\r\n MOCKABLE_FUNCTION(, void, "); - - #line 41 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(type_name)); - - #line default - #line hidden - this.Write("_destroy, "); - - #line 41 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(type_name.ToUpper())); - - #line default - #line hidden - this.Write("_HANDLE, "); - - #line 41 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(type_name)); - - #line default - #line hidden - this.Write(");\r\n MOCKABLE_FUNCTION(, bool, is_"); - - #line 42 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(type_name)); - - #line default - #line hidden - this.Write("_type_by_descriptor, AMQP_VALUE, descriptor);\r\n MOCKABLE_FUNCTION(, int, amqpv" + - "alue_get_"); - - #line 43 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(type_name)); - - #line default - #line hidden - this.Write(", AMQP_VALUE, value, "); - - #line 43 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(type_name.ToUpper())); + #line 30 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_h.tt" + foreach (section section in amqp.Items.Where(item => item is section)) #line default #line hidden - this.Write("_HANDLE*, "); - #line 43 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(type_name.ToUpper())); + #line 31 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_h.tt" + { #line default #line hidden - this.Write("_handle);\r\n MOCKABLE_FUNCTION(, AMQP_VALUE, amqpvalue_create_"); - #line 44 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(type_name)); + #line 32 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_h.tt" + List types = new List(); #line default #line hidden - this.Write(", "); - #line 44 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(type_name.ToUpper())); + #line 33 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_h.tt" + types.AddRange(section.Items.Where(item => item is type).Cast()); #line default #line hidden - this.Write("_HANDLE, "); - #line 44 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(type_name)); + #line 34 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_h.tt" + foreach (type type in types) #line default #line hidden - this.Write(");\r\n\r\n"); - #line 46 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - foreach (field field in type.Items.Where(item => item is field)) + #line 35 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_h.tt" + { #line default #line hidden - #line 47 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - { + #line 36 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_h.tt" + string type_name = type.name.ToLower().Replace('-', '_'); #line default #line hidden + this.Write("#include \""); - #line 48 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - string field_name = field.name.ToLower().Replace('-', '_'); - - #line default - #line hidden - - #line 49 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - string c_type = Program.GetCType(field.type, field.multiple == "true").Replace('-', '_').Replace(':', '_'); - - #line default - #line hidden - - #line 50 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - type field_type = Program.GetTypeByName(field.type); - - #line default - #line hidden - - #line 51 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - if ((field_type != null) && (field_type.@class == typeClass.composite)) c_type = field_type.name.ToUpper().Replace('-', '_').Replace(':', '_') + "_HANDLE"; - - #line default - #line hidden - this.Write(" MOCKABLE_FUNCTION(, int, "); - - #line 52 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(type_name)); - - #line default - #line hidden - this.Write("_get_"); - - #line 52 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(field_name)); - - #line default - #line hidden - this.Write(", "); - - #line 52 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(type_name.ToUpper())); - - #line default - #line hidden - this.Write("_HANDLE, "); - - #line 52 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(type_name)); - - #line default - #line hidden - this.Write(", "); - - #line 52 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(c_type)); - - #line default - #line hidden - this.Write("*, "); - - #line 52 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(field_name)); - - #line default - #line hidden - this.Write("_value);\r\n MOCKABLE_FUNCTION(, int, "); - - #line 53 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(type_name)); - - #line default - #line hidden - this.Write("_set_"); - - #line 53 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(field_name)); - - #line default - #line hidden - this.Write(", "); - - #line 53 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(type_name.ToUpper())); - - #line default - #line hidden - this.Write("_HANDLE, "); - - #line 53 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(type_name)); - - #line default - #line hidden - this.Write(", "); - - #line 53 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(c_type)); - - #line default - #line hidden - this.Write(", "); - - #line 53 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(field_name)); - - #line default - #line hidden - this.Write("_value);\r\n"); - - #line 54 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - } - - #line default - #line hidden - this.Write("\r\n"); - - #line 56 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - } - - #line default - #line hidden - - #line 57 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - else - - #line default - #line hidden - - #line 58 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - if (type.@class == typeClass.restricted) - - #line default - #line hidden - - #line 59 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - { - - #line default - #line hidden - - #line 60 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - string c_type = Program.GetCType(type.source, false).Replace('-', '_').Replace(':', '_'); - - #line default - #line hidden - this.Write("\r\n typedef "); - - #line 62 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(c_type)); - - #line default - #line hidden - this.Write(" "); - - #line 62 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(type_name.ToLower())); - - #line default - #line hidden - this.Write(";\r\n\r\n"); - - #line 64 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - if (c_type != "AMQP_VALUE") - - #line default - #line hidden - - #line 65 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - { - - #line default - #line hidden - this.Write(" MOCKABLE_FUNCTION(, AMQP_VALUE, amqpvalue_create_"); - - #line 66 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(type_name.ToLower())); - - #line default - #line hidden - this.Write(", "); - - #line 66 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(type_name.ToLower())); - - #line default - #line hidden - this.Write(", value);\r\n"); - - #line 67 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - } - - #line default - #line hidden - - #line 68 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - else - - #line default - #line hidden - - #line 69 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - { - - #line default - #line hidden - this.Write(" MOCKABLE_FUNCTION(, AMQP_VALUE, amqpvalue_create_"); - - #line 70 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(type_name.ToLower())); - - #line default - #line hidden - this.Write(", AMQP_VALUE, value);\r\n #define "); - - #line 71 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(type_name.ToLower())); - - #line default - #line hidden - this.Write("_clone amqpvalue_clone\r\n #define "); - - #line 72 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(type_name.ToLower())); - - #line default - #line hidden - this.Write("_destroy amqpvalue_destroy\r\n"); - - #line 73 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - } - - #line default - #line hidden - this.Write("\r\n"); - - #line 75 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - if ((type.Items != null) && (type.Items.Where(item => item is descriptor).Count() > 0)) - - #line default - #line hidden - - #line 76 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - { - - #line default - #line hidden - this.Write(" MOCKABLE_FUNCTION(, bool, is_"); - - #line 77 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(type_name)); - - #line default - #line hidden - this.Write("_type_by_descriptor, AMQP_VALUE, descriptor);\r\n"); - - #line 78 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - } - - #line default - #line hidden - this.Write("\r\n #define amqpvalue_get_"); - - #line 80 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(type_name.ToLower())); - - #line default - #line hidden - this.Write(" amqpvalue_get_"); - - #line 80 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(type.source.Replace('-', '_').Replace(':', '_'))); - - #line default - #line hidden - this.Write("\r\n\r\n"); - - #line 82 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - if (type.Items != null) - - #line default - #line hidden - - #line 83 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - { - - #line default - #line hidden - - #line 84 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - foreach (choice choice in type.Items.Where(item => item is choice)) - - #line default - #line hidden - - #line 85 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - { - - #line default - #line hidden - - #line 86 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - if (type.@source == "symbol") - - #line default - #line hidden - - #line 87 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - { - - #line default - #line hidden - this.Write(" #define "); - - #line 88 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(type_name)); - - #line default - #line hidden - this.Write("_"); - - #line 88 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(choice.name.Replace('-', '_').Replace(':', '_'))); - - #line default - #line hidden - this.Write(" \""); - - #line 88 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(choice.value)); + #line 37 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_h.tt" + this.Write(this.ToStringHelper.ToStringWithCulture($"azure_uamqp_c/amqp_definitions_{type_name}.h")); #line default #line hidden this.Write("\"\r\n"); - #line 89 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - } - - #line default - #line hidden - - #line 90 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - else - - #line default - #line hidden - - #line 91 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - { - - #line default - #line hidden - this.Write(" #define "); - - #line 92 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(type_name)); - - #line default - #line hidden - this.Write("_"); - - #line 92 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(choice.name.Replace('-', '_').Replace(':', '_'))); - - #line default - #line hidden - this.Write(" "); - - #line 92 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(choice.value.Replace('-', '_').Replace(':', '_'))); - - #line default - #line hidden - this.Write("\r\n"); - - #line 93 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - } - - #line default - #line hidden - - #line 94 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - } - - #line default - #line hidden - - #line 95 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - } - - #line default - #line hidden - this.Write("\r\n"); - - #line 97 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - } + #line 38 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_h.tt" + } #line default #line hidden - this.Write("\r\n#ifdef __cplusplus\r\n}\r\n#endif\r\n\r\n#endif /* "); - #line 103 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(amqpDefinitionName)); + #line 39 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_h.tt" + } #line default #line hidden - this.Write(" */\r\n"); + this.Write("\r\n#ifdef __cplusplus\r\n}\r\n#endif\r\n\r\n#endif /* AMQP_DEFINITIONS_H */\r\n"); return this.GenerationEnvironment.ToString(); } } @@ -656,7 +132,7 @@ public virtual string TransformText() /// Base class for this transformation /// [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "17.0.0.0")] - public class amqp_definitions_type_hBase + public class amqp_definitions_hBase { #region Fields private global::System.Text.StringBuilder generationEnvironmentField; @@ -923,4 +399,4 @@ public ToStringInstanceHelper ToStringHelper #endregion } #endregion -} \ No newline at end of file +} diff --git a/src/vendor/azure-uamqp-c/uamqp_generator/amqp_definitions_type_h.cs b/src/vendor/azure-uamqp-c/uamqp_generator/amqp_definitions_type_h.cs index 44b3d5d82..c93a2424a 100644 --- a/src/vendor/azure-uamqp-c/uamqp_generator/amqp_definitions_type_h.cs +++ b/src/vendor/azure-uamqp-c/uamqp_generator/amqp_definitions_type_h.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version: 15.0.0.0 +// Runtime Version: 17.0.0.0 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -19,8 +19,8 @@ namespace amqplib_generator /// Class to produce the template output /// - #line 1 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "15.0.0.0")] + #line 1 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "17.0.0.0")] public partial class amqp_definitions_type_h : amqp_definitions_type_hBase { #line hidden @@ -31,7 +31,7 @@ public virtual string TransformText() { this.Write("\r\n"); - #line 8 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 8 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" amqp amqp = Program.LoadAMQPTypes(); #line default @@ -45,139 +45,139 @@ public virtual string TransformText() "); - #line 16 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 16 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" type type = Program.CurrentTypeObject; #line default #line hidden - #line 17 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 17 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" string type_name = type.name.ToLower().Replace('-', '_'); #line default #line hidden - #line 18 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 18 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" string amqpDefinitionName = $"AMQP_DEFINITIONS_{type_name.ToUpper()}_H"; #line default #line hidden this.Write("#ifndef "); - #line 19 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 19 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(amqpDefinitionName)); #line default #line hidden this.Write("\r\n#define "); - #line 20 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 20 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(amqpDefinitionName)); #line default #line hidden this.Write("\r\n\r\n\r\n#ifdef __cplusplus\r\n#include \r\nextern \"C\" {\r\n#else\r\n#include \r\n#include \r\n#endif\r\n\r\n#include \"azure_uamqp_c/amqpvalue.h\"\r\n#in" + - "clude \"azure_c_shared_utility/umock_c_prod.h\"\r\n\r\n"); + "clude \"umock_c/umock_c_prod.h\"\r\n\r\n"); - #line 34 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 34 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" if (type.@class == typeClass.composite) #line default #line hidden - #line 35 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 35 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" { #line default #line hidden this.Write(" typedef struct "); - #line 36 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 36 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(type_name.ToUpper())); #line default #line hidden this.Write("_INSTANCE_TAG* "); - #line 36 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 36 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(type_name.ToUpper())); #line default #line hidden this.Write("_HANDLE;\r\n\r\n"); - #line 38 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 38 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" string arg_list = Program.GetMandatoryArgListMock(type); #line default #line hidden this.Write(" MOCKABLE_FUNCTION(, "); - #line 39 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 39 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(type_name.ToUpper())); #line default #line hidden this.Write("_HANDLE, "); - #line 39 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 39 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(type_name)); #line default #line hidden this.Write("_create "); - #line 39 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 39 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(arg_list)); #line default #line hidden this.Write(");\r\n MOCKABLE_FUNCTION(, "); - #line 40 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 40 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(type_name.ToUpper())); #line default #line hidden this.Write("_HANDLE, "); - #line 40 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 40 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(type_name)); #line default #line hidden this.Write("_clone, "); - #line 40 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 40 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(type_name.ToUpper())); #line default #line hidden this.Write("_HANDLE, value);\r\n MOCKABLE_FUNCTION(, void, "); - #line 41 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 41 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(type_name)); #line default #line hidden this.Write("_destroy, "); - #line 41 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 41 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(type_name.ToUpper())); #line default #line hidden this.Write("_HANDLE, "); - #line 41 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 41 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(type_name)); #line default #line hidden this.Write(");\r\n MOCKABLE_FUNCTION(, bool, is_"); - #line 42 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 42 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(type_name)); #line default @@ -185,461 +185,461 @@ public virtual string TransformText() this.Write("_type_by_descriptor, AMQP_VALUE, descriptor);\r\n MOCKABLE_FUNCTION(, int, amqpv" + "alue_get_"); - #line 43 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 43 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(type_name)); #line default #line hidden this.Write(", AMQP_VALUE, value, "); - #line 43 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 43 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(type_name.ToUpper())); #line default #line hidden this.Write("_HANDLE*, "); - #line 43 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 43 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(type_name.ToUpper())); #line default #line hidden this.Write("_handle);\r\n MOCKABLE_FUNCTION(, AMQP_VALUE, amqpvalue_create_"); - #line 44 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 44 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(type_name)); #line default #line hidden this.Write(", "); - #line 44 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 44 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(type_name.ToUpper())); #line default #line hidden this.Write("_HANDLE, "); - #line 44 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 44 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(type_name)); #line default #line hidden this.Write(");\r\n\r\n"); - #line 46 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 46 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" foreach (field field in type.Items.Where(item => item is field)) #line default #line hidden - #line 47 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 47 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" { #line default #line hidden - #line 48 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 48 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" string field_name = field.name.ToLower().Replace('-', '_'); #line default #line hidden - #line 49 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 49 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" string c_type = Program.GetCType(field.type, field.multiple == "true").Replace('-', '_').Replace(':', '_'); #line default #line hidden - #line 50 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 50 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" type field_type = Program.GetTypeByName(field.type); #line default #line hidden - #line 51 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 51 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" if ((field_type != null) && (field_type.@class == typeClass.composite)) c_type = field_type.name.ToUpper().Replace('-', '_').Replace(':', '_') + "_HANDLE"; #line default #line hidden this.Write(" MOCKABLE_FUNCTION(, int, "); - #line 52 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 52 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(type_name)); #line default #line hidden this.Write("_get_"); - #line 52 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 52 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field_name)); #line default #line hidden this.Write(", "); - #line 52 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 52 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(type_name.ToUpper())); #line default #line hidden this.Write("_HANDLE, "); - #line 52 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 52 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(type_name)); #line default #line hidden this.Write(", "); - #line 52 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 52 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(c_type)); #line default #line hidden this.Write("*, "); - #line 52 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 52 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field_name)); #line default #line hidden this.Write("_value);\r\n MOCKABLE_FUNCTION(, int, "); - #line 53 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 53 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(type_name)); #line default #line hidden this.Write("_set_"); - #line 53 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 53 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field_name)); #line default #line hidden this.Write(", "); - #line 53 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 53 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(type_name.ToUpper())); #line default #line hidden this.Write("_HANDLE, "); - #line 53 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 53 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(type_name)); #line default #line hidden this.Write(", "); - #line 53 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 53 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(c_type)); #line default #line hidden this.Write(", "); - #line 53 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 53 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(field_name)); #line default #line hidden this.Write("_value);\r\n"); - #line 54 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 54 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" } #line default #line hidden this.Write("\r\n"); - #line 56 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 56 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" } #line default #line hidden - #line 57 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 57 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" else #line default #line hidden - #line 58 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 58 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" if (type.@class == typeClass.restricted) #line default #line hidden - #line 59 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 59 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" { #line default #line hidden - #line 60 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 60 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" string c_type = Program.GetCType(type.source, false).Replace('-', '_').Replace(':', '_'); #line default #line hidden this.Write("\r\n typedef "); - #line 62 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 62 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(c_type)); #line default #line hidden this.Write(" "); - #line 62 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 62 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(type_name.ToLower())); #line default #line hidden this.Write(";\r\n\r\n"); - #line 64 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 64 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" if (c_type != "AMQP_VALUE") #line default #line hidden - #line 65 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 65 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" { #line default #line hidden this.Write(" MOCKABLE_FUNCTION(, AMQP_VALUE, amqpvalue_create_"); - #line 66 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 66 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(type_name.ToLower())); #line default #line hidden this.Write(", "); - #line 66 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 66 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(type_name.ToLower())); #line default #line hidden this.Write(", value);\r\n"); - #line 67 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 67 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" } #line default #line hidden - #line 68 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 68 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" else #line default #line hidden - #line 69 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 69 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" { #line default #line hidden this.Write(" MOCKABLE_FUNCTION(, AMQP_VALUE, amqpvalue_create_"); - #line 70 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 70 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(type_name.ToLower())); #line default #line hidden this.Write(", AMQP_VALUE, value);\r\n #define "); - #line 71 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 71 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(type_name.ToLower())); #line default #line hidden this.Write("_clone amqpvalue_clone\r\n #define "); - #line 72 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 72 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(type_name.ToLower())); #line default #line hidden this.Write("_destroy amqpvalue_destroy\r\n"); - #line 73 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 73 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" } #line default #line hidden this.Write("\r\n"); - #line 75 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 75 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" if ((type.Items != null) && (type.Items.Where(item => item is descriptor).Count() > 0)) #line default #line hidden - #line 76 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 76 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" { #line default #line hidden this.Write(" MOCKABLE_FUNCTION(, bool, is_"); - #line 77 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 77 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(type_name)); #line default #line hidden this.Write("_type_by_descriptor, AMQP_VALUE, descriptor);\r\n"); - #line 78 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 78 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" } #line default #line hidden this.Write("\r\n #define amqpvalue_get_"); - #line 80 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 80 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(type_name.ToLower())); #line default #line hidden this.Write(" amqpvalue_get_"); - #line 80 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 80 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(type.source.Replace('-', '_').Replace(':', '_'))); #line default #line hidden this.Write("\r\n\r\n"); - #line 82 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 82 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" if (type.Items != null) #line default #line hidden - #line 83 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 83 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" { #line default #line hidden - #line 84 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 84 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" foreach (choice choice in type.Items.Where(item => item is choice)) #line default #line hidden - #line 85 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 85 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" { #line default #line hidden - #line 86 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 86 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" if (type.@source == "symbol") #line default #line hidden - #line 87 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 87 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" { #line default #line hidden this.Write(" #define "); - #line 88 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 88 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(type_name)); #line default #line hidden this.Write("_"); - #line 88 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 88 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(choice.name.Replace('-', '_').Replace(':', '_'))); #line default #line hidden this.Write(" \""); - #line 88 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 88 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(choice.value)); #line default #line hidden this.Write("\"\r\n"); - #line 89 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 89 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" } #line default #line hidden - #line 90 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 90 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" else #line default #line hidden - #line 91 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 91 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" { #line default #line hidden this.Write(" #define "); - #line 92 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 92 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(type_name)); #line default #line hidden this.Write("_"); - #line 92 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 92 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(choice.name.Replace('-', '_').Replace(':', '_'))); #line default #line hidden this.Write(" "); - #line 92 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 92 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(choice.value.Replace('-', '_').Replace(':', '_'))); #line default #line hidden this.Write("\r\n"); - #line 93 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 93 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" } #line default #line hidden - #line 94 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 94 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" } #line default #line hidden - #line 95 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 95 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" } #line default #line hidden this.Write("\r\n"); - #line 97 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 97 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" } #line default #line hidden this.Write("\r\n#ifdef __cplusplus\r\n}\r\n#endif\r\n\r\n#endif /* "); - #line 103 "G:\repos\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" + #line 103 "C:\code\s1\azure-uamqp-c\uamqp_generator\amqp_definitions_type_h.tt" this.Write(this.ToStringHelper.ToStringWithCulture(amqpDefinitionName)); #line default @@ -655,7 +655,7 @@ public virtual string TransformText() /// /// Base class for this transformation /// - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "15.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "17.0.0.0")] public class amqp_definitions_type_hBase { #region Fields @@ -670,7 +670,7 @@ public class amqp_definitions_type_hBase /// /// The string builder that generation-time code is using to assemble generated output /// - protected System.Text.StringBuilder GenerationEnvironment + public System.Text.StringBuilder GenerationEnvironment { get { diff --git a/src/vendor/azure-uamqp-c/uamqp_generator/uamqp_generator.csproj b/src/vendor/azure-uamqp-c/uamqp_generator/uamqp_generator.csproj index c9eb9db11..66c78e61c 100644 --- a/src/vendor/azure-uamqp-c/uamqp_generator/uamqp_generator.csproj +++ b/src/vendor/azure-uamqp-c/uamqp_generator/uamqp_generator.csproj @@ -9,8 +9,9 @@ Properties amqplib_generator amqplib_generator - v4.5 + v4.8 512 + AnyCPU