Merge pull request #18284 from yang-g/fuzzer

Fix fuzzer test
pull/18319/head
Yang Gao 6 years ago committed by GitHub
commit c5311260fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      src/core/lib/gpr/cpu_posix.cc
  2. 1
      test/core/slice/percent_decode_corpus/clusterfuzz-testcase-minimized-grpc_percent_decode_fuzzer-5652313562808320
  3. 27
      test/core/slice/percent_decode_fuzzer.cc
  4. 34
      test/core/slice/percent_encode_fuzzer.cc
  5. 23
      tools/run_tests/generated/tests.json

@ -25,7 +25,6 @@
#include <string.h>
#include <unistd.h>
#include <grpc/support/alloc.h>
#include <grpc/support/cpu.h>
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
@ -52,7 +51,7 @@ unsigned gpr_cpu_num_cores(void) {
static void delete_thread_id(void* value) {
if (value) {
gpr_free(value);
free(value);
}
}
@ -71,7 +70,10 @@ unsigned gpr_cpu_current_cpu(void) {
unsigned int* thread_id =
static_cast<unsigned int*>(pthread_getspecific(thread_id_key));
if (thread_id == nullptr) {
thread_id = static_cast<unsigned int*>(gpr_malloc(sizeof(unsigned int)));
// Note we cannot use gpr_malloc here because this allocation can happen in
// a main thread and will only be free'd when the main thread exits, which
// will cause our internal memory counters to believe it is a leak.
thread_id = static_cast<unsigned int*>(malloc(sizeof(unsigned int)));
pthread_setspecific(thread_id_key, thread_id);
}

@ -31,23 +31,20 @@ bool squelch = true;
bool leak_check = true;
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
grpc_core::testing::LeakDetector leak_detector(true);
grpc_init();
{
grpc_core::testing::LeakDetector leak_detector(true);
grpc_slice input = grpc_slice_from_copied_buffer((const char*)data, size);
grpc_slice output;
if (grpc_strict_percent_decode_slice(
input, grpc_url_percent_encoding_unreserved_bytes, &output)) {
grpc_slice_unref(output);
}
if (grpc_strict_percent_decode_slice(
input, grpc_compatible_percent_encoding_unreserved_bytes,
&output)) {
grpc_slice_unref(output);
}
grpc_slice_unref(grpc_permissive_percent_decode_slice(input));
grpc_slice_unref(input);
grpc_slice input = grpc_slice_from_copied_buffer((const char*)data, size);
grpc_slice output;
if (grpc_strict_percent_decode_slice(
input, grpc_url_percent_encoding_unreserved_bytes, &output)) {
grpc_slice_unref(output);
}
if (grpc_strict_percent_decode_slice(
input, grpc_compatible_percent_encoding_unreserved_bytes, &output)) {
grpc_slice_unref(output);
}
grpc_slice_unref(grpc_permissive_percent_decode_slice(input));
grpc_slice_unref(input);
grpc_shutdown_blocking();
return 0;
}

@ -31,25 +31,23 @@ bool squelch = true;
bool leak_check = true;
static void test(const uint8_t* data, size_t size, const uint8_t* dict) {
grpc_core::testing::LeakDetector leak_detector(true);
grpc_init();
{
grpc_core::testing::LeakDetector leak_detector(true);
grpc_slice input = grpc_slice_from_copied_buffer(
reinterpret_cast<const char*>(data), size);
grpc_slice output = grpc_percent_encode_slice(input, dict);
grpc_slice decoded_output;
// encoder must always produce decodable output
GPR_ASSERT(grpc_strict_percent_decode_slice(output, dict, &decoded_output));
grpc_slice permissive_decoded_output =
grpc_permissive_percent_decode_slice(output);
// and decoded output must always match the input
GPR_ASSERT(grpc_slice_eq(input, decoded_output));
GPR_ASSERT(grpc_slice_eq(input, permissive_decoded_output));
grpc_slice_unref(input);
grpc_slice_unref(output);
grpc_slice_unref(decoded_output);
grpc_slice_unref(permissive_decoded_output);
}
grpc_slice input =
grpc_slice_from_copied_buffer(reinterpret_cast<const char*>(data), size);
grpc_slice output = grpc_percent_encode_slice(input, dict);
grpc_slice decoded_output;
// encoder must always produce decodable output
GPR_ASSERT(grpc_strict_percent_decode_slice(output, dict, &decoded_output));
grpc_slice permissive_decoded_output =
grpc_permissive_percent_decode_slice(output);
// and decoded output must always match the input
GPR_ASSERT(grpc_slice_eq(input, decoded_output));
GPR_ASSERT(grpc_slice_eq(input, permissive_decoded_output));
grpc_slice_unref(input);
grpc_slice_unref(output);
grpc_slice_unref(decoded_output);
grpc_slice_unref(permissive_decoded_output);
grpc_shutdown_blocking();
}

@ -169124,6 +169124,29 @@
],
"uses_polling": false
},
{
"args": [
"test/core/slice/percent_decode_corpus/clusterfuzz-testcase-minimized-grpc_percent_decode_fuzzer-5652313562808320"
],
"ci_platforms": [
"linux"
],
"cpu_cost": 0.1,
"exclude_configs": [
"tsan"
],
"exclude_iomgrs": [
"uv"
],
"flaky": false,
"language": "c",
"name": "percent_decode_fuzzer_one_entry",
"platforms": [
"mac",
"linux"
],
"uses_polling": false
},
{
"args": [
"test/core/slice/percent_decode_corpus/d5b2a7177339ba2b7ce2f60e5f4459bef1e72758"

Loading…
Cancel
Save