From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:44763) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qoa5U-0002bq-N7 for qemu-devel@nongnu.org; Wed, 03 Aug 2011 07:58:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qoa5Q-0003iG-JV for qemu-devel@nongnu.org; Wed, 03 Aug 2011 07:58:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:23840) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qoa5Q-0003hY-9E for qemu-devel@nongnu.org; Wed, 03 Aug 2011 07:58:08 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p73Bvv6s029641 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 3 Aug 2011 07:57:57 -0400 From: Alon Levy Date: Wed, 3 Aug 2011 14:57:27 +0300 Message-Id: <1312372647-6329-1-git-send-email-alevy@redhat.com> Subject: [Qemu-devel] [PATCH] monitor: HMP: fix consecutive integer expression parsing List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Currently a command that takes two consecutive integer operations, like client_migrate_info, will be incorrectly parsed by the human monitor if the second expression begins with a minus ('-') or plus ('+') sign: client_migrate_info client_migrate_info spice localhost 5900 -1 => port = 5899 = 5900 - 1 tls-port = -1 But expected by the user to be: port = 5900 tls-port = -1 The fix is that for any required integer (ilM) expression followed by another integer expression (ilM) the first expression will be parsed by expr_unary instead of expr_sum. So you can still use arithmetic, but you have to enclose it in parenthesis: Command line | Old parsed result | With patch result (1+1) 2 | 2, 2 | 2, 2 1 -1 | 0, -1 | 1, -1 The rest are bizarre but not any worse then before 1+2+3 | 6, 5 | 1, 5 (1+2)+3 | 3, 3 | 3, 3 Signed-off-by: Alon Levy --- monitor.c | 27 ++++++++++++++++++++++++--- 1 files changed, 24 insertions(+), 3 deletions(-) diff --git a/monitor.c b/monitor.c index 1b8ba2c..45e2d6c 100644 --- a/monitor.c +++ b/monitor.c @@ -3889,7 +3889,7 @@ static int64_t expr_sum(Monitor *mon) return val; } -static int get_expr(Monitor *mon, int64_t *pval, const char **pp) +static int get_expr(Monitor *mon, int64_t *pval, const char **pp, int unary) { pch = *pp; if (setjmp(expr_env)) { @@ -3898,7 +3898,11 @@ static int get_expr(Monitor *mon, int64_t *pval, const char **pp) } while (qemu_isspace(*pch)) pch++; - *pval = expr_sum(mon); + if (unary) { + *pval = expr_unary(mon); + } else { + *pval = expr_sum(mon); + } *pp = pch; return 0; } @@ -4267,6 +4271,9 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, case 'M': { int64_t val; + int unary = 0; + char *next_key; + char *next; while (qemu_isspace(*p)) p++; @@ -4288,7 +4295,21 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, } typestr++; } - if (get_expr(mon, &val, &p)) + next = key_get_info(typestr, &next_key); + qemu_free(next_key); + if (*next == 'i' || *next == 'l' || *next == 'M') { + /* If a command has two consecutive ii parameters the first + * get_expr will also parse the second parameter if it + * starts with a - or +. To avoid this only parse unary in + * this case, i.e.: + * client_migrate_info spice localhost 1 -1 + * => 1, -1 + * client_migrate_info spice localhost (1+3) -1 + * => 4, -1 + */ + unary = 1; + } + if (get_expr(mon, &val, &p, unary)) goto fail; /* Check if 'i' is greater than 32-bit */ if ((c == 'i') && ((val >> 32) & 0xffffffff)) { -- 1.7.6