gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet] branch master updated: also BADFOOD on realloc


From: gnunet
Subject: [gnunet] branch master updated: also BADFOOD on realloc
Date: Wed, 25 Dec 2019 17:05:11 +0100

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new 1a4bd09e6 also BADFOOD on realloc
1a4bd09e6 is described below

commit 1a4bd09e63df2300845fcb9bfa150f28943b9aea
Author: Christian Grothoff <address@hidden>
AuthorDate: Wed Dec 25 17:00:16 2019 +0100

    also BADFOOD on realloc
---
 contrib/build-common         |  2 +-
 src/util/.gitignore          |  1 +
 src/util/common_allocation.c | 27 +++++++++++++++++++++++++--
 src/util/perf_malloc.c       | 39 +++++++++++++++++++++++++++++++++++----
 4 files changed, 62 insertions(+), 7 deletions(-)

diff --git a/contrib/build-common b/contrib/build-common
index 1915a74bb..6ac60bd0b 160000
--- a/contrib/build-common
+++ b/contrib/build-common
@@ -1 +1 @@
-Subproject commit 1915a74bbb4cd2ae9bc541a382dfebc37064a2fd
+Subproject commit 6ac60bd0b1f96324b4175fa03aaf9780ed8efb47
diff --git a/src/util/.gitignore b/src/util/.gitignore
index dfa6c7947..01ebcc834 100644
--- a/src/util/.gitignore
+++ b/src/util/.gitignore
@@ -74,3 +74,4 @@ test_regex
 test_tun
 gnunet-timeout
 python27_location
+perf_malloc
diff --git a/src/util/common_allocation.c b/src/util/common_allocation.c
index 137af7b85..35c557000 100644
--- a/src/util/common_allocation.c
+++ b/src/util/common_allocation.c
@@ -264,6 +264,30 @@ GNUNET_xrealloc_ (void *ptr, size_t n, const char 
*filename, int linenumber)
   n += sizeof(size_t);
   ptr = &((size_t *) ptr)[-1];
   mem_used = mem_used - *((size_t *) ptr) + n;
+#endif
+#if defined(M_SIZE)
+#if ENABLE_POISONING
+  {
+    uint64_t *base = ptr;
+    size_t s = M_SIZE (ptr);
+
+    if (s > n)
+    {
+      const uint64_t baadfood = GNUNET_ntohll (0xBAADF00DBAADF00DLL);
+      char *cbase = ptr;
+
+      GNUNET_memcpy (&cbase[n],
+                     &baadfood,
+                     GNUNET_MIN (8 - (n % 8),
+                                 s - n));
+      for (size_t i = 1 + (n + 7) / 8; i < s / 8; i++)
+        base[i] = baadfood;
+      GNUNET_memcpy (&base[s / 8],
+                     &baadfood,
+                     s % 8);
+    }
+  }
+#endif
 #endif
   ptr = realloc (ptr, n);
   if ((NULL == ptr) && (n > 0))
@@ -316,9 +340,8 @@ GNUNET_xfree_ (void *ptr, const char *filename, int 
linenumber)
     const uint64_t baadfood = GNUNET_ntohll (0xBAADF00DBAADF00DLL);
     uint64_t *base = ptr;
     size_t s = M_SIZE (ptr);
-    size_t i;
 
-    for (i = 0; i < s / 8; i++)
+    for (size_t i = 0; i < s / 8; i++)
       base[i] = baadfood;
     GNUNET_memcpy (&base[s / 8], &baadfood, s % 8);
   }
diff --git a/src/util/perf_malloc.c b/src/util/perf_malloc.c
index 727e15979..6582505c8 100644
--- a/src/util/perf_malloc.c
+++ b/src/util/perf_malloc.c
@@ -28,13 +28,12 @@
 #include <gauger.h>
 
 static uint64_t
-perfMalloc ()
+perf_malloc ()
 {
-  size_t i;
   uint64_t ret;
 
   ret = 0;
-  for (i = 1; i < 1024 * 1024; i += 1024)
+  for (size_t i = 1; i < 1024 * 1024; i += 1024)
   {
     ret += i;
     GNUNET_free (GNUNET_malloc (i));
@@ -43,6 +42,32 @@ perfMalloc ()
 }
 
 
+static uint64_t
+perf_realloc ()
+{
+  uint64_t ret;
+
+  ret = 0;
+  for (size_t i = 10; i < 1024 * 1024 / 5; i += 1024)
+  {
+    char *ptr;
+
+    ret += i;
+    ptr = GNUNET_malloc (i);
+    memset (ptr, 1, i);
+    ptr = GNUNET_realloc (ptr, i + 5);
+    for (size_t j=0;j<i;j++)
+      GNUNET_assert (1 == ptr[j]);
+    memset (ptr, 6, i + 5);
+    ptr = GNUNET_realloc (ptr, i - 5);
+    for (size_t j=0;j<i-5;j++)
+      GNUNET_assert (6 == ptr[j]);
+    GNUNET_free (ptr);
+  }
+  return ret;
+}
+
+
 int
 main (int argc, char *argv[])
 {
@@ -50,7 +75,7 @@ main (int argc, char *argv[])
   uint64_t kb;
 
   start = GNUNET_TIME_absolute_get ();
-  kb = perfMalloc ();
+  kb = perf_malloc ();
   printf ("Malloc perf took %s\n",
           GNUNET_STRINGS_relative_time_to_string (
             GNUNET_TIME_absolute_get_duration (start),
@@ -59,6 +84,12 @@ main (int argc, char *argv[])
           kb / 1024 / (1
                        + GNUNET_TIME_absolute_get_duration
                          (start).rel_value_us / 1000LL), "kb/ms");
+  start = GNUNET_TIME_absolute_get ();
+  kb = perf_realloc ();
+  printf ("Realloc perf took %s\n",
+          GNUNET_STRINGS_relative_time_to_string (
+            GNUNET_TIME_absolute_get_duration (start),
+            GNUNET_YES));
   return 0;
 }
 

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

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