Skip to content

Commit

Permalink
Fix a crash when DNS succeeds but returned nothing
Browse files Browse the repository at this point in the history
  • Loading branch information
GreaterFire committed Mar 25, 2020
1 parent 422d41d commit 5f161d3
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/session/clientsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ void ClientSession::in_sent() {
}
auto self = shared_from_this();
resolver.async_resolve(config.remote_addr, to_string(config.remote_port), [this, self](const boost::system::error_code error, tcp::resolver::results_type results) {
if (error) {
if (error || results.size() == 0) {
Log::log_with_endpoint(in_endpoint, "cannot resolve remote server hostname " + config.remote_addr + ": " + error.message(), Log::ERROR);
destroy();
return;
Expand Down
2 changes: 1 addition & 1 deletion src/session/forwardsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void ForwardSession::start() {
Log::log_with_endpoint(in_endpoint, "forwarding to " + config.target_addr + ':' + to_string(config.target_port) + " via " + config.remote_addr + ':' + to_string(config.remote_port), Log::INFO);
auto self = shared_from_this();
resolver.async_resolve(config.remote_addr, to_string(config.remote_port), [this, self](const boost::system::error_code error, tcp::resolver::results_type results) {
if (error) {
if (error || results.size() == 0) {
Log::log_with_endpoint(in_endpoint, "cannot resolve remote server hostname " + config.remote_addr + ": " + error.message(), Log::ERROR);
destroy();
return;
Expand Down
2 changes: 1 addition & 1 deletion src/session/natsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void NATSession::start() {
Log::log_with_endpoint(in_endpoint, "forwarding to " + target_addr + ':' + to_string(target_port) + " via " + config.remote_addr + ':' + to_string(config.remote_port), Log::INFO);
auto self = shared_from_this();
resolver.async_resolve(config.remote_addr, to_string(config.remote_port), [this, self](const boost::system::error_code error, tcp::resolver::results_type results) {
if (error) {
if (error || results.size() == 0) {
Log::log_with_endpoint(in_endpoint, "cannot resolve remote server hostname " + config.remote_addr + ": " + error.message(), Log::ERROR);
destroy();
return;
Expand Down
4 changes: 2 additions & 2 deletions src/session/serversession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ void ServerSession::in_recv(const string &data) {
sent_len += out_write_buf.length();
auto self = shared_from_this();
resolver.async_resolve(query_addr, query_port, [this, self, query_addr, query_port](const boost::system::error_code error, tcp::resolver::results_type results) {
if (error) {
if (error || results.size() == 0) {
Log::log_with_endpoint(in_endpoint, "cannot resolve remote server hostname " + query_addr + ": " + error.message(), Log::ERROR);
destroy();
return;
Expand Down Expand Up @@ -293,7 +293,7 @@ void ServerSession::udp_sent() {
string query_addr = packet.address.address;
auto self = shared_from_this();
udp_resolver.async_resolve(query_addr, to_string(packet.address.port), [this, self, packet, query_addr](const boost::system::error_code error, udp::resolver::results_type results) {
if (error) {
if (error || results.size() == 0) {
Log::log_with_endpoint(in_endpoint, "cannot resolve remote server hostname " + query_addr + ": " + error.message(), Log::ERROR);
destroy();
return;
Expand Down
2 changes: 1 addition & 1 deletion src/session/udpforwardsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void UDPForwardSession::start() {
Log::log_with_endpoint(in_endpoint, "forwarding UDP packets to " + config.target_addr + ':' + to_string(config.target_port) + " via " + config.remote_addr + ':' + to_string(config.remote_port), Log::INFO);
auto self = shared_from_this();
resolver.async_resolve(config.remote_addr, to_string(config.remote_port), [this, self](const boost::system::error_code error, tcp::resolver::results_type results) {
if (error) {
if (error || results.size() == 0) {
Log::log_with_endpoint(in_endpoint, "cannot resolve remote server hostname " + config.remote_addr + ": " + error.message(), Log::ERROR);
destroy();
return;
Expand Down

0 comments on commit 5f161d3

Please sign in to comment.