From 9ef0e1cfd4116b901f55410cad1c4425e59eaac1 Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Thu, 14 Apr 2016 12:44:30 -0700 Subject: Added grpc_call_stats to the call stack --- src/core/lib/channel/channel_stack.c | 3 ++- src/core/lib/channel/channel_stack.h | 13 ++++++++++++- src/core/lib/channel/compress_filter.c | 4 ++-- src/core/lib/channel/connected_channel.c | 4 ++-- src/core/lib/channel/http_client_filter.c | 4 ++-- src/core/lib/channel/http_server_filter.c | 4 ++-- 6 files changed, 22 insertions(+), 10 deletions(-) (limited to 'src/core/lib/channel') diff --git a/src/core/lib/channel/channel_stack.c b/src/core/lib/channel/channel_stack.c index e36066d863..cc8d413d1d 100644 --- a/src/core/lib/channel/channel_stack.c +++ b/src/core/lib/channel/channel_stack.c @@ -169,6 +169,7 @@ void grpc_call_stack_init(grpc_exec_ctx *exec_ctx, size_t i; call_stack->count = count; + memset(&call_stack->stats, 0, sizeof(grpc_call_stats)); GRPC_STREAM_REF_INIT(&call_stack->refcount, initial_refs, destroy, destroy_arg, "CALL_STACK"); call_elems = CALL_ELEMS_FROM_STACK(call_stack); @@ -220,7 +221,7 @@ void grpc_call_stack_destroy(grpc_exec_ctx *exec_ctx, grpc_call_stack *stack) { /* destroy per-filter data */ for (i = 0; i < count; i++) { - elems[i].filter->destroy_call_elem(exec_ctx, &elems[i]); + elems[i].filter->destroy_call_elem(exec_ctx, &elems[i], &stack->stats); } } diff --git a/src/core/lib/channel/channel_stack.h b/src/core/lib/channel/channel_stack.h index 9e3a25a152..3d9e72ef16 100644 --- a/src/core/lib/channel/channel_stack.h +++ b/src/core/lib/channel/channel_stack.h @@ -45,6 +45,8 @@ #include #include +#include + #include "src/core/lib/debug/trace.h" #include "src/core/lib/transport/transport.h" @@ -67,6 +69,13 @@ typedef struct { grpc_call_context_element *context; } grpc_call_element_args; +typedef struct { + uint64_t bytes_in; + uint64_t bytes_out; + gpr_timespec latency; /* TODO(dgq): per op? */ + grpc_status_code final_status; +} grpc_call_stats; + /* Channel filters specify: 1. the amount of memory needed in the channel & call (via the sizeof_XXX members) @@ -105,7 +114,8 @@ typedef struct { grpc_pollset *pollset); /* Destroy per call data. The filter does not need to do any chaining */ - void (*destroy_call_elem)(grpc_exec_ctx *exec_ctx, grpc_call_element *elem); + void (*destroy_call_elem)(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, + const grpc_call_stats *stats); /* sizeof(per channel data) */ size_t sizeof_channel_data; @@ -164,6 +174,7 @@ struct grpc_call_stack { about the address of the call stack itself. */ grpc_stream_refcount refcount; size_t count; + grpc_call_stats stats; }; /* Get a channel element given a channel stack and its index */ diff --git a/src/core/lib/channel/compress_filter.c b/src/core/lib/channel/compress_filter.c index 229fdb5ef6..31f1ac43fe 100644 --- a/src/core/lib/channel/compress_filter.c +++ b/src/core/lib/channel/compress_filter.c @@ -246,8 +246,8 @@ static void init_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, } /* Destructor for call_data */ -static void destroy_call_elem(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem) { +static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, + const grpc_call_stats *stats) { /* grab pointers to our data from the call element */ call_data *calld = elem->call_data; gpr_slice_buffer_destroy(&calld->slices); diff --git a/src/core/lib/channel/connected_channel.c b/src/core/lib/channel/connected_channel.c index c1debab4c6..eb699a63e4 100644 --- a/src/core/lib/channel/connected_channel.c +++ b/src/core/lib/channel/connected_channel.c @@ -102,8 +102,8 @@ static void set_pollset(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, } /* Destructor for call_data */ -static void destroy_call_elem(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem) { +static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, + const grpc_call_stats *stats) { call_data *calld = elem->call_data; channel_data *chand = elem->channel_data; grpc_transport_destroy_stream(exec_ctx, chand->transport, diff --git a/src/core/lib/channel/http_client_filter.c b/src/core/lib/channel/http_client_filter.c index 211f537c69..e1afaf5186 100644 --- a/src/core/lib/channel/http_client_filter.c +++ b/src/core/lib/channel/http_client_filter.c @@ -155,8 +155,8 @@ static void init_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, } /* Destructor for call_data */ -static void destroy_call_elem(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem) {} +static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, + const grpc_call_stats *stats) {} static grpc_mdelem *scheme_from_args(const grpc_channel_args *args) { unsigned i; diff --git a/src/core/lib/channel/http_server_filter.c b/src/core/lib/channel/http_server_filter.c index c140c61b8f..d4bac1493d 100644 --- a/src/core/lib/channel/http_server_filter.c +++ b/src/core/lib/channel/http_server_filter.c @@ -220,8 +220,8 @@ static void init_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, } /* Destructor for call_data */ -static void destroy_call_elem(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem) {} +static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, + const grpc_call_stats *stats) {} /* Constructor for channel_data */ static void init_channel_elem(grpc_exec_ctx *exec_ctx, -- cgit v1.2.3 From c9bb983c9c50be37bae9bf6a79bd9e70fbbe8b23 Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Thu, 14 Apr 2016 12:52:31 -0700 Subject: pr comments --- src/core/lib/channel/channel_stack.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/core/lib/channel') diff --git a/src/core/lib/channel/channel_stack.h b/src/core/lib/channel/channel_stack.h index 3d9e72ef16..f5f57fac0e 100644 --- a/src/core/lib/channel/channel_stack.h +++ b/src/core/lib/channel/channel_stack.h @@ -70,9 +70,8 @@ typedef struct { } grpc_call_element_args; typedef struct { - uint64_t bytes_in; - uint64_t bytes_out; - gpr_timespec latency; /* TODO(dgq): per op? */ + grpc_transport_stream_stats transport_stream_stats; + gpr_timespec latency; /* From call creating to enqueing of received status */ grpc_status_code final_status; } grpc_call_stats; -- cgit v1.2.3 From da0beaf408c037d2c17379aee6f04cd8c69664d6 Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Thu, 14 Apr 2016 14:37:06 -0700 Subject: Done right this time... --- src/core/ext/client_config/subchannel.c | 2 +- src/core/lib/channel/channel_stack.c | 6 +++--- src/core/lib/channel/channel_stack.h | 4 ++-- src/core/lib/surface/call.c | 8 ++++---- test/core/channel/channel_stack_test.c | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) (limited to 'src/core/lib/channel') diff --git a/src/core/ext/client_config/subchannel.c b/src/core/ext/client_config/subchannel.c index 125a291f21..0aa94ca8fb 100644 --- a/src/core/ext/client_config/subchannel.c +++ b/src/core/ext/client_config/subchannel.c @@ -651,7 +651,7 @@ static void subchannel_call_destroy(grpc_exec_ctx *exec_ctx, void *call, bool success) { grpc_subchannel_call *c = call; GPR_TIMER_BEGIN("grpc_subchannel_call_unref.destroy", 0); - grpc_call_stack_destroy(exec_ctx, SUBCHANNEL_CALL_TO_CALL_STACK(c)); + grpc_call_stack_destroy(exec_ctx, SUBCHANNEL_CALL_TO_CALL_STACK(c), NULL); GRPC_CONNECTED_SUBCHANNEL_UNREF(exec_ctx, c->connection, "subchannel_call"); gpr_free(c); GPR_TIMER_END("grpc_subchannel_call_unref.destroy", 0); diff --git a/src/core/lib/channel/channel_stack.c b/src/core/lib/channel/channel_stack.c index cc8d413d1d..5c1086a03f 100644 --- a/src/core/lib/channel/channel_stack.c +++ b/src/core/lib/channel/channel_stack.c @@ -169,7 +169,6 @@ void grpc_call_stack_init(grpc_exec_ctx *exec_ctx, size_t i; call_stack->count = count; - memset(&call_stack->stats, 0, sizeof(grpc_call_stats)); GRPC_STREAM_REF_INIT(&call_stack->refcount, initial_refs, destroy, destroy_arg, "CALL_STACK"); call_elems = CALL_ELEMS_FROM_STACK(call_stack); @@ -214,14 +213,15 @@ void grpc_call_stack_ignore_set_pollset(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, grpc_pollset *pollset) {} -void grpc_call_stack_destroy(grpc_exec_ctx *exec_ctx, grpc_call_stack *stack) { +void grpc_call_stack_destroy(grpc_exec_ctx *exec_ctx, grpc_call_stack *stack, + const grpc_call_stats *call_stats) { grpc_call_element *elems = CALL_ELEMS_FROM_STACK(stack); size_t count = stack->count; size_t i; /* destroy per-filter data */ for (i = 0; i < count; i++) { - elems[i].filter->destroy_call_elem(exec_ctx, &elems[i], &stack->stats); + elems[i].filter->destroy_call_elem(exec_ctx, &elems[i], call_stats); } } diff --git a/src/core/lib/channel/channel_stack.h b/src/core/lib/channel/channel_stack.h index f5f57fac0e..3c7c65ab3f 100644 --- a/src/core/lib/channel/channel_stack.h +++ b/src/core/lib/channel/channel_stack.h @@ -173,7 +173,6 @@ struct grpc_call_stack { about the address of the call stack itself. */ grpc_stream_refcount refcount; size_t count; - grpc_call_stats stats; }; /* Get a channel element given a channel stack and its index */ @@ -233,7 +232,8 @@ void grpc_call_stack_set_pollset(grpc_exec_ctx *exec_ctx, #endif /* Destroy a call stack */ -void grpc_call_stack_destroy(grpc_exec_ctx *exec_ctx, grpc_call_stack *stack); +void grpc_call_stack_destroy(grpc_exec_ctx *exec_ctx, grpc_call_stack *stack, + const grpc_call_stats *call_stats); /* Ignore set pollset - used by filters to implement the set_pollset method if they don't care about pollsets at all. Does nothing. */ diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c index 6581bbd3d1..a60f93f25e 100644 --- a/src/core/lib/surface/call.c +++ b/src/core/lib/surface/call.c @@ -175,7 +175,7 @@ struct grpc_call { received_status status[STATUS_SOURCE_COUNT]; /* Call stats: only valid after trailing metadata received */ - grpc_transport_stream_stats stats; + grpc_call_stats stats; /* Compression algorithm for the call */ grpc_compression_algorithm compression_algorithm; @@ -375,7 +375,7 @@ static void destroy_call(grpc_exec_ctx *exec_ctx, void *call, bool success) { if (c->receiving_stream != NULL) { grpc_byte_stream_destroy(exec_ctx, c->receiving_stream); } - grpc_call_stack_destroy(exec_ctx, CALL_STACK_FROM_CALL(c)); + grpc_call_stack_destroy(exec_ctx, CALL_STACK_FROM_CALL(c), &c->stats); GRPC_CHANNEL_INTERNAL_UNREF(exec_ctx, c->channel, "call"); gpr_mu_destroy(&c->mu); for (i = 0; i < STATUS_SOURCE_COUNT; i++) { @@ -1392,7 +1392,7 @@ static grpc_call_error call_start_batch(grpc_exec_ctx *exec_ctx, bctl->recv_final_op = 1; stream_op.recv_trailing_metadata = &call->metadata_batch[1 /* is_receiving */][1 /* is_trailing */]; - stream_op.collect_stats = &call->stats; + stream_op.collect_stats = &call->stats.transport_stream_stats; break; case GRPC_OP_RECV_CLOSE_ON_SERVER: /* Flag validation: currently allow no flags */ @@ -1414,7 +1414,7 @@ static grpc_call_error call_start_batch(grpc_exec_ctx *exec_ctx, bctl->recv_final_op = 1; stream_op.recv_trailing_metadata = &call->metadata_batch[1 /* is_receiving */][1 /* is_trailing */]; - stream_op.collect_stats = &call->stats; + stream_op.collect_stats = &call->stats.transport_stream_stats; break; } } diff --git a/test/core/channel/channel_stack_test.c b/test/core/channel/channel_stack_test.c index cce35ec58f..54f9fce14b 100644 --- a/test/core/channel/channel_stack_test.c +++ b/test/core/channel/channel_stack_test.c @@ -87,7 +87,7 @@ static void free_channel(grpc_exec_ctx *exec_ctx, void *arg, bool success) { } static void free_call(grpc_exec_ctx *exec_ctx, void *arg, bool success) { - grpc_call_stack_destroy(exec_ctx, arg); + grpc_call_stack_destroy(exec_ctx, arg, NULL); gpr_free(arg); } -- cgit v1.2.3 From e293b645d425c56fd9f7d59157c827c923dce17b Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Mon, 2 May 2016 10:29:51 -0700 Subject: clang-format --- src/core/lib/channel/channel_stack.h | 2 +- src/core/lib/channel/compress_filter.c | 3 +-- src/core/lib/channel/http_client_filter.c | 3 +-- src/core/lib/channel/http_server_filter.c | 3 +-- src/core/lib/security/client_auth_filter.c | 3 +-- src/core/lib/security/server_auth_filter.c | 3 +-- src/core/lib/surface/server.c | 3 +-- src/core/plugin_registry/grpc_plugin_registry.c | 9 +++------ src/core/plugin_registry/grpc_unsecure_plugin_registry.c | 9 +++------ 9 files changed, 13 insertions(+), 25 deletions(-) (limited to 'src/core/lib/channel') diff --git a/src/core/lib/channel/channel_stack.h b/src/core/lib/channel/channel_stack.h index ca75c6cb74..2040002269 100644 --- a/src/core/lib/channel/channel_stack.h +++ b/src/core/lib/channel/channel_stack.h @@ -117,7 +117,7 @@ typedef struct { \a and_free_memory that should be passed to gpr_free when destruction is complete. */ void (*destroy_call_elem)(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, - const grpc_call_stats *stats, + const grpc_call_stats *stats, void *and_free_memory); /* sizeof(per channel data) */ diff --git a/src/core/lib/channel/compress_filter.c b/src/core/lib/channel/compress_filter.c index 4b88dcba63..b734f92e66 100644 --- a/src/core/lib/channel/compress_filter.c +++ b/src/core/lib/channel/compress_filter.c @@ -269,8 +269,7 @@ static void init_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, /* Destructor for call_data */ static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, - const grpc_call_stats *stats, - void *ignored) { + const grpc_call_stats *stats, void *ignored) { /* grab pointers to our data from the call element */ call_data *calld = elem->call_data; gpr_slice_buffer_destroy(&calld->slices); diff --git a/src/core/lib/channel/http_client_filter.c b/src/core/lib/channel/http_client_filter.c index 7e2b09c965..cd9e6e894b 100644 --- a/src/core/lib/channel/http_client_filter.c +++ b/src/core/lib/channel/http_client_filter.c @@ -156,8 +156,7 @@ static void init_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, /* Destructor for call_data */ static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, - const grpc_call_stats *stats, - void *ignored) {} + const grpc_call_stats *stats, void *ignored) {} static grpc_mdelem *scheme_from_args(const grpc_channel_args *args) { unsigned i; diff --git a/src/core/lib/channel/http_server_filter.c b/src/core/lib/channel/http_server_filter.c index 00770ea092..43d71af473 100644 --- a/src/core/lib/channel/http_server_filter.c +++ b/src/core/lib/channel/http_server_filter.c @@ -226,8 +226,7 @@ static void init_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, /* Destructor for call_data */ static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, - const grpc_call_stats *stats, - void *ignored) {} + const grpc_call_stats *stats, void *ignored) {} /* Constructor for channel_data */ static void init_channel_elem(grpc_exec_ctx *exec_ctx, diff --git a/src/core/lib/security/client_auth_filter.c b/src/core/lib/security/client_auth_filter.c index 81b2e7cd88..f808973909 100644 --- a/src/core/lib/security/client_auth_filter.c +++ b/src/core/lib/security/client_auth_filter.c @@ -278,8 +278,7 @@ static void set_pollset(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, /* Destructor for call_data */ static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, - const grpc_call_stats *stats, - void *ignored) { + const grpc_call_stats *stats, void *ignored) { call_data *calld = elem->call_data; grpc_call_credentials_unref(calld->creds); if (calld->host != NULL) { diff --git a/src/core/lib/security/server_auth_filter.c b/src/core/lib/security/server_auth_filter.c index 25c992691e..0290f8a5b5 100644 --- a/src/core/lib/security/server_auth_filter.c +++ b/src/core/lib/security/server_auth_filter.c @@ -225,8 +225,7 @@ static void set_pollset(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, /* Destructor for call_data */ static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, - const grpc_call_stats *stats, - void *ignored) {} + const grpc_call_stats *stats, void *ignored) {} /* Constructor for channel_data */ static void init_channel_elem(grpc_exec_ctx *exec_ctx, diff --git a/src/core/lib/surface/server.c b/src/core/lib/surface/server.c index cf20594b24..3c8fa3aadc 100644 --- a/src/core/lib/surface/server.c +++ b/src/core/lib/surface/server.c @@ -821,8 +821,7 @@ static void init_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, } static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, - const grpc_call_stats *stats, - void *ignored) { + const grpc_call_stats *stats, void *ignored) { channel_data *chand = elem->channel_data; call_data *calld = elem->call_data; diff --git a/src/core/plugin_registry/grpc_plugin_registry.c b/src/core/plugin_registry/grpc_plugin_registry.c index 905cd59e23..1cd2abb934 100644 --- a/src/core/plugin_registry/grpc_plugin_registry.c +++ b/src/core/plugin_registry/grpc_plugin_registry.c @@ -51,10 +51,8 @@ extern void census_grpc_plugin_init(void); extern void census_grpc_plugin_shutdown(void); void grpc_register_built_in_plugins(void) { - grpc_register_plugin(grpc_chttp2_plugin_init, - grpc_chttp2_plugin_shutdown); - grpc_register_plugin(grpc_client_config_init, - grpc_client_config_shutdown); + grpc_register_plugin(grpc_chttp2_plugin_init, grpc_chttp2_plugin_shutdown); + grpc_register_plugin(grpc_client_config_init, grpc_client_config_shutdown); grpc_register_plugin(grpc_lb_policy_pick_first_init, grpc_lb_policy_pick_first_shutdown); grpc_register_plugin(grpc_lb_policy_round_robin_init, @@ -65,6 +63,5 @@ void grpc_register_built_in_plugins(void) { grpc_resolver_sockaddr_shutdown); grpc_register_plugin(grpc_load_reporting_plugin_init, grpc_load_reporting_plugin_shutdown); - grpc_register_plugin(census_grpc_plugin_init, - census_grpc_plugin_shutdown); + grpc_register_plugin(census_grpc_plugin_init, census_grpc_plugin_shutdown); } diff --git a/src/core/plugin_registry/grpc_unsecure_plugin_registry.c b/src/core/plugin_registry/grpc_unsecure_plugin_registry.c index 7995078725..86eac132e8 100644 --- a/src/core/plugin_registry/grpc_unsecure_plugin_registry.c +++ b/src/core/plugin_registry/grpc_unsecure_plugin_registry.c @@ -51,10 +51,8 @@ extern void census_grpc_plugin_init(void); extern void census_grpc_plugin_shutdown(void); void grpc_register_built_in_plugins(void) { - grpc_register_plugin(grpc_chttp2_plugin_init, - grpc_chttp2_plugin_shutdown); - grpc_register_plugin(grpc_client_config_init, - grpc_client_config_shutdown); + grpc_register_plugin(grpc_chttp2_plugin_init, grpc_chttp2_plugin_shutdown); + grpc_register_plugin(grpc_client_config_init, grpc_client_config_shutdown); grpc_register_plugin(grpc_resolver_dns_native_init, grpc_resolver_dns_native_shutdown); grpc_register_plugin(grpc_resolver_sockaddr_init, @@ -65,6 +63,5 @@ void grpc_register_built_in_plugins(void) { grpc_lb_policy_pick_first_shutdown); grpc_register_plugin(grpc_lb_policy_round_robin_init, grpc_lb_policy_round_robin_shutdown); - grpc_register_plugin(census_grpc_plugin_init, - census_grpc_plugin_shutdown); + grpc_register_plugin(census_grpc_plugin_init, census_grpc_plugin_shutdown); } -- cgit v1.2.3 From 68897999237ab5d67278365b3bd444960fa3c4c0 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 3 May 2016 23:10:07 -0700 Subject: Fix some ubsan issues: I fear no bugs were harmed in the making of this episode --- build.yaml | 2 ++ src/core/ext/client_config/subchannel.c | 2 +- src/core/ext/client_config/subchannel_index.c | 6 +++++- .../ext/transport/chttp2/transport/frame_goaway.c | 2 +- .../ext/transport/chttp2/transport/hpack_parser.c | 5 +++++ src/core/lib/channel/channel_args.c | 2 +- src/core/lib/compression/compression_algorithm.c | 1 + src/core/lib/support/murmur_hash.c | 8 +++----- src/core/lib/transport/metadata.c | 2 +- test/core/end2end/fuzzers/api_fuzzer.c | 24 +++++++++++++--------- tools/run_tests/configs.json | 3 +++ 11 files changed, 37 insertions(+), 20 deletions(-) (limited to 'src/core/lib/channel') diff --git a/build.yaml b/build.yaml index 441752dc3d..4cf7057a90 100644 --- a/build.yaml +++ b/build.yaml @@ -3247,6 +3247,8 @@ configs: LDFLAGS: -fsanitize=undefined LDXX: clang++ compile_the_world: true + test_environ: + UBSAN_OPTIONS: halt_on_error=1 timeout_multiplier: 1.5 defaults: boringssl: diff --git a/src/core/ext/client_config/subchannel.c b/src/core/ext/client_config/subchannel.c index bd45d3825c..cfd39e7cfb 100644 --- a/src/core/ext/client_config/subchannel.c +++ b/src/core/ext/client_config/subchannel.c @@ -320,7 +320,7 @@ grpc_subchannel *grpc_subchannel_create(grpc_exec_ctx *exec_ctx, c->filters = NULL; } c->addr = gpr_malloc(args->addr_len); - memcpy(c->addr, args->addr, args->addr_len); + if (args->addr_len) memcpy(c->addr, args->addr, args->addr_len); c->pollset_set = grpc_pollset_set_create(); c->addr_len = args->addr_len; grpc_set_initial_connect_string(&c->addr, &c->addr_len, diff --git a/src/core/ext/client_config/subchannel_index.c b/src/core/ext/client_config/subchannel_index.c index b77632bba3..69de0e78c1 100644 --- a/src/core/ext/client_config/subchannel_index.c +++ b/src/core/ext/client_config/subchannel_index.c @@ -87,7 +87,9 @@ static grpc_subchannel_key *create_key( } k->args.addr_len = args->addr_len; k->args.addr = gpr_malloc(args->addr_len); - memcpy(k->args.addr, args->addr, k->args.addr_len); + if (k->args.addr_len > 0) { + memcpy(k->args.addr, args->addr, k->args.addr_len); + } k->args.args = copy_channel_args(args->args); return k; } @@ -109,8 +111,10 @@ static int subchannel_key_compare(grpc_subchannel_key *a, if (c != 0) return c; c = GPR_ICMP(a->args.filter_count, b->args.filter_count); if (c != 0) return c; + if (a->args.addr_len) { c = memcmp(a->args.addr, b->args.addr, a->args.addr_len); if (c != 0) return c; + } if (a->args.filter_count > 0) { c = memcmp(a->args.filters, b->args.filters, a->args.filter_count * sizeof(*a->args.filters)); diff --git a/src/core/ext/transport/chttp2/transport/frame_goaway.c b/src/core/ext/transport/chttp2/transport/frame_goaway.c index 69accb7696..aa25b1a231 100644 --- a/src/core/ext/transport/chttp2/transport/frame_goaway.c +++ b/src/core/ext/transport/chttp2/transport/frame_goaway.c @@ -137,7 +137,7 @@ grpc_chttp2_parse_error grpc_chttp2_goaway_parser_parse( ++cur; /* fallthrough */ case GRPC_CHTTP2_GOAWAY_DEBUG: - memcpy(p->debug_data + p->debug_pos, cur, (size_t)(end - cur)); + if (end != cur) memcpy(p->debug_data + p->debug_pos, cur, (size_t)(end - cur)); GPR_ASSERT((size_t)(end - cur) < UINT32_MAX - p->debug_pos); p->debug_pos += (uint32_t)(end - cur); p->state = GRPC_CHTTP2_GOAWAY_DEBUG; diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.c b/src/core/ext/transport/chttp2/transport/hpack_parser.c index 687936bfd3..9278a7ac42 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.c +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.c @@ -1138,6 +1138,7 @@ static int parse_string_prefix(grpc_chttp2_hpack_parser *p, const uint8_t *cur, /* append some bytes to a string */ static void append_bytes(grpc_chttp2_hpack_parser_string *str, const uint8_t *data, size_t length) { + if (length == 0) return; if (length + str->length > str->capacity) { GPR_ASSERT(str->length + length <= UINT32_MAX); str->capacity = (uint32_t)(str->length + length); @@ -1445,6 +1446,10 @@ grpc_chttp2_parse_error grpc_chttp2_header_parser_parse( stream id on a header */ if (stream_parsing != NULL) { if (parser->is_boundary) { + if (stream_parsing->header_frames_received == GPR_ARRAY_SIZE(stream_parsing->got_metadata_on_parse)) { + gpr_log(GPR_ERROR, "too many trailer frames"); + return GRPC_CHTTP2_CONNECTION_ERROR; + } stream_parsing ->got_metadata_on_parse[stream_parsing->header_frames_received] = 1; stream_parsing->header_frames_received++; diff --git a/src/core/lib/channel/channel_args.c b/src/core/lib/channel/channel_args.c index 28d2d78d00..1659c3788b 100644 --- a/src/core/lib/channel/channel_args.c +++ b/src/core/lib/channel/channel_args.c @@ -132,7 +132,7 @@ grpc_channel_args *grpc_channel_args_normalize(const grpc_channel_args *a) { for (size_t i = 0; i < a->num_args; i++) { args[i] = &a->args[i]; } - qsort(args, a->num_args, sizeof(grpc_arg *), cmp_key_stable); + if (a->num_args > 1) qsort(args, a->num_args, sizeof(grpc_arg *), cmp_key_stable); grpc_channel_args *b = gpr_malloc(sizeof(grpc_channel_args)); b->num_args = a->num_args; diff --git a/src/core/lib/compression/compression_algorithm.c b/src/core/lib/compression/compression_algorithm.c index 7039364b7b..820871d579 100644 --- a/src/core/lib/compression/compression_algorithm.c +++ b/src/core/lib/compression/compression_algorithm.c @@ -199,5 +199,6 @@ void grpc_compression_options_disable_algorithm( int grpc_compression_options_is_algorithm_enabled( const grpc_compression_options *opts, grpc_compression_algorithm algorithm) { + if (algorithm >= GRPC_COMPRESS_ALGORITHMS_COUNT) return 0; return GPR_BITGET(opts->enabled_algorithms_bitset, algorithm); } diff --git a/src/core/lib/support/murmur_hash.c b/src/core/lib/support/murmur_hash.c index 5711fff0c0..7137c1f313 100644 --- a/src/core/lib/support/murmur_hash.c +++ b/src/core/lib/support/murmur_hash.c @@ -33,6 +33,8 @@ #include "src/core/lib/support/murmur_hash.h" +#include + #define ROTL32(x, r) ((x) << (r)) | ((x) >> (32 - (r))) #define FMIX32(h) \ @@ -42,10 +44,6 @@ (h) *= 0xc2b2ae35; \ (h) ^= (h) >> 16; -/* Block read - if your platform needs to do endian-swapping or can only - handle aligned reads, do the conversion here */ -#define GETBLOCK32(p, i) (p)[(i)] - uint32_t gpr_murmur_hash3(const void *key, size_t len, uint32_t seed) { const uint8_t *data = (const uint8_t *)key; const size_t nblocks = len / 4; @@ -62,7 +60,7 @@ uint32_t gpr_murmur_hash3(const void *key, size_t len, uint32_t seed) { /* body */ for (i = -(int)nblocks; i; i++) { - k1 = GETBLOCK32(blocks, i); + memcpy(&k1, blocks + i, sizeof(uint32_t)); k1 *= c1; k1 = ROTL32(k1, 15); diff --git a/src/core/lib/transport/metadata.c b/src/core/lib/transport/metadata.c index 5847ec9053..53fe03bdc9 100644 --- a/src/core/lib/transport/metadata.c +++ b/src/core/lib/transport/metadata.c @@ -373,7 +373,7 @@ grpc_mdstr *grpc_mdstr_from_buffer(const uint8_t *buf, size_t length) { ss = g_static_strtab[idx]; if (ss == NULL) break; if (ss->hash == hash && GPR_SLICE_LENGTH(ss->slice) == length && - 0 == memcmp(buf, GPR_SLICE_START_PTR(ss->slice), length)) { + (length == 0 || 0 == memcmp(buf, GPR_SLICE_START_PTR(ss->slice), length))) { GPR_TIMER_END("grpc_mdstr_from_buffer", 0); return ss; } diff --git a/test/core/end2end/fuzzers/api_fuzzer.c b/test/core/end2end/fuzzers/api_fuzzer.c index b133a948ee..b6150151d5 100644 --- a/test/core/end2end/fuzzers/api_fuzzer.c +++ b/test/core/end2end/fuzzers/api_fuzzer.c @@ -418,17 +418,21 @@ static void add_to_free(call_state *call, void *p) { static void read_metadata(input_stream *inp, size_t *count, grpc_metadata **metadata, call_state *cs) { *count = next_byte(inp); - *metadata = gpr_malloc(*count * sizeof(**metadata)); - memset(*metadata, 0, *count * sizeof(**metadata)); - for (size_t i = 0; i < *count; i++) { - (*metadata)[i].key = read_string(inp); - read_buffer(inp, (char **)&(*metadata)[i].value, - &(*metadata)[i].value_length); - (*metadata)[i].flags = read_uint32(inp); - add_to_free(cs, (void *)(*metadata)[i].key); - add_to_free(cs, (void *)(*metadata)[i].value); + if (*count) { + *metadata = gpr_malloc(*count * sizeof(**metadata)); + memset(*metadata, 0, *count * sizeof(**metadata)); + for (size_t i = 0; i < *count; i++) { + (*metadata)[i].key = read_string(inp); + read_buffer(inp, (char **)&(*metadata)[i].value, + &(*metadata)[i].value_length); + (*metadata)[i].flags = read_uint32(inp); + add_to_free(cs, (void *)(*metadata)[i].key); + add_to_free(cs, (void *)(*metadata)[i].value); + } + } else { + *metadata = gpr_malloc(1); } - add_to_free(cs, *metadata); + add_to_free(cs, *metadata); } static call_state *destroy_call(call_state *call) { diff --git a/tools/run_tests/configs.json b/tools/run_tests/configs.json index 325e9aa929..1a67544d18 100644 --- a/tools/run_tests/configs.json +++ b/tools/run_tests/configs.json @@ -56,6 +56,9 @@ }, { "config": "ubsan", + "environ": { + "UBSAN_OPTIONS": "halt_on_error=1" + }, "timeout_multiplier": 1.5 }, { -- cgit v1.2.3 From 93dd0470cf26aed445b40a8b9332e6b06f5e5514 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 18 May 2016 15:06:37 -0700 Subject: clang-format --- src/core/ext/client_config/subchannel_index.c | 4 ++-- src/core/ext/transport/chttp2/transport/frame_goaway.c | 3 ++- src/core/ext/transport/chttp2/transport/hpack_parser.c | 3 ++- src/core/lib/channel/channel_args.c | 3 ++- src/core/lib/transport/metadata.c | 3 ++- test/core/end2end/fuzzers/api_fuzzer.c | 2 +- 6 files changed, 11 insertions(+), 7 deletions(-) (limited to 'src/core/lib/channel') diff --git a/src/core/ext/client_config/subchannel_index.c b/src/core/ext/client_config/subchannel_index.c index 69de0e78c1..690cb16b96 100644 --- a/src/core/ext/client_config/subchannel_index.c +++ b/src/core/ext/client_config/subchannel_index.c @@ -112,8 +112,8 @@ static int subchannel_key_compare(grpc_subchannel_key *a, c = GPR_ICMP(a->args.filter_count, b->args.filter_count); if (c != 0) return c; if (a->args.addr_len) { - c = memcmp(a->args.addr, b->args.addr, a->args.addr_len); - if (c != 0) return c; + c = memcmp(a->args.addr, b->args.addr, a->args.addr_len); + if (c != 0) return c; } if (a->args.filter_count > 0) { c = memcmp(a->args.filters, b->args.filters, diff --git a/src/core/ext/transport/chttp2/transport/frame_goaway.c b/src/core/ext/transport/chttp2/transport/frame_goaway.c index aa25b1a231..827e7a6977 100644 --- a/src/core/ext/transport/chttp2/transport/frame_goaway.c +++ b/src/core/ext/transport/chttp2/transport/frame_goaway.c @@ -137,7 +137,8 @@ grpc_chttp2_parse_error grpc_chttp2_goaway_parser_parse( ++cur; /* fallthrough */ case GRPC_CHTTP2_GOAWAY_DEBUG: - if (end != cur) memcpy(p->debug_data + p->debug_pos, cur, (size_t)(end - cur)); + if (end != cur) + memcpy(p->debug_data + p->debug_pos, cur, (size_t)(end - cur)); GPR_ASSERT((size_t)(end - cur) < UINT32_MAX - p->debug_pos); p->debug_pos += (uint32_t)(end - cur); p->state = GRPC_CHTTP2_GOAWAY_DEBUG; diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.c b/src/core/ext/transport/chttp2/transport/hpack_parser.c index 9278a7ac42..ed45bc9cb3 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.c +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.c @@ -1446,7 +1446,8 @@ grpc_chttp2_parse_error grpc_chttp2_header_parser_parse( stream id on a header */ if (stream_parsing != NULL) { if (parser->is_boundary) { - if (stream_parsing->header_frames_received == GPR_ARRAY_SIZE(stream_parsing->got_metadata_on_parse)) { + if (stream_parsing->header_frames_received == + GPR_ARRAY_SIZE(stream_parsing->got_metadata_on_parse)) { gpr_log(GPR_ERROR, "too many trailer frames"); return GRPC_CHTTP2_CONNECTION_ERROR; } diff --git a/src/core/lib/channel/channel_args.c b/src/core/lib/channel/channel_args.c index d95a7bf110..569be4dc28 100644 --- a/src/core/lib/channel/channel_args.c +++ b/src/core/lib/channel/channel_args.c @@ -132,7 +132,8 @@ grpc_channel_args *grpc_channel_args_normalize(const grpc_channel_args *a) { for (size_t i = 0; i < a->num_args; i++) { args[i] = &a->args[i]; } - if (a->num_args > 1) qsort(args, a->num_args, sizeof(grpc_arg *), cmp_key_stable); + if (a->num_args > 1) + qsort(args, a->num_args, sizeof(grpc_arg *), cmp_key_stable); grpc_channel_args *b = gpr_malloc(sizeof(grpc_channel_args)); b->num_args = a->num_args; diff --git a/src/core/lib/transport/metadata.c b/src/core/lib/transport/metadata.c index 53fe03bdc9..82c8e239f6 100644 --- a/src/core/lib/transport/metadata.c +++ b/src/core/lib/transport/metadata.c @@ -373,7 +373,8 @@ grpc_mdstr *grpc_mdstr_from_buffer(const uint8_t *buf, size_t length) { ss = g_static_strtab[idx]; if (ss == NULL) break; if (ss->hash == hash && GPR_SLICE_LENGTH(ss->slice) == length && - (length == 0 || 0 == memcmp(buf, GPR_SLICE_START_PTR(ss->slice), length))) { + (length == 0 || + 0 == memcmp(buf, GPR_SLICE_START_PTR(ss->slice), length))) { GPR_TIMER_END("grpc_mdstr_from_buffer", 0); return ss; } diff --git a/test/core/end2end/fuzzers/api_fuzzer.c b/test/core/end2end/fuzzers/api_fuzzer.c index b6150151d5..cacf29e261 100644 --- a/test/core/end2end/fuzzers/api_fuzzer.c +++ b/test/core/end2end/fuzzers/api_fuzzer.c @@ -432,7 +432,7 @@ static void read_metadata(input_stream *inp, size_t *count, } else { *metadata = gpr_malloc(1); } - add_to_free(cs, *metadata); + add_to_free(cs, *metadata); } static call_state *destroy_call(call_state *call) { -- cgit v1.2.3