From 6037a9074d52b1963c97cb28ea1096c7c14cbf28 Mon Sep 17 00:00:00 2001 From: Nicolas Ruff Date: Mon, 18 Aug 2014 15:16:16 +0200 Subject: Check malloc() return value on client->server ClientCutText message. Client can send up to 2**32-1 bytes of text, and such a large allocation is likely to fail in case of high memory pressure. This would in a server crash (write at address 0). --- libvncserver/rfbserver.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libvncserver/rfbserver.c b/libvncserver/rfbserver.c index 5f3b31d..7e43fe3 100644 --- a/libvncserver/rfbserver.c +++ b/libvncserver/rfbserver.c @@ -2461,6 +2461,11 @@ rfbProcessClientNormalMessage(rfbClientPtr cl) msg.cct.length = Swap32IfLE(msg.cct.length); str = (char *)malloc(msg.cct.length); + if (str == NULL) { + rfbLogPerror("rfbProcessClientNormalMessage: not enough memory"); + rfbCloseClient(cl); + return; + } if ((n = rfbReadExact(cl, str, msg.cct.length)) <= 0) { if (n != 0) -- cgit v1.1 From 05a9bd41a8ec0a9d580a8f420f41718bdd235446 Mon Sep 17 00:00:00 2001 From: Nicolas Ruff Date: Mon, 18 Aug 2014 15:22:48 +0200 Subject: Do not accept a scaling factor of zero on PalmVNCSetScaleFactor and SetScale client->server messages. This would cause a division by zero and crash the server. --- libvncserver/rfbserver.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libvncserver/rfbserver.c b/libvncserver/rfbserver.c index 7e43fe3..df7d74c 100644 --- a/libvncserver/rfbserver.c +++ b/libvncserver/rfbserver.c @@ -2491,6 +2491,13 @@ rfbProcessClientNormalMessage(rfbClientPtr cl) rfbCloseClient(cl); return; } + + if (msg.ssc.scale == 0) { + rfbLogPerror("rfbProcessClientNormalMessage: will not accept a scale factor of zero"); + rfbCloseClient(cl); + return; + } + rfbStatRecordMessageRcvd(cl, msg.type, sz_rfbSetScaleMsg, sz_rfbSetScaleMsg); rfbLog("rfbSetScale(%d)\n", msg.ssc.scale); rfbScalingSetup(cl,cl->screen->width/msg.ssc.scale, cl->screen->height/msg.ssc.scale); @@ -2507,6 +2514,13 @@ rfbProcessClientNormalMessage(rfbClientPtr cl) rfbCloseClient(cl); return; } + + if (msg.ssc.scale == 0) { + rfbLogPerror("rfbProcessClientNormalMessage: will not accept a scale factor of zero"); + rfbCloseClient(cl); + return; + } + rfbStatRecordMessageRcvd(cl, msg.type, sz_rfbSetScaleMsg, sz_rfbSetScaleMsg); rfbLog("rfbSetScale(%d)\n", msg.ssc.scale); rfbScalingSetup(cl,cl->screen->width/msg.ssc.scale, cl->screen->height/msg.ssc.scale); -- cgit v1.1