From fedee2582a92ffbbf92547bcb08fed296a5635cf Mon Sep 17 00:00:00 2001 From: Axel Svensson Date: Fri, 7 Aug 2026 00:28:14 +0200 Subject: [PATCH] Fix ucs2keysym() to reject surrogate and private use code points --- vncviewer/keysym2ucs.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/vncviewer/keysym2ucs.c b/vncviewer/keysym2ucs.c index 6607e3065c..c2dc05f6b0 100644 --- a/vncviewer/keysym2ucs.c +++ b/vncviewer/keysym2ucs.c @@ -167,8 +167,18 @@ unsigned ucs2keysym(unsigned ucs) if (keysym != NoSymbol) return keysym; - /* us the directly encoded 24-bit UCS character */ - if ((ucs & 0xff000000) == 0) + /* surrogates? */ + if (0xd800 <= ucs && ucs <= 0xdfff) + return NoSymbol; + + /* private use? */ + if ((0xe000 <= ucs && ucs <= 0xf8ff) || + (0x0f0000 <= ucs && ucs <= 0x0ffffd) || + (0x100000 <= ucs && ucs <= 0x10fffd)) + return NoSymbol; + + /* ucs is a directly encoded 21-bit Unicode character */ + if (ucs <= 0x10ffff) return ucs | 0x01000000; /* no matching keysym value found */