From a332db7cf53119bc134fb66e6efb61c6f504cc44 Mon Sep 17 00:00:00 2001 From: Joan Torres Date: Mon, 31 Jul 2023 19:01:31 +0200 Subject: [PATCH] [libfreerdp] fix endianness issues There were some fields sent without considering endianness, making the clients fail when parsing those fields. Use Data_Write_XXX functions so the endiannes won't affect the byte order and the clients will read properly the fields. --- libfreerdp/codec/xcrush.c | 14 +++++++------- libfreerdp/core/server.c | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/libfreerdp/codec/xcrush.c b/libfreerdp/codec/xcrush.c index 90e2f91d6..1dd8a12d7 100644 --- a/libfreerdp/codec/xcrush.c +++ b/libfreerdp/codec/xcrush.c @@ -694,7 +694,7 @@ static int xcrush_generate_output(XCRUSH_CONTEXT* xcrush, BYTE* OutputBuffer, UI if (&OutputBuffer[2] >= &OutputBuffer[OutputSize]) return -6001; /* error */ - *((UINT16*)OutputBuffer) = MatchCount; + Data_Write_UINT16(OutputBuffer, MatchCount); MatchDetails = (RDP61_MATCH_DETAILS*)&OutputBuffer[2]; Literals = (BYTE*)&MatchDetails[MatchCount]; @@ -703,12 +703,12 @@ static int xcrush_generate_output(XCRUSH_CONTEXT* xcrush, BYTE* OutputBuffer, UI for (MatchIndex = 0; MatchIndex < MatchCount; MatchIndex++) { - MatchDetails[MatchIndex].MatchLength = - (UINT16)(xcrush->OptimizedMatches[MatchIndex].MatchLength); - MatchDetails[MatchIndex].MatchOutputOffset = - (UINT16)(xcrush->OptimizedMatches[MatchIndex].MatchOffset - HistoryOffset); - MatchDetails[MatchIndex].MatchHistoryOffset = - xcrush->OptimizedMatches[MatchIndex].ChunkOffset; + Data_Write_UINT16(&MatchDetails[MatchIndex].MatchLength, + xcrush->OptimizedMatches[MatchIndex].MatchLength); + Data_Write_UINT16(&MatchDetails[MatchIndex].MatchOutputOffset, + xcrush->OptimizedMatches[MatchIndex].MatchOffset - HistoryOffset); + Data_Write_UINT32(&MatchDetails[MatchIndex].MatchHistoryOffset, + xcrush->OptimizedMatches[MatchIndex].ChunkOffset); } CurrentOffset = HistoryOffset; diff --git a/libfreerdp/core/server.c b/libfreerdp/core/server.c index 2f4442272..4828e9bd4 100644 --- a/libfreerdp/core/server.c +++ b/libfreerdp/core/server.c @@ -574,7 +574,7 @@ BOOL WTSVirtualChannelManagerOpen(HANDLE hServer) { ULONG written; vcm->drdynvc_channel = channel; - dynvc_caps = 0x00010050; /* DYNVC_CAPS_VERSION1 (4 bytes) */ + Data_Write_UINT32(&dynvc_caps, 0x00010050); /* DYNVC_CAPS_VERSION1 (4 bytes) */ if (!WTSVirtualChannelWrite(channel, (PCHAR)&dynvc_caps, sizeof(dynvc_caps), &written)) return FALSE;