mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-20 12:20:12 +00:00
config: bug: Fix SEGV in ast_category_insert when matching category isn't found
If you call ast_category_insert with a match category that doesn't exist, the list traverse runs out of 'next' categories and you get a SEGV. This patch adds check for the end-of-list condition and changes the signature to return an int for success/failure indication instead of a void. The only consumer of this function is manager and it was also changed to use the return value. Tested by: George Joseph Review: https://reviewboard.asterisk.org/r/3993/ ........ Merged revisions 423276 from http://svn.asterisk.org/svn/asterisk/branches/1.8 ........ Merged revisions 423277 from http://svn.asterisk.org/svn/asterisk/branches/11 ........ Merged revisions 423278 from http://svn.asterisk.org/svn/asterisk/branches/12 ........ Merged revisions 423279 from http://svn.asterisk.org/svn/asterisk/branches/13 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@423280 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -675,8 +675,11 @@ void ast_category_append(struct ast_config *config, struct ast_category *cat);
|
|||||||
* \details
|
* \details
|
||||||
* This function is used to insert a new category above another category
|
* This function is used to insert a new category above another category
|
||||||
* matching the match parameter.
|
* matching the match parameter.
|
||||||
|
*
|
||||||
|
* \retval 0 if succeeded
|
||||||
|
* \retval -1 if NULL parameters or match category was not found
|
||||||
*/
|
*/
|
||||||
void ast_category_insert(struct ast_config *config, struct ast_category *cat, const char *match);
|
int ast_category_insert(struct ast_config *config, struct ast_category *cat, const char *match);
|
||||||
int ast_category_delete(struct ast_config *cfg, const char *category);
|
int ast_category_delete(struct ast_config *cfg, const char *category);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@@ -783,24 +783,28 @@ void ast_category_append(struct ast_config *config, struct ast_category *categor
|
|||||||
config->current = category;
|
config->current = category;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ast_category_insert(struct ast_config *config, struct ast_category *cat, const char *match)
|
int ast_category_insert(struct ast_config *config, struct ast_category *cat, const char *match)
|
||||||
{
|
{
|
||||||
struct ast_category *cur_category;
|
struct ast_category *cur_category;
|
||||||
|
|
||||||
if (!cat || !match)
|
if (!config || !cat || !match) {
|
||||||
return;
|
return -1;
|
||||||
|
}
|
||||||
if (!strcasecmp(config->root->name, match)) {
|
if (!strcasecmp(config->root->name, match)) {
|
||||||
cat->next = config->root;
|
cat->next = config->root;
|
||||||
config->root = cat;
|
config->root = cat;
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
for (cur_category = config->root; cur_category; cur_category = cur_category->next) {
|
for (cur_category = config->root; cur_category && cur_category->next;
|
||||||
|
cur_category = cur_category->next) {
|
||||||
if (!strcasecmp(cur_category->next->name, match)) {
|
if (!strcasecmp(cur_category->next->name, match)) {
|
||||||
cat->next = cur_category->next;
|
cat->next = cur_category->next;
|
||||||
cur_category->next = cat;
|
cur_category->next = cat;
|
||||||
break;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ast_destroy_template_list(struct ast_category *cat)
|
static void ast_destroy_template_list(struct ast_category *cat)
|
||||||
|
@@ -3321,7 +3321,11 @@ static enum error_type handle_updates(struct mansession *s, const struct message
|
|||||||
if (ast_strlen_zero(match)) {
|
if (ast_strlen_zero(match)) {
|
||||||
ast_category_append(cfg, category);
|
ast_category_append(cfg, category);
|
||||||
} else {
|
} else {
|
||||||
ast_category_insert(cfg, category, match);
|
if (ast_category_insert(cfg, category, match)) {
|
||||||
|
result = FAILURE_NEWCAT;
|
||||||
|
ast_category_destroy(category);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (!strcasecmp(action, "renamecat")) {
|
} else if (!strcasecmp(action, "renamecat")) {
|
||||||
if (ast_strlen_zero(value)) {
|
if (ast_strlen_zero(value)) {
|
||||||
|
Reference in New Issue
Block a user