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