Debian Codegraph @

tests/fuzz/ssh_bind_config_fuzzer.c

raw
1 /*
2 * Copyright 2021 Jakub Jelen <[email protected]>
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <assert.h>
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21
22 #define LIBSSH_STATIC 1
23 #include "libssh/libssh.h"
24 #include "libssh/server.h"
25 #include "libssh/bind_config.h"
26
27 #include "nallocinc.c"
28
29 static void _fuzz_finalize(void)
30 {
31 ssh_finalize();
32 }
33
34 int LLVMFuzzerInitialize(int *argc, char ***argv)
35 {
36 (void)argc;
37
38 nalloc_init(*argv[0]);
39
40 ssh_init();
41
42 atexit(_fuzz_finalize);
43
44 return 0;
45 }
46
47 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
48 {
49 ssh_bind bind = NULL;
50 char *input = NULL;
51
52 input = (char *)malloc(size + 1);
53 if (!input) {
54 return 1;
55 }
56 strncpy(input, (const char *)data, size);
57 input[size] = '\0';
58
59 assert(nalloc_start(data, size) > 0);
60
61 bind = ssh_bind_new();
62 if (bind == NULL) {
63 goto out;
64 }
65
66 ssh_bind_config_parse_string(bind, input);
67
68 ssh_bind_free(bind);
69
70 out:
71 free(input);
72
73 nalloc_end();
74 return 0;
75 }