From 717132e0c330ef56cd0923cfe844d8e692ede9d8 Mon Sep 17 00:00:00 2001 From: Robert Falkenberg Date: Sat, 12 Mar 2022 06:19:54 +0100 Subject: [PATCH] lib,rlc_am_nr: fix access of unconfigured entity --- lib/src/rlc/rlc_am_nr.cc | 5 +++++ lib/test/rlc/rlc_am_nr_test.cc | 30 +++++++++++++++--------------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/lib/src/rlc/rlc_am_nr.cc b/lib/src/rlc/rlc_am_nr.cc index 08591f4d9..331842123 100644 --- a/lib/src/rlc/rlc_am_nr.cc +++ b/lib/src/rlc/rlc_am_nr.cc @@ -854,6 +854,11 @@ void rlc_am_nr_tx::get_buffer_state(uint32_t& n_bytes_new, uint32_t& n_bytes_pri std::lock_guard lock(mutex); RlcDebug("buffer state - do_status=%s", do_status() ? "yes" : "no"); + if (!tx_enabled) { + RlcError("get_buffer_state() failed: TX is not enabled."); + return; + } + // Bytes needed for status report if (do_status()) { n_bytes_prio += rx->get_status_pdu_length(); diff --git a/lib/test/rlc/rlc_am_nr_test.cc b/lib/test/rlc/rlc_am_nr_test.cc index d0333f746..20082552b 100644 --- a/lib/test/rlc/rlc_am_nr_test.cc +++ b/lib/test/rlc/rlc_am_nr_test.cc @@ -225,9 +225,6 @@ int basic_test(rlc_am_nr_sn_size_t sn_size) rlc_am_nr_tx* tx2 = dynamic_cast(rlc2.get_tx()); rlc_am_nr_rx* rx2 = dynamic_cast(rlc2.get_rx()); - // before configuring entity - TESTASSERT_EQ(0, rlc1.get_buffer_state()); - if (not rlc1.configure(rlc_config_t::default_rlc_am_nr_config(to_number(sn_size)))) { return -1; } @@ -236,6 +233,9 @@ int basic_test(rlc_am_nr_sn_size_t sn_size) return -1; } + // after configuring entity + TESTASSERT_EQ(0, rlc1.get_buffer_state()); + basic_test_tx(&rlc1, pdu_bufs, sn_size); // Write 5 PDUs into RLC2 @@ -332,9 +332,6 @@ int lost_pdu_test(rlc_am_nr_sn_size_t sn_size) uint32_t data_pdu_size = header_size + payload_size; uint32_t expect_buffer_state = NBUFS * data_pdu_size; - // before configuring entity - TESTASSERT(0 == rlc1.get_buffer_state()); - if (not rlc1.configure(rlc_config_t::default_rlc_am_nr_config(to_number(sn_size)))) { return -1; } @@ -343,6 +340,9 @@ int lost_pdu_test(rlc_am_nr_sn_size_t sn_size) return -1; } + // after configuring entity + TESTASSERT(0 == rlc1.get_buffer_state()); + basic_test_tx(&rlc1, pdu_bufs, sn_size); // Write 5 PDUs into RLC2 @@ -469,9 +469,6 @@ int basic_segmentation_test(rlc_am_nr_sn_size_t sn_size) rlc_am_nr_tx* tx2 = dynamic_cast(rlc2.get_tx()); rlc_am_nr_rx* rx2 = dynamic_cast(rlc2.get_rx()); - // before configuring entity - TESTASSERT_EQ(0, rlc1.get_buffer_state()); - if (not rlc1.configure(rlc_config_t::default_rlc_am_nr_config(to_number(sn_size)))) { return -1; } @@ -480,6 +477,9 @@ int basic_segmentation_test(rlc_am_nr_sn_size_t sn_size) return -1; } + // after configuring entity + TESTASSERT_EQ(0, rlc1.get_buffer_state()); + // Push 1 SDU into RLC1 unique_byte_buffer_t sdu; constexpr uint32_t payload_size = 3; // Give the SDU the size of 3 bytes @@ -557,9 +557,6 @@ int segment_retx_test() rlc_am_nr_tx* tx2 = dynamic_cast(rlc2.get_tx()); rlc_am_nr_rx* rx2 = dynamic_cast(rlc2.get_rx()); - // before configuring entity - TESTASSERT_EQ(0, rlc1.get_buffer_state()); - if (not rlc1.configure(rlc_config_t::default_rlc_am_nr_config())) { return -1; } @@ -568,6 +565,9 @@ int segment_retx_test() return -1; } + // after configuring entity + TESTASSERT_EQ(0, rlc1.get_buffer_state()); + // Push 5 SDUs into RLC1 unique_byte_buffer_t sdu_bufs[NBUFS]; for (int i = 0; i < NBUFS; i++) { @@ -728,9 +728,6 @@ int retx_segment_test() rlc_am_nr_tx* tx2 = dynamic_cast(rlc2.get_tx()); rlc_am_nr_rx* rx2 = dynamic_cast(rlc2.get_rx()); - // before configuring entity - TESTASSERT(0 == rlc1.get_buffer_state()); - if (not rlc1.configure(rlc_config_t::default_rlc_am_nr_config())) { return -1; } @@ -739,6 +736,9 @@ int retx_segment_test() return -1; } + // after configuring entity + TESTASSERT(0 == rlc1.get_buffer_state()); + int n_sdu_bufs = 5; int n_pdu_bufs = 15;