diff --git a/client/common/client_cliprdr_file.c b/client/common/client_cliprdr_file.c index 50784613b..ce5f6491c 100644 --- a/client/common/client_cliprdr_file.c +++ b/client/common/client_cliprdr_file.c @@ -433,14 +433,15 @@ static BOOL invalidate_inode(void* data, WINPR_ATTR_UNUSED size_t index, va_list WINPR_ASSERT(file_context); WINPR_ASSERT(file_context->fuse_sess); - ArrayList_ForEach(fuse_file->children, notify_delete_child, file_context, fuse_file); + const BOOL res = + ArrayList_ForEach(fuse_file->children, notify_delete_child, file_context, fuse_file); DEBUG_CLIPRDR(file_context->log, "Invalidating inode %lu for file \"%s\"", fuse_file->ino, fuse_file->filename); fuse_lowlevel_notify_inval_inode(file_context->fuse_sess, fuse_file->ino, 0, 0); WLog_Print(file_context->log, WLOG_DEBUG, "Inode %lu invalidated", fuse_file->ino); - return TRUE; + return res; } static void clear_selection(CliprdrFileContext* file_context, BOOL all_selections, @@ -2484,12 +2485,12 @@ BOOL cliprdr_file_context_clear(CliprdrFileContext* file) WLog_Print(file->log, WLOG_DEBUG, "clear file clipboard..."); HashTable_Lock(file->local_streams); - HashTable_Foreach(file->local_streams, local_stream_discard, file); + const BOOL res = HashTable_Foreach(file->local_streams, local_stream_discard, file); HashTable_Unlock(file->local_streams); memset(file->server_data_hash, 0, sizeof(file->server_data_hash)); memset(file->client_data_hash, 0, sizeof(file->client_data_hash)); - return TRUE; + return res; } BOOL cliprdr_file_context_update_client_data(CliprdrFileContext* file, const char* data, diff --git a/libfreerdp/codec/nsc.c b/libfreerdp/codec/nsc.c index 55e797c69..ec9513ee8 100644 --- a/libfreerdp/codec/nsc.c +++ b/libfreerdp/codec/nsc.c @@ -351,7 +351,6 @@ NSC_CONTEXT* nsc_context_new(void) goto error; context->priv->log = WLog_Get("com.freerdp.codec.nsc"); - WLog_OpenAppender(context->priv->log); context->BitmapData = nullptr; context->decode = nsc_decode; context->encode = nsc_encode; diff --git a/libfreerdp/codec/rfx.c b/libfreerdp/codec/rfx.c index 6caeb1623..b0c322c5d 100644 --- a/libfreerdp/codec/rfx.c +++ b/libfreerdp/codec/rfx.c @@ -220,7 +220,6 @@ RFX_CONTEXT* rfx_context_new_ex(BOOL encoder, UINT32 ThreadingFlags) goto fail; priv->log = WLog_Get("com.freerdp.codec.rfx"); - WLog_OpenAppender(priv->log); priv->TilePool = ObjectPool_New(TRUE); if (!priv->TilePool) diff --git a/libfreerdp/common/settings.c b/libfreerdp/common/settings.c index 60cf0ea5d..9f4ce9b40 100644 --- a/libfreerdp/common/settings.c +++ b/libfreerdp/common/settings.c @@ -81,13 +81,15 @@ BOOL freerdp_addin_argv_del_argument(ADDIN_ARGV* args, const char* argument) if (strcmp(argument, arg) == 0) { free(arg); - memmove_s((void*)&args->argv[x], - (WINPR_ASSERTING_INT_CAST(uint32_t, args->argc - x)) * sizeof(char*), - (void*)&args->argv[x + 1], - (WINPR_ASSERTING_INT_CAST(uint32_t, args->argc - x - 1)) * sizeof(char*)); + const BOOL res = + memmove_s((void*)&args->argv[x], + (WINPR_ASSERTING_INT_CAST(uint32_t, args->argc - x)) * sizeof(char*), + (void*)&args->argv[x + 1], + (WINPR_ASSERTING_INT_CAST(uint32_t, args->argc - x - 1)) * + sizeof(char*)) >= 0; args->argv[args->argc - 1] = nullptr; args->argc--; - return TRUE; + return res; } } return FALSE; @@ -571,15 +573,17 @@ BOOL freerdp_static_channel_collection_del(rdpSettings* settings, const char* na { if (strcmp(name, cur->argv[0]) == 0) { - memmove_s((void*)&settings->StaticChannelArray[x], - (count - x) * sizeof(ADDIN_ARGV*), - (void*)&settings->StaticChannelArray[x + 1], - (count - x - 1) * sizeof(ADDIN_ARGV*)); + const BOOL success = memmove_s((void*)&settings->StaticChannelArray[x], + (count - x) * sizeof(ADDIN_ARGV*), + (void*)&settings->StaticChannelArray[x + 1], + (count - x - 1) * sizeof(ADDIN_ARGV*)) >= 0; for (size_t y = count - 1; y < settings->StaticChannelArraySize; y++) settings->StaticChannelArray[y] = nullptr; freerdp_addin_argv_free(cur); - return freerdp_settings_set_uint32(settings, FreeRDP_StaticChannelCount, count - 1); + if (!freerdp_settings_set_uint32(settings, FreeRDP_StaticChannelCount, count - 1)) + return FALSE; + return success; } } } @@ -677,16 +681,17 @@ BOOL freerdp_dynamic_channel_collection_del(rdpSettings* settings, const char* n { if (strcmp(name, cur->argv[0]) == 0) { - memmove_s((void*)&settings->DynamicChannelArray[x], - (count - x) * sizeof(ADDIN_ARGV*), - (void*)&settings->DynamicChannelArray[x + 1], - (count - x - 1) * sizeof(ADDIN_ARGV*)); + const BOOL success = memmove_s((void*)&settings->DynamicChannelArray[x], + (count - x) * sizeof(ADDIN_ARGV*), + (void*)&settings->DynamicChannelArray[x + 1], + (count - x - 1) * sizeof(ADDIN_ARGV*)) >= 0; for (size_t y = count - 1; y < settings->DynamicChannelArraySize; y++) settings->DynamicChannelArray[y] = nullptr; freerdp_addin_argv_free(cur); - return freerdp_settings_set_uint32(settings, FreeRDP_DynamicChannelCount, - count - 1); + if (!freerdp_settings_set_uint32(settings, FreeRDP_DynamicChannelCount, count - 1)) + return FALSE; + return success; } } } diff --git a/libfreerdp/core/gateway/arm.c b/libfreerdp/core/gateway/arm.c index fe335c52b..804d0c4f9 100644 --- a/libfreerdp/core/gateway/arm.c +++ b/libfreerdp/core/gateway/arm.c @@ -322,9 +322,10 @@ static char* arm_create_request_json(rdpArm* arm) WINPR_JSON* json = WINPR_JSON_CreateObject(); if (!json) goto arm_create_cleanup; - WINPR_JSON_AddStringToObject( - json, "application", - freerdp_settings_get_string(arm->context->settings, FreeRDP_RemoteApplicationProgram)); + if (!WINPR_JSON_AddStringToObject( + json, "application", + freerdp_settings_get_string(arm->context->settings, FreeRDP_RemoteApplicationProgram))) + goto arm_create_cleanup; lbi = calloc( freerdp_settings_get_uint32(arm->context->settings, FreeRDP_LoadBalanceInfoLength) + 1, @@ -339,9 +340,12 @@ static char* arm_create_request_json(rdpArm* arm) len); } - WINPR_JSON_AddStringToObject(json, "loadBalanceInfo", lbi); - WINPR_JSON_AddNullToObject(json, "LogonToken"); - WINPR_JSON_AddNullToObject(json, "gatewayLoadBalancerToken"); + if (!WINPR_JSON_AddStringToObject(json, "loadBalanceInfo", lbi)) + goto arm_create_cleanup; + if (!WINPR_JSON_AddNullToObject(json, "LogonToken")) + goto arm_create_cleanup; + if (!WINPR_JSON_AddNullToObject(json, "gatewayLoadBalancerToken")) + goto arm_create_cleanup; message = WINPR_JSON_PrintUnformatted(json); arm_create_cleanup: diff --git a/libfreerdp/core/proxy.c b/libfreerdp/core/proxy.c index 444541b74..b3f82cf66 100644 --- a/libfreerdp/core/proxy.c +++ b/libfreerdp/core/proxy.c @@ -593,7 +593,8 @@ static BOOL http_proxy_connect(rdpContext* context, BIO* bufferedBio, const char const UINT32 timeout = freerdp_settings_get_uint32(context->settings, FreeRDP_TcpConnectTimeout); - _itoa_s(port, port_str, sizeof(port_str), 10); + if (_itoa_s(port, port_str, sizeof(port_str), 10) < 0) + return FALSE; hostLen = strlen(hostname); portLen = strnlen(port_str, sizeof(port_str)); diff --git a/server/proxy/channels/pf_channel_rdpdr.c b/server/proxy/channels/pf_channel_rdpdr.c index 2aeeb92aa..2aa92b771 100644 --- a/server/proxy/channels/pf_channel_rdpdr.c +++ b/server/proxy/channels/pf_channel_rdpdr.c @@ -1663,7 +1663,8 @@ static BOOL filter_smartcard_device_list_announce(pf_channel_server_context* rdp return TRUE; if (DeviceType == RDPDR_DTYP_SMARTCARD) { - ArrayList_Append(rdpdr->blockedDevices, (void*)(size_t)DeviceId); + if (!ArrayList_Append(rdpdr->blockedDevices, (void*)(size_t)DeviceId)) + return FALSE; if (count == 1) return TRUE; diff --git a/winpr/libwinpr/clipboard/synthetic.c b/winpr/libwinpr/clipboard/synthetic.c index d72599848..550a1a462 100644 --- a/winpr/libwinpr/clipboard/synthetic.c +++ b/winpr/libwinpr/clipboard/synthetic.c @@ -967,42 +967,56 @@ BOOL ClipboardInitSynthesizers(wClipboard* clipboard) * CF_TEXT */ { - ClipboardRegisterSynthesizer(clipboard, CF_TEXT, CF_OEMTEXT, - clipboard_synthesize_cf_oemtext); - ClipboardRegisterSynthesizer(clipboard, CF_TEXT, CF_UNICODETEXT, - clipboard_synthesize_cf_unicodetext); - ClipboardRegisterSynthesizer(clipboard, CF_TEXT, CF_LOCALE, clipboard_synthesize_cf_locale); + if (!ClipboardRegisterSynthesizer(clipboard, CF_TEXT, CF_OEMTEXT, + clipboard_synthesize_cf_oemtext)) + return FALSE; + if (!ClipboardRegisterSynthesizer(clipboard, CF_TEXT, CF_UNICODETEXT, + clipboard_synthesize_cf_unicodetext)) + return FALSE; + if (!ClipboardRegisterSynthesizer(clipboard, CF_TEXT, CF_LOCALE, + clipboard_synthesize_cf_locale)) + return FALSE; UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime_text_plain); - ClipboardRegisterSynthesizer(clipboard, CF_TEXT, altFormatId, - clipboard_synthesize_utf8_string); + if (!ClipboardRegisterSynthesizer(clipboard, CF_TEXT, altFormatId, + clipboard_synthesize_utf8_string)) + return FALSE; } /** * CF_OEMTEXT */ { - ClipboardRegisterSynthesizer(clipboard, CF_OEMTEXT, CF_TEXT, clipboard_synthesize_cf_text); - ClipboardRegisterSynthesizer(clipboard, CF_OEMTEXT, CF_UNICODETEXT, - clipboard_synthesize_cf_unicodetext); - ClipboardRegisterSynthesizer(clipboard, CF_OEMTEXT, CF_LOCALE, - clipboard_synthesize_cf_locale); + if (!ClipboardRegisterSynthesizer(clipboard, CF_OEMTEXT, CF_TEXT, + clipboard_synthesize_cf_text)) + return FALSE; + if (!ClipboardRegisterSynthesizer(clipboard, CF_OEMTEXT, CF_UNICODETEXT, + clipboard_synthesize_cf_unicodetext)) + return FALSE; + if (!ClipboardRegisterSynthesizer(clipboard, CF_OEMTEXT, CF_LOCALE, + clipboard_synthesize_cf_locale)) + return FALSE; UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime_text_plain); - ClipboardRegisterSynthesizer(clipboard, CF_OEMTEXT, altFormatId, - clipboard_synthesize_utf8_string); + if (!ClipboardRegisterSynthesizer(clipboard, CF_OEMTEXT, altFormatId, + clipboard_synthesize_utf8_string)) + return FALSE; } /** * CF_UNICODETEXT */ { - ClipboardRegisterSynthesizer(clipboard, CF_UNICODETEXT, CF_TEXT, - clipboard_synthesize_cf_text); - ClipboardRegisterSynthesizer(clipboard, CF_UNICODETEXT, CF_OEMTEXT, - clipboard_synthesize_cf_oemtext); - ClipboardRegisterSynthesizer(clipboard, CF_UNICODETEXT, CF_LOCALE, - clipboard_synthesize_cf_locale); + if (!ClipboardRegisterSynthesizer(clipboard, CF_UNICODETEXT, CF_TEXT, + clipboard_synthesize_cf_text)) + return FALSE; + if (!ClipboardRegisterSynthesizer(clipboard, CF_UNICODETEXT, CF_OEMTEXT, + clipboard_synthesize_cf_oemtext)) + return FALSE; + if (!ClipboardRegisterSynthesizer(clipboard, CF_UNICODETEXT, CF_LOCALE, + clipboard_synthesize_cf_locale)) + return FALSE; UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime_text_plain); - ClipboardRegisterSynthesizer(clipboard, CF_UNICODETEXT, altFormatId, - clipboard_synthesize_utf8_string); + if (!ClipboardRegisterSynthesizer(clipboard, CF_UNICODETEXT, altFormatId, + clipboard_synthesize_utf8_string)) + return FALSE; } /** * UTF8_STRING @@ -1012,14 +1026,18 @@ BOOL ClipboardInitSynthesizers(wClipboard* clipboard) if (formatId) { - ClipboardRegisterSynthesizer(clipboard, formatId, CF_TEXT, - clipboard_synthesize_cf_text); - ClipboardRegisterSynthesizer(clipboard, formatId, CF_OEMTEXT, - clipboard_synthesize_cf_oemtext); - ClipboardRegisterSynthesizer(clipboard, formatId, CF_UNICODETEXT, - clipboard_synthesize_cf_unicodetext); - ClipboardRegisterSynthesizer(clipboard, formatId, CF_LOCALE, - clipboard_synthesize_cf_locale); + if (!ClipboardRegisterSynthesizer(clipboard, formatId, CF_TEXT, + clipboard_synthesize_cf_text)) + return FALSE; + if (!ClipboardRegisterSynthesizer(clipboard, formatId, CF_OEMTEXT, + clipboard_synthesize_cf_oemtext)) + return FALSE; + if (!ClipboardRegisterSynthesizer(clipboard, formatId, CF_UNICODETEXT, + clipboard_synthesize_cf_unicodetext)) + return FALSE; + if (!ClipboardRegisterSynthesizer(clipboard, formatId, CF_LOCALE, + clipboard_synthesize_cf_locale)) + return FALSE; } } /** @@ -1030,14 +1048,18 @@ BOOL ClipboardInitSynthesizers(wClipboard* clipboard) if (formatId) { - ClipboardRegisterSynthesizer(clipboard, formatId, CF_TEXT, - clipboard_synthesize_cf_text); - ClipboardRegisterSynthesizer(clipboard, formatId, CF_OEMTEXT, - clipboard_synthesize_cf_oemtext); - ClipboardRegisterSynthesizer(clipboard, formatId, CF_UNICODETEXT, - clipboard_synthesize_cf_unicodetext); - ClipboardRegisterSynthesizer(clipboard, formatId, CF_LOCALE, - clipboard_synthesize_cf_locale); + if (!ClipboardRegisterSynthesizer(clipboard, formatId, CF_TEXT, + clipboard_synthesize_cf_text)) + return FALSE; + if (!ClipboardRegisterSynthesizer(clipboard, formatId, CF_OEMTEXT, + clipboard_synthesize_cf_oemtext)) + return FALSE; + if (!ClipboardRegisterSynthesizer(clipboard, formatId, CF_UNICODETEXT, + clipboard_synthesize_cf_unicodetext)) + return FALSE; + if (!ClipboardRegisterSynthesizer(clipboard, formatId, CF_LOCALE, + clipboard_synthesize_cf_locale)) + return FALSE; } } @@ -1047,16 +1069,21 @@ BOOL ClipboardInitSynthesizers(wClipboard* clipboard) /** * CF_TIFF */ - ClipboardRegisterSynthesizer(clipboard, CF_TIFF, htmlFormat, clipboard_synthesize_image_html); - ClipboardRegisterSynthesizer(clipboard, tiffFormat, htmlFormat, - clipboard_synthesize_image_html); + if (!ClipboardRegisterSynthesizer(clipboard, CF_TIFF, htmlFormat, + clipboard_synthesize_image_html)) + return FALSE; + if (!ClipboardRegisterSynthesizer(clipboard, tiffFormat, htmlFormat, + clipboard_synthesize_image_html)) + return FALSE; /** * CF_DIB */ { #if defined(WINPR_UTILS_IMAGE_DIBv5) - ClipboardRegisterSynthesizer(clipboard, CF_DIB, CF_DIBV5, clipboard_synthesize_cf_dibv5); + if (!ClipboardRegisterSynthesizer(clipboard, CF_DIB, CF_DIBV5, + clipboard_synthesize_cf_dibv5)) + return FALSE; #endif for (size_t x = 0; x < ARRAYSIZE(mime_bitmap); x++) { @@ -1064,11 +1091,13 @@ BOOL ClipboardInitSynthesizers(wClipboard* clipboard) const UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime); if (altFormatId == 0) continue; - ClipboardRegisterSynthesizer(clipboard, CF_DIB, altFormatId, - clipboard_synthesize_image_bmp); + if (!ClipboardRegisterSynthesizer(clipboard, CF_DIB, altFormatId, + clipboard_synthesize_image_bmp)) + return FALSE; } - ClipboardRegisterSynthesizer(clipboard, CF_DIB, htmlFormat, - clipboard_synthesize_image_html); + if (!ClipboardRegisterSynthesizer(clipboard, CF_DIB, htmlFormat, + clipboard_synthesize_image_html)) + return FALSE; } /** @@ -1076,7 +1105,8 @@ BOOL ClipboardInitSynthesizers(wClipboard* clipboard) */ #if defined(WINPR_UTILS_IMAGE_DIBv5) { - ClipboardRegisterSynthesizer(clipboard, CF_DIBV5, CF_DIB, clipboard_synthesize_cf_dib); + if (!ClipboardRegisterSynthesizer(clipboard, CF_DIBV5, CF_DIB, clipboard_synthesize_cf_dib)) + return FALSE; for (size_t x = 0; x < ARRAYSIZE(mime_bitmap); x++) { @@ -1084,11 +1114,13 @@ BOOL ClipboardInitSynthesizers(wClipboard* clipboard) const UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime); if (altFormatId == 0) continue; - ClipboardRegisterSynthesizer(clipboard, CF_DIBV5, altFormatId, - clipboard_synthesize_image_bmp); + if (!ClipboardRegisterSynthesizer(clipboard, CF_DIBV5, altFormatId, + clipboard_synthesize_image_bmp)) + return FALSE; } - ClipboardRegisterSynthesizer(clipboard, CF_DIBV5, htmlFormat, - clipboard_synthesize_image_html); + if (!ClipboardRegisterSynthesizer(clipboard, CF_DIBV5, htmlFormat, + clipboard_synthesize_image_html)) + return FALSE; } #endif @@ -1101,13 +1133,17 @@ BOOL ClipboardInitSynthesizers(wClipboard* clipboard) const UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime); if (altFormatId == 0) continue; - ClipboardRegisterSynthesizer(clipboard, altFormatId, CF_DIB, clipboard_synthesize_cf_dib); + if (!ClipboardRegisterSynthesizer(clipboard, altFormatId, CF_DIB, + clipboard_synthesize_cf_dib)) + return FALSE; #if defined(WINPR_UTILS_IMAGE_DIBv5) - ClipboardRegisterSynthesizer(clipboard, altFormatId, CF_DIBV5, - clipboard_synthesize_cf_dibv5); + if (!ClipboardRegisterSynthesizer(clipboard, altFormatId, CF_DIBV5, + clipboard_synthesize_cf_dibv5)) + return FALSE; #endif - ClipboardRegisterSynthesizer(clipboard, altFormatId, htmlFormat, - clipboard_synthesize_image_html); + if (!ClipboardRegisterSynthesizer(clipboard, altFormatId, htmlFormat, + clipboard_synthesize_image_html)) + return FALSE; } /** @@ -1116,17 +1152,22 @@ BOOL ClipboardInitSynthesizers(wClipboard* clipboard) #if defined(WINPR_UTILS_IMAGE_PNG) { const UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime_png); - ClipboardRegisterSynthesizer(clipboard, CF_DIB, altFormatId, - clipboard_synthesize_image_bmp_to_png); - ClipboardRegisterSynthesizer(clipboard, altFormatId, CF_DIB, - clipboard_synthesize_image_png_to_bmp); - ClipboardRegisterSynthesizer(clipboard, altFormatId, htmlFormat, - clipboard_synthesize_image_html); + if (!ClipboardRegisterSynthesizer(clipboard, CF_DIB, altFormatId, + clipboard_synthesize_image_bmp_to_png)) + return FALSE; + if (!ClipboardRegisterSynthesizer(clipboard, altFormatId, CF_DIB, + clipboard_synthesize_image_png_to_bmp)) + return FALSE; + if (!ClipboardRegisterSynthesizer(clipboard, altFormatId, htmlFormat, + clipboard_synthesize_image_html)) + return FALSE; #if defined(WINPR_UTILS_IMAGE_DIBv5) - ClipboardRegisterSynthesizer(clipboard, CF_DIBV5, altFormatId, - clipboard_synthesize_image_bmp_to_png); - ClipboardRegisterSynthesizer(clipboard, altFormatId, CF_DIBV5, - clipboard_synthesize_image_png_to_bmp); + if (!ClipboardRegisterSynthesizer(clipboard, CF_DIBV5, altFormatId, + clipboard_synthesize_image_bmp_to_png)) + return FALSE; + if (!ClipboardRegisterSynthesizer(clipboard, altFormatId, CF_DIBV5, + clipboard_synthesize_image_png_to_bmp)) + return FALSE; #endif } #endif @@ -1137,17 +1178,22 @@ BOOL ClipboardInitSynthesizers(wClipboard* clipboard) #if defined(WINPR_UTILS_IMAGE_WEBP) { const UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime_webp); - ClipboardRegisterSynthesizer(clipboard, CF_DIB, altFormatId, - clipboard_synthesize_image_bmp_to_webp); - ClipboardRegisterSynthesizer(clipboard, altFormatId, CF_DIB, - clipboard_synthesize_image_webp_to_bmp); - ClipboardRegisterSynthesizer(clipboard, altFormatId, htmlFormat, - clipboard_synthesize_image_html); + if (!ClipboardRegisterSynthesizer(clipboard, CF_DIB, altFormatId, + clipboard_synthesize_image_bmp_to_webp)) + return FALSE; + if (!ClipboardRegisterSynthesizer(clipboard, altFormatId, CF_DIB, + clipboard_synthesize_image_webp_to_bmp)) + return FALSE; + if (!ClipboardRegisterSynthesizer(clipboard, altFormatId, htmlFormat, + clipboard_synthesize_image_html)) + return FALSE; #if defined(WINPR_UTILS_IMAGE_DIBv5) - ClipboardRegisterSynthesizer(clipboard, CF_DIBV5, altFormatId, - clipboard_synthesize_image_bmp_to_webp); - ClipboardRegisterSynthesizer(clipboard, altFormatId, CF_DIBV5, - clipboard_synthesize_image_webp_to_bmp); + if (!ClipboardRegisterSynthesizer(clipboard, CF_DIBV5, altFormatId, + clipboard_synthesize_image_bmp_to_webp)) + return FALSE; + if (!ClipboardRegisterSynthesizer(clipboard, altFormatId, CF_DIBV5, + clipboard_synthesize_image_webp_to_bmp)) + return FALSE; #endif } #endif @@ -1158,17 +1204,22 @@ BOOL ClipboardInitSynthesizers(wClipboard* clipboard) #if defined(WINPR_UTILS_IMAGE_JPEG) { const UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime_jpeg); - ClipboardRegisterSynthesizer(clipboard, CF_DIB, altFormatId, - clipboard_synthesize_image_bmp_to_jpeg); - ClipboardRegisterSynthesizer(clipboard, altFormatId, CF_DIB, - clipboard_synthesize_image_jpeg_to_bmp); - ClipboardRegisterSynthesizer(clipboard, altFormatId, htmlFormat, - clipboard_synthesize_image_html); + if (!ClipboardRegisterSynthesizer(clipboard, CF_DIB, altFormatId, + clipboard_synthesize_image_bmp_to_jpeg)) + return FALSE; + if (!ClipboardRegisterSynthesizer(clipboard, altFormatId, CF_DIB, + clipboard_synthesize_image_jpeg_to_bmp)) + return FALSE; + if (!ClipboardRegisterSynthesizer(clipboard, altFormatId, htmlFormat, + clipboard_synthesize_image_html)) + return FALSE; #if defined(WINPR_UTILS_IMAGE_DIBv5) - ClipboardRegisterSynthesizer(clipboard, altFormatId, CF_DIBV5, - clipboard_synthesize_image_jpeg_to_bmp); - ClipboardRegisterSynthesizer(clipboard, CF_DIBV5, altFormatId, - clipboard_synthesize_image_bmp_to_jpeg); + if (!ClipboardRegisterSynthesizer(clipboard, altFormatId, CF_DIBV5, + clipboard_synthesize_image_jpeg_to_bmp)) + return FALSE; + if (!ClipboardRegisterSynthesizer(clipboard, CF_DIBV5, altFormatId, + clipboard_synthesize_image_bmp_to_jpeg)) + return FALSE; #endif } #endif @@ -1182,8 +1233,9 @@ BOOL ClipboardInitSynthesizers(wClipboard* clipboard) if (formatId) { const UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime_html); - ClipboardRegisterSynthesizer(clipboard, formatId, altFormatId, - clipboard_synthesize_text_html); + if (!ClipboardRegisterSynthesizer(clipboard, formatId, altFormatId, + clipboard_synthesize_text_html)) + return FALSE; } } @@ -1196,8 +1248,9 @@ BOOL ClipboardInitSynthesizers(wClipboard* clipboard) if (formatId) { const UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime_ms_html); - ClipboardRegisterSynthesizer(clipboard, formatId, altFormatId, - clipboard_synthesize_html_format); + if (!ClipboardRegisterSynthesizer(clipboard, formatId, altFormatId, + clipboard_synthesize_html_format)) + return FALSE; } } diff --git a/winpr/libwinpr/path/path.c b/winpr/libwinpr/path/path.c index 1fdf64aa1..00548ce96 100644 --- a/winpr/libwinpr/path/path.c +++ b/winpr/libwinpr/path/path.c @@ -727,7 +727,9 @@ HRESULT PathCchStripPrefixA(PSTR pszPath, size_t cchPath) if (IsCharAlpha(pszPath[4]) && (pszPath[5] == ':')) /* like C: */ { - memmove_s(pszPath, cchPath, &pszPath[4], cchPath - 4); + if (memmove_s(pszPath, cchPath, &pszPath[4], cchPath - 4) < 0) + return HRESULT_FROM_WIN32(ERROR_INVALID_DATA); + /* since the passed pszPath must not necessarily be null terminated * and we always have enough space after the strip we can always * ensure the null termination of the stripped result @@ -764,7 +766,8 @@ HRESULT PathCchStripPrefixW(PWSTR pszPath, size_t cchPath) if (IsCharAlphaW(pszPath[4]) && (pszPath[5] == L':')) /* like C: */ { - wmemmove_s(pszPath, cchPath, &pszPath[4], cchPath - 4); + if (wmemmove_s(pszPath, cchPath, &pszPath[4], cchPath - 4) < 0) + return HRESULT_FROM_WIN32(ERROR_INVALID_DATA); /* since the passed pszPath must not necessarily be null terminated * and we always have enough space after the strip we can always * ensure the null termination of the stripped result diff --git a/winpr/libwinpr/sspi/NTLM/ntlm.c b/winpr/libwinpr/sspi/NTLM/ntlm.c index 0bebe7468..759712c92 100644 --- a/winpr/libwinpr/sspi/NTLM/ntlm.c +++ b/winpr/libwinpr/sspi/NTLM/ntlm.c @@ -1122,18 +1122,29 @@ static SECURITY_STATUS SEC_ENTRY ntlm_EncryptMessage(PCtxtHandle phContext, /* Compute the HMAC-MD5 hash of ConcatenationOf(seq_num,data) using the client signing key */ WINPR_HMAC_CTX* hmac = winpr_HMAC_New(); - if (hmac && - winpr_HMAC_Init(hmac, WINPR_MD_MD5, context->SendSigningKey, WINPR_MD5_DIGEST_LENGTH)) + BOOL success = FALSE; { + if (!hmac) + goto hmac_fail; + if (!winpr_HMAC_Init(hmac, WINPR_MD_MD5, context->SendSigningKey, WINPR_MD5_DIGEST_LENGTH)) + goto hmac_fail; + winpr_Data_Write_UINT32(&value, SeqNo); - winpr_HMAC_Update(hmac, (void*)&value, 4); - winpr_HMAC_Update(hmac, data, length); - winpr_HMAC_Final(hmac, digest, WINPR_MD5_DIGEST_LENGTH); - winpr_HMAC_Free(hmac); + + if (!winpr_HMAC_Update(hmac, (void*)&value, 4)) + goto hmac_fail; + if (!winpr_HMAC_Update(hmac, data, length)) + goto hmac_fail; + if (!winpr_HMAC_Final(hmac, digest, WINPR_MD5_DIGEST_LENGTH)) + goto hmac_fail; } - else + + success = TRUE; + +hmac_fail: + winpr_HMAC_Free(hmac); + if (!success) { - winpr_HMAC_Free(hmac); free(data); return SEC_E_INSUFFICIENT_MEMORY; } @@ -1142,8 +1153,14 @@ static SECURITY_STATUS SEC_ENTRY ntlm_EncryptMessage(PCtxtHandle phContext, if ((data_buffer->BufferType & SECBUFFER_READONLY) == 0) { if (context->confidentiality) - winpr_RC4_Update(context->SendRc4Seal, length, (BYTE*)data, - (BYTE*)data_buffer->pvBuffer); + { + if (!winpr_RC4_Update(context->SendRc4Seal, length, (BYTE*)data, + (BYTE*)data_buffer->pvBuffer)) + { + free(data); + return SEC_E_INSUFFICIENT_MEMORY; + } + } else CopyMemory(data_buffer->pvBuffer, data, length); } @@ -1156,7 +1173,8 @@ static SECURITY_STATUS SEC_ENTRY ntlm_EncryptMessage(PCtxtHandle phContext, #endif free(data); /* RC4-encrypt first 8 bytes of digest */ - winpr_RC4_Update(context->SendRc4Seal, 8, digest, checksum); + if (!winpr_RC4_Update(context->SendRc4Seal, 8, digest, checksum)) + return SEC_E_INSUFFICIENT_MEMORY; if ((signature_buffer->BufferType & SECBUFFER_READONLY) == 0) { BYTE* signature = signature_buffer->pvBuffer; @@ -1222,18 +1240,29 @@ static SECURITY_STATUS SEC_ENTRY ntlm_DecryptMessage(PCtxtHandle phContext, PSec /* Compute the HMAC-MD5 hash of ConcatenationOf(seq_num,data) using the client signing key */ WINPR_HMAC_CTX* hmac = winpr_HMAC_New(); - if (hmac && - winpr_HMAC_Init(hmac, WINPR_MD_MD5, context->RecvSigningKey, WINPR_MD5_DIGEST_LENGTH)) + BOOL success = FALSE; { + if (!hmac) + goto hmac_fail; + + if (!winpr_HMAC_Init(hmac, WINPR_MD_MD5, context->RecvSigningKey, WINPR_MD5_DIGEST_LENGTH)) + goto hmac_fail; + winpr_Data_Write_UINT32(&value, SeqNo); - winpr_HMAC_Update(hmac, (void*)&value, 4); - winpr_HMAC_Update(hmac, data_buffer->pvBuffer, data_buffer->cbBuffer); - winpr_HMAC_Final(hmac, digest, WINPR_MD5_DIGEST_LENGTH); - winpr_HMAC_Free(hmac); + + if (!winpr_HMAC_Update(hmac, (void*)&value, 4)) + goto hmac_fail; + if (!winpr_HMAC_Update(hmac, data_buffer->pvBuffer, data_buffer->cbBuffer)) + goto hmac_fail; + if (!winpr_HMAC_Final(hmac, digest, WINPR_MD5_DIGEST_LENGTH)) + goto hmac_fail; + + success = TRUE; } - else +hmac_fail: + winpr_HMAC_Free(hmac); + if (!success) { - winpr_HMAC_Free(hmac); free(data); return SEC_E_INSUFFICIENT_MEMORY; } @@ -1246,7 +1275,9 @@ static SECURITY_STATUS SEC_ENTRY ntlm_DecryptMessage(PCtxtHandle phContext, PSec #endif free(data); /* RC4-encrypt first 8 bytes of digest */ - winpr_RC4_Update(context->RecvRc4Seal, 8, digest, checksum); + if (!winpr_RC4_Update(context->RecvRc4Seal, 8, digest, checksum)) + return SEC_E_MESSAGE_ALTERED; + /* Concatenate version, ciphertext and sequence number to build signature */ winpr_Data_Write_UINT32(expected_signature, version); CopyMemory(&expected_signature[4], (void*)checksum, 8); @@ -1308,7 +1339,8 @@ static SECURITY_STATUS SEC_ENTRY ntlm_MakeSignature(PCtxtHandle phContext, if (!winpr_HMAC_Final(hmac, digest, WINPR_MD5_DIGEST_LENGTH)) goto fail; - winpr_RC4_Update(context->SendRc4Seal, 8, digest, checksum); + if (!winpr_RC4_Update(context->SendRc4Seal, 8, digest, checksum)) + goto fail; BYTE* signature = sig_buffer->pvBuffer; winpr_Data_Write_UINT32(signature, 1L); diff --git a/winpr/libwinpr/sspi/NTLM/ntlm_compute.c b/winpr/libwinpr/sspi/NTLM/ntlm_compute.c index 527adc0f6..f36386d1c 100644 --- a/winpr/libwinpr/sspi/NTLM/ntlm_compute.c +++ b/winpr/libwinpr/sspi/NTLM/ntlm_compute.c @@ -530,8 +530,10 @@ SECURITY_STATUS ntlm_compute_lm_v2_response(NTLM_CONTEXT* context) response = (BYTE*)context->LmChallengeResponse.pvBuffer; /* Compute the HMAC-MD5 hash of the resulting value using the NTLMv2 hash as the key */ - winpr_HMAC(WINPR_MD_MD5, (void*)context->NtlmV2Hash, WINPR_MD5_DIGEST_LENGTH, (BYTE*)value, - WINPR_MD5_DIGEST_LENGTH, response, WINPR_MD5_DIGEST_LENGTH); + if (!winpr_HMAC(WINPR_MD_MD5, (void*)context->NtlmV2Hash, WINPR_MD5_DIGEST_LENGTH, (BYTE*)value, + WINPR_MD5_DIGEST_LENGTH, response, WINPR_MD5_DIGEST_LENGTH)) + return SEC_E_ALGORITHM_MISMATCH; + /* Concatenate the resulting HMAC-MD5 hash and the client challenge, giving us the LMv2 response * (24 bytes) */ CopyMemory(&response[16], context->ClientChallenge, 8); @@ -593,9 +595,10 @@ SECURITY_STATUS ntlm_compute_ntlm_v2_response(NTLM_CONTEXT* context) BYTE* blob = (BYTE*)ntlm_v2_temp_chal.pvBuffer; CopyMemory(blob, context->ServerChallenge, 8); CopyMemory(&blob[8], ntlm_v2_temp.pvBuffer, ntlm_v2_temp.cbBuffer); - winpr_HMAC(WINPR_MD_MD5, (BYTE*)context->NtlmV2Hash, WINPR_MD5_DIGEST_LENGTH, - (BYTE*)ntlm_v2_temp_chal.pvBuffer, ntlm_v2_temp_chal.cbBuffer, - context->NtProofString, WINPR_MD5_DIGEST_LENGTH); + if (!winpr_HMAC(WINPR_MD_MD5, (BYTE*)context->NtlmV2Hash, WINPR_MD5_DIGEST_LENGTH, + (BYTE*)ntlm_v2_temp_chal.pvBuffer, ntlm_v2_temp_chal.cbBuffer, + context->NtProofString, WINPR_MD5_DIGEST_LENGTH)) + goto exit; } /* NtChallengeResponse, Concatenate NTProofStr with temp */ @@ -609,9 +612,10 @@ SECURITY_STATUS ntlm_compute_ntlm_v2_response(NTLM_CONTEXT* context) CopyMemory(&blob[16], ntlm_v2_temp.pvBuffer, ntlm_v2_temp.cbBuffer); } /* Compute SessionBaseKey, the HMAC-MD5 hash of NTProofStr using the NTLMv2 hash as the key */ - winpr_HMAC(WINPR_MD_MD5, (BYTE*)context->NtlmV2Hash, WINPR_MD5_DIGEST_LENGTH, - context->NtProofString, WINPR_MD5_DIGEST_LENGTH, context->SessionBaseKey, - WINPR_MD5_DIGEST_LENGTH); + if (!winpr_HMAC(WINPR_MD_MD5, (BYTE*)context->NtlmV2Hash, WINPR_MD5_DIGEST_LENGTH, + context->NtProofString, WINPR_MD5_DIGEST_LENGTH, context->SessionBaseKey, + WINPR_MD5_DIGEST_LENGTH)) + goto exit; ret = SEC_E_OK; exit: sspi_SecBufferFree(&ntlm_v2_temp); diff --git a/winpr/libwinpr/utils/collections/ArrayList.c b/winpr/libwinpr/utils/collections/ArrayList.c index a3e1e978e..98b8d55ec 100644 --- a/winpr/libwinpr/utils/collections/ArrayList.c +++ b/winpr/libwinpr/utils/collections/ArrayList.c @@ -350,7 +350,7 @@ BOOL ArrayList_Insert(wArrayList* arrayList, size_t index, const void* obj) } else { - ArrayList_SetItem(arrayList, index, obj); + ret = ArrayList_SetItem(arrayList, index, obj); } } diff --git a/winpr/libwinpr/utils/collections/MessageQueue.c b/winpr/libwinpr/utils/collections/MessageQueue.c index 5f16f93c1..299fa1f49 100644 --- a/winpr/libwinpr/utils/collections/MessageQueue.c +++ b/winpr/libwinpr/utils/collections/MessageQueue.c @@ -103,6 +103,7 @@ BOOL MessageQueue_Wait(wMessageQueue* queue) static BOOL MessageQueue_EnsureCapacity(wMessageQueue* queue, size_t count) { + BOOL res = TRUE; const size_t increment = 128; WINPR_ASSERT(queue); @@ -147,8 +148,8 @@ static BOOL MessageQueue_EnsureCapacity(wMessageQueue* queue, size_t count) { const size_t remain = queue->tail - batch; const size_t movesize = remain * sizeof(wMessage); - memmove_s(queue->array, queue->tail * sizeof(wMessage), &queue->array[batch], - movesize); + res = memmove_s(queue->array, queue->tail * sizeof(wMessage), &queue->array[batch], + movesize) >= 0; const size_t zerooffset = remain; const size_t zerosize = (queue->tail - remain) * sizeof(wMessage); @@ -158,7 +159,7 @@ static BOOL MessageQueue_EnsureCapacity(wMessageQueue* queue, size_t count) } } - return TRUE; + return res; } BOOL MessageQueue_Dispatch(wMessageQueue* queue, const wMessage* message) diff --git a/winpr/libwinpr/utils/collections/Queue.c b/winpr/libwinpr/utils/collections/Queue.c index 50c08e5a0..a0d7f503e 100644 --- a/winpr/libwinpr/utils/collections/Queue.c +++ b/winpr/libwinpr/utils/collections/Queue.c @@ -188,6 +188,7 @@ BOOL Queue_Contains(wQueue* queue, const void* obj) static BOOL Queue_EnsureCapacity(wQueue* queue, size_t count) { + BOOL res = TRUE; const size_t blocksize = 32ull; WINPR_ASSERT(queue); @@ -239,8 +240,8 @@ static BOOL Queue_EnsureCapacity(wQueue* queue, size_t count) { const size_t remain = queue->tail - batch; const size_t movesize = remain * sizeof(uintptr_t); - memmove_s(queue->array, queue->tail * sizeof(uintptr_t), &queue->array[batch], - movesize); + res = memmove_s(queue->array, queue->tail * sizeof(uintptr_t), &queue->array[batch], + movesize) >= 0; const size_t zerooffset = remain; const size_t zerosize = (queue->tail - remain) * sizeof(uintptr_t); @@ -249,7 +250,7 @@ static BOOL Queue_EnsureCapacity(wQueue* queue, size_t count) } } } - return TRUE; + return res; } /**