Răsfoiți Sursa

- int2reverse_hex/reverse_hex2int fixes (tm with large "labels" was affected
by it)

Andrei Pelinescu-Onciul 20 ani în urmă
părinte
comite
190a036e67
5 a modificat fișierele cu 28 adăugiri și 23 ștergeri
  1. 1 1
      Makefile.defs
  2. 2 1
      config.h
  3. 8 4
      forward.c
  4. 8 8
      modules/tm/t_lookup.c
  5. 9 9
      ut.h

+ 1 - 1
Makefile.defs

@@ -59,7 +59,7 @@ MAIN_NAME=ser
 VERSION = 0
 PATCHLEVEL = 9
 SUBLEVEL = 5
-EXTRAVERSION = -pre1
+EXTRAVERSION = -pre2
 
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")

+ 2 - 1
config.h

@@ -178,7 +178,8 @@
 #define MCOOKIE_LEN (sizeof(MCOOKIE)-1)
 /* Maximum length of values appended to Via-branch parameter */
 #define MAX_BRANCH_PARAM_LEN  (MCOOKIE_LEN+8 /*int2hex*/ + 1 /*sep*/ + \
-								MD5_LEN + 1 /*sep*/ + 8 /*int2hex*/ + \
+								MD5_LEN /* max(int2hex, MD5_LEN) */ \
+								+ 1 /*sep*/ + 8 /*int2hex*/ + \
 								1 /*extra space, needed by t_calc_branch*/)
 
 

+ 8 - 4
forward.c

@@ -432,7 +432,7 @@ int forward_reply(struct sip_msg* msg)
 	unsigned int new_len;
 	struct sr_module *mod;
 	int proto;
-	int id; /* used only by tcp*/
+	unsigned int id; /* used only by tcp*/
 #ifdef USE_TCP
 	char* s;
 	int len;
@@ -497,14 +497,18 @@ int forward_reply(struct sip_msg* msg)
 		if (msg->via1->i&&msg->via1->i->value.s){
 			s=msg->via1->i->value.s;
 			len=msg->via1->i->value.len;
-			DBG("forward_reply: i=%.*s\n",len, s);
-			id=reverse_hex2int(s, len);
+			DBG("forward_reply: i=%.*s\n",len, ZSW(s));
+			if (reverse_hex2int(s, len, &id)<0){
+				LOG(L_ERR, "ERROR: forward_reply: bad via i param \"%.*s\"\n",
+						len, ZSW(s));
+					id=0;
+			}
 			DBG("forward_reply: id= %x\n", id);
 		}		
 				
 	} 
 #endif
-	if (msg_send(0, proto, to, id, new_buf, new_len)<0) goto error;
+	if (msg_send(0, proto, to, (int)id, new_buf, new_len)<0) goto error;
 #ifdef STATS
 	STATS_TX_RESPONSE(  (msg->first_line.u.reply.statuscode/100) );
 #endif

+ 8 - 8
modules/tm/t_lookup.c

@@ -680,9 +680,9 @@ found:
 int t_reply_matching( struct sip_msg *p_msg , int *p_branch )
 {
 	struct cell*  p_cell;
-	int hash_index   = 0;
-	int entry_label  = 0;
-	int branch_id    = 0;
+	unsigned int hash_index   = 0;
+	unsigned int entry_label  = 0;
+	unsigned int branch_id    = 0;
 	char  *hashi, *branchi, *p, *n;
 	int hashl, branchl;
 	int scan_space;
@@ -754,15 +754,15 @@ int t_reply_matching( struct sip_msg *p_msg , int *p_branch )
 	branchi=p;
 
 	/* sanity check */
-	if ((hash_index=reverse_hex2int(hashi, hashl))<0
+	if (reverse_hex2int(hashi, hashl, &hash_index)<0
 		||hash_index>=TABLE_ENTRIES
-		|| (branch_id=reverse_hex2int(branchi, branchl))<0
+		|| reverse_hex2int(branchi, branchl, &branch_id)<0
 		||branch_id>=MAX_BRANCHES
-		|| (syn_branch ? (entry_label=reverse_hex2int(syni, synl))<0 
+		|| (syn_branch ? (reverse_hex2int(syni, synl, &entry_label))<0 
 			: loopl!=MD5_LEN )
 	) {
 		DBG("DEBUG: t_reply_matching: poor reply labels %d label %d "
-			"branch %d\n",hash_index, entry_label, branch_id );
+			"branch %d\n", hash_index, entry_label, branch_id );
 		goto nomatch2;
 	}
 
@@ -816,7 +816,7 @@ int t_reply_matching( struct sip_msg *p_msg , int *p_branch )
 		   matched !
 		*/
 		set_t(p_cell);
-		*p_branch = branch_id;
+		*p_branch =(int) branch_id;
 		REF_UNSAFE( T );
 		UNLOCK_HASH(hash_index);
 		DBG("DEBUG: t_reply_matching: reply matched (T=%p)!\n",T);

+ 9 - 9
ut.h

@@ -191,25 +191,25 @@ static inline char* q_memchr(char* p, int c, unsigned int size)
 }
 	
 
-inline static int reverse_hex2int( char *c, int len )
+/* returns -1 on error, 1! on success (consistent with int2reverse_hex) */
+inline static int reverse_hex2int( char *c, int len, unsigned int* res)
 {
 	char *pc;
-	int r;
 	char mychar;
 
-	r=0;
+	*res=0;
 	for (pc=c+len-1; len>0; pc--, len--) {
-		r <<= 4 ;
+		*res <<= 4 ;
 		mychar=*pc;
-		if ( mychar >='0' && mychar <='9') r+=mychar -'0';
-		else if (mychar >='a' && mychar <='f') r+=mychar -'a'+10;
-		else if (mychar  >='A' && mychar <='F') r+=mychar -'A'+10;
+		if ( mychar >='0' && mychar <='9') *res+=mychar -'0';
+		else if (mychar >='a' && mychar <='f') *res+=mychar -'a'+10;
+		else if (mychar  >='A' && mychar <='F') *res+=mychar -'A'+10;
 		else return -1;
 	}
-	return r;
+	return 1;
 }
 
-inline static int int2reverse_hex( char **c, int *size, int nr )
+inline static int int2reverse_hex( char **c, int *size, unsigned int nr )
 {
 	unsigned short digit;