Craig Tiller | 3c26d09 | 2015-06-05 14:48:30 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 6169d5f | 2016-03-31 07:46:18 -0700 | [diff] [blame] | 3 | * Copyright 2015, Google Inc. |
Craig Tiller | 3c26d09 | 2015-06-05 14:48:30 -0700 | [diff] [blame] | 4 | * All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions are |
| 8 | * met: |
| 9 | * |
| 10 | * * Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * * Redistributions in binary form must reproduce the above |
| 13 | * copyright notice, this list of conditions and the following disclaimer |
| 14 | * in the documentation and/or other materials provided with the |
| 15 | * distribution. |
| 16 | * * Neither the name of Google Inc. nor the names of its |
| 17 | * contributors may be used to endorse or promote products derived from |
| 18 | * this software without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | * |
| 32 | */ |
| 33 | |
Craig Tiller | 9533d04 | 2016-03-25 17:11:06 -0700 | [diff] [blame] | 34 | #include "src/core/lib/surface/server.h" |
Craig Tiller | f40df23 | 2016-03-25 13:38:14 -0700 | [diff] [blame] | 35 | #include "test/core/bad_client/bad_client.h" |
Craig Tiller | 3c26d09 | 2015-06-05 14:48:30 -0700 | [diff] [blame] | 36 | |
| 37 | #define PFX_STR "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" |
Craig Tiller | 47e541c | 2015-12-07 08:51:19 -0800 | [diff] [blame] | 38 | #define ONE_SETTING_HDR "\x00\x00\x06\x04\x00\x00\x00\x00\x00" |
Craig Tiller | 3c26d09 | 2015-06-05 14:48:30 -0700 | [diff] [blame] | 39 | |
Craig Tiller | 6cb6917 | 2015-12-14 13:35:53 -0800 | [diff] [blame] | 40 | static void verifier(grpc_server *server, grpc_completion_queue *cq, |
| 41 | void *registered_method) { |
Craig Tiller | 3c26d09 | 2015-06-05 14:48:30 -0700 | [diff] [blame] | 42 | while (grpc_server_has_open_connections(server)) { |
Craig Tiller | f40df23 | 2016-03-25 13:38:14 -0700 | [diff] [blame] | 43 | GPR_ASSERT(grpc_completion_queue_next( |
| 44 | cq, GRPC_TIMEOUT_MILLIS_TO_DEADLINE(20), NULL) |
| 45 | .type == GRPC_QUEUE_TIMEOUT); |
Craig Tiller | 3c26d09 | 2015-06-05 14:48:30 -0700 | [diff] [blame] | 46 | } |
| 47 | } |
| 48 | |
| 49 | int main(int argc, char **argv) { |
| 50 | grpc_test_init(argc, argv); |
| 51 | |
| 52 | /* various partial prefixes */ |
Mark D. Roth | 8a1d805 | 2016-05-03 10:44:56 -0700 | [diff] [blame] | 53 | GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00", |
Craig Tiller | 83b2f25 | 2015-06-05 14:50:00 -0700 | [diff] [blame] | 54 | GRPC_BAD_CLIENT_DISCONNECT); |
Mark D. Roth | 8a1d805 | 2016-05-03 10:44:56 -0700 | [diff] [blame] | 55 | GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00", |
Craig Tiller | 83b2f25 | 2015-06-05 14:50:00 -0700 | [diff] [blame] | 56 | GRPC_BAD_CLIENT_DISCONNECT); |
Mark D. Roth | 8a1d805 | 2016-05-03 10:44:56 -0700 | [diff] [blame] | 57 | GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00", |
Craig Tiller | 83b2f25 | 2015-06-05 14:50:00 -0700 | [diff] [blame] | 58 | GRPC_BAD_CLIENT_DISCONNECT); |
Mark D. Roth | 8a1d805 | 2016-05-03 10:44:56 -0700 | [diff] [blame] | 59 | GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x06", |
Craig Tiller | 83b2f25 | 2015-06-05 14:50:00 -0700 | [diff] [blame] | 60 | GRPC_BAD_CLIENT_DISCONNECT); |
Mark D. Roth | 8a1d805 | 2016-05-03 10:44:56 -0700 | [diff] [blame] | 61 | GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x06", |
Craig Tiller | 83b2f25 | 2015-06-05 14:50:00 -0700 | [diff] [blame] | 62 | GRPC_BAD_CLIENT_DISCONNECT); |
Mark D. Roth | 8a1d805 | 2016-05-03 10:44:56 -0700 | [diff] [blame] | 63 | GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x06", |
Craig Tiller | 83b2f25 | 2015-06-05 14:50:00 -0700 | [diff] [blame] | 64 | GRPC_BAD_CLIENT_DISCONNECT); |
Mark D. Roth | 8a1d805 | 2016-05-03 10:44:56 -0700 | [diff] [blame] | 65 | GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x04", |
Craig Tiller | 83b2f25 | 2015-06-05 14:50:00 -0700 | [diff] [blame] | 66 | GRPC_BAD_CLIENT_DISCONNECT); |
Mark D. Roth | 8a1d805 | 2016-05-03 10:44:56 -0700 | [diff] [blame] | 67 | GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x04\x00", |
Craig Tiller | 83b2f25 | 2015-06-05 14:50:00 -0700 | [diff] [blame] | 68 | GRPC_BAD_CLIENT_DISCONNECT); |
Mark D. Roth | 8a1d805 | 2016-05-03 10:44:56 -0700 | [diff] [blame] | 69 | GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x04\x01", |
Craig Tiller | 83b2f25 | 2015-06-05 14:50:00 -0700 | [diff] [blame] | 70 | GRPC_BAD_CLIENT_DISCONNECT); |
Mark D. Roth | 8a1d805 | 2016-05-03 10:44:56 -0700 | [diff] [blame] | 71 | GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x04\xff", |
Craig Tiller | 83b2f25 | 2015-06-05 14:50:00 -0700 | [diff] [blame] | 72 | GRPC_BAD_CLIENT_DISCONNECT); |
Mark D. Roth | 8a1d805 | 2016-05-03 10:44:56 -0700 | [diff] [blame] | 73 | GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x04\x00\x00", |
Craig Tiller | 83b2f25 | 2015-06-05 14:50:00 -0700 | [diff] [blame] | 74 | GRPC_BAD_CLIENT_DISCONNECT); |
Mark D. Roth | 8a1d805 | 2016-05-03 10:44:56 -0700 | [diff] [blame] | 75 | GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, |
| 76 | PFX_STR "\x00\x00\x00\x04\x00\x00\x00", |
Craig Tiller | 83b2f25 | 2015-06-05 14:50:00 -0700 | [diff] [blame] | 77 | GRPC_BAD_CLIENT_DISCONNECT); |
Mark D. Roth | 8a1d805 | 2016-05-03 10:44:56 -0700 | [diff] [blame] | 78 | GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, |
| 79 | PFX_STR "\x00\x00\x00\x04\x00\x00\x00\x00", |
Craig Tiller | 83b2f25 | 2015-06-05 14:50:00 -0700 | [diff] [blame] | 80 | GRPC_BAD_CLIENT_DISCONNECT); |
Craig Tiller | 3c26d09 | 2015-06-05 14:48:30 -0700 | [diff] [blame] | 81 | /* must not send frames with stream id != 0 */ |
Mark D. Roth | 8a1d805 | 2016-05-03 10:44:56 -0700 | [diff] [blame] | 82 | GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, |
Craig Tiller | 83b2f25 | 2015-06-05 14:50:00 -0700 | [diff] [blame] | 83 | PFX_STR "\x00\x00\x00\x04\x00\x00\x00\x00\x01", 0); |
Mark D. Roth | 8a1d805 | 2016-05-03 10:44:56 -0700 | [diff] [blame] | 84 | GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, |
Craig Tiller | 83b2f25 | 2015-06-05 14:50:00 -0700 | [diff] [blame] | 85 | PFX_STR "\x00\x00\x00\x04\x00\x40\x00\x00\x00", 0); |
Craig Tiller | 3c26d09 | 2015-06-05 14:48:30 -0700 | [diff] [blame] | 86 | /* settings frame must be a multiple of six bytes long */ |
Mark D. Roth | 8a1d805 | 2016-05-03 10:44:56 -0700 | [diff] [blame] | 87 | GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, |
Craig Tiller | 83b2f25 | 2015-06-05 14:50:00 -0700 | [diff] [blame] | 88 | PFX_STR "\x00\x00\x01\x04\x00\x00\x00\x00\x00", 0); |
Mark D. Roth | 8a1d805 | 2016-05-03 10:44:56 -0700 | [diff] [blame] | 89 | GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, |
Craig Tiller | 83b2f25 | 2015-06-05 14:50:00 -0700 | [diff] [blame] | 90 | PFX_STR "\x00\x00\x02\x04\x00\x00\x00\x00\x00", 0); |
Mark D. Roth | 8a1d805 | 2016-05-03 10:44:56 -0700 | [diff] [blame] | 91 | GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, |
Craig Tiller | 83b2f25 | 2015-06-05 14:50:00 -0700 | [diff] [blame] | 92 | PFX_STR "\x00\x00\x03\x04\x00\x00\x00\x00\x00", 0); |
Mark D. Roth | 8a1d805 | 2016-05-03 10:44:56 -0700 | [diff] [blame] | 93 | GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, |
Craig Tiller | 83b2f25 | 2015-06-05 14:50:00 -0700 | [diff] [blame] | 94 | PFX_STR "\x00\x00\x04\x04\x00\x00\x00\x00\x00", 0); |
Mark D. Roth | 8a1d805 | 2016-05-03 10:44:56 -0700 | [diff] [blame] | 95 | GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, |
Craig Tiller | 83b2f25 | 2015-06-05 14:50:00 -0700 | [diff] [blame] | 96 | PFX_STR "\x00\x00\x05\x04\x00\x00\x00\x00\x00", 0); |
Craig Tiller | 47e541c | 2015-12-07 08:51:19 -0800 | [diff] [blame] | 97 | /* some settings values are illegal */ |
| 98 | /* max frame size = 0 */ |
Mark D. Roth | 8a1d805 | 2016-05-03 10:44:56 -0700 | [diff] [blame] | 99 | GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, |
Craig Tiller | e2c6237 | 2015-12-07 16:11:03 -0800 | [diff] [blame] | 100 | PFX_STR ONE_SETTING_HDR "\x00\x05\x00\x00\x00\x00", |
| 101 | GRPC_BAD_CLIENT_DISCONNECT); |
Mark D. Roth | 8a1d805 | 2016-05-03 10:44:56 -0700 | [diff] [blame] | 102 | GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, |
Craig Tiller | 620e965 | 2015-12-14 12:02:50 -0800 | [diff] [blame] | 103 | PFX_STR ONE_SETTING_HDR "\x00\x06\xff\xff\xff\xff", |
Craig Tiller | 9ee2eec | 2015-12-08 10:28:33 -0800 | [diff] [blame] | 104 | GRPC_BAD_CLIENT_DISCONNECT); |
| 105 | /* update intiial window size */ |
Mark D. Roth | 8a1d805 | 2016-05-03 10:44:56 -0700 | [diff] [blame] | 106 | GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, |
Craig Tiller | 620e965 | 2015-12-14 12:02:50 -0800 | [diff] [blame] | 107 | PFX_STR ONE_SETTING_HDR "\x00\x04\x00\x01\x00\x00", |
Craig Tiller | 9ee2eec | 2015-12-08 10:28:33 -0800 | [diff] [blame] | 108 | GRPC_BAD_CLIENT_DISCONNECT); |
Craig Tiller | 0ca9952 | 2015-12-09 16:31:05 -0800 | [diff] [blame] | 109 | /* ack with data */ |
Mark D. Roth | 8a1d805 | 2016-05-03 10:44:56 -0700 | [diff] [blame] | 110 | GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR |
Craig Tiller | 0ca9952 | 2015-12-09 16:31:05 -0800 | [diff] [blame] | 111 | "\x00\x00\x00\x04\x00\x00\x00\x00\x00" |
Craig Tiller | 620e965 | 2015-12-14 12:02:50 -0800 | [diff] [blame] | 112 | "\x00\x00\x01\x04\x01\x00\x00\x00\x00", |
| 113 | 0); |
Craig Tiller | 0ca9952 | 2015-12-09 16:31:05 -0800 | [diff] [blame] | 114 | /* settings frame with invalid flags */ |
Mark D. Roth | 8a1d805 | 2016-05-03 10:44:56 -0700 | [diff] [blame] | 115 | GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, |
Craig Tiller | 620e965 | 2015-12-14 12:02:50 -0800 | [diff] [blame] | 116 | PFX_STR "\x00\x00\x00\x04\x10\x00\x00\x00\x00", 0); |
Craig Tiller | 0ca9952 | 2015-12-09 16:31:05 -0800 | [diff] [blame] | 117 | /* unknown settings should be ignored */ |
Mark D. Roth | 8a1d805 | 2016-05-03 10:44:56 -0700 | [diff] [blame] | 118 | GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, |
Craig Tiller | 620e965 | 2015-12-14 12:02:50 -0800 | [diff] [blame] | 119 | PFX_STR ONE_SETTING_HDR "\x00\x99\x00\x00\x00\x00", |
Craig Tiller | 0ca9952 | 2015-12-09 16:31:05 -0800 | [diff] [blame] | 120 | GRPC_BAD_CLIENT_DISCONNECT); |
Craig Tiller | 3c26d09 | 2015-06-05 14:48:30 -0700 | [diff] [blame] | 121 | |
| 122 | return 0; |
| 123 | } |