1  /*
2   * Common helper functions for fuzzing tools
3   * Copyright (c) 2019, Jouni Malinen <j@w1.fi>
4   *
5   * This software may be distributed under the terms of the BSD license.
6   * See README for more details.
7   */
8  
9  #include "utils/includes.h"
10  
11  #include "utils/common.h"
12  
13  
wpa_fuzzer_set_debug_level(void)14  void wpa_fuzzer_set_debug_level(void)
15  {
16  	static int first = 1;
17  
18  	if (first) {
19  		char *env;
20  
21  		first = 0;
22  		env = getenv("WPADEBUG");
23  		if (env)
24  			wpa_debug_level = atoi(env);
25  		else
26  			wpa_debug_level = MSG_ERROR + 1;
27  
28  		wpa_debug_show_keys = 1;
29  	}
30  }
31  
32  
33  #ifndef TEST_LIBFUZZER
34  int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
35  
main(int argc,char * argv[])36  int main(int argc, char *argv[])
37  {
38  	char *data;
39  	size_t len;
40  
41  	if (argc < 2) {
42  		printf("usage: %s <file>\n", argv[0]);
43  		return -1;
44  	}
45  
46  	data = os_readfile(argv[1], &len);
47  	if (!data) {
48  		printf("Could not read '%s'\n", argv[1]);
49  		return -1;
50  	}
51  
52  	LLVMFuzzerTestOneInput((const uint8_t *) data, len);
53  	os_free(data);
54  	return 0;
55  }
56  #endif /* !TEST_LIBFUZZER */
57