[Asterisk-code-review] chan dahdi: check result of ast channel tech pvt (asterisk[master])

Tzafrir Cohen asteriskteam at digium.com
Wed Mar 1 13:15:20 CST 2017


Tzafrir Cohen has uploaded a new change for review. ( https://gerrit.asterisk.org/5113 )

Change subject: chan_dahdi: check result of ast_channel_tech_pvt
......................................................................

chan_dahdi: check result of ast_channel_tech_pvt

When disconnecting a PRI channel while in a call, we may still be
reading from them in a different thread. So check that a channel's
private doesn't just disappear under our feet.

ASTERISK-24473 #close

Change-Id: Ic5f3d37f15de9433f742558c6142f862d63d47ac
---
M channels/chan_dahdi.c
1 file changed, 63 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/13/5113/1

diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c
index 97c80c8..36a873c 100644
--- a/channels/chan_dahdi.c
+++ b/channels/chan_dahdi.c
@@ -1932,6 +1932,9 @@
 
 	if (bridged && ast_channel_tech(bridged) == &dahdi_tech) {
 		struct dahdi_pvt *p = ast_channel_tech_pvt(bridged);
+		if (!p) {
+			return NULL;
+		}
 
 		if (dahdi_analog_lib_handles(p->sig, p->radio, p->oprmode)) {
 			return p->sig_pvt;
@@ -4253,6 +4256,10 @@
 	int res;
 
 	pvt = ast_channel_tech_pvt(chan);
+	if (!pvt) {
+		ast_debug(1, "Unable to find technology private\n");
+		return -1;
+	}
 
 	ast_mutex_lock(&pvt->lock);
 
@@ -4315,6 +4322,10 @@
 	int x;
 
 	pvt = ast_channel_tech_pvt(chan);
+	if (!pvt) {
+		ast_debug(1, "Unable to find technology private\n");
+		return -1;
+	}
 
 	ast_mutex_lock(&pvt->lock);
 
@@ -5098,6 +5109,10 @@
 static int dahdi_callwait(struct ast_channel *ast)
 {
 	struct dahdi_pvt *p = ast_channel_tech_pvt(ast);
+	if (!p) {
+		ast_debug(1, "Unable to find technology private\n");
+		return -1;
+	}
 
 	p->callwaitingrepeat = CALLWAITING_REPEAT_SAMPLES;
 	if (p->cidspill) {
@@ -5141,6 +5156,10 @@
 		AST_APP_ARG(other);	/* Any remining unused arguments */
 	);
 
+	if (!p) {
+		ast_debug(1, "Unable to find technology private\n");
+		return -1;
+	}
 	ast_mutex_lock(&p->lock);
 	ast_copy_string(p->dialdest, rdest, sizeof(p->dialdest));
 
@@ -6374,6 +6393,10 @@
 static int dahdi_answer(struct ast_channel *ast)
 {
 	struct dahdi_pvt *p = ast_channel_tech_pvt(ast);
+	if (!p) {
+		errno = EINVAL;
+		return -1;
+	}
 	int res = 0;
 	int idx;
 	ast_setstate(ast, AST_STATE_UP);/*! \todo XXX this is redundantly set by the analog and PRI submodules! */
@@ -7022,6 +7045,10 @@
 static int dahdi_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
 {
 	struct dahdi_pvt *p = ast_channel_tech_pvt(newchan);
+	if (!p) {
+		ast_debug(1, "Unable to find technology private\n");
+		return 0;
+	}
 	int x;
 
 	ast_mutex_lock(&p->lock);
@@ -7192,6 +7219,10 @@
 static void dahdi_handle_dtmf(struct ast_channel *ast, int idx, struct ast_frame **dest)
 {
 	struct dahdi_pvt *p = ast_channel_tech_pvt(ast);
+	if (!p) {
+		ast_debug(1, "Unable to find technology private\n");
+		return;
+	}
 	struct ast_frame *f = *dest;
 
 	ast_debug(1, "%s DTMF digit: 0x%02X '%c' on %s\n",
@@ -7350,6 +7381,10 @@
 	int idx, mysig;
 	char *c;
 	struct dahdi_pvt *p = ast_channel_tech_pvt(ast);
+	if (!p) {
+		ast_debug(1, "Unable to find technology private\n");
+		return &ast_null_frame;
+	}
 	pthread_t threadid;
 	struct ast_channel *chan;
 	struct ast_frame *f;
@@ -8238,6 +8273,10 @@
 	struct ast_frame *f;
 	int usedindex = -1;
 	struct dahdi_pvt *p = ast_channel_tech_pvt(ast);
+	if (!p) {
+		ast_debug(1, "Unable to find technology private\n");
+		return &ast_null_frame;
+	}
 
 	if ((idx = dahdi_get_index(ast, p, 0)) < 0) {
 		idx = SUB_REAL;
@@ -8356,6 +8395,10 @@
 static struct ast_frame *dahdi_exception(struct ast_channel *ast)
 {
 	struct dahdi_pvt *p = ast_channel_tech_pvt(ast);
+	if (!p) {
+		ast_debug(1, "Unable to find technology private\n");
+		return NULL;
+	}
 	struct ast_frame *f;
 	ast_mutex_lock(&p->lock);
 	if (dahdi_analog_lib_handles(p->sig, p->radio, p->oprmode)) {
@@ -8382,6 +8425,10 @@
 	 * the same private structure.
 	 */
 	p = ast_channel_tech_pvt(ast);
+	if (!p) {
+		ast_debug(1, "Unable to find technology private\n");
+		return NULL;
+	}
 	while (ast_mutex_trylock(&p->lock)) {
 		CHANNEL_DEADLOCK_AVOIDANCE(ast);
 
@@ -8865,6 +8912,10 @@
 	}
 
 	p = ast_channel_tech_pvt(ast);
+	if (!p) {
+		ast_debug(1, "Unable to find technology private\n");
+		return -1;
+	}
 	ast_mutex_lock(&p->lock);
 
 	idx = dahdi_get_index(ast, p, 0);
@@ -8932,6 +8983,10 @@
 	int idx;
 	int func = DAHDI_FLASH;
 
+	if (!p) {
+		ast_debug(1, "Unable to find technology private\n");
+		return -1;
+	}
 	ast_mutex_lock(&p->lock);
 	ast_debug(1, "Requested indication %d on channel %s\n", condition, ast_channel_name(chan));
 	switch (p->sig) {
@@ -17188,6 +17243,10 @@
 	ast_assert(!strcmp(ast_channel_tech(chan)->type, "DAHDI"));
 
 	pvt = ast_channel_tech_pvt(chan);
+	if (!pvt) {
+		ast_debug(1, "Unable to find technology private\n");
+		return -1;
+	}
 	if (dahdi_sig_pri_lib_handles(pvt->sig)) {
 		pvt_chan = pvt->sig_pvt;
 	} else {
@@ -19640,6 +19699,10 @@
 
 	unsigned char *buf,*mybuf;
 	struct dahdi_pvt *p = ast_channel_tech_pvt(c);
+	if (!p) {
+		ast_debug(1, "Unable to find technology private\n");
+		return -1;
+	}
 	struct pollfd fds[1];
 	int size,res,fd,len,x;
 	int bytes=0;

-- 
To view, visit https://gerrit.asterisk.org/5113
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic5f3d37f15de9433f742558c6142f862d63d47ac
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Tzafrir Cohen <tzafrir.cohen at xorcom.com>



More information about the asterisk-code-review mailing list