| 438 | } |
| 439 | |
| 440 | void run(const u8 *data, size_t size) |
| 441 | { |
| 442 | if (setjmp(fuzz_env) != 0) |
| 443 | goto cleanup; |
| 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 | /* Initialize the global pointers to the fuzz data. */ |
| 451 | cursor = &data; |
| 452 | max = &size; |
| 453 | |
| 454 | state = fromwire_new_state(run_ctx); |
| 455 | if (!state) |
| 456 | goto cleanup; |
| 457 | |
| 458 | u8 *open_channel_msg; |
| 459 | /* Choose between creating a valid message and a fuzzed one. */ |
| 460 | if (fromwire_u8(cursor, max) % 2) |
| 461 | open_channel_msg = create_open_channel_msg(run_ctx, state); |
| 462 | else { |
| 463 | u8 *fuzz_msg = create_fuzz_msg(run_ctx); |
| 464 | |
| 465 | open_channel_msg = tal_arr(run_ctx, u8, 0); |
| 466 | towire_u16(&open_channel_msg, WIRE_OPEN_CHANNEL); |
| 467 | towire_u8_array(&open_channel_msg, fuzz_msg, tal_bytelen(fuzz_msg)); |
| 468 | } |
| 469 | |
| 470 | if (!open_channel_msg) |
| 471 | goto cleanup; |
| 472 | |
| 473 | hsmd_reads = hsmd_writes = ld_writes = 0; |
| 474 | /* We received an `open_channel` msg, so we're the fundee. */ |
| 475 | fundee_channel(state, open_channel_msg); |
| 476 | |
| 477 | cleanup: |
| 478 | tal_free(run_ctx); |
| 479 | clean_tmpctx(); |
| 480 | } |
nothing calls this directly
no test coverage detected