diff options
author | Mark D. Roth <roth@google.com> | 2016-05-12 14:02:03 -0700 |
---|---|---|
committer | Mark D. Roth <roth@google.com> | 2016-05-12 14:02:03 -0700 |
commit | 5eba7971fbb719b49039003e59508c4ccdae9cb1 (patch) | |
tree | 7bba4ac2353e023606442db37f27037b24dfcf16 /test | |
parent | 0eb3e13ea2c73a3de318c7a8297570fa2c6cdd85 (diff) |
Switch from snprintf() to gpr_asprintf().
Diffstat (limited to 'test')
-rw-r--r-- | test/core/bad_client/tests/large_metadata.c | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/test/core/bad_client/tests/large_metadata.c b/test/core/bad_client/tests/large_metadata.c index b2a900ecd8..b7d329cb74 100644 --- a/test/core/bad_client/tests/large_metadata.c +++ b/test/core/bad_client/tests/large_metadata.c @@ -33,10 +33,11 @@ #include "test/core/bad_client/bad_client.h" -#include <stdio.h> #include <string.h> #include <grpc/support/alloc.h> +#include <grpc/support/string_util.h> +#include "src/core/lib/support/string.h" #include "src/core/lib/surface/server.h" #include "test/core/end2end/cq_verifier.h" @@ -64,23 +65,22 @@ // Each large-metadata header is constructed from these start and end // strings, with a two-digit number in between. -#define PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_START_STR \ - "\x10\x0duser-header" +#define PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_START_STR "\x10\x0duser-header" #define PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_END_STR \ "~aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" // The size of each large-metadata header string. -#define PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_SIZE \ +#define PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_SIZE \ ((sizeof(PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_START_STR) - 1) + 2 + \ (sizeof(PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_END_STR) - 1)) // The number of headers we're adding and the total size of the client // payload. #define NUM_HEADERS 95 -#define PFX_TOO_MUCH_METADATA_FROM_CLIENT_PAYLOAD_SIZE \ - ((sizeof(PFX_TOO_MUCH_METADATA_FROM_CLIENT_PREFIX_STR) - 1) \ - + (NUM_HEADERS * PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_SIZE) + 1) +#define PFX_TOO_MUCH_METADATA_FROM_CLIENT_PAYLOAD_SIZE \ + ((sizeof(PFX_TOO_MUCH_METADATA_FROM_CLIENT_PREFIX_STR) - 1) + \ + (NUM_HEADERS * PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_SIZE) + 1) #define PFX_TOO_MUCH_METADATA_FROM_SERVER_STR \ "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" /* settings frame: sets \ @@ -217,19 +217,26 @@ int main(int argc, char **argv) { grpc_test_init(argc, argv); // Test sending more metadata than the server will accept. - char client_payload[PFX_TOO_MUCH_METADATA_FROM_CLIENT_PAYLOAD_SIZE] = - PFX_TOO_MUCH_METADATA_FROM_CLIENT_PREFIX_STR; - size_t offset = sizeof(PFX_TOO_MUCH_METADATA_FROM_CLIENT_PREFIX_STR); + gpr_strvec headers; + gpr_strvec_init(&headers); for (int i = 0; i < NUM_HEADERS; ++i) { - snprintf(client_payload + offset, - PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_SIZE, - "%s%02d%s", - PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_START_STR, i, - PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_END_STR); - offset += PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_SIZE; + char *str; + gpr_asprintf(&str, "%s%02d%s", + PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_START_STR, i, + PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_END_STR); + gpr_strvec_add(&headers, str); } - GRPC_RUN_BAD_CLIENT_TEST(server_verifier, client_validator, - client_payload, 0); + size_t headers_len; + const char *client_headers = gpr_strvec_flatten(&headers, &headers_len); + gpr_strvec_destroy(&headers); + char client_payload[PFX_TOO_MUCH_METADATA_FROM_CLIENT_PAYLOAD_SIZE] = + PFX_TOO_MUCH_METADATA_FROM_CLIENT_PREFIX_STR; + memcpy( + client_payload + sizeof(PFX_TOO_MUCH_METADATA_FROM_CLIENT_PREFIX_STR) - 1, + client_headers, headers_len); + GRPC_RUN_BAD_CLIENT_TEST(server_verifier, client_validator, client_payload, + 0); + gpr_free((void *)client_headers); // Test sending more metadata than the client will accept. GRPC_RUN_BAD_CLIENT_TEST(server_verifier_sends_too_much_metadata, |