Merge pull request #12409 from akallabeth/various-return-checks

Various return checks
This commit is contained in:
akallabeth
2026-03-02 19:05:12 +01:00
committed by GitHub
14 changed files with 262 additions and 158 deletions

View File

@@ -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);
WINPR_ASSERT(file_context->fuse_sess); 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, DEBUG_CLIPRDR(file_context->log, "Invalidating inode %lu for file \"%s\"", fuse_file->ino,
fuse_file->filename); fuse_file->filename);
fuse_lowlevel_notify_inval_inode(file_context->fuse_sess, fuse_file->ino, 0, 0); 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); 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, 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..."); WLog_Print(file->log, WLOG_DEBUG, "clear file clipboard...");
HashTable_Lock(file->local_streams); 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); HashTable_Unlock(file->local_streams);
memset(file->server_data_hash, 0, sizeof(file->server_data_hash)); memset(file->server_data_hash, 0, sizeof(file->server_data_hash));
memset(file->client_data_hash, 0, sizeof(file->client_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, BOOL cliprdr_file_context_update_client_data(CliprdrFileContext* file, const char* data,

View File

@@ -351,7 +351,6 @@ NSC_CONTEXT* nsc_context_new(void)
goto error; goto error;
context->priv->log = WLog_Get("com.freerdp.codec.nsc"); context->priv->log = WLog_Get("com.freerdp.codec.nsc");
WLog_OpenAppender(context->priv->log);
context->BitmapData = nullptr; context->BitmapData = nullptr;
context->decode = nsc_decode; context->decode = nsc_decode;
context->encode = nsc_encode; context->encode = nsc_encode;

View File

@@ -220,7 +220,6 @@ RFX_CONTEXT* rfx_context_new_ex(BOOL encoder, UINT32 ThreadingFlags)
goto fail; goto fail;
priv->log = WLog_Get("com.freerdp.codec.rfx"); priv->log = WLog_Get("com.freerdp.codec.rfx");
WLog_OpenAppender(priv->log);
priv->TilePool = ObjectPool_New(TRUE); priv->TilePool = ObjectPool_New(TRUE);
if (!priv->TilePool) if (!priv->TilePool)

View File

@@ -81,13 +81,15 @@ BOOL freerdp_addin_argv_del_argument(ADDIN_ARGV* args, const char* argument)
if (strcmp(argument, arg) == 0) if (strcmp(argument, arg) == 0)
{ {
free(arg); free(arg);
memmove_s((void*)&args->argv[x], const BOOL res =
(WINPR_ASSERTING_INT_CAST(uint32_t, args->argc - x)) * sizeof(char*), memmove_s((void*)&args->argv[x],
(void*)&args->argv[x + 1], (WINPR_ASSERTING_INT_CAST(uint32_t, args->argc - x)) * sizeof(char*),
(WINPR_ASSERTING_INT_CAST(uint32_t, args->argc - x - 1)) * 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->argv[args->argc - 1] = nullptr;
args->argc--; args->argc--;
return TRUE; return res;
} }
} }
return FALSE; return FALSE;
@@ -571,15 +573,17 @@ BOOL freerdp_static_channel_collection_del(rdpSettings* settings, const char* na
{ {
if (strcmp(name, cur->argv[0]) == 0) if (strcmp(name, cur->argv[0]) == 0)
{ {
memmove_s((void*)&settings->StaticChannelArray[x], const BOOL success = memmove_s((void*)&settings->StaticChannelArray[x],
(count - x) * sizeof(ADDIN_ARGV*), (count - x) * sizeof(ADDIN_ARGV*),
(void*)&settings->StaticChannelArray[x + 1], (void*)&settings->StaticChannelArray[x + 1],
(count - x - 1) * sizeof(ADDIN_ARGV*)); (count - x - 1) * sizeof(ADDIN_ARGV*)) >= 0;
for (size_t y = count - 1; y < settings->StaticChannelArraySize; y++) for (size_t y = count - 1; y < settings->StaticChannelArraySize; y++)
settings->StaticChannelArray[y] = nullptr; settings->StaticChannelArray[y] = nullptr;
freerdp_addin_argv_free(cur); 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) if (strcmp(name, cur->argv[0]) == 0)
{ {
memmove_s((void*)&settings->DynamicChannelArray[x], const BOOL success = memmove_s((void*)&settings->DynamicChannelArray[x],
(count - x) * sizeof(ADDIN_ARGV*), (count - x) * sizeof(ADDIN_ARGV*),
(void*)&settings->DynamicChannelArray[x + 1], (void*)&settings->DynamicChannelArray[x + 1],
(count - x - 1) * sizeof(ADDIN_ARGV*)); (count - x - 1) * sizeof(ADDIN_ARGV*)) >= 0;
for (size_t y = count - 1; y < settings->DynamicChannelArraySize; y++) for (size_t y = count - 1; y < settings->DynamicChannelArraySize; y++)
settings->DynamicChannelArray[y] = nullptr; settings->DynamicChannelArray[y] = nullptr;
freerdp_addin_argv_free(cur); freerdp_addin_argv_free(cur);
return freerdp_settings_set_uint32(settings, FreeRDP_DynamicChannelCount, if (!freerdp_settings_set_uint32(settings, FreeRDP_DynamicChannelCount, count - 1))
count - 1); return FALSE;
return success;
} }
} }
} }

View File

@@ -322,9 +322,10 @@ static char* arm_create_request_json(rdpArm* arm)
WINPR_JSON* json = WINPR_JSON_CreateObject(); WINPR_JSON* json = WINPR_JSON_CreateObject();
if (!json) if (!json)
goto arm_create_cleanup; goto arm_create_cleanup;
WINPR_JSON_AddStringToObject( if (!WINPR_JSON_AddStringToObject(
json, "application", json, "application",
freerdp_settings_get_string(arm->context->settings, FreeRDP_RemoteApplicationProgram)); freerdp_settings_get_string(arm->context->settings, FreeRDP_RemoteApplicationProgram)))
goto arm_create_cleanup;
lbi = calloc( lbi = calloc(
freerdp_settings_get_uint32(arm->context->settings, FreeRDP_LoadBalanceInfoLength) + 1, freerdp_settings_get_uint32(arm->context->settings, FreeRDP_LoadBalanceInfoLength) + 1,
@@ -339,9 +340,12 @@ static char* arm_create_request_json(rdpArm* arm)
len); len);
} }
WINPR_JSON_AddStringToObject(json, "loadBalanceInfo", lbi); if (!WINPR_JSON_AddStringToObject(json, "loadBalanceInfo", lbi))
WINPR_JSON_AddNullToObject(json, "LogonToken"); goto arm_create_cleanup;
WINPR_JSON_AddNullToObject(json, "gatewayLoadBalancerToken"); 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); message = WINPR_JSON_PrintUnformatted(json);
arm_create_cleanup: arm_create_cleanup:

