Coverage Report

Created: 2025-01-28 06:58

/src/wget2/fuzz/libwget_metalink_parse_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 <assert.h>
23
#include <stdio.h>
24
#include <stdint.h>
25
#include <stdlib.h>
26
#include <string.h>
27
28
#include "wget.h"
29
#include "fuzzer.h"
30
31
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
32
19.7k
{
33
19.7k
  if (size > 10000) // same as max_len = 10000 in .options file
34
44
    return 0;
35
36
19.7k
  char *in = (char *) malloc(size + 1);
37
38
19.7k
  assert(in != NULL);
39
40
  // 0 terminate
41
19.7k
  memcpy(in, data, size);
42
19.7k
  in[size] = 0;
43
44
19.7k
  wget_metalink *metalink;
45
19.7k
  metalink = wget_metalink_parse(in);
46
19.7k
  wget_metalink_sort_mirrors(metalink);
47
19.7k
  wget_metalink_free(&metalink);
48
49
19.7k
  free(in);
50
51
19.7k
  return 0;
52
19.7k
}