Skip to content

Commit 16c28b3

Browse files
douglasbagnallabartlet
authored andcommitted
fuzz: add fuzz_parse_lpq_entry
Signed-off-by: Douglas Bagnall <[email protected]> Reviewed-by: Andrew Bartlett <[email protected]>
1 parent 0cb833b commit 16c28b3

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

lib/fuzzing/fuzz_parse_lpq_entry.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
Fuzzing parse_lpq_entry
3+
Copyright (C) Douglas Bagnall <[email protected]> 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+
{
25+
return 0;
26+
}
27+
28+
#define MAX_LENGTH (1024 * 1024)
29+
char line[MAX_LENGTH + 1];
30+
31+
int LLVMFuzzerTestOneInput(uint8_t *input, size_t len)
32+
{
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;
39+
40+
if (len < 1 || len > MAX_LENGTH) {
41+
return 0;
42+
}
43+
44+
x = input[0];
45+
input++;
46+
len--;
47+
48+
/* There are 14 types, default goes to bsd */
49+
printing_type = x & 15;
50+
first = (x & 16) ? true : false;
51+
52+
memcpy(line, input, len);
53+
line[len] = '\0';
54+
55+
/* parse_lpq_bsd requires a stackframe */
56+
frame = talloc_stackframe();
57+
58+
parse_lpq_entry(printing_type,
59+
line,
60+
&pq_buf, /* out */
61+
&status, /* out */
62+
first);
63+
talloc_free(frame);
64+
return 0;
65+
}

lib/fuzzing/wscript_build

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ bld.SAMBA_BINARY('fuzz_tiniparser',
1717
deps='fuzzing tiniparser talloc afl-fuzz-main',
1818
fuzzer=True)
1919

20+
bld.SAMBA_BINARY('fuzz_parse_lpq_entry',
21+
source='fuzz_parse_lpq_entry.c',
22+
deps='fuzzing afl-fuzz-main smbd_base',
23+
fuzzer=True)
24+
2025
bld.SAMBA_BINARY('fuzz_oLschema2ldif',
2126
source='fuzz_oLschema2ldif.c',
2227
deps='fuzzing oLschema2ldif-lib afl-fuzz-main',

0 commit comments

Comments
 (0)