View File

@@ -593,7 +593,8 @@ static BOOL http_proxy_connect(rdpContext* context, BIO* bufferedBio, const char
const UINT32 timeout = const UINT32 timeout =
freerdp_settings_get_uint32(context->settings, FreeRDP_TcpConnectTimeout); 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); hostLen = strlen(hostname);
portLen = strnlen(port_str, sizeof(port_str)); portLen = strnlen(port_str, sizeof(port_str));

View File

@@ -1663,7 +1663,8 @@ static BOOL filter_smartcard_device_list_announce(pf_channel_server_context* rdp
return TRUE; return TRUE;
if (DeviceType == RDPDR_DTYP_SMARTCARD) 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) if (count == 1)
return TRUE; return TRUE;

View File

@@ -967,42 +967,56 @@ BOOL ClipboardInitSynthesizers(wClipboard* clipboard)
* CF_TEXT * CF_TEXT
*/ */
{ {
ClipboardRegisterSynthesizer(clipboard, CF_TEXT, CF_OEMTEXT, if (!ClipboardRegisterSynthesizer(clipboard, CF_TEXT, CF_OEMTEXT,
clipboard_synthesize_cf_oemtext); clipboard_synthesize_cf_oemtext))
ClipboardRegisterSynthesizer(clipboard, CF_TEXT, CF_UNICODETEXT, return FALSE;
clipboard_synthesize_cf_unicodetext); if (!ClipboardRegisterSynthesizer(clipboard, CF_TEXT, CF_UNICODETEXT,
ClipboardRegisterSynthesizer(clipboard, CF_TEXT, CF_LOCALE, clipboard_synthesize_cf_locale); 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); UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime_text_plain);
ClipboardRegisterSynthesizer(clipboard, CF_TEXT, altFormatId, if (!ClipboardRegisterSynthesizer(clipboard, CF_TEXT, altFormatId,
clipboard_synthesize_utf8_string); clipboard_synthesize_utf8_string))
return FALSE;
} }
/** /**
* CF_OEMTEXT * CF_OEMTEXT
*/ */
{ {
ClipboardRegisterSynthesizer(clipboard, CF_OEMTEXT, CF_TEXT, clipboard_synthesize_cf_text); if (!ClipboardRegisterSynthesizer(clipboard, CF_OEMTEXT, CF_TEXT,
ClipboardRegisterSynthesizer(clipboard, CF_OEMTEXT, CF_UNICODETEXT, clipboard_synthesize_cf_text))
clipboard_synthesize_cf_unicodetext); return FALSE;
ClipboardRegisterSynthesizer(clipboard, CF_OEMTEXT, CF_LOCALE, if (!ClipboardRegisterSynthesizer(clipboard, CF_OEMTEXT, CF_UNICODETEXT,
clipboard_synthesize_cf_locale); 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); UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime_text_plain);
ClipboardRegisterSynthesizer(clipboard, CF_OEMTEXT, altFormatId, if (!ClipboardRegisterSynthesizer(clipboard, CF_OEMTEXT, altFormatId,
clipboard_synthesize_utf8_string); clipboard_synthesize_utf8_string))
return FALSE;
} }
/** /**
* CF_UNICODETEXT * CF_UNICODETEXT
*/ */
{ {
ClipboardRegisterSynthesizer(clipboard, CF_UNICODETEXT, CF_TEXT, if (!ClipboardRegisterSynthesizer(clipboard, CF_UNICODETEXT, CF_TEXT,
clipboard_synthesize_cf_text); clipboard_synthesize_cf_text))
ClipboardRegisterSynthesizer(clipboard, CF_UNICODETEXT, CF_OEMTEXT, return FALSE;
clipboard_synthesize_cf_oemtext); if (!ClipboardRegisterSynthesizer(clipboard, CF_UNICODETEXT, CF_OEMTEXT,
ClipboardRegisterSynthesizer(clipboard, CF_UNICODETEXT, CF_LOCALE, clipboard_synthesize_cf_oemtext))
clipboard_synthesize_cf_locale); return FALSE;
if (!ClipboardRegisterSynthesizer(clipboard, CF_UNICODETEXT, CF_LOCALE,
clipboard_synthesize_cf_locale))
return FALSE;
UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime_text_plain); UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime_text_plain);
ClipboardRegisterSynthesizer(clipboard, CF_UNICODETEXT, altFormatId, if (!ClipboardRegisterSynthesizer(clipboard, CF_UNICODETEXT, altFormatId,
clipboard_synthesize_utf8_string); clipboard_synthesize_utf8_string))
return FALSE;
} }
/** /**
* UTF8_STRING * UTF8_STRING
@@ -1012,14 +1026,18 @@ BOOL ClipboardInitSynthesizers(wClipboard* clipboard)
if (formatId) if (formatId)
{ {
ClipboardRegisterSynthesizer(clipboard, formatId, CF_TEXT, if (!ClipboardRegisterSynthesizer(clipboard, formatId, CF_TEXT,
clipboard_synthesize_cf_text); clipboard_synthesize_cf_text))
ClipboardRegisterSynthesizer(clipboard, formatId, CF_OEMTEXT, return FALSE;
clipboard_synthesize_cf_oemtext); if (!ClipboardRegisterSynthesizer(clipboard, formatId, CF_OEMTEXT,
ClipboardRegisterSynthesizer(clipboard, formatId, CF_UNICODETEXT, clipboard_synthesize_cf_oemtext))
clipboard_synthesize_cf_unicodetext); return FALSE;
ClipboardRegisterSynthesizer(clipboard, formatId, CF_LOCALE, if (!ClipboardRegisterSynthesizer(clipboard, formatId, CF_UNICODETEXT,
clipboard_synthesize_cf_locale); 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) if (formatId)
{ {
ClipboardRegisterSynthesizer(clipboard, formatId, CF_TEXT, if (!ClipboardRegisterSynthesizer(clipboard, formatId, CF_TEXT,
clipboard_synthesize_cf_text); clipboard_synthesize_cf_text))
ClipboardRegisterSynthesizer(clipboard, formatId, CF_OEMTEXT, return FALSE;
clipboard_synthesize_cf_oemtext); if (!ClipboardRegisterSynthesizer(clipboard, formatId, CF_OEMTEXT,
ClipboardRegisterSynthesizer(clipboard, formatId, CF_UNICODETEXT, clipboard_synthesize_cf_oemtext))
clipboard_synthesize_cf_unicodetext); return FALSE;
ClipboardRegisterSynthesizer(clipboard, formatId, CF_LOCALE, if (!ClipboardRegisterSynthesizer(clipboard, formatId, CF_UNICODETEXT,
clipboard_synthesize_cf_locale); 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 * CF_TIFF
*/ */
ClipboardRegisterSynthesizer(clipboard, CF_TIFF, htmlFormat, clipboard_synthesize_image_html); if (!ClipboardRegisterSynthesizer(clipboard, CF_TIFF, htmlFormat,
ClipboardRegisterSynthesizer(clipboard, tiffFormat, htmlFormat, clipboard_synthesize_image_html))
clipboard_synthesize_image_html); return FALSE;
if (!ClipboardRegisterSynthesizer(clipboard, tiffFormat, htmlFormat,
clipboard_synthesize_image_html))
return FALSE;
/** /**
* CF_DIB * CF_DIB
*/ */
{ {
#if defined(WINPR_UTILS_IMAGE_DIBv5) #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 #endif
for (size_t x = 0; x < ARRAYSIZE(mime_bitmap); x++) for (size_t x = 0; x < ARRAYSIZE(mime_bitmap); x++)
{ {
@@ -1064,11 +1091,13 @@ BOOL ClipboardInitSynthesizers(wClipboard* clipboard)
const UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime); const UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime);
if (altFormatId == 0) if (altFormatId == 0)
continue; continue;
ClipboardRegisterSynthesizer(clipboard, CF_DIB, altFormatId, if (!ClipboardRegisterSynthesizer(clipboard, CF_DIB, altFormatId,
clipboard_synthesize_image_bmp); clipboard_synthesize_image_bmp))
return FALSE;
} }
ClipboardRegisterSynthesizer(clipboard, CF_DIB, htmlFormat, if (!ClipboardRegisterSynthesizer(clipboard, CF_DIB, htmlFormat,
clipboard_synthesize_image_html); clipboard_synthesize_image_html))
return FALSE;
} }
/** /**
@@ -1076,7 +1105,8 @@ BOOL ClipboardInitSynthesizers(wClipboard* clipboard)
*/ */
#if defined(WINPR_UTILS_IMAGE_DIBv5) #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++) for (size_t x = 0; x < ARRAYSIZE(mime_bitmap); x++)
{ {
@@ -1084,11 +1114,13 @@ BOOL ClipboardInitSynthesizers(wClipboard* clipboard)
const UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime); const UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime);
if (altFormatId == 0) if (altFormatId == 0)
continue; continue;
ClipboardRegisterSynthesizer(clipboard, CF_DIBV5, altFormatId, if (!ClipboardRegisterSynthesizer(clipboard, CF_DIBV5, altFormatId,
clipboard_synthesize_image_bmp); clipboard_synthesize_image_bmp))
return FALSE;
} }
ClipboardRegisterSynthesizer(clipboard, CF_DIBV5, htmlFormat, if (!ClipboardRegisterSynthesizer(clipboard, CF_DIBV5, htmlFormat,
clipboard_synthesize_image_html); clipboard_synthesize_image_html))
return FALSE;
} }
#endif #endif
@@ -1101,13 +1133,17 @@ BOOL ClipboardInitSynthesizers(wClipboard* clipboard)
const UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime); const UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime);
if (altFormatId == 0) if (altFormatId == 0)
continue; 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) #if defined(WINPR_UTILS_IMAGE_DIBv5)
ClipboardRegisterSynthesizer(clipboard, altFormatId, CF_DIBV5, if (!ClipboardRegisterSynthesizer(clipboard, altFormatId, CF_DIBV5,
clipboard_synthesize_cf_dibv5); clipboard_synthesize_cf_dibv5))
return FALSE;
#endif #endif
ClipboardRegisterSynthesizer(clipboard, altFormatId, htmlFormat, if (!ClipboardRegisterSynthesizer(clipboard, altFormatId, htmlFormat,
clipboard_synthesize_image_html); clipboard_synthesize_image_html))
return FALSE;
} }
/** /**
@@ -1116,17 +1152,22 @@ BOOL ClipboardInitSynthesizers(wClipboard* clipboard)
#if defined(WINPR_UTILS_IMAGE_PNG) #if defined(WINPR_UTILS_IMAGE_PNG)
{ {
const UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime_png); const UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime_png);
ClipboardRegisterSynthesizer(clipboard, CF_DIB, altFormatId, if (!ClipboardRegisterSynthesizer(clipboard, CF_DIB, altFormatId,
clipboard_synthesize_image_bmp_to_png); clipboard_synthesize_image_bmp_to_png))
ClipboardRegisterSynthesizer(clipboard, altFormatId, CF_DIB, return FALSE;
clipboard_synthesize_image_png_to_bmp); if (!ClipboardRegisterSynthesizer(clipboard, altFormatId, CF_DIB,
ClipboardRegisterSynthesizer(clipboard, altFormatId, htmlFormat, clipboard_synthesize_image_png_to_bmp))
clipboard_synthesize_image_html); return FALSE;
if (!ClipboardRegisterSynthesizer(clipboard, altFormatId, htmlFormat,
clipboard_synthesize_image_html))
return FALSE;
#if defined(WINPR_UTILS_IMAGE_DIBv5) #if defined(WINPR_UTILS_IMAGE_DIBv5)
ClipboardRegisterSynthesizer(clipboard, CF_DIBV5, altFormatId, if (!ClipboardRegisterSynthesizer(clipboard, CF_DIBV5, altFormatId,
clipboard_synthesize_image_bmp_to_png); clipboard_synthesize_image_bmp_to_png))
ClipboardRegisterSynthesizer(clipboard, altFormatId, CF_DIBV5, return FALSE;
clipboard_synthesize_image_png_to_bmp); if (!ClipboardRegisterSynthesizer(clipboard, altFormatId, CF_DIBV5,
clipboard_synthesize_image_png_to_bmp))
return FALSE;
#endif #endif
} }
#endif #endif
@@ -1137,17 +1178,22 @@ BOOL ClipboardInitSynthesizers(wClipboard* clipboard)
#if defined(WINPR_UTILS_IMAGE_WEBP) #if defined(WINPR_UTILS_IMAGE_WEBP)
{ {
const UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime_webp); const UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime_webp);
ClipboardRegisterSynthesizer(clipboard, CF_DIB, altFormatId, if (!ClipboardRegisterSynthesizer(clipboard, CF_DIB, altFormatId,
clipboard_synthesize_image_bmp_to_webp); clipboard_synthesize_image_bmp_to_webp))
ClipboardRegisterSynthesizer(clipboard, altFormatId, CF_DIB, return FALSE;
clipboard_synthesize_image_webp_to_bmp); if (!ClipboardRegisterSynthesizer(clipboard, altFormatId, CF_DIB,
ClipboardRegisterSynthesizer(clipboard, altFormatId, htmlFormat, clipboard_synthesize_image_webp_to_bmp))
clipboard_synthesize_image_html); return FALSE;
if (!ClipboardRegisterSynthesizer(clipboard, altFormatId, htmlFormat,
clipboard_synthesize_image_html))
return FALSE;
#if defined(WINPR_UTILS_IMAGE_DIBv5) #if defined(WINPR_UTILS_IMAGE_DIBv5)
ClipboardRegisterSynthesizer(clipboard, CF_DIBV5, altFormatId, if (!ClipboardRegisterSynthesizer(clipboard, CF_DIBV5, altFormatId,
clipboard_synthesize_image_bmp_to_webp); clipboard_synthesize_image_bmp_to_webp))
ClipboardRegisterSynthesizer(clipboard, altFormatId, CF_DIBV5, return FALSE;
clipboard_synthesize_image_webp_to_bmp); if (!ClipboardRegisterSynthesizer(clipboard, altFormatId, CF_DIBV5,
clipboard_synthesize_image_webp_to_bmp))
return FALSE;
#endif #endif
} }
#endif #endif
@@ -1158,17 +1204,22 @@ BOOL ClipboardInitSynthesizers(wClipboard* clipboard)
#if defined(WINPR_UTILS_IMAGE_JPEG) #if defined(WINPR_UTILS_IMAGE_JPEG)
{ {
const UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime_jpeg); const UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime_jpeg);
ClipboardRegisterSynthesizer(clipboard, CF_DIB, altFormatId, if (!ClipboardRegisterSynthesizer(clipboard, CF_DIB, altFormatId,
clipboard_synthesize_image_bmp_to_jpeg); clipboard_synthesize_image_bmp_to_jpeg))
ClipboardRegisterSynthesizer(clipboard, altFormatId, CF_DIB, return FALSE;
clipboard_synthesize_image_jpeg_to_bmp); if (!ClipboardRegisterSynthesizer(clipboard, altFormatId, CF_DIB,
ClipboardRegisterSynthesizer(clipboard, altFormatId, htmlFormat, clipboard_synthesize_image_jpeg_to_bmp))
clipboard_synthesize_image_html); return FALSE;
if (!ClipboardRegisterSynthesizer(clipboard, altFormatId, htmlFormat,
clipboard_synthesize_image_html))
return FALSE;
#if defined(WINPR_UTILS_IMAGE_DIBv5) #if defined(WINPR_UTILS_IMAGE_DIBv5)
ClipboardRegisterSynthesizer(clipboard, altFormatId, CF_DIBV5, if (!ClipboardRegisterSynthesizer(clipboard, altFormatId, CF_DIBV5,
clipboard_synthesize_image_jpeg_to_bmp); clipboard_synthesize_image_jpeg_to_bmp))
ClipboardRegisterSynthesizer(clipboard, CF_DIBV5, altFormatId, return FALSE;
clipboard_synthesize_image_bmp_to_jpeg); if (!ClipboardRegisterSynthesizer(clipboard, CF_DIBV5, altFormatId,
clipboard_synthesize_image_bmp_to_jpeg))
return FALSE;
#endif #endif
} }
#endif #endif
@@ -1182,8 +1233,9 @@ BOOL ClipboardInitSynthesizers(wClipboard* clipboard)
if (formatId) if (formatId)
{ {
const UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime_html); const UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime_html);
ClipboardRegisterSynthesizer(clipboard, formatId, altFormatId, if (!ClipboardRegisterSynthesizer(clipboard, formatId, altFormatId,
clipboard_synthesize_text_html); clipboard_synthesize_text_html))
return FALSE;
} }
} }
@@ -1196,8 +1248,9 @@ BOOL ClipboardInitSynthesizers(wClipboard* clipboard)
if (formatId) if (formatId)
{ {
const UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime_ms_html); const UINT32 altFormatId = ClipboardRegisterFormat(clipboard, mime_ms_html);
ClipboardRegisterSynthesizer(clipboard, formatId, altFormatId, if (!ClipboardRegisterSynthesizer(clipboard, formatId, altFormatId,
clipboard_synthesize_html_format); clipboard_synthesize_html_format))
return FALSE;
} }
} }

View File

@@ -727,7 +727,9 @@ HRESULT PathCchStripPrefixA(PSTR pszPath, size_t cchPath)
if (IsCharAlpha(pszPath[4]) && (pszPath[5] == ':')) /* like C: */ 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 /* since the passed pszPath must not necessarily be null terminated
* and we always have enough space after the strip we can always * and we always have enough space after the strip we can always
* ensure the null termination of the stripped result * 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: */ 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 /* since the passed pszPath must not necessarily be null terminated
* and we always have enough space after the strip we can always * and we always have enough space after the strip we can always
* ensure the null termination of the stripped result * ensure the null termination of the stripped result

View File

@@ -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 */ /* Compute the HMAC-MD5 hash of ConcatenationOf(seq_num,data) using the client signing key */
WINPR_HMAC_CTX* hmac = winpr_HMAC_New(); WINPR_HMAC_CTX* hmac = winpr_HMAC_New();
if (hmac && BOOL success = FALSE;
winpr_HMAC_Init(hmac, WINPR_MD_MD5, context->SendSigningKey, WINPR_MD5_DIGEST_LENGTH))
{ {
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_Data_Write_UINT32(&value, SeqNo);
winpr_HMAC_Update(hmac, (void*)&value, 4);
winpr_HMAC_Update(hmac, data, length); if (!winpr_HMAC_Update(hmac, (void*)&value, 4))
winpr_HMAC_Final(hmac, digest, WINPR_MD5_DIGEST_LENGTH); goto hmac_fail;
winpr_HMAC_Free(hmac); 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); free(data);
return SEC_E_INSUFFICIENT_MEMORY; 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 ((data_buffer->BufferType & SECBUFFER_READONLY) == 0)
{ {
if (context->confidentiality) 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 else
CopyMemory(data_buffer->pvBuffer, data, length); CopyMemory(data_buffer->pvBuffer, data, length);
} }
@@ -1156,7 +1173,8 @@ static SECURITY_STATUS SEC_ENTRY ntlm_EncryptMessage(PCtxtHandle phContext,
#endif #endif
free(data); free(data);
/* RC4-encrypt first 8 bytes of digest */ /* 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) if ((signature_buffer->BufferType & SECBUFFER_READONLY) == 0)
{ {
BYTE* signature = signature_buffer->pvBuffer; 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 */ /* Compute the HMAC-MD5 hash of ConcatenationOf(seq_num,data) using the client signing key */
WINPR_HMAC_CTX* hmac = winpr_HMAC_New(); WINPR_HMAC_CTX* hmac = winpr_HMAC_New();
if (hmac && BOOL success = FALSE;
winpr_HMAC_Init(hmac, WINPR_MD_MD5, context->RecvSigningKey, WINPR_MD5_DIGEST_LENGTH))
{ {
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_Data_Write_UINT32(&value, SeqNo);
winpr_HMAC_Update(hmac, (void*)&value, 4);
winpr_HMAC_Update(hmac, data_buffer->pvBuffer, data_buffer->cbBuffer); if (!winpr_HMAC_Update(hmac, (void*)&value, 4))
winpr_HMAC_Final(hmac, digest, WINPR_MD5_DIGEST_LENGTH); goto hmac_fail;
winpr_HMAC_Free(hmac); 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); free(data);
return SEC_E_INSUFFICIENT_MEMORY; return SEC_E_INSUFFICIENT_MEMORY;
} }
@@ -1246,7 +1275,9 @@ static SECURITY_STATUS SEC_ENTRY ntlm_DecryptMessage(PCtxtHandle phContext, PSec
#endif #endif
free(data); free(data);
/* RC4-encrypt first 8 bytes of digest */ /* 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 */ /* Concatenate version, ciphertext and sequence number to build signature */
winpr_Data_Write_UINT32(expected_signature, version); winpr_Data_Write_UINT32(expected_signature, version);
CopyMemory(&expected_signature[4], (void*)checksum, 8); 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)) if (!winpr_HMAC_Final(hmac, digest, WINPR_MD5_DIGEST_LENGTH))
goto fail; 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; BYTE* signature = sig_buffer->pvBuffer;
winpr_Data_Write_UINT32(signature, 1L); winpr_Data_Write_UINT32(signature, 1L);

