Coverage Report

Created: 2025-07-13 06:56

/src/cups/ossfuzz/fuzz_ipp.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Fuzztest for `ippReadIO`.
3
 *
4
 * Copyright © 2024 by OpenPrinting.
5
 *
6
 * Licensed under Apache License v2.0.  See the file "LICENSE" for more
7
 * information.
8
 */
9
10
#include <file.h>
11
#include <string-private.h>
12
#include <ipp-private.h>
13
14
4.55k
#define kMinInputLength 2
15
2.27k
#define kMaxInputLength 1024
16
17
void load_ipp(char *file);
18
19
extern int
20
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
21
2.27k
{
22
2.27k
    FILE  *fp;
23
2.27k
    char  file_name[256];
24
25
2.27k
    if (size < kMinInputLength || size > kMaxInputLength) {
26
34
      return 0;
27
34
    }
28
29
2.24k
    sprintf(file_name, "/tmp/libfuzzer.%d", getpid());
30
31
2.24k
    fp = fopen(file_name, "w");
32
2.24k
    if (fp == NULL) {
33
0
        return 0;
34
0
    }
35
36
2.24k
    fwrite(data, sizeof(char), size, fp);
37
2.24k
    fclose(fp);
38
39
2.24k
    load_ipp(file_name);
40
2.24k
    unlink(file_name);
41
42
2.24k
    return 0;
43
2.24k
}
44
45
void load_ipp(char *file)
46
1.59k
{
47
1.59k
    ipp_t    *request;
48
1.59k
    cups_file_t  *fp;
49
50
1.59k
    fp = cupsFileOpen(file, "r");
51
1.59k
    if (fp == NULL) {
52
0
        return;
53
0
    }
54
55
1.59k
    request = ippNew();
56
57
1.59k
    ippReadIO(fp, (ipp_iocb_t)cupsFileRead, 1, NULL, request);
58
59
1.59k
    cupsFileClose(fp);
60
1.59k
    ippDelete(request);
61
1.59k
}