Add incldues, fix function names

reviewable/pr8532/r1
Craig Tiller 8 years ago
parent a73537e490
commit e4222b4cbd
  1. 16
      src/core/lib/slice/percent_encoding.c
  2. 20
      src/core/lib/slice/percent_encoding.h
  3. 9
      test/core/end2end/bad_server_response_test.c
  4. 2
      test/core/end2end/dualstack_socket_test.c
  5. 1
      test/core/security/security_connector_test.c
  6. 10
      test/core/slice/percent_decode_fuzzer.c
  7. 10
      test/core/slice/percent_encode_fuzzer.c
  8. 42
      test/core/slice/percent_encoding_test.c
  9. 5
      test/core/transport/chttp2/bin_encoder_test.c
  10. 1
      test/core/transport/chttp2/hpack_encoder_test.c
  11. 4
      tools/codegen/core/gen_percent_encoding_tables.c

@ -35,11 +35,11 @@
#include <grpc/support/log.h>
const uint8_t gpr_url_percent_encoding_unreserved_bytes[256 / 8] = {
const uint8_t grpc_url_percent_encoding_unreserved_bytes[256 / 8] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xff, 0x03, 0xfe, 0xff, 0xff,
0x87, 0xfe, 0xff, 0xff, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
const uint8_t gpr_compatible_percent_encoding_unreserved_bytes[256 / 8] = {
const uint8_t grpc_compatible_percent_encoding_unreserved_bytes[256 / 8] = {
0x00, 0x00, 0x00, 0x00, 0xdf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
@ -49,8 +49,8 @@ static bool is_unreserved_character(uint8_t c,
return ((unreserved_bytes[c / 8] >> (c % 8)) & 1) != 0;
}
grpc_slice gpr_percent_encode_slice(grpc_slice slice,
const uint8_t *unreserved_bytes) {
grpc_slice grpc_percent_encode_slice(grpc_slice slice,
const uint8_t *unreserved_bytes) {
static const uint8_t hex[] = "0123456789ABCDEF";
// first pass: count the number of bytes needed to output this string
@ -97,9 +97,9 @@ static uint8_t dehex(uint8_t c) {
GPR_UNREACHABLE_CODE(return 255);
}
bool gpr_strict_percent_decode_slice(grpc_slice slice_in,
const uint8_t *unreserved_bytes,
grpc_slice *slice_out) {
bool grpc_strict_percent_decode_slice(grpc_slice slice_in,
const uint8_t *unreserved_bytes,
grpc_slice *slice_out) {
const uint8_t *p = GPR_SLICE_START_PTR(slice_in);
const uint8_t *in_end = GPR_SLICE_END_PTR(slice_in);
size_t out_length = 0;
@ -137,7 +137,7 @@ bool gpr_strict_percent_decode_slice(grpc_slice slice_in,
return true;
}
grpc_slice gpr_permissive_percent_decode_slice(grpc_slice slice_in) {
grpc_slice grpc_permissive_percent_decode_slice(grpc_slice slice_in) {
const uint8_t *p = GPR_SLICE_START_PTR(slice_in);
const uint8_t *in_end = GPR_SLICE_END_PTR(slice_in);
size_t out_length = 0;

@ -46,33 +46,33 @@
#include <grpc/slice.h>
/* URL percent encoding spec bitfield (usabel as 'unreserved_bytes' in
gpr_percent_encode_slice, gpr_strict_percent_decode_slice).
grpc_percent_encode_slice, grpc_strict_percent_decode_slice).
Flags [A-Za-z0-9-_.~] as unreserved bytes for the percent encoding routines
*/
extern const uint8_t gpr_url_percent_encoding_unreserved_bytes[256 / 8];
extern const uint8_t grpc_url_percent_encoding_unreserved_bytes[256 / 8];
/* URL percent encoding spec bitfield (usabel as 'unreserved_bytes' in
gpr_percent_encode_slice, gpr_strict_percent_decode_slice).
grpc_percent_encode_slice, grpc_strict_percent_decode_slice).
Flags ascii7 non-control characters excluding '%' as unreserved bytes for the
percent encoding routines */
extern const uint8_t gpr_compatible_percent_encoding_unreserved_bytes[256 / 8];
extern const uint8_t grpc_compatible_percent_encoding_unreserved_bytes[256 / 8];
/* Percent-encode a slice, returning the new slice (this cannot fail):
unreserved_bytes is a bitfield indicating which bytes are considered
unreserved and thus do not need percent encoding */
grpc_slice gpr_percent_encode_slice(grpc_slice slice,
const uint8_t *unreserved_bytes);
grpc_slice grpc_percent_encode_slice(grpc_slice slice,
const uint8_t *unreserved_bytes);
/* Percent-decode a slice, strictly.
If the input is legal (contains no unreserved bytes, and legal % encodings),
returns true and sets *slice_out to the decoded slice.
If the input is not legal, returns false and leaves *slice_out untouched.
unreserved_bytes is a bitfield indicating which bytes are considered
unreserved and thus do not need percent encoding */
bool gpr_strict_percent_decode_slice(grpc_slice slice_in,
const uint8_t *unreserved_bytes,
grpc_slice *slice_out);
bool grpc_strict_percent_decode_slice(grpc_slice slice_in,
const uint8_t *unreserved_bytes,
grpc_slice *slice_out);
/* Percent-decode a slice, permissively.
If a % triplet can not be decoded, pass it through verbatim.
This cannot fail. */
grpc_slice gpr_permissive_percent_decode_slice(grpc_slice slice_in);
grpc_slice grpc_permissive_percent_decode_slice(grpc_slice slice_in);
#endif /* GRPC_CORE_LIB_SUPPORT_PERCENT_ENCODING_H */

@ -33,14 +33,15 @@
#include <string.h>
#include <grpc/grpc.h>
#include <grpc/slice.h>
#include <grpc/support/alloc.h>
#include <grpc/support/host_port.h>
#include <grpc/support/log.h>
#include <grpc/slice.h>
#include <grpc/support/thd.h>
// #include "src/core/ext/transport/chttp2/transport/internal.h"
#include "src/core/lib/iomgr/sockaddr.h"
#include "src/core/lib/slice/slice_string_helpers.h"
#include "src/core/lib/support/string.h"
#include "test/core/end2end/cq_verifier.h"
#include "test/core/util/port.h"
@ -105,8 +106,8 @@ static void done_write(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
}
static void handle_write(grpc_exec_ctx *exec_ctx) {
grpc_slice slice = grpc_slice_from_copied_buffer(state.response_payload,
state.response_payload_length);
grpc_slice slice = grpc_slice_from_copied_buffer(
state.response_payload, state.response_payload_length);
grpc_slice_buffer_reset_and_unref(&state.outgoing_buffer);
grpc_slice_buffer_add(&state.outgoing_buffer, slice);
@ -120,7 +121,7 @@ static void handle_read(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
size_t i;
for (i = 0; i < state.temp_incoming_buffer.count; i++) {
char *dump = grpc_dump_slice(state.temp_incoming_buffer.slices[i],
GPR_DUMP_HEX | GPR_DUMP_ASCII);
GPR_DUMP_HEX | GPR_DUMP_ASCII);
gpr_log(GPR_DEBUG, "Server received: %s", dump);
gpr_free(dump);
}

@ -41,8 +41,8 @@
#include "src/core/lib/iomgr/resolve_address.h"
#include "src/core/lib/iomgr/socket_utils_posix.h"
#include "src/core/lib/slice/slice_string_helpers.h"
#include "src/core/lib/support/string.h"
#include "test/core/end2end/cq_verifier.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"

@ -42,6 +42,7 @@
#include "src/core/lib/security/context/security_context.h"
#include "src/core/lib/security/transport/security_connector.h"
#include "src/core/lib/slice/slice_string_helpers.h"
#include "src/core/lib/support/env.h"
#include "src/core/lib/support/string.h"
#include "src/core/lib/support/tmpfile.h"

@ -49,15 +49,15 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
grpc_memory_counters_init();
grpc_slice input = grpc_slice_from_copied_buffer((const char *)data, size);
grpc_slice output;
if (gpr_strict_percent_decode_slice(
input, gpr_url_percent_encoding_unreserved_bytes, &output)) {
if (grpc_strict_percent_decode_slice(
input, grpc_url_percent_encoding_unreserved_bytes, &output)) {
grpc_slice_unref(output);
}
if (gpr_strict_percent_decode_slice(
input, gpr_compatible_percent_encoding_unreserved_bytes, &output)) {
if (grpc_strict_percent_decode_slice(
input, grpc_compatible_percent_encoding_unreserved_bytes, &output)) {
grpc_slice_unref(output);
}
grpc_slice_unref(gpr_permissive_percent_decode_slice(input));
grpc_slice_unref(grpc_permissive_percent_decode_slice(input));
grpc_slice_unref(input);
counters = grpc_memory_counters_snapshot();
grpc_memory_counters_destroy();

@ -48,12 +48,12 @@ static void test(const uint8_t *data, size_t size, const uint8_t *dict) {
struct grpc_memory_counters counters;
grpc_memory_counters_init();
grpc_slice input = grpc_slice_from_copied_buffer((const char *)data, size);
grpc_slice output = gpr_percent_encode_slice(input, dict);
grpc_slice output = grpc_percent_encode_slice(input, dict);
grpc_slice decoded_output;
// encoder must always produce decodable output
GPR_ASSERT(gpr_strict_percent_decode_slice(output, dict, &decoded_output));
GPR_ASSERT(grpc_strict_percent_decode_slice(output, dict, &decoded_output));
grpc_slice permissive_decoded_output =
gpr_permissive_percent_decode_slice(output);
grpc_permissive_percent_decode_slice(output);
// and decoded output must always match the input
GPR_ASSERT(grpc_slice_cmp(input, decoded_output) == 0);
GPR_ASSERT(grpc_slice_cmp(input, permissive_decoded_output) == 0);
@ -67,7 +67,7 @@ static void test(const uint8_t *data, size_t size, const uint8_t *dict) {
}
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
test(data, size, gpr_url_percent_encoding_unreserved_bytes);
test(data, size, gpr_compatible_percent_encoding_unreserved_bytes);
test(data, size, grpc_url_percent_encoding_unreserved_bytes);
test(data, size, grpc_compatible_percent_encoding_unreserved_bytes);
return 0;
}

@ -60,12 +60,12 @@ static void test_vector(const char *raw, size_t raw_length, const char *encoded,
grpc_slice raw_slice = grpc_slice_from_copied_buffer(raw, raw_length);
grpc_slice encoded_slice =
grpc_slice_from_copied_buffer(encoded, encoded_length);
grpc_slice raw2encoded_slice = gpr_percent_encode_slice(raw_slice, dict);
grpc_slice raw2encoded_slice = grpc_percent_encode_slice(raw_slice, dict);
grpc_slice encoded2raw_slice;
GPR_ASSERT(
gpr_strict_percent_decode_slice(encoded_slice, dict, &encoded2raw_slice));
GPR_ASSERT(grpc_strict_percent_decode_slice(encoded_slice, dict,
&encoded2raw_slice));
grpc_slice encoded2raw_permissive_slice =
gpr_permissive_percent_decode_slice(encoded_slice);
grpc_permissive_percent_decode_slice(encoded_slice);
char *raw2encoded_msg =
grpc_dump_slice(raw2encoded_slice, GPR_DUMP_HEX | GPR_DUMP_ASCII);
@ -112,10 +112,10 @@ static void test_nonconformant_vector(const char *encoded,
grpc_slice encoded_slice =
grpc_slice_from_copied_buffer(encoded, encoded_length);
grpc_slice encoded2raw_slice;
GPR_ASSERT(!gpr_strict_percent_decode_slice(encoded_slice, dict,
&encoded2raw_slice));
GPR_ASSERT(!grpc_strict_percent_decode_slice(encoded_slice, dict,
&encoded2raw_slice));
grpc_slice encoded2raw_permissive_slice =
gpr_permissive_percent_decode_slice(encoded_slice);
grpc_permissive_percent_decode_slice(encoded_slice);
char *encoded2raw_permissive_msg = grpc_dump_slice(
encoded2raw_permissive_slice, GPR_DUMP_HEX | GPR_DUMP_ASCII);
@ -136,23 +136,23 @@ int main(int argc, char **argv) {
TEST_VECTOR(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~",
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~",
gpr_url_percent_encoding_unreserved_bytes);
TEST_VECTOR("\x00", "%00", gpr_url_percent_encoding_unreserved_bytes);
TEST_VECTOR("\x01", "%01", gpr_url_percent_encoding_unreserved_bytes);
TEST_VECTOR("a b", "a%20b", gpr_url_percent_encoding_unreserved_bytes);
TEST_VECTOR(" b", "%20b", gpr_url_percent_encoding_unreserved_bytes);
TEST_VECTOR("a b", "a b", gpr_compatible_percent_encoding_unreserved_bytes);
TEST_VECTOR(" b", " b", gpr_compatible_percent_encoding_unreserved_bytes);
TEST_VECTOR("\x0f", "%0F", gpr_url_percent_encoding_unreserved_bytes);
TEST_VECTOR("\xff", "%FF", gpr_url_percent_encoding_unreserved_bytes);
TEST_VECTOR("\xee", "%EE", gpr_url_percent_encoding_unreserved_bytes);
grpc_url_percent_encoding_unreserved_bytes);
TEST_VECTOR("\x00", "%00", grpc_url_percent_encoding_unreserved_bytes);
TEST_VECTOR("\x01", "%01", grpc_url_percent_encoding_unreserved_bytes);
TEST_VECTOR("a b", "a%20b", grpc_url_percent_encoding_unreserved_bytes);
TEST_VECTOR(" b", "%20b", grpc_url_percent_encoding_unreserved_bytes);
TEST_VECTOR("a b", "a b", grpc_compatible_percent_encoding_unreserved_bytes);
TEST_VECTOR(" b", " b", grpc_compatible_percent_encoding_unreserved_bytes);
TEST_VECTOR("\x0f", "%0F", grpc_url_percent_encoding_unreserved_bytes);
TEST_VECTOR("\xff", "%FF", grpc_url_percent_encoding_unreserved_bytes);
TEST_VECTOR("\xee", "%EE", grpc_url_percent_encoding_unreserved_bytes);
TEST_NONCONFORMANT_VECTOR("%", "%",
gpr_url_percent_encoding_unreserved_bytes);
grpc_url_percent_encoding_unreserved_bytes);
TEST_NONCONFORMANT_VECTOR("%A", "%A",
gpr_url_percent_encoding_unreserved_bytes);
grpc_url_percent_encoding_unreserved_bytes);
TEST_NONCONFORMANT_VECTOR("%AG", "%AG",
gpr_url_percent_encoding_unreserved_bytes);
grpc_url_percent_encoding_unreserved_bytes);
TEST_NONCONFORMANT_VECTOR("\0", "\0",
gpr_url_percent_encoding_unreserved_bytes);
grpc_url_percent_encoding_unreserved_bytes);
return 0;
}

@ -41,6 +41,7 @@
#include <grpc/grpc.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/lib/slice/slice_string_helpers.h"
#include "src/core/lib/support/string.h"
static int all_ok = 1;
@ -74,8 +75,8 @@ static grpc_slice HUFF(const char *s) {
return out;
}
#define EXPECT_SLICE_EQ(expected, slice) \
expect_slice_eq( \
#define EXPECT_SLICE_EQ(expected, slice) \
expect_slice_eq( \
grpc_slice_from_copied_buffer(expected, sizeof(expected) - 1), slice, \
#slice, __LINE__);

@ -41,6 +41,7 @@
#include <grpc/support/string_util.h>
#include "src/core/ext/transport/chttp2/transport/hpack_parser.h"
#include "src/core/lib/slice/slice_string_helpers.h"
#include "src/core/lib/support/string.h"
#include "src/core/lib/transport/metadata.h"
#include "test/core/util/parse_hexstring.h"

@ -71,14 +71,14 @@ int main(void) {
legal('_');
legal('.');
legal('~');
dump("gpr_url_percent_encoding_unreserved_bytes");
dump("grpc_url_percent_encoding_unreserved_bytes");
clear();
for (i = 32; i <= 126; i++) {
if (i == '%') continue;
legal(i);
}
dump("gpr_compatible_percent_encoding_unreserved_bytes");
dump("grpc_compatible_percent_encoding_unreserved_bytes");
return 0;
}

Loading…
Cancel
Save