Coverage Report

Created: 2026-10-18 06:56

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/freeradius-server/src/lib/util/fuzzer.c
Line
Count
Source
1
/*
2
 *   This library is free software; you can redistribute it and/or
3
 *   modify it under the terms of the GNU Lesser General Public
4
 *   License as published by the Free Software Foundation; either
5
 *   version 2.1 of the License, or (at your option) any later version.
6
 *
7
 *   This library is distributed in the hope that it will be useful,
8
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
 *   Lesser General Public License for more details.
11
 *
12
 *   You should have received a copy of the GNU Lesser General Public
13
 *   License along with this library; if not, write to the Free Software
14
 *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15
 */
16
17
/** Functions to manipulate DNS labels
18
 *
19
 * @file src/lib/util/fuzzer.c
20
 *
21
 * @copyright 2021 Network RADIUS SAS (legal@networkradius.com)
22
 */
23
RCSID("$Id: 0c7fa723a8cf581670511aa8952fb861aea2e0a6 $")
24
25
#include <freeradius-devel/io/test_point.h>
26
27
static int decode_test_ctx(void **out, UNUSED TALLOC_CTX *ctx, UNUSED fr_dict_t const *dict,
28
         UNUSED fr_dict_attr_t const *root_da)
29
4.62k
{
30
4.62k
  *out = NULL;
31
4.62k
  return 0;
32
4.62k
}
33
34
/*
35
 *  Try to parse the input as a (mostly text) string.
36
 *
37
 *  This isn't perfect, but it allows simple fuzzing of the parsers for all of the data types.
38
 */
39
static ssize_t util_decode_proto(TALLOC_CTX *ctx, UNUSED fr_pair_list_t *out, uint8_t const *data, size_t data_len,
40
         UNUSED void *proto_ctx)
41
4.62k
{
42
4.62k
  fr_slen_t rcode;
43
4.62k
  fr_type_t type;
44
4.62k
  fr_value_box_t *box;
45
46
4.62k
  if (data_len < 1) return data_len; /* We want to check zero length input too */
47
48
4.62k
  type = (fr_type_t)(data[0] % (FR_TYPE_MAX + 1));
49
4.62k
  switch (type) {
50
4.61k
  case FR_TYPE_LEAF:
51
4.61k
    break;
52
53
11
  default:
54
11
    return data_len;
55
4.62k
  }
56
57
4.61k
  box = fr_value_box_alloc(ctx, type, NULL);
58
4.61k
  if (!box) return -1;
59
60
4.61k
  rcode = fr_value_box_from_str(box, box, type, NULL, (char const *)data + 1, data_len - 1, NULL);
61
4.61k
  talloc_free(box);
62
4.61k
  return rcode;
63
4.61k
}
64
65
static ssize_t util_encode_proto(UNUSED TALLOC_CTX *ctx, fr_pair_list_t *vps, uint8_t *data, size_t data_len, UNUSED void *proto_ctx)
66
0
{
67
0
  return fr_pair_list_print(&FR_SBUFF_OUT((char *) data, data_len), NULL, vps);
68
0
}
69
70
71
extern fr_test_point_proto_decode_t util_tp_decode_proto;
72
fr_test_point_proto_decode_t util_tp_decode_proto = {
73
  .test_ctx = decode_test_ctx,
74
  .func   = util_decode_proto
75
};
76
77
extern fr_test_point_proto_encode_t util_tp_encode_proto;
78
fr_test_point_proto_encode_t util_tp_encode_proto = {
79
  .test_ctx = decode_test_ctx,
80
  .func   = util_encode_proto
81
};