Switch from snprintf() to gpr_asprintf().

pull/6567/head
Mark D. Roth 9 years ago
parent 0eb3e13ea2
commit 5eba7971fb
  1. 35
      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,8 +65,7 @@
// 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"
@ -79,8 +79,8 @@
// 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)
((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",
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);
offset += PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_SIZE;
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,

Loading…
Cancel
Save