From a5962c87e2ce6d178eaf8031170fe405e9b1e2e4 Mon Sep 17 00:00:00 2001 From: Jeff Peeler Date: Mon, 21 Jul 2008 15:34:21 +0000 Subject: [PATCH] Merged revisions 132425 via svnmerge from https://origsvn.digium.com/svn/asterisk/trunk ........ r132425 | jpeeler | 2008-07-21 10:33:13 -0500 (Mon, 21 Jul 2008) | 2 lines make buffers config option (chan_dahdi.conf) parsing safer and added logging in case of failure ........ git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.0@132426 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- channels/chan_dahdi.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c index d00f7103cc..3ca6b53f1a 100644 --- a/channels/chan_dahdi.c +++ b/channels/chan_dahdi.c @@ -13583,7 +13583,6 @@ static void process_echocancel(struct dahdi_chan_conf *confp, const char *data, static int process_dahdi(struct dahdi_chan_conf *confp, struct ast_variable *v, int reload, int skipchannels) { struct dahdi_pvt *tmp; - const char *tempstr; /* temporary string for parsing the dring number, buffers policy */ int y; int found_pseudo = 0; char dahdichan[MAX_CHANLIST_LEN] = {}; @@ -13605,17 +13604,24 @@ static int process_dahdi(struct dahdi_chan_conf *confp, struct ast_variable *v, if (build_channels(confp, iscrv, v->value, reload, v->lineno, &found_pseudo)) return -1; } else if (!strcasecmp(v->name, "buffers")) { - char policy[8]; - tempstr = v->value; - sscanf(tempstr, "%d,%s", &confp->chan.buf_no, policy); + int res; + char policy[8] = ""; + res = sscanf(v->value, "%d,%s", &confp->chan.buf_no, policy); + if (res != 2) { + ast_log(LOG_WARNING, "Parsing buffers option data failed, using defaults.\n"); + confp->chan.buf_no = numbufs; + continue; + } if (confp->chan.buf_no < 0) confp->chan.buf_no = numbufs; if (!strcasecmp(policy, "full")) { confp->chan.buf_policy = DAHDI_POLICY_WHEN_FULL; } else if (!strcasecmp(policy, "half")) { confp->chan.buf_policy = DAHDI_POLICY_IMMEDIATE /*HALF_FULL*/; - } else { + } else if (!strcasecmp(policy, "immediate")) { confp->chan.buf_policy = DAHDI_POLICY_IMMEDIATE; + } else { + ast_log(LOG_WARNING, "Invalid policy name given (%s).\n", policy); } } else if (!strcasecmp(v->name, "dahdichan")) { ast_copy_string(dahdichan, v->value, sizeof(dahdichan)); @@ -13636,14 +13642,11 @@ static int process_dahdi(struct dahdi_chan_conf *confp, struct ast_variable *v, } else if (!strcasecmp(v->name, "dring3range")) { confp->chan.drings.ringnum[2].range = atoi(v->value); } else if (!strcasecmp(v->name, "dring1")) { - tempstr = v->value; - sscanf(tempstr, "%d,%d,%d", &confp->chan.drings.ringnum[0].ring[0], &confp->chan.drings.ringnum[0].ring[1], &confp->chan.drings.ringnum[0].ring[2]); + sscanf(v->value, "%d,%d,%d", &confp->chan.drings.ringnum[0].ring[0], &confp->chan.drings.ringnum[0].ring[1], &confp->chan.drings.ringnum[0].ring[2]); } else if (!strcasecmp(v->name, "dring2")) { - tempstr = v->value; - sscanf(tempstr,"%d,%d,%d", &confp->chan.drings.ringnum[1].ring[0], &confp->chan.drings.ringnum[1].ring[1], &confp->chan.drings.ringnum[1].ring[2]); + sscanf(v->value,"%d,%d,%d", &confp->chan.drings.ringnum[1].ring[0], &confp->chan.drings.ringnum[1].ring[1], &confp->chan.drings.ringnum[1].ring[2]); } else if (!strcasecmp(v->name, "dring3")) { - tempstr = v->value; - sscanf(tempstr, "%d,%d,%d", &confp->chan.drings.ringnum[2].ring[0], &confp->chan.drings.ringnum[2].ring[1], &confp->chan.drings.ringnum[2].ring[2]); + sscanf(v->value, "%d,%d,%d", &confp->chan.drings.ringnum[2].ring[0], &confp->chan.drings.ringnum[2].ring[1], &confp->chan.drings.ringnum[2].ring[2]); } else if (!strcasecmp(v->name, "usecallerid")) { confp->chan.use_callerid = ast_true(v->value); } else if (!strcasecmp(v->name, "cidsignalling")) {