From 6b555f1f746781e05348cdc9f1c7901dacc0114a Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 27 Oct 2022 16:03:22 +0200 Subject: [PATCH] Mask unsupported clipboard characters Add a more explicit '?' for characters that the clipboard cannot handle, instead of getting random junk. --- core/rfb.js | 10 ++++++++-- tests/test.rfb.js | 8 ++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/core/rfb.js b/core/rfb.js index e6647eff..707de0ff 100644 --- a/core/rfb.js +++ b/core/rfb.js @@ -492,8 +492,14 @@ export default class RFB extends EventTargetMixin { } else { let data = new Uint8Array(text.length); for (let i = 0; i < text.length; i++) { - // FIXME: text can have values outside of Latin1/Uint8 - data[i] = text.charCodeAt(i); + let code = text.charCodeAt(i); + + /* Only ISO 8859-1 is supported */ + if (code > 0xff) { + code = 0x3f; // '?' + } + + data[i] = code; } RFB.messages.clientCutText(this._sock, data); diff --git a/tests/test.rfb.js b/tests/test.rfb.js index 432bcba9..eb703860 100644 --- a/tests/test.rfb.js +++ b/tests/test.rfb.js @@ -433,6 +433,14 @@ describe('Remote Frame Buffer Protocol Client', function () { new Uint8Array([97, 98, 99])); }); + it('should mask unsupported characters', function () { + client.clipboardPasteFrom('abc€'); + + expect(RFB.messages.clientCutText).to.have.been.calledOnce; + expect(RFB.messages.clientCutText).to.have.been.calledWith(client._sock, + new Uint8Array([97, 98, 99, 63])); + }); + it('should send an notify if extended clipboard is supported by server', function () { // Send our capabilities let data = [3, 0, 0, 0];