aboutsummaryrefslogtreecommitdiffstats
path: root/unix/xserver/hw
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2023-03-18 13:53:26 +0100
committerPierre Ossman <ossman@cendio.se>2023-06-30 21:39:44 +0200
commitc061a78dc1f7242cfcaf42049d5248e4eed39ff4 (patch)
tree6126e1d9944e1cc3208514eb3369a8b7f3d45759 /unix/xserver/hw
parent19df176862ff0687cabc435056061a1b6cbe9ff2 (diff)
downloadtigervnc-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 'unix/xserver/hw')
-rw-r--r--unix/xserver/hw/vnc/RFBGlue.cc9
-rw-r--r--unix/xserver/hw/vnc/RFBGlue.h2
-rw-r--r--unix/xserver/hw/vnc/vncSelection.c5
3 files changed, 16 insertions, 0 deletions
diff --git a/unix/xserver/hw/vnc/RFBGlue.cc b/unix/xserver/hw/vnc/RFBGlue.cc
index 2fbc27ee..25431b65 100644
--- a/unix/xserver/hw/vnc/RFBGlue.cc
+++ b/unix/xserver/hw/vnc/RFBGlue.cc
@@ -248,3 +248,12 @@ char* vncUTF8ToLatin1(const char* src, size_t bytes)
return NULL;
}
}
+
+int vncIsValidUTF8(const char* str, size_t bytes)
+{
+ try {
+ return isValidUTF8(str, bytes);
+ } catch (...) {
+ return 0;
+ }
+}
diff --git a/unix/xserver/hw/vnc/RFBGlue.h b/unix/xserver/hw/vnc/RFBGlue.h
index d2b2e8aa..30c13bd2 100644
--- a/unix/xserver/hw/vnc/RFBGlue.h
+++ b/unix/xserver/hw/vnc/RFBGlue.h
@@ -53,6 +53,8 @@ char* vncConvertLF(const char* src, size_t bytes);
char* vncLatin1ToUTF8(const char* src, size_t bytes);
char* vncUTF8ToLatin1(const char* src, size_t bytes);
+int vncIsValidUTF8(const char* str, size_t bytes);
+
#ifdef __cplusplus
}
#endif
diff --git a/unix/xserver/hw/vnc/vncSelection.c b/unix/xserver/hw/vnc/vncSelection.c
index 1ed35149..f7f3c51d 100644
--- a/unix/xserver/hw/vnc/vncSelection.c
+++ b/unix/xserver/hw/vnc/vncSelection.c
@@ -611,6 +611,11 @@ static void vncHandleSelection(Atom selection, Atom target,
if (prop->type != xaUTF8_STRING)
return;
+ if (!vncIsValidUTF8(prop->data, prop->size)) {
+ LOG_ERROR("Invalid UTF-8 sequence in clipboard");
+ return;
+ }
+
filtered = vncConvertLF(prop->data, prop->size);
if (filtered == NULL)
return;