Skip to content

Commit 325481b

Browse files
author
Justin Boswell
authored
Reworked fuzzer to use mem tracer (#159)
* Rewrote fuzzer to use mem tracer
1 parent 722cc07 commit 325481b

File tree

2 files changed

+8
-23
lines changed

2 files changed

+8
-23
lines changed

tests/fuzz/fuzz_h2_decoder.c

+4-9
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,17 @@
1717

1818
#include <aws/testing/aws_test_harness.h>
1919

20+
#include <aws/common/allocator.h>
2021
#include <aws/common/logging.h>
2122

2223
AWS_EXTERN_C_BEGIN
2324

24-
AWS_TEST_ALLOCATOR_INIT(fuzz_h2_decoder)
25-
2625
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
2726

2827
/* Setup allocator and parameters */
29-
struct aws_allocator *allocator = &fuzz_h2_decoder_allocator;
30-
struct memory_test_allocator *alloc_impl = &fuzz_h2_decoder_alloc_impl;
28+
struct aws_allocator *allocator = aws_mem_tracer_new(aws_default_allocator(), AWS_MEMTRACE_BYTES, 0);
3129
struct aws_byte_cursor to_decode = aws_byte_cursor_from_array(data, size);
3230

33-
/* Reset the allocator's leak checker */
34-
alloc_impl->allocated = 0;
35-
alloc_impl->freed = 0;
36-
3731
/* Enable logging */
3832
struct aws_logger logger;
3933
struct aws_logger_standard_options log_options = {
@@ -62,7 +56,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
6256
aws_logger_clean_up(&logger);
6357

6458
/* Check for leaks */
65-
AWS_FATAL_ASSERT(alloc_impl->allocated == alloc_impl->freed);
59+
ASSERT_UINT_EQUALS(0, aws_mem_tracer_count(allocator));
60+
allocator = aws_mem_tracer_destroy(allocator);
6661

6762
return 0;
6863
}

tests/fuzz/fuzz_h2_frames.c

+4-14
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,16 @@
1616
#include <aws/http/private/h2_frames.h>
1717
#include <aws/http/private/hpack.h>
1818

19+
#include <aws/common/allocator.h>
1920
#include <aws/testing/aws_test_harness.h>
2021

2122
AWS_EXTERN_C_BEGIN
2223

23-
AWS_TEST_ALLOCATOR_INIT(fuzz_h2_frames)
24-
2524
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
2625

27-
struct aws_allocator *allocator = &fuzz_h2_frames_allocator;
28-
struct memory_test_allocator *alloc_impl = &fuzz_h2_frames_alloc_impl;
26+
struct aws_allocator *allocator = aws_mem_tracer_new(aws_default_allocator(), AWS_MEMTRACE_BYTES, 0);
2927
struct aws_byte_cursor to_decode = aws_byte_cursor_from_array(data, size);
3028

31-
AWS_ZERO_STRUCT(*alloc_impl);
32-
aws_mutex_init(&alloc_impl->mutex);
33-
3429
aws_hpack_static_table_init(allocator);
3530

3631
struct aws_h2_frame_decoder decoder;
@@ -108,13 +103,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
108103
aws_h2_frame_decoder_clean_up(&decoder);
109104
aws_hpack_static_table_clean_up();
110105

111-
ASSERT_UINT_EQUALS(
112-
alloc_impl->allocated,
113-
alloc_impl->freed,
114-
"Memory Leak Detected %d bytes were allocated, "
115-
"but only %d were freed.",
116-
alloc_impl->allocated,
117-
alloc_impl->freed);
106+
ASSERT_UINT_EQUALS(0, aws_mem_tracer_count(allocator), "Memory Leak Detected");
107+
allocator = aws_mem_tracer_destroy(allocator);
118108

119109
return 0;
120110
}

0 commit comments

Comments
 (0)