Coverage Report

Created: 2025-11-09 06:55

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.26k
void fuzz_init(const uint8_t *data, size_t size) {
26
6.26k
    global_fuzz_data = (uint8_t *)data;
27
6.26k
    global_size = size;
28
    
29
6.26k
    callback1 = NULL;
30
6.26k
    callback2 = NULL;
31
6.26k
    callback3 = NULL;
32
6.26k
    callback4 = NULL;
33
6.26k
}
34
35
#ifdef ENABLE_FILE_CALLBACK
36
4.93k
void create_callback_file(const char *filename) {
37
4.93k
  fprintf(stderr, "create_callback_file: Creating file %s\n", filename);
38
4.93k
  FILE *fp = fopen(filename, "wb");
39
4.93k
  if (!fp) {
40
188
    return;
41
188
  }
42
4.74k
  fwrite(global_fuzz_data, global_size, 1, fp);
43
4.74k
  fclose(fp);
44
45
4.74k
  if (callback1 == NULL) {
46
1.73k
    callback1 = strdup(filename);
47
3.01k
  } else if (callback2 == NULL) {
48
1.23k
    callback2 = strdup(filename);
49
1.77k
  } else if (callback3 == NULL) {
50
939
    callback3 = strdup(filename);
51
939
  } else if (callback4 == NULL) {
52
494
    callback4 = strdup(filename);
53
494
  } else {
54
346
    fprintf(stderr, "create_callback_file: Too many callbacks created, ignoring %s\n", filename);
55
346
  }
56
4.74k
}
57
58
#else
59
void create_callback_file(const char *filename) {}
60
#endif
61
62
6.26k
void fuzz_cleanup() {
63
6.26k
  if (callback1) {
64
1.73k
 unlink(callback1);    
65
1.73k
    free(callback1);
66
   
67
1.73k
    callback1 = NULL;
68
1.73k
  }
69
6.26k
  if (callback2) {
70
1.23k
 unlink(callback2);    
71
1.23k
    free(callback2);
72
1.23k
    callback2 = NULL;
73
1.23k
  }
74
6.26k
  if (callback3) {
75
939
 unlink(callback3);      
76
939
    free(callback3);
77
939
    callback3 = NULL;
78
939
  }
79
6.26k
  if (callback4) {
80
494
     unlink(callback4);
81
494
    free(callback4);
82
    callback4 = NULL;
83
494
  }
84
6.26k
}