Browse code

- fixed a segfault bug in parse msg (printing of via even if via==null)

Andrei Pelinescu-Onciul authored on 24/09/2001 16:51:22
Showing 4 changed files
... ...
@@ -142,6 +142,11 @@ char* get_hdr_field(char *buffer, unsigned int len, struct hdr_field*  hdr_f)
142 142
 	char* body;
143 143
 	int offset;
144 144
 
145
+	
146
+	/* init content to the empty string */
147
+	hdr_f->name="";
148
+	hdr_f->body="";
149
+	
145 150
 	if ((*buffer=='\n')||(*buffer=='\r')){
146 151
 		/* double crlf */
147 152
 		tmp=eat_line(buffer,len);
... ...
@@ -169,7 +174,7 @@ char* get_hdr_field(char *buffer, unsigned int len, struct hdr_field*  hdr_f)
169 174
 	}while( (*tmp==' ' ||  *tmp=='\t') && (offset<len) );
170 175
 	if (offset==len){
171 176
 		hdr_f->type=HDR_ERROR;
172
-		LOG(L_INFO, "ERROR: het_hdr_field: field body too  long\n");
177
+		LOG(L_INFO, "ERROR: get_hdr_field: field body too  long\n");
173 178
 		goto error;
174 179
 	}
175 180
 	*(tmp-1)=0; /* should be an LF */
... ...
@@ -354,6 +359,14 @@ int parse_msg(char* buf, unsigned int len, struct sip_msg* msg)
354 359
 	int offset;
355 360
 
356 361
 	
362
+	/* init vb1 & vb2 to the null string */
363
+	vb1.error=VIA_PARSE_ERROR;
364
+	vb1.hdr=vb1.name=vb1.version=vb1.transport=vb1.host=0;
365
+	vb1.params=vb1.comment=0;
366
+	vb1.next=0;
367
+	vb1.size=0;
368
+	memcpy(&vb2, &vb1, sizeof(struct via_body));
369
+
357 370
 	/* eat crlf from the beginning */
358 371
 	for (tmp=buf; (*tmp=='\n' || *tmp=='\r')&&
359 372
 			tmp-buf < len ; tmp++);
... ...
@@ -457,11 +470,13 @@ skip:
457 470
 
458 471
 #ifdef DEBUG
459 472
 	/* dump parsed data */
460
-	DBG(" first  via: <%s/%s/%s> <%s:%d>",
461
-			vb1.name, vb1.version, vb1.transport, vb1.host, vb1.port);
462
-	if (vb1.params)  DBG(";<%s>", vb1.params);
463
-	if (vb1.comment) DBG(" <%s>", vb1.comment);
464
-	DBG ("\n");
473
+	if (first_via){
474
+		DBG(" first  via: <%s/%s/%s> <%s:%d>",
475
+				vb1.name, vb1.version, vb1.transport, vb1.host, vb1.port);
476
+		if (vb1.params)  DBG(";<%s>", vb1.params);
477
+		if (vb1.comment) DBG(" <%s>", vb1.comment);
478
+		DBG ("\n");
479
+	}
465 480
 	if (second_via){
466 481
 		DBG(" second via: <%s/%s/%s> <%s:%d>",
467 482
 				vb2.name, vb2.version, vb2.transport, vb2.host, vb2.port);
468 483
new file mode 100644
... ...
@@ -0,0 +1,6 @@
1
+INVITE sip:x@y.z SIP/2.0/UDP
2
+Via  : SIP  /   2.0
3
+ /UDP
4
+    193.175.133.193
5
+
6
+
0 7
new file mode 100644
... ...
@@ -0,0 +1,4 @@
1
+INVITE sip:x@y.z SIP/2.0/UDP
2
+V: SIP/2.0/UDP 193.175.133.193
3
+
4
+
0 5
new file mode 100644
... ...
@@ -0,0 +1,3 @@
1
+INVITE sip:x@y.z SIP/2.0/UDP
2
+
3
+