s3: smbd: rename_internals_fsp() has to reopen the parent directory of the target...
[Samba.git] / lib / fuzzing / fuzz_parse_lpq_entry.c
blob3537ce5bc0670440b195acf8b7f8cb0408109a20
1 /*
2 Fuzzing parse_lpq_entry
3 Copyright (C) Douglas Bagnall <dbagnall@samba.org> 2021
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.
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.
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/>.
18 #include "../../source3/include/includes.h"
19 #include "printing.h"
20 #include "fuzzing/fuzzing.h"
23 int LLVMFuzzerInitialize(int *argc, char ***argv)
25 return 0;
28 #define MAX_LENGTH (1024 * 1024)
29 char line[MAX_LENGTH + 1];
31 int LLVMFuzzerTestOneInput(const uint8_t *input, size_t len)
33 enum printing_types printing_type;
34 print_queue_struct pq_buf = {0};
35 print_status_struct status = {0};
36 bool first;
37 unsigned x;
38 TALLOC_CTX *frame = NULL;
40 if (len < 1 || len > MAX_LENGTH) {
41 return 0;
44 x = input[0];
45 input++;
46 len--;
48 /* There are 14 types, default goes to bsd */
49 printing_type = x & 15;
50 first = (x & 16) ? true : false;
52 memcpy(line, input, len);
53 line[len] = '\0';
55 /* parse_lpq_bsd requires a stackframe */
56 frame = talloc_stackframe();
58 parse_lpq_entry(printing_type,
59 line,
60 &pq_buf, /* out */
61 &status, /* out */
62 first);
63 talloc_free(frame);
64 return 0;