Skip to contentSkip to conversation

qapi: Check for negative enum values

PATCH In review Luiz Capitulino 2 participants 2 messages Nov 14, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qapi: Check for negative enum values

We don't currently check for negative enum values in qmp_output_type_enum(), this will very likely generate a segfault when triggered.

However, it _seems_ that no code in tree can trigger this today.

---

I think it's a good idea to merge this one for 1.0, but I'd be ok to queue it for 1.1 in case we're only merging fixes for "real" bugs.

I found this while extending the QAPI's unit-tests...

 qapi/qmp-output-visitor.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
qapi/qmp-output-visitor.c +1 -1
index d67724e..f76d015 100644
@@ -190,7 +190,7 @@ static void qmp_output_type_enum(Visitor *v, int *obj, const char *strings[],
 
     assert(strings);
     while (strings[i++] != NULL);
-    if (value >= i - 1) {
+    if (value < 0 || value >= i - 1) {
         error_set(errp, QERR_INVALID_PARAMETER, name ? name : "null");
         return;
     }
Signature · 1 line
1.7.8.rc2.dirty
Acked-by on v1 1/1
#1 lore raw
Quoted 21 lines · Luiz Capitulino

We don't currently check for negative enum values in qmp_output_type_enum(), this will very likely generate a segfault when triggered.

However, it _seems_ that no code in tree can trigger this today.

---

I think it's a good idea to merge this one for 1.0, but I'd be ok to queue it for 1.1 in case we're only merging fixes for "real" bugs.

I found this while extending the QAPI's unit-tests...

  qapi/qmp-output-visitor.c |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)
qapi/qmp-output-visitor.c +0 -0
index d67724e..f76d015 100644

qapi/qmp-output-visitor.c static void qmp_output_type_enum(Visitor *v, int *obj, const char *strings[], · line 196

Quoted 8 lines
qapi/qmp-output-visitor.c +1 -1
@@ -190,7 +190,7 @@ static void qmp_output_type_enum(Visitor *v, int *obj, const char *strings[],
 
      assert(strings);
      while (strings[i++] != NULL);
-    if (value>= i - 1) {
+    if (value<  0 || value>= i - 1) {
          error_set(errp, QERR_INVALID_PARAMETER, name ? name : "null");
          return;
      }