From ebb69fae687766e4c737b4e31752cde553f68779 Mon Sep 17 00:00:00 2001 From: wjiang Date: Thu, 15 May 2014 19:38:26 +0800 Subject: [PATCH] post_proc: fix post and pre process KW issues KW issue fix includes: - handle memory allocation failure - array index boundary check Change-Id: I083952ba58d348a5b650601a83e6f492b0d686bb --- post_proc/bundle.c | 17 +++++++++++++++++ post_proc/effect_api.c | 3 ++- visualizer/offload_visualizer.c | 9 +++++++++ voice_processing/voice_processing.c | 8 ++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/post_proc/bundle.c b/post_proc/bundle.c index b11a7006..a0d9fcbd 100644 --- a/post_proc/bundle.c +++ b/post_proc/bundle.c @@ -201,6 +201,11 @@ int offload_effects_bundle_hal_start_output(audio_io_handle_t output, int pcm_id output_context_t *out_ctxt = (output_context_t *) malloc(sizeof(output_context_t)); + if (!out_ctxt) { + ALOGE("%s fail to allocate for output context", __func__); + ret = -ENOMEM; + goto exit; + } out_ctxt->handle = output; out_ctxt->pcm_device_id = pcm_id; @@ -334,6 +339,9 @@ int effect_lib_create(const effect_uuid_t *uuid, sizeof(effect_uuid_t)) == 0) { equalizer_context_t *eq_ctxt = (equalizer_context_t *) calloc(1, sizeof(equalizer_context_t)); + if (eq_ctxt == NULL) { + return -ENOMEM; + } context = (effect_context_t *)eq_ctxt; context->ops.init = equalizer_init; context->ops.reset = equalizer_reset; @@ -351,6 +359,9 @@ int effect_lib_create(const effect_uuid_t *uuid, sizeof(effect_uuid_t)) == 0) { bassboost_context_t *bass_ctxt = (bassboost_context_t *) calloc(1, sizeof(bassboost_context_t)); + if (bass_ctxt == NULL) { + return -ENOMEM; + } context = (effect_context_t *)bass_ctxt; context->ops.init = bassboost_init; context->ops.reset = bassboost_reset; @@ -368,6 +379,9 @@ int effect_lib_create(const effect_uuid_t *uuid, sizeof(effect_uuid_t)) == 0) { virtualizer_context_t *virt_ctxt = (virtualizer_context_t *) calloc(1, sizeof(virtualizer_context_t)); + if (virt_ctxt == NULL) { + return -ENOMEM; + } context = (effect_context_t *)virt_ctxt; context->ops.init = virtualizer_init; context->ops.reset = virtualizer_reset; @@ -391,6 +405,9 @@ int effect_lib_create(const effect_uuid_t *uuid, sizeof(effect_uuid_t)) == 0)) { reverb_context_t *reverb_ctxt = (reverb_context_t *) calloc(1, sizeof(reverb_context_t)); + if (reverb_ctxt == NULL) { + return -ENOMEM; + } context = (effect_context_t *)reverb_ctxt; context->ops.init = reverb_init; context->ops.reset = reverb_reset; diff --git a/post_proc/effect_api.c b/post_proc/effect_api.c index bad6ee10..971b67f1 100644 --- a/post_proc/effect_api.c +++ b/post_proc/effect_api.c @@ -318,7 +318,8 @@ int offload_eq_send_params(struct mixer_ctl *ctl, struct eq_params eq, uint32_t i; ALOGV("%s: flags 0x%x", __func__, param_send_flags); - if (eq.config.preset_id < -1 ) { + if ((eq.config.preset_id < -1) || + ((param_send_flags & OFFLOAD_SEND_EQ_PRESET) && (eq.config.preset_id == -1))) { ALOGV("No Valid preset to set"); return 0; } diff --git a/visualizer/offload_visualizer.c b/visualizer/offload_visualizer.c index 95b46874..94c44a59 100644 --- a/visualizer/offload_visualizer.c +++ b/visualizer/offload_visualizer.c @@ -431,6 +431,11 @@ int visualizer_hal_start_output(audio_io_handle_t output, int pcm_id) { } output_context_t *out_ctxt = (output_context_t *)malloc(sizeof(output_context_t)); + if (out_ctxt == NULL) { + ALOGE("%s fail to allocate memory", __func__); + ret = -ENOMEM; + goto exit; + } out_ctxt->handle = output; list_init(&out_ctxt->effects_list); @@ -927,6 +932,10 @@ int effect_lib_create(const effect_uuid_t *uuid, if (memcmp(uuid, &visualizer_descriptor.uuid, sizeof(effect_uuid_t)) == 0) { visualizer_context_t *visu_ctxt = (visualizer_context_t *)calloc(1, sizeof(visualizer_context_t)); + if (visu_ctxt == NULL) { + ALOGE("%s fail to allocate memory", __func__); + return -ENOMEM; + } context = (effect_context_t *)visu_ctxt; context->ops.init = visualizer_init; context->ops.reset = visualizer_reset; diff --git a/voice_processing/voice_processing.c b/voice_processing/voice_processing.c index b8b1e1b0..1d18a3d2 100644 --- a/voice_processing/voice_processing.c +++ b/voice_processing/voice_processing.c @@ -408,6 +408,10 @@ static struct session_s *get_session(int32_t id, int32_t sessionId, int32_t io } session = (struct session_s *)calloc(1, sizeof(struct session_s)); + if (session == NULL) { + ALOGE("get_session() fail to allocate memory"); + return NULL; + } session_init(session); session->id = sessionId; session->io = ioId; @@ -682,6 +686,10 @@ static int lib_create(const effect_uuid_t *uuid, return -EINVAL; } id = uuid_to_id(&desc->type); + if (id >= NUM_ID) { + ALOGW("lib_create: fx not found type: %08x", desc->type.timeLow); + return -EINVAL; + } session = get_session(id, sessionId, ioId);