Change in libosmocore[master]: gprs_ns2: make gprs_ns2_recv_prim() always take msgb ownership

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

lynxis lazus gerrit-no-reply at lists.osmocom.org
Fri Feb 19 10:41:52 UTC 2021


lynxis lazus has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/22904 )

Change subject: gprs_ns2: make gprs_ns2_recv_prim() always take msgb ownership
......................................................................

gprs_ns2: make gprs_ns2_recv_prim() always take msgb ownership

Have a clear ownership of the msgb to prevent any leaks.

Related: OS#5022
Change-Id: I67e70561e7aae4d4556a02f03a8af6c2daf5ff9c
---
M src/gb/gprs_ns2.c
1 file changed, 25 insertions(+), 11 deletions(-)

Approvals:
  laforge: Looks good to me, approved
  daniel: Looks good to me, approved
  pespin: Looks good to me, but someone else must approve
  Jenkins Builder: Verified



diff --git a/src/gb/gprs_ns2.c b/src/gb/gprs_ns2.c
index 3699d62..3e023ca 100644
--- a/src/gb/gprs_ns2.c
+++ b/src/gb/gprs_ns2.c
@@ -482,33 +482,43 @@
 	struct gprs_ns2_vc *nsvc = NULL;
 	uint16_t bvci, nsei;
 	uint8_t sducontrol = 0;
+	int rc = 0;
 
-	if (oph->sap != SAP_NS)
-		return -EINVAL;
+	if (oph->sap != SAP_NS) {
+		rc = -EINVAL;
+		goto out;
+	}
 
 	nsp = container_of(oph, struct osmo_gprs_ns2_prim, oph);
 
-	if (oph->operation != PRIM_OP_REQUEST || oph->primitive != GPRS_NS2_PRIM_UNIT_DATA)
-		return -EINVAL;
+	if (oph->operation != PRIM_OP_REQUEST || oph->primitive != GPRS_NS2_PRIM_UNIT_DATA) {
+		rc = -EINVAL;
+		goto out;
+	}
 
-	if (!oph->msg)
-		return -EINVAL;
+	if (!oph->msg) {
+		rc = -EINVAL;
+		goto out;
+	}
 
 	bvci = nsp->bvci;
 	nsei = nsp->nsei;
 
 	nse = gprs_ns2_nse_by_nsei(nsi, nsei);
-	if (!nse)
-		return -EINVAL;
+	if (!nse) {
+		rc = -EINVAL;
+		goto out;
+	}
 
-	if (!nse->alive)
-		return 0;
+	if (!nse->alive) {
+		goto out;
+	}
 
 	nsvc = ns2_load_sharing(nse, bvci, nsp->u.unitdata.link_selector);
 
 	/* TODO: send a status primitive back */
 	if (!nsvc)
-		return 0;
+		goto out;
 
 	if (nsp->u.unitdata.change == GPRS_NS2_ENDPOINT_REQUEST_CHANGE)
 		sducontrol = 1;
@@ -516,6 +526,10 @@
 		sducontrol = 2;
 
 	return ns2_tx_unit_data(nsvc, bvci, sducontrol, oph->msg);
+
+out:
+	msgb_free(oph->msg);
+	return rc;
 }
 
 /*! Send a STATUS.ind primitive to the specified NS instance user.

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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I67e70561e7aae4d4556a02f03a8af6c2daf5ff9c
Gerrit-Change-Number: 22904
Gerrit-PatchSet: 12
Gerrit-Owner: lynxis lazus <lynxis at fe80.eu>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <dwillmann at sysmocom.de>
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: lynxis lazus <lynxis at fe80.eu>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210219/208271af/attachment.htm>


More information about the gerrit-log mailing list