From 3403e5eb884f3a74c40fe7cccc103f848c040215 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Tue, 21 Feb 2017 21:13:53 +0100 Subject: option: Fix to reject invalid and overflowing numbers parse_option_number() fails to check for these errors after strtoull(). Has always been broken. Fix that. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <1487708048-2131-10-git-send-email-armbru@redhat.com> --- tests/test-qemu-opts.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'tests') diff --git a/tests/test-qemu-opts.c b/tests/test-qemu-opts.c index 310485b..8b92f7b 100644 --- a/tests/test-qemu-opts.c +++ b/tests/test-qemu-opts.c @@ -603,17 +603,15 @@ static void test_opts_parse_number(void) /* Above upper limit */ opts = qemu_opts_parse(&opts_list_01, "number1=18446744073709551616", - false, &error_abort); - /* BUG: should reject */ - g_assert_cmpuint(opts_count(opts), ==, 1); - g_assert_cmpuint(qemu_opt_get_number(opts, "number1", 1), ==, UINT64_MAX); + false, &err); + error_free_or_abort(&err); + g_assert(!opts); /* Below lower limit */ opts = qemu_opts_parse(&opts_list_01, "number1=-18446744073709551616", - false, &error_abort); - /* BUG: should reject */ - g_assert_cmpuint(opts_count(opts), ==, 1); - g_assert_cmpuint(qemu_opt_get_number(opts, "number1", 1), ==, UINT64_MAX); + false, &err); + error_free_or_abort(&err); + g_assert(!opts); /* Hex and octal */ opts = qemu_opts_parse(&opts_list_01, "number1=0x2a,number2=052", @@ -624,9 +622,8 @@ static void test_opts_parse_number(void) /* Invalid */ opts = qemu_opts_parse(&opts_list_01, "number1=", false, &err); - /* BUG: should reject */ - g_assert_cmpuint(opts_count(opts), ==, 1); - g_assert_cmpuint(qemu_opt_get_number(opts, "number1", 1), ==, 0); + error_free_or_abort(&err); + g_assert(!opts); opts = qemu_opts_parse(&opts_list_01, "number1=eins", false, &err); error_free_or_abort(&err); g_assert(!opts); -- cgit v1.1