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

Check length of BaseResolvers to prevent division by zero #123

Merged
merged 2 commits into from May 3, 2023
Merged

Check length of BaseResolvers to prevent division by zero #123

merged 2 commits into from May 3, 2023

Conversation

sausagenoods
Copy link
Contributor

@sausagenoods sausagenoods commented May 3, 2023

I noticed that when nuclei is supplied with an empty resolver list file (-r option), it panics:

panic: runtime error: integer divide by zero

goroutine 112869 [running]:
github.com/projectdiscovery/retryabledns.(*Client).Do(0xc0038e2c80, 0x1?)
	/root/go/pkg/mod/github.com/projectdiscovery/retryabledns@v1.0.20/client.go:113 +0x2ee
github.com/projectdiscovery/nuclei/v2/pkg/protocols/dns.(*Request).ExecuteWithResults(0xc000040f00, 0xc0040c7f80, 0xc00406fc50, 0x7fcd0cf4bf18?, 0xc003932198)
	/root/go/pkg/mod/github.com/projectdiscovery/nuclei/v2@v2.8.9/pkg/protocols/dns/request.go:93 +0x79c
github.com/projectdiscovery/nuclei/v2/pkg/templates.(*ClusterExecuter).Execute(0xc004ec4a80, 0xc0040c7f00)
	/root/go/pkg/mod/github.com/projectdiscovery/nuclei/v2@v2.8.9/pkg/templates/cluster.go:245 +0x22d
github.com/projectdiscovery/nuclei/v2/pkg/core.(*Engine).executeTemplateWithTargets.func2.1(0x76c406?, 0x0?, 0xc0040c7d00)
	/root/go/pkg/mod/github.com/projectdiscovery/nuclei/v2@v2.8.9/pkg/core/executors.go:130 +0x296
created by github.com/projectdiscovery/nuclei/v2/pkg/core.(*Engine).executeTemplateWithTargets.func2
	/root/go/pkg/mod/github.com/projectdiscovery/nuclei/v2@v2.8.9/pkg/core/executors.go:107 +0x4f8

The panic is caused by this line: https://github.com/projectdiscovery/retryabledns/blob/main/client.go#L113
Modulo operator is ran with 0 when c.resolvers is empty.

I added a check for BaseResolvers' length to prevent it from panicking.

Related - projectdiscovery/nuclei#2515

@ehsandeep ehsandeep requested a review from Mzack9999 May 3, 2023 14:21
@Mzack9999 Mzack9999 merged commit b0816c6 into projectdiscovery:main May 3, 2023
5 checks passed
@Mzack9999
Copy link
Member

Nice catch - Thanks for the PR @sausagenoods !

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.

panic: runtime error: integer divide by zero
2 participants