1 /* Copyright 2021 Google LLC
2 Licensed under the Apache License, Version 2.0 (the "License");
3 you may not use this file except in compliance with the License.
4 You may obtain a copy of the License at
5 http://www.apache.org/licenses/LICENSE-2.0
6 Unless required by applicable law or agreed to in writing, software
7 distributed under the License is distributed on an "AS IS" BASIS,
8 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9 See the License for the specific language governing permissions and
10 limitations under the License.
11 */
12 #include "apr.h"
13 #include "apr_file_io.h"
14 #include "apr_poll.h"
15 #include "apr_portable.h"
16 #include "apr_proc_mutex.h"
17 #include "apr_signal.h"
18 #include "apr_strings.h"
19 #include "apr_thread_mutex.h"
20 #include "apr_thread_proc.h"
21
22 #define APR_WANT_STRFUNC
23 #include "apr_file_io.h"
24 #include "apr_fnmatch.h"
25 #include "apr_want.h"
26
27 #include "apr_poll.h"
28 #include "apr_want.h"
29
30 #include "ap_config.h"
31 #include "ap_expr.h"
32 #include "ap_listen.h"
33 #include "ap_provider.h"
34 #include "ap_regex.h"
35
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)36 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
37 char *new_str = (char *)malloc(size + 1);
38 if (new_str == NULL) {
39 return 0;
40 }
41 memcpy(new_str, data, size);
42 new_str[size] = '\0';
43
44 apr_pool_initialize();
45 apr_pool_t *v = NULL;
46 apr_pool_create(&v, NULL);
47
48 int only_ascii = 1;
49 for (int i = 0; i < size; i++) {
50 // Avoid unnessary exits because of non-ascii characters.
51 if (new_str[i] < 0x01 || new_str[i] > 0x7f) {
52 only_ascii = 0;
53 }
54 // Avoid forced exits beause of, e.g. unsupported characters or recursion
55 // depth
56 if (new_str[i] == 0x5c || new_str[i] == '{') {
57 only_ascii = 0;
58 }
59 }
60
61 // Now parse
62 if (only_ascii) {
63 ap_expr_info_t val;
64 ap_expr_parse(v, v, &val, new_str, NULL);
65 }
66
67 apr_pool_terminate();
68 free(new_str);
69 return 0;
70 }
71