Coverage Report

Created: 2023-09-25 07:13

/src/yara/tests/oss-fuzz/rules_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 <string.h>
33
#include <yara.h>
34
35
36
extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv)
37
2
{
38
2
  yr_initialize();
39
2
  return 0;
40
2
}
41
42
43
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
44
1.35k
{
45
1.35k
  YR_RULES* rules;
46
1.35k
  YR_COMPILER* compiler;
47
48
1.35k
  char* buffer = (char*) malloc(size + 1);
49
50
1.35k
  if (!buffer)
51
0
    return 0;
52
53
1.35k
  strncpy(buffer, (const char*) data, size);
54
1.35k
  buffer[size] = 0;
55
56
1.35k
  if (yr_compiler_create(&compiler) != ERROR_SUCCESS)
57
0
  {
58
0
    free(buffer);
59
0
    return 0;
60
0
  }
61
62
1.35k
  if (yr_compiler_add_string(compiler, (const char*) buffer, NULL) == 0)
63
97
  {
64
97
    if (yr_compiler_get_rules(compiler, &rules) == ERROR_SUCCESS)
65
97
      yr_rules_destroy(rules);
66
97
  }
67
68
1.35k
  yr_compiler_destroy(compiler);
69
1.35k
  free(buffer);
70
71
1.35k
  return 0;
72
1.35k
}