s3: smbd: rename_internals_fsp() has to reopen the parent directory of the target...
[Samba.git] / lib / fuzzing / fuzz_nmblib_parse_packet.c
blobc8a2d035ef73308ce6f3223aa0e4652396240fd5
1 /*
2 Fuzz NMB parse_packet
3 Copyright (C) Catalyst IT 2020
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/>.
19 #include "../../source3/include/includes.h"
20 #include "libsmb/libsmb.h"
21 #include "libsmb/nmblib.h"
22 #include "fuzzing/fuzzing.h"
24 #define PORT 138
25 #define MAX_LENGTH (1024 * 1024)
26 char buf[MAX_LENGTH + 1];
29 int LLVMFuzzerTestOneInput(const uint8_t *input, size_t len)
31 struct packet_struct *p = NULL;
32 struct in_addr ip = {
33 0x0100007f /* 127.0.0.1 */
36 p = parse_packet((char *)input,
37 len,
38 NMB_PACKET,
39 ip,
40 PORT);
42 * We expect NULL (parse failure) most of the time.
44 * When it is not NULL we want to ensure the parsed packet is
45 * reasonably sound.
48 if (p != NULL) {
49 struct nmb_packet *nmb = &p->packet.nmb;
50 pull_ascii_nstring(buf, MAX_LENGTH,
51 nmb->question.question_name.name);
52 build_packet(buf, MAX_LENGTH, p);
53 free_packet(p);
55 return 0;
59 int LLVMFuzzerInitialize(int *argc, char ***argv)
61 return 0;