Debian Codegraph @

crt/s2n/tests/fuzz/s2n_extensions_client_supported_versions_recv_test.c

raw symbols SCIP
1
2 /*
3 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License").
6 * You may not use this file except in compliance with the License.
7 * A copy of the License is located at
8 *
9 * http://aws.amazon.com/apache2.0
10 *
11 * or in the "license" file accompanying this file. This file is distributed
12 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13 * express or implied. See the License for the specific language governing
14 * permissions and limitations under the License.
15 */
16
17 /* Target Functions: s2n_extensions_client_supported_versions_recv s2n_extensions_client_supported_versions_process
18 s2n_connection_get_minimum_supported_version */
19
20 #include <stdint.h>
21
22 #include <openssl/crypto.h>
23 #include <openssl/err.h>
24
25 #include "tls/extensions/s2n_client_supported_versions.h"
26
27 #include "api/s2n.h"
28 #include "stuffer/s2n_stuffer.h"
29 #include "tls/s2n_connection.h"
30 #include "tls/s2n_tls.h"
31 #include "utils/s2n_safety.h"
32 #include "s2n_test.h"
33 #include "testlib/s2n_testlib.h"
34 #include "tls/s2n_tls13.h"
35
36 /* This test is for TLS versions 1.3 and up only */
37 static const uint8_t TLS_VERSIONS[] = {S2N_TLS13};
38
39 int s2n_fuzz_init(int *argc, char **argv[])
40 {
41 POSIX_GUARD(s2n_enable_tls13_in_test());
42 return S2N_SUCCESS;
43 }
44
45 int s2n_fuzz_test(const uint8_t *buf, size_t len)
46 {
47 /* We need at least one byte of input to set parameters */
48 S2N_FUZZ_ENSURE_MIN_LEN(len, 1);
49
50 /* Setup */
51 struct s2n_stuffer fuzz_stuffer = {0};
52 POSIX_GUARD(s2n_stuffer_alloc(&fuzz_stuffer, len));
53 POSIX_GUARD(s2n_stuffer_write_bytes(&fuzz_stuffer, buf, len));
54
55 struct s2n_connection *server_conn = s2n_connection_new(S2N_SERVER);
56 POSIX_ENSURE_REF(server_conn);
57
58 /* Pull a byte off the libfuzzer input and use it to set parameters */
59 uint8_t randval = 0;
60 POSIX_GUARD(s2n_stuffer_read_uint8(&fuzz_stuffer, &randval));
61 server_conn->server_protocol_version = TLS_VERSIONS[randval % s2n_array_len(TLS_VERSIONS)];
62
63 server_conn->config = s2n_config_new();
64
65 /* Run Test
66 * Do not use GUARD macro here since the connection memory hasn't been freed.
67 */
68 s2n_extensions_client_supported_versions_recv(server_conn, &fuzz_stuffer);
69
70 /* Cleanup */
71 POSIX_GUARD(s2n_config_free(server_conn->config));
72 POSIX_GUARD(s2n_connection_free(server_conn));
73 POSIX_GUARD(s2n_stuffer_free(&fuzz_stuffer));
74
75 return S2N_SUCCESS;
76 }
77
78 S2N_FUZZ_TARGET(s2n_fuzz_init, s2n_fuzz_test, NULL)
79