]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
config.c Make ast_variable_update update last match.
authorNaveen Albert <asterisk@phreaknet.org>
Wed, 23 Oct 2024 12:34:07 +0000 (08:34 -0400)
committerasterisk-org-access-app[bot] <120671045+asterisk-org-access-app[bot]@users.noreply.github.com>
Tue, 12 Nov 2024 19:58:32 +0000 (19:58 +0000)
ast_variable_update currently sets the first match for a variable, as
opposed to the last one. This issue is complementary to that raised
in #244.

This is incorrect and results in the wrong (or no) action being taken
in cases where a section inherits from a template section. When the
traversal occurs to update the setting, the existing code erroneously
would use the first of possibly multiple matches in its update logic,
which is wrong. Now, explicitly use the last match in the traversal,
which will ensure that the actual setting is updated properly, and
not skipped or ignored because a template from which the setting's
section inherits was used for comparison.

Resolves: #960

UpgradeNote: Config variables, when set/updated, such as via AMI,
will now have the corresponding setting updated, even if their
sections inherit from template sections.

main/config.c

index e3438da6c9bb2aa32435b539dda76dff3c640958..18ab54996990ac4f553652a0fefe60285048942b 100644 (file)
@@ -1534,13 +1534,19 @@ int ast_variable_delete(struct ast_category *category, const char *variable, con
 int ast_variable_update(struct ast_category *category, const char *variable,
                                                const char *value, const char *match, unsigned int object)
 {
-       struct ast_variable *cur, *prev=NULL, *newer=NULL;
+       struct ast_variable *cur, *prev=NULL, *newer=NULL, *matchvar = NULL;
 
        for (cur = category->root; cur; prev = cur, cur = cur->next) {
                if (strcasecmp(cur->name, variable) ||
                        (!ast_strlen_zero(match) && strcasecmp(cur->value, match)))
                        continue;
+               matchvar = cur;
+       }
 
+       for (cur = category->root; cur; prev = cur, cur = cur->next) {
+               if (cur != matchvar) {
+                       continue;
+               }
                if (!(newer = ast_variable_new(variable, value, cur->file)))
                        return -1;