Coverage Report

Created: 2025-08-26 06:32

/src/libidn/fuzz/libidn_tounicode_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
2.35k
{
32
2.35k
  char *domain;
33
2.35k
  char *out;
34
35
2.35k
  if (size > 1024)
36
9
    return 0;
37
38
2.34k
  domain = (char *) malloc (size + 1);
39
2.34k
  assert (domain != NULL);
40
41
  /* 0 terminate */
42
2.34k
  memcpy (domain, data, size);
43
2.34k
  domain[size] = 0;
44
45
2.34k
  if ((size & 3) == 0)
46
1.11k
    {
47
1.11k
      uint32_t *u32 = (uint32_t *) malloc (size);
48
1.11k
      size_t u32len;
49
1.11k
      uint32_t *data0, *out0;
50
51
1.11k
      data0 = (uint32_t *) malloc (size + 4);
52
1.11k
      assert (data0 != NULL);
53
1.11k
      memcpy (data0, data, size);
54
55
1.11k
      assert (u32 != NULL);
56
57
1.11k
      u32len = size / 4;
58
1.11k
      idna_to_unicode_44i (data0, size / 4, u32, &u32len, 0);
59
1.11k
      u32len = size / 4;
60
1.11k
      idna_to_unicode_44i (data0, size / 4, u32, &u32len,
61
1.11k
         IDNA_ALLOW_UNASSIGNED | IDNA_USE_STD3_ASCII_RULES);
62
63
1.11k
      free (u32);
64
65
1.11k
      data0[size / 4] = 0;
66
67
1.11k
      if (idna_to_unicode_4z4z (data0, &out0, 0) == IDNA_SUCCESS)
68
683
  idn_free (out0);
69
1.11k
      if (idna_to_unicode_4z4z
70
1.11k
    (data0, &out0,
71
1.11k
     IDNA_ALLOW_UNASSIGNED | IDNA_USE_STD3_ASCII_RULES) == IDNA_SUCCESS)
72
683
  idn_free (out0);
73
74
1.11k
      free (data0);
75
76
1.11k
      if (idna_to_unicode_8z4z (domain, &out0, 0) == IDNA_SUCCESS)
77
858
  idn_free (out0);
78
1.11k
      if (idna_to_unicode_8z4z
79
1.11k
    (domain, &out0,
80
1.11k
     IDNA_ALLOW_UNASSIGNED | IDNA_USE_STD3_ASCII_RULES) == IDNA_SUCCESS)
81
858
  idn_free (out0);
82
1.11k
    }
83
84
2.34k
  if (idna_to_unicode_8z8z (domain, &out, 0) == IDNA_SUCCESS)
85
2.04k
    idn_free (out);
86
2.34k
  if (idna_to_unicode_8z8z
87
2.34k
      (domain, &out,
88
2.34k
       IDNA_ALLOW_UNASSIGNED | IDNA_USE_STD3_ASCII_RULES) == IDNA_SUCCESS)
89
2.04k
    idn_free (out);
90
2.34k
  if (idna_to_unicode_8zlz (domain, &out, 0) == IDNA_SUCCESS)
91
906
    idn_free (out);
92
2.34k
  if (idna_to_unicode_8zlz
93
2.34k
      (domain, &out,
94
2.34k
       IDNA_ALLOW_UNASSIGNED | IDNA_USE_STD3_ASCII_RULES) == IDNA_SUCCESS)
95
883
    idn_free (out);
96
2.34k
  if (idna_to_unicode_lzlz (domain, &out, 0) == IDNA_SUCCESS)
97
886
    idn_free (out);
98
2.34k
  if (idna_to_unicode_lzlz
99
2.34k
      (domain, &out,
100
2.34k
       IDNA_ALLOW_UNASSIGNED | IDNA_USE_STD3_ASCII_RULES) == IDNA_SUCCESS)
101
864
    idn_free (out);
102
103
2.34k
  free (domain);
104
105
2.34k
  return 0;
106
2.34k
}