epan/dissectors/pidl/drsuapi/drsuapi.cnf init/free_ndr_pointer_list
[wireshark-sm.git] / fuzz / StandaloneFuzzTargetMain.c
blobcf29561cf55ed4f41f4ac8a26af7b5882249b91f
1 /* based on http://llvm.org/svn/llvm-project/compiler-rt/trunk/lib/fuzzer/standalone/StandaloneFuzzTargetMain.c r311407 (22 Aug 2017) */
3 /* http://llvm.org/svn/llvm-project/compiler-rt/trunk/LICENSE.TXT follows */
5 /*
6 ==============================================================================
7 compiler_rt License
8 ==============================================================================
10 The compiler_rt library is dual licensed under both the University of Illinois
11 "BSD-Like" license and the MIT license. As a user of this code you may choose
12 to use it under either license. As a contributor, you agree to allow your code
13 to be used under both.
15 Full text of the relevant licenses is included below.
17 ==============================================================================
19 University of Illinois/NCSA
20 Open Source License
22 Copyright (c) 2009-2016 by the contributors listed in CREDITS.TXT
24 All rights reserved.
26 Developed by:
28 LLVM Team
30 University of Illinois at Urbana-Champaign
32 http://llvm.org
34 Permission is hereby granted, free of charge, to any person obtaining a copy of
35 this software and associated documentation files (the "Software"), to deal with
36 the Software without restriction, including without limitation the rights to
37 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
38 of the Software, and to permit persons to whom the Software is furnished to do
39 so, subject to the following conditions:
41 * Redistributions of source code must retain the above copyright notice,
42 this list of conditions and the following disclaimers.
44 * Redistributions in binary form must reproduce the above copyright notice,
45 this list of conditions and the following disclaimers in the
46 documentation and/or other materials provided with the distribution.
48 * Neither the names of the LLVM Team, University of Illinois at
49 Urbana-Champaign, nor the names of its contributors may be used to
50 endorse or promote products derived from this Software without specific
51 prior written permission.
53 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
54 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
55 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
56 CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
57 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
58 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
59 SOFTWARE.
61 ==============================================================================
63 Copyright (c) 2009-2015 by the contributors listed in CREDITS.TXT
65 SPDX-License-Identifier: MIT
67 ==============================================================================
68 Copyrights and Licenses for Third Party Software Distributed with LLVM:
69 ==============================================================================
70 The LLVM software contains code written by third parties. Such software will
71 have its own individual LICENSE.TXT file in the directory in which it appears.
72 This file will describe the copyrights, license, and restrictions which apply
73 to that code.
75 The disclaimer of warranty in the University of Illinois Open Source License
76 applies to all code in the LLVM Distribution, and nothing in any of the
77 other licenses gives permission to use the names of the LLVM Team or the
78 University of Illinois to endorse or promote products derived from this
79 Software.
82 /*===- StandaloneFuzzTargetMain.c - standalone main() for fuzz targets. ---===//
84 // The LLVM Compiler Infrastructure
86 // This file is distributed under the University of Illinois Open Source
87 // License. See LICENSE.TXT for details.
89 //===----------------------------------------------------------------------===//
90 // This main() function can be linked to a fuzz target (i.e. a library
91 // that exports LLVMFuzzerTestOneInput() and possibly LLVMFuzzerInitialize())
92 // instead of libFuzzer. This main() function will not perform any fuzzing
93 // but will simply feed all input files one by one to the fuzz target.
95 // Use this file to provide reproducers for bugs when linking against libFuzzer
96 // or other fuzzing engine is undesirable.
97 //===----------------------------------------------------------------------===*/
98 #include <assert.h>
99 #include <stdio.h>
100 #include <stdlib.h>
102 #include <glib.h>
103 #include <wsutil/file_util.h>
105 #include "FuzzerInterface.h"
107 int main(int argc, char **argv) {
108 fprintf(stderr, "StandaloneFuzzTargetMain: running %d inputs\n", argc - 1);
109 LLVMFuzzerInitialize(&argc, &argv);
110 for (int i = 1; i < argc; i++) {
111 fprintf(stderr, "Running: %s\n", argv[i]);
112 FILE *f = ws_fopen(argv[i], "r");
113 assert(f);
114 fseek(f, 0, SEEK_END);
115 long len = ftell(f);
116 assert(len >= 0);
117 fseek(f, 0, SEEK_SET);
118 unsigned char *buf = (unsigned char*)g_malloc((size_t)len);
119 size_t n_read = fread(buf, 1, len, f);
120 assert(n_read == (size_t)len);
121 fclose(f);
122 LLVMFuzzerTestOneInput(buf, len);
123 g_free(buf);
124 fprintf(stderr, "Done: %s: (%zd bytes)\n", argv[i], n_read);