[PATCH spice-server] StreamDevice: assert preconditions in parsing functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Be a bit more defensive about handling incoming messages from the stream
device. This also makes these functions consistent with
handle_msg_format(). These assertions are only enabled if
ENABLE_EXTRA_CHECKS is defined.

Signed-off-by: Jonathon Jongsma <jjongsma@xxxxxxxxxx>
Acked-by: Frediano Ziglio <fziglio@xxxxxxxxxx>
---

NOTE: I split the assertions off from the VideoStream renaming series.
Frediano also sugested that I only assert when ENABLE_EXTRA_CHECKS is
defined. He already acked this change on IRC, but I thought I'd send to
the mailing list in case others disagree.


 server/stream-device.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/server/stream-device.c b/server/stream-device.c
index a004899ff..4eaa959b6 100644
--- a/server/stream-device.c
+++ b/server/stream-device.c
@@ -131,6 +131,10 @@ handle_msg_invalid(StreamDevice *dev, SpiceCharDeviceInstance *sin, const char *
 {
     static const char default_error_msg[] = "Protocol error";
 
+    if (ENABLE_EXTRA_CHECKS) {
+        spice_assert(dev->hdr_pos >= sizeof(StreamDevHeader));
+    }
+
     if (!error_msg) {
         error_msg = default_error_msg;
     }
@@ -164,8 +168,10 @@ handle_msg_format(StreamDevice *dev, SpiceCharDeviceInstance *sin)
 {
     SpiceCharDeviceInterface *sif = spice_char_device_get_interface(sin);
 
-    spice_assert(dev->hdr_pos >= sizeof(StreamDevHeader));
-    spice_assert(dev->hdr.type == STREAM_TYPE_FORMAT);
+    if (ENABLE_EXTRA_CHECKS) {
+        spice_assert(dev->hdr_pos >= sizeof(StreamDevHeader));
+        spice_assert(dev->hdr.type == STREAM_TYPE_FORMAT);
+    }
 
     int n = sif->read(sin, dev->msg.buf + dev->msg_pos, sizeof(StreamMsgFormat) - dev->msg_pos);
     if (n < 0) {
@@ -190,6 +196,11 @@ handle_msg_data(StreamDevice *dev, SpiceCharDeviceInstance *sin)
     SpiceCharDeviceInterface *sif = spice_char_device_get_interface(sin);
     int n;
 
+    if (ENABLE_EXTRA_CHECKS) {
+        spice_assert(dev->hdr_pos >= sizeof(StreamDevHeader));
+        spice_assert(dev->hdr.type == STREAM_TYPE_DATA);
+    }
+
     while (1) {
         uint8_t buf[16 * 1024];
         n = sif->read(sin, buf, sizeof(buf));
-- 
2.13.6

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]