ui: Fix silent truncation of numeric keys in HMP sendkey

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>
This commit is contained in:
Markus Armbruster 2023-01-09 20:03:06 +01:00
parent 49e56287cc
commit 147c48791b

View File

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