summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2016-01-18 20:00:16 -0500
committerNick Mathewson <nickm@torproject.org>2016-01-18 20:00:16 -0500
commit8335b1f9a91076f100e7d3ba6b45f3ed9fc2986a (patch)
tree7f900953d8b741e2d2b8d7afcdc581fcefc36e6a /src/common
parent83dfcfbc4a295ca52325f47291d109cd0a16ac8f (diff)
parentdb8156533133836b19bca51f7fabba4d161b6ba2 (diff)
downloadtor-8335b1f9a91076f100e7d3ba6b45f3ed9fc2986a.tar.gz
tor-8335b1f9a91076f100e7d3ba6b45f3ed9fc2986a.zip
Merge branch 'maint-0.2.6' into maint-0.2.7
Diffstat (limited to 'src/common')
-rw-r--r--src/common/crypto.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c
index 815c2ec0c5..c50a303c1d 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -2556,6 +2556,7 @@ smartlist_shuffle(smartlist_t *sl)
/**
* Destroy the <b>sz</b> bytes of data stored at <b>mem</b>, setting them to
* the value <b>byte</b>.
+ * If <b>mem</b> is NULL or <b>sz</b> is zero, nothing happens.
*
* This function is preferable to memset, since many compilers will happily
* optimize out memset() when they can convince themselves that the data being
@@ -2573,6 +2574,13 @@ smartlist_shuffle(smartlist_t *sl)
void
memwipe(void *mem, uint8_t byte, size_t sz)
{
+ if (mem == NULL || sz == 0) {
+ return;
+ }
+
+ /* Data this large is likely to be an underflow. */
+ tor_assert(sz < SIZE_T_CEILING);
+
/* Because whole-program-optimization exists, we may not be able to just
* have this function call "memset". A smart compiler could inline it, then
* eliminate dead memsets, and declare itself to be clever. */