Skip to contentSkip to conversation

qxl fixes

PATCH In review Markus Armbruster 2 participants 4 messages Jan 10, 2013

lore
Share & tools
lore
#0 lore raw

cover qxl fixes

Markus Armbruster (2):
qxl: Fix SPICE_RING_PROD_ITEM(), SPICE_RING_CONS_ITEM() sanity check
qxl: Don't drop client capability bits

 hw/qxl.c | 26 ++++++++++----------------
 1 file changed, 10 insertions(+), 16 deletions(-)
Signature · 1 line
1.7.11.7
#1 lore raw

PATCH 1/2 qxl: Fix SPICE_RING_PROD_ITEM(), SPICE_RING_CONS_ITEM() sanity check

From: Markus Armbruster <[email protected]>

The pointer arithmetic there is safe, but ugly. Coverity grouses about it. However, the actual comparison is off by one: <= end instead of < end. Fix by rewriting the check in a cleaner way.

---
 hw/qxl.c | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)
hw/qxl.c +6 -14
index d08b9bd..2c2b422 100644
@@ -37,33 +37,25 @@
  */
 #undef SPICE_RING_PROD_ITEM
 #define SPICE_RING_PROD_ITEM(qxl, r, ret) {                             \
-        typeof(r) start = r;                                            \
-        typeof(r) end = r + 1;                                          \
         uint32_t prod = (r)->prod & SPICE_RING_INDEX_MASK(r);           \
-        typeof(&(r)->items[prod]) m_item = &(r)->items[prod];           \
-        if (!((uint8_t*)m_item >= (uint8_t*)(start) && (uint8_t*)(m_item + 1) <= (uint8_t*)(end))) { \
+        if (prod >= ARRAY_SIZE((r)->items)) {                           \
             qxl_set_guest_bug(qxl, "SPICE_RING_PROD_ITEM indices mismatch " \
-                          "! %p <= %p < %p", (uint8_t *)start,          \
-                          (uint8_t *)m_item, (uint8_t *)end);           \
+                          "%u >= %zu", prod, ARRAY_SIZE((r)->items));   \
             ret = NULL;                                                 \
         } else {                                                        \
-            ret = &m_item->el;                                          \
+            ret = &(r)->items[prod].el;                                 \
         }                                                               \
     }
 
 #undef SPICE_RING_CONS_ITEM
 #define SPICE_RING_CONS_ITEM(qxl, r, ret) {                             \
-        typeof(r) start = r;                                            \
-        typeof(r) end = r + 1;                                          \
         uint32_t cons = (r)->cons & SPICE_RING_INDEX_MASK(r);           \
-        typeof(&(r)->items[cons]) m_item = &(r)->items[cons];           \
-        if (!((uint8_t*)m_item >= (uint8_t*)(start) && (uint8_t*)(m_item + 1) <= (uint8_t*)(end))) { \
+        if (cons >= ARRAY_SIZE((r)->items)) {                           \
             qxl_set_guest_bug(qxl, "SPICE_RING_CONS_ITEM indices mismatch " \
-                          "! %p <= %p < %p", (uint8_t *)start,          \
-                          (uint8_t *)m_item, (uint8_t *)end);           \
+                          "%u >= %zu", cons, ARRAY_SIZE((r)->items));   \
             ret = NULL;                                                 \
         } else {                                                        \
-            ret = &m_item->el;                                          \
+            ret = &(r)->items[cons].el;                                 \
         }                                                               \
     }
 
Signature · 1 line
1.7.11.7
#2 lore raw

PATCH 2/2 qxl: Don't drop client capability bits

In reply to Markus Armbruster

interface_set_client_capabilities() copies only the first few bits, because it falls into a Classic C trap: you can declare a parameter uint8_t caps[58], but the resulting parameter type is uint8_t *, not uint8_t[58]. In particular, sizeof(caps) is sizeof(uint8_t *), not the intended sizeof(uint8_t[58]).

Harmless, because the bits aren't used, yet. Broken in commit c10018d6. Spotted by Coverity.

---
 hw/qxl.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
hw/qxl.c +4 -2
index 2c2b422..874d56f 100644
@@ -951,9 +951,11 @@ static void interface_set_client_capabilities(QXLInstance *sin,
     }
 
     qxl->shadow_rom.client_present = client_present;
-    memcpy(qxl->shadow_rom.client_capabilities, caps, sizeof(caps));
+    memcpy(qxl->shadow_rom.client_capabilities, caps,
+           sizeof(qxl->shadow_rom.client_capabilities));
     qxl->rom->client_present = client_present;
-    memcpy(qxl->rom->client_capabilities, caps, sizeof(caps));
+    memcpy(qxl->rom->client_capabilities, caps,
+           sizeof(qxl->rom->client_capabilities));
     qxl_rom_set_dirty(qxl);
 
     qxl_send_events(qxl, QXL_INTERRUPT_CLIENT);
Signature · 1 line
1.7.11.7
#3 lore raw
In reply to Markus Armbruster
Quoted 7 lines · Markus Armbruster

Markus Armbruster (2):
qxl: Fix SPICE_RING_PROD_ITEM(), SPICE_RING_CONS_ITEM() sanity check
qxl: Don't drop client capability bits

 hw/qxl.c | 26 ++++++++++----------------
 1 file changed, 10 insertions(+), 16 deletions(-)

Patch added to spice patch queue.

thanks,
Gerd