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

Fixes stack overflow in http inspector test #12577

Merged
merged 10 commits into from
Aug 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions test/extensions/filters/listener/http_inspector/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ envoy_extension_cc_test(
name = "http_inspector_test",
srcs = ["http_inspector_test.cc"],
extension_name = "envoy.filters.listener.http_inspector",
#TODO(davinci26): The test passes on Windows *but* http inspector
# *used* to rely on Event::FileTriggerType::Edge and we got away with it
# because we mock the dispatcher. Need to verify that the scenario is
# actually working.
tags = ["fails_on_windows"],
deps = [
"//source/common/common:hex_lib",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,9 @@ TEST_F(HttpInspectorTest, MultipleReadsHttp1BadProtocol) {
}

TEST_F(HttpInspectorTest, Http1WithLargeRequestLine) {
// Verify that the http inspector can detect http requests
// with large request line even when they are split over
// multiple recv calls.
init();
absl::string_view method = "GET", http = "/index HTTP/1.0\r";
std::string spaces(Config::MAX_INSPECT_SIZE - method.size() - http.size(), ' ');
Expand All @@ -584,19 +587,21 @@ TEST_F(HttpInspectorTest, Http1WithLargeRequestLine) {
num_loops = 2;
#endif

for (size_t i = 1; i <= num_loops; i++) {
size_t len = i;
if (num_loops == 2) {
len = size_t(Config::MAX_INSPECT_SIZE / (3 - i));
}
EXPECT_CALL(os_sys_calls_, recv(42, _, _, MSG_PEEK))
.WillOnce(Invoke(
[&data, len](os_fd_t, void* buffer, size_t length, int) -> Api::SysCallSizeResult {
ASSERT(length >= len);
memcpy(buffer, data.data(), len);
return Api::SysCallSizeResult{ssize_t(len), 0};
}));
}
auto ctr = std::make_shared<size_t>(1);
EXPECT_CALL(os_sys_calls_, recv(42, _, _, MSG_PEEK))
.Times(num_loops)
.WillRepeatedly(Invoke([&data, ctr, num_loops](os_fd_t, void* buffer, size_t length,
int) -> Api::SysCallSizeResult {
size_t len = (*ctr);
if (num_loops == 2) {
Copy link
Contributor

Choose a reason for hiding this comment

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

some comments here about what this is trying to accomplish would be good. It looks like maybe you are splitting up the buffer into a few chunks to mock streaming out some content?

Copy link
Member Author

Choose a reason for hiding this comment

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

My understanding is that this test validates that in the case of a really large http request which is split over multiple reads the http listener is correctly parsing it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a comment in d540ffd let me know if you want me to elaborate more

ASSERT(*ctr != 3);
len = size_t(Config::MAX_INSPECT_SIZE / (3 - (*ctr)));
davinci26 marked this conversation as resolved.
Show resolved Hide resolved
}
ASSERT(length >= len);
memcpy(buffer, data.data(), len);
*ctr += 1;
return Api::SysCallSizeResult{ssize_t(len), 0};
}));
}

bool got_continue = false;
Expand Down