Debian Codegraph @

crt/aws-c-http/tests/fuzz/fuzz_h2_decoder_random.c

raw symbols SCIP
1 /**
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0.
4 */
5
6 #include <aws/http/private/h2_decoder.h>
7
8 #include <aws/testing/aws_test_harness.h>
9
10 #include <aws/common/allocator.h>
11 #include <aws/common/logging.h>
12
13 AWS_EXTERN_C_BEGIN
14
15 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
16
17 /* Setup allocator and parameters */
18 struct aws_allocator *allocator = aws_mem_tracer_new(aws_default_allocator(), NULL, AWS_MEMTRACE_BYTES, 0);
19 struct aws_byte_cursor to_decode = aws_byte_cursor_from_array(data, size);
20
21 /* Enable logging */
22 struct aws_logger logger;
23 struct aws_logger_standard_options log_options = {
24 .level = AWS_LL_TRACE,
25 .file = stdout,
26 };
27 aws_logger_init_standard(&logger, allocator, &log_options);
28 aws_logger_set(&logger);
29
30 /* Init HTTP (s2n init is weird, so don't do this under the tracer) */
31 aws_http_library_init(aws_default_allocator());
32
33 /* Create the decoder */
34 struct aws_h2_decoder_vtable decoder_vtable = {0};
35 struct aws_h2_decoder_params decoder_params = {
36 .alloc = allocator,
37 .vtable = &decoder_vtable,
38 .skip_connection_preface = true,
39 };
40 struct aws_h2_decoder *decoder = aws_h2_decoder_new(&decoder_params);
41
42 /* Decode whatever we got */
43 aws_h2_decode(decoder, &to_decode);
44
45 /* Clean up */
46 aws_h2_decoder_destroy(decoder);
47 aws_logger_set(NULL);
48 aws_logger_clean_up(&logger);
49
50 atexit(aws_http_library_clean_up);
51
52 /* Check for leaks */
53 ASSERT_UINT_EQUALS(0, aws_mem_tracer_count(allocator));
54 allocator = aws_mem_tracer_destroy(allocator);
55
56 return 0;
57 }
58
59 AWS_EXTERN_C_END