From 3d7cf301d8fe33a2217a89af244c98ac9c814ac6 Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Tue, 18 Sep 2007 16:34:05 +0000 Subject: [PATCH] Merged revisions 82802 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r82802 | russell | 2007-09-18 11:31:01 -0500 (Tue, 18 Sep 2007) | 4 lines 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) ........ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@82803 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- pbx/pbx_dundi.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/pbx/pbx_dundi.c b/pbx/pbx_dundi.c index 9df585ab76..7e91124af8 100644 --- a/pbx/pbx_dundi.c +++ b/pbx/pbx_dundi.c @@ -1527,6 +1527,36 @@ static int check_key(struct dundi_peer *peer, unsigned char *newkey, unsigned ch 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) { /* Handle canonical command / response */ @@ -1630,7 +1660,7 @@ static int handle_command_response(struct dundi_transaction *trans, struct dundi /* 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];