summaryrefslogtreecommitdiff
path: root/tests/test_config.c
diff options
context:
space:
mode:
authorGeorge Joseph <george.joseph@fairview5.com>2014-10-16 17:32:16 +0000
committerGeorge Joseph <george.joseph@fairview5.com>2014-10-16 17:32:16 +0000
commitc2ec5f0f6f7f9b6b8e87490c4c09166641beee7b (patch)
treec39cdb3da9ae9b502c06201c8e06f1558f3b1bc3 /tests/test_config.c
parent86a4ce495783434f6d4fef5484b44147e4b3a7b7 (diff)
config: Fix inf loop using ast_category_browse and ast_variable_retrieve
Fix infinite loop when calling ast_variable_retrieve inside an ast_category_browse loop when there is more than 1 category with the same name. Tested-by: George Joseph Review: https://reviewboard.asterisk.org/r/4089/ ........ Merged revisions 425713 from http://svn.asterisk.org/svn/asterisk/branches/12 ........ Merged revisions 425714 from http://svn.asterisk.org/svn/asterisk/branches/13 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@425715 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'tests/test_config.c')
-rw-r--r--tests/test_config.c61
1 files changed, 58 insertions, 3 deletions
diff --git a/tests/test_config.c b/tests/test_config.c
index be4bee3d2..84c4ece08 100644
--- a/tests/test_config.c
+++ b/tests/test_config.c
@@ -460,7 +460,7 @@ AST_TEST_DEFINE(config_basic_ops)
cat = ast_category_browse_filtered(cfg, NULL, NULL, NULL);
cat = ast_category_browse_filtered(cfg, NULL, cat, NULL);
cat_name = ast_category_get_name(cat);
- var = ast_variable_new("aaa", "bbb", "dummy");
+ var = ast_variable_new("aaa", "bbb0", "dummy");
if (!var) {
ast_test_status_update(test, "Couldn't allocate variable.\n");
goto out;
@@ -469,18 +469,73 @@ AST_TEST_DEFINE(config_basic_ops)
/* Make sure we can retrieve with specific category name */
var_value = ast_variable_retrieve(cfg, cat_name, "aaa");
- if (!var_value || strcmp(var_value, "bbb")) {
+ if (!var_value || strcmp(var_value, "bbb0")) {
ast_test_status_update(test, "Variable not found or wrong value.\n");
goto out;
}
/* Make sure we can retrieve with NULL category name */
var_value = ast_variable_retrieve(cfg, NULL, "aaa");
- if (!var_value || strcmp(var_value, "bbb")) {
+ if (!var_value || strcmp(var_value, "bbb0")) {
ast_test_status_update(test, "Variable not found or wrong value.\n");
goto out;
}
+ /* Now test variable retrieve inside a browse loop
+ * with multiple categories of the same name
+ */
+ cat = ast_category_new("test3", "dummy", -1);
+ if (!cat) {
+ ast_test_status_update(test, "Couldn't allocate category.\n");
+ goto out;
+ }
+ var = ast_variable_new("aaa", "bbb1", "dummy");
+ if (!var) {
+ ast_test_status_update(test, "Couldn't allocate variable.\n");
+ goto out;
+ }
+ ast_variable_append(cat, var);
+ ast_category_append(cfg, cat);
+
+ cat = ast_category_new("test3", "dummy", -1);
+ if (!cat) {
+ ast_test_status_update(test, "Couldn't allocate category.\n");
+ goto out;
+ }
+ var = ast_variable_new("aaa", "bbb2", "dummy");
+ if (!var) {
+ ast_test_status_update(test, "Couldn't allocate variable.\n");
+ goto out;
+ }
+ ast_variable_append(cat, var);
+ ast_category_append(cfg, cat);
+
+ cat_name = NULL;
+ i = 0;
+ while ((cat_name = ast_category_browse(cfg, cat_name))) {
+ if (!strcmp(cat_name, "test3")) {
+ snprintf(temp, sizeof(temp), "bbb%d", i);
+
+ var_value = ast_variable_retrieve(cfg, cat_name, "aaa");
+ if (!var_value || strcmp(var_value, temp)) {
+ ast_test_status_update(test, "Variable not found or wrong value %s.\n", var_value);
+ goto out;
+ }
+
+ var = ast_variable_browse(cfg, cat_name);
+ if (!var->value || strcmp(var->value, temp)) {
+ ast_test_status_update(test, "Variable not found or wrong value %s.\n", var->value);
+ goto out;
+ }
+
+ i++;
+ }
+ }
+ if (i != 3) {
+ ast_test_status_update(test, "There should have been 3 matches instead of %d.\n", i);
+ goto out;
+ }
+
res = AST_TEST_PASS;
out: