]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
2850. [bug] If isc_heap_insert() failed due to memory shortage
authorTatuya JINMEI 神明達哉 <jinmei@isc.org>
Thu, 4 Feb 2010 23:22:05 +0000 (23:22 +0000)
committerTatuya JINMEI 神明達哉 <jinmei@isc.org>
Thu, 4 Feb 2010 23:22:05 +0000 (23:22 +0000)
the heap would have corrupted entries.

9.8.0, 9.7.1(?), 9.6.2, 9.5.3
(what about 9.4-ESV?)

CHANGES
lib/isc/heap.c

diff --git a/CHANGES b/CHANGES
index 3546ab6b906ad29676d2e26db38aeb35e9474b8c..e6e19d106c6f854c19e8926365c6f1eae9882676 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,6 @@
+2850.  [bug]           If isc_heap_insert() failed due to memory shortage
+                       the heap would have corrupted entries.
+
 2849.  [bug]           Don't treat errors from the xml2 library as fatal.
                        [RT #20945]
 
index 91d78c06d468bcdb6b0a466e2631717dafbe79bd..7f50eac52430734293f492254a28be89c3a900de 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: heap.c,v 1.37 2007/10/19 17:15:53 explorer Exp $ */
+/* $Id: heap.c,v 1.38 2010/02/04 23:22:05 jinmei Exp $ */
 
 /*! \file
  * Heap implementation of priority queues adapted from the following:
@@ -186,15 +186,17 @@ sink_down(isc_heap_t *heap, unsigned int i, void *elt) {
 
 isc_result_t
 isc_heap_insert(isc_heap_t *heap, void *elt) {
-       unsigned int i;
+       unsigned int new_last;
 
        REQUIRE(VALID_HEAP(heap));
 
-       i = ++heap->last;
-       if (heap->last >= heap->size && !resize(heap))
+       new_last = heap->last + 1;
+       RUNTIME_CHECK(new_last > 0); /* overflow check */
+       if (new_last >= heap->size && !resize(heap))
                return (ISC_R_NOMEMORY);
+       heap->last = new_last;
 
-       float_up(heap, i, elt);
+       float_up(heap, new_last, elt);
 
        return (ISC_R_SUCCESS);
 }