The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
fuzzer.c
Go to the documentation of this file.
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: b167686ed70de6ac47c803e00989ebb1e6a57646 $")
24 
25 #include <freeradius-devel/io/test_point.h>
26 
27 static int decode_test_ctx(void **out, UNUSED TALLOC_CTX *ctx)
28 {
29  *out = NULL;
30  return 0;
31 }
32 
33 /*
34  * Try to parse the input as a (mostly text) string.
35  *
36  * This isn't perfect, but it allows simple fuzzing of the parsers for all of the data types.
37  */
38 static ssize_t util_decode_proto(TALLOC_CTX *ctx, UNUSED fr_pair_list_t *out, uint8_t const *data, size_t data_len,
39  UNUSED void *proto_ctx)
40 {
41  ssize_t rcode;
43  fr_value_box_t *box;
44 
45  if (data_len < 1) return data_len; /* We want to check zero length input too */
46 
47  type = data[0] % (FR_TYPE_MAX + 1);
48  switch (type) {
49  case FR_TYPE_LEAF:
50  break;
51 
52  default:
53  return data_len;
54  }
55 
56  box = fr_value_box_alloc(ctx, type, NULL);
57  if (!box) return -1;
58 
59  rcode = fr_value_box_from_str(box, box, type, NULL, (char const *)data + 1, data_len - 1, NULL, true);
60  talloc_free(box);
61  return rcode;
62 }
63 
67  .func = util_decode_proto
68 };
#define RCSID(id)
Definition: build.h:444
#define UNUSED
Definition: build.h:313
talloc_free(reap)
static ssize_t util_decode_proto(TALLOC_CTX *ctx, UNUSED fr_pair_list_t *out, uint8_t const *data, size_t data_len, UNUSED void *proto_ctx)
Definition: fuzzer.c:38
fr_test_point_proto_decode_t util_tp_decode_proto
Definition: fuzzer.c:65
static int decode_test_ctx(void **out, UNUSED TALLOC_CTX *ctx)
Definition: fuzzer.c:27
fr_type_t
Definition: merged_model.c:80
@ FR_TYPE_MAX
Number of defined data types.
Definition: merged_model.c:130
long int ssize_t
Definition: merged_model.c:24
unsigned char uint8_t
Definition: merged_model.c:30
fr_aka_sim_id_type_t type
fr_test_point_ctx_alloc_t test_ctx
Allocate a test ctx for the encoder.
Definition: test_point.h:66
Entry point for protocol decoders.
Definition: test_point.h:65
#define FR_TYPE_LEAF
Definition: types.h:297
ssize_t fr_value_box_from_str(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t dst_type, fr_dict_attr_t const *dst_enumv, char const *in, size_t inlen, fr_sbuff_unescape_rules_t const *erules, bool tainted)
Definition: value.c:5264
#define fr_value_box_alloc(_ctx, _type, _enumv)
Allocate a value box of a specific type.
Definition: value.h:608
static fr_slen_t data
Definition: value.h:1259
static size_t char ** out
Definition: value.h:984