diff options
author | Martin Braun <martin.braun@ettus.com> | 2020-01-23 11:02:15 -0800 |
---|---|---|
committer | atrnati <54334261+atrnati@users.noreply.github.com> | 2020-02-04 08:53:01 -0600 |
commit | 4b1d346a80f860ebcf26712b721606c19dd904dd (patch) | |
tree | 31ee6a6a42ffdf3623b8695cfa17cec5f8adebf8 /host/lib/usrp_clock/octoclock/octoclock_image_loader.cpp | |
parent | 22db12c4b2b55225801ec1efb2465c7a06295b9e (diff) | |
download | uhd-4b1d346a80f860ebcf26712b721606c19dd904dd.tar.gz uhd-4b1d346a80f860ebcf26712b721606c19dd904dd.tar.bz2 uhd-4b1d346a80f860ebcf26712b721606c19dd904dd.zip |
octoclock: Avoid usage of uninitialized memory
The Octoclock host code would send uninitialized memory over the
network, which would be flagged by tools such as Valgrind. This patch
creates a factory function for OctoClock packets that initializes the
memory to zero, defaults the proto version to the OctoClock default, and
can provide a random sequence number if none is given.
Diffstat (limited to 'host/lib/usrp_clock/octoclock/octoclock_image_loader.cpp')
-rw-r--r-- | host/lib/usrp_clock/octoclock/octoclock_image_loader.cpp | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/host/lib/usrp_clock/octoclock/octoclock_image_loader.cpp b/host/lib/usrp_clock/octoclock/octoclock_image_loader.cpp index 02a243b70..c588404aa 100644 --- a/host/lib/usrp_clock/octoclock/octoclock_image_loader.cpp +++ b/host/lib/usrp_clock/octoclock/octoclock_image_loader.cpp @@ -168,7 +168,7 @@ static void octoclock_setup_session(octoclock_session_t& session, session.sequence = uint32_t(std::rand()); // Query OctoClock again to get compat number - octoclock_packet_t pkt_out; + auto pkt_out = make_octoclock_packet(); const octoclock_packet_t* pkt_in = reinterpret_cast<const octoclock_packet_t*>(session.data_in); size_t len = 0; @@ -192,8 +192,7 @@ static void octoclock_reset_into_bootloader(octoclock_session_t& session) return; // Force compat num to device's current, works around old firmware bug - octoclock_packet_t pkt_out; - pkt_out.sequence = uhd::htonx<uint32_t>(++session.sequence); + auto pkt_out = make_octoclock_packet(uhd::htonx<uint32_t>(++session.sequence)); pkt_out.proto_ver = uhd::htonx<uint32_t>(session.starting_firmware_version); pkt_out.code = RESET_CMD; @@ -229,8 +228,7 @@ static void octoclock_burn(octoclock_session_t& session) // Make sure we're in the bootloader for this octoclock_reset_into_bootloader(session); - octoclock_packet_t pkt_out; - pkt_out.sequence = uhd::htonx<uint32_t>(++session.sequence); + auto pkt_out = make_octoclock_packet(uhd::htonx<uint32_t>(++session.sequence)); const octoclock_packet_t* pkt_in = reinterpret_cast<const octoclock_packet_t*>(session.data_in); @@ -284,8 +282,7 @@ static void octoclock_burn(octoclock_session_t& session) static void octoclock_verify(octoclock_session_t& session) { - octoclock_packet_t pkt_out; - pkt_out.sequence = uhd::htonx<uint32_t>(++session.sequence); + auto pkt_out = make_octoclock_packet(uhd::htonx<uint32_t>(++session.sequence)); const octoclock_packet_t* pkt_in = reinterpret_cast<const octoclock_packet_t*>(session.data_in); size_t len = 0; @@ -331,8 +328,7 @@ static void octoclock_verify(octoclock_session_t& session) static void octoclock_finalize(octoclock_session_t& session) { - octoclock_packet_t pkt_out; - pkt_out.sequence = uhd::htonx<uint32_t>(++session.sequence); + auto pkt_out = make_octoclock_packet(uhd::htonx<uint32_t>(++session.sequence)); const octoclock_packet_t* pkt_in = reinterpret_cast<const octoclock_packet_t*>(session.data_in); size_t len = 0; |