MCPcopy Create free account
hub / github.com/ElementsProject/lightning / LLVMFuzzerCustomCrossOver

Function LLVMFuzzerCustomCrossOver

tests/fuzz/bolt12.h:106–145  ·  view source on GitHub ↗

A custom cross-over mutator that decodes the bech32 inputs before cross-over * mutating them. Like LLVMFuzzerCustomMutator, this enables more efficient * fuzzing of bolt12 offers, invoice requests, and invoices. */

Source from the content-addressed store, hash-verified

104 * mutating them. Like LLVMFuzzerCustomMutator, this enables more efficient
105 * fuzzing of bolt12 offers, invoice requests, and invoices. */
106size_t LLVMFuzzerCustomCrossOver(const u8 *data1, size_t size1, const u8 *data2,
107 size_t size2, u8 *out, size_t max_size,
108 unsigned seed)
109{
110 const u8 *decoded_data1, *decoded_data2;
111 size_t decoded_size1, decoded_size2;
112 u8 *mutated_data;
113 size_t mutated_size;
114 char *encoded_data;
115 size_t encoded_size;
116 const char *fail;
117
118 /* Decode inputs. */
119 decoded_data1 = b12_string_to_data(tmpctx, (char *)data1, size1, bech32_hrp,
120 &decoded_size1, &fail);
121 if (!decoded_data1)
122 return cross_over_fail();
123 decoded_data2 = b12_string_to_data(tmpctx, (char *)data2, size2, bech32_hrp,
124 &decoded_size2, &fail);
125 if (!decoded_data2)
126 return cross_over_fail();
127
128 /* Cross-pollinate inputs. */
129 mutated_data = tal_arr(tmpctx, u8, max_size);
130 mutated_size = cross_over(decoded_data1, decoded_size1, decoded_data2,
131 decoded_size2, mutated_data, max_size, seed);
132 tal_resize(&mutated_data, mutated_size);
133
134 /* Encode the mutated input. */
135 encoded_data = to_bech32_charset(tmpctx, bech32_hrp, mutated_data);
136 encoded_size = tal_bytelen(encoded_data) - 1; /* Truncate null byte. */
137
138 if (encoded_size > max_size)
139 return cross_over_fail();
140
141 memcpy(out, encoded_data, encoded_size);
142 clean_tmpctx();
143
144 return encoded_size;
145}
146
147void init(int *argc, char ***argv)
148{

Callers

nothing calls this directly

Calls 6

b12_string_to_dataFunction · 0.85
cross_over_failFunction · 0.85
cross_overFunction · 0.85
tal_bytelenFunction · 0.85
clean_tmpctxFunction · 0.85
to_bech32_charsetFunction · 0.50

Tested by

no test coverage detected