diff options
author | Martin Braun <martin.braun@ettus.com> | 2021-11-11 10:38:47 +0100 |
---|---|---|
committer | Aaron Rossetto <aaron.rossetto@ni.com> | 2021-11-15 10:31:37 -0800 |
commit | 47a9e278f5a7efc1e67703814065046863ad0329 (patch) | |
tree | cc386e5cd80bd4f2df041935afcb2404ba27731b /host/lib | |
parent | 09839fa23229daf00cb9b857806d47d2cac50057 (diff) | |
download | uhd-47a9e278f5a7efc1e67703814065046863ad0329.tar.gz uhd-47a9e278f5a7efc1e67703814065046863ad0329.tar.bz2 uhd-47a9e278f5a7efc1e67703814065046863ad0329.zip |
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.
Diffstat (limited to 'host/lib')
-rw-r--r-- | host/lib/rfnoc/mgmt_portal.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
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)."); |