Skip to content

network: throw EnvoyException on address parse error#968

Merged
mattklein123 merged 4 commits intoenvoyproxy:masterfrom
hennna:parse-address-throw
May 16, 2017
Merged

network: throw EnvoyException on address parse error#968
mattklein123 merged 4 commits intoenvoyproxy:masterfrom
hennna:parse-address-throw

Conversation

@hennna
Copy link
Copy Markdown
Contributor

@hennna hennna commented May 15, 2017

Previously when an IP address could not be parsed, a nullptr was returned. However, this causes a segfault for config files with error(s) in the address field(s). This PR changes the address parsing logic to throw an exception instead.

This PR also moves IP address parsing functions from Network::Address to Network::Utility.

Fixes #952

@hennna
Copy link
Copy Markdown
Contributor Author

hennna commented May 15, 2017

@ccaraman for review.


Address::InstanceConstSharedPtr
Utility::parseInternetAddressAndPort(const std::string& ip_address) {
std::string error_msg(fmt::format("malformed IP address: {}", ip_address));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would be best to not create this string when most times we will not need it. One solution is to move to a private helper function called throwOnMalformedIp(...) or something like that.

Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thanks @hennna few small comments. LGTM. Will let @ccaraman take a pass also.

if (parts.size() == 2) {
InstanceConstSharedPtr ptr = parseInternetAddress(parts[0]);
InstanceConstSharedPtr ptr = Utility::parseInternetAddress(parts[0]);
if (ptr != nullptr && ptr->type() == Type::Ip) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

null check here is no longer needed

Address::InstanceConstSharedPtr
Utility::parseInternetAddressAndPort(const std::string& ip_address) {
if (ip_address.empty()) {
Utility::throwWithMalformedIp(ip_address);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: don't need to specify Utility:: on these calls since already inside the class and static.

Copy link
Copy Markdown
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

LGTM, some minor comments.

sa6.sin6_port = 0;
return std::make_shared<Address::Ipv6Instance>(sa6);
}
throw EnvoyException(fmt::format("malformed IP address: {}", ip_address));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

throwWithMalformedIp?


/*
* Parse an internet host address (IPv4 or IPv6) AND port, and create an Instance from it.
* Throw an exception if unable to parse the address.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You could also use an @throws Doxygen annotation, but this isn't common in the code base.

@mattklein123 mattklein123 merged commit 35c57d0 into envoyproxy:master May 16, 2017
@hennna hennna deleted the parse-address-throw branch May 23, 2017 20:45
rshriram pushed a commit to rshriram/envoy that referenced this pull request Oct 30, 2018
Automatic merge from submit-queue.

[DO NOT MERGE] Auto PR to update dependencies of proxy

This PR will be merged automatically once checks are successful.
```release-note
none
```
jpsim pushed a commit that referenced this pull request Nov 28, 2022
Signed-off-by: Mike Schore <mike.schore@gmail.com>
Signed-off-by: JP Simard <jp@jpsim.com>
jpsim pushed a commit that referenced this pull request Nov 29, 2022
Signed-off-by: Mike Schore <mike.schore@gmail.com>
Signed-off-by: JP Simard <jp@jpsim.com>
mathetake pushed a commit that referenced this pull request Mar 3, 2026
**Description**
Simplify netlify CSP settings to use wildcards to ensure we do not have
bugs for trusted domains.

**Related Issues/PRs (if applicable)**

n/a

**Special notes for reviewers (if applicable)**

n/a

---------

Signed-off-by: Erica Hughberg <erica.sundberg.90@gmail.com>
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.

3 participants