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

consumer: fix panic in nextLookupdEndpoint #321

Merged
merged 1 commit into from
May 31, 2021

Conversation

martin-sucha
Copy link
Contributor

The code can panic if invalid lookupd address is provided:

panic: parse "http:// myhostname:4161": invalid character " " in host name

This is caused different validation of the input when configured
in ConnectToNSQLookupd and when used in nextLookupdEndpoint.

Moving preparation of the URL to the beginning so that we don't
need to do any input validation in nextLookupEndpoint.

Fixes #316

@martin-sucha
Copy link
Contributor Author

Note that I have not tested the code yet as I don't have a nsq instance on the machine I'm currently on.

@mreiferson
Copy link
Member

I'm confused, it looks like validatedLookupAddr already returned an error from url.Parse, perhaps in your test case you're not checking the return value from ConnectToNSQLookupd?

@martin-sucha
Copy link
Contributor Author

If you use " myhostname:4161" as the input value then validatedLookupAddr does not call url.Parse at all because the string does not contain a slash.

@martin-sucha
Copy link
Contributor Author

I've updated the commit message so that it is clearer.

Copy link
Member

@mreiferson mreiferson left a comment

Choose a reason for hiding this comment

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

Thanks @martin-sucha, I think we can simplify this a bit so the diff isn't as noisy.

consumer.go Outdated
@@ -126,7 +126,7 @@ type Consumer struct {

// used at connection close to force a possible reconnect
lookupdRecheckChan chan int
lookupdHTTPAddrs []string
lookupdHTTPAddrs []lookupdHTTPAddr
Copy link
Member

Choose a reason for hiding this comment

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

I don't see any benefit of introducing a type here, let's keep this a string and then a few of the other changes here won't be necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I removed the type.

If you use " myhostname:4161" as NSQd HTTP address
then the code panics in nextLookupdEndpoint:

    panic: parse "http:// myhostname:4161": invalid character " " in host name

This is caused different validation of the input when configured
in ConnectToNSQLookupd and when used in nextLookupdEndpoint.

Moving preparation of the URL to the beginning so that we don't
need to do any input validation in nextLookupdEndpoint.

Fixes nsqio#316
@mreiferson mreiferson merged commit 2a2babe into nsqio:master May 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

panic in Consumer.nextLookupdEndpoint
2 participants