Coverage Report

Created: 2024-11-04 06:35

/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
3.76k
#define kMinInputLength 2
15
1.88k
#define kMaxInputLength 1024
16
17
void load_ipp(char *file);
18
19
extern int
20
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
21
1.88k
{
22
1.88k
    FILE  *fp;
23
1.88k
    char  file_name[256];
24
25
1.88k
    if (size < kMinInputLength || size > kMaxInputLength) {
26
22
      return 0;
27
22
    }
28
29
1.86k
    sprintf(file_name, "/tmp/libfuzzer.%d", getpid());
30
31
1.86k
    fp = fopen(file_name, "w");
32
1.86k
    if (fp == NULL) {
33
0
        return 0;
34
0
    }
35
36
1.86k
    fwrite(data, sizeof(char), size, fp);
37
1.86k
    fclose(fp);
38
39
1.86k
    load_ipp(file_name);
40
1.86k
    unlink(file_name);
41
42
1.86k
    return 0;
43
1.86k
}
44
45
void load_ipp(char *file)
46
1.86k
{
47
1.86k
    ipp_t    *request;
48
1.86k
    cups_file_t  *fp;
49
50
1.86k
    fp = cupsFileOpen(file, "r");
51
1.86k
    if (fp == NULL) {
52
0
        return;
53
0
    }
54
55
1.86k
    request = ippNew();
56
57
1.86k
    ippReadIO(fp, (ipp_iocb_t)cupsFileRead, 1, NULL, request);
58
59
1.86k
    cupsFileClose(fp);
60
1.86k
    ippDelete(request);
61
1.86k
}