Skip to content

Fix out-of-bounds dereference in block_delayed::flatten_iterator - #101

Open
colin-mcd wants to merge 1 commit into
cmuparlay:masterfrom
colin-mcd:fix-flatten-iterator-oob
Open

colin-mcd wants to merge 1 commit into
cmuparlay:masterfrom
colin-mcd:fix-flatten-iterator-oob

Conversation

@colin-mcd

Copy link
Copy Markdown

flatten_iterator::operator++ increments to the next non-empty inner range and unconditionally dereferences the outer iterator to do so (even when the outer iterator is past its end). Correctness-wise, this never uses the result of the dereference, so it is usually fine. However, this actually causes a segfault when the dereferenced memory address is not mapped, which I found occurs in PBBS backForwardBFS.

The fix is to give flatten_iterator the end of its outer range and stop there. Both construction sites (flatten, and block_delayed_sequence's whole-sequence iterator) have that end available. After the last element the iterator now stops at the outer end, which the enclosing forward_delayed_sequence never dereferences because its count has reached zero.

flatten_iterator::operator++ increments to the next non-empty inner
range and unconditionally dereferences the outer iterator to do so
(even when the outer iterator is past its end). Correctness-wise,
this never uses the result of the dereference, so it is usually fine.
However, this actually causes a segfault when the dereferenced memory
address is not mapped, which I found occurs in PBBS backForwardBFS.

The fix is to give flatten_iterator the end of its outer range and stop there.
Both construction sites (flatten, and block_delayed_sequence's whole-sequence
iterator) have that end available, and flatten_iterator is used nowhere else.
After the last element the iterator now parks at the outer end, which the enclosing
forward_delayed_sequence never dereferences because its count has reached zero.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant