Browse code

- reverse_hex2int/int2reverse_hex switched to unsigned int (int2reverse_hex returned error for large integers)

Andrei Pelinescu-Onciul authored on 29/11/2005 19:28:13
Showing 4 changed files
... ...
@@ -180,7 +180,8 @@
180 180
 #define MCOOKIE_LEN (sizeof(MCOOKIE)-1)
181 181
 /* Maximum length of values appended to Via-branch parameter */
182 182
 #define MAX_BRANCH_PARAM_LEN  (MCOOKIE_LEN+8 /*int2hex*/ + 1 /*sep*/ + \
183
-								MD5_LEN + 1 /*sep*/ + 8 /*int2hex*/ + \
183
+								MD5_LEN /* max(int2hex, MD5_LEN) */ \
184
+								+ 1 /*sep*/ + 8 /*int2hex*/ + \
184 185
 								1 /*extra space, needed by t_calc_branch*/)
185 186
 
186 187
 
... ...
@@ -432,7 +432,7 @@ int forward_reply(struct sip_msg* msg)
432 432
 	unsigned int new_len;
433 433
 	struct sr_module *mod;
434 434
 	int proto;
435
-	int id; /* used only by tcp*/
435
+	unsigned int id; /* used only by tcp*/
436 436
 #ifdef USE_TCP
437 437
 	char* s;
438 438
 	int len;
... ...
@@ -497,14 +497,18 @@ int forward_reply(struct sip_msg* msg)
497 497
 		if (msg->via1->i&&msg->via1->i->value.s){
498 498
 			s=msg->via1->i->value.s;
499 499
 			len=msg->via1->i->value.len;
500
-			DBG("forward_reply: i=%.*s\n",len, s);
501
-			id=reverse_hex2int(s, len);
500
+			DBG("forward_reply: i=%.*s\n",len, ZSW(s));
501
+			if (reverse_hex2int(s, len, &id)<0){
502
+				LOG(L_ERR, "ERROR: forward_reply: bad via i param \"%.*s\"\n",
503
+						len, ZSW(s));
504
+					id=0;
505
+			}
502 506
 			DBG("forward_reply: id= %x\n", id);
503 507
 		}		
504 508
 				
505 509
 	} 
506 510
 #endif
507
-	if (msg_send(0, proto, to, id, new_buf, new_len)<0) goto error;
511
+	if (msg_send(0, proto, to, (int)id, new_buf, new_len)<0) goto error;
508 512
 #ifdef STATS
509 513
 	STATS_TX_RESPONSE(  (msg->first_line.u.reply.statuscode/100) );
510 514
 #endif
... ...
@@ -680,9 +680,9 @@ found:
680 680
 int t_reply_matching( struct sip_msg *p_msg , int *p_branch )
681 681
 {
682 682
 	struct cell*  p_cell;
683
-	int hash_index   = 0;
683
+	unsigned int hash_index   = 0;
684 684
 	int entry_label  = 0;
685
-	int branch_id    = 0;
685
+	unsigned int branch_id    = 0;
686 686
 	char  *hashi, *branchi, *p, *n;
687 687
 	int hashl, branchl;
688 688
 	int scan_space;
... ...
@@ -754,15 +754,15 @@ int t_reply_matching( struct sip_msg *p_msg , int *p_branch )
754 754
 	branchi=p;
755 755
 
756 756
 	/* sanity check */
757
-	if ((hash_index=reverse_hex2int(hashi, hashl))<0
757
+	if (reverse_hex2int(hashi, hashl, &hash_index)<0
758 758
 		||hash_index>=TABLE_ENTRIES
759
-		|| (branch_id=reverse_hex2int(branchi, branchl))<0
759
+		|| reverse_hex2int(branchi, branchl, &branch_id)<0
760 760
 		||branch_id>=MAX_BRANCHES
761
-		|| (syn_branch ? (entry_label=reverse_hex2int(syni, synl))<0 
761
+		|| (syn_branch ? (reverse_hex2int(syni, synl, &entry_label))<0 
762 762
 			: loopl!=MD5_LEN )
763 763
 	) {
764 764
 		DBG("DEBUG: t_reply_matching: poor reply labels %d label %d "
765
-			"branch %d\n",hash_index, entry_label, branch_id );
765
+			"branch %d\n", hash_index, entry_label, branch_id );
766 766
 		goto nomatch2;
767 767
 	}
768 768
 
... ...
@@ -816,7 +816,7 @@ int t_reply_matching( struct sip_msg *p_msg , int *p_branch )
816 816
 		   matched !
817 817
 		*/
818 818
 		set_t(p_cell);
819
-		*p_branch = branch_id;
819
+		*p_branch =(int) branch_id;
820 820
 		REF_UNSAFE( T );
821 821
 		UNLOCK_HASH(hash_index);
822 822
 		DBG("DEBUG: t_reply_matching: reply matched (T=%p)!\n",T);
... ...
@@ -191,25 +191,25 @@ static inline char* q_memchr(char* p, int c, unsigned int size)
191 191
 }
192 192
 	
193 193
 
194
-inline static int reverse_hex2int( char *c, int len )
194
+/* returns -1 on error, 1! on success (consistent with int2reverse_hex) */
195
+inline static int reverse_hex2int( char *c, int len, unsigned int* res)
195 196
 {
196 197
 	char *pc;
197
-	int r;
198 198
 	char mychar;
199 199
 
200
-	r=0;
200
+	*res=0;
201 201
 	for (pc=c+len-1; len>0; pc--, len--) {
202
-		r <<= 4 ;
202
+		*res <<= 4 ;
203 203
 		mychar=*pc;
204
-		if ( mychar >='0' && mychar <='9') r+=mychar -'0';
205
-		else if (mychar >='a' && mychar <='f') r+=mychar -'a'+10;
206
-		else if (mychar  >='A' && mychar <='F') r+=mychar -'A'+10;
204
+		if ( mychar >='0' && mychar <='9') *res+=mychar -'0';
205
+		else if (mychar >='a' && mychar <='f') *res+=mychar -'a'+10;
206
+		else if (mychar  >='A' && mychar <='F') *res+=mychar -'A'+10;
207 207
 		else return -1;
208 208
 	}
209
-	return r;
209
+	return 1;
210 210
 }
211 211
 
212
-inline static int int2reverse_hex( char **c, int *size, int nr )
212
+inline static int int2reverse_hex( char **c, int *size, unsigned int nr )
213 213
 {
214 214
 	unsigned short digit;
215 215