From c5ba3fee85a7ecbbca1df5ffd46d32b92757bc2a Mon Sep 17 00:00:00 2001
From: Christian Beier <dontmind@freeshell.org>
Date: Sat, 29 Dec 2018 14:16:58 +0100
Subject: [PATCH] LibVNCClient: ignore server-sent cut text longer than 1MB

This is in line with how LibVNCServer does it
(28afb6c537dc82ba04d5f245b15ca7205c6dbb9c) and fixes part of #273.

[sunweaver] Port to tightvnc.

---
 libvncclient/rfbproto.c | 5 +++++
 1 file changed, 5 insertions(+)

--- a/vncviewer/rfbproto.c
+++ b/vncviewer/rfbproto.c
@@ -1214,6 +1214,11 @@
 
     msg.sct.length = Swap32IfLE(msg.sct.length);
 
+    if (msg.sct.length > 1<<20) {
+	    fprintf(stderr, "Ignoring too big cut text length sent by server: %u B > 1 MB\n", (unsigned int)msg.sct.length);
+	    return False;
+    }
+
     if (serverCutText)
       free(serverCutText);
 
