Coverage Report

Created: 2023-03-26 06:28

/src/fuzz_parse.c
Line
Count
Source (jump to first uncovered line)
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
36
1.55k
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
37
1.55k
  char *new_str = (char *)malloc(size + 1);
38
1.55k
  if (new_str == NULL) {
39
0
    return 0;
40
0
  }
41
1.55k
  memcpy(new_str, data, size);
42
1.55k
  new_str[size] = '\0';
43
44
1.55k
  apr_pool_initialize();
45
1.55k
  apr_pool_t *v = NULL;
46
1.55k
  apr_pool_create(&v, NULL);
47
48
1.55k
  int only_ascii = 1;
49
22.2M
  for (int i = 0; i < size; i++) {
50
    // Avoid unnessary exits because of non-ascii characters.
51
22.2M
    if (new_str[i] < 0x01 || new_str[i] > 0x7f) {
52
1.60M
      only_ascii = 0;
53
1.60M
    }
54
    // Avoid forced exits beause of, e.g. unsupported characters or recursion
55
    // depth
56
22.2M
    if (new_str[i] == 0x5c || new_str[i] == '{') {
57
389
      only_ascii = 0;
58
389
    }
59
22.2M
  }
60
61
  // Now parse
62
1.55k
  if (only_ascii) {
63
1.52k
    ap_expr_info_t val;
64
1.52k
    ap_expr_parse(v, v, &val, new_str, NULL);
65
1.52k
  }
66
67
1.55k
  apr_pool_terminate();
68
1.55k
  free(new_str);
69
1.55k
  return 0;
70
1.55k
}