s3: smbd: Cleanup. smb2_file_rename_information() can never have a @GMT path in the...
[Samba.git] / lib / fuzzing / fuzz_ldb_parse_binary_decode.c
blobfeb26e28c820cdbe8ac4def4c9222475ac20e06c
1 /*
2 Fuzzing ldb_binary_decode and ldb_binary_encode_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 static char * possibly_truncate(uint8_t *input, size_t len)
28 if (len > MAX_LENGTH) {
29 len = MAX_LENGTH;
31 memcpy(buf, input, len);
32 buf[len] = 0;
33 return buf;
37 int LLVMFuzzerTestOneInput(uint8_t *input, size_t len)
39 TALLOC_CTX *mem_ctx = talloc_init(__FUNCTION__);
40 struct ldb_val val = {0};
41 const char *s = possibly_truncate(input, len);
43 /* we treat the same string to encoding and decoding, not
44 * round-tripping. */
45 val = ldb_binary_decode(mem_ctx, s);
46 ldb_binary_encode_string(mem_ctx, s);
47 TALLOC_FREE(mem_ctx);
48 return 0;
52 int LLVMFuzzerInitialize(int *argc, char ***argv)
54 return 0;