From a5aad5159c07adf22842f93dd5e2f6a2776ad3d1 Mon Sep 17 00:00:00 2001 From: Martin Fleisz Date: Thu, 6 Jul 2023 13:46:31 +0200 Subject: [PATCH] core: Fix issues in settings copy code This code fixes an issue where some settings were lost when copying settings around. I.e. the device count was first set but then calling `freerdp_settings_set_pointer_len` caused the device count to be reset to 0 because we passed `NULL` for the data value. This means the count got lost upon the first copy and further copies also resulted in losing the array data (because the count was set to 0). This PR fixes this issue by first resetting the array and afterwards setting the correct count value. --- libfreerdp/core/settings.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/libfreerdp/core/settings.c b/libfreerdp/core/settings.c index 4538bd393..8de1d7749 100644 --- a/libfreerdp/core/settings.c +++ b/libfreerdp/core/settings.c @@ -1012,10 +1012,10 @@ static BOOL freerdp_settings_int_buffer_copy(rdpSettings* _settings, const rdpSe if (len < count) goto out_fail; - if (!freerdp_settings_set_uint32(_settings, FreeRDP_DeviceCount, count)) - goto out_fail; if (!freerdp_settings_set_pointer_len(_settings, FreeRDP_DeviceArray, NULL, len)) goto out_fail; + if (!freerdp_settings_set_uint32(_settings, FreeRDP_DeviceCount, count)) + goto out_fail; for (index = 0; index < count; index++) { @@ -1031,10 +1031,10 @@ static BOOL freerdp_settings_int_buffer_copy(rdpSettings* _settings, const rdpSe if (len < count) goto out_fail; - if (!freerdp_settings_set_uint32(_settings, FreeRDP_StaticChannelCount, count)) - goto out_fail; if (!freerdp_settings_set_pointer_len(_settings, FreeRDP_StaticChannelArray, NULL, len)) goto out_fail; + if (!freerdp_settings_set_uint32(_settings, FreeRDP_StaticChannelCount, count)) + goto out_fail; for (index = 0; index < count; index++) { @@ -1051,12 +1051,10 @@ static BOOL freerdp_settings_int_buffer_copy(rdpSettings* _settings, const rdpSe if (len < count) goto out_fail; - if (!freerdp_settings_set_uint32(_settings, FreeRDP_DynamicChannelCount, count)) - goto out_fail; - if (!freerdp_settings_set_uint32(_settings, FreeRDP_DynamicChannelCount, count)) - goto out_fail; if (!freerdp_settings_set_pointer_len(_settings, FreeRDP_DynamicChannelArray, NULL, len)) goto out_fail; + if (!freerdp_settings_set_uint32(_settings, FreeRDP_DynamicChannelCount, count)) + goto out_fail; for (index = 0; index < count; index++) {