Skip to contentSkip to conversation

block: Assert validity of BdrvActionOps

PATCH Applied Max Reitz 3 participants 3 messages Sep 12, 2013

lore
Share & tools
lore

Max Reitz

author
#0 lore raw

PATCH 1/1 block: Assert validity of BdrvActionOps

In qmp_transaction, assert that the BdrvActionOps to be used is actually valid.

This assertion failing is very improbable, however, it might happen, if a new TransactionActionKind is introduced "out of order" and the actions[] array is not updated.

---
 blockdev.c | 2 ++
 1 file changed, 2 insertions(+)
blockdev.c +2 -0
index 07dac05..14a0bb1 100644
@@ -1102,6 +1102,8 @@ void qmp_transaction(TransactionActionList *dev_list, Error **errp)
         assert(dev_info->kind < ARRAY_SIZE(actions));
 
         ops = &actions[dev_info->kind];
+        assert(ops->instance_size > 0);
+
         state = g_malloc0(ops->instance_size);
         state->ops = ops;
         state->action = dev_info;
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Max Reitz

In qmp_transaction, assert that the BdrvActionOps to be used is actually valid.

This assertion failing is very improbable, however, it might happen, if a new TransactionActionKind is introduced "out of order" and the actions[] array is not updated.

All of which would be a programmer bug, so assert is correct.

Quoted 11 lines
---
 blockdev.c | 2 ++
 1 file changed, 2 insertions(+)
blockdev.c +0 -0
index 07dac05..14a0bb1 100644

blockdev.c void qmp_transaction(TransactionActionList *dev_list, Error **errp) · line 1105

Quoted 4 lines
blockdev.c +1 -0
@@ -1102,6 +1102,8 @@ void qmp_transaction(TransactionActionList *dev_list, Error **errp)
         assert(dev_info->kind < ARRAY_SIZE(actions));
 
         ops = &actions[dev_info->kind];
+        assert(ops->instance_size > 0);

Bikeshedding: assert(ops->instance_size) is slightly less typing (but not enough to warrant a respin).

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Applied
#2 lore raw
In reply to Max Reitz

Am 12.09.2013 um 14:57 hat Max Reitz geschrieben:

Quoted 8 lines

In qmp_transaction, assert that the BdrvActionOps to be used is actually valid.

This assertion failing is very improbable, however, it might happen, if a new TransactionActionKind is introduced "out of order" and the actions[] array is not updated.

Thanks, applied to the block branch.

Kevin