Skip to content

Commit 10c5322

Browse files
committed
qemu: qapi: Limit traversal depth for QAPI schema queries
Implicitly the query depth is limited by the length of the QAPI schema query, but 'alternate' and 'array' QAPI meta-types don't consume a part of the query string thus a loop on such types would get our traversal code stuck in an infinite loop. Prevent this from happening by limiting the nesting depth to 1000. Signed-off-by: Peter Krempa <[email protected]> Reviewed-by: Daniel P. Berrangé <[email protected]>
1 parent 9f90a4b commit 10c5322

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/qemu/qemu_qapi.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,23 @@ struct virQEMUQAPISchemaTraverseContext {
7474
virHashTablePtr schema;
7575
char **queries;
7676
virJSONValuePtr returnType;
77+
size_t depth;
7778
};
7879

7980

81+
static int
82+
virQEMUQAPISchemaTraverseContextValidateDepth(struct virQEMUQAPISchemaTraverseContext *ctxt)
83+
{
84+
if (ctxt->depth++ > 1000) {
85+
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
86+
_("possible loop in QMP schema"));
87+
return -1;
88+
}
89+
90+
return 0;
91+
}
92+
93+
8094
static void
8195
virQEMUQAPISchemaTraverseContextInit(struct virQEMUQAPISchemaTraverseContext *ctxt,
8296
char **queries,
@@ -329,6 +343,9 @@ virQEMUQAPISchemaTraverse(const char *baseName,
329343
const char *metatype;
330344
size_t i;
331345

346+
if (virQEMUQAPISchemaTraverseContextValidateDepth(ctxt) < 0)
347+
return -2;
348+
332349
if (!(cur = virHashLookup(ctxt->schema, baseName)))
333350
return -2;
334351

0 commit comments

Comments
 (0)