Skip to content

Commit

Permalink
Fix potential multiplication overflows (#504)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobydox authored Mar 5, 2022
1 parent a7671ad commit b0609e9
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions libvncclient/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ rfbBool HandleCursorShape(rfbClient* client,int xhot, int yhot, int width, int h
if(client->rcSource)
free(client->rcSource);

client->rcSource = malloc(width * height * bytesPerPixel);
client->rcSource = malloc((size_t)width * height * bytesPerPixel);
if (client->rcSource == NULL)
return FALSE;

Expand Down Expand Up @@ -146,7 +146,7 @@ rfbBool HandleCursorShape(rfbClient* client,int xhot, int yhot, int width, int h
return FALSE;
}

client->rcMask = malloc(width * height);
client->rcMask = malloc((size_t)width * height);
if (client->rcMask == NULL) {
free(client->rcSource);
client->rcSource = NULL;
Expand Down
4 changes: 2 additions & 2 deletions libvncserver/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ void rfbMakeRichCursorFromXCursor(rfbScreenInfoPtr rfbScreen,rfbCursorPtr cursor

if(cursor->richSource && cursor->cleanupRichSource)
free(cursor->richSource);
cp=cursor->richSource=(unsigned char*)calloc(cursor->width*bpp,cursor->height);
cp=cursor->richSource=(unsigned char*)calloc((size_t)cursor->width*bpp,cursor->height);
if(!cp)
return;
cursor->cleanupRichSource=TRUE;
Expand Down Expand Up @@ -534,7 +534,7 @@ void rfbHideCursor(rfbClientPtr cl)
for(j=0;j<y2;j++)
memcpy(s->frameBuffer+(y1+j)*rowstride+x1*bpp,
s->underCursorBuffer+j*x2*bpp,
x2*bpp);
(size_t)x2*bpp);

/* Copy to all scaled versions */
rfbScaledScreenUpdate(s, x1, y1, x1+x2, y1+y2);
Expand Down
2 changes: 1 addition & 1 deletion libvncserver/hextile.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ sendHextiles##bpp(rfbClientPtr cl, int rx, int ry, int rw, int rh) {
cl->scaledScreen->paddedWidthInBytes, w, h); \
\
memcpy(&cl->updateBuf[cl->ublen], (char *)clientPixelData, \
w * h * (bpp/8)); \
(size_t)w * h * (bpp/8)); \
\
cl->ublen += w * h * (bpp/8); \
rfbStatRecordEncodingSentAdd(cl, rfbEncodingHextile, \
Expand Down
6 changes: 3 additions & 3 deletions libvncserver/selbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ int rfbSelectBox(rfbScreenInfoPtr rfbScreen,rfbFontDataPtr font,
selData.cancelX = selData.cancelBX+(k-j)/2;
selData.okY = y2-border;

frameBufferBackup = (char*)malloc(bpp*(x2-x1)*(y2-y1));
frameBufferBackup = (char*)malloc((size_t)bpp*(x2-x1)*(y2-y1));
if (!frameBufferBackup)
return(-1);

Expand All @@ -271,7 +271,7 @@ int rfbSelectBox(rfbScreenInfoPtr rfbScreen,rfbFontDataPtr font,
for(j=0;j<y2-y1;j++)
memcpy(frameBufferBackup+j*(x2-x1)*bpp,
rfbScreen->frameBuffer+j*rfbScreen->paddedWidthInBytes+x1*bpp,
(x2-x1)*bpp);
(size_t)(x2-x1)*bpp);

/* paint list and buttons */
rfbFillRect(rfbScreen,x1,y1,x2,y2,colour);
Expand All @@ -286,7 +286,7 @@ int rfbSelectBox(rfbScreenInfoPtr rfbScreen,rfbFontDataPtr font,
for(j=0;j<y2-y1;j++)
memcpy(rfbScreen->frameBuffer+j*rfbScreen->paddedWidthInBytes+x1*bpp,
frameBufferBackup+j*(x2-x1)*bpp,
(x2-x1)*bpp);
(size_t)(x2-x1)*bpp);
free(frameBufferBackup);
rfbMarkRectAsModified(rfbScreen,x1,y1,x2,y2);
rfbScreen->screenData = screenDataBackup;
Expand Down
4 changes: 2 additions & 2 deletions libvncserver/tight.c
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ SendIndexedRect(rfbClientPtr cl,
entryLen = 4;

memcpy(&cl->updateBuf[cl->ublen], tightAfterBuf,
paletteNumColors * entryLen);
(size_t)paletteNumColors * entryLen);
cl->ublen += paletteNumColors * entryLen;
rfbStatRecordEncodingSentAdd(cl, cl->tightEncoding,
3 + paletteNumColors * entryLen);
Expand Down Expand Up @@ -1617,7 +1617,7 @@ SendJpegRect(rfbClientPtr cl, int x, int y, int w, int h, int quality)
unsigned char *dst;
int inRed, inGreen, inBlue, i, j;

if((tmpbuf = (unsigned char *)malloc(w * h * 3)) == NULL)
if((tmpbuf = (unsigned char *)malloc((size_t)w * h * 3)) == NULL)
rfbLog("Memory allocation failure!\n");
srcptr = (uint16_t *)&cl->scaledScreen->frameBuffer
[y * cl->scaledScreen->paddedWidthInBytes + x * ps];
Expand Down

0 comments on commit b0609e9

Please sign in to comment.