Change in osmo-bts[master]: common/oml.c: fix: properly push abis_nm_ipa_magic

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

Vadim Yanitskiy gerrit-no-reply at lists.osmocom.org
Mon Apr 1 00:19:00 UTC 2019


Vadim Yanitskiy has uploaded this change for review. ( https://gerrit.osmocom.org/13471


Change subject: common/oml.c: fix: properly push abis_nm_ipa_magic
......................................................................

common/oml.c: fix: properly push abis_nm_ipa_magic

In oml_send_msg() we optionally push the A-bis IPA magic string
("com.ipaccess") to a given message buffer as LV (Length Value),
including the terminating null byte ('\0').

There was a mix of both sizeof() and strlen() calls, and worse
luck, memcpy() has been used in a wrong way, skipping the '\0':

  memcpy(dest, src, strlen(src));

In general, this is not critical because the headroom of a given
message buffer would most likely be zero-initialized, so the '\0'
is already there. However, msgb_push() gives no such guarantee.

Let's use the libosmocore's TLV API (in particular, lv_put()),
and stick to sizeof(), so the null byte will always be included.

Change-Id: I0c7f8776d0caec40f9ed992db541f43b732e47ae
Closes: OS#3022
---
M src/common/oml.c
1 file changed, 3 insertions(+), 3 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-bts refs/changes/71/13471/1

diff --git a/src/common/oml.c b/src/common/oml.c
index c96a893..80d424f 100644
--- a/src/common/oml.c
+++ b/src/common/oml.c
@@ -36,6 +36,7 @@
 #include <osmocom/core/msgb.h>
 #include <osmocom/gsm/protocol/gsm_12_21.h>
 #include <osmocom/gsm/abis_nm.h>
+#include <osmocom/gsm/tlv.h>
 #include <osmocom/abis/e1_input.h>
 #include <osmocom/abis/ipaccess.h>
 
@@ -94,9 +95,8 @@
 
 	if (is_manuf) {
 		/* length byte, string + 0 termination */
-		uint8_t *manuf = msgb_push(msg, 1 + sizeof(abis_nm_ipa_magic));
-		manuf[0] = strlen(abis_nm_ipa_magic)+1;
-		memcpy(manuf+1, abis_nm_ipa_magic, strlen(abis_nm_ipa_magic));
+		uint8_t *manuf = msgb_push(msg, LV_GROSS_LEN(sizeof(abis_nm_ipa_magic)));
+		lv_put(manuf, sizeof(abis_nm_ipa_magic), (const uint8_t *) abis_nm_ipa_magic);
 	}
 
 	/* Push the main OML header and send it off */

-- 
To view, visit https://gerrit.osmocom.org/13471
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0c7f8776d0caec40f9ed992db541f43b732e47ae
Gerrit-Change-Number: 13471
Gerrit-PatchSet: 1
Gerrit-Owner: Vadim Yanitskiy <axilirator at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190401/2758b5dd/attachment.htm>


More information about the gerrit-log mailing list