Coverage Report

Created: 2025-12-31 06:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/samba/lib/fuzzing/fuzz_parse_lpq_entry.c
Line
Count
Source
1
/*
2
   Fuzzing parse_lpq_entry
3
   Copyright (C) Douglas Bagnall <dbagnall@samba.org> 2021
4
5
   This program is free software; you can redistribute it and/or modify
6
   it under the terms of the GNU General Public License as published by
7
   the Free Software Foundation; either version 3 of the License, or
8
   (at your option) any later version.
9
10
   This program is distributed in the hope that it will be useful,
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
   GNU General Public License for more details.
14
15
   You should have received a copy of the GNU General Public License
16
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
*/
18
#include "../../source3/include/includes.h"
19
#include "printing.h"
20
#include "fuzzing/fuzzing.h"
21
22
23
int LLVMFuzzerInitialize(int *argc, char ***argv)
24
376
{
25
376
  return 0;
26
376
}
27
28
1.94k
#define MAX_LENGTH (1024 * 1024)
29
char line[MAX_LENGTH + 1];
30
31
int LLVMFuzzerTestOneInput(const uint8_t *input, size_t len)
32
1.94k
{
33
1.94k
  enum printing_types printing_type;
34
1.94k
  print_queue_struct pq_buf = {0};
35
1.94k
  print_status_struct status = {0};
36
1.94k
  bool first;
37
1.94k
  unsigned x;
38
1.94k
  TALLOC_CTX *frame = NULL;
39
40
1.94k
  if (len < 1 || len > MAX_LENGTH) {
41
0
    return 0;
42
0
  }
43
44
1.94k
  x = input[0];
45
1.94k
  input++;
46
1.94k
  len--;
47
48
  /* There are 14 types, default goes to bsd */
49
1.94k
  printing_type = x & 15;
50
1.94k
  first = (x & 16) ? true : false;
51
52
1.94k
  memcpy(line, input, len);
53
1.94k
  line[len] = '\0';
54
55
  /* parse_lpq_bsd requires a stackframe */
56
1.94k
  frame = talloc_stackframe();
57
58
1.94k
  parse_lpq_entry(printing_type,
59
1.94k
      line,
60
1.94k
      &pq_buf, /* out */
61
1.94k
      &status, /* out */
62
1.94k
      first);
63
  talloc_free(frame);
64
1.94k
  return 0;
65
1.94k
}