audio: fix misc static errors

Fix accessing index out of array boundary.
Fix dereference of NULL pointer.
Fix use of uninitialized variable.

Change-Id: I77d7be8709bd1c1276ba1b9bb18321083a22c9c2
CRs-Fixed: 2284371
This commit is contained in:
Weiyin Jiang 2018-08-01 18:06:27 +08:00 committed by Gerrit - the friendly Code Review server
parent fc18274875
commit 20d3fa662d
3 changed files with 40 additions and 34 deletions

View File

@ -1255,53 +1255,54 @@ bool configure_aptx_enc_format(audio_aptx_encoder_config *aptx_bt_cfg)
if(aptx_bt_cfg == NULL)
return false;
ctl_enc_data = mixer_get_ctl_by_name(a2dp.adev->mixer, MIXER_ENC_CONFIG_BLOCK);
if (!ctl_enc_data) {
ALOGE(" ERROR a2dp encoder CONFIG data mixer control not identifed");
return false;
}
#ifndef LINUX_ENABLED
struct aptx_enc_cfg_t aptx_dsp_cfg;
struct aptx_ad_enc_cfg_t aptx_ad_dsp_cfg;
if(a2dp.is_aptx_adaptive)
mixer_size = sizeof(struct aptx_ad_enc_cfg_t);
else {
if(a2dp.is_aptx_adaptive) {
mixer_size = sizeof(struct aptx_ad_enc_cfg_t);
ret = update_aptx_ad_dsp_config(&aptx_ad_dsp_cfg, aptx_bt_cfg);
sample_rate_backup = aptx_ad_dsp_cfg.custom_cfg.sample_rate;
} else {
mixer_size = sizeof(struct aptx_enc_cfg_t);
sample_rate_backup = aptx_bt_cfg->default_cfg->sampling_rate;
ret = update_aptx_dsp_config_v2(&aptx_dsp_cfg, aptx_bt_cfg);
}
if (ret) {
is_configured = false;
goto fail;
}
if(a2dp.is_aptx_adaptive) {
ret = mixer_ctl_set_array(ctl_enc_data, (void *)&aptx_ad_dsp_cfg,
mixer_size);
} else {
ret = mixer_ctl_set_array(ctl_enc_data, (void *)&aptx_dsp_cfg,
mixer_size);
}
#else
struct custom_enc_cfg_t aptx_dsp_cfg;
mixer_size = sizeof(struct custom_enc_cfg_t);
sample_rate_backup = aptx_bt_cfg->sampling_rate;
#endif
ctl_enc_data = mixer_get_ctl_by_name(a2dp.adev->mixer, MIXER_ENC_CONFIG_BLOCK);
if (!ctl_enc_data) {
ALOGE(" ERROR a2dp encoder CONFIG data mixer control not identifed");
is_configured = false;
goto fail;
}
#ifndef LINUX_ENABLED
if(a2dp.is_aptx_adaptive) {
ret = update_aptx_ad_dsp_config(&aptx_ad_dsp_cfg, aptx_bt_cfg);
sample_rate_backup = aptx_ad_dsp_cfg.custom_cfg.sample_rate;
} else
ret = update_aptx_dsp_config_v2(&aptx_dsp_cfg, aptx_bt_cfg);
#else
ret = update_aptx_dsp_config_v1(&aptx_dsp_cfg, aptx_bt_cfg);
#endif
if (ret) {
is_configured = false;
goto fail;
}
if(a2dp.is_aptx_adaptive)
ret = mixer_ctl_set_array(ctl_enc_data, (void *)&aptx_ad_dsp_cfg,
mixer_size);
else
ret = mixer_ctl_set_array(ctl_enc_data, (void *)&aptx_dsp_cfg,
mixer_size);
ret = mixer_ctl_set_array(ctl_enc_data, (void *)&aptx_dsp_cfg,
mixer_size);
#endif
if (ret != 0) {
ALOGE("%s: Failed to set APTX encoder config", __func__);
is_configured = false;
goto fail;
}
ctrl_bit_format = mixer_get_ctl_by_name(a2dp.adev->mixer,
MIXER_ENC_BIT_FORMAT);
if (!ctrl_bit_format) {

View File

@ -897,6 +897,11 @@ static int enable_disable_effect(struct audio_device *adev, int effect_type, boo
ALOGD("%s: effect_type:%d enable:%d", __func__, effect_type, enable);
usecase = get_usecase_from_list(adev, in->usecase);
if (usecase == NULL) {
ALOGE("%s: Could not find the usecase (%d) in the list",
__func__, in->usecase);
return -EINVAL;
}
ret = platform_get_effect_config_data(usecase->in_snd_device, &effect_config, effect_type);
if (ret < 0) {

View File

@ -639,7 +639,7 @@ static void process_microphone_characteristic(const XML_Char **attr) {
goto done;
}
microphone.num_frequency_responses = atoi(attr[curIdx++]);
if (microphone.num_frequency_responses > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
if (microphone.num_frequency_responses >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
ALOGE("%s: num_frequency_responses is too large", __func__);
goto done;
}
@ -653,7 +653,7 @@ static void process_microphone_characteristic(const XML_Char **attr) {
uint32_t num_frequencies = 0;
while (token) {
microphone.frequency_responses[0][num_frequencies++] = atof(token);
if (num_frequencies > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
if (num_frequencies >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
ALOGE("%s: num %u of frequency is too large", __func__, num_frequencies);
goto done;
}
@ -668,7 +668,7 @@ static void process_microphone_characteristic(const XML_Char **attr) {
uint32_t num_responses = 0;
while (token) {
microphone.frequency_responses[1][num_responses++] = atof(token);
if (num_responses > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
if (num_responses >= AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
ALOGE("%s: num %u of response is too large", __func__, num_responses);
goto done;
}
@ -724,13 +724,13 @@ static void process_microphone_characteristic(const XML_Char **attr) {
uint32_t idx = 0;
while (token) {
orientation[idx++] = atof(token);
if (idx > 3) {
if (idx >= 3) {
ALOGE("%s: orientation invalid", __func__);
goto done;
}
token = strtok_r(NULL, " ", &context);
}
if (idx != 3) {
if (idx != 2) {
ALOGE("%s: orientation invalid", __func__);
goto done;
}
@ -754,13 +754,13 @@ static void process_microphone_characteristic(const XML_Char **attr) {
uint32_t idx = 0;
while (token) {
geometric_location[idx++] = atof(token);
if (idx > 3) {
if (idx >= 3) {
ALOGE("%s: geometric_location invalid", __func__);
goto done;
}
token = strtok_r(NULL, " ", &context);
}
if (idx != 3) {
if (idx != 2) {
ALOGE("%s: geometric_location invalid", __func__);
goto done;
}