Skip to content

Commit

Permalink
Merge pull request grpc#9187 from yang-g/validate_reserved_metadata
Browse files Browse the repository at this point in the history
Check and fail if user provides a metadata key starting with :
  • Loading branch information
yang-g authored Dec 28, 2016
2 parents 5783782 + 92fa960 commit ddebfa6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/lib/surface/validate_metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ int grpc_header_key_is_legal(const char *key, size_t length) {
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 (length == 0) {
if (length == 0 || key[0] == ':') {
return 0;
}
return conforms_to(key, length, legal_header_bits);
Expand Down
24 changes: 24 additions & 0 deletions test/core/end2end/invalid_call_argument_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,29 @@ static void test_recv_close_on_server_twice() {
cleanup_test();
}

static void test_invalid_initial_metadata_reserved_key() {
gpr_log(GPR_INFO, "test_invalid_initial_metadata_reserved_key");

grpc_metadata metadata;
metadata.key = ":start_with_colon";
metadata.value = "value";
metadata.value_length = 6;

grpc_op *op;
prepare_test(1);
op = g_state.ops;
op->op = GRPC_OP_SEND_INITIAL_METADATA;
op->data.send_initial_metadata.count = 1;
op->data.send_initial_metadata.metadata = &metadata;
op->flags = 0;
op->reserved = NULL;
op++;
GPR_ASSERT(GRPC_CALL_ERROR_INVALID_METADATA ==
grpc_call_start_batch(g_state.call, g_state.ops,
(size_t)(op - g_state.ops), tag(1), NULL));
cleanup_test();
}

int main(int argc, char **argv) {
grpc_test_init(argc, argv);
grpc_init();
Expand All @@ -595,6 +618,7 @@ 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;
Expand Down

0 comments on commit ddebfa6

Please sign in to comment.