mirror of https://github.com/xemu-project/xemu.git
Refactor and fix do_sendkey (Jan Kiszka).
Looking at the sendkey implementation, planning to enhance it with a hold time argument, I found some potential out-of-bound access and not very readable code. Here is a fix for the former and a (subjective) improvement of the latter. Signed-off-by: Jan Kiszka <jan.kiszka@web.de> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4657 c046a42c-6fe2-441c-8c8c-71466251a162
This commit is contained in:
parent
0fead1259a
commit
3401c0d95f
49
monitor.c
49
monitor.c
|
@ -919,33 +919,38 @@ static int get_keycode(const char *key)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void do_send_key(const char *string)
|
static void do_sendkey(const char *string)
|
||||||
{
|
{
|
||||||
char keybuf[16], *q;
|
|
||||||
uint8_t keycodes[16];
|
uint8_t keycodes[16];
|
||||||
const char *p;
|
int nb_keycodes = 0;
|
||||||
int nb_keycodes, keycode, i;
|
char keyname_buf[16];
|
||||||
|
char *separator;
|
||||||
|
int keyname_len, keycode, i;
|
||||||
|
|
||||||
nb_keycodes = 0;
|
while (1) {
|
||||||
p = string;
|
separator = strchr(string, '-');
|
||||||
while (*p != '\0') {
|
keyname_len = separator ? separator - string : strlen(string);
|
||||||
q = keybuf;
|
if (keyname_len > 0) {
|
||||||
while (*p != '\0' && *p != '-') {
|
pstrcpy(keyname_buf, sizeof(keyname_buf), string);
|
||||||
if ((q - keybuf) < sizeof(keybuf) - 1) {
|
if (keyname_len > sizeof(keyname_buf) - 1) {
|
||||||
*q++ = *p;
|
term_printf("invalid key: '%s...'\n", keyname_buf);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
p++;
|
if (nb_keycodes == sizeof(keycodes)) {
|
||||||
|
term_printf("too many keys\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
keyname_buf[keyname_len] = 0;
|
||||||
|
keycode = get_keycode(keyname_buf);
|
||||||
|
if (keycode < 0) {
|
||||||
|
term_printf("unknown key: '%s'\n", keyname_buf);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
keycodes[nb_keycodes++] = keycode;
|
||||||
}
|
}
|
||||||
*q = '\0';
|
if (!separator)
|
||||||
keycode = get_keycode(keybuf);
|
|
||||||
if (keycode < 0) {
|
|
||||||
term_printf("unknown key: '%s'\n", keybuf);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
keycodes[nb_keycodes++] = keycode;
|
|
||||||
if (*p == '\0')
|
|
||||||
break;
|
break;
|
||||||
p++;
|
string = separator + 1;
|
||||||
}
|
}
|
||||||
/* key down events */
|
/* key down events */
|
||||||
for(i = 0; i < nb_keycodes; i++) {
|
for(i = 0; i < nb_keycodes; i++) {
|
||||||
|
@ -1347,7 +1352,7 @@ static term_cmd_t term_cmds[] = {
|
||||||
{ "i", "/ii.", do_ioport_read,
|
{ "i", "/ii.", do_ioport_read,
|
||||||
"/fmt addr", "I/O port read" },
|
"/fmt addr", "I/O port read" },
|
||||||
|
|
||||||
{ "sendkey", "s", do_send_key,
|
{ "sendkey", "s", do_sendkey,
|
||||||
"keys", "send keys to the VM (e.g. 'sendkey ctrl-alt-f1')" },
|
"keys", "send keys to the VM (e.g. 'sendkey ctrl-alt-f1')" },
|
||||||
{ "system_reset", "", do_system_reset,
|
{ "system_reset", "", do_system_reset,
|
||||||
"", "reset the system" },
|
"", "reset the system" },
|
||||||
|
|
Loading…
Reference in New Issue