From 9f7aa7f3a6c6d95637a386bcedc4aee63b9646c2 Mon Sep 17 00:00:00 2001 From: Steven Siloti Date: Sun, 22 Nov 2015 15:56:27 -0800 Subject: [PATCH] fix segfault in put_data If less than three nodes are found to put an item to then traversal_algorithm::start will add router nodes. This leads to a crash in put_data::invoke when it tries to read a token from uninitialized memory in a null_observer. --- include/libtorrent/kademlia/put_data.hpp | 1 + src/kademlia/put_data.cpp | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/include/libtorrent/kademlia/put_data.hpp b/include/libtorrent/kademlia/put_data.hpp index 5330581b5..96a91a52d 100644 --- a/include/libtorrent/kademlia/put_data.hpp +++ b/include/libtorrent/kademlia/put_data.hpp @@ -58,6 +58,7 @@ struct put_data: traversal_algorithm put_data(node& node, put_callback const& callback); virtual char const* name() const; + virtual void start(); void set_data(item const& data) { m_data = data; } diff --git a/src/kademlia/put_data.cpp b/src/kademlia/put_data.cpp index 51e7b4556..2e7a393d8 100644 --- a/src/kademlia/put_data.cpp +++ b/src/kademlia/put_data.cpp @@ -47,6 +47,14 @@ put_data::put_data(node& dht_node, put_callback const& callback) char const* put_data::name() const { return "put_data"; } +void put_data::start() +{ + // router nodes must not be added to puts + init(); + bool is_done = add_requests(); + if (is_done) done(); +} + void put_data::set_targets(std::vector > const& targets) { for (std::vector >::const_iterator i = targets.begin()