monitor: fail when 'i' type is greater than 32-bit
authorLuiz Capitulino <lcapitulino@redhat.com>
Fri, 28 Aug 2009 18:27:26 +0000 (15:27 -0300)
committerAnthony Liguori <aliguori@us.ibm.com>
Fri, 4 Sep 2009 14:37:33 +0000 (09:37 -0500)
The 'i' argument type is for 32-bit only and most handlers
will use an 'int' to store its value.

It's better to fail gracefully when the user enters a value
greater than 32-bit than to get subtle casting bugs.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
monitor.c

index 9067bf04b1ef866e7b3fc6354236da5e2d8c163b..5322bc8dc7d7bcd5658b429ee1fb4f94b06e3f4a 100644 (file)
--- a/monitor.c
+++ b/monitor.c
@@ -2759,6 +2759,12 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
                 }
                 if (get_expr(mon, &val, &p))
                     goto fail;
+                /* Check if 'i' is greater than 32-bit */
+                if ((c == 'i') && ((val >> 32) & 0xffffffff)) {
+                    monitor_printf(mon, "\'%s\' has failed: ", cmdname);
+                    monitor_printf(mon, "integer is for 32-bit values\n");
+                    goto fail;
+                }
                 qdict_put(qdict, key, qint_from_int(val));
             }
             break;