From dcde0fb24f71f7fe2a776fdfa02fa4e9b11dc905 Mon Sep 17 00:00:00 2001 From: mikec Date: Tue, 7 Jul 2009 18:06:21 +0000 Subject: [PATCH] Fixed a bug that could cause seemingly random crashes. Apparently asterisk can have sip requests where the owner of the request is null. When we try and throw the channel information for the null owner it would crashed. Added a check which accounts for this. If the owner is null we throw UNKNOWN for the callerid uniqueid and channel. git-svn-id: svn://192.168.202.10@1180 3d104415-ff17-0410-8863-d5cf3c621b8a --- extras/netborder-cpd-1.4.patch | 44 ++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/extras/netborder-cpd-1.4.patch b/extras/netborder-cpd-1.4.patch index c967ff1e..74557145 100644 --- a/extras/netborder-cpd-1.4.patch +++ b/extras/netborder-cpd-1.4.patch @@ -1,5 +1,5 @@ ---- channels/chan_sip.c.old 2009-06-23 12:13:57.000000000 -0400 -+++ channels/chan_sip.c 2009-06-23 11:26:25.000000000 -0400 +--- asterisk-1.4.21.2/channels/chan_sip.c 2008-06-03 10:46:24.000000000 -0400 ++++ asterisk-1.4.21.2-new/channels/chan_sip.c 2009-07-07 13:46:04.000000000 -0400 @@ -1454,6 +1454,7 @@ static void sip_send_all_registers(void); @@ -8,7 +8,7 @@ static void append_date(struct sip_request *req); /* Append date to SIP packet */ static int determine_firstline_parts(struct sip_request *req); static const struct cfsubscription_types *find_subscription_type(enum subscriptiontype subtype); -@@ -4247,6 +4248,29 @@ +@@ -4247,6 +4248,37 @@ return _default; } @@ -20,25 +20,33 @@ + const char *cpdr = get_header(req, "CPD-Result");\ + /* See if NetBorder had anything to say */ + if (!(ast_strlen_zero(cpdr))) { -+ /* If so throw a manager event with the result */ -+ char cpd_result[SIPBUFSIZE]; -+ ast_copy_string(cpd_result, get_header(req, "CPD-Result"), sizeof(cpd_result)); -+ manager_event( -+ EVENT_FLAG_SYSTEM, -+ "CPD-Result", -+ "ChannelDriver: SIP\r\nChannel: %s\r\nCallerIDName: %s\r\nUniqueid: %s\r\nResult: %s\r\n", -+ p->owner->name, -+ p->owner->cid.cid_name, -+ p->owner->uniqueid, -+ cpd_result -+ ); ++ if (p->owner) { ++ /* If so throw a manager event with the result */ ++ manager_event( ++ EVENT_FLAG_SYSTEM, ++ "CPD-Result", ++ "ChannelDriver: SIP\r\nChannel: %s\r\nCallerIDName: %s\r\nUniqueid: %s\r\nResult: %s\r\n", ++ p->owner->name, ++ p->owner->cid.cid_name, ++ p->owner->uniqueid, ++ cpdr ++ ); ++ } else { ++ /* Apparently we can have a CPD-Result and no owner, better not crash it though */ ++ manager_event( ++ EVENT_FLAG_SYSTEM, ++ "CPD-Result", ++ "ChannelDriver: SIP\r\nChannel: UNKNOWN\r\nCallerIDName: UNKNOWN\r\nUniqueid: UNKNOWN\r\nResult: %s\r\n", ++ cpdr ++ ); ++ } + } + return 0; +} static const char *__get_header(const struct sip_request *req, const char *name, int *start) { -@@ -6964,6 +6988,7 @@ +@@ -6964,6 +6996,7 @@ char tmp2[SIPBUFSIZE/2]; const char *l = NULL, *n = NULL; const char *urioptions = ""; @@ -46,7 +54,7 @@ if (ast_test_flag(&p->flags[0], SIP_USEREQPHONE)) { const char *s = p->username; /* being a string field, cannot be NULL */ -@@ -7050,6 +7075,9 @@ +@@ -7050,6 +7083,9 @@ if (p->options && !ast_strlen_zero(p->options->uri_options)) ast_build_string(&invite, &invite_max, ";%s", p->options->uri_options); @@ -56,7 +64,7 @@ ast_string_field_set(p, uri, invite_buf); if (sipmethod == SIP_NOTIFY && !ast_strlen_zero(p->theirtag)) { -@@ -12740,6 +12768,10 @@ +@@ -12740,6 +12776,10 @@ gettag(req, "To", tag, sizeof(tag)); ast_string_field_set(p, theirtag, tag); }