View File

@@ -530,8 +530,10 @@ SECURITY_STATUS ntlm_compute_lm_v2_response(NTLM_CONTEXT* context)
response = (BYTE*)context->LmChallengeResponse.pvBuffer; response = (BYTE*)context->LmChallengeResponse.pvBuffer;
/* Compute the HMAC-MD5 hash of the resulting value using the NTLMv2 hash as the key */ /* 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, if (!winpr_HMAC(WINPR_MD_MD5, (void*)context->NtlmV2Hash, WINPR_MD5_DIGEST_LENGTH, (BYTE*)value,
WINPR_MD5_DIGEST_LENGTH, response, WINPR_MD5_DIGEST_LENGTH); 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 /* Concatenate the resulting HMAC-MD5 hash and the client challenge, giving us the LMv2 response
* (24 bytes) */ * (24 bytes) */
CopyMemory(&response[16], context->ClientChallenge, 8); 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; BYTE* blob = (BYTE*)ntlm_v2_temp_chal.pvBuffer;
CopyMemory(blob, context->ServerChallenge, 8); CopyMemory(blob, context->ServerChallenge, 8);
CopyMemory(&blob[8], ntlm_v2_temp.pvBuffer, ntlm_v2_temp.cbBuffer); CopyMemory(&blob[8], ntlm_v2_temp.pvBuffer, ntlm_v2_temp.cbBuffer);
winpr_HMAC(WINPR_MD_MD5, (BYTE*)context->NtlmV2Hash, 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, (BYTE*)ntlm_v2_temp_chal.pvBuffer, ntlm_v2_temp_chal.cbBuffer,
context->NtProofString, WINPR_MD5_DIGEST_LENGTH); context->NtProofString, WINPR_MD5_DIGEST_LENGTH))
goto exit;
} }
/* NtChallengeResponse, Concatenate NTProofStr with temp */ /* 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); 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 */ /* 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, if (!winpr_HMAC(WINPR_MD_MD5, (BYTE*)context->NtlmV2Hash, WINPR_MD5_DIGEST_LENGTH,
context->NtProofString, WINPR_MD5_DIGEST_LENGTH, context->SessionBaseKey, context->NtProofString, WINPR_MD5_DIGEST_LENGTH, context->SessionBaseKey,
WINPR_MD5_DIGEST_LENGTH); WINPR_MD5_DIGEST_LENGTH))
goto exit;
ret = SEC_E_OK; ret = SEC_E_OK;
exit: exit:
sspi_SecBufferFree(&ntlm_v2_temp); sspi_SecBufferFree(&ntlm_v2_temp);

View File

@@ -350,7 +350,7 @@ BOOL ArrayList_Insert(wArrayList* arrayList, size_t index, const void* obj)
} }
else else
{ {
ArrayList_SetItem(arrayList, index, obj); ret = ArrayList_SetItem(arrayList, index, obj);
} }
} }

View File

@@ -103,6 +103,7 @@ BOOL MessageQueue_Wait(wMessageQueue* queue)
static BOOL MessageQueue_EnsureCapacity(wMessageQueue* queue, size_t count) static BOOL MessageQueue_EnsureCapacity(wMessageQueue* queue, size_t count)
{ {
BOOL res = TRUE;
const size_t increment = 128; const size_t increment = 128;
WINPR_ASSERT(queue); 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 remain = queue->tail - batch;
const size_t movesize = remain * sizeof(wMessage); const size_t movesize = remain * sizeof(wMessage);
memmove_s(queue->array, queue->tail * sizeof(wMessage), &queue->array[batch], res = memmove_s(queue->array, queue->tail * sizeof(wMessage), &queue->array[batch],
movesize); movesize) >= 0;
const size_t zerooffset = remain; const size_t zerooffset = remain;
const size_t zerosize = (queue->tail - remain) * sizeof(wMessage); 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) BOOL MessageQueue_Dispatch(wMessageQueue* queue, const wMessage* message)

View File

@@ -188,6 +188,7 @@ BOOL Queue_Contains(wQueue* queue, const void* obj)
static BOOL Queue_EnsureCapacity(wQueue* queue, size_t count) static BOOL Queue_EnsureCapacity(wQueue* queue, size_t count)
{ {
BOOL res = TRUE;
const size_t blocksize = 32ull; const size_t blocksize = 32ull;
WINPR_ASSERT(queue); 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 remain = queue->tail - batch;
const size_t movesize = remain * sizeof(uintptr_t); const size_t movesize = remain * sizeof(uintptr_t);
memmove_s(queue->array, queue->tail * sizeof(uintptr_t), &queue->array[batch], res = memmove_s(queue->array, queue->tail * sizeof(uintptr_t), &queue->array[batch],
movesize); movesize) >= 0;
const size_t zerooffset = remain; const size_t zerooffset = remain;
const size_t zerosize = (queue->tail - remain) * sizeof(uintptr_t); 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;
} }
/** /**