summaryrefslogtreecommitdiff
path: root/cesar/ce/rx/bitloading
diff options
context:
space:
mode:
authordufour2010-03-23 10:46:29 +0000
committerdufour2010-03-23 10:46:29 +0000
commit072d419f99963b0225b4decd2cbaf8831273f6b9 (patch)
treefdd39097c6dd81e731900586a79d27b381781842 /cesar/ce/rx/bitloading
parentf25ad7bbe5cda6874b674461bc9821f024f5f34d (diff)
cesar/ce/rx/bl: prevent access of uninitialized parts of optimization table
git-svn-id: svn+ssh://pessac/svn/cesar/trunk@6833 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cesar/ce/rx/bitloading')
-rw-r--r--cesar/ce/rx/bitloading/src/bitloading.c6
-rw-r--r--cesar/ce/rx/bitloading/test/Config1
-rw-r--r--cesar/ce/rx/bitloading/test/common-define.mk1
-rw-r--r--cesar/ce/rx/bitloading/test/src/test_bl.c53
4 files changed, 59 insertions, 2 deletions
diff --git a/cesar/ce/rx/bitloading/src/bitloading.c b/cesar/ce/rx/bitloading/src/bitloading.c
index 09d736eff3..bcca3dd0d7 100644
--- a/cesar/ce/rx/bitloading/src/bitloading.c
+++ b/cesar/ce/rx/bitloading/src/bitloading.c
@@ -149,8 +149,10 @@ ce_rx_bl_update_tone_map_at_ber_consign (u64 ber_pt,
u32 *tone_word;
s8 mod = -1;
- /* Optimize table until we reach the BER consign. */
- while (ber_pt * tm->bits_per_symbol >= ber_weighted_sum)
+ /* Optimize tone map until we reach the BER consign or we are out of
+ * table. */
+ while (ber_pt * tm->bits_per_symbol >= ber_weighted_sum
+ && pos < tonemask->carrier_nb)
{
/* Get the modulation of the lowest BER impact. */
mod = tonemap_get_tone (tm, opti[pos].carrier_index, &tone_word);
diff --git a/cesar/ce/rx/bitloading/test/Config b/cesar/ce/rx/bitloading/test/Config
new file mode 100644
index 0000000000..1221024089
--- /dev/null
+++ b/cesar/ce/rx/bitloading/test/Config
@@ -0,0 +1 @@
+CONFIG_DEBUG_FATAL_CATCH = y
diff --git a/cesar/ce/rx/bitloading/test/common-define.mk b/cesar/ce/rx/bitloading/test/common-define.mk
index acabf9d205..c3ff880491 100644
--- a/cesar/ce/rx/bitloading/test/common-define.mk
+++ b/cesar/ce/rx/bitloading/test/common-define.mk
@@ -41,3 +41,4 @@ COMPILE_DEPS += $(bl_test_vectors_tns_h) $(bl_test_vectors_scilab_h)
CLEAN_FILES += $(bl_test_vectors_tns_h) $(bl_test_vectors_scilab_h) \
$(bl_test_vectors_scilab:%=$(bl_test_vectors_dir)/%)
+USER_PROJECT_CONFIG = Config
diff --git a/cesar/ce/rx/bitloading/test/src/test_bl.c b/cesar/ce/rx/bitloading/test/src/test_bl.c
index 8fea8d3c47..95308a53dd 100644
--- a/cesar/ce/rx/bitloading/test/src/test_bl.c
+++ b/cesar/ce/rx/bitloading/test/src/test_bl.c
@@ -802,6 +802,56 @@ test_suite_ce_rx_bl_tone_map_selection (test_t t)
} test_end;
}
+/**
+ * Test suite to prevent access outside of optimization table.
+ */
+static void
+test_suite_ce_rx_bl_optimization_table (test_t t)
+{
+ test_case_begin (t, "optimization table");
+
+ ce_rx_bitloading_t bl;
+ tonemask_info_t ti;
+ ti.carrier_nb = tonemask_default (ti.tonemask);
+ ce_rx_bl_ber_impact_t opti[PHY_CARRIER_NB];
+
+ test_begin (t, "set table with impossible values for unused parts")
+ {
+ tonemap_t *tm = tonemap_alloc ();
+ TONEMAP_WRITE_BEGIN (tm, ti.tonemask)
+ {
+ TONEMAP_WRITE_MOD (1);
+ }
+ TONEMAP_WRITE_END;
+ tm->bits_per_symbol = ti.carrier_nb;
+ /* Fill optimization table for parts which should not be used with
+ * some values which will trigger a bug. */
+ uint i;
+ dbg_assert (((u16) -1) > PHY_CARRIER_NB);
+ for (i = ti.carrier_nb; i < PHY_CARRIER_NB - 1; i++)
+ {
+ opti[i].carrier_index = (u16) -1;
+ opti[i].ber_lower = opti[i].ber_diff = 0;
+ }
+ bool assert = false;
+
+ dbg_fatal_try_begin
+ {
+ ce_rx_bl_update_tone_map_at_ber_consign
+ (CE_RX_BL_BER_DEFAULT_OVER - 1, &ti, &bl, tm, opti, 0, 0);
+ }
+ dbg_fatal_try_catch_void ()
+ {
+ assert = true;
+ }
+ dbg_fatal_try_end;
+
+ /* Clean. */
+ tonemap_free (tm);
+ test_fail_if (assert == true, "access outside of optimization table");
+ } test_end;
+}
+
int
main (int argc, char **argv)
{
@@ -858,6 +908,9 @@ main (int argc, char **argv)
/* Test tone map selection. */
test_suite_ce_rx_bl_tone_map_selection (t);
+ /* Optimization table access. */
+ test_suite_ce_rx_bl_optimization_table (t);
+
/* Memory check. */
test_case_begin (t, "General");
test_begin (t, "Memory")