Coverage Report

Created: 2025-12-10 06:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libidn/fuzz/libidn_toascii_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 <https://www.gnu.org/licenses/>.
16
 */
17
18
#include <config.h>
19
20
#include <assert.h>   /* assert */
21
#include <stdint.h>   /* uint8_t, uint32_t */
22
#include <stdlib.h>   /* malloc, free */
23
#include <string.h>   /* memcpy */
24
25
#include "idna.h"
26
#include "idn-free.h"
27
#include "fuzzer.h"
28
29
int
30
LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
31
1.72k
{
32
1.72k
  char *domain;
33
1.72k
  char *out;
34
35
1.72k
  if (size > 1024)
36
8
    return 0;
37
38
1.71k
  domain = (char *) malloc (size + 1);
39
1.71k
  assert (domain != NULL);
40
41
1.71k
  if ((size & 3) == 0)
42
765
    {
43
765
      uint32_t *data0 = (uint32_t *) malloc (size + 4);
44
765
      char *asc = (char *) malloc (64);
45
46
765
      assert (data0 != NULL);
47
765
      assert (asc != NULL);
48
49
765
      memcpy (data0, data, size);
50
51
765
      idna_to_ascii_4i (data0, size / 4, asc, 0);
52
765
      idna_to_ascii_4i (data0, size / 4, asc,
53
765
      IDNA_ALLOW_UNASSIGNED | IDNA_USE_STD3_ASCII_RULES);
54
55
765
      free (asc);
56
57
765
      data0[size / 4] = 0;
58
765
      if (idna_to_ascii_4z (data0, &out, 0) == IDNA_SUCCESS)
59
102
  idn_free (out);
60
765
      if (idna_to_ascii_4z
61
765
    (data0, &out,
62
765
     IDNA_ALLOW_UNASSIGNED | IDNA_USE_STD3_ASCII_RULES) == IDNA_SUCCESS)
63
154
  idn_free (out);
64
765
      free (data0);
65
765
    }
66
67
  /* 0 terminate */
68
1.71k
  memcpy (domain, data, size);
69
1.71k
  domain[size] = 0;
70
71
1.71k
  if (idna_to_ascii_8z (domain, &out, 0) == IDNA_SUCCESS)
72
821
    idn_free (out);
73
1.71k
  if (idna_to_ascii_8z
74
1.71k
      (domain, &out,
75
1.71k
       IDNA_ALLOW_UNASSIGNED | IDNA_USE_STD3_ASCII_RULES) == IDNA_SUCCESS)
76
604
    idn_free (out);
77
1.71k
  if (idna_to_ascii_lz (domain, &out, 0) == IDNA_SUCCESS)
78
239
    idn_free (out);
79
1.71k
  if (idna_to_ascii_lz
80
1.71k
      (domain, &out,
81
1.71k
       IDNA_ALLOW_UNASSIGNED | IDNA_USE_STD3_ASCII_RULES) == IDNA_SUCCESS)
82
96
    idn_free (out);
83
84
1.71k
  free (domain);
85
86
1.71k
  return 0;
87
1.71k
}