From baa70d1ab629a3ab2d8c4ad82a78f9cd1eea8e0b Mon Sep 17 00:00:00 2001 From: akallabeth Date: Tue, 3 Sep 2024 14:38:45 +0200 Subject: [PATCH] [warnings] fix compare integers of different signs --- channels/printer/client/cups/printer_cups.c | 2 +- .../urbdrc/client/libusb/libusb_udevice.c | 4 +- .../SDL2/dialogs/sdl_connection_dialog.cpp | 2 +- client/SDL/SDL2/sdl_monitor.cpp | 8 +++- .../SDL3/dialogs/sdl_connection_dialog.cpp | 2 +- client/SDL/SDL3/sdl_monitor.cpp | 5 ++- client/SDL/common/sdl_prefs.cpp | 2 +- client/X11/xf_monitor.c | 21 ++++++---- client/X11/xf_monitor.h | 2 +- client/common/client_cliprdr_file.c | 11 ++--- libfreerdp/codec/rfx_differential.h | 2 +- libfreerdp/codec/rfx_rlgr.c | 2 +- libfreerdp/common/assistance.c | 6 +-- libfreerdp/core/childsession.c | 16 ++++---- libfreerdp/core/client.c | 2 +- libfreerdp/core/connection.c | 7 +++- libfreerdp/core/rdp.c | 40 +++++++++++-------- libfreerdp/core/rdp.h | 2 +- libfreerdp/core/tpkt.c | 2 +- libfreerdp/core/tpkt.h | 2 +- libfreerdp/core/window.c | 2 +- 21 files changed, 83 insertions(+), 59 deletions(-) diff --git a/channels/printer/client/cups/printer_cups.c b/channels/printer/client/cups/printer_cups.c index 6f996dd95..3b2fe37b8 100644 --- a/channels/printer/client/cups/printer_cups.c +++ b/channels/printer/client/cups/printer_cups.c @@ -366,7 +366,7 @@ static rdpPrinter** printer_cups_enum_printers(rdpPrinterDriver* driver) if (!printers) return NULL; - for (size_t i = 0; i < num_dests; i++) + for (size_t i = 0; i < (size_t)num_dests; i++) { const cups_dest_t* dest = &dests[i]; if (dest->instance == NULL) diff --git a/channels/urbdrc/client/libusb/libusb_udevice.c b/channels/urbdrc/client/libusb/libusb_udevice.c index a3939b126..5dfb43e90 100644 --- a/channels/urbdrc/client/libusb/libusb_udevice.c +++ b/channels/urbdrc/client/libusb/libusb_udevice.c @@ -864,7 +864,7 @@ static UINT32 libusb_udev_control_query_device_text(IUDEVICE* idev, UINT32 TextT msg, ret, devDescriptor->iProduct); len = MIN(sizeof(strDesc), inSize); - for (ssize_t i = 0; i < len; i++) + for (size_t i = 0; i < len; i++) text[i] = (WCHAR)strDesc[i]; *BufferSize = (BYTE)(len * 2); @@ -899,7 +899,7 @@ static UINT32 libusb_udev_control_query_device_text(IUDEVICE* idev, UINT32 TextT len = strnlen(deviceLocation, MIN(sizeof(deviceLocation), (inSize > 0) ? inSize - 1U : 0)); - for (ssize_t i = 0; i < len; i++) + for (size_t i = 0; i < len; i++) text[i] = (WCHAR)deviceLocation[i]; text[len++] = '\0'; *BufferSize = (UINT8)(len * sizeof(WCHAR)); diff --git a/client/SDL/SDL2/dialogs/sdl_connection_dialog.cpp b/client/SDL/SDL2/dialogs/sdl_connection_dialog.cpp index 1cecc58a0..c63673f8f 100644 --- a/client/SDL/SDL2/dialogs/sdl_connection_dialog.cpp +++ b/client/SDL/SDL2/dialogs/sdl_connection_dialog.cpp @@ -458,7 +458,7 @@ std::string SDLConnectionDialog::print(const char* fmt, va_list ap) size = vsnprintf(res.data(), res.size(), fmt, copy); va_end(copy); - } while ((size > 0) && (size > res.size())); + } while ((size > 0) && (static_cast(size) > res.size())); return res; } diff --git a/client/SDL/SDL2/sdl_monitor.cpp b/client/SDL/SDL2/sdl_monitor.cpp index 5b0e38b05..ab6f2ca38 100644 --- a/client/SDL/SDL2/sdl_monitor.cpp +++ b/client/SDL/SDL2/sdl_monitor.cpp @@ -326,9 +326,13 @@ BOOL sdl_detect_monitors(SdlContext* sdl, UINT32* pMaxWidth, UINT32* pMaxHeight) const int numDisplays = SDL_GetNumVideoDisplays(); auto nr = freerdp_settings_get_uint32(settings, FreeRDP_NumMonitorIds); + if (numDisplays < 0) + return FALSE; + if (nr == 0) { - if (!freerdp_settings_set_pointer_len(settings, FreeRDP_MonitorIds, nullptr, numDisplays)) + if (!freerdp_settings_set_pointer_len(settings, FreeRDP_MonitorIds, nullptr, + static_cast(numDisplays))) return FALSE; for (size_t x = 0; x < numDisplays; x++) { @@ -340,7 +344,7 @@ BOOL sdl_detect_monitors(SdlContext* sdl, UINT32* pMaxWidth, UINT32* pMaxHeight) { /* There were more IDs supplied than there are monitors */ - if (nr > numDisplays) + if (nr > static_cast(numDisplays)) { WLog_ERR(TAG, "Found %" PRIu32 " monitor IDs, but only have %" PRIu32 " monitors connected", diff --git a/client/SDL/SDL3/dialogs/sdl_connection_dialog.cpp b/client/SDL/SDL3/dialogs/sdl_connection_dialog.cpp index 67b3363d2..a8abd01d0 100644 --- a/client/SDL/SDL3/dialogs/sdl_connection_dialog.cpp +++ b/client/SDL/SDL3/dialogs/sdl_connection_dialog.cpp @@ -456,7 +456,7 @@ std::string SDLConnectionDialog::print(const char* fmt, va_list ap) size = vsnprintf(res.data(), res.size(), fmt, copy); va_end(copy); - } while ((size > 0) && (size > res.size())); + } while ((size > 0) && (static_cast(size) > res.size())); return res; } diff --git a/client/SDL/SDL3/sdl_monitor.cpp b/client/SDL/SDL3/sdl_monitor.cpp index 3d7759de8..2d407f57d 100644 --- a/client/SDL/SDL3/sdl_monitor.cpp +++ b/client/SDL/SDL3/sdl_monitor.cpp @@ -323,8 +323,11 @@ BOOL sdl_detect_monitors(SdlContext* sdl, UINT32* pMaxWidth, UINT32* pMaxHeight) { int numDisplays = 0; auto sids = SDL_GetDisplays(&numDisplays); - ids = std::vector(sids, sids + numDisplays); + if (sids && (numDisplays > 0)) + ids = std::vector(sids, sids + numDisplays); SDL_free(sids); + if (numDisplays < 0) + return FALSE; } auto nr = freerdp_settings_get_uint32(settings, FreeRDP_NumMonitorIds); diff --git a/client/SDL/common/sdl_prefs.cpp b/client/SDL/common/sdl_prefs.cpp index b943946e3..d9ddf5bef 100644 --- a/client/SDL/common/sdl_prefs.cpp +++ b/client/SDL/common/sdl_prefs.cpp @@ -94,7 +94,7 @@ std::vector SdlPref::get_array(const std::string& key, return fallback; std::vector values; - for (int x = 0; x < WINPR_JSON_GetArraySize(item); x++) + for (size_t x = 0; x < WINPR_JSON_GetArraySize(item); x++) { auto cur = WINPR_JSON_GetArrayItem(item, x); values.push_back(item_to_str(cur)); diff --git a/client/X11/xf_monitor.c b/client/X11/xf_monitor.c index 96171de73..b7ba07e8f 100644 --- a/client/X11/xf_monitor.c +++ b/client/X11/xf_monitor.c @@ -186,15 +186,17 @@ BOOL xf_detect_monitors(xfContext* xfc, UINT32* pMaxWidth, UINT32* pMaxHeight) if (XRRQueryExtension(xfc->display, &major, &minor) && (XRRQueryVersion(xfc->display, &major, &minor) == True) && (major * 100 + minor >= 105)) { - rrmonitors = - XRRGetMonitors(xfc->display, DefaultRootWindow(xfc->display), 1, &vscreen->nmonitors); + int nmonitors = 0; + rrmonitors = XRRGetMonitors(xfc->display, DefaultRootWindow(xfc->display), 1, &nmonitors); - if (vscreen->nmonitors > 16) + if ((nmonitors < 0) || (nmonitors > 16)) vscreen->nmonitors = 0; + else + vscreen->nmonitors = (UINT32)nmonitors; if (vscreen->nmonitors) { - for (int i = 0; i < vscreen->nmonitors; i++) + for (UINT32 i = 0; i < vscreen->nmonitors; i++) { MONITOR_INFO* cur_vscreen = &vscreen->monitors[i]; const XRRMonitorInfo* cur_monitor = &rrmonitors[i]; @@ -213,14 +215,17 @@ BOOL xf_detect_monitors(xfContext* xfc, UINT32* pMaxWidth, UINT32* pMaxHeight) #ifdef WITH_XINERAMA if (XineramaQueryExtension(xfc->display, &major, &minor) && XineramaIsActive(xfc->display)) { - XineramaScreenInfo* screenInfo = XineramaQueryScreens(xfc->display, &vscreen->nmonitors); + int nmonitors = 0; + XineramaScreenInfo* screenInfo = XineramaQueryScreens(xfc->display, &nmonitors); - if (vscreen->nmonitors > 16) + if ((nmonitors < 0) || (nmonitors > 16)) vscreen->nmonitors = 0; + else + vscreen->nmonitors = (UINT32)nmonitors; if (vscreen->nmonitors) { - for (int i = 0; i < vscreen->nmonitors; i++) + for (UINT32 i = 0; i < vscreen->nmonitors; i++) { MONITOR_INFO* monitor = &vscreen->monitors[i]; monitor->area.left = screenInfo[i].x_org; @@ -240,7 +245,7 @@ BOOL xf_detect_monitors(xfContext* xfc, UINT32* pMaxWidth, UINT32* pMaxHeight) /* Determine which monitor that the mouse cursor is on */ if (vscreen->monitors) { - for (int i = 0; i < vscreen->nmonitors; i++) + for (UINT32 i = 0; i < vscreen->nmonitors; i++) { const MONITOR_INFO* monitor = &vscreen->monitors[i]; diff --git a/client/X11/xf_monitor.h b/client/X11/xf_monitor.h index c27c88f67..6597c1560 100644 --- a/client/X11/xf_monitor.h +++ b/client/X11/xf_monitor.h @@ -32,7 +32,7 @@ typedef struct typedef struct { - int nmonitors; + UINT32 nmonitors; RECTANGLE_16 area; RECTANGLE_16 workarea; MONITOR_INFO* monitors; diff --git a/client/common/client_cliprdr_file.c b/client/common/client_cliprdr_file.c index 00d676e90..79cdd4f64 100644 --- a/client/common/client_cliprdr_file.c +++ b/client/common/client_cliprdr_file.c @@ -320,7 +320,7 @@ static CliprdrFuseClipDataEntry* clip_data_entry_new(CliprdrFileContext* file_co } static BOOL should_remove_fuse_file(CliprdrFuseFile* fuse_file, BOOL all_files, - BOOL has_clip_data_id, BOOL clip_data_id) + BOOL has_clip_data_id, UINT32 clip_data_id) { if (all_files) return TRUE; @@ -329,7 +329,8 @@ static BOOL should_remove_fuse_file(CliprdrFuseFile* fuse_file, BOOL all_files, return FALSE; if (!fuse_file->has_clip_data_id && !has_clip_data_id) return TRUE; - if (fuse_file->has_clip_data_id && has_clip_data_id && fuse_file->clip_data_id == clip_data_id) + if (fuse_file->has_clip_data_id && has_clip_data_id && + (fuse_file->clip_data_id == clip_data_id)) return TRUE; return FALSE; @@ -972,7 +973,7 @@ static void cliprdr_file_fuse_read(fuse_req_t fuse_req, fuse_ino_t fuse_ino, siz fuse_reply_err(fuse_req, EISDIR); return; } - if (!fuse_file->has_size || offset > fuse_file->size) + if (!fuse_file->has_size || (offset < 0) || (offset > fuse_file->size)) { HashTable_Unlock(file_context->inode_table); fuse_reply_err(fuse_req, EINVAL); @@ -1051,7 +1052,7 @@ static void cliprdr_file_fuse_readdir(fuse_req_t fuse_req, fuse_ino_t fuse_ino, DEBUG_CLIPRDR(file_context->log, "Reading directory \"%s\" at offset %lu", fuse_file->filename_with_root, offset); - if (offset >= ArrayList_Count(fuse_file->children)) + if ((offset < 0) || ((size_t)offset >= ArrayList_Count(fuse_file->children))) { HashTable_Unlock(file_context->inode_table); fuse_reply_buf(fuse_req, NULL, 0); @@ -1100,7 +1101,7 @@ static void cliprdr_file_fuse_readdir(fuse_req_t fuse_req, fuse_ino_t fuse_ino, for (size_t j = 0, i = 2; j < ArrayList_Count(fuse_file->children); ++j, ++i) { - if (i < offset) + if (i < (size_t)offset) continue; child = ArrayList_GetItem(fuse_file->children, j); diff --git a/libfreerdp/codec/rfx_differential.h b/libfreerdp/codec/rfx_differential.h index 0633961a1..75d96c327 100644 --- a/libfreerdp/codec/rfx_differential.h +++ b/libfreerdp/codec/rfx_differential.h @@ -38,7 +38,7 @@ static INLINE void rfx_differential_decode(INT16* WINPR_RESTRICT buffer, size_t static INLINE void rfx_differential_encode(INT16* WINPR_RESTRICT buffer, size_t size) { INT16 n1 = buffer[0]; - for (int x = 0; x < size - 1; x++) + for (size_t x = 0; x < size - 1; x++) { INT16* dst = &buffer[x + 1]; const INT16 n2 = *dst; diff --git a/libfreerdp/codec/rfx_rlgr.c b/libfreerdp/codec/rfx_rlgr.c index 8b05e5682..68226006a 100644 --- a/libfreerdp/codec/rfx_rlgr.c +++ b/libfreerdp/codec/rfx_rlgr.c @@ -561,7 +561,7 @@ int rfx_rlgr_decode(RLGR_MODE mode, const BYTE* WINPR_RESTRICT pSrcData, UINT32 offset = (pOutput - pDstData); - if (offset != DstSize) + if ((DstSize < 0) || (offset != (size_t)DstSize)) return -1; return 1; diff --git a/libfreerdp/common/assistance.c b/libfreerdp/common/assistance.c index d12d3eaba..ba5f9d6df 100644 --- a/libfreerdp/common/assistance.c +++ b/libfreerdp/common/assistance.c @@ -423,7 +423,7 @@ static BOOL freerdp_assistance_parse_attr(const char** opt, size_t* plength, con char bkey[128] = { 0 }; const int rc = _snprintf(bkey, sizeof(bkey), "%s=\"", key); WINPR_ASSERT(rc > 0); - WINPR_ASSERT(rc < sizeof(bkey)); + WINPR_ASSERT((size_t)rc < sizeof(bkey)); char* p = strstr(tag, bkey); if (!p) @@ -523,7 +523,7 @@ static char* freerdp_assistance_contains_element(char* input, size_t ilen, const char bkey[128] = { 0 }; const int rc = _snprintf(bkey, sizeof(bkey), "<%s", key); WINPR_ASSERT(rc > 0); - WINPR_ASSERT(rc < sizeof(bkey)); + WINPR_ASSERT((size_t)rc < sizeof(bkey)); char* tag = strstr(input, bkey); if (!tag || (tag > input + ilen)) @@ -562,7 +562,7 @@ static char* freerdp_assistance_contains_element(char* input, size_t ilen, const char ekey[128] = { 0 }; const int erc = _snprintf(ekey, sizeof(ekey), "", key); WINPR_ASSERT(erc > 0); - WINPR_ASSERT(erc < sizeof(ekey)); + WINPR_ASSERT((size_t)erc < sizeof(ekey)); const size_t offset = start - tag; dend = end = strrstr(start, ilen - offset, ekey); if (end) diff --git a/libfreerdp/core/childsession.c b/libfreerdp/core/childsession.c index 7c2f40d5a..6643c2f1b 100644 --- a/libfreerdp/core/childsession.c +++ b/libfreerdp/core/childsession.c @@ -211,10 +211,16 @@ static int transport_bio_named_read(BIO* bio, char* buf, int size) } } - int ret = MIN(size, ringbuffer_used(&ptr->readBuffer)); - if (ret) + SSIZE_T ret = -1; + if (size >= 0) { - DataChunk chunks[2]; + size_t rsize = ringbuffer_used(&ptr->readBuffer); + if (rsize <= SSIZE_MAX) + ret = MIN(size, (SSIZE_T)rsize); + } + if ((size >= 0) && ret) + { + DataChunk chunks[2] = { 0 }; int nchunks = ringbuffer_peek(&ptr->readBuffer, chunks, ret); for (int i = 0; i < nchunks; i++) { @@ -226,10 +232,6 @@ static int transport_bio_named_read(BIO* bio, char* buf, int size) WLog_VRB(TAG, "(%d)=%d nchunks=%d", size, ret, nchunks); } - else - { - ret = -1; - } if (!ringbuffer_used(&ptr->readBuffer)) { diff --git a/libfreerdp/core/client.c b/libfreerdp/core/client.c index 2e2bfeb25..d3b1f4ab5 100644 --- a/libfreerdp/core/client.c +++ b/libfreerdp/core/client.c @@ -511,7 +511,7 @@ BOOL freerdp_channels_data(freerdp* instance, UINT16 channelId, const BYTE* cdat return FALSE; } - for (int index = 0; index < mcs->channelCount; index++) + for (UINT32 index = 0; index < mcs->channelCount; index++) { rdpMcsChannel* cur = &mcs->channels[index]; diff --git a/libfreerdp/core/connection.c b/libfreerdp/core/connection.c index d09b2b892..a7005d1ae 100644 --- a/libfreerdp/core/connection.c +++ b/libfreerdp/core/connection.c @@ -758,8 +758,11 @@ static BOOL rdp_client_establish_keys(rdpRdp* rdp) crypto_rsa_public_encrypt(settings->ClientRandom, settings->ClientRandomLength, info, crypt_client_random, info->ModulusLength); /* send crypt client random to server */ - const size_t length = - RDP_PACKET_HEADER_MAX_LENGTH + RDP_SECURITY_HEADER_LENGTH + 4 + info->ModulusLength + 8; + const size_t length = RDP_PACKET_HEADER_MAX_LENGTH + RDP_SECURITY_HEADER_LENGTH + 4ULL + + info->ModulusLength + 8ULL; + if (length > UINT16_MAX) + return FALSE; + s = Stream_New(NULL, length); if (!s) diff --git a/libfreerdp/core/rdp.c b/libfreerdp/core/rdp.c index 17e6c0f69..1e1dd3d8c 100644 --- a/libfreerdp/core/rdp.c +++ b/libfreerdp/core/rdp.c @@ -161,9 +161,9 @@ const char* data_pdu_type_to_string(UINT8 type) } static BOOL rdp_read_flow_control_pdu(rdpRdp* rdp, wStream* s, UINT16* type, UINT16* channel_id); -static BOOL rdp_write_share_control_header(rdpRdp* rdp, wStream* s, UINT16 length, UINT16 type, +static BOOL rdp_write_share_control_header(rdpRdp* rdp, wStream* s, size_t length, UINT16 type, UINT16 channel_id); -static BOOL rdp_write_share_data_header(rdpRdp* rdp, wStream* s, UINT16 length, BYTE type, +static BOOL rdp_write_share_data_header(rdpRdp* rdp, wStream* s, size_t length, BYTE type, UINT32 share_id); /** @@ -301,11 +301,13 @@ BOOL rdp_read_share_control_header(rdpRdp* rdp, wStream* s, UINT16* tpktLength, return Stream_CheckAndLogRequiredLengthWLog(rdp->log, s, remLen); } -BOOL rdp_write_share_control_header(rdpRdp* rdp, wStream* s, UINT16 length, UINT16 type, +BOOL rdp_write_share_control_header(rdpRdp* rdp, wStream* s, size_t length, UINT16 type, UINT16 channel_id) { WINPR_ASSERT(s); WINPR_ASSERT(rdp); + if (length > UINT16_MAX) + return FALSE; if (length < RDP_PACKET_HEADER_MAX_LENGTH) return FALSE; @@ -339,13 +341,15 @@ BOOL rdp_read_share_data_header(rdpRdp* rdp, wStream* s, UINT16* length, BYTE* t return TRUE; } -BOOL rdp_write_share_data_header(rdpRdp* rdp, wStream* s, UINT16 length, BYTE type, UINT32 share_id) +BOOL rdp_write_share_data_header(rdpRdp* rdp, wStream* s, size_t length, BYTE type, UINT32 share_id) { const size_t headerLen = RDP_PACKET_HEADER_MAX_LENGTH + RDP_SHARE_CONTROL_HEADER_LENGTH + RDP_SHARE_DATA_HEADER_LENGTH; WINPR_ASSERT(s); WINPR_ASSERT(rdp); + if (length > UINT16_MAX) + return FALSE; if (length < headerLen) return FALSE; @@ -647,12 +651,14 @@ BOOL rdp_read_header(rdpRdp* rdp, wStream* s, UINT16* length, UINT16* channelId) * @return \b TRUE for success, \b FALSE otherwise */ -BOOL rdp_write_header(rdpRdp* rdp, wStream* s, UINT16 length, UINT16 channelId) +BOOL rdp_write_header(rdpRdp* rdp, wStream* s, size_t length, UINT16 channelId) { WINPR_ASSERT(rdp); WINPR_ASSERT(rdp->settings); WINPR_ASSERT(s); WINPR_ASSERT(length >= RDP_PACKET_HEADER_MAX_LENGTH); + if (length > UINT16_MAX) + return FALSE; DomainMCSPDU MCSPDU = (rdp->settings->ServerMode) ? DomainMCSPDU_SendDataIndication : DomainMCSPDU_SendDataRequest; @@ -687,12 +693,13 @@ BOOL rdp_write_header(rdpRdp* rdp, wStream* s, UINT16 length, UINT16 channelId) return TRUE; } -static BOOL rdp_security_stream_out(rdpRdp* rdp, wStream* s, int length, UINT32 sec_flags, +static BOOL rdp_security_stream_out(rdpRdp* rdp, wStream* s, size_t length, UINT32 sec_flags, UINT32* pad) { BOOL status = 0; WINPR_ASSERT(rdp); - WINPR_ASSERT(length >= 0); + if (length > UINT16_MAX) + return FALSE; sec_flags |= rdp->sec_flags; *pad = 0; @@ -715,7 +722,7 @@ static BOOL rdp_security_stream_out(rdpRdp* rdp, wStream* s, int length, UINT32 if (size > length) goto unlock; - length -= (int)size; + length -= size; Stream_Write_UINT16(s, 0x10); /* length */ Stream_Write_UINT8(s, 0x1); /* TSFIPS_VERSION 1*/ @@ -742,7 +749,10 @@ static BOOL rdp_security_stream_out(rdpRdp* rdp, wStream* s, int length, UINT32 else { const BYTE* data = Stream_PointerAs(s, const BYTE) + 8; - length = length - (data - Stream_Buffer(s)); + const size_t diff = Stream_GetPosition(s) + 8ULL; + if (diff > length) + goto unlock; + length -= diff; if (!Stream_CheckAndLogRequiredCapacityWLog(rdp->log, s, 8)) goto unlock; @@ -811,7 +821,6 @@ BOOL rdp_send(rdpRdp* rdp, wStream* s, UINT16 channel_id) { BOOL rc = FALSE; UINT32 pad = 0; - UINT16 length = 0; if (!s) return FALSE; @@ -819,7 +828,7 @@ BOOL rdp_send(rdpRdp* rdp, wStream* s, UINT16 channel_id) if (!rdp) goto fail; - length = Stream_GetPosition(s); + size_t length = Stream_GetPosition(s); Stream_SetPosition(s, 0); if (!rdp_write_header(rdp, s, length, channel_id)) goto fail; @@ -842,7 +851,6 @@ fail: BOOL rdp_send_pdu(rdpRdp* rdp, wStream* s, UINT16 type, UINT16 channel_id) { - UINT16 length = 0; UINT32 sec_bytes = 0; size_t sec_hold = 0; UINT32 pad = 0; @@ -850,7 +858,7 @@ BOOL rdp_send_pdu(rdpRdp* rdp, wStream* s, UINT16 type, UINT16 channel_id) if (!rdp || !s) return FALSE; - length = Stream_GetPosition(s); + size_t length = Stream_GetPosition(s); Stream_SetPosition(s, 0); if (!rdp_write_header(rdp, s, length, MCS_GLOBAL_CHANNEL_ID)) return FALSE; @@ -877,7 +885,6 @@ BOOL rdp_send_pdu(rdpRdp* rdp, wStream* s, UINT16 type, UINT16 channel_id) BOOL rdp_send_data_pdu(rdpRdp* rdp, wStream* s, BYTE type, UINT16 channel_id) { BOOL rc = FALSE; - size_t length = 0; UINT32 sec_bytes = 0; size_t sec_hold = 0; UINT32 pad = 0; @@ -888,7 +895,7 @@ BOOL rdp_send_data_pdu(rdpRdp* rdp, wStream* s, BYTE type, UINT16 channel_id) if (!rdp) goto fail; - length = Stream_GetPosition(s); + size_t length = Stream_GetPosition(s); Stream_SetPosition(s, 0); if (!rdp_write_header(rdp, s, length, MCS_GLOBAL_CHANNEL_ID)) goto fail; @@ -924,13 +931,12 @@ fail: BOOL rdp_send_message_channel_pdu(rdpRdp* rdp, wStream* s, UINT16 sec_flags) { BOOL rc = FALSE; - UINT16 length = 0; UINT32 pad = 0; WINPR_ASSERT(rdp); WINPR_ASSERT(s); - length = Stream_GetPosition(s); + size_t length = Stream_GetPosition(s); Stream_SetPosition(s, 0); if (!rdp_write_header(rdp, s, length, rdp->mcs->messageChannelId)) goto fail; diff --git a/libfreerdp/core/rdp.h b/libfreerdp/core/rdp.h index a4eaf47f3..7f9bb3b14 100644 --- a/libfreerdp/core/rdp.h +++ b/libfreerdp/core/rdp.h @@ -223,7 +223,7 @@ FREERDP_LOCAL wStream* rdp_send_stream_init(rdpRdp* rdp); FREERDP_LOCAL wStream* rdp_send_stream_pdu_init(rdpRdp* rdp); FREERDP_LOCAL BOOL rdp_read_header(rdpRdp* rdp, wStream* s, UINT16* length, UINT16* channel_id); -FREERDP_LOCAL BOOL rdp_write_header(rdpRdp* rdp, wStream* s, UINT16 length, UINT16 channel_id); +FREERDP_LOCAL BOOL rdp_write_header(rdpRdp* rdp, wStream* s, size_t length, UINT16 channel_id); FREERDP_LOCAL BOOL rdp_send_pdu(rdpRdp* rdp, wStream* s, UINT16 type, UINT16 channel_id); diff --git a/libfreerdp/core/tpkt.c b/libfreerdp/core/tpkt.c index 2e84c661b..4796da9af 100644 --- a/libfreerdp/core/tpkt.c +++ b/libfreerdp/core/tpkt.c @@ -160,7 +160,7 @@ BOOL tpkt_ensure_stream_consumed_(wStream* s, size_t length, const char* fkt) * @return \b TRUE for success, \b FALSE otherwise */ -BOOL tpkt_write_header(wStream* s, UINT16 length) +BOOL tpkt_write_header(wStream* s, size_t length) { if (!Stream_CheckAndLogRequiredCapacity(TAG, (s), 4)) return FALSE; diff --git a/libfreerdp/core/tpkt.h b/libfreerdp/core/tpkt.h index 9bb278198..a24058dcd 100644 --- a/libfreerdp/core/tpkt.h +++ b/libfreerdp/core/tpkt.h @@ -30,7 +30,7 @@ FREERDP_LOCAL int tpkt_verify_header(wStream* s); FREERDP_LOCAL BOOL tpkt_read_header(wStream* s, UINT16* length); -FREERDP_LOCAL BOOL tpkt_write_header(wStream* s, UINT16 length); +FREERDP_LOCAL BOOL tpkt_write_header(wStream* s, size_t length); #define tpkt_ensure_stream_consumed(s, length) tpkt_ensure_stream_consumed_((s), (length), __func__) FREERDP_LOCAL BOOL tpkt_ensure_stream_consumed_(wStream* s, size_t length, const char* fkt); diff --git a/libfreerdp/core/window.c b/libfreerdp/core/window.c index 7abe0c067..fe4ff67d1 100644 --- a/libfreerdp/core/window.c +++ b/libfreerdp/core/window.c @@ -929,7 +929,7 @@ static BOOL update_read_desktop_actively_monitored_order(wStream* s, WINDOW_ORDE monitored_desktop->windowIds = newid; /* windowIds */ - for (UINT32 i = 0; i < (int)monitored_desktop->numWindowIds; i++) + for (UINT32 i = 0; i < monitored_desktop->numWindowIds; i++) { Stream_Read_UINT32(s, monitored_desktop->windowIds[i]); }