Ignore:
Timestamp:
Apr 4, 2007 5:29:36 PM (17 years ago)
Author:
bennylp
Message:

Fixed crash with invalid PDU and added MAGIC-COOKIE attribute for backward compatibility with old TURN

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjnath/src/pjnath/stun_msg.c

    r1141 r1150  
    233233    }, 
    234234    { 
    235         /* ID 0x000F is not assigned */ 
    236         NULL, 
    237         NULL, 
    238         NULL 
     235        /* PJ_STUN_ATTR_MAGIC_COOKIE */ 
     236        "MAGIC-COOKIE", 
     237        &decode_uint_attr, 
     238        &encode_uint_attr 
    239239    }, 
    240240    { 
     
    17731773    /* Parse attributes */ 
    17741774    uattr_cnt = 0; 
    1775     while (pdu_len > 0) { 
     1775    while (pdu_len >= 4) { 
    17761776        unsigned attr_type, attr_val_len; 
    17771777        const struct attr_desc *adesc; 
     
    17801780         * to 4 bytes boundary, add padding. 
    17811781         */ 
    1782         attr_type = pj_ntohs(*(pj_uint16_t*)pdu); 
    1783         attr_val_len = pj_ntohs(*(pj_uint16_t*)(pdu+2)); 
     1782        attr_type = GETVAL16H(pdu, 0); 
     1783        attr_val_len = GETVAL16H(pdu, 2); 
    17841784        attr_val_len = (attr_val_len + 3) & (~3); 
    17851785 
     
    19201920        } 
    19211921 
    1922         pdu += (attr_val_len + 4); 
    1923         pdu_len -= (attr_val_len + 4); 
     1922        if (attr_val_len + 4 >= pdu_len) { 
     1923            pdu += pdu_len; 
     1924            pdu_len = 0; 
     1925        } else { 
     1926            pdu += (attr_val_len + 4); 
     1927            pdu_len -= (attr_val_len + 4); 
     1928        } 
     1929    } 
     1930 
     1931    if (pdu_len > 0) { 
     1932        /* Stray trailing bytes */ 
     1933        PJ_LOG(4,(THIS_FILE,  
     1934                  "Error decoding STUN message: unparsed trailing %d bytes", 
     1935                  pdu_len)); 
     1936        return PJNATH_EINSTUNMSGLEN; 
    19241937    } 
    19251938 
Note: See TracChangeset for help on using the changeset viewer.