Skip to content

Commit

Permalink
LibVNCClient: fix three possible heap buffer overflows
Browse files Browse the repository at this point in the history
An attacker could feed `0xffffffff`, causing a `malloc(0)` for the
buffers which are subsequently written to.

Closes #247
  • Loading branch information
bk138 committed Sep 29, 2018
1 parent 09f2f3f commit a83439b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions libvncclient/rfbproto.c
Expand Up @@ -433,7 +433,7 @@ rfbHandleAuthResult(rfbClient* client)
/* we have an error following */
if (!ReadFromRFBServer(client, (char *)&reasonLen, 4)) return FALSE;
reasonLen = rfbClientSwap32IfLE(reasonLen);
reason = malloc(reasonLen+1);
reason = malloc((uint64_t)reasonLen+1);
if (!ReadFromRFBServer(client, reason, reasonLen)) { free(reason); return FALSE; }
reason[reasonLen]=0;
rfbClientLog("VNC connection failed: %s\n",reason);
Expand Down Expand Up @@ -461,7 +461,7 @@ ReadReason(rfbClient* client)
/* we have an error following */
if (!ReadFromRFBServer(client, (char *)&reasonLen, 4)) return;
reasonLen = rfbClientSwap32IfLE(reasonLen);
reason = malloc(reasonLen+1);
reason = malloc((uint64_t)reasonLen+1);
if (!ReadFromRFBServer(client, reason, reasonLen)) { free(reason); return; }
reason[reasonLen]=0;
rfbClientLog("VNC connection failed: %s\n",reason);
Expand Down Expand Up @@ -2187,10 +2187,12 @@ HandleRFBServerMessage(rfbClient* client)

msg.sct.length = rfbClientSwap32IfLE(msg.sct.length);

buffer = malloc(msg.sct.length+1);
buffer = malloc((uint64_t)msg.sct.length+1);

if (!ReadFromRFBServer(client, buffer, msg.sct.length))
if (!ReadFromRFBServer(client, buffer, msg.sct.length)) {
free(buffer);
return FALSE;
}

buffer[msg.sct.length] = 0;

Expand Down

0 comments on commit a83439b

Please sign in to comment.