: QMP: Fix segfault in bad input
cover : QMP: Fix segfault in bad input
First, we do some QError usage cleanup in handle_qmp_command() and then
really fix the bug in the last patch.
PATCH 1/4 QError: New QERR_QMP_BAD_INPUT_OBJECT_MEMBER
--- qerror.c | 4 ++++ qerror.h | 3 +++ 2 files changed, 7 insertions(+), 0 deletions(-)
qerror.c +4 -0
@@ -173,6 +173,10 @@ static const QErrorStringTable qerror_table[] = { .desc = "Bad QMP input object", }, { + .error_fmt = QERR_QMP_BAD_INPUT_OBJECT_MEMBER, + .desc = "QMP input object member '%(member)' expects '%(expected)'", + }, + { .error_fmt = QERR_SET_PASSWD_FAILED, .desc = "Could not set password", },
qerror.h +3 -0
@@ -145,6 +145,9 @@ QError *qobject_to_qerror(const QObject *obj);#define QERR_QMP_BAD_INPUT_OBJECT \ "{ 'class': 'QMPBadInputObject', 'data': { 'expected': %s } }" +#define QERR_QMP_BAD_INPUT_OBJECT_MEMBER \ + "{ 'class': 'QMPBadInputObjectMember', 'data': { 'member': %s, 'expected': %s } }" +#define QERR_SET_PASSWD_FAILED \ "{ 'class': 'SetPasswdFailed', 'data': {} }"
Signature · 1 line
1.7.0.4.297.g6555b1
PATCH 2/4 QMP: Use QERR_QMP_BAD_INPUT_OBJECT_MEMBER
In reply to Luiz CapitulinoThe QERR_QMP_BAD_INPUT_OBJECT error is going to be used only for two problems: the input is not an object or the "execute" key is missing.
--- monitor.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
monitor.c +1 -1
@@ -4489,7 +4489,7 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)qerror_report (QERR_QMP_BAD_INPUT_OBJECT ,"execute" ); goto err_input; }else if (qobject_type (obj) !=QTYPE_QSTRING ) { -qerror_report (QERR_QMP_BAD_INPUT_OBJECT ,"string" ); +qerror_report (QERR_QMP_BAD_INPUT_OBJECT_MEMBER ,"execute" ,"string" ); goto err_input; }
Signature · 1 line
1.7.0.4.297.g6555b1
PATCH 3/4 QError: Improve QERR_QMP_BAD_INPUT_OBJECT desc
In reply to Luiz Capitulino--- qerror.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
qerror.c +1 -1
@@ -170,7 +170,7 @@ static const QErrorStringTable qerror_table[] = { }, { .error_fmt = QERR_QMP_BAD_INPUT_OBJECT, - .desc = "Bad QMP input object", + .desc = "Expected '%(expected)' in QMP input", }, { .error_fmt = QERR_QMP_BAD_INPUT_OBJECT_MEMBER,
Signature · 1 line
1.7.0.4.297.g6555b1
PATCH 4/4 QMP: Check "arguments" member's type
In reply to Luiz CapitulinoOtherwise the following input crashes QEMU:
{ "execute": "migrate", "arguments": "tcp:0:4446" }
--- monitor.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
monitor.c +3 -0
@@ -4522,6 +4522,9 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens) obj =qdict_get (input,"arguments" );if (!obj) { args =qdict_new (); + }else if (qobject_type (obj) !=QTYPE_QDICT ) { +qerror_report (QERR_QMP_BAD_INPUT_OBJECT_MEMBER ,"arguments" ,"object" ); + goto err_input; }else { args =qobject_to_qdict (obj);QINCREF (args);
Signature · 1 line
1.7.0.4.297.g6555b1
Quoted 2 lines · Luiz Capitulino
First, we do some QError usage cleanup in
handle_qmp_command()and then
really fix the bug in the last patch.
The bug is that we neglect to check that command object member "arguments" is an object before we access its members. Crashes when it's not an object.
The rest of the patch series tweaks diagnostics of malformed command objects:
* Split QERR_QMP_BAD_INPUT_OBJECT_MEMBER off QERR_QMP_BAD_INPUT_OBJECT. I don't care for that at all. These errors are all of the "hello client, you're too broken to live, go away" kind. Clients won't be able to do anything useful with a fine-grained error class there.
* Improve the human-readable messages. This could be occasionally useful for debugging, I guess.
That said, I'm not opposed to merging as is. There's plenty of useless error detail already, with more to come, so adding to the pile doesn't bother me.