Browse code

tcp: stun fixes

Andrei Pelinescu-Onciul authored on 10/04/2009 11:26:11
Showing 1 changed files
... ...
@@ -414,7 +414,7 @@ int tcp_read_headers(struct tcp_connection *c, int* read_flags)
414 414
 							r->state=H_STUN_MSG;
415 415
 						/* body will used as pointer to the last used byte */
416 416
 							r->body=p;
417
-							body_len = 0;
417
+							r->content_len = 0;
418 418
 							DBG("stun msg detected\n");
419 419
 						}else
420 420
 #endif
... ...
@@ -456,14 +456,13 @@ int tcp_read_headers(struct tcp_connection *c, int* read_flags)
456 456
 #ifdef USE_STUN
457 457
 			case H_STUN_MSG:
458 458
 				if ((r->pos - r->body) >= sizeof(struct stun_hdr)) {
459
-					r->content_len = 0;
460 459
 					/* copy second short from buffer where should be body 
461 460
 					 * length 
462 461
 					 */
463 462
 					memcpy(&body_len, &r->start[sizeof(unsigned short)], 
464 463
 						sizeof(unsigned short));
465 464
 					
466
-					body_len = ntohs(r->content_len);
465
+					body_len = ntohs(body_len);
467 466
 					
468 467
 					/* check if there is valid magic cookie */
469 468
 					memcpy(&mc, &r->start[sizeof(unsigned int)], 
... ...
@@ -490,6 +489,7 @@ int tcp_read_headers(struct tcp_connection *c, int* read_flags)
490 490
 									   SHA_DIGEST_LENGTH;
491 491
 						}
492 492
 					}
493
+					r->content_len=body_len;
493 494
 				}
494 495
 				else {
495 496
 					p = r->pos; 
... ...
@@ -498,15 +498,18 @@ int tcp_read_headers(struct tcp_connection *c, int* read_flags)
498 498
 				
499 499
 			case H_STUN_READ_BODY:
500 500
 				/* check if the whole body was read */
501
+				body_len=r->content_len;
501 502
 				if ((r->pos - r->body) >= body_len) {
502 503
 					r->body += body_len;
503 504
 					p = r->body;
504 505
 					if (is_msg_complete(r) != 0) {
506
+						r->content_len=0;
505 507
 						goto skip;
506 508
 					}
507 509
 					else {
508 510
 						/* set content_len to length of fingerprint */
509 511
 						body_len = sizeof(struct stun_attr)+SHA_DIGEST_LENGTH;
512
+						r->content_len=body_len;
510 513
 					}
511 514
 				}
512 515
 				else {
... ...
@@ -516,12 +519,14 @@ int tcp_read_headers(struct tcp_connection *c, int* read_flags)
516 516
 				
517 517
 			case H_STUN_FP:
518 518
 				/* content_len contains length of fingerprint in this place! */
519
+				body_len=r->content_len;
519 520
 				if ((r->pos - r->body) >= body_len) {
520 521
 					r->body += body_len;
521 522
 					p = r->body;
522 523
 					r->state = H_STUN_END;
523 524
 					r->flags |= F_TCP_REQ_COMPLETE |
524 525
 						F_TCP_REQ_HAS_CLEN; /* hack to avoid error check */
526
+					r->content_len=0;
525 527
 					goto skip;
526 528
 				}
527 529
 				else {