diff options
Diffstat (limited to 'fuzz/mutator_aux.h')
-rw-r--r-- | fuzz/mutator_aux.h | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/fuzz/mutator_aux.h b/fuzz/mutator_aux.h index d14e177..4a7e647 100644 --- a/fuzz/mutator_aux.h +++ b/fuzz/mutator_aux.h | |||
@@ -9,9 +9,10 @@ | |||
9 | 9 | ||
10 | #include <stddef.h> | 10 | #include <stddef.h> |
11 | #include <stdint.h> | 11 | #include <stdint.h> |
12 | #include <cbor.h> | ||
12 | 13 | ||
13 | /* | 14 | /* |
14 | * As of LLVM 7.0.1, MSAN support in libFuzzer was still experimental. | 15 | * As of LLVM 10.0.0, MSAN support in libFuzzer was still experimental. |
15 | * We therefore have to be careful when using our custom mutator, or | 16 | * We therefore have to be careful when using our custom mutator, or |
16 | * MSAN will flag uninitialised reads on memory populated by libFuzzer. | 17 | * MSAN will flag uninitialised reads on memory populated by libFuzzer. |
17 | * Since there is no way to suppress MSAN without regenerating object | 18 | * Since there is no way to suppress MSAN without regenerating object |
@@ -22,6 +23,7 @@ | |||
22 | 23 | ||
23 | #if defined(__has_feature) | 24 | #if defined(__has_feature) |
24 | # if __has_feature(memory_sanitizer) | 25 | # if __has_feature(memory_sanitizer) |
26 | # include <sanitizer/msan_interface.h> | ||
25 | # define NO_MSAN __attribute__((no_sanitize("memory"))) | 27 | # define NO_MSAN __attribute__((no_sanitize("memory"))) |
26 | # define WITH_MSAN 1 | 28 | # define WITH_MSAN 1 |
27 | # endif | 29 | # endif |
@@ -31,44 +33,49 @@ | |||
31 | # define NO_MSAN | 33 | # define NO_MSAN |
32 | #endif | 34 | #endif |
33 | 35 | ||
36 | #define MUTATE_SEED 0x01 | ||
37 | #define MUTATE_PARAM 0x02 | ||
38 | #define MUTATE_WIREDATA 0x04 | ||
39 | #define MUTATE_ALL (MUTATE_SEED | MUTATE_PARAM | MUTATE_WIREDATA) | ||
40 | |||
34 | #define MAXSTR 1024 | 41 | #define MAXSTR 1024 |
35 | #define MAXBLOB 3072 | 42 | #define MAXBLOB 3072 |
36 | 43 | ||
37 | #define GETLEN_MIN 0 | ||
38 | #define GETLEN_MAX 1 | ||
39 | |||
40 | struct blob { | 44 | struct blob { |
41 | uint8_t body[MAXBLOB]; | 45 | uint8_t body[MAXBLOB]; |
42 | size_t len; | 46 | size_t len; |
43 | }; | 47 | }; |
44 | 48 | ||
49 | struct param; | ||
50 | |||
51 | struct param *unpack(const uint8_t *, size_t); | ||
52 | size_t pack(uint8_t *, size_t, const struct param *); | ||
53 | size_t pack_dummy(uint8_t *, size_t); | ||
54 | void mutate(struct param *, unsigned int, unsigned int); | ||
55 | void test(const struct param *); | ||
56 | |||
45 | size_t xstrlen(const char *); | 57 | size_t xstrlen(const char *); |
46 | void consume(const void *, size_t); | 58 | void consume(const void *, size_t); |
47 | void consume_str(const char *); | 59 | void consume_str(const char *); |
48 | 60 | ||
49 | int unpack_blob(uint8_t, uint8_t **, size_t *, struct blob *); | 61 | int unpack_blob(cbor_item_t *, struct blob *); |
50 | int unpack_byte(uint8_t, uint8_t **, size_t *, uint8_t *); | 62 | int unpack_byte(cbor_item_t *, uint8_t *); |
51 | int unpack_int(uint8_t, uint8_t **, size_t *, int *); | 63 | int unpack_int(cbor_item_t *, int *); |
52 | int unpack_string(uint8_t, uint8_t **, size_t *, char *); | 64 | int unpack_string(cbor_item_t *, char *); |
53 | |||
54 | int pack_blob(uint8_t, uint8_t **, size_t *, const struct blob *); | ||
55 | int pack_byte(uint8_t, uint8_t **, size_t *, uint8_t); | ||
56 | int pack_int(uint8_t, uint8_t **, size_t *, int); | ||
57 | int pack_string(uint8_t, uint8_t **, size_t *, const char *); | ||
58 | 65 | ||
59 | size_t len_int(void); | 66 | cbor_item_t *pack_blob(const struct blob *); |
60 | size_t len_string(int); | 67 | cbor_item_t *pack_byte(uint8_t); |
61 | size_t len_byte(void); | 68 | cbor_item_t *pack_int(int); |
62 | size_t len_blob(int); | 69 | cbor_item_t *pack_string(const char *); |
63 | 70 | ||
64 | void mutate_byte(uint8_t *); | 71 | void mutate_byte(uint8_t *); |
65 | void mutate_int(int *); | 72 | void mutate_int(int *); |
66 | void mutate_blob(struct blob *); | 73 | void mutate_blob(struct blob *); |
67 | void mutate_string(char *); | 74 | void mutate_string(char *); |
68 | 75 | ||
69 | void * dev_open(const char *); | 76 | void *dev_open(const char *); |
70 | void dev_close(void *); | 77 | void dev_close(void *); |
71 | void set_wire_data(uint8_t *, size_t); | 78 | void set_wire_data(const uint8_t *, size_t); |
72 | int dev_read(void *, unsigned char *, size_t, int); | 79 | int dev_read(void *, unsigned char *, size_t, int); |
73 | int dev_write(void *, const unsigned char *, size_t); | 80 | int dev_write(void *, const unsigned char *, size_t); |
74 | 81 | ||