Patchwork [23/29] monitor: fail when 'i' type is greater than 32-bit

login
register
mail settings
Submitter Luiz Capitulino
Date Aug. 26, 2009, 5:05 p.m.
Message ID <1251306352-31316-24-git-send-email-lcapitulino@redhat.com>
Download mbox | patch
Permalink /patch/32202/
State Superseded
Headers show

Comments

Luiz Capitulino - Aug. 26, 2009, 5:05 p.m.
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>
---
 monitor.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

Patch

diff --git a/monitor.c b/monitor.c
index 68fbf34..2932f0b 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2748,6 +2748,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;