From aa787069832c7b32b90a23a4d5063f2d72f07ba3 Mon Sep 17 00:00:00 2001
From: Joel Martin <github@martintribe.org>
Date: Thu, 23 Sep 2010 09:17:09 -0500
Subject: [PATCH] rfb.js: wait for SecurityResult failure reason bytes.

Yet another weird VNC server behavior: sending a failure and length
before the reason message. To calculated the length, the reason string
is already available, why not just send everything as one packet. Oh
well.
---
 include/rfb.js | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/include/rfb.js b/include/rfb.js
index 365c513..d0f59b8 100644
--- a/include/rfb.js
+++ b/include/rfb.js
@@ -797,6 +797,11 @@ init_msg = function() {
             case 1:  // failed
                 if (rfb_version >= 3.8) {
                     reason_len = rQshift32();
+                    if (rQlen() < reason_len) {
+                        Util.Debug("   waiting for SecurityResult reason bytes");
+                        rQi -= 8; // Unshift the status and length
+                        return;
+                    }
                     reason = rQshiftStr(reason_len);
                     updateState('failed', reason);
                 } else {
-- 
2.18.1