Module: sip-router Branch: master Commit: 624a9bbf777a1c1d44400eec78911a9714872977 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=624a9bbf...
Author: Richard Fuchs rfuchs@sipwise.com Committer: Richard Fuchs rfuchs@sipwise.com Date: Sun Dec 16 15:06:32 2012 -0500
parser/digest: Fix hunting for Auth header in rare cases
Fix a bug where find_credentials() would fail to find the correct Auth header when multiple headers are present, the one being looked for isn't the first and the full message had been parsed already.
---
parser/digest/digest.c | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/parser/digest/digest.c b/parser/digest/digest.c index 064f42e..512ce31 100644 --- a/parser/digest/digest.c +++ b/parser/digest/digest.c @@ -239,7 +239,7 @@ int get_authorized_cred(struct hdr_field* _f, struct hdr_field** _h) int find_credentials(struct sip_msg* msg, str* realm, hdr_types_t hftype, struct hdr_field** hdr) { - struct hdr_field** hook, *ptr, *prev; + struct hdr_field** hook, *ptr; hdr_flags_t hdr_flags; int res; str* r; @@ -297,15 +297,18 @@ int find_credentials(struct sip_msg* msg, str* realm, } }
- prev = ptr; if (parse_headers(msg, hdr_flags, 1) == -1) { LOG(L_ERR, "auth:find_credentials: Error while parsing headers\n"); return -4; } else { - if (prev != msg->last_header) { - if (msg->last_header->type == hftype) ptr = msg->last_header; - else break; - } else break; + ptr = ptr->next; + while (ptr) { + if (ptr->type == hftype) + break; + ptr = ptr->next; + } + if (!ptr) + break; } }
On Sunday 16 December 2012, Richard Fuchs wrote:
ptr = ptr->next;
while (ptr) {
if (ptr->type == hftype)
break;
ptr = ptr->next;
}
if (!ptr)
break;
There is a dedicated function for walking the sibling headers: next_sibling_hdr(). Please consider using it instead of open coding the loop. Like in attached patch i should have pushed log time ago ;)
On 12/17/12 08:47, Alex Hermann wrote:
On Sunday 16 December 2012, Richard Fuchs wrote:
ptr = ptr->next;
while (ptr) {
if (ptr->type == hftype)
break;
ptr = ptr->next;
}
if (!ptr)
break;
There is a dedicated function for walking the sibling headers: next_sibling_hdr(). Please consider using it instead of open coding the loop. Like in attached patch i should have pushed log time ago ;)
Thanks for the hint. I was looking for a function that does this (couldn't have been the first time someone needed to do that, right?) but couldn't find it. I'll update the code.
cheers