提交 47c6d3ec 编写于 作者: P Paolo Bonzini 提交者: Anthony Liguori

qapi: protect against NULL QObject in qmp_input_get_object

A NULL qobj can occur when a parameter is fetched via qdict_get, but
the parameter is not in the command.  By returning NULL, the caller can
choose whether to raise a missing parameter error, an invalid parameter
type error, or use a default value.  For example, qom-set could can
use this to reset a property to its default value, though at this time
it will fail with "Invalid parameter type".  In any case, anything is
better than crashing!
Reviewed-by: NAnthony Liguori <anthony@codemonkey.ws>
Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
上级 b1746ddd
......@@ -49,10 +49,12 @@ static const QObject *qmp_input_get_object(QmpInputVisitor *qiv,
qobj = qiv->stack[qiv->nb_stack - 1].obj;
}
if (name && qobject_type(qobj) == QTYPE_QDICT) {
return qdict_get(qobject_to_qdict(qobj), name);
} else if (qiv->nb_stack > 0 && qobject_type(qobj) == QTYPE_QLIST) {
return qlist_entry_obj(qiv->stack[qiv->nb_stack - 1].entry);
if (qobj) {
if (name && qobject_type(qobj) == QTYPE_QDICT) {
return qdict_get(qobject_to_qdict(qobj), name);
} else if (qiv->nb_stack > 0 && qobject_type(qobj) == QTYPE_QLIST) {
return qlist_entry_obj(qiv->stack[qiv->nb_stack - 1].entry);
}
}
return qobj;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册