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
This commit is contained in:
mikec
2009-07-07 18:06:21 +00:00
parent 24966d14e4
commit 8ef89599be
+26 -18
View File
@@ -1,5 +1,5 @@
--- channels/chan_sip.c.old 2009-06-23 12:13:57.000000000 -0400 --- asterisk-1.4.21.2/channels/chan_sip.c 2008-06-03 10:46:24.000000000 -0400
+++ channels/chan_sip.c 2009-06-23 11:26:25.000000000 -0400 +++ asterisk-1.4.21.2-new/channels/chan_sip.c 2009-07-07 13:46:04.000000000 -0400
@@ -1454,6 +1454,7 @@ @@ -1454,6 +1454,7 @@
static void sip_send_all_registers(void); 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 void append_date(struct sip_request *req); /* Append date to SIP packet */
static int determine_firstline_parts(struct sip_request *req); static int determine_firstline_parts(struct sip_request *req);
static const struct cfsubscription_types *find_subscription_type(enum subscriptiontype subtype); static const struct cfsubscription_types *find_subscription_type(enum subscriptiontype subtype);
@@ -4247,6 +4248,29 @@ @@ -4247,6 +4248,37 @@
return _default; return _default;
} }
@@ -20,25 +20,33 @@
+ const char *cpdr = get_header(req, "CPD-Result");\ + const char *cpdr = get_header(req, "CPD-Result");\
+ /* See if NetBorder had anything to say */ + /* See if NetBorder had anything to say */
+ if (!(ast_strlen_zero(cpdr))) { + if (!(ast_strlen_zero(cpdr))) {
+ /* If so throw a manager event with the result */ + if (p->owner) {
+ char cpd_result[SIPBUFSIZE]; + /* If so throw a manager event with the result */
+ ast_copy_string(cpd_result, get_header(req, "CPD-Result"), sizeof(cpd_result)); + manager_event(
+ manager_event( + EVENT_FLAG_SYSTEM,
+ EVENT_FLAG_SYSTEM, + "CPD-Result",
+ "CPD-Result", + "ChannelDriver: SIP\r\nChannel: %s\r\nCallerIDName: %s\r\nUniqueid: %s\r\nResult: %s\r\n",
+ "ChannelDriver: SIP\r\nChannel: %s\r\nCallerIDName: %s\r\nUniqueid: %s\r\nResult: %s\r\n", + p->owner->name,
+ p->owner->name, + p->owner->cid.cid_name,
+ p->owner->cid.cid_name, + p->owner->uniqueid,
+ p->owner->uniqueid, + cpdr
+ cpd_result + );
+ ); + } 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; + return 0;
+} +}
static const char *__get_header(const struct sip_request *req, const char *name, int *start) 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]; char tmp2[SIPBUFSIZE/2];
const char *l = NULL, *n = NULL; const char *l = NULL, *n = NULL;
const char *urioptions = ""; const char *urioptions = "";
@@ -46,7 +54,7 @@
if (ast_test_flag(&p->flags[0], SIP_USEREQPHONE)) { if (ast_test_flag(&p->flags[0], SIP_USEREQPHONE)) {
const char *s = p->username; /* being a string field, cannot be NULL */ 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)) if (p->options && !ast_strlen_zero(p->options->uri_options))
ast_build_string(&invite, &invite_max, ";%s", 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); ast_string_field_set(p, uri, invite_buf);
if (sipmethod == SIP_NOTIFY && !ast_strlen_zero(p->theirtag)) { if (sipmethod == SIP_NOTIFY && !ast_strlen_zero(p->theirtag)) {
@@ -12740,6 +12768,10 @@ @@ -12740,6 +12776,10 @@
gettag(req, "To", tag, sizeof(tag)); gettag(req, "To", tag, sizeof(tag));
ast_string_field_set(p, theirtag, tag); ast_string_field_set(p, theirtag, tag);
} }