Changeset 2451

Show
Ignore:
Timestamp:
10/27/13 21:08:10 (4 years ago)
Author:
mocchi
Message:

[Fireworks] add prevention from buffer over run

With Audiofire12, EfcPolledValuesCmd? often return invalid data. When the number of channels is invalid, assertion is generated and aborts process. This patch remove this assertion and add prevention from buffer over run. If the command return invalid data, the process is not aborted and continue to work.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libffado/src/fireworks/efc/efc_cmds_hardware.cpp

    r1763 r2451  
    191191EfcPolledValuesCmd::deserialize( Util::Cmd::IISDeserialize& de ) 
    192192{ 
    193     bool result=true; 
    194      
    195     result &= EfcCmd::deserialize ( de ); 
     193    int i, nb_meters; 
     194    bool result; 
     195     
     196    if (!EfcCmd::deserialize(de)) 
     197        return false; 
    196198     
    197199    // the serialization is different from the deserialization 
     200    result = true; 
    198201    EFC_DESERIALIZE_AND_SWAP(de, &m_status, result); 
    199202     
     
    208211    EFC_DESERIALIZE_AND_SWAP(de, &m_reserved6, result); 
    209212 
    210     int i=0; 
    211     int nb_meters=m_nb_output_meters+m_nb_input_meters; 
    212      
    213     assert(nb_meters<POLLED_MAX_NB_METERS); 
    214     for (i=0; i<nb_meters; i++) { 
     213    if (!result) 
     214        return result; 
     215 
     216    nb_meters = m_nb_output_meters + m_nb_input_meters; 
     217    if (nb_meters > POLLED_MAX_NB_METERS) { 
     218        m_nb_output_meters = 0; 
     219        m_nb_input_meters = 0; 
     220        return false; 
     221    } 
     222 
     223    result = true; 
     224    for (i = 0; i < nb_meters; i++) 
    215225        EFC_DESERIALIZE_AND_SWAP(de, (uint32_t *)&m_meters[i], result); 
    216     } 
    217226     
    218227    return result; 
     
    222231EfcPolledValuesCmd::showEfcCmd() 
    223232{ 
     233    unsigned int i; 
     234 
    224235    EfcCmd::showEfcCmd(); 
    225236     
     
    228239    debugOutput(DEBUG_LEVEL_NORMAL, " Detect SPDIF    : 0x%08X\n", m_detect_spdif); 
    229240    debugOutput(DEBUG_LEVEL_NORMAL, " Detect ADAT     : 0x%08X\n", m_detect_adat); 
    230      
    231     unsigned int i=0; 
    232     debugOutput(DEBUG_LEVEL_NORMAL, " # Output Meters : %d\n", m_nb_output_meters); 
    233     for (i=0;i<m_nb_output_meters;i++) { 
    234         debugOutput(DEBUG_LEVEL_NORMAL, "     Meter %d: %d\n", i, m_meters[i]); 
    235     } 
    236      
    237     debugOutput(DEBUG_LEVEL_NORMAL, " # Input Meters  : %d\n", m_nb_input_meters); 
    238     for (;i<m_nb_output_meters+m_nb_input_meters;i++) { 
    239         debugOutput(DEBUG_LEVEL_NORMAL, "     Meter %d: %d\n", i, m_meters[i]); 
     241    
     242    /* prevent buffer over run */ 
     243    if (m_nb_output_meters + m_nb_input_meters > POLLED_MAX_NB_METERS) 
     244        return; 
     245 
     246    if (m_nb_output_meters > 0) { 
     247        debugOutput(DEBUG_LEVEL_NORMAL, " # Output Meters : %d\n", m_nb_output_meters); 
     248        for (i = 0; i < m_nb_output_meters; i++) 
     249            debugOutput(DEBUG_LEVEL_NORMAL, "     Meter %d: %d\n", i, m_meters[i]); 
     250    }     
     251 
     252    if (m_nb_input_meters > 0) { 
     253        debugOutput(DEBUG_LEVEL_NORMAL, " # Input Meters  : %d\n", m_nb_input_meters); 
     254        for (; i < m_nb_output_meters + m_nb_input_meters; i++) 
     255            debugOutput(DEBUG_LEVEL_NORMAL, "     Meter %d: %d\n", i, m_meters[i]); 
    240256    } 
    241257}