From 62862ecc3ed4be097d09502d57d91543f3c41bf8 Mon Sep 17 00:00:00 2001 From: michael-west Date: Fri, 7 Mar 2014 12:23:34 -0800 Subject: Fix for Bug #378: rpc_client::call() dereferences NULL pointers - Added check for empty data before write --- host/lib/transport/nirio/rpc/rpc_client.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'host/lib/transport') diff --git a/host/lib/transport/nirio/rpc/rpc_client.cpp b/host/lib/transport/nirio/rpc/rpc_client.cpp index c16a844c1..32a40a576 100644 --- a/host/lib/transport/nirio/rpc/rpc_client.cpp +++ b/host/lib/transport/nirio/rpc/rpc_client.cpp @@ -133,9 +133,12 @@ const boost::system::error_code& rpc_client::call( CHAIN_BLOCKING_XFER( boost::asio::write(_socket, boost::asio::buffer(&_request.header, sizeof(_request.header))), sizeof(_request.header), status); - CHAIN_BLOCKING_XFER( - boost::asio::write(_socket, boost::asio::buffer(&(*_request.data.begin()), _request.data.size())), - _request.data.size(), status); + if (not _request.data.empty()) + { + CHAIN_BLOCKING_XFER( + boost::asio::write(_socket, boost::asio::buffer(&(*_request.data.begin()), _request.data.size())), + _request.data.size(), status); + } } catch (boost::exception&) { status = false; } -- cgit v1.2.3 From 50a2ab1e979c191776e4fe2d08b895941e90bd18 Mon Sep 17 00:00:00 2001 From: michael-west Date: Tue, 11 Mar 2014 23:55:11 -0700 Subject: Added assertion to make sure we are resizing buffer to a value >0. --- host/lib/transport/nirio/rpc/rpc_client.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'host/lib/transport') diff --git a/host/lib/transport/nirio/rpc/rpc_client.cpp b/host/lib/transport/nirio/rpc/rpc_client.cpp index 32a40a576..028327c2e 100644 --- a/host/lib/transport/nirio/rpc/rpc_client.cpp +++ b/host/lib/transport/nirio/rpc/rpc_client.cpp @@ -16,6 +16,7 @@ // #include +#include #include #include #include @@ -174,6 +175,7 @@ void rpc_client::_handle_response_hdr(const boost::system::error_code& err, size if (!_exec_err && (transferred == expected)) { //Response header received. Verify that it is expected if (func_args_header_t::match_function(_request.header, _response.header)) { + UHD_ASSERT_THROW(_response.header.func_args_size); _response.data.resize(_response.header.func_args_size); //Wait for response data -- cgit v1.2.3 From 1d459fa2fbbc9217c9189589077536eba26724c3 Mon Sep 17 00:00:00 2001 From: michael-west Date: Thu, 13 Mar 2014 12:12:44 -0700 Subject: Added handling for responses that do not have data. --- host/lib/transport/nirio/rpc/rpc_client.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'host/lib/transport') diff --git a/host/lib/transport/nirio/rpc/rpc_client.cpp b/host/lib/transport/nirio/rpc/rpc_client.cpp index 028327c2e..f8dc26b50 100644 --- a/host/lib/transport/nirio/rpc/rpc_client.cpp +++ b/host/lib/transport/nirio/rpc/rpc_client.cpp @@ -16,7 +16,6 @@ // #include -#include #include #include #include @@ -175,16 +174,20 @@ void rpc_client::_handle_response_hdr(const boost::system::error_code& err, size if (!_exec_err && (transferred == expected)) { //Response header received. Verify that it is expected if (func_args_header_t::match_function(_request.header, _response.header)) { - UHD_ASSERT_THROW(_response.header.func_args_size); - _response.data.resize(_response.header.func_args_size); - - //Wait for response data - boost::asio::async_read(_socket, - boost::asio::buffer(&(*_response.data.begin()), _response.data.size()), - boost::bind(&rpc_client::_handle_response_data, this, - boost::asio::placeholders::error, - boost::asio::placeholders::bytes_transferred, - _response.data.size())); + if (_response.header.func_args_size) + { + _response.data.resize(_response.header.func_args_size); + + //Wait for response data + boost::asio::async_read(_socket, + boost::asio::buffer(&(*_response.data.begin()), _response.data.size()), + boost::bind(&rpc_client::_handle_response_data, this, + boost::asio::placeholders::error, + boost::asio::placeholders::bytes_transferred, + _response.data.size())); + } else { + _handle_response_data(err, 0, 0); + } } else { //Unexpected response. Ignore it. UHD_LOG << "rpc_client received garbage responses." << std::endl; -- cgit v1.2.3