From 4ed06b9eff158e5f9c85564db0bfca0ca5f7b053 Mon Sep 17 00:00:00 2001 From: Mark Thompson <129641948+NotherNgineer@users.noreply.github.com> Date: Wed, 12 Jul 2023 13:27:02 -0500 Subject: [PATCH] Correct HamRadio frequency validation (#1266) --- firmware/application/freqman_db.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/firmware/application/freqman_db.cpp b/firmware/application/freqman_db.cpp index 09c67fab..fba166d4 100644 --- a/firmware/application/freqman_db.cpp +++ b/firmware/application/freqman_db.cpp @@ -336,11 +336,18 @@ bool parse_freqman_entry(std::string_view str, freqman_entry& entry) { if (entry.type == freqman_type::Unknown) return false; - // Ranges should have both frequencies set and A <= B. - if (entry.type == freqman_type::Range || entry.type == freqman_type::HamRadio) { - if (entry.frequency_a == 0 || entry.frequency_b == 0) - return false; + // Frequency A must be set for all types + if (entry.frequency_a == 0) + return false; + // Frequency B must be set for type Range or Ham Radio + if (entry.type == freqman_type::Range || entry.type == freqman_type::HamRadio) { + if (entry.frequency_b == 0) + return false; + } + + // Ranges should have frequencies A <= B. + if (entry.type == freqman_type::Range) { if (entry.frequency_a > entry.frequency_b) return false; } @@ -457,4 +464,4 @@ bool FreqmanDB::empty() const { // FileWrapper always presents a single line even for empty files. // A DB is only really empty if the file size is 0. return !wrapper_ || wrapper_->size() == 0; -} \ No newline at end of file +}