... | ... |
@@ -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 | 489 |
SHA_DIGEST_LENGTH; |
491 | 490 |
} |
492 | 491 |
} |
492 |
+ r->content_len=body_len; |
|
493 | 493 |
} |
494 | 494 |
else { |
495 | 495 |
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 | 519 |
|
517 | 520 |
case H_STUN_FP: |
518 | 521 |
/* content_len contains length of fingerprint in this place! */ |
522 |
+ body_len=r->content_len; |
|
519 | 523 |
if ((r->pos - r->body) >= body_len) { |
520 | 524 |
r->body += body_len; |
521 | 525 |
p = r->body; |
522 | 526 |
r->state = H_STUN_END; |
523 | 527 |
r->flags |= F_TCP_REQ_COMPLETE | |
524 | 528 |
F_TCP_REQ_HAS_CLEN; /* hack to avoid error check */ |
529 |
+ r->content_len=0; |
|
525 | 530 |
goto skip; |
526 | 531 |
} |
527 | 532 |
else { |