Browse code

- fixed uri too long bug (strlen used in len calculation on non zero terminated uri) & simplified/optimized a little the set* code

Andrei Pelinescu-Onciul authored on 19/03/2003 16:38:18
Showing 2 changed files
... ...
@@ -18,7 +18,7 @@
18 18
 VERSION = 0
19 19
 PATCHLEVEL = 8
20 20
 SUBLEVEL =   11
21
-EXTRAVERSION = pre7
21
+EXTRAVERSION = pre8
22 22
 
23 23
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
24 24
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
... ...
@@ -26,8 +26,10 @@
26 26
  *
27 27
  * History:
28 28
  * ---------
29
- * 2003-02-28 scratchpad compatibility abandoned (jiri)
30
- * 2003-01-29 removed scratchpad (jiri)
29
+ * 2003-02-28  scratchpad compatibility abandoned (jiri)
30
+ * 2003-01-29  removed scratchpad (jiri)
31
+ * 2003-03-19  fixed set* len calculation bug & simplified a little the code
32
+ *              (should be a little faster now) (andrei)
31 33
  */
32 34
 
33 35
 
... ...
@@ -414,7 +416,8 @@ int do_action(struct action* a, struct sip_msg* msg)
414 414
 					tmp=a->p1.string;
415 415
 					len=strlen(tmp); if(crt+len>end) goto error_uri;
416 416
 					memcpy(crt,tmp,len);crt+=len;
417
-					/* whateever we had before, with prefix we have username now */
417
+					/* whatever we had before, with prefix we have username 
418
+					   now */
418 419
 					user=1;
419 420
 				}
420 421
 
... ...
@@ -423,8 +426,9 @@ int do_action(struct action* a, struct sip_msg* msg)
423 423
 					len=strlen(tmp);
424 424
 				} else if (a->type==STRIP_T) {
425 425
 					if (a->p1.number>uri.user.len) {
426
-						LOG(L_WARN, "Error: too long strip asked; deleting username: "
427
-							"%d of <%.*s>\n", a->p1.number, uri.user.len, uri.user.s );
426
+						LOG(L_WARN, "Error: too long strip asked; "
427
+									" deleting username: %d of <%.*s>\n",
428
+									a->p1.number, uri.user.len, uri.user.s );
428 429
 						len=0;
429 430
 					} else if (a->p1.number==uri.user.len) {
430 431
 						len=0;
... ...
@@ -447,19 +451,19 @@ int do_action(struct action* a, struct sip_msg* msg)
447 447
 				else tmp=uri.passwd.s;
448 448
 				/* passwd */
449 449
 				if (tmp){
450
-					len=strlen(":"); if(crt+len>end) goto error_uri;
451
-					memcpy(crt,":",len);crt+=len;
452
-					len=uri.passwd.len; if(crt+len>end) goto error_uri;
450
+					len=uri.passwd.len; if(crt+len+1>end) goto error_uri;
451
+					*crt=':'; crt++;
453 452
 					memcpy(crt,tmp,len);crt+=len;
454 453
 				}
455 454
 				/* host */
456 455
 				if (user || tmp){ /* add @ */
457
-					len=strlen("@"); if(crt+len>end) goto error_uri;
458
-					memcpy(crt,"@",len);crt+=len;
456
+					if(crt+1>end) goto error_uri;
457
+					*crt='@'; crt++;
459 458
 				}
460 459
 				if ((a->type==SET_HOST_T) ||(a->type==SET_HOSTPORT_T)) {
461 460
 					tmp=a->p1.string;
462 461
 					if (tmp) len = strlen(tmp);
462
+					else len=0;
463 463
 				} else {
464 464
 					tmp=uri.host.s;
465 465
 					len = uri.host.len;
... ...
@@ -473,30 +477,28 @@ int do_action(struct action* a, struct sip_msg* msg)
473 473
 				else if (a->type==SET_PORT_T) {
474 474
 					tmp=a->p1.string;
475 475
 					if (tmp) len = strlen(tmp);
476
+					else len = 0;
476 477
 				} else {
477 478
 					tmp=uri.port.s;
478 479
 					len = uri.port.len;
479 480
 				}
480 481
 				if (tmp){
481
-					len=strlen(":"); if(crt+len>end) goto error_uri;
482
-					memcpy(crt,":",len);crt+=len;
483
-					len=strlen(tmp); if(crt+len>end) goto error_uri;
482
+					if(crt+len+1>end) goto error_uri;
483
+					*crt=':'; crt++;
484 484
 					memcpy(crt,tmp,len);crt+=len;
485 485
 				}
486 486
 				/* params */
487 487
 				tmp=uri.params.s;
488 488
 				if (tmp){
489
-					len=strlen(";"); if(crt+len>end) goto error_uri;
490
-					memcpy(crt,";",len);crt+=len;
491
-					len=uri.params.len; if(crt+len>end) goto error_uri;
489
+					len=uri.params.len; if(crt+len+1>end) goto error_uri;
490
+					*crt=';'; crt++;
492 491
 					memcpy(crt,tmp,len);crt+=len;
493 492
 				}
494 493
 				/* headers */
495 494
 				tmp=uri.headers.s;
496 495
 				if (tmp){
497
-					len=strlen("?"); if(crt+len>end) goto error_uri;
498
-					memcpy(crt,"?",len);crt+=len;
499
-					len=uri.headers.len; if(crt+len>end) goto error_uri;
496
+					len=uri.headers.len; if(crt+len+1>end) goto error_uri;
497
+					*crt='?'; crt++;
500 498
 					memcpy(crt,tmp,len);crt+=len;
501 499
 				}
502 500
 				*crt=0; /* null terminate the thing */