[Spice-commits] AUTHORS server/red-stream.cpp

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon May 11 18:20:52 UTC 2020


 AUTHORS               |    1 +
 server/red-stream.cpp |   26 +++++++++++++-------------
 2 files changed, 14 insertions(+), 13 deletions(-)

New commits:
commit 15b1e2a3bb101ce3c2e91061c935b26817fe69db
Author: Gilmar Santos Jr <jgasjr at gmail.com>
Date:   Sat May 9 08:03:16 2020 -0300

    red-stream: WebDAV doesn't work when SASL is active
    
    When SASL is active, if a read request is made and SASL buffer contains some
    data (but not enough to fulfill the request), upon return the taken data from
    the buffer is not accounted for and hence part of the message gets discarded.
    
    red_stream_sasl_read function 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 part of the message).
    
    Fixes: https://gitlab.freedesktop.org/spice/spice/-/issues/40
    
    Acked-by: Frediano Ziglio <fziglio at redhat.com>

diff --git a/AUTHORS b/AUTHORS
index 30a49276..05c39998 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -42,6 +42,7 @@ Patches also contributed by
     Fabiano Fidêncio <fabiano at fidencio.org>
     Francois Gouget <fgouget at codeweavers.com>
     Gal Hammer <ghammer at redhat.com>
+    Gilmar Santos Jr <jgasjr at gmail.com>
     Hans de Goede <hdegoede at redhat.com>
     Javier Celaya <javier.celaya at flexvm.es>
     Jeremy White <jwhite at codeweavers.com>
diff --git a/server/red-stream.cpp b/server/red-stream.cpp
index 0e54df02..420433bd 100644
--- a/server/red-stream.cpp
+++ b/server/red-stream.cpp
@@ -707,20 +707,20 @@ static ssize_t red_stream_sasl_read(RedStream *s, uint8_t *buf, size_t nbyte)
     const char *decoded;
     unsigned int decodedlen;
     int err;
-    int n;
-
-    n = spice_buffer_copy(&s->priv->sasl.inbuffer, buf, nbyte);
-    if (n > 0) {
-        spice_buffer_remove(&s->priv->sasl.inbuffer, n);
-        if (n == nbyte)
-            return n;
-        nbyte -= n;
-        buf += n;
+    int n, offset;
+
+    offset = spice_buffer_copy(&s->priv->sasl.inbuffer, buf, nbyte);
+    if (offset > 0) {
+        spice_buffer_remove(&s->priv->sasl.inbuffer, offset);
+        if (offset == nbyte)
+            return offset;
+        nbyte -= offset;
+        buf += offset;
     }
 
     n = s->priv->read(s, encoded, sizeof(encoded));
     if (n <= 0) {
-        return n;
+        return offset > 0 ? offset : n;
     }
 
     err = sasl_decode(s->priv->sasl.conn,
@@ -729,18 +729,18 @@ static ssize_t red_stream_sasl_read(RedStream *s, uint8_t *buf, size_t nbyte)
     if (err != SASL_OK) {
         spice_warning("sasl_decode error: %d", err);
         errno = EIO;
-        return -1;
+        return offset > 0 ? offset : -1;
     }
 
     if (decodedlen == 0) {
         errno = EAGAIN;
-        return -1;
+        return offset > 0 ? offset : -1;
     }
 
     n = MIN(nbyte, decodedlen);
     memcpy(buf, decoded, n);
     spice_buffer_append(&s->priv->sasl.inbuffer, decoded + n, decodedlen - n);
-    return n;
+    return offset + n;
 }
 
 static char *addr_to_string(const char *format,


More information about the Spice-commits mailing list