Fix HTTP lookup segfault when the redirect host cannot be resolved #356
+68
−86
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
When the host of the redirect URL cannot be resolved, segmentation fault will happen:
pulsar-client-cpp/lib/CurlWrapper.h
Lines 173 to 175 in 0bbc155
In this case,
curl
will benullptr
. Assigning a nullptr to astd::string
is an undefined behavior that might cause segfault.Modifications
Check if
url
is nullptr inCurlWrapper::get
and before assigning it to theredirectUrl
field. Improve theHTTPLookupService::sendHTTPRequest
method by configuring themaxLookupRedirects
instead of a loop and print more detailed error messages.Verifications
It's hard to mock a redirect case so I have to modify the
TopicLookupBase#internalLookupTopicAsync
in broker side and return a 307 response.When I return a
http://unknown:8080
as the redirect URL:Before this patch, it will crash.
When I just return a
http://localhost:8080
as the redirect URL:Before this patch, it will print similar logs 20 times.