libubox
C utility functions for OpenWrt.
test-fuzz.c File Reference
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <limits.h>
#include "blob.h"
#include "blobmsg.h"

Go to the source code of this file.

Macros

#define BLOBMSG_TYPE_TROUBLE   INT_MAX
 

Functions

static void fuzz_blobmsg_parse (const uint8_t *data, size_t size)
 
static void fuzz_blob_parse (const uint8_t *data, size_t size)
 
int LLVMFuzzerTestOneInput (const uint8_t *input, size_t size)
 

Macro Definition Documentation

◆ BLOBMSG_TYPE_TROUBLE

#define BLOBMSG_TYPE_TROUBLE   INT_MAX

Definition at line 9 of file test-fuzz.c.

Function Documentation

◆ fuzz_blob_parse()

static void fuzz_blob_parse ( const uint8_t *  data,
size_t  size 
)
static

Definition at line 62 of file test-fuzz.c.

63 {
64  enum {
65  FOO_ATTR_NESTED,
66  FOO_ATTR_BINARY,
67  FOO_ATTR_STRING,
68  FOO_ATTR_INT8,
69  FOO_ATTR_INT16,
70  FOO_ATTR_INT32,
71  FOO_ATTR_INT64,
72  FOO_ATTR_DOUBLE,
73  __FOO_ATTR_MAX
74  };
75 
76 
77  static const struct blob_attr_info foo_policy[__FOO_ATTR_MAX] = {
78  [FOO_ATTR_NESTED] = { .type = BLOB_ATTR_NESTED },
79  [FOO_ATTR_BINARY] = { .type = BLOB_ATTR_BINARY },
80  [FOO_ATTR_STRING] = { .type = BLOB_ATTR_STRING },
81  [FOO_ATTR_INT8] = { .type = BLOB_ATTR_INT8 },
82  [FOO_ATTR_INT16] = { .type = BLOB_ATTR_INT16 },
83  [FOO_ATTR_INT32] = { .type = BLOB_ATTR_INT32 },
84  [FOO_ATTR_INT64] = { .type = BLOB_ATTR_INT64 },
85  [FOO_ATTR_DOUBLE] = { .type = BLOB_ATTR_DOUBLE },
86  };
87 
88  struct blob_attr *foo[__FOO_ATTR_MAX];
89  struct blob_attr *buf = (struct blob_attr *)data;
90 
91  blob_parse_untrusted(buf, size, foo, foo_policy, __FOO_ATTR_MAX);
92 }
int blob_parse_untrusted(struct blob_attr *attr, size_t attr_len, struct blob_attr **data, const struct blob_attr_info *info, int max)
Definition: blob.c:272
@ BLOB_ATTR_INT16
Definition: blob.h:39
@ BLOB_ATTR_STRING
Definition: blob.h:37
@ BLOB_ATTR_INT64
Definition: blob.h:41
@ BLOB_ATTR_DOUBLE
Definition: blob.h:42
@ BLOB_ATTR_BINARY
Definition: blob.h:36
@ BLOB_ATTR_NESTED
Definition: blob.h:35
@ BLOB_ATTR_INT32
Definition: blob.h:40
@ BLOB_ATTR_INT8
Definition: blob.h:38
char data[]
Definition: blob.h:1
Definition: blob.h:52
enum blobmsg_type type
Definition: blobmsg.h:48
static const struct blobmsg_policy foo_policy[]
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fuzz_blobmsg_parse()

static void fuzz_blobmsg_parse ( const uint8_t *  data,
size_t  size 
)
static

Definition at line 11 of file test-fuzz.c.

12 {
13  enum {
15  FOO_LIST,
17  __FOO_MAX
18  };
19 
20  static const int blobmsg_type[] = {
31  };
32 
33  static const struct blobmsg_policy foo_policy[] = {
34  [FOO_MESSAGE] = {
35  .name = "message",
36  .type = BLOBMSG_TYPE_STRING,
37  },
38  [FOO_LIST] = {
39  .name = "list",
40  .type = BLOBMSG_TYPE_ARRAY,
41  },
42  [FOO_TESTDATA] = {
43  .name = "testdata",
44  .type = BLOBMSG_TYPE_TABLE,
45  },
46  };
47 
48  struct blob_attr *tb[__FOO_MAX];
49 
50  blobmsg_parse(foo_policy, __FOO_MAX, tb, (uint8_t *)data, size);
51  blobmsg_parse_array(foo_policy, __FOO_MAX, tb, (uint8_t *)data, size);
52 
53  blobmsg_check_attr_len((struct blob_attr *)data, false, size);
54  blobmsg_check_attr_len((struct blob_attr *)data, true, size);
55 
56  for (size_t i=0; i < ARRAY_SIZE(blobmsg_type); i++) {
59  }
60 }
int blobmsg_check_array_len(const struct blob_attr *attr, int type, size_t blob_len)
Definition: blobmsg.c:92
bool blobmsg_check_attr_len(const struct blob_attr *attr, bool name, size_t len)
Definition: blobmsg.c:58
bool blobmsg_check_attr_list_len(const struct blob_attr *attr, int type, size_t len)
Definition: blobmsg.c:135
int blobmsg_parse_array(const struct blobmsg_policy *policy, int policy_len, struct blob_attr **tb, void *data, unsigned int len)
Definition: blobmsg.c:140
int blobmsg_parse(const struct blobmsg_policy *policy, int policy_len, struct blob_attr **tb, void *data, unsigned int len)
Definition: blobmsg.c:166
blobmsg_type
Definition: blobmsg.h:25
@ BLOBMSG_TYPE_TABLE
Definition: blobmsg.h:28
@ BLOBMSG_TYPE_STRING
Definition: blobmsg.h:29
@ BLOBMSG_TYPE_INT16
Definition: blobmsg.h:32
@ BLOBMSG_TYPE_ARRAY
Definition: blobmsg.h:27
@ BLOBMSG_TYPE_UNSPEC
Definition: blobmsg.h:26
@ BLOBMSG_TYPE_INT8
Definition: blobmsg.h:33
@ BLOBMSG_TYPE_INT32
Definition: blobmsg.h:31
@ BLOBMSG_TYPE_INT64
Definition: blobmsg.h:30
@ BLOBMSG_TYPE_DOUBLE
Definition: blobmsg.h:35
const char * name
Definition: blobmsg.h:47
@ FOO_TESTDATA
@ __FOO_MAX
@ FOO_MESSAGE
@ FOO_LIST
#define ARRAY_SIZE(x)
#define BLOBMSG_TYPE_TROUBLE
Definition: test-fuzz.c:9
Here is the call graph for this function:
Here is the caller graph for this function:

◆ LLVMFuzzerTestOneInput()

int LLVMFuzzerTestOneInput ( const uint8_t *  input,
size_t  size 
)

Definition at line 94 of file test-fuzz.c.

95 {
96  uint8_t *data;
97 
98  data = malloc(size);
99  if (!data)
100  return -1;
101 
102  memcpy(data, input, size);
103  fuzz_blob_parse(data, size);
104  fuzz_blobmsg_parse(data, size);
105  free(data);
106 
107  return 0;
108 }
static void fuzz_blobmsg_parse(const uint8_t *data, size_t size)
Definition: test-fuzz.c:11
static void fuzz_blob_parse(const uint8_t *data, size_t size)
Definition: test-fuzz.c:62
Here is the call graph for this function: