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

Function run

tests/fuzz/fuzz-channel_id.c:18–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16}
17
18void run(const uint8_t *data, size_t size)
19{
20 struct channel_id chan_id;
21 struct pubkey basepoint_1, basepoint_2;
22 struct bitcoin_outpoint outpoint;
23 const uint8_t **v1_chunks, **v2_chunks, **marshal_chunks;
24 const uint8_t *wire_ptr;
25 size_t wire_max;
26 uint8_t *wire_buf;
27
28 if (size < sizeof(outpoint))
29 return;
30
31 v1_chunks = get_chunks(NULL, data, size, sizeof(outpoint));
32 for (size_t i = 0; i < tal_count(v1_chunks); i++) {
33 wire_ptr = v1_chunks[i];
34 wire_max = sizeof(outpoint);
35 fromwire_bitcoin_outpoint(&wire_ptr, &wire_max, &outpoint);
36 assert(wire_ptr);
37 derive_channel_id(&chan_id, &outpoint);
38 }
39 tal_free(v1_chunks);
40
41 v2_chunks = get_chunks(NULL, data, size, PUBKEY_CMPR_LEN * 2);
42 for (size_t i = 0; i < tal_count(v2_chunks); i++) {
43 wire_ptr = v2_chunks[i];
44 wire_max = PUBKEY_CMPR_LEN;
45 fromwire_pubkey(&wire_ptr, &wire_max, &basepoint_1);
46 if (!wire_ptr)
47 continue;
48
49 wire_max = PUBKEY_CMPR_LEN;
50 fromwire_pubkey(&wire_ptr, &wire_max, &basepoint_2);
51 if (!wire_ptr)
52 continue;
53
54 derive_channel_id_v2(&chan_id, &basepoint_1, &basepoint_2);
55 }
56 tal_free(v2_chunks);
57
58 marshal_chunks = get_chunks(NULL, data, size, sizeof(chan_id));
59 for (size_t i = 0; i < tal_count(marshal_chunks); i++) {
60 wire_ptr = marshal_chunks[i];
61 wire_max = tal_count(marshal_chunks[i]);
62
63 fromwire_channel_id(&wire_ptr, &wire_max, &chan_id);
64 wire_buf = tal_arr(NULL, uint8_t, 0);
65 towire_channel_id(&wire_buf, &chan_id);
66 assert(!memcmp(marshal_chunks[i], wire_buf, tal_count(marshal_chunks[i])));
67
68 tal_free(wire_buf);
69 }
70 tal_free(marshal_chunks);
71}

Callers

nothing calls this directly

Calls 8

get_chunksFunction · 0.85
derive_channel_idFunction · 0.85
tal_freeFunction · 0.85
fromwire_pubkeyFunction · 0.85
derive_channel_id_v2Function · 0.85
fromwire_channel_idFunction · 0.50
towire_channel_idFunction · 0.50

Tested by

no test coverage detected