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

Possible invalid iterator #705

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lucassdiass
Copy link
Contributor

nodes pop_back could execute more than one time.
In this case, the iterator will be invalid in the comparison with nodes.end, so iterator must be adjusted.

If the change is invalid or doesn't make sense, while loop could be replaced by an if condition

nodes pop_back could execute more than one time.
In this case, iterator will be invalid in the comparison
with nodes.end, so iterator must be adjusted.

Signed-off-by: Lucas Dias <[email protected]>
@aberaud
Copy link
Member

aberaud commented May 30, 2024

Thanks for the PR for this delicate part of code. Please check my comment.

@lucassdiass
Copy link
Contributor Author

You're welcome. Sorry, I don't understand, what's the comment for me to check?

@lucassdiass
Copy link
Contributor Author

I have a question. Do you think changing the removeExpiredNode() call before line 847 makes sense? This call will remove expired nodes and free space for a new one.

@@ -861,6 +861,9 @@ Dht::Search::insertNode(const Sp<Node>& snode, time_point now, const Blob& token
nodes.pop_back();
if (removingNode)
return false;
// For some reason if removindNode was false, iterator could be
// invalid.
n = nodes.end();
Copy link
Member

Choose a reason for hiding this comment

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

With the current logic, n must always be the inserted node. If snode is inserted at the beginning of the list and the list if trimmed, n would be set to an invalid node.

@aberaud
Copy link
Member

aberaud commented May 31, 2024

You're welcome. Sorry, I don't understand, what's the comment for me to check?

Yeah sorry i forgot to submit the review

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.

2 participants