diff options
author | Pierre Ossman <ossman@cendio.se> | 2023-03-18 13:53:26 +0100 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2023-06-30 21:39:44 +0200 |
commit | c061a78dc1f7242cfcaf42049d5248e4eed39ff4 (patch) | |
tree | 6126e1d9944e1cc3208514eb3369a8b7f3d45759 /common/rfb/CMsgReader.cxx | |
parent | 19df176862ff0687cabc435056061a1b6cbe9ff2 (diff) | |
download | tigervnc-c061a78dc1f7242cfcaf42049d5248e4eed39ff4.tar.gz tigervnc-c061a78dc1f7242cfcaf42049d5248e4eed39ff4.zip |
Clean up string encoding handling
We should handle this in the low-level protocol code as much as possible
to avoid mistakes. This way the rest of the code can assume that strings
are always UTF-8 with \n line endings.
Diffstat (limited to 'common/rfb/CMsgReader.cxx')
-rw-r--r-- | common/rfb/CMsgReader.cxx | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/common/rfb/CMsgReader.cxx b/common/rfb/CMsgReader.cxx index c0a96690..006645df 100644 --- a/common/rfb/CMsgReader.cxx +++ b/common/rfb/CMsgReader.cxx @@ -76,7 +76,12 @@ bool CMsgReader::readServerInit() std::vector<char> name(len + 1); is->readBytes((uint8_t*)name.data(), len); name[len] = '\0'; - handler->serverInit(width, height, pf, name.data()); + + if (isValidUTF8(name.data())) + handler->serverInit(width, height, pf, name.data()); + else + handler->serverInit(width, height, pf, + latin1ToUTF8(name.data()).c_str()); return true; } @@ -275,9 +280,13 @@ bool CMsgReader::readServerCutText() vlog.error("cut text too long (%d bytes) - ignoring",len); return true; } + std::vector<char> ca(len); is->readBytes((uint8_t*)ca.data(), len); - std::string filtered(convertLF(ca.data(), len)); + + std::string utf8(latin1ToUTF8(ca.data(), ca.size())); + std::string filtered(convertLF(utf8.data(), utf8.size())); + handler->serverCutText(filtered.c_str()); return true; @@ -768,10 +777,16 @@ bool CMsgReader::readSetDesktopName(int x, int y, int w, int h) if (x || y || w || h) { vlog.error("Ignoring DesktopName rect with non-zero position/size"); - } else { - handler->setName(name.data()); + return true; } + if (!isValidUTF8(name.data())) { + vlog.error("Ignoring DesktopName rect with invalid UTF-8 sequence"); + return true; + } + + handler->setName(name.data()); + return true; } |