Changeset 1150


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

Location:
pjproject/trunk/pjnath
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjnath/include/pjnath/stun_msg.h

    r1126 r1150  
    286286    PJ_STUN_ATTR_REFLECTED_FROM     = 0x000B,/**< REFLECTED-FROM (deprecatd)*/ 
    287287    PJ_STUN_ATTR_LIFETIME           = 0x000D,/**< LIFETIME attribute.       */ 
     288    PJ_STUN_ATTR_MAGIC_COOKIE       = 0x000F,/**< MAGIC-COOKIE attr (deprec)*/ 
    288289    PJ_STUN_ATTR_BANDWIDTH          = 0x0010,/**< BANDWIDTH attribute       */ 
    289290    PJ_STUN_ATTR_REMOTE_ADDR        = 0x0012,/**< REMOTE-ADDRESS attribute  */ 
  • pjproject/trunk/pjnath/src/pjnath/errno.c

    r1141 r1150  
    135135    pj_str_t errstr; 
    136136 
     137    buf[bufsize-1] = '\0'; 
     138 
    137139    if (cmsg.slen == 0) { 
    138140        /* Not found */ 
     
    144146        errstr.ptr = buf; 
    145147        pj_strncpy(&errstr, &cmsg, bufsize); 
     148        if (errstr.slen < (int)bufsize) 
     149            buf[errstr.slen] = '\0'; 
     150        else 
     151            buf[bufsize-1] = '\0'; 
    146152    } 
    147153 
  • 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 
  • pjproject/trunk/pjnath/src/pjstun-client/client_main.c

    r1149 r1150  
    185185    status = pj_init(); 
    186186    status = pjlib_util_init(); 
     187    status = pjnath_init(); 
    187188 
    188189    pj_caching_pool_init(&g.cp, &pj_pool_factory_default_policy, 0); 
Note: See TracChangeset for help on using the changeset viewer.