Fix unsafe uses of ast_context pointers.

Although ast_context_find, ast_context_find_or_create and
ast_context_destroy perform locking of the contexts table,
any context pointer can become invalid at any time that the
contexts table is unlocked. This change adds locking around
all complete operations involving these functions.

Places where ast_context_find was followed by ast_context_destroy
have been replaced with calls ast_context_destroy_by_name.

ASTERISK-25094 #close
Reported by: Corey Farrell

Change-Id: I1866b6787730c9c4f3f836b6133ffe9c820734fa
This commit is contained in:
Corey Farrell
2015-06-08 11:09:57 -04:00
parent 8785d0ccbf
commit 80621ce3c5
9 changed files with 69 additions and 57 deletions

View File

@@ -198,7 +198,6 @@ AST_TEST_DEFINE(pattern_match_test)
*/
struct {
const char * context_string;
struct ast_context *context;
} contexts[] = {
{ TEST_PATTERN, },
{ TEST_PATTERN_INCLUDE, },
@@ -267,7 +266,7 @@ AST_TEST_DEFINE(pattern_match_test)
*/
for (i = 0; i < ARRAY_LEN(contexts); ++i) {
if (!(contexts[i].context = ast_context_find_or_create(NULL, NULL, contexts[i].context_string, registrar))) {
if (!ast_context_find_or_create(NULL, NULL, contexts[i].context_string, registrar)) {
ast_test_status_update(test, "Failed to create context %s\n", contexts[i].context_string);
res = AST_TEST_FAIL;
goto cleanup;
@@ -319,11 +318,7 @@ AST_TEST_DEFINE(pattern_match_test)
}
cleanup:
for (i = 0; i < ARRAY_LEN(contexts); ++i) {
if (contexts[i].context) {
ast_context_destroy(contexts[i].context, registrar);
}
}
ast_context_destroy(NULL, registrar);
return res;
}