Skip to content

Commit 1c7fd8c

Browse files
committed
Fix potential multiplication overflows
1 parent a30177f commit 1c7fd8c

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

libvncclient/cursor.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ rfbBool HandleCursorShape(rfbClient* client,int xhot, int yhot, int width, int h
6363
if(client->rcSource)
6464
free(client->rcSource);
6565

66-
client->rcSource = malloc(width * height * bytesPerPixel);
66+
client->rcSource = malloc((size_t)width * height * bytesPerPixel);
6767
if (client->rcSource == NULL)
6868
return FALSE;
6969

@@ -146,7 +146,7 @@ rfbBool HandleCursorShape(rfbClient* client,int xhot, int yhot, int width, int h
146146
return FALSE;
147147
}
148148

149-
client->rcMask = malloc(width * height);
149+
client->rcMask = malloc((size_t)width * height);
150150
if (client->rcMask == NULL) {
151151
free(client->rcSource);
152152
client->rcSource = NULL;

libvncserver/cursor.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ void rfbMakeRichCursorFromXCursor(rfbScreenInfoPtr rfbScreen,rfbCursorPtr cursor
477477

478478
if(cursor->richSource && cursor->cleanupRichSource)
479479
free(cursor->richSource);
480-
cp=cursor->richSource=(unsigned char*)calloc(cursor->width*bpp,cursor->height);
480+
cp=cursor->richSource=(unsigned char*)calloc((size_t)cursor->width*bpp,cursor->height);
481481
if(!cp)
482482
return;
483483
cursor->cleanupRichSource=TRUE;
@@ -534,7 +534,7 @@ void rfbHideCursor(rfbClientPtr cl)
534534
for(j=0;j<y2;j++)
535535
memcpy(s->frameBuffer+(y1+j)*rowstride+x1*bpp,
536536
s->underCursorBuffer+j*x2*bpp,
537-
x2*bpp);
537+
(size_t)x2*bpp);
538538

539539
/* Copy to all scaled versions */
540540
rfbScaledScreenUpdate(s, x1, y1, x1+x2, y1+y2);

libvncserver/hextile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ sendHextiles##bpp(rfbClientPtr cl, int rx, int ry, int rw, int rh) {
179179
cl->scaledScreen->paddedWidthInBytes, w, h); \
180180
\
181181
memcpy(&cl->updateBuf[cl->ublen], (char *)clientPixelData, \
182-
w * h * (bpp/8)); \
182+
(size_t)w * h * (bpp/8)); \
183183
\
184184
cl->ublen += w * h * (bpp/8); \
185185
rfbStatRecordEncodingSentAdd(cl, rfbEncodingHextile, \

libvncserver/selbox.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ int rfbSelectBox(rfbScreenInfoPtr rfbScreen,rfbFontDataPtr font,
244244
selData.cancelX = selData.cancelBX+(k-j)/2;
245245
selData.okY = y2-border;
246246

247-
frameBufferBackup = (char*)malloc(bpp*(x2-x1)*(y2-y1));
247+
frameBufferBackup = (char*)malloc((size_t)bpp*(x2-x1)*(y2-y1));
248248
if (!frameBufferBackup)
249249
return(-1);
250250

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

276276
/* paint list and buttons */
277277
rfbFillRect(rfbScreen,x1,y1,x2,y2,colour);
@@ -286,7 +286,7 @@ int rfbSelectBox(rfbScreenInfoPtr rfbScreen,rfbFontDataPtr font,
286286
for(j=0;j<y2-y1;j++)
287287
memcpy(rfbScreen->frameBuffer+j*rfbScreen->paddedWidthInBytes+x1*bpp,
288288
frameBufferBackup+j*(x2-x1)*bpp,
289-
(x2-x1)*bpp);
289+
(size_t)(x2-x1)*bpp);
290290
free(frameBufferBackup);
291291
rfbMarkRectAsModified(rfbScreen,x1,y1,x2,y2);
292292
rfbScreen->screenData = screenDataBackup;

libvncserver/tight.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ SendIndexedRect(rfbClientPtr cl,
975975
entryLen = 4;
976976

977977
memcpy(&cl->updateBuf[cl->ublen], tightAfterBuf,
978-
paletteNumColors * entryLen);
978+
(size_t)paletteNumColors * entryLen);
979979
cl->ublen += paletteNumColors * entryLen;
980980
rfbStatRecordEncodingSentAdd(cl, cl->tightEncoding,
981981
3 + paletteNumColors * entryLen);
@@ -1617,7 +1617,7 @@ SendJpegRect(rfbClientPtr cl, int x, int y, int w, int h, int quality)
16171617
unsigned char *dst;
16181618
int inRed, inGreen, inBlue, i, j;
16191619

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

0 commit comments

Comments
 (0)