Coverage Report

Created: 2025-12-31 07:08

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wget2/fuzz/libwget_tlssess_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, "tls"))
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
11.5k
{
51
11.5k
  void *p;
52
11.5k
  size_t len;
53
54
11.5k
  if (size > 256) // same as max_len = 256 in .options file
55
25
    return 0;
56
57
11.5k
  g_data = data;
58
11.5k
  g_size = size;
59
60
11.5k
  wget_tls_session_db *tlssess_db = wget_tls_session_db_init(NULL);
61
11.5k
#if ! defined _WIN32 && defined HAVE_FMEMOPEN
62
11.5k
  wget_tls_session_db_load(tlssess_db, "tls");
63
11.5k
#endif
64
11.5k
  if (wget_tls_session_get(tlssess_db, "x.y", &p, &len) == 0)
65
104
    wget_free(p);
66
11.5k
  wget_tls_session_db_free(&tlssess_db);
67
68
11.5k
  return 0;
69
11.5k
}