aboutsummaryrefslogtreecommitdiffstats
path: root/common/rfb
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2019-05-02 12:32:03 +0200
committerPierre Ossman <ossman@cendio.se>2019-07-01 10:48:21 +0200
commit66f1db543b425f6fe64d437477e6f78924ec57be (patch)
tree196c5e5fd095f6690da363d05be306ec877c13b0 /common/rfb
parent546b2ad80a68e80a737aade06f0685cccb5e9716 (diff)
downloadtigervnc-66f1db543b425f6fe64d437477e6f78924ec57be.tar.gz
tigervnc-66f1db543b425f6fe64d437477e6f78924ec57be.zip
Clean up internal clipboard handling
We now filter incoming data, which means we can start assuming the clipboard data is always null terminated. This allows us to clean up a lot of the internal handling.
Diffstat (limited to 'common/rfb')
-rw-r--r--common/rfb/CMsgHandler.h2
-rw-r--r--common/rfb/CMsgReader.cxx2
-rw-r--r--common/rfb/CMsgWriter.cxx7
-rw-r--r--common/rfb/CMsgWriter.h2
-rw-r--r--common/rfb/InputHandler.h3
-rw-r--r--common/rfb/SMsgReader.cxx2
-rw-r--r--common/rfb/SMsgWriter.cxx7
-rw-r--r--common/rfb/SMsgWriter.h2
-rw-r--r--common/rfb/VNCSConnectionST.cxx8
-rw-r--r--common/rfb/VNCSConnectionST.h4
-rw-r--r--common/rfb/VNCServer.h2
-rw-r--r--common/rfb/VNCServerST.cxx10
-rw-r--r--common/rfb/VNCServerST.h4
13 files changed, 30 insertions, 25 deletions
diff --git a/common/rfb/CMsgHandler.h b/common/rfb/CMsgHandler.h
index effdaabf..1581f792 100644
--- a/common/rfb/CMsgHandler.h
+++ b/common/rfb/CMsgHandler.h
@@ -70,7 +70,7 @@ namespace rfb {
virtual void setColourMapEntries(int firstColour, int nColours,
rdr::U16* rgbs) = 0;
virtual void bell() = 0;
- virtual void serverCutText(const char* str, rdr::U32 len) = 0;
+ virtual void serverCutText(const char* str) = 0;
virtual void setLEDState(unsigned int state);
diff --git a/common/rfb/CMsgReader.cxx b/common/rfb/CMsgReader.cxx
index a928eb15..86288ad9 100644
--- a/common/rfb/CMsgReader.cxx
+++ b/common/rfb/CMsgReader.cxx
@@ -160,7 +160,7 @@ void CMsgReader::readServerCutText()
CharArray ca(len);
is->readBytes(ca.buf, len);
CharArray filtered(convertLF(ca.buf, len));
- handler->serverCutText(filtered.buf, strlen(filtered.buf));
+ handler->serverCutText(filtered.buf);
}
void CMsgReader::readFence()
diff --git a/common/rfb/CMsgWriter.cxx b/common/rfb/CMsgWriter.cxx
index fed0bd27..f1fa58dd 100644
--- a/common/rfb/CMsgWriter.cxx
+++ b/common/rfb/CMsgWriter.cxx
@@ -179,11 +179,14 @@ void CMsgWriter::writePointerEvent(const Point& pos, int buttonMask)
}
-void CMsgWriter::writeClientCutText(const char* str, rdr::U32 len)
+void CMsgWriter::writeClientCutText(const char* str)
{
- if (memchr(str, '\r', len) != NULL)
+ size_t len;
+
+ if (strchr(str, '\r') != NULL)
throw Exception("Invalid carriage return in clipboard data");
+ len = strlen(str);
startMsg(msgTypeClientCutText);
os->pad(3);
os->writeU32(len);
diff --git a/common/rfb/CMsgWriter.h b/common/rfb/CMsgWriter.h
index 4d533d42..d3ac19c9 100644
--- a/common/rfb/CMsgWriter.h
+++ b/common/rfb/CMsgWriter.h
@@ -55,7 +55,7 @@ namespace rfb {
void writeKeyEvent(rdr::U32 keysym, rdr::U32 keycode, bool down);
void writePointerEvent(const Point& pos, int buttonMask);
- void writeClientCutText(const char* str, rdr::U32 len);
+ void writeClientCutText(const char* str);
protected:
void startMsg(int type);
diff --git a/common/rfb/InputHandler.h b/common/rfb/InputHandler.h
index 6c072849..b91f0e42 100644
--- a/common/rfb/InputHandler.h
+++ b/common/rfb/InputHandler.h
@@ -37,8 +37,7 @@ namespace rfb {
bool __unused_attr down) { }
virtual void pointerEvent(const Point& __unused_attr pos,
int __unused_attr buttonMask) { }
- virtual void clientCutText(const char* __unused_attr str,
- int __unused_attr len) { }
+ virtual void clientCutText(const char* __unused_attr str) { }
};
}
diff --git a/common/rfb/SMsgReader.cxx b/common/rfb/SMsgReader.cxx
index 0c0e8b26..5efbfe2b 100644
--- a/common/rfb/SMsgReader.cxx
+++ b/common/rfb/SMsgReader.cxx
@@ -215,7 +215,7 @@ void SMsgReader::readClientCutText()
CharArray ca(len);
is->readBytes(ca.buf, len);
CharArray filtered(convertLF(ca.buf, len));
- handler->clientCutText(filtered.buf, strlen(filtered.buf));
+ handler->clientCutText(filtered.buf);
}
void SMsgReader::readQEMUMessage()
diff --git a/common/rfb/SMsgWriter.cxx b/common/rfb/SMsgWriter.cxx
index f0748ff2..3d5a64ca 100644
--- a/common/rfb/SMsgWriter.cxx
+++ b/common/rfb/SMsgWriter.cxx
@@ -78,11 +78,14 @@ void SMsgWriter::writeBell()
endMsg();
}
-void SMsgWriter::writeServerCutText(const char* str, int len)
+void SMsgWriter::writeServerCutText(const char* str)
{
- if (memchr(str, '\r', len) != NULL)
+ size_t len;
+
+ if (strchr(str, '\r') != NULL)
throw Exception("Invalid carriage return in clipboard data");
+ len = strlen(str);
startMsg(msgTypeServerCutText);
os->pad(3);
os->writeU32(len);
diff --git a/common/rfb/SMsgWriter.h b/common/rfb/SMsgWriter.h
index 4f4c9cc0..8cf2ae77 100644
--- a/common/rfb/SMsgWriter.h
+++ b/common/rfb/SMsgWriter.h
@@ -56,7 +56,7 @@ namespace rfb {
// writeBell() and writeServerCutText() do the obvious thing.
void writeBell();
- void writeServerCutText(const char* str, int len);
+ void writeServerCutText(const char* str);
// writeFence() sends a new fence request or response to the client.
void writeFence(rdr::U32 flags, unsigned len, const char data[]);
diff --git a/common/rfb/VNCSConnectionST.cxx b/common/rfb/VNCSConnectionST.cxx
index fe00dab6..002ae925 100644
--- a/common/rfb/VNCSConnectionST.cxx
+++ b/common/rfb/VNCSConnectionST.cxx
@@ -282,13 +282,13 @@ void VNCSConnectionST::bellOrClose()
}
}
-void VNCSConnectionST::serverCutTextOrClose(const char *str, int len)
+void VNCSConnectionST::serverCutTextOrClose(const char *str)
{
try {
if (!accessCheck(AccessCutText)) return;
if (!rfb::Server::sendCutText) return;
if (state() == RFBSTATE_NORMAL)
- writer()->writeServerCutText(str, len);
+ writer()->writeServerCutText(str);
} catch(rdr::Exception& e) {
close(e.str());
}
@@ -596,11 +596,11 @@ void VNCSConnectionST::keyEvent(rdr::U32 keysym, rdr::U32 keycode, bool down) {
server->keyEvent(keysym, keycode, down);
}
-void VNCSConnectionST::clientCutText(const char* str, int len)
+void VNCSConnectionST::clientCutText(const char* str)
{
if (!accessCheck(AccessCutText)) return;
if (!rfb::Server::acceptCutText) return;
- server->clientCutText(str, len);
+ server->clientCutText(str);
}
void VNCSConnectionST::framebufferUpdateRequest(const Rect& r,bool incremental)
diff --git a/common/rfb/VNCSConnectionST.h b/common/rfb/VNCSConnectionST.h
index a9a8d3a4..54266e3c 100644
--- a/common/rfb/VNCSConnectionST.h
+++ b/common/rfb/VNCSConnectionST.h
@@ -72,7 +72,7 @@ namespace rfb {
void screenLayoutChangeOrClose(rdr::U16 reason);
void setCursorOrClose();
void bellOrClose();
- void serverCutTextOrClose(const char *str, int len);
+ void serverCutTextOrClose(const char *str);
void setDesktopNameOrClose(const char *name);
void setLEDStateOrClose(unsigned int state);
void approveConnectionOrClose(bool accept, const char* reason);
@@ -115,7 +115,7 @@ namespace rfb {
virtual void setPixelFormat(const PixelFormat& pf);
virtual void pointerEvent(const Point& pos, int buttonMask);
virtual void keyEvent(rdr::U32 keysym, rdr::U32 keycode, bool down);
- virtual void clientCutText(const char* str, int len);
+ virtual void clientCutText(const char* str);
virtual void framebufferUpdateRequest(const Rect& r, bool incremental);
virtual void setDesktopSize(int fb_width, int fb_height,
const ScreenSet& layout);
diff --git a/common/rfb/VNCServer.h b/common/rfb/VNCServer.h
index 298326f5..5398e9fd 100644
--- a/common/rfb/VNCServer.h
+++ b/common/rfb/VNCServer.h
@@ -57,7 +57,7 @@ namespace rfb {
// serverCutText() tells the server that the cut text has changed. This
// will normally be sent to all clients.
- virtual void serverCutText(const char* str, int len) = 0;
+ virtual void serverCutText(const char* str) = 0;
// bell() tells the server that it should make all clients make a bell sound.
virtual void bell() = 0;
diff --git a/common/rfb/VNCServerST.cxx b/common/rfb/VNCServerST.cxx
index 7820aef5..21af0dac 100644
--- a/common/rfb/VNCServerST.cxx
+++ b/common/rfb/VNCServerST.cxx
@@ -340,14 +340,14 @@ void VNCServerST::bell()
}
}
-void VNCServerST::serverCutText(const char* str, int len)
+void VNCServerST::serverCutText(const char* str)
{
- if (memchr(str, '\r', len) != NULL)
+ if (strchr(str, '\r') != NULL)
throw Exception("Invalid carriage return in clipboard data");
std::list<VNCSConnectionST*>::iterator ci, ci_next;
for (ci = clients.begin(); ci != clients.end(); ci = ci_next) {
ci_next = ci; ci_next++;
- (*ci)->serverCutTextOrClose(str, len);
+ (*ci)->serverCutTextOrClose(str);
}
}
@@ -461,9 +461,9 @@ void VNCServerST::pointerEvent(VNCSConnectionST* client,
desktop->pointerEvent(pos, buttonMask);
}
-void VNCServerST::clientCutText(const char* str, int len)
+void VNCServerST::clientCutText(const char* str)
{
- desktop->clientCutText(str, len);
+ desktop->clientCutText(str);
}
unsigned int VNCServerST::setDesktopSize(VNCSConnectionST* requester,
diff --git a/common/rfb/VNCServerST.h b/common/rfb/VNCServerST.h
index 43a3bb95..5231977d 100644
--- a/common/rfb/VNCServerST.h
+++ b/common/rfb/VNCServerST.h
@@ -85,7 +85,7 @@ namespace rfb {
virtual void setPixelBuffer(PixelBuffer* pb);
virtual void setScreenLayout(const ScreenSet& layout);
virtual const PixelBuffer* getPixelBuffer() const { return pb; }
- virtual void serverCutText(const char* str, int len);
+ virtual void serverCutText(const char* str);
virtual void approveConnection(network::Socket* sock, bool accept,
const char* reason);
@@ -115,7 +115,7 @@ namespace rfb {
// Event handlers
void keyEvent(rdr::U32 keysym, rdr::U32 keycode, bool down);
void pointerEvent(VNCSConnectionST* client, const Point& pos, int buttonMask);
- void clientCutText(const char* str, int len);
+ void clientCutText(const char* str);
unsigned int setDesktopSize(VNCSConnectionST* requester,
int fb_width, int fb_height,