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

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


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

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/15/5115/1

diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c
index 6d740d0..d68f54f 100644
--- a/channels/chan_dahdi.c
+++ b/channels/chan_dahdi.c
@@ -1937,6 +1937,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;
@@ -4258,6 +4261,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);
 
@@ -4320,6 +4327,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);
 
@@ -5103,6 +5114,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) {
@@ -5146,6 +5161,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));
 
@@ -6378,9 +6397,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);
@@ -7026,8 +7050,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);
 
@@ -7196,8 +7224,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",
@@ -7354,10 +7386,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) {
@@ -8243,6 +8279,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;
@@ -8360,8 +8400,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;
@@ -8387,6 +8432,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);
 
@@ -8870,6 +8919,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);
@@ -8937,6 +8990,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) {
@@ -17225,6 +17282,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 {
@@ -19717,12 +19778,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)
@@ -19734,6 +19795,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/5115
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic5f3d37f15de9433f742558c6142f862d63d47ac
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 13
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