diff options
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; } |