diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-07-21 21:22:35 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-07-21 21:22:35 +0000 |
commit | 55a5dcea87abe1381505d52f0b5d7a166d75aeec (patch) | |
tree | 4868928e88bd13a32072bc0e97d8bf7d6e225228 /src/statistics | |
parent | b05f920bfa907476b618a24bd78487db8873d2a1 (diff) | |
download | gnunet-55a5dcea87abe1381505d52f0b5d7a166d75aeec.tar.gz gnunet-55a5dcea87abe1381505d52f0b5d7a166d75aeec.zip |
fixing bad memcpy
Diffstat (limited to 'src/statistics')
-rw-r--r-- | src/statistics/gnunet-service-statistics.c | 43 | ||||
-rw-r--r-- | src/statistics/test_statistics_api_data.conf | 2 |
2 files changed, 27 insertions, 18 deletions
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; | |||
155 | static uint32_t uidgen; | 155 | static uint32_t uidgen; |
156 | 156 | ||
157 | 157 | ||
158 | static void | ||
159 | inject_message (void *cls, | ||
160 | void *client, | ||
161 | const struct GNUNET_MessageHeader *msg) | ||
162 | { | ||
163 | struct GNUNET_SERVER_Handle *server = cls; | ||
164 | |||
165 | GNUNET_break (GNUNET_OK == GNUNET_SERVER_inject (server, NULL, msg)); | ||
166 | } | ||
167 | |||
168 | |||
158 | /** | 169 | /** |
159 | * Load persistent values from disk. Disk format is | 170 | * Load persistent values from disk. Disk format is |
160 | * exactly the same format that we also use for | 171 | * exactly the same format that we also use for |
@@ -170,8 +181,7 @@ load (struct GNUNET_SERVER_Handle *server) | |||
170 | struct GNUNET_DISK_MapHandle *mh; | 181 | struct GNUNET_DISK_MapHandle *mh; |
171 | struct stat sb; | 182 | struct stat sb; |
172 | char *buf; | 183 | char *buf; |
173 | size_t off; | 184 | struct GNUNET_SERVER_MessageStreamTokenizer *mst; |
174 | const struct GNUNET_MessageHeader *msg; | ||
175 | 185 | ||
176 | fn = GNUNET_DISK_get_home_filename (cfg, | 186 | fn = GNUNET_DISK_get_home_filename (cfg, |
177 | "statistics", "statistics.data", NULL); | 187 | "statistics", "statistics.data", NULL); |
@@ -200,18 +210,16 @@ load (struct GNUNET_SERVER_Handle *server) | |||
200 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 210 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
201 | _("Loading %llu bytes of statistics from `%s'\n"), | 211 | _("Loading %llu bytes of statistics from `%s'\n"), |
202 | (unsigned long long) sb.st_size, fn); | 212 | (unsigned long long) sb.st_size, fn); |
203 | off = 0; | 213 | mst = GNUNET_SERVER_mst_create (&inject_message, |
204 | while (off + sizeof (struct GNUNET_MessageHeader) < sb.st_size) | 214 | server); |
205 | { | 215 | GNUNET_break (GNUNET_OK == |
206 | msg = (const struct GNUNET_MessageHeader *) &buf[off]; | 216 | GNUNET_SERVER_mst_receive (mst, |
207 | if ((ntohs (msg->size) + off > sb.st_size) || | 217 | NULL, |
208 | (GNUNET_OK != GNUNET_SERVER_inject (server, NULL, msg))) | 218 | buf, |
209 | { | 219 | sb.st_size, |
210 | GNUNET_break (0); | 220 | GNUNET_YES, |
211 | break; | 221 | GNUNET_NO)); |
212 | } | 222 | GNUNET_SERVER_mst_destroy (mst); |
213 | off += ntohs (msg->size); | ||
214 | } | ||
215 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_unmap (mh)); | 223 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_unmap (mh)); |
216 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fh)); | 224 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fh)); |
217 | GNUNET_free (fn); | 225 | GNUNET_free (fn); |
@@ -564,6 +572,7 @@ handle_watch (void *cls, | |||
564 | struct StatsEntry *pos; | 572 | struct StatsEntry *pos; |
565 | struct ClientEntry *ce; | 573 | struct ClientEntry *ce; |
566 | struct WatchEntry *we; | 574 | struct WatchEntry *we; |
575 | size_t slen; | ||
567 | 576 | ||
568 | ce = make_client_entry (client); | 577 | ce = make_client_entry (client); |
569 | msize = ntohs (message->size); | 578 | msize = ntohs (message->size); |
@@ -604,10 +613,10 @@ handle_watch (void *cls, | |||
604 | pos->msg->header.size = htons (sizeof (struct GNUNET_STATISTICS_SetMessage) + | 613 | pos->msg->header.size = htons (sizeof (struct GNUNET_STATISTICS_SetMessage) + |
605 | size); | 614 | size); |
606 | pos->msg->header.type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_SET); | 615 | pos->msg->header.type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_SET); |
607 | memcpy (pos->msg, message, ntohs (message->size)); | ||
608 | pos->service = (const char *) &pos->msg[1]; | 616 | pos->service = (const char *) &pos->msg[1]; |
609 | memcpy (&pos->msg[1], service, strlen (service)+1); | 617 | slen = strlen (service) + 1; |
610 | pos->name = &pos->service[strlen (pos->service) + 1]; | 618 | memcpy ((void*) pos->service, service, slen); |
619 | pos->name = &pos->service[slen]; | ||
611 | memcpy ((void*) pos->name, name, strlen (name)+1); | 620 | memcpy ((void*) pos->name, name, strlen (name)+1); |
612 | start = pos; | 621 | start = pos; |
613 | } | 622 | } |
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 | |||
5 | [statistics] | 5 | [statistics] |
6 | PORT = 22353 | 6 | PORT = 22353 |
7 | UNIXPATH = /tmp/test-statistics-service-statistics.unix | 7 | UNIXPATH = /tmp/test-statistics-service-statistics.unix |
8 | DEBUG = YES | 8 | DEBUG = NO |
9 | 9 | ||
10 | [arm] | 10 | [arm] |
11 | PORT = 22354 | 11 | PORT = 22354 |