From e1b238458feb5ca7fabfa8f1a06bde8e6d1d0294 Mon Sep 17 00:00:00 2001 From: Makarand Dharmapurikar Date: Tue, 11 Apr 2017 16:18:40 -0700 Subject: [PATCH 1/5] modified caching test added logic to test that cached response is specific to request payload. Removed trailing '\0' from query parameter --- src/core/lib/channel/http_client_filter.c | 4 +--- test/cpp/interop/interop_client.cc | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/core/lib/channel/http_client_filter.c b/src/core/lib/channel/http_client_filter.c index 4e47c5c658f..917a769f8a6 100644 --- a/src/core/lib/channel/http_client_filter.c +++ b/src/core/lib/channel/http_client_filter.c @@ -332,10 +332,8 @@ static grpc_error *hc_mutate_op(grpc_exec_ctx *exec_ctx, */ char *t = (char *)GRPC_SLICE_START_PTR(path_with_query_slice); /* safe to use strlen since base64_encode will always add '\0' */ - size_t path_length = strlen(t) + 1; - *(t + path_length) = '\0'; path_with_query_slice = - grpc_slice_sub(path_with_query_slice, 0, path_length); + grpc_slice_sub(path_with_query_slice, 0, strlen(t)); /* substitute previous path with the new path+query */ grpc_mdelem mdelem_path_and_query = grpc_mdelem_from_slices( diff --git a/test/cpp/interop/interop_client.cc b/test/cpp/interop/interop_client.cc index 55ba324cc7d..0e79c5e4b44 100644 --- a/test/cpp/interop/interop_client.cc +++ b/test/cpp/interop/interop_client.cc @@ -918,6 +918,26 @@ bool InteropClient::DoCacheableUnary() { // second response is a cached copy of the first response GPR_ASSERT(response2.payload().body() == response1.payload().body()); + // Request 3 + // Modify the request body so it will not get a cache hit + ts = gpr_now(GPR_CLOCK_PRECISE); + timestamp = std::to_string((long long unsigned)ts.tv_nsec); + SimpleRequest request1; + request1.mutable_payload()->set_body(timestamp.c_str(), timestamp.size()); + ClientContext context3; + SimpleResponse response3; + context3.set_cacheable(true); + context3.AddMetadata("x-user-ip", "1.2.3.4"); + Status s3 = + serviceStub_.Get()->CacheableUnaryCall(&context3, request1, &response3); + if (!AssertStatusOk(s3)) { + return false; + } + gpr_log(GPR_DEBUG, "response 3 payload: %s", + response3.payload().body().c_str()); + + // Check that the response is different from the previous response. + GPR_ASSERT(response3.payload().body() != response1.payload().body()); return true; } From 220bc643f9b4bd8c87f080fd618c9460e55566be Mon Sep 17 00:00:00 2001 From: Makarand Dharmapurikar Date: Tue, 11 Apr 2017 16:24:17 -0700 Subject: [PATCH 2/5] enable cacheable_unary test --- test/cpp/interop/client.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/cpp/interop/client.cc b/test/cpp/interop/client.cc index 369413e6a1d..ea27f2827de 100644 --- a/test/cpp/interop/client.cc +++ b/test/cpp/interop/client.cc @@ -163,8 +163,8 @@ int main(int argc, char** argv) { std::bind(&grpc::testing::InteropClient::DoUnimplementedMethod, &client); actions["unimplemented_service"] = std::bind(&grpc::testing::InteropClient::DoUnimplementedService, &client); - // actions["cacheable_unary"] = - // std::bind(&grpc::testing::InteropClient::DoCacheableUnary, &client); + actions["cacheable_unary"] = + std::bind(&grpc::testing::InteropClient::DoCacheableUnary, &client); UpdateActions(&actions); From dd1ec7f9cdf7598ed874bfe942ad837686a03ac7 Mon Sep 17 00:00:00 2001 From: Makarand Dharmapurikar Date: Wed, 12 Apr 2017 13:52:18 -0700 Subject: [PATCH 3/5] fixed asan buffer overflow --- src/core/lib/channel/http_server_filter.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/lib/channel/http_server_filter.c b/src/core/lib/channel/http_server_filter.c index c1e49ffacc8..45dcc26f9a3 100644 --- a/src/core/lib/channel/http_server_filter.c +++ b/src/core/lib/channel/http_server_filter.c @@ -228,6 +228,8 @@ static grpc_error *server_filter_incoming_metadata(grpc_exec_ctx *exec_ctx, if (offset < path_length) { grpc_slice query_slice = grpc_slice_sub(path_slice, offset + 1, path_length); + /* add a trailing '\0' before decoding */ + const char *b64_data = grpc_slice_to_c_string(query_slice); /* substitute path metadata with just the path (not query) */ grpc_mdelem mdelem_path_without_query = grpc_mdelem_from_slices( @@ -238,14 +240,12 @@ static grpc_error *server_filter_incoming_metadata(grpc_exec_ctx *exec_ctx, /* decode payload from query and add to the slice buffer to be returned */ const int k_url_safe = 1; - grpc_slice_buffer_add( - &calld->read_slice_buffer, - grpc_base64_decode(exec_ctx, - (const char *)GRPC_SLICE_START_PTR(query_slice), - k_url_safe)); + grpc_slice_buffer_add(&calld->read_slice_buffer, + grpc_base64_decode(exec_ctx, b64_data, k_url_safe)); grpc_slice_buffer_stream_init(&calld->read_stream, &calld->read_slice_buffer, 0); calld->seen_path_with_query = true; + gpr_free((void *)b64_data); grpc_slice_unref_internal(exec_ctx, query_slice); } else { gpr_log(GPR_ERROR, "GET request without QUERY"); From 7fb4036a172f23f6d2bf6b451c1052f9495c880d Mon Sep 17 00:00:00 2001 From: Makarand Dharmapurikar Date: Thu, 13 Apr 2017 09:07:47 -0700 Subject: [PATCH 4/5] clang-format fix --- test/cpp/interop/client.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cpp/interop/client.cc b/test/cpp/interop/client.cc index ea27f2827de..6f1d910304c 100644 --- a/test/cpp/interop/client.cc +++ b/test/cpp/interop/client.cc @@ -164,7 +164,7 @@ int main(int argc, char** argv) { actions["unimplemented_service"] = std::bind(&grpc::testing::InteropClient::DoUnimplementedService, &client); actions["cacheable_unary"] = - std::bind(&grpc::testing::InteropClient::DoCacheableUnary, &client); + std::bind(&grpc::testing::InteropClient::DoCacheableUnary, &client); UpdateActions(&actions); From 63ed60f0483523522067d098abb6044ab6b99e27 Mon Sep 17 00:00:00 2001 From: Makarand Dharmapurikar Date: Thu, 13 Apr 2017 12:45:18 -0700 Subject: [PATCH 5/5] using grpc_base64_decode_with_len to simplify code --- src/core/lib/channel/http_server_filter.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/lib/channel/http_server_filter.c b/src/core/lib/channel/http_server_filter.c index 45dcc26f9a3..ebcde5315fe 100644 --- a/src/core/lib/channel/http_server_filter.c +++ b/src/core/lib/channel/http_server_filter.c @@ -228,8 +228,6 @@ static grpc_error *server_filter_incoming_metadata(grpc_exec_ctx *exec_ctx, if (offset < path_length) { grpc_slice query_slice = grpc_slice_sub(path_slice, offset + 1, path_length); - /* add a trailing '\0' before decoding */ - const char *b64_data = grpc_slice_to_c_string(query_slice); /* substitute path metadata with just the path (not query) */ grpc_mdelem mdelem_path_without_query = grpc_mdelem_from_slices( @@ -240,12 +238,14 @@ static grpc_error *server_filter_incoming_metadata(grpc_exec_ctx *exec_ctx, /* decode payload from query and add to the slice buffer to be returned */ const int k_url_safe = 1; - grpc_slice_buffer_add(&calld->read_slice_buffer, - grpc_base64_decode(exec_ctx, b64_data, k_url_safe)); + grpc_slice_buffer_add( + &calld->read_slice_buffer, + grpc_base64_decode_with_len( + exec_ctx, (const char *)GRPC_SLICE_START_PTR(query_slice), + GRPC_SLICE_LENGTH(query_slice), k_url_safe)); grpc_slice_buffer_stream_init(&calld->read_stream, &calld->read_slice_buffer, 0); calld->seen_path_with_query = true; - gpr_free((void *)b64_data); grpc_slice_unref_internal(exec_ctx, query_slice); } else { gpr_log(GPR_ERROR, "GET request without QUERY");