Skip to content

Commit 23e5cbe

Browse files
committed
libvncclient: fix pointer aliasing/alignment issue
Accessing byte-aligned data through uint32_t pointers can cause crashes on some platforms or reduce the performance. Therefore ensure a proper stack alignment.
1 parent d79d913 commit 23e5cbe

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Diff for: libvncclient/rfbproto.c

+7-4
Original file line numberDiff line numberDiff line change
@@ -1151,10 +1151,13 @@ rfbBool
11511151
SetFormatAndEncodings(rfbClient* client)
11521152
{
11531153
rfbSetPixelFormatMsg spf;
1154-
char buf[sz_rfbSetEncodingsMsg + MAX_ENCODINGS * 4];
1154+
union {
1155+
char bytes[sz_rfbSetEncodingsMsg + MAX_ENCODINGS*4];
1156+
rfbSetEncodingsMsg msg;
1157+
} buf;
11551158

1156-
rfbSetEncodingsMsg *se = (rfbSetEncodingsMsg *)buf;
1157-
uint32_t *encs = (uint32_t *)(&buf[sz_rfbSetEncodingsMsg]);
1159+
rfbSetEncodingsMsg *se = &buf.msg;
1160+
uint32_t *encs = (uint32_t *)(&buf.bytes[sz_rfbSetEncodingsMsg]);
11581161
int len = 0;
11591162
rfbBool requestCompressLevel = FALSE;
11601163
rfbBool requestQualityLevel = FALSE;
@@ -1354,7 +1357,7 @@ SetFormatAndEncodings(rfbClient* client)
13541357

13551358
se->nEncodings = rfbClientSwap16IfLE(se->nEncodings);
13561359

1357-
if (!WriteToRFBServer(client, buf, len)) return FALSE;
1360+
if (!WriteToRFBServer(client, buf.bytes, len)) return FALSE;
13581361

13591362
return TRUE;
13601363
}

0 commit comments

Comments
 (0)