Changeset 5872


Ignore:
Timestamp:
Sep 3, 2018 7:13:40 AM (6 years ago)
Author:
ming
Message:

Re #2100: Fixed duplication of crypto names and keys to use pj_strdup(). Otherwise, when the account/global config's input strings are modified (or deallocated) after being passed to PJSIP, then the crypto name matching will fail and we will generate error: PJMEDIA_SRTP_ENOTSUPCRYPTO

Location:
pjproject/trunk/pjsip
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h

    r5834 r5872  
    40784078 
    40794079/** 
     4080 * Duplicate SRTP transport setting. If the \a pool argument is NULL, 
     4081 * a simple memcpy() will be used. 
     4082 * 
     4083 * @param pool      Memory to duplicate strings. 
     4084 * @param dst       Destination setting. 
     4085 * @param src       Source setting. 
     4086 * @param check_str If set to TRUE, the function will check if strings 
     4087 *                  are identical before copying. Identical strings 
     4088 *                  will not be duplicated. 
     4089 *                  If set to FALSE, all strings will be duplicated. 
     4090 */ 
     4091PJ_DECL(void) pjsua_srtp_opt_dup(pj_pool_t *pool, pjsua_srtp_opt *dst, 
     4092                                 const pjsua_srtp_opt *src, 
     4093                                 pj_bool_t check_str); 
     4094 
     4095 
     4096/** 
    40804097 * Call this function to initialize account config with default values. 
    40814098 * 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c

    r5838 r5872  
    140140    pjsua_turn_config_dup(pool, &dst->turn_cfg, &src->turn_cfg); 
    141141 
     142    pjsua_srtp_opt_dup(pool, &dst->srtp_opt, &src->srtp_opt, PJ_FALSE); 
     143 
    142144    pj_strdup(pool, &dst->ka_data, &src->ka_data); 
    143145 
     
    14241426    acc->cfg.ip_change_cfg.hangup_calls = cfg->ip_change_cfg.hangup_calls;     
    14251427    acc->cfg.ip_change_cfg.reinvite_flags = cfg->ip_change_cfg.reinvite_flags; 
     1428 
     1429    /* SRTP setting */ 
     1430    pjsua_srtp_opt_dup(acc->pool, &acc->cfg.srtp_opt, &cfg->srtp_opt, 
     1431                       PJ_TRUE); 
    14261432 
    14271433    /* RTCP-FB config */ 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c

    r5856 r5872  
    144144        pj_strdup_with_null(pool, &dst->stun_srv[i], &src->stun_srv[i]); 
    145145    } 
     146 
     147    pjsua_srtp_opt_dup(pool, &dst->srtp_opt, &src->srtp_opt, PJ_FALSE); 
    146148} 
    147149 
     
    261263{ 
    262264    pj_bzero(cfg, sizeof(*cfg)); 
     265} 
     266 
     267 
     268PJ_DEF(void) pjsua_srtp_opt_dup( pj_pool_t *pool, pjsua_srtp_opt *dst, 
     269                                 const pjsua_srtp_opt *src, 
     270                                 pj_bool_t check_str) 
     271{ 
     272    pj_memcpy(dst, src, sizeof(*src)); 
     273    if (pool) { 
     274        unsigned i; 
     275         
     276        for (i = 0; i < src->crypto_count; i++) { 
     277            if (!check_str || 
     278                pj_stricmp(&dst->crypto[i].key, &src->crypto[i].key)) 
     279            { 
     280                pj_strdup(pool, &dst->crypto[i].key, &src->crypto[i].key); 
     281            } 
     282            if (!check_str || 
     283                pj_stricmp(&dst->crypto[i].name, &src->crypto[i].name)) 
     284            { 
     285                pj_strdup(pool, &dst->crypto[i].name, &src->crypto[i].name); 
     286            } 
     287        } 
     288    } 
    263289} 
    264290 
Note: See TracChangeset for help on using the changeset viewer.