samba-tool: add `samba-tool domain kds root_key list`
[samba.git] / lib / fuzzing / fuzz_ldb_ldif_read.c
blob3c48b6a28784d2a0a405e2cba78cbf94d7ad0dfc
1 /*
2 Fuzzing ldb_ldif_read_string
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/>.
18 #include "includes.h"
19 #include "fuzzing/fuzzing.h"
20 #include "ldb_private.h"
23 #define MAX_LENGTH (2 * 1024 * 1024 - 1)
24 char buf[MAX_LENGTH + 1] = {0};
26 int LLVMFuzzerTestOneInput(const uint8_t *input, size_t len)
28 struct ldb_ldif *ldif = NULL;
29 const char *s = NULL;
30 struct ldb_context *ldb = ldb_init(NULL, NULL);
31 if (ldb == NULL) {
32 return 0;
35 if (len > MAX_LENGTH) {
36 len = MAX_LENGTH;
38 memcpy(buf, input, len);
39 buf[len] = 0;
40 s = buf;
42 ldif = ldb_ldif_read_string(ldb, &s);
44 if(ldif != NULL) {
45 ldb_ldif_write_string(ldb, ldb, ldif);
46 ldb_ldif_write_redacted_trace_string(ldb, ldb, ldif);
48 TALLOC_FREE(ldb);
49 return 0;
53 int LLVMFuzzerInitialize(int *argc, char ***argv)
55 return 0;