[asterisk-commits] twilson: trunk r348567 - in /trunk: ./ res/res_srtp.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun Dec 18 19:36:23 CST 2011


Author: twilson
Date: Sun Dec 18 19:36:21 2011
New Revision: 348567

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=348567
Log:
Add a separate buffer for SRTCP packets

The function ast_srtp_protect used a common buffer for both SRTP and SRTCP
packets. Since this function can be called from multiple threads for the same
SRTP session (scheduler for SRTCP and channel for SRTP) it was possible for the
packets to become corrupted as the buffer was used by both threads
simultaneously.

This patch adds a separate buffer for SRTCP packets to avoid the problem.

(closes issue ASTERISK-18889, Reported/patch by Daniel Collins)
........

Merged revisions 347995 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 347996 from http://svn.asterisk.org/svn/asterisk/branches/10

Modified:
    trunk/   (props changed)
    trunk/res/res_srtp.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-10-merged' - no diff available.

Modified: trunk/res/res_srtp.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_srtp.c?view=diff&rev=348567&r1=348566&r2=348567
==============================================================================
--- trunk/res/res_srtp.c (original)
+++ trunk/res/res_srtp.c Sun Dec 18 19:36:21 2011
@@ -56,6 +56,7 @@
 	void *data;
 	int warned;
 	unsigned char buf[8192 + AST_FRIENDLY_OFFSET];
+	unsigned char rtcpbuf[8192 + AST_FRIENDLY_OFFSET];
 };
 
 struct ast_srtp_policy {
@@ -401,19 +402,22 @@
 static int ast_srtp_protect(struct ast_srtp *srtp, void **buf, int *len, int rtcp)
 {
 	int res;
+	unsigned char *localbuf;
 
 	if ((*len + SRTP_MAX_TRAILER_LEN) > sizeof(srtp->buf)) {
 		return -1;
 	}
-
-	memcpy(srtp->buf, *buf, *len);
-
-	if ((res = rtcp ? srtp_protect_rtcp(srtp->session, srtp->buf, len) : srtp_protect(srtp->session, srtp->buf, len)) != err_status_ok && res != err_status_replay_fail) {
+	
+	localbuf = rtcp ? srtp->rtcpbuf : srtp->buf;
+
+	memcpy(localbuf, *buf, *len);
+
+	if ((res = rtcp ? srtp_protect_rtcp(srtp->session, localbuf, len) : srtp_protect(srtp->session, localbuf, len)) != err_status_ok && res != err_status_replay_fail) {
 		ast_log(LOG_WARNING, "SRTP protect: %s\n", srtp_errstr(res));
 		return -1;
 	}
 
-	*buf = srtp->buf;
+	*buf = localbuf;
 	return *len;
 }
 




More information about the asterisk-commits mailing list