Coverage Report

Created: 2025-12-14 06:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fuzz_header.h
Line
Count
Source
1
/* Copyright 2025 Google LLC
2
Licensed under the Apache License, Version 2.0 (the "License");
3
you may not use this file except in compliance with the License.
4
You may obtain a copy of the License at
5
      http://www.apache.org/licenses/LICENSE-2.0
6
Unless required by applicable law or agreed to in writing, software
7
distributed under the License is distributed on an "AS IS" BASIS,
8
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9
See the License for the specific language governing permissions and
10
limitations under the License.
11
*/
12
13
#include <stdint.h>
14
#include <stdio.h>
15
#include <stdlib.h>
16
17
uint8_t *global_fuzz_data;
18
size_t global_size;
19
20
char *callback1 = NULL;
21
char *callback2 = NULL;
22
char *callback3 = NULL;
23
char *callback4 = NULL;
24
25
6.52k
void fuzz_init(const uint8_t *data, size_t size) {
26
6.52k
    global_fuzz_data = (uint8_t *)data;
27
6.52k
    global_size = size;
28
    
29
6.52k
    callback1 = NULL;
30
6.52k
    callback2 = NULL;
31
6.52k
    callback3 = NULL;
32
6.52k
    callback4 = NULL;
33
6.52k
}
34
35
#ifdef ENABLE_FILE_CALLBACK
36
6.19k
void create_callback_file(const char *filename) {
37
6.19k
  fprintf(stderr, "create_callback_file: Creating file %s\n", filename);
38
6.19k
  FILE *fp = fopen(filename, "wb");
39
6.19k
  if (!fp) {
40
160
    return;
41
160
  }
42
6.03k
  fwrite(global_fuzz_data, global_size, 1, fp);
43
6.03k
  fclose(fp);
44
45
6.03k
  if (callback1 == NULL) {
46
1.98k
    callback1 = strdup(filename);
47
4.05k
  } else if (callback2 == NULL) {
48
1.47k
    callback2 = strdup(filename);
49
2.58k
  } else if (callback3 == NULL) {
50
1.23k
    callback3 = strdup(filename);
51
1.35k
  } else if (callback4 == NULL) {
52
698
    callback4 = strdup(filename);
53
698
  } else {
54
657
    fprintf(stderr, "create_callback_file: Too many callbacks created, ignoring %s\n", filename);
55
657
  }
56
6.03k
}
57
58
#else
59
void create_callback_file(const char *filename) {}
60
#endif
61
62
6.52k
void fuzz_cleanup() {
63
6.52k
  if (callback1) {
64
1.98k
 unlink(callback1);    
65
1.98k
    free(callback1);
66
   
67
1.98k
    callback1 = NULL;
68
1.98k
  }
69
6.52k
  if (callback2) {
70
1.47k
 unlink(callback2);    
71
1.47k
    free(callback2);
72
1.47k
    callback2 = NULL;
73
1.47k
  }
74
6.52k
  if (callback3) {
75
1.23k
 unlink(callback3);      
76
1.23k
    free(callback3);
77
1.23k
    callback3 = NULL;
78
1.23k
  }
79
6.52k
  if (callback4) {
80
698
     unlink(callback4);
81
698
    free(callback4);
82
    callback4 = NULL;
83
698
  }
84
6.52k
}