[asterisk-commits] rmudgett: branch rmudgett/dahdi_ccss r240410 - /team/rmudgett/dahdi_ccss/chan...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Jan 15 14:31:28 CST 2010
Author: rmudgett
Date: Fri Jan 15 14:31:25 2010
New Revision: 240410
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=240410
Log:
* Must set the monitor_instance core monitor pointer when CC is
requested or you get a crash.
* Change the libpri already cancelled flag from the pri pointer being
NULL to cc_id == -1 to avoid potential NULL pointer dereferences among
threads in the monitor_instance struct. This eliminates the need to
protect against a NULL pri pointer.
Modified:
team/rmudgett/dahdi_ccss/channels/sig_pri.c
Modified: team/rmudgett/dahdi_ccss/channels/sig_pri.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/dahdi_ccss/channels/sig_pri.c?view=diff&rev=240410&r1=240409&r2=240410
==============================================================================
--- team/rmudgett/dahdi_ccss/channels/sig_pri.c (original)
+++ team/rmudgett/dahdi_ccss/channels/sig_pri.c Fri Jan 15 14:31:25 2010
@@ -78,12 +78,9 @@
* \note Holds a reference to the CC core monitor if not NULL.
*/
struct ast_cc_monitor *monitor;
- /*!
- * \brief Asterisk span D channel control structure.
- * \note NULL if libpri association already canceled.
- */
+ /*! \brief Asterisk span D channel control structure. */
struct sig_pri_pri *pri;
- /*! CC id value to use with libpri. -1 if invalid. */
+ /*! CC id value to use with libpri. (-1 if already canceled). */
long cc_id;
/*! CC core id value. */
int core_id;
@@ -1591,7 +1588,7 @@
struct sig_pri_cc_monitor_instance *monitor_1 = obj;
struct sig_pri_cc_monitor_instance *monitor_2 = arg;
- return (monitor_1->pri && monitor_1->pri == monitor_2->pri
+ return (monitor_1->pri == monitor_2->pri
&& monitor_1->cc_id == monitor_2->cc_id) ? CMP_MATCH | CMP_STOP : 0;
}
#endif /* defined(HAVE_PRI_CCSS) */
@@ -1664,16 +1661,14 @@
{
struct sig_pri_cc_monitor_instance *monitor_instance = data;
- if (monitor_instance->pri) {
+ if (monitor_instance->cc_id != -1) {
ast_mutex_lock(&monitor_instance->pri->lock);
pri_cc_cancel(monitor_instance->pri->pri, monitor_instance->cc_id);
ast_mutex_unlock(&monitor_instance->pri->lock);
- monitor_instance->pri = NULL;
}
if (monitor_instance->monitor) {
ao2_ref(monitor_instance->monitor, -1);
- monitor_instance->monitor = NULL;
}
}
#endif /* defined(HAVE_PRI_CCSS) */
@@ -1775,7 +1770,7 @@
sig_pri_get_orig_dialstring(pri->pvts[chanpos]), service);
if (res) {
ao2_unlink(sig_pri_cc_monitors, monitor);
- monitor->pri = NULL;
+ monitor->cc_id = -1;
}
ao2_ref(monitor, -1);
break;
@@ -1910,7 +1905,7 @@
return;
}
ao2_unlink(sig_pri_cc_monitors, monitor);
- monitor->pri = NULL;
+ monitor->cc_id = -1;
ast_cc_monitor_failed(monitor->core_id, monitor->name,
sig_pri_cc_type_name);
ao2_ref(monitor, -1);
@@ -2012,7 +2007,7 @@
case 1:/* timeout */
ast_verb(2, "%s CC request timeout\n", sig_pri_cc_type_name);
ao2_unlink(sig_pri_cc_monitors, monitor);
- monitor->pri = NULL;
+ monitor->cc_id = -1;
ast_cc_monitor_failed(monitor->core_id, monitor->name,
sig_pri_cc_type_name);
break;
@@ -2020,7 +2015,7 @@
ast_verb(2, "%s CC request error: %s\n", sig_pri_cc_type_name,
pri_facility_error2str(subcmd->u.cc_request_rsp.fail_code));
ao2_unlink(sig_pri_cc_monitors, monitor);
- monitor->pri = NULL;
+ monitor->cc_id = -1;
ast_cc_monitor_failed(monitor->core_id, monitor->name,
sig_pri_cc_type_name);
break;
@@ -2028,13 +2023,13 @@
ast_verb(2, "%s CC request reject: %s\n", sig_pri_cc_type_name,
pri_facility_reject2str(subcmd->u.cc_request_rsp.fail_code));
ao2_unlink(sig_pri_cc_monitors, monitor);
- monitor->pri = NULL;
+ monitor->cc_id = -1;
ast_cc_monitor_failed(monitor->core_id, monitor->name,
sig_pri_cc_type_name);
break;
default:
ao2_unlink(sig_pri_cc_monitors, monitor);
- monitor->pri = NULL;
+ monitor->cc_id = -1;
ast_cc_monitor_failed(monitor->core_id, monitor->name,
sig_pri_cc_type_name);
break;
@@ -5424,14 +5419,15 @@
if (!instance) {
return -1;
}
- if (instance->pri) {
- /* libpri handles it's own available timer. */
- ast_mutex_lock(&instance->pri->lock);
- res = pri_cc_req(instance->pri->pri, instance->cc_id, cc_mode);
- ast_mutex_unlock(&instance->pri->lock);
- } else {
- res = -1;
- }
+
+ /* Attach the core monitor to our monitor instance. */
+ instance->monitor = monitor;
+ ao2_ref(monitor, +1);
+
+ /* libpri handles it's own available timer. */
+ ast_mutex_lock(&instance->pri->lock);
+ res = pri_cc_req(instance->pri->pri, instance->cc_id, cc_mode);
+ ast_mutex_unlock(&instance->pri->lock);
ao2_ref(instance, -1);
return res;
@@ -5456,23 +5452,17 @@
int sig_pri_cc_monitor_suspend(struct ast_cc_monitor *monitor, const int core_id)
{
struct sig_pri_cc_monitor_instance *instance;
- int res;
instance = sig_pri_find_cc_monitor_by_core_id(core_id);
if (!instance) {
return -1;
}
- if (instance->pri) {
- ast_mutex_lock(&instance->pri->lock);
- pri_cc_status(instance->pri->pri, instance->cc_id, 1/* busy */);
- ast_mutex_unlock(&instance->pri->lock);
- res = 0;
- } else {
- res = -1;
- }
+ ast_mutex_lock(&instance->pri->lock);
+ pri_cc_status(instance->pri->pri, instance->cc_id, 1/* busy */);
+ ast_mutex_unlock(&instance->pri->lock);
ao2_ref(instance, -1);
- return res;
+ return 0;
}
#endif /* defined(HAVE_PRI_CCSS) */
@@ -5493,23 +5483,17 @@
int sig_pri_cc_monitor_unsuspend(struct ast_cc_monitor *monitor, const int core_id)
{
struct sig_pri_cc_monitor_instance *instance;
- int res;
instance = sig_pri_find_cc_monitor_by_core_id(core_id);
if (!instance) {
return -1;
}
- if (instance->pri) {
- ast_mutex_lock(&instance->pri->lock);
- pri_cc_status(instance->pri->pri, instance->cc_id, 0/* free */);
- ast_mutex_unlock(&instance->pri->lock);
- res = 0;
- } else {
- res = -1;
- }
+ ast_mutex_lock(&instance->pri->lock);
+ pri_cc_status(instance->pri->pri, instance->cc_id, 0/* free */);
+ ast_mutex_unlock(&instance->pri->lock);
ao2_ref(instance, -1);
- return res;
+ return 0;
}
#endif /* defined(HAVE_PRI_CCSS) */
@@ -5535,7 +5519,6 @@
{
struct sig_pri_cc_monitor_instance *instance;
int cc_status;
- int res;
switch (devstate) {
case AST_DEVICE_UNKNOWN:
@@ -5554,17 +5537,12 @@
if (!instance) {
return -1;
}
- if (instance->pri) {
- ast_mutex_lock(&instance->pri->lock);
- pri_cc_status_req_rsp(instance->pri->pri, instance->cc_id, cc_status);
- ast_mutex_unlock(&instance->pri->lock);
- res = 0;
- } else {
- res = -1;
- }
+ ast_mutex_lock(&instance->pri->lock);
+ pri_cc_status_req_rsp(instance->pri->pri, instance->cc_id, cc_status);
+ ast_mutex_unlock(&instance->pri->lock);
ao2_ref(instance, -1);
- return res;
+ return 0;
}
#endif /* defined(HAVE_PRI_CCSS) */
More information about the asterisk-commits
mailing list