Coverage Report

Created: 2025-12-14 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libidn2/fuzz/libidn2_register_fuzzer.c
Line
Count
Source
1
/*
2
 * Copyright(c) 2017 Tim Ruehsen
3
 *
4
 * This program is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 */
17
18
#include <config.h>
19
20
#include <assert.h>   /* assert */
21
#include <stdlib.h>   /* malloc, free */
22
#include <string.h>   /* memcpy */
23
24
#include "idn2.h"
25
#include "fuzzer.h"
26
27
int
28
LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
29
2.11k
{
30
2.11k
  char *ulabel, *alabel;
31
2.11k
  char *out;
32
33
2.11k
  if (size > 1024)
34
12
    return 0;
35
36
2.10k
  ulabel = (char *) malloc (size + 1);
37
2.10k
  assert (ulabel != NULL);
38
39
  /* 0 terminate */
40
2.10k
  memcpy (ulabel, data, size);
41
2.10k
  ulabel[size] = 0;
42
43
2.10k
  if (size == 0)
44
0
    {
45
    /*** test NULL input/output combinations ***/
46
47
0
      if (idn2_register_ul (NULL, NULL, &out, 0) == IDN2_OK)
48
0
  idn2_free (out);
49
0
      idn2_register_ul (ulabel, NULL, NULL, 0);
50
0
    }
51
52
2.10k
  if (idn2_register_ul (ulabel, NULL, &out, 0) == IDN2_OK)
53
1.61k
    idn2_free (out);
54
55
2.10k
  free (ulabel);
56
57
2.10k
  alabel = (char *) malloc (size + 4 + 1);
58
2.10k
  assert (alabel != NULL);
59
60
  /* 0 terminate */
61
2.10k
  memcpy (alabel, "xn--", 4);
62
2.10k
  memcpy (alabel + 4, data, size);
63
2.10k
  alabel[size] = 0;
64
65
2.10k
  if (idn2_register_ul (NULL, alabel, &out, 0) == IDN2_OK)
66
109
    idn2_free (out);
67
68
  /*** test NULL input/output combinations ***/
69
2.10k
  if (size == 0)
70
0
    idn2_register_ul (NULL, alabel, NULL, 0);
71
72
2.10k
  free (alabel);
73
74
2.10k
  return 0;
75
2.10k
}