Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix two crashes when using websocketpp as a client library #1041

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions websocketpp/connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ class connection
public:

explicit connection(bool p_is_server, std::string const & ua, const lib::shared_ptr<alog_type>& alog,
const lib::shared_ptr<elog_type>& elog, rng_type & rng)
const lib::shared_ptr<elog_type>& elog, const lib::shared_ptr<rng_type>& rng)
: transport_con_type(p_is_server, alog, elog)
, m_handle_read_frame(lib::bind(
&type::handle_read_frame,
Expand Down Expand Up @@ -1606,7 +1606,7 @@ class connection
const lib::shared_ptr<alog_type> m_alog;
const lib::shared_ptr<elog_type> m_elog;

rng_type & m_rng;
lib::shared_ptr<rng_type> m_rng;

// Close state
/// Close code that was sent on the wire by this endpoint
Expand Down
3 changes: 2 additions & 1 deletion websocketpp/endpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class endpoint : public config::transport_type, public config::endpoint_base {
, m_pong_timeout_dur(config::timeout_pong)
, m_max_message_size(config::max_message_size)
, m_max_http_body_size(config::max_http_body_size)
, m_rng(lib::make_shared<rng_type>())
, m_is_server(p_is_server)
{
m_alog->set_channels(config::alog_level);
Expand Down Expand Up @@ -684,7 +685,7 @@ class endpoint : public config::transport_type, public config::endpoint_base {
size_t m_max_message_size;
size_t m_max_http_body_size;

rng_type m_rng;
lib::shared_ptr<rng_type> m_rng;

// static settings
bool const m_is_server;
Expand Down
6 changes: 3 additions & 3 deletions websocketpp/impl/connection_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2177,23 +2177,23 @@ connection<config>::get_processor(int version) const {
transport_con_type::is_secure(),
m_is_server,
m_msg_manager,
lib::ref(m_rng)
m_rng
);
break;
case 8:
p = lib::make_shared<processor::hybi08<config> >(
transport_con_type::is_secure(),
m_is_server,
m_msg_manager,
lib::ref(m_rng)
m_rng
);
break;
case 13:
p = lib::make_shared<processor::hybi13<config> >(
transport_con_type::is_secure(),
m_is_server,
m_msg_manager,
lib::ref(m_rng)
m_rng
);
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion websocketpp/impl/endpoint_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ endpoint<connection,config>::create_connection() {
//scoped_lock_type guard(m_mutex);
// Create a connection on the heap and manage it using a shared pointer
connection_ptr con = lib::make_shared<connection_type>(m_is_server,
m_user_agent, m_alog, m_elog, lib::ref(m_rng));
m_user_agent, m_alog, m_elog, m_rng);

connection_weak_ptr w(con);

Expand Down
2 changes: 1 addition & 1 deletion websocketpp/processors/hybi07.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class hybi07 : public hybi08<config> {
typedef typename config::con_msg_manager_type::ptr msg_manager_ptr;
typedef typename config::rng_type rng_type;

explicit hybi07(bool secure, bool p_is_server, msg_manager_ptr manager, rng_type& rng)
explicit hybi07(bool secure, bool p_is_server, msg_manager_ptr manager, const lib::shared_ptr<rng_type>& rng)
: hybi08<config>(secure, p_is_server, manager, rng) {}

/// Fill in a set of request headers for a client connection request
Expand Down
2 changes: 1 addition & 1 deletion websocketpp/processors/hybi08.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class hybi08 : public hybi13<config> {
typedef typename config::con_msg_manager_type::ptr msg_manager_ptr;
typedef typename config::rng_type rng_type;

explicit hybi08(bool secure, bool p_is_server, msg_manager_ptr manager, rng_type& rng)
explicit hybi08(bool secure, bool p_is_server, msg_manager_ptr manager, const lib::shared_ptr<rng_type>& rng)
: hybi13<config>(secure, p_is_server, manager, rng) {}

/// Fill in a set of request headers for a client connection request
Expand Down
10 changes: 5 additions & 5 deletions websocketpp/processors/hybi13.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class hybi13 : public processor<config> {

typedef std::pair<lib::error_code,std::string> err_str_pair;

explicit hybi13(bool secure, bool p_is_server, msg_manager_ptr manager, rng_type& rng)
explicit hybi13(bool secure, bool p_is_server, msg_manager_ptr manager, const lib::shared_ptr<rng_type>& rng)
: processor<config>(secure, p_is_server)
, m_msg_manager(manager)
, m_rng(rng)
Expand Down Expand Up @@ -262,7 +262,7 @@ class hybi13 : public processor<config> {
unsigned char raw_key[16];

for (int i = 0; i < 4; i++) {
conv.i = m_rng();
conv.i = (*m_rng)();
std::copy(conv.c,conv.c+4,&raw_key[i*4]);
}

Expand Down Expand Up @@ -631,7 +631,7 @@ class hybi13 : public processor<config> {

if (masked) {
// Generate masking key.
key.i = m_rng();
key.i = (*m_rng)();
} else {
key.i = 0;
}
Expand Down Expand Up @@ -999,7 +999,7 @@ class hybi13 : public processor<config> {

if (masked) {
// Generate masking key.
key.i = m_rng();
key.i = (*m_rng)();

frame::extended_header e(payload.size(),key.i);
out->set_header(frame::prepare_header(h,e));
Expand Down Expand Up @@ -1063,7 +1063,7 @@ class hybi13 : public processor<config> {
// Extended header of current frame
frame::extended_header m_extended_header;

rng_type & m_rng;
lib::shared_ptr<rng_type> m_rng;

// Overall state of the processor
state m_state;
Expand Down
27 changes: 17 additions & 10 deletions websocketpp/transport/asio/endpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ namespace asio {
* Asio.
*/
template <typename config>
class endpoint : public config::socket_type {
class endpoint : public config::socket_type, public lib::enable_shared_from_this<endpoint<config>> {
public:
/// Type of this endpoint transport component
typedef endpoint<config> type;
/// Type of a shared pointer to this endpoint transport component
typedef lib::shared_ptr<type> ptr;

/// Type of the concurrency policy
typedef typename config::concurrency_type concurrency_type;
Expand Down Expand Up @@ -168,6 +170,11 @@ class endpoint : public config::socket_type {
}*/
#endif // _WEBSOCKETPP_MOVE_SEMANTICS_

/// Get a shared pointer to this component
ptr get_shared() {
return this->shared_from_this();
}

/// Return whether or not the endpoint produces secure connections.
bool is_secure() const {
return socket_type::is_secure();
Expand Down Expand Up @@ -723,7 +730,7 @@ class endpoint : public config::socket_type {
new_timer->async_wait(
lib::bind(
&type::handle_timer,
this,
get_shared(),
new_timer,
callback,
lib::placeholders::_1
Expand Down Expand Up @@ -781,7 +788,7 @@ class endpoint : public config::socket_type {
tcon->get_raw_socket(),
tcon->get_strand()->wrap(lib::bind(
&type::handle_accept,
this,
get_shared(),
callback,
lib::placeholders::_1
))
Expand All @@ -791,7 +798,7 @@ class endpoint : public config::socket_type {
tcon->get_raw_socket(),
lib::bind(
&type::handle_accept,
this,
get_shared(),
callback,
lib::placeholders::_1
)
Expand Down Expand Up @@ -896,7 +903,7 @@ class endpoint : public config::socket_type {
config::timeout_dns_resolve,
lib::bind(
&type::handle_resolve_timeout,
this,
get_shared(),
dns_timer,
cb,
lib::placeholders::_1
Expand All @@ -908,7 +915,7 @@ class endpoint : public config::socket_type {
query,
tcon->get_strand()->wrap(lib::bind(
&type::handle_resolve,
this,
get_shared(),
tcon,
dns_timer,
cb,
Expand All @@ -921,7 +928,7 @@ class endpoint : public config::socket_type {
query,
lib::bind(
&type::handle_resolve,
this,
get_shared(),
tcon,
dns_timer,
cb,
Expand Down Expand Up @@ -1003,7 +1010,7 @@ class endpoint : public config::socket_type {
config::timeout_connect,
lib::bind(
&type::handle_connect_timeout,
this,
get_shared(),
tcon,
con_timer,
callback,
Expand All @@ -1017,7 +1024,7 @@ class endpoint : public config::socket_type {
iterator,
tcon->get_strand()->wrap(lib::bind(
&type::handle_connect,
this,
get_shared(),
tcon,
con_timer,
callback,
Expand All @@ -1030,7 +1037,7 @@ class endpoint : public config::socket_type {
iterator,
lib::bind(
&type::handle_connect,
this,
get_shared(),
tcon,
con_timer,
callback,
Expand Down