aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/json
diff options
context:
space:
mode:
authorGravatar Nicolas Noble <nicolasnoble@users.noreply.github.com>2016-03-31 20:51:30 -0700
committerGravatar Nicolas Noble <nicolasnoble@users.noreply.github.com>2016-03-31 20:51:30 -0700
commit7661da5b417130262ded988b2f881ab619d3b244 (patch)
treef1352eb0330865fc6fdd306a2cfd6dc0a86adb73 /test/core/json
parentd0fbba52d6e379b76a69016bc264b96a2318315f (diff)
parent959b6f52cda3555a92e8a7c52f213560960ce614 (diff)
Merge pull request #6012 from nicolasnoble/memleak_detector
Adding memory leak detections for the json fuzzer.
Diffstat (limited to 'test/core/json')
-rw-r--r--test/core/json/corpus/15a8f2e7f94aa00b46f1b991416aa015dd6335801
-rw-r--r--test/core/json/corpus/56cd60743c2cee939f5f357905bd36ec9363f4411
-rw-r--r--test/core/json/corpus/743e89b768af4bd591ea7228118550b1bfb8e7d11
-rw-r--r--test/core/json/corpus/775e8ffda1f5d340dba472d06dc7c8bf8159e3791
-rw-r--r--test/core/json/corpus/8d952ec2e33b2a6a1c7876898719a610f55463881
-rw-r--r--test/core/json/corpus/a0d4af29c6c223b48fe34d6a09b3a7466242f33c1
-rw-r--r--test/core/json/fuzzer.c39
-rw-r--r--test/core/json/json_test.c2
8 files changed, 46 insertions, 1 deletions
diff --git a/test/core/json/corpus/15a8f2e7f94aa00b46f1b991416aa015dd633580 b/test/core/json/corpus/15a8f2e7f94aa00b46f1b991416aa015dd633580
new file mode 100644
index 0000000000..7e613e891d
--- /dev/null
+++ b/test/core/json/corpus/15a8f2e7f94aa00b46f1b991416aa015dd633580
@@ -0,0 +1 @@
+{"":21} \ No newline at end of file
diff --git a/test/core/json/corpus/56cd60743c2cee939f5f357905bd36ec9363f441 b/test/core/json/corpus/56cd60743c2cee939f5f357905bd36ec9363f441
new file mode 100644
index 0000000000..8d53a05e08
--- /dev/null
+++ b/test/core/json/corpus/56cd60743c2cee939f5f357905bd36ec9363f441
@@ -0,0 +1 @@
+{"":21] \ No newline at end of file
diff --git a/test/core/json/corpus/743e89b768af4bd591ea7228118550b1bfb8e7d1 b/test/core/json/corpus/743e89b768af4bd591ea7228118550b1bfb8e7d1
new file mode 100644
index 0000000000..b232065b09
--- /dev/null
+++ b/test/core/json/corpus/743e89b768af4bd591ea7228118550b1bfb8e7d1
@@ -0,0 +1 @@
+{"":0}f'+G{)13(§!(''\! \ No newline at end of file
diff --git a/test/core/json/corpus/775e8ffda1f5d340dba472d06dc7c8bf8159e379 b/test/core/json/corpus/775e8ffda1f5d340dba472d06dc7c8bf8159e379
new file mode 100644
index 0000000000..6f56d403bb
--- /dev/null
+++ b/test/core/json/corpus/775e8ffda1f5d340dba472d06dc7c8bf8159e379
@@ -0,0 +1 @@
+{"":0},f'+G{)23(§!''! \ No newline at end of file
diff --git a/test/core/json/corpus/8d952ec2e33b2a6a1c7876898719a610f5546388 b/test/core/json/corpus/8d952ec2e33b2a6a1c7876898719a610f5546388
new file mode 100644
index 0000000000..fb7475be91
--- /dev/null
+++ b/test/core/json/corpus/8d952ec2e33b2a6a1c7876898719a610f5546388
@@ -0,0 +1 @@
+{"":0]f'+G{)13(§!(''\! \ No newline at end of file
diff --git a/test/core/json/corpus/a0d4af29c6c223b48fe34d6a09b3a7466242f33c b/test/core/json/corpus/a0d4af29c6c223b48fe34d6a09b3a7466242f33c
new file mode 100644
index 0000000000..db616e9f56
--- /dev/null
+++ b/test/core/json/corpus/a0d4af29c6c223b48fe34d6a09b3a7466242f33c
@@ -0,0 +1 @@
+{"":0],f'`+G{-22(§!''! \ No newline at end of file
diff --git a/test/core/json/fuzzer.c b/test/core/json/fuzzer.c
index a7b9e49878..044db973ab 100644
--- a/test/core/json/fuzzer.c
+++ b/test/core/json/fuzzer.c
@@ -35,16 +35,53 @@
#include <string.h>
#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
#include "src/core/lib/json/json.h"
+static size_t g_total_size = 0;
+static gpr_allocation_functions g_old_allocs;
+
+void *guard_malloc(size_t size) {
+ size_t *ptr;
+ g_total_size += size;
+ ptr = g_old_allocs.malloc_fn(size + sizeof(size));
+ *ptr++ = size;
+ return ptr;
+}
+
+void *guard_realloc(void *vptr, size_t size) {
+ size_t *ptr = vptr;
+ --ptr;
+ g_total_size -= *ptr;
+ ptr = g_old_allocs.realloc_fn(ptr, size + sizeof(size));
+ g_total_size += size;
+ *ptr++ = size;
+ return ptr;
+}
+
+void guard_free(void *vptr) {
+ size_t *ptr = vptr;
+ --ptr;
+ g_total_size -= *ptr;
+ g_old_allocs.free_fn(ptr);
+}
+
+struct gpr_allocation_functions g_guard_allocs = {guard_malloc, guard_realloc,
+ guard_free};
+
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
- char *s = gpr_malloc(size);
+ char *s;
+ g_old_allocs = gpr_get_allocation_functions();
+ gpr_set_allocation_functions(g_guard_allocs);
+ s = gpr_malloc(size);
memcpy(s, data, size);
grpc_json *x;
if ((x = grpc_json_parse_string_with_len(s, size))) {
grpc_json_destroy(x);
}
gpr_free(s);
+ gpr_set_allocation_functions(g_old_allocs);
+ GPR_ASSERT(g_total_size == 0);
return 0;
}
diff --git a/test/core/json/json_test.c b/test/core/json/json_test.c
index 9775779e3b..ac1abbd8f3 100644
--- a/test/core/json/json_test.c
+++ b/test/core/json/json_test.c
@@ -89,6 +89,8 @@ static testing_pair testing_pairs[] = {
{"{\"foo\": bar}", NULL},
{"{\"foo\": bar\"x\"}", NULL},
{"fals", NULL},
+ {"0,0 ", NULL},
+ {"\"foo\",[]", NULL},
/* Testing unterminated string. */
{"\"\\x", NULL},
/* Testing invalid UTF-16 number. */