mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-04 11:58:52 +00:00
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
This commit is contained in:
@@ -677,10 +677,29 @@ const char *ast_config_option(struct ast_config *cfg, const char *cat, const cha
|
||||
return tmp;
|
||||
}
|
||||
|
||||
const char *ast_variable_retrieve(struct ast_config *config,
|
||||
const char *category, const char *variable)
|
||||
const char *ast_variable_retrieve(struct ast_config *config, const char *category, const char *variable)
|
||||
{
|
||||
return ast_variable_retrieve_filtered(config, category, variable, NULL);
|
||||
struct ast_variable *v;
|
||||
|
||||
if (category) {
|
||||
for (v = ast_variable_browse(config, category); v; v = v->next) {
|
||||
if (!strcasecmp(variable, v->name)) {
|
||||
return v->value;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
struct ast_category *cat;
|
||||
|
||||
for (cat = config->root; cat; cat = cat->next) {
|
||||
for (v = cat->root; v; v = v->next) {
|
||||
if (!strcasecmp(variable, v->name)) {
|
||||
return v->value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *ast_variable_retrieve_filtered(struct ast_config *config,
|
||||
@@ -860,6 +879,12 @@ struct ast_category *ast_category_get(const struct ast_config *config,
|
||||
{
|
||||
struct ast_category *cat;
|
||||
|
||||
for (cat = config->root; cat; cat = cat->next) {
|
||||
if (cat->name == category_name && does_category_match(cat, category_name, filter)) {
|
||||
return cat;
|
||||
}
|
||||
}
|
||||
|
||||
for (cat = config->root; cat; cat = cat->next) {
|
||||
if (does_category_match(cat, category_name, filter)) {
|
||||
return cat;
|
||||
@@ -1188,7 +1213,6 @@ struct ast_category *ast_category_browse_filtered(struct ast_config *config,
|
||||
}
|
||||
|
||||
cat = next_available_category(prev, category_name, filter);
|
||||
config->last_browse = cat;
|
||||
|
||||
return cat;
|
||||
}
|
||||
|
Reference in New Issue
Block a user