Code

patches: Added CVE-2010-4336.dpatch: Fix DoS in RRD file creation.
[pkg-collectd.git] / debian / patches / bts596128-reheap-fix.dpatch
1 #! /bin/sh /usr/share/dpatch/dpatch-run
2 ## bts596128-reheap-fix.dpatch by Florian Forster <octo@verplant.org>
3 ##
4 ## DP: src/utils_heap.c: Fix calculation of the parent's index.
5 ## DP:
6 ## DP: This resulted in the "upwards" reheap function to return prematurely,
7 ## DP: leaving the heap condition violated.
9 @DPATCH@
11 diff a/src/utils_heap.c b/src/utils_heap.c
12 --- a/src/utils_heap.c
13 +++ b/src/utils_heap.c
14 @@ -96,7 +96,7 @@ static void reheap (c_heap_t *h, size_t root, enum reheap_direction dir)
15      return;
16  
17    if (dir == DIR_UP)
18 -    reheap (h, root / 2, dir);
19 +    reheap (h, (root - 1) / 2, dir);
20    else if (dir == DIR_DOWN)
21      reheap (h, min, dir);
22  } /* void reheap */
23 @@ -140,6 +140,8 @@ void c_heap_destroy (c_heap_t *h)
24  
25  int c_heap_insert (c_heap_t *h, void *ptr)
26  {
27 +  size_t index;
28 +
29    if ((h == NULL) || (ptr == NULL))
30      return (-EINVAL);
31  
32 @@ -162,11 +164,12 @@ int c_heap_insert (c_heap_t *h, void *ptr)
33    }
34  
35    /* Insert the new node as a leaf. */
36 -  h->list[h->list_len] = ptr;
37 +  index = h->list_len;
38 +  h->list[index] = ptr;
39    h->list_len++;
40  
41    /* Reorganize the heap from bottom up. */
42 -  reheap (h, /* parent of this node = */ (h->list_len - 1) / 2, DIR_UP);
43 +  reheap (h, /* parent of this node = */ (index - 1) / 2, DIR_UP);
44    
45    pthread_mutex_unlock (&h->lock);
46    return (0);