core-lightning/wire
Rusty Russell 55510ea27a io_write_wire: always make a copy (or steal if take).
I caught the gossip daemon freeing a message, while it was queued to be
written.  Using tal_dup_arr() is the Right Thing, as it handles taken()
properly automatically.

------------------------------- Valgrind errors --------------------------------
Valgrind error file: /tmp/lightning-rvc7d5oi/test_forward/lightning-3/valgrind-errors
==11057== Invalid read of size 8
==11057==    at 0x1328F2: to_tal_hdr (tal.c:174)
==11057==    by 0x133894: tal_len (tal.c:659)
==11057==    by 0x11BBE7: do_write_wire (wire_io.c:103)
==11057==    by 0x127B95: do_plan (io.c:369)
==11057==    by 0x127C31: io_ready (io.c:390)
==11057==    by 0x129461: io_loop (poll.c:295)
==11057==    by 0x10CBB4: main (gossip.c:722)
==11057==  Address 0x55a99d8 is 24 bytes inside a block of size 200 free'd
==11057==    at 0x4C2ED5B: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==11057==    by 0x133000: del_tree (tal.c:416)
==11057==    by 0x132F77: del_tree (tal.c:405)
==11057==    by 0x13333E: tal_free (tal.c:504)
==11057==    by 0x1123F1: queue_broadcast (broadcast.c:38)
==11057==    by 0x111EB0: handle_node_announcement (routing.c:918)
==11057==    by 0x10B166: handle_gossip_msg (gossip.c:170)
==11057==    by 0x10B76B: owner_msg_in (gossip.c:335)
==11057==    by 0x12712E: next_plan (io.c:59)
==11057==    by 0x127BD0: do_plan (io.c:376)
==11057==    by 0x127C09: io_ready (io.c:386)
==11057==    by 0x129461: io_loop (poll.c:295)
==11057==  Block was alloc'd at
==11057==    at 0x4C2DB2F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==11057==    by 0x132AE7: allocate (tal.c:245)
==11057==    by 0x1330A3: tal_alloc_ (tal.c:443)
==11057==    by 0x1332A6: tal_alloc_arr_ (tal.c:491)
==11057==    by 0x133FEC: tal_dup_ (tal.c:846)
==11057==    by 0x112347: new_queued_message (broadcast.c:20)
==11057==    by 0x11240B: queue_broadcast (broadcast.c:43)
==11057==    by 0x111EB0: handle_node_announcement (routing.c:918)
==11057==    by 0x10B166: handle_gossip_msg (gossip.c:170)
==11057==    by 0x10B76B: owner_msg_in (gossip.c:335)
==11057==    by 0x12712E: next_plan (io.c:59)
==11057==    by 0x127BD0: do_plan (io.c:376)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

wire_io: make a copy in io_write_wire (unless taken()).

I hit a corner case where gossipd freed a duplicate while it was being
sent out; this kind of thing doesn't happen if io_write_wire() makes
a copy by default.

We also do a memcheck() here; this gives us a caller in the backtrace
if there are uninitialized bytes, rather than waiting until the write
which happens later.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-05-19 13:30:32 +02:00
..
test sphinx: Updating daemon to new sphinx implementation 2017-05-02 11:47:52 +02:00
fromwire.c routing: Reading multiple addresses from node_announcements 2017-05-10 12:37:44 +09:30
gen_onion_wire_csv Update to latest BOLT (hyphens changed to underscores). 2017-05-12 12:59:09 +02:00
gen_peer_wire_csv Update to latest BOLT (hyphens changed to underscores). 2017-05-12 12:59:09 +02:00
Makefile Update wire from spec ed107e4ef019f33a88aa5567adca7fbb944e93af 2017-04-01 23:59:46 +10:30
onion_defs.h wire: split onion messages from peer wire messages. 2017-01-06 13:40:35 +10:30
peer_wire.c opening: don't die if we get a gossip packet. 2017-05-05 16:11:45 +09:30
peer_wire.h opening: don't die if we get a gossip packet. 2017-05-05 16:11:45 +09:30
towire.c routing: Add command line option to specify external IP address 2017-05-10 12:37:44 +09:30
wire_io.c io_write_wire: always make a copy (or steal if take). 2017-05-19 13:30:32 +02:00
wire_io.h wire/wire_io: support take() arg to io_write_wire(). 2017-03-10 21:45:55 +10:30
wire_sync.c wire/wire_sync: helper routines for direct read/write of messages. 2017-01-10 15:21:20 +10:30
wire_sync.h wire/wire_sync: helper routines for direct read/write of messages. 2017-01-10 15:21:20 +10:30
wire.h routing: Add command line option to specify external IP address 2017-05-10 12:37:44 +09:30