diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-12-12 15:01:03 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-12-12 15:01:03 +0000 |
commit | 88bc4c05422973f2dc2d1b3ed6fbf1d39c773ffd (patch) | |
tree | c8c78a2c8032a52a91abdfae581191619187fc70 /src/set | |
parent | 5c0b58109855f17232a0f00bf3ac613487b09015 (diff) | |
download | gnunet-88bc4c05422973f2dc2d1b3ed6fbf1d39c773ffd.tar.gz gnunet-88bc4c05422973f2dc2d1b3ed6fbf1d39c773ffd.zip |
do check message sizes in union p2p protocol
Diffstat (limited to 'src/set')
-rw-r--r-- | src/set/gnunet-service-set_union.c | 100 | ||||
-rw-r--r-- | src/set/gnunet-service-set_union_strata_estimator.h | 7 |
2 files changed, 68 insertions, 39 deletions
diff --git a/src/set/gnunet-service-set_union.c b/src/set/gnunet-service-set_union.c index ded371a31..0de2ed939 100644 --- a/src/set/gnunet-service-set_union.c +++ b/src/set/gnunet-service-set_union.c | |||
@@ -248,6 +248,7 @@ destroy_key_to_element_iter (void *cls, | |||
248 | while (NULL != k) | 248 | while (NULL != k) |
249 | { | 249 | { |
250 | struct KeyEntry *k_tmp = k; | 250 | struct KeyEntry *k_tmp = k; |
251 | |||
251 | k = k->next_colliding; | 252 | k = k->next_colliding; |
252 | if (GNUNET_YES == k_tmp->element->remote) | 253 | if (GNUNET_YES == k_tmp->element->remote) |
253 | { | 254 | { |
@@ -660,8 +661,10 @@ get_order_from_difference (unsigned int diff) | |||
660 | * | 661 | * |
661 | * @param cls the union operation | 662 | * @param cls the union operation |
662 | * @param mh the message | 663 | * @param mh the message |
664 | * @return #GNUNET_SYSERR if the tunnel should be disconnected, | ||
665 | * #GNUNET_OK otherwise | ||
663 | */ | 666 | */ |
664 | static void | 667 | static int |
665 | handle_p2p_strata_estimator (void *cls, | 668 | handle_p2p_strata_estimator (void *cls, |
666 | const struct GNUNET_MessageHeader *mh) | 669 | const struct GNUNET_MessageHeader *mh) |
667 | { | 670 | { |
@@ -673,13 +676,23 @@ handle_p2p_strata_estimator (void *cls, | |||
673 | { | 676 | { |
674 | fail_union_operation (op); | 677 | fail_union_operation (op); |
675 | GNUNET_break (0); | 678 | GNUNET_break (0); |
676 | return; | 679 | return GNUNET_SYSERR; |
677 | } | 680 | } |
678 | remote_se = strata_estimator_create (SE_STRATA_COUNT, SE_IBF_SIZE, | 681 | if (ntohs (mh->size) != |
682 | SE_STRATA_COUNT * SE_IBF_SIZE * IBF_BUCKET_SIZE + | ||
683 | sizeof (struct GNUNET_MessageHeader)) | ||
684 | { | ||
685 | fail_union_operation (op); | ||
686 | GNUNET_break (0); | ||
687 | return GNUNET_SYSERR; | ||
688 | } | ||
689 | remote_se = strata_estimator_create (SE_STRATA_COUNT, | ||
690 | SE_IBF_SIZE, | ||
679 | SE_IBF_HASH_NUM); | 691 | SE_IBF_HASH_NUM); |
680 | strata_estimator_read (&mh[1], remote_se); | 692 | strata_estimator_read (&mh[1], remote_se); |
681 | GNUNET_assert (NULL != op->state->se); | 693 | GNUNET_assert (NULL != op->state->se); |
682 | diff = strata_estimator_difference (remote_se, op->state->se); | 694 | diff = strata_estimator_difference (remote_se, |
695 | op->state->se); | ||
683 | strata_estimator_destroy (remote_se); | 696 | strata_estimator_destroy (remote_se); |
684 | strata_estimator_destroy (op->state->se); | 697 | strata_estimator_destroy (op->state->se); |
685 | op->state->se = NULL; | 698 | op->state->se = NULL; |
@@ -689,10 +702,10 @@ handle_p2p_strata_estimator (void *cls, | |||
689 | 1<<get_order_from_difference (diff)); | 702 | 1<<get_order_from_difference (diff)); |
690 | send_ibf (op, | 703 | send_ibf (op, |
691 | get_order_from_difference (diff)); | 704 | get_order_from_difference (diff)); |
705 | return GNUNET_OK; | ||
692 | } | 706 | } |
693 | 707 | ||
694 | 708 | ||
695 | |||
696 | /** | 709 | /** |
697 | * Iterator to send elements to a remote peer | 710 | * Iterator to send elements to a remote peer |
698 | * | 711 | * |
@@ -749,7 +762,8 @@ send_element_iterator (void *cls, | |||
749 | * @param ibf_key IBF key of interest | 762 | * @param ibf_key IBF key of interest |
750 | */ | 763 | */ |
751 | static void | 764 | static void |
752 | send_elements_for_key (struct Operation *op, struct IBF_Key ibf_key) | 765 | send_elements_for_key (struct Operation *op, |
766 | struct IBF_Key ibf_key) | ||
753 | { | 767 | { |
754 | struct SendElementClosure send_cls; | 768 | struct SendElementClosure send_cls; |
755 | 769 | ||
@@ -757,7 +771,8 @@ send_elements_for_key (struct Operation *op, struct IBF_Key ibf_key) | |||
757 | send_cls.op = op; | 771 | send_cls.op = op; |
758 | (void) GNUNET_CONTAINER_multihashmap32_get_multiple (op->state->key_to_element, | 772 | (void) GNUNET_CONTAINER_multihashmap32_get_multiple (op->state->key_to_element, |
759 | (uint32_t) ibf_key.key_val, | 773 | (uint32_t) ibf_key.key_val, |
760 | &send_element_iterator, &send_cls); | 774 | &send_element_iterator, |
775 | &send_cls); | ||
761 | } | 776 | } |
762 | 777 | ||
763 | 778 | ||
@@ -881,29 +896,39 @@ decode_and_send (struct Operation *op) | |||
881 | * | 896 | * |
882 | * @param cls the union operation | 897 | * @param cls the union operation |
883 | * @param mh the header of the message | 898 | * @param mh the header of the message |
899 | * @return #GNUNET_SYSERR if the tunnel should be disconnected, | ||
900 | * #GNUNET_OK otherwise | ||
884 | */ | 901 | */ |
885 | static void | 902 | static int |
886 | handle_p2p_ibf (void *cls, const struct GNUNET_MessageHeader *mh) | 903 | handle_p2p_ibf (void *cls, |
904 | const struct GNUNET_MessageHeader *mh) | ||
887 | { | 905 | { |
888 | struct Operation *op = cls; | 906 | struct Operation *op = cls; |
889 | struct IBFMessage *msg = (struct IBFMessage *) mh; | 907 | const struct IBFMessage *msg; |
890 | unsigned int buckets_in_message; | 908 | unsigned int buckets_in_message; |
891 | 909 | ||
910 | if (ntohs (mh->size) < sizeof (struct IBFMessage)) | ||
911 | { | ||
912 | GNUNET_break_op (0); | ||
913 | fail_union_operation (op); | ||
914 | return GNUNET_SYSERR; | ||
915 | } | ||
916 | msg = (const struct IBFMessage *) mh; | ||
892 | if ( (op->state->phase == PHASE_EXPECT_ELEMENTS_AND_REQUESTS) || | 917 | if ( (op->state->phase == PHASE_EXPECT_ELEMENTS_AND_REQUESTS) || |
893 | (op->state->phase == PHASE_EXPECT_IBF) ) | 918 | (op->state->phase == PHASE_EXPECT_IBF) ) |
894 | { | 919 | { |
895 | op->state->phase = PHASE_EXPECT_IBF_CONT; | 920 | op->state->phase = PHASE_EXPECT_IBF_CONT; |
896 | GNUNET_assert (NULL == op->state->remote_ibf); | 921 | GNUNET_assert (NULL == op->state->remote_ibf); |
897 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 922 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
898 | "creating new ibf of size %u\n", | 923 | "Creating new ibf of size %u\n", |
899 | 1<<msg->order); | 924 | 1 << msg->order); |
900 | op->state->remote_ibf = ibf_create (1<<msg->order, SE_IBF_HASH_NUM); | 925 | op->state->remote_ibf = ibf_create (1<<msg->order, SE_IBF_HASH_NUM); |
901 | op->state->ibf_buckets_received = 0; | 926 | op->state->ibf_buckets_received = 0; |
902 | if (0 != ntohs (msg->offset)) | 927 | if (0 != ntohs (msg->offset)) |
903 | { | 928 | { |
904 | GNUNET_break (0); | 929 | GNUNET_break_op (0); |
905 | fail_union_operation (op); | 930 | fail_union_operation (op); |
906 | return; | 931 | return GNUNET_SYSERR; |
907 | } | 932 | } |
908 | } | 933 | } |
909 | else if (op->state->phase == PHASE_EXPECT_IBF_CONT) | 934 | else if (op->state->phase == PHASE_EXPECT_IBF_CONT) |
@@ -911,9 +936,9 @@ handle_p2p_ibf (void *cls, const struct GNUNET_MessageHeader *mh) | |||
911 | if ( (ntohs (msg->offset) != op->state->ibf_buckets_received) || | 936 | if ( (ntohs (msg->offset) != op->state->ibf_buckets_received) || |
912 | (1<<msg->order != op->state->remote_ibf->size) ) | 937 | (1<<msg->order != op->state->remote_ibf->size) ) |
913 | { | 938 | { |
914 | GNUNET_break (0); | 939 | GNUNET_break_op (0); |
915 | fail_union_operation (op); | 940 | fail_union_operation (op); |
916 | return; | 941 | return GNUNET_SYSERR; |
917 | } | 942 | } |
918 | } | 943 | } |
919 | 944 | ||
@@ -923,14 +948,14 @@ handle_p2p_ibf (void *cls, const struct GNUNET_MessageHeader *mh) | |||
923 | { | 948 | { |
924 | GNUNET_break_op (0); | 949 | GNUNET_break_op (0); |
925 | fail_union_operation (op); | 950 | fail_union_operation (op); |
926 | return; | 951 | return GNUNET_SYSERR; |
927 | } | 952 | } |
928 | 953 | ||
929 | if ((ntohs (msg->header.size) - sizeof *msg) != buckets_in_message * IBF_BUCKET_SIZE) | 954 | if ((ntohs (msg->header.size) - sizeof *msg) != buckets_in_message * IBF_BUCKET_SIZE) |
930 | { | 955 | { |
931 | GNUNET_break (0); | 956 | GNUNET_break_op (0); |
932 | fail_union_operation (op); | 957 | fail_union_operation (op); |
933 | return; | 958 | return GNUNET_SYSERR; |
934 | } | 959 | } |
935 | 960 | ||
936 | ibf_read_slice (&msg[1], | 961 | ibf_read_slice (&msg[1], |
@@ -946,6 +971,7 @@ handle_p2p_ibf (void *cls, const struct GNUNET_MessageHeader *mh) | |||
946 | op->state->phase = PHASE_EXPECT_ELEMENTS; | 971 | op->state->phase = PHASE_EXPECT_ELEMENTS; |
947 | decode_and_send (op); | 972 | decode_and_send (op); |
948 | } | 973 | } |
974 | return GNUNET_OK; | ||
949 | } | 975 | } |
950 | 976 | ||
951 | 977 | ||
@@ -1108,13 +1134,12 @@ handle_p2p_elements (void *cls, | |||
1108 | uint16_t element_size; | 1134 | uint16_t element_size; |
1109 | 1135 | ||
1110 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1136 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1111 | "got element from peer\n"); | 1137 | "Got element from peer\n"); |
1112 | |||
1113 | if ( (op->state->phase != PHASE_EXPECT_ELEMENTS) && | 1138 | if ( (op->state->phase != PHASE_EXPECT_ELEMENTS) && |
1114 | (op->state->phase != PHASE_EXPECT_ELEMENTS_AND_REQUESTS) ) | 1139 | (op->state->phase != PHASE_EXPECT_ELEMENTS_AND_REQUESTS) ) |
1115 | { | 1140 | { |
1116 | fail_union_operation (op); | 1141 | fail_union_operation (op); |
1117 | GNUNET_break (0); | 1142 | GNUNET_break_op (0); |
1118 | return; | 1143 | return; |
1119 | } | 1144 | } |
1120 | element_size = ntohs (mh->size) - sizeof (struct GNUNET_MessageHeader); | 1145 | element_size = ntohs (mh->size) - sizeof (struct GNUNET_MessageHeader); |
@@ -1153,27 +1178,27 @@ handle_p2p_element_requests (void *cls, | |||
1153 | const struct GNUNET_MessageHeader *mh) | 1178 | const struct GNUNET_MessageHeader *mh) |
1154 | { | 1179 | { |
1155 | struct Operation *op = cls; | 1180 | struct Operation *op = cls; |
1156 | struct IBF_Key *ibf_key; | 1181 | const struct IBF_Key *ibf_key; |
1157 | unsigned int num_keys; | 1182 | unsigned int num_keys; |
1158 | 1183 | ||
1159 | /* look up elements and send them */ | 1184 | /* look up elements and send them */ |
1160 | if (op->state->phase != PHASE_EXPECT_ELEMENTS_AND_REQUESTS) | 1185 | if (op->state->phase != PHASE_EXPECT_ELEMENTS_AND_REQUESTS) |
1161 | { | 1186 | { |
1162 | GNUNET_break (0); | 1187 | GNUNET_break_op (0); |
1163 | fail_union_operation (op); | 1188 | fail_union_operation (op); |
1164 | return; | 1189 | return; |
1165 | } | 1190 | } |
1166 | 1191 | num_keys = (ntohs (mh->size) - sizeof (struct GNUNET_MessageHeader)) | |
1167 | num_keys = (ntohs (mh->size) - sizeof *mh) / sizeof (struct IBF_Key); | 1192 | / sizeof (struct IBF_Key); |
1168 | 1193 | if ((ntohs (mh->size) - sizeof (struct GNUNET_MessageHeader)) | |
1169 | if ((ntohs (mh->size) - sizeof *mh) != num_keys * sizeof (struct IBF_Key)) | 1194 | != num_keys * sizeof (struct IBF_Key)) |
1170 | { | 1195 | { |
1171 | GNUNET_break (0); | 1196 | GNUNET_break_op (0); |
1172 | fail_union_operation (op); | 1197 | fail_union_operation (op); |
1173 | return; | 1198 | return; |
1174 | } | 1199 | } |
1175 | 1200 | ||
1176 | ibf_key = (struct IBF_Key *) &mh[1]; | 1201 | ibf_key = (const struct IBF_Key *) &mh[1]; |
1177 | while (0 != num_keys--) | 1202 | while (0 != num_keys--) |
1178 | { | 1203 | { |
1179 | send_elements_for_key (op, *ibf_key); | 1204 | send_elements_for_key (op, *ibf_key); |
@@ -1189,7 +1214,8 @@ handle_p2p_element_requests (void *cls, | |||
1189 | * @param mh the message | 1214 | * @param mh the message |
1190 | */ | 1215 | */ |
1191 | static void | 1216 | static void |
1192 | handle_p2p_done (void *cls, const struct GNUNET_MessageHeader *mh) | 1217 | handle_p2p_done (void *cls, |
1218 | const struct GNUNET_MessageHeader *mh) | ||
1193 | { | 1219 | { |
1194 | struct Operation *op = cls; | 1220 | struct Operation *op = cls; |
1195 | struct GNUNET_MQ_Envelope *ev; | 1221 | struct GNUNET_MQ_Envelope *ev; |
@@ -1213,7 +1239,7 @@ handle_p2p_done (void *cls, const struct GNUNET_MessageHeader *mh) | |||
1213 | finish_and_destroy (op); | 1239 | finish_and_destroy (op); |
1214 | return; | 1240 | return; |
1215 | } | 1241 | } |
1216 | GNUNET_break (0); | 1242 | GNUNET_break_op (0); |
1217 | fail_union_operation (op); | 1243 | fail_union_operation (op); |
1218 | } | 1244 | } |
1219 | 1245 | ||
@@ -1353,8 +1379,8 @@ union_set_destroy (struct SetState *set_state) | |||
1353 | * | 1379 | * |
1354 | * @param op the state of the union evaluate operation | 1380 | * @param op the state of the union evaluate operation |
1355 | * @param mh the received message | 1381 | * @param mh the received message |
1356 | * @return GNUNET_SYSERR if the tunnel should be disconnected, | 1382 | * @return #GNUNET_SYSERR if the tunnel should be disconnected, |
1357 | * GNUNET_OK otherwise | 1383 | * #GNUNET_OK otherwise |
1358 | */ | 1384 | */ |
1359 | int | 1385 | int |
1360 | union_handle_p2p_message (struct Operation *op, | 1386 | union_handle_p2p_message (struct Operation *op, |
@@ -1367,11 +1393,9 @@ union_handle_p2p_message (struct Operation *op, | |||
1367 | switch (ntohs (mh->type)) | 1393 | switch (ntohs (mh->type)) |
1368 | { | 1394 | { |
1369 | case GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF: | 1395 | case GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF: |
1370 | handle_p2p_ibf (op, mh); | 1396 | return handle_p2p_ibf (op, mh); |
1371 | break; | ||
1372 | case GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE: | 1397 | case GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE: |
1373 | handle_p2p_strata_estimator (op, mh); | 1398 | return handle_p2p_strata_estimator (op, mh); |
1374 | break; | ||
1375 | case GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS: | 1399 | case GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS: |
1376 | handle_p2p_elements (op, mh); | 1400 | handle_p2p_elements (op, mh); |
1377 | break; | 1401 | break; |
diff --git a/src/set/gnunet-service-set_union_strata_estimator.h b/src/set/gnunet-service-set_union_strata_estimator.h index 4d18db60b..3479a0ff9 100644 --- a/src/set/gnunet-service-set_union_strata_estimator.h +++ b/src/set/gnunet-service-set_union_strata_estimator.h | |||
@@ -45,7 +45,9 @@ extern "C" | |||
45 | */ | 45 | */ |
46 | struct StrataEstimator | 46 | struct StrataEstimator |
47 | { | 47 | { |
48 | 48 | /** | |
49 | * The IBFs of this strata estimator. | ||
50 | */ | ||
49 | struct InvertibleBloomFilter **strata; | 51 | struct InvertibleBloomFilter **strata; |
50 | 52 | ||
51 | /** | 53 | /** |
@@ -53,6 +55,9 @@ struct StrataEstimator | |||
53 | */ | 55 | */ |
54 | unsigned int strata_count; | 56 | unsigned int strata_count; |
55 | 57 | ||
58 | /** | ||
59 | * Size of each IBF stratum (in bytes) | ||
60 | */ | ||
56 | unsigned int ibf_size; | 61 | unsigned int ibf_size; |
57 | }; | 62 | }; |
58 | 63 | ||