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

libmsc: make pitfall in gsm0408_dispatch() more obvious

The function gsm0408_dispatch() accepts a message buffer pointer
and accesses the l3h pointer. Even in a properly allocated
message buffer, this may lead into a segfault if the user forgets
to set the l3h pointer. This commit adds assertions to popup a
more expressive error message.

Change-Id: Ic0463191e68bac1630481a5cc220222b2f7ef3f2
---
M openbsc/src/libmsc/gsm_04_08.c
1 file changed, 6 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/openbsc refs/changes/47/2447/1

diff --git a/openbsc/src/libmsc/gsm_04_08.c b/openbsc/src/libmsc/gsm_04_08.c
index 376106f..6641eb9 100644
--- a/openbsc/src/libmsc/gsm_04_08.c
+++ b/openbsc/src/libmsc/gsm_04_08.c
@@ -3991,13 +3991,17 @@
 /* Main entry point for GSM 04.08/44.008 Layer 3 data (e.g. from the BSC). */
 int gsm0408_dispatch(struct gsm_subscriber_connection *conn, struct msgb *msg)
 {
-       struct gsm48_hdr *gh = msgb_l3(msg);
-       uint8_t pdisc = gsm48_hdr_pdisc(gh);
+       struct gsm48_hdr *gh;
+       uint8_t pdisc;
        int rc = 0;
 
+       OSMO_ASSERT(msg->l3h)
        OSMO_ASSERT(conn);
        OSMO_ASSERT(msg);
 
+       gh = msgb_l3(msg);
+       pdisc = gsm48_hdr_pdisc(gh);
+
        LOGP(DRLL, LOGL_DEBUG, "Dispatching 04.08 message, pdisc=%d\n", pdisc);
 #if 0
        if (silent_call_reroute(conn, msg))

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic0463191e68bac1630481a5cc220222b2f7ef3f2
Gerrit-PatchSet: 1
Gerrit-Project: openbsc
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <[email protected]>
Gerrit-Reviewer: dexter <[email protected]>

Reply via email to