[Spice-devel] [PATCH spice-server 1/2] red-stream-device: Fix and check empty data messages
Frediano Ziglio
fziglio at redhat.com
Wed Jul 11 13:16:15 UTC 2018
If guest sent an empty data message this was not parsed correctly.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
server/red-stream-device.c | 2 +-
server/tests/test-stream-device.c | 18 +++++++++++++++---
2 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/server/red-stream-device.c b/server/red-stream-device.c
index 6a2b6a73a..77d0acd06 100644
--- a/server/red-stream-device.c
+++ b/server/red-stream-device.c
@@ -332,7 +332,7 @@ handle_msg_data(StreamDevice *dev, SpiceCharDeviceInstance *sin)
/* read from device */
n = sif->read(sin, dev->msg->buf + dev->msg_pos, dev->hdr.size - dev->msg_pos);
if (n <= 0) {
- return false;
+ return dev->msg_pos == dev->hdr.size;
}
dev->msg_pos += n;
diff --git a/server/tests/test-stream-device.c b/server/tests/test-stream-device.c
index 00fbc90c7..ae9a78da5 100644
--- a/server/tests/test-stream-device.c
+++ b/server/tests/test-stream-device.c
@@ -352,8 +352,8 @@ static void test_stream_device_format_after_data(void)
basic_event_loop_destroy();
}
-// check empty capabilities
-static void test_stream_device_empty_capabilities(void)
+// check empty message
+static void test_stream_device_empty(StreamMsgType msg_type)
{
uint8_t *p = message;
SpiceCoreInterface *core = basic_event_loop_init();
@@ -365,7 +365,7 @@ static void test_stream_device_empty_capabilities(void)
message_sizes_end = message_sizes;
// add some messages into device buffer
- p = add_stream_hdr(p, STREAM_TYPE_CAPABILITIES, 0);
+ p = add_stream_hdr(p, msg_type, 0);
*message_sizes_end = p - message;
++message_sizes_end;
p = add_format(p, 640, 480, SPICE_VIDEO_CODEC_TYPE_MJPEG);
@@ -396,6 +396,17 @@ static void test_stream_device_empty_capabilities(void)
basic_event_loop_destroy();
}
+// check empty capabilities
+static void test_stream_device_empty_capabilities(void)
+{
+ test_stream_device_empty(STREAM_TYPE_CAPABILITIES);
+}
+
+// check empty data
+static void test_stream_device_empty_data(void)
+{
+ test_stream_device_empty(STREAM_TYPE_DATA);
+}
int main(int argc, char *argv[])
{
@@ -406,6 +417,7 @@ int main(int argc, char *argv[])
g_test_add_func("/server/stream-device-multiple", test_stream_device_multiple);
g_test_add_func("/server/stream-device-format-after-data", test_stream_device_format_after_data);
g_test_add_func("/server/stream-device-empty-capabilities", test_stream_device_empty_capabilities);
+ g_test_add_func("/server/stream-device-empty-data", test_stream_device_empty_data);
return g_test_run();
}
--
2.17.1
More information about the Spice-devel
mailing list