Skip to content
New issue

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

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

Already on GitHub? # to your account

p2p: fix infinite loop in dnsaddr resolution #5926

Merged

Conversation

algorandskiy
Copy link
Contributor

Summary

dnsaddr.Iterate() is not tolerate to cycles. Added max attempts to prevent infinite looping.

Test Plan

Added a unit test.

@algorandskiy algorandskiy added Bug-Fix p2p Work related to the p2p project labels Feb 1, 2024
@algorandskiy algorandskiy self-assigned this Feb 1, 2024
mockController{},
func(dnsaddr multiaddr.Multiaddr, entries []multiaddr.Multiaddr) error { return nil },
)
return true
Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally this would check the error returned by Iterate

Copy link
Contributor Author

Choose a reason for hiding this comment

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

why? I want to check no infinite loops and not resolution errors

Copy link
Contributor

Choose a reason for hiding this comment

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

You made the decision to return an error when max hops are reached. In my view, it only makes sense to test that return value here, rather than ignoring it

Copy link

codecov bot commented Feb 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (a8e2254) 55.98% compared to head (8137156) 55.99%.

Additional details and impacted files
@@               Coverage Diff               @@
##           feature/p2p    #5926      +/-   ##
===============================================
+ Coverage        55.98%   55.99%   +0.01%     
===============================================
  Files              482      482              
  Lines            68057    68062       +5     
===============================================
+ Hits             38103    38114      +11     
+ Misses           27347    27343       -4     
+ Partials          2607     2605       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@jasonpaulos jasonpaulos left a comment

Choose a reason for hiding this comment

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

I left a test suggestion, but it's not serious enough to be a blocker

mockController{},
func(dnsaddr multiaddr.Multiaddr, entries []multiaddr.Multiaddr) error { return nil },
)
return true
Copy link
Contributor

Choose a reason for hiding this comment

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

You made the decision to return an error when max hops are reached. In my view, it only makes sense to test that return value here, rather than ignoring it

@@ -35,8 +35,14 @@ func Iterate(initial multiaddr.Multiaddr, controller ResolveController, f func(d
if resolver == nil {
return errors.New("passed controller has no resolvers Iterate")
}
const maxHops = 100
Copy link
Contributor

Choose a reason for hiding this comment

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

Why 100 - i.e. this feels more like 10 is sufficient..?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do not know what is actual max limit

@algorandskiy algorandskiy merged commit ba8b2cd into algorand:feature/p2p Feb 2, 2024
16 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Bug-Fix p2p Work related to the p2p project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants