Skip to content

Commit

Permalink
Fix access to freed mem in WS client after #23241
Browse files Browse the repository at this point in the history
I was wrong in assuming that String had to survive long enough to avoid
it, what actually needed to survive was the CharString obtained from the
acsii() or utf8() function.
At least according to valgrind
  • Loading branch information
Faless committed Nov 3, 2018
1 parent 121cead commit e3008b7
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions modules/websocket/lws_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,13 @@ Error LWSClient::connect_to_host(String p_host, String p_path, uint16_t p_port,
i.ssl_connection = 0;
}

// This String needs to survive till we call lws_client_connect_via_info
String addr_str = (String)addr;

i.address = addr_str.ascii().get_data();
i.host = p_host.utf8().get_data();
i.path = p_path.utf8().get_data();
// These CharStrings needs to survive till we call lws_client_connect_via_info
CharString addr_ch = ((String)addr).ascii();
CharString host_ch = p_host.utf8();
CharString path_ch = p_path.utf8();
i.address = addr_ch.get_data();
i.host = host_ch.get_data();
i.path = path_ch.get_data();
i.port = p_port;

lws_client_connect_via_info(&i);
Expand Down

0 comments on commit e3008b7

Please sign in to comment.