diff --git a/.clang-tidy b/.clang-tidy index bf8edbeba..743b256ca 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -28,6 +28,7 @@ Checks: > -cert-dcl16-c, -cert-env33-c, -cert-dcl50-cpp, + -clang-analyzer-webkit.NoUncountedMemberChecker, -clang-analyzer-optin.performance.Padding, -clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling, -clang-analyzer-valist.Uninitialized, diff --git a/channels/cliprdr/cliprdr_common.c b/channels/cliprdr/cliprdr_common.c index d6552af03..1b079ad61 100644 --- a/channels/cliprdr/cliprdr_common.c +++ b/channels/cliprdr/cliprdr_common.c @@ -426,6 +426,9 @@ UINT cliprdr_read_format_list(wStream* s, CLIPRDR_FORMAT_LIST* formatList, BOOL while (Stream_GetRemainingLength(sub1) >= 4) { + if (index >= formatList->numFormats) + goto error_out; + CLIPRDR_FORMAT* format = &formats[index]; Stream_Read_UINT32(sub1, format->formatId); /* formatId (4 bytes) */ diff --git a/client/Mac/main.m b/client/Mac/main.m index 6b1035f87..b4663f1f8 100644 --- a/client/Mac/main.m +++ b/client/Mac/main.m @@ -21,5 +21,5 @@ int main(int argc, char *argv[]) { - return NSApplicationMain(argc, argv); + return NSApplicationMain(argc, (const char *const *)argv); } diff --git a/client/Windows/wf_client.c b/client/Windows/wf_client.c index e97f4a015..c8fab2a8d 100644 --- a/client/Windows/wf_client.c +++ b/client/Windows/wf_client.c @@ -718,7 +718,7 @@ static DWORD wf_is_x509_certificate_trusted(const char* common_name, const char* CERT_CHAIN_POLICY_STATUS PolicyStatus = { 0 }; CERT_CHAIN_ENGINE_CONFIG EngineConfig = { 0 }; - DWORD derPubKeyLen = strlen(fingerprint); + DWORD derPubKeyLen = WINPR_ASSERTING_INT_CAST(uint32_t, strlen(fingerprint)); char* derPubKey = calloc(derPubKeyLen, sizeof(char)); if (NULL == derPubKey) { diff --git a/client/Windows/wf_cliprdr.c b/client/Windows/wf_cliprdr.c index 9335772a0..e489739fa 100644 --- a/client/Windows/wf_cliprdr.c +++ b/client/Windows/wf_cliprdr.c @@ -2114,7 +2114,7 @@ exit: if (groupDsc) { - groupDsc->cItems = clipboard->nFiles; + groupDsc->cItems = WINPR_ASSERTING_INT_CAST(UINT, clipboard->nFiles); for (size_t i = 0; i < clipboard->nFiles; i++) { diff --git a/client/common/test/TestClientCmdLine.c b/client/common/test/TestClientCmdLine.c index 0c9c72c80..f1bca2acf 100644 --- a/client/common/test/TestClientCmdLine.c +++ b/client/common/test/TestClientCmdLine.c @@ -232,13 +232,14 @@ int TestClientCmdLine(int argc, char* argv[]) WINPR_UNUSED(argc); WINPR_UNUSED(argv); - for (size_t i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) + for (size_t i = 0; i < ARRAYSIZE(tests); i++) { const test* current = &tests[i]; int failure = 0; char** command_line = string_list_copy(current->command_line); - if (!testcase(__func__, command_line, string_list_length((const char* const*)command_line), + const int len = string_list_length((const char* const*)command_line); + if (!testcase(__func__, command_line, WINPR_ASSERTING_INT_CAST(size_t, len), current->expected_status, current->validate_settings)) { TEST_FAILURE("parsing arguments.\n"); diff --git a/libfreerdp/codec/test/TestFreeRDPCodecProgressive.c b/libfreerdp/codec/test/TestFreeRDPCodecProgressive.c index ac889bb08..e4a5bf9fc 100644 --- a/libfreerdp/codec/test/TestFreeRDPCodecProgressive.c +++ b/libfreerdp/codec/test/TestFreeRDPCodecProgressive.c @@ -1386,7 +1386,7 @@ static int test_dump(int argc, char* argv[]) const RECTANGLE_16* rects = region16_rects(&invalid, &nbRects); for (size_t x = 0; x < nbRects; x++) { - RECTANGLE_16* rect = &rects[x]; + const RECTANGLE_16* rect = &rects[x]; const UINT32 w = rect->right - rect->left; const UINT32 h = rect->bottom - rect->top; if (!freerdp_image_copy_no_overlap(output, DstFormat, stride, rect->left, diff --git a/libfreerdp/codec/test/cursor/cursor_dump_00000000.c b/libfreerdp/codec/test/cursor/cursor_dump_00000000.c index 475fceaa1..b9acebfa8 100644 --- a/libfreerdp/codec/test/cursor/cursor_dump_00000000.c +++ b/libfreerdp/codec/test/cursor/cursor_dump_00000000.c @@ -5,11 +5,11 @@ #include "cursor_dump_00000000.h" -static const uint8_t andmask[] = { 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc1, 0x80, 0xe3, 0x80, 0xe3, - 0x80, 0xe3, 0x80, 0xe3, 0x80, 0xe3, 0x80, 0xe3, 0x80, 0xe3, 0x80, - 0xe3, 0x80, 0xc1, 0x80, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00 }; +static uint8_t andmask[] = { 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc1, 0x80, 0xe3, 0x80, 0xe3, + 0x80, 0xe3, 0x80, 0xe3, 0x80, 0xe3, 0x80, 0xe3, 0x80, 0xe3, 0x80, + 0xe3, 0x80, 0xc1, 0x80, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00 }; -static const uint8_t xormask[] = { +static uint8_t xormask[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, diff --git a/libfreerdp/codec/test/cursor/cursor_dump_00000001.c b/libfreerdp/codec/test/cursor/cursor_dump_00000001.c index baffd6a9d..7d8778de2 100644 --- a/libfreerdp/codec/test/cursor/cursor_dump_00000001.c +++ b/libfreerdp/codec/test/cursor/cursor_dump_00000001.c @@ -5,7 +5,7 @@ #include "cursor_dump_00000001.h" -static const uint8_t andmask[] = { +static uint8_t andmask[] = { 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xe1, 0xff, 0x00, 0xff, 0xc0, 0xff, 0x00, 0xff, 0xc0, 0xff, 0x00, 0xff, 0xc0, 0xff, 0x00, 0xff, 0xc0, 0xff, 0x00, 0xff, 0xc0, 0xff, 0x00, 0xff, 0xc0, 0xff, 0x00, 0xff, 0xc0, 0xff, 0x00, 0xfc, 0x00, 0x07, 0x00, 0xf8, 0x00, 0x07, 0x00, @@ -14,7 +14,7 @@ static const uint8_t andmask[] = { 0xf0, 0x00, 0x07, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00 }; -static const uint8_t xormask[] = { +static uint8_t xormask[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, diff --git a/libfreerdp/codec/test/cursor/cursor_dump_00000002.c b/libfreerdp/codec/test/cursor/cursor_dump_00000002.c index 069e7bcf4..14dfa02b6 100644 --- a/libfreerdp/codec/test/cursor/cursor_dump_00000002.c +++ b/libfreerdp/codec/test/cursor/cursor_dump_00000002.c @@ -5,7 +5,7 @@ #include "cursor_dump_00000002.h" -static const uint8_t andmask[] = { +static uint8_t andmask[] = { 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0x8f, 0xff, 0x00, 0xef, 0x87, 0xff, 0x00, 0xe3, 0x07, 0xff, 0x00, 0xe0, 0x07, 0xff, 0x00, 0xe0, 0x0f, 0xff, 0x00, 0xe0, 0x0f, 0xff, 0x00, 0xe0, 0x01, 0xff, 0x00, 0xe0, 0x00, 0xff, 0x00, 0xe0, 0x01, 0xff, 0x00, 0xe0, 0x03, 0xff, 0x00, @@ -14,7 +14,7 @@ static const uint8_t andmask[] = { 0xe7, 0xff, 0xff, 0x00, 0xef, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00 }; -static const uint8_t xormask[] = { +static uint8_t xormask[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, diff --git a/libfreerdp/codec/test/cursor/cursor_dump_00000003.c b/libfreerdp/codec/test/cursor/cursor_dump_00000003.c index 476c8e1d1..6b979a70c 100644 --- a/libfreerdp/codec/test/cursor/cursor_dump_00000003.c +++ b/libfreerdp/codec/test/cursor/cursor_dump_00000003.c @@ -5,7 +5,7 @@ #include "cursor_dump_00000003.h" -static const uint8_t andmask[] = { +static uint8_t andmask[] = { 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xc7, 0xff, 0x00, 0xff, 0x83, 0xff, 0x00, 0xff, 0x01, 0xff, 0x00, 0xfe, 0x00, 0xff, 0x00, 0xfc, 0x00, 0x7f, 0x00, 0xf8, 0x00, 0x3f, 0x00, 0xf0, 0xc2, 0x1f, 0x00, 0xe0, 0x82, 0x0f, 0x00, 0xc0, 0x00, 0x07, 0x00, @@ -14,7 +14,7 @@ static const uint8_t andmask[] = { 0xff, 0x03, 0xff, 0x00, 0xff, 0x87, 0xff, 0x00, 0xff, 0xcf, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00 }; -static const uint8_t xormask[] = { +static uint8_t xormask[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, diff --git a/libfreerdp/codec/test/cursor/cursor_dump_00000004.c b/libfreerdp/codec/test/cursor/cursor_dump_00000004.c index 99121c759..bde34b7e3 100644 --- a/libfreerdp/codec/test/cursor/cursor_dump_00000004.c +++ b/libfreerdp/codec/test/cursor/cursor_dump_00000004.c @@ -5,7 +5,7 @@ #include "cursor_dump_00000004.h" -static const uint8_t andmask[] = { +static uint8_t andmask[] = { 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xc7, 0xff, 0x00, 0xff, 0x83, 0xff, 0x00, 0xff, 0x01, 0xff, 0x00, 0xfe, 0x00, 0xff, 0x00, 0xfc, 0x00, 0x7f, 0x00, 0xf8, 0x00, 0x3f, 0x00, 0xf0, 0xc2, 0x1f, 0x00, 0xe0, 0x82, 0x0f, 0x00, 0xc0, 0x00, 0x07, 0x00, @@ -14,7 +14,7 @@ static const uint8_t andmask[] = { 0xff, 0x03, 0xff, 0x00, 0xff, 0x87, 0xff, 0x00, 0xff, 0xcf, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00 }; -static const uint8_t xormask[] = { +static uint8_t xormask[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, diff --git a/libfreerdp/codec/test/cursor/cursor_dump_00000005.c b/libfreerdp/codec/test/cursor/cursor_dump_00000005.c index 68bcf20ef..27f041c27 100644 --- a/libfreerdp/codec/test/cursor/cursor_dump_00000005.c +++ b/libfreerdp/codec/test/cursor/cursor_dump_00000005.c @@ -5,7 +5,7 @@ #include "cursor_dump_00000005.h" -static const uint8_t andmask[] = { +static uint8_t andmask[] = { 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0x8f, 0xff, 0x00, 0xef, 0x87, 0xff, 0x00, 0xe3, 0x07, 0xff, 0x00, 0xe0, 0x07, 0xff, 0x00, 0xe0, 0x0f, 0xff, 0x00, 0xe0, 0x0f, 0xff, 0x00, 0xe0, 0x01, 0xff, 0x00, 0xe0, 0x00, 0xff, 0x00, 0xe0, 0x01, 0xff, 0x00, 0xe0, 0x03, 0xff, 0x00, @@ -14,7 +14,7 @@ static const uint8_t andmask[] = { 0xe7, 0xff, 0xff, 0x00, 0xef, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00 }; -static const uint8_t xormask[] = { +static uint8_t xormask[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, diff --git a/libfreerdp/core/capabilities.c b/libfreerdp/core/capabilities.c index 21e2bdb92..a42da7488 100644 --- a/libfreerdp/core/capabilities.c +++ b/libfreerdp/core/capabilities.c @@ -2895,10 +2895,10 @@ static bool sUuidEqual(const UUID* Uuid1, const UUID* Uuid2) if (!Uuid1 && !Uuid2) return false; - if (!Uuid2 && Uuid1) + if (Uuid1 && !Uuid2) return false; - if (!Uuid1 && !Uuid2) + if (!Uuid1 && Uuid2) return true; if (Uuid1->Data1 != Uuid2->Data1) diff --git a/libfreerdp/core/gateway/rpc.c b/libfreerdp/core/gateway/rpc.c index f08f18e15..c37a773bf 100644 --- a/libfreerdp/core/gateway/rpc.c +++ b/libfreerdp/core/gateway/rpc.c @@ -482,10 +482,18 @@ SSIZE_T rpc_channel_read(RpcChannel* channel, wStream* s, size_t length) return -1; } -SSIZE_T rpc_channel_write(RpcChannel* channel, const BYTE* data, size_t length) +SSIZE_T rpc_channel_write_int(RpcChannel* channel, const BYTE* data, size_t length, + const char* file, size_t line, const char* fkt) { - if (!channel) - return -1; + WINPR_ASSERT(channel); + WINPR_ASSERT(channel->rpc); + + const DWORD level = WLOG_TRACE; + if (WLog_IsLevelActive(channel->rpc->log, level)) + { + WLog_PrintMessage(channel->rpc->log, WLOG_MESSAGE_TEXT, level, line, file, fkt, + "Sending [%s] %" PRIuz " bytes", fkt, length); + } return freerdp_tls_write_all(channel->tls, data, length); } diff --git a/libfreerdp/core/gateway/rpc.h b/libfreerdp/core/gateway/rpc.h index 236688617..55abe469d 100644 --- a/libfreerdp/core/gateway/rpc.h +++ b/libfreerdp/core/gateway/rpc.h @@ -767,7 +767,10 @@ FREERDP_LOCAL size_t rpc_offset_pad(size_t* offset, size_t pad); FREERDP_LOCAL BOOL rpc_get_stub_data_info(rdpRpc* rpc, const rpcconn_hdr_t* header, size_t* offset, size_t* length); -FREERDP_LOCAL SSIZE_T rpc_channel_write(RpcChannel* channel, const BYTE* data, size_t length); +#define rpc_channel_write(channel, data, length) \ + rpc_channel_write_int((channel), (data), (length), __FILE__, __LINE__, __func__) +FREERDP_LOCAL SSIZE_T rpc_channel_write_int(RpcChannel* channel, const BYTE* data, size_t length, + const char* file, size_t line, const char* fkt); FREERDP_LOCAL SSIZE_T rpc_channel_read(RpcChannel* channel, wStream* s, size_t length); diff --git a/libfreerdp/core/gateway/rpc_client.c b/libfreerdp/core/gateway/rpc_client.c index 784301c36..93d881122 100644 --- a/libfreerdp/core/gateway/rpc_client.c +++ b/libfreerdp/core/gateway/rpc_client.c @@ -195,8 +195,8 @@ static int rpc_client_recv_pdu_int(rdpRpc* rpc, RPC_PDU* pdu) rdpTsg* tsg = transport_get_tsg(rpc->transport); - WLog_VRB(TAG, "client state %s, vc state %s", rpc_client_state_str(rpc->State), - rpc_vc_state_str(rpc->VirtualConnection->State)); + WLog_Print(rpc->log, WLOG_TRACE, "client state %s, vc state %s", + rpc_client_state_str(rpc->State), rpc_vc_state_str(rpc->VirtualConnection->State)); const BOOL rc = rts_match_pdu_signature_ex(&RTS_PDU_PING_SIGNATURE, pdu->s, NULL, &found, TRUE); rts_print_pdu_signature(rpc->log, WLOG_TRACE, &found); @@ -216,15 +216,14 @@ static int rpc_client_recv_pdu_int(rdpRpc* rpc, RPC_PDU* pdu) case VIRTUAL_CONNECTION_STATE_WAIT_A3W: if (memcmp(&found, &RTS_PDU_CONN_A3_SIGNATURE, sizeof(found)) != 0) { - wLog* log = WLog_Get(TAG); - WLog_Print(log, WLOG_ERROR, "unexpected RTS PDU: Expected CONN/A3"); - rts_print_pdu_signature(log, WLOG_ERROR, &found); + WLog_Print(rpc->log, WLOG_ERROR, "unexpected RTS PDU: Expected CONN/A3"); + rts_print_pdu_signature(rpc->log, WLOG_ERROR, &found); return -1; } if (!rts_recv_CONN_A3_pdu(rpc, pdu->s)) { - WLog_ERR(TAG, "rts_recv_CONN_A3_pdu failure"); + WLog_Print(rpc->log, WLOG_ERROR, "rts_recv_CONN_A3_pdu failure"); return -1; } @@ -236,15 +235,14 @@ static int rpc_client_recv_pdu_int(rdpRpc* rpc, RPC_PDU* pdu) case VIRTUAL_CONNECTION_STATE_WAIT_C2: if (memcmp(&found, &RTS_PDU_CONN_C2_SIGNATURE, sizeof(found)) != 0) { - wLog* log = WLog_Get(TAG); - WLog_Print(log, WLOG_ERROR, "unexpected RTS PDU: Expected CONN/C2"); - rts_print_pdu_signature(log, WLOG_ERROR, &found); + WLog_Print(rpc->log, WLOG_ERROR, "unexpected RTS PDU: Expected CONN/C2"); + rts_print_pdu_signature(rpc->log, WLOG_ERROR, &found); return -1; } if (!rts_recv_CONN_C2_pdu(rpc, pdu->s)) { - WLog_ERR(TAG, "rts_recv_CONN_C2_pdu failure"); + WLog_Print(rpc->log, WLOG_ERROR, "rts_recv_CONN_C2_pdu failure"); return -1; } @@ -254,7 +252,7 @@ static int rpc_client_recv_pdu_int(rdpRpc* rpc, RPC_PDU* pdu) if (rpc_send_bind_pdu(rpc, TRUE) < 0) { - WLog_ERR(TAG, "rpc_send_bind_pdu failure"); + WLog_Print(rpc->log, WLOG_ERROR, "rpc_send_bind_pdu failure"); return -1; } @@ -279,16 +277,16 @@ static int rpc_client_recv_pdu_int(rdpRpc* rpc, RPC_PDU* pdu) { if (!rpc_recv_bind_ack_pdu(rpc, pdu->s)) { - WLog_ERR(TAG, "rpc_recv_bind_ack_pdu failure"); + WLog_Print(rpc->log, WLOG_ERROR, "rpc_recv_bind_ack_pdu failure"); return -1; } } else { - WLog_ERR(TAG, - "RPC_CLIENT_STATE_WAIT_SECURE_BIND_ACK unexpected pdu type: 0x%08" PRIX32 - "", - pdu->Type); + WLog_Print(rpc->log, WLOG_ERROR, + "RPC_CLIENT_STATE_WAIT_SECURE_BIND_ACK unexpected pdu type: 0x%08" PRIX32 + "", + pdu->Type); return -1; } @@ -297,14 +295,15 @@ static int rpc_client_recv_pdu_int(rdpRpc* rpc, RPC_PDU* pdu) case RPC_BIND_STATE_INCOMPLETE: if (rpc_send_bind_pdu(rpc, FALSE) < 0) { - WLog_ERR(TAG, "rpc_send_bind_pdu failure"); + WLog_Print(rpc->log, WLOG_ERROR, "rpc_send_bind_pdu failure"); return -1; } break; case RPC_BIND_STATE_LAST_LEG: if (rpc_send_rpc_auth_3_pdu(rpc) < 0) { - WLog_ERR(TAG, "rpc_secure_bind: error sending rpc_auth_3 pdu!"); + WLog_Print(rpc->log, WLOG_ERROR, + "rpc_secure_bind: error sending rpc_auth_3 pdu!"); return -1; } /* fallthrough */ @@ -314,7 +313,7 @@ static int rpc_client_recv_pdu_int(rdpRpc* rpc, RPC_PDU* pdu) if (!tsg_proxy_begin(tsg)) { - WLog_ERR(TAG, "tsg_proxy_begin failure"); + WLog_Print(rpc->log, WLOG_ERROR, "tsg_proxy_begin failure"); return -1; } break; @@ -326,7 +325,7 @@ static int rpc_client_recv_pdu_int(rdpRpc* rpc, RPC_PDU* pdu) } else { - WLog_ERR(TAG, "invalid rpc->State: %d", rpc->State); + WLog_Print(rpc->log, WLOG_ERROR, "invalid rpc->State: %d", rpc->State); } } else if (rpc->State >= RPC_CLIENT_STATE_CONTEXT_NEGOTIATED) @@ -349,7 +348,7 @@ static int rpc_client_recv_pdu(rdpRpc* rpc, RPC_PDU* pdu) Stream_SetPosition(pdu->s, 0); const size_t before = Stream_GetRemainingLength(pdu->s); - WLog_VRB(TAG, "RPC PDU parsing %" PRIuz " bytes", before); + WLog_Print(rpc->log, WLOG_TRACE, "RPC PDU parsing %" PRIuz " bytes", before); const int rc = rpc_client_recv_pdu_int(rpc, pdu); if (rc < 0) return rc; @@ -357,7 +356,8 @@ static int rpc_client_recv_pdu(rdpRpc* rpc, RPC_PDU* pdu) if (after > 0) { /* Just log so we do not fail if we have some unprocessed padding bytes */ - WLog_WARN(TAG, "Incompletely parsed RPC PDU (%" PRIuz " bytes remain)", after); + WLog_Print(rpc->log, WLOG_WARN, "Incompletely parsed RPC PDU (%" PRIuz " bytes remain)", + after); } return rc; diff --git a/libfreerdp/core/gateway/rts.c b/libfreerdp/core/gateway/rts.c index 6503d9ada..67258f026 100644 --- a/libfreerdp/core/gateway/rts.c +++ b/libfreerdp/core/gateway/rts.c @@ -1509,15 +1509,26 @@ void rts_generate_cookie(BYTE* cookie) winpr_RAND(cookie, 16); } -static BOOL rts_send_buffer(RpcChannel* channel, wStream* s, size_t frag_length) +#define rts_send_buffer(channel, s, frag_length) \ + rts_send_buffer_int((channel), (s), (frag_length), __FILE__, __LINE__, __func__) +static BOOL rts_send_buffer_int(RpcChannel* channel, wStream* s, size_t frag_length, + const char* file, size_t line, const char* fkt) { BOOL status = FALSE; SSIZE_T rc = 0; WINPR_ASSERT(channel); + WINPR_ASSERT(channel->rpc); WINPR_ASSERT(s); Stream_SealLength(s); + + const DWORD level = WLOG_TRACE; + if (WLog_IsLevelActive(channel->rpc->log, level)) + { + WLog_PrintMessage(channel->rpc->log, WLOG_MESSAGE_TEXT, level, line, file, fkt, + "Sending [%s] %" PRIuz " bytes", fkt, Stream_Length(s)); + } if (Stream_Length(s) < sizeof(rpcconn_common_hdr_t)) goto fail; if (Stream_Length(s) != frag_length) diff --git a/libfreerdp/core/gateway/tsg.c b/libfreerdp/core/gateway/tsg.c index ab74f2465..39b3fbbfb 100644 --- a/libfreerdp/core/gateway/tsg.c +++ b/libfreerdp/core/gateway/tsg.c @@ -233,6 +233,8 @@ struct rdp_tsg wLog* log; }; +static BOOL TsProxyReadPacketSTringMessage(wLog* log, wStream* s, uint32_t* index, + TSG_PACKET_STRING_MESSAGE* msg); static BOOL tsg_stream_align(wLog* log, wStream* s, size_t align); static const char* tsg_packet_id_to_string(UINT32 packetId) @@ -525,11 +527,18 @@ static BOOL tsg_ndr_read_tsg_caps(wLog* log, wStream* s, TSG_PACKET_CAPABILITIES switch (caps->capabilityType) { case TSG_CAPABILITY_TYPE_NAP: + if (count < 1) + { + WLog_Print(log, WLOG_ERROR, "Inconsistent data, capabilityType %s count=%" PRIu32, + tsg_packet_id_to_string(capabilityType), count); + return FALSE; + } return tsg_ndr_read_nap(log, s, &caps->tsgPacket.tsgCapNap); default: WLog_Print(log, WLOG_ERROR, - "unknown TSG_PACKET_CAPABILITIES::capabilityType 0x%04" PRIx32, - caps->capabilityType); + "unknown TSG_PACKET_CAPABILITIES::capabilityType 0x%04" PRIx32 + " [count=%" PRIu32 "]", + caps->capabilityType, count); return FALSE; } } @@ -1457,47 +1466,27 @@ fail: return rc; } -static BOOL tsg_ndr_read_consent_message(wLog* log, rdpContext* context, wStream* s, UINT32* index) +static BOOL tsg_ndr_read_consent_message(wLog* log, rdpContext* context, wStream* s, UINT32* index, + BOOL isMessagePresent) { TSG_PACKET_STRING_MESSAGE packetStringMessage = { 0 }; - UINT32 Pointer = 0; WINPR_ASSERT(context); WINPR_ASSERT(index); - if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12)) + if (!TsProxyReadPacketSTringMessage(log, s, index, &packetStringMessage)) return FALSE; - Stream_Read_INT32(s, packetStringMessage.isDisplayMandatory); - Stream_Read_INT32(s, packetStringMessage.isConsentMandatory); - Stream_Read_UINT32(s, packetStringMessage.msgBytes); - - if (!tsg_ndr_pointer_read(log, s, index, &Pointer, FALSE)) - return FALSE; - - if (Pointer) + if (context->instance && isMessagePresent) { - if (packetStringMessage.msgBytes > TSG_MESSAGING_MAX_MESSAGE_LENGTH) - { - WLog_Print(log, WLOG_ERROR, "Out of Spec Message Length %" PRIu32 "", - packetStringMessage.msgBytes); - return FALSE; - } - if (!tsg_ndr_read_string(log, s, &packetStringMessage.msgBuffer, - packetStringMessage.msgBytes)) - return FALSE; - - if (context->instance) - { - return IFCALLRESULT(TRUE, context->instance->PresentGatewayMessage, context->instance, - TSG_ASYNC_MESSAGE_CONSENT_MESSAGE - ? GATEWAY_MESSAGE_CONSENT - : TSG_ASYNC_MESSAGE_SERVICE_MESSAGE, - packetStringMessage.isDisplayMandatory != 0, - packetStringMessage.isConsentMandatory != 0, - packetStringMessage.msgBytes, packetStringMessage.msgBuffer); - } + return IFCALLRESULT(TRUE, context->instance->PresentGatewayMessage, context->instance, + TSG_ASYNC_MESSAGE_CONSENT_MESSAGE ? GATEWAY_MESSAGE_CONSENT + : TSG_ASYNC_MESSAGE_SERVICE_MESSAGE, + packetStringMessage.isDisplayMandatory != 0, + packetStringMessage.isConsentMandatory != 0, + packetStringMessage.msgBytes, packetStringMessage.msgBuffer); } + return TRUE; } @@ -1524,19 +1513,80 @@ static BOOL tsg_ndr_read_tunnel_context(wLog* log, wStream* s, CONTEXT_HANDLE* t return TRUE; } +static BOOL tsg_ndr_read_TSG_PACKET_MSG_RESPONSE_header(wLog* log, wStream* s, + TSG_PACKET_MSG_RESPONSE* pkt) +{ + + if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16)) + return FALSE; + + Stream_Read_UINT32(s, pkt->msgID); /* MsgId (4 bytes) */ + Stream_Read_UINT32(s, pkt->msgType); /* MsgType (4 bytes) */ + Stream_Read_INT32(s, pkt->isMsgPresent); /* IsMsgPresent (4 bytes) */ + const uint32_t SwitchValue = Stream_Get_UINT32(s); /* SwitchValue (4 bytes) */ + + if (pkt->msgType != SwitchValue) + { + WLog_ERR(TAG, + "[MS-TSGU] 2.2.9.2.1.9 TSG_PACKET_MSG_RESPONSE MsgType[0x%08" PRIx32 + "] != MessageSwitchValue [0x%08" PRIx32 "]", + pkt->msgType, SwitchValue); + return FALSE; + } + + return TRUE; +} + +static BOOL tsg_ndr_read_TSG_PACKET_MSG_RESPONSE(wLog* log, rdpContext* context, wStream* s, + uint32_t* index, uint32_t MsgPtr, + const TSG_PACKET_MSG_RESPONSE* pkg, + uint64_t* reauthContext) +{ + WINPR_ASSERT(pkg); + + if (MsgPtr == 0) + { + WLog_Print(log, WLOG_DEBUG, + "Message {0x%08" PRIx32 "} [%s]::isMsgPresent=%" PRIu32 ", MsgPtr=0x%08" PRIx32, + pkg->msgType, tsg_packet_id_to_string(pkg->msgType), pkg->isMsgPresent, MsgPtr); + return TRUE; + } + + switch (pkg->msgType) + { + case TSG_ASYNC_MESSAGE_CONSENT_MESSAGE: + case TSG_ASYNC_MESSAGE_SERVICE_MESSAGE: + return tsg_ndr_read_consent_message(log, context, s, index, pkg->isMsgPresent); + + case TSG_ASYNC_MESSAGE_REAUTH: + { + if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8)) + return FALSE; + + WINPR_ASSERT(reauthContext); + const uint64_t val = Stream_Get_UINT64(s); /* TunnelContext (8 bytes) */ + if (pkg->isMsgPresent != 0) + *reauthContext = val; + return TRUE; + } + + default: + WLog_Print(log, WLOG_ERROR, "Unexpected Message Type: 0x%" PRIx32 "", pkg->msgType); + return FALSE; + } +} + static BOOL tsg_ndr_read_caps_response(wLog* log, rdpContext* context, wStream* s, UINT32* index, UINT32 PacketPtr, TSG_PACKET_CAPS_RESPONSE* caps, - CONTEXT_HANDLE* tunnelContext, UINT32* tunnelId) + CONTEXT_HANDLE* tunnelContext, UINT32* tunnelId, + uint64_t* reauthContext) { UINT32 PacketQuarResponsePtr = 0; - UINT32 MessageSwitchValue = 0; - UINT32 MsgId = 0; - UINT32 MsgType = 0; - UINT32 IsMessagePresent = 0; WINPR_ASSERT(context); WINPR_ASSERT(index); WINPR_ASSERT(caps); + WINPR_ASSERT(reauthContext); if (!tsg_ndr_pointer_read(log, s, index, &PacketQuarResponsePtr, TRUE)) goto fail; @@ -1546,61 +1596,21 @@ static BOOL tsg_ndr_read_caps_response(wLog* log, rdpContext* context, wStream* if (PacketPtr) { - if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16)) + TSG_PACKET_MSG_RESPONSE pkg = { 0 }; + UINT32 MsgPtr = 0; + + if (!tsg_ndr_read_TSG_PACKET_MSG_RESPONSE_header(log, s, &pkg)) goto fail; - Stream_Read_UINT32(s, MsgId); /* MsgId (4 bytes) */ - Stream_Read_UINT32(s, MsgType); /* MsgType (4 bytes) */ - Stream_Read_UINT32(s, IsMessagePresent); /* IsMessagePresent (4 bytes) */ - if (IsMessagePresent != 0) - { + if (!tsg_ndr_pointer_read(log, s, index, &MsgPtr, TRUE)) + return FALSE; - Stream_Read_UINT32(s, MessageSwitchValue); /* MessageSwitchValue (4 bytes) */ + if (!tsg_ndr_read_quarenc_data(log, s, index, &caps->pktQuarEncResponse)) + goto fail; - (void)MsgId; /* [MS-TSGU] 2.2.9.2.1.9 TSG_PACKET_MSG_RESPONSE MsgId is unused */ - if (MsgType != MessageSwitchValue) - { - WLog_ERR(TAG, - "[MS-TSGU] 2.2.9.2.1.9 TSG_PACKET_MSG_RESPONSE MsgType[0x%08" PRIx32 - "] != MessageSwitchValue [0x%08" PRIx32 "]", - MsgType, MessageSwitchValue); - goto fail; - } - - { - UINT32 MsgPtr = 0; - if (!tsg_ndr_pointer_read(log, s, index, &MsgPtr, TRUE)) - return FALSE; - } - if (!tsg_ndr_read_quarenc_data(log, s, index, &caps->pktQuarEncResponse)) - goto fail; - - switch (MessageSwitchValue) - { - case TSG_ASYNC_MESSAGE_CONSENT_MESSAGE: - case TSG_ASYNC_MESSAGE_SERVICE_MESSAGE: - if (!tsg_ndr_read_consent_message(log, context, s, index)) - goto fail; - break; - - case TSG_ASYNC_MESSAGE_REAUTH: - { - if (!tsg_stream_align(log, s, 8)) - goto fail; - - if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8)) - goto fail; - - Stream_Seek_UINT64(s); /* TunnelContext (8 bytes) */ - } - break; - - default: - WLog_Print(log, WLOG_ERROR, "Unexpected Message Type: 0x%" PRIX32 "", - MessageSwitchValue); - goto fail; - } - } + if (!tsg_ndr_read_TSG_PACKET_MSG_RESPONSE(log, context, s, index, MsgPtr, &pkg, + reauthContext)) + goto fail; } return tsg_ndr_read_tunnel_context(log, s, tunnelContext, tunnelId); @@ -1643,7 +1653,7 @@ static BOOL TsProxyCreateTunnelReadResponse(rdpTsg* tsg, const RPC_PDU* pdu, { if (!tsg_ndr_read_caps_response(tsg->log, context, pdu->s, &index, PacketPtr, &packet.tsgPacket.packetCapsResponse, tunnelContext, - tunnelId)) + tunnelId, &tsg->ReauthTunnelContext)) goto fail; } else if ((packet.packetId == TSG_PACKET_TYPE_QUARENC_RESPONSE) && @@ -1674,6 +1684,12 @@ static BOOL TsProxyCreateTunnelReadResponse(rdpTsg* tsg, const RPC_PDU* pdu, goto fail; } + const size_t rem = Stream_GetRemainingLength(pdu->s); + if (rem != 0) + { + WLog_Print(tsg->log, WLOG_WARN, "Partially parsed %s, %" PRIuz " bytes remain", + tsg_packet_id_to_string(packet.packetId), rem); + } rc = TRUE; fail: return rc; @@ -1880,42 +1896,48 @@ fail: return FALSE; } -static BOOL TsProxyReadPacketSTringMessage(rdpTsg* tsg, wStream* s, TSG_PACKET_STRING_MESSAGE* msg) +static BOOL TsProxyReadPacketSTringMessage(wLog* log, wStream* s, uint32_t* index, + TSG_PACKET_STRING_MESSAGE* msg) { - UINT32 ConsentMessagePtr = 0; UINT32 MsgPtr = 0; - UINT32 index = 0; - if (!tsg || !s || !msg) - return FALSE; + WINPR_ASSERT(msg); - if (!Stream_CheckAndLogRequiredLengthWLog(tsg->log, s, 32)) - return FALSE; + const TSG_PACKET_STRING_MESSAGE empty = { 0 }; + *msg = empty; - if (!tsg_ndr_pointer_read(tsg->log, s, &index, &ConsentMessagePtr, TRUE)) + if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12)) return FALSE; Stream_Read_INT32(s, msg->isDisplayMandatory); /* IsDisplayMandatory (4 bytes) */ Stream_Read_INT32(s, msg->isConsentMandatory); /* IsConsentMandatory (4 bytes) */ Stream_Read_UINT32(s, msg->msgBytes); /* MsgBytes (4 bytes) */ - if (!tsg_ndr_pointer_read(tsg->log, s, &index, &MsgPtr, TRUE)) + if (!tsg_ndr_pointer_read(log, s, index, &MsgPtr, msg->msgBytes != 0)) return FALSE; - return tsg_ndr_read_string(tsg->log, s, &msg->msgBuffer, msg->msgBytes); + if (msg->msgBytes > TSG_MESSAGING_MAX_MESSAGE_LENGTH) + { + WLog_Print(log, WLOG_ERROR, "Out of Spec Message Length %" PRIu32 "", msg->msgBytes); + return FALSE; + } + + if (msg->msgBytes == 0) + { + WLog_Print(log, WLOG_DEBUG, "Empty message, skipping string read"); + return TRUE; + } + + return tsg_ndr_read_string(log, s, &msg->msgBuffer, msg->msgBytes); } static BOOL TsProxyMakeTunnelCallReadResponse(rdpTsg* tsg, const RPC_PDU* pdu) { BOOL rc = FALSE; UINT32 index = 0; - UINT32 SwitchValue = 0; - TSG_PACKET packet; + TSG_PACKET packet = { 0 }; rdpContext* context = NULL; - char* messageText = NULL; TSG_PACKET_MSG_RESPONSE packetMsgResponse = { 0 }; - TSG_PACKET_STRING_MESSAGE packetStringMessage = { 0 }; - TSG_PACKET_REAUTH_MESSAGE packetReauthMessage = { 0 }; UINT32 PacketPtr = 0; UINT32 PacketMsgResponsePtr = 0; @@ -1937,12 +1959,11 @@ static BOOL TsProxyMakeTunnelCallReadResponse(rdpTsg* tsg, const RPC_PDU* pdu) goto fail; Stream_Read_UINT32(pdu->s, packet.packetId); /* PacketId (4 bytes) */ - Stream_Read_UINT32(pdu->s, SwitchValue); /* SwitchValue (4 bytes) */ + const uint32_t SwitchValue = Stream_Get_UINT32(pdu->s); /* SwitchValue (4 bytes) */ WLog_Print(tsg->log, WLOG_DEBUG, "%s", tsg_packet_id_to_string(packet.packetId)); - if ((packet.packetId != TSG_PACKET_TYPE_MESSAGE_PACKET) || - (SwitchValue != TSG_PACKET_TYPE_MESSAGE_PACKET)) + if ((packet.packetId != TSG_PACKET_TYPE_MESSAGE_PACKET) || (packet.packetId != SwitchValue)) { WLog_Print(tsg->log, WLOG_ERROR, "Unexpected PacketId: 0x%08" PRIX32 ", Expected TSG_PACKET_TYPE_MESSAGE_PACKET", @@ -1953,84 +1974,16 @@ static BOOL TsProxyMakeTunnelCallReadResponse(rdpTsg* tsg, const RPC_PDU* pdu) if (!tsg_ndr_pointer_read(tsg->log, pdu->s, &index, &PacketMsgResponsePtr, TRUE)) goto fail; - Stream_Read_UINT32(pdu->s, packetMsgResponse.msgID); /* MsgId (4 bytes) */ - Stream_Read_UINT32(pdu->s, packetMsgResponse.msgType); /* MsgType (4 bytes) */ - Stream_Read_INT32(pdu->s, packetMsgResponse.isMsgPresent); /* IsMsgPresent (4 bytes) */ - - /* 2.2.9.2.1.9 TSG_PACKET_MSG_RESPONSE: Ignore empty message body. */ - if (!packetMsgResponse.isMsgPresent) - { - rc = TRUE; + if (!tsg_ndr_read_TSG_PACKET_MSG_RESPONSE_header(tsg->log, pdu->s, &packetMsgResponse)) goto fail; - } - Stream_Read_UINT32(pdu->s, SwitchValue); /* SwitchValue (4 bytes) */ + UINT32 MessagePtr = 0; + if (!tsg_ndr_pointer_read(tsg->log, pdu->s, &index, &MessagePtr, TRUE)) + goto fail; - switch (SwitchValue) - { - case TSG_ASYNC_MESSAGE_CONSENT_MESSAGE: - if (!TsProxyReadPacketSTringMessage(tsg, pdu->s, &packetStringMessage)) - goto fail; - - messageText = ConvertWCharNToUtf8Alloc( - packetStringMessage.msgBuffer, packetStringMessage.msgBytes / sizeof(WCHAR), NULL); - WLog_Print(tsg->log, WLOG_INFO, "Consent Message: %s", messageText); - free(messageText); - - if (context->instance) - { - rc = IFCALLRESULT(TRUE, context->instance->PresentGatewayMessage, context->instance, - GATEWAY_MESSAGE_CONSENT, - packetStringMessage.isDisplayMandatory != 0, - packetStringMessage.isConsentMandatory != 0, - packetStringMessage.msgBytes, packetStringMessage.msgBuffer); - if (!rc) - goto fail; - } - - break; - - case TSG_ASYNC_MESSAGE_SERVICE_MESSAGE: - if (!TsProxyReadPacketSTringMessage(tsg, pdu->s, &packetStringMessage)) - goto fail; - - messageText = ConvertWCharNToUtf8Alloc( - packetStringMessage.msgBuffer, packetStringMessage.msgBytes / sizeof(WCHAR), NULL); - WLog_Print(tsg->log, WLOG_INFO, "Service Message: %s", messageText); - free(messageText); - - if (context->instance) - { - rc = IFCALLRESULT(TRUE, context->instance->PresentGatewayMessage, context->instance, - GATEWAY_MESSAGE_SERVICE, - packetStringMessage.isDisplayMandatory != 0, - packetStringMessage.isConsentMandatory != 0, - packetStringMessage.msgBytes, packetStringMessage.msgBuffer); - if (!rc) - goto fail; - } - break; - - case TSG_ASYNC_MESSAGE_REAUTH: - { - UINT32 ReauthMessagePtr = 0; - if (!Stream_CheckAndLogRequiredLengthWLog(tsg->log, pdu->s, 20)) - goto fail; - - if (!tsg_ndr_pointer_read(tsg->log, pdu->s, &index, &ReauthMessagePtr, TRUE)) - goto fail; - Stream_Seek_UINT32(pdu->s); /* alignment pad (4 bytes) */ - Stream_Read_UINT64(pdu->s, - packetReauthMessage.tunnelContext); /* TunnelContext (8 bytes) */ - Stream_Seek_UINT32(pdu->s); /* ReturnValue (4 bytes) */ - tsg->ReauthTunnelContext = packetReauthMessage.tunnelContext; - } - break; - - default: - WLog_Print(tsg->log, WLOG_ERROR, "unexpected message type: %" PRIu32 "", SwitchValue); - goto fail; - } + if (!tsg_ndr_read_TSG_PACKET_MSG_RESPONSE(tsg->log, context, pdu->s, &index, MessagePtr, + &packetMsgResponse, &tsg->ReauthTunnelContext)) + goto fail; rc = TRUE; fail: diff --git a/libfreerdp/primitives/sse/prim_templates.h b/libfreerdp/primitives/sse/prim_templates.h index 9d92b0186..b512d1ba6 100644 --- a/libfreerdp/primitives/sse/prim_templates.h +++ b/libfreerdp/primitives/sse/prim_templates.h @@ -139,7 +139,6 @@ int shifts = 0; \ const _type_* sptr = pSrc; \ _type_* dptr = pDst; \ - size_t count; \ __m128i xmm0; \ if (sizeof(_type_) == 1) \ shifts = 1; \ @@ -150,10 +149,10 @@ else if (sizeof(_type_) == 8) \ shifts = 4; \ /* Use 4 128-bit SSE registers. */ \ - count = len >> (7 - shifts); \ + size_t count = len >> (7 - shifts); \ len -= count << (7 - shifts); \ xmm0 = mm_set1_epu32(val); \ - while (count--) \ + for (size_t x = 0; x < count; x++) \ { \ __m128i xmm1 = LOAD_SI128(sptr); \ sptr += (16 / sizeof(_type_)); \ @@ -179,7 +178,7 @@ /* Use a single 128-bit SSE register. */ \ count = len >> (5 - shifts); \ len -= count << (5 - shifts); \ - while (count--) \ + for (size_t x = 0; x < count; x++) \ { \ __m128i xmm1 = LOAD_SI128(sptr); \ sptr += (16 / sizeof(_type_)); \ @@ -188,7 +187,7 @@ dptr += (16 / sizeof(_type_)); \ } \ /* Finish off the remainder. */ \ - while (len--) \ + for (size_t x = 0; x < len; x++) \ { \ _slowWay_; \ } \ diff --git a/libfreerdp/primitives/test/TestPrimitivesYUV.c b/libfreerdp/primitives/test/TestPrimitivesYUV.c index 24c56bd79..9d33fe1ed 100644 --- a/libfreerdp/primitives/test/TestPrimitivesYUV.c +++ b/libfreerdp/primitives/test/TestPrimitivesYUV.c @@ -1036,9 +1036,11 @@ static BOOL compare_yuv444_to_rgb(prim_size_t roi, DWORD type) if (!allocate_yuv(yuv, roi) || !rgb1 || !rgb2) goto fail; - if (soft->YUV444ToRGB_8u_P3AC4R(yuv, yuvStep, rgb1, stride, format, &roi) != PRIMITIVES_SUCCESS) + const BYTE* cyuv[] = { yuv[0], yuv[1], yuv[2] }; + if (soft->YUV444ToRGB_8u_P3AC4R(cyuv, yuvStep, rgb1, stride, format, &roi) != + PRIMITIVES_SUCCESS) goto fail; - if (prims->YUV444ToRGB_8u_P3AC4R(yuv, yuvStep, rgb2, stride, format, &roi) != + if (prims->YUV444ToRGB_8u_P3AC4R(cyuv, yuvStep, rgb2, stride, format, &roi) != PRIMITIVES_SUCCESS) goto fail; @@ -1207,9 +1209,11 @@ static BOOL compare_yuv420_to_rgb(prim_size_t roi, DWORD type) if (!allocate_yuv(yuv, roi) || !rgb1 || !rgb2) goto fail; - if (soft->YUV420ToRGB_8u_P3AC4R(yuv, yuvStep, rgb1, stride, format, &roi) != PRIMITIVES_SUCCESS) + const BYTE* cyuv[3] = { yuv[0], yuv[1], yuv[2] }; + if (soft->YUV420ToRGB_8u_P3AC4R(cyuv, yuvStep, rgb1, stride, format, &roi) != + PRIMITIVES_SUCCESS) goto fail; - if (prims->YUV420ToRGB_8u_P3AC4R(yuv, yuvStep, rgb2, stride, format, &roi) != + if (prims->YUV420ToRGB_8u_P3AC4R(cyuv, yuvStep, rgb2, stride, format, &roi) != PRIMITIVES_SUCCESS) goto fail; diff --git a/winpr/include/winpr/strlst.h b/winpr/include/winpr/strlst.h index 4e49d8b72..346946da1 100644 --- a/winpr/include/winpr/strlst.h +++ b/winpr/include/winpr/strlst.h @@ -30,9 +30,9 @@ extern "C" #endif WINPR_API void string_list_free(char** string_list); - WINPR_API int string_list_length(const char** string_list); - WINPR_API char** string_list_copy(const char** string_list); - WINPR_API void string_list_print(FILE* out, const char** string_list); + WINPR_API int string_list_length(const char* const* string_list); + WINPR_API char** string_list_copy(const char* const* string_list); + WINPR_API void string_list_print(FILE* out, const char* const* string_list); #ifdef __cplusplus } diff --git a/winpr/libwinpr/sspi/NTLM/ntlm_av_pairs.c b/winpr/libwinpr/sspi/NTLM/ntlm_av_pairs.c index ea730f913..8dd801c22 100644 --- a/winpr/libwinpr/sspi/NTLM/ntlm_av_pairs.c +++ b/winpr/libwinpr/sspi/NTLM/ntlm_av_pairs.c @@ -554,7 +554,7 @@ fail: BOOL ntlm_construct_authenticate_target_info(NTLM_CONTEXT* context) { ULONG AvPairsCount = 0; - ULONG AvPairsValueLength = 0; + size_t AvPairsValueLength = 0; NTLM_AV_PAIR* AvTimestamp = NULL; NTLM_AV_PAIR* AvNbDomainName = NULL; NTLM_AV_PAIR* AvNbComputerName = NULL; @@ -575,7 +575,6 @@ BOOL ntlm_construct_authenticate_target_info(NTLM_CONTEXT* context) WINPR_ASSERT(context); AvPairsCount = 1; - AvPairsValueLength = 0; ChallengeTargetInfo = (NTLM_AV_PAIR*)context->ChallengeTargetInfo.pvBuffer; cbChallengeTargetInfo = context->ChallengeTargetInfo.cbBuffer; AvNbDomainName = ntlm_av_pair_get(ChallengeTargetInfo, cbChallengeTargetInfo, MsvAvNbDomainName, diff --git a/winpr/libwinpr/utils/collections/BufferPool.c b/winpr/libwinpr/utils/collections/BufferPool.c index de6682ad1..caf8a23bc 100644 --- a/winpr/libwinpr/utils/collections/BufferPool.c +++ b/winpr/libwinpr/utils/collections/BufferPool.c @@ -379,7 +379,7 @@ BOOL BufferPool_Return(wBufferPool* pool, void* buffer) if ((pool->size + 1) >= pool->capacity) { - SSIZE_T newCapacity = MAX(1, pool->size + (pool->size + 2) / 2 + 1); + SSIZE_T newCapacity = MAX(2, pool->size + (pool->size + 2) / 2 + 1); void** newArray = (void**)realloc( (void*)pool->array, sizeof(void*) * WINPR_ASSERTING_INT_CAST(size_t, newCapacity)); if (!newArray) @@ -416,7 +416,7 @@ BOOL BufferPool_Return(wBufferPool* pool, void* buffer) { if ((pool->aSize + 1) >= pool->aCapacity) { - SSIZE_T newCapacity = MAX(1, pool->aSize + (pool->aSize + 2) / 2 + 1); + SSIZE_T newCapacity = MAX(2, pool->aSize + (pool->aSize + 2) / 2 + 1); wBufferPoolItem* newArray = (wBufferPoolItem*)realloc( pool->aArray, sizeof(wBufferPoolItem) * WINPR_ASSERTING_INT_CAST(size_t, newCapacity)); diff --git a/winpr/libwinpr/utils/strlst.c b/winpr/libwinpr/utils/strlst.c index 44a213538..d60d11075 100644 --- a/winpr/libwinpr/utils/strlst.c +++ b/winpr/libwinpr/utils/strlst.c @@ -35,7 +35,7 @@ void string_list_free(char** string_list) free((void*)string_list); } -int string_list_length(const char** string_list) +int string_list_length(const char* const* string_list) { int i = 0; for (; string_list[i]; i++) @@ -44,7 +44,7 @@ int string_list_length(const char** string_list) return i; } -char** string_list_copy(const char** string_list) +char** string_list_copy(const char* const* string_list) { int length = string_list_length(string_list); char** copy = (char**)calloc(WINPR_ASSERTING_INT_CAST(size_t, length) + 1, sizeof(char*)); @@ -63,7 +63,7 @@ char** string_list_copy(const char** string_list) return copy; } -void string_list_print(FILE* out, const char** string_list) +void string_list_print(FILE* out, const char* const* string_list) { for (int j = 0; string_list[j]; j++) { diff --git a/winpr/libwinpr/utils/windows/debug.c b/winpr/libwinpr/utils/windows/debug.c index 7790d0af2..79cccded4 100644 --- a/winpr/libwinpr/utils/windows/debug.c +++ b/winpr/libwinpr/utils/windows/debug.c @@ -147,7 +147,8 @@ char* winpr_win_strerror(DWORD dw, char* dmsg, size_t size) if (rc > 0) { #if defined(UNICODE) - WideCharToMultiByte(CP_ACP, 0, msg, (int)rc, dmsg, (int)MIN(size - 1, INT_MAX), NULL, NULL); + (void)WideCharToMultiByte(CP_ACP, 0, msg, (int)rc, dmsg, (int)MIN(size - 1, INT_MAX), NULL, + NULL); #else /* defined(UNICODE) */ memcpy(dmsg, msg, MIN(rc, size - 1)); #endif /* defined(UNICODE) */