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

Function run

tests/fuzz/fuzz-open_channel.c:443–483  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

441}
442
443void run(const u8 *data, size_t size)
444{
445 /* The function under test: fundee_channel(), calls
446 * clean_tmpctx() mid-run, so create a separate context.
447 */
448 const tal_t *run_ctx = tal(NULL, tal_t);
449
450 if (setjmp(fuzz_env) != 0)
451 goto cleanup;
452
453 /* Initialize the global pointers to the fuzz data. */
454 cursor = &data;
455 max = &size;
456
457 state = fromwire_new_state(run_ctx);
458 if (!state)
459 goto cleanup;
460
461 u8 *open_channel_msg;
462 /* Choose between creating a valid message and a fuzzed one. */
463 if (fromwire_u8(cursor, max) % 2)
464 open_channel_msg = create_open_channel_msg(run_ctx, state);
465 else {
466 u8 *fuzz_msg = create_fuzz_msg(run_ctx);
467
468 open_channel_msg = tal_arr(run_ctx, u8, 0);
469 towire_u16(&open_channel_msg, WIRE_OPEN_CHANNEL);
470 towire_u8_array(&open_channel_msg, fuzz_msg, tal_bytelen(fuzz_msg));
471 }
472
473 if (!open_channel_msg)
474 goto cleanup;
475
476 hsmd_reads = hsmd_writes = ld_writes = 0;
477 /* We received an `open_channel` msg, so we're the fundee. */
478 fundee_channel(state, open_channel_msg);
479
480cleanup:
481 tal_free(run_ctx);
482 clean_tmpctx();
483}

Callers

nothing calls this directly

Calls 10

fromwire_new_stateFunction · 0.85
create_open_channel_msgFunction · 0.85
create_fuzz_msgFunction · 0.85
tal_bytelenFunction · 0.85
fundee_channelFunction · 0.85
tal_freeFunction · 0.85
clean_tmpctxFunction · 0.85
fromwire_u8Function · 0.50
towire_u16Function · 0.50
towire_u8_arrayFunction · 0.50

Tested by

no test coverage detected