From 7cde0cf6498c1836c5ad9a487d5376822905fc21 Mon Sep 17 00:00:00 2001 From: Xavrax Date: Fri, 22 Mar 2024 09:37:28 +0100 Subject: [PATCH 1/5] add sanitizer to cmake --- CMakeLists.txt | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 171b1bae..6a453d9b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,7 @@ endfunction() # Function to log a option and its value function(log_option name description default) option(${name} ${description} ${default}) - if(${value}) + if(${name}) message(STATUS "[*] ${name}") else() message(STATUS "[ ] ${name}") @@ -41,6 +41,7 @@ log_option(OPENSSL "Use OpenSSL" OFF) log_option(EXAMPLES "Build all examples" OFF) log_option(SHARED_LIB "Library type. [SHARED=ON STATIC=OFF]" OFF) log_option(WITH_CPP "Build the CPP headers" OFF) +log_option(ASAN "Use Address sanitizer" OFF) if (WITH_CPP) set(DEFAULT_USE_CALLBACK_API ON) @@ -90,6 +91,9 @@ set(FLAGS "\ -D PUBNUB_USE_GRANT_TOKEN_API=${USE_GRANT_TOKEN_API} \ -D PUBNUB_USE_REVOKE_TOKEN_API=${USE_REVOKE_TOKEN_API} \ -D PUBNUB_USE_FETCH_HISTORY=${USE_FETCH_HISTORY}") + +set(LDLIBS) +set(OS_SOURCEFILES) if (${USE_CALLBACK_API}) set(FLAGS "\ @@ -99,6 +103,15 @@ if (${USE_CALLBACK_API}) -D PUBNUB_CALLBACK_API") endif() +if (${ASAN}) + set(FLAGS "\ + ${FLAGS} \ + -fsanitize=address") + set(LDLIBS "\ + ${LDLIBS} \ + -fsanitize=address") +endif() + set(CMAKE_C_FLAGS "\ ${FLAGS} \ ${CMAKE_C_FLAGS}") @@ -145,11 +158,8 @@ set(LIB_SOURCEFILES ${CMAKE_CURRENT_LIST_DIR}/lib/sockets/pbpal_adns_sockets.c ${CMAKE_CURRENT_LIST_DIR}/lib/pubnub_dns_codec.c) -set(LDLIBS) -set(OS_SOURCEFILES) - if(UNIX) - set(LDLIBS "-lpthread") + set(LDLIBS "-lpthread ${LDLIBS}") set(OS_SOURCEFILES ${CMAKE_CURRENT_LIST_DIR}/posix/posix_socket_blocking_io.c ${CMAKE_CURRENT_LIST_DIR}/posix/pubnub_version_posix.c @@ -529,6 +539,11 @@ if(${EXAMPLES}) pubnub_advanced_history_sample pubnub_fetch_history_sample cancel_subscribe_sync_sample) + if (OPENSSL) + set(EXAMPLE_LIST + pubnub_crypto_module_sample + ${EXAMPLE_LIST}) + endif() endif() else() message(STATUS "Building example ${EXAMPLE}") From d80352c002a85597b1f5024191e17e1955ed9f99 Mon Sep 17 00:00:00 2001 From: Xavrax Date: Fri, 22 Mar 2024 10:21:11 +0100 Subject: [PATCH 2/5] add IV to args --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a453d9b..2177a3b1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,6 +68,7 @@ num_option(USE_CALLBACK_API "Use callback API [CALLBACK=ON SYNC=OFF]" ${DEFAULT_ num_option(USE_IPV6 "Use IPv6 [CALLBACK=ON]" ${DEFAULT_USE_CALLBACK_API}) num_option(USE_SET_DNS_SERVERS "Use set DNS servers [CALLBACK=ON]" ${DEFAULT_USE_CALLBACK_API}) num_option(USE_EXTERN_API "Use extern C API [WITH_CPP=ON]" ON) +num_option(USE_LEGACY_CRYPTO_RANDOM_IV "Use random IV for legacy crypto module [OpenSSL only]" ON) log_set(OPENSSL_ROOT_DIR "" "OpenSSL root directory (leave empty for find_package function)[OPENSSL=ON needed]") log_set(EXAMPLE "all" "Build example with provided name (use 'all' for all examples) [EXAMPLES=ON needed]") log_set(CGREEN_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}/cgreen" "CGreen root directory [UNIT_TEST=ON needed]") @@ -90,7 +91,8 @@ set(FLAGS "\ -D PUBNUB_USE_AUTO_HEARTBEAT=${USE_AUTO_HEARTBEAT} \ -D PUBNUB_USE_GRANT_TOKEN_API=${USE_GRANT_TOKEN_API} \ -D PUBNUB_USE_REVOKE_TOKEN_API=${USE_REVOKE_TOKEN_API} \ - -D PUBNUB_USE_FETCH_HISTORY=${USE_FETCH_HISTORY}") + -D PUBNUB_USE_FETCH_HISTORY=${USE_FETCH_HISTORY} \ + -D PUBNUB_RAND_INIT_VECTOR=${USE_LEGACY_CRYPTO_RANDOM_IV}") set(LDLIBS) set(OS_SOURCEFILES) From 8ccd0ab8e17a62a69bc5a75097b6ed5acd935280 Mon Sep 17 00:00:00 2001 From: Xavrax Date: Fri, 22 Mar 2024 13:34:10 +0100 Subject: [PATCH 3/5] fix lack of needed amount of space --- core/pbcc_crypto_legacy.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/pbcc_crypto_legacy.c b/core/pbcc_crypto_legacy.c index ea4d12aa..adbca8f8 100644 --- a/core/pbcc_crypto_legacy.c +++ b/core/pbcc_crypto_legacy.c @@ -55,7 +55,11 @@ static size_t estimated_enc_buffer_size(size_t n) { } static size_t estimated_dec_buffer_size(size_t n) { - return n + 1; // for the terminating array + // In most cases formula (n + 1) is enough to + // handle the amount of decrypted bytes. + // Addition AES_BLOCK_SIZE just to be sure if message + // contains very specific padding. + return n + AES_BLOCK_SIZE + 1; } static int legacy_encrypt( From fdba65e40c0c443e5a748e93409261b2ccda9de1 Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Tue, 26 Mar 2024 23:21:59 +0200 Subject: [PATCH 4/5] fix(versions): fix `versions.json` format Remove trailing commas from the `versions.json` file. --- .github/workflows/release/versions.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release/versions.json b/.github/workflows/release/versions.json index 67665b68..09267262 100644 --- a/.github/workflows/release/versions.json +++ b/.github/workflows/release/versions.json @@ -7,6 +7,6 @@ { "pattern": "#define PUBNUB_SDK_VERSION \"(.+)\"$", "cleared": true } ], "CMakeLists.txt": [ - { "pattern": "^version(\"(.+)\")$", "cleared": true }, - ], + { "pattern": "^version(\"(.+)\")$", "cleared": true } + ] } From aae208045d01dab517766e11524162994fc16aaa Mon Sep 17 00:00:00 2001 From: PubNub Release Bot <120067856+pubnub-release-bot@users.noreply.github.com> Date: Tue, 26 Mar 2024 21:37:49 +0000 Subject: [PATCH 5/5] PubNub SDK v4.9.1 release. --- .pubnub.yml | 7 +++++++ CHANGELOG.md | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/.pubnub.yml b/.pubnub.yml index 6ec06587..736e780f 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -3,6 +3,13 @@ schema: 1 version: "4.9.0" scm: github.com/pubnub/c-core changelog: + - date: 2024-03-26 + version: v4.9.1 + changes: + - type: bug + text: "Fix too small amount of memory allocated for aes cbc algorithm in some cases." + - type: improvement + text: "Add possibility to include address sanitizer in build via CMake." - date: 2024-01-08 version: v4.9.0 changes: diff --git a/CHANGELOG.md b/CHANGELOG.md index 30a54d0f..0af13f52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## v4.9.1 +March 26 2024 + +#### Fixed +- Fix too small amount of memory allocated for aes cbc algorithm in some cases. + +#### Modified +- Add possibility to include address sanitizer in build via CMake. + ## v4.9.0 January 08 2024