[Spice-devel] [PATCH spice-gtk] spice-channel: Avoids spice_channel_read_wire returning success

Frediano Ziglio fziglio at redhat.com
Thu Nov 22 09:17:17 UTC 2018


Although is really unlikely that errno get <= 0 do not returns a
valid result for a failure from spice_channel_read_wire.
Such results could end up in buffer overflows.
errno is not always set (for instance GLib functions prefer to
set a GError instead or Windows uses WSASetLastError to store
sockets function errors). Sometimes is also set to an invalid
value to check if some function (like strtod) modify it.
This is more a safety but better safe than sorry.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 src/spice-channel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/spice-channel.c b/src/spice-channel.c
index 602869e1..e6110b0a 100644
--- a/src/spice-channel.c
+++ b/src/spice-channel.c
@@ -1060,7 +1060,7 @@ static int spice_channel_read_wire(SpiceChannel *channel, void *data, size_t len
                 continue;
             } else {
                 c->has_error = TRUE;
-                return -errno;
+                return errno > 0 ? -errno : -EIO;
             }
         }
         if (ret == 0) {
-- 
2.17.2



More information about the Spice-devel mailing list