From d6920df6303bf3004f34cc888a06948c399f09a5 Mon Sep 17 00:00:00 2001 From: Tom Tsou Date: Thu, 28 Jul 2016 11:14:08 -0700 Subject: [PATCH] trx: Fix coverity BER calculation NULL dereference Allow output of encoded bit count or error count on BER calculation without requiring both pointers to exist. Change-Id: I2c78fa6a92a3b3da4aad8f70353e5a43451b0aa5 Fixes: Coverity CID 137963 Signed-off-by: Tom Tsou --- src/osmo-bts-trx/gsm0503_coding.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/osmo-bts-trx/gsm0503_coding.c b/src/osmo-bts-trx/gsm0503_coding.c index c601cac36..4c4f7f1e1 100644 --- a/src/osmo-bts-trx/gsm0503_coding.c +++ b/src/osmo-bts-trx/gsm0503_coding.c @@ -442,30 +442,33 @@ struct gsm0503_mcs_code gsm0503_mcs_dl_codes[EGPRS_NUM_MCS] = { }, }; -int osmo_conv_decode_ber(const struct osmo_conv_code *code, +static int osmo_conv_decode_ber(const struct osmo_conv_code *code, const sbit_t *input, ubit_t *output, int *n_errors, int *n_bits_total) { - int res, i; + int res, i, coded_len; ubit_t recoded[EGPRS_DATA_C_MAX]; res = osmo_conv_decode(code, input, output); - if (n_bits_total) { - *n_bits_total = osmo_conv_encode(code, output, recoded); - OSMO_ASSERT(sizeof(recoded)/sizeof(recoded[0]) >= *n_bits_total); + if (n_bits_total || n_errors) { + coded_len = osmo_conv_encode(code, output, recoded); + OSMO_ASSERT(sizeof(recoded)/sizeof(recoded[0]) >= coded_len); } /* Count bit errors */ if (n_errors) { *n_errors = 0; - for (i=0; i< *n_bits_total; i++) { + for (i = 0; i < coded_len; i++) { if (! ((recoded[i] && input[i]<0) || (!recoded[i] && input[i]>0)) ) *n_errors += 1; } } + if (n_bits_total) + *n_bits_total = coded_len; + return res; }