[asterisk-commits] russell: branch 1.4 r82802 - /branches/1.4/pbx/pbx_dundi.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Sep 18 11:31:01 CDT 2007


Author: russell
Date: Tue Sep 18 11:31:01 2007
New Revision: 82802

URL: http://svn.digium.com/view/asterisk?view=rev&rev=82802
Log:
When copying the contents from the wildcard peer, do a deep copy instead of
shallow copy so that it doesn't crash when beging destroyed.
(closes issue #10546, patch by me)

Modified:
    branches/1.4/pbx/pbx_dundi.c

Modified: branches/1.4/pbx/pbx_dundi.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/pbx/pbx_dundi.c?view=diff&rev=82802&r1=82801&r2=82802
==============================================================================
--- branches/1.4/pbx/pbx_dundi.c (original)
+++ branches/1.4/pbx/pbx_dundi.c Tue Sep 18 11:31:01 2007
@@ -1503,6 +1503,36 @@
 	aes_decrypt_key128(dst, &peer->them_dcx);
 	aes_encrypt_key128(dst, &peer->them_ecx);
 	return 1;
+}
+
+static void deep_copy_peer(struct dundi_peer *peer_dst, const struct dundi_peer *peer_src)
+{
+	struct permission *cur, *perm;
+
+	memcpy(peer_dst, peer_src, sizeof(*peer_dst));
+	
+	memset(&peer_dst->permit, 0, sizeof(peer_dst->permit));
+	memset(&peer_dst->include, 0, sizeof(peer_dst->permit));
+
+	AST_LIST_TRAVERSE(&peer_src->permit, cur, list) {
+		if (!(perm = ast_calloc(1, sizeof(*perm) + strlen(cur->name) + 1)))
+			continue;
+
+		perm->allow = cur->allow;
+		strcpy(perm->name, cur->name);
+
+		AST_LIST_INSERT_HEAD(&peer_dst->permit, perm, list);
+	}
+
+	AST_LIST_TRAVERSE(&peer_src->include, cur, list) {
+		if (!(perm = ast_calloc(1, sizeof(*perm) + strlen(cur->name) + 1)))
+			continue;
+
+		perm->allow = cur->allow;
+		strcpy(perm->name, cur->name);
+
+		AST_LIST_INSERT_HEAD(&peer_dst->include, perm, list);
+	}
 }
 
 static int handle_command_response(struct dundi_transaction *trans, struct dundi_hdr *hdr, int datalen, int encrypted)
@@ -1607,7 +1637,7 @@
 			/* copy any_peer into a new peer object */
 			peer = ast_calloc(1, sizeof(*peer));
 			if (peer) {
-				memcpy(peer, any_peer, sizeof(*peer));
+				deep_copy_peer(peer, any_peer);
 
 				/* set EID to remote EID */
 				peer->eid = *ies.eids[0];




More information about the asterisk-commits mailing list