WebDAV doesn't work when SASL is active
I built a VM using QEMU/KVM/Libvirt and set spice_sasl=1 in /etc/libvirt/qemu.conf (/etc/sasl2/qemu.conf is adjusted to use GSSAPI). Everything seems to work fine (display, mouse, keyboard, sound etc). When I share some folder (using virt-viewer) a virtual drive appears on guest, but it's not possible to list its contents. I also tried to access http://localhost:9843 using firefox and got no answer. Using wireshark to monitor port 9843, I can see the HTTP request, but no response.
On the client side, I run virt-viewer --debug --spice-debug and it seems that requests arrive and responses are sent, but somehow they get lost (I could see that SASL authentication is working fine).
With spice_sasl=0 everything works as expected.
The issue seems to be at red_stream_sasl_read function (server/red-stream.cpp). First, it takes available data from sasl buffer and returns if it's enough. If it's not, nbyte is decremented and buf pointer is incremented to account for the taken data (if any). Then it tries to get more data from the socket and decode it.
Suppose there was some data in the sasl buffer, but not enough. Then the socket is not readable (EAGAIN, EINTR, whatever) or the new data isn't enough for sasl_decode (hence decodedlen == 0). In both cases the function returns as if no data was read, but it took some data from sasl buffer. This data is lost and from this point on the communication ceases on the channel (eventually new data is read, but messages are corrupt without the parts previously discarded).
On the other hand, if some data is read from sasl buffer and everything else works fine, the output buffer contains all the data, but the count returned only inform the caller about the newly read data (which causes the similar effect of discarding some data).
The bug doesn't show up if:
- There is no previous data in sasl buffer, or
- The available data in sasl buffer is enough
Maybe this problem arises easily with WebDAV cause of frequent large messages comparing to other channels, but this bug could affect others channels as well when SASL is in use.