From 55a5dcea87abe1381505d52f0b5d7a166d75aeec Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 21 Jul 2010 21:22:35 +0000 Subject: fixing bad memcpy --- src/statistics/gnunet-service-statistics.c | 43 +++++++++++++++++----------- src/statistics/test_statistics_api_data.conf | 2 +- 2 files changed, 27 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/statistics/gnunet-service-statistics.c b/src/statistics/gnunet-service-statistics.c index 251302a66..823dc419e 100644 --- a/src/statistics/gnunet-service-statistics.c +++ b/src/statistics/gnunet-service-statistics.c @@ -155,6 +155,17 @@ static struct GNUNET_SERVER_NotificationContext *nc; static uint32_t uidgen; +static void +inject_message (void *cls, + void *client, + const struct GNUNET_MessageHeader *msg) +{ + struct GNUNET_SERVER_Handle *server = cls; + + GNUNET_break (GNUNET_OK == GNUNET_SERVER_inject (server, NULL, msg)); +} + + /** * Load persistent values from disk. Disk format is * exactly the same format that we also use for @@ -170,8 +181,7 @@ load (struct GNUNET_SERVER_Handle *server) struct GNUNET_DISK_MapHandle *mh; struct stat sb; char *buf; - size_t off; - const struct GNUNET_MessageHeader *msg; + struct GNUNET_SERVER_MessageStreamTokenizer *mst; fn = GNUNET_DISK_get_home_filename (cfg, "statistics", "statistics.data", NULL); @@ -200,18 +210,16 @@ load (struct GNUNET_SERVER_Handle *server) GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading %llu bytes of statistics from `%s'\n"), (unsigned long long) sb.st_size, fn); - off = 0; - while (off + sizeof (struct GNUNET_MessageHeader) < sb.st_size) - { - msg = (const struct GNUNET_MessageHeader *) &buf[off]; - if ((ntohs (msg->size) + off > sb.st_size) || - (GNUNET_OK != GNUNET_SERVER_inject (server, NULL, msg))) - { - GNUNET_break (0); - break; - } - off += ntohs (msg->size); - } + mst = GNUNET_SERVER_mst_create (&inject_message, + server); + GNUNET_break (GNUNET_OK == + GNUNET_SERVER_mst_receive (mst, + NULL, + buf, + sb.st_size, + GNUNET_YES, + GNUNET_NO)); + GNUNET_SERVER_mst_destroy (mst); GNUNET_break (GNUNET_OK == GNUNET_DISK_file_unmap (mh)); GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fh)); GNUNET_free (fn); @@ -564,6 +572,7 @@ handle_watch (void *cls, struct StatsEntry *pos; struct ClientEntry *ce; struct WatchEntry *we; + size_t slen; ce = make_client_entry (client); msize = ntohs (message->size); @@ -604,10 +613,10 @@ handle_watch (void *cls, pos->msg->header.size = htons (sizeof (struct GNUNET_STATISTICS_SetMessage) + size); pos->msg->header.type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_SET); - memcpy (pos->msg, message, ntohs (message->size)); pos->service = (const char *) &pos->msg[1]; - memcpy (&pos->msg[1], service, strlen (service)+1); - pos->name = &pos->service[strlen (pos->service) + 1]; + slen = strlen (service) + 1; + memcpy ((void*) pos->service, service, slen); + pos->name = &pos->service[slen]; memcpy ((void*) pos->name, name, strlen (name)+1); start = pos; } diff --git a/src/statistics/test_statistics_api_data.conf b/src/statistics/test_statistics_api_data.conf index 6666e8cc2..d93758fd3 100644 --- a/src/statistics/test_statistics_api_data.conf +++ b/src/statistics/test_statistics_api_data.conf @@ -5,7 +5,7 @@ DEFAULTCONFIG = test_statistics_api_data.conf [statistics] PORT = 22353 UNIXPATH = /tmp/test-statistics-service-statistics.unix -DEBUG = YES +DEBUG = NO [arm] PORT = 22354 -- cgit v1.2.3