]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Add a fix for the buf_pullup bug that Vektor reported
authorNick Mathewson <nickm@torproject.org>
Wed, 14 Dec 2011 21:38:43 +0000 (16:38 -0500)
committerNick Mathewson <nickm@torproject.org>
Thu, 15 Dec 2011 16:28:24 +0000 (11:28 -0500)
changes/buffer_bug [new file with mode: 0644]
src/or/buffers.c

diff --git a/changes/buffer_bug b/changes/buffer_bug
new file mode 100644 (file)
index 0000000..634f609
--- /dev/null
@@ -0,0 +1,7 @@
+
+  o Major bugfixes:
+    - Fix a heap overflow bug that could occur when trying to pull
+      data into the first chunk of a buffer, when that chunk had
+      already had some data drained from it. Fixes CVE-2011-2778;
+      bugfix on 0.2.0.16-alpha. Reported by "Vektor".
+
index 710374638b99e0da011e78f58c8d2b08a75b47b3..570160490967188a7a71d108c97d739bd18c83d8 100644 (file)
@@ -375,9 +375,10 @@ buf_pullup(buf_t *buf, size_t bytes, int nulterminate)
 
   if (buf->head->memlen >= capacity) {
     /* We don't need to grow the first chunk, but we might need to repack it.*/
-    if (CHUNK_REMAINING_CAPACITY(buf->head) < capacity-buf->datalen)
+    size_t needed = capacity - buf->head->datalen;
+    if (CHUNK_REMAINING_CAPACITY(buf->head) < needed)
       chunk_repack(buf->head);
-    tor_assert(CHUNK_REMAINING_CAPACITY(buf->head) >= capacity-buf->datalen);
+    tor_assert(CHUNK_REMAINING_CAPACITY(buf->head) >= needed);
   } else {
     chunk_t *newhead;
     size_t newsize;