Coverage Report

Created: 2024-07-27 06:09

/src/fuzz_optparse.c
Line
Count
Source
1
/* Copyright 2023 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
13
#define FUSE_USE_VERSION 31
14
15
#include <stdint.h>
16
#include <stdio.h>
17
#include <stdlib.h>
18
#include <string.h>
19
20
#include <fuse.h>
21
#include <stddef.h>
22
23
// To make some fuzz data operations easier.
24
#include "ada_fuzz_header.h"
25
26
static char *my_argv[10];
27
28
static struct options {
29
  const char *char_opt1;
30
  const char *char_opt2;
31
  int int_opt3;
32
} options;
33
34
#define OPTION(t, p)                                                           \
35
  { t, offsetof(struct options, p), 1 }
36
static const struct fuse_opt option_spec[] = {
37
    OPTION("--char_opt1=%s", char_opt1), OPTION("--char_opt2=%s", char_opt2),
38
    OPTION("-i", int_opt3), OPTION("--intopt3", int_opt3), FUSE_OPT_END};
39
40
324
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
41
324
  af_safe_gb_init(data, size);
42
324
  char *opt1 = ada_safe_get_char_p();
43
324
  char *opt2 = ada_safe_get_char_p();
44
45
3.56k
  for (int i = 0; i < 10; i++) {
46
3.24k
    my_argv[i] = ada_safe_get_char_p();
47
3.24k
  }
48
324
  struct fuse_args args = {10, my_argv, 0};
49
50
324
  options.char_opt1 = strdup(opt1);
51
324
  options.char_opt2 = strdup(opt2);
52
324
  options.int_opt3 = ada_safe_get_int();
53
54
324
  if (fuse_opt_parse(&args, &options, option_spec, NULL) == -1) {
55
7
    free(options.char_opt1);
56
7
    free(options.char_opt2);
57
7
    af_safe_gb_cleanup();
58
7
    return 0;
59
7
  }
60
317
  free(options.char_opt1);
61
317
  free(options.char_opt2);
62
63
317
  fuse_opt_free_args(&args);
64
65
317
  af_safe_gb_cleanup();
66
317
  return 0;
67
324
}