python: models: rename argument ldb to samdb
[samba.git] / lib / fuzzing / fuzz_regfio.c
blob588efb0afdd379b04927fa0150f80e2b3c934a01
1 /*
2 * Unix SMB/CIFS implementation.
3 * Windows NT registry I/O library
4 * Copyright (C) Michael Hanselmann 2019
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include "includes.h"
21 #include "fuzzing/fuzzing.h"
22 #include "system/filesys.h"
23 #include "lib/util/fault.h"
24 #include "registry/reg_objects.h"
25 #include "registry/regfio.h"
27 static FILE *fp;
28 static char filename[128];
30 int LLVMFuzzerInitialize(int *argc, char ***argv)
32 fp = tmpfile();
34 (void)snprintf(filename, sizeof(filename), "/proc/self/fd/%d", fileno(fp));
36 return 0;
39 int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len)
41 REGF_FILE* regfile;
42 REGF_NK_REC *nk, *subkey;
44 rewind(fp);
45 (void)fwrite(buf, len, 1, fp);
46 (void)fflush(fp);
48 regfile = regfio_open(filename, O_RDONLY, 0600);
49 if (!regfile) {
50 goto out;
53 regfile->ignore_checksums = true;
55 nk = regfio_rootkey(regfile);
56 if (nk != NULL) {
57 nk->subkey_index = 0;
58 while ((subkey = regfio_fetch_subkey(regfile, nk))) {
62 out:
63 if (regfile != NULL) {
64 regfio_close(regfile);
67 return 0;