| 441 | } |
| 442 | |
| 443 | void 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 | |
| 480 | cleanup: |
| 481 | tal_free(run_ctx); |
| 482 | clean_tmpctx(); |
| 483 | } |
nothing calls this directly
no test coverage detected