Module: sip-router Branch: 4.0 Commit: 92f29137c8815ba5a4cf5cb98a1e1a10d4c7f9af URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=92f29137...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: Fri Feb 21 15:48:36 2014 +0100
lib/kcore: fix loop on broken values matching the prefix of a good value in parse_supported()
- reported by Savolainen Dmitri, FS#396
---
lib/kcore/parse_supported.c | 59 +++++++++++++++++++++++------------------- 1 files changed, 32 insertions(+), 27 deletions(-)
diff --git a/lib/kcore/parse_supported.c b/lib/kcore/parse_supported.c index eb90290..1c2b7a8 100644 --- a/lib/kcore/parse_supported.c +++ b/lib/kcore/parse_supported.c @@ -50,6 +50,7 @@ static inline int parse_supported_body(str *body, unsigned int *sup) register char* p; register unsigned int val; int len, pos = 0; + int case_found;
*sup = 0;
@@ -61,6 +62,7 @@ static inline int parse_supported_body(str *body, unsigned int *sup) for (; pos < len && IS_DELIM(p); ++pos, ++p);
val = LOWER_DWORD(READ(p)); + case_found = 0; switch (val) {
/* "path" */ @@ -68,6 +70,7 @@ static inline int parse_supported_body(str *body, unsigned int *sup) if(pos + 4 <= len && IS_DELIM(p+4)) { *sup |= F_SUPPORTED_PATH; pos += 5; p += 5; + case_found = 1; } break;
@@ -79,6 +82,7 @@ static inline int parse_supported_body(str *body, unsigned int *sup) *sup |= F_SUPPORTED_100REL; pos += SUPPORTED_100REL_LEN + 1; p += SUPPORTED_100REL_LEN + 1; + case_found = 1; } break;
@@ -89,37 +93,38 @@ static inline int parse_supported_body(str *body, unsigned int *sup) *sup |= F_SUPPORTED_TIMER; pos += SUPPORTED_TIMER_LEN + 1; p += SUPPORTED_TIMER_LEN + 1; + case_found = 1; } break; + }
+ if(case_found==0) { /* extra supported or unknown */ - default: - if(pos+SUPPORTED_EVENTLIST_LEN<=len - && strncasecmp(p, SUPPORTED_EVENTLIST_STR, - SUPPORTED_EVENTLIST_LEN)==0 - && IS_DELIM(p+SUPPORTED_EVENTLIST_LEN) ) { - *sup |= F_SUPPORTED_EVENTLIST; - pos += SUPPORTED_EVENTLIST_LEN + 1; - p += SUPPORTED_EVENTLIST_LEN + 1; - } else if(pos+SUPPORTED_GRUU_LEN<=len - && strncasecmp(p, SUPPORTED_GRUU_STR, - SUPPORTED_GRUU_LEN)==0 - && IS_DELIM(p+SUPPORTED_GRUU_LEN)) { - *sup |= F_SUPPORTED_GRUU; - pos += SUPPORTED_GRUU_LEN + 1; - p += SUPPORTED_GRUU_LEN + 1; - } else if(pos+SUPPORTED_OUTBOUND_LEN<=len - && strncasecmp(p, SUPPORTED_OUTBOUND_STR, - SUPPORTED_OUTBOUND_LEN)==0 - && IS_DELIM(p+SUPPORTED_OUTBOUND_LEN)) { - *sup |= F_SUPPORTED_OUTBOUND; - pos += SUPPORTED_OUTBOUND_LEN + 1; - p += SUPPORTED_OUTBOUND_LEN + 1; - } else { - /* skip element */ - for (; pos < len && !IS_DELIM(p); ++pos, ++p); - } - break; + if(pos+SUPPORTED_EVENTLIST_LEN<=len + && strncasecmp(p, SUPPORTED_EVENTLIST_STR, + SUPPORTED_EVENTLIST_LEN)==0 + && IS_DELIM(p+SUPPORTED_EVENTLIST_LEN) ) { + *sup |= F_SUPPORTED_EVENTLIST; + pos += SUPPORTED_EVENTLIST_LEN + 1; + p += SUPPORTED_EVENTLIST_LEN + 1; + } else if(pos+SUPPORTED_GRUU_LEN<=len + && strncasecmp(p, SUPPORTED_GRUU_STR, + SUPPORTED_GRUU_LEN)==0 + && IS_DELIM(p+SUPPORTED_GRUU_LEN)) { + *sup |= F_SUPPORTED_GRUU; + pos += SUPPORTED_GRUU_LEN + 1; + p += SUPPORTED_GRUU_LEN + 1; + } else if(pos+SUPPORTED_OUTBOUND_LEN<=len + && strncasecmp(p, SUPPORTED_OUTBOUND_STR, + SUPPORTED_OUTBOUND_LEN)==0 + && IS_DELIM(p+SUPPORTED_OUTBOUND_LEN)) { + *sup |= F_SUPPORTED_OUTBOUND; + pos += SUPPORTED_OUTBOUND_LEN + 1; + p += SUPPORTED_OUTBOUND_LEN + 1; + } else { + /* skip element */ + for (; pos < len && !IS_DELIM(p); ++pos, ++p); + } } }