gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r12328 - gnunet/src/statistics


From: gnunet
Subject: [GNUnet-SVN] r12328 - gnunet/src/statistics
Date: Wed, 21 Jul 2010 23:22:35 +0200

Author: grothoff
Date: 2010-07-21 23:22:35 +0200 (Wed, 21 Jul 2010)
New Revision: 12328

Modified:
   gnunet/src/statistics/gnunet-service-statistics.c
   gnunet/src/statistics/test_statistics_api_data.conf
Log:
fixing bad memcpy

Modified: gnunet/src/statistics/gnunet-service-statistics.c
===================================================================
--- gnunet/src/statistics/gnunet-service-statistics.c   2010-07-21 20:48:40 UTC 
(rev 12327)
+++ gnunet/src/statistics/gnunet-service-statistics.c   2010-07-21 21:22:35 UTC 
(rev 12328)
@@ -155,6 +155,17 @@
 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 @@
   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 @@
   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 @@
   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 @@
       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;
     }

Modified: gnunet/src/statistics/test_statistics_api_data.conf
===================================================================
--- gnunet/src/statistics/test_statistics_api_data.conf 2010-07-21 20:48:40 UTC 
(rev 12327)
+++ gnunet/src/statistics/test_statistics_api_data.conf 2010-07-21 21:22:35 UTC 
(rev 12328)
@@ -5,7 +5,7 @@
 [statistics]
 PORT = 22353
 UNIXPATH = /tmp/test-statistics-service-statistics.unix
-DEBUG = YES
+DEBUG = NO
 
 [arm]
 PORT = 22354




reply via email to

[Prev in Thread] Current Thread [Next in Thread]