PageRenderTime 136ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/external/srtp/googlepatches/google-9-rdbx-leak-plug.patch

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