Changeset 6040


Ignore:
Timestamp:
Jul 18, 2019 9:51:00 AM (5 years ago)
Author:
riza
Message:

Fix #2214: Check for PJ_ICE_ST_MAX_CAND when adding new ICE candidate.

File:
1 edited

Legend:

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

    r5983 r6040  
    313313static pj_status_t add_update_turn(pj_ice_strans *ice_st, 
    314314                                   pj_ice_strans_comp *comp, 
    315                                    unsigned idx) 
     315                                   unsigned idx, 
     316                                   unsigned max_cand_cnt) 
    316317{ 
    317318    pj_ice_sess_cand *cand = NULL; 
     
    322323    sock_user_data *data; 
    323324    unsigned i; 
     325    pj_bool_t new_cand = PJ_FALSE; 
    324326    pj_uint8_t tp_id; 
    325327    pj_status_t status; 
     
    384386    /* Add relayed candidate with pending status if there's no existing one */ 
    385387    if (cand == NULL) { 
     388        PJ_ASSERT_RETURN(max_cand_cnt > 0, PJ_ETOOSMALL); 
     389 
    386390        cand = &comp->cand_list[comp->cand_cnt]; 
    387391        cand->type = PJ_ICE_CAND_TYPE_RELAYED; 
     
    390394        cand->transport_id = tp_id; 
    391395        cand->comp_id = (pj_uint8_t) comp->comp_id; 
     396        new_cand = PJ_TRUE; 
    392397    } 
    393398 
     
    421426    } 
    422427 
    423     /* Commit the relayed candidate. */ 
    424     comp->cand_cnt++; 
     428    if (new_cand) { 
     429        /* Commit the relayed candidate. */ 
     430        comp->cand_cnt++; 
     431    } 
    425432 
    426433    PJ_LOG(4,(ice_st->obj_name, 
     
    460467static pj_status_t add_stun_and_host(pj_ice_strans *ice_st, 
    461468                                     pj_ice_strans_comp *comp, 
    462                                      unsigned idx) 
     469                                     unsigned idx, 
     470                                     unsigned max_cand_cnt) 
    463471{ 
    464472    pj_ice_sess_cand *cand; 
     
    469477    sock_user_data *data; 
    470478    pj_status_t status; 
     479 
     480    PJ_ASSERT_RETURN(max_cand_cnt > 0, PJ_ETOOSMALL); 
    471481 
    472482    /* Check if STUN transport or host candidate is configured */ 
     
    566576                               cand->type, &cand->base_addr); 
    567577        comp->cand_cnt++; 
     578        max_cand_cnt--; 
    568579 
    569580        /* Set default candidate to srflx */ 
     
    605616            const pj_sockaddr *addr = &stun_sock_info.aliases[i]; 
    606617 
    607             /* Leave one candidate for relay */ 
    608             if (comp->cand_cnt >= PJ_ICE_ST_MAX_CAND-1) { 
     618            if (max_cand_cnt==0) { 
    609619                PJ_LOG(4,(ice_st->obj_name, "Too many host candidates")); 
    610620                break; 
     
    669679                comp->cand_cnt+=1; 
    670680                cand_cnt++; 
     681                max_cand_cnt--; 
    671682            } 
    672683             
     
    726737    /* Create STUN transport if configured */ 
    727738    for (i=0; i<ice_st->cfg.stun_tp_cnt; ++i) { 
    728         status = add_stun_and_host(ice_st, comp, i); 
     739        unsigned max_cand_cnt = PJ_ICE_ST_MAX_CAND - comp->cand_cnt - 
     740                                ice_st->cfg.turn_tp_cnt; 
     741 
     742        status = PJ_ETOOSMALL; 
     743 
     744        if ((max_cand_cnt > 0) && (max_cand_cnt <= PJ_ICE_ST_MAX_CAND)) 
     745            status = add_stun_and_host(ice_st, comp, i, max_cand_cnt); 
     746 
    729747        if (status != PJ_SUCCESS) { 
    730748            PJ_PERROR(3,(ice_st->obj_name, status, 
     
    737755    /* Create TURN relay if configured. */ 
    738756    for (i=0; i<ice_st->cfg.turn_tp_cnt; ++i) { 
    739         status = add_update_turn(ice_st, comp, i); 
     757        unsigned max_cand_cnt = PJ_ICE_ST_MAX_CAND - comp->cand_cnt; 
     758 
     759        status = PJ_ETOOSMALL; 
     760 
     761        if ((max_cand_cnt > 0) && (max_cand_cnt <= PJ_ICE_ST_MAX_CAND)) 
     762            status = add_update_turn(ice_st, comp, i, max_cand_cnt); 
     763 
    740764        if (status != PJ_SUCCESS) { 
    741765            PJ_PERROR(3,(ice_st->obj_name, status, 
    742766                         "Failed creating TURN transport #%d for comp %d", 
    743767                         i, comp->comp_id)); 
     768 
    744769            //return status; 
     770        } else if (max_cand_cnt > 0) { 
     771            max_cand_cnt = PJ_ICE_ST_MAX_CAND - comp->cand_cnt; 
    745772        } 
    746773    } 
     
    22452272                          "Comp %d: TURN allocation failed, retrying", 
    22462273                          comp->comp_id)); 
    2247                 add_update_turn(comp->ice_st, comp, tp_idx); 
     2274                add_update_turn(comp->ice_st, comp, tp_idx, 
     2275                                PJ_ICE_ST_MAX_CAND - comp->cand_cnt); 
    22482276            } 
    22492277        } 
Note: See TracChangeset for help on using the changeset viewer.