aboutsummaryrefslogtreecommitdiff
path: root/src/common/util.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2013-01-26 18:01:06 -0500
committerNick Mathewson <nickm@torproject.org>2013-01-26 18:01:06 -0500
commitacd72d4e3e47c2d81d9f3586d227069b9c87094e (patch)
tree67671109ff5e30cb0f539ab28ae6e9e5e07cc7f4 /src/common/util.c
parentdfbd19df418347d833df650e68367c96a3aa37ad (diff)
downloadtor-acd72d4e3e47c2d81d9f3586d227069b9c87094e.tar
tor-acd72d4e3e47c2d81d9f3586d227069b9c87094e.tar.gz
Correctly copy microdescs/extrinfos with internal NUL bytes
Fixes bug 8037; bugfix on 0.2.0.1-alpha; reported by cypherpunks.
Diffstat (limited to 'src/common/util.c')
-rw-r--r--src/common/util.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/common/util.c b/src/common/util.c
index 49ec75dc4..71b77e20f 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -282,6 +282,20 @@ tor_memdup_(const void *mem, size_t len DMALLOC_PARAMS)
return dup;
}
+/** As tor_memdup(), but add an extra 0 byte at the end of the resulting
+ * memory. */
+void *
+tor_memdup_nulterm(const void *mem, size_t len DMALLOC_PARAMS)
+{
+ char *dup;
+ tor_assert(len < SIZE_T_CEILING+1);
+ tor_assert(mem);
+ dup = tor_malloc_(len+1 DMALLOC_FN_ARGS);
+ memcpy(dup, mem, len);
+ dup[len] = '\0';
+ return dup;
+}
+
/** Helper for places that need to take a function pointer to the right
* spelling of "free()". */
void