mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-30 10:33:13 +00:00
Use built-in parsing functions for Contact and Record-Route headers.
If a Contact or a Record-Route header had a quoted string with an item in angle brackets, then we would mis-parse it. For instance, "Bob <1234>" <1234@example.org> would be misparsed as having the URI "1234" The fix for this is to use parsing functions from reqresp_parser.h since they are heavily tested and are awesome. (issue ASTERISK-18990) ........ Merged revisions 351284 from http://svn.asterisk.org/svn/asterisk/branches/1.8 ........ Merged revisions 351286 from http://svn.asterisk.org/svn/asterisk/branches/10 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@351288 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -14384,7 +14384,7 @@ static void build_route(struct sip_pvt *p, struct sip_request *req, int backward
|
|||||||
struct sip_route *thishop, *head, *tail;
|
struct sip_route *thishop, *head, *tail;
|
||||||
int start = 0;
|
int start = 0;
|
||||||
int len;
|
int len;
|
||||||
const char *rr, *contact, *c;
|
const char *rr, *c;
|
||||||
|
|
||||||
/* Once a persistent route is set, don't fool with it */
|
/* Once a persistent route is set, don't fool with it */
|
||||||
if (p->route && p->route_persistent) {
|
if (p->route && p->route_persistent) {
|
||||||
@@ -14410,17 +14410,22 @@ static void build_route(struct sip_pvt *p, struct sip_request *req, int backward
|
|||||||
/* 1st we pass through all the hops in any Record-Route headers */
|
/* 1st we pass through all the hops in any Record-Route headers */
|
||||||
for (;;) {
|
for (;;) {
|
||||||
/* Each Record-Route header */
|
/* Each Record-Route header */
|
||||||
|
char rr_copy[256];
|
||||||
|
char *rr_copy_ptr;
|
||||||
|
char *rr_iter;
|
||||||
rr = __get_header(req, "Record-Route", &start);
|
rr = __get_header(req, "Record-Route", &start);
|
||||||
if (*rr == '\0') {
|
if (*rr == '\0') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
for (; (rr = strchr(rr, '<')) ; rr += len) { /* Each route entry */
|
ast_copy_string(rr_copy, rr, sizeof(rr_copy));
|
||||||
++rr;
|
rr_copy_ptr = rr_copy;
|
||||||
len = strcspn(rr, ">") + 1;
|
while ((rr_iter = strsep(&rr_copy_ptr, ","))) { /* Each route entry */
|
||||||
|
char *uri = get_in_brackets(rr_iter);
|
||||||
|
len = strlen(uri) + 1;
|
||||||
/* Make a struct route */
|
/* Make a struct route */
|
||||||
if ((thishop = ast_malloc(sizeof(*thishop) + len))) {
|
if ((thishop = ast_malloc(sizeof(*thishop) + len))) {
|
||||||
/* ast_calloc is not needed because all fields are initialized in this block */
|
/* ast_calloc is not needed because all fields are initialized in this block */
|
||||||
ast_copy_string(thishop->hop, rr, len);
|
ast_copy_string(thishop->hop, uri, len);
|
||||||
ast_debug(2, "build_route: Record-Route hop: <%s>\n", thishop->hop);
|
ast_debug(2, "build_route: Record-Route hop: <%s>\n", thishop->hop);
|
||||||
/* Link in */
|
/* Link in */
|
||||||
if (backwards) {
|
if (backwards) {
|
||||||
@@ -14449,20 +14454,12 @@ static void build_route(struct sip_pvt *p, struct sip_request *req, int backward
|
|||||||
if (!head || (!ast_strlen_zero(head->hop) && strstr(head->hop, ";lr") == NULL) ) {
|
if (!head || (!ast_strlen_zero(head->hop) && strstr(head->hop, ";lr") == NULL) ) {
|
||||||
/* 2nd append the Contact: if there is one */
|
/* 2nd append the Contact: if there is one */
|
||||||
/* Can be multiple Contact headers, comma separated values - we just take the first */
|
/* Can be multiple Contact headers, comma separated values - we just take the first */
|
||||||
contact = sip_get_header(req, "Contact");
|
char *contact = ast_strdupa(sip_get_header(req, "Contact"));
|
||||||
if (!ast_strlen_zero(contact)) {
|
if (!ast_strlen_zero(contact)) {
|
||||||
ast_debug(2, "build_route: Contact hop: %s\n", contact);
|
ast_debug(2, "build_route: Contact hop: %s\n", contact);
|
||||||
/* Look for <: delimited address */
|
/* Look for <: delimited address */
|
||||||
c = strchr(contact, '<');
|
c = get_in_brackets(contact);
|
||||||
if (c) {
|
len = strlen(c) + 1;
|
||||||
/* Take to > */
|
|
||||||
++c;
|
|
||||||
len = strcspn(c, ">") + 1;
|
|
||||||
} else {
|
|
||||||
/* No <> - just take the lot */
|
|
||||||
c = contact;
|
|
||||||
len = strlen(contact) + 1;
|
|
||||||
}
|
|
||||||
if ((thishop = ast_malloc(sizeof(*thishop) + len))) {
|
if ((thishop = ast_malloc(sizeof(*thishop) + len))) {
|
||||||
/* ast_calloc is not needed because all fields are initialized in this block */
|
/* ast_calloc is not needed because all fields are initialized in this block */
|
||||||
ast_copy_string(thishop->hop, c, len);
|
ast_copy_string(thishop->hop, c, len);
|
||||||
|
Reference in New Issue
Block a user