Skip to contentSkip to conversation

hw/xen/xen_pt: fix uninitialized variable

PATCH In review Marek Marczykowski-Górecki 2 participants 2 messages Jan 27, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/xen/xen_pt: fix uninitialized variable

xen_pt_config_reg_init() reads only that many bytes as the size of the register that is being initialized. It uses xen_host_pci_get_{byte,word,long} and casts its last argument to expected pointer type. This means for smaller registers higher bits of 'val' are not initialized. Then, the function fails if any of those higher bits are set.

Fix this by initializing 'val' with zero.

---
 hw/xen/xen_pt_config_init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/xen/xen_pt_config_init.c +1 -1
index cde898b744..8b9b554352 100644
@@ -1924,7 +1924,7 @@ static void xen_pt_config_reg_init(XenPCIPassthroughState *s,
     if (reg->init) {
         uint32_t host_mask, size_mask;
         unsigned int offset;
-        uint32_t val;
+        uint32_t val = 0;
 
         /* initialize emulate register */
         rc = reg->init(s, reg_entry->reg,
Signature · 1 line
2.37.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Marek Marczykowski-Górecki

xen_pt_config_reg_init() reads only that many bytes as the size of the register that is being initialized. It uses xen_host_pci_get_{byte,word,long} and casts its last argument to expected pointer type. This means for smaller registers higher bits of 'val' are not initialized. Then, the function fails if any of those higher bits are set.

Fix this by initializing 'val' with zero.

Quoted 20 lines
---
 hw/xen/xen_pt_config_init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/xen/xen_pt_config_init.c +1 -1
index cde898b744..8b9b554352 100644
@@ -1924,7 +1924,7 @@ static void xen_pt_config_reg_init(XenPCIPassthroughState *s,
     if (reg->init) {
         uint32_t host_mask, size_mask;
         unsigned int offset;
-        uint32_t val;
+        uint32_t val = 0;
 
         /* initialize emulate register */
         rc = reg->init(s, reg_entry->reg,
Signature · 1 line
2.37.3