From c8a7ce26a56517e5ece4b6abf0e5fb052f60f883 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Sat, 7 Nov 2026 14:45:27 +0100 Subject: [PATCH] Fix defects detected by Coverity Scan --- .../PVT/gnuradio_blocks/rtklib_pvt_gs.cc | 1 - src/algorithms/PVT/libs/rtklib_solver.cc | 2 +- src/algorithms/libs/rtklib/rtklib_stream.cc | 17 +++++++++++++++-- .../apps/volk_gnsssdr_option_helpers.cc | 5 +++-- .../volk_gnsssdr/apps/volk_gnsssdr_profile.cc | 4 ++-- .../volk_gnsssdr/lib/qa_utils.cc | 2 +- .../adapters/custom_udp_signal_source.cc | 2 +- src/core/libs/osnma_msg_receiver.cc | 2 +- .../control-plane/satellite_visibility_test.cc | 5 +++-- 9 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_gs.cc b/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_gs.cc index f95abb71b..d1c584c61 100644 --- a/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_gs.cc +++ b/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_gs.cc @@ -2850,7 +2850,6 @@ void rtklib_pvt_gs::report_fixed_base_status() << " common satellites: " << d_user_pvt_solver->get_fixed_base_common_satellites(); break; - case Rtklib_Fixed_Base_Status::NOT_REQUESTED: default: break; } diff --git a/src/algorithms/PVT/libs/rtklib_solver.cc b/src/algorithms/PVT/libs/rtklib_solver.cc index 307338ab9..bdf96f8a7 100644 --- a/src/algorithms/PVT/libs/rtklib_solver.cc +++ b/src/algorithms/PVT/libs/rtklib_solver.cc @@ -3495,7 +3495,7 @@ bool Rtklib_Solver::get_PVT(const std::map &gnss_observables_ { info.healthy = healthy; } - d_monitor_pvt.tracked_satellites.push_back(info); + d_monitor_pvt.tracked_satellites.push_back(std::move(info)); } } diff --git a/src/algorithms/libs/rtklib/rtklib_stream.cc b/src/algorithms/libs/rtklib/rtklib_stream.cc index a9e3127ed..cb484a9cb 100644 --- a/src/algorithms/libs/rtklib/rtklib_stream.cc +++ b/src/algorithms/libs/rtklib/rtklib_stream.cc @@ -46,6 +46,7 @@ #include #include #include +#include #include #include #include @@ -613,8 +614,19 @@ int readfile(file_t *file, unsigned char *buff, int nmax, char *msg) std::snprintf(msg, MAXSTRPATH, "T%+.1fs", seconds); } + /* Reject positions fseeko() cannot address (corrupted tag file). + Past this check, the cast to int64_t below cannot wrap negative, + so nmax can never exceed the caller's buffer size. */ + if (record.fpos > static_cast(std::numeric_limits::max())) + { + trace(1, "readfile: invalid file position in tag file\n"); + return 0; + } + + const int64_t fpos_delta = static_cast(record.fpos) - static_cast(file->fpos); + /* If jump in file position */ - if (static_cast(record.fpos) - static_cast(file->fpos) >= nmax) + if (fpos_delta >= nmax) { if (fseeko(file->fp, static_cast(record.fpos), SEEK_SET) != 0) { @@ -624,7 +636,8 @@ int readfile(file_t *file, unsigned char *buff, int nmax, char *msg) return 0; } - nmax = static_cast(record.fpos - file->fpos); + /* 0 <= nmax < caller's nmax; a backward position reads nothing */ + nmax = fpos_delta > 0 ? static_cast(fpos_delta) : 0; if (file->repmode || file->speed > 0.0) { diff --git a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/apps/volk_gnsssdr_option_helpers.cc b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/apps/volk_gnsssdr_option_helpers.cc index 9d6f16a7f..61e42c6df 100644 --- a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/apps/volk_gnsssdr_option_helpers.cc +++ b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/apps/volk_gnsssdr_option_helpers.cc @@ -87,7 +87,8 @@ option_t::option_t(std::string t_longform, : longform("--" + t_longform), shortform("-" + t_shortform), msg(std::move(t_msg)), - printval(std::move(t_printval)) + printval(std::move(t_printval)), + callback(nullptr) { option_type = STRING; } @@ -97,7 +98,7 @@ option_t::option_t(std::string t_longform, * Option List */ -option_list::option_list(std::string program_name) : d_program_name(program_name) +option_list::option_list(std::string program_name) : d_program_name(std::move(program_name)) { d_internal_list = std::vector(); } diff --git a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/apps/volk_gnsssdr_profile.cc b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/apps/volk_gnsssdr_profile.cc index 8710f2966..77f871f24 100644 --- a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/apps/volk_gnsssdr_profile.cc +++ b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/apps/volk_gnsssdr_profile.cc @@ -53,9 +53,9 @@ void set_update(bool val) { update_mode = val; } bool dry_run = false; void set_dryrun(bool val) { dry_run = val; } std::string json_filename(""); -void set_json(std::string val) { json_filename = val; } +void set_json(std::string val) { json_filename = std::move(val); } std::string volk_config_path(""); -void set_volk_config(std::string val) { volk_config_path = val; } +void set_volk_config(std::string val) { volk_config_path = std::move(val); } int main(int argc, char *argv[]) { diff --git a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/lib/qa_utils.cc b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/lib/qa_utils.cc index 2dae51f31..b132d5b4f 100644 --- a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/lib/qa_utils.cc +++ b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/lib/qa_utils.cc @@ -627,7 +627,7 @@ bool run_volk_gnsssdr_tests(volk_gnsssdr_func_desc_t desc, memcpy(arch_inbuff, inbuffs[j], vlen * inputsig[j].size * (inputsig[j].is_complex ? 2 : 1)); arch_buffs.push_back(arch_inbuff); } - test_data.push_back(arch_buffs); + test_data.push_back(std::move(arch_buffs)); } std::vector both_sigs; diff --git a/src/algorithms/signal_source/adapters/custom_udp_signal_source.cc b/src/algorithms/signal_source/adapters/custom_udp_signal_source.cc index 705ef2bb9..a4bab4430 100644 --- a/src/algorithms/signal_source/adapters/custom_udp_signal_source.cc +++ b/src/algorithms/signal_source/adapters/custom_udp_signal_source.cc @@ -61,7 +61,7 @@ CustomUDPSignalSource::CustomUDPSignalSource(const ConfigurationInterface* confi const std::string sample_type = configuration->property(role + ".sample_type", default_sample_type); item_type_ = configuration->property(role + ".item_type", default_item_type); - udp_gnss_rx_source_ = Gr_Complex_Ip_Packet_Source::make(capture_device, + udp_gnss_rx_source_ = Gr_Complex_Ip_Packet_Source::make(std::move(capture_device), address, port, payload_bytes, diff --git a/src/core/libs/osnma_msg_receiver.cc b/src/core/libs/osnma_msg_receiver.cc index 5bb8d0efd..f69807d91 100644 --- a/src/core/libs/osnma_msg_receiver.cc +++ b/src/core/libs/osnma_msg_receiver.cc @@ -2308,7 +2308,7 @@ void osnma_msg_receiver::process_dsm_message(const std::vector& dsm_msg candidate_public_key.pkid = npktid; candidate_public_key.npkt_valid = true; candidate_public_key.npkt = d_osnma_data.d_dsm_pkr_message.npkt; - candidate_public_key.key_type = PKT; + candidate_public_key.key_type = std::move(PKT); candidate_public_key.source = "DSM-PKR"; candidate_public_key.compressed_key = d_new_public_key; candidate_public_key.fingerprint_sha256 = diff --git a/tests/unit-tests/control-plane/satellite_visibility_test.cc b/tests/unit-tests/control-plane/satellite_visibility_test.cc index 2cc52d7fb..58ad0fce5 100644 --- a/tests/unit-tests/control-plane/satellite_visibility_test.cc +++ b/tests/unit-tests/control-plane/satellite_visibility_test.cc @@ -38,6 +38,7 @@ #include #include #include +#include class VisibilityTestPvt : public PvtInterface { @@ -116,7 +117,7 @@ protected: gps.WN = fix.week % 1024; gps.toe = gps.toc = gps.tow = tow; gps.sqrtA = 5153.795; - pvt->gps_eph[1] = gps; + pvt->gps_eph[1] = std::move(gps); SetGpsAlmanac(tow); Gps_Almanac gps_almanac = pvt->gps_alm.at(1); gps_almanac.PRN = 2; @@ -141,7 +142,7 @@ protected: beidou.WN = fix.week - 1356; beidou.toe = beidou.toc = beidou.tow = tow; beidou.sqrtA = 5282.0; - pvt->bds_eph[10] = beidou; + pvt->bds_eph[10] = std::move(beidou); Beidou_Dnav_Almanac beidou_almanac; beidou_almanac.PRN = 11; beidou_almanac.WNa = fix.week - 1356;