From b3ceb50b239747d5d7aea97f4de646a5e7b8b13b Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sat, 27 Apr 2024 12:16:49 +0200 Subject: [PATCH 1/2] Fix one-byte buffer-overflow in layer1_rx_process() --- impl/src/layer1/rx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/impl/src/layer1/rx.c b/impl/src/layer1/rx.c index f33b5d9..d90a0f6 100644 --- a/impl/src/layer1/rx.c +++ b/impl/src/layer1/rx.c @@ -415,7 +415,7 @@ result_t layer1_rx_process(layer1_rx_t *rx, const float complex *samples, size_t if(symbol_counter == rx->payload_len_symbols) { unsigned int nsyms; unsigned char payload_enc[rx->payload_len_enc_bytes]; - unsigned char payload[rx->payload_len_bytes]; + unsigned char payload[rx->payload_len_bytes+1]; ERR_CHECK_LIQUID(liquid_repack_bytes( symbols_int, modem_get_bps(rx->payload_demod), rx->payload_len_symbols, -- 2.45.2 From a3928d0ad0aae18a04e72014451aef6200c09c88 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sat, 27 Apr 2024 12:22:33 +0200 Subject: [PATCH 2/2] Fix compiler warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - passing argument 2 of 'crc_generate_key' discards ‘const’ qualifier; a bit ugly but signature of crc_generate_key() is wrong - variable 'linearized_history' set but not used - typedef is unused - superfluous arguments to DEBUG_LOG() and fprintf() - implicit declaration of function 'memset' - unused arguments --- impl/src/layer1/packet_mod.c | 2 +- impl/src/layer1/rx.c | 12 ++++++------ impl/src/layer1/tx.c | 2 +- impl/src/main.c | 1 + impl/test/layer1/test_rx_file.c | 3 +++ 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/impl/src/layer1/packet_mod.c b/impl/src/layer1/packet_mod.c index 03b8554..a371ce3 100644 --- a/impl/src/layer1/packet_mod.c +++ b/impl/src/layer1/packet_mod.c @@ -81,7 +81,7 @@ result_t packet_mod_set_data(packet_mod_ctx_t *ctx, const unsigned char *data, s memcpy(ctx->pkt_bytes, data, length); ctx->length = length; - ctx->raw_data_crc = crc_generate_key(PAYLOAD_CRC_SCHEME, data, length); + ctx->raw_data_crc = crc_generate_key(PAYLOAD_CRC_SCHEME, (unsigned char *)data, length); ctx->raw_data_len = length; ctx->state = DATA_RAW; diff --git a/impl/src/layer1/rx.c b/impl/src/layer1/rx.c index d90a0f6..8fffc62 100644 --- a/impl/src/layer1/rx.c +++ b/impl/src/layer1/rx.c @@ -101,10 +101,10 @@ static bool acquire_preamble(layer1_rx_t *rx, const float complex sample, bool d // BPSK symbols and therefore can be used during ramp-up and preamble. if(freq_est_holdoff_samples == 0) { //freq_est_history_write_idx == FREQ_EST_L) { - float complex linearized_history[FREQ_EST_L]; - for(size_t i = 0; i < FREQ_EST_L; i++) { - linearized_history[i] = freq_est_history[(i + freq_est_history_write_idx) % FREQ_EST_L]; - } + //float complex linearized_history[FREQ_EST_L]; + //for(size_t i = 0; i < FREQ_EST_L; i++) { + // linearized_history[i] = freq_est_history[(i + freq_est_history_write_idx) % FREQ_EST_L]; + //} float freq_est = freq_est_in_rampup(freq_est_history, FREQ_EST_L, NULL); @@ -148,7 +148,7 @@ static bool acquire_preamble(layer1_rx_t *rx, const float complex sample, bool d } -typedef enum squelch_state_t { +enum squelch_state_t { SQUELCH_CLOSED, SQUELCH_OPEN, SQUELCH_JUST_OPENED, @@ -331,7 +331,7 @@ result_t layer1_rx_process(layer1_rx_t *rx, const float complex *samples, size_t header_enc, 8, sizeof(header_enc), &nsyms)); if(fec_decode(rx->hdr_fec, sizeof(header), header_enc, header) != LIQUID_OK) { - DEBUG_LOG("Header decoding failed!\n", rx->modcod); + DEBUG_LOG("Header decoding failed!\n"); rx->state = RX_STATE_ACQUISITION; rx->callback(RX_EVT_HEADER_ERROR, NULL, 0); break; diff --git a/impl/src/layer1/tx.c b/impl/src/layer1/tx.c index 6a7e1c1..c48df0f 100644 --- a/impl/src/layer1/tx.c +++ b/impl/src/layer1/tx.c @@ -164,7 +164,7 @@ result_t layer1_tx_finalize_burst(layer1_tx_t *tx) // allocate a temporary buffer float complex *tmp = malloc(sizeof(float complex) * tx->samples_used); if(!tmp) { - fprintf(stderr, "Could not allocate buffer for TX frequency correction.\n", len, tx->samples_used); + fprintf(stderr, "Could not allocate buffer for TX frequency correction.\n"); return ERR_NO_MEM; } diff --git a/impl/src/main.c b/impl/src/main.c index 9a24a13..ea8708a 100644 --- a/impl/src/main.c +++ b/impl/src/main.c @@ -2,6 +2,7 @@ #include #include #include +#include #include diff --git a/impl/test/layer1/test_rx_file.c b/impl/test/layer1/test_rx_file.c index b8afa96..06a5c4c 100644 --- a/impl/test/layer1/test_rx_file.c +++ b/impl/test/layer1/test_rx_file.c @@ -58,6 +58,9 @@ static result_t sdr_rf_to_baseband(nco_crcf nco, firdecim_crcf decim, void cb_rx(rx_evt_t evt, uint8_t *packet_data, size_t packet_len) { + (void)packet_data; + (void)packet_len; + switch(evt) { case RX_EVT_CHECKSUM_ERROR: -- 2.45.2