Coverage Report

Created: 2025-03-18 06:55

/src/wget2/fuzz/libwget_bar_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> // assert
23
#include <stdint.h> // uint8_t
24
#include <stdlib.h> // malloc, free
25
#include <string.h> // memcpy
26
27
#include "wget.h"
28
#include "fuzzer.h"
29
30
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
31
215
{
32
215
  wget_bar *bar;
33
215
  char *in = (char *) malloc(size + 1);
34
35
215
  assert(in != NULL);
36
37
  // 0 terminate
38
215
  memcpy(in, data, size);
39
215
  in[size] = 0;
40
41
215
  wget_bar_screen_resized();
42
43
215
  bar = wget_bar_init(NULL, 0);
44
215
  wget_bar_free(&bar);
45
46
215
  bar = wget_bar_init(NULL, 3);
47
215
  wget_bar_set_slots(bar, 2);
48
49
215
  wget_bar_slot_begin(bar, 1, "test", 1, 64000);
50
215
  wget_bar_slot_downloaded(bar, 1, (unsigned) atoi(in));
51
215
  wget_bar_printf(bar, 1, "%s", in);
52
215
  wget_bar_write_line(bar, (char *) data, size);
53
215
  wget_bar_update(bar);
54
215
  wget_bar_slot_deregister(bar, 0);
55
215
  wget_bar_slot_deregister(bar, 2);
56
215
  wget_bar_slot_deregister(bar, 999);
57
215
  wget_bar_free(&bar);
58
59
215
  free(in);
60
61
215
  return 0;
62
215
}