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

Conversation

chu11
Copy link
Member

@chu11 chu11 commented Aug 23, 2024

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.

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.
Comment on lines +2281 to +2285
if (i->idx >= (i->hl->size - 1)) {
++i->idx;
i->hr = NULL;
return;
}
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.

Copy link
Member

@grondo grondo left a comment

Choose a reason for hiding this comment

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

LGTM!

@grondo grondo added the merge-when-passing Let mergify auto-rebase and merge when CI passes label Aug 23, 2024
@mergify mergify bot merged commit 2547fe7 into chaos:master Aug 23, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge-when-passing Let mergify auto-rebase and merge when CI passes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants