aboutsummaryrefslogtreecommitdiff
path: root/src/psyc
diff options
context:
space:
mode:
authorGabor X Toth <*@tg-x.net>2014-01-06 00:09:45 +0000
committerGabor X Toth <*@tg-x.net>2014-01-06 00:09:45 +0000
commit5334122e364ba91757d7fc7c1afe403e2d15c39a (patch)
treedca4913f506c9774b67ba408069632377415eea8 /src/psyc
parent1a0ffe2288b97b47a5b2bfbda2f9438680429422 (diff)
downloadgnunet-5334122e364ba91757d7fc7c1afe403e2d15c39a.tar.gz
gnunet-5334122e364ba91757d7fc7c1afe403e2d15c39a.zip
psyc: message handler checks
Diffstat (limited to 'src/psyc')
-rw-r--r--src/psyc/psyc_api.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/psyc/psyc_api.c b/src/psyc/psyc_api.c
index e904e00b5..20394bbce 100644
--- a/src/psyc/psyc_api.c
+++ b/src/psyc/psyc_api.c
@@ -310,8 +310,6 @@ recv_reset (struct GNUNET_PSYC_Channel *ch)
310static void 310static void
311recv_error (struct GNUNET_PSYC_Channel *ch) 311recv_error (struct GNUNET_PSYC_Channel *ch)
312{ 312{
313 recv_reset (ch);
314
315 GNUNET_PSYC_MessageCallback message_cb 313 GNUNET_PSYC_MessageCallback message_cb
316 = ch->recv_flags & GNUNET_PSYC_MESSAGE_HISTORIC 314 = ch->recv_flags & GNUNET_PSYC_MESSAGE_HISTORIC
317 ? ch->hist_message_cb 315 ? ch->hist_message_cb
@@ -319,6 +317,8 @@ recv_error (struct GNUNET_PSYC_Channel *ch)
319 317
320 if (NULL != message_cb) 318 if (NULL != message_cb)
321 message_cb (ch->cb_cls, ch->recv_message_id, ch->recv_flags, NULL); 319 message_cb (ch->cb_cls, ch->recv_message_id, ch->recv_flags, NULL);
320
321 recv_reset (ch);
322} 322}
323 323
324 324
@@ -577,6 +577,7 @@ handle_psyc_message (struct GNUNET_PSYC_Channel *ch,
577 GNUNET_ntohll (msg->message_id), ch->recv_message_id); 577 GNUNET_ntohll (msg->message_id), ch->recv_message_id);
578 GNUNET_break_op (0); 578 GNUNET_break_op (0);
579 recv_error (ch); 579 recv_error (ch);
580 return;
580 } 581 }
581 else if (ntohl (msg->flags) != ch->recv_flags) 582 else if (ntohl (msg->flags) != ch->recv_flags)
582 { 583 {
@@ -585,6 +586,7 @@ handle_psyc_message (struct GNUNET_PSYC_Channel *ch,
585 ntohl (msg->flags), ch->recv_flags); 586 ntohl (msg->flags), ch->recv_flags);
586 GNUNET_break_op (0); 587 GNUNET_break_op (0);
587 recv_error (ch); 588 recv_error (ch);
589 return;
588 } 590 }
589 591
590 uint16_t pos = 0, psize = 0, ptype, size_eq, size_min; 592 uint16_t pos = 0, psize = 0, ptype, size_eq, size_min;
@@ -606,7 +608,8 @@ handle_psyc_message (struct GNUNET_PSYC_Channel *ch,
606 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 608 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
607 "Discarding message of type %u with invalid size %u.\n", 609 "Discarding message of type %u with invalid size %u.\n",
608 ptype, psize); 610 ptype, psize);
609 break; 611 recv_error (ch);
612 return;
610 } 613 }
611 614
612 switch (ptype) 615 switch (ptype)
@@ -625,13 +628,17 @@ handle_psyc_message (struct GNUNET_PSYC_Channel *ch,
625 case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_CANCEL: 628 case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_CANCEL:
626 size_eq = sizeof (struct GNUNET_MessageHeader); 629 size_eq = sizeof (struct GNUNET_MessageHeader);
627 break; 630 break;
631 default:
632 GNUNET_break_op (0);
633 recv_error (ch);
634 return;
628 } 635 }
629 636
630 if (! ((0 < size_eq && psize == size_eq) 637 if (! ((0 < size_eq && psize == size_eq)
631 || (0 < size_min && size_min <= psize))) 638 || (0 < size_min && size_min <= psize)))
632 { 639 {
633 GNUNET_break (0); 640 GNUNET_break_op (0);
634 reschedule_connect (ch); 641 recv_error (ch);
635 return; 642 return;
636 } 643 }
637 644
@@ -693,6 +700,7 @@ handle_psyc_message (struct GNUNET_PSYC_Channel *ch,
693 { 700 {
694 LOG (GNUNET_ERROR_TYPE_WARNING, "Discarding malformed modifier.\n"); 701 LOG (GNUNET_ERROR_TYPE_WARNING, "Discarding malformed modifier.\n");
695 GNUNET_break_op (0); 702 GNUNET_break_op (0);
703 recv_error (ch);
696 return; 704 return;
697 } 705 }
698 ch->recv_state = MSG_STATE_MODIFIER; 706 ch->recv_state = MSG_STATE_MODIFIER;
@@ -709,7 +717,7 @@ handle_psyc_message (struct GNUNET_PSYC_Channel *ch,
709 LOG (GNUNET_ERROR_TYPE_WARNING, 717 LOG (GNUNET_ERROR_TYPE_WARNING,
710 "Discarding out of order message modifier continuation.\n"); 718 "Discarding out of order message modifier continuation.\n");
711 GNUNET_break_op (0); 719 GNUNET_break_op (0);
712 recv_reset (ch); 720 recv_error (ch);
713 return; 721 return;
714 } 722 }
715 break; 723 break;
@@ -722,7 +730,7 @@ handle_psyc_message (struct GNUNET_PSYC_Channel *ch,
722 LOG (GNUNET_ERROR_TYPE_WARNING, 730 LOG (GNUNET_ERROR_TYPE_WARNING,
723 "Discarding out of order message data fragment.\n"); 731 "Discarding out of order message data fragment.\n");
724 GNUNET_break_op (0); 732 GNUNET_break_op (0);
725 recv_reset (ch); 733 recv_error (ch);
726 return; 734 return;
727 } 735 }
728 ch->recv_state = MSG_STATE_DATA; 736 ch->recv_state = MSG_STATE_DATA;
@@ -792,13 +800,15 @@ message_handler (void *cls,
792 case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_ACK: 800 case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_ACK:
793 size_eq = sizeof (struct GNUNET_MessageHeader); 801 size_eq = sizeof (struct GNUNET_MessageHeader);
794 break; 802 break;
803 default:
804 GNUNET_break_op (0);
805 return;
795 } 806 }
796 807
797 if (! ((0 < size_eq && size == size_eq) 808 if (! ((0 < size_eq && size == size_eq)
798 || (0 < size_min && size_min <= size))) 809 || (0 < size_min && size_min <= size)))
799 { 810 {
800 GNUNET_break (0); 811 GNUNET_break_op (0);
801 reschedule_connect (ch);
802 return; 812 return;
803 } 813 }
804 814