Coverage Report

Created: 2025-12-31 08:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wget/fuzz/wget_robots_fuzzer.c
Line
Count
Source
1
/*
2
 * Copyright (c) 2017-2024 Free Software Foundation, Inc.
3
 *
4
 * This file is part of GNU Wget.
5
 *
6
 * GNU Wget is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * GNU Wget is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with Wget.  If not, see <https://www.gnu.org/licenses/>.
18
 */
19
20
#include <config.h>
21
22
#include <sys/types.h>
23
#include <dirent.h> // opendir, readdir
24
#include <stdint.h> // uint8_t
25
#include <stdio.h>  // fmemopen
26
#include <string.h>  // strncmp
27
#include <stdlib.h>  // free
28
#include <fcntl.h>  // open flags
29
#include <unistd.h>  // close
30
#include <setjmp.h> // longjmp, setjmp
31
32
#include "wget.h"
33
#undef fopen_wgetrc
34
35
#ifdef __cplusplus
36
  extern "C" {
37
#endif
38
  #include "res.h"
39
40
  // declarations for wget internal functions
41
  int main_wget(int argc, const char **argv);
42
  void cleanup(void);
43
  FILE *fopen_wget(const char *pathname, const char *mode);
44
  FILE *fopen_wgetrc(const char *pathname, const char *mode);
45
  void exit_wget(int status);
46
#ifdef __cplusplus
47
  }
48
#endif
49
50
#include "fuzzer.h"
51
52
FILE *fopen_wget(const char *pathname, const char *mode)
53
0
{
54
0
  return fopen("/dev/null", mode);
55
0
}
56
57
FILE *fopen_wgetrc(const char *pathname, const char *mode)
58
0
{
59
0
  return NULL;
60
0
}
61
62
#ifdef FUZZING
63
void exit_wget(int status)
64
0
{
65
0
}
66
#endif
67
68
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
69
1.26k
{
70
1.26k
  struct robot_specs *specs;
71
72
1.26k
  if (size > 4096) // same as max_len = ... in .options file
73
10
    return 0;
74
75
1.25k
  CLOSE_STDERR
76
77
1.25k
  specs = res_parse((char *) data, (int) size);
78
1.25k
  if (!specs)
79
0
    return 0;
80
81
1.25k
  res_match_path(specs, "a%ff%a");
82
83
1.25k
  res_register_specs("host", 80, specs);
84
85
1.25k
  res_cleanup();
86
87
1.25k
  RESTORE_STDERR
88
89
1.25k
  return 0;
90
1.25k
}