Coverage Report

Created: 2025-08-20 06:32

/src/cups/ossfuzz/fuzz_ppd_gen_conflicts.c
Line
Count
Source (jump to first uncovered line)
1
#include <stdint.h>
2
#include <stddef.h>
3
#include "ppd.h"
4
#include "cups.h"
5
#include "file-private.h"
6
7
14.7k
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
8
    // Create a temporary file name using process id to avoid conflicts
9
14.7k
    char filename[256];
10
14.7k
    snprintf(filename, sizeof(filename), "/tmp/fuzz_ppd_%d.ppd", getpid());
11
12
    // Write the data to a temporary file
13
14.7k
    FILE *file = fopen(filename, "wb");
14
14.7k
    if (!file) {
15
0
        return 0;
16
0
    }
17
14.7k
    fwrite(data, 1, size, file);
18
14.7k
    fclose(file);
19
20
    // Open the PPD file
21
14.7k
    ppd_file_t *ppd = ppdOpenFile(filename);
22
14.7k
    if (!ppd) {
23
5.88k
        remove(filename);
24
5.88k
        return 0;
25
5.88k
    }
26
27
    // Check for conflicts
28
8.85k
    ppdConflicts(ppd);
29
30
    // Parse options from a sample string
31
8.85k
    cups_option_t *options = NULL;
32
8.85k
    int num_options = cupsParseOptions("SampleOption=SampleValue", 0, &options);
33
34
    // Mark options in the PPD file
35
8.85k
    cupsMarkOptions(ppd, num_options, options);
36
37
    // Check for conflicts with specific options and choices
38
8.85k
    cupsGetConflicts(ppd, "SampleOption", "SampleChoice", &options);
39
40
    // Resolve conflicts with specific options and choices
41
8.85k
    int num_resolved_options = num_options;
42
8.85k
    cupsResolveConflicts(ppd, "SampleOption", "SampleChoice", &num_resolved_options, &options);
43
44
    // Free options
45
8.85k
    cupsFreeOptions(num_options, options);
46
47
    // Close the PPD file
48
8.85k
    ppdClose(ppd);
49
50
    // Remove the temporary file
51
8.85k
    remove(filename);
52
53
8.85k
    return 0;
54
14.7k
}