[MERGED] osmo-bts[master]: trx: Fix coverity BER calculation NULL dereference

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Fri Jul 29 16:45:57 UTC 2016


Harald Welte has submitted this change and it was merged.

Change subject: trx: Fix coverity BER calculation NULL dereference
......................................................................


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 <tom.tsou at ettus.com>
---
M src/osmo-bts-trx/gsm0503_coding.c
1 file changed, 9 insertions(+), 6 deletions(-)

Approvals:
  Max: Looks good to me, but someone else must approve
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/osmo-bts-trx/gsm0503_coding.c b/src/osmo-bts-trx/gsm0503_coding.c
index c601cac..4c4f7f1 100644
--- a/src/osmo-bts-trx/gsm0503_coding.c
+++ b/src/osmo-bts-trx/gsm0503_coding.c
@@ -442,30 +442,33 @@
 	},
 };
 
-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;
 }
 

-- 
To view, visit https://gerrit.osmocom.org/630
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I2c78fa6a92a3b3da4aad8f70353e5a43451b0aa5
Gerrit-PatchSet: 1
Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Owner: Tom Tsou <tom at tsou.cc>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Max <msuraev at sysmocom.de>



More information about the gerrit-log mailing list