]> git.proxmox.com Git - mirror_qemu.git/commitdiff
ui: Fix silent truncation of numeric keys in HMP sendkey
authorMarkus Armbruster <armbru@redhat.com>
Mon, 9 Jan 2023 19:03:06 +0000 (20:03 +0100)
committerMarkus Armbruster <armbru@redhat.com>
Thu, 19 Jan 2023 12:30:01 +0000 (13:30 +0100)
Keys are int.  HMP sendkey assigns them from the value strtoul(),
silently truncating values greater than INT_MAX.  Fix to reject them.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Message-Id: <20230109190321.1056914-3-armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
monitor/hmp-cmds.c

index ed78a87ddd8087cc348dcd7ab49c620c53a2597c..9947ff0b453c8a6f91e6b9456396fe7b43866fd4 100644 (file)
@@ -1549,8 +1549,12 @@ void hmp_sendkey(Monitor *mon, const QDict *qdict)
         v = g_malloc0(sizeof(*v));
 
         if (strstart(keys, "0x", NULL)) {
-            char *endp;
-            int value = strtoul(keys, &endp, 0);
+            const char *endp;
+            int value;
+
+            if (qemu_strtoi(keys, &endp, 0, &value) < 0) {
+                goto err_out;
+            }
             assert(endp <= keys + keyname_len);
             if (endp != keys + keyname_len) {
                 goto err_out;