From 296c7bb8fa9711f580a01a7d61482f8240cba55d Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 10 Jan 2017 15:34:02 -0800 Subject: [PATCH] Fix metadata validation --- src/core/lib/surface/validate_metadata.c | 7 +++++-- test/core/end2end/invalid_call_argument_test.c | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/core/lib/surface/validate_metadata.c b/src/core/lib/surface/validate_metadata.c index 8c11345c658..7ec9137265d 100644 --- a/src/core/lib/surface/validate_metadata.c +++ b/src/core/lib/surface/validate_metadata.c @@ -73,8 +73,11 @@ grpc_error *grpc_validate_header_key_is_legal(grpc_slice slice) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xff, 0x03, 0x00, 0x00, 0x00, 0x80, 0xfe, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - if (GRPC_SLICE_LENGTH(slice) == 0 || GRPC_SLICE_START_PTR(slice)[0] == ':') { - return 0; + if (GRPC_SLICE_LENGTH(slice) == 0) { + return GRPC_ERROR_CREATE("Metadata keys cannot be zero length"); + } + if (GRPC_SLICE_START_PTR(slice)[0] == ':') { + return GRPC_ERROR_CREATE("Metadata keys cannot start with :"); } return conforms_to(slice, legal_header_bits, "Illegal header key"); } diff --git a/test/core/end2end/invalid_call_argument_test.c b/test/core/end2end/invalid_call_argument_test.c index 9067b24168c..a9d0287952e 100644 --- a/test/core/end2end/invalid_call_argument_test.c +++ b/test/core/end2end/invalid_call_argument_test.c @@ -597,6 +597,7 @@ static void test_invalid_initial_metadata_reserved_key() { int main(int argc, char **argv) { grpc_test_init(argc, argv); grpc_init(); + test_invalid_initial_metadata_reserved_key(); test_non_null_reserved_on_start_batch(); test_non_null_reserved_on_op(); test_send_initial_metadata_more_than_once(); @@ -616,7 +617,6 @@ int main(int argc, char **argv) { test_send_server_status_twice(); test_recv_close_on_server_with_invalid_flags(); test_recv_close_on_server_twice(); - test_invalid_initial_metadata_reserved_key(); grpc_shutdown(); return 0;