aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-06-25 21:08:55 +0000
committerChristian Grothoff <christian@grothoff.org>2010-06-25 21:08:55 +0000
commit537903a8dc4c3ecf2dfa382af0289ddf890adfc7 (patch)
tree93e448c15c843861bd5dfe86c7cad3245abedfe7
parent2b61888a0bf1d41b2b25256ca9834c3040551ce9 (diff)
downloadgnunet-537903a8dc4c3ecf2dfa382af0289ddf890adfc7.tar.gz
gnunet-537903a8dc4c3ecf2dfa382af0289ddf890adfc7.zip
fixing common off-by-one error with respect to maximum message size
-rw-r--r--src/arm/arm_api.c3
-rw-r--r--src/core/gnunet-service-core.c4
-rw-r--r--src/datastore/datastore_api.c6
-rw-r--r--src/dv/gnunet-service-dv.c2
-rw-r--r--src/fs/fs_publish.c2
-rw-r--r--src/fs/gnunet-service-fs_indexing.c5
-rw-r--r--src/hello/hello.c2
-rw-r--r--src/hostlist/hostlist-client.c4
-rw-r--r--src/hostlist/hostlist-server.c2
-rw-r--r--src/peerinfo/gnunet-service-peerinfo.c6
-rw-r--r--src/topology/gnunet-daemon-topology.c2
-rw-r--r--src/transport/plugin_transport_http.c4
-rw-r--r--src/transport/plugin_transport_tcp.c4
-rw-r--r--src/transport/test_plugin_transport_http.c9
-rw-r--r--src/transport/test_transport_api_reliability.c16
-rw-r--r--src/transport/transport_api.c3
-rw-r--r--src/util/client.c6
-rw-r--r--src/util/connection.c5
-rw-r--r--src/util/resolver_api.c10
-rw-r--r--src/util/server.c8
-rw-r--r--src/util/server_mst.c2
-rw-r--r--src/util/service.c6
22 files changed, 59 insertions, 52 deletions
diff --git a/src/arm/arm_api.c b/src/arm/arm_api.c
index 6c2b53a71..0726f7e66 100644
--- a/src/arm/arm_api.c
+++ b/src/arm/arm_api.c
@@ -541,8 +541,7 @@ change_service (struct GNUNET_ARM_Handle *h,
541 struct GNUNET_MessageHeader *msg; 541 struct GNUNET_MessageHeader *msg;
542 542
543 slen = strlen (service_name) + 1; 543 slen = strlen (service_name) + 1;
544 if (slen + sizeof (struct GNUNET_MessageHeader) > 544 if (slen + sizeof (struct GNUNET_MessageHeader) >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
545 GNUNET_SERVER_MAX_MESSAGE_SIZE)
546 { 545 {
547 GNUNET_break (0); 546 GNUNET_break (0);
548 if (cb != NULL) 547 if (cb != NULL)
diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c
index a181ae5bb..5a223d70b 100644
--- a/src/core/gnunet-service-core.c
+++ b/src/core/gnunet-service-core.c
@@ -1717,7 +1717,7 @@ batch_message (struct Neighbour *n,
1717 struct GNUNET_TIME_Relative *retry_time, 1717 struct GNUNET_TIME_Relative *retry_time,
1718 unsigned int *priority) 1718 unsigned int *priority)
1719{ 1719{
1720 char ntmb[GNUNET_SERVER_MAX_MESSAGE_SIZE]; 1720 char ntmb[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1];
1721 struct NotifyTrafficMessage *ntm = (struct NotifyTrafficMessage*) ntmb; 1721 struct NotifyTrafficMessage *ntm = (struct NotifyTrafficMessage*) ntmb;
1722 struct MessageEntry *pos; 1722 struct MessageEntry *pos;
1723 struct MessageEntry *prev; 1723 struct MessageEntry *prev;
@@ -3824,7 +3824,7 @@ run (void *cls,
3824 &handle_transport_notify_disconnect); 3824 &handle_transport_notify_disconnect);
3825 GNUNET_assert (NULL != transport); 3825 GNUNET_assert (NULL != transport);
3826 stats = GNUNET_STATISTICS_create (sched, "core", cfg); 3826 stats = GNUNET_STATISTICS_create (sched, "core", cfg);
3827 mst = GNUNET_SERVER_mst_create (GNUNET_SERVER_MAX_MESSAGE_SIZE, 3827 mst = GNUNET_SERVER_mst_create (GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
3828 &deliver_message, 3828 &deliver_message,
3829 NULL); 3829 NULL);
3830 GNUNET_SCHEDULER_add_delayed (sched, 3830 GNUNET_SCHEDULER_add_delayed (sched,
diff --git a/src/datastore/datastore_api.c b/src/datastore/datastore_api.c
index 2218fffc3..1344eaeff 100644
--- a/src/datastore/datastore_api.c
+++ b/src/datastore/datastore_api.c
@@ -245,7 +245,7 @@ GNUNET_DATASTORE_connect (const struct
245 if (c == NULL) 245 if (c == NULL)
246 return NULL; /* oops */ 246 return NULL; /* oops */
247 h = GNUNET_malloc (sizeof(struct GNUNET_DATASTORE_Handle) + 247 h = GNUNET_malloc (sizeof(struct GNUNET_DATASTORE_Handle) +
248 GNUNET_SERVER_MAX_MESSAGE_SIZE); 248 GNUNET_SERVER_MAX_MESSAGE_SIZE - 1);
249 h->client = c; 249 h->client = c;
250 h->cfg = cfg; 250 h->cfg = cfg;
251 h->sched = sched; 251 h->sched = sched;
@@ -790,7 +790,7 @@ GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
790 GNUNET_h2s (key)); 790 GNUNET_h2s (key));
791#endif 791#endif
792 msize = sizeof(struct DataMessage) + size; 792 msize = sizeof(struct DataMessage) + size;
793 GNUNET_assert (msize <= GNUNET_SERVER_MAX_MESSAGE_SIZE); 793 GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
794 qc.sc.cont = cont; 794 qc.sc.cont = cont;
795 qc.sc.cont_cls = cont_cls; 795 qc.sc.cont_cls = cont_cls;
796 qe = make_queue_entry (h, msize, 796 qe = make_queue_entry (h, msize,
@@ -1037,7 +1037,7 @@ GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
1037 qc.sc.cont = cont; 1037 qc.sc.cont = cont;
1038 qc.sc.cont_cls = cont_cls; 1038 qc.sc.cont_cls = cont_cls;
1039 msize = sizeof(struct DataMessage) + size; 1039 msize = sizeof(struct DataMessage) + size;
1040 GNUNET_assert (msize <= GNUNET_SERVER_MAX_MESSAGE_SIZE); 1040 GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
1041 qe = make_queue_entry (h, msize, 1041 qe = make_queue_entry (h, msize,
1042 queue_priority, max_queue_size, timeout, 1042 queue_priority, max_queue_size, timeout,
1043 &process_status_message, &qc); 1043 &process_status_message, &qc);
diff --git a/src/dv/gnunet-service-dv.c b/src/dv/gnunet-service-dv.c
index 8366348d5..6ef4e82fe 100644
--- a/src/dv/gnunet-service-dv.c
+++ b/src/dv/gnunet-service-dv.c
@@ -3002,7 +3002,7 @@ run (void *cls,
3002 if (coreAPI == NULL) 3002 if (coreAPI == NULL)
3003 return; 3003 return;
3004 3004
3005 coreMST = GNUNET_SERVER_mst_create (GNUNET_SERVER_MAX_MESSAGE_SIZE, 3005 coreMST = GNUNET_SERVER_mst_create (GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
3006 &tokenized_message_handler, 3006 &tokenized_message_handler,
3007 NULL); 3007 NULL);
3008 3008
diff --git a/src/fs/fs_publish.c b/src/fs/fs_publish.c
index 2ebb96169..13701405e 100644
--- a/src/fs/fs_publish.c
+++ b/src/fs/fs_publish.c
@@ -761,7 +761,7 @@ hash_for_index_cb (void *cls,
761 fn = GNUNET_STRINGS_filename_expand (p->filename); 761 fn = GNUNET_STRINGS_filename_expand (p->filename);
762 GNUNET_assert (fn != NULL); 762 GNUNET_assert (fn != NULL);
763 slen = strlen (fn) + 1; 763 slen = strlen (fn) + 1;
764 if (slen > GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof(struct IndexStartMessage)) 764 if (slen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof(struct IndexStartMessage))
765 { 765 {
766 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 766 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
767 _("Can not index file `%s': %s. Will try to insert instead.\n"), 767 _("Can not index file `%s': %s. Will try to insert instead.\n"),
diff --git a/src/fs/gnunet-service-fs_indexing.c b/src/fs/gnunet-service-fs_indexing.c
index d6654bcdc..b72c53fc0 100644
--- a/src/fs/gnunet-service-fs_indexing.c
+++ b/src/fs/gnunet-service-fs_indexing.c
@@ -430,7 +430,7 @@ GNUNET_FS_handle_index_list_get (void *cls,
430{ 430{
431 struct GNUNET_SERVER_TransmitContext *tc; 431 struct GNUNET_SERVER_TransmitContext *tc;
432 struct IndexInfoMessage *iim; 432 struct IndexInfoMessage *iim;
433 char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE]; 433 char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1];
434 size_t slen; 434 size_t slen;
435 const char *fn; 435 const char *fn;
436 struct IndexInfo *pos; 436 struct IndexInfo *pos;
@@ -442,8 +442,7 @@ GNUNET_FS_handle_index_list_get (void *cls,
442 { 442 {
443 fn = pos->filename; 443 fn = pos->filename;
444 slen = strlen (fn) + 1; 444 slen = strlen (fn) + 1;
445 if (slen + sizeof (struct IndexInfoMessage) > 445 if (slen + sizeof (struct IndexInfoMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
446 GNUNET_SERVER_MAX_MESSAGE_SIZE)
447 { 446 {
448 GNUNET_break (0); 447 GNUNET_break (0);
449 break; 448 break;
diff --git a/src/hello/hello.c b/src/hello/hello.c
index abcc25c71..f41a601fd 100644
--- a/src/hello/hello.c
+++ b/src/hello/hello.c
@@ -167,7 +167,7 @@ GNUNET_HELLO_create (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
167 GNUNET_HELLO_GenerateAddressListCallback addrgen, 167 GNUNET_HELLO_GenerateAddressListCallback addrgen,
168 void *addrgen_cls) 168 void *addrgen_cls)
169{ 169{
170 char buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE - 256 - 170 char buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - 256 -
171 sizeof (struct GNUNET_HELLO_Message)]; 171 sizeof (struct GNUNET_HELLO_Message)];
172 size_t max; 172 size_t max;
173 size_t used; 173 size_t used;
diff --git a/src/hostlist/hostlist-client.c b/src/hostlist/hostlist-client.c
index ff8ab2e9a..b6514984d 100644
--- a/src/hostlist/hostlist-client.c
+++ b/src/hostlist/hostlist-client.c
@@ -272,7 +272,7 @@ callback_download (void *ptr,
272 size_t nmemb, 272 size_t nmemb,
273 void *ctx) 273 void *ctx)
274{ 274{
275 static char download_buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE]; 275 static char download_buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1];
276 const char * cbuf = ptr; 276 const char * cbuf = ptr;
277 const struct GNUNET_MessageHeader *msg; 277 const struct GNUNET_MessageHeader *msg;
278 size_t total; 278 size_t total;
@@ -295,7 +295,7 @@ callback_download (void *ptr,
295 while ( (left > 0) || 295 while ( (left > 0) ||
296 (download_pos > 0) ) 296 (download_pos > 0) )
297 { 297 {
298 cpy = GNUNET_MIN (left, GNUNET_SERVER_MAX_MESSAGE_SIZE - download_pos); 298 cpy = GNUNET_MIN (left, GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - download_pos);
299 memcpy (&download_buffer[download_pos], 299 memcpy (&download_buffer[download_pos],
300 cbuf, 300 cbuf,
301 cpy); 301 cpy);
diff --git a/src/hostlist/hostlist-server.c b/src/hostlist/hostlist-server.c
index 0726bf3e0..014c0f41f 100644
--- a/src/hostlist/hostlist-server.c
+++ b/src/hostlist/hostlist-server.c
@@ -399,7 +399,7 @@ connect_handler (void *cls,
399 if (hostlist_uri == NULL) 399 if (hostlist_uri == NULL)
400 return; 400 return;
401 size = strlen (hostlist_uri) + 1; 401 size = strlen (hostlist_uri) + 1;
402 if (size + sizeof (struct GNUNET_MessageHeader) > GNUNET_SERVER_MAX_MESSAGE_SIZE) 402 if (size + sizeof (struct GNUNET_MessageHeader) >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
403 { 403 {
404 GNUNET_break (0); 404 GNUNET_break (0);
405 return; 405 return;
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c
index ae8a0dfe3..a839da049 100644
--- a/src/peerinfo/gnunet-service-peerinfo.c
+++ b/src/peerinfo/gnunet-service-peerinfo.c
@@ -249,7 +249,7 @@ add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity)
249 struct HostEntry *entry; 249 struct HostEntry *entry;
250 char *fn; 250 char *fn;
251 uint32_t trust; 251 uint32_t trust;
252 char buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE]; 252 char buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1];
253 const struct GNUNET_HELLO_Message *hello; 253 const struct GNUNET_HELLO_Message *hello;
254 struct GNUNET_HELLO_Message *hello_clean; 254 struct GNUNET_HELLO_Message *hello_clean;
255 int size; 255 int size;
@@ -494,7 +494,7 @@ send_to_each_host (const struct GNUNET_PeerIdentity *only,
494 struct HostEntry *pos; 494 struct HostEntry *pos;
495 struct InfoMessage *im; 495 struct InfoMessage *im;
496 uint16_t hs; 496 uint16_t hs;
497 char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE]; 497 char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1];
498 struct GNUNET_SERVER_TransmitContext *tc; 498 struct GNUNET_SERVER_TransmitContext *tc;
499 int match; 499 int match;
500 500
@@ -600,7 +600,7 @@ static int
600discard_hosts_helper (void *cls, const char *fn) 600discard_hosts_helper (void *cls, const char *fn)
601{ 601{
602 struct GNUNET_TIME_Absolute *now = cls; 602 struct GNUNET_TIME_Absolute *now = cls;
603 char buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE]; 603 char buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1];
604 const struct GNUNET_HELLO_Message *hello; 604 const struct GNUNET_HELLO_Message *hello;
605 struct GNUNET_HELLO_Message *new_hello; 605 struct GNUNET_HELLO_Message *new_hello;
606 int size; 606 int size;
diff --git a/src/topology/gnunet-daemon-topology.c b/src/topology/gnunet-daemon-topology.c
index 970045093..1c58b5210 100644
--- a/src/topology/gnunet-daemon-topology.c
+++ b/src/topology/gnunet-daemon-topology.c
@@ -629,7 +629,7 @@ schedule_next_hello (void *cls,
629 /* find applicable HELLOs */ 629 /* find applicable HELLOs */
630 fah.peer = pl; 630 fah.peer = pl;
631 fah.result = NULL; 631 fah.result = NULL;
632 fah.max_size = GNUNET_SERVER_MAX_MESSAGE_SIZE; 632 fah.max_size = GNUNET_SERVER_MAX_MESSAGE_SIZE - 1;
633 fah.next_adv = GNUNET_TIME_UNIT_FOREVER_REL; 633 fah.next_adv = GNUNET_TIME_UNIT_FOREVER_REL;
634 GNUNET_CONTAINER_multihashmap_iterate (peers, 634 GNUNET_CONTAINER_multihashmap_iterate (peers,
635 &find_advertisable_hello, 635 &find_advertisable_hello,
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c
index 5946105ac..f512d3580 100644
--- a/src/transport/plugin_transport_http.c
+++ b/src/transport/plugin_transport_http.c
@@ -541,7 +541,7 @@ accessHandlerCallback (void *cls,
541 } 541 }
542 */ 542 */
543 if (cs->msgtok==NULL) 543 if (cs->msgtok==NULL)
544 cs->msgtok = GNUNET_SERVER_mst_create (GNUNET_SERVER_MAX_MESSAGE_SIZE, &messageTokenizerCallback, cs); 544 cs->msgtok = GNUNET_SERVER_mst_create (GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, &messageTokenizerCallback, cs);
545 } 545 }
546 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Daemon has new an incoming `%s' request from peer `%s'\n",method, GNUNET_i2s(&cs->identity)); 546 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Daemon has new an incoming `%s' request from peer `%s'\n",method, GNUNET_i2s(&cs->identity));
547 } 547 }
@@ -570,7 +570,7 @@ accessHandlerCallback (void *cls,
570 570
571 if ((*upload_data_size > 0) && (cs->is_bad_request != GNUNET_YES)) 571 if ((*upload_data_size > 0) && (cs->is_bad_request != GNUNET_YES))
572 { 572 {
573 if (*upload_data_size + cs->pending_inbound_msg.bytes_recv <= GNUNET_SERVER_MAX_MESSAGE_SIZE) 573 if (*upload_data_size + cs->pending_inbound_msg.bytes_recv < GNUNET_SERVER_MAX_MESSAGE_SIZE)
574 { 574 {
575 /* copy uploaded data to buffer */ 575 /* copy uploaded data to buffer */
576 576
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c
index 9b09d8948..c1397da61 100644
--- a/src/transport/plugin_transport_tcp.c
+++ b/src/transport/plugin_transport_tcp.c
@@ -1120,7 +1120,7 @@ tcp_plugin_send (void *cls,
1120 } 1120 }
1121 sa = GNUNET_CONNECTION_create_from_sockaddr (plugin->env->sched, 1121 sa = GNUNET_CONNECTION_create_from_sockaddr (plugin->env->sched,
1122 af, sb, sbs, 1122 af, sb, sbs,
1123 GNUNET_SERVER_MAX_MESSAGE_SIZE); 1123 GNUNET_SERVER_MAX_MESSAGE_SIZE - 1);
1124 if (sa == NULL) 1124 if (sa == NULL)
1125 { 1125 {
1126#if DEBUG_TCP 1126#if DEBUG_TCP
@@ -1991,7 +1991,7 @@ tcp_plugin_server_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc
1991 * that wants to connect to us! Send a message to establish a connection. 1991 * that wants to connect to us! Send a message to establish a connection.
1992 */ 1992 */
1993 sock = GNUNET_CONNECTION_create_from_sockaddr (plugin->env->sched, AF_INET, (struct sockaddr *)&in_addr, 1993 sock = GNUNET_CONNECTION_create_from_sockaddr (plugin->env->sched, AF_INET, (struct sockaddr *)&in_addr,
1994 sizeof(in_addr), GNUNET_SERVER_MAX_MESSAGE_SIZE); 1994 sizeof(in_addr), GNUNET_SERVER_MAX_MESSAGE_SIZE - 1);
1995 if (sock == NULL) 1995 if (sock == NULL)
1996 { 1996 {
1997 plugin->server_read_task = 1997 plugin->server_read_task =
diff --git a/src/transport/test_plugin_transport_http.c b/src/transport/test_plugin_transport_http.c
index 75df9c90a..9c98d8c06 100644
--- a/src/transport/test_plugin_transport_http.c
+++ b/src/transport/test_plugin_transport_http.c
@@ -1036,15 +1036,6 @@ static void run_connection_tests( )
1036 api->send(api->cls, &my_identity, tmp, 425, 0, TIMEOUT, NULL,addr_head->addr, addr_head->addrlen, GNUNET_YES, &task_send_cont, NULL);*/ 1036 api->send(api->cls, &my_identity, tmp, 425, 0, TIMEOUT, NULL,addr_head->addr, addr_head->addrlen, GNUNET_YES, &task_send_cont, NULL);*/
1037 1037
1038 1038
1039 /* send a message with size GNUNET_SERVER_MAX_MESSAGE_SIZE )*/
1040 /*
1041 GNUNET_free(tmp);
1042 tmp = GNUNET_malloc(GNUNET_SERVER_MAX_MESSAGE_SIZE);
1043 uint16_t t2 = (uint16_t)GNUNET_SERVER_MAX_MESSAGE_SIZE;
1044 msg.size = htons(t2);
1045 memcpy(tmp,&msg,sizeof(struct GNUNET_MessageHeader));
1046 api->send(api->cls, &my_identity, tmp, GNUNET_SERVER_MAX_MESSAGE_SIZE, 0, TIMEOUT, NULL,addr_head->addr, addr_head->addrlen, GNUNET_YES, &task_send_cont, &fail_msg_transmited_bigger_max_size);
1047*/
1048 /* send a message with size GNUNET_SERVER_MAX_MESSAGE_SIZE-1 */ 1039 /* send a message with size GNUNET_SERVER_MAX_MESSAGE_SIZE-1 */
1049 GNUNET_free(tmp); 1040 GNUNET_free(tmp);
1050 tmp = GNUNET_malloc(GNUNET_SERVER_MAX_MESSAGE_SIZE-1); 1041 tmp = GNUNET_malloc(GNUNET_SERVER_MAX_MESSAGE_SIZE-1);
diff --git a/src/transport/test_transport_api_reliability.c b/src/transport/test_transport_api_reliability.c
index 755d5a576..4f00fa0d9 100644
--- a/src/transport/test_transport_api_reliability.c
+++ b/src/transport/test_transport_api_reliability.c
@@ -46,7 +46,7 @@
46 * 'MAX_PENDING' in 'gnunet-service-transport.c', otherwise 46 * 'MAX_PENDING' in 'gnunet-service-transport.c', otherwise
47 * messages may be dropped even for a reliable transport. 47 * messages may be dropped even for a reliable transport.
48 */ 48 */
49#define TOTAL_MSGS (60000 * 2) 49#define TOTAL_MSGS (60000 * 20)
50 50
51/** 51/**
52 * How long until we give up on transmitting the message? 52 * How long until we give up on transmitting the message?
@@ -152,6 +152,7 @@ static unsigned int
152get_size (unsigned int iter) 152get_size (unsigned int iter)
153{ 153{
154 unsigned int ret; 154 unsigned int ret;
155
155 if (iter < 60000) 156 if (iter < 60000)
156 return iter + sizeof (struct TestMessage); 157 return iter + sizeof (struct TestMessage);
157 ret = (iter * iter * iter); 158 ret = (iter * iter * iter);
@@ -168,6 +169,7 @@ notify_receive (void *cls,
168{ 169{
169 static int n; 170 static int n;
170 unsigned int s; 171 unsigned int s;
172 char cbuf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1];
171 const struct TestMessage *hdr; 173 const struct TestMessage *hdr;
172 174
173 hdr = (const struct TestMessage*) message; 175 hdr = (const struct TestMessage*) message;
@@ -196,6 +198,18 @@ notify_receive (void *cls,
196 die_task = GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL); 198 die_task = GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL);
197 return; 199 return;
198 } 200 }
201 memset (cbuf, n, s - sizeof (struct TestMessage));
202 if (0 != memcmp (cbuf,
203 &hdr[1],
204 s - sizeof (struct TestMessage)))
205 {
206 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
207 "Expected message %u with bits %u, but body did not match\n",
208 n, (unsigned char) n);
209 GNUNET_SCHEDULER_cancel (sched, die_task);
210 die_task = GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL);
211 return;
212 }
199#if VERBOSE 213#if VERBOSE
200 if (ntohl(hdr->num) % 5000 == 0) 214 if (ntohl(hdr->num) % 5000 == 0)
201 { 215 {
diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c
index 2cd563178..d76ff6e5d 100644
--- a/src/transport/transport_api.c
+++ b/src/transport/transport_api.c
@@ -598,6 +598,7 @@ transport_notify_ready (void *cls, size_t size, void *buf)
598#endif 598#endif
599 if (mret != 0) 599 if (mret != 0)
600 { 600 {
601 GNUNET_assert (mret + sizeof (struct OutboundMessage) < GNUNET_SERVER_MAX_MESSAGE_SIZE);
601 obm.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND); 602 obm.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND);
602 obm.header.size = htons (mret + sizeof (struct OutboundMessage)); 603 obm.header.size = htons (mret + sizeof (struct OutboundMessage));
603 obm.priority = htonl (th->priority); 604 obm.priority = htonl (th->priority);
@@ -1699,7 +1700,7 @@ GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle
1699#if DEBUG_TRANSPORT 1700#if DEBUG_TRANSPORT
1700 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1701 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1701 "Message size is %d, max allowed is %d.\n", 1702 "Message size is %d, max allowed is %d.\n",
1702 size + sizeof (struct OutboundMessage), GNUNET_SERVER_MAX_MESSAGE_SIZE); 1703 size + sizeof (struct OutboundMessage), GNUNET_SERVER_MAX_MESSAGE_SIZE - 1);
1703#endif 1704#endif
1704 GNUNET_break (0); 1705 GNUNET_break (0);
1705 return NULL; 1706 return NULL;
diff --git a/src/util/client.c b/src/util/client.c
index c7853d146..4ec40d032 100644
--- a/src/util/client.c
+++ b/src/util/client.c
@@ -291,7 +291,7 @@ do_connect (struct GNUNET_SCHEDULER_Handle *sched,
291 sock = GNUNET_CONNECTION_create_from_connect_to_unixpath (sched, 291 sock = GNUNET_CONNECTION_create_from_connect_to_unixpath (sched,
292 cfg, 292 cfg,
293 unixpath, 293 unixpath,
294 GNUNET_SERVER_MAX_MESSAGE_SIZE); 294 GNUNET_SERVER_MAX_MESSAGE_SIZE - 1);
295 GNUNET_free (unixpath); 295 GNUNET_free (unixpath);
296 if (sock != NULL) 296 if (sock != NULL)
297 return sock; 297 return sock;
@@ -328,7 +328,7 @@ do_connect (struct GNUNET_SCHEDULER_Handle *sched,
328 cfg, 328 cfg,
329 hostname, 329 hostname,
330 port, 330 port,
331 GNUNET_SERVER_MAX_MESSAGE_SIZE); 331 GNUNET_SERVER_MAX_MESSAGE_SIZE - 1);
332 GNUNET_free (hostname); 332 GNUNET_free (hostname);
333 return sock; 333 return sock;
334} 334}
@@ -579,7 +579,7 @@ GNUNET_CLIENT_receive (struct GNUNET_CLIENT_Connection *sock,
579 GNUNET_assert (sock->in_receive == GNUNET_NO); 579 GNUNET_assert (sock->in_receive == GNUNET_NO);
580 sock->in_receive = GNUNET_YES; 580 sock->in_receive = GNUNET_YES;
581 GNUNET_CONNECTION_receive (sock->sock, 581 GNUNET_CONNECTION_receive (sock->sock,
582 GNUNET_SERVER_MAX_MESSAGE_SIZE, 582 GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
583 timeout, &receive_helper, sock); 583 timeout, &receive_helper, sock);
584 } 584 }
585} 585}
diff --git a/src/util/connection.c b/src/util/connection.c
index 1631718e7..6c53bdef7 100644
--- a/src/util/connection.c
+++ b/src/util/connection.c
@@ -37,6 +37,7 @@
37#include "gnunet_container_lib.h" 37#include "gnunet_container_lib.h"
38#include "gnunet_resolver_service.h" 38#include "gnunet_resolver_service.h"
39#include "gnunet_scheduler_lib.h" 39#include "gnunet_scheduler_lib.h"
40#include "gnunet_server_lib.h"
40 41
41#define DEBUG_CONNECTION GNUNET_NO 42#define DEBUG_CONNECTION GNUNET_NO
42 43
@@ -326,6 +327,7 @@ GNUNET_CONNECTION_create_from_existing (struct GNUNET_SCHEDULER_Handle
326 struct GNUNET_CONNECTION_Handle *ret; 327 struct GNUNET_CONNECTION_Handle *ret;
327 ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle) + maxbuf); 328 ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle) + maxbuf);
328 ret->write_buffer = (char *) &ret[1]; 329 ret->write_buffer = (char *) &ret[1];
330 GNUNET_assert (maxbuf < GNUNET_SERVER_MAX_MESSAGE_SIZE);
329 ret->write_buffer_size = maxbuf; 331 ret->write_buffer_size = maxbuf;
330 ret->sock = osSocket; 332 ret->sock = osSocket;
331 ret->sched = sched; 333 ret->sched = sched;
@@ -416,6 +418,7 @@ GNUNET_CONNECTION_create_from_accept (struct GNUNET_SCHEDULER_Handle
416 } 418 }
417 ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle) + maxbuf); 419 ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle) + maxbuf);
418 ret->write_buffer = (char *) &ret[1]; 420 ret->write_buffer = (char *) &ret[1];
421 GNUNET_assert (maxbuf < GNUNET_SERVER_MAX_MESSAGE_SIZE);
419 ret->write_buffer_size = maxbuf; 422 ret->write_buffer_size = maxbuf;
420 ret->addr = uaddr; 423 ret->addr = uaddr;
421 ret->addrlen = addrlen; 424 ret->addrlen = addrlen;
@@ -873,6 +876,7 @@ GNUNET_CONNECTION_create_from_connect (struct GNUNET_SCHEDULER_Handle *sched,
873 ret->cfg = cfg; 876 ret->cfg = cfg;
874 ret->sched = sched; 877 ret->sched = sched;
875 ret->write_buffer = (char *) &ret[1]; 878 ret->write_buffer = (char *) &ret[1];
879 GNUNET_assert (maxbuf < GNUNET_SERVER_MAX_MESSAGE_SIZE);
876 ret->write_buffer_size = maxbuf; 880 ret->write_buffer_size = maxbuf;
877 ret->port = port; 881 ret->port = port;
878 ret->hostname = GNUNET_strdup (hostname); 882 ret->hostname = GNUNET_strdup (hostname);
@@ -929,6 +933,7 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (struct GNUNET_SCHEDULER_Handl
929 ret->cfg = cfg; 933 ret->cfg = cfg;
930 ret->sched = sched; 934 ret->sched = sched;
931 ret->write_buffer = (char *) &ret[1]; 935 ret->write_buffer = (char *) &ret[1];
936 GNUNET_assert (maxbuf < GNUNET_SERVER_MAX_MESSAGE_SIZE);
932 ret->write_buffer_size = maxbuf; 937 ret->write_buffer_size = maxbuf;
933 ret->port = 0; 938 ret->port = 0;
934 ret->hostname = NULL; 939 ret->hostname = NULL;
diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c
index 8905810d4..f4832ed9c 100644
--- a/src/util/resolver_api.c
+++ b/src/util/resolver_api.c
@@ -426,12 +426,11 @@ GNUNET_RESOLVER_ip_get (struct GNUNET_SCHEDULER_Handle *sched,
426 unsigned int i; 426 unsigned int i;
427 struct in_addr v4; 427 struct in_addr v4;
428 struct in6_addr v6; 428 struct in6_addr v6;
429 char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE]; 429 char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1];
430 430
431 check_config (cfg); 431 check_config (cfg);
432 slen = strlen (hostname) + 1; 432 slen = strlen (hostname) + 1;
433 if (slen + sizeof (struct GNUNET_RESOLVER_GetMessage) > 433 if (slen + sizeof (struct GNUNET_RESOLVER_GetMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
434 GNUNET_SERVER_MAX_MESSAGE_SIZE)
435 { 434 {
436 GNUNET_break (0); 435 GNUNET_break (0);
437 return NULL; 436 return NULL;
@@ -619,7 +618,7 @@ GNUNET_RESOLVER_hostname_get (struct GNUNET_SCHEDULER_Handle *sched,
619 struct GNUNET_CLIENT_Connection *client; 618 struct GNUNET_CLIENT_Connection *client;
620 struct GNUNET_RESOLVER_GetMessage *msg; 619 struct GNUNET_RESOLVER_GetMessage *msg;
621 struct GNUNET_RESOLVER_RequestHandle *rh; 620 struct GNUNET_RESOLVER_RequestHandle *rh;
622 char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE]; 621 char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1];
623 622
624 check_config (cfg); 623 check_config (cfg);
625 rh = GNUNET_malloc (sizeof (struct GNUNET_RESOLVER_RequestHandle) + salen); 624 rh = GNUNET_malloc (sizeof (struct GNUNET_RESOLVER_RequestHandle) + salen);
@@ -636,8 +635,7 @@ GNUNET_RESOLVER_hostname_get (struct GNUNET_SCHEDULER_Handle *sched,
636 &numeric_reverse, rh); 635 &numeric_reverse, rh);
637 return rh; 636 return rh;
638 } 637 }
639 if (salen + sizeof (struct GNUNET_RESOLVER_GetMessage) > 638 if (salen + sizeof (struct GNUNET_RESOLVER_GetMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
640 GNUNET_SERVER_MAX_MESSAGE_SIZE)
641 { 639 {
642 GNUNET_break (0); 640 GNUNET_break (0);
643 GNUNET_free (rh); 641 GNUNET_free (rh);
diff --git a/src/util/server.c b/src/util/server.c
index c31168e8c..606d44369 100644
--- a/src/util/server.c
+++ b/src/util/server.c
@@ -701,7 +701,7 @@ process_mst (struct GNUNET_SERVER_Client *client,
701 "Server re-enters receive loop.\n"); 701 "Server re-enters receive loop.\n");
702#endif 702#endif
703 GNUNET_CONNECTION_receive (client->connection, 703 GNUNET_CONNECTION_receive (client->connection,
704 GNUNET_SERVER_MAX_MESSAGE_SIZE, 704 GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
705 client->server->idle_timeout, 705 client->server->idle_timeout,
706 &process_incoming, client); 706 &process_incoming, client);
707 break; 707 break;
@@ -811,7 +811,7 @@ restart_processing (void *cls,
811#endif 811#endif
812 client->receive_pending = GNUNET_YES; 812 client->receive_pending = GNUNET_YES;
813 GNUNET_CONNECTION_receive (client->connection, 813 GNUNET_CONNECTION_receive (client->connection,
814 GNUNET_SERVER_MAX_MESSAGE_SIZE, 814 GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
815 client->server->idle_timeout, &process_incoming, client); 815 client->server->idle_timeout, &process_incoming, client);
816 return; 816 return;
817 } 817 }
@@ -877,7 +877,7 @@ GNUNET_SERVER_connect_socket (struct
877 877
878 client = GNUNET_malloc (sizeof (struct GNUNET_SERVER_Client)); 878 client = GNUNET_malloc (sizeof (struct GNUNET_SERVER_Client));
879 client->connection = connection; 879 client->connection = connection;
880 client->mst = GNUNET_SERVER_mst_create (GNUNET_SERVER_MAX_MESSAGE_SIZE, 880 client->mst = GNUNET_SERVER_mst_create (GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
881 &client_message_tokenizer_callback, 881 &client_message_tokenizer_callback,
882 server); 882 server);
883 client->reference_count = 1; 883 client->reference_count = 1;
@@ -887,7 +887,7 @@ GNUNET_SERVER_connect_socket (struct
887 server->clients = client; 887 server->clients = client;
888 client->receive_pending = GNUNET_YES; 888 client->receive_pending = GNUNET_YES;
889 GNUNET_CONNECTION_receive (client->connection, 889 GNUNET_CONNECTION_receive (client->connection,
890 GNUNET_SERVER_MAX_MESSAGE_SIZE, 890 GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
891 server->idle_timeout, &process_incoming, client); 891 server->idle_timeout, &process_incoming, client);
892 return client; 892 return client;
893} 893}
diff --git a/src/util/server_mst.c b/src/util/server_mst.c
index 29c04e96c..9dc47e94b 100644
--- a/src/util/server_mst.c
+++ b/src/util/server_mst.c
@@ -84,7 +84,7 @@ struct GNUNET_SERVER_MessageStreamTokenizer
84 * Create a message stream tokenizer. 84 * Create a message stream tokenizer.
85 * 85 *
86 * @param maxbuf maximum message size to support (typically 86 * @param maxbuf maximum message size to support (typically
87 * GNUNET_SERVER_MAX_MESSAGE_SIZE) 87 * GNUNET_SERVER_MAX_MESSAGE_SIZE - 1)
88 * @param cb function to call on completed messages 88 * @param cb function to call on completed messages
89 * @param cb_cls closure for cb 89 * @param cb_cls closure for cb
90 * @return handle to tokenizer 90 * @return handle to tokenizer
diff --git a/src/util/service.c b/src/util/service.c
index cff701a3c..46a01a098 100644
--- a/src/util/service.c
+++ b/src/util/service.c
@@ -1140,7 +1140,7 @@ setup_service (struct GNUNET_SERVICE_Context *sctx)
1140 } 1140 }
1141 } 1141 }
1142 else 1142 else
1143 maxbuf = GNUNET_SERVER_MAX_MESSAGE_SIZE; 1143 maxbuf = GNUNET_SERVER_MAX_MESSAGE_SIZE - 1;
1144 1144
1145 if (GNUNET_CONFIGURATION_have_value (sctx->cfg, 1145 if (GNUNET_CONFIGURATION_have_value (sctx->cfg,
1146 sctx->serviceName, "TOLERANT")) 1146 sctx->serviceName, "TOLERANT"))
@@ -1577,7 +1577,7 @@ GNUNET_SERVICE_run (int argc,
1577 sctx.ready_confirm_fd = -1; 1577 sctx.ready_confirm_fd = -1;
1578 sctx.ret = GNUNET_OK; 1578 sctx.ret = GNUNET_OK;
1579 sctx.timeout = GNUNET_TIME_UNIT_FOREVER_REL; 1579 sctx.timeout = GNUNET_TIME_UNIT_FOREVER_REL;
1580 sctx.maxbuf = GNUNET_SERVER_MAX_MESSAGE_SIZE; 1580 sctx.maxbuf = GNUNET_SERVER_MAX_MESSAGE_SIZE - 1;
1581 sctx.task = task; 1581 sctx.task = task;
1582 sctx.serviceName = serviceName; 1582 sctx.serviceName = serviceName;
1583 sctx.cfg = cfg = GNUNET_CONFIGURATION_create (); 1583 sctx.cfg = cfg = GNUNET_CONFIGURATION_create ();
@@ -1656,7 +1656,7 @@ GNUNET_SERVICE_start (const char *serviceName,
1656 sctx->ready_confirm_fd = -1; /* no daemonizing */ 1656 sctx->ready_confirm_fd = -1; /* no daemonizing */
1657 sctx->ret = GNUNET_OK; 1657 sctx->ret = GNUNET_OK;
1658 sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL; 1658 sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
1659 sctx->maxbuf = GNUNET_SERVER_MAX_MESSAGE_SIZE; 1659 sctx->maxbuf = GNUNET_SERVER_MAX_MESSAGE_SIZE - 1;
1660 sctx->serviceName = serviceName; 1660 sctx->serviceName = serviceName;
1661 sctx->cfg = cfg; 1661 sctx->cfg = cfg;
1662 sctx->sched = sched; 1662 sctx->sched = sched;