From 47a9e278f5a7efc1e67703814065046863ad0329 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Thu, 11 Nov 2021 10:38:47 +0100 Subject: rfnoc: mgmt_portal: Fix order of validity checks The order must: - Check transaction has the right number of hops, then read hop - Check hop has the right number of operations (at least 2), then read those ops - Check the ops have the correct opcodes The code was doing checks in the wrong order. Thanks to Github user johnwstanford for pointing this out. --- host/lib/rfnoc/mgmt_portal.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'host/lib') diff --git a/host/lib/rfnoc/mgmt_portal.cpp b/host/lib/rfnoc/mgmt_portal.cpp index 8ad214f5b..0a0a696a5 100644 --- a/host/lib/rfnoc/mgmt_portal.cpp +++ b/host/lib/rfnoc/mgmt_portal.cpp @@ -918,7 +918,7 @@ private: // Functions throw uhd::op_failed("Management operation failed. Incorrect format (hops)."); } const mgmt_hop_t& rhop = resp_xact.get_hop(0); - if (rhop.get_num_ops() <= 1 + if (rhop.get_num_ops() < 2 || rhop.get_op(0).get_op_code() != mgmt_op_t::MGMT_OP_NOP) { throw uhd::op_failed( "Management operation failed. Incorrect format (operations)."); @@ -982,9 +982,13 @@ private: // Functions throw uhd::op_failed("Management operation failed. Incorrect format (hops)."); } const mgmt_hop_t& rhop = transaction.get_hop(0); + if (rhop.get_num_ops() < 2) { + throw uhd::op_failed( + "Management operation failed. Incorrect number of operations."); + } const mgmt_op_t& nop_resp = rhop.get_op(0); const mgmt_op_t& info_resp = rhop.get_op(1); - if (rhop.get_num_ops() <= 1 || nop_resp.get_op_code() != mgmt_op_t::MGMT_OP_NOP + if (nop_resp.get_op_code() != mgmt_op_t::MGMT_OP_NOP || info_resp.get_op_code() != mgmt_op_t::MGMT_OP_INFO_RESP) { throw uhd::op_failed( "Management operation failed. Incorrect format (operations)."); -- cgit v1.2.3