Coverage Report

Created: 2026-04-01 06:45

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