Coverage Report

Created: 2025-12-31 07:08

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wget2/fuzz/libwget_netrc_fuzzer.c
Line
Count
Source
1
/*
2
 * Copyright (c) 2017-2024 Free Software Foundation, Inc.
3
 *
4
 * This file is part of libwget.
5
 *
6
 * Libwget is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU Lesser 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
 * Libwget 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 Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public License
17
 * along with libwget.  If not, see <https://www.gnu.org/licenses/>.
18
 */
19
20
#include <config.h>
21
22
#include <stdio.h>
23
#include <stdint.h>
24
#include <stdlib.h>
25
#include <string.h>
26
27
#include "wget.h"
28
#include "fuzzer.h"
29
30
static const uint8_t *g_data;
31
static size_t g_size;
32
33
#if defined HAVE_DLFCN_H && defined HAVE_FMEMOPEN
34
#include <dlfcn.h>
35
#ifdef RTLD_NEXT /* Not defined e.g. on CygWin */
36
FILE *fopen(const char *pathname, const char *mode)
37
11.2k
{
38
11.2k
  FILE *(*libc_fopen)(const char *, const char *) =
39
11.2k
    (FILE *(*)(const char *, const char *)) dlsym (RTLD_NEXT, "fopen");
40
41
11.2k
  if (!strcmp(pathname, "netrc"))
42
5.58k
    return fmemopen((void *) g_data, g_size, mode);
43
44
5.67k
  return libc_fopen(pathname, mode);
45
11.2k
}
46
#endif
47
#endif
48
49
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
50
5.16k
{
51
5.16k
  if (size > 256) // same as max_len = 256 in .options file
52
56
    return 0;
53
54
5.10k
  g_data = data;
55
5.10k
  g_size = size;
56
57
5.10k
  wget_netrc_db *netrc_db = wget_netrc_db_init(NULL);
58
5.10k
#if ! defined _WIN32 && defined HAVE_FMEMOPEN
59
5.10k
  wget_netrc_db_load(netrc_db, "netrc");
60
5.10k
#endif
61
5.10k
  wget_netrc_get(netrc_db, "x.y");
62
5.10k
  wget_netrc_db_free(&netrc_db);
63
64
5.10k
  return 0;
65
5.16k
}