fuzz: add fuzz_dcerpc_parse_binding
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Wed, 30 Sep 2020 02:34:37 +0000 (15:34 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 16 Oct 2020 04:45:39 +0000 (04:45 +0000)
We parse a binding and do a few tricks with it, including turning it
into a tower and back.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
lib/fuzzing/fuzz_dcerpc_parse_binding.c [new file with mode: 0644]
lib/fuzzing/wscript_build

diff --git a/lib/fuzzing/fuzz_dcerpc_parse_binding.c b/lib/fuzzing/fuzz_dcerpc_parse_binding.c
new file mode 100644 (file)
index 0000000..5f1c687
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+  Fuzz NMB parse_packet
+  Copyright (C) Catalyst IT 2020
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 3 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#include "includes.h"
+#include "librpc/gen_ndr/ndr_epmapper.h"
+#include "librpc/rpc/dcerpc.h"
+#include "fuzzing/fuzzing.h"
+
+#define MAX_LENGTH (1024 * 10)
+char buf[MAX_LENGTH + 1];
+
+
+int LLVMFuzzerTestOneInput(uint8_t *input, size_t len)
+{
+       TALLOC_CTX *mem_ctx = talloc_new(NULL);
+       struct dcerpc_binding *binding = NULL;
+       struct dcerpc_binding *dup = NULL;
+       struct epm_tower tower;
+       NTSTATUS status;
+       struct GUID guid;
+
+       if (len > MAX_LENGTH) {
+               return 0;
+       }
+       memcpy(buf, input, len);
+       buf[len]  = '\0';
+
+       status = dcerpc_parse_binding(mem_ctx, buf, &binding);
+
+       if (! NT_STATUS_IS_OK(status)) {
+               talloc_free(mem_ctx);
+               return 0;
+       }
+
+       /* If the string parses, we try manipulating it a bit */
+
+       dcerpc_binding_string(mem_ctx, binding);
+       dcerpc_binding_get_abstract_syntax(binding);
+       dup = dcerpc_binding_dup(mem_ctx, binding);
+
+       status = dcerpc_binding_build_tower(mem_ctx,
+                                           binding,
+                                           &tower);
+       if (NT_STATUS_IS_OK(status)) {
+               status = dcerpc_binding_from_tower(mem_ctx,
+                                                  &tower,
+                                                  &dup);
+       }
+
+       guid = dcerpc_binding_get_object(binding);
+
+       talloc_free(mem_ctx);
+       return 0;
+}
index f8b3886d3dae7bffb70943f61707ed3689c2ca01..8bf0db000cf877ab5a592f87d1c5085c8789f1c0 100644 (file)
@@ -72,6 +72,11 @@ bld.SAMBA_BINARY('fuzz_ldb_parse_tree',
                  deps='fuzzing ldb afl-fuzz-main',
                  fuzzer=True)
 
+bld.SAMBA_BINARY('fuzz_dcerpc_parse_binding',
+                 source='fuzz_dcerpc_parse_binding.c',
+                 deps='fuzzing dcerpc afl-fuzz-main',
+                 fuzzer=True)
+
 # The fuzz_type and fuzz_function parameters make the built
 # fuzzer take the same input as ndrdump and so the same that
 # could be sent to the client or server as the stub data.