Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b22c5bed authored by Jasmine Cha's avatar Jasmine Cha
Browse files

audio: waves: check array index



If other caller use audio_hw_send_ma_parameter directly,
that would be a risk if we don’t confirm the index before access it.

Bug: 119283928
Test: build pass / Waves effect - preset / LR swap / LR mix

Change-Id: Ibe2cdb025994a4191ffd85665cf27baddf52fe52
Signed-off-by: default avatarJasmine Cha <chajasmine@google.com>
parent 5f4ca950
Loading
Loading
Loading
Loading
+12 −5
Original line number Diff line number Diff line
@@ -62,8 +62,8 @@ struct ma_state {
};

typedef enum MA_STREAM_TYPE {
    STREAM_MIN_STREAM_TYPES,
    STREAM_VOICE = STREAM_MIN_STREAM_TYPES,
    STREAM_MIN_TYPES = 0,
    STREAM_VOICE = STREAM_MIN_TYPES,
    STREAM_SYSTEM,
    STREAM_RING,
    STREAM_MUSIC,
@@ -509,21 +509,28 @@ bool audio_extn_ma_set_state(struct audio_device *adev, int stream_type,
                             float vol, bool active)
{
    bool ret = false;
    ma_stream_type_t stype = (ma_stream_type_t)stream_type;
    ma_stream_type_t stype;

    ALOGV("%s: stream[%d] vol[%f] active[%s]",
          __func__, stream_type, vol, active ? "true" : "false");
    if (stream_type >= STREAM_MAX_TYPES ||
        stream_type < STREAM_MIN_TYPES) {
        ALOGE("%s: stream_type %d out of range.", __func__, stream_type);
        return ret;
    }

    if (!my_data) {
        ALOGV("%s: maxxaudio isn't initialized.", __func__);
        return ret;
    }

    ALOGV("%s: stream[%d] vol[%f] active[%s]",
          __func__, stream_type, vol, active ? "true" : "false");

    // update condition
    // 1. start track: active and volume isn't zero
    // 2. stop track: no tracks are active
    if ((active && vol != 0) ||
        (!active)) {
        stype = (ma_stream_type_t)stream_type;
        pthread_mutex_lock(&my_data->lock);

        ma_cur_state_table[stype].vol = vol;