chan_dahdi: Address gcc9 issues

Fixed format-truncation issues in chan_dahdi.c and
sig_analog.c.  Since they're related to fields provided
by dahdi-tools we can't change the buffer sizes so we're just
checking the return from snprintf and printing an errior if we
overflow.

Change-Id: Idc1f3c1565b88a7d145332a0196074b5832864e5
13.28
George Joseph 6 years ago
parent d5fed38ab5
commit d0f01af913

@ -7740,8 +7740,16 @@ static struct ast_frame *dahdi_handle_event(struct ast_channel *ast)
c++; c++;
else else
c = p->dialdest; c = p->dialdest;
if (*c) snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*0%s#", c);
else ast_copy_string(p->dop.dialstr,"M*2#", sizeof(p->dop.dialstr)); if (*c) {
int numchars = snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*0%s#", c);
if (numchars >= sizeof(p->dop.dialstr)) {
ast_log(LOG_WARNING, "Dial string '%s' truncated\n", c);
}
} else {
ast_copy_string(p->dop.dialstr,"M*2#", sizeof(p->dop.dialstr));
}
if (strlen(p->dop.dialstr) > 4) { if (strlen(p->dop.dialstr) > 4) {
memset(p->echorest, 'w', sizeof(p->echorest) - 1); memset(p->echorest, 'w', sizeof(p->echorest) - 1);
strcpy(p->echorest + (p->echotraining / 401) + 1, p->dop.dialstr + strlen(p->dop.dialstr) - 2); strcpy(p->echorest + (p->echotraining / 401) + 1, p->dop.dialstr + strlen(p->dop.dialstr) - 2);

@ -2957,11 +2957,16 @@ static struct ast_frame *__analog_handle_event(struct analog_pvt *p, struct ast_
} else { } else {
c = p->dialdest; c = p->dialdest;
} }
if (*c) { if (*c) {
snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*0%s#", c); int numchars = snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*0%s#", c);
if (numchars >= sizeof(p->dop.dialstr)) {
ast_log(LOG_WARNING, "Dial string '%s' truncated\n", c);
}
} else { } else {
ast_copy_string(p->dop.dialstr,"M*2#", sizeof(p->dop.dialstr)); ast_copy_string(p->dop.dialstr,"M*2#", sizeof(p->dop.dialstr));
} }
if (strlen(p->dop.dialstr) > 4) { if (strlen(p->dop.dialstr) > 4) {
memset(p->echorest, 'w', sizeof(p->echorest) - 1); memset(p->echorest, 'w', sizeof(p->echorest) - 1);
strcpy(p->echorest + (p->echotraining / 401) + 1, p->dop.dialstr + strlen(p->dop.dialstr) - 2); strcpy(p->echorest + (p->echotraining / 401) + 1, p->dop.dialstr + strlen(p->dop.dialstr) - 2);

Loading…
Cancel
Save