/src/yara/tests/oss-fuzz/elf_fuzzer.cc
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | Copyright (c) 2017. The YARA Authors. All Rights Reserved. |
3 | | |
4 | | Redistribution and use in source and binary forms, with or without modification, |
5 | | are permitted provided that the following conditions are met: |
6 | | |
7 | | 1. Redistributions of source code must retain the above copyright notice, this |
8 | | list of conditions and the following disclaimer. |
9 | | |
10 | | 2. Redistributions in binary form must reproduce the above copyright notice, |
11 | | this list of conditions and the following disclaimer in the documentation and/or |
12 | | other materials provided with the distribution. |
13 | | |
14 | | 3. Neither the name of the copyright holder nor the names of its contributors |
15 | | may be used to endorse or promote products derived from this software without |
16 | | specific prior written permission. |
17 | | |
18 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
19 | | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
20 | | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
21 | | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
22 | | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
23 | | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
24 | | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
25 | | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
27 | | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | | */ |
29 | | |
30 | | #include <stddef.h> |
31 | | #include <stdint.h> |
32 | | #include <yara.h> |
33 | | |
34 | | |
35 | | YR_RULES* rules = NULL; |
36 | | |
37 | | |
38 | | extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) |
39 | 10 | { |
40 | 10 | YR_COMPILER* compiler; |
41 | | |
42 | 10 | if (yr_initialize() != ERROR_SUCCESS) |
43 | 0 | return 0; |
44 | | |
45 | 10 | if (yr_compiler_create(&compiler) != ERROR_SUCCESS) |
46 | 0 | return 0; |
47 | | |
48 | 10 | if (yr_compiler_add_string(compiler, "import \"elf\"", NULL) == 0) |
49 | 10 | yr_compiler_get_rules(compiler, &rules); |
50 | | |
51 | 10 | yr_compiler_destroy(compiler); |
52 | | |
53 | 10 | return 0; |
54 | 10 | } |
55 | | |
56 | | |
57 | | int callback( |
58 | | YR_SCAN_CONTEXT* context, |
59 | | int message, |
60 | | void* message_data, |
61 | | void* user_data) |
62 | 75.4k | { |
63 | 75.4k | return CALLBACK_CONTINUE; |
64 | 75.4k | } |
65 | | |
66 | | |
67 | | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) |
68 | 21.3k | { |
69 | 21.3k | if (rules == NULL) |
70 | 0 | return 0; |
71 | | |
72 | 21.3k | yr_rules_scan_mem( |
73 | 21.3k | rules, data, size, SCAN_FLAGS_NO_TRYCATCH, callback, NULL, 0); |
74 | | |
75 | 21.3k | return 0; |
76 | 21.3k | } |