Skip to content

pointer aliasing/alignment issue in rfbSendSetColourMapEntries() #668

@ReBeating

Description

@ReBeating

Description

The function rfbSendSetColourMapEntries contains a pointer aliasing and memory alignment issue. This issue may lead to crashes or performance degradation on certain platforms, such as those requiring strict memory alignment (e.g., ARM architectures).

Location

File Path: src/libvncserver/rfbserver.c
Function Name: rfbSendSetColourMapEntries
Code Snippet:

char buf[sz_rfbSetColourMapEntriesMsg + 256 * 3 * 2];
char *wbuf = buf;
rfbSetColourMapEntriesMsg *scme;
uint16_t *rgb;

if (nColours > 256) {
    wbuf = (char *) malloc(sz_rfbSetColourMapEntriesMsg + nColours * 3 * 2);
}

scme = (rfbSetColourMapEntriesMsg *)wbuf;
rgb = (uint16_t *)(&wbuf[sz_rfbSetColourMapEntriesMsg]);

Impact

Pointer Aliasing Issue:
The code uses a char array and casts it to rfbSetColourMapEntriesMsg and uint16_t pointers. This may result in unaligned memory access.

Fix

Referencing the patch file commit.patch, the issue can be resolved by:

  1. Using a union to replace the char array and avoid unsafe typecasting.
  2. Ensuring proper memory alignment for all accesses.

Ref

This is similar to CVE-2020-14400.
Link: 53073c8

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions