]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Clear memory in smartlist_remove_keeporder.
authorTobias Stoeckmann <tobias@stoeckmann.org>
Sat, 13 Apr 2019 14:55:36 +0000 (16:55 +0200)
committerNick Mathewson <nickm@torproject.org>
Mon, 15 Apr 2019 18:51:36 +0000 (14:51 -0400)
The smartlist functions take great care to reset unused pointers inside
the smartlist memory to NULL.

The function smartlist_remove_keeporder does not clear memory in such
way when elements have been removed. Therefore call memset after the
for-loop that removes elements. If no element is removed, it is
effectively a no-op.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
changes/ticket30176 [new file with mode: 0644]
src/lib/smartlist_core/smartlist_core.c

diff --git a/changes/ticket30176 b/changes/ticket30176
new file mode 100644 (file)
index 0000000..da23760
--- /dev/null
@@ -0,0 +1,4 @@
+  o Minor features (defense in depth):
+    - In smartlist_remove_keeporder(), set any pointers that become
+      unused to NULL, in case a bug causes them to be used later. Closes
+      ticket 30176.  Patch from Tobias Stoeckmann.
index 5947e7627109e0d9b1d554b0cb5ac5228473501a..6b0a305a932b788d0735219975d1c0bbf4ae30c7 100644 (file)
@@ -177,6 +177,8 @@ smartlist_remove_keeporder(smartlist_t *sl, const void *element)
       sl->list[i++] = sl->list[j];
     }
   }
+  memset(sl->list + sl->num_used, 0,
+         sizeof(void *) * (num_used_orig - sl->num_used));
 }
 
 /** If <b>sl</b> is nonempty, remove and return the final element.  Otherwise,