aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2013-05-21 17:37:49 +0200
committerHolger Hans Peter Freyther <zecke@selfish.org>2013-05-21 18:00:21 +0200
commitb2e8cfbe8d447b048c181566ee3d96659f7f96e4 (patch)
tree70e5116e176bc2798cddb0ee104d94dd5d386f73
parent5d76e957fe8916d234e68ec2786febf13b4dde47 (diff)
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.
-rw-r--r--src/dtmf_scheduler.c3
-rw-r--r--src/mgcp_ss7.c16
-rw-r--r--tests/dtmf/dtmf_test.c9
3 files changed, 27 insertions, 1 deletions
diff --git a/src/dtmf_scheduler.c b/src/dtmf_scheduler.c
index 4f64eb0..5a99a5b 100644
--- a/src/dtmf_scheduler.c
+++ b/src/dtmf_scheduler.c
@@ -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;
diff --git a/src/mgcp_ss7.c b/src/mgcp_ss7.c
index 3490a9a..017bb8e 100644
--- a/src/mgcp_ss7.c
+++ b/src/mgcp_ss7.c
@@ -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);
diff --git a/tests/dtmf/dtmf_test.c b/tests/dtmf/dtmf_test.c
index 6fab052..97f4f14 100644
--- a/tests/dtmf/dtmf_test.c
+++ b/tests/dtmf/dtmf_test.c
@@ -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;
}