From d59b352548bdac76d147d36e493035c0c47338c3 Mon Sep 17 00:00:00 2001 From: Albert Chu Date: Fri, 23 Aug 2024 12:00:49 -0700 Subject: [PATCH] common/hostlist: fix out of bounds array access Problem: Internally within the hostlist data structure, an array of hostranges is kept. An out of bounds array access can occur if the number of hostranges is equal to the length of the array. Add check to ensure out of bound array access is not allowed when iterating hosts. --- src/common/hostlist.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/common/hostlist.c b/src/common/hostlist.c index 2ab4c04..2bae0b1 100644 --- a/src/common/hostlist.c +++ b/src/common/hostlist.c @@ -2278,6 +2278,11 @@ static void _iterator_advance(hostlist_iterator_t i) return; if (++(i->depth) > (i->hr->hi - i->hr->lo)) { i->depth = 0; + if (i->idx >= (i->hl->size - 1)) { + ++i->idx; + i->hr = NULL; + return; + } i->hr = i->hl->hr[++i->idx]; } }