comms/voip/smtp: 30 CWE-407 defects + 9 CLEAN; 224 sites, 101 ecosystems
This commit is contained in:
parent
4d3fcc8e73
commit
b3842ab6b8
86 changed files with 6516 additions and 5 deletions
70
defects/asterisk/patch/asterisk-0001.patch
Normal file
70
defects/asterisk/patch/asterisk-0001.patch
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
--- a/apps/app_meetme.c
|
||||
+++ b/apps/app_meetme.c
|
||||
@@ -944,7 +944,17 @@ static char *complete_meetmecmd_mute_kick(const char *line, const char *word, in
|
||||
|
||||
-static AST_LIST_HEAD_STATIC(confs, ast_conference);
|
||||
+/*
|
||||
+ * CWE-407 fix: replace O(n) linked-list traversal with O(1) ao2_container
|
||||
+ * hash lookup keyed on confno string.
|
||||
+ */
|
||||
+static struct ao2_container *confs_container;
|
||||
+
|
||||
+static int conf_hash_fn(const void *obj, const int flags)
|
||||
+{
|
||||
+ const struct ast_conference *cnf = obj;
|
||||
+ return ast_str_hash(cnf->confno);
|
||||
+}
|
||||
+
|
||||
+static int conf_cmp_fn(void *obj, void *arg, int flags)
|
||||
+{
|
||||
+ const struct ast_conference *left = obj;
|
||||
+ const struct ast_conference *right = arg;
|
||||
+ return strcmp(left->confno, right->confno) ? 0 : CMP_MATCH | CMP_STOP;
|
||||
+}
|
||||
|
||||
@@ -1482,7 +1482,7 @@ static struct ast_conference *build_conf(const char *confno, ...)
|
||||
- AST_LIST_LOCK(&confs);
|
||||
- AST_LIST_TRAVERSE(&confs, cnf, list) {
|
||||
- if (!strcmp(confno, cnf->confno))
|
||||
- break;
|
||||
- }
|
||||
- if (cnf || (!make && !dynamic) || !cap_slin)
|
||||
- goto cnfout;
|
||||
+ struct ast_conference lookup = {};
|
||||
+ ast_copy_string(lookup.confno, confno, sizeof(lookup.confno));
|
||||
+ ao2_lock(confs_container);
|
||||
+ cnf = ao2_find(confs_container, &lookup, OBJ_POINTER);
|
||||
+ if (cnf || (!make && !dynamic) || !cap_slin) {
|
||||
+ ao2_unlock(confs_container);
|
||||
+ goto cnfout;
|
||||
+ }
|
||||
|
||||
/* ... create new cnf ... */
|
||||
- AST_LIST_INSERT_HEAD(&confs, cnf, list);
|
||||
+ ao2_link(confs_container, cnf);
|
||||
+ ao2_unlock(confs_container);
|
||||
|
||||
@@ -4308,11 +4308,8 @@ static struct ast_conference *find_conf(...)
|
||||
- AST_LIST_LOCK(&confs);
|
||||
- AST_LIST_TRAVERSE(&confs, cnf, list) {
|
||||
- ast_debug(3, "Does conf %s match %s?\n", confno, cnf->confno);
|
||||
- if (!strcmp(confno, cnf->confno))
|
||||
- break;
|
||||
- }
|
||||
- if (cnf) {
|
||||
- cnf->refcount += refcount;
|
||||
- }
|
||||
- AST_LIST_UNLOCK(&confs);
|
||||
+ struct ast_conference lookup = {};
|
||||
+ ast_copy_string(lookup.confno, confno, sizeof(lookup.confno));
|
||||
+ ao2_lock(confs_container);
|
||||
+ cnf = ao2_find(confs_container, &lookup, OBJ_POINTER);
|
||||
+ if (cnf) cnf->refcount += refcount;
|
||||
+ ao2_unlock(confs_container);
|
||||
|
||||
@@ -load_module,0 +load_module,5 @@
|
||||
+ confs_container = ao2_container_alloc_hash(
|
||||
+ AO2_ALLOC_OPT_LOCK_MUTEX, 0,
|
||||
+ 131, conf_hash_fn, NULL, conf_cmp_fn);
|
||||
+ if (!confs_container)
|
||||
+ return AST_MODULE_LOAD_FAILURE;
|
||||
65
defects/asterisk/patch/asterisk-0002.patch
Normal file
65
defects/asterisk/patch/asterisk-0002.patch
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
--- a/apps/confbridge/include/confbridge.h
|
||||
+++ b/apps/confbridge/include/confbridge.h
|
||||
@@ -258,6 +258,10 @@ struct confbridge_conference {
|
||||
AST_LIST_HEAD_NOLOCK(, confbridge_user) active_list;
|
||||
AST_LIST_HEAD_NOLOCK(, confbridge_user) waiting_list;
|
||||
+ /*
|
||||
+ * CWE-407 fix: O(1) user lookup by channel name.
|
||||
+ * Maintained in sync with active_list + waiting_list.
|
||||
+ */
|
||||
+ struct ao2_container *users_by_name;
|
||||
|
||||
--- a/apps/app_confbridge.c
|
||||
+++ b/apps/app_confbridge.c
|
||||
@@ -conf_bridge_alloc,0 @@
|
||||
+ conference->users_by_name = ao2_container_alloc_hash(
|
||||
+ AO2_ALLOC_OPT_LOCK_NOLOCK, 0, 127,
|
||||
+ user_name_hash_fn, NULL, user_name_cmp_fn);
|
||||
|
||||
/* On user join — replace list insert + O(n) search with O(1) link */
|
||||
- AST_LIST_INSERT_TAIL(&conference->active_list, user, list);
|
||||
+ AST_LIST_INSERT_TAIL(&conference->active_list, user, list);
|
||||
+ ao2_link(conference->users_by_name, user);
|
||||
|
||||
/* On user leave */
|
||||
- AST_LIST_REMOVE(&conference->active_list, user, list);
|
||||
+ AST_LIST_REMOVE(&conference->active_list, user, list);
|
||||
+ ao2_unlink(conference->users_by_name, user);
|
||||
|
||||
/* Replace every AST_LIST_TRAVERSE + strcasecmp pattern: */
|
||||
- AST_LIST_TRAVERSE(&conference->active_list, user, list) {
|
||||
- if (strcasecmp(ast_channel_name(user->chan),
|
||||
- old_snapshot->base->name) == 0) {
|
||||
- found_user = 1;
|
||||
- break;
|
||||
- }
|
||||
- }
|
||||
- if (!found_user && conference->waitingusers) {
|
||||
- AST_LIST_TRAVERSE(&conference->waiting_list, user, list) {
|
||||
- if (strcasecmp(ast_channel_name(user->chan),
|
||||
- old_snapshot->base->name) == 0) {
|
||||
- found_user = 1;
|
||||
- break;
|
||||
- }
|
||||
- }
|
||||
- }
|
||||
+ user = ao2_find(conference->users_by_name,
|
||||
+ old_snapshot->base->name, OBJ_SEARCH_KEY);
|
||||
+ found_user = (user != NULL);
|
||||
|
||||
+static int user_name_hash_fn(const void *obj, const int flags)
|
||||
+{
|
||||
+ const struct confbridge_user *u = obj;
|
||||
+ return flags & OBJ_SEARCH_KEY
|
||||
+ ? ast_str_case_hash(obj)
|
||||
+ : ast_str_case_hash(ast_channel_name(u->chan));
|
||||
+}
|
||||
+
|
||||
+static int user_name_cmp_fn(void *obj, void *arg, int flags)
|
||||
+{
|
||||
+ const struct confbridge_user *u = obj;
|
||||
+ const char *name = (flags & OBJ_SEARCH_KEY)
|
||||
+ ? (const char *)arg
|
||||
+ : ast_channel_name(((struct confbridge_user *)arg)->chan);
|
||||
+ return strcasecmp(ast_channel_name(u->chan), name) ? 0 : CMP_MATCH | CMP_STOP;
|
||||
+}
|
||||
Loading…
Add table
Add a link
Reference in a new issue