Coverage Report

Created: 2025-07-23 06:19

/src/jpegoptim/fuzz/fuzz_manager.c
Line
Count
Source (jump to first uncovered line)
1
#include <libgen.h>
2
#include <stdlib.h>
3
#include <string.h>
4
#include <unistd.h>
5
#include "fuzz_manager.h"
6
#include "jpegoptim.h"
7
8
fuzz_manager_t fuzz_manager = {0};
9
10
void generate_temp_file_name(char *buf, size_t size)
11
0
{
12
0
  int fd;
13
0
  strncpy(buf, "/dev/shm/fuzz_file_XXXXXX", size);
14
0
  if (-1 == (fd = mkstemp(buf)))
15
0
  {
16
0
    perror("mkstemp");
17
0
    exit(EXIT_FAILURE);
18
0
  }
19
0
  close(fd);
20
0
}
21
22
void fuzz_manager_init()
23
0
{
24
0
  if (fuzz_manager.is_init)
25
0
  {
26
0
    return;
27
0
  }
28
29
0
  fuzz_set_target_size(-75);
30
31
0
  fuzz_manager.is_init = true;
32
0
  fuzz_manager.log_fh = fopen("/dev/null", "a"); // Do not log
33
34
0
  generate_temp_file_name(fuzz_manager.fuzz_file_name, PATH_MAX);
35
0
  generate_temp_file_name(fuzz_manager.new_fuzz_file_name, PATH_MAX);
36
37
0
  strncpy(fuzz_manager.tmp_dir, fuzz_manager.fuzz_file_name, PATH_MAX);
38
0
  dirname(fuzz_manager.tmp_dir);
39
  // Ensure the temp path ends with a /
40
0
  size_t tmp_len = strnlen(fuzz_manager.tmp_dir, PATH_MAX);
41
42
0
  if (tmp_len < PATH_MAX - 1 && fuzz_manager.tmp_dir[tmp_len - 1] != '/')
43
0
  {
44
0
    fuzz_manager.tmp_dir[tmp_len] = '/';
45
0
    fuzz_manager.tmp_dir[tmp_len + 1] = '\0';
46
0
  }
47
0
}