Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common/hostlist: fix out of bounds array access #158

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/common/hostlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Comment on lines +2281 to +2285
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was going to apply this fix to upstream hostlist, slightly modified for simplicity (avoid increment of i->idx in two places)

diff --git a/hostlist/hostlist.c b/hostlist/hostlist.c
index 4db24ba..6385cf9 100644
--- a/hostlist/hostlist.c
+++ b/hostlist/hostlist.c
@@ -2281,7 +2281,11 @@ static void _iterator_advance(hostlist_iterator_t i)
         return;
     if (++(i->depth) > (i->hr->hi - i->hr->lo)) {
         i->depth = 0;
-        i->hr = i->hl->hr[++i->idx];
+        if (++i->idx >= i->hl->size) {
+            i->hr = NULL;
+            return;
+        }
+        i->hr = i->hl->hr[i->idx];
     }
 }

LMK if that looks ok

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternately, we can merge this PR for historical value, then I'll propose a PR to update hostlist.[ch] to the latest.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks fine to me. Would you like to close this PR and submit your own PR to update hostlist? Then I can copy it down into powerman, genders, etc. etc.

i->hr = i->hl->hr[++i->idx];
}
}
Expand Down
Loading