[Asterisk-code-review] cdr: Missing NULL check and unlock. (asterisk[master])
Corey Farrell
asteriskteam at digium.com
Mon Dec 25 20:24:56 CST 2017
Corey Farrell has uploaded this change for review. ( https://gerrit.asterisk.org/7738
Change subject: cdr: Missing NULL check and unlock.
......................................................................
cdr: Missing NULL check and unlock.
* handle_dial_message: Missing a check for NULL peer.
* cdr_generic_register: Missing unlock on allocation failure.
cdr_generic_register is fixed by reordering so the new structure is
allocated and initialized before locking the list.
Change-Id: I5799b99270d1a7a716a555c31ac85f4b00ce8686
---
M main/cdr.c
1 file changed, 26 insertions(+), 12 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/38/7738/1
diff --git a/main/cdr.c b/main/cdr.c
index 0f6a665..bb56844 100644
--- a/main/cdr.c
+++ b/main/cdr.c
@@ -2097,7 +2097,12 @@
if (!peer && !caller) {
return;
}
- if (filter_channel_snapshot(peer) || (caller && filter_channel_snapshot(caller))) {
+
+ if (peer && filter_channel_snapshot(peer)) {
+ return;
+ }
+
+ if (caller && filter_channel_snapshot(caller)) {
return;
}
@@ -2871,32 +2876,41 @@
static int cdr_generic_register(struct be_list *generic_list, const char *name, const char *desc, ast_cdrbe be)
{
- struct cdr_beitem *i = NULL;
+ struct cdr_beitem *i;
+ struct cdr_beitem *cur;
- if (!name)
+ if (!name) {
return -1;
+ }
if (!be) {
ast_log(LOG_WARNING, "CDR engine '%s' lacks backend\n", name);
+
return -1;
}
- AST_RWLIST_WRLOCK(generic_list);
- AST_RWLIST_TRAVERSE(generic_list, i, list) {
- if (!strcasecmp(name, i->name)) {
- ast_log(LOG_WARNING, "Already have a CDR backend called '%s'\n", name);
- AST_RWLIST_UNLOCK(generic_list);
- return -1;
- }
- }
+ i = ast_calloc(1, sizeof(*i))
+ if (!i) {
+ ast_log(LOG_WARNING, "Failed to allocate space for CDR engine '%s'\n", name);
- if (!(i = ast_calloc(1, sizeof(*i))))
return -1;
+ }
i->be = be;
ast_copy_string(i->name, name, sizeof(i->name));
ast_copy_string(i->desc, desc, sizeof(i->desc));
+ AST_RWLIST_WRLOCK(generic_list);
+ AST_RWLIST_TRAVERSE(generic_list, cur, list) {
+ if (!strcasecmp(name, cur->name)) {
+ ast_log(LOG_WARNING, "Already have a CDR backend called '%s'\n", name);
+ AST_RWLIST_UNLOCK(generic_list);
+ ast_free(i);
+
+ return -1;
+ }
+ }
+
AST_RWLIST_INSERT_HEAD(generic_list, i, list);
AST_RWLIST_UNLOCK(generic_list);
--
To view, visit https://gerrit.asterisk.org/7738
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5799b99270d1a7a716a555c31ac85f4b00ce8686
Gerrit-Change-Number: 7738
Gerrit-PatchSet: 1
Gerrit-Owner: Corey Farrell <git at cfware.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20171225/797816e4/attachment.html>
More information about the asterisk-code-review
mailing list