[libvirt] [PATCH 0/2] Clean up and fix handling of --holdtime in the virsh send-key command

Peter Krempa (2): virsh-domain: Clean up cmdSendKey virsh-domain: Report errors on invalid --holdtime value for cmdSendKey tools/virsh-domain.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) -- 1.8.1.5

Rename the get_integer_keycode helper to vshKeyCodeGetInt and get rid of a unneeded typecast. --- tools/virsh-domain.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 4d0cc8f..0255542 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -6725,7 +6725,7 @@ static const vshCmdOptDef opts_send_key[] = { }; static int -get_integer_keycode(const char *key_name) +vshKeyCodeGetInt(const char *key_name) { unsigned int val; @@ -6757,7 +6757,7 @@ cmdSendKey(vshControl *ctl, const vshCmd *cmd) holdtime = 0; codeset = virKeycodeSetTypeFromString(codeset_option); - if ((int)codeset < 0) { + if (codeset < 0) { vshError(ctl, _("unknown codeset: '%s'"), codeset_option); goto cleanup; } @@ -6768,7 +6768,7 @@ cmdSendKey(vshControl *ctl, const vshCmd *cmd) goto cleanup; } - if ((keycode = get_integer_keycode(opt->data)) <= 0) { + if ((keycode = vshKeyCodeGetInt(opt->data)) <= 0) { if ((keycode = virKeycodeValueFromString(codeset, opt->data)) <= 0) { vshError(ctl, _("invalid keycode: '%s'"), opt->data); goto cleanup; -- 1.8.1.5

On 04/18/2013 02:51 AM, Peter Krempa wrote:
Rename the get_integer_keycode helper to vshKeyCodeGetInt and get rid of a unneeded typecast. --- tools/virsh-domain.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
ACK. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Using of a incorrect value for the --holdtime option was silently ignored and 0 was used. In case a negative number was used, it overflowed as the API expects a unsigned int. Fix the data type and getter function type and report errors on incorrect values. --- tools/virsh-domain.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 0255542..4652914 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -6741,7 +6741,7 @@ cmdSendKey(vshControl *ctl, const vshCmd *cmd) int ret = false; const char *codeset_option; int codeset; - int holdtime; + unsigned int holdtime = 0; int count = 0; const vshCmdOpt *opt = NULL; int keycode; @@ -6753,8 +6753,10 @@ cmdSendKey(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "codeset", &codeset_option) <= 0) codeset_option = "linux"; - if (vshCommandOptInt(cmd, "holdtime", &holdtime) <= 0) - holdtime = 0; + if (vshCommandOptUInt(cmd, "holdtime", &holdtime) < 0) { + vshError(ctl, _("invalid value of --holdtime")); + goto cleanup; + } codeset = virKeycodeSetTypeFromString(codeset_option); if (codeset < 0) { -- 1.8.1.5

On 04/18/2013 02:51 AM, Peter Krempa wrote:
Using of a incorrect value for the --holdtime option was silently ignored and 0 was used. In case a negative number was used, it overflowed as the API expects a unsigned int.
Fix the data type and getter function type and report errors on incorrect values. --- tools/virsh-domain.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
ACK. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 04/18/13 14:44, Eric Blake wrote:
On 04/18/2013 02:51 AM, Peter Krempa wrote:
Using of a incorrect value for the --holdtime option was silently ignored and 0 was used. In case a negative number was used, it overflowed as the API expects a unsigned int.
Fix the data type and getter function type and report errors on incorrect values. --- tools/virsh-domain.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
ACK.
Pushed. Thanks. Peter
participants (2)
-
Eric Blake
-
Peter Krempa