[PATCH] openbsc[master]: abis: fix unaligned memory access

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/.

Max gerrit-no-reply at lists.osmocom.org
Wed Aug 30 17:50:26 UTC 2017


Review at  https://gerrit.osmocom.org/3750

abis: fix unaligned memory access

* replace pointer arithmetic with struct use to prevent unaligned memory
access on arm.
* constify function parameters

Change-Id: Ie8a3107c22cd7f3682fac037e04a50ef3ea9171c
Fixes: OS#2472
---
M openbsc/include/openbsc/gsm_data.h
M openbsc/src/libbsc/abis_nm.c
M openbsc/src/libcommon/gsm_data.c
3 files changed, 8 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/openbsc refs/changes/50/3750/1

diff --git a/openbsc/include/openbsc/gsm_data.h b/openbsc/include/openbsc/gsm_data.h
index 4035b39..8b689a5 100644
--- a/openbsc/include/openbsc/gsm_data.h
+++ b/openbsc/include/openbsc/gsm_data.h
@@ -558,8 +558,8 @@
 const char *bts_gprs_mode_name(enum bts_gprs_mode mode);
 int bts_gprs_mode_is_compat(struct gsm_bts *bts, enum bts_gprs_mode mode);
 
-int gsm48_ra_id_by_bts(uint8_t *buf, struct gsm_bts *bts);
-void gprs_ra_id_by_bts(struct gprs_ra_id *raid, struct gsm_bts *bts);
+int gsm48_ra_id_by_bts(uint8_t *buf, const struct gsm_bts *bts, bool rac_override);
+void gprs_ra_id_by_bts(struct gprs_ra_id *raid, const struct gsm_bts *bts);
 struct gsm_meas_rep *lchan_next_meas_rep(struct gsm_lchan *lchan);
 
 int gsm_btsmodel_set_feature(struct gsm_bts_model *model, enum gsm_bts_features feat);
diff --git a/openbsc/src/libbsc/abis_nm.c b/openbsc/src/libbsc/abis_nm.c
index cf20d7c..ec1f8d1 100644
--- a/openbsc/src/libbsc/abis_nm.c
+++ b/openbsc/src/libbsc/abis_nm.c
@@ -2787,8 +2787,7 @@
 {
 	/* we simply reuse the GSM48 function and overwrite the RAC
 	 * with the Cell ID */
-	gsm48_ra_id_by_bts(buf, bts);
-	*((uint16_t *)(buf + 5)) = htons(bts->cell_identity);
+	gsm48_ra_id_by_bts(buf, bts, true);
 }
 
 void gsm_trx_lock_rf(struct gsm_bts_trx *trx, int locked)
diff --git a/openbsc/src/libcommon/gsm_data.c b/openbsc/src/libcommon/gsm_data.c
index f1049e9..c62072f 100644
--- a/openbsc/src/libcommon/gsm_data.c
+++ b/openbsc/src/libcommon/gsm_data.c
@@ -335,7 +335,7 @@
 	return bts;
 }
 
-void gprs_ra_id_by_bts(struct gprs_ra_id *raid, struct gsm_bts *bts)
+void gprs_ra_id_by_bts(struct gprs_ra_id *raid, const struct gsm_bts *bts)
 {
 	raid->mcc = bts->network->country_code;
 	raid->mnc = bts->network->network_code;
@@ -343,12 +343,15 @@
 	raid->rac = bts->gprs.rac;
 }
 
-int gsm48_ra_id_by_bts(uint8_t *buf, struct gsm_bts *bts)
+int gsm48_ra_id_by_bts(uint8_t *buf, const struct gsm_bts *bts, bool rac_override)
 {
 	struct gprs_ra_id raid;
 
 	gprs_ra_id_by_bts(&raid, bts);
 
+	if (rac_override)
+		raid.rac = htons(bts->cell_identity);
+
 	return gsm48_construct_ra(buf, &raid);
 }
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie8a3107c22cd7f3682fac037e04a50ef3ea9171c
Gerrit-PatchSet: 1
Gerrit-Project: openbsc
Gerrit-Branch: master
Gerrit-Owner: Max <msuraev at sysmocom.de>



More information about the gerrit-log mailing list