Home | History | Annotate | Download | only in googlepatches
      1 diff --git a/google3/third_party/libsrtp/include/srtp_priv.h b/google3/third_party/libsrtp/include/srtp_priv.h
      2 index cf2274e..3bed757 100644
      3 --- a/google3/third_party/libsrtp/include/srtp_priv.h
      4 +++ b/google3/third_party/libsrtp/include/srtp_priv.h
      5 @@ -189,6 +189,13 @@ srtp_stream_init(srtp_stream_t srtp,
      6  
      7  
      8  /*
      9 + * Uninitializes and Deallocates a stream.
     10 + */
     11 +err_status_t
     12 +srtp_stream_uninit_and_dealloc(srtp_stream_t stream,
     13 +                               srtp_stream_t stream_template);
     14 +
     15 +/*
     16   * libsrtp internal datatypes 
     17   */
     18  
     19 diff --git a/google3/third_party/libsrtp/srtp/srtp.c b/google3/third_party/libsrtp/srtp/srtp.c
     20 index 3fc52ee..314c3e4 100644
     21 --- a/google3/third_party/libsrtp/srtp/srtp.c
     22 +++ b/google3/third_party/libsrtp/srtp/srtp.c
     23 @@ -92,35 +92,31 @@ srtp_stream_alloc(srtp_stream_ctx_t **str_ptr,
     24    str = (srtp_stream_ctx_t *) crypto_alloc(sizeof(srtp_stream_ctx_t));
     25    if (str == NULL)
     26      return err_status_alloc_fail;
     27 -  *str_ptr = str;  
     28 -  
     29 +  *str_ptr = str;
     30 +
     31    /* allocate cipher */
     32    stat = crypto_kernel_alloc_cipher(p->rtp.cipher_type, 
     33  				    &str->rtp_cipher, 
     34  				    p->rtp.cipher_key_len); 
     35    if (stat) {
     36 -    crypto_free(str);
     37 -    return stat;
     38 +    goto err_rtp_cipher_alloc;
     39    }
     40  
     41    /* allocate auth function */
     42    stat = crypto_kernel_alloc_auth(p->rtp.auth_type, 
     43  				  &str->rtp_auth,
     44  				  p->rtp.auth_key_len, 
     45 -				  p->rtp.auth_tag_len); 
     46 +				  p->rtp.auth_tag_len);
     47 +
     48    if (stat) {
     49 -    cipher_dealloc(str->rtp_cipher);
     50 -    crypto_free(str);
     51 -    return stat;
     52 +    goto err_rtp_auth_alloc;
     53    }
     54 -  
     55 +
     56    /* allocate key limit structure */
     57    str->limit = (key_limit_ctx_t*) crypto_alloc(sizeof(key_limit_ctx_t));
     58    if (str->limit == NULL) {
     59 -    auth_dealloc(str->rtp_auth);
     60 -    cipher_dealloc(str->rtp_cipher);
     61 -    crypto_free(str); 
     62 -    return err_status_alloc_fail;
     63 +    stat = err_status_alloc_fail;
     64 +    goto err_limit_alloc;
     65    }
     66  
     67    /*
     68 @@ -129,13 +125,9 @@ srtp_stream_alloc(srtp_stream_ctx_t **str_ptr,
     69     */
     70    stat = crypto_kernel_alloc_cipher(p->rtcp.cipher_type, 
     71  				    &str->rtcp_cipher, 
     72 -				    p->rtcp.cipher_key_len); 
     73 +				    p->rtcp.cipher_key_len);
     74    if (stat) {
     75 -    auth_dealloc(str->rtp_auth);
     76 -    cipher_dealloc(str->rtp_cipher);
     77 -    crypto_free(str->limit);
     78 -    crypto_free(str);
     79 -    return stat;
     80 +    goto err_rtcp_cipher_alloc;
     81    }
     82  
     83    /* allocate auth function */
     84 @@ -144,33 +136,37 @@ srtp_stream_alloc(srtp_stream_ctx_t **str_ptr,
     85  				  p->rtcp.auth_key_len, 
     86  				  p->rtcp.auth_tag_len); 
     87    if (stat) {
     88 -    cipher_dealloc(str->rtcp_cipher);
     89 -    auth_dealloc(str->rtp_auth);
     90 -    cipher_dealloc(str->rtp_cipher);
     91 -    crypto_free(str->limit);
     92 -    crypto_free(str);
     93 -   return stat;
     94 -  }  
     95 +    goto err_rtcp_auth_alloc;
     96 +  }
     97  
     98    /* allocate ekt data associated with stream */
     99    stat = ekt_alloc(&str->ekt, p->ekt);
    100    if (stat) {
    101 -    auth_dealloc(str->rtcp_auth);
    102 -    cipher_dealloc(str->rtcp_cipher);
    103 -    auth_dealloc(str->rtp_auth);
    104 -    cipher_dealloc(str->rtp_cipher);
    105 -    crypto_free(str->limit);
    106 -    crypto_free(str);
    107 -   return stat;    
    108 +    goto err_ekt_alloc;
    109    }
    110  
    111    return err_status_ok;
    112 +
    113 +err_ekt_alloc:
    114 +  auth_dealloc(str->rtcp_auth);
    115 +err_rtcp_auth_alloc:
    116 +  cipher_dealloc(str->rtcp_cipher);
    117 +err_rtcp_cipher_alloc:
    118 +  crypto_free(str->limit);
    119 +err_limit_alloc:
    120 +  auth_dealloc(str->rtp_auth);
    121 +err_rtp_auth_alloc:
    122 +  cipher_dealloc(str->rtp_cipher);
    123 +err_rtp_cipher_alloc:
    124 +  crypto_free(str);
    125 +  return stat;
    126  }
    127  
    128  err_status_t
    129 -srtp_stream_dealloc(srtp_t session, srtp_stream_ctx_t *stream) { 
    130 +srtp_stream_dealloc(srtp_stream_ctx_t *stream,
    131 +                    srtp_stream_ctx_t *stream_template) {
    132    err_status_t status;
    133 -  
    134 +
    135    /*
    136     * we use a conservative deallocation strategy - if any deallocation
    137     * fails, then we report that fact without trying to deallocate
    138 @@ -178,41 +174,29 @@ srtp_stream_dealloc(srtp_t session, srtp_stream_ctx_t *stream) {
    139     */
    140  
    141    /* deallocate cipher, if it is not the same as that in template */
    142 -  if (session->stream_template
    143 -      && stream->rtp_cipher == session->stream_template->rtp_cipher) {
    144 -    /* do nothing */
    145 -  } else {
    146 +  if (!stream_template || stream->rtp_cipher != stream_template->rtp_cipher) {
    147      status = cipher_dealloc(stream->rtp_cipher); 
    148      if (status) 
    149        return status;
    150    }
    151  
    152    /* deallocate auth function, if it is not the same as that in template */
    153 -  if (session->stream_template
    154 -      && stream->rtp_auth == session->stream_template->rtp_auth) {
    155 -    /* do nothing */
    156 -  } else {
    157 +  if (!stream_template || stream->rtp_auth != stream_template->rtp_auth) {
    158      status = auth_dealloc(stream->rtp_auth);
    159      if (status)
    160        return status;
    161    }
    162  
    163    /* deallocate key usage limit, if it is not the same as that in template */
    164 -  if (session->stream_template
    165 -      && stream->limit == session->stream_template->limit) {
    166 -    /* do nothing */
    167 -  } else {
    168 +  if (!stream_template || stream->limit != stream_template->limit) {
    169      crypto_free(stream->limit);
    170 -  }   
    171 +  }
    172  
    173 -  /* 
    174 +  /*
    175     * deallocate rtcp cipher, if it is not the same as that in
    176 -   * template 
    177 +   * template
    178     */
    179 -  if (session->stream_template
    180 -      && stream->rtcp_cipher == session->stream_template->rtcp_cipher) {
    181 -    /* do nothing */
    182 -  } else {
    183 +  if (!stream_template || stream->rtcp_cipher != stream_template->rtcp_cipher) {
    184      status = cipher_dealloc(stream->rtcp_cipher); 
    185      if (status) 
    186        return status;
    187 @@ -222,17 +206,14 @@ srtp_stream_dealloc(srtp_t session, srtp_stream_ctx_t *stream) {
    188     * deallocate rtcp auth function, if it is not the same as that in
    189     * template 
    190     */
    191 -  if (session->stream_template
    192 -      && stream->rtcp_auth == session->stream_template->rtcp_auth) {
    193 -    /* do nothing */
    194 -  } else {
    195 +  if (!stream_template || stream->rtcp_auth != stream_template->rtcp_auth) {
    196      status = auth_dealloc(stream->rtcp_auth);
    197      if (status)
    198        return status;
    199    }
    200  
    201    /* DAM - need to deallocate EKT here */
    202 -  
    203 +
    204    /* deallocate srtp stream context */
    205    crypto_free(stream);
    206  
    207 @@ -549,7 +530,12 @@ srtp_stream_init(srtp_stream_ctx_t *srtp,
    208     }
    209  
    210     return err_status_ok;  
    211 - }
    212 +}
    213 +
    214 +err_status_t
    215 +srtp_stream_uninit(srtp_stream_ctx_t *srtp) {
    216 +  return rdbx_uninit(&srtp->rtp_rdbx);
    217 +}
    218  
    219  
    220   /*
    221 @@ -1201,28 +1187,16 @@ srtp_dealloc(srtp_t session) {
    222    stream = session->stream_list;
    223    while (stream != NULL) {
    224      srtp_stream_t next = stream->next;
    225 -    status = srtp_stream_dealloc(session, stream);
    226 -    if (status)
    227 +    status = srtp_stream_uninit_and_dealloc(stream, session->stream_template);
    228 +    if (status) {
    229        return status;
    230 +    }
    231      stream = next;
    232    }
    233 -  
    234 +
    235    /* deallocate stream template, if there is one */
    236    if (session->stream_template != NULL) {
    237 -    status = auth_dealloc(session->stream_template->rtcp_auth); 
    238 -    if (status) 
    239 -      return status; 
    240 -    status = cipher_dealloc(session->stream_template->rtcp_cipher); 
    241 -    if (status) 
    242 -      return status; 
    243 -    crypto_free(session->stream_template->limit);
    244 -    status = cipher_dealloc(session->stream_template->rtp_cipher); 
    245 -    if (status) 
    246 -      return status; 
    247 -    status = auth_dealloc(session->stream_template->rtp_auth);
    248 -    if (status)
    249 -      return status;
    250 -    crypto_free(session->stream_template);
    251 +    status = srtp_stream_uninit_and_dealloc(session->stream_template, NULL);
    252    }
    253  
    254    /* deallocate session context */
    255 @@ -1287,7 +1261,6 @@ srtp_add_stream(srtp_t session,
    256      crypto_free(tmp);
    257      return err_status_bad_param;
    258    }
    259 -    
    260    return err_status_ok;
    261  }
    262  
    263 @@ -1334,12 +1307,11 @@ srtp_create(srtp_t *session,               /* handle for session     */
    264  err_status_t
    265  srtp_remove_stream(srtp_t session, uint32_t ssrc) {
    266    srtp_stream_ctx_t *stream, *last_stream;
    267 -  err_status_t status;
    268  
    269    /* sanity check arguments */
    270    if (session == NULL)
    271      return err_status_bad_param;
    272 -  
    273 +
    274    /* find stream in list; complain if not found */
    275    last_stream = stream = session->stream_list;
    276    while ((stream != NULL) && (ssrc != stream->ssrc)) {
    277 @@ -1352,8 +1324,20 @@ srtp_remove_stream(srtp_t session, uint32_t ssrc) {
    278    /* remove stream from the list */
    279    last_stream->next = stream->next;
    280  
    281 +  return srtp_stream_uninit_and_dealloc(stream, session->stream_template);
    282 +}
    283 +
    284 +err_status_t
    285 +srtp_stream_uninit_and_dealloc(srtp_stream_ctx_t *stream,
    286 +                               srtp_stream_ctx_t *stream_template) {
    287 +  err_status_t status;
    288 +  /* deallocate rdbx data */
    289 +  status = srtp_stream_uninit(stream);
    290 +  if (status)
    291 +    return status;
    292 +
    293    /* deallocate the stream */
    294 -  status = srtp_stream_dealloc(session, stream);
    295 +  status = srtp_stream_dealloc(stream, stream_template);
    296    if (status)
    297      return status;
    298  
    299