Browse code

- fixed a memory leak in via parsing: on error the via parameters were not freed (reported by Raphael Coeffic) - better error handling for via headers with multiple bodies (if one via body is bad, then the whole via header is marked as invalid)

Andrei Pelinescu-Onciul authored on 02/03/2005 18:42:40
Showing 3 changed files
... ...
@@ -53,7 +53,7 @@ MAIN_NAME=ser
53 53
 VERSION = 0
54 54
 PATCHLEVEL = 10
55 55
 SUBLEVEL =   99
56
-EXTRAVERSION = -dev3
56
+EXTRAVERSION = -dev4
57 57
 
58 58
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
59 59
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
... ...
@@ -36,6 +36,7 @@
36 36
  *  2003-04-26 ZSW (jiri)
37 37
  *  2003-05-01  parser extended to support Accept header field (janakj)
38 38
  *  2005-02-23  parse_headers uses hdr_flags_t now (andrei)
39
+ *  2005-03-02  free_via_list(vb) on via parse error (andrei)
39 40
  */
40 41
 
41 42
 
... ...
@@ -117,7 +118,7 @@ char* get_hdr_field(char* buf, char* end, struct hdr_field* hdr)
117 118
 			tmp=parse_via(tmp, end, vb);
118 119
 			if (vb->error==PARSE_ERROR){
119 120
 				LOG(L_ERR, "ERROR: get_hdr_field: bad via\n");
120
-				pkg_free(vb);
121
+				free_via_list(vb);
121 122
 				goto error;
122 123
 			}
123 124
 			hdr->parsed=vb;
... ...
@@ -47,6 +47,8 @@
47 47
  *  2003-10-27  added support for alias via param parsing [see
48 48
  *               draft-ietf-sip-connect-reuse-00.txt.]  (andrei)
49 49
  *  2004-03-31  fixed rport set instead of i bug (andrei)
50
+ *  2005-03-02  if via has multiple bodies, and one of them is bad set
51
+ *               also the first one as bad (andrei)
50 52
  */
51 53
 
52 54
 
... ...
@@ -987,7 +989,12 @@ normal_exit:
987 989
 
988 990
 
989 991
 
990
-char* parse_via(char* buffer, char* end, struct via_body *vb)
992
+/*
993
+ * call it with a vb initialized to 0
994
+ * returns: pointer after the parsed parts and sets vb->error
995
+ * WARNING: don't forget to cleanup on error with free_via_list(vb)!
996
+ */
997
+char* parse_via(char* buffer, char* end, struct via_body *vbody)
991 998
 {
992 999
 	char* tmp;
993 1000
 	char* param_start;
... ...
@@ -995,9 +1002,11 @@ char* parse_via(char* buffer, char* end, struct via_body *vb)
995 1002
 	unsigned char saved_state;
996 1003
 	int c_nest;
997 1004
 	int err;
998
-
1005
+	struct via_body* vb;
999 1006
 	struct via_param* param;
1000 1007
 
1008
+	vb=vbody; /* keep orignal vbody value, needed to set the error member
1009
+				 in case of multiple via bodies in the same header */
1001 1010
 parse_again:
1002 1011
 	vb->error=PARSE_ERROR;
1003 1012
 	/* parse start of via ( SIP/2.0/UDP    )*/
... ...
@@ -1996,6 +2005,8 @@ error:
1996 2005
 		LOG(L_ERR, "ERROR: parse_via: via parse error\n");
1997 2006
 	}
1998 2007
 	vb->error=PARSE_ERROR;
2008
+	vbody->error=PARSE_ERROR; /* make sure the first via body is marked
2009
+								 as bad also */
1999 2010
 	return tmp;
2000 2011
 }
2001 2012