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

Richard Mudgett asteriskteam at digium.com
Thu Mar 2 12:29:32 CST 2017


Richard Mudgett has uploaded a new change for review. ( https://gerrit.asterisk.org/5114 )

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, 76 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/14/5114/1

diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c
index 71dbd35..a927065 100644
--- a/channels/chan_dahdi.c
+++ b/channels/chan_dahdi.c
@@ -1934,6 +1934,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;
@@ -4255,6 +4258,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);
 
@@ -4317,6 +4324,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);
 
@@ -5100,6 +5111,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) {
@@ -5143,6 +5158,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));
 
@@ -6375,9 +6394,14 @@
 
 static int dahdi_answer(struct ast_channel *ast)
 {
-	struct dahdi_pvt *p = ast_channel_tech_pvt(ast);
 	int res = 0;
 	int idx;
+	struct dahdi_pvt *p = ast_channel_tech_pvt(ast);
+	if (!p) {
+		errno = EINVAL;
+		return -1;
+	}
+
 	ast_setstate(ast, AST_STATE_UP);/*! \todo XXX this is redundantly set by the analog and PRI submodules! */
 	ast_mutex_lock(&p->lock);
 	idx = dahdi_get_index(ast, p, 0);
@@ -7023,8 +7047,12 @@
 
 static int dahdi_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
 {
-	struct dahdi_pvt *p = ast_channel_tech_pvt(newchan);
 	int x;
+	struct dahdi_pvt *p = ast_channel_tech_pvt(newchan);
+	if (!p) {
+		ast_debug(1, "Unable to find technology private\n");
+		return 0;
+	}
 
 	ast_mutex_lock(&p->lock);
 
@@ -7193,8 +7221,12 @@
 
 static void dahdi_handle_dtmf(struct ast_channel *ast, int idx, struct ast_frame **dest)
 {
-	struct dahdi_pvt *p = ast_channel_tech_pvt(ast);
 	struct ast_frame *f = *dest;
+	struct dahdi_pvt *p = ast_channel_tech_pvt(ast);
+	if (!p) {
+		ast_debug(1, "Unable to find technology private\n");
+		return;
+	}
 
 	ast_debug(1, "%s DTMF digit: 0x%02X '%c' on %s\n",
 		f->frametype == AST_FRAME_DTMF_BEGIN ? "Begin" : "End",
@@ -7351,10 +7383,14 @@
 	int res, x;
 	int idx, mysig;
 	char *c;
-	struct dahdi_pvt *p = ast_channel_tech_pvt(ast);
 	pthread_t threadid;
 	struct ast_channel *chan;
 	struct ast_frame *f;
+	struct dahdi_pvt *p = ast_channel_tech_pvt(ast);
+	if (!p) {
+		ast_debug(1, "Unable to find technology private\n");
+		return &ast_null_frame;
+	}
 
 	idx = dahdi_get_index(ast, p, 0);
 	if (idx < 0) {
@@ -8240,6 +8276,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;
@@ -8357,8 +8397,13 @@
 
 static struct ast_frame *dahdi_exception(struct ast_channel *ast)
 {
-	struct dahdi_pvt *p = ast_channel_tech_pvt(ast);
 	struct ast_frame *f;
+	struct dahdi_pvt *p = ast_channel_tech_pvt(ast);
+	if (!p) {
+		ast_debug(1, "Unable to find technology private\n");
+		return NULL;
+	}
+
 	ast_mutex_lock(&p->lock);
 	if (dahdi_analog_lib_handles(p->sig, p->radio, p->oprmode)) {
 		struct analog_pvt *analog_p = p->sig_pvt;
@@ -8384,6 +8429,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);
 
@@ -8867,6 +8916,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);
@@ -8934,6 +8987,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) {
@@ -17222,6 +17279,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 {
@@ -19714,12 +19775,12 @@
 #define	HEADER_LEN ((HEADER_MS + TRAILER_MS) * 8)
 #define	ASCII_BYTES_PER_CHAR 80
 
-	unsigned char *buf,*mybuf;
-	struct dahdi_pvt *p = ast_channel_tech_pvt(c);
+	unsigned char *buf, *mybuf;
 	struct pollfd fds[1];
-	int size,res,fd,len,x;
-	int bytes=0;
+	int size, res, fd, len, x;
+	int bytes = 0;
 	int idx;
+	struct dahdi_pvt *p;
 
 	/*
 	 * Initial carrier (imaginary)
@@ -19731,6 +19792,12 @@
 	float ci = 0.0;
 	float scont = 0.0;
 
+	p = ast_channel_tech_pvt(c);
+	if (!p) {
+		ast_debug(1, "Unable to find technology private\n");
+		return -1;
+	}
+
 	if (!text[0]) {
 		return(0); /* if nothing to send, don't */
 	}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic5f3d37f15de9433f742558c6142f862d63d47ac
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 14
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
Gerrit-Reviewer: Tzafrir Cohen <tzafrir.cohen at xorcom.com>



More information about the asterisk-code-review mailing list