aboutsummaryrefslogtreecommitdiffstats
path: root/common/rfb/util.cxx
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2023-03-18 14:59:27 +0100
committerPierre Ossman <ossman@cendio.se>2023-06-30 21:39:52 +0200
commit94d6a693eac3401c50723ccc75aa11fc7017782d (patch)
treed5a40fe882f2a9d316d0a12b39ec270257543b50 /common/rfb/util.cxx
parentc061a78dc1f7242cfcaf42049d5248e4eed39ff4 (diff)
downloadtigervnc-94d6a693eac3401c50723ccc75aa11fc7017782d.tar.gz
tigervnc-94d6a693eac3401c50723ccc75aa11fc7017782d.zip
Don't allow surrugate code points in UTF-8
These are not valid outside of UTF-16 so seeing them in a UTF-8 sequence means that something is wrong with that sequence. Best to filter them out rather than letting them propagate and have unknown effects.
Diffstat (limited to 'common/rfb/util.cxx')
-rw-r--r--common/rfb/util.cxx6
1 files changed, 6 insertions, 0 deletions
diff --git a/common/rfb/util.cxx b/common/rfb/util.cxx
index a3f16443..d1a8cc33 100644
--- a/common/rfb/util.cxx
+++ b/common/rfb/util.cxx
@@ -266,6 +266,8 @@ namespace rfb {
*dst++ = 0x80 | (src & 0x3f);
*dst++ = '\0';
return 2;
+ } else if ((src >= 0xd800) && (src < 0xe000)) {
+ return ucs4ToUTF8(0xfffd, dst);
} else if (src < 0x10000) {
*dst++ = 0xe0 | (src >> 12);
*dst++ = 0x80 | ((src >> 6) & 0x3f);
@@ -334,6 +336,10 @@ namespace rfb {
max--;
}
+ // UTF-16 surrogate code point?
+ if ((*dst >= 0xd800) && (*dst < 0xe000))
+ *dst = 0xfffd;
+
return consumed;
}