From daa7ea5913bcbe2c63715eaab18b8c8f26608608 Mon Sep 17 00:00:00 2001 From: Steven Koo Date: Fri, 18 Dec 2020 16:11:57 -0600 Subject: usrprio: catch exceptions if rpc data read fails This is an unhandled exception case that can cause silent failures for detecting ethernet x310 devices if the niusrpriorpc service is enabled. The "out_args >> vtr_size" read can throw an exception if there are no PCIe devices connected. Signed-off-by: Steven Koo --- host/lib/transport/nirio/rpc/usrprio_rpc_client.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'host/lib') diff --git a/host/lib/transport/nirio/rpc/usrprio_rpc_client.cpp b/host/lib/transport/nirio/rpc/usrprio_rpc_client.cpp index 718ff7c05..116232def 100644 --- a/host/lib/transport/nirio/rpc/usrprio_rpc_client.cpp +++ b/host/lib/transport/nirio/rpc/usrprio_rpc_client.cpp @@ -40,14 +40,28 @@ nirio_status usrprio_rpc_client::niusrprio_enumerate(NIUSRPRIO_ENUMERATE_ARGS) _rpc_client.call(NIUSRPRIO_ENUMERATE, in_args, out_args, _timeout)); if (nirio_status_not_fatal(status)) { - out_args >> status; - out_args >> vtr_size; + try { + out_args >> status; + out_args >> vtr_size; + } catch (std::exception&) { + if (status == NiRio_Status_Success) { + status = NiRio_Status_RpcSessionError; + } + return status; + } } if (nirio_status_not_fatal(status) && vtr_size > 0) { device_info_vtr.resize(vtr_size); for (size_t i = 0; i < (size_t)vtr_size; i++) { usrprio_device_info info; - out_args >> info; + try { + out_args >> info; + } catch (std::exception&) { + if (status == NiRio_Status_Success) { + status = NiRio_Status_RpcSessionError; + } + return status; + } device_info_vtr[i] = info; } } -- cgit v1.2.3