[Olsr-dev] [PATCH v1 1/1] cookie: fix loop invariant assert and exit on cookie exhaustion

Ferry Huberts (spam-protected)
Sat Oct 17 22:38:48 CEST 2015


From: Ferry Huberts <(spam-protected)>

Signed-off-by: Ferry Huberts <(spam-protected)>
---
 src/olsr_cookie.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/olsr_cookie.c b/src/olsr_cookie.c
index dfd618a..b7b3e4d 100644
--- a/src/olsr_cookie.c
+++ b/src/olsr_cookie.c
@@ -67,7 +67,12 @@ olsr_alloc_cookie(const char *cookie_name, olsr_cookie_type cookie_type)
     }
   }
 
-  assert(ci_index < COOKIE_ID_MAX);     /* increase COOKIE_ID_MAX */
+  assert(ci_index <= COOKIE_ID_MAX);
+
+  if (ci_index == COOKIE_ID_MAX) {
+    olsr_exit("No more cookies available", 1);
+    return NULL;
+  }
 
   ci = calloc(1, sizeof(struct olsr_cookie_info));
   cookies[ci_index] = ci;
-- 
2.4.3




More information about the Olsr-dev mailing list