From f55a8fbfc580583b15370e83d3fd84e6c3c187c3 Mon Sep 17 00:00:00 2001 From: matt335672 <30179339+matt335672@users.noreply.github.com> Date: Fri, 30 Jul 2021 15:20:10 +0100 Subject: [PATCH] Cater for RFB clip size of zero bytes --- vnc/vnc_clip.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/vnc/vnc_clip.c b/vnc/vnc_clip.c index f079dbc6..1cfb1d06 100644 --- a/vnc/vnc_clip.c +++ b/vnc/vnc_clip.c @@ -1003,21 +1003,34 @@ vnc_clip_process_rfb_data(struct vnc *v) vc->rfb_clip_s = 0; make_stream(vc->rfb_clip_s); - if (size >= 0) + if (size < 0) { - init_stream(vc->rfb_clip_s, size); - } - if (vc->rfb_clip_s->data == NULL) - { - LOG(LOG_LEVEL_ERROR, - "Memory exhausted allocating %d bytes for RFB clip data", - size); + /* This shouldn't happen - see Extended Clipboard + * Pseudo-Encoding */ + LOG(LOG_LEVEL_ERROR, "Unexpected size %d for RFB data", size); rv = 1; } + else if (size == 0) + { + LOG(LOG_LEVEL_DEBUG, "RFB clip data cleared by VNC server"); + } else { - LOG(LOG_LEVEL_DEBUG, "Reading %d clip bytes from RFB", size); - rv = trans_force_read_s(v->trans, vc->rfb_clip_s, size); + init_stream(vc->rfb_clip_s, size); + if (vc->rfb_clip_s->data == NULL) + { + LOG(LOG_LEVEL_ERROR, + "Memory exhausted allocating %d bytes" + " for RFB clip data", + size); + rv = 1; + } + else + { + LOG(LOG_LEVEL_DEBUG, "Reading %d clip bytes from RFB", + size); + rv = trans_force_read_s(v->trans, vc->rfb_clip_s, size); + } } /* Consider telling the RDP client about the update only if we've