From 537903a8dc4c3ecf2dfa382af0289ddf890adfc7 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 25 Jun 2010 21:08:55 +0000 Subject: [PATCH] fixing common off-by-one error with respect to maximum message size --- src/arm/arm_api.c | 3 +-- src/core/gnunet-service-core.c | 4 ++-- src/datastore/datastore_api.c | 6 +++--- src/dv/gnunet-service-dv.c | 2 +- src/fs/fs_publish.c | 2 +- src/fs/gnunet-service-fs_indexing.c | 5 ++--- src/hello/hello.c | 2 +- src/hostlist/hostlist-client.c | 4 ++-- src/hostlist/hostlist-server.c | 2 +- src/peerinfo/gnunet-service-peerinfo.c | 6 +++--- src/topology/gnunet-daemon-topology.c | 2 +- src/transport/plugin_transport_http.c | 4 ++-- src/transport/plugin_transport_tcp.c | 4 ++-- src/transport/test_plugin_transport_http.c | 9 --------- src/transport/test_transport_api_reliability.c | 16 +++++++++++++++- src/transport/transport_api.c | 3 ++- src/util/client.c | 6 +++--- src/util/connection.c | 5 +++++ src/util/resolver_api.c | 10 ++++------ src/util/server.c | 8 ++++---- src/util/server_mst.c | 2 +- src/util/service.c | 6 +++--- 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, struct GNUNET_MessageHeader *msg; slen = strlen (service_name) + 1; - if (slen + sizeof (struct GNUNET_MessageHeader) > - GNUNET_SERVER_MAX_MESSAGE_SIZE) + if (slen + sizeof (struct GNUNET_MessageHeader) >= GNUNET_SERVER_MAX_MESSAGE_SIZE) { GNUNET_break (0); 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, struct GNUNET_TIME_Relative *retry_time, unsigned int *priority) { - char ntmb[GNUNET_SERVER_MAX_MESSAGE_SIZE]; + char ntmb[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; struct NotifyTrafficMessage *ntm = (struct NotifyTrafficMessage*) ntmb; struct MessageEntry *pos; struct MessageEntry *prev; @@ -3824,7 +3824,7 @@ run (void *cls, &handle_transport_notify_disconnect); GNUNET_assert (NULL != transport); stats = GNUNET_STATISTICS_create (sched, "core", cfg); - mst = GNUNET_SERVER_mst_create (GNUNET_SERVER_MAX_MESSAGE_SIZE, + mst = GNUNET_SERVER_mst_create (GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, &deliver_message, NULL); 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 if (c == NULL) return NULL; /* oops */ h = GNUNET_malloc (sizeof(struct GNUNET_DATASTORE_Handle) + - GNUNET_SERVER_MAX_MESSAGE_SIZE); + GNUNET_SERVER_MAX_MESSAGE_SIZE - 1); h->client = c; h->cfg = cfg; h->sched = sched; @@ -790,7 +790,7 @@ GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h, GNUNET_h2s (key)); #endif msize = sizeof(struct DataMessage) + size; - GNUNET_assert (msize <= GNUNET_SERVER_MAX_MESSAGE_SIZE); + GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE); qc.sc.cont = cont; qc.sc.cont_cls = cont_cls; qe = make_queue_entry (h, msize, @@ -1037,7 +1037,7 @@ GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h, qc.sc.cont = cont; qc.sc.cont_cls = cont_cls; msize = sizeof(struct DataMessage) + size; - GNUNET_assert (msize <= GNUNET_SERVER_MAX_MESSAGE_SIZE); + GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE); qe = make_queue_entry (h, msize, queue_priority, max_queue_size, timeout, &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, if (coreAPI == NULL) return; - coreMST = GNUNET_SERVER_mst_create (GNUNET_SERVER_MAX_MESSAGE_SIZE, + coreMST = GNUNET_SERVER_mst_create (GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, &tokenized_message_handler, NULL); 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, fn = GNUNET_STRINGS_filename_expand (p->filename); GNUNET_assert (fn != NULL); slen = strlen (fn) + 1; - if (slen > GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof(struct IndexStartMessage)) + if (slen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof(struct IndexStartMessage)) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("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, { struct GNUNET_SERVER_TransmitContext *tc; struct IndexInfoMessage *iim; - char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE]; + char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; size_t slen; const char *fn; struct IndexInfo *pos; @@ -442,8 +442,7 @@ GNUNET_FS_handle_index_list_get (void *cls, { fn = pos->filename; slen = strlen (fn) + 1; - if (slen + sizeof (struct IndexInfoMessage) > - GNUNET_SERVER_MAX_MESSAGE_SIZE) + if (slen + sizeof (struct IndexInfoMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE) { GNUNET_break (0); 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 GNUNET_HELLO_GenerateAddressListCallback addrgen, void *addrgen_cls) { - char buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE - 256 - + char buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - 256 - sizeof (struct GNUNET_HELLO_Message)]; size_t max; 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, size_t nmemb, void *ctx) { - static char download_buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE]; + static char download_buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; const char * cbuf = ptr; const struct GNUNET_MessageHeader *msg; size_t total; @@ -295,7 +295,7 @@ callback_download (void *ptr, while ( (left > 0) || (download_pos > 0) ) { - cpy = GNUNET_MIN (left, GNUNET_SERVER_MAX_MESSAGE_SIZE - download_pos); + cpy = GNUNET_MIN (left, GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - download_pos); memcpy (&download_buffer[download_pos], cbuf, 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, if (hostlist_uri == NULL) return; size = strlen (hostlist_uri) + 1; - if (size + sizeof (struct GNUNET_MessageHeader) > GNUNET_SERVER_MAX_MESSAGE_SIZE) + if (size + sizeof (struct GNUNET_MessageHeader) >= GNUNET_SERVER_MAX_MESSAGE_SIZE) { GNUNET_break (0); 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) struct HostEntry *entry; char *fn; uint32_t trust; - char buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE]; + char buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; const struct GNUNET_HELLO_Message *hello; struct GNUNET_HELLO_Message *hello_clean; int size; @@ -494,7 +494,7 @@ send_to_each_host (const struct GNUNET_PeerIdentity *only, struct HostEntry *pos; struct InfoMessage *im; uint16_t hs; - char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE]; + char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; struct GNUNET_SERVER_TransmitContext *tc; int match; @@ -600,7 +600,7 @@ static int discard_hosts_helper (void *cls, const char *fn) { struct GNUNET_TIME_Absolute *now = cls; - char buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE]; + char buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; const struct GNUNET_HELLO_Message *hello; struct GNUNET_HELLO_Message *new_hello; 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, /* find applicable HELLOs */ fah.peer = pl; fah.result = NULL; - fah.max_size = GNUNET_SERVER_MAX_MESSAGE_SIZE; + fah.max_size = GNUNET_SERVER_MAX_MESSAGE_SIZE - 1; fah.next_adv = GNUNET_TIME_UNIT_FOREVER_REL; GNUNET_CONTAINER_multihashmap_iterate (peers, &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, } */ if (cs->msgtok==NULL) - cs->msgtok = GNUNET_SERVER_mst_create (GNUNET_SERVER_MAX_MESSAGE_SIZE, &messageTokenizerCallback, cs); + cs->msgtok = GNUNET_SERVER_mst_create (GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, &messageTokenizerCallback, cs); } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Daemon has new an incoming `%s' request from peer `%s'\n",method, GNUNET_i2s(&cs->identity)); } @@ -570,7 +570,7 @@ accessHandlerCallback (void *cls, if ((*upload_data_size > 0) && (cs->is_bad_request != GNUNET_YES)) { - if (*upload_data_size + cs->pending_inbound_msg.bytes_recv <= GNUNET_SERVER_MAX_MESSAGE_SIZE) + if (*upload_data_size + cs->pending_inbound_msg.bytes_recv < GNUNET_SERVER_MAX_MESSAGE_SIZE) { /* copy uploaded data to buffer */ 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, } sa = GNUNET_CONNECTION_create_from_sockaddr (plugin->env->sched, af, sb, sbs, - GNUNET_SERVER_MAX_MESSAGE_SIZE); + GNUNET_SERVER_MAX_MESSAGE_SIZE - 1); if (sa == NULL) { #if DEBUG_TCP @@ -1991,7 +1991,7 @@ tcp_plugin_server_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc * that wants to connect to us! Send a message to establish a connection. */ sock = GNUNET_CONNECTION_create_from_sockaddr (plugin->env->sched, AF_INET, (struct sockaddr *)&in_addr, - sizeof(in_addr), GNUNET_SERVER_MAX_MESSAGE_SIZE); + sizeof(in_addr), GNUNET_SERVER_MAX_MESSAGE_SIZE - 1); if (sock == NULL) { 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( ) api->send(api->cls, &my_identity, tmp, 425, 0, TIMEOUT, NULL,addr_head->addr, addr_head->addrlen, GNUNET_YES, &task_send_cont, NULL);*/ - /* send a message with size GNUNET_SERVER_MAX_MESSAGE_SIZE )*/ - /* - GNUNET_free(tmp); - tmp = GNUNET_malloc(GNUNET_SERVER_MAX_MESSAGE_SIZE); - uint16_t t2 = (uint16_t)GNUNET_SERVER_MAX_MESSAGE_SIZE; - msg.size = htons(t2); - memcpy(tmp,&msg,sizeof(struct GNUNET_MessageHeader)); - 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); -*/ /* send a message with size GNUNET_SERVER_MAX_MESSAGE_SIZE-1 */ GNUNET_free(tmp); 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 @@ * 'MAX_PENDING' in 'gnunet-service-transport.c', otherwise * messages may be dropped even for a reliable transport. */ -#define TOTAL_MSGS (60000 * 2) +#define TOTAL_MSGS (60000 * 20) /** * How long until we give up on transmitting the message? @@ -152,6 +152,7 @@ static unsigned int get_size (unsigned int iter) { unsigned int ret; + if (iter < 60000) return iter + sizeof (struct TestMessage); ret = (iter * iter * iter); @@ -168,6 +169,7 @@ notify_receive (void *cls, { static int n; unsigned int s; + char cbuf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; const struct TestMessage *hdr; hdr = (const struct TestMessage*) message; @@ -196,6 +198,18 @@ notify_receive (void *cls, die_task = GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL); return; } + memset (cbuf, n, s - sizeof (struct TestMessage)); + if (0 != memcmp (cbuf, + &hdr[1], + s - sizeof (struct TestMessage))) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Expected message %u with bits %u, but body did not match\n", + n, (unsigned char) n); + GNUNET_SCHEDULER_cancel (sched, die_task); + die_task = GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL); + return; + } #if VERBOSE if (ntohl(hdr->num) % 5000 == 0) { 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) #endif if (mret != 0) { + GNUNET_assert (mret + sizeof (struct OutboundMessage) < GNUNET_SERVER_MAX_MESSAGE_SIZE); obm.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND); obm.header.size = htons (mret + sizeof (struct OutboundMessage)); obm.priority = htonl (th->priority); @@ -1699,7 +1700,7 @@ GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message size is %d, max allowed is %d.\n", - size + sizeof (struct OutboundMessage), GNUNET_SERVER_MAX_MESSAGE_SIZE); + size + sizeof (struct OutboundMessage), GNUNET_SERVER_MAX_MESSAGE_SIZE - 1); #endif GNUNET_break (0); 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, sock = GNUNET_CONNECTION_create_from_connect_to_unixpath (sched, cfg, unixpath, - GNUNET_SERVER_MAX_MESSAGE_SIZE); + GNUNET_SERVER_MAX_MESSAGE_SIZE - 1); GNUNET_free (unixpath); if (sock != NULL) return sock; @@ -328,7 +328,7 @@ do_connect (struct GNUNET_SCHEDULER_Handle *sched, cfg, hostname, port, - GNUNET_SERVER_MAX_MESSAGE_SIZE); + GNUNET_SERVER_MAX_MESSAGE_SIZE - 1); GNUNET_free (hostname); return sock; } @@ -579,7 +579,7 @@ GNUNET_CLIENT_receive (struct GNUNET_CLIENT_Connection *sock, GNUNET_assert (sock->in_receive == GNUNET_NO); sock->in_receive = GNUNET_YES; GNUNET_CONNECTION_receive (sock->sock, - GNUNET_SERVER_MAX_MESSAGE_SIZE, + GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, timeout, &receive_helper, sock); } } 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 @@ #include "gnunet_container_lib.h" #include "gnunet_resolver_service.h" #include "gnunet_scheduler_lib.h" +#include "gnunet_server_lib.h" #define DEBUG_CONNECTION GNUNET_NO @@ -326,6 +327,7 @@ GNUNET_CONNECTION_create_from_existing (struct GNUNET_SCHEDULER_Handle struct GNUNET_CONNECTION_Handle *ret; ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle) + maxbuf); ret->write_buffer = (char *) &ret[1]; + GNUNET_assert (maxbuf < GNUNET_SERVER_MAX_MESSAGE_SIZE); ret->write_buffer_size = maxbuf; ret->sock = osSocket; ret->sched = sched; @@ -416,6 +418,7 @@ GNUNET_CONNECTION_create_from_accept (struct GNUNET_SCHEDULER_Handle } ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle) + maxbuf); ret->write_buffer = (char *) &ret[1]; + GNUNET_assert (maxbuf < GNUNET_SERVER_MAX_MESSAGE_SIZE); ret->write_buffer_size = maxbuf; ret->addr = uaddr; ret->addrlen = addrlen; @@ -873,6 +876,7 @@ GNUNET_CONNECTION_create_from_connect (struct GNUNET_SCHEDULER_Handle *sched, ret->cfg = cfg; ret->sched = sched; ret->write_buffer = (char *) &ret[1]; + GNUNET_assert (maxbuf < GNUNET_SERVER_MAX_MESSAGE_SIZE); ret->write_buffer_size = maxbuf; ret->port = port; ret->hostname = GNUNET_strdup (hostname); @@ -929,6 +933,7 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (struct GNUNET_SCHEDULER_Handl ret->cfg = cfg; ret->sched = sched; ret->write_buffer = (char *) &ret[1]; + GNUNET_assert (maxbuf < GNUNET_SERVER_MAX_MESSAGE_SIZE); ret->write_buffer_size = maxbuf; ret->port = 0; 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, unsigned int i; struct in_addr v4; struct in6_addr v6; - char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE]; + char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; check_config (cfg); slen = strlen (hostname) + 1; - if (slen + sizeof (struct GNUNET_RESOLVER_GetMessage) > - GNUNET_SERVER_MAX_MESSAGE_SIZE) + if (slen + sizeof (struct GNUNET_RESOLVER_GetMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE) { GNUNET_break (0); return NULL; @@ -619,7 +618,7 @@ GNUNET_RESOLVER_hostname_get (struct GNUNET_SCHEDULER_Handle *sched, struct GNUNET_CLIENT_Connection *client; struct GNUNET_RESOLVER_GetMessage *msg; struct GNUNET_RESOLVER_RequestHandle *rh; - char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE]; + char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; check_config (cfg); rh = GNUNET_malloc (sizeof (struct GNUNET_RESOLVER_RequestHandle) + salen); @@ -636,8 +635,7 @@ GNUNET_RESOLVER_hostname_get (struct GNUNET_SCHEDULER_Handle *sched, &numeric_reverse, rh); return rh; } - if (salen + sizeof (struct GNUNET_RESOLVER_GetMessage) > - GNUNET_SERVER_MAX_MESSAGE_SIZE) + if (salen + sizeof (struct GNUNET_RESOLVER_GetMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE) { GNUNET_break (0); 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, "Server re-enters receive loop.\n"); #endif GNUNET_CONNECTION_receive (client->connection, - GNUNET_SERVER_MAX_MESSAGE_SIZE, + GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, client->server->idle_timeout, &process_incoming, client); break; @@ -811,7 +811,7 @@ restart_processing (void *cls, #endif client->receive_pending = GNUNET_YES; GNUNET_CONNECTION_receive (client->connection, - GNUNET_SERVER_MAX_MESSAGE_SIZE, + GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, client->server->idle_timeout, &process_incoming, client); return; } @@ -877,7 +877,7 @@ GNUNET_SERVER_connect_socket (struct client = GNUNET_malloc (sizeof (struct GNUNET_SERVER_Client)); client->connection = connection; - client->mst = GNUNET_SERVER_mst_create (GNUNET_SERVER_MAX_MESSAGE_SIZE, + client->mst = GNUNET_SERVER_mst_create (GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, &client_message_tokenizer_callback, server); client->reference_count = 1; @@ -887,7 +887,7 @@ GNUNET_SERVER_connect_socket (struct server->clients = client; client->receive_pending = GNUNET_YES; GNUNET_CONNECTION_receive (client->connection, - GNUNET_SERVER_MAX_MESSAGE_SIZE, + GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, server->idle_timeout, &process_incoming, client); return client; } 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 * Create a message stream tokenizer. * * @param maxbuf maximum message size to support (typically - * GNUNET_SERVER_MAX_MESSAGE_SIZE) + * GNUNET_SERVER_MAX_MESSAGE_SIZE - 1) * @param cb function to call on completed messages * @param cb_cls closure for cb * @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) } } else - maxbuf = GNUNET_SERVER_MAX_MESSAGE_SIZE; + maxbuf = GNUNET_SERVER_MAX_MESSAGE_SIZE - 1; if (GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->serviceName, "TOLERANT")) @@ -1577,7 +1577,7 @@ GNUNET_SERVICE_run (int argc, sctx.ready_confirm_fd = -1; sctx.ret = GNUNET_OK; sctx.timeout = GNUNET_TIME_UNIT_FOREVER_REL; - sctx.maxbuf = GNUNET_SERVER_MAX_MESSAGE_SIZE; + sctx.maxbuf = GNUNET_SERVER_MAX_MESSAGE_SIZE - 1; sctx.task = task; sctx.serviceName = serviceName; sctx.cfg = cfg = GNUNET_CONFIGURATION_create (); @@ -1656,7 +1656,7 @@ GNUNET_SERVICE_start (const char *serviceName, sctx->ready_confirm_fd = -1; /* no daemonizing */ sctx->ret = GNUNET_OK; sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL; - sctx->maxbuf = GNUNET_SERVER_MAX_MESSAGE_SIZE; + sctx->maxbuf = GNUNET_SERVER_MAX_MESSAGE_SIZE - 1; sctx->serviceName = serviceName; sctx->cfg = cfg; sctx->sched = sched; -- 2.25.1