Coverage Report

Created: 2025-10-10 06:38

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