]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Make memwipe() do nothing when passed a NULL pointer or zero size
authorteor (Tim Wilson-Brown) <teor2345@gmail.com>
Tue, 19 Jan 2016 00:22:58 +0000 (11:22 +1100)
committerNick Mathewson <nickm@torproject.org>
Tue, 7 Feb 2017 13:33:39 +0000 (08:33 -0500)
Check size argument to memwipe() for underflow.

Closes bug #18089. Reported by "gk", patch by "teor".
Bugfix on 0.2.3.25 and 0.2.4.6-alpha (#7352),
commit 49dd5ef3 on 7 Nov 2012.

changes/bug18089 [new file with mode: 0644]
src/common/crypto.c

diff --git a/changes/bug18089 b/changes/bug18089
new file mode 100644 (file)
index 0000000..c1fb342
--- /dev/null
@@ -0,0 +1,6 @@
+  o Minor fixes (security):
+    - Make memwipe() do nothing when passed a NULL pointer
+      or zero size. Check size argument to memwipe() for underflow.
+      Closes bug #18089. Reported by "gk", patch by "teor".
+      Bugfix on 0.2.3.25 and 0.2.4.6-alpha (#7352),
+      commit 49dd5ef3 on 7 Nov 2012.
index 925beb3529b21ecc36e6e3180862bbaeb6c44956..f91391780ab5b6b20fe6ae9778c17626049360d4 100644 (file)
@@ -2972,6 +2972,7 @@ secret_to_key(char *key_out, size_t key_out_len, const char *secret,
 /**
  * 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
@@ -2989,6 +2990,13 @@ secret_to_key(char *key_out, size_t key_out_len, const char *secret,
 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. */