1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
The RDP file buffers contain little endian UTF-16, but all the wcs* and
UTF conversion functions use the WCHAR type and assume native endian.
Convert the buffer to little endian on big endian machines.
--- a/client/common/file.c
+++ b/client/common/file.c
@@ -42,6 +42,18 @@
#include <winpr/crt.h>
+#if defined(WIN32) || defined(WIN64)
+ #ifndef __LITTLE_ENDIAN
+ #define __LITTLE_ENDIAN 1234
+ #define __BIG_ENDIAN 4321
+ #endif
+ #ifndef __BYTE_ORDER
+ #define __BYTE_ORDER __LITTLE_ENDIAN
+ #endif
+#else
+ #include <endian.h>
+#endif
+
#define DEBUG_CLIENT_FILE 1
static BYTE BOM_UTF16_LE[2] = { 0xFF, 0xFE };
@@ -364,7 +376,8 @@
BOOL freerdp_client_parse_rdp_file_buffer_unicode(rdpFile* file, BYTE* buffer, size_t size)
{
- int length;
+ int i, length;
+ BYTE* bufferne;
WCHAR* line;
WCHAR* type;
WCHAR* context;
@@ -372,7 +385,19 @@
WCHAR *beg, *end;
WCHAR *name, *value;
- line = wcstok_s((WCHAR*) buffer, CR_LF_STR_W, &context);
+#if __BYTE_ORDER == __BIG_ENDIAN
+ /* Convert the buffer from little endian to native endian */
+ bufferne = (BYTE*) malloc(size);
+ for (i = 0; i < size / 2; i++)
+ {
+ bufferne[i*2] = buffer[i*2 + 1];
+ bufferne[i*2 + 1] = buffer[i*2];
+ }
+#else
+ bufferne = buffer;
+#endif
+
+ line = wcstok_s((WCHAR*) bufferne, CR_LF_STR_W, &context);
while (line != NULL)
{
@@ -425,6 +450,10 @@
line = wcstok_s(NULL, CR_LF_STR_W, &context);
}
+#if __BYTE_ORDER == __BIG_ENDIAN
+ free(bufferne);
+#endif
+
return TRUE;
}
|