From 91beabf9b38974ed5ed4bcc9562de33b2fc03088 Mon Sep 17 00:00:00 2001 From: Kamil Gronek Date: Thu, 22 May 2025 13:50:12 +0200 Subject: [PATCH 1/3] Fix crashes during unsubscribe. Fix pubnub_fetch_history when using with crypto module enabled. --- core/pbcc_subscribe_event_engine.c | 8 ++++---- core/pbcc_subscribe_event_engine_transitions.c | 4 ++-- core/test/pubnub_config.h | 2 +- freertos/pubnub_internal.h | 2 +- openssl/pubnub_config.h | 2 +- posix/pubnub_config.h | 2 +- qt/pubnub_config.h | 2 +- windows/pubnub_config.h | 2 +- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/core/pbcc_subscribe_event_engine.c b/core/pbcc_subscribe_event_engine.c index 928ba97d..34131a49 100644 --- a/core/pbcc_subscribe_event_engine.c +++ b/core/pbcc_subscribe_event_engine.c @@ -601,8 +601,8 @@ enum pubnub_res pbcc_subscribe_ee_unsubscribe_all(pbcc_subscribe_ee_t* ee) pubnub_mutex_unlock(ee->mutw); pubnub_leave(ee->pb, - 0 == strlen(ch) ? NULL : ch, - 0 == strlen(cg) ? NULL : cg); + NULL == ch || 0 == strlen(ch) ? NULL : ch, + NULL == cg || 0 == strlen(cg) ? NULL : cg); } } @@ -859,8 +859,8 @@ enum pubnub_res pbcc_subscribe_ee_unsubscribe_( sending_leave = true; pubnub_leave(ee->pb, - 0 == strlen(ch) ? NULL : ch, - 0 == strlen(cg) ? NULL : cg); + NULL == ch || 0 == strlen(ch) ? NULL : ch, + NULL == cg || 0 == strlen(cg) ? NULL : cg); } } diff --git a/core/pbcc_subscribe_event_engine_transitions.c b/core/pbcc_subscribe_event_engine_transitions.c index 4887154a..aca5097f 100644 --- a/core/pbcc_subscribe_event_engine_transitions.c +++ b/core/pbcc_subscribe_event_engine_transitions.c @@ -79,8 +79,8 @@ pbcc_ee_transition_t* pbcc_handshaking_state_transition_alloc( pbcc_ee_data_value(context->channel_groups); const char* channels = pbcc_ee_data_value(context->channels); - if (NULL != context && 0 == strlen(channels) && - 0 == strlen(channel_groups)) { + if (NULL != context && (NULL == channels || 0 == strlen(channels)) && + (NULL == channel_groups || 0 == strlen(channel_groups))) { target_state_type = SUBSCRIBE_EE_STATE_UNSUBSCRIBED; data = NULL; } diff --git a/core/test/pubnub_config.h b/core/test/pubnub_config.h index 421adf92..c05e9286 100644 --- a/core/test/pubnub_config.h +++ b/core/test/pubnub_config.h @@ -148,7 +148,7 @@ #define PUBNUB_USE_FETCH_HISTORY 1 #endif -#define PUBNUB_MAX_URL_PARAMS 10 +#define PUBNUB_MAX_URL_PARAMS 12 #ifndef PUBNUB_RAND_INIT_VECTOR #define PUBNUB_RAND_INIT_VECTOR 1 diff --git a/freertos/pubnub_internal.h b/freertos/pubnub_internal.h index 0cac9f1b..5992aed5 100644 --- a/freertos/pubnub_internal.h +++ b/freertos/pubnub_internal.h @@ -111,7 +111,7 @@ struct pubnub_pal { /** The maximum number of URL parameters that can be saved in the Pubnub context. */ -#define PUBNUB_MAX_URL_PARAMS 10 +#define PUBNUB_MAX_URL_PARAMS 12 #endif #if !defined(PUBNUB_MIN_WAIT_CONNECT_TIMER) diff --git a/openssl/pubnub_config.h b/openssl/pubnub_config.h index 5f975e3a..924911d8 100644 --- a/openssl/pubnub_config.h +++ b/openssl/pubnub_config.h @@ -236,7 +236,7 @@ these things all by himself using pubnub_heartbeat() transaction */ #define PUBNUB_USE_AUTO_HEARTBEAT 1 #endif -#define PUBNUB_MAX_URL_PARAMS 10 +#define PUBNUB_MAX_URL_PARAMS 12 #ifndef PUBNUB_RAND_INIT_VECTOR #define PUBNUB_RAND_INIT_VECTOR 1 diff --git a/posix/pubnub_config.h b/posix/pubnub_config.h index 1d3f2c27..74bb94bb 100644 --- a/posix/pubnub_config.h +++ b/posix/pubnub_config.h @@ -228,7 +228,7 @@ #define PUBNUB_USE_AUTO_HEARTBEAT 1 #endif -#define PUBNUB_MAX_URL_PARAMS 10 +#define PUBNUB_MAX_URL_PARAMS 12 #ifndef PUBNUB_RAND_INIT_VECTOR #define PUBNUB_RAND_INIT_VECTOR 1 diff --git a/qt/pubnub_config.h b/qt/pubnub_config.h index 6cd414bc..7966f74a 100644 --- a/qt/pubnub_config.h +++ b/qt/pubnub_config.h @@ -89,7 +89,7 @@ #define PUBNUB_USE_AUTO_HEARTBEAT 1 #endif -#define PUBNUB_MAX_URL_PARAMS 10 +#define PUBNUB_MAX_URL_PARAMS 12 #ifndef PUBNUB_RAND_INIT_VECTOR #define PUBNUB_RAND_INIT_VECTOR 1 diff --git a/windows/pubnub_config.h b/windows/pubnub_config.h index 5029e56d..ea4f6a67 100644 --- a/windows/pubnub_config.h +++ b/windows/pubnub_config.h @@ -227,7 +227,7 @@ these things all by himself using pubnub_heartbeat() transaction */ #define PUBNUB_USE_AUTO_HEARTBEAT 1 -#define PUBNUB_MAX_URL_PARAMS 10 +#define PUBNUB_MAX_URL_PARAMS 12 #ifndef PUBNUB_RAND_INIT_VECTOR #define PUBNUB_RAND_INIT_VECTOR 1 From bfe12560a5cba36968e4b02c71843ff64d166d06 Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Mon, 26 May 2025 16:32:08 +0300 Subject: [PATCH 2/3] fix(auto-heartbeat): fix user ID copy crash Fix the issue that was causing memory fragmentation fault at the moment of the next automated heartbeat call. --- core/pbauto_heartbeat.c | 9 ++++++--- qt/pubnub_qt.cpp | 4 +--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/core/pbauto_heartbeat.c b/core/pbauto_heartbeat.c index e78fd750..4ebc58b7 100644 --- a/core/pbauto_heartbeat.c +++ b/core/pbauto_heartbeat.c @@ -61,6 +61,11 @@ static int copy_context_settings(pubnub_t* pb_clone, pubnub_t const* pb) pubnub_mutex_lock(pb_clone->monitor); pb_clone->core.auth_token = pb->core.auth_token; pb_clone->core.auth = pb->core.auth; + if (pb_clone->core.user_id_len != pb->core.user_id_len) { + if (NULL != pb_clone->core.user_id) free(pb_clone->core.user_id); + pb_clone->core.user_id_len = pb->core.user_id_len; + pb_clone->core.user_id = (char*)malloc((pb->core.user_id_len + 1) * sizeof(char)); + } strcpy(pb_clone->core.user_id, pb->core.user_id); if (PUBNUB_ORIGIN_SETTABLE) { pb_clone->origin = pb->origin; @@ -443,9 +448,7 @@ int pubnub_set_heartbeat_period(pubnub_t* pb, size_t period_sec) return -1; } pubnub_mutex_lock(m_watcher.mutw); - m_watcher.heartbeat_data[pb->thumperIndex].period_sec = - period_sec < PUBNUB_MIN_HEARTBEAT_PERIOD ? PUBNUB_MIN_HEARTBEAT_PERIOD - : period_sec; + m_watcher.heartbeat_data[pb->thumperIndex].period_sec = period_sec; pubnub_mutex_unlock(pb->monitor); pubnub_mutex_unlock(m_watcher.mutw); diff --git a/qt/pubnub_qt.cpp b/qt/pubnub_qt.cpp index 4ef7dc70..fa343dcd 100644 --- a/qt/pubnub_qt.cpp +++ b/qt/pubnub_qt.cpp @@ -220,9 +220,7 @@ int pubnub_qt::set_heartbeat_period(size_t period_sec) if (false == d_auto_heartbeat_enabled) { return -1; } - d_auto_heartbeat_period_sec = - period_sec < PUBNUB_MIN_HEARTBEAT_PERIOD ? PUBNUB_MIN_HEARTBEAT_PERIOD - : period_sec; + d_auto_heartbeat_period_sec = period_sec; return 0; } From cf378eb543422e555a724fb99298229652ee90b9 Mon Sep 17 00:00:00 2001 From: PubNub Release Bot <120067856+pubnub-release-bot@users.noreply.github.com> Date: Mon, 26 May 2025 13:57:56 +0000 Subject: [PATCH 3/3] PubNub SDK v5.0.1 release. --- .pubnub.yml | 25 +++++++++++++++++-------- CHANGELOG.md | 8 ++++++++ core/pubnub_version_internal.h | 2 +- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index 86ae12ac..fe628adc 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,8 +1,17 @@ name: c-core schema: 1 -version: "5.0.0" +version: "5.0.1" scm: github.com/pubnub/c-core changelog: + - date: 2025-05-26 + version: v5.0.1 + changes: + - type: bug + text: "Fix crashes that could sometimes happen during unsubscribe due to calling `strlen` on null pointers." + - type: bug + text: "Fix `pubnub_fetch_history` function when used with crypto api. Change `PUBNUB_MAX_URL_PARAMS` to 12." + - type: bug + text: "Fix the issue that was causing memory fragmentation fault at the moment of the next automated heartbeat call." - date: 2025-04-03 version: v5.0.0 changes: @@ -936,7 +945,7 @@ sdks: distribution-type: source code distribution-repository: GitHub release package-name: C-Core - location: https://github.com/pubnub/c-core/releases/tag/v5.0.0 + location: https://github.com/pubnub/c-core/releases/tag/v5.0.1 requires: - name: "miniz" @@ -1002,7 +1011,7 @@ sdks: distribution-type: source code distribution-repository: GitHub release package-name: C-Core - location: https://github.com/pubnub/c-core/releases/tag/v5.0.0 + location: https://github.com/pubnub/c-core/releases/tag/v5.0.1 requires: - name: "miniz" @@ -1068,7 +1077,7 @@ sdks: distribution-type: source code distribution-repository: GitHub release package-name: C-Core - location: https://github.com/pubnub/c-core/releases/tag/v5.0.0 + location: https://github.com/pubnub/c-core/releases/tag/v5.0.1 requires: - name: "miniz" @@ -1130,7 +1139,7 @@ sdks: distribution-type: source code distribution-repository: GitHub release package-name: C-Core - location: https://github.com/pubnub/c-core/releases/tag/v5.0.0 + location: https://github.com/pubnub/c-core/releases/tag/v5.0.1 requires: - name: "miniz" @@ -1191,7 +1200,7 @@ sdks: distribution-type: source code distribution-repository: GitHub release package-name: C-Core - location: https://github.com/pubnub/c-core/releases/tag/v5.0.0 + location: https://github.com/pubnub/c-core/releases/tag/v5.0.1 requires: - name: "miniz" @@ -1247,7 +1256,7 @@ sdks: distribution-type: source code distribution-repository: GitHub release package-name: C-Core - location: https://github.com/pubnub/c-core/releases/tag/v5.0.0 + location: https://github.com/pubnub/c-core/releases/tag/v5.0.1 requires: - name: "miniz" @@ -1300,7 +1309,7 @@ sdks: distribution-type: source code distribution-repository: GitHub release package-name: C-Core - location: https://github.com/pubnub/c-core/releases/tag/v5.0.0 + location: https://github.com/pubnub/c-core/releases/tag/v5.0.1 requires: - name: "miniz" diff --git a/CHANGELOG.md b/CHANGELOG.md index f5f89caf..c7be3cf7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## v5.0.1 +May 26 2025 + +#### Fixed +- Fix crashes that could sometimes happen during unsubscribe due to calling `strlen` on null pointers. +- Fix `pubnub_fetch_history` function when used with crypto api. Change `PUBNUB_MAX_URL_PARAMS` to 12. +- Fix the issue that was causing memory fragmentation fault at the moment of the next automated heartbeat call. + ## v5.0.0 April 03 2025 diff --git a/core/pubnub_version_internal.h b/core/pubnub_version_internal.h index ca8a7ad4..c4203ab7 100644 --- a/core/pubnub_version_internal.h +++ b/core/pubnub_version_internal.h @@ -3,7 +3,7 @@ #define INC_PUBNUB_VERSION_INTERNAL -#define PUBNUB_SDK_VERSION "5.0.0" +#define PUBNUB_SDK_VERSION "5.0.1" #endif /* !defined INC_PUBNUB_VERSION_INTERNAL */