Closed layercak3 closed 3 weeks ago
I didn't see any memory leaks, but I was able to sometimes trigger 'Invalid read of size 8' in wayvnc with both an unpatched and patched neatvnc (so the issue isn't caused by this patch) when doing silly things like:
-Log '*:stderr:100' -MaxCutText 8388608
# base64 /dev/urandom | head -c 8388608 > /tmp/data.txt
# while true; do wl-copy -t 'text/plain;charset=utf-8' < /tmp/data.txt; done
Ctrl+c the loop after a few seconds and close vncviewer, re-open vncviewer. Maybe even try closing without ctrl+c first.
That last one finally read an unmapped area crashing the process, and tells me it happened at LIST_FOREACH (client, &server->clients, link)
.
That looks like a use-after-free of the client object. Good catch. It's not obvious how this happens though.
Thanks!
This patch implements the extended clipboard pseudo-encoding, specifically only the text format. The appeal of this protocol is that it specifies that the text must be UTF-8 rather than Latin-1. In addition, the text is encoded by zlib which can reduce the length of the freeze that would occur when pushing a large clipboard update over a low-bandwidth link so long as the text is compressible.
The library user/wayvnc doesn't need to do anything to enable the protocol. The protocol is request-based, but I integrated it with the existing interface by simply caching the response in a buffer in nvnc_send_cut_text which can be sent when the client sends a request. Alternatively, the API could be extended in some way and wayvnc's data control code would need to adapt to it.
The protocol states that text must be transmitted in CRLF, so I convert the client's text to LF before running the nvnc_cut_text_fn. The normal ServerCutText/ClientCutText states that line endings must be LF, so it's not like preserving original line endings was possible with strict clients in the past anyway. neatvnc didn't convert server text to Latin-1 before sending it to the client, so I don't convert text to CRLF before sending to the client here.
Tested with TigerVNC's client (vncviewer). I have read and understood CONTRIBUTING.md.