Merged revisions 185952 via svnmerge from

https://origsvn.digium.com/svn/asterisk/branches/1.4

........
  r185952 | kpfleming | 2009-04-02 08:43:43 -0500 (Thu, 02 Apr 2009) | 5 lines
  
  the DAHDI_GETCONF, DAHDI_SETCONF and DAHDI_GET_PARAMS ioctls were recently corrected to show that they do, in fact, read data from userspace as part of their work. due to this fix, valgrind now reports a number of cases where chan_dahdi passed an uninitialized (or partially) buffer to these ioctls, which could lead to unexpected behavior.
  
  this patch corrects chan_dahdi to ensure that buffers passed to these ioctls are always fully initialized.
........


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@185953 65c4cc65-6c06-0410-ace0-fbb531ad65f3
certified/1.8.6
Kevin P. Fleming 16 years ago
parent be40f3a33c
commit d99d2f22cd

@ -2532,9 +2532,6 @@ static int conf_del(struct dahdi_pvt *p, struct dahdi_subchannel *c, int idx)
/* Don't delete if we don't think it's conferenced at all (implied) */ /* Don't delete if we don't think it's conferenced at all (implied) */
) return 0; ) return 0;
memset(&zi, 0, sizeof(zi)); memset(&zi, 0, sizeof(zi));
zi.chan = 0;
zi.confno = 0;
zi.confmode = 0;
if (ioctl(c->dfd, DAHDI_SETCONF, &zi)) { if (ioctl(c->dfd, DAHDI_SETCONF, &zi)) {
ast_log(LOG_WARNING, "Failed to drop %d from conference %d/%d: %s\n", c->dfd, c->curconf.confmode, c->curconf.confno, strerror(errno)); ast_log(LOG_WARNING, "Failed to drop %d from conference %d/%d: %s\n", c->dfd, c->curconf.confmode, c->curconf.confno, strerror(errno));
return -1; return -1;
@ -2590,11 +2587,12 @@ static int isslavenative(struct dahdi_pvt *p, struct dahdi_pvt **out)
static int reset_conf(struct dahdi_pvt *p) static int reset_conf(struct dahdi_pvt *p)
{ {
struct dahdi_confinfo zi;
memset(&zi, 0, sizeof(zi));
p->confno = -1; p->confno = -1;
memset(&p->subs[SUB_REAL].curconf, 0, sizeof(p->subs[SUB_REAL].curconf)); memset(&p->subs[SUB_REAL].curconf, 0, sizeof(p->subs[SUB_REAL].curconf));
if (p->subs[SUB_REAL].dfd > -1) { if (p->subs[SUB_REAL].dfd > -1) {
struct dahdi_confinfo zi;
memset(&zi, 0, sizeof(zi));
if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETCONF, &zi)) if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETCONF, &zi))
ast_log(LOG_WARNING, "Failed to reset conferencing on channel %d: %s\n", p->channel, strerror(errno)); ast_log(LOG_WARNING, "Failed to reset conferencing on channel %d: %s\n", p->channel, strerror(errno));
} }
@ -2908,8 +2906,7 @@ static int save_conference(struct dahdi_pvt *p)
p->saveconf.confmode = 0; p->saveconf.confmode = 0;
return -1; return -1;
} }
c.chan = 0; memset(&c, 0, sizeof(c));
c.confno = 0;
c.confmode = DAHDI_CONF_NORMAL; c.confmode = DAHDI_CONF_NORMAL;
res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETCONF, &c); res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETCONF, &c);
if (res) { if (res) {
@ -4599,6 +4596,7 @@ static int dahdi_hangup(struct ast_channel *ast)
case SIG_FXOGS: case SIG_FXOGS:
case SIG_FXOLS: case SIG_FXOLS:
case SIG_FXOKS: case SIG_FXOKS:
memset(&par, 0, sizeof(par));
res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &par); res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &par);
if (!res) { if (!res) {
#if 0 #if 0
@ -5576,6 +5574,7 @@ static int get_alarms(struct dahdi_pvt *p)
} }
/* No alarms on the span. Check for channel alarms. */ /* No alarms on the span. Check for channel alarms. */
memset(&params, 0, sizeof(params));
if ((res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &params)) >= 0) if ((res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &params)) >= 0)
return params.chan_alarms; return params.chan_alarms;
@ -6202,6 +6201,7 @@ static struct ast_frame *dahdi_handle_event(struct ast_channel *ast)
{ {
struct dahdi_params par; struct dahdi_params par;
memset(&par, 0, sizeof(par));
if (ioctl(p->oprpeer->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &par) != -1) if (ioctl(p->oprpeer->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &par) != -1)
{ {
if (!par.rxisoffhook) if (!par.rxisoffhook)
@ -6694,6 +6694,7 @@ static struct ast_frame *dahdi_read(struct ast_channel *ast)
{ {
struct dahdi_params ps; struct dahdi_params ps;
memset(&ps, 0, sizeof(ps));
ps.channo = p->channel; ps.channo = p->channel;
if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &ps) < 0) { if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &ps) < 0) {
ast_mutex_unlock(&p->lock); ast_mutex_unlock(&p->lock);
@ -7387,6 +7388,7 @@ static struct ast_channel *dahdi_new(struct dahdi_pvt *i, int state, int startpb
if (!tmp) if (!tmp)
return NULL; return NULL;
tmp->tech = &dahdi_tech; tmp->tech = &dahdi_tech;
memset(&ps, 0, sizeof(ps));
ps.channo = i->channel; ps.channo = i->channel;
res = ioctl(i->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &ps); res = ioctl(i->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &ps);
if (res) { if (res) {
@ -10216,10 +10218,11 @@ static struct dahdi_pvt *mkintf(int channel, const struct dahdi_chan_conf *conf,
#endif #endif
} else { } else {
chan_sig = tmp->sig; chan_sig = tmp->sig;
if (tmp->subs[SUB_REAL].dfd > -1) {
memset(&p, 0, sizeof(p)); memset(&p, 0, sizeof(p));
if (tmp->subs[SUB_REAL].dfd > -1)
res = ioctl(tmp->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &p); res = ioctl(tmp->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &p);
} }
}
/* Adjust starttime on loopstart and kewlstart trunks to reasonable values */ /* Adjust starttime on loopstart and kewlstart trunks to reasonable values */
switch (chan_sig) { switch (chan_sig) {
case SIG_FXSKS: case SIG_FXSKS:
@ -10599,9 +10602,10 @@ static inline int available(struct dahdi_pvt *p, int channelmatch, ast_group_t g
if (!p->sig || (p->sig == SIG_FXSLS)) if (!p->sig || (p->sig == SIG_FXSLS))
return 1; return 1;
/* Check hook state */ /* Check hook state */
if (p->subs[SUB_REAL].dfd > -1) if (p->subs[SUB_REAL].dfd > -1) {
memset(&par, 0, sizeof(par));
res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &par); res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &par);
else { } else {
/* Assume not off hook on CVRS */ /* Assume not off hook on CVRS */
res = 0; res = 0;
par.rxisoffhook = 0; par.rxisoffhook = 0;
@ -11937,6 +11941,7 @@ static int pri_find_principle(struct dahdi_pri *pri, int channel)
if (!explicit) { if (!explicit) {
spanfd = pri_active_dchan_fd(pri); spanfd = pri_active_dchan_fd(pri);
memset(&param, 0, sizeof(param));
if (ioctl(spanfd, DAHDI_GET_PARAMS, &param)) if (ioctl(spanfd, DAHDI_GET_PARAMS, &param))
return -1; return -1;
span = pris[param.spanno - 1].prilogicalspan; span = pris[param.spanno - 1].prilogicalspan;
@ -13402,6 +13407,7 @@ static int start_pri(struct dahdi_pri *pri)
ast_log(LOG_ERROR, "Unable to open D-channel %d (%s)\n", x, strerror(errno)); ast_log(LOG_ERROR, "Unable to open D-channel %d (%s)\n", x, strerror(errno));
return -1; return -1;
} }
memset(&p, 0, sizeof(p));
res = ioctl(pri->fds[i], DAHDI_GET_PARAMS, &p); res = ioctl(pri->fds[i], DAHDI_GET_PARAMS, &p);
if (res) { if (res) {
dahdi_close_pri_fd(pri, i); dahdi_close_pri_fd(pri, i);
@ -14634,12 +14640,14 @@ static char *dahdi_show_channel(struct ast_cli_entry *e, int cmd, struct ast_cli
memset(&ci, 0, sizeof(ci)); memset(&ci, 0, sizeof(ci));
ps.channo = tmp->channel; ps.channo = tmp->channel;
if (tmp->subs[SUB_REAL].dfd > -1) { if (tmp->subs[SUB_REAL].dfd > -1) {
memset(&ci, 0, sizeof(ci));
if (!ioctl(tmp->subs[SUB_REAL].dfd, DAHDI_GETCONF, &ci)) { if (!ioctl(tmp->subs[SUB_REAL].dfd, DAHDI_GETCONF, &ci)) {
ast_cli(a->fd, "Actual Confinfo: Num/%d, Mode/0x%04x\n", ci.confno, ci.confmode); ast_cli(a->fd, "Actual Confinfo: Num/%d, Mode/0x%04x\n", ci.confno, ci.confmode);
} }
if (!ioctl(tmp->subs[SUB_REAL].dfd, DAHDI_GETCONFMUTE, &x)) { if (!ioctl(tmp->subs[SUB_REAL].dfd, DAHDI_GETCONFMUTE, &x)) {
ast_cli(a->fd, "Actual Confmute: %s\n", x ? "Yes" : "No"); ast_cli(a->fd, "Actual Confmute: %s\n", x ? "Yes" : "No");
} }
memset(&ps, 0, sizeof(ps));
if (ioctl(tmp->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &ps) < 0) { if (ioctl(tmp->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &ps) < 0) {
ast_log(LOG_WARNING, "Failed to get parameters on channel %d: %s\n", tmp->channel, strerror(errno)); ast_log(LOG_WARNING, "Failed to get parameters on channel %d: %s\n", tmp->channel, strerror(errno));
} else { } else {
@ -15299,6 +15307,7 @@ static int linkset_addsigchan(int sigchan)
ast_log(LOG_ERROR, "Unable to open SS7 sigchan %d (%s)\n", sigchan, strerror(errno)); ast_log(LOG_ERROR, "Unable to open SS7 sigchan %d (%s)\n", sigchan, strerror(errno));
return -1; return -1;
} }
memset(&p, 0, sizeof(p));
res = ioctl(link->fds[curfd], DAHDI_GET_PARAMS, &p); res = ioctl(link->fds[curfd], DAHDI_GET_PARAMS, &p);
if (res) { if (res) {
dahdi_close_ss7_fd(link, curfd); dahdi_close_ss7_fd(link, curfd);

Loading…
Cancel
Save