From f2fe7197971bb0a776e675b1cb6c97280867b38d Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Tue, 1 Nov 2016 15:47:01 +0100 Subject: [PATCH] tools/mgmt-tester: Fix use of uninitialized memory unmet_setup_conditions in test_data was not properly initialized by test_* macros. To avoid this issue in future use new0 for test_data allocation and explicitly initialize variables with non-zero values only. --- tools/mgmt-tester.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c index d87d8003d..9d8f73eef 100644 --- a/tools/mgmt-tester.c +++ b/tools/mgmt-tester.c @@ -325,9 +325,7 @@ static void test_condition_complete(struct test_data *data) #define test_bredrle_full(name, data, setup, func, timeout) \ do { \ struct test_data *user; \ - user = malloc(sizeof(struct test_data)); \ - if (!user) \ - break; \ + user = new0(struct test_data, 1); \ user->hciemu_type = HCIEMU_TYPE_BREDRLE; \ user->test_setup = setup; \ user->test_data = data; \ @@ -335,7 +333,6 @@ static void test_condition_complete(struct test_data *data) user->expected_manufacturer = 0x003f; \ user->expected_supported_settings = 0x0000bfff; \ user->initial_settings = 0x00000080; \ - user->unmet_conditions = 0; \ tester_add_full(name, data, \ test_pre_setup, test_setup, func, NULL, \ test_post_teardown, timeout, user, free); \ @@ -347,9 +344,7 @@ static void test_condition_complete(struct test_data *data) #define test_bredr20(name, data, setup, func) \ do { \ struct test_data *user; \ - user = malloc(sizeof(struct test_data)); \ - if (!user) \ - break; \ + user = new0(struct test_data, 1); \ user->hciemu_type = HCIEMU_TYPE_LEGACY; \ user->test_setup = setup; \ user->test_data = data; \ @@ -357,7 +352,6 @@ static void test_condition_complete(struct test_data *data) user->expected_manufacturer = 0x003f; \ user->expected_supported_settings = 0x000010bf; \ user->initial_settings = 0x00000080; \ - user->unmet_conditions = 0; \ tester_add_full(name, data, \ test_pre_setup, test_setup, func, NULL, \ test_post_teardown, 2, user, free); \ @@ -366,9 +360,7 @@ static void test_condition_complete(struct test_data *data) #define test_bredr(name, data, setup, func) \ do { \ struct test_data *user; \ - user = malloc(sizeof(struct test_data)); \ - if (!user) \ - break; \ + user = new0(struct test_data, 1); \ user->hciemu_type = HCIEMU_TYPE_BREDR; \ user->test_setup = setup; \ user->test_data = data; \ @@ -376,7 +368,6 @@ static void test_condition_complete(struct test_data *data) user->expected_manufacturer = 0x003f; \ user->expected_supported_settings = 0x000011ff; \ user->initial_settings = 0x00000080; \ - user->unmet_conditions = 0; \ tester_add_full(name, data, \ test_pre_setup, test_setup, func, NULL, \ test_post_teardown, 2, user, free); \ @@ -385,9 +376,7 @@ static void test_condition_complete(struct test_data *data) #define test_le(name, data, setup, func) \ do { \ struct test_data *user; \ - user = malloc(sizeof(struct test_data)); \ - if (!user) \ - break; \ + user = new0(struct test_data, 1); \ user->hciemu_type = HCIEMU_TYPE_LE; \ user->test_setup = setup; \ user->test_data = data; \ @@ -395,7 +384,6 @@ static void test_condition_complete(struct test_data *data) user->expected_manufacturer = 0x003f; \ user->expected_supported_settings = 0x0000be1b; \ user->initial_settings = 0x00000200; \ - user->unmet_conditions = 0; \ tester_add_full(name, data, \ test_pre_setup, test_setup, func, NULL, \ test_post_teardown, 2, user, free); \ -- 2.47.3