Browse Source

fixed Content-Lenght bug in build_res_buf_with_body_from_sip_req.

Raphael Coeffic 22 years ago
parent
commit
74ed389d55
3 changed files with 11 additions and 5 deletions
  1. 7 4
      msg_translator.c
  2. 2 0
      msg_translator.h
  3. 2 1
      ut.h

+ 7 - 4
msg_translator.c

@@ -889,11 +889,12 @@ char * build_res_buf_with_body_from_sip_req( unsigned int code, char *text ,
 	char              *warning;
 	unsigned int      warning_len;
 	unsigned int	  text_len;
-	int r;
-	int content_len_len;
+	int  r;
+	int  content_len_len;
 	char *content_len;
+	char content_len_buf[MAX_CONTENT_LEN_BUF];
 	char *after_body;
-	str to_tag;
+	str  to_tag;
 	char *totags;
 
 	received_buf=0;
@@ -988,8 +989,10 @@ char * build_res_buf_with_body_from_sip_req( unsigned int code, char *text ,
 
 	if (body_len) {
 		content_len=int2str(body_len, &content_len_len);
+		memcpy(content_len_buf,content_len,content_len_len+1);
+		content_len = content_len_buf;
 		len += CONTENT_LENGTH_LEN + content_len_len + CRLF_LEN;
-	    len += body_len;
+		len += body_len;
 	} else {
 		len +=CONTENT_LENGTH_LEN+1 + CRLF_LEN;
 	}

+ 2 - 0
msg_translator.h

@@ -42,6 +42,8 @@
 #define WARNING_PHRASE " \"Noisy feedback tells: "
 #define WARNING_PHRASE_LEN (sizeof(WARNING_PHRASE)-1)
 
+#define MAX_CONTENT_LEN_BUF INT2STR_MAX_LEN /* see ut.h/int2str() */
+
 #include "parser/msg_parser.h"
 #include "ip_addr.h"
 

+ 2 - 1
ut.h

@@ -148,11 +148,12 @@ static inline int btostr( char *p,  unsigned char val)
 }
 
 
+#define INT2STR_MAX_LEN 11 /* 10 digits + 0 */
 
 /* returns a pointer to a static buffer containing l in asciiz & sets len */
 static inline char* int2str(unsigned int l, int* len)
 {
-	static char r[11]; /* 10 digits + 0 */
+	static char r[INT2STR_MAX_LEN];
 	int i;
 	
 	i=9;