Skip to contentSkip to conversation

: QMP: Fix segfault in bad input

PATCH In review Luiz Capitulino 2 participants 6 messages Apr 7, 2010 – Apr 20, 2010

lore
Share & tools
lore
#0 lore raw

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.

#1 lore raw

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
index 8d885cd..b6aaec7 100644
@@ -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
index bae08c0..c98c61a 100644
@@ -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
#2 lore raw

PATCH 2/4 QMP: Use QERR_QMP_BAD_INPUT_OBJECT_MEMBER

In reply to Luiz Capitulino

The 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
index 709b326..cd350d6 100644
@@ -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
#3 lore raw

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
index b6aaec7..034c7de 100644
@@ -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
#4 lore raw

PATCH 4/4 QMP: Check "arguments" member's type

In reply to Luiz Capitulino

Otherwise 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
index cd350d6..91d7da5 100644
@@ -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
#5 lore raw
In reply to Luiz Capitulino
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.