Fix buffer overflow and compiler warnings #2

Merged
thomas merged 2 commits from rudi_s into main 2024-04-27 17:37:36 +02:00
5 changed files with 13 additions and 9 deletions

View file

@ -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); memcpy(ctx->pkt_bytes, data, length);
ctx->length = 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->raw_data_len = length;
ctx->state = DATA_RAW; ctx->state = DATA_RAW;

View file

@ -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. // 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) { if(freq_est_holdoff_samples == 0) { //freq_est_history_write_idx == FREQ_EST_L) {
float complex linearized_history[FREQ_EST_L]; //float complex linearized_history[FREQ_EST_L];
for(size_t i = 0; i < FREQ_EST_L; i++) { //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]; // 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); 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_CLOSED,
SQUELCH_OPEN, SQUELCH_OPEN,
SQUELCH_JUST_OPENED, 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)); header_enc, 8, sizeof(header_enc), &nsyms));
if(fec_decode(rx->hdr_fec, sizeof(header), header_enc, header) != LIQUID_OK) { 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->state = RX_STATE_ACQUISITION;
rx->callback(RX_EVT_HEADER_ERROR, NULL, 0); rx->callback(RX_EVT_HEADER_ERROR, NULL, 0);
break; break;
@ -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) { if(symbol_counter == rx->payload_len_symbols) {
unsigned int nsyms; unsigned int nsyms;
unsigned char payload_enc[rx->payload_len_enc_bytes]; 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( ERR_CHECK_LIQUID(liquid_repack_bytes(
symbols_int, modem_get_bps(rx->payload_demod), rx->payload_len_symbols, symbols_int, modem_get_bps(rx->payload_demod), rx->payload_len_symbols,

View file

@ -164,7 +164,7 @@ result_t layer1_tx_finalize_burst(layer1_tx_t *tx)
// allocate a temporary buffer // allocate a temporary buffer
float complex *tmp = malloc(sizeof(float complex) * tx->samples_used); float complex *tmp = malloc(sizeof(float complex) * tx->samples_used);
if(!tmp) { 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; return ERR_NO_MEM;
} }

View file

@ -2,6 +2,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #include <ctype.h>
#include <string.h>
#include <liquid/liquid.h> #include <liquid/liquid.h>

View file

@ -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 cb_rx(rx_evt_t evt, uint8_t *packet_data, size_t packet_len)
{ {
(void)packet_data;
(void)packet_len;
switch(evt) switch(evt)
{ {
case RX_EVT_CHECKSUM_ERROR: case RX_EVT_CHECKSUM_ERROR: