[sr-dev] git:4.1: core/parser: fix loop on broken values matching the prefix of a good value in parse_option_tag_body ()

Daniel-Constantin Mierla miconda at gmail.com
Fri Feb 21 15:40:51 CET 2014


Module: sip-router
Branch: 4.1
Commit: 774cefd9dfd2253923f95b12269cacbe6b315a77
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=774cefd9dfd2253923f95b12269cacbe6b315a77

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Fri Feb 21 15:37:24 2014 +0100

core/parser: fix loop on broken values matching the prefix of a good value in parse_option_tag_body()

- reported by Savolainen Dmitri, FS#396

(cherry picked from commit 9ff18b15c24a933fa061663add3223b8256a88d1)

---

 parser/parse_option_tags.h |   60 +++++++++++++++++++++++--------------------
 1 files changed, 32 insertions(+), 28 deletions(-)

diff --git a/parser/parse_option_tags.h b/parser/parse_option_tags.h
index c41ce63..db2c0eb 100644
--- a/parser/parse_option_tags.h
+++ b/parser/parse_option_tags.h
@@ -84,6 +84,7 @@ static inline int parse_option_tag_body(str *body, unsigned int *tags)
 	register char* p;
 	register unsigned int val;
 	int len, pos = 0;
+	int case_found;
 
 	*tags = 0;
 
@@ -95,6 +96,7 @@ static inline int parse_option_tag_body(str *body, unsigned int *tags)
 		for (; pos < len && IS_DELIM(p); ++pos, ++p);
 
 		val = LOWER_DWORD(READ(p));
+		case_found = 0;
 		switch (val) {
 
 			/* "path" */
@@ -102,6 +104,7 @@ static inline int parse_option_tag_body(str *body, unsigned int *tags)
 				if(pos + 4 <= len && IS_DELIM(p+4)) {
 					*tags |= F_OPTION_TAG_PATH;
 					pos += 5; p += 5;
+					case_found = 1;
 				}
 				break;
 
@@ -113,6 +116,7 @@ static inline int parse_option_tag_body(str *body, unsigned int *tags)
 					*tags |= F_OPTION_TAG_100REL;
 					pos += OPTION_TAG_100REL_LEN + 1;
 					p   += OPTION_TAG_100REL_LEN + 1;
+					case_found = 1;
 				}
 				break;
 
@@ -123,37 +127,37 @@ static inline int parse_option_tag_body(str *body, unsigned int *tags)
 					*tags |= F_OPTION_TAG_TIMER;
 					pos += OPTION_TAG_TIMER_LEN + 1;
 					p   += OPTION_TAG_TIMER_LEN + 1;
+					case_found = 1;
 				}
 				break;
-
+		}
+		if(case_found==0) {
 			/* extra require or unknown */
-			default:
-				if(pos+OPTION_TAG_EVENTLIST_LEN<=len
-						&& strncasecmp(p, OPTION_TAG_EVENTLIST_STR,
-							OPTION_TAG_EVENTLIST_LEN)==0
-						&& IS_DELIM(p+OPTION_TAG_EVENTLIST_LEN) ) {
-					*tags |= F_OPTION_TAG_EVENTLIST;
-					pos += OPTION_TAG_EVENTLIST_LEN + 1;
-					p   += OPTION_TAG_EVENTLIST_LEN + 1;
-				} else if(pos+OPTION_TAG_GRUU_LEN<=len
-						&& strncasecmp(p, OPTION_TAG_GRUU_STR,
-							OPTION_TAG_GRUU_LEN)==0
-						&& IS_DELIM(p+OPTION_TAG_GRUU_LEN)) {
-					*tags |= F_OPTION_TAG_GRUU;
-					pos += OPTION_TAG_GRUU_LEN + 1;
-					p   += OPTION_TAG_GRUU_LEN + 1;
-				} else if(pos+OPTION_TAG_OUTBOUND_LEN<=len
-						&& strncasecmp(p, OPTION_TAG_OUTBOUND_STR,
-							OPTION_TAG_OUTBOUND_LEN)==0
-						&& IS_DELIM(p+OPTION_TAG_OUTBOUND_LEN)) {
-					*tags |= F_OPTION_TAG_OUTBOUND;
-					pos += OPTION_TAG_OUTBOUND_LEN + 1;
-					p   += OPTION_TAG_OUTBOUND_LEN + 1;
-				} else {
-					/* skip element */
-					for (; pos < len && !IS_DELIM(p); ++pos, ++p);
-				}
-				break;
+			if(pos+OPTION_TAG_EVENTLIST_LEN<=len
+					&& strncasecmp(p, OPTION_TAG_EVENTLIST_STR,
+						OPTION_TAG_EVENTLIST_LEN)==0
+					&& IS_DELIM(p+OPTION_TAG_EVENTLIST_LEN) ) {
+				*tags |= F_OPTION_TAG_EVENTLIST;
+				pos += OPTION_TAG_EVENTLIST_LEN + 1;
+				p   += OPTION_TAG_EVENTLIST_LEN + 1;
+			} else if(pos+OPTION_TAG_GRUU_LEN<=len
+					&& strncasecmp(p, OPTION_TAG_GRUU_STR,
+						OPTION_TAG_GRUU_LEN)==0
+					&& IS_DELIM(p+OPTION_TAG_GRUU_LEN)) {
+				*tags |= F_OPTION_TAG_GRUU;
+				pos += OPTION_TAG_GRUU_LEN + 1;
+				p   += OPTION_TAG_GRUU_LEN + 1;
+			} else if(pos+OPTION_TAG_OUTBOUND_LEN<=len
+					&& strncasecmp(p, OPTION_TAG_OUTBOUND_STR,
+						OPTION_TAG_OUTBOUND_LEN)==0
+					&& IS_DELIM(p+OPTION_TAG_OUTBOUND_LEN)) {
+				*tags |= F_OPTION_TAG_OUTBOUND;
+				pos += OPTION_TAG_OUTBOUND_LEN + 1;
+				p   += OPTION_TAG_OUTBOUND_LEN + 1;
+			} else {
+				/* unknown (not needed) - skip element */
+				for (; pos < len && !IS_DELIM(p); ++pos, ++p);
+			}
 		}
 	}
 	




More information about the sr-dev mailing list