Changeset 572


Ignore:
Timestamp:
Jul 2, 2006 1:36:50 PM (18 years ago)
Author:
bennylp
Message:

Fixed bug in SDP rtpmap parsing that caused SDP failed to parse the rtpmap attribute (because input is not null terminated)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/src/pjmedia/sdp.c

    r571 r572  
    102102 
    103103    if (value) 
    104         pj_strdup(pool, &attr->value, value); 
     104        pj_strdup_with_null(pool, &attr->value, value); 
    105105    else { 
    106106        attr->value.ptr = NULL; 
     
    121121 
    122122    pj_strdup(pool, &attr->name, &rhs->name); 
    123     pj_strdup(pool, &attr->value, &rhs->value); 
     123    pj_strdup_with_null(pool, &attr->value, &rhs->value); 
    124124 
    125125    return attr; 
     
    250250    pj_str_t token; 
    251251    pj_status_t status = -1; 
     252    char term = 0; 
    252253    PJ_USE_EXCEPTION; 
    253254 
    254255    PJ_ASSERT_RETURN(pj_strcmp2(&attr->name, "rtpmap")==0, PJ_EINVALIDOP); 
     256 
     257    PJ_ASSERT_RETURN(attr->value.slen != 0, PJMEDIA_SDP_EINATTR); 
     258 
     259    /* Check if input is null terminated, and null terminate if 
     260     * necessary. Unfortunately this may crash the application if 
     261     * attribute was allocated from a read-only memory location. 
     262     * But this shouldn't happen as attribute's value normally is 
     263     * null terminated. 
     264     */ 
     265    if (attr->value.ptr[attr->value.slen] != 0 && 
     266        attr->value.ptr[attr->value.slen] != '\r') 
     267    { 
     268        pj_assert(!"Shouldn't happen"); 
     269        term = attr->value.ptr[attr->value.slen]; 
     270        attr->value.ptr[attr->value.slen] = '\0'; 
     271    } 
    255272 
    256273    pj_scan_init(&scanner, (char*)attr->value.ptr, attr->value.slen, 
     
    311328on_return: 
    312329    pj_scan_fini(&scanner); 
     330    if (term) { 
     331        attr->value.ptr[attr->value.slen] = term; 
     332    } 
    313333    return status; 
    314334} 
Note: See TracChangeset for help on using the changeset viewer.