Explorar o código

- 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 %!s(int64=20) %!d(string=hai) anos
pai
achega
7418afcf03
Modificáronse 3 ficheiros con 16 adicións e 4 borrados
  1. 1 1
      Makefile.defs
  2. 2 1
      parser/msg_parser.c
  3. 13 2
      parser/parse_via.c

+ 1 - 1
Makefile.defs

@@ -53,7 +53,7 @@ MAIN_NAME=ser
 VERSION = 0
 PATCHLEVEL = 10
 SUBLEVEL =   99
-EXTRAVERSION = -dev3
+EXTRAVERSION = -dev4
 
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")

+ 2 - 1
parser/msg_parser.c

@@ -36,6 +36,7 @@
  *  2003-04-26 ZSW (jiri)
  *  2003-05-01  parser extended to support Accept header field (janakj)
  *  2005-02-23  parse_headers uses hdr_flags_t now (andrei)
+ *  2005-03-02  free_via_list(vb) on via parse error (andrei)
  */
 
 
@@ -117,7 +118,7 @@ char* get_hdr_field(char* buf, char* end, struct hdr_field* hdr)
 			tmp=parse_via(tmp, end, vb);
 			if (vb->error==PARSE_ERROR){
 				LOG(L_ERR, "ERROR: get_hdr_field: bad via\n");
-				pkg_free(vb);
+				free_via_list(vb);
 				goto error;
 			}
 			hdr->parsed=vb;

+ 13 - 2
parser/parse_via.c

@@ -47,6 +47,8 @@
  *  2003-10-27  added support for alias via param parsing [see
  *               draft-ietf-sip-connect-reuse-00.txt.]  (andrei)
  *  2004-03-31  fixed rport set instead of i bug (andrei)
+ *  2005-03-02  if via has multiple bodies, and one of them is bad set
+ *               also the first one as bad (andrei)
  */
 
 
@@ -987,7 +989,12 @@ normal_exit:
 
 
 
-char* parse_via(char* buffer, char* end, struct via_body *vb)
+/*
+ * call it with a vb initialized to 0
+ * returns: pointer after the parsed parts and sets vb->error
+ * WARNING: don't forget to cleanup on error with free_via_list(vb)!
+ */
+char* parse_via(char* buffer, char* end, struct via_body *vbody)
 {
 	char* tmp;
 	char* param_start;
@@ -995,9 +1002,11 @@ char* parse_via(char* buffer, char* end, struct via_body *vb)
 	unsigned char saved_state;
 	int c_nest;
 	int err;
-
+	struct via_body* vb;
 	struct via_param* param;
 
+	vb=vbody; /* keep orignal vbody value, needed to set the error member
+				 in case of multiple via bodies in the same header */
 parse_again:
 	vb->error=PARSE_ERROR;
 	/* parse start of via ( SIP/2.0/UDP    )*/
@@ -1996,6 +2005,8 @@ error:
 		LOG(L_ERR, "ERROR: parse_via: via parse error\n");
 	}
 	vb->error=PARSE_ERROR;
+	vbody->error=PARSE_ERROR; /* make sure the first via body is marked
+								 as bad also */
 	return tmp;
 }