9
0
Fork 0

dtmf: Check the tones that are put into the DTMF scheduler and reject a 0

Playing tones should be printable ascii characters, begin by checking
for NULL (as it happened before) as the first illegal tone. This is
an attempt to make the API more robust and detect errors more early.
This commit is contained in:
Holger Hans Peter Freyther 2013-05-21 17:37:49 +02:00
parent 9905b18811
commit e48231c539
3 changed files with 27 additions and 1 deletions

View File

@ -32,6 +32,9 @@ int dtmf_state_add(struct dtmf_state *state, char tone)
/* we would override the head */
if (state->size == sizeof(state->tones))
return -1;
/* avoid someone adding a NULL byte */
if (tone == 0)
return -2;
state->tones[state->size++] = tone;
return 0;

View File

@ -97,7 +97,7 @@ static void send_dtmf(struct mgcp_endpoint *mgw_endp, int ascii_tone)
{
int rc;
rc = dtmf_state_add(&mgw_endp->dtmf_state, ascii_tone);
if (rc != 0) {
if (rc == -1) {
fprintf(stderr, "DTMF queue too long on 0x%x with %u tones\n",
ENDPOINT_NUMBER(mgw_endp),
dtmf_tones_queued(&mgw_endp->dtmf_state));
@ -106,6 +106,20 @@ static void send_dtmf(struct mgcp_endpoint *mgw_endp, int ascii_tone)
dtmf_tones_queued(&mgw_endp->dtmf_state));
return;
}
if (rc == -2) {
fprintf(stderr, "DTMF illegal tone %d on 0x%x\n",
ascii_tone, ENDPOINT_NUMBER(mgw_endp));
syslog(LOG_ERR, "DTMF illegal tone %d on 0x%x\n",
ascii_tone, ENDPOINT_NUMBER(mgw_endp));
return;
}
if (rc < 0) {
fprintf(stderr, "DTMF unknown error %d on 0x%x\n",
rc, ENDPOINT_NUMBER(mgw_endp));
syslog(LOG_ERR, "DTMF unknown error %d on 0x%x\n",
rc, ENDPOINT_NUMBER(mgw_endp));
return;
}
if (!mgw_endp->dtmf_state.playing)
play_pending_tones(mgw_endp);

View File

@ -99,11 +99,20 @@ static void test_queue_over_flow(void)
ASSERT(state.playing, 0);
}
static void test_queue_null_byte(void)
{
struct dtmf_state state;
dtmf_state_init(&state);
ASSERT(dtmf_state_add(&state, 0), -2);
}
int main(int argc, char **argv)
{
test_queue_while_play();
test_queue_over_flow();
test_queue_null_byte();
printf("All tests passed.\n");
return 0;
}