| 1 |
/* |
| 2 |
* |
| 3 |
* Copyright 2015 gRPC authors. |
| 4 |
* |
| 5 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 |
* you may not use this file except in compliance with the License. |
| 7 |
* You may obtain a copy of the License at |
| 8 |
* |
| 9 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
* |
| 11 |
* Unless required by applicable law or agreed to in writing, software |
| 12 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 |
* See the License for the specific language governing permissions and |
| 15 |
* limitations under the License. |
| 16 |
* |
| 17 |
*/ |
| 18 |
|
| 19 |
#include <grpc/grpc.h> |
| 20 |
#include <grpc/support/log.h> |
| 21 |
|
| 22 |
#include "src/core/lib/surface/server.h" |
| 23 |
#include "test/core/bad_client/bad_client.h" |
| 24 |
#include "test/core/util/test_config.h" |
| 25 |
|
| 26 |
#define PFX_STR "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" |
| 27 |
#define ONE_SETTING_HDR "\x00\x00\x06\x04\x00\x00\x00\x00\x00" |
| 28 |
|
| 29 |
static void verifier(grpc_server* server, grpc_completion_queue* cq, |
| 30 |
void* /*registered_method*/) { |
| 31 |
while (grpc_core::Server::FromC(server)->HasOpenConnections()) { |
| 32 |
GPR_ASSERT(grpc_completion_queue_next( |
| 33 |
cq, grpc_timeout_milliseconds_to_deadline(20), nullptr) |
| 34 |
.type == GRPC_QUEUE_TIMEOUT); |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
int main(int argc, char** argv) { |
| 39 |
grpc::testing::TestEnvironment env(&argc, argv); |
| 40 |
grpc_init(); |
| 41 |
|
| 42 |
/* various partial prefixes */ |
| 43 |
GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, PFX_STR "\x00", |
| 44 |
GRPC_BAD_CLIENT_DISCONNECT); |
| 45 |
GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, PFX_STR "\x00\x00", |
| 46 |
GRPC_BAD_CLIENT_DISCONNECT); |
| 47 |
GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, PFX_STR "\x00\x00\x00", |
| 48 |
GRPC_BAD_CLIENT_DISCONNECT); |
| 49 |
GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, PFX_STR "\x06", |
| 50 |
GRPC_BAD_CLIENT_DISCONNECT); |
| 51 |
GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, PFX_STR "\x00\x06", |
| 52 |
GRPC_BAD_CLIENT_DISCONNECT); |
| 53 |
GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, PFX_STR "\x00\x00\x06", |
| 54 |
GRPC_BAD_CLIENT_DISCONNECT); |
| 55 |
GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, PFX_STR "\x00\x00\x00\x04", |
| 56 |
GRPC_BAD_CLIENT_DISCONNECT); |
| 57 |
GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, PFX_STR "\x00\x00\x00\x04\x00", |
| 58 |
GRPC_BAD_CLIENT_DISCONNECT); |
| 59 |
GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, PFX_STR "\x00\x00\x00\x04\x01", |
| 60 |
GRPC_BAD_CLIENT_DISCONNECT); |
| 61 |
GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, PFX_STR "\x00\x00\x00\x04\xff", |
| 62 |
GRPC_BAD_CLIENT_DISCONNECT); |
| 63 |
GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, |
| 64 |
PFX_STR "\x00\x00\x00\x04\x00\x00", |
| 65 |
GRPC_BAD_CLIENT_DISCONNECT); |
| 66 |
GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, |
| 67 |
PFX_STR "\x00\x00\x00\x04\x00\x00\x00", |
| 68 |
GRPC_BAD_CLIENT_DISCONNECT); |
| 69 |
GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, |
| 70 |
PFX_STR "\x00\x00\x00\x04\x00\x00\x00\x00", |
| 71 |
GRPC_BAD_CLIENT_DISCONNECT); |
| 72 |
/* must not send frames with stream id != 0 */ |
| 73 |
GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, |
| 74 |
PFX_STR "\x00\x00\x00\x04\x00\x00\x00\x00\x01", 0); |
| 75 |
GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, |
| 76 |
PFX_STR "\x00\x00\x00\x04\x00\x40\x00\x00\x00", 0); |
| 77 |
/* settings frame must be a multiple of six bytes long */ |
| 78 |
GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, |
| 79 |
PFX_STR "\x00\x00\x01\x04\x00\x00\x00\x00\x00", 0); |
| 80 |
GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, |
| 81 |
PFX_STR "\x00\x00\x02\x04\x00\x00\x00\x00\x00", 0); |
| 82 |
GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, |
| 83 |
PFX_STR "\x00\x00\x03\x04\x00\x00\x00\x00\x00", 0); |
| 84 |
GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, |
| 85 |
PFX_STR "\x00\x00\x04\x04\x00\x00\x00\x00\x00", 0); |
| 86 |
GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, |
| 87 |
PFX_STR "\x00\x00\x05\x04\x00\x00\x00\x00\x00", 0); |
| 88 |
/* some settings values are illegal */ |
| 89 |
/* max frame size = 0 */ |
| 90 |
GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, |
| 91 |
PFX_STR ONE_SETTING_HDR "\x00\x05\x00\x00\x00\x00", |
| 92 |
GRPC_BAD_CLIENT_DISCONNECT); |
| 93 |
GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, |
| 94 |
PFX_STR ONE_SETTING_HDR "\x00\x06\xff\xff\xff\xff", |
| 95 |
GRPC_BAD_CLIENT_DISCONNECT); |
| 96 |
/* update intiial window size */ |
| 97 |
GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, |
| 98 |
PFX_STR ONE_SETTING_HDR "\x00\x04\x00\x01\x00\x00", |
| 99 |
GRPC_BAD_CLIENT_DISCONNECT); |
| 100 |
/* ack with data */ |
| 101 |
GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, |
| 102 |
PFX_STR |
| 103 |
"\x00\x00\x00\x04\x00\x00\x00\x00\x00" |
| 104 |
"\x00\x00\x01\x04\x01\x00\x00\x00\x00", |
| 105 |
0); |
| 106 |
/* settings frame with invalid flags */ |
| 107 |
GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, |
| 108 |
PFX_STR "\x00\x00\x00\x04\x10\x00\x00\x00\x00", 0); |
| 109 |
/* unknown settings should be ignored */ |
| 110 |
GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, |
| 111 |
PFX_STR ONE_SETTING_HDR "\x00\x99\x00\x00\x00\x00", |
| 112 |
GRPC_BAD_CLIENT_DISCONNECT); |
| 113 |
|
| 114 |
grpc_shutdown(); |
| 115 |
return 0; |
| 116 |
} |