From 088b842ced53c4994a32fd34a193512f1af9d792 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Wed, 21 May 2008 22:26:30 +0000 Subject: [PATCH] Add safety check for codec implementations with bytes_per_frames being larger than the recommended buffer size (Klocwork #1039) git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8514 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/switch_ivr.c | 1 + src/switch_loadable_module.c | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/switch_ivr.c b/src/switch_ivr.c index 44efb18ca0..dbd94f8f24 100644 --- a/src/switch_ivr.c +++ b/src/switch_ivr.c @@ -487,6 +487,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_park(switch_core_session_t *session, if (switch_test_flag(read_frame, SFF_CNG)) { sendlen = read_codec->implementation->bytes_per_frame; + switch_assert(sendlen <= SWITCH_RECOMMENDED_BUFFER_SIZE); memset(decoded, 255, sendlen); sendbuf = decoded; tstatus = SWITCH_STATUS_SUCCESS; diff --git a/src/switch_loadable_module.c b/src/switch_loadable_module.c index d592a35da6..1a2c2fbd61 100644 --- a/src/switch_loadable_module.c +++ b/src/switch_loadable_module.c @@ -154,13 +154,18 @@ static switch_status_t switch_loadable_module_process(char *key, switch_loadable for (impl = ptr->implementations; impl; impl = impl->next) { if (!impl->iananame) { load_interface = 0; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, + "Failed to load codec interface %s from %s due to no iana name in an implementation.\n", ptr->interface_name, key); + break; + } + if (impl->bytes_per_frame > SWITCH_RECOMMENDED_BUFFER_SIZE) { + load_interface = 0; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, + "Failed to load codec interface %s from %s due to bytes per frame exceeding buffer size.\n", ptr->interface_name, key); break; } } - if (!load_interface) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, - "Failed to load codec interface %s from %s due to no iana name in an implementation.\n", ptr->interface_name, key); - } else { + if (load_interface) { for (impl = ptr->implementations; impl; impl = impl->next) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Adding Codec '%s' (%s) %dhz %dms\n",