From 988ae82c17b9519e5bede4adcc2b81d8e3df76a0 Mon Sep 17 00:00:00 2001
From: Jan David Mol <mol@astron.nl>
Date: Sat, 27 Aug 2016 20:44:50 +0000
Subject: [PATCH] Task #9522: Fix possibility of overlapping allocation in
 SparseSetAllocator

---
 RTCP/Cobalt/CoInterface/src/Allocator.cc | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/RTCP/Cobalt/CoInterface/src/Allocator.cc b/RTCP/Cobalt/CoInterface/src/Allocator.cc
index ba185a4b90a..a6b80b9a1d7 100644
--- a/RTCP/Cobalt/CoInterface/src/Allocator.cc
+++ b/RTCP/Cobalt/CoInterface/src/Allocator.cc
@@ -124,6 +124,11 @@ namespace LOFAR
       for (SparseSet<void *>::const_iterator it = freeList.getRanges().begin(); it != freeList.getRanges().end(); it++) {
         void *begin = align(it->begin, alignment);
 
+        if ((char *) begin >= (char *) it->end ) {
+          // alignment shift already results in out of bounds
+          continue;
+        }
+
         if ((char *) it->end - (char *) begin >= (ptrdiff_t) size) {
           // enough space -- reserve it
           freeList.exclude(begin, (void *) ((char *) begin + size));
-- 
GitLab