diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-05-04 11:44:58 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-05-04 11:44:58 +0000 |
commit | 3fb1330bb4d963049f538297e56942150ef0590c (patch) | |
tree | 8f3019535dace9e449c4488881a76bf272048af3 /src/peerinfo/peerinfo_api.c | |
parent | 463fcbc22b805a862e1d136fe541fc849dc393f0 (diff) | |
download | gnunet-3fb1330bb4d963049f538297e56942150ef0590c.tar.gz gnunet-3fb1330bb4d963049f538297e56942150ef0590c.zip |
-extra IPC checks
Diffstat (limited to 'src/peerinfo/peerinfo_api.c')
-rw-r--r-- | src/peerinfo/peerinfo_api.c | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/src/peerinfo/peerinfo_api.c b/src/peerinfo/peerinfo_api.c index 96857b5a8..0ccd8a61a 100644 --- a/src/peerinfo/peerinfo_api.c +++ b/src/peerinfo/peerinfo_api.c | |||
@@ -121,6 +121,16 @@ struct GNUNET_PEERINFO_IteratorContext | |||
121 | struct GNUNET_TIME_Absolute timeout; | 121 | struct GNUNET_TIME_Absolute timeout; |
122 | 122 | ||
123 | /** | 123 | /** |
124 | * Peer we are interested in (only valid if iteration was restricted to one peer). | ||
125 | */ | ||
126 | struct GNUNET_PeerIdentity peer; | ||
127 | |||
128 | /** | ||
129 | * Is 'peer' set? | ||
130 | */ | ||
131 | int have_peer; | ||
132 | |||
133 | /** | ||
124 | * Are we now receiving? | 134 | * Are we now receiving? |
125 | */ | 135 | */ |
126 | int in_receive; | 136 | int in_receive; |
@@ -476,6 +486,7 @@ peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
476 | const struct InfoMessage *im; | 486 | const struct InfoMessage *im; |
477 | const struct GNUNET_HELLO_Message *hello; | 487 | const struct GNUNET_HELLO_Message *hello; |
478 | GNUNET_PEERINFO_Processor cb; | 488 | GNUNET_PEERINFO_Processor cb; |
489 | struct GNUNET_PeerIdentity id; | ||
479 | void *cb_cls; | 490 | void *cb_cls; |
480 | uint16_t ms; | 491 | uint16_t ms; |
481 | 492 | ||
@@ -519,6 +530,18 @@ peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
519 | } | 530 | } |
520 | im = (const struct InfoMessage *) msg; | 531 | im = (const struct InfoMessage *) msg; |
521 | GNUNET_break (0 == ntohl (im->reserved)); | 532 | GNUNET_break (0 == ntohl (im->reserved)); |
533 | if ( (GNUNET_YES == ic->have_peer) && | ||
534 | (0 != memcmp (&ic->peer, &im->peer, sizeof (struct GNUNET_PeerIdentity))) ) | ||
535 | { | ||
536 | /* bogus message (from a different iteration call?); out of sequence! */ | ||
537 | GNUNET_break (0); | ||
538 | GNUNET_PEERINFO_iterate_cancel (ic); | ||
539 | reconnect (h); | ||
540 | if (NULL != cb) | ||
541 | cb (cb_cls, NULL, NULL, | ||
542 | _("Received invalid message from `PEERINFO' service.")); | ||
543 | return; | ||
544 | } | ||
522 | hello = NULL; | 545 | hello = NULL; |
523 | if (ms > sizeof (struct InfoMessage) + sizeof (struct GNUNET_MessageHeader)) | 546 | if (ms > sizeof (struct InfoMessage) + sizeof (struct GNUNET_MessageHeader)) |
524 | { | 547 | { |
@@ -534,7 +557,30 @@ peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
534 | _("Received invalid message from `PEERINFO' service.")); | 557 | _("Received invalid message from `PEERINFO' service.")); |
535 | return; | 558 | return; |
536 | } | 559 | } |
560 | if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &id)) | ||
561 | { | ||
562 | /* malformed message */ | ||
563 | GNUNET_break (0); | ||
564 | GNUNET_PEERINFO_iterate_cancel (ic); | ||
565 | reconnect (h); | ||
566 | if (NULL != cb) | ||
567 | cb (cb_cls, NULL, NULL, | ||
568 | _("Received invalid message from `PEERINFO' service.")); | ||
569 | return; | ||
570 | } | ||
571 | if (0 != memcmp (&im->peer, &id, sizeof (struct GNUNET_PeerIdentity))) | ||
572 | { | ||
573 | /* malformed message */ | ||
574 | GNUNET_break (0); | ||
575 | GNUNET_PEERINFO_iterate_cancel (ic); | ||
576 | reconnect (h); | ||
577 | if (NULL != cb) | ||
578 | cb (cb_cls, NULL, NULL, | ||
579 | _("Received invalid message from `PEERINFO' service.")); | ||
580 | return; | ||
581 | } | ||
537 | } | 582 | } |
583 | |||
538 | /* normal data message */ | 584 | /* normal data message */ |
539 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 585 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
540 | "Received %u bytes of `%s' information about peer `%s' from `%s' service\n", | 586 | "Received %u bytes of `%s' information about peer `%s' from `%s' service\n", |
@@ -637,6 +683,7 @@ GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h, | |||
637 | struct GNUNET_PEERINFO_IteratorContext *ic; | 683 | struct GNUNET_PEERINFO_IteratorContext *ic; |
638 | struct GNUNET_PEERINFO_AddContext *ac; | 684 | struct GNUNET_PEERINFO_AddContext *ac; |
639 | 685 | ||
686 | ic = GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_IteratorContext)); | ||
640 | if (NULL == peer) | 687 | if (NULL == peer) |
641 | { | 688 | { |
642 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 689 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -662,8 +709,9 @@ GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h, | |||
662 | lpm->header.size = htons (sizeof (struct ListPeerMessage)); | 709 | lpm->header.size = htons (sizeof (struct ListPeerMessage)); |
663 | lpm->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_GET); | 710 | lpm->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_GET); |
664 | memcpy (&lpm->peer, peer, sizeof (struct GNUNET_PeerIdentity)); | 711 | memcpy (&lpm->peer, peer, sizeof (struct GNUNET_PeerIdentity)); |
712 | ic->have_peer = GNUNET_YES; | ||
713 | ic->peer = *peer; | ||
665 | } | 714 | } |
666 | ic = GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_IteratorContext)); | ||
667 | ic->h = h; | 715 | ic->h = h; |
668 | ic->ac = ac; | 716 | ic->ac = ac; |
669 | ic->callback = callback; | 717 | ic->callback = callback; |