Skip to content

tools: prevent use of 'throw new'#10116

Merged
mattklein123 merged 3 commits intoenvoyproxy:masterfrom
derekargueta:dereka/throw-new
Feb 21, 2020
Merged

tools: prevent use of 'throw new'#10116
mattklein123 merged 3 commits intoenvoyproxy:masterfrom
derekargueta:dereka/throw-new

Conversation

@derekargueta
Copy link
Copy Markdown
Member

Description: throw new should be avoided, as the type being thrown is a pointer to the exception and not the exception itself. This can mess with catch statements. See https://stackoverflow.com/a/10964457 for more info.
Risk Level: low
Testing: added
Docs Changes: n/a
Release Notes: n/a

Signed-off-by: Derek Argueta darguetap@gmail.com

Signed-off-by: Derek Argueta <darguetap@gmail.com>
Signed-off-by: Derek Argueta <darguetap@gmail.com>
// don't allow an empty configuration
if (!response_set_ && !request_set_) {
throw new EnvoyException("Must at least specify either response or request config");
throw EnvoyException("Must at least specify either response or request config");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Love this! One of my fuzzers caught this but it's fixed in an open PR :) Anything to fix bugs with tools

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 this is great. Surprised that clang-tidy can't catch this. Is this ready for final review?

@mattklein123 mattklein123 self-assigned this Feb 20, 2020
@derekargueta derekargueta marked this pull request as ready for review February 20, 2020 23:23
@derekargueta
Copy link
Copy Markdown
Member Author

misc-throw-by-value-catch-by-reference actually looks like it should do the job

https://github.com/llvm/llvm-project/blob/master/clang-tools-extra/clang-tidy/misc/ThrowByValueCatchByReferenceCheck.cpp#L86

Should I remove the check_format.py change or leave a TODO?

@mattklein123
Copy link
Copy Markdown
Member

I would probably just remove the format check and add it when you fix clang-tidy, but up to you.

Signed-off-by: Derek Argueta <darguetap@gmail.com>
@derekargueta
Copy link
Copy Markdown
Member Author

@mattklein123 SGTM, removed format check

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!

@mattklein123 mattklein123 merged commit 0784a75 into envoyproxy:master Feb 21, 2020
@derekargueta derekargueta deleted the dereka/throw-new branch February 29, 2020 01:25
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