Selaa lähdekoodia

- fixed bad buffer size calculation in build_res_buf_from_sip_req
(bug reported by daniel & nils)

Andrei Pelinescu-Onciul 22 vuotta sitten
vanhempi
commit
f178e85194
1 muutettua tiedostoa jossa 7 lisäystä ja 3 poistoa
  1. 7 3
      msg_translator.c

+ 7 - 3
msg_translator.c

@@ -643,8 +643,9 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
 	char              backup;
 	char              backup;
 	char              *received_buf;
 	char              *received_buf;
 	char              *rport_buf;
 	char              *rport_buf;
-	unsigned int               received_len;
-	unsigned int               rport_len;
+	unsigned int      received_len;
+	unsigned int      rport_len;
+	unsigned int      delete_len;
 	char              *warning;
 	char              *warning;
 	unsigned int      warning_len;
 	unsigned int      warning_len;
 	int r;
 	int r;
@@ -654,6 +655,7 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
 	received_len=0;
 	received_len=0;
 	rport_buf=0;
 	rport_buf=0;
 	rport_len=0;
 	rport_len=0;
+	delete_len=0;
 	buf=0;
 	buf=0;
 	/* make -Wall happy */
 	/* make -Wall happy */
 	warning=0;
 	warning=0;
@@ -687,6 +689,7 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
 							" rport_builder failed\n");
 							" rport_builder failed\n");
 			goto error01; /* free everything */
 			goto error01; /* free everything */
 		}
 		}
+		delete_len=msg->via1->rport->size+1; /* include ';' */
 	}
 	}
 
 
 	/*computes the lenght of the new response buffer*/
 	/*computes the lenght of the new response buffer*/
@@ -706,7 +709,7 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
 					len+=new_tag_len+TOTAG_TOKEN_LEN/*";tag="*/;
 					len+=new_tag_len+TOTAG_TOKEN_LEN/*";tag="*/;
 			}
 			}
 		} else if (hdr->type==HDR_VIA) {
 		} else if (hdr->type==HDR_VIA) {
-				if (hdr==msg->h_via1) len += received_len+rport_len-RPORT_LEN;
+				if (hdr==msg->h_via1) len += received_len+rport_len;
 		} else if (hdr->type==HDR_RECORDROUTE) {
 		} else if (hdr->type==HDR_RECORDROUTE) {
 				/* RR only for 1xx and 2xx replies */
 				/* RR only for 1xx and 2xx replies */
 				if (code<180 || code>=300) continue;
 				if (code<180 || code>=300) continue;
@@ -717,6 +720,7 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
 		}
 		}
 		len += ((hdr->body.s+hdr->body.len )-hdr->name.s )+CRLF_LEN;
 		len += ((hdr->body.s+hdr->body.len )-hdr->name.s )+CRLF_LEN;
 	}
 	}
+	len-=delete_len;
 	/*lumps length*/
 	/*lumps length*/
 	for(lump=msg->reply_lump;lump;lump=lump->next)
 	for(lump=msg->reply_lump;lump;lump=lump->next)
 		len += lump->text.len;
 		len += lump->text.len;