Changeset 2775


Ignore:
Timestamp:
Jun 18, 2009 2:04:44 PM (15 years ago)
Author:
nanang
Message:

Ticket #892: Added IPv6-enabled check (compile-time) in stun test vector containing IPv6 data, also added more run-time checks in stun fingerprint test internal.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjnath/src/pjnath-test/stun.c

    r2580 r2775  
    503503        "", 
    504504        &create_msgint2 
    505     }, 
     505    } 
     506#if defined(PJ_HAS_IPV6) && PJ_HAS_IPV6!=0 
     507    , 
    506508    { 
    507509        PJ_STUN_BINDING_RESPONSE, 
     
    531533        "\x80\x28\x00\x04" //    FINGERPRINT attribute header 
    532534        "\xc8\xfb\x0b\x4c" //    CRC32 fingerprint 
    533 , 
     535        , 
    534536        92, 
    535537        USE_MESSAGE_INTEGRITY | USE_FINGERPRINT, 
     
    540542        &create_msgint3 
    541543    } 
     544#endif 
    542545}; 
    543546 
     
    634637        /* Create our message */ 
    635638        msg = v->create(pool, v); 
     639        if (msg == NULL) { 
     640            PJ_LOG(1,(THIS_FILE, "    Error creating stun message")); 
     641            rc = -1030; 
     642            goto on_return; 
     643        } 
    636644 
    637645        /* Encode message */ 
     
    723731    pj_timestamp u64; 
    724732    pj_str_t s1; 
    725  
    726     pj_stun_msg_create(pool, v->msg_type, PJ_STUN_MAGIC, 
    727                        (pj_uint8_t*)v->tsx_id, &msg); 
    728  
    729     pj_stun_msg_add_uint_attr(pool, msg, PJ_STUN_ATTR_PRIORITY, 0x6e0001ff); 
     733    pj_status_t status; 
     734 
     735    status = pj_stun_msg_create(pool, v->msg_type, PJ_STUN_MAGIC, 
     736                                (pj_uint8_t*)v->tsx_id, &msg); 
     737    if (status != PJ_SUCCESS) 
     738        goto on_error; 
     739 
     740    status = pj_stun_msg_add_uint_attr(pool, msg, PJ_STUN_ATTR_PRIORITY,  
     741                                       0x6e0001ff); 
     742    if (status != PJ_SUCCESS) 
     743        goto on_error; 
     744 
    730745    u64.u32.hi = 0x932ff9b1; 
    731746    u64.u32.lo = 0x51263b36; 
    732     pj_stun_msg_add_uint64_attr(pool, msg, PJ_STUN_ATTR_ICE_CONTROLLED, 
    733                                 &u64); 
    734  
    735     pj_stun_msg_add_string_attr(pool, msg, PJ_STUN_ATTR_USERNAME,  
    736                                 pj_cstr(&s1, v->username)); 
    737  
    738     pj_stun_msg_add_msgint_attr(pool, msg); 
    739  
    740     pj_stun_msg_add_uint_attr(pool, msg, PJ_STUN_ATTR_FINGERPRINT, 0); 
     747    status = pj_stun_msg_add_uint64_attr(pool, msg,  
     748                                         PJ_STUN_ATTR_ICE_CONTROLLED, &u64); 
     749    if (status != PJ_SUCCESS) 
     750        goto on_error; 
     751 
     752    status = pj_stun_msg_add_string_attr(pool, msg, PJ_STUN_ATTR_USERNAME,  
     753                                         pj_cstr(&s1, v->username)); 
     754    if (status != PJ_SUCCESS) 
     755        goto on_error; 
     756 
     757    status = pj_stun_msg_add_msgint_attr(pool, msg); 
     758    if (status != PJ_SUCCESS) 
     759        goto on_error; 
     760 
     761    status = pj_stun_msg_add_uint_attr(pool, msg, PJ_STUN_ATTR_FINGERPRINT, 0); 
     762    if (status != PJ_SUCCESS) 
     763        goto on_error; 
    741764 
    742765    return msg; 
     766 
     767on_error: 
     768    app_perror("    error: create_msgint1()", status); 
     769    return NULL; 
    743770} 
    744771 
     
    748775    pj_sockaddr_in mapped_addr; 
    749776    pj_str_t s1; 
    750  
    751     pj_stun_msg_create(pool, v->msg_type, PJ_STUN_MAGIC, 
    752                        (pj_uint8_t*)v->tsx_id, &msg); 
    753  
    754     pj_stun_msg_add_string_attr(pool, msg, PJ_STUN_ATTR_SOFTWARE,  
    755                                 pj_cstr(&s1, "test vector")); 
    756  
    757     pj_sockaddr_in_init(&mapped_addr, pj_cstr(&s1, "192.0.2.1"), 32853); 
    758     pj_stun_msg_add_sockaddr_attr(pool, msg, PJ_STUN_ATTR_XOR_MAPPED_ADDR, 
    759                                   PJ_TRUE, &mapped_addr,  
    760                                   sizeof(pj_sockaddr_in)); 
    761  
    762     pj_stun_msg_add_msgint_attr(pool, msg); 
    763     pj_stun_msg_add_uint_attr(pool, msg, PJ_STUN_ATTR_FINGERPRINT, 0); 
     777    pj_status_t status; 
     778 
     779    status = pj_stun_msg_create(pool, v->msg_type, PJ_STUN_MAGIC, 
     780                                (pj_uint8_t*)v->tsx_id, &msg); 
     781    if (status != PJ_SUCCESS) 
     782        goto on_error; 
     783 
     784    status = pj_stun_msg_add_string_attr(pool, msg, PJ_STUN_ATTR_SOFTWARE,  
     785                                         pj_cstr(&s1, "test vector")); 
     786    if (status != PJ_SUCCESS) 
     787        goto on_error; 
     788 
     789    status = pj_sockaddr_in_init(&mapped_addr, pj_cstr(&s1, "192.0.2.1"),  
     790                                 32853); 
     791    if (status != PJ_SUCCESS) 
     792        goto on_error; 
     793 
     794    status = pj_stun_msg_add_sockaddr_attr(pool, msg,  
     795                                           PJ_STUN_ATTR_XOR_MAPPED_ADDR, 
     796                                           PJ_TRUE, &mapped_addr,  
     797                                           sizeof(pj_sockaddr_in)); 
     798    if (status != PJ_SUCCESS) 
     799        goto on_error; 
     800 
     801    status = pj_stun_msg_add_msgint_attr(pool, msg); 
     802    if (status != PJ_SUCCESS) 
     803        goto on_error; 
     804 
     805    status = pj_stun_msg_add_uint_attr(pool, msg, PJ_STUN_ATTR_FINGERPRINT, 0); 
     806    if (status != PJ_SUCCESS) 
     807        goto on_error; 
    764808 
    765809    return msg; 
     810 
     811on_error: 
     812    app_perror("    error: create_msgint2()", status); 
     813    return NULL; 
    766814} 
    767815 
     
    772820    pj_sockaddr mapped_addr; 
    773821    pj_str_t s1; 
    774  
    775     pj_stun_msg_create(pool, v->msg_type, PJ_STUN_MAGIC, 
    776                        (pj_uint8_t*)v->tsx_id, &msg); 
    777  
    778     pj_stun_msg_add_string_attr(pool, msg, PJ_STUN_ATTR_SOFTWARE,  
    779                                 pj_cstr(&s1, "test vector")); 
    780  
    781     pj_sockaddr_init(pj_AF_INET6(), &mapped_addr, 
    782                      pj_cstr(&s1, "2001:db8:1234:5678:11:2233:4455:6677"), 
    783                      32853); 
    784  
    785     pj_stun_msg_add_sockaddr_attr(pool, msg, PJ_STUN_ATTR_XOR_MAPPED_ADDR, 
    786                                   PJ_TRUE, &mapped_addr,  
    787                                   sizeof(pj_sockaddr)); 
    788  
    789     pj_stun_msg_add_msgint_attr(pool, msg); 
    790     pj_stun_msg_add_uint_attr(pool, msg, PJ_STUN_ATTR_FINGERPRINT, 0); 
     822    pj_status_t status; 
     823 
     824    status = pj_stun_msg_create(pool, v->msg_type, PJ_STUN_MAGIC, 
     825                                (pj_uint8_t*)v->tsx_id, &msg); 
     826    if (status != PJ_SUCCESS) 
     827        goto on_error; 
     828 
     829    status = pj_stun_msg_add_string_attr(pool, msg, PJ_STUN_ATTR_SOFTWARE,  
     830                                         pj_cstr(&s1, "test vector")); 
     831    if (status != PJ_SUCCESS) 
     832        goto on_error; 
     833 
     834    status = pj_sockaddr_init(pj_AF_INET6(), &mapped_addr, 
     835                      pj_cstr(&s1, "2001:db8:1234:5678:11:2233:4455:6677"), 
     836                      32853); 
     837    if (status != PJ_SUCCESS) 
     838        goto on_error; 
     839 
     840    status = pj_stun_msg_add_sockaddr_attr(pool, msg,  
     841                                           PJ_STUN_ATTR_XOR_MAPPED_ADDR, 
     842                                           PJ_TRUE, &mapped_addr,  
     843                                           sizeof(pj_sockaddr)); 
     844    if (status != PJ_SUCCESS) 
     845        goto on_error; 
     846 
     847    status = pj_stun_msg_add_msgint_attr(pool, msg); 
     848    if (status != PJ_SUCCESS) 
     849        goto on_error; 
     850 
     851    status = pj_stun_msg_add_uint_attr(pool, msg, PJ_STUN_ATTR_FINGERPRINT, 0); 
     852    if (status != PJ_SUCCESS) 
     853        goto on_error; 
    791854 
    792855    return msg; 
     856 
     857on_error: 
     858    app_perror("    error: create_msgint3()", status); 
     859    return NULL; 
    793860} 
    794861 
Note: See TracChangeset for help on using the changeset viewer.