[Kimchi-devel] [PATCH] [Kimchi] Bug fix: Convert CPU and memory values to number before doing any data validation

Socorro Stoppler socorro at linux.vnet.ibm.com
Tue Apr 26 17:10:16 UTC 2016


Hi Aline,

Rodrigo also had a fix for this that I had already tested/reviewed. I 
guess you can decide which fix you want upstream :)

Thanks
-Socorro

On 04/26/2016 10:04 AM, Aline Manera wrote:
> The value entered for CPUs must not be greater than maximum CPUs value;
> and the value entered for memory must not be greater than the maximum
> memory value.
>
> But the input boxes return the data in string format which may cause
> issues while doing data validation. So convert the inputed values to
> number to do the input validation.
>
> Signed-off-by: Aline Manera <alinefm at linux.vnet.ibm.com>
> ---
>   ui/js/src/kimchi.guest_edit_main.js | 24 ++++++++++++++++--------
>   1 file changed, 16 insertions(+), 8 deletions(-)
>
> diff --git a/ui/js/src/kimchi.guest_edit_main.js b/ui/js/src/kimchi.guest_edit_main.js
> index ef6d650..47c8422 100644
> --- a/ui/js/src/kimchi.guest_edit_main.js
> +++ b/ui/js/src/kimchi.guest_edit_main.js
> @@ -746,17 +746,25 @@ kimchi.guest_edit_main = function() {
>           }
>
>           // Test memory values before submit. Avoid requests we know are going to fail
> -        if ($('#guest-edit-memory-textbox').val() > $('#guest-edit-max-memory-textbox').val()) {
> -            wok.message.error(i18n['KCHVM0002E'], '#alert-modal-container');
> -            $(saveButton).prop('disabled', false);
> -            return;
> +        var memValue = Number($('#guest-edit-memory-textbox').val());
> +        var maxmemValue = Number($('#guest-edit-max-memory-textbox').val());
> +        if (memValue !== undefined && memValue !== "" && maxmemValue !== undefined && maxmemValue !== "") {
> +            if (memValue > maxmemValue) {
> +                wok.message.error(i18n['KCHVM0002E'], '#alert-modal-container');
> +                $(saveButton).prop('disabled', false);
> +                return;
> +            }
>           }
>
>           // Test CPU values before submit. Avoid requests we know are going to fail
> -        if ($('#guest-edit-cores-textbox').val() > $('#guest-edit-max-processor-textbox').val()) {
> -            wok.message.error(i18n['KCHVM0003E'], '#alert-modal-container');
> -            $(saveButton).prop('disabled', false);
> -            return;
> +        var coresValue = Number($('#guest-edit-cores-textbox').val());
> +        var maxprocessorValue = Number($('#guest-edit-max-processor-textbox').val());
> +        if (coresValue !== undefined && coresValue !== "" && maxprocessorValue !== undefined && maxprocessorValue !== "") {
> +            if (coresValue > maxprocessorValue) {
> +                wok.message.error(i18n['KCHVM0003E'], '#alert-modal-container');
> +                $(saveButton).prop('disabled', false);
> +                return;
> +            }
>           }
>
>           if (data['vcpus'] !== undefined) {




More information about the Kimchi-devel mailing list