Ignore:
Timestamp:
Jun 21, 2008 12:36:56 PM (16 years ago)
Author:
bennylp
Message:

Fixed bug with authenticating STUN messages when unrecognized/unknown non-mandatory STUN attribute is present in the message

File:
1 edited

Legend:

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

    r1997 r2041  
    16571657    INIT_ATTR(attr, attr_type, length); 
    16581658 
     1659    attr->magic = PJ_STUN_MAGIC; 
     1660 
    16591661    if (data && length) { 
    16601662        attr->length = length; 
     
    20242026        if (adesc == NULL) { 
    20252027            /* Unrecognized attribute */ 
     2028            pj_stun_binary_attr *attr; 
    20262029 
    20272030            PJ_LOG(4,(THIS_FILE, "Unrecognized attribute type %d",  
     
    20472050                return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_UNKNOWN_ATTRIBUTE); 
    20482051            } 
     2052 
     2053            /* Make sure we have rooms for the new attribute */ 
     2054            if (msg->attr_count >= PJ_STUN_MAX_ATTR) { 
     2055                if (p_response) { 
     2056                    pj_stun_msg_create_response(pool, msg, 
     2057                                                PJ_STUN_SC_SERVER_ERROR, 
     2058                                                NULL, p_response); 
     2059                } 
     2060                return PJNATH_ESTUNTOOMANYATTR; 
     2061            } 
     2062 
     2063            /* Create binary attribute to represent this */ 
     2064            status = pj_stun_binary_attr_create(pool, attr_type, pdu+4,  
     2065                                                GETVAL16H(pdu, 2), &attr); 
     2066            if (status != PJ_SUCCESS) { 
     2067                if (p_response) { 
     2068                    pj_stun_msg_create_response(pool, msg, 
     2069                                                PJ_STUN_SC_SERVER_ERROR, 
     2070                                                NULL, p_response); 
     2071                } 
     2072 
     2073                PJ_LOG(4,(THIS_FILE,  
     2074                          "Error parsing unknown STUN attribute type %d", 
     2075                          attr_type)); 
     2076 
     2077                return status; 
     2078            } 
     2079 
     2080            /* Add the attribute */ 
     2081            msg->attr[msg->attr_count++] = &attr->hdr; 
    20492082 
    20502083        } else { 
     
    21252158                if (p_response) { 
    21262159                    pj_stun_msg_create_response(pool, msg, 
    2127                                                 PJ_STUN_SC_BAD_REQUEST, 
     2160                                                PJ_STUN_SC_SERVER_ERROR, 
    21282161                                                NULL, p_response); 
    21292162                } 
     
    21352168        } 
    21362169 
     2170        /* Next attribute */ 
    21372171        if (attr_val_len + 4 >= pdu_len) { 
    21382172            pdu += pdu_len; 
     
    22402274 
    22412275        adesc = find_attr_desc(attr_hdr->type); 
    2242         PJ_ASSERT_RETURN(adesc != NULL, PJ_EBUG); 
    2243  
    2244         status = adesc->encode_attr(attr_hdr, buf, buf_size, &printed); 
     2276        if (adesc) { 
     2277            status = adesc->encode_attr(attr_hdr, buf, buf_size, &printed); 
     2278        } else { 
     2279            /* This may be a generic attribute */ 
     2280            const pj_stun_binary_attr *bin_attr = (const pj_stun_binary_attr*)  
     2281                                                   attr_hdr; 
     2282            PJ_ASSERT_RETURN(bin_attr->magic == PJ_STUN_MAGIC, PJ_EBUG); 
     2283            status = encode_binary_attr(bin_attr, buf, buf_size, &printed); 
     2284        } 
     2285 
    22452286        if (status != PJ_SUCCESS) 
    22462287            return status; 
     
    24152456    /* Get the attribute descriptor */ 
    24162457    adesc = find_attr_desc(attr->type); 
    2417     PJ_ASSERT_RETURN(adesc != NULL, NULL); 
    2418  
    2419     return (pj_stun_attr_hdr*) (*adesc->clone_attr)(pool, attr); 
    2420 } 
    2421  
    2422  
     2458    if (adesc) { 
     2459        return (pj_stun_attr_hdr*) (*adesc->clone_attr)(pool, attr); 
     2460    } else { 
     2461        /* Clone generic attribute */ 
     2462        const pj_stun_binary_attr *bin_attr = (const pj_stun_binary_attr*) 
     2463                                               attr; 
     2464        PJ_ASSERT_RETURN(bin_attr->magic == PJ_STUN_MAGIC, NULL); 
     2465        if (bin_attr->magic == PJ_STUN_MAGIC) { 
     2466            return (pj_stun_attr_hdr*) clone_binary_attr(pool, attr); 
     2467        } else { 
     2468            return NULL; 
     2469        } 
     2470    } 
     2471} 
     2472 
     2473 
Note: See TracChangeset for help on using the changeset viewer.